Search in sources :

Example 16 with RequirementDefinition

use of org.alien4cloud.tosca.model.definitions.RequirementDefinition in project alien4cloud by alien4cloud.

the class EditorTopologyRecoveryHelperService method checkRequirement.

/**
 * validate the requirement:<br>
 * <ul>
 * <li>Check that a node still has the requirement, by checking directly from the related node type</li>
 * <li>Check that the requirement type of the node hasn't changed</li>
 * </ul>
 *
 * @param relationshipTemplate The name of the requirement to check
 * @param nodeTemplate The node template in which to check for the requirement
 * @param nodeType
 * @throws InvalidStateException when something is wrong
 */
private void checkRequirement(RelationshipTemplate relationshipTemplate, NodeTemplate nodeTemplate, NodeType nodeType) {
    Map<String, RequirementDefinition> requirementMap = AlienUtils.fromListToMap(nodeType.getRequirements(), "id", true);
    if (!AlienUtils.safe(requirementMap).containsKey(relationshipTemplate.getRequirementName())) {
        throw new InvalidStateException("A requirement with name [" + relationshipTemplate.getName() + "] cannot be found in the node [" + nodeTemplate.getName() + "].");
    }
    // check that the requirement type hasn't changed
    RequirementDefinition requirement = AlienUtils.safe(requirementMap).get(relationshipTemplate.getRequirementName());
    if (!Objects.equals(requirement.getType(), relationshipTemplate.getRequirementType())) {
        // TODO check if this requirement is compatible with the previous one, and mabey try to rebuild the relationship
        throw new InvalidStateException("The type of the requirement [" + relationshipTemplate.getRequirementName() + "], node [" + nodeTemplate.getName() + "] has changed");
    }
}
Also used : RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition)

Example 17 with RequirementDefinition

use of org.alien4cloud.tosca.model.definitions.RequirementDefinition in project alien4cloud by alien4cloud.

the class EsQuickSearchTest method prepareToscaElement.

private void prepareToscaElement() {
    List<CapabilityDefinition> capa = Arrays.asList(new CapabilityDefinition("container", "container", 1), new CapabilityDefinition("container1", "container1", 1), new CapabilityDefinition("container2", "container2", 1), new CapabilityDefinition("container3", "container3", 1));
    List<RequirementDefinition> req = Arrays.asList(new RequirementDefinition("Runtime", "Runtime"), new RequirementDefinition("server", "server"), new RequirementDefinition("blob", "blob"));
    List<String> der = Arrays.asList("app", "Parent2");
    indexedNodeTypeTest = TestModelUtil.createIndexedNodeType("1", "app-1", "1.0", "", capa, req, der, new ArrayList<String>(), null, new Date(), new Date());
    componentDataTest.add(indexedNodeTypeTest);
    capa = Arrays.asList(new CapabilityDefinition("banana", "banana", 1), new CapabilityDefinition("banana1", "banana1", 1), new CapabilityDefinition("container", "container", 1), new CapabilityDefinition("banana3", "banana3", 1), new CapabilityDefinition("zar", "zar", 1));
    req = Arrays.asList(new RequirementDefinition("Pant", "Pant"), new RequirementDefinition("DBZ", "DBZ"), new RequirementDefinition("Animes", "Animes"));
    der = Arrays.asList("Songoku", "Kami");
    indexedNodeTypeTest2 = TestModelUtil.createIndexedNodeType("2", "pokerFace", "1.0", "", capa, req, der, new ArrayList<String>(), null, new Date(), new Date());
    componentDataTest.add(indexedNodeTypeTest2);
}
Also used : ArrayList(java.util.ArrayList) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) Date(java.util.Date)

Example 18 with RequirementDefinition

use of org.alien4cloud.tosca.model.definitions.RequirementDefinition in project alien4cloud by alien4cloud.

the class SearchDefinitionSteps method The_in_the_response_should_all_have_the.

