Search in sources :

Example 1 with CSARDependency

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

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

use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.

the class DeploymentServiceTest method isArchiveDeployedTest.

@Test
public void isArchiveDeployedTest() {
    DeploymentTopology deploymentTopology = new DeploymentTopology();
    deploymentTopology.setId("id");
    deploymentTopology.setDeployed(false);
    deploymentTopology.setDependencies(Sets.newHashSet(new CSARDependency("toto", "2.0.0")));
    alienMonitorDao.save(deploymentTopology);
    deploymentTopology.setId("id2");
    deploymentTopology.setDeployed(true);
    deploymentTopology.setDependencies(Sets.newHashSet(new CSARDependency("tata", "1.0.0")));
    alienMonitorDao.save(deploymentTopology);
    deploymentTopology.setId("id3");
    deploymentTopology.setDeployed(true);
    deploymentTopology.setDependencies(Sets.newHashSet(new CSARDependency("toto", "1.0.0")));
    alienMonitorDao.save(deploymentTopology);
    Assert.assertFalse(deploymentService.isArchiveDeployed("toto", "2.0.0"));
    deploymentTopology.setId("id");
    deploymentTopology.setDeployed(true);
    deploymentTopology.setDependencies(Sets.newHashSet(new CSARDependency("toto", "2.0.0")));
    alienMonitorDao.save(deploymentTopology);
    Assert.assertTrue(deploymentService.isArchiveDeployed("toto", "2.0.0"));
}
Also used : DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test)

Example 4 with CSARDependency

use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.

the class EditorTopologyRecoveryHelperService method buildRecoveryOperations.

/**
 * Given a set of dependencies, analyse a given topology and build a list of {@link AbstractEditorOperation} to apply to the topology to make it synch
 * with the dependencies present in the repository
 *
 * @param topology The topology we want to recover
 * @param updatedDependencies The updated dependencies within the topology
 * @return a list of {@link AbstractEditorOperation} representing the operations to perform on the topology for recovery
 */
public List<AbstractEditorOperation> buildRecoveryOperations(Topology topology, Set<CSARDependency> updatedDependencies) {
    List<AbstractEditorOperation> recoveryOperations = Lists.newArrayList();
    if (!topology.isEmpty()) {
        for (CSARDependency updatedDependency : AlienUtils.safe(updatedDependencies)) {
            buildNodesRecoveryOperations(topology, updatedDependency, recoveryOperations);
            buildRelationshipsRecoveryOperations(topology, updatedDependency, recoveryOperations);
        }
    }
    return recoveryOperations;
}
Also used : AbstractEditorOperation(org.alien4cloud.tosca.editor.operations.AbstractEditorOperation) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 5 with CSARDependency

use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.

the class CsarServiceTest method isArchiveDeployedTest.

@Test
public void isArchiveDeployedTest() throws ExecutionException, InterruptedException {
    alienDao.getClient().prepareDeleteByQuery(new String[] { "csar" }).setQuery(QueryBuilders.matchAllQuery()).execute().get();
    Csar csar = new Csar("archive", "1.0.0-SNAPSHOT");
    csar.setDependencies(Sets.newHashSet(new CSARDependency("toto", "1.0.0"), new CSARDependency("titi", "2.0.0")));
    alienDao.save(csar);
    csar = new Csar("archive2", "1.0.0-SNAPSHOT");
    csar.setDependencies(Sets.newHashSet(new CSARDependency("tata", "1.0.0"), new CSARDependency("tutu", "2.0.0")));
    alienDao.save(csar);
    Csar[] csars = csarService.getDependantCsars("toto", "2.0.0");
    Assert.assertEquals(0, csars.length);
    csar = new Csar("archive3", "1.0.0-SNAPSHOT");
    csar.setDependencies(Sets.newHashSet(new CSARDependency("tata", "1.0.0"), new CSARDependency("toto", "2.0.0")));
    alienDao.save(csar);
    csars = csarService.getDependantCsars("toto", "2.0.0");
    Assert.assertEquals(1, csars.length);
    csar = new Csar("archive4", "1.0.0-SNAPSHOT");
    csar.setDependencies(Sets.newHashSet(new CSARDependency("tata", "1.0.0"), new CSARDependency("toto", "2.0.0")));
    alienDao.save(csar);
    csars = csarService.getDependantCsars("toto", "2.0.0");
    Assert.assertEquals(2, csars.length);
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test)

Aggregations

CSARDependency (org.alien4cloud.tosca.model.CSARDependency)50 Csar (org.alien4cloud.tosca.model.Csar)16 Test (org.junit.Test)11 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)8 Set (java.util.Set)7 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)6 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)6 ServiceResource (alien4cloud.model.service.ServiceResource)5 Capability (org.alien4cloud.tosca.model.templates.Capability)5 Topology (org.alien4cloud.tosca.model.templates.Topology)5 NodeType (org.alien4cloud.tosca.model.types.NodeType)5 NotFoundException (alien4cloud.exception.NotFoundException)4 ParsingError (alien4cloud.tosca.parser.ParsingError)4 HashSet (java.util.HashSet)4 CsarDependenciesBean (org.alien4cloud.tosca.model.CsarDependenciesBean)4 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)3 ParsingException (alien4cloud.tosca.parser.ParsingException)3 VersionConflictException (alien4cloud.exception.VersionConflictException)2 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)2 Location (alien4cloud.model.orchestrators.locations.Location)2