Search in sources :

Example 6 with LocationModifierReference

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);
}
Also used : LocationModifierReference(alien4cloud.model.orchestrators.locations.LocationModifierReference) NotFoundException(alien4cloud.exception.NotFoundException)

Example 7 with LocationModifierReference

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;
}
Also used : LocationModifierReference(alien4cloud.model.orchestrators.locations.LocationModifierReference) PluginUsage(alien4cloud.plugin.model.PluginUsage) Location(alien4cloud.model.orchestrators.locations.Location)

Example 8 with LocationModifierReference

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() + ".");
            }
        }
    }
}
Also used : LocationModifierReference(alien4cloud.model.orchestrators.locations.LocationModifierReference) LocationService(alien4cloud.orchestrators.locations.services.LocationService) PluginManager(alien4cloud.plugin.PluginManager) MetaPropertiesService(alien4cloud.common.MetaPropertiesService) LocationPolicyValidationService(alien4cloud.topology.validation.LocationPolicyValidationService) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Location(alien4cloud.model.orchestrators.locations.Location) Inject(javax.inject.Inject) SecretCredentialInfo(org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo) LocationMatchingService(alien4cloud.deployment.matching.services.location.LocationMatchingService) Lists(com.google.common.collect.Lists) Map(java.util.Map) SecretProviderService(org.alien4cloud.secret.services.SecretProviderService) LinkedList(java.util.LinkedList) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) ToscaContext(alien4cloud.tosca.context.ToscaContext) MapUtils(org.apache.commons.collections4.MapUtils) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) MissingPluginException(alien4cloud.plugin.exception.MissingPluginException) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) List(java.util.List) Component(org.springframework.stereotype.Component) Slf4j(lombok.extern.slf4j.Slf4j) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) Optional(java.util.Optional) Topology(org.alien4cloud.tosca.model.templates.Topology) SecretCredentialInfo(org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo) LinkedList(java.util.LinkedList) MissingPluginException(alien4cloud.plugin.exception.MissingPluginException) LocationModifierReference(alien4cloud.model.orchestrators.locations.LocationModifierReference) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) Map(java.util.Map) Location(alien4cloud.model.orchestrators.locations.Location)

Example 9 with LocationModifierReference

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());
}
Also used : LocationModifierReference(alien4cloud.model.orchestrators.locations.LocationModifierReference) List(java.util.List) ArrayList(java.util.ArrayList) And(cucumber.api.java.en.And)

Example 10 with LocationModifierReference

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);
}
Also used : LocationModifierReference(alien4cloud.model.orchestrators.locations.LocationModifierReference) PostConstruct(javax.annotation.PostConstruct)

Aggregations

LocationModifierReference (alien4cloud.model.orchestrators.locations.LocationModifierReference)10 List (java.util.List)6 And (cucumber.api.java.en.And)4 ArrayList (java.util.ArrayList)4 Location (alien4cloud.model.orchestrators.locations.Location)3 MetaPropertiesService (alien4cloud.common.MetaPropertiesService)1 LocationMatchingService (alien4cloud.deployment.matching.services.location.LocationMatchingService)1 NotFoundException (alien4cloud.exception.NotFoundException)1 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 ILocationMatch (alien4cloud.model.deployment.matching.ILocationMatch)1 LocationService (alien4cloud.orchestrators.locations.services.LocationService)1 PluginManager (alien4cloud.plugin.PluginManager)1 MissingPluginException (alien4cloud.plugin.exception.MissingPluginException)1 PluginUsage (alien4cloud.plugin.model.PluginUsage)1 LocationPolicyValidationService (alien4cloud.topology.validation.LocationPolicyValidationService)1 ToscaContext (alien4cloud.tosca.context.ToscaContext)1 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 When (cucumber.api.java.en.When)1