@Then("^The \"([^\"]*)\" in the response should all have the \"([^\"]*)\" \"([^\"]*)\"$")
public void The_in_the_response_should_all_have_the(String searchedComponentType, String propertyValue, String property) throws Throwable {
    RestResponse<FacetedSearchResult> restResponse = JsonUtil.read(Context.getInstance().takeRestResponse(), FacetedSearchResult.class);
    FacetedSearchResult searchResp = restResponse.getData();
    List<Object> resultData = Lists.newArrayList(searchResp.getData());
    if (searchedComponentType.equalsIgnoreCase("node types")) {
        for (Object object : resultData) {
            NodeType idnt = JsonUtil.readObject(JsonUtil.toString(object), NodeType.class);
            switch(property) {
                case "capability":
                    assertNotNull(idnt.getCapabilities());
                    assertTrue(idnt.getCapabilities().contains(new CapabilityDefinition(propertyValue, propertyValue, 1)));
                    break;
                case "requirement":
                    assertNotNull(idnt.getRequirements());
                    assertTrue(idnt.getRequirements().contains(new RequirementDefinition(propertyValue, propertyValue)));
                    break;
                default:
                    break;
            }
        }
    } else if (searchedComponentType.equalsIgnoreCase("relationship types")) {
        for (Object object : resultData) {
            RelationshipType idrt = JsonUtil.readObject(JsonUtil.toString(object), RelationshipType.class);
            switch(property) {
                case "validSource":
                    assertNotNull(idrt.getValidSources());
                    assertTrue(Arrays.equals(new String[] { propertyValue }, idrt.getValidSources()));
                    break;
                default:
                    break;
            }
        }
    }
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult) Then(cucumber.api.java.en.Then)

Example 19 with RequirementDefinition

use of org.alien4cloud.tosca.model.definitions.RequirementDefinition in project alien4cloud by alien4cloud.

the class ToscaParserAlien200Test method parsingInvalidRelationshipTargetInWorkflowStepShouldFail.

@Test
public void parsingInvalidRelationshipTargetInWorkflowStepShouldFail() 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(mockType.getCapabilities()).thenReturn(Lists.newArrayList(new CapabilityDefinition("host", "tosca.capabilities.Container", 1)));
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockType);
    mockType = Mockito.mock(NodeType.class);
    Mockito.when(mockType.getRequirements()).thenReturn(Lists.newArrayList(new RequirementDefinition("host", "tosca.capabilities.Container")));
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockType);
    CapabilityType mockCapaType = Mockito.mock(CapabilityType.class);
    Mockito.when(mockCapaType.getElementId()).thenReturn("tosca.capabilities.Container");
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Container"), Mockito.any(Set.class))).thenReturn(mockCapaType);
    RelationshipType mockRelType = Mockito.mock(RelationshipType.class);
    Mockito.when(mockRelType.getElementId()).thenReturn("tosca.relationships.HostedOn");
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(mockRelType);
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-workflow-relationship-operation-invalid-target.yml"));
    // Same error is duplicated but is it that bad ?
    assertEquals(2, parsingResult.getContext().getParsingErrors().size());
    assertEquals(ErrorCode.UNKNWON_WORKFLOW_STEP_RELATIONSHIP_TARGET, parsingResult.getContext().getParsingErrors().get(0).getErrorCode());
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) Test(org.junit.Test)

Example 20 with RequirementDefinition

use of org.alien4cloud.tosca.model.definitions.RequirementDefinition in project alien4cloud by alien4cloud.

the class TemplateBuilder method fillRequirementsMap.

private static void fillRequirementsMap(Map<String, Requirement> map, List<RequirementDefinition> elements, Map<String, Requirement> mapToMerge, boolean adaptToType) {
    if (elements == null) {
        return;
    }
    for (RequirementDefinition requirement : elements) {
        Requirement toAddRequirement = MapUtils.getObject(mapToMerge, requirement.getId());
        // the type of a requirement is a capability type in TOSCA as they match each other.
        CapabilityType requirementType = ToscaContext.get(CapabilityType.class, requirement.getType());
        if (toAddRequirement == null || !Objects.equals(toAddRequirement.getType(), requirement.getType())) {
            toAddRequirement = new Requirement();
            toAddRequirement.setType(requirement.getType());
        }
        Map<String, AbstractPropertyValue> properties = Maps.newLinkedHashMap();
        fillProperties(properties, requirementType != null ? requirementType.getProperties() : null, toAddRequirement.getProperties(), adaptToType);
        toAddRequirement.setProperties(properties);
        map.put(requirement.getId(), toAddRequirement);
    }
}
Also used : Requirement(org.alien4cloud.tosca.model.templates.Requirement) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Aggregations

RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)20 NodeType (org.alien4cloud.tosca.model.types.NodeType)14 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)11 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)5 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)4 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)4 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)3 Date (java.util.Date)3 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)3 Set (java.util.Set)2 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)2 NodeFilter (org.alien4cloud.tosca.model.definitions.NodeFilter)2 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)2 Capability (org.alien4cloud.tosca.model.templates.Capability)2 Requirement (org.alien4cloud.tosca.model.templates.Requirement)2 Test (org.junit.Test)2 FacetedSearchResult (alien4cloud.dao.model.FacetedSearchResult)1 NodeFilterToSatisfy (alien4cloud.topology.task.NodeFilterToSatisfy)1