Search in sources :

Example 1 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project yorc-a4c-plugin by ystia.

the class ShowTopology method printNode.

/**
 * Print info about a Node
 * @param node
 */
private static void printNode(PaaSNodeTemplate node) {
    log.debug("******* Compute Node " + node.getId() + " *******");
    NodeTemplate nt = node.getTemplate();
    log.debug("CsarPath = " + node.getCsarPath());
    log.debug("Type = " + nt.getType());
    // Children
    List<PaaSNodeTemplate> children = node.getChildren();
    for (PaaSNodeTemplate child : children) {
        log.info("Child: " + child.getId());
    }
    // properties
    for (String prop : nt.getProperties().keySet()) {
        AbstractPropertyValue absval = nt.getProperties().get(prop);
        if (absval instanceof ScalarPropertyValue) {
            ScalarPropertyValue scaval = (ScalarPropertyValue) absval;
            log.debug(">> Property: " + prop + "=" + scaval.getValue());
        }
    }
    // Attributes
    Map<String, IValue> attrs = nt.getAttributes();
    if (attrs != null) {
        for (String attname : attrs.keySet()) {
            IValue att = attrs.get(attname);
            log.debug(">> Attribute: " + attname + "=" + att);
        }
    }
    // capabilities
    Map<String, Capability> capabilities = nt.getCapabilities();
    if (capabilities != null) {
        for (String capname : capabilities.keySet()) {
            Capability cap = capabilities.get(capname);
            log.debug(">> Capability " + capname);
            log.debug("type : " + cap.getType());
            log.debug("properties : " + cap.getProperties());
        }
    }
    // requirements
    Map<String, Requirement> requirements = nt.getRequirements();
    if (requirements != null) {
        for (String reqname : requirements.keySet()) {
            Requirement req = requirements.get(reqname);
            log.debug(">> Requirement: " + reqname);
            log.debug("type : " + req.getType());
            log.debug("properties : " + req.getProperties());
        }
    }
    // relationships
    Map<String, RelationshipTemplate> relations = nt.getRelationships();
    if (relations != null) {
        for (String relname : relations.keySet()) {
            RelationshipTemplate rel = relations.get(relname);
            log.debug(">> Relationship: " + relname);
            log.debug("type : " + rel.getType());
            log.debug("properties : " + rel.getProperties());
        }
    }
    // artifacts
    Map<String, DeploymentArtifact> artifacts = nt.getArtifacts();
    if (artifacts != null) {
        for (DeploymentArtifact art : artifacts.values()) {
            printArtifact(art);
        }
    }
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability) Requirement(org.alien4cloud.tosca.model.templates.Requirement) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate)

Example 2 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project yorc-a4c-plugin by ystia.

the class OpenStackBSComputeWFModifier method doProcess.

