Search in sources :

Example 56 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class UnsetNodePropertyAsInputProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodePropertyAsInputOperation operation, NodeTemplate nodeTemplate) {
    // check if the node property value is a get_input
    AbstractPropertyValue currentValue = nodeTemplate.getProperties().get(operation.getPropertyName());
    if (!isGetInput(currentValue)) {
        throw new NotFoundException("Property {} of node {} is not associated to an input.", operation.getPropertyName(), operation.getNodeName());
    }
    NodeType nodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
    PropertyDefinition nodePropertyDefinition = getOrFail(nodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName());
    AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(nodePropertyDefinition);
    nodeTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
    log.debug("Remove association from property [ {} ] of the node template [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), topology.getId());
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 57 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class SetNodePropertyAsInputProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, SetNodePropertyAsInputOperation operation, NodeTemplate nodeTemplate) {
    PropertyDefinition inputPropertyDefinition = getOrFail(topology.getInputs(), operation.getInputName(), "Input {} not found in topology", operation.getInputName());
    NodeType indexedNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
    PropertyDefinition nodePropertyDefinition = getOrFail(indexedNodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName());
    // Check that the property definition of the input is indeed compatible with the property definition of the capability.
    inputPropertyDefinition.checkIfCompatibleOrFail(nodePropertyDefinition);
    FunctionPropertyValue getInput = new FunctionPropertyValue();
    getInput.setFunction(ToscaFunctionConstants.GET_INPUT);
    getInput.setParameters(Arrays.asList(operation.getInputName()));
    nodeTemplate.getProperties().put(operation.getPropertyName(), getInput);
    log.debug("Associate the property [ {} ] of the node template [ {} ] to input [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), operation.getInputName(), topology.getId());
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 58 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class SearchTest method searchPostTest.

@Test
public void searchPostTest() {
    String query = "positive";
    RestResponse<FacetedSearchResult<? extends AbstractToscaType>> response;
    ComponentSearchRequest req;
    FacetedSearchResult data;
    String[] ids;
    // without filters
    req = new ComponentSearchRequest(QueryComponentType.NODE_TYPE, query, 0, NUMBER_ELEMENT, null);
    response = componentController.search(req);
    assertNotNull(response);
    assertNotNull(response.getData());
    assertNull(response.getError());
    data = response.getData();
    assertEquals(2, data.getTotalResults());
    assertEquals(2, data.getTypes().length);
    assertEquals(2, data.getData().length);
    ids = new String[] { indexedNodeTypeTest.getId(), indexedNodeTypeTest4.getId() };
    for (int i = 0; i < data.getData().length; i++) {
        NodeType idnt = (NodeType) data.getData()[i];
        assertElementIn(idnt.getId(), ids);
    }
    // filter based test
    Map<String, String[]> filters = new HashMap<String, String[]>();
    filters.put("capabilities.type", new String[] { "container", "banana" });
    req = new ComponentSearchRequest(QueryComponentType.NODE_TYPE, query, 0, NUMBER_ELEMENT, filters);
    response = componentController.search(req);
    assertNotNull(response);
    assertNotNull(response.getData());
    assertNull(response.getError());
    data = response.getData();
    assertEquals(1, data.getTotalResults());
    assertEquals(1, data.getTypes().length);
    assertEquals(1, data.getData().length);
    NodeType idnt = (NodeType) data.getData()[0];
    assertElementIn(idnt.getId(), new String[] { indexedNodeTypeTest.getId() });
    // test nothing found
    query = "pacpac";
    req = new ComponentSearchRequest(QueryComponentType.NODE_TYPE, query, 0, NUMBER_ELEMENT, null);
    response = componentController.search(req);
    assertNotNull(response);
    assertNotNull(response.getData());
    assertNull(response.getError());
    data = response.getData();
    assertNotNull(data.getTypes());
    assertEquals(0, data.getTotalResults());
    assertEquals(0, data.getData().length);
    assertEquals(0, data.getTypes().length);
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) HashMap(java.util.HashMap) NodeType(org.alien4cloud.tosca.model.types.NodeType) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult) Test(org.junit.Test)

Example 59 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class SearchTest method createIndexedNodeType.

private static NodeType createIndexedNodeType(String id, String archiveName, String archiveVersion, String description, List<CapabilityDefinition> capabilities, List<RequirementDefinition> requirements, List<String> derivedFroms, List<String> defaultCapabilities) {
    NodeType nodeType = new NodeType();
    nodeType.setElementId(id);
    nodeType.setArchiveName(archiveName);
    nodeType.setArchiveVersion(archiveVersion);
    nodeType.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
    nodeType.setCapabilities(capabilities);
    nodeType.setDescription(description);
    nodeType.setDefaultCapabilities(defaultCapabilities);
    nodeType.setRequirements(requirements);
    nodeType.setDerivedFrom(derivedFroms);
    return nodeType;
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType)

Example 60 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class ComponentTest method recommendForCapabilityTest.

@Test
public void recommendForCapabilityTest() {
    RestResponse<NodeType> response = null;
    RecommendationRequest recRequest = new RecommendationRequest();
    recRequest.setComponentId(indexedNodeType.getId());
    recRequest.setCapability("wor");
    response = componentController.recommendComponentForCapability(recRequest);
    assertNull(response.getError());
    NodeType component = dao.findById(NodeType.class, recRequest.getComponentId());
    assertNotNull(component.getDefaultCapabilities());
    assertEquals(1, component.getDefaultCapabilities().size());
    assertTrue(" component of Id " + component.getId() + " should contains " + "wor", component.getDefaultCapabilities().contains("wor"));
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) Test(org.junit.Test)

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