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