Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorddunne2011-08-04 15:42:45 +0000
committerRyan D. Brooks2011-08-04 15:42:45 +0000
commit0c5916b7d21616ebdf67061bbc878ef3f9bc2f7f (patch)
tree0cc9d67a58dfaafdceb95f7575a3db7ad14786ac /plugins/org.eclipse.osee.framework.core.client
parent4d16985757adcad1d1a9270ba73579288d2eb566 (diff)
downloadorg.eclipse.osee-0c5916b7d21616ebdf67061bbc878ef3f9bc2f7f.tar.gz
org.eclipse.osee-0c5916b7d21616ebdf67061bbc878ef3f9bc2f7f.tar.xz
org.eclipse.osee-0c5916b7d21616ebdf67061bbc878ef3f9bc2f7f.zip
feature[ats_4F0X2]: Provide better connection unavailable information for failed OSEE launch
Diffstat (limited to 'plugins/org.eclipse.osee.framework.core.client')
-rw-r--r--plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ApplicationServer.java97
-rw-r--r--plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ArbitrationServer.java102
-rw-r--r--plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/InternalClientSessionManager.java4
-rw-r--r--plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/OseeApplicationServer.java137
-rw-r--r--plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/OseeServer.java67
5 files changed, 296 insertions, 111 deletions
diff --git a/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ApplicationServer.java b/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ApplicationServer.java
new file mode 100644
index 00000000000..c1b4eed30a2
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ApplicationServer.java
@@ -0,0 +1,97 @@
+/*
+ * Created on Aug 3, 2011
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.framework.core.client.internal;
+
+import java.sql.Timestamp;
+import java.util.Date;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.eclipse.osee.framework.core.client.OseeClientProperties;
+import org.eclipse.osee.framework.core.data.OseeServerInfo;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.util.Conditions;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
+class ApplicationServer extends OseeServer {
+ private OseeServerInfo serverInfo;
+ private String oseeServer;
+ private boolean overrideArbitration = false;
+
+ public ApplicationServer() {
+ super("Application Server");
+ }
+
+ public boolean hasServerInfo() {
+ return serverInfo != null;
+ }
+
+ public OseeServerInfo getServerInfo() {
+ return serverInfo;
+ }
+
+ public void setServerInfo(OseeServerInfo serverInfo) {
+ this.serverInfo = serverInfo;
+ }
+
+ public String getOseeServer() {
+ if (oseeServer == null && serverInfo != null) {
+ oseeServer = String.format("http://%s:%s/", serverInfo.getServerAddress(), serverInfo.getPort());
+ }
+ return oseeServer;
+ }
+
+ public void setOseeServer(String oseeServer) {
+ this.oseeServer = oseeServer;
+ }
+
+ public void validate() throws OseeCoreException {
+ Conditions.checkNotNullOrEmpty(oseeServer, "resource server address");
+ }
+
+ @Override
+ public void reset() {
+ super.reset();
+ oseeServer = null;
+ String overrideValue = OseeClientProperties.getOseeApplicationServer();
+ if (Strings.isValid(overrideValue)) {
+ overrideArbitration = true;
+ serverInfo = setFromString(overrideValue);
+ }
+ }
+
+ public boolean isOverrideArbitration() {
+ return overrideArbitration;
+ }
+
+ public OseeServerInfo setFromString(String value) {
+ OseeServerInfo toReturn = null;
+ String rawAddress = value;
+ if (rawAddress.startsWith("http")) {
+ rawAddress = value.replace("http://", "");
+ }
+ Pattern pattern = Pattern.compile("(.*):(\\d+)");
+ Matcher matcher = pattern.matcher(rawAddress);
+ if (matcher.find()) {
+ String address = matcher.group(1);
+ int port = Integer.valueOf(matcher.group(2));
+ toReturn =
+ new OseeServerInfo("OVERRIDE", address, port, new String[] {"OVERRIDE"},
+ new Timestamp(new Date().getTime()), true);
+ }
+ return toReturn;
+ }
+
+ @Override
+ public String report() {
+ String errorStr = super.report();
+ if (!Strings.isValid(errorStr)) {
+ errorStr = "";
+ }
+ System.setProperty("osee.application.server.error", errorStr);
+ return errorStr;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ArbitrationServer.java b/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ArbitrationServer.java
new file mode 100644
index 00000000000..42dacaeb027
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ArbitrationServer.java
@@ -0,0 +1,102 @@
+/*
+ * Created on Aug 3, 2011
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.framework.core.client.internal;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.core.client.CoreClientActivator;
+import org.eclipse.osee.framework.core.client.server.HttpUrlBuilderClient;
+import org.eclipse.osee.framework.core.data.OseeCodeVersion;
+import org.eclipse.osee.framework.core.data.OseeServerContext;
+import org.eclipse.osee.framework.core.data.OseeServerInfo;
+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.Strings;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+class ArbitrationServer extends OseeServer {
+
+ public ArbitrationServer() {
+ super("Arbitration Server");
+ }
+
+ public void acquireApplicationServer(ApplicationServer applicationServer) {
+ if (applicationServer.isOverrideArbitration()) {
+ set(Level.INFO, null, "Arbitration Overridden");
+ setAlive(true);
+ }
+ reset();
+ ByteArrayOutputStream outputStream = null;
+ InputStream inputStream = null;
+ AcquireResult result = null;
+ try {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put("version", OseeCodeVersion.getVersion());
+ String url =
+ HttpUrlBuilderClient.getInstance().getOsgiArbitrationServiceUrl(OseeServerContext.LOOKUP_CONTEXT,
+ parameters);
+
+ outputStream = new ByteArrayOutputStream();
+ result = HttpProcessor.acquire(new URL(url), outputStream);
+ } catch (Exception ex) {
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
+ set(Level.SEVERE, ex, "Error connecting - " + ex.getLocalizedMessage());
+ applicationServer.reset();
+ applicationServer.set(Level.SEVERE, null, "Arbitration Server Unavailable");
+ return;
+ }
+ try {
+ set(Level.INFO, null, HttpUrlBuilderClient.getInstance().getArbitrationServerPrefix());
+ if (result.getCode() == HttpURLConnection.HTTP_OK) {
+ inputStream = new ByteArrayInputStream(outputStream.toByteArray());
+ applicationServer.setServerInfo(OseeServerInfo.fromXml(inputStream));
+ set(Level.INFO, null, HttpUrlBuilderClient.getInstance().getArbitrationServerPrefix());
+ } else {
+ String arbitrationServerMessage = result.getResult();
+ if (!Strings.isValid(arbitrationServerMessage)) {
+ arbitrationServerMessage =
+ String.format("Error requesting application server for version [%s]", OseeCodeVersion.getVersion());
+ }
+ applicationServer.set(Level.SEVERE, null, arbitrationServerMessage);
+ }
+ } catch (Exception ex) {
+ set(Level.SEVERE, ex, "Error retrieving application server - " + ex.getLocalizedMessage());
+ applicationServer.reset();
+ applicationServer.set(Level.SEVERE, null, "Arbitration Server Error");
+ } finally {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException ex) {
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
+ }
+ }
+ try {
+ outputStream.close();
+ } catch (IOException ex) {
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
+ }
+ }
+ }
+
+ @Override
+ public String report() {
+ String errorStr = super.report();
+ if (!Strings.isValid(errorStr)) {
+ errorStr = "";
+ }
+ System.setProperty("osee.arbitration.server.error", errorStr);
+ return errorStr;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/InternalClientSessionManager.java b/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/InternalClientSessionManager.java
index 77654432361..f94e5d04bbc 100644
--- a/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/InternalClientSessionManager.java
+++ b/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/InternalClientSessionManager.java
@@ -103,6 +103,10 @@ public class InternalClientSessionManager {
}
public synchronized OseeClientSession authenticate(ICredentialProvider credentialProvider) throws OseeCoreException {
+ if (!OseeApplicationServer.isApplicationServerAlive()) {
+ OseeLog.reportStatus(new BaseStatus(STATUS_ID, Level.SEVERE, "Application Server not Available"));
+ return null;
+ }
if (!isSessionValid()) {
try {
OseeCredential credential = credentialProvider.getCredential();
diff --git a/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/OseeApplicationServer.java b/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/OseeApplicationServer.java
index 1b9edd7121f..8c55760ca05 100644
--- a/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/OseeApplicationServer.java
+++ b/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/OseeApplicationServer.java
@@ -11,46 +11,23 @@
package org.eclipse.osee.framework.core.client.internal;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
import java.util.logging.Level;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.eclipse.osee.framework.core.client.CoreClientActivator;
-import org.eclipse.osee.framework.core.client.OseeClientProperties;
-import org.eclipse.osee.framework.core.client.server.HttpUrlBuilderClient;
-import org.eclipse.osee.framework.core.data.OseeCodeVersion;
-import org.eclipse.osee.framework.core.data.OseeServerContext;
import org.eclipse.osee.framework.core.data.OseeServerInfo;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.util.Conditions;
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.Strings;
-import org.eclipse.osee.framework.logging.BaseStatus;
-import org.eclipse.osee.framework.logging.OseeLog;
/**
* @author Andrew M. Finkbeiner
+ * @author Donald G. Dunne
*/
public class OseeApplicationServer {
- private static String oseeServer = null;
- private static boolean isServerAlive = false;
- private static OseeServerInfo serverInfo = null;
- private static final String ArbitrationService = "Arbitration Server";
- private static final String ApplicationServer = "Application Server";
+ public static ArbitrationServer arbitrationServer = new ArbitrationServer();
+ public static ApplicationServer applicationServer = new ApplicationServer();
+ private static DateFormat format = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
private OseeApplicationServer() {
// private constructor
@@ -58,100 +35,38 @@ public class OseeApplicationServer {
public static String getOseeApplicationServer() throws OseeCoreException {
checkAndUpdateStatus();
- Conditions.checkNotNullOrEmpty(oseeServer, "resource server address");
- return oseeServer;
+ applicationServer.validate();
+ return applicationServer.getOseeServer();
}
public static boolean isApplicationServerAlive() {
checkAndUpdateStatus();
- return isServerAlive;
+ return applicationServer.isAlive();
}
private static void checkAndUpdateStatus() {
- isServerAlive = false;
- if (serverInfo == null) {
- String overrideValue = OseeClientProperties.getOseeApplicationServer();
- if (Strings.isValid(overrideValue)) {
- serverInfo = fromString(overrideValue);
- } else {
- serverInfo = getOseeServerAddress();
- }
- if (serverInfo != null) {
- oseeServer = String.format("http://%s:%s/", serverInfo.getServerAddress(), serverInfo.getPort());
- }
+ applicationServer.reset();
+ if (!applicationServer.hasServerInfo()) {
+ arbitrationServer.acquireApplicationServer(applicationServer);
+ } else if (applicationServer.isOverrideArbitration()) {
+ arbitrationServer.set(Level.INFO, null, "Arbitration Overridden");
}
- DateFormat format = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
- if (serverInfo == null) {
- OseeLog.reportStatus(new BaseStatus(ApplicationServer, Level.SEVERE, "Application server address was null"));
- } else {
- isServerAlive = HttpProcessor.isAlive(serverInfo.getServerAddress(), serverInfo.getPort());
- if (isServerAlive) {
- OseeLog.reportStatus(new BaseStatus(ApplicationServer, Level.INFO, "%s %s Running Since: %s", oseeServer,
- Arrays.deepToString(serverInfo.getVersion()), format.format(serverInfo.getDateStarted())));
+ OseeServerInfo serverInfo = applicationServer.getServerInfo();
+ if (serverInfo != null) {
+ boolean alive = HttpProcessor.isAlive(serverInfo.getServerAddress(), serverInfo.getPort());
+ applicationServer.setAlive(alive);
+ if (alive) {
+ applicationServer.set(
+ Level.INFO,
+ null,
+ String.format("%s %s Running Since: %s", applicationServer.getOseeServer(),
+ Arrays.deepToString(serverInfo.getVersion()), format.format(serverInfo.getDateStarted())));
} else {
- OseeLog.reportStatus(new BaseStatus(ApplicationServer, Level.SEVERE, "Unable to Connect to [%s]",
- oseeServer));
- }
- }
- }
-
- public static OseeServerInfo fromString(String value) {
- OseeServerInfo toReturn = null;
- String rawAddress = value;
- if (rawAddress.startsWith("http")) {
- rawAddress = value.replace("http://", "");
- }
- Pattern pattern = Pattern.compile("(.*):(\\d+)");
- Matcher matcher = pattern.matcher(rawAddress);
- if (matcher.find()) {
- String address = matcher.group(1);
- int port = Integer.valueOf(matcher.group(2));
- toReturn =
- new OseeServerInfo("OVERRIDE", address, port, new String[] {"OVERRIDE"},
- new Timestamp(new Date().getTime()), true);
- }
- return toReturn;
- }
-
- private static OseeServerInfo getOseeServerAddress() {
- OseeServerInfo oseeServerInfo = null;
- ByteArrayOutputStream outputStream = null;
- InputStream inputStream = null;
- try {
- Map<String, String> parameters = new HashMap<String, String>();
- parameters.put("version", OseeCodeVersion.getVersion());
- String url =
- HttpUrlBuilderClient.getInstance().getOsgiArbitrationServiceUrl(OseeServerContext.LOOKUP_CONTEXT,
- parameters);
-
- outputStream = new ByteArrayOutputStream();
- AcquireResult result = HttpProcessor.acquire(new URL(url), outputStream);
- OseeLog.reportStatus(new BaseStatus(ArbitrationService, Level.INFO, "%s",
- HttpUrlBuilderClient.getInstance().getArbitrationServerPrefix()));
- if (result.getCode() == HttpURLConnection.HTTP_OK) {
- inputStream = new ByteArrayInputStream(outputStream.toByteArray());
- oseeServerInfo = OseeServerInfo.fromXml(inputStream);
- }
- } catch (Exception ex) {
- OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
- OseeLog.reportStatus(new BaseStatus(ArbitrationService, Level.SEVERE, ex,
- "Error requesting application server for version [%s]", OseeCodeVersion.getVersion()));
- } finally {
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (IOException ex) {
- OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
- }
- }
- if (outputStream != null) {
- try {
- outputStream.close();
- } catch (IOException ex) {
- OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
- }
+ applicationServer.set(Level.SEVERE, null,
+ String.format("Unable to Connect to [%s]", applicationServer.getOseeServer()));
}
}
- return oseeServerInfo;
+ arbitrationServer.report();
+ applicationServer.report();
}
}
diff --git a/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/OseeServer.java b/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/OseeServer.java
new file mode 100644
index 00000000000..eef1257db89
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/OseeServer.java
@@ -0,0 +1,67 @@
+/*
+ * Created on Aug 3, 2011
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.framework.core.client.internal;
+
+import java.util.logging.Level;
+import org.eclipse.osee.framework.logging.BaseStatus;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+abstract class OseeServer {
+
+ private boolean isAlive;
+ private String message = "";
+ private final String name;
+ private Exception exception;
+ private Level level = Level.INFO;
+
+ public OseeServer(String serverName) {
+ this.name = serverName;
+ }
+
+ public void set(Level level, Exception ex, String message) {
+ this.level = level;
+ this.message = message;
+ this.exception = ex;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setAlive(boolean isServerAlive) {
+ this.isAlive = isServerAlive;
+ }
+
+ public Exception getException() {
+ return exception;
+ }
+
+ public Level getLevel() {
+ return level;
+ }
+
+ public void reset() {
+ message = null;
+ level = null;
+ exception = null;
+ isAlive = false;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public boolean isAlive() {
+ return isAlive;
+ }
+
+ public String report() {
+ OseeLog.reportStatus(new BaseStatus(getName(), level, message, getException()));
+ OseeLog.log(OseeApplicationServer.class, level, message, getException());
+ return String.format("%s: %s %s", level, message,
+ (getException() != null ? "[" + getException().getLocalizedMessage() + "]" : ""));
+ }
+}

Back to the top