use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class PreconfiguredInputsModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
EnvironmentContext environmentContext = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Preconfigured input modifier requires an environment context."));
ApplicationEnvironment environment = environmentContext.getEnvironment();
Map<String, Location> locations = (Map<String, Location>) context.getExecutionCache().get(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY);
AlienContextVariables alienContextVariables = new AlienContextVariables();
alienContextVariables.setApplicationEnvironment(environment);
alienContextVariables.setLocation(locations.values().stream().findFirst().get());
alienContextVariables.setApplication(environmentContext.getApplication());
// TODO: avoid reloading every time - find a way to know the last update on files (git hash ?)
Properties appVarProps = quickFileStorageService.loadApplicationVariables(environmentContext.getApplication().getId());
Properties envTypeVarProps = quickFileStorageService.loadEnvironmentTypeVariables(topology.getId(), environment.getEnvironmentType());
Properties envVarProps = quickFileStorageService.loadEnvironmentVariables(topology.getId(), environment.getId());
Map<String, Object> inputsMappingsMap = quickFileStorageService.loadInputsMappingFile(topology.getId());
InputsMappingFileVariableResolver.InputsResolvingResult inputsResolvingResult = InputsMappingFileVariableResolver.configure(appVarProps, envTypeVarProps, envVarProps, alienContextVariables).resolve(inputsMappingsMap, topology.getInputs());
if (CollectionUtils.isNotEmpty(inputsResolvingResult.getMissingVariables())) {
context.log().error(new MissingVariablesTask(inputsResolvingResult.getMissingVariables()));
}
if (CollectionUtils.isNotEmpty(inputsResolvingResult.getUnresolved())) {
context.log().error(new UnresolvablePredefinedInputsTask(inputsResolvingResult.getUnresolved()));
}
// checking constraints
Map<String, ConstraintUtil.ConstraintInformation> violations = Maps.newHashMap();
Map<String, ConstraintUtil.ConstraintInformation> typesViolations = Maps.newHashMap();
for (Map.Entry<String, PropertyValue> entry : safe(inputsResolvingResult.getResolved()).entrySet()) {
try {
ConstraintPropertyService.checkPropertyConstraint(entry.getKey(), entry.getValue(), topology.getInputs().get(entry.getKey()));
} catch (ConstraintViolationException e) {
violations.put(entry.getKey(), getConstraintInformation(e.getMessage(), e.getConstraintInformation()));
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
typesViolations.put(entry.getKey(), getConstraintInformation(e.getMessage(), e.getConstraintInformation()));
}
}
if (MapUtils.isNotEmpty(violations)) {
context.log().error(new PredefinedInputsConstraintViolationTask(violations, TaskCode.PREDEFINED_INPUTS_CONSTRAINT_VIOLATION));
}
if (MapUtils.isNotEmpty(typesViolations)) {
context.log().error(new PredefinedInputsConstraintViolationTask(typesViolations, TaskCode.PREDEFINED_INPUTS_TYPE_VIOLATION));
}
PreconfiguredInputsConfiguration preconfiguredInputsConfiguration = new PreconfiguredInputsConfiguration(environment.getTopologyVersion(), environment.getId());
preconfiguredInputsConfiguration.setInputs(inputsResolvingResult.getResolved());
// add unresolved so that they are not considered as deployer input
inputsResolvingResult.getUnresolved().forEach(unresolved -> preconfiguredInputsConfiguration.getInputs().put(unresolved, null));
// TODO: improve me
preconfiguredInputsConfiguration.setLastUpdateDate(new Date());
preconfiguredInputsConfiguration.setCreationDate(new Date());
context.saveConfiguration(preconfiguredInputsConfiguration);
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class NodeMatchingCandidateModifier method getAvailableSubstitutions.
private Map<String, List<LocationResourceTemplate>> getAvailableSubstitutions(Topology topology, Map<String, NodeGroup> locationGroups, Map<String, Location> locationByIds, String environmentId) {
// Fetch all node types for templates in the topology
Map<String, NodeType> nodeTypes = getNodeTypes(topology);
Map<String, List<LocationResourceTemplate>> availableSubstitutions = Maps.newHashMap();
// Based on our model nodes may come from various locations actually.
for (final Map.Entry<String, NodeGroup> locationGroupEntry : locationGroups.entrySet()) {
String groupName = locationGroupEntry.getKey();
final NodeGroup locationNodeGroup = locationGroupEntry.getValue();
Map<String, NodeTemplate> nodesToMatch = Maps.newHashMap();
if (MapUtils.isNotEmpty(topology.getNodeTemplates())) {
if (AlienConstants.GROUP_ALL.equals(groupName)) {
locationNodeGroup.setMembers(topology.getNodeTemplates().keySet());
nodesToMatch = topology.getNodeTemplates();
} else {
nodesToMatch = Maps.filterEntries(topology.getNodeTemplates(), input -> locationNodeGroup.getMembers().contains(input.getKey()));
}
}
availableSubstitutions.putAll(nodeMatcherService.match(nodeTypes, nodesToMatch, locationByIds.get(groupName), environmentId));
}
return availableSubstitutions;
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class LocationMatchingModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
// first process
processLocationMatching(topology, context);
Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, LocationMatchingModifier.class.getSimpleName());
// perform validation
locationPolicyValidationService.validateLocationPolicies(configurationOptional.orElse(new DeploymentMatchingConfiguration())).forEach(locationPolicyTask -> context.log().error(locationPolicyTask));
// No errors from validation let's inject location topology modifiers if any.
if (context.log().isValid()) {
Map<String, Location> selectedLocations = (Map<String, Location>) context.getExecutionCache().get(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY);
List<Location> locationsWithVault = selectedLocations.values().stream().filter(location -> location.getSecretProviderConfiguration() != null && location.getSecretProviderConfiguration().getConfiguration() != null).collect(Collectors.toList());
boolean needVaultCredential = locationsWithVault.size() > 0;
if (needVaultCredential) {
List<SecretCredentialInfo> secretCredentialInfos = new LinkedList<>();
for (Location location : locationsWithVault) {
try {
SecretCredentialInfo info = new SecretCredentialInfo();
String pluginName = location.getSecretProviderConfiguration().getPluginName();
Object rawSecretConfiguration = location.getSecretProviderConfiguration().getConfiguration();
secretCredentialInfos.add(secretProviderService.getSecretCredentialInfo(pluginName, rawSecretConfiguration));
} catch (Exception e) {
log.error("Cannot process secret provider configuration", e);
}
}
context.getExecutionCache().put(FlowExecutionContext.SECRET_CREDENTIAL, secretCredentialInfos);
} else {
context.getExecutionCache().remove(FlowExecutionContext.SECRET_CREDENTIAL);
}
for (LocationModifierReference modifierReference : safe(selectedLocations.values().iterator().next().getModifiers())) {
if (pluginManager.getPluginOrFail(modifierReference.getPluginId()).isEnabled()) {
injectLocationTopologyModfier(context, selectedLocations.values().iterator().next().getName(), modifierReference);
} else {
log.info("The plugin " + modifierReference.getPluginId() + " is not activated. Ignoring " + modifierReference.getBeanName() + ".");
}
}
}
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class CsarService method getCsarRelatedResourceList.
/**
* Get the list of resources that are using the given archive.
*
* @param csar The archive for which to get usage.
* @return The list of usage of the archive.
*/
public List<Usage> getCsarRelatedResourceList(Csar csar) {
if (csar == null) {
log.debug("You have requested a resource list for a invalid csar object : <" + csar + ">");
return Lists.newArrayList();
}
ArchiveUsageRequestEvent archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, csar.getName(), csar.getVersion());
// Archive from applications are used by the application.
if (Objects.equals(csar.getDelegateType(), ArchiveDelegateType.APPLICATION.toString())) {
// The CSAR is from an application's topology
Application application = applicationService.checkAndGetApplication(csar.getDelegateId());
archiveUsageRequestEvent.addUsage(new Usage(application.getName(), Application.class.getSimpleName().toLowerCase(), csar.getDelegateId(), csar.getWorkspace()));
}
// a csar that is a dependency of another csar can not be deleted
Csar[] relatedCsars = getDependantCsars(csar.getName(), csar.getVersion());
if (ArrayUtils.isNotEmpty(relatedCsars)) {
archiveUsageRequestEvent.addUsages(generateCsarsInfo(relatedCsars));
}
// check if some of the nodes are used in topologies.
Topology[] topologies = getDependantTopologies(csar.getName(), csar.getVersion());
if (topologies != null && topologies.length > 0) {
archiveUsageRequestEvent.addUsages(generateTopologiesInfo(topologies));
}
// a csar that is a dependency of location can not be deleted
Location[] relatedLocations = getDependantLocations(csar.getName(), csar.getVersion());
if (relatedLocations != null && relatedLocations.length > 0) {
archiveUsageRequestEvent.addUsages(generateLocationsInfo(relatedLocations));
}
publisher.publishEvent(archiveUsageRequestEvent);
return archiveUsageRequestEvent.getUsages();
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class CsarService method generateLocationsInfo.
/**
* Generate resources related to a locations list
*
* @param locations
* @return
*/
public List<Usage> generateLocationsInfo(Location[] locations) {
String resourceName;
String resourceId;
List<Usage> resourceList = Lists.newArrayList();
for (Location location : locations) {
resourceName = location.getName();
resourceId = location.getId();
Usage temp = new Usage(resourceName, Location.class.getSimpleName().toLowerCase(), resourceId, AlienConstants.GLOBAL_WORKSPACE_ID);
resourceList.add(temp);
}
return resourceList;
}
Aggregations