use of org.alien4cloud.tosca.model.Csar in project yorc-a4c-plugin by ystia.
the class ToscaExportersTest method testComponentSerialization.
@Test
public void testComponentSerialization() throws Exception {
Mockito.reset(repositorySearchService);
String rootDir = "src/test/resources/org/ystia/yorc/alien4cloud/plugin/tosca";
Csar csar = new Csar("tosca-normative-types", "1.0.0-ALIEN20");
Mockito.when(repositorySearchService.getArchive(csar.getName(), csar.getVersion())).thenReturn(csar);
NodeType mockedResult = Mockito.mock(NodeType.class);
Mockito.when(mockedResult.getArchiveName()).thenReturn("tosca-normative-types");
Mockito.when(mockedResult.getArchiveVersion()).thenReturn("1.0.0-ALIEN20");
DeploymentArtifact da = Mockito.mock(DeploymentArtifact.class);
Mockito.when(da.getArtifactPath()).thenReturn("test");
Mockito.when(da.getArtifactRef()).thenReturn("test");
Mockito.when(da.getArtifactType()).thenReturn("file");
Mockito.when(da.getArchiveName()).thenReturn("tosca-normative-types");
Mockito.when(da.getArchiveVersion()).thenReturn("1.0.0-ALIEN20");
Mockito.when(mockedResult.getArtifacts()).thenReturn(Collections.singletonMap("SoftwareComponentArtifact", da));
Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(mockedResult.getDerivedFrom()).thenReturn(Lists.newArrayList("tosca.nodes.Root"));
Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(DataType.class), Mockito.eq(NormativeCredentialConstant.DATA_TYPE), Mockito.any(Set.class))).thenReturn(Mockito.mock(DataType.class));
RelationshipType hostedOn = new RelationshipType();
Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(hostedOn);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(rootDir, "tosca_component_input.yaml"));
System.out.println(parsingResult.getContext().getParsingErrors());
assertNoBlocker(parsingResult);
String resultYaml = toscaComponentExporter.getYaml(parsingResult.getResult());
System.out.println(resultYaml);
String expectedResult = FileUtils.readFileToString(Paths.get(rootDir, "tosca_component_output.yaml").toFile(), "UTF-8");
// Make some whitespaces change here as IDEs have auto-format features that will overwrite them in the file
expectedResult = expectedResult.replaceAll("verbose:\\n", "verbose: \n");
expectedResult = expectedResult.replaceAll("default:\\n", "default: \n");
Assert.assertEquals(expectedResult, resultYaml);
}
use of org.alien4cloud.tosca.model.Csar 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
}
}));
}
use of org.alien4cloud.tosca.model.Csar 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.Csar 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();
}
use of org.alien4cloud.tosca.model.Csar 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