use of alien4cloud.topology.task.ScalableTask in project alien4cloud by alien4cloud.
the class TopologyPropertiesValidationService method verifyScalableProperties.
private void verifyScalableProperties(Map<String, AbstractPropertyValue> scalableProperties, List<PropertiesTask> toReturnTaskList, String nodeTemplateId, boolean skipInputProperties) {
Set<String> missingProperties = Sets.newHashSet();
Set<String> errorProperties = Sets.newHashSet();
if (skipInputProperties) {
for (Entry<String, AbstractPropertyValue> entry : scalableProperties.entrySet()) {
if (entry.getValue() instanceof FunctionPropertyValue) {
return;
}
}
}
if (MapUtils.isEmpty(scalableProperties)) {
missingProperties.addAll(Lists.newArrayList(NormativeComputeConstants.SCALABLE_MIN_INSTANCES, NormativeComputeConstants.SCALABLE_MAX_INSTANCES, NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES));
} else {
int min = verifyScalableProperty(scalableProperties, NormativeComputeConstants.SCALABLE_MIN_INSTANCES, missingProperties, errorProperties);
int max = verifyScalableProperty(scalableProperties, NormativeComputeConstants.SCALABLE_MAX_INSTANCES, missingProperties, errorProperties);
int init = verifyScalableProperty(scalableProperties, NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, missingProperties, errorProperties);
if (min > 0 && max > 0 && init > 0) {
if (min > init || min > max) {
errorProperties.add(NormativeComputeConstants.SCALABLE_MIN_INSTANCES);
}
if (init > max || init < min) {
errorProperties.add(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES);
}
if (max < min || max < init) {
errorProperties.add(NormativeComputeConstants.SCALABLE_MAX_INSTANCES);
}
}
}
if (!missingProperties.isEmpty()) {
ScalableTask scalableTask = new ScalableTask(nodeTemplateId);
scalableTask.getProperties().put(TaskLevel.REQUIRED, Lists.newArrayList(missingProperties));
toReturnTaskList.add(scalableTask);
}
if (!errorProperties.isEmpty()) {
ScalableTask scalableTask = new ScalableTask(nodeTemplateId);
scalableTask.getProperties().put(TaskLevel.ERROR, Lists.newArrayList(errorProperties));
toReturnTaskList.add(scalableTask);
}
}
Aggregations