private void doProcess(Topology topology, FlowExecutionContext context) {
    Csar csar = new Csar(topology.getArchiveName(), topology.getArchiveVersion());
    Workflow installWF = topology.getWorkflows().get("install");
    Workflow uninstallWF = topology.getWorkflows().get("uninstall");
    Set<NodeTemplate> bsSet = TopologyNavigationUtil.getNodesOfType(topology, YORC_OPENSTACK_BS_TYPE, true);
    // Let's process all BS
    bsSet.forEach(bs -> safe(bs.getRelationships()).forEach((rn, rt) -> {
        if ("tosca.capabilities.Attachment".equals(rt.getRequirementType())) {
            // Attachment found
            context.getLog().info("Found a BlockStorage <{}> with an attachment on <{}>. Let's swap their workflow steps to match Yorc " + "expectations.", bs.getName(), rt.getTarget());
            String computeNodeName = rt.getTarget();
            // Now lets locate corresponding wf steps in install wf
            for (Map.Entry<String, WorkflowStep> workflowStepEntry : installWF.getSteps().entrySet()) {
                if (workflowStepEntry.getValue().getTarget().equals(bs.getName())) {
                    for (String precedingStepName : workflowStepEntry.getValue().getPrecedingSteps()) {
                        WorkflowStep precedingStep = installWF.getSteps().get(precedingStepName);
                        if (precedingStep.getTarget().equals(computeNodeName)) {
                            // We do not use swap operation here as it may mess up other workflow edges
                            // First remove the edge between steps
                            RemoveEdgeOperation removeEdgeOperation = new RemoveEdgeOperation();
                            removeEdgeOperation.setWorkflowName(installWF.getName());
                            removeEdgeOperation.setFromStepId(precedingStepName);
                            removeEdgeOperation.setToStepId(workflowStepEntry.getKey());
                            log.debug("Swapping {} with target {}", precedingStepName, workflowStepEntry.getKey());
                            removeEdgeProcessor.process(csar, topology, removeEdgeOperation);
                            // Then reconnect them in the right sequence
                            ConnectStepFromOperation connectStepFromOperation = new ConnectStepFromOperation();
                            connectStepFromOperation.setWorkflowName(installWF.getName());
                            connectStepFromOperation.setFromStepIds(new String[] { workflowStepEntry.getKey() });
                            connectStepFromOperation.setToStepId(precedingStepName);
                            connectStepFromProcessor.process(csar, topology, connectStepFromOperation);
                            break;
                        }
                    }
                    break;
                }
            }
            // Now lets locate corresponding wf steps in uninstall wf
            for (Map.Entry<String, WorkflowStep> workflowStepEntry : uninstallWF.getSteps().entrySet()) {
                if (workflowStepEntry.getValue().getTarget().equals(bs.getName())) {
                    for (String onSuccessStepName : workflowStepEntry.getValue().getOnSuccess()) {
                        WorkflowStep onSuccessStep = uninstallWF.getSteps().get(onSuccessStepName);
                        if (onSuccessStep.getTarget().equals(computeNodeName)) {
                            // We do not use swap operation here as it may mess up other workflow edges
                            // First remove the edge between steps
                            RemoveEdgeOperation removeEdgeOperation = new RemoveEdgeOperation();
                            removeEdgeOperation.setWorkflowName(uninstallWF.getName());
                            removeEdgeOperation.setFromStepId(workflowStepEntry.getKey());
                            removeEdgeOperation.setToStepId(onSuccessStepName);
                            log.debug("Swapping {} with target {}", onSuccessStepName, workflowStepEntry.getKey());
                            removeEdgeProcessor.process(csar, topology, removeEdgeOperation);
                            // Then reconnect them in the right sequence
                            ConnectStepFromOperation connectStepFromOperation = new ConnectStepFromOperation();
                            connectStepFromOperation.setWorkflowName(uninstallWF.getName());
                            connectStepFromOperation.setFromStepIds(new String[] { onSuccessStepName });
                            connectStepFromOperation.setToStepId(workflowStepEntry.getKey());
                            connectStepFromProcessor.process(csar, topology, connectStepFromOperation);
                            break;
                        }
                    }
                    break;
                }
            }
        // Start & Stop make no sense for those kind of nodes in Yorc as those operations are not implemented.
        // Do not change those WFs
        }
    }));
}
Also used : ToscaContextual(alien4cloud.tosca.context.ToscaContextual) Csar(org.alien4cloud.tosca.model.Csar) WorkflowValidator(alien4cloud.paas.wf.validation.WorkflowValidator) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Resource(javax.annotation.Resource) Set(java.util.Set) ConnectStepFromProcessor(org.alien4cloud.tosca.editor.processors.workflow.ConnectStepFromProcessor) TopologyModifierSupport(org.alien4cloud.alm.deployment.configuration.flow.TopologyModifierSupport) TopologyNavigationUtil(org.alien4cloud.tosca.utils.TopologyNavigationUtil) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) RemoveEdgeOperation(org.alien4cloud.tosca.editor.operations.workflow.RemoveEdgeOperation) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) Map(java.util.Map) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Topology(org.alien4cloud.tosca.model.templates.Topology) ConnectStepFromOperation(org.alien4cloud.tosca.editor.operations.workflow.ConnectStepFromOperation) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) RemoveEdgeProcessor(org.alien4cloud.tosca.editor.processors.workflow.RemoveEdgeProcessor) Csar(org.alien4cloud.tosca.model.Csar) RemoveEdgeOperation(org.alien4cloud.tosca.editor.operations.workflow.RemoveEdgeOperation) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) ConnectStepFromOperation(org.alien4cloud.tosca.editor.operations.workflow.ConnectStepFromOperation) Workflow(org.alien4cloud.tosca.model.workflow.Workflow)

