Search in sources :

Example 6 with ServiceResource

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

the class ServiceSecurityController method getAuthorizedUsers.

/**
 * List all users authorised to access the location.
 *
 * @return list of all users.
 */
@ApiOperation(value = "List all users authorized to access the service resource", notes = "Only user with ADMIN role can list authorized users to the location.")
@RequestMapping(value = "/users", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<List<UserDTO>> getAuthorizedUsers(@PathVariable String serviceId) {
    ServiceResource service = serviceResourceService.getOrFail(serviceId);
    List<UserDTO> users = UserDTO.convert(resourcePermissionService.getAuthorizedUsers(service));
    return RestResponseBuilder.<List<UserDTO>>builder().data(users).build();
}
Also used : UserDTO(alien4cloud.rest.orchestrator.model.UserDTO) ServiceResource(alien4cloud.model.service.ServiceResource) List(java.util.List) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with ServiceResource

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

the class NodeMatcherService method match.

public Map<String, List<LocationResourceTemplate>> match(Map<String, NodeType> nodesTypes, Map<String, NodeTemplate> nodesToMatch, Location location, String environmentId) {
    Map<String, List<LocationResourceTemplate>> matchingResult = Maps.newHashMap();
    // fetch location resources
    LocationResources locationResources = locationResourceService.getLocationResources(location);
    // Authorization filtering of location resources
    filterOnAuthorization(locationResources.getNodeTemplates(), environmentId);
    // fetch service resources
    List<ServiceResource> services = serviceResourceService.searchByLocation(location.getId());
    // self filtering: remove managed service linked to this location
    filterSelfManagedService(services, environmentId);
    // Authorization filtering of location resources
    filterOnAuthorization(services, environmentId);
    // from serviceResource to locationResource
    populateLocationResourcesWithServiceResource(locationResources, services, location.getId());
    Map<String, MatchingConfiguration> matchingConfigurations = locationMatchingConfigurationService.getMatchingConfiguration(location);
    Set<String> typesManagedByLocation = Sets.newHashSet();
    for (NodeType nodeType : locationResources.getNodeTypes().values()) {
        typesManagedByLocation.add(nodeType.getElementId());
        typesManagedByLocation.addAll(nodeType.getDerivedFrom());
    }
    INodeMatcherPlugin nodeMatcherPlugin = getNodeMatcherPlugin();
    for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodesToMatch.entrySet()) {
        String nodeTemplateId = nodeTemplateEntry.getKey();
        NodeTemplate nodeTemplate = nodeTemplateEntry.getValue();
        if (typesManagedByLocation.contains(nodeTemplate.getType())) {
            NodeType nodeTemplateType = nodesTypes.get(nodeTemplate.getType());
            if (nodeTemplateType == null) {
                throw new InvalidArgumentException("The given node types map must contain the type of the node template");
            }
            matchingResult.put(nodeTemplateId, nodeMatcherPlugin.matchNode(nodeTemplate, nodeTemplateType, locationResources, matchingConfigurations));
        }
    }
    return matchingResult;
}
Also used : MatchingConfiguration(alien4cloud.model.deployment.matching.MatchingConfiguration) LocationResources(alien4cloud.model.orchestrators.locations.LocationResources) ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) InvalidArgumentException(alien4cloud.exception.InvalidArgumentException) NodeType(org.alien4cloud.tosca.model.types.NodeType) List(java.util.List) ServiceResource(alien4cloud.model.service.ServiceResource) INodeMatcherPlugin(alien4cloud.deployment.matching.plugins.INodeMatcherPlugin) Map(java.util.Map)

Example 8 with ServiceResource

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

the class ManagedServiceResourceService method delete.

/**
 * Delete the managed service resource
 *
 * Note that the service will still exists, but will only be updatable via service api
 *
 * @param environmentId The environment for which to get the service resource.
 */
public void delete(String environmentId) {
    ServiceResource serviceResource = getOrFail(environmentId);
    serviceResourceService.delete(serviceResource.getId());
    publisher.publishEvent(new ManagedServiceDeletedEvent(this, serviceResource));
}
Also used : ManagedServiceDeletedEvent(org.alien4cloud.alm.events.ManagedServiceDeletedEvent) ServiceResource(alien4cloud.model.service.ServiceResource)

Example 9 with ServiceResource

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

the class ManagedServiceResourceService method onSubstitutionTypeChanged.

