Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrescobar2011-08-31 01:43:55 +0000
committerRyan D. Brooks2011-08-31 01:43:55 +0000
commit316dbcb72ea8cbeb14bf1b580b538b9fc71e3521 (patch)
tree2f63af1c88ff446fff02bab8b2515bf2b1c1faee /plugins/org.eclipse.osee.framework.core.client
parentc4d02f1743ca4ab01fca3466acd79301f0926df8 (diff)
downloadorg.eclipse.osee-316dbcb72ea8cbeb14bf1b580b538b9fc71e3521.tar.gz
org.eclipse.osee-316dbcb72ea8cbeb14bf1b580b538b9fc71e3521.tar.xz
org.eclipse.osee-316dbcb72ea8cbeb14bf1b580b538b9fc71e3521.zip
bug: Fix osee client arbitration logic
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.java105
-rw-r--r--plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ArbitrationServer.java85
-rw-r--r--plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/OseeApplicationServer.java80
-rw-r--r--plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/OseeServer.java62
4 files changed, 151 insertions, 181 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
index c1b4eed30a2..ad9782ba423 100644
--- 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
@@ -1,30 +1,33 @@
-/*
- * Created on Aug 3, 2011
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 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
*
- * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
- */
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
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 java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.logging.Level;
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;
+import org.eclipse.osee.framework.core.util.HttpProcessor;
+
+public class ApplicationServer extends OseeServer {
+ private static final DateFormat format = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
-class ApplicationServer extends OseeServer {
private OseeServerInfo serverInfo;
- private String oseeServer;
- private boolean overrideArbitration = false;
+ private String serverAddress;
public ApplicationServer() {
super("Application Server");
}
- public boolean hasServerInfo() {
+ public boolean isServerInfoValid() {
return serverInfo != null;
}
@@ -34,64 +37,28 @@ class ApplicationServer extends OseeServer {
public void setServerInfo(OseeServerInfo serverInfo) {
this.serverInfo = serverInfo;
+ this.serverAddress = null;
}
- public String getOseeServer() {
- if (oseeServer == null && serverInfo != null) {
- oseeServer = String.format("http://%s:%s/", serverInfo.getServerAddress(), serverInfo.getPort());
+ public String getServerAddress() {
+ if (serverAddress == null && serverInfo != null) {
+ serverAddress = 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");
+ return serverAddress;
}
- @Override
- public void reset() {
- super.reset();
- oseeServer = null;
- String overrideValue = OseeClientProperties.getOseeApplicationServer();
- if (Strings.isValid(overrideValue)) {
- overrideArbitration = true;
- serverInfo = setFromString(overrideValue);
+ public void checkAlive() {
+ if (isServerInfoValid()) {
+ boolean alive = HttpProcessor.isAlive(serverInfo.getServerAddress(), serverInfo.getPort());
+ setAlive(alive);
+ if (alive) {
+ set(Level.INFO, null, "%s %s Running Since: %s", getServerAddress(),
+ Arrays.deepToString(serverInfo.getVersion()), format.format(serverInfo.getDateStarted()));
+ } else {
+ set(Level.SEVERE, null, "Unable to Connect to [%s]", getServerAddress());
+ }
+ } else {
+ setAlive(false);
}
}
-
- 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
index 42dacaeb027..c3591d1777a 100644
--- 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
@@ -1,14 +1,17 @@
-/*
- * Created on Aug 3, 2011
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 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
*
- * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
- */
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
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;
@@ -21,23 +24,20 @@ 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.Lib;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.logging.OseeLog;
-class ArbitrationServer extends OseeServer {
+public 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();
+ public OseeServerInfo getViaArbitration() {
+ OseeServerInfo serverInfo = null;
+ resetStatus();
ByteArrayOutputStream outputStream = null;
- InputStream inputStream = null;
AcquireResult result = null;
try {
Map<String, String> parameters = new HashMap<String, String>();
@@ -48,55 +48,38 @@ class ArbitrationServer extends OseeServer {
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 {
+ setAlive(true);
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());
+ serverInfo = getServerInfo(outputStream, result);
} else {
String arbitrationServerMessage = result.getResult();
- if (!Strings.isValid(arbitrationServerMessage)) {
- arbitrationServerMessage =
- String.format("Error requesting application server for version [%s]", OseeCodeVersion.getVersion());
+ if (Strings.isValid(arbitrationServerMessage)) {
+ set(Level.SEVERE, null, arbitrationServerMessage);
+ } else {
+ set(Level.SEVERE, null, "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");
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
+ set(Level.SEVERE, ex, "Error connecting to arbitration server - [%s]", ex.getLocalizedMessage());
} 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);
- }
+ Lib.close(outputStream);
}
+ return serverInfo;
}
- @Override
- public String report() {
- String errorStr = super.report();
- if (!Strings.isValid(errorStr)) {
- errorStr = "";
+ private OseeServerInfo getServerInfo(ByteArrayOutputStream outputStream, AcquireResult result) {
+ OseeServerInfo serverInfo = null;
+ try {
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
+ serverInfo = OseeServerInfo.fromXml(inputStream);
+ } catch (Exception ex) {
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
+ set(Level.SEVERE, ex, "Error parsing arbitration server response - [%s]", ex.getLocalizedMessage());
}
- System.setProperty("osee.arbitration.server.error", errorStr);
- return errorStr;
+ return serverInfo;
}
}
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 8c55760ca05..46c6c0573c7 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,13 +11,18 @@
package org.eclipse.osee.framework.core.client.internal;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
+import java.sql.Timestamp;
+import java.util.Date;
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.data.OseeServerInfo;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.util.HttpProcessor;
+import org.eclipse.osee.framework.core.util.Conditions;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.logging.OseeLog;
/**
* @author Andrew M. Finkbeiner
@@ -25,9 +30,8 @@ import org.eclipse.osee.framework.core.util.HttpProcessor;
*/
public class OseeApplicationServer {
- 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 static final ArbitrationServer arbitrationServer = new ArbitrationServer();
+ private static final ApplicationServer applicationServer = new ApplicationServer();
private OseeApplicationServer() {
// private constructor
@@ -35,8 +39,9 @@ public class OseeApplicationServer {
public static String getOseeApplicationServer() throws OseeCoreException {
checkAndUpdateStatus();
- applicationServer.validate();
- return applicationServer.getOseeServer();
+ String serverAddress = applicationServer.getServerAddress();
+ Conditions.checkNotNull(serverAddress, "resource server address");
+ return serverAddress;
}
public static boolean isApplicationServerAlive() {
@@ -44,29 +49,48 @@ public class OseeApplicationServer {
return applicationServer.isAlive();
}
- private static void checkAndUpdateStatus() {
- applicationServer.reset();
- if (!applicationServer.hasServerInfo()) {
- arbitrationServer.acquireApplicationServer(applicationServer);
- } else if (applicationServer.isOverrideArbitration()) {
- arbitrationServer.set(Level.INFO, null, "Arbitration Overridden");
- }
- 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())));
+ private synchronized static void checkAndUpdateStatus() {
+ if (!applicationServer.isServerInfoValid()) {
+ applicationServer.resetStatus();
+ OseeServerInfo serverInfo = null;
+ String overrideValue = OseeClientProperties.getOseeApplicationServer();
+ if (Strings.isValid(overrideValue)) {
+ arbitrationServer.set(Level.INFO, null, "Arbitration Overridden");
+ try {
+ serverInfo = parseServerInfo(overrideValue);
+ } catch (Exception ex) {
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
+ applicationServer.set(Level.SEVERE, ex, "Error parsing arbitration server override [%s]", overrideValue);
+ }
} else {
- applicationServer.set(Level.SEVERE, null,
- String.format("Unable to Connect to [%s]", applicationServer.getOseeServer()));
+ serverInfo = arbitrationServer.getViaArbitration();
+ if (serverInfo == null) {
+ applicationServer.set(Level.SEVERE, null, "Arbitration Server Error");
+ }
}
+ applicationServer.setServerInfo(serverInfo);
}
+ applicationServer.checkAlive();
+
arbitrationServer.report();
applicationServer.report();
}
+
+ private static OseeServerInfo parseServerInfo(String value) throws Exception {
+ 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;
+ }
}
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
index eef1257db89..f99e76f1d0c 100644
--- 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
@@ -1,30 +1,36 @@
-/*
- * Created on Aug 3, 2011
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 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
*
- * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
- */
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
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.IHealthStatus;
import org.eclipse.osee.framework.logging.OseeLog;
-abstract class OseeServer {
+public abstract class OseeServer {
private boolean isAlive;
- private String message = "";
private final String name;
- private Exception exception;
- private Level level = Level.INFO;
+ private IHealthStatus status;
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 void set(Level level, Exception ex, String message, Object... args) {
+ Level myLevel = level;
+ if (myLevel == null) {
+ myLevel = Level.INFO;
+ }
+ status = new BaseStatus(getName(), myLevel, ex, message, args);
}
public String getName() {
@@ -35,33 +41,23 @@ abstract class OseeServer {
this.isAlive = isServerAlive;
}
- public Exception getException() {
- return exception;
- }
-
- public Level getLevel() {
- return level;
- }
-
- public void reset() {
- message = null;
- level = null;
- exception = null;
+ public void resetStatus() {
isAlive = false;
- }
-
- public String getMessage() {
- return message;
+ status = null;
}
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() + "]" : ""));
+ public void report() {
+ if (status == null) {
+ status = new BaseStatus(name, Level.INFO, null, (Throwable) null);
+ }
+ OseeLog.reportStatus(new BaseStatus(name, status.getLevel(), status.getException(), "%s: %s %s",
+ status.getLevel(), status.getMessage(),
+ (status.getException() != null ? "[" + status.getException().getLocalizedMessage() + "]" : "")));
+ OseeLog.log(OseeApplicationServer.class, status.getLevel(), status.getMessage(), status.getException());
}
+
}

Back to the top