use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.
the class TopologyUtils method filterInterfaces.
/**
* Extract all interfaces that have given operations, and filter out all operations that are not in the includedOperations
*
* @param interfaces interfaces to filter
* @param includedOperations operations that will be included in the result
* @return filter interfaces
*/
public static Map<String, Interface> filterInterfaces(Map<String, Interface> interfaces, Set<String> includedOperations) {
Map<String, Interface> result = Maps.newHashMap();
for (Map.Entry<String, Interface> interfaceEntry : interfaces.entrySet()) {
Map<String, Operation> operations = Maps.newHashMap();
for (Map.Entry<String, Operation> operationEntry : interfaceEntry.getValue().getOperations().entrySet()) {
if (includedOperations.contains(operationEntry.getKey())) {
operations.put(operationEntry.getKey(), operationEntry.getValue());
}
}
if (!operations.isEmpty()) {
Interface inter = new Interface();
inter.setDescription(interfaceEntry.getValue().getDescription());
inter.setOperations(operations);
result.put(interfaceEntry.getKey(), inter);
}
}
return result;
}
use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.
the class RuntimeController method validateParameters.
private void validateParameters(Interface interfass, OperationExecRequest operationRequest, Set<CSARDependency> dependencies) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException, ConstraintRequiredParameterException {
try {
if (dependencies != null) {
ToscaContext.init(dependencies);
}
ArrayList<String> missingParams = Lists.newArrayList();
Operation operation = interfass.getOperations().get(operationRequest.getOperationName());
if (operation.getInputParameters() != null) {
for (Entry<String, IValue> inputParameter : operation.getInputParameters().entrySet()) {
if (inputParameter.getValue().isDefinition()) {
Object requestInputParameter = operationRequest.getParameters() == null ? null : operationRequest.getParameters().get(inputParameter.getKey());
PropertyDefinition currentOperationParameter = (PropertyDefinition) inputParameter.getValue();
if (requestInputParameter != null) {
if (!(requestInputParameter instanceof Map) || !FunctionEvaluator.containGetSecretFunction(PropertyService.asFunctionPropertyValue(requestInputParameter))) {
// recover the good property definition for the current parameter
ConstraintPropertyService.checkPropertyConstraint(inputParameter.getKey(), requestInputParameter, currentOperationParameter);
}
} else if (currentOperationParameter.isRequired()) {
// input param not in the request, id required this is a missing parameter...
missingParams.add(inputParameter.getKey());
} else {
// set the value to null
operation.getInputParameters().put(inputParameter.getKey(), null);
}
}
}
}
// check required input issue
if (!missingParams.isEmpty()) {
log.error("Missing required parameter", missingParams);
ConstraintInformation constraintInformation = new ConstraintInformation(null, null, missingParams.toString(), "required");
throw new ConstraintRequiredParameterException("Missing required parameters", null, constraintInformation);
}
} finally {
if (ToscaContext.get() != null) {
ToscaContext.destroy();
}
}
}
use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.
the class ToscaSerializerUtils method formatRepositories.
public static String formatRepositories(String topologyArchiveName, String topologyArchiveVersion, Topology topology) {
StringBuilder buffer = new StringBuilder();
Set<String> repositoriesName = Sets.newHashSet();
for (NodeTemplate node : safe(topology.getNodeTemplates()).values()) {
for (DeploymentArtifact artifact : safe(node.getArtifacts()).values()) {
// Only generate repositories for the current topology
if (isInternalRepoArtifact(artifact, topologyArchiveName, topologyArchiveVersion)) {
buffer.append(" ").append(artifact.getRepositoryName()).append(":");
buffer.append("\n").append(formatRepository(artifact, 2)).append("\n");
}
}
for (Interface anInterface : safe(node.getInterfaces()).values()) {
for (Operation operation : safe(anInterface.getOperations()).values()) {
if (operation.getImplementationArtifact() != null && isInternalRepoArtifact(operation.getImplementationArtifact(), topologyArchiveName, topologyArchiveVersion)) {
buffer.append(" ").append(operation.getImplementationArtifact().getRepositoryName()).append(":");
buffer.append("\n").append(formatRepository(operation.getImplementationArtifact(), 2)).append("\n");
}
}
}
}
if (MapUtils.isNotEmpty(topology.getInputArtifacts())) {
topology.getInputArtifacts().values().forEach(inputArtifact -> {
if (StringUtils.isNotBlank(inputArtifact.getRepositoryURL()) && repositoriesName.add(inputArtifact.getRepositoryName())) {
buffer.append(" ").append(inputArtifact.getRepositoryName()).append(":");
buffer.append("\n").append(formatRepository(inputArtifact, 2)).append("\n");
}
});
}
buffer.setLength(buffer.length() - 1);
return buffer.toString();
}
use of org.alien4cloud.tosca.model.definitions.Operation in project alien4cloud by alien4cloud.
the class NodeTemplatePostProcessor method process.
@Override
public void process(final NodeTemplate instance) {
// ensure type exists
referencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance, instance.getType(), NodeType.class));
final NodeType nodeType = ToscaContext.get(NodeType.class, instance.getType());
if (nodeType == null) {
// error managed by the reference post processor.
return;
}
// FIXME we should check that the artifact is defined at the type level.
safe(instance.getArtifacts()).values().forEach(templateDeploymentArtifactPostProcessor);
// TODO Manage interfaces inputs to copy them to all operations.
safe(instance.getInterfaces()).values().stream().flatMap(anInterface -> safe(anInterface.getOperations()).values().stream()).map(Operation::getImplementationArtifact).filter(Objects::nonNull).forEach(implementationArtifactPostProcessor);
// Merge the node template with data coming from the type (default values etc.).
NodeTemplate tempObject = TemplateBuilder.buildNodeTemplate(nodeType, instance, false);
safe(instance.getCapabilities()).keySet().forEach(s -> {
if (!safe(tempObject.getCapabilities()).containsKey(s)) {
Node node = ParsingContextExecution.getObjectToNodeMap().get(s);
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKNOWN_CAPABILITY, null, node.getStartMark(), null, node.getEndMark(), s));
}
});
instance.setAttributes(tempObject.getAttributes());
instance.setCapabilities(tempObject.getCapabilities());
instance.setProperties(tempObject.getProperties());
instance.setRequirements(tempObject.getRequirements());
instance.setArtifacts(tempObject.getArtifacts());
instance.setInterfaces(tempObject.getInterfaces());
// apply post processor to capabilities defined locally on the element (no need to post-processed the one merged)
safe(instance.getCapabilities()).entrySet().forEach(capabilityPostProcessor);
safe(instance.getRequirements()).entrySet().forEach(requirementPostProcessor);
propertyValueChecker.checkProperties(nodeType, instance.getProperties(), instance.getName());
}
Aggregations