Search in sources :

Example 1 with InjectorReplaceOptions

use of org.eclipse.winery.repository.rest.resources._support.dataadapter.injectionadapter.InjectorReplaceOptions 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) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 TRequirement (org.eclipse.winery.model.tosca.TRequirement)1 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)1 InjectorReplaceOptions (org.eclipse.winery.repository.rest.resources._support.dataadapter.injectionadapter.InjectorReplaceOptions)1 Splitting (org.eclipse.winery.repository.splitting.Splitting)1 SplittingException (org.eclipse.winery.repository.splitting.SplittingException)1