Search in sources :

Example 1 with IPlanBuilderProvPhaseOperationPlugin

use of org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderProvPhaseOperationPlugin in project container by OpenTOSCA.

the class OperationChain method executeOperationProvisioning.

public boolean executeOperationProvisioning(final BPELPlanContext context, final List<String> operationNames, final Map<TParameter, Variable> param2propertyMapping) {
    int checkCount = 0;
    if (!this.provCandidates.isEmpty()) {
        final OperationNodeTypeImplCandidate provCandidate = this.provCandidates.get(this.selectedCandidateSet);
        final Map<String, Integer> order = new HashMap<>();
        // check for index of prov candidates
        for (final String opName : operationNames) {
            for (Integer index = 0; index < provCandidate.ops.size(); index++) {
                final TOperation op = provCandidate.ops.get(index);
                if (opName.equals(op.getName())) {
                    order.put(opName, index);
                }
            }
        }
        for (final String opName : operationNames) {
            final Integer index = order.get(opName);
            if (index == null) {
                continue;
            }
            final TOperation op = provCandidate.ops.get(index);
            if (!operationNames.contains(op.getName())) {
                // list, don't execute the operation
                continue;
            }
            final TImplementationArtifact ia = provCandidate.ias.get(index);
            final IPlanBuilderProvPhaseOperationPlugin plugin = provCandidate.plugins.get(index);
            if (plugin instanceof IPlanBuilderProvPhaseParamOperationPlugin) {
                final IPlanBuilderProvPhaseParamOperationPlugin paramPlugin = (IPlanBuilderProvPhaseParamOperationPlugin) plugin;
                if (!(op instanceof InterfaceDummy)) {
                    if (paramPlugin.handle(context, op, ia, param2propertyMapping)) {
                        checkCount++;
                    }
                } else {
                    final TOperation dummyOp = this.createDummyOperation(opName, op);
                    if (paramPlugin.handle(context, dummyOp, ia, param2propertyMapping)) {
                        checkCount++;
                    }
                }
            }
        }
    }
    return checkCount == operationNames.size();
}
Also used : TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) HashMap(java.util.HashMap) TOperation(org.eclipse.winery.model.tosca.TOperation) IPlanBuilderProvPhaseOperationPlugin(org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderProvPhaseOperationPlugin) IPlanBuilderProvPhaseParamOperationPlugin(org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderProvPhaseParamOperationPlugin)

Example 2 with IPlanBuilderProvPhaseOperationPlugin

use of org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderProvPhaseOperationPlugin in project container by OpenTOSCA.

the class OperationChain method executeOperationProvisioning.

public boolean executeOperationProvisioning(final BPELPlanContext context, final List<String> operationNames, final Map<TParameter, Variable> param2propertyMapping, final Map<TParameter, Variable> param2propertyOutputMapping, final Element elementToAppendTo) {
    int checkCount = 0;
    if (!this.provCandidates.isEmpty()) {
        final OperationNodeTypeImplCandidate provCandidate = this.provCandidates.get(this.selectedCandidateSet);
        final Map<String, Integer> order = new HashMap<>();
        // check for index of prov candidates
        for (final String opName : operationNames) {
            for (Integer index = 0; index < provCandidate.ops.size(); index++) {
                final TOperation op = provCandidate.ops.get(index);
                if (op instanceof InterfaceDummy) {
                    if (((InterfaceDummy) op).getOperation(opName) != null) {
                        order.put(opName, index);
                    }
                } else {
                    if (opName.equals(op.getName())) {
                        order.put(opName, index);
                    }
                }
            }
        }
        for (final String opName : operationNames) {
            final Integer index = order.get(opName);
            if (index == null) {
                continue;
            }
            final TOperation op = provCandidate.ops.get(index);
            if (op instanceof InterfaceDummy) {
                boolean matched = true;
                for (final String opname : operationNames) {
                    if (((InterfaceDummy) op).getOperation(opname) == null) {
                        matched = false;
                        break;
                    }
                }
                if (!matched) {
                    continue;
                }
            } else {
                if (!operationNames.contains(op.getName())) {
                    // list, don't execute the operation
                    continue;
                }
            }
            final TImplementationArtifact ia = provCandidate.ias.get(index);
            final IPlanBuilderProvPhaseOperationPlugin plugin = provCandidate.plugins.get(index);
            if (plugin instanceof IPlanBuilderProvPhaseParamOperationPlugin) {
                final IPlanBuilderProvPhaseParamOperationPlugin paramPlugin = (IPlanBuilderProvPhaseParamOperationPlugin) plugin;
                if (!(op instanceof InterfaceDummy)) {
                    if (paramPlugin.handle(context, op, ia, param2propertyMapping, elementToAppendTo)) {
                        checkCount++;
                    }
                } else {
                    final TOperation dummyOp = this.createDummyOperation(opName, op);
                    if (paramPlugin.handle(context, dummyOp, ia, param2propertyMapping, param2propertyOutputMapping, elementToAppendTo)) {
                        checkCount++;
                    }
                }
            }
        }
    }
    return checkCount == operationNames.size();
}
Also used : TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) HashMap(java.util.HashMap) TOperation(org.eclipse.winery.model.tosca.TOperation) IPlanBuilderProvPhaseOperationPlugin(org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderProvPhaseOperationPlugin) IPlanBuilderProvPhaseParamOperationPlugin(org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderProvPhaseParamOperationPlugin)

