Search in sources :

Example 6 with ServiceTemplateId

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");
}
Also used : ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) AbstractResourceTest(org.eclipse.winery.repository.rest.resources.AbstractResourceTest) Test(org.junit.Test)

Example 7 with ServiceTemplateId

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);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Converter(org.eclipse.winery.yaml.converter.Converter) XmlId(org.eclipse.winery.common.ids.XmlId) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) FileInputStream(java.io.FileInputStream) Namespace(org.eclipse.winery.common.ids.Namespace) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.Test)

Example 8 with ServiceTemplateId

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);
}
Also used : java.util(java.util) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) Util(org.eclipse.winery.common.Util) Collectors(java.util.stream.Collectors) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) org.eclipse.winery.model.tosca(org.eclipse.winery.model.tosca) DASpecification(org.eclipse.winery.repository.driverspecificationandinjection.DASpecification) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) IRepository(org.eclipse.winery.repository.backend.IRepository) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) DriverInjection(org.eclipse.winery.repository.driverspecificationandinjection.DriverInjection) QName(javax.xml.namespace.QName) NonNull(org.eclipse.jdt.annotation.NonNull) QName(javax.xml.namespace.QName) NonNull(org.eclipse.jdt.annotation.NonNull) IRepository(org.eclipse.winery.repository.backend.IRepository)

Example 9 with ServiceTemplateId

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;
}
Also used : IRepository(org.eclipse.winery.repository.backend.IRepository) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId)

Example 10 with ServiceTemplateId

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;
}
Also used : NonNull(org.eclipse.jdt.annotation.NonNull) IRepository(org.eclipse.winery.repository.backend.IRepository) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId)

Aggregations

ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)34 QName (javax.xml.namespace.QName)12 Test (org.junit.Test)12 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 URI (java.net.URI)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)6 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)5 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)5 POST (javax.ws.rs.POST)4 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)4 NonNull (org.eclipse.jdt.annotation.NonNull)3 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)3 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)3 RequirementTypeId (org.eclipse.winery.common.ids.definitions.RequirementTypeId)3 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)3 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)3 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)3