diff options
author | Andrew M Finkbeiner | 2013-06-04 21:50:09 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2013-06-24 17:05:38 +0000 |
commit | 65f1cf61e09766b9c9caa08eb5142dcc2d988f2c (patch) | |
tree | 223a354c9465735868936e9d2de9a9faf0e2d33e | |
parent | ec2a4b213f464cff38204510d91c150cf3d5e479 (diff) | |
download | org.eclipse.osee-65f1cf61e09766b9c9caa08eb5142dcc2d988f2c.tar.gz org.eclipse.osee-65f1cf61e09766b9c9caa08eb5142dcc2d988f2c.tar.xz org.eclipse.osee-65f1cf61e09766b9c9caa08eb5142dcc2d988f2c.zip |
feature[ats_LJNN0]: Add support for connection
Change-Id: I2da2d0773cf58033827b16314ca1bd4052b2d1aa
9 files changed, 297 insertions, 33 deletions
diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/OteBaseMessages.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/OteBaseMessages.java index 07e05764eeb..75fb5beccfb 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/OteBaseMessages.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/OteBaseMessages.java @@ -16,8 +16,9 @@ import org.eclipse.osee.framework.messaging.MessageID; * @author Andrew M. Finkbeiner */ public enum OteBaseMessages implements MessageID { - RequestOteHost(true, "ABjyjamBQRvvgsdgwers", "topic:lba.ote.get.host", null, true); - + RequestOteHost(true, "ABjyjamBQRvvgsdgwers", "topic:lba.ote.get.host", null, true), + OteHostShutdown(true, "topic:lba.ote.host.shutdown", "topic:lba.ote.host.shutdown", null, false); + private String name; private Class<?> clazz; boolean isReplyRequired; diff --git a/plugins/org.eclipse.osee.ote.master.rest.model/src/org/eclipse/osee/ote/master/rest/model/OTEServer.java b/plugins/org.eclipse.osee.ote.master.rest.model/src/org/eclipse/osee/ote/master/rest/model/OTEServer.java index bdc3f9ef2f0..76fed872025 100644 --- a/plugins/org.eclipse.osee.ote.master.rest.model/src/org/eclipse/osee/ote/master/rest/model/OTEServer.java +++ b/plugins/org.eclipse.osee.ote.master.rest.model/src/org/eclipse/osee/ote/master/rest/model/OTEServer.java @@ -6,40 +6,102 @@ import javax.xml.bind.annotation.XmlRootElement; public class OTEServer { private String uuid; - private String uri; private String type; private String startTime; private String name; + private String station; + private String version; + private String comment; + private String owner; + private String oteRestServer; + private String oteActivemqServer; + private String connectedUsers; + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getOteRestServer() { + return oteRestServer; + } + + public void setOteRestServer(String oteRestServer) { + this.oteRestServer = oteRestServer; + } + + public String getOteActivemqServer() { + return oteActivemqServer; + } + + public void setOteActivemqServer(String oteActivemqServer) { + this.oteActivemqServer = oteActivemqServer; + } + + public String getConnectedUsers() { + return connectedUsers; + } + + public void setConnectedUsers(String connectedUsers) { + this.connectedUsers = connectedUsers; + } + public void setUUID(String uuid){ this.uuid = uuid; } - public String getUri() { - return uri; - } - public void setUri(String uri) { - this.uri = uri; - } public String getType() { return type; } + public void setType(String type) { this.type = type; } + public String getStartTime() { return startTime; } + public void setStartTime(String startTime) { this.startTime = startTime; } + public String getName() { return name; } + public void setName(String name) { this.name = name; } public String getUUID() { return uuid; } + } diff --git a/plugins/org.eclipse.osee.ote.master.rest.test/src/org/eclipse/osee/ote/master/rest/test/ClientAPITest.java b/plugins/org.eclipse.osee.ote.master.rest.test/src/org/eclipse/osee/ote/master/rest/test/ClientAPITest.java index e56886377fc..6efea50da4d 100644 --- a/plugins/org.eclipse.osee.ote.master.rest.test/src/org/eclipse/osee/ote/master/rest/test/ClientAPITest.java +++ b/plugins/org.eclipse.osee.ote.master.rest.test/src/org/eclipse/osee/ote/master/rest/test/ClientAPITest.java @@ -54,7 +54,7 @@ public class ClientAPITest { server.setName("test"); server.setStartTime(new Date().toString()); server.setType("oteserver"); - server.setUri("tcp://localhost:8998"); + server.setOteActivemqServer("tcp://localhost:8998"); return server; } diff --git a/plugins/org.eclipse.osee.ote.master.rest/src/org/eclipse/osee/ote/master/rest/internal/Util.java b/plugins/org.eclipse.osee.ote.master.rest/src/org/eclipse/osee/ote/master/rest/internal/Util.java index 86c27a553e7..eafaaf6c353 100644 --- a/plugins/org.eclipse.osee.ote.master.rest/src/org/eclipse/osee/ote/master/rest/internal/Util.java +++ b/plugins/org.eclipse.osee.ote.master.rest/src/org/eclipse/osee/ote/master/rest/internal/Util.java @@ -17,20 +17,34 @@ class Util { static OTEServer convert(OTELookupServerEntry entry){ OTEServer server = new OTEServer(); + server.setComment(entry.getComment()); + server.setConnectedUsers(entry.getConnectedUsers()); server.setName(entry.getName()); + server.setOteActivemqServer(entry.getOteActivemqServer().toString()); + server.setOteRestServer(entry.getOteRestServer().toString()); + server.setOwner(entry.getOwner()); server.setStartTime(entry.getStartTime().toString()); server.setType(entry.getType().getName()); - server.setUri(entry.getURI().toString()); + server.setStation(entry.getStation()); + server.setUUID(entry.getUUID().toString()); + server.setVersion(entry.getVersion()); return server; } public static OTELookupServerEntry convert(OTEServer server) throws ParseException, URISyntaxException { UUID uuid = UUID.fromString(server.getUUID()); - URI uri = new URI(server.getUri()); + URI uri = new URI(server.getOteActivemqServer()); DateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); Date date = df.parse(server.getStartTime()); OTELookupServerEntry entry = new OTELookupServerEntry(uuid, uri, server.getName(), new OTEServerTypeGeneric(server.getType()) ,date); + entry.setComment(server.getComment()); + entry.setConnectedUsers(server.getConnectedUsers()); + entry.setOteActivemqServer(new URI(server.getOteActivemqServer())); + entry.setOteRestServer(new URI(server.getOteRestServer())); + entry.setOwner(server.getOwner()); + entry.setStation(server.getStation()); + entry.setVersion(server.getVersion()); return entry; } diff --git a/plugins/org.eclipse.osee.ote.master/src/org/eclipse/osee/ote/master/OTELookupServerEntry.java b/plugins/org.eclipse.osee.ote.master/src/org/eclipse/osee/ote/master/OTELookupServerEntry.java index c3004d598bd..60e32ff81d9 100644 --- a/plugins/org.eclipse.osee.ote.master/src/org/eclipse/osee/ote/master/OTELookupServerEntry.java +++ b/plugins/org.eclipse.osee.ote.master/src/org/eclipse/osee/ote/master/OTELookupServerEntry.java @@ -7,19 +7,25 @@ import java.util.UUID; public class OTELookupServerEntry { private final UUID uuid; - private final String name; - private final Date startTime; private final OTEServerType type; - private final URI uri; + private final Date startTime; + private final String name; + private String station; + private String version; + private String comment; + private String owner; + private URI oteRestServer; + private URI oteActivemqServer; + private String connectedUsers; private Date lastUpdate; - public OTELookupServerEntry(UUID uuid, URI uri, String name, OTEServerType type, Date startTime) { + public OTELookupServerEntry(UUID uuid, URI oteActivemqServer, String name, OTEServerType type, Date startTime) { this.name = name; this.uuid = uuid; this.startTime = startTime; this.type = type; - this.uri = uri; + this.oteActivemqServer = oteActivemqServer; } public UUID getUUID() { @@ -39,7 +45,7 @@ public class OTELookupServerEntry { } public URI getURI() { - return uri; + return oteActivemqServer; } @Override @@ -49,7 +55,7 @@ public class OTELookupServerEntry { result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((startTime == null) ? 0 : startTime.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode()); - result = prime * result + ((uri == null) ? 0 : uri.hashCode()); + result = prime * result + ((oteActivemqServer == null) ? 0 : oteActivemqServer.hashCode()); result = prime * result + ((uuid == null) ? 0 : uuid.hashCode()); return result; } @@ -78,10 +84,10 @@ public class OTELookupServerEntry { return false; } else if (!type.getName().equals(other.type.getName())) return false; - if (uri == null) { - if (other.uri != null) + if (oteActivemqServer == null) { + if (other.oteActivemqServer != null) return false; - } else if (!uri.equals(other.uri)) + } else if (!oteActivemqServer.equals(other.oteActivemqServer)) return false; if (uuid == null) { if (other.uuid != null) @@ -98,4 +104,72 @@ public class OTELookupServerEntry { synchronized public Date getUpdateTime() { return lastUpdate; } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public URI getOteRestServer() { + return oteRestServer; + } + + public void setOteRestServer(URI oteRestServer) { + this.oteRestServer = oteRestServer; + } + + public URI getOteActivemqServer() { + return oteActivemqServer; + } + + public void setOteActivemqServer(URI oteActivemqServer) { + this.oteActivemqServer = oteActivemqServer; + } + + public String getConnectedUsers() { + return connectedUsers; + } + + public void setConnectedUsers(String connectedUsers) { + this.connectedUsers = connectedUsers; + } + + public Date getLastUpdate() { + return lastUpdate; + } + + public void setLastUpdate(Date lastUpdate) { + this.lastUpdate = lastUpdate; + } + + public UUID getUuid() { + return uuid; + } } diff --git a/plugins/org.eclipse.osee.ote.master/src/org/eclipse/osee/ote/master/internal/OTELookupImpl.java b/plugins/org.eclipse.osee.ote.master/src/org/eclipse/osee/ote/master/internal/OTELookupImpl.java index 8e86bc11a92..b1360fd67f5 100644 --- a/plugins/org.eclipse.osee.ote.master/src/org/eclipse/osee/ote/master/internal/OTELookupImpl.java +++ b/plugins/org.eclipse.osee.ote.master/src/org/eclipse/osee/ote/master/internal/OTELookupImpl.java @@ -36,6 +36,7 @@ public class OTELookupImpl implements OTELookup { server.setUpdateTime(new Date()); servers.add(server); } else { + oldone.setConnectedUsers(server.getConnectedUsers()); oldone.setUpdateTime(new Date()); } } diff --git a/plugins/org.eclipse.osee.ote.server/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.server/META-INF/MANIFEST.MF index 7a08d9f762d..30255a02104 100644 --- a/plugins/org.eclipse.osee.ote.server/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.ote.server/META-INF/MANIFEST.MF @@ -30,6 +30,8 @@ Import-Package: org.apache.felix.service.command;status=provisional;version="0.8 org.eclipse.osee.ote.core.environment.status, org.eclipse.osee.ote.core.framework.command, org.eclipse.osee.ote.core.model, + org.eclipse.osee.ote.master.rest.client, + org.eclipse.osee.ote.master.rest.model, org.eclipse.osee.ote.message, org.eclipse.osee.ote.message.instrumentation, org.eclipse.osee.ote.message.interfaces, diff --git a/plugins/org.eclipse.osee.ote.server/OSGI-INF/ote.service.starter.xml b/plugins/org.eclipse.osee.ote.server/OSGI-INF/ote.service.starter.xml index 1cca896448d..693734b9064 100644 --- a/plugins/org.eclipse.osee.ote.server/OSGI-INF/ote.service.starter.xml +++ b/plugins/org.eclipse.osee.ote.server/OSGI-INF/ote.service.starter.xml @@ -10,4 +10,5 @@ <reference unbind="unbindIConnectionService" bind="bindIConnectionService" cardinality="1..1" interface="org.eclipse.osee.connection.service.IConnectionService" name="IConnectionService" policy="static"/> <reference unbind="unbindPackageAdmin" bind="bindPackageAdmin" cardinality="1..1" interface="org.osgi.service.packageadmin.PackageAdmin" name="PackageAdmin" policy="static"/> <reference bind="bindOTESessionManager" cardinality="1..1" interface="org.eclipse.osee.ote.core.OTESessionManager" name="OTESessionManager" policy="static" unbind="unbindOTESessionManager"/> + <reference bind="bindOTEMasterServer" cardinality="1..1" interface="org.eclipse.osee.ote.master.rest.client.OTEMasterServer" name="OTEMasterServer" policy="static" unbind="unbindOTEMasterServer"/> </scr:component> diff --git a/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteServiceStarterImpl.java b/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteServiceStarterImpl.java index 1c51d2cbf68..fb05ac83646 100644 --- a/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteServiceStarterImpl.java +++ b/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteServiceStarterImpl.java @@ -19,9 +19,15 @@ import java.net.InetAddress; import java.net.URI; import java.net.UnknownHostException; import java.rmi.RemoteException; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import org.apache.activemq.broker.BrokerService; @@ -45,6 +51,8 @@ import org.eclipse.osee.ote.core.OteBaseMessages; import org.eclipse.osee.ote.core.environment.interfaces.IHostTestEnvironment; import org.eclipse.osee.ote.core.environment.interfaces.IRuntimeLibraryManager; import org.eclipse.osee.ote.core.environment.interfaces.ITestEnvironmentServiceConfig; +import org.eclipse.osee.ote.master.rest.client.OTEMasterServer; +import org.eclipse.osee.ote.master.rest.model.OTEServer; import org.eclipse.osee.ote.server.OteServiceStarter; import org.eclipse.osee.ote.server.PropertyParamter; import org.eclipse.osee.ote.server.TestEnvironmentFactory; @@ -68,8 +76,30 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu private IServiceConnector serviceSideConnector; private OTESessionManager oteSessions; + private OTEMasterServer masterServer; + + private ScheduledExecutorService executor; + private OTEServer oteServerEntry; + private ScheduledFuture<?> taskToCancel; + private LookupRegistration lookupRegistration; + private URI masterURI; + private NodeInfo nodeInfo; + + public OteServiceStarterImpl() { + listenForHostRequest = new ListenForHostRequest(); + executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory(){ + + @Override + public Thread newThread(Runnable arg0) { + Thread th = new Thread(arg0); + th.setName("OTE Lookup Registration"); + th.setDaemon(true); + return th; + } + + }); + } - public void bindOTESessionManager(OTESessionManager oteSessions){ this.oteSessions = oteSessions; } @@ -109,7 +139,15 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu public void unbindIConnectionService(IConnectionService connectionService){ this.connectionService = null; } - + + public void bindOTEMasterServer(OTEMasterServer masterServer){ + this.masterServer = masterServer; + } + + public void unbindOTEMasterServer(OTEMasterServer masterServer){ + this.masterServer = null; + } + public void bindPackageAdmin(PackageAdmin packageAdmin){ this.packageAdmin = packageAdmin; } @@ -118,10 +156,6 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu this.packageAdmin = null; } - public OteServiceStarterImpl() { - listenForHostRequest = new ListenForHostRequest(); - } - @Override public IHostTestEnvironment start(IServiceConnector serviceSideConnector, ITestEnvironmentServiceConfig config, PropertyParamter propertyParameter, String environmentFactoryClass) throws Exception { return start(serviceSideConnector, config, propertyParameter, null, environmentFactoryClass); @@ -164,7 +198,7 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu brokerService.start(); URI uri = new URI(strUri); - NodeInfo nodeInfo = new NodeInfo("OTEEmbeddedBroker", uri); + nodeInfo = new NodeInfo("OTEEmbeddedBroker", uri); EnvironmentCreationParameter environmentCreationParameter = new EnvironmentCreationParameter(runtimeLibraryManager, nodeInfo, serviceSideConnector, config, factory, @@ -180,9 +214,23 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu connectionService.addConnector(serviceSideConnector); } if (!propertyParameter.isLocalConnector()) { - messageService.get(nodeInfo).subscribe(OteBaseMessages.RequestOteHost, listenForHostRequest, this); - RegisteredServiceReference ref = remoteServiceRegistrar.registerService("osee.ote.server", "1.0", service.getServiceID().toString(), uri, this, 60 * 3); - service.set(ref); + String masterURIStr = System.getProperty("ote.master.uri"); + if(masterURIStr != null){ + try{ + messageService.get(nodeInfo).subscribe(OteBaseMessages.RequestOteHost, listenForHostRequest, this); + masterURI = new URI(masterURIStr); + oteServerEntry = createOTEServer(nodeInfo, environmentCreationParameter, propertyParameter, service.getServiceID().toString()); + lookupRegistration = new LookupRegistration(masterURI, masterServer, oteServerEntry, service); + taskToCancel = executor.scheduleAtFixedRate(lookupRegistration, 0, 30, TimeUnit.SECONDS); + } catch(Throwable th){ + OseeLog.log(getClass(), Level.SEVERE, th); + } + } else { //user old lookup + messageService.get(nodeInfo).subscribe(OteBaseMessages.RequestOteHost, listenForHostRequest, this); + RegisteredServiceReference ref = remoteServiceRegistrar.registerService("osee.ote.server", "1.0", service.getServiceID().toString(), uri, this, 60 * 3); + service.set(ref); + } + } else { serviceSideConnector.setProperty("OTEEmbeddedBroker", nodeInfo); } @@ -191,6 +239,21 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu return service; } + + private OTEServer createOTEServer(NodeInfo nodeInfo, EnvironmentCreationParameter environmentCreationParameter, PropertyParamter propertyParameter, String uuid) throws NumberFormatException, UnknownHostException{ + OTEServer server = new OTEServer(); + server.setName(environmentCreationParameter.getServerTitle().toString()); + server.setStation(propertyParameter.getStation()); + server.setVersion(propertyParameter.getVersion()); + server.setType(propertyParameter.getType()); + server.setComment(propertyParameter.getComment()); + server.setStartTime(new Date().toString()); + server.setOwner(System.getProperty("user.name")); + server.setUUID(uuid); + server.setOteRestServer(String.format("http://%s:%s", InetAddress.getLocalHost().getHostAddress(), Integer.parseInt(System.getProperty("org.osgi.service.http.port")))); + server.setOteActivemqServer(nodeInfo.getUri().toString()); + return server; + } private int getServerPort() throws IOException { String portFromLaunch = System.getProperty("ote.server.broker.uri.port"); @@ -209,6 +272,15 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu @Override public void stop() { + if(messageService != null && nodeInfo != null){ + try { + messageService.get(nodeInfo).send(OteBaseMessages.OteHostShutdown, service.getServiceID().toString()); + } catch (OseeCoreException e) { + OseeLog.log(getClass(), Level.SEVERE, e); + } catch (RemoteException e) { + OseeLog.log(getClass(), Level.SEVERE, e); + } + } if (service != null) { try { service.updateDynamicInfo(); @@ -231,7 +303,11 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu OseeLog.log(getClass(), Level.SEVERE, ex); } } - service = null; + if(oteServerEntry != null) { + lookupRegistration.stop(); + taskToCancel.cancel(true); + masterServer.removeServer(masterURI, oteServerEntry); + } brokerService = null; } @@ -291,5 +367,38 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu @Override public void success() { } + + private static class LookupRegistration implements Runnable { + + private OTEMasterServer masterServer; + private OTEServer server; + private URI uri; + private volatile boolean run = true; + private OteService service; + + public LookupRegistration(URI uri, OTEMasterServer masterServer, OTEServer server, OteService service) { + this.masterServer = masterServer; + this.server = server; + this.uri = uri; + this.service = service; + } + + @Override + public void run() { + try{ + if(run){ + server.setConnectedUsers(service.getProperties().getProperty("user_list", "N.A.").toString()); + masterServer.addServer(uri, server); + } + } catch (Throwable th){ + th.printStackTrace(); + } + } + + public void stop(){ + run = false; + } + + } } |