Search in sources :

Example 1 with PaaSNodeTemplate

use of alien4cloud.paas.model.PaaSNodeTemplate in project yorc-a4c-plugin by ystia.

the class ShowTopology method topologyInLog.

/**
 * Log topology infos for debugging
 * @param ctx
 */
public static void topologyInLog(PaaSTopologyDeploymentContext ctx) {
    String paasId = ctx.getDeploymentPaaSId();
    PaaSTopology ptopo = ctx.getPaaSTopology();
    DeploymentTopology dtopo = ctx.getDeploymentTopology();
    // Deployment Workflows
    Map<String, Workflow> workflows = dtopo.getWorkflows();
    for (String wfname : workflows.keySet()) {
        log.debug("***** Workflow " + wfname);
        Workflow wf = workflows.get(wfname);
        log.debug("name: " + wf.getName());
        log.debug("host: " + wf.getHosts().toString());
        log.debug("steps: " + wf.getSteps().keySet().toString());
    }
    // Deployment Groups
    Map<String, NodeGroup> groups = dtopo.getGroups();
    if (groups != null) {
        for (String grname : groups.keySet()) {
            NodeGroup group = groups.get(grname);
            log.debug("***** Group " + grname);
            log.debug("name: " + group.getName());
            log.debug("members: " + group.getMembers().toString());
        }
    }
    // PaaS Compute Nodes
    for (PaaSNodeTemplate node : ptopo.getAllNodes().values()) {
        printNode(node);
    }
}
Also used : PaaSTopology(alien4cloud.paas.model.PaaSTopology) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

Example 2 with PaaSNodeTemplate

use of alien4cloud.paas.model.PaaSNodeTemplate 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 3 with PaaSNodeTemplate

use of alien4cloud.paas.model.PaaSNodeTemplate in project yorc-a4c-plugin by ystia.

the class DeployTask method buildZip.

/**
 * Create the zip for yorc, with a modified yaml and all needed archives.
 * Assumes a file original.yml exists in the current directory
 * @param ctx all needed information about the deployment
 * @throws IOException
 */
