Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.x.server.application')
-rw-r--r--plugins/org.eclipse.osee.x.server.application/.project5
-rw-r--r--plugins/org.eclipse.osee.x.server.application/META-INF/MANIFEST.MF17
-rw-r--r--plugins/org.eclipse.osee.x.server.application/OSGI-INF/osee.server.application.xml10
-rw-r--r--plugins/org.eclipse.osee.x.server.application/build.properties3
-rw-r--r--plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/ServerApplication.java52
-rw-r--r--plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/ServerHealthEndpointImpl.java166
-rw-r--r--plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/model/ServerStatus.java56
-rw-r--r--plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/model/StatusKey.java51
-rw-r--r--plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/operations/BuildServerStatusOperation.java60
9 files changed, 406 insertions, 14 deletions
diff --git a/plugins/org.eclipse.osee.x.server.application/.project b/plugins/org.eclipse.osee.x.server.application/.project
index c2341d0e97c..10d2165ed75 100644
--- a/plugins/org.eclipse.osee.x.server.application/.project
+++ b/plugins/org.eclipse.osee.x.server.application/.project
@@ -20,6 +20,11 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ds.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
diff --git a/plugins/org.eclipse.osee.x.server.application/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.x.server.application/META-INF/MANIFEST.MF
index 3fafda2902b..7467c9610d3 100644
--- a/plugins/org.eclipse.osee.x.server.application/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.x.server.application/META-INF/MANIFEST.MF
@@ -4,5 +4,20 @@ Bundle-Name: OSEE X Server Application
Bundle-SymbolicName: org.eclipse.osee.x.server.application
Bundle-Version: 0.25.4.qualifier
Bundle-Vendor: Eclipse Open System Engineering Environment
+Service-Component: OSGI-INF/*.xml
+Osee-Data: OSEE-INF/*
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
-Import-Package: org.eclipse.equinox.app
+Import-Package: javax.ws.rs,
+ javax.ws.rs.core,
+ javax.ws.rs.ext,
+ org.codehaus.jackson,
+ org.codehaus.jackson.annotate;version="1.9.13",
+ org.codehaus.jackson.map;version="1.9.13",
+ org.eclipse.core.runtime.jobs,
+ org.eclipse.equinox.app,
+ org.eclipse.osee.framework.core.server,
+ org.eclipse.osee.framework.core.util,
+ org.eclipse.osee.framework.jdk.core.util,
+ org.eclipse.osee.jdbc,
+ org.eclipse.osee.logger,
+ org.eclipse.osee.orcs.data
diff --git a/plugins/org.eclipse.osee.x.server.application/OSGI-INF/osee.server.application.xml b/plugins/org.eclipse.osee.x.server.application/OSGI-INF/osee.server.application.xml
new file mode 100644
index 00000000000..4362dec2435
--- /dev/null
+++ b/plugins/org.eclipse.osee.x.server.application/OSGI-INF/osee.server.application.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop">
+ <implementation class="org.eclipse.osee.x.server.application.ServerApplication"/>
+ <service>
+ <provide interface="javax.ws.rs.core.Application"/>
+ </service>
+ <reference bind="setApplicationServerManager" cardinality="1..1" interface="org.eclipse.osee.framework.core.server.IApplicationServerManager" name="IApplicationServerManager" policy="static"/>
+ <reference bind="addJdbcService" cardinality="0..n" interface="org.eclipse.osee.jdbc.JdbcService" name="JdbcService" policy="dynamic" unbind="removeJdbcService"/>
+ <reference bind="setAuthenticationManager" cardinality="1..1" interface="org.eclipse.osee.framework.core.server.IAuthenticationManager" name="IAuthenticationManager" policy="static"/>
+</scr:component>
diff --git a/plugins/org.eclipse.osee.x.server.application/build.properties b/plugins/org.eclipse.osee.x.server.application/build.properties
index 34d2e4d2dad..c58ea2178c3 100644
--- a/plugins/org.eclipse.osee.x.server.application/build.properties
+++ b/plugins/org.eclipse.osee.x.server.application/build.properties
@@ -1,4 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
- .
+ .,\
+ OSGI-INF/
diff --git a/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/ServerApplication.java b/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/ServerApplication.java
index 7994f811521..58774f6c20a 100644
--- a/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/ServerApplication.java
+++ b/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/ServerApplication.java
@@ -10,28 +10,56 @@
*******************************************************************************/
package org.eclipse.osee.x.server.application;
-import org.eclipse.equinox.app.IApplication;
-import org.eclipse.equinox.app.IApplicationContext;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+import org.eclipse.osee.framework.core.server.IApplicationServerManager;
+import org.eclipse.osee.framework.core.server.IAuthenticationManager;
+import org.eclipse.osee.jdbc.JdbcService;
+import org.eclipse.osee.x.server.application.internal.ServerHealthEndpointImpl;
/**
* @author Roberto E. Escobar
+ * @author Donald G. Dunne
*/
-public class ServerApplication implements IApplication {
+@ApplicationPath("server")
+public class ServerApplication extends Application {
- private IApplicationContext context;
+ private final Set<Object> singletons = new HashSet<Object>();
+ private IApplicationServerManager applicationServerManager;
+ private final Map<String, JdbcService> jdbcServices = new ConcurrentHashMap<>();
+ private IAuthenticationManager authManager;
- @Override
- public Object start(IApplicationContext context) throws Exception {
- this.context = context;
- // context.applicationRunning();
- return IApplicationContext.EXIT_ASYNC_RESULT;
+ public void setAuthenticationManager(IAuthenticationManager authManager) {
+ this.authManager = authManager;
+ }
+
+ public void setApplicationServerManager(IApplicationServerManager applicationServerManager) {
+ this.applicationServerManager = applicationServerManager;
+ }
+
+ public void addJdbcService(JdbcService jdbcService) {
+ jdbcServices.put(jdbcService.getId(), jdbcService);
+ }
+
+ public void removeJdbcService(JdbcService jdbcService) {
+ jdbcServices.remove(jdbcService.getId());
}
@Override
+ public Set<Object> getSingletons() {
+ return singletons;
+ }
+
+ public void start(Map<String, Object> properties) {
+ singletons.add(new ServerHealthEndpointImpl(applicationServerManager, jdbcServices, authManager));
+ }
+
public void stop() {
- if (context != null) {
- context.setResult(IApplication.EXIT_OK, this);
- }
+ singletons.clear();
}
}
diff --git a/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/ServerHealthEndpointImpl.java b/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/ServerHealthEndpointImpl.java
new file mode 100644
index 00000000000..c228ff81c77
--- /dev/null
+++ b/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/ServerHealthEndpointImpl.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * Copyright (c) 2017 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.x.server.application.internal;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.LinkedList;
+import java.util.List;
+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.codehaus.jackson.map.ObjectMapper;
+import org.eclipse.osee.framework.core.server.IApplicationServerManager;
+import org.eclipse.osee.framework.core.server.IAuthenticationManager;
+import org.eclipse.osee.framework.core.util.HttpProcessor;
+import org.eclipse.osee.framework.core.util.HttpProcessor.AcquireResult;
+import org.eclipse.osee.framework.jdk.core.util.AHTML;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.jdbc.JdbcClientConfig;
+import org.eclipse.osee.jdbc.JdbcService;
+import org.eclipse.osee.x.server.application.internal.model.ServerStatus;
+import org.eclipse.osee.x.server.application.internal.model.StatusKey;
+import org.eclipse.osee.x.server.application.internal.operations.BuildServerStatusOperation;
+
+/**
+ * @author Donald G. Dunne
+ */
+@Path("/health")
+public final class ServerHealthEndpointImpl {
+ private final IApplicationServerManager applicationServerManager;
+ private final Map<String, JdbcService> jdbcServices;
+ private final IAuthenticationManager authManager;
+ private ObjectMapper mapper;
+
+ public ServerHealthEndpointImpl(IApplicationServerManager applicationServerManager, Map<String, JdbcService> jdbcServices, IAuthenticationManager authManager) {
+ this.applicationServerManager = applicationServerManager;
+ this.jdbcServices = jdbcServices;
+ this.authManager = authManager;
+ }
+
+ @Path("top")
+ @GET
+ @Produces(MediaType.TEXT_HTML)
+ public String getTop() throws Exception {
+ StringBuilder sb = new StringBuilder();
+ if (Lib.isWindows()) {
+ sb.append("Top is not available for windows");
+ } else {
+ ProcessBuilder pb = new ProcessBuilder("top", "-l", "1");
+ pb.redirectError();
+ Process p = pb.start();
+ InputStream is = p.getInputStream();
+ int value = -1;
+ while ((value = is.read()) != -1) {
+ sb.append(((char) value));
+ }
+ int exitCode = p.waitFor();
+ sb.append("Top exited with " + exitCode);
+ }
+ return sb.toString();
+ }
+
+ @Path("status")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public ServerStatus serverStatus() {
+ return new BuildServerStatusOperation(applicationServerManager, authManager).get();
+ }
+
+ @Path("status/all")
+ @GET
+ @Produces(MediaType.TEXT_HTML)
+ public String serverStatusAsll() {
+ return serverStatusAsll(false);
+ }
+
+ @Path("status/all/detail")
+ @GET
+ @Produces(MediaType.TEXT_HTML)
+ public String serverStatusAsllDetails() {
+ return serverStatusAsll(true);
+ }
+
+ private String serverStatusAsll(boolean details) {
+
+ final JdbcClientConfig config = jdbcServices.values().iterator().next().getClient().getConfig();
+ Object serverObj = config.getDbProps().get("application.servers");
+ if (serverObj == null || !(serverObj instanceof String)) {
+ throw new IllegalStateException("No application.servers configured in osee.json file");
+ }
+ String serversStr = ((String) serverObj).replaceAll("[\\[\\]]", "");
+ serversStr = serversStr.replaceAll(" ", "");
+ String[] servers = serversStr.split(",");
+ if (servers.length == 0) {
+ throw new IllegalStateException("No application.servers configured in osee.json file");
+ }
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(AHTML.beginMultiColumnTable(95, 2));
+ List<String> headers = new LinkedList<>();
+ headers.add("Name");
+ headers.add("Alive");
+ for (StatusKey key : StatusKey.values()) {
+ if (details || !key.isDetails()) {
+ headers.add(key.name());
+ }
+ }
+ sb.append(AHTML.addHeaderRowMultiColumnTable(headers));
+ for (String server : (servers)) {
+ addServer(sb, server, details);
+ }
+ sb.append(AHTML.endMultiColumnTable());
+ return sb.toString();
+ }
+
+ private ObjectMapper getMapper() {
+ if (mapper == null) {
+ mapper = new ObjectMapper();
+ }
+ return mapper;
+ }
+
+ private void addServer(StringBuilder sb, String server, boolean details) {
+ List<String> values = new LinkedList<>();
+ String statusUrl = "http://" + server + "/server/health/status";
+ values.add(AHTML.getHyperlink(statusUrl, server));
+ try {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ URL url = new URL(String.format("http://%s%s", server, "/server/health/status"));
+ AcquireResult result = HttpProcessor.acquire(url, outputStream, 5000);
+ if (result.wasSuccessful()) {
+ values.add("Ok");
+ } else {
+ values.add("Not successful: " + result.getResult());
+ return;
+ }
+
+ String json = outputStream.toString(result.getEncoding());
+ ServerStatus stat = getMapper().readValue(json, ServerStatus.class);
+ for (StatusKey key : StatusKey.values()) {
+ if (details || !key.isDetails()) {
+ String value = stat.get(key);
+ if (value == null) {
+ value = "";
+ }
+ values.add(value);
+ }
+ }
+ } catch (Exception ex) {
+ values.add("Exception: " + ex.getMessage());
+ }
+ sb.append(AHTML.addRowMultiColumnTable(values.toArray(new String[values.size()])));
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/model/ServerStatus.java b/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/model/ServerStatus.java
new file mode 100644
index 00000000000..74c5c1a39a7
--- /dev/null
+++ b/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/model/ServerStatus.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2017 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.x.server.application.internal.model;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.codehaus.jackson.annotate.JsonIgnore;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class ServerStatus {
+
+ private final Map<String, String> data = new HashMap<String, String>();
+
+ public void set(StatusKey key, String value) {
+ data.put(key.name(), value);
+ }
+
+ @JsonIgnore
+ public String get(StatusKey key) {
+ return data.get(key.name());
+ }
+
+ public void add(String keyStr, String value) {
+ StatusKey key = StatusKey.Unknown;
+ try {
+ key = StatusKey.valueOf(keyStr);
+ } catch (Exception ex) {
+ // do nothing
+ }
+ if (key == StatusKey.Unknown) {
+ String newStr = data.get(StatusKey.Unknown);
+ if (newStr == null) {
+ newStr = String.format("[%s][%s]", key.name(), value);
+ } else {
+ newStr += String.format("%s - [%s][%s]", key.name(), value);
+ }
+ data.put(StatusKey.Unknown.name(), newStr);
+ }
+ data.put(keyStr, value);
+ }
+
+ public Map<String, String> getData() {
+ return data;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/model/StatusKey.java b/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/model/StatusKey.java
new file mode 100644
index 00000000000..2f19a8d5afa
--- /dev/null
+++ b/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/model/StatusKey.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2017 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.x.server.application.internal.model;
+
+/**
+ * @author Donald G. Dunne
+ */
+public enum StatusKey {
+ ServerUri("URI", false),
+ ServerState("State", false),
+ MemoryAllocated("Mem Alloc", false),
+ MemoryUsed("Mem-Used", false),
+ MemoryMax("Mem-Max", false),
+ ActiveThreads("Threads", false),
+ JobManager("Jobs", false),
+ CurrentJob("Curr Job", false),
+ CurrentTasks("Curr Tasks", true),
+ ServerId("ID", true),
+ StartTime("Start", true),
+ CodeLocation("Start", true),
+ BinaryDataPath("Binary", true),
+ AuthenticationScheme("Auth-Scheme", true),
+ AuthenticationSchemeSupported("Auth-Supported", true),
+ SupportedVersions("Versions", true),
+ Unknown("Unknown", true);
+
+ private final String shortName;
+ private final boolean details;
+
+ private StatusKey(String shortName, boolean details) {
+ this.shortName = shortName;
+ this.details = details;
+ }
+
+ public boolean isDetails() {
+ return details;
+ }
+
+ public String getShortName() {
+ return shortName;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/operations/BuildServerStatusOperation.java b/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/operations/BuildServerStatusOperation.java
new file mode 100644
index 00000000000..58d90cdfa82
--- /dev/null
+++ b/plugins/org.eclipse.osee.x.server.application/src/org/eclipse/osee/x/server/application/internal/operations/BuildServerStatusOperation.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2017 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.x.server.application.internal.operations;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryUsage;
+import java.text.DateFormat;
+import java.util.Arrays;
+import java.util.List;
+import org.eclipse.osee.framework.core.server.IApplicationServerManager;
+import org.eclipse.osee.framework.core.server.IAuthenticationManager;
+import org.eclipse.osee.framework.core.server.OseeServerProperties;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.x.server.application.internal.model.ServerStatus;
+import org.eclipse.osee.x.server.application.internal.model.StatusKey;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class BuildServerStatusOperation {
+
+ private final IApplicationServerManager applicationServerManager;
+ private final IAuthenticationManager authManager;
+
+ public BuildServerStatusOperation(IApplicationServerManager applicationServerManager, IAuthenticationManager authManager) {
+ this.applicationServerManager = applicationServerManager;
+ this.authManager = authManager;
+ }
+
+ public ServerStatus get() {
+ ServerStatus stat = new ServerStatus();
+ stat.set(StatusKey.ServerUri, applicationServerManager.getServerUri().toString());
+ stat.set(StatusKey.ServerId, applicationServerManager.getId());
+ stat.set(StatusKey.StartTime, DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(
+ applicationServerManager.getDateStarted()));
+ stat.set(StatusKey.CodeLocation, System.getProperty("user.dir"));
+ stat.set(StatusKey.BinaryDataPath, OseeServerProperties.getOseeApplicationServerData(null));
+ stat.set(StatusKey.AuthenticationScheme, authManager.getProtocol());
+ stat.set(StatusKey.AuthenticationSchemeSupported, Arrays.deepToString(authManager.getProtocols()));
+ stat.set(StatusKey.SupportedVersions, Arrays.deepToString(applicationServerManager.getVersions()));
+ MemoryUsage heapMem = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
+ stat.set(StatusKey.MemoryUsed, Lib.toMBytes(heapMem.getUsed()));
+ stat.set(StatusKey.MemoryAllocated, Lib.toMBytes(heapMem.getCommitted()));
+ stat.set(StatusKey.MemoryMax, Lib.toMBytes(heapMem.getMax()));
+ stat.set(StatusKey.ServerState, applicationServerManager.isSystemIdle() ? "IDLE" : "BUSY");
+ stat.set(StatusKey.ActiveThreads, String.valueOf(applicationServerManager.getNumberOfActiveThreads()));
+ List<String> entries = applicationServerManager.getCurrentProcesses();
+ stat.set(StatusKey.CurrentTasks,
+ entries.isEmpty() ? "NONE" : org.eclipse.osee.framework.jdk.core.util.Collections.toString(", ", entries));
+ return stat;
+ }
+} \ No newline at end of file

Back to the top