Search in sources :

Example 1 with Splitting

use of org.eclipse.winery.repository.splitting.Splitting in project winery by eclipse.

the class ServiceTemplateResource method injectNodeTemplates.

@POST
@Path("injector/replace")
@Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
public Response injectNodeTemplates(InjectorReplaceData injectorReplaceData, @Context UriInfo uriInfo) throws Exception, IOException, ParserConfigurationException, SAXException, SplittingException {
    if (injectorReplaceData.hostInjections != null) {
        Collection<TTopologyTemplate> hostInjectorTopologyTemplates = injectorReplaceData.hostInjections.values();
        hostInjectorTopologyTemplates.forEach(t -> {
            try {
                ModelUtilities.patchAnyAttributes(t.getNodeTemplates());
            } catch (IOException e) {
                LOGGER.error("XML was invalid", e);
            }
        });
    }
    if (injectorReplaceData.connectionInjections != null) {
        Collection<TTopologyTemplate> connectionInjectorTopologyTemplates = injectorReplaceData.connectionInjections.values();
        connectionInjectorTopologyTemplates.forEach(t -> {
            try {
                ModelUtilities.patchAnyAttributes(t.getNodeTemplates());
            } catch (IOException e) {
                LOGGER.error("XML was invalid", e);
            }
        });
    }
    Splitting splitting = new Splitting();
    TTopologyTemplate matchedHostsTopologyTemplate;
    TTopologyTemplate matchedConnectedTopologyTemplate;
    // Test Method findOpenRequirements
    Map<TRequirement, String> requirementsAndMatchingBasisCapabilityTypes = splitting.getOpenRequirementsAndMatchingBasisCapabilityTypeNames(this.getServiceTemplate().getTopologyTemplate());
    // Output check
    for (TRequirement req : requirementsAndMatchingBasisCapabilityTypes.keySet()) {
        System.out.println("open Requirement: " + req.getId());
        System.out.println("matchingbasisType: " + requirementsAndMatchingBasisCapabilityTypes.get(req));
    }
    if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Container")) {
        matchedHostsTopologyTemplate = splitting.injectNodeTemplates(this.getServiceTemplate().getTopologyTemplate(), injectorReplaceData.hostInjections);
        if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) {
            matchedConnectedTopologyTemplate = splitting.injectConnectionNodeTemplates(matchedHostsTopologyTemplate, injectorReplaceData.connectionInjections);
        } else {
            matchedConnectedTopologyTemplate = matchedHostsTopologyTemplate;
        }
    } else if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) {
        matchedConnectedTopologyTemplate = splitting.injectConnectionNodeTemplates(this.getServiceTemplate().getTopologyTemplate(), injectorReplaceData.connectionInjections);
    } else {
        throw new SplittingException("No open Requirements which can be matched");
    }
    TTopologyTemplate daSpecifiedTopology = matchedConnectedTopologyTemplate;
    // Start additional functionality Driver Injection
    if (!DASpecification.getNodeTemplatesWithAbstractDAs(matchedConnectedTopologyTemplate).isEmpty() && DASpecification.getNodeTemplatesWithAbstractDAs(matchedConnectedTopologyTemplate) != null) {
        daSpecifiedTopology = DriverInjection.injectDriver(matchedConnectedTopologyTemplate);
    }
    // End additional functionality Driver Injection
    this.getServiceTemplate().setTopologyTemplate(daSpecifiedTopology);
    LOGGER.debug("Persisting...");
    RestUtils.persist(this);
    LOGGER.debug("Persisted.");
    // No renaming of the Service Template allowed because of the plans
    URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(id));
    LOGGER.debug("URI of the old and new service template {}", url.toString());
    return Response.created(url).build();
}
Also used : Splitting(org.eclipse.winery.repository.splitting.Splitting) TRequirement(org.eclipse.winery.model.tosca.TRequirement) SplittingException(org.eclipse.winery.repository.splitting.SplittingException) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) IOException(java.io.IOException) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 2 with Splitting

use of org.eclipse.winery.repository.splitting.Splitting in project winery by eclipse.

the class ServiceTemplateResource method getInjectorOptions.