private void buildZip(PaaSTopologyDeploymentContext ctx) throws IOException {
    // Check location
    int location = LOC_OPENSTACK;
    Location loc = ctx.getLocations().get("_A4C_ALL");
    Set<CSARDependency> locdeps = loc.getDependencies();
    for (CSARDependency dep : locdeps) {
        if (dep.getName().contains("kubernetes")) {
            location = LOC_KUBERNETES;
            break;
        }
        if (dep.getName().contains("slurm")) {
            location = LOC_SLURM;
            break;
        }
        if (dep.getName().contains("aws")) {
            location = LOC_AWS;
            break;
        }
    }
    // Final zip file will be named topology.zip
    final File zip = new File("topology.zip");
    final OutputStream out = new FileOutputStream(zip);
    final ZipOutputStream zout = new ZipOutputStream(out);
    final Closeable res = zout;
    final int finalLocation = location;
    this.ctx.getDeploymentTopology().getDependencies().forEach(d -> {
        if (!"tosca-normative-types".equals(d.getName())) {
            Csar csar = csarRepoSearchService.getArchive(d.getName(), d.getVersion());
            if (CSARSource.ORCHESTRATOR != CSARSource.valueOf(csar.getImportSource())) {
                try {
                    csar2zip(zout, csar, finalLocation);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    });
    // Copy overwritten artifacts for each node
    PaaSTopology ptopo = ctx.getPaaSTopology();
    for (PaaSNodeTemplate node : ptopo.getAllNodes().values()) {
        copyArtifacts(node, zout);
    }
    String topoFileName = "topology.yml";
    // Copy modified topology
    createZipEntries(topoFileName, zout);
    // Get the yaml of the application as built by from a4c
    DeploymentTopology dtopo = ctx.getDeploymentTopology();
    Csar myCsar = new Csar(ctx.getDeploymentPaaSId(), dtopo.getArchiveVersion());
    myCsar.setToscaDefinitionsVersion(ToscaParser.LATEST_DSL);
    String yaml = orchestrator.getToscaTopologyExporter().getYaml(myCsar, dtopo, true);
    zout.write(yaml.getBytes(Charset.forName("UTF-8")));
    zout.closeEntry();
    res.close();
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) PaaSTopology(alien4cloud.paas.model.PaaSTopology) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Closeable(java.io.Closeable) ZipException(java.util.zip.ZipException) YorcRestException(org.ystia.yorc.alien4cloud.plugin.rest.YorcRestException) ParsingException(alien4cloud.tosca.parser.ParsingException) IOException(java.io.IOException) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Location(alien4cloud.model.orchestrators.locations.Location)

Example 4 with PaaSNodeTemplate

use of alien4cloud.paas.model.PaaSNodeTemplate in project alien4cloud by alien4cloud.

the class FunctionEvaluatorTest method nodeTemplatesGetPropertyKeywordsSucessTest.

@Test
public void nodeTemplatesGetPropertyKeywordsSucessTest() throws Throwable {
    String computeName = "comp_tomcat_war";
    PaaSNodeTemplate computePaaS = builtPaaSNodeTemplates.get(computeName);
    Operation configOp = computePaaS.getIndexedToscaElement().getInterfaces().get(ToscaNodeLifecycleConstants.STANDARD).getOperations().get(ToscaNodeLifecycleConstants.CONFIGURE);
    IValue param = configOp.getInputParameters().get("customHostName");
    Assert.assertEquals(getPropertyValue(computePaaS, "customHostName"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, computePaaS, builtPaaSNodeTemplates));
    // HOST keyword
    String tomcatName = "tomcat";
    String warName = "war_1";
    PaaSNodeTemplate tomcatPaaS = builtPaaSNodeTemplates.get(tomcatName);
    PaaSNodeTemplate warPaaS = builtPaaSNodeTemplates.get(warName);
    Operation op = warPaaS.getIndexedToscaElement().getInterfaces().get("custom").getOperations().get("update_war_file");
    param = op.getInputParameters().get("TOMCAT_HOME");
    Assert.assertEquals(getPropertyValue(tomcatPaaS, "tomcat_home"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, warPaaS, builtPaaSNodeTemplates));
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) Test(org.junit.Test) AbstractToscaParserSimpleProfileTest(alien4cloud.tosca.parser.AbstractToscaParserSimpleProfileTest)

Example 5 with PaaSNodeTemplate

use of alien4cloud.paas.model.PaaSNodeTemplate in project alien4cloud by alien4cloud.

the class FunctionEvaluatorTest method relationshipGetPropertyKeywordsSucessTest.

@Test
public void relationshipGetPropertyKeywordsSucessTest() throws Throwable {
    String warName = "war_1";
    String warName_2 = "war_2";
    String tomcatName = "tomcat";
    String computeName = "comp_tomcat_war";
    PaaSNodeTemplate warPaaS = builtPaaSNodeTemplates.get(warName);
    PaaSNodeTemplate warPaaS_2 = builtPaaSNodeTemplates.get(warName_2);
    PaaSNodeTemplate tomcatPaaS = builtPaaSNodeTemplates.get(tomcatName);
    PaaSNodeTemplate computePaaS = builtPaaSNodeTemplates.get(computeName);
    PaaSRelationshipTemplate hostedOnRelTemp = warPaaS.getRelationshipTemplate("warHostedOnTomcatTomcat", "war_1");
    PaaSRelationshipTemplate hostedOnRelTemp_2 = warPaaS_2.getRelationshipTemplate("warHostedOnTomcatTomcat", "war_2");
    Operation configOp = hostedOnRelTemp.getIndexedToscaElement().getInterfaces().get(ToscaRelationshipLifecycleConstants.CONFIGURE).getOperations().get(ToscaRelationshipLifecycleConstants.POST_CONFIGURE_SOURCE);
    // test SOURCE keyword
    IValue param = configOp.getInputParameters().get("contextPath");
    Assert.assertEquals(getPropertyValue(warPaaS, "context_path"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
    // get prop from the host of the source node
    param = configOp.getInputParameters().get("propFromSourceCompute");
    Assert.assertEquals(getPropertyValue(computePaaS, "customHostName"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
    // test TARGET keyword
    param = configOp.getInputParameters().get("tomcatVersion");
    Assert.assertEquals(getPropertyValue(tomcatPaaS, "component_version"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
    // get prop from the host of the source node
    param = configOp.getInputParameters().get("propFromTargetCompute");
    Assert.assertEquals(getPropertyValue(computePaaS, "customHostName"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
    // test SELF keyword on relationship
    param = configOp.getInputParameters().get("relName");
    Assert.assertEquals(getPropertyValue(hostedOnRelTemp, "relName"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
    Assert.assertEquals(getPropertyValue(hostedOnRelTemp_2, "relName"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp_2, builtPaaSNodeTemplates));
    // getting capability properties
    param = configOp.getInputParameters().get("valid_node_types");
    Assert.assertEquals(getCapabilityPropertyValue(tomcatPaaS, "war_host", "valid_node_types"), FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
    // capabilities not existing in the node
    param = configOp.getInputParameters().get("null_capa_prop1");
    Assert.assertEquals(null, FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
    // property not existing in the capability
    param = configOp.getInputParameters().get("null_capa_prop2");
    Assert.assertEquals(null, FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
    // using SELF keywork to get a capability's property on a relationship should return null
    param = configOp.getInputParameters().get("bad_valid_node_types");
    Assert.assertEquals(null, FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, hostedOnRelTemp, builtPaaSNodeTemplates));
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate) Test(org.junit.Test) AbstractToscaParserSimpleProfileTest(alien4cloud.tosca.parser.AbstractToscaParserSimpleProfileTest)

Aggregations

PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)21 PaaSRelationshipTemplate (alien4cloud.paas.model.PaaSRelationshipTemplate)7 Test (org.junit.Test)7 AbstractToscaParserSimpleProfileTest (alien4cloud.tosca.parser.AbstractToscaParserSimpleProfileTest)5 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)5 PaaSTopology (alien4cloud.paas.model.PaaSTopology)4 Capability (org.alien4cloud.tosca.model.templates.Capability)3 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)2 NodeGroup (org.alien4cloud.tosca.model.templates.NodeGroup)2 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)2 Location (alien4cloud.model.orchestrators.locations.Location)1 ParsingException (alien4cloud.tosca.parser.ParsingException)1 Closeable (java.io.Closeable)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1