use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class TopologyTemplateResourceTest method farmTopologyTemplateCanBeCreatedAsJson.
@Test
public void farmTopologyTemplateCanBeCreatedAsJson() throws Exception {
this.setRevisionTo("1e2054315f18e80c466c26e6918d6506ce53f7f7");
// Quick hack to ensure that the service template containing the tpology template exists
ServiceTemplateId id = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates/fruits", "farm", false);
RepositoryFactory.getRepository().flagAsExisting(id);
this.assertPut("servicetemplates/http%253A%252F%252Fwinery.opentosca.org%252Ftest%252Fservicetemplates%252Ffruits/farm/topologytemplate/", "servicetemplates/farm_topologytemplate.json");
}
use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class Showcases method zipTypeTest.
@Test
public void zipTypeTest() throws Exception {
String name = "Showcase.csar";
InputStream inputStream = new FileInputStream(path + File.separator + name);
Converter converter = new Converter();
converter.convertY2X(inputStream);
TServiceTemplate serviceTemplate = RepositoryFactory.getRepository().getElement(new ServiceTemplateId(new Namespace(Namespaces.DEFAULT_NS, false), new XmlId("Showcase", false)));
Assert.assertNotNull(serviceTemplate);
}
use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class Splitting method resolveTopologyTemplate.
/**
* @param serviceTemplateId
* @throws SplittingException
*/
public void resolveTopologyTemplate(ServiceTemplateId serviceTemplateId) throws SplittingException, IOException {
IRepository repository = RepositoryFactory.getRepository();
@NonNull TServiceTemplate serviceTemplate = repository.getElement(serviceTemplateId);
@NonNull TTopologyTemplate topologyTemplate = serviceTemplate.getTopologyTemplate();
List<TRequirement> openRequirements = getOpenRequirements(topologyTemplate);
for (TRequirement requirement : openRequirements) {
QName requiredCapTypeQName = getRequiredCapabilityTypeQNameOfRequirement(requirement);
List<TNodeTemplate> nodesWithMatchingCapability = topologyTemplate.getNodeTemplates().stream().filter(nt -> nt.getCapabilities() != null).filter(nt -> nt.getCapabilities().getCapability().stream().anyMatch(c -> c.getType().equals(requiredCapTypeQName))).collect(Collectors.toList());
if (!nodesWithMatchingCapability.isEmpty() && nodesWithMatchingCapability.size() == 1) {
TCapability matchingCapability = nodesWithMatchingCapability.get(0).getCapabilities().getCapability().stream().filter(c -> c.getType().equals(requiredCapTypeQName)).findFirst().get();
TRelationshipType matchingRelationshipType = getMatchingRelationshipType(requirement, matchingCapability);
if (matchingRelationshipType != null) {
addMatchingRelationshipTemplateToTopologyTemplate(topologyTemplate, matchingRelationshipType, requirement, matchingCapability);
} else {
throw new SplittingException("No suitable relationship type found for matching");
}
}
}
repository.setElement(serviceTemplateId, serviceTemplate);
}
use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class Splitting method splitTopologyOfServiceTemplate.
/**
* Splits the topology template of the given service template. Creates a new service template with "-split" suffix
* as id. Any existing "-split" service template will be deleted. Matches the split topology template to the cloud
* providers according to the target labels. Creates a new service template with "-matched" suffix as id. Any
* existing "-matched" service template will be deleted.
*
* @param id of the ServiceTemplate switch should be split and matched to cloud providers
* @return id of the ServiceTemplate which contains the matched topology
*/
public ServiceTemplateId splitTopologyOfServiceTemplate(ServiceTemplateId id) throws SplittingException, IOException {
long start = System.currentTimeMillis();
IRepository repository = RepositoryFactory.getRepository();
TServiceTemplate serviceTemplate = repository.getElement(id);
// create wrapper service template
ServiceTemplateId splitServiceTemplateId = new ServiceTemplateId(id.getNamespace().getDecoded(), id.getXmlId().getDecoded() + "-split", false);
repository.forceDelete(splitServiceTemplateId);
repository.flagAsExisting(splitServiceTemplateId);
TServiceTemplate splitServiceTemplate = new TServiceTemplate();
splitServiceTemplate.setName(splitServiceTemplateId.getXmlId().getDecoded());
splitServiceTemplate.setId(splitServiceTemplate.getName());
splitServiceTemplate.setTargetNamespace(id.getNamespace().getDecoded());
TTopologyTemplate splitTopologyTemplate = split(serviceTemplate.getTopologyTemplate());
splitServiceTemplate.setTopologyTemplate(splitTopologyTemplate);
LOGGER.debug("Persisting...");
repository.setElement(splitServiceTemplateId, splitServiceTemplate);
LOGGER.debug("Persisted.");
// create wrapper service template
ServiceTemplateId matchedServiceTemplateId = new ServiceTemplateId(id.getNamespace().getDecoded(), id.getXmlId().getDecoded() + "-split-matched", false);
repository.forceDelete(matchedServiceTemplateId);
repository.flagAsExisting(matchedServiceTemplateId);
TServiceTemplate matchedServiceTemplate = new TServiceTemplate();
matchedServiceTemplate.setName(matchedServiceTemplateId.getXmlId().getDecoded());
matchedServiceTemplate.setId(matchedServiceTemplate.getName());
matchedServiceTemplate.setTargetNamespace(id.getNamespace().getDecoded());
TTopologyTemplate matchedTopologyTemplate = hostMatchingWithDefaultHostSelection(splitTopologyTemplate);
matchedServiceTemplate.setTopologyTemplate(matchedTopologyTemplate);
LOGGER.debug("Persisting...");
repository.setElement(matchedServiceTemplateId, matchedServiceTemplate);
LOGGER.debug("Persisted.");
long duration = System.currentTimeMillis() - start;
LOGGER.debug("Execution Time in millisec: " + duration + "ms");
return matchedServiceTemplateId;
}
use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class Splitting method matchTopologyOfServiceTemplate.
/**
* Splits the topology template of the given service template. Creates a new service template with "-split" suffix
* as id. Any existing "-split" service template will be deleted. Matches the split topology template to the cloud
* providers according to the target labels. Creates a new service template with "-matched" suffix as id. Any
* existing "-matched" service template will be deleted.
*
* @param id of the ServiceTemplate switch should be split and matched to cloud providers
* @return id of the ServiceTemplate which contains the matched topology
*/
public ServiceTemplateId matchTopologyOfServiceTemplate(ServiceTemplateId id) throws Exception {
long start = System.currentTimeMillis();
IRepository repository = RepositoryFactory.getRepository();
@NonNull TServiceTemplate serviceTemplate = repository.getElement(id);
@NonNull TTopologyTemplate topologyTemplate = serviceTemplate.getTopologyTemplate();
/*
Get all open requirements and the basis type of the required capability type
Two different basis types are distinguished:
"Container" which means a hostedOn injection is required
"Endpoint" which means a connectsTo injection is required
*/
Map<TRequirement, String> requirementsAndMatchingBasisCapabilityTypes = getOpenRequirementsAndMatchingBasisCapabilityTypeNames(topologyTemplate);
// Output check
for (TRequirement req : requirementsAndMatchingBasisCapabilityTypes.keySet()) {
System.out.println("open Requirement: " + req.getId());
System.out.println("matchingbasisType: " + requirementsAndMatchingBasisCapabilityTypes.get(req));
}
TTopologyTemplate matchedConnectedTopologyTemplate;
if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Container")) {
@NonNull TTopologyTemplate matchedHostsTopologyTemplate = hostMatchingWithDefaultLabelingAndHostSelection(topologyTemplate);
if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) {
matchedConnectedTopologyTemplate = connectionMatchingWithDefaultConnectorSelection(matchedHostsTopologyTemplate);
} else {
matchedConnectedTopologyTemplate = matchedHostsTopologyTemplate;
}
} else if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) {
matchedConnectedTopologyTemplate = connectionMatchingWithDefaultConnectorSelection(topologyTemplate);
} 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
// create wrapper service template
ServiceTemplateId matchedServiceTemplateId = new ServiceTemplateId(id.getNamespace().getDecoded(), id.getXmlId().getDecoded() + "-matched", false);
RepositoryFactory.getRepository().forceDelete(matchedServiceTemplateId);
RepositoryFactory.getRepository().flagAsExisting(matchedServiceTemplateId);
repository.flagAsExisting(matchedServiceTemplateId);
TServiceTemplate matchedServiceTemplate = new TServiceTemplate();
matchedServiceTemplate.setName(matchedServiceTemplateId.getXmlId().getDecoded());
matchedServiceTemplate.setId(matchedServiceTemplate.getName());
matchedServiceTemplate.setTargetNamespace(id.getNamespace().getDecoded());
matchedServiceTemplate.setTopologyTemplate(daSpecifiedTopology);
LOGGER.debug("Persisting...");
repository.setElement(matchedServiceTemplateId, matchedServiceTemplate);
LOGGER.debug("Persisted.");
long duration = System.currentTimeMillis() - start;
LOGGER.debug("Execution Time in millisec: " + duration + "ms");
return matchedServiceTemplateId;
}
Aggregations