Search in sources :

Example 1 with MissingPluginException

use of alien4cloud.plugin.exception.MissingPluginException in project alien4cloud by alien4cloud.

the class PolicyMatchingReplaceModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    super.process(topology, context);
    for (PolicyTemplate policyTemplate : safe(topology.getPolicies()).values()) {
        PolicyType policyType = ToscaContext.getOrFail(PolicyType.class, policyTemplate.getType());
        String policyImplMeta = TagUtil.getTagValue(policyType.getTags(), "a4c_policy_impl");
        if (policyImplMeta == null) {
            context.log().warn("Matched policy {} for {} does not define an alien topology modifier implementation, it may not be taken in account.", policyTemplate.getType(), policyTemplate.getName());
            continue;
        }
        String[] policyImpl = policyImplMeta.split(":");
        if (policyImpl.length != 3) {
            context.log().error("Matched policy {} for policy {} defines an invalid modifier implementation {}, format should be policy_plugin_id:policy_plugin_bean:injection_phase", policyTemplate.getType(), policyTemplate.getName(), policyImplMeta);
        }
        try {
            ITopologyModifier modifier = pluginModifierRegistry.getPluginBean(policyImpl[0], policyImpl[1]);
            List<ITopologyModifier> phaseModifiers = (List<ITopologyModifier>) context.getExecutionCache().computeIfAbsent(policyImpl[2], s -> Lists.<ITopologyModifier>newArrayList());
            // No need to add a modifier more than once for a phase
            if (!phaseModifiers.contains(modifier)) {
                phaseModifiers.add(modifier);
            }
        } catch (MissingPluginException e) {
            context.log().error("Implementation specified for policy type {} that refers to plugin bean {}, {} cannot be found.", policyTemplate.getType(), policyImpl[0], policyImpl[1]);
        }
    }
}
Also used : TagUtil(alien4cloud.utils.TagUtil) Set(java.util.Set) PolicyType(org.alien4cloud.tosca.model.types.PolicyType) MissingPluginException(alien4cloud.plugin.exception.MissingPluginException) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Inject(javax.inject.Inject) List(java.util.List) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) PluginModifierRegistry(org.alien4cloud.alm.deployment.configuration.flow.modifiers.PluginModifierRegistry) Map(java.util.Map) Topology(org.alien4cloud.tosca.model.templates.Topology) PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) ToscaContext(alien4cloud.tosca.context.ToscaContext) PolicyType(org.alien4cloud.tosca.model.types.PolicyType) MissingPluginException(alien4cloud.plugin.exception.MissingPluginException) List(java.util.List) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Example 2 with MissingPluginException

use of alien4cloud.plugin.exception.MissingPluginException in project alien4cloud by alien4cloud.

the class LocationMatchingModifier method injectLocationTopologyModfier.

private void injectLocationTopologyModfier(FlowExecutionContext context, String locationName, LocationModifierReference modifierReference) {
    try {
        ITopologyModifier modifier = pluginModifierRegistry.getPluginBean(modifierReference.getPluginId(), modifierReference.getBeanName());
        List<ITopologyModifier> phaseModifiers = (List<ITopologyModifier>) context.getExecutionCache().get(modifierReference.getPhase());
        if (phaseModifiers == null) {
            phaseModifiers = Lists.newArrayList();
            context.getExecutionCache().put(modifierReference.getPhase(), phaseModifiers);
        }
        phaseModifiers.add(modifier);
    } catch (MissingPluginException e) {
        context.log().error("Location {} defines modifier that refers to plugin bean {}, {} cannot be found.", locationName, modifierReference.getPluginId(), modifierReference.getBeanName());
    }
}
Also used : MissingPluginException(alien4cloud.plugin.exception.MissingPluginException) LinkedList(java.util.LinkedList) List(java.util.List) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier)

Aggregations

MissingPluginException (alien4cloud.plugin.exception.MissingPluginException)2 List (java.util.List)2 ITopologyModifier (org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier)2 ILocationMatch (alien4cloud.model.deployment.matching.ILocationMatch)1 PolicyLocationResourceTemplate (alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate)1 ToscaContext (alien4cloud.tosca.context.ToscaContext)1 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)1 TagUtil (alien4cloud.utils.TagUtil)1 Lists (com.google.common.collect.Lists)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Set (java.util.Set)1 Inject (javax.inject.Inject)1 FlowExecutionContext (org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext)1 PluginModifierRegistry (org.alien4cloud.alm.deployment.configuration.flow.modifiers.PluginModifierRegistry)1 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)1 PolicyTemplate (org.alien4cloud.tosca.model.templates.PolicyTemplate)1 Topology (org.alien4cloud.tosca.model.templates.Topology)1 PolicyType (org.alien4cloud.tosca.model.types.PolicyType)1 Component (org.springframework.stereotype.Component)1