Search in sources :

Example 16 with ServiceTemplateId

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

the class PatternRefinementTestWithGitBackedRepository method refineTopologyWithMultipleSameSubGraphs.

@Test
public void refineTopologyWithMultipleSameSubGraphs() throws Exception {
    this.setRevisionTo("origin/plain");
    List<RefinementCandidate> myCandidates = new ArrayList<>();
    PatternRefinement refinement = new PatternRefinement((candidates, refinementServiceTemplate, currentTopology) -> {
        myCandidates.addAll(candidates);
        return null;
    });
    ServiceTemplateId serviceTemplateId = refinement.refineServiceTemplate(new ServiceTemplateId("http://winery.opentosca.org/test/concrete/servicetemplates", "Pattern-basedDeplyomentModelWithTwoSameSubgraphs_w1-wip1", false));
    assertEquals(2, myCandidates.size());
    myCandidates.forEach(prmc -> assertEquals("IaaS_connectedTo_ThirdPattern_w1-wip1", prmc.getRefinementModel().getName()));
    ArrayList<String> nodeIdsToBeReplacedInFirstPmc = myCandidates.get(0).getNodeIdsToBeReplaced();
    assertEquals("Infrastructure-As-A-Service_w1", nodeIdsToBeReplacedInFirstPmc.get(0));
    assertEquals("ThirdPattern_w1", nodeIdsToBeReplacedInFirstPmc.get(1));
    ArrayList<String> nodeIdsToBeReplacedInSecondPmc = myCandidates.get(1).getNodeIdsToBeReplaced();
    assertEquals("Infrastructure-As-A-Service_w1_2", nodeIdsToBeReplacedInSecondPmc.get(0));
    assertEquals("ThirdPattern_w1", nodeIdsToBeReplacedInSecondPmc.get(1));
    assertEquals("Pattern-basedDeplyomentModelWithTwoSameSubgraphs_w1-wip1-refined-w1-wip1", serviceTemplateId.getQName().getLocalPart());
    assertEquals("http://winery.opentosca.org/test/concrete/servicetemplates", serviceTemplateId.getQName().getNamespaceURI());
}
Also used : RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test)

Example 17 with ServiceTemplateId

use of org.eclipse.winery.model.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(), VersionSupport.getNewComponentVersionId(id, "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(), VersionSupport.getNewComponentVersionId(id, "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 : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) IRepository(org.eclipse.winery.repository.backend.IRepository) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Example 18 with ServiceTemplateId

use of org.eclipse.winery.model.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();
    TServiceTemplate serviceTemplate = repository.getElement(id);
    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
    LOGGER.debug("Matching for ServiceTemplate with ID: {}", id.getQName());
    for (TRequirement req : requirementsAndMatchingBasisCapabilityTypes.keySet()) {
        LOGGER.debug("Open Requirement: {}", req.getId());
        LOGGER.debug("Matching basis type: {}", requirementsAndMatchingBasisCapabilityTypes.get(req));
    }
    TTopologyTemplate matchedConnectedTopologyTemplate;
    if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Container")) {
        // set default target labels if they are not yet set
        if (!hasTargetLabels(topologyTemplate)) {
            LOGGER.debug("Target labels are not set for all NodeTemplates. Using default target labels.");
            topologyTemplate.getNodeTemplates().forEach(t -> ModelUtilities.setTargetLabel(t, "*"));
        }
        TTopologyTemplate matchedHostsTopologyTemplate = hostMatchingWithDefaultHostSelection(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(), VersionSupport.getNewComponentVersionId(id, "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 : TRequirement(org.eclipse.winery.model.tosca.TRequirement) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) IRepository(org.eclipse.winery.repository.backend.IRepository) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Example 19 with ServiceTemplateId

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

the class Splitting method resolveTopologyTemplate.

/**
 */
public void resolveTopologyTemplate(ServiceTemplateId serviceTemplateId) throws SplittingException, IOException {
    IRepository repository = RepositoryFactory.getRepository();
    TServiceTemplate serviceTemplate = repository.getElement(serviceTemplateId);
    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().stream().anyMatch(c -> c.getType().equals(requiredCapTypeQName))).collect(Collectors.toList());
        if (!nodesWithMatchingCapability.isEmpty() && nodesWithMatchingCapability.size() == 1) {
            TCapability matchingCapability = nodesWithMatchingCapability.get(0).getCapabilities().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 : SortedSet(java.util.SortedSet) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) TParameter(org.eclipse.winery.model.tosca.TParameter) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) VersionSupport(org.eclipse.winery.model.version.VersionSupport) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) Map(java.util.Map) TRequirement(org.eclipse.winery.model.tosca.TRequirement) Util(org.eclipse.winery.repository.common.Util) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ListUtils.listIsNotNullOrEmpty(org.eclipse.winery.common.ListUtils.listIsNotNullOrEmpty) Set(java.util.Set) IOException(java.io.IOException) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Collectors(java.util.stream.Collectors) TInterface(org.eclipse.winery.model.tosca.TInterface) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) Objects(java.util.Objects) List(java.util.List) DASpecification(org.eclipse.winery.repository.driverspecificationandinjection.DASpecification) TCapability(org.eclipse.winery.model.tosca.TCapability) IRepository(org.eclipse.winery.repository.backend.IRepository) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) Optional(java.util.Optional) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TOperation(org.eclipse.winery.model.tosca.TOperation) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) DriverInjection(org.eclipse.winery.repository.driverspecificationandinjection.DriverInjection) QName(javax.xml.namespace.QName) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TRequirement(org.eclipse.winery.model.tosca.TRequirement) QName(javax.xml.namespace.QName) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TCapability(org.eclipse.winery.model.tosca.TCapability) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Example 20 with ServiceTemplateId

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

