Search in sources :

Example 31 with Location

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

the class WorkflowExecutionService method launchWorkflow.

/**
 * Launch a given workflow.
 */
public synchronized void launchWorkflow(SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials, String applicationEnvironmentId, String workflowName, Map<String, Object> params, IPaaSCallback<?> iPaaSCallback) {
    Deployment deployment = deploymentService.getActiveDeploymentOrFail(applicationEnvironmentId);
    DeploymentTopology deploymentTopology = deploymentRuntimeStateService.getRuntimeTopologyFromEnvironment(deployment.getEnvironmentId());
    IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
    final DeploymentTopology topology = alienMonitorDao.findById(DeploymentTopology.class, deployment.getId());
    // get the secret provider configuration from the location
    Map<String, String> locationIds = TopologyLocationUtils.getLocationIds(topology);
    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, deploymentTopology, authResponse);
    orchestratorPlugin.launchWorkflow(deploymentContext, workflowName, params, iPaaSCallback);
}
Also used : PaaSDeploymentContext(alien4cloud.paas.model.PaaSDeploymentContext) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Deployment(alien4cloud.model.deployment.Deployment) SecretProviderConfigurationAndCredentials(alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin) Location(alien4cloud.model.orchestrators.locations.Location)

Example 32 with Location

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

the class DefaultLocationMatcher method match.

@Override
public List<ILocationMatch> match(Topology topology) throws LocationMatchingException {
    List<ILocationMatch> matched = Lists.newArrayList();
    try {
        // get all enabled orchestrators
        List<Orchestrator> enabledOrchestrators = orchestratorService.getAll();
        if (CollectionUtils.isEmpty(enabledOrchestrators)) {
            return matched;
        }
        Map<String, Orchestrator> orchestratorMap = AlienUtils.fromListToMap(enabledOrchestrators, "id", true);
        List<Location> locations = locationService.getOrchestratorsLocations(orchestratorMap.keySet());
        for (Location location : locations) {
            matched.add(new LocationMatch(location, orchestratorMap.get(location.getOrchestratorId()), null));
        }
        // filter on supported artifacts
        locationMatchNodeFilter.filter(matched, topology);
        return matched;
    } catch (Exception e) {
        throw new LocationMatchingException("Failed to match topology <" + topology.getId() + "> against locations. ", e);
    }
}
Also used : LocationMatch(alien4cloud.model.deployment.matching.LocationMatch) ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) LocationMatchingException(alien4cloud.paas.exception.LocationMatchingException) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) LocationMatchingException(alien4cloud.paas.exception.LocationMatchingException) Location(alien4cloud.model.orchestrators.locations.Location)

Example 33 with Location

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

the class ServiceResourceService method updateLocations.

private void updateLocations(ServiceResource serviceResource, String[] locations) {
    if (locations == null) {
        return;
    }
    // Check what elements have changed.
    Set<String> removedLocations = CollectionUtils.safeNewHashSet(serviceResource.getLocationIds());
    Set<String> addedLocations = Sets.newHashSet();
    Set<String> newLocations = Sets.newHashSet();
    for (String locationId : locations) {
        if (removedLocations.contains(locationId)) {
            // This location was already affected
            removedLocations.remove(locationId);
            newLocations.add(locationId);
        } else {
            // This is an added element.
            if (!alienDAO.exist(Location.class, locationId)) {
                throw new NotFoundException("Location with id <" + locationId + "> does not exist.");
            }
            addedLocations.add(locationId);
            newLocations.add(locationId);
        }
    }
    serviceResource.setLocationIds(newLocations.toArray(new String[newLocations.size()]));
    // Dispatch location changed events (not a big deal if the save is actually canceled as it just changed the update date).
    for (String locationId : addedLocations) {
        publisher.publishEvent(new OnLocationResourceChangeEvent(this, locationId));
    }
    for (String locationId : removedLocations) {
        publisher.publishEvent(new OnLocationResourceChangeEvent(this, locationId));
    }
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) OnLocationResourceChangeEvent(alien4cloud.orchestrators.locations.events.OnLocationResourceChangeEvent) Location(alien4cloud.model.orchestrators.locations.Location)

