use of alien4cloud.topology.task.PropertiesTask in project alien4cloud by alien4cloud.
the class TopologyValidationService method doValidate.
private TopologyValidationResult doValidate(Topology topology) {
TopologyValidationResult dto = new TopologyValidationResult();
if (MapUtils.isEmpty(topology.getNodeTemplates())) {
dto.addTask(new EmptyTask());
dto.setValid(false);
return dto;
}
// validate the workflows
dto.addTasks(workflowBuilderService.validateWorkflows(topology));
// validate abstract relationships
dto.addTasks(topologyAbstractRelationshipValidationService.validateAbstractRelationships(topology));
// validate requirements lowerBounds
dto.addTasks(topologyRequirementBoundsValidationServices.validateRequirementsLowerBounds(topology));
// validate the node filters for all relationships
dto.addTasks(nodeFilterValidationService.validateStaticRequirementFilters(topology));
// validate that all artifacts has been filled
dto.addTasks(topologyArtifactsValidationService.validate(topology));
// Add warning for deprecated nodes.
dto.addWarnings(deprecatedNodeTypesValidationService.validate(topology));
// validate required properties (properties of NodeTemplate, Relationship and Capability)
List<PropertiesTask> validateProperties = topologyPropertiesValidationService.validateStaticProperties(topology);
// List<PropertiesTask> validateProperties = null;
if (hasOnlyPropertiesWarnings(validateProperties)) {
dto.addWarnings(validateProperties);
} else {
dto.addTasks(validateProperties);
}
dto.setValid(isValidTaskList(dto.getTaskList()));
return dto;
}
use of alien4cloud.topology.task.PropertiesTask in project alien4cloud by alien4cloud.
the class TopologyPropertiesValidationService method validateProperties.
/**
* Validate properties.
*
* @param topology
* @param skipInputProperties whether to skip input properties validation or not. This is in case inputs are not yet processed
* @return
*/
private List<PropertiesTask> validateProperties(Topology topology, boolean skipInputProperties) {
List<PropertiesTask> toReturnTaskList = Lists.newArrayList();
Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
// create task by nodetemplate
for (Map.Entry<String, NodeTemplate> nodeTempEntry : nodeTemplates.entrySet()) {
NodeTemplate nodeTemplate = nodeTempEntry.getValue();
NodeType relatedIndexedNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
// do pass if abstract node
if (relatedIndexedNodeType.isAbstract()) {
continue;
}
validateNodeTemplate(toReturnTaskList, relatedIndexedNodeType, nodeTemplate, nodeTempEntry.getKey(), skipInputProperties);
}
return toReturnTaskList.isEmpty() ? null : toReturnTaskList;
}
use of alien4cloud.topology.task.PropertiesTask in project alien4cloud by alien4cloud.
the class TopologyPropertiesValidationService method validateNodeTemplate.
public void validateNodeTemplate(List<PropertiesTask> toReturnTaskList, NodeType relatedIndexedNodeType, NodeTemplate nodeTemplate, String nodeTempalteName, boolean skipInputProperties) {
// Define a task regarding properties
PropertiesTask task = new PropertiesTask();
task.setNodeTemplateName(nodeTempalteName);
task.setComponent(relatedIndexedNodeType);
task.setCode(TaskCode.PROPERTIES);
task.setProperties(Maps.newHashMap());
// Check the properties of node template
if (MapUtils.isNotEmpty(nodeTemplate.getProperties())) {
addRequiredPropertyIdToTaskProperties(null, nodeTemplate.getProperties(), relatedIndexedNodeType.getProperties(), task, skipInputProperties);
}
// Check relationships PD
for (Map.Entry<String, RelationshipTemplate> relationshipEntry : safe(nodeTemplate.getRelationships()).entrySet()) {
RelationshipTemplate relationship = relationshipEntry.getValue();
if (relationship.getProperties() == null || relationship.getProperties().isEmpty()) {
continue;
}
addRequiredPropertyIdToTaskProperties("relationships[" + relationshipEntry.getKey() + "]", relationship.getProperties(), safe(ToscaContext.getOrFail(RelationshipType.class, relationshipEntry.getValue().getType()).getProperties()), task, skipInputProperties);
}
for (Map.Entry<String, Capability> capabilityEntry : safe(nodeTemplate.getCapabilities()).entrySet()) {
Capability capability = capabilityEntry.getValue();
if (capability.getProperties() == null || capability.getProperties().isEmpty()) {
continue;
}
addRequiredPropertyIdToTaskProperties("capabilities[" + capabilityEntry.getKey() + "]", capability.getProperties(), safe(ToscaContext.getOrFail(CapabilityType.class, capabilityEntry.getValue().getType()).getProperties()), task, skipInputProperties);
if (capability.getType().equals(NormativeCapabilityTypes.SCALABLE)) {
Map<String, AbstractPropertyValue> scalableProperties = capability.getProperties();
verifyScalableProperties(scalableProperties, toReturnTaskList, nodeTempalteName, skipInputProperties);
}
}
if (MapUtils.isNotEmpty(task.getProperties())) {
toReturnTaskList.add(task);
}
}
use of alien4cloud.topology.task.PropertiesTask in project alien4cloud by alien4cloud.
the class OrchestratorPropertiesValidationService method validate.
public PropertiesTask validate(OrchestratorDeploymentProperties orchestratorDeploymentProperties) {
if (orchestratorDeploymentProperties == null || StringUtils.isBlank(orchestratorDeploymentProperties.getOrchestratorId())) {
return null;
}
Map<String, PropertyDefinition> deploymentProperties = orchestratorDeploymentService.getDeploymentPropertyDefinitions(orchestratorDeploymentProperties.getOrchestratorId());
if (MapUtils.isEmpty(deploymentProperties)) {
return null;
}
Map<String, String> properties = orchestratorDeploymentProperties.getProviderDeploymentProperties();
if (properties == null) {
properties = Maps.newHashMap();
}
PropertiesTask task = null;
List<String> required = Lists.newArrayList();
for (Entry<String, PropertyDefinition> entry : deploymentProperties.entrySet()) {
if (entry.getValue().isRequired()) {
String value = properties.get(entry.getKey());
if (StringUtils.isBlank(value)) {
required.add(entry.getKey());
}
}
}
if (CollectionUtils.isNotEmpty(required)) {
task = new PropertiesTask(Maps.<TaskLevel, List<String>>newHashMap());
task.setCode(TaskCode.ORCHESTRATOR_PROPERTY);
task.getProperties().put(TaskLevel.REQUIRED, required);
}
return task;
}
use of alien4cloud.topology.task.PropertiesTask in project alien4cloud by alien4cloud.
the class NodeInstanceService method checkRequired.
/**
* Performs validation of the node instance. Note that based on the actual node state the validation is more or less strict.
*
* When the node state is initial the validation checks that all elements defined in the node template or node instance attributes matches the definition of
* the node
* type. It however does not check if the type has all required properties configured.
*
* When the node state is anything else the validation performs above validation and also checks that all required properties are defined.
*
* @param nodeType The node type against which to perform validation of the node instance.
* @param nodeInstance The actual node instance to validate
*/
@ToscaContextual
public void checkRequired(NodeType nodeType, NodeInstance nodeInstance) {
List<PropertiesTask> errors = Lists.newArrayList();
topologyPropertiesValidationService.validateNodeTemplate(errors, nodeType, nodeInstance.getNodeTemplate(), "", false);
if (!errors.isEmpty()) {
Set<String> errorProperties = Sets.newHashSet();
for (PropertiesTask task : errors) {
for (List<String> properties : task.getProperties().values()) {
errorProperties.addAll(properties);
}
}
throw new InstanceRequiredPropertiesException("Some required properties are not defined.", errorProperties);
}
}
Aggregations