Search in sources :

Example 1 with SplittingException

use of org.eclipse.winery.repository.splitting.SplittingException 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 SplittingException

use of org.eclipse.winery.repository.splitting.SplittingException 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)

Aggregations

Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 TRequirement (org.eclipse.winery.model.tosca.TRequirement)2 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)2 Splitting (org.eclipse.winery.repository.splitting.Splitting)2 SplittingException (org.eclipse.winery.repository.splitting.SplittingException)2 IOException (java.io.IOException)1 URI (java.net.URI)1 List (java.util.List)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 InjectorReplaceOptions (org.eclipse.winery.repository.rest.resources._support.dataadapter.injectionadapter.InjectorReplaceOptions)1