Example 3 with IPlanBuilderProvPhaseOperationPlugin

use of org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderProvPhaseOperationPlugin in project container by OpenTOSCA.

the class BPELScopeBuilder method createOperationCall.

/**
 * TODO: We assume that IAs are already provisinoned on IA engine
 *
 * @return OperationChain
 */
public OperationChain createOperationCall(final TRelationshipTemplate relationshipTemplate, final String interfaceName, final String operationName, Csar csar) {
    final Collection<TRelationshipTypeImplementation> impls = ModelUtils.findRelationshipTypeImplementation(relationshipTemplate, csar);
    if (impls.isEmpty()) {
        LOG.warn("No implementations available for RelationshipTemplate {} , can't generate Provisioning logic", relationshipTemplate.getId());
        return null;
    }
    final OperationChain chain = new OperationChain(relationshipTemplate);
    chain.provCandidates = new ArrayList<>();
    final List<IPlanBuilderProvPhaseOperationPlugin<?>> provPlugins = pluginRegistry.getProvPlugins();
    for (final TRelationshipTypeImplementation impl : impls) {
        final OperationNodeTypeImplCandidate provCandidate = new OperationNodeTypeImplCandidate();
        for (final TImplementationArtifact ia : impl.getImplementationArtifacts()) {
            for (final IPlanBuilderProvPhaseOperationPlugin<?> plugin : provPlugins) {
                if (plugin.canHandle(ia.getArtifactType()) && getOperationForIa(chain.relationshipTemplate, ia, operationName, csar) != null) {
                    provCandidate.add(getOperationForIa(chain.relationshipTemplate, ia, operationName, csar), ia, plugin);
                }
            }
        }
        chain.provCandidates.add(provCandidate);
    }
    return chain;
}
Also used : TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) IPlanBuilderProvPhaseOperationPlugin(org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderProvPhaseOperationPlugin)

Example 4 with IPlanBuilderProvPhaseOperationPlugin

use of org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderProvPhaseOperationPlugin in project container by OpenTOSCA.

the class BPELScopeBuilder method createOperationChain.

/**
 * Creates a complete ProvisioningChain for the given NodeTemplate
 *
 * @param nodeTemplate an TNodeTemplate to create a ProvisioningChain for
 * @return a complete ProvisioningChain
 */
