use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class EsDaoPaginatedSearchTest method saveDataToES.
private void saveDataToES() throws IOException, IndexingServiceException {
testDataList.clear();
Path path = Paths.get("src/test/resources/nodetypes-faceted-search-result.json");
FacetedSearchResult res = jsonMapper.readValue(path.toFile(), FacetedSearchResult.class);
Object[] data = res.getData();
for (Object element : data) {
String serializeDatum = jsonMapper.writeValueAsString(element);
NodeType indexedNodeType = jsonMapper.readValue(serializeDatum, NodeType.class);
indexedNodeType.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
String typeName = MappingBuilder.indexTypeFromClass(NodeType.class);
dao.save(indexedNodeType);
assertDocumentExisit(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName, indexedNodeType.getId(), true);
testDataList.add(indexedNodeType);
for (CapabilityDefinition capaDef : indexedNodeType.getCapabilities()) {
if (capaDef.getType().equals("jndi")) {
jndiTestDataList.add(indexedNodeType);
}
}
}
refresh();
}
use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class TopologySubstitutionService method fillCapabilities.
private void fillCapabilities(Topology topology, NodeType substituteNodeType) {
if (topology.getSubstitutionMapping().getCapabilities() != null) {
for (Map.Entry<String, SubstitutionTarget> e : topology.getSubstitutionMapping().getCapabilities().entrySet()) {
String key = e.getKey();
String nodeName = e.getValue().getNodeTemplateName();
String capabilityName = e.getValue().getTargetId();
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
CapabilityDefinition capabilityDefinition = IndexedModelUtils.getCapabilityDefinitionById(nodeTemplateType.getCapabilities(), capabilityName);
// We cannot change the capability definition here or we will change the original one so we need a clone
capabilityDefinition = CloneUtil.clone(capabilityDefinition);
capabilityDefinition.setId(key);
substituteNodeType.getCapabilities().add(capabilityDefinition);
}
}
}
use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class TopologyDTOBuilder method getCapabilityTypes.
private <T extends Topology> Map<String, CapabilityType> getCapabilityTypes(AbstractTopologyDTO<T> topologyDTO) {
Map<String, CapabilityType> types = Maps.newHashMap();
Map<String, NodeType> delayedNodeTypeAddMap = Maps.newHashMap();
for (NodeType nodeType : topologyDTO.getNodeTypes().values()) {
if (nodeType != null) {
for (CapabilityDefinition capabilityDefinition : safe(nodeType.getCapabilities())) {
types.put(capabilityDefinition.getType(), ToscaContext.get(CapabilityType.class, capabilityDefinition.getType()));
}
for (RequirementDefinition requirementDefinition : safe(nodeType.getRequirements())) {
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, requirementDefinition.getType());
if (capabilityType != null) {
types.put(requirementDefinition.getType(), capabilityType);
} else {
// requirements are authorized to be a node type rather than a capability type TODO is it still possible in TOSCA ?
NodeType indexedNodeType = ToscaContext.get(NodeType.class, requirementDefinition.getType());
// add it to the actual node types map
delayedNodeTypeAddMap.put(requirementDefinition.getType(), indexedNodeType);
}
}
}
}
for (Map.Entry<String, NodeType> delayedNodeType : delayedNodeTypeAddMap.entrySet()) {
topologyDTO.getNodeTypes().put(delayedNodeType.getKey(), delayedNodeType.getValue());
}
return types;
}
use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class EditorTopologyRecoveryHelperService method checkCapability.
/**
* validate that a node still has a capability, by checkibg directly from the related node type
*
* @param capabilityName The name of the capability to check
* @param nodeTemplate The node template in which to check for the capability
*/
private void checkCapability(String capabilityName, NodeTemplate nodeTemplate) {
// FIXME check if the relationship is still valid concerning binded capability
// This call should never throw a NotFoundException
NodeType indexedNodeType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
Map<String, CapabilityDefinition> capabilitiesMap = AlienUtils.fromListToMap(indexedNodeType.getCapabilities(), "id", true);
if (!AlienUtils.safe(capabilitiesMap).containsKey(capabilityName)) {
throw new InvalidStateException("A capability with name [" + capabilityName + "] cannot be found in the node [" + nodeTemplate.getName() + "].");
}
}
use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class LocationResourceService method setTemplateCapabilityProperty.
private void setTemplateCapabilityProperty(LocationResourceTemplate resourceTemplate, String capabilityName, String propertyName, Object propertyValue) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
Location location = locationService.getOrFail(resourceTemplate.getLocationId());
NodeType resourceType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, resourceTemplate.getTemplate().getType(), location.getDependencies());
Capability capability = getOrFailCapability(resourceTemplate.getTemplate(), capabilityName);
CapabilityDefinition capabilityDefinition = getOrFailCapabilityDefinition(resourceType, capabilityName);
CapabilityType capabilityType = csarRepoSearchService.getRequiredElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), location.getDependencies());
PropertyDefinition propertyDefinition = getOrFailCapabilityPropertyDefinition(capabilityType, propertyName);
propertyService.setCapabilityPropertyValue(location.getDependencies(), capability, propertyDefinition, propertyName, propertyValue);
}
Aggregations