@GET
@Path("injector/options")
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
public Response getInjectorOptions() {
    Splitting splitting = new Splitting();
    TTopologyTemplate topologyTemplate = this.getServiceTemplate().getTopologyTemplate();
    Map<String, List<TTopologyTemplate>> hostMatchingOptions;
    Map<String, List<TTopologyTemplate>> connectionMatchingOptions;
    InjectorReplaceOptions injectionReplaceOptions = new InjectorReplaceOptions();
    try {
        Map<TRequirement, String> requirementsAndMatchingBasisCapabilityTypes = splitting.getOpenRequirementsAndMatchingBasisCapabilityTypeNames(this.getServiceTemplate().getTopologyTemplate());
        // Output check
        for (TRequirement req : requirementsAndMatchingBasisCapabilityTypes.keySet()) {
            System.out.println("open Requirement: " + req.getId());
            System.out.println("matchingBasisType: " + requirementsAndMatchingBasisCapabilityTypes.get(req));
        }
        if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Container")) {
            hostMatchingOptions = splitting.getHostingMatchingOptionsWithDefaultLabeling(topologyTemplate);
        } else {
            hostMatchingOptions = null;
        }
        if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) {
            connectionMatchingOptions = splitting.getConnectionInjectionOptions(topologyTemplate);
        } else {
            connectionMatchingOptions = null;
        }
        injectionReplaceOptions.setTopologyTemplate(topologyTemplate);
        injectionReplaceOptions.setHostInjectionOptions(hostMatchingOptions);
        injectionReplaceOptions.setConnectionInjectionOptions(connectionMatchingOptions);
        if (hostMatchingOptions == null && connectionMatchingOptions == null) {
            return Response.status(Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN).entity("No need for matching").build();
        }
    } catch (SplittingException e) {
        LOGGER.error("Could not match", e);
        return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
    }
    return Response.ok().entity(injectionReplaceOptions).build();
}
Also used : InjectorReplaceOptions(org.eclipse.winery.repository.rest.resources._support.dataadapter.injectionadapter.InjectorReplaceOptions) Splitting(org.eclipse.winery.repository.splitting.Splitting) TRequirement(org.eclipse.winery.model.tosca.TRequirement) SplittingException(org.eclipse.winery.repository.splitting.SplittingException) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) List(java.util.List) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with Splitting

use of org.eclipse.winery.repository.splitting.Splitting in project winery by eclipse.

the class TopologyTemplateResource method match.

@Path("match/")
@Produces(MediaType.TEXT_PLAIN)
@POST
public Response match(@Context UriInfo uriInfo) {
    Splitting splitting = new Splitting();
    ServiceTemplateId matchedServiceTemplateId;
    try {
        matchedServiceTemplateId = splitting.matchTopologyOfServiceTemplate((ServiceTemplateId) this.serviceTemplateRes.getId());
    } catch (Exception e) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Could not match. " + e.getMessage()).build();
    }
    URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(matchedServiceTemplateId));
    return Response.created(url).build();
}
Also used : Splitting(org.eclipse.winery.repository.splitting.Splitting) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) URI(java.net.URI) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) POST(javax.ws.rs.POST)

Example 4 with Splitting

use of org.eclipse.winery.repository.splitting.Splitting in project winery by eclipse.

the class TopologyTemplateResource method split.

@Path("split/")
@Produces(MediaType.TEXT_PLAIN)
@POST
public Response split(@Context UriInfo uriInfo) {
    Splitting splitting = new Splitting();
    ServiceTemplateId splitServiceTemplateId;
    try {
        splitServiceTemplateId = splitting.splitTopologyOfServiceTemplate((ServiceTemplateId) this.serviceTemplateRes.getId());
    } catch (Exception e) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Could not split. " + e.getMessage()).build();
    }
    URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(splitServiceTemplateId));
    return Response.created(url).build();
}
Also used : Splitting(org.eclipse.winery.repository.splitting.Splitting) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) URI(java.net.URI) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) POST(javax.ws.rs.POST)

Example 5 with Splitting

use of org.eclipse.winery.repository.splitting.Splitting in project winery by eclipse.

the class TopologyTemplateResource method composeServiceTemplates.

@POST
@Path("compose/")
@Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
public Response composeServiceTemplates(CompositionData compositionData, @Context UriInfo uriInfo) {
    Splitting splitting = new Splitting();
    String newComposedSolutionServiceTemplateId = compositionData.getTargetid();
    List<ServiceTemplateId> compositionServiceTemplateIDs = new ArrayList<>();
    compositionData.getCspath().stream().forEach(entry -> {
        QName qName = QName.valueOf(entry);
        compositionServiceTemplateIDs.add(new ServiceTemplateId(qName.getNamespaceURI(), qName.getLocalPart(), false));
    });
    ServiceTemplateId composedServiceTemplateId;
    try {
        composedServiceTemplateId = splitting.composeServiceTemplates(newComposedSolutionServiceTemplateId, compositionServiceTemplateIDs);
    } catch (Exception e) {
        e.printStackTrace();
        return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
    }
    Response mergeResponse = this.mergeWithOtherTopologyTemplate(composedServiceTemplateId.getQName().toString());
    if (mergeResponse.getStatus() == 500) {
        return mergeResponse;
    }
    URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(serviceTemplateRes.getId()));
    String location = url.toString();
    location = location + "topologytemplate?edit";
    url = RestUtils.createURI(location);
    LOGGER.debug("URI of the composed Service Template {}", url.toString());
    return Response.created(url).build();
}
Also used : Response(javax.ws.rs.core.Response) Splitting(org.eclipse.winery.repository.splitting.Splitting) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) URI(java.net.URI) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 Splitting (org.eclipse.winery.repository.splitting.Splitting)5 IOException (java.io.IOException)4 URI (java.net.URI)4 POST (javax.ws.rs.POST)4 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)3 Consumes (javax.ws.rs.Consumes)2 TRequirement (org.eclipse.winery.model.tosca.TRequirement)2 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)2 SplittingException (org.eclipse.winery.repository.splitting.SplittingException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 Response (javax.ws.rs.core.Response)1 QName (javax.xml.namespace.QName)1 InjectorReplaceOptions (org.eclipse.winery.repository.rest.resources._support.dataadapter.injectionadapter.InjectorReplaceOptions)1