Search in sources :

Example 41 with Location

use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.

the class UndeployService method undeploy.

private void undeploy(SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials, final Deployment deployment) {
    deploymentLockService.doWithDeploymentWriteLock(deployment.getOrchestratorDeploymentId(), () -> {
        log.info("Un-deploying deployment [{}] on orchestrator [{}]", deployment.getId(), deployment.getOrchestratorId());
        IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
        DeploymentTopology deployedTopology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
        Map<String, String> locationIds = TopologyLocationUtils.getLocationIds(deployedTopology);
        Map<String, Location> locations = deploymentTopologyService.getLocations(locationIds);
        SecretProviderConfigurationAndCredentials authResponse = null;
        if (secretProviderService.isSecretProvided(secretProviderConfigurationAndCredentials)) {
            authResponse = secretProviderService.generateToken(locations, secretProviderConfigurationAndCredentials.getSecretProviderConfiguration().getPluginName(), secretProviderConfigurationAndCredentials.getCredentials());
        }
        PaaSDeploymentContext deploymentContext = new PaaSDeploymentContext(deployment, deployedTopology, authResponse);
        orchestratorPlugin.undeploy(deploymentContext, new IPaaSCallback<ResponseEntity>() {

            @Override
            public void onSuccess(ResponseEntity data) {
                deploymentService.markUndeployed(deployment);
                log.info("Un-deployed deployment [{}] on orchestrator [{}]", deployment.getId(), deployment.getOrchestratorId());
            }

            @Override
            public void onFailure(Throwable throwable) {
                log.warn("Fail while Undeploying deployment [{}] on orchestrator [{}]", deployment.getId(), deployment.getOrchestratorId());
            }
        });
        return null;
    });
}
Also used : PaaSDeploymentContext(alien4cloud.paas.model.PaaSDeploymentContext) ResponseEntity(org.springframework.http.ResponseEntity) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) SecretProviderConfigurationAndCredentials(alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin) Location(alien4cloud.model.orchestrators.locations.Location)

Example 42 with Location

use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.

the class LocationResourceService method duplicatePolicyTemplate.

@Override
public LocationResourceTemplateWithDependencies duplicatePolicyTemplate(String resourceId) {
    PolicyLocationResourceTemplate policyLocationResourceTemplate = getOrFail(resourceId);
    policyLocationResourceTemplate.setId(UUID.randomUUID().toString());
    policyLocationResourceTemplate.setName(policyLocationResourceTemplate.getName() + "_" + "copy");
    Location location = locationService.getOrFail(policyLocationResourceTemplate.getLocationId());
    PolicyType resourceType = csarRepoSearchService.getRequiredElementInDependencies(PolicyType.class, policyLocationResourceTemplate.getTemplate().getType(), location.getDependencies());
    publishCreatedEventAndSaveResource(location, policyLocationResourceTemplate, resourceType);
    return new LocationResourceTemplateWithDependencies(policyLocationResourceTemplate, Sets.newHashSet(location.getDependencies()));
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType) LocationResourceTemplateWithDependencies(alien4cloud.model.orchestrators.locations.LocationResourceTemplateWithDependencies) PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) Location(alien4cloud.model.orchestrators.locations.Location)

Example 43 with Location

use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.

the class LocationResourceService method fillLocationResourceTypes.

private void fillLocationResourceTypes(Collection<? extends AbstractLocationResourceTemplate> resourceTemplates, IResourceTypeFiller resourceTypeFiller) {
    Map<String, Set<String>> resourceTypesByLocationId = Maps.newHashMap();
    for (AbstractLocationResourceTemplate resourceTemplate : resourceTemplates) {
        if (!resourceTemplate.isService()) {
            Set<String> locationResourceTypesSet = resourceTypesByLocationId.computeIfAbsent(resourceTemplate.getLocationId(), k -> Sets.newHashSet());
            locationResourceTypesSet.add(resourceTemplate.getTemplate().getType());
        }
    }
    for (Map.Entry<String, Set<String>> resourceTypeByLocationIdEntry : resourceTypesByLocationId.entrySet()) {
        String locationId = resourceTypeByLocationIdEntry.getKey();
        Set<String> exposedTypes = resourceTypeByLocationIdEntry.getValue();
        Location location = locationService.getOrFail(locationId);
        resourceTypeFiller.process(exposedTypes, location.getDependencies());
    }
}
Also used : Set(java.util.Set) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) Map(java.util.Map) HashMap(java.util.HashMap) Location(alien4cloud.model.orchestrators.locations.Location)

