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();
}
}
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();
}
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);
}
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)));
}
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));
}
Aggregations