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();
}
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());
}
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"));
}
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;
}
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);
}
Aggregations