public OperationChain createOperationChain(BPELPlanContext context, final TNodeTemplate nodeTemplate, final List<String> operationNames) {
    // get nodetype implementations
    final Collection<TNodeTypeImplementation> nodeTypeImpls = ModelUtils.findNodeTypeImplementation(nodeTemplate, context.getCsar());
    if (nodeTypeImpls.isEmpty()) {
        LOG.warn("No implementations available for NodeTemplate {} , can't generate Provisioning logic", nodeTemplate.getId());
        return null;
    }
    final OperationChain chain = new OperationChain(nodeTemplate);
    // calculate infrastructure nodes
    final List<TNodeTemplate> infraNodes = new ArrayList<>();
    ModelUtils.getInfrastructureNodes(nodeTemplate, infraNodes, context.getCsar());
    // we'll add here a dummy infra node, representing the management
    // infrastructure of the tosca engine (WAR IA's implementing tosca
    // operation,..)
    infraNodes.add(new TOSCAManagementInfrastructureNodeTemplate());
    // check for IA Plugins
    final List<IPlanBuilderPrePhaseIAPlugin<?>> iaPlugins = pluginRegistry.getIaPlugins();
    final List<IPlanBuilderPrePhaseIAPlugin<BPELPlanContext>> iaPlugins2 = Lists.newArrayList();
    iaPlugins.forEach(x -> iaPlugins2.add((IPlanBuilderPrePhaseIAPlugin<BPELPlanContext>) x));
    LOG.debug("Calculating best IA candidates for nodeTemplate {} ", nodeTemplate.getId());
    // calculate nodeImpl candidates where all IAs of each can be
    // provisioned
    calculateBestImplementationIACandidates(context, nodeTypeImpls, iaPlugins2, infraNodes, chain);
    for (final IANodeTypeImplCandidate wrapper : chain.iaCandidates) {
        final int length = wrapper.ias.size();
        for (int i = 0; i < length; i++) {
            final TImplementationArtifact ia = wrapper.ias.get(i);
            final TNodeTemplate infraNode = wrapper.infraNodes.get(i);
            final IPlanBuilderPlugin plugin = wrapper.plugins.get(i);
            LOG.debug("Found IA {} for deployment on the InfraNode {} with the Plugin {}", ia.getName(), infraNode.getId(), plugin.getID());
        }
    }
    // check for DA Plugins
    final List<IPlanBuilderPrePhaseDAPlugin<?>> daPlugins = pluginRegistry.getDaPlugins();
    final List<IPlanBuilderPrePhaseDAPlugin<BPELPlanContext>> daPlugins2 = Lists.newArrayList();
    daPlugins.forEach(x -> daPlugins2.add((IPlanBuilderPrePhaseDAPlugin<BPELPlanContext>) x));
    // calculate nodeImpl candidates where all DAs of each can be
    // provisioned
    calculateBestImplementationDACandidates(context, nodeTemplate, nodeTypeImpls, daPlugins2, infraNodes, chain);
    for (final DANodeTypeImplCandidate wrapper : chain.daCandidates) {
        final int length = wrapper.das.size();
        for (int i = 0; i < length; i++) {
            final TDeploymentArtifact da = wrapper.das.get(i);
            final TNodeTemplate infraNode = wrapper.infraNodes.get(i);
            final IPlanBuilderPlugin plugin = wrapper.plugins.get(i);
            LOG.debug("Found DA {} for deployment on the InfraNode {} with the Plugin {}", da.getName(), infraNode.getId(), plugin.getID());
        }
    }
    // filter for nodeTypeImpl Candidates where both DAs and IAs can
    // be provisioned
    filterIncompatibleIADACandidates(chain);
    // check for prov plugins
    final List<IPlanBuilderProvPhaseOperationPlugin<?>> provPlugins = pluginRegistry.getProvPlugins();
    // search for prov plugins according to the chosen IA provisionings in
    // the chain
    calculateProvPlugins(chain, provPlugins, context.getCsar());
    // filter ia and da candidates where the operations can't be executed
    filterIADACandidates(chain);
    // order provisioning candidates
    reorderProvCandidates(chain);
    // TODO consistency plugins
    // select provisioning
    selectProvisioning(chain, operationNames);
    return chain;
}
Also used : TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) IPlanBuilderPrePhaseIAPlugin(org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderPrePhaseIAPlugin) IPlanBuilderProvPhaseOperationPlugin(org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderProvPhaseOperationPlugin) TOSCAManagementInfrastructureNodeTemplate(org.opentosca.planbuilder.core.bpel.handlers.TOSCAManagementInfrastructureNodeTemplate) ArrayList(java.util.ArrayList) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) IPlanBuilderPlugin(org.opentosca.planbuilder.core.plugins.typebased.IPlanBuilderPlugin) IPlanBuilderPrePhaseDAPlugin(org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderPrePhaseDAPlugin) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Example 5 with IPlanBuilderProvPhaseOperationPlugin

use of org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderProvPhaseOperationPlugin in project container by OpenTOSCA.

the class BPELScopeBuilder method createOperationCall.

/**
 * Creates a complete ProvisioningChain for the given NodeTemplate
 *
 * @param nodeTemplate an TNodeTemplate to create a ProvisioningChain for
 * @return a complete ProvisioningChain
 */
