Search in sources :

Example 46 with NodeType

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());
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) Test(org.junit.Test)

Example 47 with NodeType

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));
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) PolicyType(org.alien4cloud.tosca.model.types.PolicyType) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) Test(org.junit.Test)

Example 48 with NodeType

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());
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) Test(org.junit.Test)

Example 49 with NodeType

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);
}
Also used : RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType)

Example 50 with NodeType

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);
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) EqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)

Aggregations

NodeType (org.alien4cloud.tosca.model.types.NodeType)156 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)50 Test (org.junit.Test)44 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)26 Set (java.util.Set)26 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)23 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)22 Map (java.util.Map)19 Csar (org.alien4cloud.tosca.model.Csar)19 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)16 HashMap (java.util.HashMap)15 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)15 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)14 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)14 Topology (org.alien4cloud.tosca.model.templates.Topology)9 NotFoundException (alien4cloud.exception.NotFoundException)8 Capability (org.alien4cloud.tosca.model.templates.Capability)8 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)8 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)7 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7