use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class ToscaParserAlien200Test method parsingInvalidTargetInWorkflowStepShouldFail.
@Test
public void parsingInvalidTargetInWorkflowStepShouldFail() throws ParsingException {
Mockito.reset(csarRepositorySearchService);
Mockito.when(csarRepositorySearchService.getArchive("tosca-normative-types", "1.0.0-ALIEN14")).thenReturn(Mockito.mock(Csar.class));
NodeType mockType = Mockito.mock(NodeType.class);
Mockito.when(mockType.isAbstract()).thenReturn(true);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockType);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockType);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-workflow-invalid-target.yml"));
assertEquals(1, parsingResult.getContext().getParsingErrors().size());
assertEquals(ErrorCode.UNKNWON_WORKFLOW_STEP_TARGET, parsingResult.getContext().getParsingErrors().get(0).getErrorCode());
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class ToscaParserAlien200Test method policyTemplateParsingWithUnknownTargetShouldFail.
@Test
public void policyTemplateParsingWithUnknownTargetShouldFail() throws ParsingException {
Mockito.reset(csarRepositorySearchService);
Mockito.when(csarRepositorySearchService.getArchive("tosca-normative-types", "1.0.0-ALIEN14")).thenReturn(Mockito.mock(Csar.class));
NodeType nodeType = new NodeType();
nodeType.setElementId("tosca.nodes.Compute");
nodeType.setArchiveName("tosca-normative-types");
nodeType.setArchiveVersion("1.0.0-ALIEN14");
nodeType.setDerivedFrom(Lists.newArrayList("tosca.nodes.Root"));
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(nodeType);
nodeType = new NodeType();
nodeType.setElementId("tosca.nodes.Root");
nodeType.setArchiveName("tosca-normative-types");
nodeType.setArchiveVersion("1.0.0-ALIEN14");
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(nodeType);
PolicyType policyType = new PolicyType();
policyType.setAbstract(true);
policyType.setElementId("org.alien4cloud.sample.SamplePolicy");
policyType.setArchiveName("org.alien4cloud.test.policies.PolicyTemplate");
policyType.setArchiveVersion("2.0.0-SNAPSHOT");
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(PolicyType.class), Mockito.eq("org.alien4cloud.sample.SamplePolicy"), Mockito.any(Set.class))).thenReturn(policyType);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-policy-template-fail.yml"));
assertEquals(1, parsingResult.getContext().getParsingErrors().size());
assertEquals(1, countErrorByLevelAndCode(parsingResult, ParsingErrorLevel.ERROR, ErrorCode.POLICY_TARGET_NOT_FOUND));
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class ToscaParserAlien200Test method parseTopologyTemplateWithRelationshipWorkflow.
@Test
public void parseTopologyTemplateWithRelationshipWorkflow() throws ParsingException {
Mockito.reset(csarRepositorySearchService);
Mockito.when(csarRepositorySearchService.getArchive("tosca-normative-types", "1.0.0-ALIEN14")).thenReturn(Mockito.mock(Csar.class));
NodeType mockCompute = new NodeType();
mockCompute.setElementId(NormativeComputeConstants.COMPUTE_TYPE);
mockCompute.setArchiveName("tosca-normative-types");
mockCompute.setArchiveVersion("1.0.0-ALIEN14");
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq(NormativeComputeConstants.COMPUTE_TYPE), Mockito.any(Set.class))).thenReturn(mockCompute);
RelationshipType mockHostedOn = Mockito.mock(RelationshipType.class);
Mockito.when(mockHostedOn.getElementId()).thenReturn(NormativeRelationshipConstants.HOSTED_ON);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq(NormativeRelationshipConstants.HOSTED_ON), Mockito.any(Set.class))).thenReturn(mockHostedOn);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-relationship-workflow.yml"));
Assert.assertFalse(parsingResult.getResult().getTopology().getWorkflows().isEmpty());
Assert.assertTrue(parsingResult.getResult().getTopology().getWorkflows().get("install") != null);
Workflow wf = parsingResult.getResult().getTopology().getWorkflows().get("install");
WorkflowStep relStep = wf.getSteps().get("OracleJDK_hostedOnComputeHost_pre_configure_source");
Assert.assertNotNull(relStep);
Assert.assertTrue(relStep instanceof RelationshipWorkflowStep);
RelationshipWorkflowStep relationshipWorkflowStep = (RelationshipWorkflowStep) relStep;
Assert.assertNotNull(relationshipWorkflowStep.getTargetRelationship());
Assert.assertNotNull(relationshipWorkflowStep.getSourceHostId());
Assert.assertNotNull(relationshipWorkflowStep.getTargetHostId());
WorkflowStep nStep = wf.getSteps().get("OracleJDK_start");
Assert.assertNotNull(nStep);
Assert.assertTrue(nStep instanceof NodeWorkflowStep);
NodeWorkflowStep nodeWorkflowStep = (NodeWorkflowStep) nStep;
Assert.assertNotNull(nodeWorkflowStep.getHostId());
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class NodeTemplateRelationshipPostProcessor method process.
@Override
public void process(NodeTemplate instance) {
final NodeType nodeType = ToscaContext.get(NodeType.class, instance.getType());
if (nodeType == null) {
// error managed by the reference post processor.
return;
}
Map<String, RelationshipTemplate> updated = Maps.newLinkedHashMap();
safe(instance.getRelationships()).entrySet().forEach(entry -> {
relationshipPostProcessor.process(nodeType, entry);
String relationshipTemplateName = entry.getValue().getName();
if (StringUtils.isEmpty(relationshipTemplateName)) {
// from 2.0.0 the relationship's name is filled by the parser
relationshipTemplateName = buildRelationShipTemplateName(entry.getValue());
}
relationshipTemplateName = getUniqueKey(updated, relationshipTemplateName);
updated.put(relationshipTemplateName, entry.getValue());
entry.getValue().setName(relationshipTemplateName);
});
instance.setRelationships(updated);
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class DanglingRequirementService method addDanglingNodes.
private void addDanglingNodes(Topology topology, TopologyContext topologyContext, NodeTemplate nodeTemplate, RequirementDefinition requirementDefinition, int count) {
// TODO If the TOSCA context does not has the TOSCA normative types then add it automatically
String danglingTemplateType = requirementDefinition.getNodeType() == null ? NormativeTypesConstant.ROOT_NODE_TYPE : requirementDefinition.getNodeType();
NodeType danglingNodeType = ToscaContext.get(NodeType.class, danglingTemplateType);
List<CapabilityDefinition> compatibleCapabilityByType = capabilityMatcherService.getCompatibleCapabilityByType(danglingNodeType, requirementDefinition.getType());
CapabilityDefinition targetCapabilityDefinition = compatibleCapabilityByType.size() == 0 ? null : compatibleCapabilityByType.get(0);
RelationshipType danglingRelationshipType = fetchValidRelationshipType(requirementDefinition, targetCapabilityDefinition);
// check if the type is scalable (then count is used as a scalability parameter) or if we should add multiple instances
CapabilityDefinition scalable = NodeTypeUtils.getCapabilityByType(danglingNodeType, NormativeCapabilityTypes.SCALABLE);
if (scalable == null) {
scalable = NodeTypeUtils.getCapabilityByType(danglingNodeType, AlienCapabilityTypes.CLUSTER_CONTROLLER);
}
List<NodeTemplate> addedNodes = Lists.newArrayList();
if (scalable == null) {
for (int i = 0; i < count; i++) {
NodeTemplate addedNode = addDanglingNode(topology, topologyContext, nodeTemplate, requirementDefinition, danglingNodeType, danglingRelationshipType, targetCapabilityDefinition);
addedNodes.add(addedNode);
}
} else {
NodeTemplate danglingTemplate = addDanglingNode(topology, topologyContext, nodeTemplate, requirementDefinition, danglingNodeType, danglingRelationshipType, targetCapabilityDefinition);
Capability scalableCapability = danglingTemplate.getCapabilities().get(scalable.getId());
TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, count, scalableCapability);
TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_MAX_INSTANCES, requirementDefinition.getUpperBound(), scalableCapability);
addedNodes.add(danglingTemplate);
}
// Recursively add dangling nodes.
for (NodeTemplate addedNode : addedNodes) {
addDanglingRequirements(topology, topologyContext, addedNode, null);
}
}
Aggregations