use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ToscaParserAlien200Test method parseTopologyTemplateWithRelationshipWorkflowMultipleActivities.
@Test
public void parseTopologyTemplateWithRelationshipWorkflowMultipleActivities() throws ParsingException {
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-workflow-relationship-operation.yml"));
assertFalse(parsingResult.getResult().getTopology().getWorkflows().isEmpty());
assertNotNull(parsingResult.getResult().getTopology().getWorkflows().get("install"));
Workflow wf = parsingResult.getResult().getTopology().getWorkflows().get("install");
assertNotNull(wf.getSteps().get("SoftwareComponent_hostedOnComputeHost_pre_configure_source"));
WorkflowStep step = wf.getSteps().get("SoftwareComponent_hostedOnComputeHost_pre_configure_source");
assertTrue(step instanceof RelationshipWorkflowStep);
RelationshipWorkflowStep relStep = (RelationshipWorkflowStep) step;
assertTrue(relStep.getTarget().equals("SoftwareComponent"));
assertTrue(relStep.getTargetRelationship().equals("hostedOnComputeHost"));
assertTrue(relStep.getOperationHost().equals("SOURCE"));
assertEquals(1, relStep.getActivities().size());
assertEquals(1, relStep.getOnSuccess().size());
assertTrue(relStep.getOnSuccess().contains("SoftwareComponent_hostedOnComputeHost_pre_configure_source_0"));
// test the second step, create to split activities into steps
WorkflowStep step_0 = wf.getSteps().get("SoftwareComponent_hostedOnComputeHost_pre_configure_source_0");
assertTrue(step_0 instanceof RelationshipWorkflowStep);
RelationshipWorkflowStep relStep_0 = (RelationshipWorkflowStep) step_0;
assertTrue(relStep_0.getTarget().equals("SoftwareComponent"));
assertTrue(relStep_0.getTargetRelationship().equals("hostedOnComputeHost"));
assertTrue(relStep_0.getOperationHost().equals("SOURCE"));
assertEquals(1, relStep_0.getActivities().size());
assertEquals(1, relStep_0.getOnSuccess().size());
assertTrue(relStep_0.getOnSuccess().contains("SoftwareComponent_install"));
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class PolicyTemplatePostProcessor method process.
@Override
public void process(final PolicyTemplate instance) {
// ensure type exists
referencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance, instance.getType(), PolicyType.class));
final PolicyType policyType = ToscaContext.get(PolicyType.class, instance.getType());
if (policyType == null) {
// error managed by the reference post processor.
return;
}
final Topology topology = ((ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance()).getTopology();
// check that the targets are exiting node templates
// TODO should we also check the type of the target, see if it matches with one provided in PolicyType.getTargets() ?
safe(instance.getTargets()).forEach(target -> {
if (!safe((topology.getNodeTemplates())).containsKey(target)) {
// Dispatch an error.
Node node = ParsingContextExecution.getObjectToNodeMap().get(instance.getTargets());
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.POLICY_TARGET_NOT_FOUND, instance.getName(), node.getStartMark(), null, node.getEndMark(), target));
}
});
// Merge the policy template with data coming from the type (default values etc.).
PolicyTemplate tempObject = TemplateBuilder.buildPolicyTemplate(policyType, instance, false);
instance.setProperties(tempObject.getProperties());
propertyValueChecker.checkProperties(policyType, instance.getProperties(), instance.getName());
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class PropertyDefinitionPostProcessor method validateType.
private void validateType(PropertyDefinition propertyDefinition) {
String propertyType = propertyDefinition.getType();
if (propertyType == null) {
Node node = ParsingContextExecution.getObjectToNodeMap().get(propertyType);
if (node == null) {
node = ParsingContextExecution.getObjectToNodeMap().get(propertyDefinition);
}
ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.VALIDATION_ERROR, "ToscaPropertyType", node.getStartMark(), "Property type must be defined", node.getEndMark(), "type"));
} else if (!ToscaTypes.isSimple(propertyType)) {
if (ToscaTypes.LIST.equals(propertyType) || ToscaTypes.MAP.equals(propertyType)) {
PropertyDefinition entrySchema = propertyDefinition.getEntrySchema();
if (entrySchema == null) {
Node node = ParsingContextExecution.getObjectToNodeMap().get(propertyDefinition);
ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.VALIDATION_ERROR, "ToscaPropertyType", node.getStartMark(), "Type " + propertyType + " must define entry schema", node.getEndMark(), "type"));
} else {
validateType(entrySchema);
}
} else {
// It's data type
ArchiveRoot archiveRoot = ParsingContextExecution.getRootObj();
if (!archiveRoot.getDataTypes().containsKey(propertyType)) {
DataType dataType = ToscaContext.get(DataType.class, propertyType);
if (dataType == null) {
Node node = ParsingContextExecution.getObjectToNodeMap().get(propertyType);
ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.TYPE_NOT_FOUND, "ToscaPropertyType", node.getStartMark(), "Type " + propertyType + " is not found.", node.getEndMark(), "type"));
}
}
}
}
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class SuggestionService method postProcessSuggestionFromArchive.
public void postProcessSuggestionFromArchive(ParsingResult<ArchiveRoot> parsingResult) {
ArchiveRoot archiveRoot = parsingResult.getResult();
ParsingContext context = parsingResult.getContext();
if (archiveRoot.hasToscaTopologyTemplate()) {
Topology topology = archiveRoot.getTopology();
Map<String, NodeTemplate> nodeTemplateMap = topology.getNodeTemplates();
if (MapUtils.isEmpty(nodeTemplateMap)) {
return;
}
for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplateMap.entrySet()) {
NodeTemplate nodeTemplate = nodeTemplateEntry.getValue();
String nodeName = nodeTemplateEntry.getKey();
if (MapUtils.isNotEmpty(nodeTemplate.getProperties())) {
checkProperties(nodeName, nodeTemplate.getProperties(), NodeType.class, nodeTemplate.getType(), context);
}
Map<String, Capability> capabilityMap = nodeTemplate.getCapabilities();
if (MapUtils.isNotEmpty(capabilityMap)) {
for (Map.Entry<String, Capability> capabilityEntry : capabilityMap.entrySet()) {
String capabilityName = capabilityEntry.getKey();
Capability capability = capabilityEntry.getValue();
if (MapUtils.isNotEmpty(capability.getProperties())) {
checkProperties(nodeName + ".capabilities." + capabilityName, capability.getProperties(), CapabilityType.class, capability.getType(), context);
}
}
}
Map<String, RelationshipTemplate> relationshipTemplateMap = nodeTemplate.getRelationships();
if (MapUtils.isNotEmpty(relationshipTemplateMap)) {
for (Map.Entry<String, RelationshipTemplate> relationshipEntry : relationshipTemplateMap.entrySet()) {
String relationshipName = relationshipEntry.getKey();
RelationshipTemplate relationship = relationshipEntry.getValue();
if (MapUtils.isNotEmpty(relationship.getProperties())) {
checkProperties(nodeName + ".relationships." + relationshipName, relationship.getProperties(), RelationshipType.class, relationship.getType(), context);
}
}
}
}
}
if (archiveRoot.hasToscaTypes()) {
Map<String, NodeType> allNodeTypes = archiveRoot.getNodeTypes();
if (MapUtils.isNotEmpty(allNodeTypes)) {
for (Map.Entry<String, NodeType> nodeTypeEntry : allNodeTypes.entrySet()) {
NodeType nodeType = nodeTypeEntry.getValue();
if (nodeType.getRequirements() != null && !nodeType.getRequirements().isEmpty()) {
for (RequirementDefinition requirementDefinition : nodeType.getRequirements()) {
NodeFilter nodeFilter = requirementDefinition.getNodeFilter();
if (nodeFilter != null) {
Map<String, FilterDefinition> capabilitiesFilters = nodeFilter.getCapabilities();
if (MapUtils.isNotEmpty(capabilitiesFilters)) {
for (Map.Entry<String, FilterDefinition> capabilityFilterEntry : capabilitiesFilters.entrySet()) {
FilterDefinition filterDefinition = capabilityFilterEntry.getValue();
for (Map.Entry<String, List<PropertyConstraint>> constraintEntry : filterDefinition.getProperties().entrySet()) {
List<PropertyConstraint> constraints = constraintEntry.getValue();
checkPropertyConstraints("node_filter.capabilities", CapabilityType.class, capabilityFilterEntry.getKey(), constraintEntry.getKey(), constraints, context);
}
}
}
// FIXME check also the value properties filter of a node filter
}
}
}
}
}
}
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ArchiveIndexer method performIndexing.
private void performIndexing(ArchiveRoot root) {
indexerService.indexInheritableElements(root.getArtifactTypes(), root.getArchive().getDependencies());
indexerService.indexInheritableElements(root.getCapabilityTypes(), root.getArchive().getDependencies());
indexerService.indexInheritableElements(root.getNodeTypes(), root.getArchive().getDependencies());
indexerService.indexInheritableElements(root.getRelationshipTypes(), root.getArchive().getDependencies());
indexerService.indexInheritableElements(root.getDataTypes(), root.getArchive().getDependencies());
indexerService.indexInheritableElements(root.getPolicyTypes(), root.getArchive().getDependencies());
if (root.getLocalImports() != null) {
for (ArchiveRoot child : root.getLocalImports()) {
performIndexing(child);
}
}
}
Aggregations