diff --git a/org.opentosca.container.api.legacy/META-INF/MANIFEST.MF b/org.opentosca.container.api.legacy/META-INF/MANIFEST.MF deleted file mode 100644 index 6a771f1e9..000000000 --- a/org.opentosca.container.api.legacy/META-INF/MANIFEST.MF +++ /dev/null @@ -1,63 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: OpenTOSCA Container API (legacy) -Bundle-SymbolicName: org.opentosca.container.api.legacy -Bundle-Version: 2.0.0.qualifier -Bundle-Activator: org.opentosca.container.api.legacy.Activator -Import-Package: com.fasterxml.jackson.core;version="2.6.2", - com.fasterxml.jackson.databind;version="2.6.2", - com.google.gson;version="2.2.4", - javax.servlet;version="2.4.0", - javax.servlet.http;version="3.1.0", - javax.ws.rs;version="1.1.1", - javax.ws.rs.core;version="1.1.1", - javax.ws.rs.ext;version="1.1.1", - org.eclipse.equinox.http.servlet;version="1.2.0", - org.glassfish.jersey.media.multipart;version="2.22.2", - org.glassfish.jersey.servlet;version="2.22.2", - org.glassfish.jersey.uri;version="2.22.2", - org.osgi.framework;version="1.3.0", - org.osgi.service.component;version="1.1.0", - org.osgi.service.http;version="1.2.1", - org.slf4j;version="1.7.2" -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Require-Bundle: org.opentosca.container.control;bundle-version="1.0.0", - org.opentosca.container.core;bundle-version="1.0.0", - org.opentosca.container.core.tosca;bundle-version="1.0.0", - org.opentosca.container.connector.bps;bundle-version="1.0.0", - org.opentosca.container.connector.winery;bundle-version="1.0.0", - org.opentosca.planbuilder.integration;bundle-version="1.0.0", - org.opentosca.planbuilder.model;bundle-version="1.0.0", - org.opentosca.planbuilder.service;bundle-version="1.0.0", - org.opentosca.container.portability;bundle-version="1.0.0", - org.opentosca.container.core.impl -Bundle-ActivationPolicy: lazy -Service-Component: OSGI-INF/* -Export-Package: org.opentosca.container.api.legacy, - org.opentosca.container.api.legacy.instancedata, - org.opentosca.container.api.legacy.instancedata.exception, - org.opentosca.container.api.legacy.instancedata.model, - org.opentosca.container.api.legacy.instancedata.utilities, - org.opentosca.container.api.legacy.osgi.servicegetter, - org.opentosca.container.api.legacy.portability, - org.opentosca.container.api.legacy.resources, - org.opentosca.container.api.legacy.resources.credentials, - org.opentosca.container.api.legacy.resources.credentials.jaxb, - org.opentosca.container.api.legacy.resources.csar, - org.opentosca.container.api.legacy.resources.csar.content, - org.opentosca.container.api.legacy.resources.csar.control, - org.opentosca.container.api.legacy.resources.csar.control.jaxb, - org.opentosca.container.api.legacy.resources.csar.jaxb, - org.opentosca.container.api.legacy.resources.csar.servicetemplate, - org.opentosca.container.api.legacy.resources.csar.servicetemplate.boundarydefinitions, - org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances, - org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.plans, - org.opentosca.container.api.legacy.resources.csar.servicetemplate.nodetemplate, - org.opentosca.container.api.legacy.resources.csar.servicetemplate.nodetemplate.instances, - org.opentosca.container.api.legacy.resources.marketplace, - org.opentosca.container.api.legacy.resources.packager, - org.opentosca.container.api.legacy.resources.smartservices, - org.opentosca.container.api.legacy.resources.storageproviders, - org.opentosca.container.api.legacy.resources.storageproviders.jaxb, - org.opentosca.container.api.legacy.resources.utilities, - org.opentosca.container.api.legacy.resources.xlink diff --git a/org.opentosca.container.api.legacy/OSGI-INF/CSARInstanceManagementHandler_component.xml b/org.opentosca.container.api.legacy/OSGI-INF/CSARInstanceManagementHandler_component.xml deleted file mode 100644 index 1b42f2dff..000000000 --- a/org.opentosca.container.api.legacy/OSGI-INF/CSARInstanceManagementHandler_component.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/org.opentosca.container.api.legacy/OSGI-INF/CredentialsServiceHandler_component.xml b/org.opentosca.container.api.legacy/OSGI-INF/CredentialsServiceHandler_component.xml deleted file mode 100644 index eac734adf..000000000 --- a/org.opentosca.container.api.legacy/OSGI-INF/CredentialsServiceHandler_component.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/org.opentosca.container.api.legacy/OSGI-INF/HttpService_component.xml b/org.opentosca.container.api.legacy/OSGI-INF/HttpService_component.xml deleted file mode 100644 index aef691ad3..000000000 --- a/org.opentosca.container.api.legacy/OSGI-INF/HttpService_component.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - diff --git a/org.opentosca.container.api.legacy/OSGI-INF/ICoreFileService_component.xml b/org.opentosca.container.api.legacy/OSGI-INF/ICoreFileService_component.xml deleted file mode 100644 index a1de9b98a..000000000 --- a/org.opentosca.container.api.legacy/OSGI-INF/ICoreFileService_component.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/org.opentosca.container.api.legacy/OSGI-INF/ICoreModelRepositoryService_component.xml b/org.opentosca.container.api.legacy/OSGI-INF/ICoreModelRepositoryService_component.xml deleted file mode 100644 index aa1e92496..000000000 --- a/org.opentosca.container.api.legacy/OSGI-INF/ICoreModelRepositoryService_component.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/org.opentosca.container.api.legacy/OSGI-INF/IFileAccessService_component.xml b/org.opentosca.container.api.legacy/OSGI-INF/IFileAccessService_component.xml deleted file mode 100644 index cd1320ee0..000000000 --- a/org.opentosca.container.api.legacy/OSGI-INF/IFileAccessService_component.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/org.opentosca.container.api.legacy/OSGI-INF/IOpenToscaControlService_component.xml b/org.opentosca.container.api.legacy/OSGI-INF/IOpenToscaControlService_component.xml deleted file mode 100644 index ce85f7c39..000000000 --- a/org.opentosca.container.api.legacy/OSGI-INF/IOpenToscaControlService_component.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/org.opentosca.container.api.legacy/OSGI-INF/IPlanInvocationEngineHandler_component.xml b/org.opentosca.container.api.legacy/OSGI-INF/IPlanInvocationEngineHandler_component.xml deleted file mode 100644 index c1e2ba512..000000000 --- a/org.opentosca.container.api.legacy/OSGI-INF/IPlanInvocationEngineHandler_component.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/org.opentosca.container.api.legacy/OSGI-INF/InstanceData_component.xml b/org.opentosca.container.api.legacy/OSGI-INF/InstanceData_component.xml deleted file mode 100644 index d8711e649..000000000 --- a/org.opentosca.container.api.legacy/OSGI-INF/InstanceData_component.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/org.opentosca.container.api.legacy/OSGI-INF/PortabilityService_component.xml b/org.opentosca.container.api.legacy/OSGI-INF/PortabilityService_component.xml deleted file mode 100644 index 5abb1ad30..000000000 --- a/org.opentosca.container.api.legacy/OSGI-INF/PortabilityService_component.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/org.opentosca.container.api.legacy/OSGI-INF/ToscaServiceHandler_component.xml b/org.opentosca.container.api.legacy/OSGI-INF/ToscaServiceHandler_component.xml deleted file mode 100644 index 220a6e746..000000000 --- a/org.opentosca.container.api.legacy/OSGI-INF/ToscaServiceHandler_component.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/org.opentosca.container.api.legacy/build.properties b/org.opentosca.container.api.legacy/build.properties deleted file mode 100644 index 98d41e652..000000000 --- a/org.opentosca.container.api.legacy/build.properties +++ /dev/null @@ -1,4 +0,0 @@ -source.. = src/ -bin.includes = META-INF/,\ - .,\ - OSGI-INF/, diff --git a/org.opentosca.container.api.legacy/pom.xml b/org.opentosca.container.api.legacy/pom.xml deleted file mode 100644 index 252658e7a..000000000 --- a/org.opentosca.container.api.legacy/pom.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - 4.0.0 - - - org.opentosca - container - 2.0.0-SNAPSHOT - - - org.opentosca.container.api.legacy - eclipse-plugin - - diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/Activator.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/Activator.java deleted file mode 100644 index 94cd5abdf..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/Activator.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright 2012 - 2017, University of Stuttgart and the OpenTOSCA contributors - * SPDX-License-Identifier: Apache-2.0 - *******************************************************************************/ -package org.opentosca.container.api.legacy; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Activator implements BundleActivator { - - private static Logger logger = LoggerFactory.getLogger(Activator.class); - - private static BundleContext context; - - - public static BundleContext getContext() { - return context; - } - - @Override - public void start(final BundleContext bundleContext) throws Exception { - logger.info("Starting bundle \"{}\" ({})...", bundleContext.getBundle().getSymbolicName(), - bundleContext.getBundle().getVersion()); - context = bundleContext; - } - - @Override - public void stop(final BundleContext bundleContext) throws Exception { - logger.info("Stopping bundle \"{}\" ({})...", bundleContext.getBundle().getSymbolicName(), - bundleContext.getBundle().getVersion()); - Activator.context = null; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/CorsFilter.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/CorsFilter.java deleted file mode 100644 index 0cbf16106..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/CorsFilter.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.opentosca.container.api.legacy; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public class CorsFilter implements Filter { - - - @Override - public void doFilter(final ServletRequest request, final ServletResponse response, - final FilterChain chain) throws IOException, ServletException { - final HttpServletRequest req = (HttpServletRequest) request; - final HttpServletResponse res = (HttpServletResponse) response; - - if (req.getHeader("Origin") != null) { - res.addHeader("Access-Control-Allow-Origin", "*"); - res.addHeader("Access-Control-Expose-Headers", "Origin, Content-Type, X-Cache-Date, Location"); - } - - if ("OPTIONS".equals(req.getMethod())) { - res.addHeader("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PUT, DELETE"); - res.addHeader("Access-Control-Allow-Headers", "Origin, Content-Type, X-Cache-Date, Location"); - res.addHeader("Access-Control-Max-Age", "-1"); - } - chain.doFilter(req, res); - } - - @Override - public void destroy() {} - - @Override - public void init(final FilterConfig filterConfig) throws ServletException {} -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/JerseyApplication.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/JerseyApplication.java deleted file mode 100644 index c86ca60f7..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/JerseyApplication.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.opentosca.container.api.legacy; - -import java.util.HashSet; -import java.util.Set; - -import javax.ws.rs.core.Application; - -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.opentosca.container.api.legacy.instancedata.InstanceDataRoot; -import org.opentosca.container.api.legacy.portability.PortabilityRoot; -import org.opentosca.container.api.legacy.resources.RootResource; -import org.opentosca.container.api.legacy.resources.credentials.AllCredentialsResource; -import org.opentosca.container.api.legacy.resources.csar.CSARsResource; -import org.opentosca.container.api.legacy.resources.csar.control.CSARControl; -import org.opentosca.container.api.legacy.resources.marketplace.MarketplaceRootResource; -import org.opentosca.container.api.legacy.resources.packager.PackagerResource; -import org.opentosca.container.api.legacy.resources.smartservices.SmartServicesResource; -import org.opentosca.container.api.legacy.resources.storageproviders.StorageProvidersResource; - -/** - * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * @author Rene Trefft - rene.trefft@developers.opentosca.org - */ -public class JerseyApplication extends Application { - - // @Override - // public Set getSingletons() { - // Set singletons = new HashSet(); - // singletons.add(new ContainerResponseFilter() { - // - // - // @Override - // public void filter(ContainerRequestContext arg0, ContainerResponseContext - // arg1) throws IOException { - // arg1.getHeaders().putSingle("Access-Control-Allow-Origin", "*"); - // arg1.getHeaders().putSingle("Access-Control-Allow-Credentials", "true"); - // arg1.getHeaders().putSingle("Access-Control-Allow-Methods", "GET, POST, - // DELETE, PUT, OPTIONS, HEAD"); - // arg1.getHeaders().putSingle("Access-Control-Allow-Headers", - // "Content-Type, Accept, X-Requested-With"); - // - // return arg1; - // } - // }); - // return singletons; - // }; - - @Override - public Set> getClasses() { - - final Set> s = new HashSet<>(); - - // add all root resources - s.add(RootResource.class); - s.add(CSARControl.class); - s.add(CSARsResource.class); - s.add(AllCredentialsResource.class); - s.add(StorageProvidersResource.class); - s.add(InstanceDataRoot.class); - s.add(PortabilityRoot.class); - - s.add(SmartServicesResource.class); - - s.add(org.opentosca.planbuilder.service.resources.RootResource.class); - - s.add(MarketplaceRootResource.class); - - s.add(PackagerResource.class); - - // add all exception mappers - s.add(SystemExceptionMapper.class); - s.add(UserExceptionMapper.class); - s.add(NotFoundExceptionMapper.class); - - // add json mapper, no functionality yet, needs additional dependencies - // s.add(JSONMapper.class); - - s.add(MultiPartFeature.class); - - return s; - } - - - public class JSONMapper { - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/JerseyServletComponent.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/JerseyServletComponent.java deleted file mode 100644 index 5f02a8f32..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/JerseyServletComponent.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.opentosca.container.api.legacy; - -import java.util.Dictionary; -import java.util.Hashtable; - -import org.eclipse.equinox.http.servlet.ExtendedHttpService; -import org.glassfish.jersey.servlet.ServletContainer; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.osgi.service.component.ComponentContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * - */ -public class JerseyServletComponent { - - private static final Logger LOG = LoggerFactory.getLogger(JerseyServletComponent.class); - - - protected void bindHttpService(final ExtendedHttpService httpService) { - JerseyServletComponent.LOG.debug("Binding HTTP Service"); - try { - - // final JerseyApplication app = new JerseyApplication(); - final ServletContainer container = new ServletContainer(); - - // this is for supporting json, but unfortunately we need further - // bundles in the target platform ... - // - // com.sun.jersey.api.json.POJOMappingFeature - // true - // - final Dictionary initParams = new Hashtable<>(); - initParams.put("javax.ws.rs.Application", JerseyApplication.class.getName()); - // initParams.put("com.sun.jersey.api.json.POJOMappingFeature", - // "true"); - - // TODO: Temporary workaround - // This is a workaround related to issue JERSEY-2093; grizzly - // (1.9.5) - final ClassLoader classLoader = this.getClass().getClassLoader(); - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(classLoader); - httpService.registerServlet(ResourceConstants.ROOT, container, initParams, null); - httpService.registerFilter("/", new CorsFilter(), null, null); - } - finally { - Thread.currentThread().setContextClassLoader(contextClassLoader); - } - - } - catch (final Exception ex) { - ex.printStackTrace(); - } - } - - protected void unbindHttpService(final ExtendedHttpService httpService) { - JerseyServletComponent.LOG.debug("Unbinding HTTP Service"); - httpService.unregister(ResourceConstants.ROOT); - } - - protected void activate(final ComponentContext componentContext) { - // the Uri for the ContainerApi is also stored in the SettingsBundle - String port = componentContext.getBundleContext().getProperty("org.osgi.service.http.port"); - if (port == null || port.trim().length() == 0) { - port = "1337"; - } - - JerseyServletComponent.LOG.info("Container API started: http://localhost:{}{}", port, ResourceConstants.ROOT); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/NotFoundExceptionMapper.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/NotFoundExceptionMapper.java deleted file mode 100644 index 6f2e8c764..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/NotFoundExceptionMapper.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2016, 2017 University of Stuttgart - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.opentosca.container.api.legacy; - -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.opentosca.container.core.common.NotFoundException; - -@Provider -public class NotFoundExceptionMapper implements ExceptionMapper { - - @Override - public Response toResponse(final NotFoundException e) { - return Response.status(Status.NOT_FOUND).build(); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/SystemExceptionMapper.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/SystemExceptionMapper.java deleted file mode 100644 index d48445bdb..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/SystemExceptionMapper.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright 2017 University of Stuttgart - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - *******************************************************************************/ -package org.opentosca.container.api.legacy; - -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.opentosca.container.core.common.SystemException; - -@Provider -public class SystemExceptionMapper implements ExceptionMapper { - - @Override - public Response toResponse(final SystemException e) { - return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).type(MediaType.TEXT_PLAIN).build(); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/UserExceptionMapper.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/UserExceptionMapper.java deleted file mode 100644 index 3feecf7bd..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/UserExceptionMapper.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright 2017 University of Stuttgart - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - *******************************************************************************/ -package org.opentosca.container.api.legacy; - -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.opentosca.container.core.common.UserException; - -@Provider -public class UserExceptionMapper implements ExceptionMapper { - - @Override - public Response toResponse(final UserException e) { - return Response.status(Status.BAD_REQUEST).build(); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/ExistenceChecker.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/ExistenceChecker.java deleted file mode 100644 index 466e6cd45..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/ExistenceChecker.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.opentosca.container.api.legacy.instancedata; - -import java.net.URI; -import java.util.List; - -import javax.ws.rs.core.Response.Status; - -import org.opentosca.container.api.legacy.instancedata.exception.GenericRestException; -import org.opentosca.container.core.model.instance.IdConverter; -import org.opentosca.container.core.model.instance.NodeInstance; -import org.opentosca.container.core.model.instance.RelationInstance; -import org.opentosca.container.core.model.instance.ServiceInstance; -import org.opentosca.container.core.service.IInstanceDataService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This class checks for Existence of ServiceInstances and NodeInstances by calling the given - * InstanceDataService - * - * @author Marcus Eisele - marcus.eisele@gmail.com - * - */ -public class ExistenceChecker { - - private static Logger logger = LoggerFactory.getLogger(ExistenceChecker.class); - - public static boolean existsServiceInstance(final URI serviceInstanceID, final IInstanceDataService service) { - final List serviceInstances = service.getServiceInstances(serviceInstanceID, null, null); - // check if only one instance was returned - we dont verify because we - // assume the get Method returns the correct one! - // we got really bad problems if this wouldnt work anyway - if (serviceInstances != null && serviceInstances.size() == 1 && serviceInstances.get(0) != null) { - return true; - } - - // if the instance wasnt returned => it was not found = it doesnt exist - return false; - } - - public static boolean existsNodeInstance(final URI nodeInstanceID, final IInstanceDataService service) { - final List nodeInstances = service.getNodeInstances(nodeInstanceID, null, null, null); - // check if only one instance was returned - we dont verify because we - // assume the get Method returns the correct one! - // we got really bad problems if this wouldnt work anyway - if (nodeInstances != null && nodeInstances.size() == 1 && nodeInstances.get(0) != null) { - return true; - } - - // if the instance wasnt returned => it was not found = it doesnt exist - return false; - } - - /** - * @param nodeInstanceID the id given (int) by the rest-service - * @param service initialized InstanceDataService - * @return the specified nodeInstance - * - * @throws GenericRestException when specified nodeInstance doesn't exist - */ - public static NodeInstance checkNodeInstanceWithException(final int nodeInstanceID, - final IInstanceDataService service) throws GenericRestException { - final List nodeInstances = - service.getNodeInstances(IdConverter.nodeInstanceIDtoURI(nodeInstanceID), null, null, null); - // check if only one instance was returned - we dont verify because we - // assume the get Method returns the correct one! - // we got really bad problems if this wouldnt work anyway - if (nodeInstances != null && nodeInstances.size() == 1 && nodeInstances.get(0) != null) { - return nodeInstances.get(0); - } else { - throw new GenericRestException(Status.NOT_FOUND, - "Specified nodeInstance with id: " + nodeInstanceID + " doesn't exist"); - } - - } - - public static ServiceInstance checkServiceInstanceWithException(final int serviceInstanceID, - final IInstanceDataService service) throws GenericRestException { - final List serviceInstances = - service.getServiceInstances(IdConverter.serviceInstanceIDtoURI(serviceInstanceID), null, null); - // check if only one instance was returned - we dont verify because we - // assume the get Method returns the correct one! - // we got really bad problems if this wouldnt work anyway - if (serviceInstances != null && serviceInstances.size() == 1 && serviceInstances.get(0) != null) { - return serviceInstances.get(0); - } else { - throw new GenericRestException(Status.NOT_FOUND, - "Specified serviceInstance with id: " + serviceInstanceID + " doesn't exist"); - } - } - - public static RelationInstance checkRelationInstanceWithException(final int relationInstanceID, - final IInstanceDataService service) throws GenericRestException { - final List relationInstances = - service.getRelationInstances(IdConverter.relationInstanceIDtoURI(relationInstanceID), null, null, null); - // check if only one instance was returned - we dont verify because we - // assume the get Method returns the correct one! - // we got really bad problems if this wouldnt work anyway - if (relationInstances != null && relationInstances.size() == 1 && relationInstances.get(0) != null) { - return relationInstances.get(0); - } else { - logger.info("Specified relationInstance with id: " + relationInstanceID + " doesn't exist"); - throw new GenericRestException(Status.NOT_FOUND, - "Specified relationInstance with id: " + relationInstanceID + " doesn't exist"); - } - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/InstanceDataRoot.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/InstanceDataRoot.java deleted file mode 100644 index ebee772b2..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/InstanceDataRoot.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.opentosca.container.api.legacy.instancedata; - -import java.util.LinkedList; -import java.util.List; - -import javax.ws.rs.GET; -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.Response; -import javax.ws.rs.core.UriInfo; - -import org.opentosca.container.api.legacy.instancedata.model.InstanceDataEntry; -import org.opentosca.container.api.legacy.instancedata.model.SimpleXLink; - -/** - * The root resource for the instance data API. - * - * @author Florian Haupt - * - */ -@Path("/instancedata") -public class InstanceDataRoot { - - - @Context - UriInfo uriInfo; - @Context - Request request; - - - @GET - @Produces(MediaType.APPLICATION_XML) - public Response doGetXML() { - - final InstanceDataEntry idr = getRefs(); - - return Response.ok(idr).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response doGetJSON() { - - final InstanceDataEntry idr = getRefs(); - - return Response.ok(idr.toJSON()).build(); - } - - private InstanceDataEntry getRefs() { - final List links = new LinkedList<>(); - links.add(LinkBuilder.selfLink(this.uriInfo)); - // links.add(new SimpleXLink(LinkBuilder.linkToNodeInstanceList(uriInfo), "Node Instances")); - // links.add(new SimpleXLink(LinkBuilder.linkToServiceInstanceList(uriInfo), "Service Instances")); - - final InstanceDataEntry idr = new InstanceDataEntry(links); - return idr; - } - - // @Path("/nodeInstances") - // public Object getNodeInstances() { - // return new NodeInstanceListResource(); - // } - - // @Path("/serviceInstances") - // public Object getServiceInstances() { - // return new ServiceInstanceListResource(); - // } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/LinkBuilder.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/LinkBuilder.java deleted file mode 100644 index 8207fe6c0..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/LinkBuilder.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.opentosca.container.api.legacy.instancedata; - -import java.net.URI; -import java.util.HashMap; -import java.util.Map; - -import javax.ws.rs.core.UriBuilder; -import javax.ws.rs.core.UriInfo; - -import org.opentosca.container.api.legacy.instancedata.model.SimpleXLink; -import org.opentosca.container.api.legacy.instancedata.utilities.Constants; -import org.opentosca.container.api.legacy.portability.PortabilityRoot; -import org.opentosca.container.api.legacy.resources.csar.CSARResource; -import org.opentosca.container.api.legacy.resources.csar.CSARsResource; -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.ServiceTemplateResource; -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.ServiceTemplateInstanceResource; -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.ServiceTemplateInstancesResource; -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.nodetemplate.instances.NodeTemplateInstanceListResource; -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.nodetemplate.instances.NodeTemplateInstanceResource; -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.relationshiptemplate.instances.RelationshipTemplateInstanceListResource; - -/** - * - * @author Florian Haupt - * - */ -public class LinkBuilder { - - public static SimpleXLink selfLink(final UriInfo uriInfo) { - return new SimpleXLink(uriInfo.getAbsolutePath().toString(), "self"); - } - - // TODO: move to own linkBuilder - public static URI linkToArtifactList(final UriInfo uriInfo) { - return uriInfo.getBaseUriBuilder().path(PortabilityRoot.class).path(PortabilityRoot.class, "getArtifacts") - .build(new Object[0]); - } - - // TODO: move to own linkBuilder - public static URI linkToPoliciesList(final UriInfo uriInfo) { - return uriInfo.getBaseUriBuilder().path(PortabilityRoot.class).path(PortabilityRoot.class, "getPolicies") - .build(new Object[0]); - } - - public static URI linkToNodeInstanceList(final UriInfo uriInfo) { - return uriInfo.getBaseUriBuilder().path(InstanceDataRoot.class).path(InstanceDataRoot.class, "getNodeInstances") - .build(new Object[0]); - } - - public static URI linkToRelationInstanceList(final UriInfo uriInfo) { - return uriInfo.getBaseUriBuilder().path(InstanceDataRoot.class) - .path(InstanceDataRoot.class, "getRelationInstances").build(new Object[0]); - } - - public static URI linkToServiceInstanceList(final UriInfo uriInfo) { - return uriInfo.getBaseUriBuilder().path(InstanceDataRoot.class) - .path(ServiceTemplateResource.class, "getInstances").build(new Object[0]); - } - - public static URI linkToCSAR(final UriInfo uriInfo, final String csarID) { - return uriInfo.getBaseUriBuilder().path(CSARsResource.class).path(CSARsResource.class, "getCSAR") - .build(new Object[] {csarID}); - } - - public static URI linkToCSARContent(final UriInfo uriInfo, final String csarID) { - return UriBuilder.fromUri(linkToCSAR(uriInfo, csarID)).path(CSARResource.class, "getContent") - .build(new Object[0]); - } - - public static URI linkToNodeInstance(final UriInfo uriInfo, final int id) { - final Map paramMap = new HashMap<>(); - paramMap.put(Constants.NodeInstanceListResource_getNodeInstance_PARAM, Integer.toString(id)); - return UriBuilder.fromUri(linkToNodeInstanceList(uriInfo)) - .path(NodeTemplateInstanceListResource.class, "getNodeInstance").buildFromMap(paramMap); - } - - public static URI linkToRelationInstance(final UriInfo uriInfo, final int id) { - final Map paramMap = new HashMap<>(); - paramMap.put(Constants.RelationInstanceListResource_getRelationInstance_PARAM, Integer.toString(id)); - return UriBuilder.fromUri(linkToRelationInstanceList(uriInfo)) - .path(RelationshipTemplateInstanceListResource.class, "getRelationInstance") - .buildFromMap(paramMap); - } - - public static URI linkToServiceInstance(final UriInfo uriInfo, final int id) { - final Map paramMap = new HashMap<>(); - paramMap.put(Constants.ServiceInstanceListResource_getServiceInstance_PARAM, Integer.toString(id)); - return UriBuilder.fromUri(linkToServiceInstanceList(uriInfo)) - .path(ServiceTemplateInstancesResource.class, "getServiceInstance").buildFromMap(paramMap); - } - - public static URI linkToFile(final UriInfo uriInfo, final String csarID, final String relativePath) { - - // get base path to csar content - URI uri = linkToCSARContent(uriInfo, csarID); - final String[] parts = relativePath.split("/"); - for (final String part : parts) { - uri = UriBuilder.fromUri(uri).path(part).build(); - } - - return uri; - - } - - public static URI linkToServiceInstanceProperties(final UriInfo uriInfo, final int serviceInstanceID) { - return UriBuilder.fromUri(linkToServiceInstance(uriInfo, serviceInstanceID)) - .path(ServiceTemplateInstanceResource.class, "getProperties").build(new Object[0]); - } - - public static URI linkToNodeInstanceProperties(final UriInfo uriInfo, final int nodeInstanceID) { - return UriBuilder.fromUri(linkToNodeInstance(uriInfo, nodeInstanceID)) - .path(NodeTemplateInstanceResource.class, "getProperties").build(new Object[0]); - } - - public static URI linkToNodeInstanceState(final UriInfo uriInfo, final int nodeInstanceID) { - return UriBuilder.fromUri(linkToNodeInstance(uriInfo, nodeInstanceID)) - .path(NodeTemplateInstanceResource.class, "getState").build(new Object[0]); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/exception/GenericRestException.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/exception/GenericRestException.java deleted file mode 100644 index 8cf096ee3..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/exception/GenericRestException.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.opentosca.container.api.legacy.instancedata.exception; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; - -/** - * This exception is used to return a 400 BadRequest response an error messages in the body - * - * @author Marcus Eisele - marcus.eisele@gmail.com - * - */ -public class GenericRestException extends WebApplicationException { - - private static final long serialVersionUID = 1L; - private final String errorMessage; - - public GenericRestException(final Status serverStatus, final String errorMessage) { - super(Response.status(serverStatus).type(MediaType.TEXT_PLAIN).entity(errorMessage).build()); - this.errorMessage = errorMessage; - } - - public String getErrorMessage() { - return this.errorMessage; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/InstanceDataEntry.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/InstanceDataEntry.java deleted file mode 100644 index d79a0e876..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/InstanceDataEntry.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.opentosca.container.api.legacy.instancedata.model; - -import java.util.LinkedList; -import java.util.List; - -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; - -/** - * - * @author Florian Haupt - * - */ -@XmlRootElement(name = "InstanceDataAPI") -public class InstanceDataEntry { - - private final String version = "0.1"; - - private List links = new LinkedList<>(); - - - protected InstanceDataEntry() { - super(); - } - - public InstanceDataEntry(final List links) { - super(); - this.links = links; - } - - @XmlAttribute(name = "version", required = true) - public String getVersion() { - return this.version; - } - - @XmlElement(name = "Link") - public List getLinks() { - return this.links; - } - - public String toJSON() { - - final JsonObject ret = new JsonObject(); - final JsonArray refs = new JsonArray(); - - for (final SimpleXLink ref : this.links) { - final JsonObject obj = new JsonObject(); - obj.addProperty("type", ref.getType()); - obj.addProperty("href", ref.getHref()); - obj.addProperty("title", ref.getTitle()); - refs.add(obj); - } - ret.add("References", refs); - - return ret.toString(); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/NodeInstanceEntry.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/NodeInstanceEntry.java deleted file mode 100644 index ed6cfe97c..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/NodeInstanceEntry.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.opentosca.container.api.legacy.instancedata.model; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; - -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -import org.opentosca.container.core.model.instance.NodeInstance; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; - -/** - * - * @author Marcus Eisele - * - */ -@XmlRootElement(name = "NodeInstance") -public class NodeInstanceEntry { - - private URI nodeInstanceID; - private String nodeTemplateID; - private String nodeTemplateName; - private Date created; - private URI serviceInstanceID; - private List nodeType; - private List links = new LinkedList<>(); - - - protected NodeInstanceEntry() { - super(); - } - - public NodeInstanceEntry(final NodeInstance ni, final List links) { - this.nodeInstanceID = ni.getNodeInstanceID(); - this.nodeTemplateID = ni.getNodeTemplateID().toString(); - this.nodeTemplateName = ni.getNodeTemplateName(); - this.created = ni.getCreated(); - this.serviceInstanceID = ni.getServiceInstance().getServiceInstanceID(); - - // TODO: change this behavior when the requirement for multiple - // nodeTypes arises - final ArrayList list = new ArrayList<>(); - list.add(ni.getNodeType().toString()); - this.nodeType = list; - this.links = links; - } - - @XmlElement(name = "Link") - public List getLinks() { - return this.links; - } - - @XmlAttribute(name = "nodeInstanceID", required = true) - public URI getNodeInstanceID() { - return this.nodeInstanceID; - } - - @XmlAttribute(name = "nodeTemplateID", required = true) - public String getNodeTemplateID() { - return this.nodeTemplateID; - } - - @XmlAttribute(name = "nodeTemplateName") - public String getNodeTemplateName() { - return this.nodeTemplateName; - } - - @XmlAttribute(name = "created-at") - public Date getCreated() { - return this.created; - } - - @XmlAttribute(name = "serviceInstanceID") - public URI getServiceInstanceID() { - return this.serviceInstanceID; - } - - @XmlElement(name = "NodeType") - public List getNodeType() { - return this.nodeType; - } - - public String toJSON() { - - final JsonObject ret = new JsonObject(); - final JsonArray refs = new JsonArray(); - - for (final SimpleXLink ref : this.links) { - final JsonObject obj = new JsonObject(); - obj.addProperty("type", ref.getType()); - obj.addProperty("href", ref.getHref()); - obj.addProperty("title", ref.getTitle()); - refs.add(obj); - } - ret.add("References", refs); - - return ret.toString(); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/NodeInstanceList.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/NodeInstanceList.java deleted file mode 100644 index 4905de415..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/NodeInstanceList.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.opentosca.container.api.legacy.instancedata.model; - -import java.util.List; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; - -/** - * - * @author Florian Haupt - * - */ -@XmlRootElement(name = "NodeInstanceList") -@XmlType(propOrder = {"selfLink", "links"}) -public class NodeInstanceList { - - private List links; - - private SimpleXLink selfLink; - - public NodeInstanceList() { - - } - - public NodeInstanceList(final SimpleXLink selfLink, final List links) { - super(); - this.selfLink = selfLink; - this.links = links; - } - - @XmlElement(name = "self") - public SimpleXLink getSelfLink() { - return this.selfLink; - } - - public void setSelfLink(final SimpleXLink selfLink) { - this.selfLink = selfLink; - } - - @XmlElement(name = "link") - @XmlElementWrapper(name = "nodeinstances") - public List getLinks() { - return this.links; - } - - public void setLinks(final List links) { - this.links = links; - } - - public String toJSON() { - - final JsonObject ret = new JsonObject(); - final JsonArray refs = new JsonArray(); - - for (final SimpleXLink ref : this.links) { - final JsonObject obj = new JsonObject(); - obj.addProperty("type", ref.getType()); - obj.addProperty("href", ref.getHref()); - obj.addProperty("title", ref.getTitle()); - refs.add(obj); - } - ret.add("References", refs); - - return ret.toString(); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/RelationInstanceList.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/RelationInstanceList.java deleted file mode 100644 index e46f76912..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/RelationInstanceList.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.opentosca.container.api.legacy.instancedata.model; - -import java.util.List; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; - -/** - * - * @author Florian Haupt - * - */ -@XmlRootElement(name = "RelationInstanceList") -@XmlType(propOrder = {"selfLink", "links"}) -public class RelationInstanceList { - - private List links; - - private SimpleXLink selfLink; - - - public RelationInstanceList() { - - } - - public RelationInstanceList(final SimpleXLink selfLink, final List links) { - super(); - this.selfLink = selfLink; - this.links = links; - } - - @XmlElement(name = "self") - public SimpleXLink getSelfLink() { - return this.selfLink; - } - - public void setSelfLink(final SimpleXLink selfLink) { - this.selfLink = selfLink; - } - - @XmlElement(name = "link") - @XmlElementWrapper(name = "nodeinstances") - public List getLinks() { - return this.links; - } - - public void setLinks(final List links) { - this.links = links; - } - - public String toJSON() { - - final JsonObject ret = new JsonObject(); - final JsonArray refs = new JsonArray(); - - for (final SimpleXLink ref : this.links) { - final JsonObject obj = new JsonObject(); - obj.addProperty("type", ref.getType()); - obj.addProperty("href", ref.getHref()); - obj.addProperty("title", ref.getTitle()); - refs.add(obj); - } - ret.add("References", refs); - - return ret.toString(); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/ServiceInstanceEntry.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/ServiceInstanceEntry.java deleted file mode 100644 index cf72b98a8..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/ServiceInstanceEntry.java +++ /dev/null @@ -1,135 +0,0 @@ -package org.opentosca.container.api.legacy.instancedata.model; - -import java.net.URI; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; - -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; - -import org.opentosca.container.core.model.instance.ServiceInstance; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; - -/** - * - * @author Marcus Eisele - * - */ -@XmlRootElement(name = "ServiceInstance") -public class ServiceInstanceEntry { - - private URI serviceInstanceID; - private String csarID; - private String serviceTemplateID; - private String serviceTemplateName; - private Date created; - private List links = new LinkedList<>(); - - private List nodeInstanceList = new LinkedList<>(); - - private List relationInstanceList = new LinkedList<>(); - - /** - * @param serviceInstanceID - * @param csarID - * @param serviceTemplateID - * @param serviceTemplateName - * @param created - * @param links - * @param nodeInstanceList - */ - public ServiceInstanceEntry(final ServiceInstance si, final List links, - final NodeInstanceList nodeInstanceList) { - super(); - this.serviceInstanceID = si.getServiceInstanceID(); - this.csarID = si.getCSAR_ID().toString(); - this.serviceTemplateID = si.getServiceTemplateID().toString(); - this.serviceTemplateName = si.getServiceTemplateName(); - this.created = si.getCreated(); - - this.links = links; - this.nodeInstanceList = nodeInstanceList.getLinks(); - } - - public ServiceInstanceEntry(final ServiceInstance si, final List links, - final RelationInstanceList relationInstanceList) { - super(); - this.serviceInstanceID = si.getServiceInstanceID(); - this.csarID = si.getCSAR_ID().toString(); - this.serviceTemplateID = si.getServiceTemplateID().toString(); - this.serviceTemplateName = si.getServiceTemplateName(); - this.created = si.getCreated(); - - this.links = links; - this.relationInstanceList = relationInstanceList.getLinks(); - } - - protected ServiceInstanceEntry() { - super(); - } - - @XmlAttribute(name = "serviceInstanceID", required = true) - public URI getServiceInstanceID() { - return this.serviceInstanceID; - } - - @XmlAttribute(name = "csarID", required = true) - public String getCsarID() { - return this.csarID; - } - - @XmlAttribute(name = "serviceTemplateID", required = true) - public String getServiceTemplateID() { - return this.serviceTemplateID; - } - - @XmlAttribute(name = "serviceTemplateName") - public String getServiceTemplateName() { - return this.serviceTemplateName; - } - - @XmlAttribute(name = "created-at") - public Date getCreated() { - return this.created; - } - - @XmlElement(name = "Link") - public List getLinks() { - return this.links; - } - - @XmlElementWrapper(name = "nodeInstances") - @XmlElement(name = "nodeInstance") - public List getNodeInstanceList() { - return this.nodeInstanceList; - } - - @XmlElementWrapper(name = "relationInstances") - @XmlElement(name = "relationInstance") - public List getRelationInstanceList() { - return this.relationInstanceList; - } - - public String toJSON() { - - final JsonObject ret = new JsonObject(); - final JsonArray refs = new JsonArray(); - - for (final SimpleXLink ref : this.links) { - final JsonObject obj = new JsonObject(); - obj.addProperty("type", ref.getType()); - obj.addProperty("href", ref.getHref()); - obj.addProperty("title", ref.getTitle()); - refs.add(obj); - } - ret.add("References", refs); - - return ret.toString(); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/ServiceInstanceList.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/ServiceInstanceList.java deleted file mode 100644 index 46a56e5ac..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/ServiceInstanceList.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.opentosca.container.api.legacy.instancedata.model; - -import java.util.List; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; - -/** - * - * @author Marcus Eisele - * - */ -@XmlRootElement(name = "ServiceInstanceList") -@XmlType(propOrder = {"selfLink", "links"}) -public class ServiceInstanceList { - - - List links; - - private SimpleXLink selfLink; - - - public ServiceInstanceList() { - - } - - public ServiceInstanceList(final SimpleXLink selfLink, final List links) { - super(); - this.links = links; - } - - @XmlElement(name = "self") - public SimpleXLink getSelfLink() { - return this.selfLink; - } - - public void setSelfLink(final SimpleXLink selfLink) { - this.selfLink = selfLink; - } - - @XmlElement(name = "link") - @XmlElementWrapper(name = "serviceinstances") - public List getLinks() { - return this.links; - } - - public void setLinks(final List links) { - this.links = links; - } - - public String toJSON() { - - final JsonObject ret = new JsonObject(); - final JsonArray refs = new JsonArray(); - - for (final SimpleXLink ref : this.links) { - final JsonObject obj = new JsonObject(); - obj.addProperty("type", ref.getType()); - obj.addProperty("href", ref.getHref()); - obj.addProperty("title", ref.getTitle()); - refs.add(obj); - } - ret.add("References", refs); - - return ret.toString(); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/SimpleXLink.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/SimpleXLink.java deleted file mode 100644 index 436972da8..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/model/SimpleXLink.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.opentosca.container.api.legacy.instancedata.model; - -import java.net.URI; - -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlRootElement; - -/** - * A simple link following the XLink specification - * http://www.w3.org/TR/xlink11/ - * - * @author Florian Haupt - * - */ -@XmlRootElement(name = "link", namespace = "http://opentosca.org/api/pp") -public class SimpleXLink { - - // XLink namespace - private static final String XLINKK_NS = "http://www.w3.org/1999/xlink"; - - private final String type = "simple"; - private String href; - private String title; - - - // required by JAXB - @SuppressWarnings("unused") - private SimpleXLink() { - super(); - } - - /** - * Constructor - * - * @param href The target of the link - * @param title The title to show - */ - public SimpleXLink(final String href, final String title) { - super(); - this.href = href; - this.title = title; - } - - /** - * Constructor - * - * @param href The target of the link - * @param title The title to show - */ - public SimpleXLink(final URI href, final String title) { - super(); - this.href = href.toString(); - this.title = title; - } - - @XmlAttribute(name = "type", namespace = XLINKK_NS, required = true) - public String getType() { - return this.type; - } - - @XmlAttribute(name = "href", namespace = XLINKK_NS) - public String getHref() { - return this.href; - } - - @XmlAttribute(name = "title", namespace = XLINKK_NS) - public String getTitle() { - return this.title; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/utilities/ArtifactAbsolutizer.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/utilities/ArtifactAbsolutizer.java deleted file mode 100644 index b9582610a..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/utilities/ArtifactAbsolutizer.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.opentosca.container.api.legacy.instancedata.utilities; - -import java.util.List; - -import javax.ws.rs.core.UriInfo; - -import org.opentosca.container.api.legacy.instancedata.LinkBuilder; -import org.opentosca.container.portability.model.Artifacts; -import org.opentosca.container.portability.model.DeploymentArtifact; -import org.opentosca.container.portability.model.ImplementationArtifact; - -/** - * This class takes Artifacts with relative references and converts the references to absolute ones - * which could be accessed from outside of the container - * - * @author Marcus Eisele - marcus.eisele@gmail.com - * - */ -public class ArtifactAbsolutizer { - - /** - * This method takes org.opentosca.portability.service.model.Artifacts and converts the - * contained references to absolute ones (before they are like - * "/IA/ApacheWebserver/start.sh" afterwards they will be external links f.ex. - * "http://localhost:1337/containerapi/csars/CSARID_1234/Content/IA/ApacheWebserver/start.sh" - * - * This is used to ensure, that all external services can use those files - * - * @param uriInfo - * @param csarID - * @param artifacts - */ - public static void absolutize(final UriInfo uriInfo, final String csarID, final Artifacts artifacts) { - - // TODO: create temp Artifacts to fallback if anything bad happens? (we - // are working on the original object here - it will be permanently - // altered if an error occurs during this operations) - final List das = artifacts.getDeploymentArtifact(); - final List ias = artifacts.getImplementationArtifact(); - - // null check of those lists because they sadly maybe null if only one - // of both type is selected - // we can't really work with empty lists because they will return in the - // result as f.ex. even when only selecting - // implArtifacts - if (das != null) { - for (final DeploymentArtifact deploymentArtifact : das) { - - if (deploymentArtifact.getReferences() != null - && deploymentArtifact.getReferences().allReferences != null) { - final List allDAReferences = deploymentArtifact.getReferences().allReferences; - for (int i = 0; i < allDAReferences.size(); i++) { - final String absolutizedRef = absolutizeReference(uriInfo, csarID, allDAReferences.get(i)); - allDAReferences.set(i, absolutizedRef); - } - } - } - } - - if (ias != null) { - for (final ImplementationArtifact implArtifact : ias) { - - if (implArtifact.getReferences() != null && implArtifact.getReferences().allReferences != null) { - final List allIAReferences = implArtifact.getReferences().allReferences; - for (int i = 0; i < allIAReferences.size(); i++) { - final String absolutizedRef = absolutizeReference(uriInfo, csarID, allIAReferences.get(i)); - allIAReferences.set(i, absolutizedRef); - } - } - } - } - - } - - private static String absolutizeReference(final UriInfo uriInfo, final String csarID, - final String relativeReference) { - return LinkBuilder.linkToFile(uriInfo, csarID, relativeReference).toString(); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/utilities/Constants.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/utilities/Constants.java deleted file mode 100644 index af21346c4..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/instancedata/utilities/Constants.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.opentosca.container.api.legacy.instancedata.utilities; - -/** - * - * @author Florian Haupt - * - */ -public class Constants { - - public static final String NodeInstanceListResource_getNodeInstance_PARAM = "id"; - - public static final String RelationInstanceListResource_getRelationInstance_PARAM = "id"; - - public static final String PP_API_NS = "http://opentosca.org/api/pp"; - - public static final String ServiceInstanceListResource_getServiceInstance_PARAM = "id"; - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/CSARInstanceManagementHandler.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/CSARInstanceManagementHandler.java deleted file mode 100644 index 71e9d0d1d..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/CSARInstanceManagementHandler.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.opentosca.container.api.legacy.osgi.servicegetter; - -import org.opentosca.container.core.service.ICSARInstanceManagementService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class to bind interface ICSARInstanceManagementService - * - * Copyright 2013 IAAS University of Stuttgart
- *
- * - * Copyright 2013 Christian Endres - * - * @author endrescn@fachschaft.informatik.uni-stuttgart.de - * - */ -public class CSARInstanceManagementHandler { - - final private static Logger LOG = LoggerFactory.getLogger(CSARInstanceManagementHandler.class); - - public static ICSARInstanceManagementService csarInstanceManagement; - - - public void bindService(final ICSARInstanceManagementService service) { - CSARInstanceManagementHandler.LOG.debug("ContainerApi: Bind ICSARInstanceManagementService"); - CSARInstanceManagementHandler.csarInstanceManagement = service; - } - - public void unbindService(final ICSARInstanceManagementService service) { - CSARInstanceManagementHandler.LOG.debug("ContainerApi: Unbind ICSARInstanceManagementService"); - CSARInstanceManagementHandler.csarInstanceManagement = null; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/CredentialsServiceHandler.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/CredentialsServiceHandler.java deleted file mode 100644 index ca484f4b1..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/CredentialsServiceHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.opentosca.container.api.legacy.osgi.servicegetter; - -import org.opentosca.container.core.service.ICoreCredentialsService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class to bind interface ICoreCredentialsService.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -public class CredentialsServiceHandler { - - final private static Logger LOG = LoggerFactory.getLogger(CredentialsServiceHandler.class); - - private static ICoreCredentialsService credentialsService; - - - public static ICoreCredentialsService getCredentialsService() { - return CredentialsServiceHandler.credentialsService; - } - - public void bindCoreCredentialsService(final ICoreCredentialsService credentialsService) { - CredentialsServiceHandler.LOG.debug("ContainerApi: Bind ICoreCredentialsService"); - CredentialsServiceHandler.credentialsService = credentialsService; - } - - public void unbindCoreCredentialsService(final ICoreCredentialsService credentialsService) { - CredentialsServiceHandler.LOG.debug("ContainerApi: Unbind ICoreCredentialsService"); - CredentialsServiceHandler.credentialsService = null; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/FileAccessServiceHandler.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/FileAccessServiceHandler.java deleted file mode 100644 index 6ac3678ff..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/FileAccessServiceHandler.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.opentosca.container.api.legacy.osgi.servicegetter; - -import org.opentosca.container.core.service.IFileAccessService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class to bind interface IFileAccessService - * - * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * - */ -public class FileAccessServiceHandler { - - final private static Logger LOG = LoggerFactory.getLogger(FileAccessServiceHandler.class); - - private static IFileAccessService fileAccessService; - - - public static IFileAccessService getFileAccessService() { - return FileAccessServiceHandler.fileAccessService; - } - - public void bind(final IFileAccessService fa) { - FileAccessServiceHandler.LOG.debug("ContainerApi: Bind IFileAccessService"); - FileAccessServiceHandler.fileAccessService = fa; - } - - public void unbind(final IFileAccessService fa) { - FileAccessServiceHandler.LOG.debug("ContainerApi: Unbind IFileAccessService"); - FileAccessServiceHandler.fileAccessService = null; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/FileRepositoryServiceHandler.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/FileRepositoryServiceHandler.java deleted file mode 100644 index bc117dc89..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/FileRepositoryServiceHandler.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.opentosca.container.api.legacy.osgi.servicegetter; - -import org.opentosca.container.core.service.ICoreFileService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class to bind interface ICoreFileService - * - * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * - */ -public class FileRepositoryServiceHandler { - - final private static Logger LOG = LoggerFactory.getLogger(FileRepositoryServiceHandler.class); - - private static ICoreFileService fileHandler; - - - public static ICoreFileService getFileHandler() { - return FileRepositoryServiceHandler.fileHandler; - } - - public void bindFileRepository(final ICoreFileService is) { - FileRepositoryServiceHandler.LOG.debug("ContainerApi: Bind ICoreFileService"); - FileRepositoryServiceHandler.fileHandler = is; - } - - public void unbindFileRepository(final ICoreFileService is) { - FileRepositoryServiceHandler.LOG.debug("ContainerApi: Unbind ICoreFileService"); - FileRepositoryServiceHandler.fileHandler = null; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/IOpenToscaControlServiceHandler.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/IOpenToscaControlServiceHandler.java deleted file mode 100644 index c090aee2e..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/IOpenToscaControlServiceHandler.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.opentosca.container.api.legacy.osgi.servicegetter; - -import org.opentosca.container.control.IOpenToscaControlService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class to bind interface IOpenToscaControlService - * - * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * - */ -public class IOpenToscaControlServiceHandler { - - final private static Logger LOG = LoggerFactory.getLogger(IOpenToscaControlServiceHandler.class); - - private static IOpenToscaControlService openToscaControl; - - - public static IOpenToscaControlService getOpenToscaControlService() { - return IOpenToscaControlServiceHandler.openToscaControl; - } - - public void bind(final IOpenToscaControlService tm) { - IOpenToscaControlServiceHandler.LOG.debug("ContainerApi: Bind IOpenToscaControlService"); - IOpenToscaControlServiceHandler.openToscaControl = tm; - } - - public void unbind(final IOpenToscaControlService tm) { - IOpenToscaControlServiceHandler.LOG.debug("ContainerApi: Unbind IOpenToscaControlService"); - IOpenToscaControlServiceHandler.openToscaControl = null; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/InstanceDataServiceHandler.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/InstanceDataServiceHandler.java deleted file mode 100644 index f62ff5771..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/InstanceDataServiceHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.opentosca.container.api.legacy.osgi.servicegetter; - -import org.opentosca.container.core.service.IInstanceDataService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class to bind interface IInstanceDataService - * - * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Marcus Eisele - marcus.eisele@gmail.com - * - */ -public class InstanceDataServiceHandler { - - final private static Logger LOG = LoggerFactory.getLogger(InstanceDataServiceHandler.class); - - private static IInstanceDataService instanceDataService; - - - public static IInstanceDataService getInstanceDataService() { - return InstanceDataServiceHandler.instanceDataService; - } - - public void bindInstanceDataService(final IInstanceDataService instanceDataService) { - InstanceDataServiceHandler.LOG.debug("ContainerApi: Bind IInstanceDataService"); - InstanceDataServiceHandler.instanceDataService = instanceDataService; - } - - public void unbindInstanceDataService(final IInstanceDataService credentialsService) { - InstanceDataServiceHandler.LOG.debug("ContainerApi: Unbind IInstanceDataService"); - InstanceDataServiceHandler.instanceDataService = null; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/ModelRepositoryServiceHandler.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/ModelRepositoryServiceHandler.java deleted file mode 100644 index e779795a7..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/ModelRepositoryServiceHandler.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.opentosca.container.api.legacy.osgi.servicegetter; - -import org.opentosca.container.core.service.ICoreModelRepositoryService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class to bind interface ICoreModelRepositoryService - * - * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * - */ -public class ModelRepositoryServiceHandler { - - final private static Logger LOG = LoggerFactory.getLogger(ModelRepositoryServiceHandler.class); - - private static ICoreModelRepositoryService modelHandler; - - - public static ICoreModelRepositoryService getModelHandler() { - return ModelRepositoryServiceHandler.modelHandler; - } - - public void bindModelRepository(final ICoreModelRepositoryService ms) { - ModelRepositoryServiceHandler.LOG.debug("ContainerApi: Bind ICoreModelRepositoryService"); - ModelRepositoryServiceHandler.modelHandler = ms; - } - - public void unbindModelRepository(final ICoreModelRepositoryService ms) { - ModelRepositoryServiceHandler.LOG.debug("ContainerApi: Unbind ICoreModelRepositoryService"); - ModelRepositoryServiceHandler.modelHandler = null; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/PlanInvocationEngineHandler.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/PlanInvocationEngineHandler.java deleted file mode 100644 index 635f1d913..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/PlanInvocationEngineHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.opentosca.container.api.legacy.osgi.servicegetter; - -import org.opentosca.container.core.service.IPlanInvocationEngine; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PlanInvocationEngineHandler { - - final private static Logger LOG = LoggerFactory.getLogger(ToscaServiceHandler.class); - - public static IPlanInvocationEngine planInvocationEngine; - - - public void bindIPlanInvocationEngineService(final IPlanInvocationEngine service) { - PlanInvocationEngineHandler.LOG.debug("ContainerApi: Bind IPlanInvocationEngine"); - PlanInvocationEngineHandler.planInvocationEngine = service; - } - - public void unbindIPlanInvocationEngineService(final IPlanInvocationEngine service) { - PlanInvocationEngineHandler.LOG.debug("ContainerApi: Unbind IPlanInvocationEngine"); - PlanInvocationEngineHandler.planInvocationEngine = null; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/PortabilityServiceHandler.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/PortabilityServiceHandler.java deleted file mode 100644 index c0278120f..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/PortabilityServiceHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.opentosca.container.api.legacy.osgi.servicegetter; - -import org.opentosca.container.portability.IPortabilityService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class to bind interface IPortabilityService.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Marcus Eisele - marcus.eisele@gmail.com - * - */ -public class PortabilityServiceHandler { - - final private static Logger LOG = LoggerFactory.getLogger(PortabilityServiceHandler.class); - - private static IPortabilityService portabilityService; - - - public static IPortabilityService getPortabilityService() { - return PortabilityServiceHandler.portabilityService; - } - - public void bindPortabilityService(final IPortabilityService portabilityService) { - PortabilityServiceHandler.LOG.debug("ContainerApi: Bind IPortabilityService"); - PortabilityServiceHandler.portabilityService = portabilityService; - } - - public void unbindPortabilityService(final IPortabilityService portabilityService) { - PortabilityServiceHandler.LOG.debug("ContainerApi: Unbind IPortabilityService"); - PortabilityServiceHandler.portabilityService = null; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/ToscaServiceHandler.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/ToscaServiceHandler.java deleted file mode 100644 index f5ad74f4a..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/osgi/servicegetter/ToscaServiceHandler.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.opentosca.container.api.legacy.osgi.servicegetter; - -import org.opentosca.container.api.legacy.Activator; -import org.opentosca.container.core.engine.IToscaEngineService; -import org.opentosca.container.core.engine.xml.IXMLSerializer; -import org.opentosca.container.core.engine.xml.IXMLSerializerService; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class to bind interface IToscaService - * - * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * - */ -public class ToscaServiceHandler { - - final private static Logger LOG = LoggerFactory.getLogger(ToscaServiceHandler.class); - - private static IXMLSerializerService xmlSerializerService; - private static IToscaEngineService toscaEngineService; - - - public static IXMLSerializer getIXMLSerializer() { - final BundleContext context = Activator.getContext(); - final ServiceReference service = - context.getServiceReference(IXMLSerializerService.class); - return context.getService(service).getXmlSerializer(); - } - - public void bindIXMLSerializerService(final IXMLSerializerService fa) { - ToscaServiceHandler.LOG.debug("ContainerApi: Bind IXMLSerializerService"); - ToscaServiceHandler.xmlSerializerService = fa; - } - - public void unbindIXMLSerializerService(final IXMLSerializerService fa) { - ToscaServiceHandler.LOG.debug("ContainerApi: Unbind IXMLSerializerService"); - ToscaServiceHandler.xmlSerializerService = null; - } - - public static IToscaEngineService getToscaEngineService() { - final BundleContext context = Activator.getContext(); - final ServiceReference service = context.getServiceReference(IToscaEngineService.class); - return context.getService(service); - } - - public void bindToscaEngineService(final IToscaEngineService fa) { - ToscaServiceHandler.LOG.debug("ContainerApi: Bind IToscaEngineService"); - ToscaServiceHandler.toscaEngineService = fa; - } - - public void unbindToscaEngineService(final IToscaEngineService fa) { - ToscaServiceHandler.LOG.debug("ContainerApi: Unbind IToscaEngineService"); - ToscaServiceHandler.toscaEngineService = null; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/portability/ArtifactsListResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/portability/ArtifactsListResource.java deleted file mode 100644 index dde93f876..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/portability/ArtifactsListResource.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.opentosca.container.api.legacy.portability; - -import javax.ws.rs.GET; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.instancedata.exception.GenericRestException; -import org.opentosca.container.api.legacy.instancedata.utilities.ArtifactAbsolutizer; -import org.opentosca.container.api.legacy.osgi.servicegetter.PortabilityServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.portability.IPortabilityService.ArtifactType; -import org.opentosca.container.portability.model.Artifacts; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This represents a List of Implementation and/or DeploymentArtifacts - * - * @author Marcus Eisele - marcus.eisele@gmail.com - * - */ -public class ArtifactsListResource { - - private static final Logger LOG = LoggerFactory.getLogger(ArtifactsListResource.class); - - - @GET - @Produces(MediaType.APPLICATION_XML) - // example: - // localhost:1337/containerapi/portability/artifacts?csarID=TestLifeCycle.csar&targetNamespace=org.opentosca.demo&serviceTemplateID=TestLifeCycleDemo_ServiceTemplate&templateID=TestLifeCycleDemoNodeTemplate&artifactType=DA - public Response getArtifacts(@Context final UriInfo uriInfo, @QueryParam("csarID") final String csarID, - @QueryParam("targetNamespace") final String namespace, - @QueryParam("serviceTemplateID") final String serviceTemplateID, - @QueryParam("templateID") final String templateID, - @QueryParam("artifactType") final String artifactType, - @QueryParam("deploymentArtifactName") final String deploymentArtifactName, - @QueryParam("interfaceName") final String interfaceName, - @QueryParam("operationName") final String operationName) { - - if (Utilities.areEmpty(csarID, namespace, serviceTemplateID, templateID, artifactType)) { - throw new GenericRestException(Status.BAD_REQUEST, - "one of the required parameters: csarID, targetNamespace, serviceTemplateID, templateID, artifactType was not set"); - } - - CSARID csarID_csarID; - QName qname_serviceTemplateID; - QName qname_templateID; - ArtifactType artType = null; - - csarID_csarID = new CSARID(csarID); - qname_serviceTemplateID = new QName(namespace, serviceTemplateID); - qname_templateID = new QName(namespace, templateID); - // map artifactType to enumeration - artType = ArtifactType.valueOf(artifactType.toUpperCase()); - - if (PortabilityServiceHandler.getPortabilityService().isNodeTemplate(csarID_csarID, qname_serviceTemplateID, - qname_templateID)) { - - LOG.trace(templateID + " is a NodeTemplate."); - - final Artifacts artifacts = - PortabilityServiceHandler.getPortabilityService() - .getNodeTemplateArtifacts(csarID_csarID, qname_serviceTemplateID, - qname_templateID, artType, deploymentArtifactName, - interfaceName, operationName); - // use absolutizer to build absolute paths - ArtifactAbsolutizer.absolutize(uriInfo, csarID, artifacts); - // return - - LOG.trace("everything done and ok"); - - return Response.ok(artifacts).build(); - } else { - - LOG.trace(templateID + " is a RelationshipTemplate."); - - final Artifacts artifacts = - PortabilityServiceHandler.getPortabilityService() - .getRelationshipTemplateArtifacts(csarID_csarID, qname_serviceTemplateID, - qname_templateID, artType, - deploymentArtifactName, interfaceName, - operationName); - // use absolutizer to build absolute paths - ArtifactAbsolutizer.absolutize(uriInfo, csarID, artifacts); - // return - return Response.ok(artifacts).build(); - } - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/portability/PoliciesListResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/portability/PoliciesListResource.java deleted file mode 100644 index ff95766c3..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/portability/PoliciesListResource.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.opentosca.container.api.legacy.portability; - -import javax.ws.rs.GET; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Response.Status; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.instancedata.exception.GenericRestException; -import org.opentosca.container.api.legacy.osgi.servicegetter.ToscaServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.tosca.model.TBoundaryDefinitions; -import org.opentosca.container.core.tosca.model.TBoundaryDefinitions.Policies; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This resource handles the request to query for consolidatedPolicies - * - * @author Marcus Eisele - marcus.eisele@gmail.com - * - */ -public class PoliciesListResource { - - private static final Logger LOG = LoggerFactory.getLogger(PoliciesListResource.class); - - - /** - * Returns the policies for the specified parameters - * - * @param csarID csarID of the service/nodeTemplate - * @param serviceTemplateID serviceTemplateID - * @param nodeTemplateID nodeTemplateID - * @return - */ - @GET - @Produces(ResourceConstants.TOSCA_XML) - // arID=TestLifeCycle.csar&namespace=org.opentosca.demo&serviceTemplateID=TestLifeCycleDemo_ServiceTemplate&nodeTemplateName=TestLifeCycleDemoNodeTemplate - public TBoundaryDefinitions.Policies getPolicies(@QueryParam("csarID") final String csarID, - @QueryParam("namespace") final String namespaceServiceTemplate, - @QueryParam("serviceTemplateID") final String serviceTemplateID, - @QueryParam("nodeTemplateID") final String nodeTemplateID) { - - if (Utilities.areEmpty(csarID, serviceTemplateID)) { - throw new GenericRestException(Status.BAD_REQUEST, - "one of the required parameters: csarID, serviceTemplateID was not set"); - } - - if (null == ToscaServiceHandler.getToscaEngineService()) { - PoliciesListResource.LOG.error("ToscaEngineService is null!"); - return null; - } - - CSARID csarID_csarID; - QName templateID = null; - - try { - csarID_csarID = new CSARID(csarID); - // determine which ID to use - if (nodeTemplateID == null) { - templateID = new QName(namespaceServiceTemplate, serviceTemplateID); - } else { - templateID = new QName(namespaceServiceTemplate, nodeTemplateID); - } - } - catch (final Exception e) { - throw new GenericRestException(Status.BAD_REQUEST, - "error converting one of the parameters: " + e.getMessage()); - } - - // FIXME: use TOSCA Engine method providing this instead of - // ToscaReferenceMapper this is just to return - // something "correct" at the moment - Policies policies = ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper() - .getPolicies(csarID_csarID, templateID); - - if (policies == null) { - policies = new Policies(); - } - - return policies; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/portability/PortabilityEntry.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/portability/PortabilityEntry.java deleted file mode 100644 index f0b8324d3..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/portability/PortabilityEntry.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.opentosca.container.api.legacy.portability; - -import java.util.LinkedList; -import java.util.List; - -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -import org.opentosca.container.api.legacy.instancedata.model.SimpleXLink; - -/** - * - * @author Marcus Eisele - * - */ -@XmlRootElement(name = "PortabilityAPI") -public class PortabilityEntry { - - private final String version = "0.1"; - - private List links = new LinkedList<>(); - - protected PortabilityEntry() { - super(); - } - - public PortabilityEntry(final List links) { - super(); - this.links = links; - } - - @XmlAttribute(name = "version", required = true) - public String getVersion() { - return this.version; - } - - @XmlElement(name = "Link") - public List getLinks() { - return this.links; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/portability/PortabilityRoot.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/portability/PortabilityRoot.java deleted file mode 100644 index 3974e7c4f..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/portability/PortabilityRoot.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.opentosca.container.api.legacy.portability; - -import java.util.LinkedList; -import java.util.List; - -import javax.ws.rs.GET; -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.Response; -import javax.ws.rs.core.UriInfo; - -import org.opentosca.container.api.legacy.instancedata.LinkBuilder; -import org.opentosca.container.api.legacy.instancedata.model.SimpleXLink; - -/** - * Root-Resource represents all the portabilityAPI and all its features by linking to additional - * Resources
- * - * @author Marcus Eisele - marcus.eisele@gmail.com - * - */ - -@Path("/portability") -public class PortabilityRoot { - - @Context - UriInfo uriInfo; - @Context - Request request; - - @GET - @Produces(MediaType.APPLICATION_XML) - public Response doGet() { - - final List links = new LinkedList<>(); - links.add(LinkBuilder.selfLink(this.uriInfo)); - links.add(new SimpleXLink(LinkBuilder.linkToArtifactList(this.uriInfo), "Artifacts")); - links.add(new SimpleXLink(LinkBuilder.linkToPoliciesList(this.uriInfo), "Policies")); - - final PortabilityEntry pe = new PortabilityEntry(links); - - return Response.ok(pe).build(); - } - - @Path("/artifacts") - public Object getArtifacts() { - return new ArtifactsListResource(); - } - - @Path("/policies") - public Object getPolicies() { - return new PoliciesListResource(); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/RootResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/RootResource.java deleted file mode 100644 index af5f396d4..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/RootResource.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.opentosca.container.api.legacy.resources; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Request; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; - -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * RootResource at Uri: host/containerapi - * - * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer - fischema@studi.informatik.uni-stuttgart.de - * @author Rene Trefft - trefftre@studi.informatik.uni-stuttgart.de - * - */ -@Path("") -public class RootResource { - - final private static Logger LOG = LoggerFactory.getLogger(RootResource.class); - - @Context - UriInfo uriInfo; - @Context - Request request; - - - public RootResource() { - RootResource.LOG.debug("{} created: {}", this.getClass(), this); - } - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML() { - - return Response.ok(this.getRefs().getXMLString()).build(); - - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON() { - - return Response.ok(this.getRefs().getJSONString()).build(); - - } - - private References getRefs() { - - final References refs = new References(); - - refs.getReference(); - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "CSARs"), - XLinkConstants.SIMPLE, "CSARs")); - - // refs.getReference().add(new - // Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), - // "AllDefinitions"), XLinkConstants.SIMPLE, "AllDefinitions")); - // refs.getReference().add(new - // Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), - // "CSARFiles"), XLinkConstants.SIMPLE, "CSARFiles")); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "CSARControl"), - XLinkConstants.SIMPLE, "CSARControl")); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "Credentials"), - XLinkConstants.SIMPLE, "Credentials")); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "StorageProviders"), - XLinkConstants.SIMPLE, "StorageProviders")); - - // InstanceData API and PortabilityAPI - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "instancedata"), - XLinkConstants.SIMPLE, "instancedata")); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "portability"), - XLinkConstants.SIMPLE, "portability")); - - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "SmartServices"), - XLinkConstants.SIMPLE, "SmartServices")); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "planbuilder"), - XLinkConstants.SIMPLE, "planbuilder")); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "marketplace"), - XLinkConstants.SIMPLE, "marketplace")); - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "packager"), - XLinkConstants.SIMPLE, "packager")); - - RootResource.LOG.debug("Number of References in Root: {}", refs.getReference().size()); - // selflink - - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return refs; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/credentials/AllCredentialsResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/credentials/AllCredentialsResource.java deleted file mode 100644 index e0ee57262..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/credentials/AllCredentialsResource.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.opentosca.container.api.legacy.resources.credentials; - -import java.net.URI; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Request; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; - -import org.opentosca.container.api.legacy.osgi.servicegetter.CredentialsServiceHandler; -import org.opentosca.container.api.legacy.resources.credentials.jaxb.AllCredentialsJaxb; -import org.opentosca.container.api.legacy.resources.credentials.jaxb.JaxbFactory; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.core.common.UserException; -import org.opentosca.container.core.model.credentials.Credentials; -import org.opentosca.container.core.service.ICoreCredentialsService; - -/** - * Resource of all credentials of the Core Credentials Service.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -@Path("/Credentials") -public class AllCredentialsResource { - - // private static Logger LOG = - // LoggerFactory.getLogger(AllCredentialsResource.class); - - private final ICoreCredentialsService CREDENTIALS_SERVICE = CredentialsServiceHandler.getCredentialsService(); - - @Context - private UriInfo uriInfo; - @Context - private Request request; - - - /** - * @return 200 (OK) with entity {@link AllCredentialsJaxb} containing all credentials. - */ - @GET - @Produces(MediaType.APPLICATION_XML) - public Response getAllCredentialsXML(@QueryParam("storageProviderID") final String storageProviderID) { - return Response.ok(JaxbFactory.createAllCredentialsJaxb(storageProviderID)).build(); - } - - /** - * Creates a {@link CredentialsResource} of credentials {@code credentialsIDAsString}. If these - * credentials are not stored it will be created with {@code null}.
- *
- * A resource of credentials is located at:
- * {@code ...\} - * - * @param credentialsIDAsString of credentials - * @return {@link CredentialsResource} - * @throws UserException - */ - @Path("{credentialsID}") - public CredentialsResource getCredentialsResource(@PathParam("credentialsID") final String credentialsIDAsString) throws UserException { - - Credentials credentials = null; - - try { - final long credentialsID = Long.parseLong(credentialsIDAsString); - credentials = this.CREDENTIALS_SERVICE.getCredentials(credentialsID); - } - catch (final NumberFormatException exc) { - throw new UserException("Credentials ID must be a whole number.", exc); - } - - return new CredentialsResource(credentials); - - } - - /** - * Stores the {@code credentials} given as XML in the body of a POST message in the Core Credentials - * Service. - * - * @param credentials to store. - * @return 200 (OK) - credentials were successfully stored.
- * 500 (internal server error) - storing credentials failed. - * @throws UserException - * - * @see Credentials - * @see ICoreCredentialsService#storeCredentials(Credentials) - */ - @POST - @Consumes(MediaType.APPLICATION_XML) - @Produces(MediaType.TEXT_PLAIN) - public Response storeCredentials(final Credentials credentials) throws UserException { - - // try { - - final Long credentialsID = this.CREDENTIALS_SERVICE.storeCredentials(credentials); - - return Response.created(URI.create(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), - Long.toString(credentialsID)))) - .build(); - - // } catch (UserException exc) { - // AllCredentialsResource.LOG.warn("An User Exception occured.", exc); - // } - - // return Response.status(Status.INTERNAL_SERVER_ERROR).build(); - - } - - /** - * Deletes all credentials in the Core Credentials Service in case of a DELETE message (with - * arbitrary body). - * - * @param input - * @return 200 (OK) - * - * @see Credentials - * @see ICoreCredentialsService#deleteAllCredentials() - */ - @DELETE - @Consumes(MediaType.TEXT_PLAIN) - @Produces(ResourceConstants.TEXT_PLAIN) - public Response deleteAllCredentials() { - - this.CREDENTIALS_SERVICE.deleteAllCredentials(); - return Response.ok("All credentials were deleted.").build(); - - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/credentials/CredentialsResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/credentials/CredentialsResource.java deleted file mode 100644 index 89226bce9..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/credentials/CredentialsResource.java +++ /dev/null @@ -1,170 +0,0 @@ -package org.opentosca.container.api.legacy.resources.credentials; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; - -import org.opentosca.container.api.legacy.osgi.servicegetter.CredentialsServiceHandler; -import org.opentosca.container.api.legacy.resources.credentials.jaxb.CredentialsJaxb; -import org.opentosca.container.api.legacy.resources.credentials.jaxb.JaxbFactory; -import org.opentosca.container.core.common.SystemException; -import org.opentosca.container.core.common.UserException; -import org.opentosca.container.core.model.credentials.Credentials; -import org.opentosca.container.core.service.ICoreCredentialsService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Resource of credentials of the Core Credentials Service.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -public class CredentialsResource { - - private static Logger LOG = LoggerFactory.getLogger(CredentialsResource.class); - - private final ICoreCredentialsService CREDENTIALS_SERVICE = CredentialsServiceHandler.getCredentialsService(); - - /** - * If {@code null} it's a not existing credentials and every method returns 404 (not found). - */ - private final Credentials CREDENTIALS; - - - /** - * Creates a {@link CredentialsResource} of {@code credentials}. - * - * @param credentials - */ - public CredentialsResource(final Credentials credentials) { - CredentialsResource.LOG.debug("{} created: {}", this.getClass(), this); - this.CREDENTIALS = credentials; - } - - /** - * @return 200 (OK) with entity {@link CredentialsJaxb} containing the credentials to show. If - * credentials not exist 404 (not found). - */ - @GET - @Produces(MediaType.APPLICATION_XML) - public Response getCredentials() { - - if (this.CREDENTIALS == null) { - return Response.status(Status.NOT_FOUND).build(); - } - - return Response.ok(JaxbFactory.createCredentialsJaxb(this.CREDENTIALS)).build(); - - } - - /** - * Deletes this credentials in the Core Credentials Service. - * - * @return 200 (OK) - credentials were deleted.
- * 404 (not found) - credentials don't exist.
- * 500 (internal server error) - deleting failed. - * @throws UserException - * - * @see Credentials - * @see ICoreCredentialsService#deleteCredentials(String, String) - */ - @DELETE - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.TEXT_PLAIN) - public Response deleteCredentials() throws UserException { - - if (this.CREDENTIALS == null) { - return Response.status(Status.NOT_FOUND).build(); - } - - // try { - - this.CREDENTIALS_SERVICE.deleteCredentials(this.CREDENTIALS.getID()); - return Response.ok("Credentials for storage provider \"" + this.CREDENTIALS.getStorageProviderID() - + "\" were deleted.").build(); - - // } catch (UserException exc) { - // CredentialsResource.LOG.warn("An User Exception occured.", exc); - // } - - // return Response.status(Status.INTERNAL_SERVER_ERROR).build(); - - } - - /** - * Sets or deletes these credentials in their storage provider if {@code set} respectively - * {@code unset} is passed in {@code input} (body of a POST message). - * - * @param input - * @return 200 (OK) - credentials were set respectively deleted in their storage provider.
- * 400 (bad request) - credentials are currently not set in their storage provider or - * neither {@code set} nor {@code unset} were passed.
- * 404 (not found) - credentials don't exist.
- * 500 (internal server error) - setting / deleting credentials failed. - * @throws SystemException - * @throws UserException - * - * @see ICoreCredentialsService#setCredentialsInStorageProvider(String, String) - * @see ICoreCredentialsService#hasStorageProviderCredentials(Long) - * @see ICoreCredentialsService#deleteCredentialsInStorageProvider(String) - */ - @POST - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.TEXT_PLAIN) - public Response setOrUnsetCredentialsInStorageProvider(final String input) throws SystemException, UserException { - - if (this.CREDENTIALS == null) { - return Response.status(Status.NOT_FOUND).build(); - } - - final long credentialsID = this.CREDENTIALS.getID(); - final String storageProviderID = this.CREDENTIALS.getStorageProviderID(); - - // try { - - if (input.equalsIgnoreCase("set")) { - - this.CREDENTIALS_SERVICE.setCredentialsInStorageProvider(credentialsID); - return Response.ok("Credentials \"" + credentialsID + "\" were set in their storage provider \"" - + storageProviderID + "\".").build(); - - } else if (input.equalsIgnoreCase("unset")) { - - // we must check at first if storage provider has currently - // these credentials - final boolean hasThisCredentials = this.CREDENTIALS_SERVICE.hasStorageProviderCredentials(credentialsID); - - if (hasThisCredentials) { - this.CREDENTIALS_SERVICE.deleteCredentialsInStorageProvider(storageProviderID); - return Response.ok("Credentials \"" + credentialsID + "\" were deleted in their storage provider \"" - + storageProviderID + "\".").build(); - } else { - return Response.status(Status.BAD_REQUEST).entity("Credentials \"" + credentialsID - + "\" are not set in their storage provider \"" + storageProviderID + "\".").build(); - } - - } else { - - return Response.status(Status.BAD_REQUEST).build(); - - } - - // } catch (UserException exc) { - // CredentialsResource.LOG.warn("A User exception occured.", exc); - // } catch (SystemException exc) { - // CredentialsResource.LOG.warn("A System exception occured.", exc); - // } - - // return Response.status(Status.INTERNAL_SERVER_ERROR).build(); - - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/credentials/jaxb/AllCredentialsJaxb.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/credentials/jaxb/AllCredentialsJaxb.java deleted file mode 100644 index ff9b8a478..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/credentials/jaxb/AllCredentialsJaxb.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.opentosca.container.api.legacy.resources.credentials.jaxb; - -import java.util.Set; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -import org.opentosca.container.api.legacy.resources.credentials.AllCredentialsResource; - -/** - * JAXB annotated class that represents a set of credentials.
- * It will be created by {@link JaxbFactory} and used in {@link AllCredentialsResource}.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -@XmlRootElement(name = "AllCredentials") -@XmlAccessorType(XmlAccessType.FIELD) -public class AllCredentialsJaxb { - - @XmlElement(name = "Credentials") - private Set allCredentials; - - - /** - * - * @return All Credentials. - */ - public Set getCredentials() { - return this.allCredentials; - } - - /** - * Sets all {@code credentials}. - * - * @param credentials to set. - */ - public void setCredentials(final Set allCredentials) { - this.allCredentials = allCredentials; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/credentials/jaxb/CredentialsJaxb.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/credentials/jaxb/CredentialsJaxb.java deleted file mode 100644 index db1d87db3..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/credentials/jaxb/CredentialsJaxb.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.opentosca.container.api.legacy.resources.credentials.jaxb; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -import org.opentosca.container.api.legacy.resources.credentials.AllCredentialsResource; -import org.opentosca.container.api.legacy.resources.credentials.CredentialsResource; -import org.opentosca.container.core.model.credentials.Credentials; - -/** - * JAXB annotated class that represents credentials (extends {@link Credentials} ) with additional - * information if the credentials are set in their storage provider or not.
- * It will be created by - * {@link org.opentosca.container.api.legacy.resources.credentials.jaxb.JaxbFactory} and used in - * {@link AllCredentialsResource} and {@link CredentialsResource}.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -@XmlRootElement(name = "Credentials") -@XmlAccessorType(XmlAccessType.FIELD) -public class CredentialsJaxb extends Credentials { - - @XmlElement(name = "InjectedInStorageProvider") - private boolean injectedInStorageProvider; - - - /** - * Needed by Jersey. - */ - protected CredentialsJaxb() { - - } - - /** - * Creates {@code CredentialsJaxb} with all data of {@code credentials}. - * - * @param credentials - */ - public CredentialsJaxb(final Credentials credentials) { - this.setID(credentials.getID()); - this.setStorageProviderID(credentials.getStorageProviderID()); - this.setIdentity(credentials.getIdentity()); - this.setKey(credentials.getKey()); - this.setDescription(credentials.getDescription()); - } - - /** - * - * @return {@true} if these credentials are set in the appropriate storage provider, otherwise - * {@code false}. - */ - public boolean isInjectedInStorageProvider() { - return this.injectedInStorageProvider; - } - - /** - * Sets that these credentials are set in a storage provider or not. - * - * @param injectedInStorageProvider to set. - */ - public void setInjectedInStorageProvider(final boolean injectedInStorageProvider) { - this.injectedInStorageProvider = injectedInStorageProvider; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/credentials/jaxb/JaxbFactory.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/credentials/jaxb/JaxbFactory.java deleted file mode 100644 index 6abc11612..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/credentials/jaxb/JaxbFactory.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.opentosca.container.api.legacy.resources.credentials.jaxb; - -import java.util.HashSet; -import java.util.Set; - -import org.opentosca.container.api.legacy.osgi.servicegetter.CredentialsServiceHandler; -import org.opentosca.container.api.legacy.resources.credentials.AllCredentialsResource; -import org.opentosca.container.api.legacy.resources.credentials.CredentialsResource; -import org.opentosca.container.core.common.UserException; -import org.opentosca.container.core.model.credentials.Credentials; -import org.opentosca.container.core.service.ICoreCredentialsService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Creates the JAXB objects for the {@link AllCredentialsResource} and - * {@link CredentialsResource}.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -public class JaxbFactory { - - private final static Logger LOG = LoggerFactory.getLogger(JaxbFactory.class); - - private static ICoreCredentialsService credentialsService = CredentialsServiceHandler.getCredentialsService(); - - - /** - * @return {@link AllCredentialsJaxb} containing stored credentials for storage provider - * {@code storageProviderID}. If {@code null} or an empty string is passed instead all - * stored credentials are contained.
- * Necessary data will be fetched from {@link ICoreCredentialsService}.
- * - * @see #createCredentialsJaxb(Credentials) - */ - public static AllCredentialsJaxb createAllCredentialsJaxb(final String storageProviderID) { - - Set allCredentials; - - if (storageProviderID == null || storageProviderID.isEmpty()) { - allCredentials = JaxbFactory.credentialsService.getAllCredentials(); - } else { - allCredentials = JaxbFactory.credentialsService.getAllCredentialsOfStorageProvider(storageProviderID); - } - - final Set credentialsJaxbSet = new HashSet<>(); - - for (final Credentials credentials : allCredentials) { - final CredentialsJaxb credentialsJaxb = JaxbFactory.createCredentialsJaxb(credentials); - credentialsJaxbSet.add(credentialsJaxb); - } - - final AllCredentialsJaxb allCredentialsJaxb = new AllCredentialsJaxb(); - allCredentialsJaxb.setCredentials(credentialsJaxbSet); - - return allCredentialsJaxb; - - } - - /** - * Builds {@link CredentialsJaxb} of credentials {@code credentials}. It contains additionally the - * information if these credentials are currently set in their storage provider (if storage provider - * is not available it's {@code false}).
- * Necessary data will be fetched from {@link ICoreCredentialsService}.
- * - * @param credentials - * @return {@link CredentialsJaxb} of credentials {@code credentials} - */ - public static CredentialsJaxb createCredentialsJaxb(final Credentials credentials) { - - final CredentialsJaxb credentialsJaxb = new CredentialsJaxb(credentials); - - final long credentialsID = credentials.getID(); - - try { - final boolean injectedInStorageProvider = - JaxbFactory.credentialsService.hasStorageProviderCredentials(credentialsID); - credentialsJaxb.setInjectedInStorageProvider(injectedInStorageProvider); - } - catch (final UserException exc) { - JaxbFactory.LOG.warn("An User Exception occured.", exc); - } - - return credentialsJaxb; - - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/CSARIDResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/CSARIDResource.java deleted file mode 100644 index c8e2e356c..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/CSARIDResource.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar; - -import javax.ws.rs.GET; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Response; - -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.core.model.csar.id.CSARID; - -/** - * The Class is used to provide an easy way to retrieve the ID of a CSAR file without analyzing its - * URI Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * @author Rene Trefft - trefftre@studi.informatik.uni-stuttgart.de - * - */ -public class CSARIDResource { - - private final CSARID csarID; - - - public CSARIDResource(final CSARID csarID) { - this.csarID = csarID; - } - - @GET - @Produces(ResourceConstants.TEXT_PLAIN) - public Response getCSARID() { - return Response.ok(this.csarID.toString()).build(); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/CSARResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/CSARResource.java deleted file mode 100644 index ae830610a..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/CSARResource.java +++ /dev/null @@ -1,270 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.util.List; -import java.util.Objects; - -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -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.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; - -import org.opentosca.container.api.legacy.osgi.servicegetter.FileRepositoryServiceHandler; -import org.opentosca.container.api.legacy.osgi.servicegetter.IOpenToscaControlServiceHandler; -import org.opentosca.container.api.legacy.resources.csar.content.ContentResource; -import org.opentosca.container.api.legacy.resources.csar.content.DirectoryResource; -import org.opentosca.container.api.legacy.resources.csar.content.FileResource; -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.ServiceTemplatesResource; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.common.SystemException; -import org.opentosca.container.core.common.UserException; -import org.opentosca.container.core.model.AbstractFile; -import org.opentosca.container.core.model.csar.CSARContent; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.service.ICoreFileService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Resource represents a CSAR.
- *
- * - * - * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - trefftre@studi.informatik.uni-stuttgart.de - * @author christian.endres@iaas.uni-stuttgart.de - * - * - */ -public class CSARResource { - - private static final Logger LOG = LoggerFactory.getLogger(ContentResource.class); - - // If csar is null, CSAR is not stored - private final CSARContent CSAR; - UriInfo uriInfo; - - - public CSARResource(final CSARContent csar) { - Objects.requireNonNull(csar); - - this.CSAR = csar; - CSARResource.LOG.info("{} created: {}", this.getClass(), this); - } - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getJSONString()).build(); - } - - public References getRefs() { - - if (this.CSAR == null) { - return null; - } - - final References refs = new References(); - - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "Content"), - XLinkConstants.SIMPLE, "Content")); - // refs.getReference().add(new - // Reference(Utilities.buildURI(uriInfo.getAbsolutePath().toString(), - // "BoundaryDefinitions"), XLinkConstants.SIMPLE, - // "BoundaryDefinitions")); - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "MetaData"), - XLinkConstants.SIMPLE, "MetaData")); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "ServiceTemplates"), - XLinkConstants.SIMPLE, "ServiceTemplates")); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "TopologyPicture"), - XLinkConstants.SIMPLE, "TopologyPicture")); - - // TODO both following links (PlanInstances, PlanResults) have to be - // replaced as soon as the instance data api is merged into here - // refs.getReference().add(new - // Reference(Utilities.buildURI(uriInfo.getAbsolutePath().toString(), - // "PlanInstances"), XLinkConstants.SIMPLE, "PlanInstances")); - // refs.getReference().add(new - // Reference(Utilities.buildURI(uriInfo.getAbsolutePath().toString(), - // "PlanResults"), XLinkConstants.SIMPLE, "PlanResults")); - - // refs.getReference().add(new - // Reference(Utilities.buildURI(uriInfo.getAbsolutePath().toString(), - // "Instances"), XLinkConstants.SIMPLE, "Instances")); - CSARResource.LOG.info("Number of References in Root: {}", refs.getReference().size()); - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return refs; - } - - @Path("Content") - public ContentResource getContent() { - return new ContentResource(this.CSAR); - - } - - // @Path("BoundaryDefinitions") - // public BoundsResource getBoundaryDefs() { - // return new BoundsResource(CSAR.getCSARID()); - // } - - // @Path("Plans") - // public CSARPlansResource getPuplicPlans() { - // return new CSARPlansResource(CSAR.getCSARID()); - // } - - // @Path("Instances") - // public InstancesResource getInstances() { - // return new InstancesResource(CSAR.getCSARID()); - // } - - // "image/*" will be preferred over "text/xml" when requesting an image. - // This is a fix for Webkit Browsers who are too dumb for content - // negotiation. - - @Produces("image/*; qs=2.0") - @GET - @Path("TopologyPicture") - public Response getTopologyPicture() throws SystemException { - - final AbstractFile topologyPicture = this.CSAR.getTopologyPicture(); - - if (topologyPicture != null) { - final MediaType mt = new MediaType("image", "*"); - - // try { - final InputStream is = topologyPicture.getFileAsInputStream(); - return Response.ok(is, mt) - .header("Content-Disposition", "attachment; filename=\"" + topologyPicture.getName() + "\"") - .build(); - // } catch (SystemException exc) { - // CSARResource.LOG.error("An System Exception occured.", exc); - // } - - } - return Response.status(Status.NOT_FOUND).type(MediaType.TEXT_PLAIN) - .entity("No Topology Picture exists in CSAR \"" + this.CSAR.getCSARID() + "\".").build(); - } - - @GET - @Path("MetaData") - @Produces(ResourceConstants.APPLICATION_JSON) - public Response getMetaDataJSON() throws SystemException { - // /containerapi/CSARs/MongoDB_On_VSphere.csar/Content/SELFSERVICE-Metadata/data.json - - final DirectoryResource dir = - (DirectoryResource) new ContentResource(this.CSAR).getDirectoryOrFile("SELFSERVICE-Metadata"); - final FileResource file = (FileResource) dir.getDirectoryOrFile("data.json"); - - - CSARResource.LOG.trace("Metadata file is of class: {}", file.getClass()); - - return Response.status(Status.OK).type(MediaType.APPLICATION_JSON).entity(file.getAsJSONString()).build();// .type(MediaType.TEXT_PLAIN).entity("No - // Topology - // Picture - // exists - // in - // CSAR - // \"" - // + - // CSAR.getCSARID() - // + - // "\".").build(); - } - - @Path("ServiceTemplates") - public ServiceTemplatesResource getServiceTemplates() { - - return new ServiceTemplatesResource(this.CSAR); - } - - /** - * Exports this CSAR. - * - * @return CSAR as {@code application/octet-stream}. If an error occurred during exporting (e.g. - * during retrieving files from storage provider(s)) 500 (internal server error). - * @throws SystemException - * @throws UserException - * - * @see ICoreFileService#exportCSAR(CSARID) - * - */ - @GET - @Produces(ResourceConstants.OCTET_STREAM) - public Response downloadCSAR() throws SystemException, UserException { - - final CSARID csarID = this.CSAR.getCSARID(); - - // try { - - final java.nio.file.Path csarFile = FileRepositoryServiceHandler.getFileHandler().exportCSAR(csarID); - InputStream csarFileInputStream; - - try { - csarFileInputStream = Files.newInputStream(csarFile); - } - catch (final IOException e) { - throw new SystemException("Retrieving input stream of file \"" + csarFile.toString() + "\" failed.", e); - } - - // We add Content Disposition header, because exported CSAR file to - // download should have the correct file name. - return Response.ok("CSAR \"" + csarID + "\" was successfully exported to \"" + csarFile + "\".") - .entity(csarFileInputStream) - .header("Content-Disposition", "attachment; filename=\"" + csarID.getFileName() + "\"").build(); - - } - - @DELETE - @Produces("text/plain") - public Response delete() { - - final CSARID csarID = this.CSAR.getCSARID(); - - CSARResource.LOG.info("Deleting CSAR \"{}\".", csarID); - final List errors = IOpenToscaControlServiceHandler.getOpenToscaControlService().deleteCSAR(csarID); - - // if (errors.contains("CSAR has instances.")) { - // return Response.notModified("CSAR has instances.").build(); - // } - - if (errors.isEmpty()) { - return Response.ok("Deletion of CSAR " + "\"" + csarID + "\" was sucessful.").build(); - } else { - String errorList = ""; - for (final String err : errors) { - errorList = errorList + err + "\\n"; - } - return Response.status(Status.INTERNAL_SERVER_ERROR) - .entity("Deletion of CSAR \"" + csarID + "\" failed with errors: " + errorList).build(); - } - - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/CSARsResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/CSARsResource.java deleted file mode 100644 index 20fc40fcf..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/CSARsResource.java +++ /dev/null @@ -1,539 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -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.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.glassfish.jersey.media.multipart.FormDataContentDisposition; -import org.glassfish.jersey.media.multipart.FormDataParam; -import org.opentosca.container.api.legacy.osgi.servicegetter.FileAccessServiceHandler; -import org.opentosca.container.api.legacy.osgi.servicegetter.FileRepositoryServiceHandler; -import org.opentosca.container.api.legacy.osgi.servicegetter.IOpenToscaControlServiceHandler; -import org.opentosca.container.api.legacy.osgi.servicegetter.ToscaServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ModelUtils; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.connector.winery.WineryConnector; -import org.opentosca.container.control.IOpenToscaControlService; -import org.opentosca.container.core.common.SystemException; -import org.opentosca.container.core.common.UserException; -import org.opentosca.container.core.model.csar.CSARContent; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.service.ICoreFileService; -import org.opentosca.planbuilder.export.Exporter; -import org.opentosca.planbuilder.importer.Importer; -import org.opentosca.planbuilder.model.plan.AbstractPlan; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -/** - * Resource represents all CSARs.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - trefftre@studi.informatik.uni-stuttgart.de - * @author Christian Endres - endrescn@studi.informatik.uni-stuttgart.de - * - */ -@Path("/CSARs") -public class CSARsResource { - - private static final Logger LOG = LoggerFactory.getLogger(CSARsResource.class); - - private final ICoreFileService fileHandler; - private final IOpenToscaControlService control; - - @Context - UriInfo uriInfo; - @Context - Request request; - - - public CSARsResource() { - this.fileHandler = FileRepositoryServiceHandler.getFileHandler(); - this.control = IOpenToscaControlServiceHandler.getOpenToscaControlService(); - CSARsResource.LOG.debug("{} created: {}", this.getClass(), this); - } - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML() { - return Response.ok(getRefs().getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON() { - return Response.ok(getRefs().getJSONString()).build(); - } - - public References getRefs() { - final References refs = new References(); - for (final CSARID csarID : this.fileHandler.getCSARIDs()) { - final Reference ref = - new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), csarID.toString()), - XLinkConstants.SIMPLE, csarID.toString()); - refs.getReference().add(ref); - - CSARsResource.LOG.debug("CSAR \"{}\" added as Reference.", csarID); - - } - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return refs; - } - - /** - * Stores the CSAR file at {@code fileLocation} (absolute path on the local file system) in the - * Container. - * - * @param fileLocation - * @return - * @throws SystemException - * @throws UserException - * @throws URISyntaxException - * @throws IOException - */ - @POST - @Consumes(MediaType.TEXT_PLAIN) - public Response uploadCSAR(final String fileLocation) throws UserException, SystemException, IOException, - URISyntaxException { - CSARsResource.LOG.info("Upload file from location: {}", fileLocation); - - try { - - final java.nio.file.Path csarFile = Paths.get(fileLocation.trim()); - - // try { - return handleCSAR(csarFile.getFileName().toString(), Files.newInputStream(csarFile)); - - } - catch (final java.nio.file.InvalidPathException exc) { - - final java.nio.file.Path csarFile = Paths.get(fileLocation.trim()); - - // try { - return handleCSAR(csarFile.getFileName().toString(), Files.newInputStream(csarFile)); - - } - } - - @POST - @Consumes(ResourceConstants.APPLICATION_JSON) - @Produces(ResourceConstants.APPLICATION_JSON) - public Response uploadCSARAdminUI(final String json) throws MalformedURLException { - - CSARsResource.LOG.debug("Received payload for uploading CSAR:\\n {}", json); - - final JsonParser parser = new JsonParser(); - final JsonObject jsonObj = (JsonObject) parser.parse(json); - - String urlStr = jsonObj.get("URL").toString(); - urlStr = urlStr.substring(1, urlStr.length() - 1); - - // if ((null == url) || url.equals("")) { - // CSARsResource.LOG.error("The url is null or empty."); - // return Response.serverError().build(); - // } - - String fileName = ""; - URL url = null; - try { - - // http://ds/joomla/images/a%25.txt to - // http://ds/joomla/images/a%2525.txt - - // String urlStr = url.toExternalForm(); - // urlStr = urlStr.substring(0, urlStr.lastIndexOf("/") + 1) + - // Utilities.encodeURIPath((urlStr.substring(urlStr.lastIndexOf("/") - // + 1))); - url = new URL(urlStr); - CSARsResource.LOG.trace("\n{}\n{}", urlStr, url); - - fileName = CSARsResource.createXMLidAsString(url.toExternalForm() - .substring(url.toExternalForm().lastIndexOf("/") + 1)); - fileName = fileName.replace("?", "."); - - CSARsResource.LOG.debug("Recieved URL " + urlStr); - // } catch (UnsupportedEncodingException e1) { - // CSARsResource.LOG.error("Encoding of recieved URL failed."); - // e1.printStackTrace(); - } - catch (final MalformedURLException e) { - CSARsResource.LOG.error("Generation of URL of encoded URL failed."); - e.printStackTrace(); - } - - if (null == fileName || fileName.equals("")) { - CSARsResource.LOG.error("The decoding of the file name has failed."); - return Response.status(Status.INTERNAL_SERVER_ERROR).build(); - } - - CSARsResource.LOG.info("Recieved the URL \"" + url + "\" for uploading a CSAR."); - CSARsResource.LOG.debug("File name is \"" + fileName + "\"."); - - try { - return handleCSAR(fileName, url.openStream()); - } - catch (final IOException e) { - CSARsResource.LOG.error("There was an error while opening the input stream."); - e.printStackTrace(); - } - catch (final URISyntaxException e) { - e.printStackTrace(); - } - catch (final UserException e) { - e.printStackTrace(); - } - catch (final SystemException e) { - e.printStackTrace(); - } - - return Response.status(Status.INTERNAL_SERVER_ERROR).build(); - } - - /** - * - * Accepts the InputStream of a CSAR file. After storing and unzipping the CSAR the processing - * of TOSCA, IAs and BPEL-Plans is triggered. - * - * @param uploadedInputStream - * @param fileDetail - * @return - * @throws URISyntaxException - * @throws IOException - * @throws SystemException - * @throws UserException - */ - @POST - @Consumes(MediaType.MULTIPART_FORM_DATA) - @Produces(ResourceConstants.APPLICATION_JSON) - public Response uploadCSARAdminUI(@FormDataParam("file") final InputStream uploadedInputStream, - @FormDataParam("file") final FormDataContentDisposition fileDetail) throws IOException, - URISyntaxException, - UserException, - SystemException { - - CSARsResource.LOG.info("Try to upload a new CSAR."); - - if (null == uploadedInputStream) { - CSARsResource.LOG.error("The stream is null."); - return Response.serverError().build(); - } - if (null == fileDetail) { - CSARsResource.LOG.error("The file details are null."); - return Response.serverError().build(); - } - - CSARsResource.LOG.debug("Post for uploading a new CSAR as file with name \"" + fileDetail.getFileName() - + "\" with size " + fileDetail.getSize() + "."); - - final String fileName = fileDetail.getFileName(); - - return handleCSAR(fileName, uploadedInputStream); - - } - - private File storeTemporaryFile(final String fileName, final InputStream uploadedInputStream) throws IOException { - final File tmpDir = FileAccessServiceHandler.getFileAccessService().getTemp(); - tmpDir.mkdir(); - - final File uploadFile = new File(tmpDir.getAbsoluteFile() + System.getProperty("file.separator") + fileName); - - OutputStream out; - - out = new FileOutputStream(uploadFile); - - int read = 0; - final byte[] bytes = new byte[1024]; - - while ((read = uploadedInputStream.read(bytes)) != -1) { - out.write(bytes, 0, read); - } - - uploadedInputStream.close(); - - CSARsResource.LOG.debug("Temporary file: " + uploadFile.getAbsolutePath() + " with size " - + uploadFile.getTotalSpace()); - - out.flush(); - out.close(); - return uploadFile; - } - - public CSARID storeCSAR(final String fileName, final InputStream uploadedInputStream) { - try { - final File uploadFile = storeTemporaryFile(fileName, uploadedInputStream); - CSARID csarID = null; - csarID = this.fileHandler.storeCSAR(uploadFile.toPath()); - - csarID = startPlanBuilder(csarID); - - if (csarID != null) { - CSARsResource.LOG.info("Storing CSAR file \"{}\" was successful.", csarID.toString()); - CSARsResource.LOG.trace("Control is bound: " + (null != this.control)); - this.control.setDeploymentProcessStateStored(csarID); - - if (this.control.invokeTOSCAProcessing(csarID)) { - - final List serviceTemplates = - ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper() - .getServiceTemplateIDsContainedInCSAR(csarID); - - for (final QName serviceTemplate : serviceTemplates) { - - CSARsResource.LOG.debug("Invoke Plan Deployment for ServiceTemplate \"" + serviceTemplate - + "\" of CSAR \"" + csarID + "\"."); - - final boolean success = this.control.invokePlanDeployment(csarID, serviceTemplate); - - CSARsResource.LOG.debug("Plan Deployment was successful: {}", success); - - } - return csarID; - } - } - } - catch (final FileNotFoundException e) { - e.printStackTrace(); - } - catch (final IOException e) { - e.printStackTrace(); - } - catch (final UserException e) { - e.printStackTrace(); - } - catch (final SystemException e) { - e.printStackTrace(); - } - - return null; - } - - public Response handleCSAR(final String fileName, - final InputStream uploadedInputStream) throws IOException, URISyntaxException, - UserException, SystemException { - - final File uploadFile = storeTemporaryFile(fileName, uploadedInputStream); - - CSARID csarID = this.fileHandler.storeCSAR(uploadFile.toPath()); - - this.control.invokeTOSCAProcessing(csarID); - - boolean toscaProcessed = true; - - if (ModelUtils.hasOpenRequirements(csarID)) { - // return a 406 with location to ServiceTemplate in local Winery in - // Body - // winery instance - final WineryConnector winCon = new WineryConnector(); - - if (winCon.isWineryRepositoryAvailable()) { - - final QName serviceTemplate = winCon.uploadCSAR(uploadFile); - - this.control.deleteCSAR(csarID); - // TODO - return Response.status(Response.Status.NOT_ACCEPTABLE).entity("{ \"Location\": \"" - + winCon.getServiceTemplateURI(serviceTemplate).toString() + "\" }").build(); - // return - // Response.status(Response.Status.SEE_OTHER).location(new - // URI(winCon.getServiceTemplateURI(serviceTemplate).toString()+"/injector/options")).build(); - } else { - this.fileHandler.deleteCSAR(csarID); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } - } - - if (!ModelUtils.hasBuildPlan(csarID) | !ModelUtils.hasTerminationPlan(csarID)) { - // looks dumb, and it is. But the "TOSCA Processing" must be done - // again - // here - this.control.deleteCSAR(csarID); - csarID = this.fileHandler.storeCSAR(uploadFile.toPath()); - - csarID = startPlanBuilder(csarID); - - toscaProcessed = false; - - } - - processTOSCA(csarID, toscaProcessed); - - if (csarID != null) { - CSARsResource.LOG.info("Storing CSAR file \"{}\" was successful.", csarID.toString()); - final String path = Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), csarID.toString()); - final JsonObject retObj = new JsonObject(); - retObj.addProperty("csarPath", path); - return Response.created(URI.create(path)).entity(retObj.toString()).build(); - - } else { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } - - } - - @Path("{csarID}") - public CSARResource getCSAR(@PathParam("csarID") final String csarIDAsString) throws UserException { - - CSARsResource.LOG.debug("Searching for CSAR \"{}\".", csarIDAsString); - - final CSARContent csar = this.fileHandler.getCSAR(new CSARID(csarIDAsString)); - - return new CSARResource(csar); - } - - @DELETE - @Produces("text/plain") - public Response deleteCSARs() throws SystemException, UserException { - - final List notDeleted = new ArrayList<>(); - - for (final CSARID csarID : this.fileHandler.getCSARIDs()) { - - CSARsResource.LOG.info("Deleting CSAR \"{}\".", csarID); - if (!IOpenToscaControlServiceHandler.getOpenToscaControlService().deleteCSAR(csarID).isEmpty()) { - notDeleted.add(csarID.toString()); - } - - } - return Response.ok(notDeleted).build(); - } - - public CSARID processTOSCA(final CSARID csarID, final boolean toscaProcessed) { - if (csarID != null) { - CSARsResource.LOG.info("Storing CSAR file \"{}\" was successful.", csarID.toString()); - CSARsResource.LOG.trace("Control is bound: " + (null != this.control)); - this.control.setDeploymentProcessStateStored(csarID); - - if (!toscaProcessed) { - this.control.invokeTOSCAProcessing(csarID); - } - - final List serviceTemplates = ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper() - .getServiceTemplateIDsContainedInCSAR(csarID); - - for (final QName serviceTemplate : serviceTemplates) { - - CSARsResource.LOG.debug("Invoke Plan Deployment for ServiceTemplate \"" + serviceTemplate - + "\" of CSAR \"" + csarID + "\"."); - - final boolean success = this.control.invokePlanDeployment(csarID, serviceTemplate); - - CSARsResource.LOG.debug("Plan Deployment was successful: {}", success); - - } - return csarID; - - } - return null; - } - - /** - * Checks whether the root tosca definitions file, contains servicetemplates where no build plan - * is available. If there is no such plan available the plan builder starts to generate a build - * plan. - * - * @param csarId the CSARID of the definitions to generate build plans for - * @return a new CSARID for the repackaged csar if new build plans were generated, the same - * csarid if no build plans were generated, else null - */ - private CSARID startPlanBuilder(final CSARID csarId) { - final Importer planBuilderImporter = new Importer(); - final Exporter planBuilderExporter = new Exporter(); - - final List buildPlans = planBuilderImporter.importDefs(csarId); - // no buildplan generated <=> nothing to do - if (buildPlans.isEmpty()) { - return csarId; - } - - final File repackagedCsar = planBuilderExporter.export(buildPlans, csarId); - try { - this.fileHandler.deleteCSAR(csarId); - return this.fileHandler.storeCSAR(repackagedCsar.toPath()); - } - catch (final SystemException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - catch (final UserException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - return null; - } - - /** - * Creates a (valid) XML ID (NCName) based on the passed name - * - * Valid NCNames: http://www.w3.org/TR/REC-xml-names/#NT-NCName / - * http://www.w3.org/TR/xml/#NT-Name http://www.w3.org/TR/xml/#NT-Name - * - * @author oliver.kopp@iaas.uni-stuttgart.de license: Apache 2.0 without NOTICE - * - */ - private static String createXMLidAsString(final String name) { - // RegExp inspired by http://stackoverflow.com/a/5396246/873282 - // NameStartChar without ":" - // stackoverflow: -dfff, standard: d7fff - final String RANGE_NCNAMESTARTCHAR = "A-Z_a-z\\u00C0\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02ff\\u0370-\\u037d" - + "\\u037f-\\u1fff\\u200c\\u200d\\u2070-\\u218f\\u2c00-\\u2fef\\u3001-\\ud7ff" - + "\\uf900-\\ufdcf\\ufdf0-\\ufffd\\x10000-\\xEFFFF"; - final String REGEX_NCNAMESTARTCHAR = "[" + RANGE_NCNAMESTARTCHAR + "]"; - final String RANGE_NCNAMECHAR = RANGE_NCNAMESTARTCHAR + "\\-\\.0-9\\u00b7\\u0300-\\u036f\\u203f-\\u2040"; - final String REGEX_INVALIDNCNAMESCHAR = "[^" + RANGE_NCNAMECHAR + "]"; - String id = name; - if (!id.substring(0, 1).matches(REGEX_NCNAMESTARTCHAR)) { - id = "_".concat(id); - } - // id starts with a valid character - - // before we wipe out all invalid characters, we do a readable - // replacement for appropriate characters - id = id.replace(' ', '_'); - - // keep length of ID, only wipe out invalid characters - // alternative: replace invalid characters by URLencoded version. As the - // ID is visible only in the URL, this quick hack should be OK - // ID is visible only in the URL, this quick hack should be OK - id = id.replaceAll(REGEX_INVALIDNCNAMESCHAR, "_"); - - return id; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/content/ContentResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/content/ContentResource.java deleted file mode 100644 index cdbd772f2..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/content/ContentResource.java +++ /dev/null @@ -1,186 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.content; - -import java.util.Set; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -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.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; - -import org.opentosca.container.api.legacy.osgi.servicegetter.FileRepositoryServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.common.SystemException; -import org.opentosca.container.core.common.UserException; -import org.opentosca.container.core.model.AbstractDirectory; -import org.opentosca.container.core.model.AbstractFile; -import org.opentosca.container.core.model.csar.CSARContent; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.service.ICoreFileService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Resource represents the root of a CSAR. - * - * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer - fischema@studi.informatik.uni-stuttgart.de - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -public class ContentResource { - - private static final Logger LOG = LoggerFactory.getLogger(ContentResource.class); - // If the CSAR is null, CSAR does not exist in the Container - private final CSARContent CSAR; - - UriInfo uriInfo; - - - public ContentResource(final CSARContent csar) { - this.CSAR = csar; - ContentResource.LOG.debug("{} created: {}", this.getClass(), this); - - if (csar != null) { - ContentResource.LOG.debug("Accessing content of CSAR \"{}\".", csar.getCSARID()); - } else { - ContentResource.LOG.error("Requested CSAR is not stored!"); - System.out.println(csar); - } - - } - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getJSONString()).build(); - } - - public References getReferences() { - - if (this.CSAR == null) { - ContentResource.LOG.info("CSAR is not stored."); - return null; - } - - final References refs = new References(); - - final Set directories = this.CSAR.getDirectories(); - for (final AbstractDirectory directory : directories) { - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), directory.getName()), - XLinkConstants.SIMPLE, directory.getName())); - } - - final Set files = this.CSAR.getFiles(); - for (final AbstractFile file : files) { - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), file.getName()), - XLinkConstants.SIMPLE, file.getName())); - } - - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return refs; - - } - - @Path("{directoryOrFile}") - public Object getDirectoryOrFile(@PathParam("directoryOrFile") final String directoryOrFile) { - - ContentResource.LOG.debug("Checking if \"{}\" exists in CSAR \"{}\"...", directoryOrFile, - this.CSAR.getCSARID()); - - final Set directories = this.CSAR.getDirectories(); - - for (final AbstractDirectory directory : directories) { - if (directory.getName().equals(directoryOrFile)) { - ContentResource.LOG.debug("\"{}\" is a directory of CSAR \"{}\".", directoryOrFile, - this.CSAR.getCSARID()); - return new DirectoryResource(directory, this.CSAR.getCSARID()); - - } - } - - final Set files = this.CSAR.getFiles(); - - for (final AbstractFile file : files) { - if (file.getName().equals(directoryOrFile)) { - ContentResource.LOG.debug("\"{}\" is a file of CSAR \"{}\".", directoryOrFile, this.CSAR.getCSARID()); - return new FileResource(file, this.CSAR.getCSARID()); - } - } - - ContentResource.LOG.error("\"{}\" does not exist in CSAR \"{}\"!", directoryOrFile, this.CSAR.getCSARID()); - - return null; - - } - - /** - * Moves this CSAR to the active / default storage provider if {@code move} is passed in - * {@code input} (body of a POST message). - * - * @param input - * @return 200 (OK) - CSAR was moved successful.
- * 400 (bad request) - {@code move} was not passed.
- * 404 (not found) - CSAR is not stored.
- * 500 (internal server error) - moving CSAR failed. - * @throws SystemException - * @throws UserException - * - * @see ICoreFileService#moveCSAR(CSARID) - */ - @POST - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.TEXT_PLAIN) - public Response moveCSAR(final String input) throws UserException, SystemException { - - if (this.CSAR == null) { - return Response.status(Status.NOT_FOUND).build(); - } - - if (input.equalsIgnoreCase("move")) { - - // try { - - FileRepositoryServiceHandler.getFileHandler().moveCSAR(this.CSAR.getCSARID()); - - return Response.ok("Moving CSAR \"" + this.CSAR.getCSARID() + "\" was successful.").build(); - - // } catch (UserException exc) { - // CSARContentResource.LOG.warn("An User Exception occured.", exc); - // } catch (SystemException exc) { - // CSARContentResource.LOG.warn("A System Exception occured.", exc); - // } - - // return Response.status(Status.INTERNAL_SERVER_ERROR).build(); - - } - - return Response.status(Status.BAD_REQUEST).build(); - - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/content/DirectoryResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/content/DirectoryResource.java deleted file mode 100644 index ec98b5b00..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/content/DirectoryResource.java +++ /dev/null @@ -1,186 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.content; - -import java.io.File; -import java.nio.file.Paths; -import java.util.Set; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -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.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; - -import org.opentosca.container.api.legacy.osgi.servicegetter.FileRepositoryServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.common.SystemException; -import org.opentosca.container.core.common.UserException; -import org.opentosca.container.core.model.AbstractDirectory; -import org.opentosca.container.core.model.AbstractFile; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.service.ICoreFileService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Resource represents a directory of a CSAR.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -public class DirectoryResource { - - private static Logger LOG = LoggerFactory.getLogger(DirectoryResource.class); - - private final AbstractDirectory CSAR_DIRECTORY; - private final CSARID CSAR_ID; - - UriInfo uriInfo; - - - /** - * - * - * @param resourceFile - */ - public DirectoryResource(final AbstractDirectory csarDirectory, final CSARID csarID) { - this.CSAR_DIRECTORY = csarDirectory; - this.CSAR_ID = csarID; - DirectoryResource.LOG.info("{} created: {}", this.getClass(), this); - DirectoryResource.LOG.info("Directory path: {}", csarDirectory.getPath()); - } - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getJSONString()).build(); - } - - public References getReferences() { - - if (this.CSAR_DIRECTORY == null) { - return null; - } - - final References refs = new References(); - - // References refs = new References(); - - final Set directories = this.CSAR_DIRECTORY.getDirectories(); - for (final AbstractDirectory directory : directories) { - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo, directory.getName()), - XLinkConstants.SIMPLE, directory.getName())); - } - - final Set files = this.CSAR_DIRECTORY.getFiles(); - for (final AbstractFile file : files) { - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo, file.getName()), - XLinkConstants.SIMPLE, file.getName())); - } - - final Reference self = - new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF); - refs.getReference().add(self); - return refs; - - } - - @Path("{directoryOrFile}") - public Object getDirectoryOrFile(@PathParam("directoryOrFile") String directoryOrFile) { - - directoryOrFile = Utilities.URLencode(directoryOrFile); - DirectoryResource.LOG.debug("Checking if \"{}\" exists in directory \"{}\" of CSAR \"{}\"...", directoryOrFile, - this.CSAR_DIRECTORY.getPath(), this.CSAR_ID); - - final Set directories = this.CSAR_DIRECTORY.getDirectories(); - - for (final AbstractDirectory directory : directories) { - if (directory.getName().equals(directoryOrFile)) { - DirectoryResource.LOG.debug("\"{}\" is a directory in directory \"{}\" of CSAR \"{}\".", - directoryOrFile, this.CSAR_DIRECTORY.getPath(), this.CSAR_ID); - return new DirectoryResource(directory, this.CSAR_ID); - } - } - - final Set files = this.CSAR_DIRECTORY.getFiles(); - - for (final AbstractFile file : files) { - if (file.getName().equals(directoryOrFile)) { - DirectoryResource.LOG.debug("\"{}\" is a file in directory \"{}\" of CSAR \"{}\".", directoryOrFile, - this.CSAR_DIRECTORY.getPath(), this.CSAR_ID); - return new FileResource(file, this.CSAR_ID); - } - } - - DirectoryResource.LOG.warn("\"{}\" does not exist in directory \"{}\" of CSAR \"{}\".", directoryOrFile, - this.CSAR_DIRECTORY.getPath(), this.CSAR_ID); - return null; - - } - - /** - * Moves this directory of a CSAR to the active / default storage provider if {@code move} is passed - * in {@code input} (body of a POST message). - * - * @param input - * @return 200 (OK) - directory was moved successful.
- * 400 (bad request) - {@code move} was not passed.
- * 500 (internal server error) - moving directory failed. - * @throws SystemException - * @throws UserException - * - * - * @see ICoreFileService#moveFileOrDirectoryOfCSAR(CSARID, File) - */ - @POST - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.TEXT_PLAIN) - public Response moveDirectoryOfCSAR(final String input) throws UserException, SystemException { - - if (input.equalsIgnoreCase("move")) { - - // try { - - FileRepositoryServiceHandler.getFileHandler() - .moveFileOrDirectoryOfCSAR(this.CSAR_ID, - Paths.get(this.CSAR_DIRECTORY.getPath())); - - return Response.ok("Moving directory \"" + this.CSAR_DIRECTORY.getPath() + "\" of CSAR \"" - + this.CSAR_ID.toString() + "\" was successful.").build(); - - // } catch (UserException exc) { - // CSARDirectoryResource.LOG.warn("An User Exception occured.", - // exc); - // } catch (SystemException exc) { - // CSARDirectoryResource.LOG.warn("An System Exception occured.", - // exc); - // } - // - // return Response.status(Status.INTERNAL_SERVER_ERROR).build(); - - } - - return Response.status(Status.BAD_REQUEST).build(); - - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/content/FileResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/content/FileResource.java deleted file mode 100644 index 225cb8f3e..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/content/FileResource.java +++ /dev/null @@ -1,300 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.content; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.nio.file.Paths; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; - -import org.opentosca.container.api.legacy.osgi.servicegetter.FileRepositoryServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.common.SystemException; -import org.opentosca.container.core.common.UserException; -import org.opentosca.container.core.model.AbstractFile; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.service.ICoreFileService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Resource represents a file of a CSAR.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -public class FileResource { - - private static Logger LOG = LoggerFactory.getLogger(FileResource.class); - - private final AbstractFile CSAR_FILE; - private final CSARID CSAR_ID; - - UriInfo uriInfo; - - - /** - * - * - * @param resourceFile - */ - public FileResource(final AbstractFile csarFile, final CSARID csarID) { - this.CSAR_FILE = csarFile; - this.CSAR_ID = csarID; - FileResource.LOG.info("{} created: {}", this.getClass(), this); - FileResource.LOG.info("File path: {}", csarFile.getPath()); - } - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - - final String json = this.getAsJSONString(); - - if (null != json && !json.equals("")) { - return Response.ok(json).build(); - } - - return Response.ok(this.getReferences().getJSONString()).build(); - } - - public References getReferences() { - if (this.CSAR_FILE != null) { - final References refs = new References(); - final Reference self = - new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF); - refs.getReference().add(self); - return refs; - } - return null; - } - - /** - * @return - * @throws SystemException - */ - @GET - @Produces(ResourceConstants.OCTET_STREAM) - public Response downloadFile() throws SystemException { - - if (this.CSAR_FILE != null) { - - FileResource.LOG.info("Attempt to download file: \"{}\"", this.CSAR_FILE.getPath()); - - InputStream inputStream; - // try { - inputStream = this.CSAR_FILE.getFileAsInputStream(); - // We add Content Disposition header, because file to download - // should have the correct file name. - return Response.ok(inputStream) - .header("Content-Disposition", "attachment; filename=\"" + this.CSAR_FILE.getName() + "\"") - .build(); - // } catch (SystemException exc) { - // CSARFileResource.LOG.warn("An System Exception occured.", exc); - // } - - // return Response.status(Status.INTERNAL_SERVER_ERROR).build(); - - } - - return Response.status(Status.NOT_FOUND).build(); - - } - - public String getAsJSONString() { - - try { - - FileResource.LOG.trace("Attempt to download file: \"{}\"", this.CSAR_FILE.getPath()); - - final InputStream inputStream = this.CSAR_FILE.getFileAsInputStream(); - final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); - final StringBuilder strBuilder = new StringBuilder(); - - String inputStr; - do { - inputStr = reader.readLine(); - if (null == inputStr) { - break; - } - strBuilder.append(inputStr); - } while (true); - - reader.close(); - - LOG.trace("Found a json file and parsed it, contents are:\n {}", strBuilder.toString()); - return strBuilder.toString(); - - } - catch (final SystemException e) { - e.printStackTrace(); - } - catch (final UnsupportedEncodingException e) { - e.printStackTrace(); - } - catch (final IOException e) { - e.printStackTrace(); - } - - return ""; - - } - - /** - * Retrieval of image files. Is handled separately from the generic file retrieval as the - * corresponding mime type has to be set. - * - * TODO Can we set the supported media types depending on the imageMediaTypes map in - * ResourceConstants? (String[])ResourceConstants.imageMediaTypes.values().toArray(new - * String[ResourceConstants.imageMediaTypes.values().size()]); - * - * @return - * @throws SystemException - */ - @GET - @Produces(ResourceConstants.IMAGE) - public Response getImage() throws SystemException { - if (this.CSAR_FILE != null) { - - FileResource.LOG.info("Attempt to download image: \"{}\"", this.CSAR_FILE.getPath()); - - // Check if file is a (supported) image - if (this.CSAR_FILE.getName() != null) { - // retrieve file extension - final String ext = this.CSAR_FILE.getName().substring(this.CSAR_FILE.getName().lastIndexOf(".") + 1); - // known? - if (ResourceConstants.imageMediaTypes.containsKey(ext)) { - FileResource.LOG.debug("Supported image file, *.{} maps to {}", ext, - ResourceConstants.imageMediaTypes.get(ext)); - final InputStream inputStream = this.CSAR_FILE.getFileAsInputStream(); - // set matching media type and return - return Response.ok(inputStream, ResourceConstants.imageMediaTypes.get(ext)).build(); - } else { - // file is no (supported) image - return Response.status(Status.NOT_ACCEPTABLE).build(); - } - } else { - // file without name, should not happen... - return Response.serverError().build(); - } - } - - return Response.status(Status.NOT_FOUND).build(); - - } - - // @Produces("image/*;qs=2") - // // "image/*" will be preferred over "text/xml" when requesting an image. - // // This is a fix for Webkit Browsers who are too dumb for content - // // negotiation. - // public Response getImage(@PathParam("image") String imageRelativePath) { - // - // // File f = this.resourceFile; - // // - // // if ((f == null) || !f.isFile()) { - // // throw new WebApplicationException(404); - // // } - // MediaType mt = new MediaType("image", "*"); - // - // // new - // // MimetypesFileTypeMap().getContentType(f); - // // System.out.println("####### MIMETYPE: " + mt); - // return Response.ok(f, mt).build(); - // - // // Response.ok() - // - // } - - // @GET - // @Produces(ResourceConstants.TEXT_PLAIN) - // public Response getAbsolutePath() { - // if (this.fileInCSAR == null) { - // return Response.status(404).build(); - // } else { - // return Response.ok(this.fileInCSAR.getAbsolutePath()).build(); - // } - // } - - // @Path("{path}") - // public FileDirectoryResource getDirectory(@PathParam("path") String path) - // { - // CSARFileResource.LOG.info("Trying to open directory or file: {}", path); - // File returnFile = null; - // if (this.fileInCSAR.isDirectory()) { - // for (File file : this.fileInCSAR.listFiles()) { - // if (file.getName().equals(path)) { - // CSARFileResource.LOG.info("Requested resource found: {}", path); - // returnFile = file; - // } - // } - // } - // return new FileDirectoryResource(returnFile); - // } - - /** - * Moves this file of a CSAR to the active / default storage provider if {@code move} is passed in - * {@code input} (body of a POST message). - * - * @param input - * @return 200 (OK) - file was moved successful.
- * 500 (internal server error) - moving file failed.
- * 400 (bad request) - {@code move} was not passed. - * @throws @throws UserException - * - * @see ICoreFileService#moveFileOrDirectoryOfCSAR(CSARID, File) - */ - @POST - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.TEXT_PLAIN) - public Response moveFileOfCSAR(final String input) throws UserException, SystemException { - - if (input.equalsIgnoreCase("move")) { - - // try { - - FileRepositoryServiceHandler.getFileHandler() - .moveFileOrDirectoryOfCSAR(this.CSAR_ID, Paths.get(this.CSAR_FILE.getPath())); - - return Response.ok("Moving file \"" + this.CSAR_FILE.getPath() + "\" of CSAR \"" + this.CSAR_ID.toString() - + "\" was successful.").build(); - - // } catch (UserException exc) { - // CSARFileResource.LOG.warn("An User Exception occured.", exc); - // } catch (SystemException exc) { - // CSARFileResource.LOG.warn("An System Exception occured.", exc); - // } - - // return Response.status(Status.INTERNAL_SERVER_ERROR).build(); - - } - - return Response.status(Status.BAD_REQUEST).build(); - - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/CSARControl.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/CSARControl.java deleted file mode 100644 index 60161668f..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/CSARControl.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.control; - -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.Request; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; - -import org.opentosca.container.api.legacy.osgi.servicegetter.FileRepositoryServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.service.ICoreFileService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This Resource shows all ongoing DeploymentProcesses within the Container. - * - * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * @author Rene Trefft - trefftre@studi.informatik.uni-stuttgart.de - * - */ -@Path("/CSARControl") -public class CSARControl { - - private static Logger LOG = LoggerFactory.getLogger(CSARControl.class); - private final ICoreFileService fileHandler; - @Context - UriInfo uriInfo; - @Context - Request request; - - - public CSARControl() { - this.fileHandler = FileRepositoryServiceHandler.getFileHandler(); - CSARControl.LOG.info("{} created: {}", this.getClass(), this); - } - - @GET - @Produces(ResourceConstants.TOSCA_XML) - public Response getReferences() { - final References refs = new References(); - // If a CSAR file is stored, it automatically is an ongoing - // DeploymentProcess - for (final CSARID csarID : this.fileHandler.getCSARIDs()) { - final Reference ref = - new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), csarID.toString()), - XLinkConstants.SIMPLE, csarID.toString()); - refs.getReference().add(ref); - } - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return Response.ok(refs.getXMLString()).build(); - } - - @Path("{id}") - public DeploymentProcessResource getDeploymentProcessResource(@PathParam("id") final String id) { - CSARID processID = null; - CSARControl.LOG.info("Trying to find DeploymentProcess with id: {}", id); - for (final CSARID csarID : this.fileHandler.getCSARIDs()) { - if (csarID.toString().trim().equals(id.trim())) { - CSARControl.LOG.info("Found DeploymentProcess with id: {}", id); - processID = csarID; - } - } - return new DeploymentProcessResource(processID); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/DeploymentProcessOperationsResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/DeploymentProcessOperationsResource.java deleted file mode 100644 index b8c7b4038..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/DeploymentProcessOperationsResource.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.control; - -import java.util.Set; - -import javax.ws.rs.GET; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Response; - -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.core.model.deployment.process.DeploymentProcessOperation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Resource class representing the available Methods of a DeploymentProcess Copyright 2012 IAAS - * University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * - */ -public class DeploymentProcessOperationsResource { - - private static final Logger LOG = LoggerFactory.getLogger(DeploymentProcessOperationsResource.class); - private final Set operations; - private final String sep = "&"; - - - public DeploymentProcessOperationsResource(final Set operations) { - this.operations = operations; - DeploymentProcessOperationsResource.LOG.info("{} created: {}", this.getClass(), this); - - } - - /** - * - * @return all available Operations as String separated by "&" - */ - @GET - @Produces(ResourceConstants.TEXT_PLAIN) - public Response getOperationss() { - DeploymentProcessOperationsResource.LOG.info("Get Request on DeploymentProcessOperationsResource"); - String operations = ""; - for (final DeploymentProcessOperation operation : this.operations) { - operations = operations + this.sep + operation.toString(); - } - return Response.ok(operations).build(); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/DeploymentProcessResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/DeploymentProcessResource.java deleted file mode 100644 index b99acc520..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/DeploymentProcessResource.java +++ /dev/null @@ -1,141 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.control; - -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.MediaType; -import javax.ws.rs.core.Response; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.IOpenToscaControlServiceHandler; -import org.opentosca.container.api.legacy.resources.csar.control.jaxb.DeploymentProcessJaxb; -import org.opentosca.container.api.legacy.resources.csar.control.jaxb.JaxbFactoryControl; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.control.IOpenToscaControlService; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.model.deployment.process.DeploymentProcessOperation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Resource class representing a DeploymentProcess - * - * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * - */ -public class DeploymentProcessResource { - - private static Logger LOG = LoggerFactory.getLogger(DeploymentProcessResource.class); - - private final CSARID processID; - private QName serviceTemplateId; - - private final String sep = "&"; - IOpenToscaControlService openToscaControl = IOpenToscaControlServiceHandler.getOpenToscaControlService(); - - - public DeploymentProcessResource(final CSARID processID) { - this.processID = processID; - - // this. - DeploymentProcessResource.LOG.info("{} created: {}", this.getClass(), this); - - } - - /** - * - * @return String with Information about the DeploymentProcess separated by "&" - */ - @GET - @Produces(ResourceConstants.TEXT_PLAIN) - public Response getDeploymentProcess() { - DeploymentProcessResource.LOG.info("Get Request on DeploymentProcessResource with ID: {}", this.processID); - String res = "DeploymentProcessID=" + this.processID + this.sep + "DeploymentState=" - + this.openToscaControl.getDeploymentProcessState(this.processID); - for (final DeploymentProcessOperation operation : this.openToscaControl.getExecutableDeploymentProcessOperations(this.processID)) { - final String o = "OPERATION=" + operation.toString(); - res = res + this.sep + o; - } - return Response.ok(res.trim()).build(); - } - - @GET - @Produces(MediaType.APPLICATION_XML) - public DeploymentProcessJaxb getDeploymentProcessXML() { - DeploymentProcessResource.LOG.info("Get Request on DeploymentProcessResource with ID: {}", this.processID); - return JaxbFactoryControl.createDeploymentProcessJaxb(this.processID); - } - - @POST - @Consumes(ResourceConstants.TEXT_PLAIN) - public Response invoke(final String input) { - - // // ** HACK HERE **// - // if ( input.equals("SET_STEMPLATEID")){ - // - // } - final String params[] = input.split("&"); - - final DeploymentProcessOperation operation = DeploymentProcessOperation.valueOf(params[0]); - - final CSARID csarID = this.processID; - DeploymentProcessResource.LOG.info("POST method called on DeploymentProcess: {}, Parameter: {}", - csarID.toString(), operation); - if (this.openToscaControl.getExecutableDeploymentProcessOperations(this.processID).contains(operation)) { - switch (operation) { - case PROCESS_TOSCA: - DeploymentProcessResource.LOG.info("OPERATION: {}", DeploymentProcessOperation.PROCESS_TOSCA); - - if (IOpenToscaControlServiceHandler.getOpenToscaControlService().invokeTOSCAProcessing(csarID)) { - return Response.ok().build(); - } else { - } - break; - - case INVOKE_PLAN_DEPL: - DeploymentProcessResource.LOG.info("OPERATION: {}", DeploymentProcessOperation.INVOKE_PLAN_DEPL); - - // Dirty hack. Needs some redesign - if (params[1] == null) { - return Response.serverError().build(); - } else { - this.serviceTemplateId = QName.valueOf(params[1]); - } - - if (IOpenToscaControlServiceHandler.getOpenToscaControlService() - .invokePlanDeployment(csarID, this.serviceTemplateId)) { - return Response.ok().build(); - } else { - } - break; - } - } - /** - * 424 Method Failure (WebDAV)[13] Indicates the method was not executed on a particular - * resource within its scope because some part of the method's execution failed causing the - * entire method to be aborted. - */ - return Response.status(424).build(); - } - - @Path("/DeploymentState") - public DeploymentProcessStateResource getCSARFile() { - return new DeploymentProcessStateResource(this.openToscaControl.getDeploymentProcessState(this.processID)); - } - - @Path("/Operations") - public DeploymentProcessOperationsResource getMethods() { - return new DeploymentProcessOperationsResource( - this.openToscaControl.getExecutableDeploymentProcessOperations(this.processID)); - } - - @Path("/ServiceTemplates") - public DeploymentProcessServiceTemplatesResource getServiceTemplates() { - return new DeploymentProcessServiceTemplatesResource(this.processID); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/DeploymentProcessServiceTemplatesResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/DeploymentProcessServiceTemplatesResource.java deleted file mode 100644 index 626ffb471..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/DeploymentProcessServiceTemplatesResource.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.control; - -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Response; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.IOpenToscaControlServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DeploymentProcessServiceTemplatesResource { - - private static final Logger LOG = LoggerFactory.getLogger(DeploymentProcessOperationsResource.class); - - private final String sep = "&"; - private final CSARID csarid; - - - public DeploymentProcessServiceTemplatesResource(final CSARID csarid) { - this.csarid = csarid; - DeploymentProcessServiceTemplatesResource.LOG.info("{} created: {}", this.getClass(), this); - - } - - /** - * - * @return all available Operations as String separated by "&" - */ - @GET - @Produces(ResourceConstants.TEXT_PLAIN) - public Response getServiceTemplates() { - DeploymentProcessServiceTemplatesResource.LOG.info("Get Request on DeploymentProcessOperationsResource"); - String sTemplates = ""; - final List ServiceTemplates = - IOpenToscaControlServiceHandler.getOpenToscaControlService().getAllContainedServiceTemplates(this.csarid); - for (final QName serviceTemplate : ServiceTemplates) { - sTemplates = sTemplates + this.sep + serviceTemplate.toString(); - } - sTemplates = sTemplates.substring(1); - - // for (DeploymentProcessOperation operation : this.operations) { - // operations = operations + this.sep + operation.toString(); - // } - return Response.ok(sTemplates).build(); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/DeploymentProcessStateResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/DeploymentProcessStateResource.java deleted file mode 100644 index db3b53fdf..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/DeploymentProcessStateResource.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.control; - -import javax.ws.rs.GET; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Response; - -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.core.model.deployment.process.DeploymentProcessState; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Resource class representing the current State of a DeploymentProcess Copyright 2012 IAAS - * University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * - */ -public class DeploymentProcessStateResource { - - private static final Logger LOG = LoggerFactory.getLogger(DeploymentProcessStateResource.class); - - private final DeploymentProcessState deploymentState; - - - public DeploymentProcessStateResource(final DeploymentProcessState deploymentState) { - this.deploymentState = deploymentState; - DeploymentProcessStateResource.LOG.info("{} created: {}", this.getClass(), this); - - } - - @GET - @Produces(ResourceConstants.TEXT_PLAIN) - public Response getDeploymentProcessState() { - DeploymentProcessStateResource.LOG.info("Get Request on DeploymentProcessStateResource State: {}", - this.deploymentState.toString()); - return Response.ok(this.deploymentState.toString()).build(); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/jaxb/DeploymentProcessJaxb.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/jaxb/DeploymentProcessJaxb.java deleted file mode 100644 index 15eb74ab8..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/jaxb/DeploymentProcessJaxb.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.control.jaxb; - -import java.util.HashSet; -import java.util.Set; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.model.deployment.process.DeploymentProcessState; - -/** - * Class to provide JAXB-Annotation for a DeploymentProcess
- *
- * - * To be used by Jersey to automatically generate XML-Responses
- *
- * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * - */ -@XmlRootElement(name = "DeploymentProcess") -@XmlAccessorType(XmlAccessType.FIELD) -public class DeploymentProcessJaxb { - - @XmlAttribute(name = "DeploymentState") - private DeploymentProcessState deploymentState; - @XmlElement(name = "ProcessId") - private CSARID processID; - @XmlElement(name = "Operations") - private Set operations; - - - public DeploymentProcessJaxb() {} - - /** - * @return the deploymentState - */ - public DeploymentProcessState getDeploymentState() { - return this.deploymentState; - } - - /** - * @param deploymentState the deploymentState to set - */ - public void setDeploymentState(final DeploymentProcessState deploymentState) { - this.deploymentState = deploymentState; - } - - /** - * @return the CSAR ID - */ - public CSARID getProcessID() { - return this.processID; - } - - /** - * @param csarID to set - */ - public void setProcessID(final CSARID csarID) { - this.processID = csarID; - } - - /** - * @return the operations - */ - public Set getOperations() { - if (this.operations == null) { - return new HashSet<>(); - } else { - return this.operations; - } - } - - /** - * @param operations the operations to set - */ - public void setOperations(final Set operations) { - this.operations = operations; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/jaxb/JaxbFactoryControl.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/jaxb/JaxbFactoryControl.java deleted file mode 100644 index f62f71ec9..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/jaxb/JaxbFactoryControl.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.control.jaxb; - -import java.util.HashSet; - -import org.opentosca.container.api.legacy.osgi.servicegetter.IOpenToscaControlServiceHandler; -import org.opentosca.container.control.IOpenToscaControlService; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.model.deployment.process.DeploymentProcessOperation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Provides static methods to create instances of Classes provided by this package.
- * - * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * - */ -public class JaxbFactoryControl { - - private static Logger LOG = LoggerFactory.getLogger(JaxbFactoryControl.class); - - private static IOpenToscaControlService openToscaControl = - IOpenToscaControlServiceHandler.getOpenToscaControlService(); - - - public static DeploymentProcessJaxb createDeploymentProcessJaxb(final CSARID processID) { - JaxbFactoryControl.LOG.info("Creating a new DeploymentProcessJaxb object for id: {}", processID); - final DeploymentProcessJaxb jaxbObject = new DeploymentProcessJaxb(); - jaxbObject.setProcessID(processID); - jaxbObject.setDeploymentState(JaxbFactoryControl.openToscaControl.getDeploymentProcessState(processID)); - final HashSet operations = new HashSet<>(); - for (final DeploymentProcessOperation op : JaxbFactoryControl.openToscaControl.getExecutableDeploymentProcessOperations(processID)) { - operations.add(JaxbFactoryControl.createOperationJaxb(op)); - } - jaxbObject.setOperations(operations); - return jaxbObject; - } - - public static OperationJaxb createOperationJaxb(final DeploymentProcessOperation operation) { - JaxbFactoryControl.LOG.info("Creating a new OperationJaxb object for id: {}", operation); - final OperationJaxb jaxbObject = new OperationJaxb(); - jaxbObject.setOperation(operation); - return jaxbObject; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/jaxb/OperationJaxb.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/jaxb/OperationJaxb.java deleted file mode 100644 index 9770ce277..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/control/jaxb/OperationJaxb.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.control.jaxb; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -import org.opentosca.container.core.model.deployment.process.DeploymentProcessOperation; - -/** - * Class to provide JAXB-Annotation for a DeploymentProcessOperation
- *
- * - * To be used by Jersey to automatically generate XML-Responses
- *
- * - * - * - * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * - */ -@XmlRootElement -@XmlAccessorType(XmlAccessType.FIELD) -public class OperationJaxb { - - @XmlElement(name = "Operation") - private DeploymentProcessOperation operation; - - - public OperationJaxb() {} - - public DeploymentProcessOperation getOperation() { - return this.operation; - } - - public void setOperation(final DeploymentProcessOperation operation) { - this.operation = operation; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/jaxb/AllDeploymentArtifactsJaxb.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/jaxb/AllDeploymentArtifactsJaxb.java deleted file mode 100644 index 7e78e87a5..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/jaxb/AllDeploymentArtifactsJaxb.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.jaxb; - -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -/** - * This class is currently not in Use.
- *
- * - * Class to provide JAXB-Annotation for a AllDeploymentArtifacts
- * Intended to show all DeploymentArtifacts and their absolutePaths within a csarFile.
- *
- * - * To be used by Jersey to automatically generate XML-Responses
- *
- * - * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * - */ -@XmlRootElement(name = "AllDeploymentArtifacts") -@XmlAccessorType(XmlAccessType.FIELD) -public class AllDeploymentArtifactsJaxb { - - @XmlElement(name = "DeploymentArtifact") - private List allDeploymentArtifacts; - @XmlAttribute(name = "ServiceTemplateId") - private String serviceTemplateID; - @XmlAttribute(name = "csarID") - private String csarID; - - - public AllDeploymentArtifactsJaxb() { - - } - - public List getAllDeploymentArtifacts() { - return this.allDeploymentArtifacts; - } - - public void setAllDeploymentArtifacts(final List allDeploymentArtifacts) { - this.allDeploymentArtifacts = allDeploymentArtifacts; - } - - public String getServiceTemplateID() { - return this.serviceTemplateID; - } - - public void setServiceTemplateID(final String serviceTemplateID) { - this.serviceTemplateID = serviceTemplateID; - } - - public String getCSARID() { - return this.csarID; - } - - public void setCSARID(final String csarID) { - this.csarID = csarID; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/jaxb/DeploymentArtifactAbsJaxb.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/jaxb/DeploymentArtifactAbsJaxb.java deleted file mode 100644 index 683c92312..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/jaxb/DeploymentArtifactAbsJaxb.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.jaxb; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlRootElement; - -/** - * This class is currently not in Use.
- *
- * - * Class to provide JAXB-Annotation for a DeploymentArtifact including its absolutePath on the - * filesystem
- * - *
- * - * To be used by Jersey to automatically generate XML-Responses
- *
- * - * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * - */ -@XmlRootElement(name = "DeploymentArtifact") -@XmlAccessorType(XmlAccessType.FIELD) -public class DeploymentArtifactAbsJaxb { - - @XmlAttribute(name = "AbsolutePath") - private String absolutePath; - @XmlAttribute(name = "Type") - private String type; - @XmlAttribute(name = "Name") - private String name; - - - public DeploymentArtifactAbsJaxb() { - - } - - public String getName() { - return this.name; - } - - public void setName(final String name) { - this.name = name; - } - - public String getType() { - return this.type; - } - - public void setType(final String type) { - this.type = type; - } - - public String getAbsolutePath() { - return this.absolutePath; - } - - public void setAbsolutePath(final String absolutePath) { - this.absolutePath = absolutePath; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/jaxb/JaxbFactoryCSAR.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/jaxb/JaxbFactoryCSAR.java deleted file mode 100644 index b569bb0b5..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/jaxb/JaxbFactoryCSAR.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.jaxb; - -import java.util.ArrayList; -import java.util.List; - -/** - * This class is currently not in Use.
- *
- * Provides static methods to create instances of Classes provided by this package.
- * - * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * - */ -public class JaxbFactoryCSAR { - - public static AllDeploymentArtifactsJaxb createAllDeploymentArtifactsDTO(final List allDeploymentArtifacts, - final String serviceTemplateID, - final String csarID) { - final AllDeploymentArtifactsJaxb jaxbObject = new AllDeploymentArtifactsJaxb(); - jaxbObject.setAllDeploymentArtifacts(allDeploymentArtifacts); - jaxbObject.setServiceTemplateID(serviceTemplateID); - jaxbObject.setCSARID(csarID); - return jaxbObject; - } - - public static DeploymentArtifactAbsJaxb createDeploymentArtifactAbsDTO(final String absolutePath, final String name, - final String type) { - final DeploymentArtifactAbsJaxb dto = new DeploymentArtifactAbsJaxb(); - dto.setAbsolutePath(absolutePath); - dto.setName(name); - dto.setType(type); - return dto; - } - - public static List createDADTOList() { - return new ArrayList<>(); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/ServiceTemplateResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/ServiceTemplateResource.java deleted file mode 100644 index 3c6c6d46d..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/ServiceTemplateResource.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate; - -import java.io.UnsupportedEncodingException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.boundarydefinitions.BoundsResource; -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.ServiceTemplateInstancesResource; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.CSARContent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * Copyright 2016 IAAS University of Stuttgart
- *
- * - * @author christian.endres@iaas.uni-stuttgart.de - * - */ -public class ServiceTemplateResource { - - private final Logger log = LoggerFactory.getLogger(ServiceTemplateResource.class); - private final CSARContent csarContent; - private final QName serviceTemplateID; - private UriInfo uriInfo; - - - public ServiceTemplateResource(final CSARContent csarContent, final String serviceTemplateID) { - - this.csarContent = csarContent; - final String namespace = serviceTemplateID.substring(1, serviceTemplateID.indexOf("}")); - final String localName = serviceTemplateID.substring(serviceTemplateID.indexOf("}") + 1); - this.serviceTemplateID = new QName(namespace, localName); - this.log.info("{} created: \"{}\":\"{}\"; out of \"{}\"", this.getClass(), - this.serviceTemplateID.getNamespaceURI(), this.serviceTemplateID.getLocalPart(), - serviceTemplateID); - } - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) throws UnsupportedEncodingException { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) throws UnsupportedEncodingException { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getJSONString()).build(); - } - - public References getRefs() throws UnsupportedEncodingException { - - if (this.csarContent == null) { - return null; - } - - final References refs = new References(); - - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo, "BoundaryDefinitions"), - XLinkConstants.SIMPLE, "BoundaryDefinitions")); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo, "Instances"), XLinkConstants.SIMPLE, "Instances")); - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return refs; - } - - @Path("BoundaryDefinitions") - public BoundsResource getBoundaryDefs() { - return new BoundsResource(this.csarContent.getCSARID(), this.serviceTemplateID); - } - - @Path("Instances") - public ServiceTemplateInstancesResource getInstances() { - this.log.debug("Create ST instances list resource for {}", this.serviceTemplateID); - return new ServiceTemplateInstancesResource(this.csarContent.getCSARID(), this.serviceTemplateID); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/ServiceTemplatesResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/ServiceTemplatesResource.java deleted file mode 100644 index 6772f22e8..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/ServiceTemplatesResource.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.net.URLEncoder; - -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.FileRepositoryServiceHandler; -import org.opentosca.container.api.legacy.osgi.servicegetter.ToscaServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.common.SystemException; -import org.opentosca.container.core.common.UserException; -import org.opentosca.container.core.model.AbstractFile; -import org.opentosca.container.core.model.csar.CSARContent; -import org.opentosca.container.core.tosca.model.Definitions; -import org.opentosca.container.core.tosca.model.TExtensibleElements; -import org.opentosca.container.core.tosca.model.TServiceTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * Copyright 2016 IAAS University of Stuttgart
- *
- * - * @author christian.endres@iaas.uni-stuttgart.de - * - */ -public class ServiceTemplatesResource { - - private final Logger log = LoggerFactory.getLogger(ServiceTemplatesResource.class); - private final CSARContent csarContent; - UriInfo uriInfo; - - - public ServiceTemplatesResource(final CSARContent csar) { - - this.csarContent = csar; - this.log.info("{} created: {}", this.getClass(), this); - } - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo, - @DefaultValue("false") @QueryParam("main") final boolean onlyMainServiceTemplate) throws UnsupportedEncodingException, - UserException, - SystemException { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs(onlyMainServiceTemplate).getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo, - @QueryParam("main") final boolean onlyMainServiceTemplate) throws UnsupportedEncodingException, - UserException, - SystemException { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs(onlyMainServiceTemplate).getJSONString()).build(); - } - - public References getRefs(final boolean onlyMainServiceTemplate) throws UnsupportedEncodingException, UserException, - SystemException { - - if (this.csarContent == null) { - return null; - } - - final References refs = new References(); - - if (onlyMainServiceTemplate) { - this.log.debug("Only reference to main Service Template is requested."); - final String st = this.getEntryServiceTemplateName(); - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), st), - XLinkConstants.SIMPLE, st)); - - } else { - for (final QName qname : ToscaServiceHandler.getToscaEngineService() - .getServiceTemplatesInCSAR(this.csarContent.getCSARID())) { - final String name = URLEncoder.encode(qname.toString(), "UTF-8"); - refs.getReference().add(new Reference( - Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), name), XLinkConstants.SIMPLE, name)); - } - } - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return refs; - } - - private String getEntryServiceTemplateName() throws UserException, SystemException, UnsupportedEncodingException { - - final AbstractFile root = - FileRepositoryServiceHandler.getFileHandler().getCSAR(this.csarContent.getCSARID()).getRootTOSCA(); - final Definitions def = ToscaServiceHandler.getIXMLSerializer().unmarshal(root.getFileAsInputStream()); - - for (final TExtensibleElements el : def.getServiceTemplateOrNodeTypeOrNodeTypeImplementation()) { - if (el instanceof TServiceTemplate) { - final TServiceTemplate st = (TServiceTemplate) el; - final QName qn = new QName(st.getTargetNamespace(), st.getId()); - return URLEncoder.encode(qn.toString(), "UTF-8"); - } - } - - return null; - } - - @Path("{qname}") - public ServiceTemplateResource getServiceTemplate(@PathParam("qname") final String qname) throws UnsupportedEncodingException { - this.log.debug("Create Service Template resource for {}", qname); - return new ServiceTemplateResource(this.csarContent, URLDecoder.decode(qname, "UTF-8")); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsInterfaceOperationPlanResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsInterfaceOperationPlanResource.java deleted file mode 100644 index 53c17a59b..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsInterfaceOperationPlanResource.java +++ /dev/null @@ -1,332 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.boundarydefinitions; - -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.util.LinkedHashMap; -import java.util.Map; - -import javax.ws.rs.GET; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.bind.JAXBElement; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.ToscaServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.engine.IToscaReferenceMapper; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.tosca.extension.PlanTypes; -import org.opentosca.container.core.tosca.model.TParameter; -import org.opentosca.container.core.tosca.model.TPlan; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; - -public class BoundsInterfaceOperationPlanResource { - - private static final Logger LOG = LoggerFactory.getLogger(BoundsInterfaceOperationPlanResource.class); - CSARID csarID; - QName serviceTemplateID; - String intName; - String opName; - - UriInfo uriInfo; - - - public BoundsInterfaceOperationPlanResource(final CSARID csarID, final QName serviceTemplateID, - final String intName, final String opName) { - - this.csarID = csarID; - this.serviceTemplateID = serviceTemplateID; - this.intName = intName; - this.opName = opName; - - if (null == ToscaServiceHandler.getToscaEngineService()) { - LOG.error("The ToscaEngineService is not alive."); - } - } - - /** - * Returns the Boundary Definitions Node Operation. TODO not yet implemented yet, thus, just returns - * itself. - * - * @param uriInfo - * @return Response - * @throws UnsupportedEncodingException - */ - @GET - // @Path("{PlanName}") - @Produces(ResourceConstants.TOSCA_XML) - public JAXBElement getPlanXML(@Context final UriInfo uriInfo) throws UnsupportedEncodingException { - final String planName = - ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper() - .getBoundaryPlanOfCSARInterface(this.csarID, this.intName, this.opName).getLocalPart(); - - final TPlan plan = getPlan(planName); - - return ToscaServiceHandler.getIXMLSerializer().createJAXBElement(plan); - } - - private String getPostPath() throws UnsupportedEncodingException { - - String serviceTemplateID = Utilities.URLencode(this.serviceTemplateID.toString()); - serviceTemplateID = Utilities.URLencode(serviceTemplateID); - - final String path = - "CSARs/" + this.csarID.getFileName() + "/ServiceTemplates/" + serviceTemplateID + "/Instances"; - - LOG.debug("POST URL: {}", path); - - return path; - } - - /** - * Returns the Plan. - * - * @param uriInfo - * @return Response - * @throws UnsupportedEncodingException - */ - @GET - // @Path("{PlanName}") - @Produces(ResourceConstants.TOSCA_JSON) - public Response getPlanJSON(@Context final UriInfo uriInfo) throws UnsupportedEncodingException { - - final String planName = - ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper() - .getBoundaryPlanOfCSARInterface(this.csarID, this.intName, this.opName).getLocalPart(); - - final TPlan plan = getPlan(planName); - - final JsonObject json = new JsonObject(); - - if (plan.getPlanType().startsWith("http://docs.oasis-open.org/tosca/ns/2011/12/PlanTypes/BuildPlan")) { - final URI url = uriInfo.getBaseUriBuilder().path(getPostPath()).build(); - json.add("Reference", new Reference(url.toString(), XLinkConstants.REFERENCE, "PlanPostURL").toJson()); - } else { - final URI url = uriInfo.getBaseUriBuilder().path(getPostPath()).build(); - json.add("Reference", - new Reference(url.toString() + "/{instanceId}", XLinkConstants.REFERENCE, "PlanPostURL").toJson()); - } - - final JsonObject planJson = new JsonObject(); - json.add("Plan", planJson); - planJson.addProperty("ID", plan.getId()); - planJson.addProperty("Name", plan.getName()); - planJson.addProperty("PlanType", plan.getPlanType()); - planJson.addProperty("PlanLanguage", plan.getPlanLanguage()); - - final JsonArray input = new JsonArray(); - try { - for (final TParameter param : plan.getInputParameters().getInputParameter()) { - final JsonObject paramObj = new JsonObject(); - final JsonObject paramDetails = new JsonObject(); - paramDetails.addProperty("Name", param.getName()); - paramDetails.addProperty("Type", param.getType()); - paramDetails.addProperty("Required", param.getRequired().value()); - paramObj.add("InputParameter", paramDetails); - input.add(paramObj); - } - } - catch (final NullPointerException e) { - } - planJson.add("InputParameters", input); - - final JsonArray output = new JsonArray(); - try { - for (final TParameter param : plan.getOutputParameters().getOutputParameter()) { - final JsonObject paramObj = new JsonObject(); - final JsonObject paramDetails = new JsonObject(); - paramDetails.addProperty("Name", param.getName()); - paramDetails.addProperty("Type", param.getType()); - paramDetails.addProperty("Required", param.getRequired().value()); - paramObj.add("OutputParameter", paramDetails); - output.add(paramObj); - } - } - catch (final NullPointerException e) { - } - planJson.add("OutputParameters", output); - - final JsonObject planModelReference = new JsonObject(); - planModelReference.addProperty("Reference", plan.getPlanModelReference().getReference()); - planJson.add("PlanModelReference", planModelReference); - - return Response.ok(json.toString()).build(); - } - - public TPlan getPlan(final String plan) { - LOG.trace("Return plan " + plan); - final Map> map = - ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper().getCSARIDToPlans(this.csarID); - - final IToscaReferenceMapper service = ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper(); - final String ns = service.getNamespaceOfPlan(this.csarID, plan); - - final QName id = new QName(ns, plan); - - for (final PlanTypes type : PlanTypes.values()) { - if (map.get(type).containsKey(id)) { - final TPlan tPlan = map.get(type).get(id); - return tPlan; - } - } - - return null; - } - - // /** - // * PUT for BUILD plans which have no CSAR-Instance-ID yet. - // * - // * @param planElement the BUILD PublicPlan - // * @return Response - // */ - // @POST - // @Path("{PlanName}") - // @Consumes(ResourceConstants.TOSCA_XML) - // public Response postManagementPlan(@PathParam("PlanName") String plan, - // JAXBElement planElement) { - // - // CSARBoundsInterfaceOperationPlanResource.LOG.debug("Received a plan for - // CSAR " + csarID); - // - // TPlanDTO planDTO = planElement.getValue(); - // - // if (null == planDTO) { - // LOG.error("The given PublicPlan is null!"); - // return Response.status(Status.CONFLICT).build(); - // } - // - // if (null == planDTO.getId()) { - // LOG.error("The given PublicPlan has no ID!"); - // return Response.status(Status.CONFLICT).build(); - // } - // - // String namespace = - // ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper().getNamespaceOfPlan(csarID, - // planDTO.getId().getLocalPart()); - // planDTO.setId(new QName(namespace, planDTO.getId().getLocalPart())); - // - // LOG.debug("PublicPlan to invoke: " + planDTO.getId()); - // - // CSARBoundsInterfaceOperationPlanResource.LOG.debug("Post of the - // PublicPlan " + planDTO.getId()); - // - // // TODO return correlation ID - // String correlationID = - // IOpenToscaControlServiceHandler.getOpenToscaControlService().invokePlanInvocation(csarID, - // -1, planDTO); - // - // References refs = new References(); - // - // refs.getReference().add(new - // Reference(Utilities.buildURI("http://localhost:1337/containerapi", - // "/CSARs/" + csarID + "/PlanInstances/" + correlationID), - // XLinkConstants.SIMPLE, plan)); - // - // return - // Response.status(Response.Status.ACCEPTED).entity(refs.getXMLString()).build(); - // - // } - - // /** - // * - // * TODO consider to deliver this output not under the path - // * "{PlanName}/PlanWithMinimalInput" but with other MIME type under - // * "{PlanName}" - // * - // * @param uriInfo - // * @return Response - // */ - // @GET - // @Path("{PlanName}/PlanWithMinimalInput") - // @Produces(ResourceConstants.TOSCA_XML) - // public JAXBElement getMissingInputFields(@PathParam("PlanName") String - // plan) { - // LOG.trace("Return missing input fields of plan " + plan); - // - // List docs = new ArrayList(); - // - // List serviceTemplates = - // ToscaServiceHandler.getToscaEngineService().getServiceTemplatesInCSAR(csarID); - // for (QName serviceTemplate : serviceTemplates) { - // List nodeTemplates = - // ToscaServiceHandler.getToscaEngineService().getNodeTemplatesOfServiceTemplate(csarID, - // serviceTemplate); - // - // for (String nodeTemplate : nodeTemplates) { - // Document doc = - // ToscaServiceHandler.getToscaEngineService().getPropertiesOfNodeTemplate(csarID, - // serviceTemplate, nodeTemplate); - // if (null != doc) { - // docs.add(doc); - // LOG.trace("Found property document: {}", - // ToscaServiceHandler.getIXMLSerializer().docToString(doc, false)); - // } - // } - // } - // - // Map> mapPlans = - // ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper().getCSARIDToPlans(csarID); - // - // IToscaReferenceMapper service = - // ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper(); - // String ns = service.getNamespaceOfPlan(csarID, plan); - // - // QName id = new QName(ns, plan); - // TPlan tPlan = null; - // for (PlanTypes type : PlanTypes.values()) { - // if (mapPlans.get(type).containsKey(id)) { - // tPlan = mapPlans.get(type).get(id); - // } - // } - // - // TPlan retPlan = new TPlan(); - // retPlan.setId(tPlan.getId()); - // retPlan.setName(tPlan.getName()); - // retPlan.setPlanLanguage(tPlan.getPlanLanguage()); - // retPlan.setPlanType(tPlan.getPlanType()); - // retPlan.setInputParameters(new InputParameters()); - // - // List list = new ArrayList<>(); - // for (TParameter para : tPlan.getInputParameters().getInputParameter()) { - // if (para.getType().equalsIgnoreCase("correlation") || - // para.getName().equalsIgnoreCase("csarName") || - // para.getName().equalsIgnoreCase("containerApiAddress") || - // para.getName().equalsIgnoreCase("instanceDataAPIUrl")) { - // LOG.trace("Skipping parameter {}", para.getName()); - // // list.add(para); - // } else { - // LOG.trace("The parameter \"" + para.getName() + "\" may have values in - // the properties."); - // String value = ""; - // for (Document doc : docs) { - // NodeList nodes = doc.getElementsByTagNameNS("*", para.getName()); - // LOG.trace("Found {} nodes.", nodes.getLength()); - // if (nodes.getLength() > 0) { - // value = nodes.item(0).getTextContent(); - // LOG.debug("Found value {}", value); - // break; - // } - // } - // if (value.equals("")) { - // LOG.debug("Found empty input paramater {}.", para.getName()); - // list.add(para); - // } else { - // } - // } - // } - // retPlan.getInputParameters().getInputParameter().addAll(list); - // - // return - // ToscaServiceHandler.getIXMLSerializer().createJAXBElement(retPlan); - // } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsInterfaceOperationResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsInterfaceOperationResource.java deleted file mode 100644 index 4249efa1f..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsInterfaceOperationResource.java +++ /dev/null @@ -1,187 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.boundarydefinitions; - -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.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.ToscaServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BoundsInterfaceOperationResource { - - private static final Logger LOG = LoggerFactory.getLogger(BoundsInterfaceOperationResource.class); - CSARID csarID; - QName serviceTemplateID; - String intName; - String opName; - - UriInfo uriInfo; - - - public BoundsInterfaceOperationResource(final CSARID csarID, final QName serviceTemplateID, final String intName, - final String op) { - - this.csarID = csarID; - this.serviceTemplateID = serviceTemplateID; - this.intName = intName; - this.opName = op; - - if (null == ToscaServiceHandler.getToscaEngineService()) { - LOG.error("The ToscaEngineService is not alive."); - } - } - - /** - * Builds the references of the Boundary Definitions of a CSAR. - * - * @param uriInfo - * @return Response - */ - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getXMLString()).build(); - } - - /** - * Builds the references of the Boundary Definitions of a CSAR. - * - * @param uriInfo - * @return Response - */ - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getJSONString()).build(); - } - - private References getReferences() { - - final References refs = new References(); - - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo, "NodeOperation"), XLinkConstants.SIMPLE, - "NodeOperation")); - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo, "RelationshipOperation"), - XLinkConstants.SIMPLE, "RelationshipOperation")); - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo, "Plan"), XLinkConstants.SIMPLE, "Plan")); - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return refs; - } - - /** - * Returns a PublicPlan for a given Index. - * - * @param planName - * @return the PublicPlan - */ - @Path("{OperationName}") - public BoundsInterfaceOperationResource getPublicPlan(@PathParam("OperationName") final String op) { - return new BoundsInterfaceOperationResource(this.csarID, this.serviceTemplateID, this.intName, op); - } - - /** - * Returns the Boundary Definitions Node Operation. TODO not yet implemented yet, thus, just returns - * itself. - * - * @param uriInfo - * @return Response - */ - @GET - @Path("NodeOperation") - @Produces(ResourceConstants.LINKED_XML) - public Response getNodeOperationXML(@Context final UriInfo uriInfo) { - - final References refs = new References(); - // selflink - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return Response.ok(refs.getXMLString()).build(); - } - - /** - * Returns the Boundary Definitions Node Operation. TODO not yet implemented yet, thus, just returns - * itself. - * - * @param uriInfo - * @return Response - */ - @GET - @Path("NodeOperation") - @Produces(ResourceConstants.LINKED_JSON) - public Response getNodeOperationJSON(@Context final UriInfo uriInfo) { - - final References refs = new References(); - // selflink - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return Response.ok(refs.getJSONString()).build(); - } - - /** - * Returns the Boundary Definitions Node Operation. TODO not yet implemented yet, thus, just returns - * itself. - * - * @param uriInfo - * @return Response - */ - @GET - @Path("RelationshipOperation") - @Produces(ResourceConstants.LINKED_XML) - public Response getRelationshipOperationXML(@Context final UriInfo uriInfo) { - - final References refs = new References(); - // selflink - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return Response.ok(refs.getXMLString()).build(); - } - - /** - * Returns the Boundary Definitions Node Operation. TODO not yet implemented yet, thus, just returns - * itself. - * - * @param uriInfo - * @return Response - */ - @GET - @Path("RelationshipOperation") - @Produces(ResourceConstants.LINKED_JSON) - public Response getRelationshipOperationJSON(@Context final UriInfo uriInfo) { - - final References refs = new References(); - // selflink - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return Response.ok(refs.getJSONString()).build(); - } - - /** - * Returns the Boundary Definitions Node Operation. TODO not yet implemented yet, thus, just returns - * itself. - * - * @param uriInfo - * @return Response - */ - @Path("Plan") - public BoundsInterfaceOperationPlanResource getPlan(@Context final UriInfo uriInfo) { - return new BoundsInterfaceOperationPlanResource(this.csarID, this.serviceTemplateID, this.intName, this.opName); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsInterfaceOperationsResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsInterfaceOperationsResource.java deleted file mode 100644 index b0ddb1469..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsInterfaceOperationsResource.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.boundarydefinitions; - -import java.util.List; - -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.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.ToscaServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BoundsInterfaceOperationsResource { - - private static final Logger LOG = LoggerFactory.getLogger(BoundsInterfaceOperationsResource.class); - private final CSARID csarID; - private final QName serviceTemplateID; - private final String intName; - - UriInfo uriInfo; - - - public BoundsInterfaceOperationsResource(final CSARID csarID, final QName serviceTemplateID, final String intName) { - - this.csarID = csarID; - this.intName = intName; - this.serviceTemplateID = serviceTemplateID; - - if (null == ToscaServiceHandler.getToscaEngineService()) { - LOG.error("The ToscaEngineService is not alive."); - } - } - - /** - * Builds the references of the Boundary Definitions of a CSAR. - * - * @param uriInfo - * @return Response - */ - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getXMLString()).build(); - } - - /** - * Builds the references of the Boundary Definitions of a CSAR. - * - * @param uriInfo - * @return Response - */ - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getJSONString()).build(); - } - - private References getReferences() { - - final References refs = new References(); - - LOG.debug("Find operations for ST {} and Intf {}", this.serviceTemplateID, this.intName); - - final List ops = - ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper() - .getBoundaryOperationsOfCSARInterface(this.csarID, this.serviceTemplateID, this.intName); - - for (final String op : ops) { - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo, op), XLinkConstants.SIMPLE, op)); - } - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return refs; - } - - /** - * Returns a PublicPlan for a given Index. - * - * @param planName - * @return the PublicPlan - */ - @Path("{OperationName}") - public BoundsInterfaceOperationResource getPublicPlan(@PathParam("OperationName") final String op) { - return new BoundsInterfaceOperationResource(this.csarID, this.serviceTemplateID, this.intName, op); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsInterfaceResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsInterfaceResource.java deleted file mode 100644 index cf11429aa..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsInterfaceResource.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.boundarydefinitions; - -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.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.ToscaServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BoundsInterfaceResource { - - private static final Logger LOG = LoggerFactory.getLogger(BoundsInterfaceResource.class); - private final CSARID csarID; - private QName serviceTemplateID = null; - private final String intName; - - UriInfo uriInfo; - - - public BoundsInterfaceResource(final CSARID csarID, final QName serviceTemplateID, final String intName) { - this.csarID = csarID; - this.serviceTemplateID = serviceTemplateID; - this.intName = intName; - - if (null == ToscaServiceHandler.getToscaEngineService()) { - LOG.error("The ToscaEngineService is not alive."); - } - } - - /** - * Builds the references of the Boundary Definitions of a CSAR. - * - * @param uriInfo - * @return Response - */ - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getXMLString()).build(); - } - - /** - * Builds the references of the Boundary Definitions of a CSAR. - * - * @param uriInfo - * @return Response - */ - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getJSONString()).build(); - } - - private References getReferences() { - - final References refs = new References(); - - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo, "Operations"), XLinkConstants.SIMPLE, "Operations")); - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return refs; - } - - /** - * Returns the Interface Operations for a given Interface name. - * - * @param planName - * @return the PublicPlan - */ - @Path("Operations") - public BoundsInterfaceOperationsResource getPublicPlan(@PathParam("InterfaceName") final String intName) { - return new BoundsInterfaceOperationsResource(this.csarID, this.serviceTemplateID, intName); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsInterfacesResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsInterfacesResource.java deleted file mode 100644 index a54338f19..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsInterfacesResource.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.boundarydefinitions; - -import java.util.List; - -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.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.ToscaServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BoundsInterfacesResource { - - private static final Logger LOG = LoggerFactory.getLogger(BoundsInterfacesResource.class); - private CSARID csarID = null; - private QName serviceTemplateID = null; - - UriInfo uriInfo; - - - public BoundsInterfacesResource(final CSARID csarID, final QName serviceTemplateID) { - this.csarID = csarID; - this.serviceTemplateID = serviceTemplateID; - - if (null == ToscaServiceHandler.getToscaEngineService()) { - LOG.error("The ToscaEngineService is not alive."); - } - } - - /** - * Builds the references of the Boundary Definitions of a CSAR. - * - * @param uriInfo - * @return Response - */ - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getXMLString()).build(); - } - - /** - * Builds the references of the Boundary Definitions of a CSAR. - * - * @param uriInfo - * @return Response - */ - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getJSONString()).build(); - } - - private References getReferences() { - - final References refs = new References(); - - final List interfaces = ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper() - .getBoundaryInterfacesOfCSAR(this.csarID); - - if (null != interfaces) { - for (final String intf : interfaces) { - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo, intf), XLinkConstants.SIMPLE, intf)); - } - } - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return refs; - } - - /** - * Returns the Interface Operations for a given Interface name. - * - * @param planName - * @return the PublicPlan - */ - @Path("{InterfaceName}") - public BoundsInterfaceResource getPublicPlan(@PathParam("InterfaceName") final String intName) { - return new BoundsInterfaceResource(this.csarID, this.serviceTemplateID, intName); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsProperties.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsProperties.java deleted file mode 100644 index 105ca7203..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsProperties.java +++ /dev/null @@ -1,219 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.boundarydefinitions; - -import java.io.IOException; -import java.io.StringReader; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.opentosca.container.api.legacy.osgi.servicegetter.ToscaServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.JSONUtils; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.tosca.model.TBoundaryDefinitions.Properties.PropertyMappings; -import org.opentosca.container.core.tosca.model.TPropertyMapping; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; - -public class BoundsProperties { - - private static final Logger LOG = LoggerFactory.getLogger(BoundsInterfacesResource.class); - CSARID csarID = null; - - UriInfo uriInfo; - - - public BoundsProperties(final CSARID csarID, final QName serviceTemplateID) { - this.csarID = csarID; - - if (null == ToscaServiceHandler.getToscaEngineService()) { - LOG.error("The ToscaEngineService is not alive."); - } - } - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getPropertiesXML(@Context final UriInfo uriInfo) { - - if (this.csarID == null) { - return Response.status(404).build(); - } - - LOG.trace("Return Boundary Definitions Properties for CSAR {}.", this.csarID); - - - final References refs = getRefs(uriInfo); - - - return Response.ok(refs.getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getPropertiesJSON(@Context final UriInfo uriInfo) { - - if (this.csarID == null) { - return Response.status(404).build(); - } - - LOG.trace("Return Boundary Definitions Properties for CSAR {}.", this.csarID); - - final References refs = getRefs(uriInfo); - - return Response.ok(refs.getJSONString()).build(); - } - - private References getRefs(final UriInfo uriInfo) { - final References refs = new References(); - // selflink - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - refs.getReference() - .add(new Reference(Utilities.buildURI(uriInfo, "XMLFragments"), XLinkConstants.SIMPLE, "XMLFragments")); - refs.getReference().add(new Reference(Utilities.buildURI(uriInfo, "PropertyMappings"), XLinkConstants.SIMPLE, - "PropertyMappings")); - return refs; - } - - /** - * Returns the Boundary Definitions Properties XML fragment content as XML. TODO This resource is - * not scoped under a Service Template, thus, return all Bounds Properties of all STs. - * - * @param uriInfo - * @return Response - */ - @GET - @Path("XMLFragments") - @Produces(ResourceConstants.TOSCA_XML) - public Response getPropertiesContentXML(@Context final UriInfo uriInfo) { - - if (this.csarID == null) { - return Response.status(404).build(); - } - - LOG.trace("Return Boundary Definitions Properties XML for CSAR {}.", this.csarID); - - final StringBuilder builder = - new StringBuilder().append(""); - final List props = ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper() - .getServiceTemplateBoundsPropertiesContent(this.csarID); - - for (final String str : props) { - builder.append(str.replace("", "")); - } - - builder.append(""); - - return Response.ok(builder.toString()).build(); - } - - /** - * Returns the Boundary Definitions Properties JSON fragment content as XML. TODO This resource is - * not scoped under a Service Template, thus, return all Bounds Properties of all STs. - * - * @param uriInfo - * @return Response - */ - @GET - @Path("XMLFragments") - @Produces(ResourceConstants.TOSCA_JSON) - public Response getPropertiesContentJSON(@Context final UriInfo uriInfo) { - - if (this.csarID == null) { - return Response.status(404).build(); - } - - LOG.trace("Return Boundary Definitions Properties XML for CSAR {}.", this.csarID); - - final JsonObject ret = new JsonObject(); - final JsonArray array = new JsonArray(); - ret.add("XMLFragments", array); - final List props = ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper() - .getServiceTemplateBoundsPropertiesContent(this.csarID); - - for (final String xml : props) { - - try { - final DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - final InputSource source = new InputSource(); - source.setCharacterStream(new StringReader(xml)); - final Document doc = db.parse(source); - - array.addAll(new JSONUtils().xmlToJsonArray(doc.getElementsByTagName("Properties").item(0) - .getChildNodes())); - - } - catch (final ParserConfigurationException e) { - e.printStackTrace(); - } - catch (final SAXException e) { - e.printStackTrace(); - } - catch (final IOException e) { - e.printStackTrace(); - } - - } - - return Response.ok(ret.toString()).build(); - } - - @GET - @Path("PropertyMappings") - @Produces(ResourceConstants.TOSCA_XML) - public PropertyMappings getMappingsXML() { - return ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper() - .getServiceTemplateBoundsPropertyMappings(this.csarID).get(0); - } - - @GET - @Path("PropertyMappings") - @Produces(ResourceConstants.TOSCA_JSON) - public Response getMappingsJSON() { - - final List mappingsList = - ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper() - .getServiceTemplateBoundsPropertyMappings(this.csarID); - final JsonObject ret = new JsonObject(); - final JsonArray array = new JsonArray(); - ret.add("XMLFragments", array); - - for (final PropertyMappings mappings : mappingsList) { - final JsonObject jMappings = new JsonObject(); - final JsonArray mappingArray = new JsonArray(); - jMappings.add("PropertyMappings", mappingArray); - for (final TPropertyMapping mapping : mappings.getPropertyMapping()) { - final JsonObject mappingObj = new JsonObject(); - mappingObj.addProperty("serviceTemplatePropertyRef", mapping.getServiceTemplatePropertyRef()); - mappingObj.addProperty("targetObjectRef", - ToscaServiceHandler.getIXMLSerializer() - .marshalToString(mapping.getTargetObjectRef())); - mappingObj.addProperty("targetPropertyRef", mapping.getTargetPropertyRef()); - mappingArray.add(mappingObj); - } - array.add(jMappings); - } - - return Response.ok(ret.toString()).build(); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsResource.java deleted file mode 100644 index 341d1597f..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/boundarydefinitions/BoundsResource.java +++ /dev/null @@ -1,230 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.boundarydefinitions; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.ToscaServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * Copyright 2016 IAAS University of Stuttgart
- *
- * - * @author christian.endres@iaas.uni-stuttgart.de - * - */ -public class BoundsResource { - - private static final Logger LOG = LoggerFactory.getLogger(BoundsResource.class); - - private final CSARID csarID; - private final QName serviceTemplateID; - - UriInfo uriInfo; - - - public BoundsResource(final CSARID csarid, final QName serviceTemplateID) { - - this.csarID = csarid; - this.serviceTemplateID = serviceTemplateID; - - if (null == ToscaServiceHandler.getToscaEngineService()) { - LOG.error("The ToscaEngineService is not alive."); - } - - LOG.info("{} created: {}", this.getClass(), this); - LOG.debug("Public Plans for requested CSAR: {}", this.csarID.getFileName()); - } - - /** - * Builds the references of the Boundary Definitions of a CSAR. - * - * @param uriInfo - * @return Response - */ - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getXMLString()).build(); - } - - /** - * Builds the references of the Boundary Definitions of a CSAR. - * - * @param uriInfo - * @return Response - */ - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getJSONString()).build(); - } - - private References getReferences() { - - if (this.csarID == null) { - return null; - } - - LOG.trace("Return Boundary Definitions for CSAR {}.", this.csarID); - - final References refs = new References(); - - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo, "Properties"), XLinkConstants.SIMPLE, "Properties")); - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo, "PropertyConstraints"), - XLinkConstants.SIMPLE, "PropertyConstraints")); - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo, "Requirements"), XLinkConstants.SIMPLE, - "Requirements")); - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo, "Capabilities"), XLinkConstants.SIMPLE, - "Capabilities")); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo, "Policies"), XLinkConstants.SIMPLE, "Policies")); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo, "Interfaces"), XLinkConstants.SIMPLE, "Interfaces")); - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return refs; - } - - /** - * Returns the Boundary Definitions Properties. * - * - * @param uriInfo - * @return Response - */ - - @Path("Properties") - public BoundsProperties getProperties(@Context final UriInfo uriInfo) { - return new BoundsProperties(this.csarID, this.serviceTemplateID); - } - - /** - * Returns the Boundary Definitions Properties. TODO not yet implemented yet, thus, just returns - * itself. - * - * @param uriInfo - * @return Response - */ - @GET - @Path("PropertyConstraints") - @Produces(ResourceConstants.LINKED_XML) - public Response getPropertyConstraints(@Context final UriInfo uriInfo) { - - if (this.csarID == null) { - return Response.status(404).build(); - } - - LOG.trace("Return Boundary Definitions for CSAR {}.", this.csarID); - - final References refs = new References(); - // selflink - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return Response.ok(refs.getXMLString()).build(); - } - - /** - * Returns the Boundary Definitions Properties. TODO not yet implemented yet, thus, just returns - * itself. - * - * @param uriInfo - * @return Response - */ - @GET - @Path("Requirements") - @Produces(ResourceConstants.LINKED_XML) - public Response getRequirements(@Context final UriInfo uriInfo) { - - if (this.csarID == null) { - return Response.status(404).build(); - } - - LOG.trace("Return Boundary Definitions for CSAR {}.", this.csarID); - - final References refs = new References(); - // selflink - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return Response.ok(refs.getXMLString()).build(); - } - - /** - * Returns the Boundary Definitions Properties. TODO not yet implemented yet, thus, just returns - * itself. - * - * @param uriInfo - * @return Response - */ - @GET - @Path("Capabilities") - @Produces(ResourceConstants.LINKED_XML) - public Response getCapabilities(@Context final UriInfo uriInfo) { - - if (this.csarID == null) { - return Response.status(404).build(); - } - - LOG.trace("Return Boundary Definitions for CSAR {}.", this.csarID); - - final References refs = new References(); - // selflink - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return Response.ok(refs.getXMLString()).build(); - } - - /** - * Returns the Boundary Definitions Properties. TODO not yet implemented yet, thus, just returns - * itself. - * - * @param uriInfo - * @return Response - */ - @GET - @Path("Policies") - @Produces(ResourceConstants.LINKED_XML) - public Response getPolicies(@Context final UriInfo uriInfo) { - - if (this.csarID == null) { - return Response.status(404).build(); - } - - LOG.trace("Return Boundary Definitions for CSAR {}.", this.csarID); - - final References refs = new References(); - // selflink - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return Response.ok(refs.getXMLString()).build(); - } - - /** - * Returns a PublicPlan for a given Index. - * - * @param planName - * @return the PublicPlan - */ - @Path("Interfaces") - public BoundsInterfacesResource getInterfaces(@Context final UriInfo uriInfo) { - return new BoundsInterfacesResource(this.csarID, this.serviceTemplateID); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/BuildCorrelationToInstanceMapping.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/BuildCorrelationToInstanceMapping.java deleted file mode 100644 index 522632bb9..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/BuildCorrelationToInstanceMapping.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances; - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -/** - * TODO refactoring: move this to a suitable point - * - * Copyright 2017 IAAS University of Stuttgart
- *
- * - * @author Christian Endres - christian.endres@iaas.uni-stuttgart.de - * - */ -@Deprecated -public class BuildCorrelationToInstanceMapping { - - public static BuildCorrelationToInstanceMapping instance = new BuildCorrelationToInstanceMapping(); - - private final Map correlationIdToServiceTemplateInstanceId = new HashMap<>(); - - - private BuildCorrelationToInstanceMapping() {} - - public void correlateCorrelationIdToServiceTemplateInstanceId(final String corrId, - final int serviceTemplateInstanceId) { - this.correlationIdToServiceTemplateInstanceId.put(corrId, serviceTemplateInstanceId); - } - - public Integer getServiceTemplateInstanceIdForBuildPlanCorrelation(final String corrId) { - return this.correlationIdToServiceTemplateInstanceId.get(corrId); - } - - public boolean knowsCorrelationId(final String buildPlanCorrId) { - return this.correlationIdToServiceTemplateInstanceId.containsKey(buildPlanCorrId); - } - - public String getCorrelationId(final int serviceTemplateInstanceId) { - for (final Entry entry : this.correlationIdToServiceTemplateInstanceId.entrySet()) { - if (entry.getValue() == serviceTemplateInstanceId) { - return entry.getKey(); - } - } - return null; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/ServiceTemplateInstancePropertiesResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/ServiceTemplateInstancePropertiesResource.java deleted file mode 100644 index 0aa63250b..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/ServiceTemplateInstancePropertiesResource.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances; - -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.PUT; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.instancedata.LinkBuilder; -import org.opentosca.container.api.legacy.instancedata.exception.GenericRestException; -import org.opentosca.container.api.legacy.instancedata.model.SimpleXLink; -import org.opentosca.container.api.legacy.osgi.servicegetter.InstanceDataServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.JSONUtils; -import org.opentosca.container.core.common.ReferenceNotFoundException; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.model.instance.IdConverter; -import org.opentosca.container.core.service.IInstanceDataService; -import org.w3c.dom.Document; - -/** - * - * @author Kálmán Képes - kalman.kepes@iaas.uni-stuttgart.de - * - */ -public class ServiceTemplateInstancePropertiesResource { - - private final CSARID csarId; - private final QName serviceTemplateID; - private final int serviceInstanceID; - - - public ServiceTemplateInstancePropertiesResource(final CSARID csarId, final QName serviceTemplateID, final int id) { - this.csarId = csarId; - this.serviceTemplateID = serviceTemplateID; - this.serviceInstanceID = id; - } - - @GET - @Produces(MediaType.APPLICATION_XML) - public Response doGetXML(@QueryParam("property") final List propertiesList) { - - final Document idr = this.getRefs(propertiesList); - - return Response.ok(idr).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response doGetJSON(@QueryParam("property") final List propertiesList) { - - final Document idr = this.getRefs(propertiesList); - - return Response.ok(new JSONUtils().xmlToGenericJsonObject(idr.getChildNodes()).toString()).build(); - } - - public Document getRefs(final List propertiesList) { - final List qnameList = new ArrayList<>(); - - // convert all String in propertyList to qnames - try { - if (propertiesList != null) { - for (final String stringValue : propertiesList) { - qnameList.add(QName.valueOf(stringValue)); - } - } - } - catch (final Exception e) { - throw new GenericRestException(Status.BAD_REQUEST, - "error converting one of the properties-parameters: " + e.getMessage()); - } - - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - try { - final Document properties = - service.getServiceInstanceProperties(IdConverter.serviceInstanceIDtoURI(this.serviceInstanceID), - qnameList); - return properties; - } - catch (final ReferenceNotFoundException e) { - throw new GenericRestException(Status.NOT_FOUND, e.getMessage()); - } - } - - @PUT - @Produces(MediaType.APPLICATION_XML) - @Consumes(MediaType.APPLICATION_XML) - public Response setProperties(@Context final UriInfo uriInfo, final Document xml) { - - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - - try { - service.setServiceInstanceProperties(IdConverter.serviceInstanceIDtoURI(this.serviceInstanceID), xml); - } - catch (final ReferenceNotFoundException e) { - throw new GenericRestException(Status.NOT_FOUND, e.getMessage()); - } - - final SimpleXLink xLink = - new SimpleXLink(LinkBuilder.linkToServiceInstanceProperties(uriInfo, this.serviceInstanceID), - "ServiceInstance: " + this.serviceInstanceID + " Properties"); - return Response.ok(xLink).build(); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/ServiceTemplateInstanceResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/ServiceTemplateInstanceResource.java deleted file mode 100644 index 57950910c..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/ServiceTemplateInstanceResource.java +++ /dev/null @@ -1,268 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances; - -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -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.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.InstanceDataServiceHandler; -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.plans.PlanInstances; -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.nodetemplate.NodeTemplatesResource; -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.relationshiptemplate.RelationshipTemplatesResource; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.model.instance.IdConverter; -import org.opentosca.container.core.service.IInstanceDataService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.JsonObject; - -/** - * - * @author Marcus Eisele - * - */ -public class ServiceTemplateInstanceResource { - - private final Logger log = LoggerFactory.getLogger(ServiceTemplateInstanceResource.class); - - private final CSARID csarId; - private final QName serviceTemplateID; - private final int serviceTemplateInstanceId; - - - public ServiceTemplateInstanceResource(final CSARID csarId, final QName serviceTemplateID, - final int serviceTemplateInstanceId) { - this.csarId = csarId; - this.serviceTemplateID = serviceTemplateID; - this.serviceTemplateInstanceId = serviceTemplateInstanceId; - } - - @GET - @Produces(MediaType.APPLICATION_XML) - public Response doGetXML(@Context final UriInfo uriInfo) { - - final References idr = this.getRefs(uriInfo); - - if (null == idr) { - Response.status(Status.INTERNAL_SERVER_ERROR).build(); - } - - return Response.ok(idr.getXMLString()).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response doGetJSON(@Context final UriInfo uriInfo) { - - final References idr = this.getRefs(uriInfo); - - if (null == idr) { - Response.status(Status.INTERNAL_SERVER_ERROR).build(); - } - - return Response.ok(idr.getJSONString()).build(); - } - - public References getRefs(final UriInfo uriInfo) { - - final References refs = new References(); - - refs.getReference() - .add(new Reference(Utilities.buildURI(uriInfo, "NodeTemplates"), XLinkConstants.SIMPLE, "NodeTemplates")); - refs.getReference() - .add(new Reference(Utilities.buildURI(uriInfo, "PlanInstances"), XLinkConstants.SIMPLE, "PlanInstances")); - refs.getReference() - .add(new Reference(Utilities.buildURI(uriInfo, "Properties"), XLinkConstants.SIMPLE, "Properties")); - refs.getReference().add(new Reference(Utilities.buildURI(uriInfo, "State"), XLinkConstants.SIMPLE, "State")); - refs.getReference().add(new Reference(Utilities.buildURI(uriInfo, "RelationshipTemplates"), - XLinkConstants.SIMPLE, "RelationshipTemplates")); - - // selflink - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return refs; - // } catch (Exception e) { - // e.printStackTrace(); - // return null; - // } - } - - @DELETE - public Response deleteServiceInstance() { - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - service.deleteServiceInstance(IdConverter.serviceInstanceIDtoURI(this.serviceTemplateInstanceId)); - return Response.noContent().build(); - } - - @Path("NodeTemplates") - public Object getNodeTemplates() { - return new NodeTemplatesResource(this.csarId, this.serviceTemplateID, this.serviceTemplateInstanceId); - } - - @Path("RelationshipTemplates") - public Object getRelationshipTemplates() { - return new RelationshipTemplatesResource(this.csarId, this.serviceTemplateID, this.serviceTemplateInstanceId); - } - - @Path("/Properties") - public Object getProperties() { - return new ServiceTemplateInstancePropertiesResource(this.csarId, this.serviceTemplateID, - this.serviceTemplateInstanceId); - } - - @Path("/State") - public Object getState() { - return new ServiceTemplateInstanceStateResource(this.serviceTemplateInstanceId); - } - - @Path("/PlanInstances") - public Object getPlanInstances() { - return new PlanInstances(this.csarId, this.serviceTemplateID, this.serviceTemplateInstanceId); - } - - // @Path("/NodeTemplates") - // public Object getNodeInstances() { - // return new NodeTemplateInstancesResource(csarId, serviceTemplateID, - // serviceTemplateInstanceId); - // } - - /** - * PUT for BUILD plans which have no CSAR-Instance-ID yet. - * - * @param planElement the BUILD PublicPlan - * @return Response - * @throws URISyntaxException - * @throws UnsupportedEncodingException - */ - @POST - @Consumes(ResourceConstants.TEXT_PLAIN) - @Produces(ResourceConstants.APPLICATION_JSON) - public Response postBUILDJSONReturnJSON(@Context final UriInfo uriInfo, - final String json) throws URISyntaxException, UnsupportedEncodingException { - final String url = this.postManagementPlanJSON(uriInfo, json); - final JsonObject ret = new JsonObject(); - ret.addProperty("PlanURL", url); - return Response.created(new URI(url)).entity(ret.toString()).build(); - } - - /** - * PUT for BUILD plans which have no CSAR-Instance-ID yet. - * - * @param planElement the BUILD PublicPlan - * @return Response - * @throws URISyntaxException - * @throws UnsupportedEncodingException - */ - @POST - @Consumes(ResourceConstants.TEXT_PLAIN) - @Produces(ResourceConstants.TOSCA_XML) - public Response postBUILDJSONReturnXML(@Context final UriInfo uriInfo, - final String json) throws URISyntaxException, UnsupportedEncodingException { - - final String url = this.postManagementPlanJSON(uriInfo, json); - // return Response.ok(postManagementPlanJSON(uriInfo, json)).build(); - return Response.created(new URI(url)).build(); - } - - /** - * PUT for BUILD plans which have no CSAR-Instance-ID yet. - * - * @param planElement the BUILD PublicPlan - * @return Response - * @throws UnsupportedEncodingException - */ - @Deprecated - private String postManagementPlanJSON(final UriInfo uriInfo, - final String json) throws UnsupportedEncodingException { - - throw new UnsupportedOperationException(); - - // this.log - // .debug("Received a build plan for CSAR " + this.csarId + "\npassed entity:\n " + json); - // - // final JsonParser parser = new JsonParser(); - // final JsonObject object = parser.parse(json).getAsJsonObject(); - // - // this.log.trace(JSONUtils.withoutQuotationMarks(object.get("ID").toString())); - // - // final TPlanDTO plan = new TPlanDTO(); - // - // plan.setId(new QName(JSONUtils.withoutQuotationMarks(object.get("ID").toString()))); - // plan.setName(JSONUtils.withoutQuotationMarks(object.get("Name").toString())); - // plan.setPlanType(JSONUtils.withoutQuotationMarks(object.get("PlanType").toString())); - // plan.setPlanLanguage(JSONUtils.withoutQuotationMarks(object.get("PlanLanguage").toString())); - // - // JsonArray array = object.get("InputParameters").getAsJsonArray(); - // Iterator iterator = array.iterator(); - // while (iterator.hasNext()) { - // final TParameterDTO para = new TParameterDTO(); - // final JsonObject tmp = iterator.next().getAsJsonObject(); - // para.setName(JSONUtils.withoutQuotationMarks( - // tmp.get("InputParameter").getAsJsonObject().get("Name").toString())); - // para.setRequired(TBoolean.fromValue(JSONUtils.withoutQuotationMarks( - // tmp.get("InputParameter").getAsJsonObject().get("Required").toString()))); - // para.setType(JSONUtils.withoutQuotationMarks( - // tmp.get("InputParameter").getAsJsonObject().get("Type").toString())); - // // if a parameter value is not set, just add "" as value - // if (null != tmp.get("InputParameter").getAsJsonObject().get("Value")) { - // para.setValue(JSONUtils.withoutQuotationMarks( - // tmp.get("InputParameter").getAsJsonObject().get("Value").toString())); - // } else { - // para.setValue(""); - // } - // plan.getInputParameters().getInputParameter().add(para); - // } - // array = object.get("OutputParameters").getAsJsonArray(); - // iterator = array.iterator(); - // while (iterator.hasNext()) { - // final TParameterDTO para = new TParameterDTO(); - // final JsonObject tmp = iterator.next().getAsJsonObject(); - // para.setName(JSONUtils.withoutQuotationMarks( - // tmp.get("OutputParameter").getAsJsonObject().get("Name").toString())); - // para.setRequired(TBoolean.fromValue(JSONUtils.withoutQuotationMarks( - // tmp.get("OutputParameter").getAsJsonObject().get("Required").toString()))); - // para.setType(JSONUtils.withoutQuotationMarks( - // tmp.get("OutputParameter").getAsJsonObject().get("Type").toString())); - // plan.getOutputParameters().getOutputParameter().add(para); - // } - // - // final String namespace = - // ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper() - // .getNamespaceOfPlan(this.csarId, plan.getId().getLocalPart()); - // plan.setId(new QName(namespace, plan.getId().getLocalPart())); - // - // this.log.debug("Post of the Plan " + plan.getId()); - // - // final String correlationID = - // IOpenToscaControlServiceHandler.getOpenToscaControlService().invokePlanInvocation( - // this.csarId, this.serviceTemplateID, this.serviceTemplateInstanceId, plan); - // - // this.log.debug("Return correlation ID of running plan: " + correlationID); - // - // final String url = uriInfo.getBaseUri().toString() + "CSARs/" + this.csarId.getFileName() - // + "/ServiceTemplates/" + URLEncoder.encode(this.serviceTemplateID.toString(), "UTF-8") - // + "/ServiceTemplateInstances/" + this.serviceTemplateInstanceId + "/PlanInstances/" - // + correlationID; - // - // return url; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/ServiceTemplateInstanceStateResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/ServiceTemplateInstanceStateResource.java deleted file mode 100644 index 495e18f80..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/ServiceTemplateInstanceStateResource.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.PUT; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.instancedata.exception.GenericRestException; -import org.opentosca.container.api.legacy.osgi.servicegetter.InstanceDataServiceHandler; -import org.opentosca.container.core.common.ReferenceNotFoundException; -import org.opentosca.container.core.model.instance.IdConverter; -import org.opentosca.container.core.service.IInstanceDataService; - -import com.google.gson.JsonObject; - -/** - * @author Marcus Eisele - marcus.eisele@gmail.com - * - */ -public class ServiceTemplateInstanceStateResource { - - private final int nodeInstanceID; - - - public ServiceTemplateInstanceStateResource(final int id) { - this.nodeInstanceID = id; - } - - @GET - @Produces(MediaType.TEXT_PLAIN) - public Response doGetXML() { - - final String idr = this.getState(); - - return Response.ok(idr).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response doGetJSON() { - - final String idr = this.getState(); - - final JsonObject json = new JsonObject(); - json.addProperty("state", idr); - - return Response.ok(json.toString()).build(); - } - - public String getState() { - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - - try { - final String state = - service.getServiceInstanceState(IdConverter.serviceInstanceIDtoURI(this.nodeInstanceID)); - - if (state != null) { - return state; - } else { - return null; - } - } - catch (final ReferenceNotFoundException e) { - throw new GenericRestException(Status.NOT_FOUND, - "Specified nodeInstance with id: " + this.nodeInstanceID + " doesn't exist"); - } - } - - @PUT - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.APPLICATION_XML) - public Response setState(@Context final UriInfo uriInfo, final String state) { - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - - QName stateQName = null; - try { - stateQName = QName.valueOf(state); - - } - catch (final Exception e1) { - throw new GenericRestException(Status.BAD_REQUEST, "Error converting parameter state: " + e1.getMessage()); - } - - try { - service.setServiceInstanceState(IdConverter.serviceInstanceIDtoURI(this.nodeInstanceID), state); - - // SimpleXLink xLink = new - // SimpleXLink(LinkBuilder.linkToNodeInstanceState(uriInfo, - // nodeInstanceID), "NodeInstance: " + nodeInstanceID + " State"); - return Response.ok().build(); - } - catch (final ReferenceNotFoundException e) { - throw new GenericRestException(Status.NOT_FOUND, - "Specified nodeInstance with id: " + this.nodeInstanceID + " doesn't exist"); - } - - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/ServiceTemplateInstancesResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/ServiceTemplateInstancesResource.java deleted file mode 100644 index 477430525..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/ServiceTemplateInstancesResource.java +++ /dev/null @@ -1,388 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances; - -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Iterator; -import java.util.List; -import java.util.Optional; - -import javax.ws.rs.BadRequestException; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.instancedata.ExistenceChecker; -import org.opentosca.container.api.legacy.instancedata.exception.GenericRestException; -import org.opentosca.container.api.legacy.instancedata.model.SimpleXLink; -import org.opentosca.container.api.legacy.instancedata.utilities.Constants; -import org.opentosca.container.api.legacy.osgi.servicegetter.IOpenToscaControlServiceHandler; -import org.opentosca.container.api.legacy.osgi.servicegetter.InstanceDataServiceHandler; -import org.opentosca.container.api.legacy.osgi.servicegetter.ToscaServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.JSONUtils; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.impl.persistence.Converters; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.model.instance.ServiceInstance; -import org.opentosca.container.core.next.model.PlanInstance; -import org.opentosca.container.core.next.model.ServiceTemplateInstance; -import org.opentosca.container.core.next.repository.PlanInstanceRepository; -import org.opentosca.container.core.next.repository.ServiceTemplateInstanceRepository; -import org.opentosca.container.core.service.IInstanceDataService; -import org.opentosca.container.core.tosca.extension.TParameterDTO; -import org.opentosca.container.core.tosca.extension.TPlanDTO; -import org.opentosca.container.core.tosca.model.TBoolean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -/** - * @author User christian.endres@iaas.uni-stuttgart.de - * @author Florian Haupt - * @author Marcus Eisele - * - */ -public class ServiceTemplateInstancesResource { - - private final Logger log = LoggerFactory.getLogger(ServiceTemplateInstancesResource.class); - private final CSARID csarId; - private final QName serviceTemplateID; - - public ServiceTemplateInstancesResource(final CSARID csarid, final QName serviceTemplateID) { - this.csarId = csarid; - this.serviceTemplateID = serviceTemplateID; - this.log.debug("Created \"{}\":\"{}\";", serviceTemplateID.getNamespaceURI(), serviceTemplateID.getLocalPart()); - } - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response doGetXML(@Context final UriInfo uriInfo, - @QueryParam("BuildPlanCorrelationId") final String buildPlanCorrId) { - - final References refs = this.getRefs(uriInfo, buildPlanCorrId); - - return Response.ok(refs.getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response doGetJSON(@Context final UriInfo uriInfo, - @QueryParam("BuildPlanCorrelationId") final String buildPlanCorrId) { - - final References refs = this.getRefs(uriInfo, buildPlanCorrId); - - return Response.ok(refs.getJSONString()).build(); - } - - public References getRefs(final UriInfo uriInfo, final String buildPlanCorrId) { - - // URI serviceInstanceIdURI = null; - // QName serviceTemplateIDQName = null; - // try { - // if (serviceInstanceID != null) { - // serviceInstanceIdURI = new URI(serviceInstanceID); - // if (!IdConverter.isValidServiceInstanceID(serviceInstanceIdURI)) { - // throw new Exception("Error converting serviceInstanceID: invalid - // format!"); - // } - // } - // if (serviceTemplateID != null) { - // serviceTemplateIDQName = QName.valueOf(serviceTemplateID); - // } - // } catch (Exception e1) { - // throw new GenericRestException(Status.BAD_REQUEST, "Bad Request due - // to bad variable content: " + e1.getMessage()); - // } - - // try { - - final References refs = new References(); - - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - - final List serviceInstances = - service.getServiceInstancesWithDetails(this.csarId, this.serviceTemplateID, null); - - // get all instance ids - if (null == buildPlanCorrId || buildPlanCorrId.isEmpty()) { - - // List serviceInstances = - // service.getServiceInstances(serviceInstanceIdURI, - // serviceTemplateName, serviceTemplateIDQName); - this.log.debug("Returning all known Service Template instance IDs ({}).", serviceInstances.size()); - - for (final ServiceInstance serviceInstance : serviceInstances) { - - this.log.debug("ST ID of service \"{}\":\"{}\" vs. path \"{}\":\"{}\"", - serviceInstance.getServiceTemplateID().getNamespaceURI(), - serviceInstance.getServiceTemplateID().getLocalPart(), - this.serviceTemplateID.getNamespaceURI(), this.serviceTemplateID.getLocalPart()); - if (serviceInstance.getServiceTemplateID().equals(this.serviceTemplateID)) { - - final int instanceId = serviceInstance.getDBId(); - refs.getReference().add(new Reference(serviceInstance.getServiceInstanceID().toString(), - XLinkConstants.SIMPLE, Integer.toString(instanceId))); - } - // URI urlToServiceInstance = - // LinkBuilder.linkToServiceInstance(uriInfo, - // serviceInstance.getDBId()); - // - // // build simpleXLink with the internalID as LinkText - // // TODO: is the id the correct linkText? - // links.add(new SimpleXLink(urlToServiceInstance, - // serviceInstance.getDBId() + "")); - } - } - // get instance id of plan correlation only - else { - final PlanInstanceRepository repo = new PlanInstanceRepository(); - final PlanInstance pi = repo.findByCorrelationId(buildPlanCorrId); - - final ServiceTemplateInstance sti = pi.getServiceTemplateInstance(); - - final ServiceInstance si = Converters.convert(sti); - - // final int instanceId = BuildCorrelationToInstanceMapping.instance - // .getServiceTemplateInstanceIdForBuildPlanCorrelation(buildPlanCorrId); - // for (ServiceInstance serviceInstance : serviceInstances) { - // if (serviceInstance.getDBId() == instanceId) { - refs.getReference().add(new Reference(si.getServiceInstanceID().toString(), XLinkConstants.SIMPLE, - Integer.toString(si.getDBId()))); - // } - // } - this.log.debug("Returning only the Service Template instance ID for correlation {} ({}).", buildPlanCorrId, - si.getServiceInstanceID()); - - // URI urlToServiceInstance = - // LinkBuilder.linkToServiceInstance(uriInfo, instanceId); - // - // // build simpleXLink with the internalID as LinkText - // // TODO: is the id the correct linkText? - // links.add(new SimpleXLink(urlToServiceInstance, instanceId + - // "")); - - } - - // selflink - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - // ServiceInstanceList sil = new - // ServiceInstanceList(LinkBuilder.selfLink(uriInfo), links); - return refs; - // } catch (Exception e) { - // throw new GenericRestException(Status.INTERNAL_SERVER_ERROR, - // e.getMessage()); - // } - - } - - @POST - @Consumes(MediaType.APPLICATION_XML) - @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML}) - public Response createServiceInstance(@Context final UriInfo uriInfo, final String xml) { - - this.log.debug("Create a instance of CSAR = \"{}\" Service Template = \"{}\"", this.csarId, - this.serviceTemplateID); - - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - try { - - final ServiceInstance createdServiceInstance = - service.createServiceInstance(this.csarId, this.serviceTemplateID); - - // create xlink with the link to the newly created serviceInstance, - // the link text is the internal serviceInstanceID - - final String corr = xml.substring(xml.indexOf(">") + 1, xml.indexOf(" sti = repo.find(Long.valueOf(serviceTemplateInstanceId)); - if (!sti.isPresent()) { - throw new BadRequestException("Service Template Instance could not be found"); - } - pi.setServiceTemplateInstance(sti.get()); - repository.update(pi); - } else { - this.log.error("Could not find plan instance with correlation id {}", corr); - } - - // final String redirectUrl = uriInfo.getAbsolutePath().toString(); - final SimpleXLink response = new SimpleXLink( - Utilities.encode(uriInfo.getAbsolutePathBuilder().path(String.valueOf(serviceTemplateInstanceId)) - .build()), - "simple"); - this.log.debug("Returning following link: " + response.getHref()); - return Response.ok(response).build(); - } - catch (final Exception e) { - e.printStackTrace(); - throw new GenericRestException(Status.INTERNAL_SERVER_ERROR, e.getMessage()); - } - - } - - @Path("{" + Constants.ServiceInstanceListResource_getServiceInstance_PARAM + "}") - public Object getServiceInstance(@PathParam(Constants.ServiceInstanceListResource_getServiceInstance_PARAM) final int id) { - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - ExistenceChecker.checkServiceInstanceWithException(id, service); - return new ServiceTemplateInstanceResource(this.csarId, this.serviceTemplateID, id); - } - - /** - * POST for BUILD plans which have no CSAR-Instance-ID yet. - * - * @param planElement the BUILD PublicPlan - * @return Response - * @throws URISyntaxException - * @throws UnsupportedEncodingException - */ - @POST - @Consumes(ResourceConstants.TEXT_PLAIN) - @Produces(ResourceConstants.APPLICATION_JSON) - public Response postBUILDJSONReturnJSON(@Context final UriInfo uriInfo, - final String json) throws URISyntaxException, UnsupportedEncodingException { - final String url = this.postManagementPlanJSON(uriInfo, json); - final JsonObject ret = new JsonObject(); - ret.addProperty("PlanURL", url); - return Response.created(new URI(url)).entity(ret.toString()).build(); - } - - /** - * POST for BUILD plans which have no CSAR-Instance-ID yet. - * - * @param planElement the BUILD PublicPlan - * @return Response - * @throws URISyntaxException - * @throws UnsupportedEncodingException - */ - @POST - @Consumes(ResourceConstants.TEXT_PLAIN) - @Produces(ResourceConstants.TOSCA_XML) - public Response postBUILDJSONReturnXML(@Context final UriInfo uriInfo, - final String json) throws URISyntaxException, UnsupportedEncodingException { - - final String url = this.postManagementPlanJSON(uriInfo, json); - // return Response.ok(postManagementPlanJSON(uriInfo, json)).build(); - return Response.created(new URI(url)).build(); - } - - /** - * POST for BUILD plans which have no CSAR-Instance-ID yet. - * - * @param planElement the BUILD PublicPlan - * @return Response - * @throws UnsupportedEncodingException - */ - private String postManagementPlanJSON(final UriInfo uriInfo, - final String json) throws UnsupportedEncodingException { - - this.log.debug("Received a build plan for CSAR " + this.csarId + "\npassed entity:\n " + json); - - final JsonParser parser = new JsonParser(); - final JsonObject object = parser.parse(json).getAsJsonObject(); - - this.log.debug(object.toString()); - - this.log.trace(JSONUtils.withoutQuotationMarks(object.get("ID").toString())); - - final TPlanDTO plan = new TPlanDTO(); - - plan.setId(new QName(JSONUtils.withoutQuotationMarks(object.get("ID").toString()))); - plan.setName(JSONUtils.withoutQuotationMarks(object.get("Name").toString())); - plan.setPlanType(JSONUtils.withoutQuotationMarks(object.get("PlanType").toString())); - plan.setPlanLanguage(JSONUtils.withoutQuotationMarks(object.get("PlanLanguage").toString())); - - JsonArray array = object.get("InputParameters").getAsJsonArray(); - Iterator iterator = array.iterator(); - while (iterator.hasNext()) { - final TParameterDTO para = new TParameterDTO(); - final JsonObject tmp = iterator.next().getAsJsonObject(); - para.setName(JSONUtils.withoutQuotationMarks(tmp.get("InputParameter").getAsJsonObject().get("Name") - .toString())); - para.setRequired(TBoolean.fromValue(JSONUtils.withoutQuotationMarks(tmp.get("InputParameter") - .getAsJsonObject().get("Required") - .toString()))); - para.setType(JSONUtils.withoutQuotationMarks(tmp.get("InputParameter").getAsJsonObject().get("Type") - .toString())); - // if a parameter value is not set, just add "" as value - if (null != tmp.get("InputParameter").getAsJsonObject().get("Value")) { - para.setValue(JSONUtils.withoutQuotationMarks(tmp.get("InputParameter").getAsJsonObject().get("Value") - .toString())); - } else { - para.setValue(""); - } - plan.getInputParameters().getInputParameter().add(para); - } - array = object.get("OutputParameters").getAsJsonArray(); - iterator = array.iterator(); - while (iterator.hasNext()) { - final TParameterDTO para = new TParameterDTO(); - final JsonObject tmp = iterator.next().getAsJsonObject(); - para.setName(JSONUtils.withoutQuotationMarks(tmp.get("OutputParameter").getAsJsonObject().get("Name") - .toString())); - para.setRequired(TBoolean.fromValue(JSONUtils.withoutQuotationMarks(tmp.get("OutputParameter") - .getAsJsonObject().get("Required") - .toString()))); - para.setType(JSONUtils.withoutQuotationMarks(tmp.get("OutputParameter").getAsJsonObject().get("Type") - .toString())); - plan.getOutputParameters().getOutputParameter().add(para); - } - - final String namespace = ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper() - .getNamespaceOfPlan(this.csarId, plan.getId().getLocalPart()); - plan.setId(new QName(namespace, plan.getId().getLocalPart())); - - this.log.debug("Post of the Plan " + plan.getId()); - - final String correlationID = - IOpenToscaControlServiceHandler.getOpenToscaControlService() - .invokePlanInvocation(this.csarId, this.serviceTemplateID, -1, plan); - - this.log.debug("Return correlation ID of running plan: " + correlationID); - - final URI url = - uriInfo.getBaseUriBuilder().path("/CSARs/").path(this.csarId.getFileName()).path("/ServiceTemplates/") - .path(Utilities.UrlDoubleEncode(this.serviceTemplateID.toString())).path("/Instances") - .queryParam("BuildPlanCorrelationId", correlationID).build(); - - this.log.debug("Callback URL is {}", url); - - return url.toString(); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/InstancePlanHistoryResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/InstancePlanHistoryResource.java deleted file mode 100644 index 840dc2aba..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/InstancePlanHistoryResource.java +++ /dev/null @@ -1,179 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.plans; - -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.Response; -import javax.ws.rs.core.UriInfo; - -import org.opentosca.container.api.legacy.osgi.servicegetter.CSARInstanceManagementHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.service.ICSARInstanceManagementService; -import org.opentosca.container.core.tosca.extension.PlanInvocationEvent; -import org.opentosca.container.core.tosca.extension.TParameterDTO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; - -/** - * - * - * Copyright 2013 Christian Endres - * - * @author endrescn@fachschaft.informatik.uni-stuttgart.de - * - */ -public class InstancePlanHistoryResource { - - private static final Logger LOG = LoggerFactory.getLogger(InstancePlanHistoryResource.class); - - private final CSARID csarID; - private final int instanceID; - - UriInfo uriInfo; - - - public InstancePlanHistoryResource(final CSARID csarID, final int instanceID) { - this.csarID = csarID; - this.instanceID = instanceID; - } - - /** - * Produces the xml which lists the CorrelationIDs of the PublicPlans in History. - * - * @param uriInfo - * @return The response with the legal PublicPlanTypes. - */ - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getXMLString()).build(); - } - - /** - * Produces the JSON which lists the links to the History and the active plans. - * - * @param uriInfo - * @return The response with the legal PublicPlanTypes. - */ - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getJSONString()).build(); - } - - public References getReferences() { - - InstancePlanHistoryResource.LOG.debug("Access the plan history at " - + this.uriInfo.getAbsolutePath().toString()); - - if (this.csarID == null) { - InstancePlanHistoryResource.LOG.debug("The CSAR does not exist."); - return null; - } - - final References refs = new References(); - - final ICSARInstanceManagementService manager = CSARInstanceManagementHandler.csarInstanceManagement; - - // for (String correlation : manager.getCorrelationsOfInstance(csarID, - // new ServiceTemplateInstanceID(csarID, instanceID))) { - // refs.getReference().add(new - // Reference(Utilities.buildURI(uriInfo.getAbsolutePath().toString(), - // correlation), XLinkConstants.SIMPLE, correlation)); - // } - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return refs; - } - - /** - * Returns a PlanInvocationEvent for a CorrelationID. - * - * @param correlationID - * @return the PublicPlan for the CorrelationID - */ - @GET - @Path("{CorrelationID}") - @Produces(ResourceConstants.TOSCA_XML) - public PlanInvocationEvent getInstance(@PathParam("CorrelationID") final String correlationID) { - InstancePlanHistoryResource.LOG.debug("Return plan for correlation " + correlationID); - return CSARInstanceManagementHandler.csarInstanceManagement.getPlanFromHistory(correlationID); - } - - /** - * Returns the plan information from history. - * - * @param uriInfo - * @return Response - */ - @GET - @Path("{CorrelationID}") - @Produces(ResourceConstants.TOSCA_JSON) - public Response getPlanJSON(@PathParam("CorrelationID") final String correlationID) { - - InstancePlanHistoryResource.LOG.debug("Return plan for correlation " + correlationID); - final PlanInvocationEvent event = - CSARInstanceManagementHandler.csarInstanceManagement.getPlanFromHistory(correlationID); - - final JsonObject json = new JsonObject(); - json.addProperty("ID", event.getPlanID().toString()); - json.addProperty("Name", event.getPlanName()); - json.addProperty("PlanType", event.getPlanType()); - json.addProperty("PlanLanguage", event.getPlanLanguage()); - - final JsonArray input = new JsonArray(); - try { - for (final TParameterDTO param : event.getInputParameter()) { - final JsonObject paramObj = new JsonObject(); - final JsonObject paramDetails = new JsonObject(); - paramDetails.addProperty("Name", param.getName()); - paramDetails.addProperty("Type", param.getType()); - paramDetails.addProperty("Value", param.getValue()); - paramDetails.addProperty("Required", param.getRequired().value()); - paramObj.add("InputParameter", paramDetails); - input.add(paramObj); - } - } - catch (final NullPointerException e) { - } - json.add("InputParameters", input); - - final JsonArray output = new JsonArray(); - try { - for (final TParameterDTO param : event.getOutputParameter()) { - final JsonObject paramObj = new JsonObject(); - final JsonObject paramDetails = new JsonObject(); - paramDetails.addProperty("Name", param.getName()); - paramDetails.addProperty("Type", param.getType()); - paramDetails.addProperty("Value", param.getValue()); - paramDetails.addProperty("Required", param.getRequired().value()); - paramObj.add("OutputParameter", paramDetails); - output.add(paramObj); - } - } - catch (final NullPointerException e) { - } - json.add("OutputParameters", output); - - final JsonObject planModelReference = new JsonObject(); - // planModelReference.addProperty("Reference", - // event.getPlanModelReference().getReference()); - json.add("PlanModelReference", planModelReference); - - return Response.ok(json.toString()).build(); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstance.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstance.java deleted file mode 100644 index 12dd5bb0e..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstance.java +++ /dev/null @@ -1,120 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.plans; - -import java.net.URISyntaxException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PlanInstance { - - private static final Logger LOG = LoggerFactory.getLogger(PlanInstance.class); - - private final CSARID csarID; - private final QName serviceTemplateID; - private final int serviceTemplateInstanceId; - private final String correlationID; - private UriInfo uriInfo; - - - public PlanInstance(final CSARID csarID, final QName serviceTemplateID, final int serviceTemplateInstanceId, - final String correlationID) { - this.csarID = csarID; - this.serviceTemplateID = serviceTemplateID; - this.serviceTemplateInstanceId = serviceTemplateInstanceId; - this.correlationID = correlationID; - } - - /** - * Produces the xml which lists the CorrelationIDs of the active PublicPlans. - * - * @param uriInfo - * @return The response with the legal PublicPlanTypes. - */ - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getXMLString()).build(); - } - - /** - * Produces the JSON which lists the links to the History and the active plans. - * - * @param uriInfo - * @return The response with the legal PublicPlanTypes. - */ - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getJSONString()).build(); - } - - public References getReferences() { - - LOG.debug("return plan instance of corr {}", this.correlationID); - - final References refs = new References(); - - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo, "Logs"), XLinkConstants.SIMPLE, "Logs")); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo, "MetaData"), XLinkConstants.SIMPLE, "MetaData")); - // if ((null != - // CSARInstanceManagementHandler.csarInstanceManagement.getFinishedCorrelations(this.csarID)) && - // CSARInstanceManagementHandler.csarInstanceManagement.getFinishedCorrelations(this.csarID).contains(this.correlationID)) - // { - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo, "Output"), XLinkConstants.SIMPLE, "Output")); - // } - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo, "State"), XLinkConstants.SIMPLE, "State")); - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return refs; - } - - @Path("State") - @Produces(ResourceConstants.TOSCA_JSON) - public PlanInstanceState getPlanState(@Context final UriInfo uriInfo) throws URISyntaxException { - return new PlanInstanceState(this.csarID, this.serviceTemplateID, this.serviceTemplateInstanceId, - this.correlationID); - } - - @Path("Output") - @Produces(ResourceConstants.TOSCA_JSON) - public PlanInstanceOutput getPlanOutput(@Context final UriInfo uriInfo) throws URISyntaxException { - return new PlanInstanceOutput(this.csarID, this.serviceTemplateID, this.serviceTemplateInstanceId, - this.correlationID); - } - - @Path("Logs") - @Produces(ResourceConstants.TOSCA_JSON) - public PlanInstanceLogs getPlanLogs(@Context final UriInfo uriInfo) throws URISyntaxException { - return new PlanInstanceLogs(this.csarID, this.serviceTemplateID, this.serviceTemplateInstanceId, - this.correlationID); - } - - @Path("MetaData") - @Produces(ResourceConstants.TOSCA_JSON) - public PlanInstanceMetaData getPlanMetaData(@Context final UriInfo uriInfo) throws URISyntaxException { - return new PlanInstanceMetaData(this.csarID, this.serviceTemplateID, this.serviceTemplateInstanceId, - this.correlationID); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstanceLogs.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstanceLogs.java deleted file mode 100644 index aeaedf9d5..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstanceLogs.java +++ /dev/null @@ -1,144 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.plans; - -import java.io.UnsupportedEncodingException; -import java.net.URISyntaxException; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.PlanInvocationEngineHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.next.model.PlanInstance; -import org.opentosca.container.core.next.model.PlanInstanceEvent; -import org.opentosca.container.core.next.repository.PlanInstanceRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.databind.ObjectMapper; - -/** - * - * TODO implement - * - * Copyright 2016 IAAS University of Stuttgart
- *
- * - * @author christian.endres@iaas.uni-stuttgart.de - * - */ -public class PlanInstanceLogs { - - private static final Logger LOG = LoggerFactory.getLogger(PlanInstanceLogs.class); - - private final CSARID csarID; - private final QName serviceTemplateID; - private final int serviceTemplateInstanceId; - private final String correlationID; - - private UriInfo uriInfo; - - - public PlanInstanceLogs(final CSARID csarID, final QName serviceTemplateID, final int serviceTemplateInstanceId, - final String correlationID) { - this.csarID = csarID; - this.serviceTemplateID = serviceTemplateID; - this.serviceTemplateInstanceId = serviceTemplateInstanceId; - this.correlationID = correlationID; - } - - /** - * Produces the xml which lists the CorrelationIDs of the active PublicPlans. - * - * @param uriInfo - * @return The response with the legal PublicPlanTypes. - */ - // @GET - // @Produces(ResourceConstants.LINKED_XML) - // public Response getReferencesXML(@Context final UriInfo uriInfo) { - // final StringBuilder builder = new StringBuilder(); - // builder.append(""); - // - // final Map msgs = PlanInvocationEngineHandler.planInvocationEngine - // .getPlanLogHandler().getLogsOfPlanInstance(this.correlationID); - // for (final String millis : msgs.keySet()) { - // builder.append(""); - // builder.append(""); - // builder.append(millis); - // builder.append(""); - // builder.append(""); - // builder.append(msgs.get(millis)); - // builder.append(""); - // builder.append(""); - // } - // - // builder.append(""); - // return Response.ok(builder.toString()).build(); - // } - - /** - * Produces the JSON which lists the links to the History and the active plans. - * - * @param uriInfo - * @return The response with the legal PublicPlanTypes. - */ - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) throws Exception { - this.uriInfo = uriInfo; - - final ObjectMapper mapper = new ObjectMapper(); - final PlanInstanceRepository repository = new PlanInstanceRepository(); - final PlanInstance pi = repository.findByCorrelationId(this.correlationID); - if (pi != null) { - return Response.ok(mapper.writeValueAsString(pi.getEvents())).build(); - } else { - LOG.error("Plan instance for correlation id '{}' not found", this.correlationID); - } - return Response.serverError().build(); - - // final JsonObject json = new JsonObject(); - // final JsonArray logs = new JsonArray(); - // - // final Map msgs = PlanInvocationEngineHandler.planInvocationEngine - // .getPlanLogHandler().getLogsOfPlanInstance(this.correlationID); - // for (final String millis : msgs.keySet()) { - // final JsonObject entry = new JsonObject(); - // entry.addProperty("Millisecods", millis); - // entry.addProperty("Entry", msgs.get(millis)); - // logs.add(entry); - // } - // - // json.add("PlanLogs", logs); - // return Response.ok(json.toString()).build(); - } - - @POST - @Consumes(ResourceConstants.TOSCA_XML) - @Produces(ResourceConstants.TOSCA_XML) - public Response postLogEntry(@Context final UriInfo uriInfo, final String xml) throws URISyntaxException, - UnsupportedEncodingException { - - final String logEntry = xml.substring(5, xml.length() - 6); - - PlanInvocationEngineHandler.planInvocationEngine.getPlanLogHandler().log(this.correlationID, logEntry); - - final PlanInstanceRepository repository = new PlanInstanceRepository(); - final org.opentosca.container.core.next.model.PlanInstance pi = - repository.findByCorrelationId(this.correlationID); - if (pi != null) { - pi.addEvent(new PlanInstanceEvent("INFO", "PLAN_LOG", logEntry)); - repository.update(pi); - } else { - LOG.error("Plan instance for correlation id '{}' not found", this.correlationID); - } - - return Response.ok().build(); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstanceMetaData.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstanceMetaData.java deleted file mode 100644 index 836cc5f3b..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstanceMetaData.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.plans; - -import javax.ws.rs.GET; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PlanInstanceMetaData { - - private static final Logger LOG = LoggerFactory.getLogger(PlanInstanceMetaData.class); - - private final CSARID csarID; - private final QName serviceTemplateID; - private final int serviceTemplateInstanceId; - private final String correlationID; - - private UriInfo uriInfo; - - - public PlanInstanceMetaData(final CSARID csarID, final QName serviceTemplateID, final int serviceTemplateInstanceId, - final String correlationID) { - this.csarID = csarID; - this.serviceTemplateID = serviceTemplateID; - this.serviceTemplateInstanceId = serviceTemplateInstanceId; - this.correlationID = correlationID; - } - - /** - * Produces the xml which lists the CorrelationIDs of the active PublicPlans. - * - * @param uriInfo - * @return The response with the legal PublicPlanTypes. - */ - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getXMLString()).build(); - } - - /** - * Produces the JSON which lists the links to the History and the active plans. - * - * @param uriInfo - * @return The response with the legal PublicPlanTypes. - */ - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getJSONString()).build(); - } - - public References getReferences() { - - final References refs = new References(); - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return refs; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstanceOutput.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstanceOutput.java deleted file mode 100644 index b61bd8488..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstanceOutput.java +++ /dev/null @@ -1,133 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.plans; - -import java.util.HashMap; -import java.util.Map; - -import javax.ws.rs.GET; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Response; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.next.model.PlanInstance; -import org.opentosca.container.core.next.repository.PlanInstanceRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.databind.ObjectMapper; - -public class PlanInstanceOutput { - - private static final Logger LOG = LoggerFactory.getLogger(PlanInstanceOutput.class); - - private final CSARID csarId; - private final QName serviceTemplateId; - private final int serviceTemplateInstanceId; - private final String correlationId; - - - public PlanInstanceOutput(final CSARID csarID, final QName serviceTemplateID, final int serviceTemplateInstanceId, - final String correlationID) { - this.csarId = csarID; - this.serviceTemplateId = serviceTemplateID; - this.serviceTemplateInstanceId = serviceTemplateInstanceId; - this.correlationId = correlationID; - } - - // /** - // * Returns a PlanInvocationEvent for a CorrelationID. - // * - // * @param correlationID - // * @return the PublicPlan for the CorrelationID - // */ - // @GET - // @Produces(ResourceConstants.TOSCA_XML) - // public Response getInstance() { - // LOG.debug("Return plan for correlation " + this.correlationId); - // - // PlanInstanceRepository repository = new PlanInstanceRepository(); - // PlanInstance pi = repository.findByCorrelationId(this.correlationId); - // if (pi != null) { - // return Response.ok(pi.getOutputs()).build(); - // } else { - // LOG.error("Plan instance for correlation id '{}' not found", this.correlationId); - // } - // return Response.serverError().build(); - // // return - // // CSARInstanceManagementHandler.csarInstanceManagement.getPlanFromHistory(this.correlationId); - // } - - /** - * Returns the plan information from history. - * - * @param uriInfo - * @return Response - */ - @GET - @Produces(ResourceConstants.TOSCA_JSON) - public Response getPlanJSON() throws Exception { - LOG.debug("Return plan for correlation " + this.correlationId); - final ObjectMapper mapper = new ObjectMapper(); - final Map response = new HashMap<>(); - final PlanInstanceRepository repository = new PlanInstanceRepository(); - final PlanInstance pi = repository.findByCorrelationId(this.correlationId); - if (pi != null) { - response.put("inputs", pi.getInputs()); - response.put("outputs", pi.getOutputs()); - return Response.ok(mapper.writeValueAsString(response)).build(); - } else { - LOG.error("Plan instance for correlation id '{}' not found", this.correlationId); - } - return Response.serverError().build(); - - // final PlanInvocationEvent event = - // CSARInstanceManagementHandler.csarInstanceManagement.getPlanFromHistory(this.correlationId); - // - // final JsonObject json = new JsonObject(); - // json.addProperty("ID", event.getPlanID().toString()); - // json.addProperty("Name", event.getPlanName()); - // json.addProperty("PlanType", event.getPlanType()); - // json.addProperty("PlanLanguage", event.getPlanLanguage()); - // - // final JsonArray input = new JsonArray(); - // try { - // for (final TParameterDTO param : event.getInputParameter()) { - // final JsonObject paramObj = new JsonObject(); - // final JsonObject paramDetails = new JsonObject(); - // paramDetails.addProperty("Name", param.getName()); - // paramDetails.addProperty("Type", param.getType()); - // paramDetails.addProperty("Value", param.getValue()); - // paramDetails.addProperty("Required", param.getRequired().value()); - // paramObj.add("InputParameter", paramDetails); - // input.add(paramObj); - // } - // } catch (final NullPointerException e) { - // } - // json.add("InputParameters", input); - // - // final JsonArray output = new JsonArray(); - // try { - // for (final TParameterDTO param : event.getOutputParameter()) { - // final JsonObject paramObj = new JsonObject(); - // final JsonObject paramDetails = new JsonObject(); - // paramDetails.addProperty("Name", param.getName()); - // paramDetails.addProperty("Type", param.getType()); - // paramDetails.addProperty("Value", param.getValue()); - // paramDetails.addProperty("Required", param.getRequired().value()); - // paramObj.add("OutputParameter", paramDetails); - // output.add(paramObj); - // } - // } catch (final NullPointerException e) { - // } - // json.add("OutputParameters", output); - // - // final JsonObject planModelReference = new JsonObject(); - // // planModelReference.addProperty("Reference", - // // event.getPlanModelReference().getReference()); - // json.add("PlanModelReference", planModelReference); - // - // return Response.ok(json.toString()).build(); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstanceState.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstanceState.java deleted file mode 100644 index 4a4c6f780..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstanceState.java +++ /dev/null @@ -1,130 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.plans; - -import javax.ws.rs.GET; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.CSARInstanceManagementHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.next.repository.PlanInstanceRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.JsonObject; - -public class PlanInstanceState { - - private static final Logger LOG = LoggerFactory.getLogger(PlanInstanceState.class); - - private final CSARID csarID; - private final QName serviceTemplateID; - private final int serviceTemplateInstanceId; - private final String correlationID; - private UriInfo uriInfo; - - PlanInstanceRepository repository = new PlanInstanceRepository(); - - - public PlanInstanceState(final CSARID csarID, final QName serviceTemplateID, final int serviceTemplateInstanceId, - final String correlationID) { - this.csarID = csarID; - this.serviceTemplateID = serviceTemplateID; - this.serviceTemplateInstanceId = serviceTemplateInstanceId; - this.correlationID = correlationID; - } - - /** - * Produces the xml which lists the CorrelationIDs of the active PublicPlans. - * - * @param uriInfo - * @return The response with the legal PublicPlanTypes. - */ - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - - final org.opentosca.container.core.next.model.PlanInstance pi = - this.repository.findByCorrelationId(this.correlationID); - - final StringBuilder builder = new StringBuilder(); - - // final PlanInvocationEvent event = CSARInstanceManagementHandler.csarInstanceManagement - // .getPlanForCorrelationId(this.correlationID); - // - // final Boolean finished = this.hasFinished(); - // - // if (null == finished) { - // return Response.serverError().build(); - // } - - builder.append(""); - builder.append(pi.getState().toString().toLowerCase()); - builder.append(""); - return Response.ok(builder.toString()).build(); - } - - /** - * Produces the JSON which lists the links to the History and the active plans. - * - * @param uriInfo - * @return The response with the legal PublicPlanTypes. - */ - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - - final org.opentosca.container.core.next.model.PlanInstance pi = - this.repository.findByCorrelationId(this.correlationID); - - - final JsonObject json = new JsonObject(); - - // final PlanInvocationEvent event = CSARInstanceManagementHandler.csarInstanceManagement - // .getPlanForCorrelationId(this.correlationID); - // - // final Boolean finished = this.hasFinished(); - // - // if (null == finished) { - // return Response.serverError().build(); - // } - - final JsonObject instance = new JsonObject(); - json.add("PlanInstance", instance); - - instance.addProperty("PlanName", pi.getTemplateId().toString()); - instance.addProperty("CorrelationID", this.correlationID); - instance.addProperty("State", pi.getState().toString().toLowerCase()); - - return Response.ok(json.toString()).build(); - } - - public Boolean hasFinished() { - - // finished - if (null != CSARInstanceManagementHandler.csarInstanceManagement.getFinishedCorrelations(this.csarID) - && CSARInstanceManagementHandler.csarInstanceManagement.getFinishedCorrelations(this.csarID) - .contains(this.correlationID)) { - return true; - } - - // not finished - else if (null != CSARInstanceManagementHandler.csarInstanceManagement.getActiveCorrelations(this.csarID) - && CSARInstanceManagementHandler.csarInstanceManagement.getActiveCorrelations(this.csarID) - .contains(this.correlationID)) { - return false; - } - - // ouch - else { - return null; - } - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstances.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstances.java deleted file mode 100644 index b514f907b..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/instances/plans/PlanInstances.java +++ /dev/null @@ -1,123 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.plans; - -import java.net.URISyntaxException; -import java.util.Optional; - -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.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.IOpenToscaControlServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.control.IOpenToscaControlService; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.next.model.ServiceTemplateInstance; -import org.opentosca.container.core.next.repository.ServiceTemplateInstanceRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This resource represents the active PublicPlans for a CSAR-Instance. - * - * Copyright 2013 Christian Endres - * - * @author endrescn@fachschaft.informatik.uni-stuttgart.de - * - */ -public class PlanInstances { - - private static final Logger LOG = LoggerFactory.getLogger(PlanInstances.class); - - private final CSARID csarID; - private final QName serviceTemplateID; - private final int serviceTemplateInstanceId; - - UriInfo uriInfo; - - - public PlanInstances(final CSARID csarID, final QName serviceTemplateID, final int serviceTemplateInstanceId) { - this.csarID = csarID; - this.serviceTemplateID = serviceTemplateID; - this.serviceTemplateInstanceId = serviceTemplateInstanceId; - } - - /** - * Produces the xml which lists the CorrelationIDs of the active PublicPlans. - * - * @param uriInfo - * @return The response with the legal PublicPlanTypes. - */ - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getXMLString()).build(); - } - - /** - * Produces the JSON which lists the links to the History and the active plans. - * - * @param uriInfo - * @return The response with the legal PublicPlanTypes. - */ - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getReferences().getJSONString()).build(); - } - - public References getReferences() { - - PlanInstances.LOG.debug("Access plan instance list at " + this.uriInfo.getAbsolutePath().toString()); - - if (this.csarID == null) { - PlanInstances.LOG.debug("The CSAR does not exist."); - return null; - } - - final References refs = new References(); - - final IOpenToscaControlService control = IOpenToscaControlServiceHandler.getOpenToscaControlService(); - - final ServiceTemplateInstanceRepository repo = new ServiceTemplateInstanceRepository(); - - final Optional o = repo.find(Long.valueOf(this.serviceTemplateInstanceId)); - final ServiceTemplateInstance sit = o.get(); - - for (final org.opentosca.container.core.next.model.PlanInstance p : sit.getPlanInstances()) { - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo, p.getCorrelationId()), - XLinkConstants.SIMPLE, p.getCorrelationId())); - } - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return refs; - } - - /** - * Returns the plan information from history. - * - * @param uriInfo - * @return Response - * @throws URISyntaxException - */ - @Path("{CorrelationID}") - @Produces(ResourceConstants.TOSCA_JSON) - public PlanInstance getPlanJSON(@Context final UriInfo uriInfo, - @PathParam("CorrelationID") final String correlationID) throws URISyntaxException { - LOG.debug("get plan of corr {}", correlationID); - return new PlanInstance(this.csarID, this.serviceTemplateID, this.serviceTemplateInstanceId, correlationID); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/NodeTemplateResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/NodeTemplateResource.java deleted file mode 100644 index 65e9e3302..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/NodeTemplateResource.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.nodetemplate; - -import java.io.UnsupportedEncodingException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.nodetemplate.instances.NodeTemplateInstancesResource; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class NodeTemplateResource { - - private final Logger log = LoggerFactory.getLogger(NodeTemplateResource.class); - private final CSARID csarId; - private final QName serviceTemplateID; - private final int serviceTemplateInstanceId; - private final QName nodeTemplateID; - private UriInfo uriInfo; - - - public NodeTemplateResource(final CSARID csarId, final QName serviceTemplateID, final int serviceTemplateInstanceId, - final String planIdLocalPart) { - this.csarId = csarId; - this.serviceTemplateID = serviceTemplateID; - this.serviceTemplateInstanceId = serviceTemplateInstanceId; - this.nodeTemplateID = new QName(serviceTemplateID.getNamespaceURI(), planIdLocalPart); - } - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) throws UnsupportedEncodingException { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) throws UnsupportedEncodingException { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getJSONString()).build(); - } - - public References getRefs() throws UnsupportedEncodingException { - - if (this.csarId == null) { - return null; - } - - final References refs = new References(); - - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo, "Instances"), XLinkConstants.SIMPLE, "Instances")); - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return refs; - } - - @Path("Instances") - public NodeTemplateInstancesResource getNodeTemplateInstances() { - return new NodeTemplateInstancesResource(this.csarId, this.serviceTemplateID, this.serviceTemplateInstanceId, - this.nodeTemplateID); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/NodeTemplatesResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/NodeTemplatesResource.java deleted file mode 100644 index e03a54771..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/NodeTemplatesResource.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.nodetemplate; - -import java.io.UnsupportedEncodingException; -import java.net.URISyntaxException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.ToscaServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class NodeTemplatesResource { - - private final Logger log = LoggerFactory.getLogger(NodeTemplatesResource.class); - private final CSARID csarId; - private final QName serviceTemplateID; - private final int serviceTemplateInstanceId; - private UriInfo uriInfo; - - - public NodeTemplatesResource(final CSARID csarId, final QName serviceTemplateID, - final int serviceTemplateInstanceId) { - this.csarId = csarId; - this.serviceTemplateID = serviceTemplateID; - this.serviceTemplateInstanceId = serviceTemplateInstanceId; - } - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo, - @QueryParam("nodeType") final QName nodeType) throws UnsupportedEncodingException { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs(nodeType).getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) throws UnsupportedEncodingException { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs(null).getJSONString()).build(); - } - - public References getRefs(final QName nodeType) throws UnsupportedEncodingException { - - if (this.csarId == null) { - return null; - } - - final References refs = new References(); - - for (final String ntID : ToscaServiceHandler.getToscaEngineService() - .getNodeTemplatesOfServiceTemplate(this.csarId, - this.serviceTemplateID)) { - - if (nodeType != null - && ToscaServiceHandler.getToscaEngineService() - .getNodeTypeOfNodeTemplate(this.csarId, this.serviceTemplateID, ntID) - .equals(nodeType)) { - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo, ntID), XLinkConstants.SIMPLE, ntID)); - } else { - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo, ntID), XLinkConstants.SIMPLE, ntID)); - } - } - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return refs; - } - - @Path("{PlanIdLocalPart}") - @Produces(ResourceConstants.TOSCA_JSON) - public NodeTemplateResource getNodeTemplate(@Context final UriInfo uriInfo, - @PathParam("PlanIdLocalPart") final String planIdLocalPart) throws URISyntaxException { - return new NodeTemplateResource(this.csarId, this.serviceTemplateID, this.serviceTemplateInstanceId, - planIdLocalPart); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/instances/NodeTemplateInstanceListResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/instances/NodeTemplateInstanceListResource.java deleted file mode 100644 index 5791647bc..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/instances/NodeTemplateInstanceListResource.java +++ /dev/null @@ -1,169 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.nodetemplate.instances; - -import java.net.URI; -import java.util.LinkedList; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.instancedata.LinkBuilder; -import org.opentosca.container.api.legacy.instancedata.exception.GenericRestException; -import org.opentosca.container.api.legacy.instancedata.model.NodeInstanceList; -import org.opentosca.container.api.legacy.instancedata.model.SimpleXLink; -import org.opentosca.container.api.legacy.osgi.servicegetter.InstanceDataServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.core.common.ReferenceNotFoundException; -import org.opentosca.container.core.model.instance.IdConverter; -import org.opentosca.container.core.model.instance.NodeInstance; -import org.opentosca.container.core.service.IInstanceDataService; - -/** - * TODO delete this class - * - * @author Florian Haupt - * @author Marcus Eisele - * - */ -public class NodeTemplateInstanceListResource { - - @GET - @Produces(MediaType.APPLICATION_XML) - public Response doGetXML(@Context final UriInfo uriInfo, @QueryParam("nodeInstanceID") final String nodeInstanceID, - @QueryParam("nodeTemplateID") final String nodeTemplateID, - @QueryParam("serviceInstanceID") final String serviceInstanceID, - @QueryParam("nodeTemplateName") final String nodeTemplateName) { - - final NodeInstanceList idr = - this.getRefs(uriInfo, nodeInstanceID, nodeTemplateID, serviceInstanceID, nodeTemplateName); - - return Response.ok(idr).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response doGetJSON(@Context final UriInfo uriInfo, @QueryParam("nodeInstanceID") final String nodeInstanceID, - @QueryParam("nodeTemplateID") final String nodeTemplateID, - @QueryParam("serviceInstanceID") final String serviceInstanceID, - @QueryParam("nodeTemplateName") final String nodeTemplateName) { - - final NodeInstanceList idr = - this.getRefs(uriInfo, nodeInstanceID, nodeTemplateID, serviceInstanceID, nodeTemplateName); - - return Response.ok(idr.toJSON()).build(); - } - - public NodeInstanceList getRefs(final UriInfo uriInfo, final String nodeInstanceID, final String nodeTemplateID, - final String serviceInstanceID, final String nodeTemplateName) { - - // these parameters are not required and cant therefore be generally - // checked against null - - URI nodeInstanceIdURI = null; - URI serviceInstanceIdURI = null; - QName nodeTemplateIDQName = null; - try { - if (nodeInstanceID != null) { - nodeInstanceIdURI = new URI(nodeInstanceID); - if (!IdConverter.isValidNodeInstanceID(nodeInstanceIdURI)) { - throw new Exception("Error converting nodeInstanceID: invalid format!"); - } - } - - if (serviceInstanceID != null) { - serviceInstanceIdURI = new URI(serviceInstanceID); - if (!IdConverter.isValidServiceInstanceID(serviceInstanceIdURI)) { - throw new Exception("Error converting serviceInstanceID: invalid format!"); - } - } - - if (nodeTemplateID != null) { - nodeTemplateIDQName = QName.valueOf(nodeTemplateID); - } - } - catch (final Exception e1) { - throw new GenericRestException(Status.BAD_REQUEST, - "Bad Request due to bad variable content: " + e1.getMessage()); - } - - try { - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - final List result = service.getNodeInstances(nodeInstanceIdURI, nodeTemplateIDQName, - nodeTemplateName, serviceInstanceIdURI); - final List links = new LinkedList<>(); - - // add links to nodeInstances - for (final NodeInstance nodeInstance : result) { - final URI uriToNodeInstance = LinkBuilder.linkToNodeInstance(uriInfo, nodeInstance.getId()); - // build simpleXLink with the internalID as LinkText - // TODO: is the id the correct linkText? - links.add(new SimpleXLink(uriToNodeInstance, nodeInstance.getId() + "")); - } - - final NodeInstanceList nil = new NodeInstanceList(LinkBuilder.selfLink(uriInfo), links); - - return nil; - } - catch (final Exception e) { - throw new GenericRestException(Status.INTERNAL_SERVER_ERROR, "Internal Server Error: " + e.getMessage()); - } - } - - @POST - @Produces(MediaType.APPLICATION_XML) - public Response createNodeInstance(@QueryParam("nodeTemplateID") final String nodeTemplateID, - @QueryParam("serviceInstanceID") final String serviceInstanceID, - @Context final UriInfo uriInfo) { - - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - - if (Utilities.areEmpty(nodeTemplateID, serviceInstanceID)) { - throw new GenericRestException(Status.BAD_REQUEST, - "Missing one of the required parameters: nodeTemplateID, serviceInstanceID"); - } - - URI serviceInstanceIdURI = null; - QName nodeTemplateIDQName = null; - try { - serviceInstanceIdURI = new URI(serviceInstanceID); - if (!IdConverter.isValidServiceInstanceID(serviceInstanceIdURI)) { - throw new Exception("Error converting serviceInstanceID: invalid format!"); - } - nodeTemplateIDQName = QName.valueOf(nodeTemplateID); - - } - catch (final Exception e1) { - throw new GenericRestException(Status.BAD_REQUEST, "Error converting parameter: " + e1.getMessage()); - } - - try { - final NodeInstance nodeInstance = service.createNodeInstance(nodeTemplateIDQName, serviceInstanceIdURI); - final SimpleXLink response = new SimpleXLink(LinkBuilder.linkToNodeInstance(uriInfo, nodeInstance.getId()), - nodeInstance.getNodeInstanceID().toString()); - return Response.ok(response).build(); - } - catch (final ReferenceNotFoundException e) { - throw new GenericRestException(Status.NOT_FOUND, e.getMessage()); - } - } - - // @Path("/{" + Constants.NodeInstanceListResource_getNodeInstance_PARAM + - // "}") - // public Object - // getNodeInstance(@PathParam(Constants.NodeInstanceListResource_getNodeInstance_PARAM) - // int id, @Context UriInfo uriInfo) { - // IInstanceDataService service = - // InstanceDataServiceHandler.getInstanceDataService(); - // ExistenceChecker.checkNodeInstanceWithException(id, service); - // return new NodeTemplateInstanceResource(id); - // } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/instances/NodeTemplateInstancePropertiesResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/instances/NodeTemplateInstancePropertiesResource.java deleted file mode 100644 index 318bbe9ee..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/instances/NodeTemplateInstancePropertiesResource.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.nodetemplate.instances; - -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.PUT; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.instancedata.exception.GenericRestException; -import org.opentosca.container.api.legacy.instancedata.model.SimpleXLink; -import org.opentosca.container.api.legacy.osgi.servicegetter.InstanceDataServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.JSONUtils; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.core.common.ReferenceNotFoundException; -import org.opentosca.container.core.model.instance.IdConverter; -import org.opentosca.container.core.service.IInstanceDataService; -import org.w3c.dom.Document; - -/** - * Properties - * - * @author Marcus Eisele - marcus.eisele@gmail.com - * - */ -public class NodeTemplateInstancePropertiesResource { - - private final int nodeInstanceID; - - - public NodeTemplateInstancePropertiesResource(final int id) { - this.nodeInstanceID = id; - } - - @GET - @Produces(MediaType.APPLICATION_XML) - public Response doGetXML(@QueryParam("property") final List propertiesList) { - - final Document idr = this.getProperties(propertiesList); - - return Response.ok(idr).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response doGetJSON(@QueryParam("property") final List propertiesList) { - - final Document idr = this.getProperties(propertiesList); - - return Response.ok(new JSONUtils().xmlToGenericJsonObject(idr.getChildNodes()).toString()).build(); - } - - public Document getProperties(final List propertiesList) { - final List qnameList = new ArrayList<>(); - - // convert all String in propertyList to qnames - try { - if (propertiesList != null) { - for (final String stringValue : propertiesList) { - qnameList.add(QName.valueOf(stringValue)); - } - } - } - catch (final Exception e) { - throw new GenericRestException(Status.BAD_REQUEST, - "error converting one of the properties-parameters: " + e.getMessage()); - } - - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - try { - final Document properties = - service.getNodeInstanceProperties(IdConverter.nodeInstanceIDtoURI(this.nodeInstanceID), qnameList); - return properties; - } - catch (final ReferenceNotFoundException e) { - throw new GenericRestException(Status.NOT_FOUND, e.getMessage()); - } - } - - @PUT - @Produces(MediaType.APPLICATION_XML) - @Consumes(MediaType.APPLICATION_XML) - public Response setProperties(@Context final UriInfo uriInfo, final Document xml) { - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - try { - service.setNodeInstanceProperties(IdConverter.nodeInstanceIDtoURI(this.nodeInstanceID), xml); - } - catch (final ReferenceNotFoundException e) { - throw new GenericRestException(Status.NOT_FOUND, e.getMessage()); - } - final SimpleXLink xLink = new SimpleXLink(Utilities.encode(uriInfo.getAbsolutePath()), - "NodeInstance: " + this.nodeInstanceID + " Properties"); - return Response.ok(xLink).build(); - - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/instances/NodeTemplateInstanceResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/instances/NodeTemplateInstanceResource.java deleted file mode 100644 index 118752d4c..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/instances/NodeTemplateInstanceResource.java +++ /dev/null @@ -1,153 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.nodetemplate.instances; - -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -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.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.instancedata.LinkBuilder; -import org.opentosca.container.api.legacy.instancedata.model.SimpleXLink; -import org.opentosca.container.api.legacy.osgi.servicegetter.InstanceDataServiceHandler; -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.ServiceTemplateInstanceResource; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.model.instance.IdConverter; -import org.opentosca.container.core.model.instance.NodeInstance; -import org.opentosca.container.core.service.IInstanceDataService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This class manages access to a specific nodeInstance. It also checks the existance of the - * nodeInstance with the given ID (also for all children resources before passing the request along) - * - * @author Florian Haupt - * - */ -public class NodeTemplateInstanceResource { - - private final Logger log = LoggerFactory.getLogger(ServiceTemplateInstanceResource.class); - - private final CSARID csarId; - private final QName serviceTemplateID; - private final int serviceTemplateInstanceId; - private final QName nodeTemplateID; - private final int nodeTemplateInstanceId; - - - public NodeTemplateInstanceResource(final CSARID csarId, final QName serviceTemplateID, - final int serviceTemplateInstanceId, final QName nodeTemplateID, final int id) { - this.csarId = csarId; - this.serviceTemplateID = serviceTemplateID; - this.serviceTemplateInstanceId = serviceTemplateInstanceId; - this.nodeTemplateID = nodeTemplateID; - this.nodeTemplateInstanceId = id; - } - - @GET - @Produces(MediaType.APPLICATION_XML) - public Response doGetXML(@Context final UriInfo uriInfo) throws UnsupportedEncodingException { - - final References idr = this.getRefs(uriInfo); - - return Response.ok(idr.getXMLString()).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response doGetJSON(@Context final UriInfo uriInfo) throws UnsupportedEncodingException { - - final References idr = this.getRefs(uriInfo); - - return Response.ok(idr.getJSONString()).build(); - } - - public References getRefs(final UriInfo uriInfo) throws UnsupportedEncodingException { - - final References refs = new References(); - - this.log.debug("try to build node template instance resource"); - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - final List nodeInstances = - service.getNodeInstances(IdConverter.nodeInstanceIDtoURI(this.nodeTemplateInstanceId), null, null, null); - - // existence of instance is already checked before invoking this class - // and its methods - final NodeInstance nodeInstance = nodeInstances.get(0); - - final QName nodeTypeQName = nodeInstance.getNodeType(); - final List nodeType = new ArrayList<>(); - nodeType.add(nodeTypeQName.toString()); - - final List links = new LinkedList<>(); - links.add(LinkBuilder.selfLink(uriInfo)); - - final URI serviceInstanceID = nodeInstance.getServiceInstance().getServiceInstanceID(); - // URI linkToServiceInstance = - // LinkBuilder.linkToServiceInstance(uriInfo, - // IdConverter.serviceInstanceUriToID(serviceInstanceID)); - - // String nodeUrl = "/CSARs/" + csarId + "/ServiceTemplates/" + - // URLEncoder.encode(serviceTemplateID.toString(), "UTF-8") + - // "/Instances/" + serviceTemplateInstanceId; - // refs.getReference().add(new - // Reference(Utilities.buildURI(uriInfo.getBaseUri().toString(), - // nodeUrl), XLinkConstants.REFERENCE, - // "ParentServiceTemplateInstance")); - - // links.add(new SimpleXLink(linkToServiceInstance, "ServiceInstance")); - // // properties link - // URI linkToProperties = - // LinkBuilder.linkToNodeInstanceProperties(uriInfo, - // nodeTemplateInstanceId); - // links.add(new SimpleXLink(linkToProperties, "Properties")); - // // state link - // links.add(new - // SimpleXLink(LinkBuilder.linkToNodeInstanceState(uriInfo, - // nodeTemplateInstanceId), "State")); - // NodeInstanceEntry nie = new NodeInstanceEntry(nodeInstance, links); - - refs.getReference() - .add(new Reference(Utilities.buildURI(uriInfo, "Properties"), XLinkConstants.SIMPLE, "Properties")); - refs.getReference().add(new Reference(Utilities.buildURI(uriInfo, "State"), XLinkConstants.SIMPLE, "State")); - - // selflink - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return refs; - } - - @DELETE - public Response deleteNodeInstance() { - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - service.deleteNodeInstance(IdConverter.nodeInstanceIDtoURI(this.nodeTemplateInstanceId)); - return Response.noContent().build(); - - } - - @Path("/Properties") - public Object getProperties() { - return new NodeTemplateInstancePropertiesResource(this.nodeTemplateInstanceId); - } - - @Path("/State") - public Object getState() { - return new NodeTemplateInstanceStateResource(this.nodeTemplateInstanceId); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/instances/NodeTemplateInstanceStateResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/instances/NodeTemplateInstanceStateResource.java deleted file mode 100644 index cb71b4ea9..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/instances/NodeTemplateInstanceStateResource.java +++ /dev/null @@ -1,103 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.nodetemplate.instances; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.PUT; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.instancedata.exception.GenericRestException; -import org.opentosca.container.api.legacy.osgi.servicegetter.InstanceDataServiceHandler; -import org.opentosca.container.core.common.ReferenceNotFoundException; -import org.opentosca.container.core.model.instance.IdConverter; -import org.opentosca.container.core.service.IInstanceDataService; - -import com.google.gson.JsonObject; - -/** - * @author Marcus Eisele - marcus.eisele@gmail.com - * - */ -public class NodeTemplateInstanceStateResource { - - private final int nodeInstanceID; - - - public NodeTemplateInstanceStateResource(final int id) { - this.nodeInstanceID = id; - } - - @GET - @Produces(MediaType.TEXT_PLAIN) - public Response doGetXML() { - - final String idr = this.getState(); - - return Response.ok(idr).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response doGetJSON() { - - final String idr = this.getState(); - - final JsonObject json = new JsonObject(); - json.addProperty("state", idr); - - return Response.ok(json.toString()).build(); - } - - public String getState() { - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - - try { - final QName state = service.getNodeInstanceState(IdConverter.nodeInstanceIDtoURI(this.nodeInstanceID)); - if (state != null) { - return state.toString(); - } else { - return null; - } - } - catch (final ReferenceNotFoundException e) { - throw new GenericRestException(Status.NOT_FOUND, - "Specified nodeInstance with id: " + this.nodeInstanceID + " doesn't exist"); - } - } - - @PUT - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.APPLICATION_XML) - public Response setState(@Context final UriInfo uriInfo, final String state) { - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - - QName stateQName = null; - try { - stateQName = QName.valueOf(state); - - } - catch (final Exception e1) { - throw new GenericRestException(Status.BAD_REQUEST, "Error converting parameter state: " + e1.getMessage()); - } - - try { - service.setNodeInstanceState(IdConverter.nodeInstanceIDtoURI(this.nodeInstanceID), state); - - // SimpleXLink xLink = new - // SimpleXLink(LinkBuilder.linkToNodeInstanceState(uriInfo, - // nodeInstanceID), "NodeInstance: " + nodeInstanceID + " State"); - return Response.ok().build(); - } - catch (final ReferenceNotFoundException e) { - throw new GenericRestException(Status.NOT_FOUND, - "Specified nodeInstance with id: " + this.nodeInstanceID + " doesn't exist"); - } - - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/instances/NodeTemplateInstancesResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/instances/NodeTemplateInstancesResource.java deleted file mode 100644 index b8eb4bd55..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/nodetemplate/instances/NodeTemplateInstancesResource.java +++ /dev/null @@ -1,267 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.nodetemplate.instances; - -import java.net.URI; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.instancedata.ExistenceChecker; -import org.opentosca.container.api.legacy.instancedata.LinkBuilder; -import org.opentosca.container.api.legacy.instancedata.exception.GenericRestException; -import org.opentosca.container.api.legacy.instancedata.model.NodeInstanceList; -import org.opentosca.container.api.legacy.instancedata.model.ServiceInstanceEntry; -import org.opentosca.container.api.legacy.instancedata.model.SimpleXLink; -import org.opentosca.container.api.legacy.instancedata.utilities.Constants; -import org.opentosca.container.api.legacy.osgi.servicegetter.InstanceDataServiceHandler; -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.ServiceTemplateInstanceResource; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.common.ReferenceNotFoundException; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.model.instance.IdConverter; -import org.opentosca.container.core.model.instance.NodeInstance; -import org.opentosca.container.core.model.instance.ServiceInstance; -import org.opentosca.container.core.service.IInstanceDataService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * Copyright 2016 IAAS University of Stuttgart
- *
- * - * @author Florian Haupt - * @author Marcus Eisele - * @author christian.endres@iaas.uni-stuttgart.de - * - */ -public class NodeTemplateInstancesResource { - - private final Logger log = LoggerFactory.getLogger(ServiceTemplateInstanceResource.class); - - private final CSARID csarId; - private final QName serviceTemplateID; - private final int serviceTemplateInstanceId; - private final QName nodeTemplateID; - - public NodeTemplateInstancesResource(final CSARID csarId, final QName serviceTemplateID, - final int serviceTemplateInstanceId, final QName nodeTemplateID) { - this.csarId = csarId; - this.serviceTemplateID = serviceTemplateID; - this.serviceTemplateInstanceId = serviceTemplateInstanceId; - this.nodeTemplateID = nodeTemplateID; - } - - @GET - @Produces(MediaType.APPLICATION_XML) - public Response doGetXML(@Context final UriInfo uriInfo, @QueryParam("state") final String state) { - - final References idr = this.getRefs(uriInfo, state); - - if (null == idr) { - Response.status(Status.INTERNAL_SERVER_ERROR).build(); - } - - return Response.ok(idr.getXMLString()).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response doGetJSON(@Context final UriInfo uriInfo) { - - final References idr = this.getRefs(uriInfo, null); - - if (null == idr) { - Response.status(Status.INTERNAL_SERVER_ERROR).build(); - } - - return Response.ok(idr.getJSONString()).build(); - } - - public References getRefs(final UriInfo uriInfo, final String state) { - final References refs = new References(); - - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - final URI serviceInstanceIDtoURI = IdConverter.serviceInstanceIDtoURI(this.serviceTemplateInstanceId); - - final List states = new ArrayList<>(); - if (state != null && !state.isEmpty()) { - if (state.contains(",")) { - for (final String split : state.split(",")) { - if (!split.trim().isEmpty()) { - states.add(split.trim()); - } - } - } else if (!state.isEmpty()) { - states.add(state); - } - } - try { - // self link is only link at the moment in the main list - final List serviceInstanceLinks = new LinkedList<>(); - serviceInstanceLinks.add(LinkBuilder.selfLink(uriInfo)); - - // its ensured that this serviceInstance exists - final List serviceInstances = - service.getServiceInstances(serviceInstanceIDtoURI, null, null); - final ServiceInstance serviceInstance = serviceInstances.get(0); - - // extract values - - // build nodeInstanceList - final List nodeInstances = service.getNodeInstances(null, null, null, serviceInstanceIDtoURI); - final List nodeInstanceLinks = new LinkedList<>(); - - for (final NodeInstance nodeInstance : nodeInstances) { - // URI uriToNodeInstance = - // LinkBuilder.linkToNodeInstance(uriInfo, - // nodeInstance.getId()); - // // build simpleXLink with the nodeInstanceID as LinkText - // nodeInstanceLinks.add(new SimpleXLink(uriToNodeInstance, - // nodeInstance.getNodeInstanceID().toString())); - if (!states.isEmpty() && !states.contains(nodeInstance.getState().toString())) { - continue; - } - - final QName nodeId = nodeInstance.getNodeTemplateID(); - final int nodeInstanceId = nodeInstance.getId(); - // String nodeUrl = "/CSARs/" + csarId + "/ServiceTemplates/" + - // URLEncoder.encode(serviceTemplateID.toString(), "UTF-8") + - // "/Instances/" + serviceTemplateInstanceId + "/NodeTemplates/" - // + nodeInstanceId; - - if (this.nodeTemplateID.toString().equalsIgnoreCase(nodeId.toString()) - || this.nodeTemplateID.toString().equalsIgnoreCase(nodeId.getLocalPart())) { - final Reference ref = new Reference(Utilities.buildURI(uriInfo, String.valueOf(nodeInstanceId)), - XLinkConstants.SIMPLE, String.valueOf(nodeInstanceId)); - refs.getReference().add(ref); - // String nodeUrl = "/CSARs/" + csarId + - // "/ServiceTemplates/" + - // URLEncoder.encode(serviceTemplateID.toString(), "UTF-8") - // + "/Instances/" + serviceTemplateInstanceId + - // "/NodeTemplates/" + nodeTemplateID.getLocalPart() + - // "Instances" + nodeInstanceId; - // refs.getReference().add(new - // Reference(Utilities.buildURI(uriInfo.getBaseUri().toString(), - // nodeUrl), XLinkConstants.REFERENCE, - // URLEncoder.encode(nodeId.getLocalPart(), "UTF-8"))); - this.log.debug("build node reference {}", ref.getXhref()); - } else { - this.log.debug("Skipped node instance {} of node template id {}", nodeInstanceId, nodeId); - } - - // if (nodeType == null) { - // QName nodeId = nodeInstance.getNodeTemplateID(); - // int nodeInstanceId = nodeInstance.getId(); - // String nodeUrl = "/CSARs/" + csarId + "/ServiceTemplates/" + - // URLEncoder.encode(serviceTemplateID.toString(), "UTF-8") + - // "/Instances/" + serviceTemplateInstanceId + "/NodeTemplates/" - // + nodeInstanceId; - // refs.getReference().add(new - // Reference(Utilities.buildURI(uriInfo.getBaseUri().toString(), - // nodeUrl), XLinkConstants.REFERENCE, - // URLEncoder.encode(nodeId.getLocalPart(), "UTF-8"))); - // log.debug("build node reference {}", nodeUrl); - // } else { - // if (nodeInstance.getNodeType().equals(nodeType)) { - // QName nodeId = nodeInstance.getNodeTemplateID(); - // int nodeInstanceId = nodeInstance.getId(); - // String nodeUrl = "/CSARs/" + csarId + "/ServiceTemplates/" + - // URLEncoder.encode(serviceTemplateID.toString(), "UTF-8") + - // "/Instances/" + serviceTemplateInstanceId + "/NodeTemplates/" - // + nodeInstanceId; - // refs.getReference().add(new - // Reference(Utilities.buildURI(uriInfo.getBaseUri().toString(), - // nodeUrl), XLinkConstants.REFERENCE, - // URLEncoder.encode(nodeId.getLocalPart(), "UTF-8"))); - // log.debug("build node reference {}", nodeUrl); - // } - // } - } - // we dont want a self link because the InstanceList is part of - // another list already containing a self link - final NodeInstanceList nil = new NodeInstanceList(null, nodeInstanceLinks); - - final ServiceInstanceEntry sie = new ServiceInstanceEntry(serviceInstance, serviceInstanceLinks, nil); - - // selflink - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return refs; - } - catch (final Exception e) { - e.printStackTrace(); - return null; - } - } - - @POST - @Produces(MediaType.APPLICATION_XML) - public Response createNodeInstance(@Context final UriInfo uriInfo) { - - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - // ServiceInstance serviceInstanceIdURI = service.getservi - - // if (Utilities.areEmpty(nodeTemplateID, serviceTemplateInstanceId)) { - // throw new GenericRestException(Status.BAD_REQUEST, "Missing one of - // the required parameters: nodeTemplateID, serviceInstanceID"); - // } - - // URI serviceInstanceIdURI = null; - // try { - // - // serviceInstanceIdURI = new ServiceInstance(csarId, nodeTemplateID, - // nodeTemplateID.getLocalPart(), - // serviceTemplateInstanceId).getServiceInstanceID(); - // if (!IdConverter.isValidServiceInstanceID(serviceInstanceIdURI)) { - // throw new Exception("Error converting serviceInstanceID: invalid - // format!"); - // } - // - // } catch (Exception e1) { - // throw new GenericRestException(Status.BAD_REQUEST, "Error converting - // parameter: " + e1.getMessage()); - // } - - try { - final NodeInstance nodeInstance = - service.createNodeInstance(this.csarId, this.serviceTemplateID, this.serviceTemplateInstanceId, - this.nodeTemplateID); - // SimpleXLink response = new - // SimpleXLink(uriInfo.getAbsolutePath().toString() + "/" + - // serviceTemplateInstanceId, "simple"); - final URI link = uriInfo.getAbsolutePathBuilder().path(String.valueOf(nodeInstance.getId())).build(); - final SimpleXLink response = new SimpleXLink(Utilities.encode(link), "simple"); - return Response.ok(response).build(); - } - catch (final ReferenceNotFoundException e) { - throw new GenericRestException(Status.NOT_FOUND, e.getMessage()); - } - } - - @Path("/{" + Constants.NodeInstanceListResource_getNodeInstance_PARAM + "}") - public Object getNodeInstance(@PathParam(Constants.NodeInstanceListResource_getNodeInstance_PARAM) final int nodeTemplateInstanceId, - @Context final UriInfo uriInfo) { - - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - ExistenceChecker.checkNodeInstanceWithException(nodeTemplateInstanceId, service); - return new NodeTemplateInstanceResource(this.csarId, this.serviceTemplateID, this.serviceTemplateInstanceId, - this.nodeTemplateID, nodeTemplateInstanceId); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/package-info.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/package-info.java deleted file mode 100644 index e01691b3b..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/package-info.java +++ /dev/null @@ -1,11 +0,0 @@ -/** - * - */ -/** - * Copyright 2016 IAAS University of Stuttgart
- *
- * - * @author christian.endres@iaas.uni-stuttgart.de - * - */ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate; diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/RelationshipTemplateResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/RelationshipTemplateResource.java deleted file mode 100644 index d1cd988b6..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/RelationshipTemplateResource.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.relationshiptemplate; - -import java.io.UnsupportedEncodingException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.relationshiptemplate.instances.RelationshipTemplateInstancesResource; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class RelationshipTemplateResource { - - private final Logger log = LoggerFactory.getLogger(RelationshipTemplateResource.class); - private final CSARID csarId; - private final QName serviceTemplateID; - private final int serviceTemplateInstanceId; - private final QName relationshipTemplateID; - private UriInfo uriInfo; - - - public RelationshipTemplateResource(final CSARID csarId, final QName serviceTemplateID, - final int serviceTemplateInstanceId, final String planIdLocalPart) { - this.csarId = csarId; - this.serviceTemplateID = serviceTemplateID; - this.serviceTemplateInstanceId = serviceTemplateInstanceId; - this.relationshipTemplateID = new QName(serviceTemplateID.getNamespaceURI(), planIdLocalPart); - } - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) throws UnsupportedEncodingException { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) throws UnsupportedEncodingException { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getJSONString()).build(); - } - - public References getRefs() throws UnsupportedEncodingException { - - if (this.csarId == null) { - return null; - } - - final References refs = new References(); - - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo, "Instances"), XLinkConstants.SIMPLE, "Instances")); - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return refs; - } - - @Path("Instances") - public RelationshipTemplateInstancesResource getNodeTemplateInstances() { - return new RelationshipTemplateInstancesResource(this.csarId, this.serviceTemplateID, - this.serviceTemplateInstanceId, this.relationshipTemplateID); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/RelationshipTemplatesResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/RelationshipTemplatesResource.java deleted file mode 100644 index 837077940..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/RelationshipTemplatesResource.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.relationshiptemplate; - -import java.io.UnsupportedEncodingException; -import java.net.URISyntaxException; - -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.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.ToscaServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class RelationshipTemplatesResource { - - private final Logger log = LoggerFactory.getLogger(RelationshipTemplatesResource.class); - private final CSARID csarId; - private final QName serviceTemplateID; - private final int serviceTemplateInstanceId; - private UriInfo uriInfo; - - - public RelationshipTemplatesResource(final CSARID csarId, final QName serviceTemplateID, - final int serviceTemplateInstanceId) { - this.csarId = csarId; - this.serviceTemplateID = serviceTemplateID; - this.serviceTemplateInstanceId = serviceTemplateInstanceId; - } - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) throws UnsupportedEncodingException { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) throws UnsupportedEncodingException { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getJSONString()).build(); - } - - public References getRefs() throws UnsupportedEncodingException { - - if (this.csarId == null) { - return null; - } - - final References refs = new References(); - - for (final String rtID : ToscaServiceHandler.getToscaEngineService() - .getRelationshipTemplatesOfServiceTemplate(this.csarId, - this.serviceTemplateID)) { - refs.getReference().add(new Reference(Utilities.buildURI(this.uriInfo, rtID), XLinkConstants.SIMPLE, rtID)); - } - - // selflink - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return refs; - } - - @Path("{PlanIdLocalPart}") - @Produces(ResourceConstants.TOSCA_JSON) - public RelationshipTemplateResource getRelationshipTemplate(@Context final UriInfo uriInfo, - @PathParam("PlanIdLocalPart") final String planIdLocalPart) throws URISyntaxException { - return new RelationshipTemplateResource(this.csarId, this.serviceTemplateID, this.serviceTemplateInstanceId, - planIdLocalPart); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/instances/RelationshipTemplateInstanceListResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/instances/RelationshipTemplateInstanceListResource.java deleted file mode 100644 index 80dd6e29d..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/instances/RelationshipTemplateInstanceListResource.java +++ /dev/null @@ -1,182 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.relationshiptemplate.instances; - -import java.net.URI; -import java.util.LinkedList; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.instancedata.LinkBuilder; -import org.opentosca.container.api.legacy.instancedata.exception.GenericRestException; -import org.opentosca.container.api.legacy.instancedata.model.RelationInstanceList; -import org.opentosca.container.api.legacy.instancedata.model.SimpleXLink; -import org.opentosca.container.api.legacy.osgi.servicegetter.InstanceDataServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.core.common.ReferenceNotFoundException; -import org.opentosca.container.core.model.instance.IdConverter; -import org.opentosca.container.core.model.instance.NodeInstance; -import org.opentosca.container.core.model.instance.RelationInstance; -import org.opentosca.container.core.service.IInstanceDataService; - -/** - * TODO delete this class - * - * @author Florian Haupt - * @author Marcus Eisele - * - */ -public class RelationshipTemplateInstanceListResource { - - @GET - @Produces(MediaType.APPLICATION_XML) - public Response doGetXML(@Context final UriInfo uriInfo, - @QueryParam("relationInstanceID") final String relationInstanceID, - @QueryParam("relationshipTemplateID") final String relationshipTemplateID, - @QueryParam("serviceInstanceID") final String serviceInstanceID, - @QueryParam("relationshipTemplateName") final String relationshipTemplateName) { - - final RelationInstanceList idr = this.getRefs(uriInfo, relationInstanceID, relationshipTemplateID, - serviceInstanceID, relationshipTemplateName); - - return Response.ok(idr).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response doGetJSON(@Context final UriInfo uriInfo, - @QueryParam("relationInstanceID") final String relationInstanceID, - @QueryParam("relationshipTemplateID") final String relationshipTemplateID, - @QueryParam("serviceInstanceID") final String serviceInstanceID, - @QueryParam("relationshipTemplateName") final String relationshipTemplateName) { - - final RelationInstanceList idr = this.getRefs(uriInfo, relationInstanceID, relationshipTemplateID, - serviceInstanceID, relationshipTemplateName); - - return Response.ok(idr.toJSON()).build(); - } - - public RelationInstanceList getRefs(final UriInfo uriInfo, final String relationInstanceID, - final String relationshipTemplateID, final String serviceInstanceID, - final String relationshipTemplateName) { - - // these parameters are not required and cant therefore be generally - // checked against null - - URI relationInstanceIdURI = null; - URI serviceInstanceIdURI = null; - QName relationshipTemplateIDQName = null; - try { - if (relationInstanceID != null) { - relationInstanceIdURI = new URI(relationInstanceID); - if (!IdConverter.isValidRelationInstanceID(relationInstanceIdURI)) { - throw new Exception("Error converting relationInstanceID: invalid format!"); - } - } - - if (serviceInstanceID != null) { - serviceInstanceIdURI = new URI(serviceInstanceID); - if (!IdConverter.isValidServiceInstanceID(serviceInstanceIdURI)) { - throw new Exception("Error converting serviceInstanceID: invalid format!"); - } - } - - if (relationshipTemplateID != null) { - relationshipTemplateIDQName = QName.valueOf(relationshipTemplateID); - } - } - catch (final Exception e1) { - throw new GenericRestException(Status.BAD_REQUEST, - "Bad Request due to bad variable content: " + e1.getMessage()); - } - - try { - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - final List result = - service.getRelationInstances(relationInstanceIdURI, relationshipTemplateIDQName, - relationshipTemplateName, serviceInstanceIdURI); - final List links = new LinkedList<>(); - - // add links to nodeInstances - for (final RelationInstance relationInstance : result) { - final URI uriToRelationInstance = LinkBuilder.linkToRelationInstance(uriInfo, relationInstance.getId()); - // build simpleXLink with the internalID as LinkText - // TODO: is the id the correct linkText? - links.add(new SimpleXLink(uriToRelationInstance, relationInstance.getId() + "")); - } - - final RelationInstanceList ril = new RelationInstanceList(LinkBuilder.selfLink(uriInfo), links); - - return ril; - } - catch (final Exception e) { - throw new GenericRestException(Status.INTERNAL_SERVER_ERROR, "Internal Server Error: " + e.getMessage()); - } - } - - @POST - @Produces(MediaType.APPLICATION_XML) - public Response createRelationInstance(@QueryParam("relationshipTemplateID") final String relationshipTemplateID, - @QueryParam("serviceInstanceID") final String serviceInstanceID, - @Context final UriInfo uriInfo) { - - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - - if (Utilities.areEmpty(relationshipTemplateID, serviceInstanceID)) { - throw new GenericRestException(Status.BAD_REQUEST, - "Missing one of the required parameters: relationshipTemplateID, serviceInstanceID"); - } - - URI serviceInstanceIdURI = null; - QName relationshipTemplateIDQName = null; - try { - serviceInstanceIdURI = new URI(serviceInstanceID); - if (!IdConverter.isValidServiceInstanceID(serviceInstanceIdURI)) { - throw new Exception("Error converting serviceInstanceID: invalid format!"); - } - relationshipTemplateIDQName = QName.valueOf(relationshipTemplateID); - - } - catch (final Exception e1) { - throw new GenericRestException(Status.BAD_REQUEST, "Error converting parameter: " + e1.getMessage()); - } - - try { - // FIXME at this point a brutal amount of confusion is rising up, - // while - // implementing I noticed that this method - // createNodeInstance(para,para) is deprecated and doesn't work. So - // it seems this whole class is useless? Because I tried to - // implement relation in the style of the nodeInstances but this - // method makes literally no sense - final NodeInstance nodeInstance = - service.createNodeInstance(relationshipTemplateIDQName, serviceInstanceIdURI); - final SimpleXLink response = new SimpleXLink(LinkBuilder.linkToNodeInstance(uriInfo, nodeInstance.getId()), - nodeInstance.getNodeInstanceID().toString()); - return Response.ok(response).build(); - } - catch (final ReferenceNotFoundException e) { - throw new GenericRestException(Status.NOT_FOUND, e.getMessage()); - } - } - - // @Path("/{" + Constants.NodeInstanceListResource_getNodeInstance_PARAM + - // "}") - // public Object - // getNodeInstance(@PathParam(Constants.NodeInstanceListResource_getNodeInstance_PARAM) - // int id, @Context UriInfo uriInfo) { - // IInstanceDataService service = - // InstanceDataServiceHandler.getInstanceDataService(); - // ExistenceChecker.checkNodeInstanceWithException(id, service); - // return new NodeTemplateInstanceResource(id); - // } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/instances/RelationshipTemplateInstancePropertiesResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/instances/RelationshipTemplateInstancePropertiesResource.java deleted file mode 100644 index 0a3fe4685..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/instances/RelationshipTemplateInstancePropertiesResource.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.relationshiptemplate.instances; - -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.PUT; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.instancedata.exception.GenericRestException; -import org.opentosca.container.api.legacy.instancedata.model.SimpleXLink; -import org.opentosca.container.api.legacy.osgi.servicegetter.InstanceDataServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.JSONUtils; -import org.opentosca.container.core.common.ReferenceNotFoundException; -import org.opentosca.container.core.model.instance.IdConverter; -import org.opentosca.container.core.service.IInstanceDataService; -import org.w3c.dom.Document; - -/** - * Properties - * - * @author Marcus Eisele - marcus.eisele@gmail.com - * - */ -public class RelationshipTemplateInstancePropertiesResource { - - private final int relationInstanceID; - - - public RelationshipTemplateInstancePropertiesResource(final int id) { - this.relationInstanceID = id; - } - - @GET - @Produces(MediaType.APPLICATION_XML) - public Response doGetXML(@QueryParam("property") final List propertiesList) { - - final Document idr = this.getProperties(propertiesList); - - if (idr == null) { - return Response.noContent().build(); - } - - return Response.ok(idr).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response doGetJSON(@QueryParam("property") final List propertiesList) { - - final Document idr = this.getProperties(propertiesList); - - if (idr == null) { - return Response.noContent().build(); - } - - return Response.ok(new JSONUtils().xmlToGenericJsonObject(idr.getChildNodes()).toString()).build(); - } - - public Document getProperties(final List propertiesList) { - final List qnameList = new ArrayList<>(); - - // convert all String in propertyList to qnames - try { - if (propertiesList != null) { - for (final String stringValue : propertiesList) { - qnameList.add(QName.valueOf(stringValue)); - } - } - } - catch (final Exception e) { - throw new GenericRestException(Status.BAD_REQUEST, - "error converting one of the properties-parameters: " + e.getMessage()); - } - - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - try { - final Document properties = - service.getRelationInstanceProperties(IdConverter.relationInstanceIDtoURI(this.relationInstanceID), - qnameList); - return properties; - } - catch (final ReferenceNotFoundException e) { - throw new GenericRestException(Status.NOT_FOUND, e.getMessage()); - } - } - - @PUT - @Produces(MediaType.APPLICATION_XML) - @Consumes(MediaType.APPLICATION_XML) - public Response setProperties(@Context final UriInfo uriInfo, final Document xml) { - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - try { - service.setRelationInstanceProperties(IdConverter.relationInstanceIDtoURI(this.relationInstanceID), xml); - } - catch (final ReferenceNotFoundException e) { - throw new GenericRestException(Status.NOT_FOUND, e.getMessage()); - } - final SimpleXLink xLink = - new SimpleXLink(uriInfo.getAbsolutePath(), "RelationInstance: " + this.relationInstanceID + " Properties"); - return Response.ok(xLink).build(); - - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/instances/RelationshipTemplateInstanceResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/instances/RelationshipTemplateInstanceResource.java deleted file mode 100644 index b2f50579b..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/instances/RelationshipTemplateInstanceResource.java +++ /dev/null @@ -1,164 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.relationshiptemplate.instances; - -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -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.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.instancedata.LinkBuilder; -import org.opentosca.container.api.legacy.instancedata.model.SimpleXLink; -import org.opentosca.container.api.legacy.osgi.servicegetter.InstanceDataServiceHandler; -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.ServiceTemplateInstanceResource; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.model.instance.IdConverter; -import org.opentosca.container.core.model.instance.RelationInstance; -import org.opentosca.container.core.service.IInstanceDataService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This class manages access to a specific nodeInstance. It also checks the existance of the - * nodeInstance with the given ID (also for all children resources before passing the request along) - * - * @author Florian Haupt - * - */ -public class RelationshipTemplateInstanceResource { - - private final Logger log = LoggerFactory.getLogger(ServiceTemplateInstanceResource.class); - - private final CSARID csarId; - private final QName serviceTemplateID; - private final int serviceTemplateInstanceId; - private final QName relationshipTemplateID; - private final int relationshipTemplateInstanceId; - - - public RelationshipTemplateInstanceResource(final CSARID csarId, final QName serviceTemplateID, - final int serviceTemplateInstanceId, final QName relationshipTemplateID, - final int id) { - this.csarId = csarId; - this.serviceTemplateID = serviceTemplateID; - this.serviceTemplateInstanceId = serviceTemplateInstanceId; - this.relationshipTemplateID = relationshipTemplateID; - this.relationshipTemplateInstanceId = id; - } - - @GET - @Produces(MediaType.APPLICATION_XML) - public Response doGetXML(@Context final UriInfo uriInfo) throws UnsupportedEncodingException { - - final References idr = this.getRefs(uriInfo); - - return Response.ok(idr.getXMLString()).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response doGetJSON(@Context final UriInfo uriInfo) throws UnsupportedEncodingException { - - final References idr = this.getRefs(uriInfo); - - return Response.ok(idr.getJSONString()).build(); - } - - public References getRefs(final UriInfo uriInfo) throws UnsupportedEncodingException { - - final References refs = new References(); - - this.log.debug("try to build relation template instance resource"); - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - final List relationInstances = - service.getRelationInstances(IdConverter.relationInstanceIDtoURI(this.relationshipTemplateInstanceId), null, - null, null); - - // existence of instance is already checked before invoking this class - // and its methods - final RelationInstance relationInstance = relationInstances.get(0); - - final QName relationshipTypeQName = relationInstance.getRelationshipType(); - final List relationshipType = new ArrayList<>(); - relationshipType.add(relationshipTypeQName.toString()); - - final List links = new LinkedList<>(); - links.add(LinkBuilder.selfLink(uriInfo)); - - // final URI serviceInstanceID = relationInstance.getServiceInstance().getServiceInstanceID(); - // URI linkToServiceInstance = - // LinkBuilder.linkToServiceInstance(uriInfo, - // IdConverter.serviceInstanceUriToID(serviceInstanceID)); - - // String nodeUrl = "/CSARs/" + csarId + "/ServiceTemplates/" + - // URLEncoder.encode(serviceTemplateID.toString(), "UTF-8") + - // "/Instances/" + serviceTemplateInstanceId; - // refs.getReference().add(new - // Reference(Utilities.buildURI(uriInfo.getBaseUri().toString(), - // nodeUrl), XLinkConstants.REFERENCE, - // "ParentServiceTemplateInstance")); - - // links.add(new SimpleXLink(linkToServiceInstance, "ServiceInstance")); - // // properties link - // URI linkToProperties = - // LinkBuilder.linkToNodeInstanceProperties(uriInfo, - // nodeTemplateInstanceId); - // links.add(new SimpleXLink(linkToProperties, "Properties")); - // // state link - // links.add(new - // SimpleXLink(LinkBuilder.linkToNodeInstanceState(uriInfo, - // nodeTemplateInstanceId), "State")); - // NodeInstanceEntry nie = new NodeInstanceEntry(nodeInstance, links); - - refs.getReference() - .add(new Reference(Utilities.buildURI(uriInfo, "Properties"), XLinkConstants.SIMPLE, "Properties")); - refs.getReference().add(new Reference(Utilities.buildURI(uriInfo, "State"), XLinkConstants.SIMPLE, "State")); - - if (relationInstance.getSourceInstance() != null) { - refs.getReference().add(new Reference(relationInstance.getSourceInstance().getNodeInstanceID().toString(), - XLinkConstants.SIMPLE, "SourceInstanceId")); - } - - if (relationInstance.getTargetInstance() != null) { - refs.getReference().add(new Reference(relationInstance.getTargetInstance().getNodeInstanceID().toString(), - XLinkConstants.SIMPLE, "TargetInstanceId")); - } - - // selflink - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return refs; - } - - @DELETE - public Response deleteRelationInstance() { - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - service.deleteRelationInstance(IdConverter.relationInstanceIDtoURI(this.relationshipTemplateInstanceId)); - return Response.noContent().build(); - - } - - @Path("/Properties") - public Object getProperties() { - return new RelationshipTemplateInstancePropertiesResource(this.relationshipTemplateInstanceId); - } - - @Path("/State") - public Object getState() { - return new RelationshipTemplateInstanceStateResource(this.relationshipTemplateInstanceId); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/instances/RelationshipTemplateInstanceStateResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/instances/RelationshipTemplateInstanceStateResource.java deleted file mode 100644 index 483ed5c41..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/instances/RelationshipTemplateInstanceStateResource.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.relationshiptemplate.instances; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.PUT; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.instancedata.exception.GenericRestException; -import org.opentosca.container.api.legacy.osgi.servicegetter.InstanceDataServiceHandler; -import org.opentosca.container.core.common.ReferenceNotFoundException; -import org.opentosca.container.core.model.instance.IdConverter; -import org.opentosca.container.core.service.IInstanceDataService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.JsonObject; - -/** - * @author Marcus Eisele - marcus.eisele@gmail.com - * - */ -public class RelationshipTemplateInstanceStateResource { - - private static Logger logger = LoggerFactory.getLogger(RelationshipTemplateInstanceStateResource.class); - - private final int relationInstanceID; - - - public RelationshipTemplateInstanceStateResource(final int id) { - this.relationInstanceID = id; - } - - @GET - @Produces(MediaType.TEXT_PLAIN) - public Response doGetXML() { - - final String idr = this.getState(); - - return Response.ok(idr).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response doGetJSON() { - - final String idr = this.getState(); - - final JsonObject json = new JsonObject(); - json.addProperty("state", idr); - - return Response.ok(json.toString()).build(); - } - - public String getState() { - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - - try { - final QName state = - service.getRelationInstanceState(IdConverter.relationInstanceIDtoURI(this.relationInstanceID)); - if (state != null) { - return state.toString(); - } else { - return null; - } - } - catch (final ReferenceNotFoundException e) { - logger.error("Error getting state: {}", e.getMessage(), e); - throw new GenericRestException(Status.NOT_FOUND, - "Specified relationInstance with id: " + this.relationInstanceID + " doesn't exist"); - } - } - - @PUT - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.APPLICATION_XML) - public Response setState(@Context final UriInfo uriInfo, final String state) { - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - - QName stateQName = null; - try { - stateQName = QName.valueOf(state); - - } - catch (final Exception e1) { - throw new GenericRestException(Status.BAD_REQUEST, "Error converting parameter state: " + e1.getMessage()); - } - - try { - service.setRelationInstanceState(IdConverter.relationInstanceIDtoURI(this.relationInstanceID), state); - - // SimpleXLink xLink = new - // SimpleXLink(LinkBuilder.linkToNodeInstanceState(uriInfo, - // nodeInstanceID), "NodeInstance: " + nodeInstanceID + " State"); - return Response.ok().build(); - } - catch (final ReferenceNotFoundException e) { - logger.error("Error setting state: {}", e.getMessage(), e); - throw new GenericRestException(Status.NOT_FOUND, - "Specified relationInstance with id: " + this.relationInstanceID + " doesn't exist"); - } - - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/instances/RelationshipTemplateInstancesResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/instances/RelationshipTemplateInstancesResource.java deleted file mode 100644 index 1805cf415..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/csar/servicetemplate/relationshiptemplate/instances/RelationshipTemplateInstancesResource.java +++ /dev/null @@ -1,258 +0,0 @@ -package org.opentosca.container.api.legacy.resources.csar.servicetemplate.relationshiptemplate.instances; - -import java.net.URI; -import java.util.LinkedList; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.instancedata.ExistenceChecker; -import org.opentosca.container.api.legacy.instancedata.LinkBuilder; -import org.opentosca.container.api.legacy.instancedata.exception.GenericRestException; -import org.opentosca.container.api.legacy.instancedata.model.RelationInstanceList; -import org.opentosca.container.api.legacy.instancedata.model.ServiceInstanceEntry; -import org.opentosca.container.api.legacy.instancedata.model.SimpleXLink; -import org.opentosca.container.api.legacy.instancedata.utilities.Constants; -import org.opentosca.container.api.legacy.osgi.servicegetter.InstanceDataServiceHandler; -import org.opentosca.container.api.legacy.resources.csar.servicetemplate.instances.ServiceTemplateInstanceResource; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.common.ReferenceNotFoundException; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.model.instance.IdConverter; -import org.opentosca.container.core.model.instance.RelationInstance; -import org.opentosca.container.core.model.instance.ServiceInstance; -import org.opentosca.container.core.service.IInstanceDataService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * Copyright 2016 IAAS University of Stuttgart
- *
- * - * @author Florian Haupt - * @author Marcus Eisele - * @author christian.endres@iaas.uni-stuttgart.de - * - */ -public class RelationshipTemplateInstancesResource { - - private final Logger log = LoggerFactory.getLogger(ServiceTemplateInstanceResource.class); - - private final CSARID csarId; - private final QName serviceTemplateID; - private final int serviceTemplateInstanceId; - private final QName relatioshipTemplateID; - - - public RelationshipTemplateInstancesResource(final CSARID csarId, final QName serviceTemplateID, - final int serviceTemplateInstanceId, - final QName relationshipTemplateID) { - this.csarId = csarId; - this.serviceTemplateID = serviceTemplateID; - this.serviceTemplateInstanceId = serviceTemplateInstanceId; - this.relatioshipTemplateID = relationshipTemplateID; - } - - @GET - @Produces(MediaType.APPLICATION_XML) - public Response doGetXML(@Context final UriInfo uriInfo) { - - final References idr = this.getRefs(uriInfo); - - if (null == idr) { - Response.status(Status.INTERNAL_SERVER_ERROR).build(); - } - - return Response.ok(idr.getXMLString()).build(); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response doGetJSON(@Context final UriInfo uriInfo) { - - final References idr = this.getRefs(uriInfo); - - if (null == idr) { - Response.status(Status.INTERNAL_SERVER_ERROR).build(); - } - - return Response.ok(idr.getJSONString()).build(); - } - - public References getRefs(final UriInfo uriInfo) { - final References refs = new References(); - - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - final URI serviceInstanceIDtoURI = IdConverter.serviceInstanceIDtoURI(this.serviceTemplateInstanceId); - - try { - // self link is only link at the moment in the main list - final List serviceInstanceLinks = new LinkedList<>(); - serviceInstanceLinks.add(LinkBuilder.selfLink(uriInfo)); - - // its ensured that this serviceInstance exists - final List serviceInstances = - service.getServiceInstances(serviceInstanceIDtoURI, null, null); - final ServiceInstance serviceInstance = serviceInstances.get(0); - - // extract values - - // build nodeInstanceList - final List relationInstances = - service.getRelationInstances(null, null, null, serviceInstanceIDtoURI); - final List relationInstanceLinks = new LinkedList<>(); - - for (final RelationInstance relationInstance : relationInstances) { - // URI uriToNodeInstance = - // LinkBuilder.linkToNodeInstance(uriInfo, - // nodeInstance.getId()); - // // build simpleXLink with the nodeInstanceID as LinkText - // nodeInstanceLinks.add(new SimpleXLink(uriToNodeInstance, - // nodeInstance.getNodeInstanceID().toString())); - - final QName relationId = relationInstance.getRelationshipTemplateID(); - final int relationInstanceId = relationInstance.getId(); - // String nodeUrl = "/CSARs/" + csarId + "/ServiceTemplates/" + - // URLEncoder.encode(serviceTemplateID.toString(), "UTF-8") + - // "/Instances/" + serviceTemplateInstanceId + "/NodeTemplates/" - // + nodeInstanceId; - - if (this.relatioshipTemplateID.toString().equalsIgnoreCase(relationId.toString()) - || this.relatioshipTemplateID.toString().equalsIgnoreCase(relationId.getLocalPart())) { - final Reference ref = new Reference(Utilities.buildURI(uriInfo, String.valueOf(relationInstanceId)), - XLinkConstants.SIMPLE, String.valueOf(relationInstanceId)); - refs.getReference().add(ref); - // String nodeUrl = "/CSARs/" + csarId + - // "/ServiceTemplates/" + - // URLEncoder.encode(serviceTemplateID.toString(), "UTF-8") - // + "/Instances/" + serviceTemplateInstanceId + - // "/NodeTemplates/" + nodeTemplateID.getLocalPart() + - // "Instances" + nodeInstanceId; - // refs.getReference().add(new - // Reference(Utilities.buildURI(uriInfo.getBaseUri().toString(), - // nodeUrl), XLinkConstants.REFERENCE, - // URLEncoder.encode(nodeId.getLocalPart(), "UTF-8"))); - this.log.debug("build relation reference {}", ref.getXhref()); - } else { - this.log.debug("Skipped node instance {} of node template id {}", relationInstanceId, relationId); - } - - // if (nodeType == null) { - // QName nodeId = nodeInstance.getNodeTemplateID(); - // int nodeInstanceId = nodeInstance.getId(); - // String nodeUrl = "/CSARs/" + csarId + "/ServiceTemplates/" + - // URLEncoder.encode(serviceTemplateID.toString(), "UTF-8") + - // "/Instances/" + serviceTemplateInstanceId + "/NodeTemplates/" - // + nodeInstanceId; - // refs.getReference().add(new - // Reference(Utilities.buildURI(uriInfo.getBaseUri().toString(), - // nodeUrl), XLinkConstants.REFERENCE, - // URLEncoder.encode(nodeId.getLocalPart(), "UTF-8"))); - // log.debug("build node reference {}", nodeUrl); - // } else { - // if (nodeInstance.getNodeType().equals(nodeType)) { - // QName nodeId = nodeInstance.getNodeTemplateID(); - // int nodeInstanceId = nodeInstance.getId(); - // String nodeUrl = "/CSARs/" + csarId + "/ServiceTemplates/" + - // URLEncoder.encode(serviceTemplateID.toString(), "UTF-8") + - // "/Instances/" + serviceTemplateInstanceId + "/NodeTemplates/" - // + nodeInstanceId; - // refs.getReference().add(new - // Reference(Utilities.buildURI(uriInfo.getBaseUri().toString(), - // nodeUrl), XLinkConstants.REFERENCE, - // URLEncoder.encode(nodeId.getLocalPart(), "UTF-8"))); - // log.debug("build node reference {}", nodeUrl); - // } - // } - } - // we dont want a self link because the InstanceList is part of - // another list already containing a self link - final RelationInstanceList ril = new RelationInstanceList(null, relationInstanceLinks); - - final ServiceInstanceEntry sie = new ServiceInstanceEntry(serviceInstance, serviceInstanceLinks, ril); - - // selflink - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return refs; - } - catch (final Exception e) { - e.printStackTrace(); - return null; - } - } - - @POST - @Produces(MediaType.APPLICATION_XML) - public Response createRelationInstance(@Context final UriInfo uriInfo, - @QueryParam("sourceInstanceId") final String sourceInstanceId, - @QueryParam("targetInstanceId") final String targetInstanceId) { - - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - // ServiceInstance serviceInstanceIdURI = service.getservi - - // if (Utilities.areEmpty(nodeTemplateID, serviceTemplateInstanceId)) { - // throw new GenericRestException(Status.BAD_REQUEST, "Missing one of - // the required parameters: nodeTemplateID, serviceInstanceID"); - // } - - // URI serviceInstanceIdURI = null; - // try { - // - // serviceInstanceIdURI = new ServiceInstance(csarId, nodeTemplateID, - // nodeTemplateID.getLocalPart(), - // serviceTemplateInstanceId).getServiceInstanceID(); - // if (!IdConverter.isValidServiceInstanceID(serviceInstanceIdURI)) { - // throw new Exception("Error converting serviceInstanceID: invalid - // format!"); - // } - // - // } catch (Exception e1) { - // throw new GenericRestException(Status.BAD_REQUEST, "Error converting - // parameter: " + e1.getMessage()); - // } - - try { - final RelationInstance relationInstance = - service.createRelationInstance(this.csarId, this.serviceTemplateID, this.serviceTemplateInstanceId, - this.relatioshipTemplateID, sourceInstanceId, targetInstanceId); - // SimpleXLink response = new - // SimpleXLink(uriInfo.getAbsolutePath().toString() + "/" + - // serviceTemplateInstanceId, "simple"); - final SimpleXLink response = new SimpleXLink( - Utilities.encode(uriInfo.getAbsolutePathBuilder().path(String.valueOf(relationInstance.getId())) - .build()), - "simple"); - return Response.ok(response).build(); - } - catch (final ReferenceNotFoundException e) { - throw new GenericRestException(Status.NOT_FOUND, e.getMessage()); - } - } - - @Path("/{" + Constants.RelationInstanceListResource_getRelationInstance_PARAM + "}") - public Object getRelationInstance(@PathParam(Constants.RelationInstanceListResource_getRelationInstance_PARAM) final int relationshipTemplateInstanceId, - @Context final UriInfo uriInfo) { - - final IInstanceDataService service = InstanceDataServiceHandler.getInstanceDataService(); - ExistenceChecker.checkRelationInstanceWithException(relationshipTemplateInstanceId, service); - return new RelationshipTemplateInstanceResource(this.csarId, this.serviceTemplateID, - this.serviceTemplateInstanceId, this.relatioshipTemplateID, relationshipTemplateInstanceId); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/marketplace/MarketplaceRootResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/marketplace/MarketplaceRootResource.java deleted file mode 100644 index 6f55e166e..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/marketplace/MarketplaceRootResource.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.opentosca.container.api.legacy.resources.marketplace; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; - -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; - -/** - * Copyright 2016 IAAS University of Stuttgart
- *
- * - * @author Kálmán Képes - kalman.kepes@iaas.uni-stuttgart.de - * - */ -@Path("/marketplace") -public class MarketplaceRootResource { - - @Context - UriInfo uriInfo; - - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML() { - return Response.ok(this.getRefs().getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON() { - return Response.ok(this.getRefs().getJSONString()).build(); - } - - public References getRefs() { - final References refs = new References(); - - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "servicetemplates"), - XLinkConstants.SIMPLE, "servicetemplates")); - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return refs; - } - - @Path("/servicetemplates") - public MarketplaceServiceTemplatesResource getServiceTemplates() { - return new MarketplaceServiceTemplatesResource(); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/marketplace/MarketplaceServiceTemplateResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/marketplace/MarketplaceServiceTemplateResource.java deleted file mode 100644 index af211fed7..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/marketplace/MarketplaceServiceTemplateResource.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.opentosca.container.api.legacy.resources.marketplace; - -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; - -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.resources.csar.CSARsResource; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.connector.winery.WineryConnector; -import org.opentosca.container.core.model.csar.id.CSARID; - -/** - * Copyright 2016 IAAS University of Stuttgart
- *
- * - * @author Kálmán Képes - kalman.kepes@iaas.uni-stuttgart.de - * - */ -public class MarketplaceServiceTemplateResource { - - UriInfo uriInfo; - - private final WineryConnector connector = new WineryConnector(); - private final QName serviceTemplate; - - - public MarketplaceServiceTemplateResource(final QName qname) { - this.serviceTemplate = qname; - } - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getJSONString()).build(); - } - - public References getRefs() { - final References refs = new References(); - - refs.getReference() - .add(new Reference(this.getWineryUri(), XLinkConstants.REFERENCE, this.serviceTemplate.toString())); - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return refs; - } - - private String getWineryUri() { - final String encodedNamespace = - Utilities.URLencode(Utilities.URLencode(this.serviceTemplate.getNamespaceURI())); - return Utilities.buildURI(this.connector.getWineryPath() + "servicetemplates/" + encodedNamespace, - this.serviceTemplate.getLocalPart()); - } - - @POST - public Response deploy(@Context final UriInfo uriInfo) throws MalformedURLException, IOException, - URISyntaxException { - this.uriInfo = uriInfo; - // example url: - // http://localhost:8080/winery/servicetemplates/http%253A%252F%252Fopentosca.org%252Fdeclarative%252Fbpel/BPELStack/?csar - final String csarUrl = this.getWineryUri() + "/?csar"; - - final InputStream inputStream = new URL(csarUrl).openConnection().getInputStream(); - - final CSARsResource res = new CSARsResource(); - - final CSARID csarId = res.storeCSAR(this.serviceTemplate.getLocalPart() + ".csar", inputStream); - - final String csarsResourcePath = - this.uriInfo.getAbsolutePath().getScheme() + "://" + this.uriInfo.getAbsolutePath().getHost() + ":" - + this.uriInfo.getAbsolutePath().getPort() + "/containerapi/CSARs/" + csarId.toString(); - - return Response.created(URI.create(csarsResourcePath)).build(); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/marketplace/MarketplaceServiceTemplatesResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/marketplace/MarketplaceServiceTemplatesResource.java deleted file mode 100644 index f65c85efc..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/marketplace/MarketplaceServiceTemplatesResource.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.opentosca.container.api.legacy.resources.marketplace; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.net.URLEncoder; - -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.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.connector.winery.WineryConnector; - -/** - * Copyright 2016 IAAS University of Stuttgart
- *
- * - * @author Kálmán Képes - kalman.kepes@iaas.uni-stuttgart.de - * - */ -public class MarketplaceServiceTemplatesResource { - - UriInfo uriInfo; - - private final WineryConnector connector = new WineryConnector(); - - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getJSONString()).build(); - } - - @Path("/{serviceTemplateId}") - public MarketplaceServiceTemplateResource getServiceTemplate(@PathParam("serviceTemplateId") final String serviceTemplateId) { - - QName serviceTemplate = null; - try { - final String decodedServiceTemplateId = URLDecoder.decode(serviceTemplateId, "UTF-8"); - final String namespace = decodedServiceTemplateId.substring(1).split("}")[0]; - final String localPart = decodedServiceTemplateId.substring(1).split("}")[1]; - serviceTemplate = new QName(namespace, localPart); - } - catch (final UnsupportedEncodingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - if (serviceTemplate == null) { - throw new IllegalArgumentException("ServiceTemplateId couldn't be read"); - } - - return new MarketplaceServiceTemplateResource(serviceTemplate); - } - - public References getRefs() { - final References refs = new References(); - - for (final QName serviceTemplateId : this.connector.getServiceTemplates()) { - refs.getReference() - .add(new Reference( - Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), - URLEncoder.encode(serviceTemplateId.toString())), - XLinkConstants.SIMPLE, serviceTemplateId.toString())); - } - - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return refs; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/packager/PackagerPackagesResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/packager/PackagerPackagesResource.java deleted file mode 100644 index 78eb68499..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/packager/PackagerPackagesResource.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.opentosca.container.api.legacy.resources.packager; - -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.connector.winery.WineryConnector; - -/** - * Copyright 2017 IAAS University of Stuttgart
- *
- * - * @author Kálmán Képes - kalman.kepes@iaas.uni-stuttgart.de - * - */ -public class PackagerPackagesResource { - - @Context - UriInfo uriInfo; - - private final WineryConnector connector = new WineryConnector(); - - private static final List tags = new ArrayList<>(); - - static { - PackagerPackagesResource.tags.add("xaasPackageDeploymentArtefact"); - PackagerPackagesResource.tags.add("xaasPackageNode"); - PackagerPackagesResource.tags.add("xaasPackageArtefactType"); - } - - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON(@Context final UriInfo uriInfo) { - this.uriInfo = uriInfo; - return Response.ok(this.getRefs().getJSONString()).build(); - } - - public References getRefs() { - final References refs = new References(); - - if (this.connector.isWineryRepositoryAvailable()) { - for (final QName xaasPackageServiceTemplateId : this.connector.getServiceTemplates(PackagerPackagesResource.tags)) { - final String uri = Utilities - .buildURI(this.uriInfo.getAbsolutePath().toString(), - Utilities.URLencode(xaasPackageServiceTemplateId.toString())) - .replace("packager/packages", "marketplace/servicetemplates"); - refs.getReference() - .add(new Reference(uri, XLinkConstants.SIMPLE, xaasPackageServiceTemplateId.toString())); - } - } - - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return refs; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/packager/PackagerResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/packager/PackagerResource.java deleted file mode 100644 index 7a726a8ce..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/packager/PackagerResource.java +++ /dev/null @@ -1,169 +0,0 @@ -package org.opentosca.container.api.legacy.resources.packager; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.file.Files; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -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.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; -import javax.xml.bind.JAXBException; -import javax.xml.namespace.QName; - -import org.glassfish.jersey.media.multipart.FormDataBodyPart; -import org.glassfish.jersey.media.multipart.FormDataContentDisposition; -import org.glassfish.jersey.media.multipart.FormDataParam; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.connector.winery.WineryConnector; - -/** - * Copyright 2017 IAAS University of Stuttgart
- *
- * - * @author Kálmán Képes - kalman.kepes@iaas.uni-stuttgart.de - * - */ -@Path("/packager") -public class PackagerResource { - - @Context - UriInfo uriInfo; - - private final WineryConnector connector = new WineryConnector(); - - - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferencesXML() { - return Response.ok(this.getRefs().getXMLString()).build(); - } - - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getReferencesJSON() { - return Response.ok(this.getRefs().getJSONString()).build(); - } - - public References getRefs() { - final References refs = new References(); - - if (this.connector.isWineryRepositoryAvailable()) { - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "packages"), - XLinkConstants.SIMPLE, "servicetemplates")); - } - refs.getReference() - .add(new Reference(this.uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - return refs; - } - - @Path("/packages") - public PackagerPackagesResource getPackages() { - return new PackagerPackagesResource(); - } - - @POST - @Consumes(MediaType.MULTIPART_FORM_DATA) - public Response createFromArtefact(@FormDataParam("file") final InputStream uploadedInputStream, - @FormDataParam("file") final FormDataContentDisposition fileDetail, - @FormDataParam("file") final FormDataBodyPart body, - @FormDataParam("artefactType") final QName artifactType, - @FormDataParam("nodeTypes") final Set nodeTypes, - @FormDataParam("infrastructureNodeType") final QName infrastructureNodeType, - @FormDataParam("tags") final Set tags, - @Context final UriInfo uriInfo) throws IllegalArgumentException, JAXBException, - IOException { - - if (!this.connector.isWineryRepositoryAvailable()) { - return Response.status(Status.SERVICE_UNAVAILABLE).build(); - } - - final File tempFile = this.inputStream2File(uploadedInputStream, fileDetail.getFileName()); - - try { - final QName xaasServiceTemplate = - this.connector.createServiceTemplateFromXaaSPackage(tempFile, artifactType, nodeTypes, - infrastructureNodeType, - this.createTagMapFromTagSet(tags)); - final String redirectUrl = Utilities - .buildURI(this.uriInfo.getAbsolutePath().toString(), - "servicetemplates/" - + Utilities.URLencode(xaasServiceTemplate.toString())) - .replace("packager", "marketplace"); - return Response.created(URI.create(redirectUrl)).build(); - } - catch (final URISyntaxException e) { - e.printStackTrace(); - } - return Response.serverError().build(); - } - - private Map createTagMapFromTagSet(final Set tags) { - final Map tagMap = new HashMap<>(); - - for (final String tag : tags) { - if (tag.contains(":")) { - final String key = tag.split(":")[0]; - final String value = tag.split(":")[1]; - tagMap.put(key, value); - } else { - tagMap.put(tag, null); - } - } - - return tagMap; - } - - private File inputStream2File(final InputStream is, final String fileName) { - OutputStream out = null; - File tempFile = null; - try { - ; - - tempFile = new File(Files.createTempDirectory("XaaSPackager").toFile(), fileName); - tempFile.createNewFile(); - out = new FileOutputStream(tempFile); - - int read = 0; - final byte[] bytes = new byte[1024]; - - while ((read = is.read(bytes)) != -1) { - out.write(bytes, 0, read); - } - - is.close(); - out.close(); - } - catch (final FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - catch (final IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - return tempFile; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/smartservices/SmartServicesResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/smartservices/SmartServicesResource.java deleted file mode 100644 index ebfde3afa..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/smartservices/SmartServicesResource.java +++ /dev/null @@ -1,500 +0,0 @@ -package org.opentosca.container.api.legacy.resources.smartservices; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.namespace.QName; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; - -import org.opentosca.container.api.legacy.osgi.servicegetter.FileRepositoryServiceHandler; -import org.opentosca.container.api.legacy.osgi.servicegetter.InstanceDataServiceHandler; -import org.opentosca.container.api.legacy.osgi.servicegetter.ModelRepositoryServiceHandler; -import org.opentosca.container.api.legacy.osgi.servicegetter.ToscaServiceHandler; -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.opentosca.container.core.common.SystemException; -import org.opentosca.container.core.common.UserException; -import org.opentosca.container.core.model.AbstractDirectory; -import org.opentosca.container.core.model.AbstractFile; -import org.opentosca.container.core.model.csar.CSARContent; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.model.instance.ServiceInstance; -import org.opentosca.container.core.service.ICoreFileService; -import org.opentosca.container.core.service.IInstanceDataService; -import org.opentosca.container.core.tosca.model.TExtensibleElements; -import org.opentosca.container.core.tosca.model.TServiceTemplate; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; - -/** - * Copyright 2016 IAAS University of Stuttgart
- *
- * - * @author Kálmán Képes - kalman.kepes@iaas.uni-stuttgart.de - * - */ -@Path("/SmartServices") -public class SmartServicesResource { - - @Context - UriInfo uriInfo; - - private final ICoreFileService fileHandler; - - - public SmartServicesResource() { - this.fileHandler = FileRepositoryServiceHandler.getFileHandler(); - } - - /** - * Returns links to subresources as JSON - * - * @return a list of links to templates and instances of Smart Services - */ - @GET - @Produces(ResourceConstants.LINKED_JSON) - public Response getJSONLinks() { - final References refs = new References(); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "templates"), - XLinkConstants.SIMPLE, "SmartServiceTemplates")); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "instances"), - XLinkConstants.SIMPLE, "SmartServiceInstances")); - return Response.ok(refs.getJSONString()).build(); - } - - /** - * Returns links to subresources as XML - * - * @return a list of links to templates and instances of Smart Services - */ - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getXMLLinks() { - final References refs = new References(); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "templates"), - XLinkConstants.SIMPLE, "SmartServiceTemplates")); - refs.getReference() - .add(new Reference(Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), "instances"), - XLinkConstants.SIMPLE, "SmartServiceInstances")); - return Response.ok(refs.getXMLString()).build(); - } - - /** - * Returns a list of links to Smart Services inside the model API as JSON - * - * @return a list of links to Smart Service templates inside the model API - */ - @GET - @Path("/templates") - @Produces(ResourceConstants.LINKED_JSON) - public Response getTemplateJSONLinks() { - final References refs = this.getSmartServiceTemplatesReferences(); - return Response.ok(refs.getJSONString()).build(); - } - - /** - * Returns a list of links to Smart Services inside the model API as XML - * - * @return a list of links to Smart Service templates inside the model API - */ - @GET - @Path("/templates") - @Produces(ResourceConstants.LINKED_XML) - public Response getTemplateXMLLinks() { - final References refs = this.getSmartServiceTemplatesReferences(); - return Response.ok(refs.getXMLString()).build(); - } - - @GET - @Path("/instances") - @Produces(ResourceConstants.LINKED_JSON) - public Response getInstancesJSON() { - - final JsonObject root = new JsonObject(); - - final JsonObject runningSmartServices = new JsonObject(); - - final JsonArray sensorDataProviderServices = new JsonArray(); - final JsonArray uiProviderServices = new JsonArray(); - - try { - final List instances = this.getSmartServiceInstances(); - - for (final ServiceInstance instance : instances) { - final Map instanceProperties = this.getSmartServiceInstanceData(instance); - - if (instanceProperties.containsKey("smartServiceType")) { - switch (instanceProperties.get("smartServiceType")) { - case "SensorDataProviderService": - sensorDataProviderServices.add(this.createJSON(instanceProperties)); - break; - case "UIProviderService": - uiProviderServices.add(this.createJSON(instanceProperties)); - break; - } - } - - } - - } - catch (final UserException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - runningSmartServices.add("SensorDataProviderServices", sensorDataProviderServices); - runningSmartServices.add("UIProviderServices", uiProviderServices); - - root.add("RunningSmartService", runningSmartServices); - - return Response.ok(root.toString()).build(); - } - - @GET - @Path("/instances") - @Produces(ResourceConstants.LINKED_XML) - public Response getInstancesXML() { - String rootElementString = ""; - - String sensorDataProviderServicesElementString = ""; - String uiProviderServicesElementString = ""; - - List instances; - try { - instances = this.getSmartServiceInstances(); - - for (final ServiceInstance instance : instances) { - final Map instanceProperties = this.getSmartServiceInstanceData(instance); - - if (instanceProperties.containsKey("smartServiceType")) { - switch (instanceProperties.get("smartServiceType")) { - case "SensorDataProviderService": - sensorDataProviderServicesElementString += - this.createServiceElementAsString(instanceProperties); - break; - case "UIProviderService": - uiProviderServicesElementString += this.createServiceElementAsString(instanceProperties); - break; - } - } - } - } - catch (final UserException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - sensorDataProviderServicesElementString += ""; - uiProviderServicesElementString += ""; - - rootElementString += sensorDataProviderServicesElementString; - rootElementString += uiProviderServicesElementString; - rootElementString += ""; - - return Response.ok(rootElementString).build(); - } - - private String createServiceElementAsString(final Map map) { - - String elementString = ""; - - for (final String key : map.keySet()) { - final String subElement = this.createElementAsString(key, map.get(key)); - elementString += subElement; - } - - elementString += ""; - - return elementString; - } - - private String createElementAsString(final String localName, final String value) { - final String stringElement = "<" + localName + ">" + value + ""; - return stringElement; - } - - private JsonObject createJSON(final Map map) { - - final JsonObject jsonObj = new JsonObject(); - - for (final String key : map.keySet()) { - jsonObj.addProperty(key, map.get(key)); - } - - return jsonObj; - } - - private Map getSmartServiceInstanceData(final ServiceInstance smartServiceInstance) throws UserException { - final CSARID csarId = smartServiceInstance.getCSAR_ID(); - // we take all properties and add them with their values into the map. - // Additionally we fetch data set in self-service meta-data - final Map kvMap = this.getKVProperties(smartServiceInstance.getProperties()); - - final AbstractDirectory dir = - FileRepositoryServiceHandler.getFileHandler().getCSAR(csarId).getDirectory("SELFSERVICE-Metadata"); - - final AbstractFile file = dir.getFile("data.xml"); - - final Map selfServiceMap = this.getSelfServiceProperties(file); - - kvMap.putAll(selfServiceMap); - - kvMap.put("id", smartServiceInstance.getServiceInstanceID().toString()); - - return kvMap; - } - - private Map getSelfServiceProperties(final AbstractFile file) { - final Map selfServiceProperties = new HashMap<>(); - - try { - final Document doc = Utilities.fileToDom(file.getFile().toFile()); - - final Element rootElement = doc.getDocumentElement(); - - final NodeList childNodes = rootElement.getChildNodes(); - - for (int i = 0; i < childNodes.getLength(); i++) { - if (childNodes.item(i) instanceof Element) { - final Element element = (Element) childNodes.item(i); - // the elements are create with DOM level 1 methode - // getLocalName() is always null.. - final String nodeName = element.getNodeName(); - switch (nodeName) { - case "displayName": - selfServiceProperties.put("name", element.getNodeValue()); - break; - case "description": - selfServiceProperties.put("description", element.getNodeValue()); - break; - case "iconUrl": - if (element.getNodeValue() != null) { - selfServiceProperties.put("smartServiceIconURL", - Utilities.buildURI(this.uriInfo.getAbsolutePath().toString(), - "SELFSERVICE-Metadata/" - + element.getNodeValue())); - } else { - selfServiceProperties.put("smartServiceIconURL", null); - } - break; - } - } - } - - } - catch (final ParserConfigurationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - catch (final SAXException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - catch (final IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - catch (final SystemException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - return selfServiceProperties; - } - - private Map getKVProperties(final Document doc) { - final Map kvMap = new HashMap<>(); - - final Element rootElement = doc.getDocumentElement(); - - final NodeList childNodes = rootElement.getChildNodes(); - - for (int i = 0; i < childNodes.getLength(); i++) { - if (childNodes.item(i) instanceof Element) { - final Element childElement = (Element) childNodes.item(i); - - final String key = childElement.getLocalName(); - final String val = childElement.getTextContent(); - - kvMap.put(key, val); - } - } - - return kvMap; - } - - private References getSmartServiceInstancesReferences() { - final References refs = new References(); - - try { - for (final ServiceInstance instance : this.getSmartServiceInstances()) { - refs.getReference().add(new Reference(instance.getServiceInstanceID().toString(), XLinkConstants.SIMPLE, - "smartServiceInstance")); - } - } - catch (final UserException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return refs; - } - - private List getSmartServiceInstances() throws UserException { - final List instances = new ArrayList<>(); - final Map smartServiceTemplates = this.getSmartServiceTemplates(); - final IInstanceDataService instancesService = InstanceDataServiceHandler.getInstanceDataService(); - - for (final CSARID csarId : smartServiceTemplates.keySet()) { - - // TODO/FIXME query with serviceTemplateId doesn't work - final List instanceList = instancesService.getServiceInstances(null, null, null); - - final List toAdd = new ArrayList<>(); - - for (final ServiceInstance instance : instanceList) { - if (instance.getServiceTemplateID().equals(smartServiceTemplates.get(csarId))) { - toAdd.add(instance); - } - } - - if (!toAdd.isEmpty()) { - instances.addAll(toAdd); - } - - } - - return instances; - } - - private References getSmartServiceTemplatesReferences() { - final References refs = new References(); - - try { - final Map smartServices = this.getSmartServiceTemplates(); - for (final CSARID csarId : smartServices.keySet()) { - final Reference ref = new Reference( - Utilities.buildURI(this.uriInfo.getAbsolutePath().toString().replace("/SmartServices/templates", - "/CSARs/"), - csarId.toString() + "/Content/" - + ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper() - .getDefinitionsLocation(csarId, - smartServices.get(csarId))), - XLinkConstants.SIMPLE, smartServices.get(csarId).toString()); - refs.getReference().add(ref); - } - } - catch (final UserException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return refs; - } - - return refs; - } - - private Map getSmartServiceTemplates() throws UserException { - final Map map = new HashMap<>(); - - for (final CSARID csarId : this.fileHandler.getCSARIDs()) { - final CSARContent content = this.fileHandler.getCSAR(csarId); - final AbstractFile absFile = content.getRootTOSCA(); - - for (final QName serviceTemplateId : ModelRepositoryServiceHandler.getModelHandler() - .getAllDefinitionsIDs(csarId)) { - final String location = ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper() - .getDefinitionsLocation(csarId, serviceTemplateId); - if (absFile.getPath().contains(location)) { - // found root TOSCA - - for (final TExtensibleElements extElem : ModelRepositoryServiceHandler.getModelHandler() - .getDefinitions(csarId, - serviceTemplateId) - .getServiceTemplateOrNodeTypeOrNodeTypeImplementation()) { - if (extElem instanceof TServiceTemplate) { - final TServiceTemplate servTemplate = (TServiceTemplate) extElem; - final Object obj = servTemplate.getBoundaryDefinitions().getProperties().getAny(); - - final String defNs = ModelRepositoryServiceHandler.getModelHandler() - .getDefinitions(csarId, serviceTemplateId) - .getTargetNamespace(); - - final String localName = servTemplate.getId(); - final String stNs = servTemplate.getTargetNamespace(); - - if (obj instanceof Element) { - try { - if (this.containsSmartServiceProperties((Element) obj)) { - if (stNs == null) { - map.put(csarId, new QName(defNs, localName)); - } else { - map.put(csarId, new QName(stNs, localName)); - } - } else { - // if this serviceTemplate isn't a smart - // service we can skip the csar - break; - } - } - catch (final XPathExpressionException e) { - e.printStackTrace(); - // skip - break; - } - } - - } - } - } - } - - } - - return map; - } - - private boolean containsSmartServiceProperties(final Element element) throws XPathExpressionException { - final XPath xpath = XPathFactory.newInstance().newXPath(); - final String xpathExprSmartServiceType = "//*[local-name()='smartServiceType']"; - final String xpathExprSmartServiceSensorDataType = "//*[local-name()='sensorDataType']"; - final String xpathExprSmartServiceSensorDataValueType = "//*[local-name()='sensorDataValueType']"; - - final Node smartServiceTypeNode = - (Node) xpath.evaluate(xpathExprSmartServiceType, element, XPathConstants.NODE); - final Node smartServiceSensorDataTypeNode = - (Node) xpath.evaluate(xpathExprSmartServiceSensorDataType, element, XPathConstants.NODE); - final Node smartServiceSensorDataValueTypeNode = - (Node) xpath.evaluate(xpathExprSmartServiceSensorDataValueType, element, XPathConstants.NODE); - - if (!Utilities.areNotNull(smartServiceTypeNode, smartServiceSensorDataTypeNode, - smartServiceSensorDataValueTypeNode)) { - return false; - } - - return true; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/AvailableStorageProviderResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/AvailableStorageProviderResource.java deleted file mode 100644 index 5f753cdca..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/AvailableStorageProviderResource.java +++ /dev/null @@ -1,142 +0,0 @@ -package org.opentosca.container.api.legacy.resources.storageproviders; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; - -import org.opentosca.container.api.legacy.osgi.servicegetter.CredentialsServiceHandler; -import org.opentosca.container.api.legacy.osgi.servicegetter.FileRepositoryServiceHandler; -import org.opentosca.container.api.legacy.resources.storageproviders.jaxb.JaxbFactory; -import org.opentosca.container.api.legacy.resources.storageproviders.jaxb.StorageProviderJaxb; -import org.opentosca.container.core.common.SystemException; -import org.opentosca.container.core.common.UserException; -import org.opentosca.container.core.service.ICoreCredentialsService; -import org.opentosca.container.core.service.ICoreFileService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Resource of a available storage provider of the Core File Service.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -public class AvailableStorageProviderResource { - - private static final Logger LOG = LoggerFactory.getLogger(AvailableStorageProviderResource.class); - - private final ICoreFileService FILE_SERVICE = FileRepositoryServiceHandler.getFileHandler(); - - private final ICoreCredentialsService CREDENTIALS_SERVICE = CredentialsServiceHandler.getCredentialsService(); - - /** - * If {@code null} it's a not available storage provider and every method returns 404 (not found). - */ - private final String STORAGE_PROVIDER_ID; - - - /** - * Creates a {@link AvailableStorageProviderResource} of storage provider {@code storageProviderID}. - * - * @param storageProviderID of storage provider. - */ - public AvailableStorageProviderResource(final String storageProviderID) { - AvailableStorageProviderResource.LOG.debug("{} created: {}", this.getClass(), this); - this.STORAGE_PROVIDER_ID = storageProviderID; - } - - /** - * Gets the storage provider that will be showed on this resource. - * - * @return 200 (OK) with entity {@link StorageProviderJaxb} containing the storage provider that - * will be showed. If this storage provider is not available 404 (not found). - */ - @GET - @Produces(MediaType.APPLICATION_XML) - public Response getStorageProvider() { - - if (this.STORAGE_PROVIDER_ID == null) { - return Response.status(Status.NOT_FOUND).build(); - } - - return Response.ok(JaxbFactory.createStorageProviderJaxb(this.STORAGE_PROVIDER_ID)).build(); - - } - - /** - * Either sets this storage provider as the active one if {@code activate} is passed in - * {@code input} (body of a POST message) or deletes the credentials in this storage provider if - * {@code unset} is passed instead. - * - * @param input - * - * @return 200 (OK) - storage provider was set as the active one or credentials were deleted in this - * storage provider.
- * 400 (bad request) - {@code activate} respectively {@code unset} was not passed or storage - * provider has no credentials to delete.
- * 500 (internal server error) - setting this storage provider as the active one or deleting - * credentials in this storage provider failed.
- * 404 (not found) - this storage provider is not available. - * @throws UserException - * @throws SystemException - * @see ICoreFileService#setActiveStorageProvider(String) - * @see ICoreCredentialsService#deleteCredentialsInStorageProvider(String) - */ - @POST - @Consumes(MediaType.TEXT_PLAIN) - @Produces(MediaType.TEXT_PLAIN) - public Response setAsActiveOrUnsetCredentials(final String input) throws UserException, SystemException { - - if (this.STORAGE_PROVIDER_ID == null) { - return Response.status(Status.NOT_FOUND).build(); - } - - // try { - - if (input.equalsIgnoreCase("activate")) { - - this.FILE_SERVICE.setActiveStorageProvider(this.STORAGE_PROVIDER_ID); - - return Response.ok("Storage provider \"" + this.STORAGE_PROVIDER_ID + "\" was set as the active one.") - .build(); - - } else if (input.equalsIgnoreCase("unset")) { - - final boolean hasCredentials = - this.CREDENTIALS_SERVICE.hasStorageProviderCredentials(this.STORAGE_PROVIDER_ID); - - if (hasCredentials) { - this.CREDENTIALS_SERVICE.deleteCredentialsInStorageProvider(this.STORAGE_PROVIDER_ID); - return Response.ok("Credentials were deleted in storage provider \"" + this.STORAGE_PROVIDER_ID + "\".") - .build(); - } else { - return Response.status(Status.BAD_REQUEST) - .entity("Storage provider \"" + this.STORAGE_PROVIDER_ID + "\" has no credentials.") - .build(); - } - - } else { - return Response.status(Status.BAD_REQUEST).build(); - } - - // } catch (SystemException exc) { - // AvailableStorageProviderResource.LOG.warn("A System Exception - // occured.", - // exc); - // } catch (UserException exc) { - // AvailableStorageProviderResource.LOG.warn("An User Exception - // occured.", - // exc); - // } - - // return Response.status(Status.INTERNAL_SERVER_ERROR).build(); - - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/AvailableStorageProvidersResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/AvailableStorageProvidersResource.java deleted file mode 100644 index 9c8170436..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/AvailableStorageProvidersResource.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.opentosca.container.api.legacy.resources.storageproviders; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; - -import org.opentosca.container.api.legacy.osgi.servicegetter.FileRepositoryServiceHandler; -import org.opentosca.container.api.legacy.resources.storageproviders.jaxb.JaxbFactory; -import org.opentosca.container.api.legacy.resources.storageproviders.jaxb.StorageProvidersJaxb; -import org.opentosca.container.core.service.ICoreFileService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Resource of all available storage providers of the Core File Service.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -public class AvailableStorageProvidersResource { - - private static final Logger LOG = LoggerFactory.getLogger(AvailableStorageProvidersResource.class); - - private final ICoreFileService FILE_SERVICE = FileRepositoryServiceHandler.getFileHandler(); - - - /** - * Creates a {@link AvailableStorageProvidersResource}. - */ - public AvailableStorageProvidersResource() { - AvailableStorageProvidersResource.LOG.debug("{} created: {}", this.getClass(), this); - } - - /** - * Gets the storage providers that will be showed on this resource. It depends on the query - * parameter {@code type} passed by the user. - * - * @param type - optional query parameter that determines if only storage providers with a certain - * property ( {@link StorageProviderProperties}) should be showed. If type is invalid all - * storage providers will be showed. - * @return {@link StorageProvidersJaxb} containing the storage providers that will be showed. - * - * @see StorageProviderProperties - */ - @GET - @Produces(MediaType.APPLICATION_XML) - public StorageProvidersJaxb getStorageProviders(@QueryParam("type") final String type) { - - if (StorageProviderProperties.ACTIVE.toString().equalsIgnoreCase(type)) { - return JaxbFactory.createStorageProvidersJaxbOfActiveStorageProvider(); - } else if (StorageProviderProperties.READY.toString().equalsIgnoreCase(type)) { - return JaxbFactory.createStorageProvidersJaxbOfReadyStorageProviders(); - } else if (StorageProviderProperties.DEFAULT.toString().equalsIgnoreCase(type)) { - return JaxbFactory.createStorageProvidersJaxbOfDefaultStorageProvider(); - } - - return JaxbFactory.createStorageProvidersJaxbOfAllStorageProviders(); - - } - - /** - * - * Creates a {@link AvailableStorageProviderResource} of storage provider {@code storageProviderID}. - * If storage provider {@code storageProviderID} is not available it will be created with - * {@code null}. - * - * @param storageProviderID of storage provider - * @return {@link AvailableStorageProviderResource} - */ - @Path("{id}") - public AvailableStorageProviderResource getStorageProviderResource(@PathParam("id") final String storageProviderID) { - - if (this.FILE_SERVICE.getStorageProviders().contains(storageProviderID)) { - return new AvailableStorageProviderResource(storageProviderID); - } - - return new AvailableStorageProviderResource(null); - - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/DefaultStorageProviderResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/DefaultStorageProviderResource.java deleted file mode 100644 index 4345aeee6..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/DefaultStorageProviderResource.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.opentosca.container.api.legacy.resources.storageproviders; - -import javax.ws.rs.GET; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -import org.opentosca.container.api.legacy.resources.storageproviders.jaxb.JaxbFactory; -import org.opentosca.container.api.legacy.resources.storageproviders.jaxb.StorageProviderJaxb; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Resource of the default storage provider of the Core File Service (regardless if it's available - * or not).
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -public class DefaultStorageProviderResource { - - private static final Logger LOG = LoggerFactory.getLogger(DefaultStorageProviderResource.class); - - - /** - * Creates a {@link DefaultStorageProviderResource}. - */ - public DefaultStorageProviderResource() { - DefaultStorageProviderResource.LOG.info("{} created: {}", this.getClass(), this); - } - - /** - * @return {@link StorageProviderJaxb} containing the default storage provider that will be showed - * on this resource. - */ - @GET - @Produces(MediaType.APPLICATION_XML) - public StorageProviderJaxb getDefaultStorageProviderXML() { - return JaxbFactory.createStorageProviderJaxbOfDefaultStorageProvider(); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/StorageProviderProperties.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/StorageProviderProperties.java deleted file mode 100644 index dddf38f43..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/StorageProviderProperties.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.opentosca.container.api.legacy.resources.storageproviders; - -/** - * Possible properties of a available storage provider of the Core File Service. - * - *
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -public enum StorageProviderProperties { - ACTIVE, READY, DEFAULT; -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/StorageProvidersResource.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/StorageProvidersResource.java deleted file mode 100644 index 16852fa20..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/StorageProvidersResource.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.opentosca.container.api.legacy.resources.storageproviders; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; - -import org.opentosca.container.api.legacy.resources.utilities.ResourceConstants; -import org.opentosca.container.api.legacy.resources.utilities.Utilities; -import org.opentosca.container.api.legacy.resources.xlink.Reference; -import org.opentosca.container.api.legacy.resources.xlink.References; -import org.opentosca.container.api.legacy.resources.xlink.XLinkConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Main resource of the storage providers of the Core File Service. It shows only XLink references - * to sub resources.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -@Path("/StorageProviders") -public class StorageProvidersResource { - - private static final Logger LOG = LoggerFactory.getLogger(StorageProvidersResource.class); - - - /** - * Creates a {@link StorageProvidersResource}. - */ - public StorageProvidersResource() { - StorageProvidersResource.LOG.info("{} created: {}", this.getClass(), this); - } - - /** - * @param uriInfo - * @return 200 (OK) with XLink references to available storage providers and default storage - * provider resources (and self reference). - */ - @GET - @Produces(ResourceConstants.LINKED_XML) - public Response getReferences(@Context final UriInfo uriInfo) { - - final References refs = new References(); - - refs.getReference().add(new Reference(Utilities.buildURI(uriInfo.getAbsolutePath().toString(), "Available"), - XLinkConstants.SIMPLE, "Available")); - refs.getReference().add(new Reference(Utilities.buildURI(uriInfo.getAbsolutePath().toString(), "Default"), - XLinkConstants.SIMPLE, "Default")); - refs.getReference() - .add(new Reference(uriInfo.getAbsolutePath().toString(), XLinkConstants.SIMPLE, XLinkConstants.SELF)); - - return Response.ok(refs.getXMLString()).build(); - } - - /** - * @return {@link AvailableStorageProvidersResource} - */ - @Path("Available") - public AvailableStorageProvidersResource getAvailableStorageProvidersResource() { - return new AvailableStorageProvidersResource(); - } - - /** - * @return {@link DefaultStorageProviderResource} - */ - @Path("Default") - public DefaultStorageProviderResource getDefaultStorageProviderResource() { - return new DefaultStorageProviderResource(); - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/jaxb/JaxbFactory.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/jaxb/JaxbFactory.java deleted file mode 100644 index 4da6b26cf..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/jaxb/JaxbFactory.java +++ /dev/null @@ -1,212 +0,0 @@ -package org.opentosca.container.api.legacy.resources.storageproviders.jaxb; - -import java.util.HashSet; -import java.util.Set; - -import org.opentosca.container.api.legacy.osgi.servicegetter.CredentialsServiceHandler; -import org.opentosca.container.api.legacy.osgi.servicegetter.FileRepositoryServiceHandler; -import org.opentosca.container.api.legacy.resources.storageproviders.AvailableStorageProviderResource; -import org.opentosca.container.api.legacy.resources.storageproviders.AvailableStorageProvidersResource; -import org.opentosca.container.api.legacy.resources.storageproviders.DefaultStorageProviderResource; -import org.opentosca.container.core.common.SystemException; -import org.opentosca.container.core.service.ICoreCredentialsService; -import org.opentosca.container.core.service.ICoreFileService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Creates the JAXB objects for the {@link AvailableStorageProvidersResource}, - * {@link AvailableStorageProviderResource} and {@link DefaultStorageProviderResource}.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -public class JaxbFactory { - - private final static Logger LOG = LoggerFactory.getLogger(JaxbFactory.class); - - private static ICoreFileService fileService = FileRepositoryServiceHandler.getFileHandler(); - private static ICoreCredentialsService credentialsService = CredentialsServiceHandler.getCredentialsService(); - - - /** - * - * @return {@link StorageProvidersJaxb} that contains all available storage providers. - * @see #createStorageProvidersJaxb(Set) - */ - public static StorageProvidersJaxb createStorageProvidersJaxbOfAllStorageProviders() { - - final Set storageProviderIDs = JaxbFactory.fileService.getStorageProviders(); - - final StorageProvidersJaxb storageProvidersJaxb = JaxbFactory.createStorageProvidersJaxb(storageProviderIDs); - - return storageProvidersJaxb; - - } - - /** - * - * @return {@link StorageProvidersJaxb} that contains the active storage provider if it's set - * (otherwise not storage provider is contained). - * @see #createStorageProvidersJaxb(Set) - */ - public static StorageProvidersJaxb createStorageProvidersJaxbOfActiveStorageProvider() { - - final String activeStorageProviderID = JaxbFactory.fileService.getActiveStorageProvider(); - - final Set storageProviderIDs = new HashSet<>(); - - if (activeStorageProviderID != null) { - storageProviderIDs.add(activeStorageProviderID); - } - - final StorageProvidersJaxb storageProvidersJaxb = JaxbFactory.createStorageProvidersJaxb(storageProviderIDs); - - return storageProvidersJaxb; - - } - - /** - * - * @return {@link StorageProvidersJaxb} that contains the ready storage providers. - * @see #createStorageProvidersJaxb(Set) - */ - public static StorageProvidersJaxb createStorageProvidersJaxbOfReadyStorageProviders() { - - final Set readyStorageProviderIDs = JaxbFactory.fileService.getReadyStorageProviders(); - - final StorageProvidersJaxb storageProvidersJaxb = - JaxbFactory.createStorageProvidersJaxb(readyStorageProviderIDs); - - return storageProvidersJaxb; - - } - - /** - * - * @return {@link StorageProviderJaxb} that contains the default storage provider. - * @see #createStorageProviderJaxb(String) - */ - public static StorageProviderJaxb createStorageProviderJaxbOfDefaultStorageProvider() { - - final String defaultStorageProviderID = JaxbFactory.fileService.getDefaultStorageProvider(); - - final StorageProviderJaxb storageProviderJaxb = JaxbFactory.createStorageProviderJaxb(defaultStorageProviderID); - - return storageProviderJaxb; - - } - - /** - * - * @return {@link StorageProvidersJaxb} that contains the default storage provider. - * @see #createStorageProvidersJaxb(Set) - */ - public static StorageProvidersJaxb createStorageProvidersJaxbOfDefaultStorageProvider() { - - final String defaultStorageProviderID = JaxbFactory.fileService.getDefaultStorageProvider(); - - final Set storageProviderIDs = new HashSet<>(); - storageProviderIDs.add(defaultStorageProviderID); - - final StorageProvidersJaxb storageProvidersJaxb = JaxbFactory.createStorageProvidersJaxb(storageProviderIDs); - - return storageProvidersJaxb; - } - - /** - * - * Builds a {@link StorageProviderJaxb} of the storage provider {@code storageProviderID}.
- * Necessary data (e.g. is storage provider ready) will be fetched from the {@link ICoreFileService} - * and {@link ICoreCredentialsService}. - * - * @param storageProviderID of storage provider. - * @return {@link StorageProviderJaxb} of the storage provider {@code storageProviderID}. - */ - public static StorageProviderJaxb createStorageProviderJaxb(final String storageProviderID) { - - final StorageProviderJaxb storageProviderJaxb = new StorageProviderJaxb(); - - storageProviderJaxb.setId(storageProviderID); - - // the following information can be only set in the JAXB object if the - // storage provider is available (otherwise the information is not - // available) - if (JaxbFactory.fileService.getStorageProviders().contains(storageProviderID)) { - - storageProviderJaxb.setName(JaxbFactory.fileService.getStorageProviderName(storageProviderID)); - storageProviderJaxb.setReady(JaxbFactory.fileService.isReadyStorageProvider(storageProviderID)); - - try { - storageProviderJaxb.setNeedsCredentials(JaxbFactory.credentialsService.needsStorageProviderCredentials(storageProviderID)); - } - catch (final SystemException exc) { - JaxbFactory.LOG.debug("A System Exception occured.", exc); - } - - try { - storageProviderJaxb.setCredentialsIdentityName(JaxbFactory.credentialsService.getCredentialsIdentityName(storageProviderID)); - } - catch (final SystemException exc) { - JaxbFactory.LOG.debug("A System Exception occured.", exc); - } - - try { - storageProviderJaxb.setCredentialsKeyName(JaxbFactory.credentialsService.getCredentialsKeyName(storageProviderID)); - } - catch (final SystemException exc) { - JaxbFactory.LOG.debug("A System Exception occured.", exc); - } - - try { - storageProviderJaxb.setHasCredentials(JaxbFactory.credentialsService.hasStorageProviderCredentials(storageProviderID)); - } - catch (final SystemException exc) { - JaxbFactory.LOG.debug("A System Exception occured.", exc); - } - - if (storageProviderID.equals(JaxbFactory.fileService.getActiveStorageProvider())) { - storageProviderJaxb.setActive(true); - } else { - storageProviderJaxb.setActive(false); - } - - } - - if (storageProviderID.equals(JaxbFactory.fileService.getDefaultStorageProvider())) { - storageProviderJaxb.setDefault(true); - } else { - storageProviderJaxb.setDefault(false); - } - - return storageProviderJaxb; - - } - - /** - * Builds {@link StorageProvidersJaxb} containing the storage providers - * {@code storageProviderIDs}.
- * It uses {@link #buildStorageProviderJaxb(String)}. - * - * @param storageProviderIDs of storage providers. - * @return {@link StorageProvidersJaxb} containing the storage providers {@code storageProviderIDs}. - */ - private static StorageProvidersJaxb createStorageProvidersJaxb(final Set storageProviderIDs) { - - final Set storageProviders = new HashSet<>(); - - for (final String storageProviderID : storageProviderIDs) { - final StorageProviderJaxb storageProviderJaxb = JaxbFactory.createStorageProviderJaxb(storageProviderID); - storageProviders.add(storageProviderJaxb); - } - - final StorageProvidersJaxb storageProvidersJaxb = new StorageProvidersJaxb(); - storageProvidersJaxb.setStorageProvider(storageProviders); - - return storageProvidersJaxb; - - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/jaxb/StorageProviderJaxb.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/jaxb/StorageProviderJaxb.java deleted file mode 100644 index 4764a2653..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/jaxb/StorageProviderJaxb.java +++ /dev/null @@ -1,203 +0,0 @@ -package org.opentosca.container.api.legacy.resources.storageproviders.jaxb; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -import org.opentosca.container.api.legacy.resources.storageproviders.AvailableStorageProviderResource; -import org.opentosca.container.api.legacy.resources.storageproviders.AvailableStorageProvidersResource; -import org.opentosca.container.api.legacy.resources.storageproviders.DefaultStorageProviderResource; - -/** - * JAXB annotated class that represents a storage provider.
- * It will be created by {@link JaxbFactory} and used in {@link AvailableStorageProvidersResource}, - * {@link AvailableStorageProviderResource} and {@link DefaultStorageProviderResource}.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -@XmlRootElement(name = "StorageProvider") -@XmlAccessorType(XmlAccessType.FIELD) -public class StorageProviderJaxb { - - @XmlAttribute(name = "id") - private String id; - - @XmlAttribute(name = "name") - private String name; - - /** - * We use the wrapper class {@link Boolean}, because we doesn't want to show a XML element (with - * value {@code false}) in case boolean was not set. - */ - - @XmlElement(name = "Active") - private Boolean active; - - @XmlElement(name = "Ready") - private Boolean ready; - - @XmlElement(name = "Default") - private Boolean def; - - @XmlElement(name = "NeedsCredentials") - private Boolean needsCredentials; - - @XmlElement(name = "CredentialsIdentityName") - private String credentialsIdentityName; - - @XmlElement(name = "CredentialsKeyName") - private String credentialsKeyName; - - @XmlElement(name = "HasCredentials") - private Boolean hasCredentials; - - - /** - * @return ID of this storage provider. - */ - public String getId() { - return this.id; - } - - /** - * Sets the ID of this storage provider. - * - * @param id to set. - */ - public void setId(final String id) { - this.id = id; - } - - /** - * @return Name of this storage provider. - */ - public String getName() { - return this.name; - } - - /** - * Sets the name of this storage provider. - * - * @param name to set. - */ - public void setName(final String name) { - this.name = name; - } - - /** - * @return {@code true} if this storage provider is active, otherwise {@code false}. - */ - public boolean isActive() { - return this.active; - } - - /** - * Sets that this storage provider is active or not. - * - * @param active to set. - */ - public void setActive(final boolean active) { - this.active = active; - } - - /** - * @return {@code true} if this storage provider is ready, otherwise {@code false}. - */ - public boolean isReady() { - return this.ready; - } - - /** - * Sets that this storage provider is ready or not. - * - * @param ready to set. - */ - public void setReady(final boolean ready) { - this.ready = ready; - } - - /** - * @return {@code true} if this storage provider is the default storage provider, otherwise - * {@code false}. - */ - public boolean isDefault() { - return this.def; - } - - /** - * Sets that this storage provider is the default storage provider or not. - * - * @param def to set. - */ - public void setDefault(final boolean def) { - this.def = def; - } - - /** - * - * @return {@code true} if this storage provider needs credentials, otherwise {@code false}. - */ - public boolean getNeedsCredentials() { - return this.needsCredentials; - } - - /** - * Sets that this storage provider needs credentials or not. - * - * @param needsCredentials to set. - */ - public void setNeedsCredentials(final boolean needsCredentials) { - this.needsCredentials = needsCredentials; - } - - /** - * @return Name of the credentials identity of this storage provider. - */ - public String getCredentialsIdentityName() { - return this.credentialsIdentityName; - } - - /** - * Sets {@code credentialsIdentityName} as the credentials identity name of this storage provider. - */ - public void setCredentialsIdentityName(final String credentialsIdentityName) { - this.credentialsIdentityName = credentialsIdentityName; - } - - /** - * @return Name of the credentials key of this storage provider. - */ - public String getCredentialsKeyName() { - return this.credentialsKeyName; - } - - /** - * Sets {@code credentialsKeyName} as the credentials key name of this storage provider. - */ - public void setCredentialsKeyName(final String credentialsKeyName) { - this.credentialsKeyName = credentialsKeyName; - } - - /** - * @return {@code true} if this storage provider has credentials set, otherwise {@code false}. - */ - public Boolean hasCredentials() { - return this.hasCredentials; - } - - /** - * Sets that this storage provider has credentials set or not. - * - * @param hasCredentials to set. - */ - public void setHasCredentials(final boolean hasCredentials) { - this.hasCredentials = hasCredentials; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/jaxb/StorageProvidersJaxb.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/jaxb/StorageProvidersJaxb.java deleted file mode 100644 index fdf561b5f..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/storageproviders/jaxb/StorageProvidersJaxb.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.opentosca.container.api.legacy.resources.storageproviders.jaxb; - -import java.util.Set; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -import org.opentosca.container.api.legacy.resources.storageproviders.AvailableStorageProvidersResource; - -/** - * JAXB annotated class that represents a set of storage providers.
- * It will be created by {@link JaxbFactory} and used in - * {@link AvailableStorageProvidersResource}.
- *
- * Copyright 2013 IAAS University of Stuttgart
- *
- * - * @author Rene Trefft - rene.trefft@developers.opentosca.org - * - */ -@XmlRootElement(name = "StorageProviders") -@XmlAccessorType(XmlAccessType.FIELD) -public class StorageProvidersJaxb { - - @XmlElement(name = "StorageProvider") - private Set storageProviders; - - - /** - * @return Storage providers. - */ - public Set getStorageProviders() { - return this.storageProviders; - } - - /** - * Sets the storage providers. - * - * @param storageProviders to set. - */ - public void setStorageProvider(final Set storageProviders) { - this.storageProviders = storageProviders; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/JSONUtils.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/JSONUtils.java deleted file mode 100644 index 4e3babe2b..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/JSONUtils.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.opentosca.container.api.legacy.resources.utilities; - -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; - -public class JSONUtils { - - - public static String withoutQuotationMarks(final String str) { - return str.substring(1, str.length() - 1); - } - - public JsonObject xmlToGenericJsonObject(final NodeList nodes) { - final JsonObject ret = new JsonObject(); - ret.add("payload", xmlToJsonArray(nodes)); - return ret; - } - - public JsonArray xmlToJsonArray(final NodeList nodes) { - final JsonArray array = new JsonArray(); - - for (int itr = 0; itr < nodes.getLength(); itr++) { - - final Node node = nodes.item(itr); - if (node.getNodeName().equalsIgnoreCase("#text")) {// || - // node.getNodeName().equalsIgnoreCase("PropertyMappings")) - // { - break; - } - - final JsonObject nodeJson = new JsonObject(); - array.add(nodeJson); - - // content of node - final JsonObject nodeContent = new JsonObject(); - nodeJson.add(node.getNodeName(), nodeContent); - - // attribute content - if (null != node.getAttributes()) { - final JsonArray attributes = new JsonArray(); - nodeContent.add("Attributes", attributes); - for (int attrItr = 0; attrItr < node.getAttributes().getLength(); attrItr++) { - - final Node attr = node.getAttributes().item(attrItr); - if (attr.getNodeName().startsWith("xmlns")) { - break; - } - - final JsonObject attrJson = new JsonObject(); - attrJson.addProperty(attr.getNodeName(), attr.getTextContent()); - attributes.add(attrJson); - } - - // try { - // if (node.getNodeName().equalsIgnoreCase("PropertyMapping")) { - // LOG.debug("adding the xml attribute \"targetObjectRef\" of - // element {}", node.getNodeName()); - // XPathFactory factory = XPathFactory.newInstance(); - // XPath xpath = factory.newXPath(); - // Node refObject = (Node) - // xpath.evaluate("/PropertyMapping/@targetObjectRef", node, - // XPathConstants.NODE); - // LOG.debug(ToscaServiceHandler.getIXMLSerializer().docToString(node, - // true) + "\n " + (String) - // xpath.evaluate("/PropertyMapping/@targetObjectRef", node, - // XPathConstants.STRING)); - // LOG.debug(refObject.getNodeName() + ": " + - // refObject.getTextContent()); - // } - // } catch (XPathExpressionException e) { - // e.printStackTrace(); - // } - } - - // child element content - final JsonArray children = new JsonArray(); - nodeContent.add("Children", children); - children.addAll(xmlToJsonArray(node.getChildNodes())); - - // text value content - nodeContent.addProperty("TextContent", node.getTextContent()); - } - - return array; - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/ModelUtils.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/ModelUtils.java deleted file mode 100644 index 2ede9baf2..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/ModelUtils.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.opentosca.container.api.legacy.resources.utilities; - -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.namespace.QName; - -import org.opentosca.container.api.legacy.osgi.servicegetter.FileRepositoryServiceHandler; -import org.opentosca.container.api.legacy.osgi.servicegetter.ToscaServiceHandler; -import org.opentosca.container.core.common.SystemException; -import org.opentosca.container.core.common.UserException; -import org.opentosca.container.core.model.csar.CSARContent; -import org.opentosca.container.core.model.csar.id.CSARID; -import org.opentosca.container.core.service.ICoreFileService; -import org.opentosca.container.core.tosca.extension.PlanTypes; -import org.opentosca.container.core.tosca.model.Definitions; -import org.opentosca.container.core.tosca.model.TExtensibleElements; -import org.opentosca.container.core.tosca.model.TPlan; -import org.opentosca.container.core.tosca.model.TServiceTemplate; - -public class ModelUtils { - - public static QName getEntryServiceTemplate(final CSARID csarId) throws UserException, SystemException { - final ICoreFileService fileService = FileRepositoryServiceHandler.getFileHandler(); - final CSARContent content = fileService.getCSAR(csarId); - final Definitions def = - ToscaServiceHandler.getIXMLSerializer().unmarshal(content.getRootTOSCA().getFileAsInputStream()); - for (final TExtensibleElements el : def.getServiceTemplateOrNodeTypeOrNodeTypeImplementation()) { - if (el instanceof TServiceTemplate) { - final TServiceTemplate st = (TServiceTemplate) el; - return new QName(st.getTargetNamespace(), st.getId()); - - } - } - return null; - } - - public static boolean hasBuildPlan(final CSARID csarId) throws UserException, SystemException { - final Map> plans = - ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper().getCSARIDToPlans(csarId); - - if (plans == null) { - return false; - } - - return plans.containsKey(PlanTypes.BUILD) & !plans.get(PlanTypes.BUILD).isEmpty() ? true : false; - } - - public static boolean hasOpenRequirements(final CSARID csarId) throws UserException, SystemException { - final QName serviceTemplateId = ModelUtils.getEntryServiceTemplate(csarId); - - final List nodeTemplateIds = - ToscaServiceHandler.getToscaEngineService().getNodeTemplatesOfServiceTemplate(csarId, serviceTemplateId); - final List relationshipTemplateIds = - ToscaServiceHandler.getToscaEngineService().getRelationshipTemplatesOfServiceTemplate(csarId, - serviceTemplateId); - - for (final String nodeTemplateId : nodeTemplateIds) { - final List nodeReqs = - ToscaServiceHandler.getToscaEngineService().getNodeTemplateRequirements(csarId, serviceTemplateId, - nodeTemplateId); - int foundRelations = 0; - - for (final String relationshipTemplateId : relationshipTemplateIds) { - final QName relationReq = - ToscaServiceHandler.getToscaEngineService().getRelationshipTemplateSource(csarId, serviceTemplateId, - relationshipTemplateId); - if (relationReq.getLocalPart().equals(nodeTemplateId)) { - foundRelations++; - } - } - - if (foundRelations < nodeReqs.size()) { - return true; - } - - } - return false; - } - - public static boolean hasTerminationPlan(final CSARID csarId) throws UserException, SystemException { - final Map> plans = - ToscaServiceHandler.getToscaEngineService().getToscaReferenceMapper().getCSARIDToPlans(csarId); - - if (plans == null) { - return false; - } - - return plans.containsKey(PlanTypes.TERMINATION) & !plans.get(PlanTypes.TERMINATION).isEmpty() ? true : false; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/ResourceConstants.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/ResourceConstants.java deleted file mode 100644 index 35bc1d1b4..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/ResourceConstants.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.opentosca.container.api.legacy.resources.utilities; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import javax.ws.rs.core.MediaType; - -/** - * Class to Hold all Constants of MediaTypes
- *
- * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer - fischema@studi.informatik.uni-stuttgart.de - * - */ -public final class ResourceConstants { - - public static final String TEXT_PLAIN = MediaType.TEXT_PLAIN; - public static final String LINKED_XML = MediaType.TEXT_XML; - public static final String LINKED_JSON = MediaType.APPLICATION_JSON; - public static final String TOSCA_XML = MediaType.APPLICATION_XML; - public static final String TOSCA_JSON = MediaType.APPLICATION_JSON; - public static final String APPLICATION_JSON = MediaType.APPLICATION_JSON; - public static final String OCTET_STREAM = MediaType.APPLICATION_OCTET_STREAM; - public static final String IMAGE = "image/*"; - - // File extensions and corresponding media type - public static final Map imageMediaTypes; - static { - final Map tmp = new HashMap<>(); - // http://www.iana.org/assignments/media-types/image - tmp.put("png", "image/png"); - tmp.put("jpg", "image/jpeg"); - tmp.put("jpeg", "image/jpeg"); - tmp.put("gif", "image/gif"); - imageMediaTypes = Collections.unmodifiableMap(tmp); - } - - - public static final String ROOT = "/containerapi"; - - public static final String NOT_IMPLEMENTED = - ""; - public static final String NOT_FOUND = - ""; - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/TemplateResourceUtilities.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/TemplateResourceUtilities.java deleted file mode 100644 index e2091c669..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/TemplateResourceUtilities.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.opentosca.container.api.legacy.resources.utilities; - - -/** - * Provides functionality concerning the "template-business"
- *
- * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer - fischema@studi.informatik.uni-stuttgart.de - * @author Rene Trefft - trefftre@studi.informatik.uni-stuttgart.de - * - */ -public class TemplateResourceUtilities { - - // /** - // * Compares the id with the ids of the children. Then creates an - // appropriate - // * AbstractToscaResourceObject.
- // * - // * This method is needed due to the fact. That the class of the children - // of - // * a TopologyTemplate or GroupTemplate are not known by default.
- // * - // * @param children List list of elements to compare - // to - // * the id - // * @param id String the id to compare the elements to - // * @param uriInfo - // * @return AbstractToscaResource - // */ - // public static AbstractToscaResource - // getTemplateChildResource(List children, String id, - // UriInfo uriInfo) { - // for (TExtensibleElements child : children) { - // if (child instanceof TNodeTemplate) { - // TNodeTemplate nt = (TNodeTemplate) child; - // if (nt.getId().equals(id)) { - // return new NodeTemplateResource(uriInfo, nt); - // } - // } - // - // if (child instanceof TRelationshipTemplate) { - // TRelationshipTemplate rt = (TRelationshipTemplate) child; - // if (rt.getId().equals(id)) { - // return new RelationshipTemplateResource(uriInfo, rt); - // } - // } - // - // // if (child instanceof TGroupTemplate) { - // // TGroupTemplate gt = (TGroupTemplate) child; - // // if (gt.getId().equals(id)) { - // // return new GroupTemplateResource(uriInfo, gt); - // // } - // // } - // } - // return null; - // } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/Utilities.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/Utilities.java deleted file mode 100644 index de53abcd9..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/Utilities.java +++ /dev/null @@ -1,186 +0,0 @@ -package org.opentosca.container.api.legacy.resources.utilities; - -import java.io.File; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URLDecoder; -import java.net.URLEncoder; -import java.util.List; - -import javax.ws.rs.core.PathSegment; -import javax.ws.rs.core.UriBuilder; -import javax.ws.rs.core.UriInfo; -import javax.ws.rs.ext.RuntimeDelegate; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.glassfish.jersey.uri.UriComponent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.xml.sax.SAXException; - -/** - * Utilities. Provides static methods for the ContainerApi
- * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer - fischema@studi.informatik.uni-stuttgart.de - * - */ -public class Utilities { - - private static final Logger LOG = LoggerFactory.getLogger(Utilities.class); - - - public static URI encode(final URI uri) { - final List pathSegments = UriComponent.decodePath(uri, false); - final UriBuilder uriBuilder = RuntimeDelegate.getInstance().createUriBuilder(); - // Build base URL - uriBuilder.scheme(uri.getScheme()).host(uri.getHost()).port(uri.getPort()); - // Interate over path segments and encode it if necessary - for (final PathSegment ps : pathSegments) { - uriBuilder.path(UriComponent.encode(ps.toString(), UriComponent.Type.PATH_SEGMENT)); - } - LOG.debug("URL before encoding: {}", uri); - LOG.debug("URL after encoding: {}", uriBuilder); - return URI.create(uriBuilder.toString()); - } - - /** - * Encodes URI path according to RFC 2396. This means e.g space will be encoded to "%20" and not - * "+". - * - * @param path to encode - * @return Encoded URI path. - */ - public static String encodeURIPath(final String path) { - try { - - return new URI(null, null, path, null).toString(); - - } - catch (final URISyntaxException e) { - Utilities.LOG.warn("Can't encode URI path \"{}\".", path, e); - } - - return null; - } - - public static String buildURI(final UriInfo uriInfo, final String path) { - - final UriBuilder builder = uriInfo.getBaseUriBuilder(); - final List pathSegments = uriInfo.getPathSegments(false); - - // Interate over path segments and encode it if necessary - for (final PathSegment ps : pathSegments) { - final String pathEncoded = URLencode(ps.toString()); - LOG.debug("Encoding path segment <{}> to <{}>", ps, pathEncoded); - builder.path(pathEncoded); - } - - final URI url = builder.path(URLencode(path)).build(); - - LOG.debug("Final URL: {}", url); - return url.toString(); - } - - /** - * Builds an URI - * - * @param base baseURI as String - * @param path path to extend the URI - * @return - */ - public static String buildURI(final String base, final String path) { - - LOG.debug("Create URL; base=<{}>, path=<{}>", base, path); - - final UriBuilder builder = UriBuilder.fromUri(base); - - // separately encode URI path first, because builder.path(...) later - // prevents double-encoding (we want double-encoding if given path is - // already encoded) - final String pathEncoded = Utilities.encodeURIPath(path); - - builder.path(pathEncoded); - final URI uri = builder.build(); - Utilities.LOG.debug("URI built: {}", uri); - - try { - LOG.debug("URL: {}", uri.toURL()); - } - catch (final MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - LOG.debug("Encoded URL: {}", URLencode(uri.toString())); - - return uri.toString(); - - } - - public static String URLencode(final String s) { - try { - return URLEncoder.encode(s, "UTF-8"); - } - catch (final UnsupportedEncodingException e) { - throw new IllegalStateException(); - } - } - - public static String UrlDoubleEncode(final String s) { - return URLencode(URLencode(s)); - } - - public static String URLdecode(final String s) { - try { - return URLDecoder.decode(s, "UTF-8"); - } - catch (final UnsupportedEncodingException e) { - throw new IllegalStateException(); - } - } - - public static boolean areNotNull(final Object... objs) { - for (final Object obj : objs) { - if (obj == null) { - return false; - } - } - return true; - } - - /** - * This method checks all given string if they are null or empty and returns yes if at - * least one String is null or empty - * - * This method is perfectly fitted for checking all required parameters of a request at once (jersey - * doesn't support @required for parameters) - * - * @param strings - * @return false - if all given Strings are initialized and not "" true - if at least - * one given string is NULL or empty - */ - public static boolean areEmpty(final String... strings) { - for (final String string : strings) { - if (string == null || string.isEmpty()) { - return true; - } - } - return false; - - } - - public static Document fileToDom(final File file) throws ParserConfigurationException, SAXException, IOException { - final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); - final Document doc = dBuilder.parse(file); - return doc; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/package-info.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/package-info.java deleted file mode 100644 index 529224c93..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/utilities/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.opentosca.container.api.legacy.resources.utilities; - -/** - * This package contains Utilities and Constants - */ diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/xlink/Reference.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/xlink/Reference.java deleted file mode 100644 index a85b01c9c..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/xlink/Reference.java +++ /dev/null @@ -1,124 +0,0 @@ -package org.opentosca.container.api.legacy.resources.xlink; - -import com.google.gson.JsonObject; - -/** - * Provides xml for XLink-References.
- * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer - fischema@studi.informatik.uni-stuttgart.de - * @author Christian Endres - christian.endres@iaas.uni-stuttgart.de - */ -public class Reference { - - - private String absPath = null; - private String xtype = null; - private String xhref = null; - private String xtitle = null; - - - public Reference() {} - - public Reference(final String xhref, final String xtype, final String xtitle) { - setXhref(xhref); - setXtitle(xtitle); - setXtype(xtype); - } - - public Reference(final String xhref, final String xtype, final String xtitle, final String absPath) { - setXhref(xhref); - setXtitle(xtitle); - setXtype(xtype); - setAbsPath(absPath); - } - - /** - * @return the absPath - */ - public String getAbsPath() { - return this.absPath; - } - - /** - * @param absPath the absPath to set - */ - public void setAbsPath(final String absPath) { - this.absPath = absPath; - } - - public String getXtype() { - if (this.xtype == null) { - return ""; - } - return this.xtype; - } - - public void setXtype(final String type) { - this.xtype = type; - } - - public String getXhref() { - if (this.xhref == null) { - return ""; - } - return this.xhref; - } - - public void setXhref(final String xhref) { - this.xhref = xhref; - } - - public String getXtitle() { - if (this.xtitle == null) { - return ""; - } - return this.xtitle; - } - - public void setXtitle(final String xtitle) { - this.xtitle = xtitle; - } - - public String toXml() { - final StringBuilder xml = new StringBuilder(""); - xml.append("<"); - xml.append(XLinkConstants.REFERENCE); - xml.append(" "); - - if (getAbsPath() != null) { - xml.append(XLinkConstants.ABSPATH); - xml.append("=\""); - xml.append(getAbsPath()); - xml.append("\" "); - } - - xml.append(XLinkConstants.XTYPE); - xml.append("=\""); - xml.append(getXtype()); - xml.append("\" "); - xml.append(XLinkConstants.XHREF); - xml.append("=\""); - xml.append(getXhref()); - xml.append("\" "); - xml.append(XLinkConstants.XTITLE); - xml.append("=\""); - xml.append(getXtitle()); - xml.append("\" "); - xml.append("/>"); - return xml.toString(); - - } - - public JsonObject toJson() { - - final JsonObject ref = new JsonObject(); - ref.addProperty("type", getXtype()); - ref.addProperty("href", getXhref()); - ref.addProperty("title", getXtitle()); - - return ref; - } - -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/xlink/References.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/xlink/References.java deleted file mode 100644 index 3bb32a919..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/xlink/References.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.opentosca.container.api.legacy.resources.xlink; - -import java.util.ArrayList; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; - - -/** - * Holds a list 'List' and provides XML-representation.
- * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer - fischema@studi.informatik.uni-stuttgart.de - * @author Christian Endres - christian.endres@iaas.uni-stuttgart.de - * - */ -public class References { - - - private static final Logger LOG = LoggerFactory.getLogger(References.class); - - protected List reference; - - - public References() {} - - public List getReference() { - if (this.reference == null) { - this.reference = new ArrayList<>(); - } - return this.reference; - } - - public String getXMLString() { - - final StringBuilder xml = new StringBuilder(""); - xml.append(""); - - for (final Reference ref : getReference()) { - xml.append(ref.toXml()); - } - - xml.append(""); - - return xml.toString(); - } - - private JsonObject getJSON() { - - final JsonObject json = new JsonObject(); - final JsonArray refs = new JsonArray(); - - for (final Reference ref : getReference()) { - refs.add(ref.toJson()); - } - json.add("References", refs); - - return json; - - } - - public String getJSONString() { - - final JsonObject json = getJSON(); - LOG.trace(json.toString()); - - return json.toString(); - } -} diff --git a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/xlink/XLinkConstants.java b/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/xlink/XLinkConstants.java deleted file mode 100644 index 318ac0ad9..000000000 --- a/org.opentosca.container.api.legacy/src/org/opentosca/container/api/legacy/resources/xlink/XLinkConstants.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.opentosca.container.api.legacy.resources.xlink; - -/** - * Provides constant strings
- * Copyright 2012 IAAS University of Stuttgart
- *
- * - * @author Markus Fischer fischema@studi.informatik.uni-stuttgart.de - * @author Rene Trefft - trefftre@studi.informatik.uni-stuttgart.de - */ -public class XLinkConstants { - - public static final String SELF = "Self"; - - public static final String REFERENCES = "References"; - public static final String REFERENCE = "Reference"; - public static final String XMLNS = "xmlns:xlink"; - public static final String XLINK_NAMESPACE = "http://www.w3.org/1999/xlink"; - public static final String XTYPE = "xlink:type"; - public static final String XHREF = "xlink:href"; - public static final String XTITLE = "xlink:title"; - - public static final String SIMPLE = "simple"; - - public static final String ABSPATH = "absPath"; -} diff --git a/org.opentosca.container.feature/feature.xml b/org.opentosca.container.feature/feature.xml index c5d60a8d2..46f500f33 100644 --- a/org.opentosca.container.feature/feature.xml +++ b/org.opentosca.container.feature/feature.xml @@ -803,13 +803,6 @@ version="0.0.0" unpack="false"/> - - - diff --git a/pom.xml b/pom.xml index f843a5717..f14d263a6 100644 --- a/pom.xml +++ b/pom.xml @@ -145,7 +145,6 @@ org.opentosca.bus.application.plugin.service org.opentosca.bus.application.service org.opentosca.bus.application.service.impl - org.opentosca.container.api.legacy org.opentosca.container.api org.opentosca.planbuilder org.opentosca.planbuilder.core.bpel