the class CsarImporter method processDefinitionsImport.

protected Optional<ServiceTemplateId> processDefinitionsImport(TDefinitions defs, TOSCAMetaFile tmf, Path definitionsPath, List<String> errors, CsarImportOptions options) throws IOException {
    List<TImport> imports = defs.getImport();
    this.importImports(definitionsPath.getParent(), tmf, imports, errors, options);
    // imports has been modified to contain necessary imports only
    // this method adds new imports to defs which may not be imported using "importImports".
    // Therefore, "importTypes" has to be called *after* importImports
    this.importTypes(defs, errors);
    Optional<ServiceTemplateId> entryServiceTemplate = Optional.empty();
    String defaultNamespace = defs.getTargetNamespace();
    List<TExtensibleElements> componentInstanceList = defs.getServiceTemplateOrNodeTypeOrNodeTypeImplementation();
    for (final TExtensibleElements ci : componentInstanceList) {
        // Determine namespace
        String namespace = this.getNamespace(ci, defaultNamespace);
        // Ensure that element has the namespace
        this.setNamespace(ci, namespace);
        // Determine id
        String id = ModelUtilities.getId(ci);
        final DefinitionsChildId wid = determineWineryId(ci, namespace, id);
        if (targetRepository.exists(wid)) {
            if (options.isOverwrite()) {
                targetRepository.forceDelete(wid);
                String msg = String.format("Deleted %1$s %2$s to enable replacement", ci.getClass().getName(), wid.getQName().toString());
                CsarImporter.LOGGER.debug(msg);
            } else {
                String msg = String.format("Skipped %1$s %2$s, because it already exists", ci.getClass().getName(), wid.getQName().toString());
                CsarImporter.LOGGER.debug(msg);
                // this is not displayed in the UI as we currently do not distinguish between pre-existing types and types created during the import.
                continue;
            }
        }
        // Create a fresh definitions object without the other data.
        final TDefinitions newDefs = BackendUtils.createWrapperDefinitions(wid, targetRepository);
        // copy over the inputs determined by this.importImports
        newDefs.getImport().addAll(imports);
        // add the current TExtensibleElements as the only content to it
        newDefs.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().add(ci);
        if (ci instanceof TArtifactTemplate) {
            // convention: Definitions are stored in the "Definitions" directory, therefore going to levels up (Definitions dir -> root dir) resolves to the root dir
            // COS01, line 2663 states that the path has to be resolved from the *root* of the CSAR
            this.adjustArtifactTemplate(definitionsPath.getParent().getParent(), tmf, (ArtifactTemplateId) wid, (TArtifactTemplate) ci, errors);
        } else if (ci instanceof TNodeType) {
            this.adjustNodeType(definitionsPath.getParent().getParent(), (TNodeType) ci, (NodeTypeId) wid, tmf, errors);
        } else if (ci instanceof TRelationshipType) {
            this.adjustRelationshipType(definitionsPath.getParent().getParent(), (TRelationshipType) ci, (RelationshipTypeId) wid, tmf, errors);
        } else if (ci instanceof TServiceTemplate) {
            this.adjustServiceTemplate(definitionsPath.getParent().getParent(), tmf, (ServiceTemplateId) wid, (TServiceTemplate) ci, errors);
            entryServiceTemplate = Optional.of((ServiceTemplateId) wid);
        }
        // import license and readme files
        importLicenseAndReadme(definitionsPath.getParent().getParent(), wid, tmf, errors);
        // Therefore, we check the entity type separately here
        if (ci instanceof TEntityType) {
            if (options.isAsyncWPDParsing()) {
                // Adjusting takes a long time
                // Therefore, we first save the type as is and convert to Winery-Property-Definitions in the background
                CsarImporter.storeDefinitions(targetRepository, wid, newDefs);
                CsarImporter.entityTypeAdjustmentService.submit(() -> {
                    adjustEntityType((TEntityType) ci, (EntityTypeId) wid, newDefs, errors);
                    CsarImporter.storeDefinitions(targetRepository, wid, newDefs);
                });
            } else {
                adjustEntityType((TEntityType) ci, (EntityTypeId) wid, newDefs, errors);
                CsarImporter.storeDefinitions(targetRepository, wid, newDefs);
            }
        } else {
            CsarImporter.storeDefinitions(targetRepository, wid, newDefs);
        }
    }
    return entryServiceTemplate;
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TEntityType(org.eclipse.winery.model.tosca.TEntityType) TImport(org.eclipse.winery.model.tosca.TImport) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

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