diff options
author | Andrew M Finkbeiner | 2013-03-18 23:42:34 +0000 |
---|---|---|
committer | donald.g.dunne | 2013-03-27 19:21:25 +0000 |
commit | b56832663141e952a02267c207cdb0cfa938fd45 (patch) | |
tree | 521966bc2389b44429e32ae48e7980b353d501b1 | |
parent | 36ce89dfbdb3148fb91239e151b07543ea599099 (diff) | |
download | org.eclipse.osee-b56832663141e952a02267c207cdb0cfa938fd45.tar.gz org.eclipse.osee-b56832663141e952a02267c207cdb0cfa938fd45.tar.xz org.eclipse.osee-b56832663141e952a02267c207cdb0cfa938fd45.zip |
feature[ats_5Z6FP]: Add OTE rest server
Change-Id: I231e42246e5134a0bfb191dfbedd1823b38a4692
47 files changed, 2122 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.ote.rest.client/.classpath b/plugins/org.eclipse.osee.ote.rest.client/.classpath new file mode 100644 index 00000000000..ad32c83a788 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/org.eclipse.osee.ote.rest.client/.project b/plugins/org.eclipse.osee.ote.rest.client/.project new file mode 100644 index 00000000000..8ed6bb71280 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/.project @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.osee.ote.rest.client</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ds.core.builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> 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 new file mode 100644 index 00000000000..993a0749a79 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/META-INF/MANIFEST.MF @@ -0,0 +1,29 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: OSEE OTE Rest Client (Incubation) +Bundle-SymbolicName: org.eclipse.osee.ote.rest.client +Bundle-Version: 0.11.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-Vendor: Eclipse Open System Engineering Environment +Service-Component: OSGI-INF/*.xml +Import-Package: javax.ws.rs, + javax.ws.rs.core, + org.apache.commons.lang.time, + org.eclipse.core.net.proxy, + org.eclipse.osee.framework.core.data, + 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, + org.eclipse.osee.framework.jdk.core.util.network, + org.eclipse.osee.framework.plugin.core.server +Export-Package: org.eclipse.osee.ote.rest.client +Bundle-ActivationPolicy: lazy +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.osee.ote.rest.model, + com.sun.jersey;bundle-version="1.8.0", + com.sun.jersey.client.apache;bundle-version="1.8.0", + javax.servlet diff --git a/plugins/org.eclipse.osee.ote.rest.client/OSGI-INF/ote.client.xml b/plugins/org.eclipse.osee.ote.rest.client/OSGI-INF/ote.client.xml new file mode 100644 index 00000000000..35d328b4059 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/OSGI-INF/ote.client.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" name="org.eclipse.osee.ote.rest.client.OteClient"> + <implementation class="org.eclipse.osee.ote.rest.client.internal.OteClientImpl"/> + <service> + <provide interface="org.eclipse.osee.ote.rest.client.OteClient"/> + </service> +</scr:component> diff --git a/plugins/org.eclipse.osee.ote.rest.client/OSGI-INF/web.client.provider.xml b/plugins/org.eclipse.osee.ote.rest.client/OSGI-INF/web.client.provider.xml new file mode 100644 index 00000000000..bd52d64fad1 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/OSGI-INF/web.client.provider.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" name="org.eclipse.osee.ote.rest.client.internal.WebClientProviderImpl"> + <implementation class="org.eclipse.osee.ote.rest.client.internal.WebClientProviderImpl"/> + <reference bind="setProxyService" cardinality="1..1" interface="org.eclipse.core.net.proxy.IProxyService" name="IProxyService" policy="static"/> + <service> + <provide interface="org.eclipse.osee.ote.rest.client.internal.WebClientProvider"/> + </service> +</scr:component> diff --git a/plugins/org.eclipse.osee.ote.rest.client/build.properties b/plugins/org.eclipse.osee.ote.rest.client/build.properties new file mode 100644 index 00000000000..5fc7ab483ae --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/build.properties @@ -0,0 +1,10 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/ +additional.bundles = org.eclipse.osee.framework.core,\ + org.eclipse.osee.framework.jdk.core,\ + org.eclipse.osee.framework.core.model,\ + org.apache.commons.lang,\ + javax.ws.rs diff --git a/plugins/org.eclipse.osee.ote.rest.client/pom.xml b/plugins/org.eclipse.osee.ote.rest.client/pom.xml new file mode 100644 index 00000000000..e4d4ed0b85d --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/pom.xml @@ -0,0 +1,35 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.eclipse.osee</groupId> + <artifactId>org.eclipse.osee.client.parent</artifactId> + <version>0.11.0-SNAPSHOT</version> + <relativePath>../../plugins/org.eclipse.osee.client.parent</relativePath> + </parent> + + <artifactId>org.eclipse.osee.ote.rest.client</artifactId> + <packaging>eclipse-plugin</packaging> + <name>OSEE OTE REST Client (Incubation)</name> + + <build> + <!-- workaround for https://issues.sonatype.org/browse/TYCHO-168 --> + <resources> + <resource> + <directory>src</directory> + <excludes> + <exclude>**/*.java</exclude> + </excludes> + </resource> + </resources> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-source-plugin</artifactId> + </plugin> + </plugins> + </build> + +</project>
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/ConfigurationStatusCallback.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/ConfigurationStatusCallback.java new file mode 100644 index 00000000000..e2db3ad8de8 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/ConfigurationStatusCallback.java @@ -0,0 +1,12 @@ +package org.eclipse.osee.ote.rest.client; + +public interface ConfigurationStatusCallback { + + 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/OteClient.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/OteClient.java new file mode 100644 index 00000000000..763409295af --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/OteClient.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * 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.rest.client; + +import java.io.File; +import java.net.URI; +import java.util.List; + +import org.eclipse.core.runtime.jobs.Job; + + +/** + * @author Andrew Finkbeiner + */ +public interface OteClient { + + Job configureServerEnvironment(URI uri, List<File> jars, final ConfigurationStatusCallback callback) ; + +} 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 new file mode 100644 index 00000000000..83da69ee738 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/ConfigureOperation.java @@ -0,0 +1,143 @@ +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.core.runtime.IProgressMonitor; +import org.eclipse.osee.framework.core.operation.AbstractOperation; +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.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 ConfigureOperation extends AbstractOperation { + + private static final String PLUGIN_ID = "org.eclipse.osee.ote.rest.client"; + + private static final long POLLING_RATE = 1000; + + private final WebResourceFactory factory; + private final URI uri; + private final List<File> jars; + + // Temps + private OteJobStatus status; +// private final Object lock = new Object(); + + public ConfigureOperation(WebResourceFactory factory, URI uri, List<File> jars) { + super("Configure Server", PLUGIN_ID); + this.factory = factory; + this.uri = uri; + this.jars = jars; + } + + @Override + protected void doWork(IProgressMonitor monitor) throws Exception { + Conditions.checkNotNull(uri, "uri"); + Conditions.checkNotNull(factory, "factory"); + Conditions.checkNotNullOrEmpty(jars, "jars"); + + status = sendBundleConfiguration(monitor, 0.20); + if(!status.isJobComplete()){ + waitForJobComplete(monitor, 0.80); + } + + if(!status.isSuccess()){ + throw new Exception("Failed to configure the environment: " + status.getErrorLog()); + } + } + + // Put on JobStatus + private long getEstimatedTotalTime(OteJobStatus jobStatus) { + return 1000 * 60; + } + + private long calculateConfigurationTicks(OteJobStatus jobStatus) { + return getEstimatedTotalTime(jobStatus) / (long) POLLING_RATE; + } + + private void waitForJobComplete(final IProgressMonitor monitor, double percent) throws Exception { + URI jobUri = status.getUpdatedJobStatus().toURI(); + + final WebResource service = factory.createResource(jobUri); + + double stepAmount = percent / (double) calculateConfigurationTicks(status); + final int amount = calculateWork(stepAmount); + +// Timer timer = new Timer(); +// timer.schedule(new TimerTask() { +// @Override +// public void run() { + boolean shouldCancel = false; + while(!shouldCancel){ + Thread.sleep(POLLING_RATE); + try { + checkForCancelledStatus(monitor); + + status = service.accept(MediaType.APPLICATION_XML).get(OteJobStatus.class); + if (status.isJobComplete()) { + shouldCancel = true; + } + } catch (Exception ex) { + ex.printStackTrace(); + shouldCancel = true; + } finally { + monitor.worked(amount); + } +// if (shouldCancel) { +// cancel(); +// synchronized (lock) { +// lock.notify(); +// } +// } + } +// }, POLLING_RATE); + +// if(!status.isJobComplete()){ +// synchronized (lock) { +// lock.wait(); +// } +// } +// if(!status.isSuccess()){ +// throw new Exception(status.getErrorLog()); +// } + } + + private OteJobStatus sendBundleConfiguration(IProgressMonitor monitor, double percent) 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()) { + checkForCancelledStatus(monitor); + 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/OteClientImpl.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/OteClientImpl.java new file mode 100644 index 00000000000..28ccc6b0549 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/OteClientImpl.java @@ -0,0 +1,178 @@ +/******************************************************************************* + * 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.rest.client.internal; + +import java.io.File; +import java.net.URI; +import java.util.List; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; +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.ConfigurationStatusCallback; +import org.eclipse.osee.ote.rest.client.OteClient; + +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.api.client.config.DefaultClientConfig; + +/** + * @author Andrew M. Finkbeiner + */ +public class OteClientImpl implements OteClient, WebResourceFactory { + +// private URIProvider uriProvider; +// private WebClientProvider clientProvider; +// +// public void setWebClientProvider(WebClientProvider clientProvider) { +// this.clientProvider = clientProvider; +// } +// +// public void setUriProvider(URIProvider uriProvider) { +// this.uriProvider = uriProvider; +// } + + public void start() { + + } + + public void stop() { + } + + public Job configureServerEnvironment(URI uri, List<File> jars, final ConfigurationStatusCallback callback) { + IOperation operation = new ConfigureOperation(this, uri, jars); + Job job = Operations.executeAsJob(operation, true, Job.LONG, new JobChangeAdapter() { + @Override + public void aboutToRun(IJobChangeEvent event) { + super.aboutToRun(event); + } + + @Override + public void running(IJobChangeEvent event) { + super.running(event); + } + + @Override + public void done(IJobChangeEvent event) { + super.done(event); + IStatus status = event.getResult(); + if (status.isOK()) { + callback.success(); + } else { + if(status.getException() != null){ + callback.fail(status.getException()); + } + if(status.getMessage() != null) { + callback.fail(status.getMessage()); + } + } + } + + }); + return job; + } + +// @Override +// public void configureServer(URI uri, List<File> jars, ConfigurationStatusCallback callback) { +// OteConfiguration configuration = new OteConfiguration(); +// OteConfigurationIdentity identity = new OteConfigurationIdentity(); +// identity.setName("test"); +// configuration.setIdentity(identity); +// try { +// HeadlessClassServer classServer = new +// HeadlessClassServer(PortUtil.getInstance().getValidPort(), +// InetAddress.getLocalHost(), jars); +// try { +// 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 = getWebResource(""); +// OteJobStatus response = +// baseService.path("ote").path("config").accept(MediaType.APPLICATION_XML).post(OteJobStatus.class, +// configuration); +// if (response != null) { +// +// WebResource service = +// getWebResource(UriBuilder.fromUri(response.getUpdatedJobStatus().toURI()).build()); +// +// OteJobStatus innerResponse = response; +// callback.setUnitsOfWork(response.getTotalUnitsOfWork()); +// while (innerResponse != null && !innerResponse.isJobComplete()) { +// Thread.sleep(100); +// innerResponse = +// service.accept(MediaType.APPLICATION_XML).get(OteJobStatus.class); +// if (innerResponse != null) { +// callback.setUnitsOfWork(innerResponse.getTotalUnitsOfWork()); +// callback.setUnitsWorked(innerResponse.getUnitsWorked()); +// } +// } +// if (innerResponse != null) { +// callback.setUnitsWorked(innerResponse.getUnitsWorked()); +// if (innerResponse.isSuccess()) { +// callback.success(); +// } else { +// callback.fail(innerResponse.getLog()); +// } +// } else { +// callback.fail("Unable to determine job status."); +// } +// } else { +// callback.fail("Unable to determine job status."); +// } +// } finally { +// classServer.stop(); +// } +// } catch (Throwable th) { +// callback.fail(th); +// } +// } + + // private WebResource getWebResource() { + // ClientConfig config = new DefaultClientConfig(); + // Client client = Client.create(config); + // WebResource service = + // client.resource(UriBuilder.fromUri("http://localhost:8089").build()); + // // uriProvider.getApplicationServerURI(); + // return service; + // } + // + // private WebResource getWebResource(URI uri) { + // ClientConfig config = new DefaultClientConfig(); + // Client client = Client.create(config); + // WebResource service = client.resource(uri); + // return service; + // } + + @Override + public WebResource createResource(URI uri) throws Exception { + ClientConfig config = new DefaultClientConfig(); + Client client = Client.create(config); + WebResource service = client.resource(uri); + return service; + } + +// @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/WebClientProvider.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/WebClientProvider.java new file mode 100644 index 00000000000..b0ce5cfb8f2 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/WebClientProvider.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * 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.rest.client.internal; + +import java.net.URI; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import com.sun.jersey.api.client.AsyncWebResource; +import com.sun.jersey.api.client.WebResource; + +/** + * @author John Misinco + * @author Roberto E. Escobar + */ +public interface WebClientProvider { + + WebResource createResource(URI uri) throws OseeCoreException; + + AsyncWebResource createAsyncResource(URI uri) throws OseeCoreException; + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/WebClientProviderImpl.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/WebClientProviderImpl.java new file mode 100644 index 00000000000..cab8a7f8695 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/WebClientProviderImpl.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * 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.rest.client.internal; + +import java.net.URI; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.eclipse.core.net.proxy.IProxyChangeEvent; +import org.eclipse.core.net.proxy.IProxyChangeListener; +import org.eclipse.core.net.proxy.IProxyData; +import org.eclipse.core.net.proxy.IProxyService; + +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; + +/** + * @author Roberto E. Escobar + */ +public class WebClientProviderImpl implements WebClientProvider { + + private Map<String, IProxyData[]> proxiedData; + private IProxyService proxyService; + private Client client; + + public void setProxyService(IProxyService proxyService) { + this.proxyService = proxyService; + } + + public void start() { + proxiedData = new ConcurrentHashMap<String, IProxyData[]>(); + proxyService.addProxyChangeListener(new IProxyChangeListener() { + @Override + public void proxyInfoChanged(IProxyChangeEvent event) { + proxiedData.clear(); + } + }); + } + + public void stop() { + if (proxiedData != null) { + proxiedData.clear(); + } + } + + @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); + +// configureProxyData(uri, properties); + client = ApacheHttpClient.create(clientConfig); + } + return client; + } + +// private void configureProxyData(URI uri, Map<String, Object> properties) { +// boolean proxyBypass = OseeProperties.getOseeProxyBypassEnabled(); +// if (!proxyBypass) { +// String key = String.format("%s_%s", uri.getScheme(), uri.getHost()); +// IProxyData[] datas = proxiedData.get(key); +// if (datas == null) { +// datas = proxyService.select(uri); +// proxiedData.put(key, datas); +// } +// +// for (IProxyData proxyData : datas) { +// String type = proxyData.getType(); +// if (Strings.isValid(type) && type.startsWith("HTTP")) { +// String proxyURL = +// String.format("%s://%s:%s", type.toLowerCase(), proxyData.getHost(), proxyData.getPort()); +// properties.put(ApacheHttpClientConfig.PROPERTY_PROXY_URI, proxyURL); +// } +// } +// } +// } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/WebResourceFactory.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/WebResourceFactory.java new file mode 100644 index 00000000000..d92981fb778 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/WebResourceFactory.java @@ -0,0 +1,11 @@ +package org.eclipse.osee.ote.rest.client.internal; + +import java.net.URI; + +import com.sun.jersey.api.client.WebResource; + +public interface WebResourceFactory { + + WebResource createResource(URI uri) throws Exception; + +} diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/jarserver/BundleInfo.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/jarserver/BundleInfo.java new file mode 100644 index 00000000000..829f0cf9c5c --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/jarserver/BundleInfo.java @@ -0,0 +1,172 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.rest.client.internal.jarserver; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URISyntaxException; +import java.net.URL; +import java.security.NoSuchAlgorithmException; +import java.util.jar.JarFile; +import java.util.jar.Manifest; + +import org.eclipse.osee.framework.jdk.core.util.ChecksumUtil; + +/** + * @author Robert A. Fisher + */ +public class BundleInfo { + private final String symbolicName; + private final String version; + private final URL systemLocation; + private final URL bundleServerLocation; + private final File file; + private final Manifest manifest; + private final boolean systemLibrary; + private String md5Digest; + + public BundleInfo(URL systemLocation, String bundleServerBaseLocation, boolean systemLibrary) throws IOException { + File tmpFile; + try { + tmpFile = new File(systemLocation.toURI()); + } catch (URISyntaxException ex) { + tmpFile = new File(systemLocation.getPath()); + } + this.file = tmpFile; + + JarFile jarFile = new JarFile(file); + this.manifest = jarFile.getManifest(); + this.symbolicName = generateBundleName(manifest); + this.version = manifest.getMainAttributes().getValue("Bundle-Version"); + + this.systemLocation = systemLocation; + this.bundleServerLocation = new URL(bundleServerBaseLocation + symbolicName); + this.systemLibrary = systemLibrary; + this.md5Digest = null; + } + + public BundleInfo(URL systemLocation) throws IOException { + File tmpFile; + try { + tmpFile = new File(systemLocation.toURI()); + } catch (URISyntaxException ex) { + tmpFile = new File(systemLocation.getPath()); + } + this.file = tmpFile; + + JarFile jarFile = new JarFile(file); + this.manifest = jarFile.getManifest(); + this.symbolicName = generateBundleName(manifest); + this.version = manifest.getMainAttributes().getValue("Bundle-Version"); + + this.systemLocation = systemLocation; + this.bundleServerLocation = systemLocation; + this.systemLibrary = true; + this.md5Digest = null; + } + + /** + * @return the name of the bundle + */ + public static String generateBundleName(Manifest jarManifest) { + String nameEntry = jarManifest.getMainAttributes().getValue("Bundle-SymbolicName"); + if(nameEntry == null){ + return "unknown"; + } + // Sometimes there's a semicolon then extra info - ignore this + int index = nameEntry.indexOf(';'); + if (index != -1) { + nameEntry = nameEntry.substring(0, index); + } + + return nameEntry; + } + + /** + * @return the symbolicName + */ + public String getSymbolicName() { + return symbolicName; + } + + /** + * @return the version + */ + public String getVersion() { + return version; + } + + /** + * @return the location + */ + public URL getSystemLocation() { + return systemLocation; + } + + /** + * @return the bundleServerLocation + */ + public URL getServerBundleLocation() { + return bundleServerLocation; + } + + /** + * @return the file + */ + public File getFile() { + return file; + } + + /** + * @return the manifest + */ + public Manifest getManifest() { + return manifest; + } + + @Override + public String toString() { + return getSymbolicName() + ":" + getVersion(); + } + + /** + * @return the systemLibrary + */ + public boolean isSystemLibrary() { + return systemLibrary; + } + + /** + * @return the md5Digest + */ + public String getMd5Digest() { + // Do lazy calculation of this since it can be costly + // and does not get read for all bundle info's + if (md5Digest == null) { + try { + InputStream in = systemLocation.openStream(); + + md5Digest = ChecksumUtil.createChecksumAsString(in, "MD5"); + + in.close(); + } catch (NoSuchAlgorithmException ex) { + throw new IllegalStateException("Always expect MD5 to be available", ex); + } catch (IOException ex) { + throw new IllegalStateException("Always expect local jar file to be available", ex); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return md5Digest; + } +} diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/jarserver/BundleResourceFinder.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/jarserver/BundleResourceFinder.java new file mode 100644 index 00000000000..716d76b9ca1 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/jarserver/BundleResourceFinder.java @@ -0,0 +1,32 @@ +package org.eclipse.osee.ote.rest.client.internal.jarserver; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.List; + +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.plugin.core.server.ResourceFinder; + +public class BundleResourceFinder extends ResourceFinder { + + private List<BundleInfo> bundleInfo; + + public BundleResourceFinder(List<BundleInfo> bundleInfo) { + super(); + this.bundleInfo = bundleInfo; + } + + @Override + public byte[] find(String path) throws IOException { + for (BundleInfo info : bundleInfo) { + if (info.getSymbolicName().equals(path)) { + return Lib.inputStreamToBytes(new FileInputStream(info.getFile())); + } + } + return null; + } + + @Override + public void dispose() { + } +} diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/jarserver/HeadlessClassServer.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/jarserver/HeadlessClassServer.java new file mode 100644 index 00000000000..05c68a43a86 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/jarserver/HeadlessClassServer.java @@ -0,0 +1,88 @@ +package org.eclipse.osee.ote.rest.client.internal.jarserver; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.osee.framework.plugin.core.server.ClassServer; + + + +public class HeadlessClassServer { + + private ClassServer classServer; + private List<BundleInfo> jars; + + public HeadlessClassServer(int port, InetAddress address, List<File> bundleFolders) throws IOException{ + Thread.currentThread().setName("BundleClassServer"); + classServer = new ClassServer(port, address); + jars = new ArrayList<BundleInfo>(); + for(File dir:bundleFolders){ + if(dir.exists() && dir.isDirectory()){ + findJarFiles(dir, jars); + } else if(dir.exists()){//it may be a jar + BundleInfo info = getBundleInfo(dir); + if(info != null){ + jars.add(info); + } + } + } + BundleResourceFinder bundleResourceFinder = new BundleResourceFinder(jars); + classServer.addResourceFinder(bundleResourceFinder); + classServer.start(); + + } + + public void stop(){ + classServer.terminate(); + } + + public List<BundleInfo> getBundles(){ + return jars; + } + + private void findJarFiles(File dir, final List<BundleInfo> jars) { + dir.listFiles(new FileFilter(){ + @Override + public boolean accept(File pathname) { + if(pathname.isDirectory()){ + findJarFiles(pathname, jars); + } else { + BundleInfo info = getBundleInfo(pathname); + if(info != null){ + jars.add(info); + } + } + return false; + } + }); + } + + private BundleInfo getBundleInfo(File file){ + BundleInfo bundleInfo = null; + try { + if(file.getAbsolutePath().endsWith(".jar")){ + bundleInfo = new BundleInfo(file.toURI().toURL(), getHostName().toExternalForm(), true); + if(bundleInfo.getSymbolicName() != null && !bundleInfo.getSymbolicName().equalsIgnoreCase("unknown") && bundleInfo.getVersion() != null){ + if(bundleInfo.getManifest() == null){ + bundleInfo = null; + } + } + } + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return bundleInfo; + } + + public URL getHostName(){ + return classServer.getHostName(); + } +} 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 new file mode 100644 index 00000000000..72b2fbcfbee --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/main/Runner.java @@ -0,0 +1,70 @@ +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 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.internal.OteClientImpl; + +public class Runner { + + public static void main(String[] args) throws IOException, OseeCoreException { + + ConfigurationStatusCallback callback = new ConfigurationStatusCallback() { + + private int total; + + @Override + public void fail(String string) { + System.out.println("fail: " + string); + + } + + @Override + public void fail(Throwable th) { + th.printStackTrace(); + } + + @Override + public void setUnitsOfWork(int totalUnitsOfWork) { + total = totalUnitsOfWork; + } + + @Override + public void setUnitsWorked(int unitsWorked) { + System.out.println(unitsWorked + " of " + total); + } + + @Override + public void success() { + System.out.println("success"); + } + }; + + 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")); + + 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()); + } + +} diff --git a/plugins/org.eclipse.osee.ote.rest.model/.classpath b/plugins/org.eclipse.osee.ote.rest.model/.classpath new file mode 100644 index 00000000000..ad32c83a788 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.model/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/org.eclipse.osee.ote.rest.model/.project b/plugins/org.eclipse.osee.ote.rest.model/.project new file mode 100644 index 00000000000..a8ae5b42c61 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.model/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.osee.ote.rest.model</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/plugins/org.eclipse.osee.ote.rest.model/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.rest.model/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..9ef62a149f3 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.model/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: OSEE OTE Rest Model (Incubation) +Bundle-SymbolicName: org.eclipse.osee.ote.rest.model +Bundle-Version: 0.11.0.qualifier +Bundle-Vendor: Eclipse Open System Engineering Environment +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Export-Package: org.eclipse.osee.ote.rest.model +Import-Package: javax.xml.bind.annotation, + org.eclipse.osee.framework.core.exception, + org.eclipse.osee.framework.core.util, + org.eclipse.osee.framework.jdk.core.util, + org.eclipse.osee.ote +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.osee.framework.core diff --git a/plugins/org.eclipse.osee.ote.rest.model/build.properties b/plugins/org.eclipse.osee.ote.rest.model/build.properties new file mode 100644 index 00000000000..e218306d004 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.model/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . +additional.bundles = org.eclipse.osee.framework.core,\ + org.eclipse.osee.framework.jdk.core diff --git a/plugins/org.eclipse.osee.ote.rest.model/pom.xml b/plugins/org.eclipse.osee.ote.rest.model/pom.xml new file mode 100644 index 00000000000..f2bbb56f345 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.model/pom.xml @@ -0,0 +1,34 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.eclipse.osee</groupId> + <artifactId>org.eclipse.osee.x.server.parent</artifactId> + <version>0.11.0-SNAPSHOT</version> + <relativePath>../../plugins/org.eclipse.osee.x.server.parent</relativePath> + </parent> + + <artifactId>org.eclipse.osee.ote.rest.model</artifactId> + <packaging>eclipse-plugin</packaging> + <name>OSEE OTE Rest Model - (Incubation)</name> + + <build> + <!-- workaround for https://issues.sonatype.org/browse/TYCHO-168 --> + <resources> + <resource> + <directory>src</directory> + <excludes> + <exclude>**/*.java</exclude> + </excludes> + </resource> + </resources> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-source-plugin</artifactId> + </plugin> + </plugins> + </build> +</project>
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.ote.rest.model/src/org/eclipse/osee/ote/rest/model/ExceptionEntity.java b/plugins/org.eclipse.osee.ote.rest.model/src/org/eclipse/osee/ote/rest/model/ExceptionEntity.java new file mode 100644 index 00000000000..86fed79dc10 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.model/src/org/eclipse/osee/ote/rest/model/ExceptionEntity.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2013 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.rest.model; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author John Misinco + */ +@XmlRootElement +public class ExceptionEntity { + + private String exceptionString; + + public ExceptionEntity(String exceptionString) { + this.exceptionString = exceptionString; + } + + public ExceptionEntity() { + // do nothing + } + + public String getExceptionString() { + return exceptionString; + } + + public void setExceptionString(String exceptionString) { + this.exceptionString = exceptionString; + } + +} diff --git a/plugins/org.eclipse.osee.ote.rest.model/src/org/eclipse/osee/ote/rest/model/OteConfiguration.java b/plugins/org.eclipse.osee.ote.rest.model/src/org/eclipse/osee/ote/rest/model/OteConfiguration.java new file mode 100644 index 00000000000..a6f3a186260 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.model/src/org/eclipse/osee/ote/rest/model/OteConfiguration.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * 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.rest.model; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + +import org.eclipse.osee.ote.OTEConfiguration; +import org.eclipse.osee.ote.OTEConfigurationItem; + +/** + * @author Andrew M. Finkbeiner + */ +@XmlRootElement +public class OteConfiguration { + + private OteConfigurationIdentity identity; + + private List<OteConfigurationItem> items; + + public OteConfiguration(){ + items = new ArrayList<OteConfigurationItem>(); + } + + public OteConfiguration(OTEConfiguration config){ + this(); + for(OTEConfigurationItem item:config.getItems()){ + OteConfigurationItem newitem = new OteConfigurationItem(); + newitem.setBundleName(item.getSymbolicName()); + newitem.setBundleVersion(item.getVersion()); + newitem.setLocationUrl(item.getLocationUrl()); + newitem.setMd5Digest(item.getMd5Digest()); + items.add(newitem); + } + } + + public OteConfigurationIdentity getIdentity(){ + return identity; + } + + @XmlElementWrapper + @XmlElement(name="OteConfigurationItem") + public List<OteConfigurationItem> getItems(){ + return items; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((identity == null) ? 0 : identity.hashCode()); + result = prime * result + ((items == null) ? 0 : items.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + OteConfiguration other = (OteConfiguration) obj; +// if (identity == null) { +// if (other.identity != null) +// return false; +// } else if (!identity.equals(other.identity)) +// return false; + if (items == null) { + if (other.items != null) + return false; + } else if (!items.equals(other.items)) + return false; + return true; + } + + public void setIdentity(OteConfigurationIdentity identity) { + this.identity = identity; + } + + public void addItem(OteConfigurationItem item){ + items.add(item); + } + + public OTEConfiguration translateToOtherConfig() { + OTEConfiguration config = new OTEConfiguration(); + for(OteConfigurationItem item:items){ + config.addItem(item.translateToOtherConfig()); + } + return config; + } + +} diff --git a/plugins/org.eclipse.osee.ote.rest.model/src/org/eclipse/osee/ote/rest/model/OteConfigurationIdentity.java b/plugins/org.eclipse.osee.ote.rest.model/src/org/eclipse/osee/ote/rest/model/OteConfigurationIdentity.java new file mode 100644 index 00000000000..d0ecf1562d6 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.model/src/org/eclipse/osee/ote/rest/model/OteConfigurationIdentity.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * 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.rest.model; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Roberto E. Escobar + */ +@XmlRootElement +public class OteConfigurationIdentity { + private String uuid; + private String name; + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/plugins/org.eclipse.osee.ote.rest.model/src/org/eclipse/osee/ote/rest/model/OteConfigurationItem.java b/plugins/org.eclipse.osee.ote.rest.model/src/org/eclipse/osee/ote/rest/model/OteConfigurationItem.java new file mode 100644 index 00000000000..63af7a583d3 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.model/src/org/eclipse/osee/ote/rest/model/OteConfigurationItem.java @@ -0,0 +1,92 @@ +package org.eclipse.osee.ote.rest.model; + +import javax.xml.bind.annotation.XmlRootElement; + +import org.eclipse.osee.ote.OTEConfigurationItem; + +@XmlRootElement +public class OteConfigurationItem { + + private String locationUrl; + private String md5Digest; + private String bundleVersion; + private String bundleName; + + public String getLocationUrl() { + return locationUrl; + } + public void setLocationUrl(String locationUrl) { + this.locationUrl = locationUrl; + } + public String getMd5Digest() { + return md5Digest; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((bundleName == null) ? 0 : bundleName.hashCode()); + result = prime * result + ((bundleVersion == null) ? 0 : bundleVersion.hashCode()); + result = prime * result + ((locationUrl == null) ? 0 : locationUrl.hashCode()); + result = prime * result + ((md5Digest == null) ? 0 : md5Digest.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + OteConfigurationItem other = (OteConfigurationItem) obj; + if (bundleName == null) { + if (other.bundleName != null) + return false; + } else if (!bundleName.equals(other.bundleName)) + return false; + if (bundleVersion == null) { + if (other.bundleVersion != null) + return false; + } else if (!bundleVersion.equals(other.bundleVersion)) + return false; + if (locationUrl == null) { + if (other.locationUrl != null) + return false; + } else if (!locationUrl.equals(other.locationUrl)) + return false; + if (md5Digest == null) { + if (other.md5Digest != null) + return false; + } else if (!md5Digest.equals(other.md5Digest)) + return false; + return true; + } + public void setMd5Digest(String md5Digest) { + this.md5Digest = md5Digest; + } + public String getBundleVersion() { + return bundleVersion; + } + public void setBundleVersion(String bundleVersion) { + this.bundleVersion = bundleVersion; + } + public String getBundleName() { + return bundleName; + } + public void setBundleName(String bundleName) { + this.bundleName = bundleName; + } + public String getSymbolicName() { + return bundleName; + } + public String getVersion() { + return bundleVersion; + } + public OTEConfigurationItem translateToOtherConfig() { + return new OTEConfigurationItem(locationUrl, bundleVersion, bundleName, md5Digest); + } + +} diff --git a/plugins/org.eclipse.osee.ote.rest.model/src/org/eclipse/osee/ote/rest/model/OteJobStatus.java b/plugins/org.eclipse.osee.ote.rest.model/src/org/eclipse/osee/ote/rest/model/OteJobStatus.java new file mode 100644 index 00000000000..62859ed50dd --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest.model/src/org/eclipse/osee/ote/rest/model/OteJobStatus.java @@ -0,0 +1,91 @@ +package org.eclipse.osee.ote.rest.model; + +import java.net.URL; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class OteJobStatus { + + private URL updatedJobStatus; + private String jobId; + + private int totalUnitsOfWork; + private int unitsWorked; + private String errorLog; + private boolean jobComplete; + private boolean success; + + public OteJobStatus(){ + errorLog = ""; + jobComplete = false; + success = true; + totalUnitsOfWork = 0; + unitsWorked = 0; + } + + public int getTotalUnitsOfWork() { + return totalUnitsOfWork; + } + + public int getUnitsWorked() { + return unitsWorked; + } + + public String getErrorLog() { + return errorLog; + } + + public boolean isJobComplete() { + return jobComplete; + } + + public void setTotalUnitsOfWork(int i) { + totalUnitsOfWork = i; + } + + public void jobComplete() { + jobComplete = true; + } + + public void incrememtUnitsWorked() { + unitsWorked++; + } + + public void setUnitsWorked(int unitsWorked) { + this.unitsWorked = unitsWorked; + } + + public void setErrorLog(String log) { + this.errorLog = log; + } + + public void setJobComplete(boolean jobComplete) { + this.jobComplete = jobComplete; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public URL getUpdatedJobStatus() { + return updatedJobStatus; + } + + public void setUpdatedJobStatus(URL updatedJobStatus) { + this.updatedJobStatus = updatedJobStatus; + } + + public String getJobId() { + return jobId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + +} diff --git a/plugins/org.eclipse.osee.ote.rest/.classpath b/plugins/org.eclipse.osee.ote.rest/.classpath new file mode 100644 index 00000000000..ad32c83a788 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/org.eclipse.osee.ote.rest/.project b/plugins/org.eclipse.osee.ote.rest/.project new file mode 100644 index 00000000000..e388ba0b504 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/.project @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.osee.ote.rest</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ds.core.builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/plugins/org.eclipse.osee.ote.rest/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.rest/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..5b693498bd3 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Osee OTE Rest +Bundle-SymbolicName: org.eclipse.osee.ote.rest +Bundle-Version: 0.11.0.qualifier +Bundle-Vendor: Eclipse Open System Engineering Environment +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Service-Component: OSGI-INF/*.xml +Import-Package: javax.ws.rs, + javax.ws.rs.core, + javax.ws.rs.ext, + org.eclipse.core.resources, + org.eclipse.osee.framework.core.data, + org.eclipse.osee.framework.core.enums, + org.eclipse.osee.framework.core.exception, + org.eclipse.osee.framework.core.model, + org.eclipse.osee.framework.core.model.cache, + org.eclipse.osee.framework.core.util, + org.eclipse.osee.ote, + org.eclipse.osee.ote.rest.model +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.osee.framework.jdk.core;bundle-version="0.11.0" diff --git a/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.configuration.store.xml b/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.configuration.store.xml new file mode 100644 index 00000000000..b3dcec39f4e --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.configuration.store.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.osee.ote.rest.configuration"> + <implementation class="org.eclipse.osee.ote.rest.internal.OteConfigurationStoreImpl"/> + <service> + <provide interface="org.eclipse.osee.ote.rest.internal.OteConfigurationStore"/> + </service> + <reference bind="bindOTEApi" cardinality="1..1" interface="org.eclipse.osee.ote.OTEApi" name="OTEApi" policy="static" unbind="unbindOTEApi"/> + <reference bind="bindOteJobStore" cardinality="1..1" interface="org.eclipse.osee.ote.rest.internal.OteJobStore" name="OteJobStore" policy="static" unbind="unbindOteJobStore"/> +</scr:component> diff --git a/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.job.store.xml b/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.job.store.xml new file mode 100644 index 00000000000..eee590006ac --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.job.store.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.osee.ote.rest"> + <implementation class="org.eclipse.osee.ote.rest.internal.OteJobStoreImpl"/> + <service> + <provide interface="org.eclipse.osee.ote.rest.internal.OteJobStore"/> + </service> +</scr:component> diff --git a/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.rest.application.xml b/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.rest.application.xml new file mode 100644 index 00000000000..710ac2e2238 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/OSGI-INF/ote.rest.application.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.osee.ote.rest.internal.OteRestApplication"> + <implementation class="org.eclipse.osee.ote.rest.internal.OteRestApplication"/> + <service> + <provide interface="javax.ws.rs.core.Application"/> + </service> + <property name="context.name" type="String" value="ote"/> + <reference bind="setOteConfigurationStore" cardinality="1..1" interface="org.eclipse.osee.ote.rest.internal.OteConfigurationStore" name="OteConfigurationStore" policy="static"/> +</scr:component> diff --git a/plugins/org.eclipse.osee.ote.rest/build.properties b/plugins/org.eclipse.osee.ote.rest/build.properties new file mode 100644 index 00000000000..9b4616ae0ea --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/build.properties @@ -0,0 +1,13 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/,\ + OSGI-INF/ote.configuration.store.xml,\ + OSGI-INF/ote.job.store.xml +source.. = src/ +additional.bundles = org.eclipse.osee.orcs,\ + javax.ws.rs,\ + org.eclipse.osee.framework.core.model,\ + org.eclipse.osee.framework.core,\ + org.eclipse.osee.framework.jdk.core,\ + org.eclipse.osee.orcs.rest.model diff --git a/plugins/org.eclipse.osee.ote.rest/pom.xml b/plugins/org.eclipse.osee.ote.rest/pom.xml new file mode 100644 index 00000000000..3cb108093e0 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/pom.xml @@ -0,0 +1,34 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.eclipse.osee</groupId> + <artifactId>org.eclipse.osee.x.server.parent</artifactId> + <version>0.11.0-SNAPSHOT</version> + <relativePath>../../plugins/org.eclipse.osee.x.server.parent</relativePath> + </parent> + + <artifactId>org.eclipse.osee.ote.rest</artifactId> + <packaging>eclipse-plugin</packaging> + <name>OSEE OTE Rest - (Incubation)</name> + + <build> + <!-- workaround for https://issues.sonatype.org/browse/TYCHO-168 --> + <resources> + <resource> + <directory>src</directory> + <excludes> + <exclude>**/*.java</exclude> + </excludes> + </resource> + </resources> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-source-plugin</artifactId> + </plugin> + </plugins> + </build> +</project>
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/ConfigurationJobStatus.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/ConfigurationJobStatus.java new file mode 100644 index 00000000000..d2a55d3d2b9 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/ConfigurationJobStatus.java @@ -0,0 +1,101 @@ +package org.eclipse.osee.ote.rest.internal; + +import java.net.URL; +import java.util.concurrent.ExecutionException; + +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.ote.OTEConfigurationStatus; +import org.eclipse.osee.ote.OTEFuture; +import org.eclipse.osee.ote.OTEStatusCallback; +import org.eclipse.osee.ote.rest.model.OteJobStatus; + +public class ConfigurationJobStatus implements OTEStatusCallback<OTEConfigurationStatus>, OteJob { + + private int totalUnitsOfWork; + private int count; + private StringBuilder errorLog; + private StringBuilder statusLog; + private OTEFuture<OTEConfigurationStatus> future; + private String uuid; + private URL url; + + public ConfigurationJobStatus(){ + totalUnitsOfWork = 0; + errorLog = new StringBuilder(); + statusLog = new StringBuilder(); + } + + @Override + public void complete(OTEConfigurationStatus done) { + } + + @Override + public void setTotalUnitsOfWork(int totalUnitsOfWork) { + this.totalUnitsOfWork = totalUnitsOfWork; + } + + @Override + public void incrememtUnitsWorked(int count) { + this.count+=count; + } + + @Override + public void log(String string) { + statusLog.append(string); + statusLog.append("\n"); + } + + @Override + public void error(String message, Throwable th) { + errorLog.append(message); + errorLog.append("\n"); + errorLog.append(Lib.exceptionToString(th)); + errorLog.append("\n"); + } + + @Override + public void error(String message) { + errorLog.append(message); + errorLog.append("\n"); + } + + public void setFuture(OTEFuture<OTEConfigurationStatus> future) { + this.future = future; + } + + @Override + public OteJobStatus getStatus() throws InterruptedException, ExecutionException { + OteJobStatus jobStatus = new OteJobStatus(); + if(future.isDone()){ + jobStatus.setJobComplete(true); + jobStatus.setSuccess(future.get().isSuccess()); + if(!future.get().isSuccess()){ + error(future.get().getMessage()); + } + } else { + jobStatus.setJobComplete(false); + jobStatus.setSuccess(false); + } + jobStatus.setJobId(uuid); + jobStatus.setErrorLog(errorLog.toString()); + jobStatus.setTotalUnitsOfWork(totalUnitsOfWork); + jobStatus.setUnitsWorked(count); + jobStatus.setUpdatedJobStatus(url); + return jobStatus; + } + + @Override + public String getId() { + return uuid; + } + + @Override + public void setId(String uuid) { + this.uuid = uuid; + } + + public void setUrl(URL url) { + this.url = url; + } + +} diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationResource.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationResource.java new file mode 100644 index 00000000000..f0d46907cc3 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationResource.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.rest.internal; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Request; +import javax.ws.rs.core.UriBuilderException; +import javax.ws.rs.core.UriInfo; + +import org.eclipse.osee.ote.rest.model.OteConfiguration; +import org.eclipse.osee.ote.rest.model.OteJobStatus; + +/** + * @author Andrew M. Finkbeiner + */ +@Path("config") +public class OteConfigurationResource { + + // Allows to insert contextual objects into the class, + // e.g. ServletContext, Request, Response, UriInfo + @Context + UriInfo uriInfo; + @Context + Request request; + + @GET + @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public OteConfiguration getConfiguration() throws MalformedURLException, IllegalArgumentException, UriBuilderException, InterruptedException, ExecutionException { + return getDataStore().getConfiguration(uriInfo); + } + + @POST + @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public OteJobStatus createConfig(OteConfiguration config) throws IOException, InterruptedException, ExecutionException { + return getDataStore().setup(config, uriInfo); + } + + private OteConfigurationStore getDataStore(){ + return OteRestApplication.get(); + } +} diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStore.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStore.java new file mode 100644 index 00000000000..a6c3751e25e --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStore.java @@ -0,0 +1,19 @@ +package org.eclipse.osee.ote.rest.internal; + +import java.net.MalformedURLException; +import java.util.Collection; +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.core.UriBuilderException; +import javax.ws.rs.core.UriInfo; + +import org.eclipse.osee.ote.rest.model.OteConfiguration; +import org.eclipse.osee.ote.rest.model.OteJobStatus; + +public interface OteConfigurationStore { + OteJobStatus setup(OteConfiguration config, UriInfo uriInfo) throws InterruptedException, ExecutionException, MalformedURLException, IllegalArgumentException, UriBuilderException; + OteJobStatus reset(UriInfo uriInfo) throws InterruptedException, ExecutionException, MalformedURLException, IllegalArgumentException, UriBuilderException; + OteConfiguration getConfiguration(UriInfo uriInfo) throws MalformedURLException, IllegalArgumentException, UriBuilderException, InterruptedException, ExecutionException; + OteJobStatus getJob(String uuid) throws InterruptedException, ExecutionException; + Collection<String> getAllJobIds(); +} diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStoreImpl.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStoreImpl.java new file mode 100644 index 00000000000..9ccf4ebae8e --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteConfigurationStoreImpl.java @@ -0,0 +1,102 @@ +package org.eclipse.osee.ote.rest.internal; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collection; +import java.util.UUID; +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.core.UriBuilderException; +import javax.ws.rs.core.UriInfo; + +import org.eclipse.osee.ote.OTEApi; +import org.eclipse.osee.ote.OTEConfiguration; +import org.eclipse.osee.ote.OTEConfigurationStatus; +import org.eclipse.osee.ote.OTEFuture; +import org.eclipse.osee.ote.rest.model.OteConfiguration; +import org.eclipse.osee.ote.rest.model.OteJobStatus; + +public class OteConfigurationStoreImpl implements OteConfigurationStore { + + private OTEApi ote; + private OteJobStore oteJobs; + + public OteConfigurationStoreImpl(){ + } + + public void bindOTEApi(OTEApi ote){ + this.ote = ote; + } + + public void unbindOTEApi(OTEApi ote){ + this.ote = null; + } + + public void bindOteJobStore(OteJobStore oteJobs){ + this.oteJobs = oteJobs; + } + + public void unbindOteJobStore(OteJobStore oteJobs){ + this.oteJobs = null; + } + + @Override + public OteJobStatus setup(OteConfiguration config, UriInfo uriInfo) throws InterruptedException, ExecutionException, MalformedURLException, IllegalArgumentException, UriBuilderException { + OTEConfiguration realConfig = config.translateToOtherConfig(); + ConfigurationJobStatus status = createConfigurationJobStatus(config, uriInfo); + OTEFuture<OTEConfigurationStatus> future = ote.loadConfiguration(realConfig, status); + status.setFuture(future); + return status.getStatus(); + } + + private ConfigurationJobStatus createConfigurationJobStatus(OteConfiguration config, UriInfo uriInfo) throws MalformedURLException, IllegalArgumentException, UriBuilderException { + ConfigurationJobStatus status = new ConfigurationJobStatus(); + status.setId(UUID.randomUUID().toString()); + status.setUrl(generateJobUrl(status, uriInfo)); + oteJobs.add(status); + return status; + } + + private URL generateJobUrl(OteJob job, UriInfo uriInfo) throws MalformedURLException, IllegalArgumentException, UriBuilderException{ + return uriInfo.getBaseUriBuilder().path("job").path(job.getId()).build().toURL(); + } + + @Override + public OteJobStatus reset(UriInfo uriInfo) throws InterruptedException, ExecutionException, MalformedURLException, IllegalArgumentException, UriBuilderException { + ConfigurationJobStatus status = createConfigurationJobStatus(uriInfo); + OTEFuture<OTEConfigurationStatus> future = ote.resetConfiguration(status); + status.setFuture(future); + return status.getStatus(); + } + + @Override + public OteConfiguration getConfiguration(UriInfo uriInfo) throws MalformedURLException, IllegalArgumentException, UriBuilderException, InterruptedException, ExecutionException { + ConfigurationJobStatus status = createConfigurationJobStatus(uriInfo); + OTEFuture<OTEConfigurationStatus> future = ote.getConfiguration(); + status.setFuture(future); + if(future.isDone()){ + return new OteConfiguration(future.get().getConfiguration()); + } else { + return new OteConfiguration(); + } + } + + private ConfigurationJobStatus createConfigurationJobStatus(UriInfo uriInfo) throws MalformedURLException, IllegalArgumentException, UriBuilderException { + ConfigurationJobStatus status = new ConfigurationJobStatus(); + status.setId(UUID.randomUUID().toString()); + status.setUrl(generateJobUrl(status, uriInfo)); + oteJobs.add(status); + return status; + } + + @Override + public OteJobStatus getJob(String uuid) throws InterruptedException, ExecutionException { + return oteJobs.get(uuid); + } + + @Override + public Collection<String> getAllJobIds() { + return oteJobs.getAll(); + } + +} diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJob.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJob.java new file mode 100644 index 00000000000..d9614fdbe6d --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJob.java @@ -0,0 +1,13 @@ +package org.eclipse.osee.ote.rest.internal; + +import java.util.concurrent.ExecutionException; + +import org.eclipse.osee.ote.rest.model.OteJobStatus; + +public interface OteJob { + + String getId(); + void setId(String uuid); + OteJobStatus getStatus() throws InterruptedException, ExecutionException; + +} diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobResource.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobResource.java new file mode 100644 index 00000000000..c3a8246089d --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobResource.java @@ -0,0 +1,53 @@ +/******************************************************************************* +9 * 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 + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.rest.internal; + +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.GET; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Request; +import javax.ws.rs.core.UriInfo; + +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.ote.rest.model.OteJobStatus; + +/** + * @author Andrew M. Finkbeiner + */ +public class OteJobResource { + + @Context + private final UriInfo uriInfo; + @Context + private final Request request; + + private final String uuid; + + private final OteConfigurationStore store; + + + public OteJobResource(UriInfo uriInfo, Request request, OteConfigurationStore store, String id) { + this.uriInfo = uriInfo; + this.request = request; + this.uuid = id; + this.store = store; + } + + @GET + @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public OteJobStatus getConfig() throws OseeCoreException, InterruptedException, ExecutionException { + return store.getJob(uuid); + } + +} diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStore.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStore.java new file mode 100644 index 00000000000..bba69370c65 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStore.java @@ -0,0 +1,16 @@ +package org.eclipse.osee.ote.rest.internal; + +import java.util.Collection; +import java.util.concurrent.ExecutionException; + +import org.eclipse.osee.ote.rest.model.OteJobStatus; + +public interface OteJobStore { + + OteJobStatus get(String uuid) throws InterruptedException, ExecutionException; + + Collection<String> getAll(); + + void add(OteJob job); + +} diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStoreImpl.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStoreImpl.java new file mode 100644 index 00000000000..f3a30f587b6 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobStoreImpl.java @@ -0,0 +1,36 @@ +package org.eclipse.osee.ote.rest.internal; + +import java.util.Collection; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutionException; + +import org.eclipse.osee.ote.rest.model.OteJobStatus; + +public class OteJobStoreImpl implements OteJobStore { + + ConcurrentHashMap<String, OteJob> jobs; + + public OteJobStoreImpl(){ + jobs = new ConcurrentHashMap<String, OteJob>(); + } + + @Override + public OteJobStatus get(String uuid) throws InterruptedException, ExecutionException { + OteJob job = jobs.get(uuid); + if(job != null){ + return job.getStatus(); + } + return null; + } + + @Override + public Collection<String> getAll() { + return jobs.keySet(); + } + + @Override + public void add(OteJob job) { + jobs.put(job.getId(), job); + } + +} diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobsResource.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobsResource.java new file mode 100644 index 00000000000..ec416862f11 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteJobsResource.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.rest.internal; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Request; +import javax.ws.rs.core.UriInfo; + +import org.eclipse.osee.framework.core.exception.OseeCoreException; + +/** + * @author Andrew M. Finkbeiner + */ +@Path("job") +public class OteJobsResource { + + // Allows to insert contextual objects into the class, + // e.g. ServletContext, Request, Response, UriInfo + @Context + UriInfo uriInfo; + @Context + Request request; + + @Path("{uuid}") + public OteJobResource getConfiguration(@PathParam("uuid") String id) { + return new OteJobResource(uriInfo, request, getDataStore(), id); + } + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getConfiguration() throws OseeCoreException { + StringBuilder sb = new StringBuilder(); + for(String id:getDataStore().getAllJobIds()){ + sb.append(id); + sb.append("\n"); + } + return sb.toString(); + } + + private OteConfigurationStore getDataStore(){ + return OteRestApplication.get(); + } +} diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteRestApplication.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteRestApplication.java new file mode 100644 index 00000000000..dfb988ca60d --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteRestApplication.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.rest.internal; + +import java.util.HashSet; +import java.util.Set; + +import javax.ws.rs.core.Application; + +import org.eclipse.osee.ote.rest.internal.mappers.OseeCoreExceptionMapper; + +/** + * Get application.wadl at this context to get rest documentation + * + * @author Roberto E. Escobar + */ +public class OteRestApplication extends Application { + + private static OteConfigurationStore store; + + public void setOteConfigurationStore(OteConfigurationStore store){ + OteRestApplication.store = store; + } + + public static OteConfigurationStore get(){ + return store; + } + + @Override + public Set<Class<?>> getClasses() { + Set<Class<?>> classes = new HashSet<Class<?>>(); + classes.add(OseeCoreExceptionMapper.class); + classes.add(OteConfigurationResource.class); + classes.add(OteJobsResource.class); + return classes; + } + +} diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/mappers/OseeCoreExceptionMapper.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/mappers/OseeCoreExceptionMapper.java new file mode 100644 index 00000000000..4bc0f0ba1a0 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/mappers/OseeCoreExceptionMapper.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2013 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.rest.internal.mappers; + +import javax.ws.rs.core.GenericEntity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.ote.rest.model.ExceptionEntity; + +/** + * @author John Misinco + */ +@Provider +public class OseeCoreExceptionMapper implements ExceptionMapper<OseeCoreException> { + + @Override + public Response toResponse(OseeCoreException exception) { + ExceptionEntity entity = new ExceptionEntity(Lib.exceptionToString(exception)); + GenericEntity<ExceptionEntity> ge = new GenericEntity<ExceptionEntity>(entity, ExceptionEntity.class); + return Response.status(Status.INTERNAL_SERVER_ERROR).type(MediaType.APPLICATION_JSON_TYPE).entity(ge).build(); + } + +} |