Search in sources :

Example 1 with ServiceNodeTemplate

use of org.alien4cloud.tosca.model.templates.ServiceNodeTemplate in project alien4cloud by alien4cloud.

the class NodeMatcherService method populateLocationResourcesWithServiceResource.

/**
 * Populate this {@link LocationResources} using these {@link ServiceResource}s in order to make them available as {@link LocationResourceTemplate} for
 * matching purpose.
 *
 * TODO: Improve this ugly code to put ServiceResource in LocationResourceTemplates.
 */
private void populateLocationResourcesWithServiceResource(LocationResources locationResources, List<ServiceResource> services, String locationId) {
    for (ServiceResource serviceResource : services) {
        LocationResourceTemplate lrt = new LocationResourceTemplate();
        lrt.setService(true);
        lrt.setEnabled(true);
        // for a service we also want to display the version, so just add it to the name
        lrt.setName(serviceResource.getName() + ":" + serviceResource.getVersion());
        lrt.setId(serviceResource.getId());
        ServiceNodeTemplate serviceNodeTemplate = new ServiceNodeTemplate(serviceResource.getNodeInstance());
        lrt.setTemplate(serviceNodeTemplate);
        lrt.setLocationId(locationId);
        String serviceTypeName = serviceResource.getNodeInstance().getNodeTemplate().getType();
        List<String> types = Lists.newArrayList(serviceTypeName);
        lrt.setTypes(types);
        NodeType serviceType = toscaTypeSearchService.findOrFail(NodeType.class, serviceTypeName, serviceResource.getNodeInstance().getTypeVersion());
        types.addAll(serviceType.getDerivedFrom());
        locationResources.getNodeTypes().put(serviceTypeName, serviceType);
        Csar csar = toscaTypeSearchService.getArchive(serviceType.getArchiveName(), serviceType.getArchiveVersion());
        Set<CSARDependency> dependencies = Sets.newHashSet();
        if (csar.getDependencies() != null) {
            dependencies.addAll(csar.getDependencies());
        }
        dependencies.add(new CSARDependency(csar.getName(), csar.getVersion()));
        if (serviceType.getCapabilities() != null && !serviceType.getCapabilities().isEmpty()) {
            for (CapabilityDefinition capabilityDefinition : serviceType.getCapabilities()) {
                locationResources.getCapabilityTypes().put(capabilityDefinition.getType(), csarRepoSearchService.getRequiredElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), dependencies));
            }
        }
        locationResources.getNodeTemplates().add(lrt);
    }
}
Also used : ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) Csar(org.alien4cloud.tosca.model.Csar) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) ServiceResource(alien4cloud.model.service.ServiceResource) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 2 with ServiceNodeTemplate

use of org.alien4cloud.tosca.model.templates.ServiceNodeTemplate in project alien4cloud by alien4cloud.

the class ServiceResourceRelationshipService method processService.

private void processService(PaaSNodeTemplate paaSNodeTemplate) {
    ServiceNodeTemplate serviceNodeTemplate = (ServiceNodeTemplate) paaSNodeTemplate.getTemplate();
    ServiceResource serviceResource = serviceResourceService.getOrFail(serviceNodeTemplate.getServiceResourceId());
    for (PaaSRelationshipTemplate paaSRelationshipTemplate : paaSNodeTemplate.getRelationshipTemplates()) {
        Interface templateInterface = safe(paaSRelationshipTemplate.getInterfaces()).get(ToscaRelationshipLifecycleConstants.CONFIGURE);
        if (templateInterface != null) {
            if (paaSRelationshipTemplate.getSource().equals(paaSNodeTemplate.getId())) {
                processSourceOperations(paaSRelationshipTemplate, serviceResource, templateInterface);
            } else {
                processTargetOperations(paaSRelationshipTemplate, serviceResource, templateInterface);
            }
        }
    }
}
Also used : ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate) ServiceResource(alien4cloud.model.service.ServiceResource) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 3 with ServiceNodeTemplate

use of org.alien4cloud.tosca.model.templates.ServiceNodeTemplate in project alien4cloud by alien4cloud.

the class NodeMatchingReplaceModifier method processServiceResourceReplacement.

@Override
protected void processServiceResourceReplacement(Topology topology, Map<String, NodeTemplate> topologyTemplateMap, String nodeId, String serviceResourceId) {
    ServiceResource serviceResource = getServiceResourceService().getOrFail(serviceResourceId);
    NodeTemplate serviceNodeTemplate = serviceResource.getNodeInstance().getNodeTemplate();
    ServiceNodeTemplate substitutionNodeTemplate = new ServiceNodeTemplate(serviceNodeTemplate.getType(), serviceNodeTemplate.getProperties(), serviceNodeTemplate.getAttributes(), serviceNodeTemplate.getRelationships(), serviceNodeTemplate.getRequirements(), serviceNodeTemplate.getCapabilities(), serviceNodeTemplate.getInterfaces(), serviceNodeTemplate.getArtifacts());
    substitutionNodeTemplate.setServiceResourceId(serviceResource.getId());
    substitutionNodeTemplate.setAttributeValues(serviceResource.getNodeInstance().getAttributeValues());
    NodeTemplate abstractTopologyNode = topologyTemplateMap.put(nodeId, substitutionNodeTemplate);
    substitutionNodeTemplate.setName(abstractTopologyNode.getName());
    substitutionNodeTemplate.setRelationships(abstractTopologyNode.getRelationships());
    // add all the necessary dependencies to the topology
    Csar csar = getToscaTypeSearchService().getArchive(serviceResource.getDependency().getName(), serviceResource.getDependency().getVersion());
    Set<CSARDependency> dependencies = Sets.newHashSet();
    if (csar.getDependencies() != null) {
        dependencies.addAll(csar.getDependencies());
    }
    dependencies.add(new CSARDependency(csar.getName(), csar.getVersion()));
    topology.getDependencies().addAll(dependencies);
}
Also used : ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) Csar(org.alien4cloud.tosca.model.Csar) ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ServiceResource(alien4cloud.model.service.ServiceResource) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Aggregations

ServiceResource (alien4cloud.model.service.ServiceResource)3 ServiceNodeTemplate (org.alien4cloud.tosca.model.templates.ServiceNodeTemplate)3 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)2 Csar (org.alien4cloud.tosca.model.Csar)2 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)1 PaaSRelationshipTemplate (alien4cloud.paas.model.PaaSRelationshipTemplate)1 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)1 Interface (org.alien4cloud.tosca.model.definitions.Interface)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)1 NodeType (org.alien4cloud.tosca.model.types.NodeType)1