public OperationChain createOperationCall(BPELPlanContext context, final TNodeTemplate nodeTemplate, final String interfaceName, final String operationName) {
    // get nodetype implementations
    final Collection<TNodeTypeImplementation> nodeTypeImpls = ModelUtils.findNodeTypeImplementation(nodeTemplate, context.getCsar());
    if (nodeTypeImpls.isEmpty()) {
        LOG.warn("No implementations available for NodeTemplate {} , can't generate Provisioning logic", nodeTemplate.getId());
        return null;
    }
    final OperationChain chain = new OperationChain(nodeTemplate);
    // calculate infrastructure nodes
    final List<TNodeTemplate> infraNodes = new ArrayList<>();
    ModelUtils.getInfrastructureNodes(nodeTemplate, infraNodes, context.getCsar());
    // we'll add here a dummy infra node, representing the management
    // infrastructure of the tosca engine (WAR IA's implementing tosca
    // operation,..)
    infraNodes.add(new TOSCAManagementInfrastructureNodeTemplate());
    // check for IA Plugins
    final List<IPlanBuilderPrePhaseIAPlugin<?>> iaPlugins = pluginRegistry.getIaPlugins();
    final List<IPlanBuilderPrePhaseIAPlugin<BPELPlanContext>> iaPlugins2 = Lists.newArrayList();
    iaPlugins.forEach(x -> iaPlugins2.add((IPlanBuilderPrePhaseIAPlugin<BPELPlanContext>) x));
    LOG.debug("Calculating best IA candidates for nodeTemplate {} ", nodeTemplate.getId());
    // calculate nodeImpl candidates where all IAs of each can be
    // provisioned
    calculateBestImplementationIACandidates(context, nodeTypeImpls, iaPlugins2, infraNodes, chain, interfaceName, operationName);
    for (final IANodeTypeImplCandidate iaCandidate : chain.iaCandidates) {
        final int length = iaCandidate.ias.size();
        for (int i = 0; i < length; i++) {
            final TImplementationArtifact ia = iaCandidate.ias.get(i);
            final TNodeTemplate infraNode = iaCandidate.infraNodes.get(i);
            final IPlanBuilderPlugin plugin = iaCandidate.plugins.get(i);
            LOG.debug("Found IA {} for deployment on the InfraNode {} with the Plugin {}", ia.getName(), infraNode.getId(), plugin.getID());
        }
    }
    // check for prov plugins
    final List<IPlanBuilderProvPhaseOperationPlugin<?>> provPlugins = pluginRegistry.getProvPlugins();
    // search for prov plugins according to the chosen IA provisionings in
    // the chain
    calculateProvPlugins(chain, provPlugins, interfaceName, operationName, context.getCsar());
    // filter ia and da candidates where the operations can't be executed
    filterIADACandidates(chain);
    // order provisioning candidates
    reorderProvCandidates(chain);
    // TODO consistency plugins
    final List<String> array = new ArrayList<>();
    array.add(operationName);
    // select provisioning
    selectProvisioning(chain, array);
    return chain;
}
Also used : TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) IPlanBuilderPrePhaseIAPlugin(org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderPrePhaseIAPlugin) IPlanBuilderProvPhaseOperationPlugin(org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderProvPhaseOperationPlugin) TOSCAManagementInfrastructureNodeTemplate(org.opentosca.planbuilder.core.bpel.handlers.TOSCAManagementInfrastructureNodeTemplate) ArrayList(java.util.ArrayList) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) IPlanBuilderPlugin(org.opentosca.planbuilder.core.plugins.typebased.IPlanBuilderPlugin) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Aggregations

TImplementationArtifact (org.eclipse.winery.model.tosca.TImplementationArtifact)6 IPlanBuilderProvPhaseOperationPlugin (org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderProvPhaseOperationPlugin)6 HashMap (java.util.HashMap)3 TOperation (org.eclipse.winery.model.tosca.TOperation)3 ArrayList (java.util.ArrayList)2 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)2 TNodeTypeImplementation (org.eclipse.winery.model.tosca.TNodeTypeImplementation)2 TOSCAManagementInfrastructureNodeTemplate (org.opentosca.planbuilder.core.bpel.handlers.TOSCAManagementInfrastructureNodeTemplate)2 IPlanBuilderPrePhaseIAPlugin (org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderPrePhaseIAPlugin)2 IPlanBuilderProvPhaseParamOperationPlugin (org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderProvPhaseParamOperationPlugin)2 IPlanBuilderPlugin (org.opentosca.planbuilder.core.plugins.typebased.IPlanBuilderPlugin)2 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)1 TRelationshipTypeImplementation (org.eclipse.winery.model.tosca.TRelationshipTypeImplementation)1 IPlanBuilderPrePhaseDAPlugin (org.opentosca.planbuilder.core.plugins.artifactbased.IPlanBuilderPrePhaseDAPlugin)1