Example 3 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project yorc-a4c-plugin by ystia.

the class YorcPaaSProvider method switchMaintenanceMode.

/**
 * Switch the maintenance mode for this deployed topology.
 *
 * @param  ctx the deployment context
 * @param  maintenanceModeOn
 * @throws MaintenanceModeException
 */
@Override
public void switchMaintenanceMode(PaaSDeploymentContext ctx, boolean maintenanceModeOn) throws MaintenanceModeException {
    String paasId = ctx.getDeploymentPaaSId();
    YorcRuntimeDeploymentInfo jrdi = runtimeDeploymentInfos.get(paasId);
    log.debug(paasId + " switchMaintenanceMode");
    if (jrdi == null) {
        log.error(paasId + " switchMaintenanceMode: No Deployment Information");
        throw new MaintenanceModeException("No Deployment Information");
    }
    Topology topology = jrdi.getDeploymentContext().getDeploymentTopology();
    Map<String, Map<String, InstanceInformation>> nodes = jrdi.getInstanceInformations();
    if (nodes == null || nodes.isEmpty()) {
        log.error(paasId + " switchMaintenanceMode: No Node found");
        throw new MaintenanceModeException("No Node found");
    }
    for (Entry<String, Map<String, InstanceInformation>> nodeEntry : nodes.entrySet()) {
        String node = nodeEntry.getKey();
        Map<String, InstanceInformation> nodeInstances = nodeEntry.getValue();
        if (nodeInstances != null && !nodeInstances.isEmpty()) {
            NodeTemplate nodeTemplate = topology.getNodeTemplates().get(node);
            NodeType nodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), topology.getDependencies());
        // ALIEN 2.0.0 Update
        /*
                if (isFromType(NormativeComputeConstants.COMPUTE_TYPE, nodeType)) {
                    for (Entry<String, InstanceInformation> nodeInstanceEntry : nodeInstances.entrySet()) {
                        String instance = nodeInstanceEntry.getKey();
                        InstanceInformation iinfo = nodeInstanceEntry.getValue();
                        if (iinfo != null) {
                            doSwitchInstanceMaintenanceMode(paasId, node, instance, iinfo, maintenanceModeOn);
                        }
                    }
                }*/
        }
    }
}
Also used : MaintenanceModeException(alien4cloud.paas.exception.MaintenanceModeException) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) InstanceInformation(alien4cloud.paas.model.InstanceInformation) Topology(org.alien4cloud.tosca.model.templates.Topology) Map(java.util.Map)

Example 4 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class NodeTypeScoreServiceTest method testScoreService.