Example 34 with Location

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

the class InputService method getLocationContextualInputs.

/**
 * Get input values matching the requested input definitions as defined in location meta properties.
 *
 * @param locations        The map of locations from which to fetch meta properties based inputs.
 * @param inputDefinitions The input definitions that may define request for location meta based inputs.
 * @return A map of <Input name, Property value> computed from the location meta properties.
 */
public Map<String, PropertyValue> getLocationContextualInputs(Map<String, Location> locations, Map<String, PropertyDefinition> inputDefinitions) {
    if (inputDefinitions == null) {
        return Maps.newHashMap();
    }
    Map<String, String> metaPropertiesValuesMap = Maps.newHashMap();
    for (Location location : safe(locations).values()) {
        metaPropertiesValuesMap.putAll(safe(location.getMetaProperties()));
    }
    Map<String, PropertyValue> inputs = Maps.newHashMap();
    prefixAndAddContextInput(inputDefinitions, inputs, LOC_META, metaPropertiesValuesMap, true);
    return inputs;
}
Also used : ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Location(alien4cloud.model.orchestrators.locations.Location)

Example 35 with Location

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

the class LocationMatchService method setLocationPolicy.

public void setLocationPolicy(ApplicationEnvironment environment, String orchestratorId, Map<String, String> groupsLocationsMapping) {
    if (MapUtils.isEmpty(groupsLocationsMapping)) {
        return;
    }
    DeploymentMatchingConfiguration configuration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(environment.getTopologyVersion(), environment.getId()));
    if (configuration == null) {
        configuration = new DeploymentMatchingConfiguration(environment.getTopologyVersion(), environment.getId());
    } else if (configuration.getLocationGroups() == null) {
        configuration.setLocationGroups(Maps.newHashMap());
    }
    Map<String, String> currentConfiguration = configuration.getLocationIds();
    // TODO For now, we only support one location policy for all nodes. So we have a group _A4C_ALL that represents all compute nodes in the topology
    // To improve later on for multiple groups support
    // throw an exception if multiple location policies provided: not yet supported
    // throw an exception if group name is not _A4C_ALL
    checkGroups(groupsLocationsMapping);
    boolean updated = false;
    for (Entry<String, String> matchEntry : groupsLocationsMapping.entrySet()) {
        String current = currentConfiguration.get(matchEntry.getKey());
        if (current != null && current.equals(matchEntry.getValue())) {
            continue;
        }
        updated = true;
        String locationId = matchEntry.getValue();
        Location location = locationService.getOrFail(locationId);
        locationSecurityService.checkAuthorisation(location, environment.getId());
        LocationPlacementPolicy locationPolicy = new LocationPlacementPolicy(locationId);
        locationPolicy.setName("Location policy");
        Map<String, NodeGroup> groups = configuration.getLocationGroups();
        NodeGroup group = new NodeGroup();
        group.setName(matchEntry.getKey());
        group.setPolicies(Lists.<AbstractPolicy>newArrayList());
        group.getPolicies().add(locationPolicy);
        groups.put(matchEntry.getKey(), group);
    }
    if (!updated) {
        // nothing has changed.
        return;
    }
    configuration.setOrchestratorId(orchestratorId);
    configuration.setMatchedLocationResources(Maps.newHashMap());
    configuration.setMatchedNodesConfiguration(Maps.newHashMap());
    publisher.publishEvent(new OnMatchedLocationChangedEvent(this, environment, orchestratorId, groupsLocationsMapping));
    deploymentConfigurationDao.save(configuration);
}
Also used : OnMatchedLocationChangedEvent(org.alien4cloud.alm.deployment.configuration.events.OnMatchedLocationChangedEvent) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) LocationPlacementPolicy(org.alien4cloud.tosca.model.templates.LocationPlacementPolicy) Location(alien4cloud.model.orchestrators.locations.Location) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

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