Example 44 with Location

use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.

the class LocationResourceService method setTemplateProperty.

/*
     * (non-Javadoc)
     * 
     * @see alien4cloud.orchestrators.locations.services.ILocationResourceService#setTemplateProperty(java.lang.String, java.lang.String,
     * java.lang.Object)
     */
@Override
public void setTemplateProperty(String resourceId, String propertyName, Object propertyValue) throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException {
    AbstractLocationResourceTemplate resourceTemplate = getOrFail(resourceId);
    Location location = locationService.getOrFail(resourceTemplate.getLocationId());
    AbstractInheritableToscaType resourceType = (AbstractInheritableToscaType) csarRepoSearchService.getRequiredElementInDependencies(AbstractToscaType.class, resourceTemplate.getTemplate().getType(), location.getDependencies());
    if (!safe(resourceType.getProperties()).containsKey(propertyName)) {
        throw new NotFoundException("Property [" + propertyName + "] is not found in type [" + resourceType.getElementId() + "]");
    }
    propertyService.setPropertyValue(location.getDependencies(), resourceTemplate.getTemplate(), resourceType.getProperties().get(propertyName), propertyName, propertyValue);
    saveResource(resourceTemplate);
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) NotFoundException(alien4cloud.exception.NotFoundException) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) AbstractInheritableToscaType(org.alien4cloud.tosca.model.types.AbstractInheritableToscaType) Location(alien4cloud.model.orchestrators.locations.Location)

Example 45 with Location

use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.

the class LocationResourceService method duplicateResourceTemplate.

@Override
public LocationResourceTemplateWithDependencies duplicateResourceTemplate(String resourceId) {
    LocationResourceTemplate locationResourceTemplate = getOrFail(resourceId);
    locationResourceTemplate.setId(UUID.randomUUID().toString());
    locationResourceTemplate.setName(locationResourceTemplate.getName() + "_" + "copy");
    locationResourceTemplate.setGenerated(false);
    Location location = locationService.getOrFail(locationResourceTemplate.getLocationId());
    NodeType resourceType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, locationResourceTemplate.getTemplate().getType(), location.getDependencies());
    publishCreatedEventAndSaveResource(location, locationResourceTemplate, resourceType);
    return new LocationResourceTemplateWithDependencies(locationResourceTemplate, Sets.newHashSet(location.getDependencies()));
}
Also used : PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) LocationResourceTemplateWithDependencies(alien4cloud.model.orchestrators.locations.LocationResourceTemplateWithDependencies) Location(alien4cloud.model.orchestrators.locations.Location)

Aggregations

Location (alien4cloud.model.orchestrators.locations.Location)80 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)31 ApiOperation (io.swagger.annotations.ApiOperation)30 List (java.util.List)28 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)28 Audit (alien4cloud.audit.annotation.Audit)21 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)15 LocationService (alien4cloud.orchestrators.locations.services.LocationService)13 Set (java.util.Set)13 Collectors (java.util.stream.Collectors)13 Application (alien4cloud.model.application.Application)12 AbstractLocationResourceTemplate (alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate)12 RestResponse (alien4cloud.rest.model.RestResponse)12 RestResponseBuilder (alien4cloud.rest.model.RestResponseBuilder)12 GroupDTO (alien4cloud.rest.orchestrator.model.GroupDTO)12 UserDTO (alien4cloud.rest.orchestrator.model.UserDTO)12 Resource (javax.annotation.Resource)12 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)11 ResourcePermissionService (alien4cloud.authorization.ResourcePermissionService)11 ApplicationEnvironmentAuthorizationUpdateRequest (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationUpdateRequest)11