diff options
author | Andrew M Finkbeiner | 2013-03-21 21:46:56 +0000 |
---|---|---|
committer | donald.g.dunne | 2013-03-27 19:21:42 +0000 |
commit | efc2a587ad3585880e35a65b446ecafc122955de (patch) | |
tree | 652aeb6e81072aaf5eb5ffa2fce60fcc2f37097d /plugins/org.eclipse.osee.ote.rest.client | |
parent | 44f4e9a833acf2a2571d96cd856857cf65f0713e (diff) | |
download | org.eclipse.osee-efc2a587ad3585880e35a65b446ecafc122955de.tar.gz org.eclipse.osee-efc2a587ad3585880e35a65b446ecafc122955de.tar.xz org.eclipse.osee-efc2a587ad3585880e35a65b446ecafc122955de.zip |
feature[ats_5Z6FP]: Fix up some of the rest API
Change-Id: Ide9db8324d4d7bcd7b21dbf4ca7f281d17df2f7c
Diffstat (limited to 'plugins/org.eclipse.osee.ote.rest.client')
11 files changed, 246 insertions, 21 deletions
diff --git a/plugins/org.eclipse.osee.ote.rest.client/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.rest.client/META-INF/MANIFEST.MF index 993a0749a79..d12826910f8 100644 --- a/plugins/org.eclipse.osee.ote.rest.client/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.ote.rest.client/META-INF/MANIFEST.MF @@ -14,7 +14,6 @@ Import-Package: javax.ws.rs, org.eclipse.osee.framework.core.enums, org.eclipse.osee.framework.core.exception, org.eclipse.osee.framework.core.operation, - org.eclipse.osee.framework.core.services, org.eclipse.osee.framework.core.util, org.eclipse.osee.framework.jdk.core.type, org.eclipse.osee.framework.jdk.core.util, diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/ConfigurationProgress.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/ConfigurationProgress.java new file mode 100644 index 00000000000..d103cb41815 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/ConfigurationProgress.java @@ -0,0 +1,5 @@ +package org.eclipse.osee.ote.rest.client; + +public interface ConfigurationProgress extends Progress { + +} diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/GetFileProgress.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/GetFileProgress.java new file mode 100644 index 00000000000..525f1e6a895 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/GetFileProgress.java @@ -0,0 +1,6 @@ +package org.eclipse.osee.ote.rest.client; + + +public interface GetFileProgress extends Progress { + +} diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/OteClient.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/OteClient.java index 763409295af..6a08ca68d86 100644 --- a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/OteClient.java +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/OteClient.java @@ -13,6 +13,7 @@ package org.eclipse.osee.ote.rest.client; import java.io.File; import java.net.URI; import java.util.List; +import java.util.concurrent.Future; import org.eclipse.core.runtime.jobs.Job; @@ -23,5 +24,7 @@ import org.eclipse.core.runtime.jobs.Job; public interface OteClient { Job configureServerEnvironment(URI uri, List<File> jars, final ConfigurationStatusCallback callback) ; - + + Future<GetFileProgress> getFile(URI uri, File destination, String filePath, final GetFileProgress progress); + Future<ConfigurationProgress> configureServerEnvironment(URI uri, List<File> jars, final ConfigurationProgress progress); } diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/Progress.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/Progress.java new file mode 100644 index 00000000000..095e40e0cd0 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/Progress.java @@ -0,0 +1,11 @@ +package org.eclipse.osee.ote.rest.client; + +public interface Progress { + + void fail(String string); + void fail(Throwable th); + + void setUnitsOfWork(int totalUnitsOfWork); + void setUnitsWorked(int unitsWorked); + void success(); +} diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/BaseClientCallable.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/BaseClientCallable.java new file mode 100644 index 00000000000..baaa2728fa2 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/BaseClientCallable.java @@ -0,0 +1,28 @@ +package org.eclipse.osee.ote.rest.client.internal; + +import java.util.concurrent.Callable; + +import org.eclipse.osee.ote.rest.client.Progress; + +public abstract class BaseClientCallable<T extends Progress> implements Callable<T>{ + + private T progress; + + public BaseClientCallable(T progress) { + this.progress = progress; + } + + @Override + final public T call() throws Exception { + try{ + doWork(); + progress.success(); + } catch (Throwable th){ + progress.fail(th); + } + return progress; + } + + public abstract void doWork() throws Exception; + +} diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/ConfigureOperation.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/ConfigureOperation.java index 83da69ee738..a86dea029b3 100644 --- a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/ConfigureOperation.java +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/ConfigureOperation.java @@ -124,7 +124,7 @@ public class ConfigureOperation extends AbstractOperation { OteConfigurationItem item = new OteConfigurationItem(); item.setBundleName(bundleInfo.getSymbolicName()); item.setBundleVersion(bundleInfo.getVersion()); - item.setLocationUrl(bundleInfo.getSystemLocation().toString()); + item.setLocationUrl(bundleInfo.getServerBundleLocation().toString()); item.setMd5Digest(bundleInfo.getMd5Digest()); configuration.addItem(item); } diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/ConfigureOteServerFile.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/ConfigureOteServerFile.java new file mode 100644 index 00000000000..386242a74b8 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/ConfigureOteServerFile.java @@ -0,0 +1,92 @@ +package org.eclipse.osee.ote.rest.client.internal; + +import java.io.File; +import java.net.InetAddress; +import java.net.URI; +import java.util.List; + +import javax.ws.rs.core.MediaType; + +import org.eclipse.osee.framework.core.util.Conditions; +import org.eclipse.osee.framework.jdk.core.util.network.PortUtil; +import org.eclipse.osee.ote.rest.client.ConfigurationProgress; +import org.eclipse.osee.ote.rest.client.internal.jarserver.BundleInfo; +import org.eclipse.osee.ote.rest.client.internal.jarserver.HeadlessClassServer; +import org.eclipse.osee.ote.rest.model.OteConfiguration; +import org.eclipse.osee.ote.rest.model.OteConfigurationIdentity; +import org.eclipse.osee.ote.rest.model.OteConfigurationItem; +import org.eclipse.osee.ote.rest.model.OteJobStatus; + +import com.sun.jersey.api.client.WebResource; + +public class ConfigureOteServerFile extends BaseClientCallable<ConfigurationProgress> { + + private static final long POLLING_RATE = 1000; + private URI uri; + private List<File> jars; + private ConfigurationProgress progress; + private WebResourceFactory factory; + private OteJobStatus status; + + public ConfigureOteServerFile(URI uri, List<File> jars, ConfigurationProgress progress, WebResourceFactory factory) { + super(progress); + this.uri = uri; + this.jars = jars; + this.progress = progress; + this.factory = factory; + } + + @Override + public void doWork() throws Exception { + Conditions.checkNotNull(uri, "uri"); + Conditions.checkNotNull(factory, "factory"); + Conditions.checkNotNullOrEmpty(jars, "jars"); + + status = sendBundleConfiguration(); + if(!status.isJobComplete()){ + waitForJobComplete(); + } + + if(!status.isSuccess()){ + throw new Exception("Failed to configure the environment: " + status.getErrorLog()); + } + } + + private void waitForJobComplete() throws Exception { + URI jobUri = status.getUpdatedJobStatus().toURI(); + final WebResource service = factory.createResource(jobUri); + + while(!status.isJobComplete()){ + Thread.sleep(POLLING_RATE); + status = service.accept(MediaType.APPLICATION_XML).get(OteJobStatus.class); + } + } + + private OteJobStatus sendBundleConfiguration() throws Exception { + OteConfiguration configuration = new OteConfiguration(); + OteConfigurationIdentity identity = new OteConfigurationIdentity(); + identity.setName("test"); + configuration.setIdentity(identity); + HeadlessClassServer classServer = new HeadlessClassServer(PortUtil.getInstance().getValidPort(), InetAddress.getLocalHost(), jars); + for (BundleInfo bundleInfo : classServer.getBundles()) { + OteConfigurationItem item = new OteConfigurationItem(); + item.setBundleName(bundleInfo.getSymbolicName()); + item.setBundleVersion(bundleInfo.getVersion()); + item.setLocationUrl(bundleInfo.getSystemLocation().toString()); + item.setMd5Digest(bundleInfo.getMd5Digest()); + configuration.addItem(item); + } + WebResource baseService = factory.createResource(uri); + + OteConfiguration currentConfig = baseService.path("ote").path("config").accept(MediaType.APPLICATION_XML).get(OteConfiguration.class); + if(currentConfig.equals(configuration)){ + OteJobStatus status = new OteJobStatus(); + status.setSuccess(true); + status.setJobComplete(true); + return status; + } else { + return baseService.path("ote").path("config").accept(MediaType.APPLICATION_XML).post(OteJobStatus.class, configuration); + } + } + +} diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/GetOteServerFile.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/GetOteServerFile.java new file mode 100644 index 00000000000..18b372e4768 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/GetOteServerFile.java @@ -0,0 +1,51 @@ +package org.eclipse.osee.ote.rest.client.internal; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.net.URI; + +import javax.ws.rs.core.MediaType; + +import org.eclipse.osee.ote.rest.client.GetFileProgress; + +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; + +public class GetOteServerFile extends BaseClientCallable<GetFileProgress> { + + private URI uri; + private String filePath; + private GetFileProgress progress; + private WebResourceFactory factory; + private File destination; + + public GetOteServerFile(URI uri, File destination, String filePath, GetFileProgress progress, WebResourceFactory factory) { + super(progress); + this.uri = uri; + this.filePath = filePath; + this.progress = progress; + this.factory = factory; + this.destination = destination; + } + + @Override + public void doWork() throws Exception { + WebResource client = factory.createResource(uri); + ClientResponse response = client.queryParam("path", filePath).path("ote").path("file").accept(MediaType.APPLICATION_XML).get(ClientResponse.class); + if(response.getStatus() == ClientResponse.Status.OK.getStatusCode()){ + InputStream is = response.getEntityInputStream(); + FileOutputStream fos = new FileOutputStream(destination); + byte[] data = new byte[2048]; + int numRead = 0; + while((numRead = is.read(data)) != -1){ + fos.write(data, 0, numRead); + } + fos.flush(); + fos.close(); + } else { + throw new Exception(response.toString()); + } + } + +} diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/OteClientImpl.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/OteClientImpl.java index 28ccc6b0549..5faff4d702d 100644 --- a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/OteClientImpl.java +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/OteClientImpl.java @@ -13,6 +13,10 @@ package org.eclipse.osee.ote.rest.client.internal; import java.io.File; import java.net.URI; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.ThreadFactory; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.jobs.IJobChangeEvent; @@ -20,7 +24,9 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.osee.framework.core.operation.IOperation; import org.eclipse.osee.framework.core.operation.Operations; +import org.eclipse.osee.ote.rest.client.ConfigurationProgress; import org.eclipse.osee.ote.rest.client.ConfigurationStatusCallback; +import org.eclipse.osee.ote.rest.client.GetFileProgress; import org.eclipse.osee.ote.rest.client.OteClient; import com.sun.jersey.api.client.Client; @@ -43,6 +49,20 @@ public class OteClientImpl implements OteClient, WebResourceFactory { // public void setUriProvider(URIProvider uriProvider) { // this.uriProvider = uriProvider; // } + + private ExecutorService executor; + + public OteClientImpl(){ + executor = Executors.newCachedThreadPool(new ThreadFactory(){ + @Override + public Thread newThread(Runnable arg0) { + Thread th = new Thread(arg0); + th.setName("OTE Client " + th.getId()); + th.setDaemon(true); + return th; + } + }); + } public void start() { @@ -169,6 +189,16 @@ public class OteClientImpl implements OteClient, WebResourceFactory { return service; } + @Override + public Future<GetFileProgress> getFile(URI uri, File destination, String filePath, final GetFileProgress progress){ + return executor.submit(new GetOteServerFile(uri, destination, filePath, progress, this)); + } + + @Override + public Future<ConfigurationProgress> configureServerEnvironment(URI uri, List<File> jars, final ConfigurationProgress progress){ + return executor.submit(new ConfigureOteServerFile(uri, jars, progress, this)); + } + // @Override // public void configureServer(URI server, List<File> jarsToLoad, ConfigurationStatusCallback callback) { // // TODO Auto-generated method stub diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/main/Runner.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/main/Runner.java index 72b2fbcfbee..1395209f323 100644 --- a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/main/Runner.java +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/main/Runner.java @@ -3,22 +3,20 @@ package org.eclipse.osee.ote.rest.client.internal.main; import java.io.File; import java.io.IOException; import java.net.URI; -import java.util.ArrayList; -import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; import javax.ws.rs.core.UriBuilder; -import org.eclipse.core.runtime.jobs.Job; import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.operation.Operations; -import org.eclipse.osee.ote.rest.client.ConfigurationStatusCallback; +import org.eclipse.osee.ote.rest.client.GetFileProgress; import org.eclipse.osee.ote.rest.client.internal.OteClientImpl; public class Runner { - public static void main(String[] args) throws IOException, OseeCoreException { + public static void main(String[] args) throws IOException, OseeCoreException, InterruptedException, ExecutionException { - ConfigurationStatusCallback callback = new ConfigurationStatusCallback() { + GetFileProgress callback = new GetFileProgress() { private int total; @@ -30,6 +28,7 @@ public class Runner { @Override public void fail(Throwable th) { + System.out.println(th.getMessage()); th.printStackTrace(); } @@ -51,20 +50,21 @@ public class Runner { OteClientImpl imp = new OteClientImpl(); // imp.setUriProvider(new URIProviderImpl()); - List<File> folders = new ArrayList<File>(); - folders.add(new File("C:\\UserData\\CAx\\gitrepos\\ote\\lba\\usg\\no_rmi\\ote.lba.usg\\plugins\\ote.lba.usg.v4.p2\\target\\precompiled\\commonBundles")); - folders.add(new File("C:\\UserData\\CAx\\gitrepos\\ote\\lba\\usg\\no_rmi\\ote.lba.usg\\plugins\\ote.lba.usg.v4.p2\\target\\precompiled\\externalServerDependencies")); - folders.add(new File("C:\\UserData\\CAx\\gitrepos\\ote\\lba\\usg\\no_rmi\\ote.lba.usg\\plugins\\ote.lba.usg.v4.p2\\target\\precompiled\\runtimeLibs")); +// List<File> folders = new ArrayList<File>(); +// folders.add(new File("C:\\UserData\\CAx\\gitrepos\\ote\\lba\\usg\\no_rmi\\ote.lba.usg\\plugins\\ote.lba.usg.v4.p2\\target\\precompiled\\commonBundles")); +// folders.add(new File("C:\\UserData\\CAx\\gitrepos\\ote\\lba\\usg\\no_rmi\\ote.lba.usg\\plugins\\ote.lba.usg.v4.p2\\target\\precompiled\\externalServerDependencies")); +// folders.add(new File("C:\\UserData\\CAx\\gitrepos\\ote\\lba\\usg\\no_rmi\\ote.lba.usg\\plugins\\ote.lba.usg.v4.p2\\target\\precompiled\\runtimeLibs")); URI uri = UriBuilder.fromPath("http://localhost:8089").build(); - Job job = imp.configureServerEnvironment(uri, folders, callback); - try { - job.join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - Operations.checkForErrorStatus(job.getResult()); + Future<GetFileProgress> job = imp.getFile(uri, new File("test1"), "C:\\UserData\\AH-6\\AH6_X86_BUILDS\\fcc_main_x86_ote.exe1", callback); + Future<GetFileProgress> job1 = imp.getFile(uri, new File("test2"), "C:\\UserData\\AH-6\\AH6_X86_BUILDS\\fcc_main_x86_ote.exe", callback); + Future<GetFileProgress> job2 = imp.getFile(uri, new File("test3"), "C:\\UserData\\AH-6\\AH6_X86_BUILDS\\fcc_main_x86_ote.exe", callback); + Future<GetFileProgress> job3 = imp.getFile(uri, new File("test4"), "C:\\UserData\\AH-6\\AH6_X86_BUILDS\\fcc_main_x86_ote.exe", callback); + job.get(); + job1.get(); + job2.get(); + job3.get(); } } |