use of org.alien4cloud.tosca.model.templates.NodeTemplate 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);
}
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate 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.NodeTemplate 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.NodeTemplate 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.NodeTemplate in project alien4cloud by alien4cloud.
the class DefaultNodeMatcherTest method unknown_type_from_topology_should_not_match_any_location_resource.
@Test
public void unknown_type_from_topology_should_not_match_any_location_resource() throws Exception {
// Given
Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>();
// When
NodeTemplate wantedNodeTemplate = nodeTemplate("tosca.nodes.Unknown");
NodeType wantedNodeType = new NodeType();
List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, wantedNodeType, locationResources, emptyMatchingConfigurations);
// Then
assertThat(proposition).hasSize(0);
}
Aggregations