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();
}
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;
}
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));
}
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.");
}
}
}
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;
}
Aggregations