Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote')
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServer.java12
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerAvailableNodes.java27
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerResult.java21
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/AddServer.java38
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/GetAvailableServers.java38
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/MasterServerCallable.java9
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/OTEMasterServerImpl.java65
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/RemoveServer.java38
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProvider.java24
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProviderImpl.java58
10 files changed, 330 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServer.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServer.java
new file mode 100644
index 00000000000..3ef9077bc91
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServer.java
@@ -0,0 +1,12 @@
+package org.eclipse.osee.ote.master.rest.client;
+
+import java.net.URI;
+import java.util.concurrent.Future;
+
+import org.eclipse.osee.ote.master.rest.model.OTEServer;
+
+public interface OTEMasterServer {
+ Future<OTEMasterServerAvailableNodes> getAvailableServers(URI uri);
+ Future<OTEMasterServerResult> addServer(URI uri, OTEServer server);
+ Future<OTEMasterServerResult> removeServer(URI uri, OTEServer server);
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerAvailableNodes.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerAvailableNodes.java
new file mode 100644
index 00000000000..1909e9ac103
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerAvailableNodes.java
@@ -0,0 +1,27 @@
+package org.eclipse.osee.ote.master.rest.client;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.osee.ote.master.rest.model.OTEServer;
+
+public class OTEMasterServerAvailableNodes extends OTEMasterServerResult {
+
+ private List<OTEServer> oteServers;
+
+ public OTEMasterServerAvailableNodes(){
+ oteServers = new ArrayList<OTEServer>();
+ }
+
+ public List<OTEServer> getServers(){
+ return oteServers;
+ }
+
+ public void setServers(OTEServer[] servers) {
+ oteServers.clear();
+ for(OTEServer server:servers){
+ oteServers.add(server);
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerResult.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerResult.java
new file mode 100644
index 00000000000..df14451b74e
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerResult.java
@@ -0,0 +1,21 @@
+package org.eclipse.osee.ote.master.rest.client;
+
+public class OTEMasterServerResult {
+
+ private Throwable th = null;
+ private boolean success = true;
+
+ public Throwable getThrowable() {
+ return th;
+ }
+ public void setThrowable(Throwable th) {
+ this.th = th;
+ }
+ public boolean isSuccess() {
+ return success;
+ }
+ public void setSuccess(boolean success) {
+ this.success = success;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/AddServer.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/AddServer.java
new file mode 100644
index 00000000000..6450e618375
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/AddServer.java
@@ -0,0 +1,38 @@
+package org.eclipse.osee.ote.master.rest.client.internal;
+
+import java.net.URI;
+import java.util.concurrent.Callable;
+
+import javax.ws.rs.core.MediaType;
+
+import org.eclipse.osee.ote.master.rest.client.OTEMasterServerResult;
+import org.eclipse.osee.ote.master.rest.model.OTEServer;
+
+import com.sun.jersey.api.client.WebResource;
+
+public class AddServer implements Callable<OTEMasterServerResult> {
+
+ private WebClientProvider webClientProvider;
+ private OTEServer server;
+ private URI uri;
+
+ public AddServer(WebClientProvider webClientProvider, URI uri, OTEServer server) {
+ this.webClientProvider = webClientProvider;
+ this.uri = uri;
+ this.server = server;
+ }
+
+ @Override
+ public OTEMasterServerResult call() throws Exception {
+ OTEMasterServerResult result = new OTEMasterServerResult();
+ try{
+ WebResource resource = webClientProvider.createResource(uri);
+ resource.path(OTEMasterServerImpl.CONTEXT_NAME).path(OTEMasterServerImpl.CONTEXT_SERVERS).accept(MediaType.APPLICATION_XML).post(server);
+ } catch (Throwable th){
+ result.setSuccess(false);
+ result.setThrowable(th);
+ }
+ return result;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/GetAvailableServers.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/GetAvailableServers.java
new file mode 100644
index 00000000000..0ef39942cab
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/GetAvailableServers.java
@@ -0,0 +1,38 @@
+package org.eclipse.osee.ote.master.rest.client.internal;
+
+import java.net.URI;
+import java.util.concurrent.Callable;
+
+import javax.ws.rs.core.MediaType;
+
+import org.eclipse.osee.ote.master.rest.client.OTEMasterServerAvailableNodes;
+import org.eclipse.osee.ote.master.rest.model.OTEServer;
+
+import com.sun.jersey.api.client.WebResource;
+
+public class GetAvailableServers implements Callable<OTEMasterServerAvailableNodes> {
+
+ private WebClientProvider webClientProvider;
+ private URI uri;
+
+ public GetAvailableServers(WebClientProvider webClientProvider, URI uri) {
+ this.webClientProvider = webClientProvider;
+ this.uri = uri;
+ }
+
+ @Override
+ public OTEMasterServerAvailableNodes call() throws Exception {
+ OTEMasterServerAvailableNodes result = new OTEMasterServerAvailableNodes();
+ try{
+ WebResource resource = webClientProvider.createResource(uri);
+ OTEServer[] servers = resource.path(OTEMasterServerImpl.CONTEXT_NAME).path(OTEMasterServerImpl.CONTEXT_SERVERS).accept(MediaType.APPLICATION_XML).get(OTEServer[].class);
+ result.setServers(servers);
+ result.setSuccess(true);
+ } catch (Throwable th){
+ result.setSuccess(false);
+ result.setThrowable(th);
+ }
+ return result;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/MasterServerCallable.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/MasterServerCallable.java
new file mode 100644
index 00000000000..49a65bb364a
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/MasterServerCallable.java
@@ -0,0 +1,9 @@
+package org.eclipse.osee.ote.master.rest.client.internal;
+
+import java.util.concurrent.Callable;
+
+public abstract class MasterServerCallable<V> implements Callable<V> {
+
+
+
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/OTEMasterServerImpl.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/OTEMasterServerImpl.java
new file mode 100644
index 00000000000..533201e202a
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/OTEMasterServerImpl.java
@@ -0,0 +1,65 @@
+package org.eclipse.osee.ote.master.rest.client.internal;
+
+import java.net.URI;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ThreadFactory;
+
+import org.eclipse.osee.ote.master.rest.client.OTEMasterServer;
+import org.eclipse.osee.ote.master.rest.client.OTEMasterServerAvailableNodes;
+import org.eclipse.osee.ote.master.rest.client.OTEMasterServerResult;
+import org.eclipse.osee.ote.master.rest.model.OTEServer;
+
+public class OTEMasterServerImpl implements OTEMasterServer {
+
+ static final String CONTEXT_NAME = "otemaster";
+ static final String CONTEXT_SERVERS = "servers";
+
+ private WebClientProvider webClientProvider;
+ private ExecutorService executor;
+
+ public OTEMasterServerImpl(){
+ executor = Executors.newCachedThreadPool(new ThreadFactory(){
+ @Override
+ public Thread newThread(Runnable arg0) {
+ Thread th = new Thread(arg0);
+ th.setName("OTE Master Client " + th.getId());
+ th.setDaemon(true);
+ return th;
+ }
+ });
+ }
+
+ public void start(){
+
+ }
+
+ public void stop(){
+
+ }
+
+ public void bindWebClientProvider(WebClientProvider webClientProvider){
+ this.webClientProvider = webClientProvider;
+ }
+
+ public void unbindWebClientProvider(WebClientProvider webClientProvider){
+ this.webClientProvider = null;
+ }
+
+ @Override
+ public Future<OTEMasterServerAvailableNodes> getAvailableServers(URI uri) {
+ return executor.submit(new GetAvailableServers(webClientProvider, uri));
+ }
+
+ @Override
+ public Future<OTEMasterServerResult> addServer(URI uri, OTEServer server) {
+ return executor.submit(new AddServer(webClientProvider, uri, server));
+ }
+
+ @Override
+ public Future<OTEMasterServerResult> removeServer(URI uri, OTEServer server) {
+ return executor.submit(new RemoveServer(webClientProvider, uri, server));
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/RemoveServer.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/RemoveServer.java
new file mode 100644
index 00000000000..f087640a594
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/RemoveServer.java
@@ -0,0 +1,38 @@
+package org.eclipse.osee.ote.master.rest.client.internal;
+
+import java.net.URI;
+import java.util.concurrent.Callable;
+
+import javax.ws.rs.core.MediaType;
+
+import org.eclipse.osee.ote.master.rest.client.OTEMasterServerResult;
+import org.eclipse.osee.ote.master.rest.model.OTEServer;
+
+import com.sun.jersey.api.client.WebResource;
+
+public class RemoveServer implements Callable<OTEMasterServerResult> {
+
+ private WebClientProvider webClientProvider;
+ private OTEServer server;
+ private URI uri;
+
+ public RemoveServer(WebClientProvider webClientProvider, URI uri, OTEServer server) {
+ this.webClientProvider = webClientProvider;
+ this.uri = uri;
+ this.server = server;
+ }
+
+ @Override
+ public OTEMasterServerResult call() throws Exception {
+ OTEMasterServerResult result = new OTEMasterServerResult();
+ try{
+ WebResource resource = webClientProvider.createResource(uri);
+ resource.path(OTEMasterServerImpl.CONTEXT_NAME).path(OTEMasterServerImpl.CONTEXT_SERVERS).accept(MediaType.APPLICATION_XML).delete(server);
+ } catch (Throwable th){
+ result.setSuccess(false);
+ result.setThrowable(th);
+ }
+ return result;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProvider.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProvider.java
new file mode 100644
index 00000000000..65c40e8475b
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProvider.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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.ote.master.rest.client.internal;
+
+import java.net.URI;
+
+import com.sun.jersey.api.client.AsyncWebResource;
+import com.sun.jersey.api.client.WebResource;
+
+public interface WebClientProvider {
+
+ WebResource createResource(URI uri) throws Exception;
+
+ AsyncWebResource createAsyncResource(URI uri) throws Exception;
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProviderImpl.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProviderImpl.java
new file mode 100644
index 00000000000..8f7fbf77c99
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProviderImpl.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * 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.ote.master.rest.client.internal;
+
+import java.net.URI;
+import java.util.Map;
+
+import com.sun.jersey.api.client.AsyncWebResource;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.client.apache.ApacheHttpClient;
+import com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig;
+
+public class WebClientProviderImpl implements WebClientProvider {
+
+ private Client client;
+
+ public void start() {
+
+ }
+
+ public void stop() {
+ }
+
+ @Override
+ public WebResource createResource(URI uri) {
+ Client client = createClient(uri);
+ return client.resource(uri);
+ }
+
+ @Override
+ public AsyncWebResource createAsyncResource(URI uri) {
+ Client client = createClient(uri);
+ return client.asyncResource(uri);
+ }
+
+ private Client createClient(URI uri) {
+ if (client == null) {
+ DefaultApacheHttpClientConfig clientConfig = new DefaultApacheHttpClientConfig();
+ Map<String, Object> properties = clientConfig.getProperties();
+
+ properties.put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
+
+ client = ApacheHttpClient.create(clientConfig);
+ }
+ return client;
+ }
+
+} \ No newline at end of file

Back to the top