@EventListener
private void onSubstitutionTypeChanged(SubstitutionTypeChangedEvent event) {
    ServiceResource[] serviceResources = serviceResourceService.getByNodeTypes(event.getSubstituteNodeType().getElementId(), event.getSubstituteNodeType().getArchiveVersion());
    // we just change non-running services as we don't actually update the service
    for (ServiceResource serviceResource : serviceResources) {
        if (ToscaNodeLifecycleConstants.INITIAL.equals(serviceResource.getState())) {
            log.debug("Trying to update node based on substitution type.");
            nodeInstanceService.update(event.getSubstituteNodeType(), serviceResource.getNodeInstance(), serviceResource.getNodeInstance().getNodeTemplate().getProperties(), serviceResource.getNodeInstance().getNodeTemplate().getCapabilities(), serviceResource.getNodeInstance().getAttributeValues());
            // Update relationships
            updateServiceRelationship(serviceResource, event.getTopology());
            serviceResourceService.save(serviceResource);
        } else {
            log.info("Substitution type <" + event.getSubstituteNodeType().getElementId() + ":" + event.getSubstituteNodeType().getArchiveVersion() + "> for service <" + serviceResource.getName() + "> has changed. Service will be updated on restart. Note that services based on snapshot versions are not recommended.");
        }
    }
}
Also used : ServiceResource(alien4cloud.model.service.ServiceResource) EventListener(org.springframework.context.event.EventListener)

Example 10 with ServiceResource

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

the class ManagedServiceResourceService method create.

/**
 * Create a Service resource associated with the given environment.
 *
 * @param environmentId The environment to create a service for, the service version will be the one of the environment current associated version.
 * @param serviceName The name of the service as it should appears.
 * @param fromRuntime If we should try to create the service from the runtime topology related to the environment.
 * @return the id of the created service
 *
 * @throws AlreadyExistException if a service with the given name, or related to the given environment already exists
 * @throws alien4cloud.exception.NotFoundException if <b>fromRuntime</b> is set to true, but the environment is not deployed
 * @throws MissingSubstitutionException if topology related to the environment doesn't define a substitution type
 */
public synchronized String create(String serviceName, String environmentId, boolean fromRuntime) {
    ApplicationEnvironment environment = checkAndGetApplicationEnvironment(environmentId);
    // check that the service does not exists already for this environment
    if (alienDAO.buildQuery(ServiceResource.class).setFilters(fromKeyValueCouples("environmentId", environmentId)).count() > 0) {
        throw new AlreadyExistException("A service resource for environment <" + environmentId + "> and version <" + environment.getTopologyVersion() + "> already exists.");
    }
    Topology topology;
    String state = ToscaNodeLifecycleConstants.INITIAL;
    Deployment deployment = null;
    if (fromRuntime) {
        deployment = deploymentService.getActiveDeploymentOrFail(environmentId);
        topology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
        DeploymentStatus currentStatus = deploymentRuntimeStateService.getDeploymentStatus(deployment);
        state = managedServiceResourceEventService.getInstanceStateFromDeploymentStatus(currentStatus);
        if (state == null) {
            // We need a valid deployment state to expose as service.
            throw new InvalidDeploymentStatusException("Creating a service out of a running deployment is possible only when it's status is one of [DEPLOYED, FAILURE, UNDEPLOYED] current was <" + currentStatus + ">", currentStatus);
        }
    } else {
        topology = topologyServiceCore.getOrFail(Csar.createId(environment.getApplicationId(), environment.getTopologyVersion()));
    }
    if (topology.getSubstitutionMapping() == null) {
        throw new MissingSubstitutionException("Substitution is required to expose a topology.");
    }
    // The elementId of the type created out of the substitution is currently the archive name.
    String serviceId = serviceResourceService.create(serviceName, environment.getTopologyVersion(), topology.getArchiveName(), environment.getTopologyVersion(), environmentId);
    // Update the service relationships definition from the topology substitution
    updateServiceRelationship(serviceId, topology);
    if (fromRuntime) {
        managedServiceResourceEventService.updateRunningService((DeploymentTopology) topology, serviceResourceService.getOrFail(serviceId), deployment, state);
    }
    ServiceResource serviceResource = serviceResourceService.getOrFail(serviceId);
    // trigger a ManagedServiceCreatedEvent
    publisher.publishEvent(new ManagedServiceCreatedEvent(this, serviceResource));
    return serviceId;
}
Also used : MissingSubstitutionException(org.alien4cloud.alm.service.exceptions.MissingSubstitutionException) InvalidDeploymentStatusException(org.alien4cloud.alm.service.exceptions.InvalidDeploymentStatusException) Deployment(alien4cloud.model.deployment.Deployment) ServiceResource(alien4cloud.model.service.ServiceResource) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) AlreadyExistException(alien4cloud.exception.AlreadyExistException) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ManagedServiceCreatedEvent(org.alien4cloud.alm.events.ManagedServiceCreatedEvent) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus)

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