Search in sources :

Example 1 with SetMatchedPolicyModifier

use of org.alien4cloud.alm.deployment.configuration.flow.modifiers.action.SetMatchedPolicyModifier in project alien4cloud by alien4cloud.

the class PolicyMatchingSubstitutionService method getModifierListWithSelectionAction.

private List<ITopologyModifier> getModifierListWithSelectionAction(SetMatchedPolicyModifier matchedModifier) {
    List<ITopologyModifier> modifierList = flowExecutor.getDefaultFlowModifiers();
    PolicyMatchingCompositeModifier matchingModifier = (PolicyMatchingCompositeModifier) modifierList.stream().filter(modifier -> modifier instanceof PolicyMatchingCompositeModifier).findFirst().orElseThrow(() -> new IllegalArgumentException("Unexpected exception in deployment flow to update node substitution; unable to find the master node matching modifier to inject selection action modifier."));
    // inject the SetMatchedNodeModifier into the nodeMatchingModifiers, just after policyMatchingConfigAutoSelectModifier
    matchingModifier.addModifierAfter(matchedModifier, policyMatchingConfigAutoSelectModifier);
    return modifierList;
}
Also used : PolicyMatchingCompositeModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.PolicyMatchingCompositeModifier) TopologyServiceCore(alien4cloud.topology.TopologyServiceCore) PolicyMatchingCompositeModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.PolicyMatchingCompositeModifier) PolicyMatchingConfigAutoSelectModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.PolicyMatchingConfigAutoSelectModifier) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) Map(java.util.Map) Application(alien4cloud.model.application.Application) ApplicationService(alien4cloud.application.ApplicationService) OnDeploymentConfigCopyEvent(org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) MapUtils(org.apache.commons.collections4.MapUtils) Csar(org.alien4cloud.tosca.model.Csar) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Set(java.util.Set) SetMatchedPolicyModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.action.SetMatchedPolicyModifier) AbstractDeploymentConfig(org.alien4cloud.alm.deployment.configuration.model.AbstractDeploymentConfig) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) NotFoundException(alien4cloud.exception.NotFoundException) List(java.util.List) EnvironmentContext(org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext) FlowExecutor(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutor) AbstractComposedModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.AbstractComposedModifier) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) Topology(org.alien4cloud.tosca.model.templates.Topology) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier)

Example 2 with SetMatchedPolicyModifier

use of org.alien4cloud.alm.deployment.configuration.flow.modifiers.action.SetMatchedPolicyModifier in project alien4cloud by alien4cloud.

the class PolicyMatchingSubstitutionService method updateSubstitution.

/**
 * Execute the deployment flow with a modification of changing the substitution for one of the nodes.
 *
 * @param application The application for which to execute the deployment flow.
 * @param environment The environment for which to execute the deployment flow.
 * @param topology The topology linked to the specified environment.
 * @param nodeId The id of the node to substitute at matching phase.
 * @param resourceTemplateId The id of the location resource to substitute.
 * @return The flow execution context.
 */
public FlowExecutionContext updateSubstitution(Application application, ApplicationEnvironment environment, Topology topology, String nodeId, String resourceTemplateId) {
    FlowExecutionContext executionContext = new FlowExecutionContext(deploymentConfigurationDao, topology, new EnvironmentContext(application, environment));
    // Load the actual configuration
    // add a modifier that will actually perform the configuration of a substitution from user request (after cleanup and prior to node matching
    // auto-selection).
    SetMatchedPolicyModifier setMatchedPolicyModifier = new SetMatchedPolicyModifier(nodeId, resourceTemplateId);
    List<ITopologyModifier> modifierList = getModifierListWithSelectionAction(setMatchedPolicyModifier);
    flowExecutor.execute(topology, modifierList, executionContext);
    if (!setMatchedPolicyModifier.isExecuted()) {
        throw new NotFoundException("Requested substitution <" + resourceTemplateId + "> for node <" + nodeId + "> is not available as a match. Please check that inputs and location are configured and ask your admin to grant you access to requested resources on the location.");
    }
    return executionContext;
}
Also used : EnvironmentContext(org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext) SetMatchedPolicyModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.action.SetMatchedPolicyModifier) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) NotFoundException(alien4cloud.exception.NotFoundException) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier)

Aggregations

NotFoundException (alien4cloud.exception.NotFoundException)2 EnvironmentContext (org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext)2 FlowExecutionContext (org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext)2 ITopologyModifier (org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier)2 SetMatchedPolicyModifier (org.alien4cloud.alm.deployment.configuration.flow.modifiers.action.SetMatchedPolicyModifier)2 ApplicationService (alien4cloud.application.ApplicationService)1 Application (alien4cloud.model.application.Application)1 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 TopologyServiceCore (alien4cloud.topology.TopologyServiceCore)1 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)1 Maps (com.google.common.collect.Maps)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 OnDeploymentConfigCopyEvent (org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent)1 FlowExecutor (org.alien4cloud.alm.deployment.configuration.flow.FlowExecutor)1 AbstractComposedModifier (org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.AbstractComposedModifier)1 PolicyMatchingCompositeModifier (org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.PolicyMatchingCompositeModifier)1