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