Search in sources :

Example 16 with ServiceResource

use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.

the class DeploymentTopologyDTOBuilder method enrichSubstitutionTypesWithServicesDependencies.

/**
 * Enrich {@link LocationResourceTypes} adding types coming from on demand service resources.
 */
private void enrichSubstitutionTypesWithServicesDependencies(Collection<LocationResourceTemplate> resourceTemplates, LocationResourceTypes locationResourceTypes) {
    Set<String> serviceTypes = Sets.newHashSet();
    Set<CSARDependency> dependencies = Sets.newHashSet();
    for (LocationResourceTemplate resourceTemplate : resourceTemplates) {
        if (resourceTemplate.isService()) {
            String serviceId = resourceTemplate.getId();
            ServiceResource serviceResource = serviceResourceService.getOrFail(serviceId);
            NodeType serviceType = ToscaContext.get(NodeType.class, serviceResource.getNodeInstance().getNodeTemplate().getType());
            if (serviceType == null || !serviceType.getArchiveVersion().equals(serviceResource.getNodeInstance().getTypeVersion())) {
                serviceType = toscaTypeSearchService.findOrFail(NodeType.class, serviceResource.getNodeInstance().getNodeTemplate().getType(), serviceResource.getNodeInstance().getTypeVersion());
            }
            dependencies.addAll(csarDependencyLoader.getDependencies(serviceType.getArchiveName(), serviceType.getArchiveVersion()));
            dependencies.add(new CSARDependency(serviceType.getArchiveName(), serviceType.getArchiveVersion()));
            serviceTypes.add(serviceResource.getNodeInstance().getNodeTemplate().getType());
        }
    }
    locationResourceService.fillLocationResourceTypes(serviceTypes, locationResourceTypes, dependencies);
}
Also used : PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) ServiceResource(alien4cloud.model.service.ServiceResource) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 17 with ServiceResource

use of alien4cloud.model.service.ServiceResource 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 18 with ServiceResource

use of alien4cloud.model.service.ServiceResource 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 19 with ServiceResource

use of alien4cloud.model.service.ServiceResource 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)

Example 20 with ServiceResource

use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.

the class ManagedServiceResourceEventService method eventHappened.

@Override
public void eventHappened(AbstractMonitorEvent event) {
    String state = getInstanceStateFromDeploymentStatus(((PaaSDeploymentStatusMonitorEvent) event).getDeploymentStatus());
    if (state == null) {
        // Ignored.
        return;
    }
    ServiceResource serviceResource = alienDAO.buildQuery(ServiceResource.class).setFilters(fromKeyValueCouples("deploymentId", event.getDeploymentId())).prepareSearch().find();
    if (serviceResource == null) {
        // No service resources matching this deployment.
        return;
    }
    String currentState = serviceResource.getNodeInstance().getAttributeValues().get(ToscaNodeLifecycleConstants.ATT_STATE);
    if (state.equals(currentState)) {
        // nothing changed
        return;
    }
    if (ToscaNodeLifecycleConstants.INITIAL.equals(state)) {
        // Reset service node attribute and properties.
        resetRunningServiceResource(serviceResource);
    } else {
        // Set service node attribute and properties.
        updateRunningService(serviceResource, event.getDeploymentId(), state);
    }
}
Also used : ServiceResource(alien4cloud.model.service.ServiceResource)

Aggregations

ServiceResource (alien4cloud.model.service.ServiceResource)29 ApiOperation (io.swagger.annotations.ApiOperation)9 List (java.util.List)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 Audit (alien4cloud.audit.annotation.Audit)6 GroupDTO (alien4cloud.rest.orchestrator.model.GroupDTO)5 UserDTO (alien4cloud.rest.orchestrator.model.UserDTO)5 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)5 NodeType (org.alien4cloud.tosca.model.types.NodeType)5 ServiceNodeTemplate (org.alien4cloud.tosca.model.templates.ServiceNodeTemplate)4 Application (alien4cloud.model.application.Application)3 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)3 EventListener (org.springframework.context.event.EventListener)3 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)2 ResourcePermissionService (alien4cloud.authorization.ResourcePermissionService)2 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)2 Usage (alien4cloud.model.common.Usage)2 Deployment (alien4cloud.model.deployment.Deployment)2 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)2