Search in sources :

Example 41 with TTopologyTemplate

use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.

the class TopologyTemplateResource method applyGroupingAndPlacement.

@POST
@Path("applyplacement")
@Produces(MediaType.APPLICATION_JSON)
public Response applyGroupingAndPlacement(@Context UriInfo uriInfo) {
    try {
        TTopologyTemplate topology = PlacementUtils.groupAndPlaceComponents((ServiceTemplateId) this.parent.getId(), this.topologyTemplate);
        this.parent.setTopology(topology, this.type);
        RestUtils.persist(this.parent);
        ServiceTemplateId thisServiceTemplateId = (ServiceTemplateId) this.parent.getId();
        URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(thisServiceTemplateId));
        return Response.created(url).build();
    } catch (InvalidParameterException e) {
        LOGGER.debug("Error while grouping and placing: {}", e.getMessage());
        return Response.serverError().entity(e.getMessage()).build();
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 42 with TTopologyTemplate

use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.

the class TopologyTemplateResource method updateVersionOfNodeTemplate.

@POST
@Path("update")
@Consumes(MediaType.APPLICATION_JSON)
public TTopologyTemplate updateVersionOfNodeTemplate(UpdateInfo updateInfo) {
    TTopologyTemplate localTemplate = updateInfo.getTopologyTemplate() == null ? this.topologyTemplate : updateInfo.getTopologyTemplate();
    TNodeTemplate nodeTemplate = localTemplate.getNodeTemplate(updateInfo.getNodeTemplateId());
    if (nodeTemplate != null && nodeTemplate.getProperties() != null) {
        Map<String, String> propertyMappings = new LinkedHashMap<>();
        updateInfo.getMappingList().forEach(propertyMatching -> propertyMappings.put(propertyMatching.getOldKey(), propertyMatching.getNewKey()));
        LinkedHashMap<String, String> resultKvs = new LinkedHashMap<>();
        Map<String, String> oldKvs = ModelUtilities.getPropertiesKV(nodeTemplate);
        if (oldKvs != null) {
            oldKvs.forEach((key, value) -> {
                if (propertyMappings.containsKey(key)) {
                    resultKvs.put(propertyMappings.get(key), value);
                }
                if (updateInfo.getResolvedList().contains(key)) {
                    resultKvs.put(key, value);
                }
            });
            updateInfo.getNewList().forEach(key -> {
                if (!resultKvs.containsKey(key)) {
                    resultKvs.put(key, "");
                }
            });
            ModelUtilities.setPropertiesKV(nodeTemplate, resultKvs);
        }
    }
    BackendUtils.updateVersionOfNodeTemplate(localTemplate, updateInfo.getNodeTemplateId(), updateInfo.getNewComponentType());
    if (updateInfo.isSaveAfterUpdate()) {
        this.setModel(localTemplate);
    }
    return localTemplate;
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) LinkedHashMap(java.util.LinkedHashMap) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 43 with TTopologyTemplate

use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.

the class TopologyTemplateResource method applyAvailableFeatures.

@PUT
@Path("availablefeatures")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public TTopologyTemplate applyAvailableFeatures(ArrayList<AvailableFeaturesApiData> featuresList) {
    Map<String, Map<QName, String>> featureMap = new HashMap<>();
    featuresList.forEach(availableFeaturesApiData -> {
        HashMap<QName, String> featureTypesMap = new HashMap<>();
        if (Objects.nonNull(availableFeaturesApiData.getFeatures()) && availableFeaturesApiData.getFeatures().size() > 0) {
            availableFeaturesApiData.getFeatures().forEach(features -> featureTypesMap.put(features.getType(), features.getFeatureName()));
            featureMap.put(availableFeaturesApiData.getNodeTemplateId(), featureTypesMap);
        }
    });
    TTopologyTemplate enrichedTopology = EnhancementUtils.applyFeaturesForTopology(this.topologyTemplate, featureMap);
    this.parent.setTopology(enrichedTopology, this.type);
    RestUtils.persist(this.parent);
    return enrichedTopology;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) QName(javax.xml.namespace.QName) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 44 with TTopologyTemplate

use of org.eclipse.winery.model.tosca.TTopologyTemplate 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 45 with TTopologyTemplate

use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.

the class Splitting method getHostingInjectionOptions.

/**
 * This method returns the possible hosts for each lowest level node. Before a suitable node is found nodes may be
 * removed.
 *
 * @param topologyTemplate which should be mapped to the cloud provider according to the attached target labels -
 *                         target labels have to be attached to each node
 * @return map with a list of possible hosts for each lowest level node
 */
public Map<String, List<TTopologyTemplate>> getHostingInjectionOptions(TTopologyTemplate topologyTemplate) throws SplittingException {
    ProviderRepository repository = new ProviderRepository();
    Map<String, List<TTopologyTemplate>> injectionOptions = new HashMap<>();
    // Contains all nodes for which at least one cloud provider node is found to host them
    List<TNodeTemplate> nodesForWhichHostsFound = new ArrayList<>();
    nodesForWhichHostsFound.clear();
    List<TNodeTemplate> needHostNodeTemplateCandidates = getNodeTemplatesWithoutOutgoingHostedOnRelationships(topologyTemplate);
    List<TNodeTemplate> nodesToCheck = new ArrayList<>();
    // Find lowest level nodes with open requirements which means they can be hosted by an other component
    for (TNodeTemplate nodeTemplateCandidate : needHostNodeTemplateCandidates) {
        if (hasNodeOpenRequirement(topologyTemplate, nodeTemplateCandidate)) {
            if (nodeTemplateCandidate.getRequirements() != null && nodeTemplateCandidate.getRequirements().stream().anyMatch(req -> getBasisCapabilityType(getRequiredCapabilityTypeQNameOfRequirement(req)).getName().equalsIgnoreCase("Container"))) {
                nodesToCheck.add(nodeTemplateCandidate);
            }
        }
    }
    LOGGER.debug("Start...");
    if (!nodesToCheck.isEmpty()) {
        // Check all lowest level nodes with open requirements if a compatible node is available
        for (TNodeTemplate needHostNode : nodesToCheck) {
            Optional<String> label = ModelUtilities.getTargetLabel(needHostNode);
            if (!label.isPresent()) {
                LOGGER.error("No target label present");
                LOGGER.error("id " + needHostNode.getId());
                throw new SplittingException("No target label present for Node Template " + needHostNode.getId());
            }
            // noinspection OptionalGetWithoutIsPresent
            String targetLabel = ModelUtilities.getTargetLabel(needHostNode).get();
            List<TRequirement> openHostedOnRequirements = needHostNode.getRequirements().stream().filter(req -> getBasisCapabilityType(getRequiredCapabilityTypeQNameOfRequirement(req)).getName().equalsIgnoreCase("Container")).collect(Collectors.toList());
            List<TTopologyTemplate> compatibleTopologyFragments = repository.getAllTopologyFragmentsForLocationAndOfferingCapability(targetLabel, openHostedOnRequirements.get(0));
            LOGGER.debug("Found {} compatible topology fragments for NodeTemplate {}", compatibleTopologyFragments.size(), needHostNode.getId());
            // Add compatible nodes to the injectionOptions to host the considered lowest level node
            if (!compatibleTopologyFragments.isEmpty()) {
                injectionOptions.put(needHostNode.getId(), compatibleTopologyFragments);
                nodesForWhichHostsFound.add(needHostNode);
            }
        }
    }
    LOGGER.debug("Nodes to check: {}; Nodes with found host: {}", nodesToCheck.size(), nodesForWhichHostsFound.size());
    /*
         * Only the lowest components which are not in the matching list and which have still hostedOn-predecessors
         * are candidates which can be replaced by an other node
         */
    List<TNodeTemplate> replacementNodeTemplateCandidates = getReplacementNodeTemplateCandidatesForMatching(topologyTemplate, nodesForWhichHostsFound);
    while (!replacementNodeTemplateCandidates.isEmpty()) {
        for (TNodeTemplate replacementCandidate : replacementNodeTemplateCandidates) {
            List<TNodeTemplate> predecessorsOfReplacementCandidate = getHostedOnPredecessorsOfNodeTemplate(topologyTemplate, replacementCandidate);
            Optional<String> label = ModelUtilities.getTargetLabel(replacementCandidate);
            if (!label.isPresent()) {
                LOGGER.error("No target label present");
                LOGGER.error("id " + replacementCandidate.getId());
                throw new SplittingException("No target label present for Node Template " + replacementCandidate.getId());
            }
            // noinspection OptionalGetWithoutIsPresent
            String targetLabel = ModelUtilities.getTargetLabel(replacementCandidate).get();
            // For each replacement candidate the predecessors are considered
            for (TNodeTemplate predecessor : predecessorsOfReplacementCandidate) {
                // Check if a compatible node for the predecessor from the right provider is available
                if (predecessor.getRequirements() == null) {
                    nodesForWhichHostsFound.add(predecessor);
                // throw new SplittingException("The Node Template with the ID " + predecessor.getId() + " has no requirement assigned and the injected can't be processed");
                } else {
                    List<TRequirement> openHostedOnRequirements = predecessor.getRequirements().stream().filter(req -> getBasisCapabilityType(getRequiredCapabilityTypeQNameOfRequirement(req)).getName().equalsIgnoreCase("Container")).collect(Collectors.toList());
                    List<TTopologyTemplate> compatibleTopologyFragments = repository.getAllTopologyFragmentsForLocationAndOfferingCapability(targetLabel, openHostedOnRequirements.get(0));
                    // Add compatible nodes to the injectionOptions to host the considered lowest level node
                    if (!compatibleTopologyFragments.isEmpty()) {
                        injectionOptions.put(predecessor.getId(), compatibleTopologyFragments);
                        nodesForWhichHostsFound.add(predecessor);
                    }
                }
            }
        }
        // Delete all replacement candidates and their relationships.
        topologyTemplate.getNodeTemplateOrRelationshipTemplate().removeAll(replacementNodeTemplateCandidates);
        List<TRelationshipTemplate> removingIncomingRelationships = ModelUtilities.getAllRelationshipTemplates(topologyTemplate).stream().filter(ir -> replacementNodeTemplateCandidates.contains(ir.getTargetElement().getRef())).collect(Collectors.toList());
        topologyTemplate.getNodeTemplateOrRelationshipTemplate().removeAll(removingIncomingRelationships);
        List<TRelationshipTemplate> removingOutgoingRelationships = ModelUtilities.getAllRelationshipTemplates(topologyTemplate).stream().filter(ir -> replacementNodeTemplateCandidates.contains(ir.getSourceElement().getRef())).collect(Collectors.toList());
        topologyTemplate.getNodeTemplateOrRelationshipTemplate().removeAll(removingIncomingRelationships);
        topologyTemplate.getNodeTemplateOrRelationshipTemplate().removeAll(removingOutgoingRelationships);
        // The former predecessors now are either matched by a new host or they are new replacement candidates
        replacementNodeTemplateCandidates.clear();
        replacementNodeTemplateCandidates.addAll(getReplacementNodeTemplateCandidatesForMatching(topologyTemplate, nodesForWhichHostsFound));
    }
    /*
         * Check if all lowest level nodes are contained in the nodesForWhichHostsFound, i.e., at least one
         * cloud provider node is found to host them.
         * The application-specific nodes must not be replacement candidates!
         */
    List<TNodeTemplate> checkListAllNodesMatched = topologyTemplate.getNodeTemplates().stream().filter(z -> getNodeTemplatesWithoutOutgoingHostedOnRelationships(topologyTemplate).contains(z)).filter(node -> hasNodeOpenRequirement(topologyTemplate, node)).filter(y -> !nodesForWhichHostsFound.contains(y)).collect(Collectors.toList());
    LOGGER.debug("{} nodes without matching:", checkListAllNodesMatched.size());
    for (TNodeTemplate node : checkListAllNodesMatched) {
        LOGGER.debug(node.getId());
    }
    if (!checkListAllNodesMatched.isEmpty()) {
        throw new SplittingException("No matching possible");
    }
    return injectionOptions;
}
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) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) TRequirement(org.eclipse.winery.model.tosca.TRequirement) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ArrayList(java.util.ArrayList) List(java.util.List) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Aggregations

TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)158 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)112 ArrayList (java.util.ArrayList)85 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)62 List (java.util.List)59 QName (javax.xml.namespace.QName)55 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)55 Test (org.junit.jupiter.api.Test)51 Map (java.util.Map)48 HashMap (java.util.HashMap)47 LinkedHashMap (java.util.LinkedHashMap)42 TNodeType (org.eclipse.winery.model.tosca.TNodeType)42 ModelUtilities (org.eclipse.winery.model.tosca.utils.ModelUtilities)38 IRepository (org.eclipse.winery.repository.backend.IRepository)38 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)36 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)35 Objects (java.util.Objects)34 IOException (java.io.IOException)32 HashSet (java.util.HashSet)32 Collectors (java.util.stream.Collectors)32