use of alien4cloud.model.orchestrators.locations.LocationModifierReference in project alien4cloud by alien4cloud.
the class LocationModifierService method move.
/**
* Move a location modifier from a position to another
*
* @param location
* @param from
* @param to
*/
public void move(Location location, int from, int to) {
if (from == to) {
return;
}
if (from < 0 || to < 0 || location.getModifiers() == null || from > location.getModifiers().size() || to > location.getModifiers().size()) {
throw new NotFoundException("Cannot move location modifier from " + from + "to index " + to);
}
LocationModifierReference modifier = location.getModifiers().remove(from);
location.getModifiers().add(to, modifier);
sort(location);
alienDAO.save(location);
}
use of alien4cloud.model.orchestrators.locations.LocationModifierReference in project alien4cloud by alien4cloud.
the class TopologyModifierPluginLinker method usage.
@Override
public List<PluginUsage> usage(String pluginId) {
// Get all modifiers associated with a location
GetMultipleDataResult<Location> locationData = alienDAO.buildQuery(Location.class).prepareSearch().search(0, Integer.MAX_VALUE);
List<PluginUsage> usages = Lists.newArrayList();
for (Location location : locationData.getData()) {
for (LocationModifierReference locationModifierReference : safe(location.getModifiers())) {
if (pluginId.equals(locationModifierReference.getPluginId())) {
usages.add(new PluginUsage(location.getId(), location.getName(), Location.class.getSimpleName()));
}
}
}
return usages;
}
use of alien4cloud.model.orchestrators.locations.LocationModifierReference 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.LocationModifierReference in project alien4cloud by alien4cloud.
the class LocationModifierStep method theLocationAtIndexShouldHaveThePluginId.
@And("^the location at index (\\d+) should have the phase \"([^\"]*)\"$")
public void theLocationAtIndexShouldHaveThePluginId(int index, String phase) throws Throwable {
RestResponse<List> response = JsonUtil.read(Context.getInstance().getRestResponse(), List.class);
Object obj = response.getData().get(index);
LocationModifierReference modifier = Context.getInstance().getJsonMapper().readValue(Context.getInstance().getJsonMapper().writeValueAsString(obj), LocationModifierReference.class);
Assert.assertEquals(phase, modifier.getPhase());
}
use of alien4cloud.model.orchestrators.locations.LocationModifierReference in project yorc-a4c-plugin by ystia.
the class LocationCreationListener method init.
@PostConstruct
public synchronized void init() {
openstackFipModifierRef = new LocationModifierReference();
openstackFipModifierRef.setPluginId(selfContext.getPlugin().getId());
openstackFipModifierRef.setBeanName(FipTopologyModifier.YORC_OPENSTACK_FIP_MODIFIER_TAG);
openstackFipModifierRef.setPhase(FlowPhases.POST_NODE_MATCH);
openstackBSWFModifierRef = new LocationModifierReference();
openstackBSWFModifierRef.setPluginId(selfContext.getPlugin().getId());
openstackBSWFModifierRef.setBeanName(OpenStackBSComputeWFModifier.YORC_OPENSTACK_BS_WF_MODIFIER_TAG);
openstackBSWFModifierRef.setPhase(FlowPhases.POST_MATCHED_NODE_SETUP);
}
Aggregations