use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class DefaultNodeMatcherTest method abstract_template_should_be_matched_if_service_is_available_2.
@Test
public void abstract_template_should_be_matched_if_service_is_available_2() throws Exception {
// Given
Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>();
// When
NodeTemplate wantedNodeTemplate = nodeTemplate("alien.service.MongoDB");
NodeType wantedNodeType = new NodeType();
wantedNodeType.setAbstract(true);
List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, wantedNodeType, locationResources, emptyMatchingConfigurations);
// Then
assertThat(proposition).hasSize(1);
assertThat(proposition.get(0).isService()).isTrue();
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class TopologySubstitutionService method fillRequirements.
private void fillRequirements(Topology topology, NodeType substituteNodeType) {
if (topology.getSubstitutionMapping().getRequirements() != null) {
for (Map.Entry<String, SubstitutionTarget> e : topology.getSubstitutionMapping().getRequirements().entrySet()) {
String key = e.getKey();
String nodeName = e.getValue().getNodeTemplateName();
String requirementName = e.getValue().getTargetId();
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
RequirementDefinition requirementDefinition = IndexedModelUtils.getRequirementDefinitionById(nodeTemplateType.getRequirements(), requirementName);
// We cannot change the capability definition here or we will change the original one so we need a clone
requirementDefinition = CloneUtil.clone(requirementDefinition);
requirementDefinition.setId(key);
substituteNodeType.getRequirements().add(requirementDefinition);
}
}
}
use of org.alien4cloud.tosca.model.types.NodeType 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.types.NodeType in project alien4cloud by alien4cloud.
the class TopologySubstitutionService method fillSubstituteAttributesFromOutputProperties.
private void fillSubstituteAttributesFromOutputProperties(Topology topology, NodeType substituteNodeType) {
Map<String, Set<String>> outputProperties = topology.getOutputProperties();
if (outputProperties != null) {
for (Map.Entry<String, Set<String>> ope : outputProperties.entrySet()) {
String nodeName = ope.getKey();
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
for (String propertyName : ope.getValue()) {
PropertyDefinition pd = nodeTemplateType.getProperties().get(propertyName);
// is a conflict
addAttributeFromPropertyDefinition(pd, propertyName, substituteNodeType);
}
}
}
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class TopologySubstitutionService method updateSubstitutionType.
@ToscaContextual
public void updateSubstitutionType(final Topology topology, Csar csar) {
if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) {
return;
}
// first we update the csar and the dependencies
NodeType nodeType = ToscaContext.getOrFail(NodeType.class, topology.getSubstitutionMapping().getSubstitutionType());
if (csar.getDependencies() == null) {
csar.setDependencies(Sets.newHashSet());
}
boolean updateCsar = false;
if (csar.getDependencies().add(csarDependencyLoader.buildDependencyBean(nodeType.getArchiveName(), nodeType.getArchiveVersion()))) {
updateCsar = true;
}
Path archiveGitPath = csarRepositry.getExpandedCSAR(csar.getName(), csar.getVersion());
String hash = FileUtil.deepSHA1(archiveGitPath);
if (!hash.equals(csar.getHash())) {
csar.setHash(hash);
updateCsar = true;
}
if (updateCsar) {
csarService.save(csar);
}
// We create the nodeType that will serve as substitute
NodeType substituteNodeType = buildSubstituteNodeType(topology, csar, nodeType);
// inputs from topology become properties of type
substituteNodeType.setProperties(topology.getInputs());
// output attributes become attributes for the type
fillSubstituteAttributesFromTypeAtttributes(topology, substituteNodeType);
// output properties become attributes for the type
fillSubstituteAttributesFromOutputProperties(topology, substituteNodeType);
// output capabilities properties also become attributes for the type
fillAttributesFromOutputCapabilitiesProperties(topology, substituteNodeType);
// capabilities substitution
fillCapabilities(topology, substituteNodeType);
// requirement substitution
fillRequirements(topology, substituteNodeType);
// finally we index the created type
indexerService.indexInheritableElement(csar.getName(), csar.getVersion(), substituteNodeType, csar.getDependencies());
// Dispatch event
publisher.publishEvent(new SubstitutionTypeChangedEvent(this, topology, substituteNodeType));
}
Aggregations