Search in sources :

Example 26 with IRepository

use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.

the class Splitting method getInputParamListofIncomingRelationshipTemplates.

public List<TParameter> getInputParamListofIncomingRelationshipTemplates(TTopologyTemplate topologyTemplate, List<TRelationshipTemplate> listOfIncomingRelationshipTemplates) {
    List<TParameter> listOfInputs = new ArrayList<>();
    IRepository repo = RepositoryFactory.getRepository();
    for (TRelationshipTemplate incomingRelationshipTemplate : listOfIncomingRelationshipTemplates) {
        TNodeTemplate incomingNodetemplate = ModelUtilities.getSourceNodeTemplateOfRelationshipTemplate(topologyTemplate, incomingRelationshipTemplate);
        NodeTypeId incomingNodeTypeId = new NodeTypeId(incomingNodetemplate.getType());
        TNodeType incomingNodeType = repo.getElement(incomingNodeTypeId);
        List<TInterface> incomingNodeTypeInterfaces = incomingNodeType.getInterfaces();
        RelationshipTypeId incomingRelationshipTypeId = new RelationshipTypeId(incomingRelationshipTemplate.getType());
        if (!incomingNodeTypeInterfaces.isEmpty()) {
            TInterface relevantInterface = null;
            List<TInterface> connectionInterfaces = incomingNodeTypeInterfaces.stream().filter(tInterface -> tInterface.getIdFromIdOrNameField().contains("connection")).collect(Collectors.toList());
            if (connectionInterfaces.size() > 1) {
                TNodeTemplate targetNodeTemplate = ModelUtilities.getTargetNodeTemplateOfRelationshipTemplate(topologyTemplate, incomingRelationshipTemplate);
                for (TInterface tInterface : connectionInterfaces) {
                    int separator = tInterface.getIdFromIdOrNameField().lastIndexOf("/");
                    String prefixRelation = tInterface.getIdFromIdOrNameField().substring(separator + 1);
                    if (targetNodeTemplate.getName() != null && targetNodeTemplate.getName().toLowerCase().contains(prefixRelation.toLowerCase())) {
                        relevantInterface = tInterface;
                    }
                }
            } else {
                relevantInterface = connectionInterfaces.get(0);
            }
            if (relevantInterface != null) {
                for (TOperation tOperation : relevantInterface.getOperations()) {
                    List<TParameter> inputParameters = tOperation.getInputParameters();
                    if (inputParameters != null) {
                        listOfInputs.addAll(inputParameters);
                    }
                }
            }
        }
    }
    return listOfInputs;
}
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) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) TInterface(org.eclipse.winery.model.tosca.TInterface) ArrayList(java.util.ArrayList) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TOperation(org.eclipse.winery.model.tosca.TOperation) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TParameter(org.eclipse.winery.model.tosca.TParameter) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Example 27 with IRepository

use of org.eclipse.winery.repository.backend.IRepository 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 28 with IRepository

use of org.eclipse.winery.repository.backend.IRepository 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 29 with IRepository

use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.

the class YamlCsarImporter method storeDefs.

private void storeDefs(DefinitionsChildId id, TDefinitions defs) {
    RepositoryFileReference ref = BackendUtils.getRefOfDefinitions(id);
    IRepository repo = RepositoryFactory.getRepository();
    FromCanonical converter = null;
    if (repo instanceof GitBasedRepository) {
        GitBasedRepository wrapper = (GitBasedRepository) RepositoryFactory.getRepository();
        converter = new FromCanonical((YamlRepository) wrapper.getRepository());
    } else if (repo instanceof YamlRepository) {
        converter = new FromCanonical((YamlRepository) repo);
    }
    if (Objects.nonNull(converter)) {
        YamlWriter writer = new YamlWriter();
        writer.write(converter.convert((TDefinitions) defs), repo.ref2AbsolutePath(ref));
    }
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) FromCanonical(org.eclipse.winery.repository.yaml.converter.FromCanonical) YamlRepository(org.eclipse.winery.repository.yaml.YamlRepository) IRepository(org.eclipse.winery.repository.backend.IRepository) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) YamlWriter(org.eclipse.winery.repository.converter.writer.YamlWriter)

Example 30 with IRepository

use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.

the class PolicyWrapper method extractProperty.

private Object extractProperty() {
    IRepository repository = RepositoryFactory.getRepository();
    PolicyTypeId policyTypeId = new PolicyTypeId(policy.getType());
    TPolicyType policyType = repository.getElement(policyTypeId);
    LinkedHashMap<String, String> properties = ModelUtilities.getPropertiesKV(policy);
    if (properties == null) {
        // FIXME This needs to correctly deal with YamlProperties as well!!
        return null;
    }
    for (Map.Entry<String, String> property : properties.entrySet()) {
        if (property.getKey().equals(propertyKey)) {
            String type = getType(policyType, propertyKey);
            return cast(property.getValue(), type);
        }
    }
    return null;
}
Also used : PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) IRepository(org.eclipse.winery.repository.backend.IRepository) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

IRepository (org.eclipse.winery.repository.backend.IRepository)75 TNodeType (org.eclipse.winery.model.tosca.TNodeType)29 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)28 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)27 IOException (java.io.IOException)24 QName (javax.xml.namespace.QName)24 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)22 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)21 ArrayList (java.util.ArrayList)20 Map (java.util.Map)20 HashMap (java.util.HashMap)15 LoggerFactory (org.slf4j.LoggerFactory)15 LinkedHashMap (java.util.LinkedHashMap)14 List (java.util.List)14 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)14 RepositoryFactory (org.eclipse.winery.repository.backend.RepositoryFactory)14 Collectors (java.util.stream.Collectors)13 POST (javax.ws.rs.POST)13 Path (javax.ws.rs.Path)13 Produces (javax.ws.rs.Produces)13