Search in sources :

Example 1 with Topology

use of org.alien4cloud.tosca.model.templates.Topology 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 2 with Topology

use of org.alien4cloud.tosca.model.templates.Topology 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 3 with Topology

use of org.alien4cloud.tosca.model.templates.Topology 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 4 with Topology

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

the class FunctionEvaluatorTest method testParseAttributConcatScalar.

@Test
public void testParseAttributConcatScalar() {
    Map<String, NodeTemplate> nodeTemplates = Maps.newHashMap();
    NodeTemplate nodeTemplate1 = new NodeTemplate();
    nodeTemplate1.setProperties(MapUtil.newHashMap(new String[] { "the_property_name_1" }, new AbstractPropertyValue[] { new ScalarPropertyValue("the_property_value_1") }));
    nodeTemplates.put("the_node_tempalte_1", nodeTemplate1);
    NodeTemplate nodeTemplate2 = new NodeTemplate();
    nodeTemplate2.setProperties(MapUtil.newHashMap(new String[] { "the_property_name_2" }, new AbstractPropertyValue[] { new ScalarPropertyValue("the_property_value_2") }));
    nodeTemplates.put("the_node_tempalte_2", nodeTemplate2);
    Topology topology = new Topology();
    topology.setNodeTemplates(nodeTemplates);
    Map<String, Map<String, InstanceInformation>> runtimeInformations = Maps.newHashMap();
    // Create a IAttributeValue
    ConcatPropertyValue concatAttributeValue = new ConcatPropertyValue();
    ScalarPropertyValue scalarParameter1 = new ScalarPropertyValue();
    ScalarPropertyValue scalarParameter2 = new ScalarPropertyValue();
    ScalarPropertyValue scalarParameter3 = new ScalarPropertyValue();
    ScalarPropertyValue scalarParameter4 = new ScalarPropertyValue();
    scalarParameter1.setValue("http://");
    scalarParameter2.setValue("mywebsiteurl");
    scalarParameter3.setValue(":");
    scalarParameter4.setValue("port");
    concatAttributeValue.setParameters(new ArrayList<>());
    concatAttributeValue.getParameters().add(scalarParameter1);
    concatAttributeValue.getParameters().add(scalarParameter2);
    concatAttributeValue.getParameters().add(scalarParameter3);
    concatAttributeValue.getParameters().add(scalarParameter4);
    String parsedConcatString = FunctionEvaluator.parseAttribute(null, concatAttributeValue, topology, runtimeInformations, "0", null, null);
    String fullUrl = scalarParameter1.getValue() + scalarParameter2.getValue() + scalarParameter3.getValue() + scalarParameter4.getValue();
    Assert.assertEquals(fullUrl, parsedConcatString);
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Topology(org.alien4cloud.tosca.model.templates.Topology) Map(java.util.Map) Test(org.junit.Test) AbstractToscaParserSimpleProfileTest(alien4cloud.tosca.parser.AbstractToscaParserSimpleProfileTest)

Example 5 with Topology

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

the class FunctionEvaluatorTest method postConstruct.

@PostConstruct
public void postConstruct() throws Throwable {
    if (!INITIALIZED) {
        if (Files.exists(Paths.get(alienRepoDir))) {
            try {
                FileUtil.delete(Paths.get(alienRepoDir));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        SecurityTestUtils.setTestAuthentication(Role.ADMIN);
        alienDAO.delete(Csar.class, QueryBuilders.matchAllQuery());
        String normativeLocalName = "tosca-normative-types";
        repositoryManager.cloneOrCheckout(artifactsDirectory, "https://github.com/alien4cloud/tosca-normative-types.git", "1.2.0", normativeLocalName);
        String sampleLocalName = "samples";
        repositoryManager.cloneOrCheckout(artifactsDirectory, "https://github.com/alien4cloud/samples.git", "1.4.0-RC1", sampleLocalName);
        Path typesPath = artifactsDirectory.resolve(normativeLocalName);
        Path typesZipPath = artifactsDirectory.resolve(normativeLocalName + ".zip");
        FileUtil.zip(typesPath, typesZipPath);
        ParsingResult<Csar> result = archiveUploadService.upload(typesZipPath, CSARSource.OTHER, AlienConstants.GLOBAL_WORKSPACE_ID);
        ParserTestUtil.displayErrors(result);
        AbstractToscaParserSimpleProfileTest.assertNoBlocker(result);
        // typesPath = artifactsDirectory.resolve(extendedLocalName).resolve("alien-base-types");
        // typesZipPath = artifactsDirectory.resolve("alien-base-types.zip");
        // FileUtil.zip(typesPath, typesZipPath);
        // result = archiveUploadService.upload(typesZipPath, CSARSource.OTHER, AlienConstants.GLOBAL_WORKSPACE_ID);
        // AbstractToscaParserSimpleProfileTest.assertNoBlocker(result);
        typesPath = artifactsDirectory.resolve(sampleLocalName).resolve("jdk");
        typesZipPath = artifactsDirectory.resolve("jdk.zip");
        FileUtil.zip(typesPath, typesZipPath);
        result = archiveUploadService.upload(typesZipPath, CSARSource.OTHER, AlienConstants.GLOBAL_WORKSPACE_ID);
        AbstractToscaParserSimpleProfileTest.assertNoBlocker(result);
        typesPath = artifactsDirectory.resolve(sampleLocalName).resolve("tomcat-war");
        typesZipPath = artifactsDirectory.resolve("tomcat_war.zip");
        FileUtil.zip(typesPath, typesZipPath);
        result = archiveUploadService.upload(typesZipPath, CSARSource.OTHER, AlienConstants.GLOBAL_WORKSPACE_ID);
        AbstractToscaParserSimpleProfileTest.assertNoBlocker(result);
        typesPath = Paths.get("src/test/resources/alien4cloud/paas/function/test-types");
        typesZipPath = artifactsDirectory.resolve("target/test-types.zip");
        FileUtil.zip(typesPath, typesZipPath);
        result = archiveUploadService.upload(typesZipPath, CSARSource.OTHER, AlienConstants.GLOBAL_WORKSPACE_ID);
        AbstractToscaParserSimpleProfileTest.assertNoBlocker(result);
        INITIALIZED = true;
    }
    ParsingResult<ArchiveRoot> result = applicationUtil.parseYamlTopology("src/test/resources/alien4cloud/paas/function/topology/badFunctionsTomcatWar");
    // AbstractToscaParserSimpleProfileTest.assertNoBlocker(result);
    Topology topology = result.getResult().getTopology();
    topology.setId(UUID.randomUUID().toString());
    topology.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
    builtPaaSNodeTemplates = treeBuilder.buildPaaSTopology(topology).getAllNodes();
}
Also used : Path(java.nio.file.Path) Csar(org.alien4cloud.tosca.model.Csar) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) IOException(java.io.IOException) Topology(org.alien4cloud.tosca.model.templates.Topology) PostConstruct(javax.annotation.PostConstruct)

Aggregations

Topology (org.alien4cloud.tosca.model.templates.Topology)79 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)22 Map (java.util.Map)21 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)17 Csar (org.alien4cloud.tosca.model.Csar)16 Application (alien4cloud.model.application.Application)15 NotFoundException (alien4cloud.exception.NotFoundException)14 ApiOperation (io.swagger.annotations.ApiOperation)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)12 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)9 FlowExecutionContext (org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext)9 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 IOException (java.io.IOException)8 List (java.util.List)8 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)8 Component (org.springframework.stereotype.Component)8 Audit (alien4cloud.audit.annotation.Audit)7