@Test
public void testScoreService() throws InterruptedException {
    // Initialize test data
    NodeType indexedNodeType = new NodeType();
    indexedNodeType.setElementId("mordor");
    indexedNodeType.setArchiveName("middleEarth");
    indexedNodeType.setArchiveVersion("1.0.0");
    indexedNodeType.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
    indexedNodeType.setCreationDate(new Date());
    indexedNodeType.setLastUpdateDate(new Date());
    indexedNodeType.setDefaultCapabilities(Lists.newArrayList("very_evil"));
    dao.save(indexedNodeType);
    String mordor100Id = indexedNodeType.getId();
    indexedNodeType.setArchiveVersion("1.0.1");
    indexedNodeType.setCreationDate(new Date());
    indexedNodeType.setLastUpdateDate(new Date());
    indexedNodeType.setDefaultCapabilities(Lists.newArrayList("deprecated_evil"));
    dao.save(indexedNodeType);
    String mordor101Id = indexedNodeType.getId();
    indexedNodeType.setElementId("isengard");
    indexedNodeType.setArchiveName("middleEarth");
    indexedNodeType.setArchiveVersion("1.0.0");
    indexedNodeType.setCreationDate(new Date());
    indexedNodeType.setLastUpdateDate(new Date());
    indexedNodeType.setDefaultCapabilities(null);
    dao.save(indexedNodeType);
    String isengard100Id = indexedNodeType.getId();
    indexedNodeType.setElementId("isengard");
    indexedNodeType.setArchiveName("middleEarth");
    indexedNodeType.setArchiveVersion("1.0.1");
    indexedNodeType.setCreationDate(new Date());
    indexedNodeType.setLastUpdateDate(new Date());
    indexedNodeType.setDefaultCapabilities(Lists.newArrayList("evil"));
    dao.save(indexedNodeType);
    String isengard101Id = indexedNodeType.getId();
    Topology topology = new Topology();
    topology.setId("topology");
    topology.setArchiveName("test-archive");
    topology.setArchiveVersion("1.0.0");
    topology.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
    topology.setDependencies(Sets.newHashSet(new CSARDependency("middleEarth", "1.0.1")));
    topology.setNodeTemplates(MapUtil.newHashMap(new String[] { "isengard" }, new NodeTemplate[] { new NodeTemplate(indexedNodeType.getElementId(), null, null, null, null, null, null, null) }));
    dao.save(topology);
    indexedNodeType.setElementId("osgiliath");
    indexedNodeType.setArchiveName("middleEarth");
    indexedNodeType.setArchiveVersion("1.0.0");
    indexedNodeType.setCreationDate(new Date());
    indexedNodeType.setLastUpdateDate(new Date());
    indexedNodeType.setDefaultCapabilities(null);
    dao.save(indexedNodeType);
    String osgiliath100Id = indexedNodeType.getId();
    // perform scoring
    scoreService.run();
    // check that order on query is correct
    GetMultipleDataResult data = dao.search(NodeType.class, "", null, AlienConstants.DEFAULT_ES_SEARCH_SIZE);
    Assert.assertEquals(5, data.getData().length);
    Assert.assertEquals(isengard101Id, ((NodeType) data.getData()[0]).getId());
    Assert.assertEquals(1011, ((NodeType) data.getData()[0]).getAlienScore());
    Assert.assertEquals(mordor101Id, ((NodeType) data.getData()[1]).getId());
    Assert.assertEquals(1010, ((NodeType) data.getData()[1]).getAlienScore());
    Assert.assertEquals(osgiliath100Id, ((NodeType) data.getData()[2]).getId());
    Assert.assertEquals(1000, ((NodeType) data.getData()[2]).getAlienScore());
    Assert.assertEquals(mordor100Id, ((NodeType) data.getData()[3]).getId());
    Assert.assertEquals(10, ((NodeType) data.getData()[3]).getAlienScore());
    Assert.assertEquals(isengard100Id, ((NodeType) data.getData()[4]).getId());
    Assert.assertEquals(0, ((NodeType) data.getData()[4]).getAlienScore());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Topology(org.alien4cloud.tosca.model.templates.Topology) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Date(java.util.Date) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test)

Example 5 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class DefaultNodeMatcherTest method unknown_type_from_topology_should_not_match_any_location_resource.

@Test
public void unknown_type_from_topology_should_not_match_any_location_resource() throws Exception {
    // Given
    Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>();
    // When
    NodeTemplate wantedNodeTemplate = nodeTemplate("tosca.nodes.Unknown");
    NodeType wantedNodeType = new NodeType();
    List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, wantedNodeType, locationResources, emptyMatchingConfigurations);
    // Then
    assertThat(proposition).hasSize(0);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) HashMap(java.util.HashMap) MatchingConfiguration(alien4cloud.model.deployment.matching.MatchingConfiguration) NodeType(org.alien4cloud.tosca.model.types.NodeType) Test(org.junit.Test)

Aggregations

NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)162 NodeType (org.alien4cloud.tosca.model.types.NodeType)52 Map (java.util.Map)40 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)37 Test (org.junit.Test)32 Capability (org.alien4cloud.tosca.model.templates.Capability)27 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)25 Topology (org.alien4cloud.tosca.model.templates.Topology)22 NotFoundException (alien4cloud.exception.NotFoundException)17 Then (cucumber.api.java.en.Then)15 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)15 HashMap (java.util.HashMap)14 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)13 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)13 TopologyDTO (alien4cloud.topology.TopologyDTO)12 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)12 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)11 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)11 DeploymentArtifact (org.alien4cloud.tosca.model.definitions.DeploymentArtifact)10 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)10