Search in sources :

Example 71 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class TopologyTemplateResource method allocate.

@Path("allocate")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@POST
public Response allocate(@Context UriInfo uriInfo, AllocationRequest allocationRequest) {
    try {
        Allocation allocation = new Allocation(allocationRequest);
        List<ServiceTemplateId> allocatedIds = allocation.allocate((ServiceTemplateId) this.parent.getId());
        List<URI> urls = new ArrayList<>();
        for (ServiceTemplateId id : allocatedIds) {
            urls.add(uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(id)));
        }
        return Response.ok(urls, MediaType.APPLICATION_JSON).build();
    } catch (Exception e) {
        LOGGER.debug("Error allocating", e);
        return Response.serverError().entity(e.getMessage()).build();
    }
}
Also used : Allocation(org.eclipse.winery.repository.targetallocation.Allocation) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) URI(java.net.URI) InvalidParameterException(java.security.InvalidParameterException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) POST(javax.ws.rs.POST)

Example 72 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId 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().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(parent.getId()));
    String location = url.toString();
    location = location + "topologytemplate?edit";
    url = URI.create(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.model.ids.definitions.ServiceTemplateId) URI(java.net.URI) InvalidParameterException(java.security.InvalidParameterException) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 73 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class ServiceTemplateResourceTest method createInstance.

@Test
public void createInstance() throws Exception {
    this.setRevisionTo("8cf0ce80c2c40c6ec178ef8e5bdc4e2fcdecc7f9");
    ServiceTemplateId id = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates/fruits", "farm", false);
    ServiceTemplateResource serviceTemplateResource = new ServiceTemplateResource(id);
    assertNotNull(serviceTemplateResource);
}
Also used : ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test) AbstractResourceTest(org.eclipse.winery.repository.rest.resources.AbstractResourceTest)

Example 74 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class PatternDetectionTestWithGitBackedRepository method detectPatterns.

@Test
public void detectPatterns() throws Exception {
    this.setRevisionTo("origin/plain");
    ServiceTemplateId testTemplateId = new ServiceTemplateId("http://www.example.org/tosca/servicetemplates", "PatternDetectionTest_w1-wip1", false);
    PatternDetection detection = new PatternDetection(new DefaultRefinementChooser());
    ServiceTemplateId serviceTemplateId = detection.refineServiceTemplate(testTemplateId);
    TTopologyTemplate topology = RepositoryFactory.getRepository().getElement(serviceTemplateId).getTopologyTemplate();
    assertNotNull(topology);
    QName java = QName.valueOf("{http://winery.opentosca.org/test/nodetypes}Java_8-Servelet-w1");
    QName firstPattern = QName.valueOf("{http://plain.winery.opentosca.org/patterns}FirstPattern_w1");
    QName secondPattern = QName.valueOf("{http://plain.winery.opentosca.org/patterns}SecondPattern_w1");
    QName thirdPattern = QName.valueOf("{http://plain.winery.opentosca.org/patterns}ThirdPattern_w1");
    QName secureSql = QName.valueOf("{http://www.example.org/tosca/relationshiptypes}Secure-SQL-Con_w1-wip1");
    QName hostedOn = QName.valueOf("{http://winery.opentosca.org/test/relationshiptypes}hostedOn");
    List<TNodeTemplate> nodeTemplates = topology.getNodeTemplates();
    assertEquals(nodeTemplates.size(), 4);
    Set<QName> nodeTypes = nodeTemplates.stream().map(TNodeTemplate::getType).collect(Collectors.toSet());
    assertEquals(nodeTypes.size(), 4);
    assertTrue(nodeTypes.contains(java));
    assertTrue(nodeTypes.contains(firstPattern));
    assertTrue(nodeTypes.contains(secondPattern));
    assertTrue(nodeTypes.contains(thirdPattern));
    List<TRelationshipTemplate> relationshipTemplates = topology.getRelationshipTemplates();
    assertEquals(relationshipTemplates.size(), 4);
    assertTrue(relationshipTemplates.stream().anyMatch(rt -> rt.getType().equals(secureSql) && rt.getSourceElement().getRef().getType().equals(java) && rt.getTargetElement().getRef().getType().equals(secondPattern)));
    assertTrue(relationshipTemplates.stream().anyMatch(rt -> rt.getType().equals(hostedOn) && rt.getSourceElement().getRef().getType().equals(java) && rt.getTargetElement().getRef().getType().equals(firstPattern)));
    assertTrue(relationshipTemplates.stream().anyMatch(rt -> rt.getType().equals(hostedOn) && rt.getSourceElement().getRef().getType().equals(firstPattern) && rt.getTargetElement().getRef().getType().equals(thirdPattern)));
    assertTrue(relationshipTemplates.stream().anyMatch(rt -> rt.getType().equals(hostedOn) && rt.getSourceElement().getRef().getType().equals(secondPattern) && rt.getTargetElement().getRef().getType().equals(thirdPattern)));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) DefaultRefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Set(java.util.Set) Collectors(java.util.stream.Collectors) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) Test(org.junit.jupiter.api.Test) List(java.util.List) TestWithGitBackedRepository(org.eclipse.winery.repository.TestWithGitBackedRepository) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) QName(javax.xml.namespace.QName) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DefaultRefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser) QName(javax.xml.namespace.QName) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test)

Example 75 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class InstanceModelRefinementTest method refineApplication.

@Test
void refineApplication() throws Exception {
    this.setRevisionTo("origin/plain");
    TNodeTemplate mySpecialNode = new TNodeTemplate.Builder("mySpecialNode", OpenToscaBaseTypes.OperatingSystem).build();
    InstanceModelRefinement modelRefinement = new InstanceModelRefinement((template, plugins) -> template.getNodeTemplate("mySpecialNode") != null ? null : new InstanceModelRefinementPlugin("noop") {

        @Override
        public Set<String> apply(TTopologyTemplate template) {
            template.addNodeTemplate(mySpecialNode);
            Set<String> discoveredNodeIds = new HashSet<>();
            discoveredNodeIds.add(mySpecialNode.getId());
            return discoveredNodeIds;
        }

        @Override
        public Set<String> determineAdditionalInputs(TTopologyTemplate template, ArrayList<String> nodeIdsToBeReplaced) {
            return null;
        }

        @Override
        protected List<TTopologyTemplate> getDetectorGraphs() {
            return null;
        }
    });
    TTopologyTemplate topologyTemplate = modelRefinement.refine(new ServiceTemplateId("http://opentosca.org/servicetemplates", "SshTest_w1-wip1", false));
    assertNotNull(topologyTemplate);
    assertEquals(2, topologyTemplate.getNodeTemplates().size());
    assertTrue(topologyTemplate.getNodeTemplates().remove(mySpecialNode));
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)126 Test (org.junit.jupiter.api.Test)73 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)44 ArrayList (java.util.ArrayList)41 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)40 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)35 QName (javax.xml.namespace.QName)25 IOException (java.io.IOException)24 IRepository (org.eclipse.winery.repository.backend.IRepository)19 List (java.util.List)17 POST (javax.ws.rs.POST)17 Path (javax.ws.rs.Path)16 Produces (javax.ws.rs.Produces)16 HashMap (java.util.HashMap)15 TopologyWrapper (org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)15 Map (java.util.Map)14 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)14 URI (java.net.URI)13 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)13 TNodeType (org.eclipse.winery.model.tosca.TNodeType)13