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());
}
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());
}
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);
}
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;
}
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"));
}
Aggregations