Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan D. Brooks2015-01-26 21:53:34 +0000
committerdonald.g.dunne2017-03-21 02:08:33 +0000
commit407b1cb626302fc5dabfd56271da86995618d4df (patch)
treefa40af37602af8dc19e7b45660d9b5c330df7b08 /plugins/org.eclipse.osee.orcs.db
parente95211879cea7c4331653a44a6ef213c041e47f6 (diff)
downloadorg.eclipse.osee-407b1cb626302fc5dabfd56271da86995618d4df.tar.gz
org.eclipse.osee-407b1cb626302fc5dabfd56271da86995618d4df.tar.xz
org.eclipse.osee-407b1cb626302fc5dabfd56271da86995618d4df.zip
feature: Create database health rest api
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.db')
-rw-r--r--plugins/org.eclipse.osee.orcs.db/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.osee.orcs.db/OSGI-INF/db_health.app.xml (renamed from plugins/org.eclipse.osee.orcs.db/OSGI-INF/tx.prune.console.command.xml)7
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/DbHeathApplication.java47
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/console/TxPruneCommand.java48
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/health/DatabaseHealthResource.java50
5 files changed, 103 insertions, 52 deletions
diff --git a/plugins/org.eclipse.osee.orcs.db/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.orcs.db/META-INF/MANIFEST.MF
index b7f30ca583..4d645425b4 100644
--- a/plugins/org.eclipse.osee.orcs.db/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.orcs.db/META-INF/MANIFEST.MF
@@ -10,6 +10,9 @@ Import-Package: com.google.common.base;version="15.0.0",
com.google.common.collect;version="15.0.0",
com.google.common.io;version="15.0.0",
org.apache.commons.lang.mutable,
+ javax.ws.rs,
+ javax.ws.rs.core,
+ javax.ws.rs.ext,
org.eclipse.core.runtime,
org.eclipse.osee.console.admin,
org.eclipse.osee.executor.admin,
diff --git a/plugins/org.eclipse.osee.orcs.db/OSGI-INF/tx.prune.console.command.xml b/plugins/org.eclipse.osee.orcs.db/OSGI-INF/db_health.app.xml
index 1eefd068ef..876550efc5 100644
--- a/plugins/org.eclipse.osee.orcs.db/OSGI-INF/tx.prune.console.command.xml
+++ b/plugins/org.eclipse.osee.orcs.db/OSGI-INF/db_health.app.xml
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
-<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" >
- <implementation class="org.eclipse.osee.orcs.db.internal.console.TxPruneCommand"/>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop">
+ <implementation class="org.eclipse.osee.orcs.db.internal.DbHeathApplication"/>
<service>
- <provide interface="org.eclipse.osee.console.admin.ConsoleCommand"/>
+ <provide interface="javax.ws.rs.core.Application"/>
</service>
- <reference bind="setLogger" cardinality="1..1" interface="org.eclipse.osee.logger.Log" name="Log" policy="static"/>
<reference bind="setJdbcService" cardinality="1..1" interface="org.eclipse.osee.jdbc.JdbcService" name="JdbcService" policy="static" target="(osgi.binding=orcs.jdbc.service)"/>
</scr:component>
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/DbHeathApplication.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/DbHeathApplication.java
new file mode 100644
index 0000000000..256e37b5f6
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/DbHeathApplication.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.db.internal;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+import org.eclipse.osee.jdbc.JdbcService;
+import org.eclipse.osee.orcs.db.internal.health.DatabaseHealthResource;
+
+/**
+ * @author Ryan D. Brooks
+ */
+@ApplicationPath("db")
+public final class DbHeathApplication extends Application {
+
+ private JdbcService jdbcService;
+
+ private final Set<Object> singletons = new HashSet<Object>();
+
+ public void setJdbcService(JdbcService jdbcService) {
+ this.jdbcService = jdbcService;
+ }
+
+ @Override
+ public Set<Object> getSingletons() {
+ return singletons;
+ }
+
+ public void start(Map<String, Object> properties) {
+ singletons.add(new DatabaseHealthResource(properties, jdbcService));
+ }
+
+ public void stop() {
+ singletons.clear();
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/console/TxPruneCommand.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/console/TxPruneCommand.java
deleted file mode 100644
index e00cc2206c..0000000000
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/console/TxPruneCommand.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.orcs.db.internal.console;
-
-import java.util.concurrent.Callable;
-import org.eclipse.osee.console.admin.Console;
-import org.eclipse.osee.console.admin.ConsoleParameters;
-import org.eclipse.osee.orcs.db.internal.callable.PurgeUnusedBackingDataAndTransactions;
-
-/**
- * @author Roberto E. Escobar
- */
-public class TxPruneCommand extends AbstractDatastoreConsoleCommand {
-
- @Override
- public String getName() {
- return "db_tx_prune";
- }
-
- @Override
- public String getDescription() {
- return "Purge artifact, attribute, and relation versions that are not addressed or non-existent and purge empty transactions";
- }
-
- @Override
- public String getUsage() {
- return "";
- }
-
- @Override
- public Callable<?> createCallable(Console console, ConsoleParameters params) {
- return new Callable<Void>() {
- @Override
- public Void call() throws Exception {
- new PurgeUnusedBackingDataAndTransactions(getJdbcClient()).purge();
- return null;
- }
- };
- }
-}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/health/DatabaseHealthResource.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/health/DatabaseHealthResource.java
new file mode 100644
index 0000000000..061fef5f8c
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/health/DatabaseHealthResource.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.db.internal.health;
+
+import java.util.Map;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.eclipse.osee.jdbc.JdbcClient;
+import org.eclipse.osee.jdbc.JdbcService;
+import org.eclipse.osee.orcs.db.internal.callable.PurgeUnusedBackingDataAndTransactions;
+
+/**
+ * @author Ryan D. Brooks
+ */
+@Path("/health")
+public final class DatabaseHealthResource {
+ private final Map<String, Object> properties;
+ private final JdbcClient jdbcClient;
+
+ public DatabaseHealthResource(Map<String, Object> properties, JdbcService jdbcService) {
+ this.properties = properties;
+ this.jdbcClient = jdbcService.getClient();
+ }
+
+ @Path("purgeunused")
+ @GET
+ @Produces(MediaType.TEXT_HTML)
+ public String deleteObsoleteData() {
+ PurgeUnusedBackingDataAndTransactions app = new PurgeUnusedBackingDataAndTransactions(jdbcClient);
+ int[] counts = app.purge();
+
+ StringBuilder strB = new StringBuilder();
+ for (int count : counts) {
+ strB.append(count);
+ strB.append("<br />");
+ }
+ return strB.toString();
+ }
+
+} \ No newline at end of file

Back to the top