use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class APIResource method getAllArtifactTemplatesOfContainedImplementationArtifacts.
/**
* Implementation similar to
* getAllArtifactTemplatesOfContainedDeploymentArtifacts. Only difference is
* "getArtifactTemplatesOfReferencedImplementationArtifacts" instead of
* "getArtifactTemplatesOfReferencedDeploymentArtifacts".
*/
@GET
@Path("getallartifacttemplatesofcontainedimplementationartifacts")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllArtifactTemplatesOfContainedImplementationArtifacts(@QueryParam("servicetemplate") String serviceTemplateQNameString, @QueryParam("nodetemplateid") String nodeTemplateId) {
if (StringUtils.isEmpty(serviceTemplateQNameString)) {
return Response.status(Status.BAD_REQUEST).entity("servicetemplate has be given as query parameter").build();
}
QName serviceTemplateQName = QName.valueOf(serviceTemplateQNameString);
ServiceTemplateId serviceTemplateId = new ServiceTemplateId(serviceTemplateQName);
final IRepository repository = RepositoryFactory.getRepository();
if (!repository.exists(serviceTemplateId)) {
return Response.status(Status.BAD_REQUEST).entity("service template does not exist").build();
}
ServiceTemplateResource serviceTemplateResource = new ServiceTemplateResource(serviceTemplateId);
Collection<QName> artifactTemplates = new ArrayList<>();
List<TNodeTemplate> allNestedNodeTemplates = BackendUtils.getAllNestedNodeTemplates(serviceTemplateResource.getServiceTemplate());
for (TNodeTemplate nodeTemplate : allNestedNodeTemplates) {
if (StringUtils.isEmpty(nodeTemplateId) || nodeTemplate.getId().equals(nodeTemplateId)) {
Collection<QName> ats = BackendUtils.getArtifactTemplatesOfReferencedImplementationArtifacts(nodeTemplate, repository);
artifactTemplates.addAll(ats);
}
}
// convert QName list to select2 data
Select2DataWithOptGroups res = new Select2DataWithOptGroups();
for (QName qName : artifactTemplates) {
res.add(qName.getNamespaceURI(), qName.toString(), qName.getLocalPart());
}
return Response.ok().entity(res.asSortedSet()).build();
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class AccountabilityResource method getModelHistory.
@GET
@Path("modelHistory")
@Produces(MediaType.APPLICATION_JSON)
public List<ModelProvenanceElement> getModelHistory() {
ServiceTemplateId serviceTemplateId = new ServiceTemplateId(new QName(provenanceId));
String qNameWithComponentVersionOnly = VersionSupport.getQNameWithComponentVersionOnly(serviceTemplateId);
try {
return getAccountabilityManager().getHistory(qNameWithComponentVersionOnly).exceptionally(error -> null).get();
} catch (InterruptedException | ExecutionException | AccountabilityException e) {
LOGGER.error("Cannot get history of model. Reason: {}", e.getMessage());
throw createException(e);
}
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class KargerMinCutVariationTest method twoTargetLabelsOnePossibleResult.
@Test
public void twoTargetLabelsOnePossibleResult() {
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "MinExternalConnectionsTest1", false);
TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
ConnectsToGraph connectsToGraph = new ConnectsToGraph(topology);
KargerMinCutVariation kargerMinCutVariation = new KargerMinCutVariation(connectsToGraph);
List<ConnectsToGraph> results = new ArrayList<>(kargerMinCutVariation.computeTargetLabelPartitions());
// testing a monte carlo algorithm doesn't always work
if (results.size() != 1 || results.get(0).getEdges().size() != 1) {
LOGGER.debug("Monte Carlo Algorithm produced wrong result");
return;
}
assertEquals(results.size(), 1);
ConnectsToGraph result = results.get(0);
assertEquals(result.getEdges().size(), 1);
assertEquals(result.getNodes().size(), 2);
Set<String> pastureProvider = new HashSet<>(Collections.singletonList("shetland_pony"));
Set<String> fieldProvider = new HashSet<>(Arrays.asList("shetland_pony_2", "shetland_pony_3", "shetland_pony_4"));
ConnectsToGraph.Node pastureNode = result.getNodes().stream().filter(node -> node.getTargetLabel().equalsIgnoreCase("PastureProvider")).collect(Collectors.toList()).get(0);
ConnectsToGraph.Node fieldNode = result.getNodes().stream().filter(node -> node.getTargetLabel().equalsIgnoreCase("FieldProvider")).collect(Collectors.toList()).get(0);
assertEquals(pastureNode.getNodeTemplateIds(), pastureProvider);
assertEquals(fieldNode.getNodeTemplateIds(), fieldProvider);
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class KargerMinCutVariationTest method performanceTest.
@Test
public void performanceTest() {
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "MinExternalConnectionsTest2", false);
TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
ConnectsToGraph connectsToGraph = new ConnectsToGraph(topology);
KargerMinCutVariation kargerMinCutVariation = new KargerMinCutVariation(connectsToGraph);
List<ConnectsToGraph> results = new ArrayList<>(kargerMinCutVariation.computeTargetLabelPartitions());
// testing a monte carlo algorithm doesn't always work
if (results.size() != 4 || results.get(0).getEdges().size() != 4) {
LOGGER.debug("Monte Carlo Algorithm produced wrong result");
return;
}
assertEquals(results.size(), 4);
assertEquals(results.get(0).getEdges().size(), 4);
assertEquals(results.get(1).getEdges().size(), 4);
assertEquals(results.get(2).getEdges().size(), 4);
assertEquals(results.get(3).getEdges().size(), 4);
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class MinHostsTest method testOneTargetLabelPresent.
@Test
public void testOneTargetLabelPresent() throws Exception {
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest2", false);
TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
List<TopologyWrapper> topologies = minHosts.allocate(topology);
assertEquals(1, topologies.size());
TTopologyTemplate topology1 = topologies.get(0).getTopology();
assertEquals(7, topology1.getNodeTemplateOrRelationshipTemplate().size());
List<String> types1 = new ArrayList<>();
for (TNodeTemplate nodeTemplate : topology1.getNodeTemplates()) {
types1.add(nodeTemplate.getType().getLocalPart());
}
assertEquals(4, types1.size());
assertEquals(3, types1.stream().filter(type -> type.equalsIgnoreCase("shetland_pony")).count());
assertEquals(1, types1.stream().filter(type -> type.equalsIgnoreCase("pasture")).count());
for (TNodeTemplate nodeTemplate : topologies.get(0).getTopLevelNTs()) {
assertEquals("pasture", topologies.get(0).getHostedOnSuccessor(nodeTemplate).getType().getLocalPart());
}
}
Aggregations