use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class InputPropertiesStepDefinitions method i_define_the_capability_property_of_the_node_of_typeId_as_input_property.
@Given("^I define the capability \"(.*?)\" property \"(.*?)\" of the node \"(.*?)\" as input property$")
public void i_define_the_capability_property_of_the_node_of_typeId_as_input_property(String capabilityName, String propertyName, String nodeName) throws Throwable {
String url = String.format("/rest/v1/topologies/%s", Context.getInstance().getTopologyId());
String response = Context.getRestClientInstance().get(url);
TopologyDTO topologyDTO = JsonUtil.read(response, TopologyDTO.class, Context.getJsonMapper()).getData();
NodeTemplate template = MapUtils.getObject(topologyDTO.getTopology().getNodeTemplates(), nodeName);
Capability capability = template.getCapabilities().get(capabilityName);
CapabilityType capabilityType = topologyDTO.getCapabilityTypes().get(capability.getType());
PropertyDefinition propertyDefinition = capabilityType.getProperties().get(propertyName);
String fullUrl = String.format("/rest/v1/topologies/%s/inputs/%s", Context.getInstance().getTopologyId(), propertyName);
String json = JsonUtil.toString(propertyDefinition);
Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon(fullUrl, json));
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class InputPropertiesStepDefinitions method I_define_the_property_of_the_node_as_input_property.
@When("^I define the property \"([^\"]*)\" of the node \"([^\"]*)\" as input property$")
public void I_define_the_property_of_the_node_as_input_property(String inputId, String nodeName) throws Throwable {
// get the topologyTDO to have the real type of the propertyDefinition
PropertyDefinition propertyDefinition = getPropertyDefinition(nodeName, inputId);
AddInputOperation addInputOperation = new AddInputOperation();
addInputOperation.setPropertyDefinition(propertyDefinition);
addInputOperation.setInputName(inputId);
EditorStepDefinitions.do_i_execute_the_operation(addInputOperation);
SetNodePropertyAsInputOperation setNodePropertyAsInputOperation = new SetNodePropertyAsInputOperation();
setNodePropertyAsInputOperation.setInputName(inputId);
setNodePropertyAsInputOperation.setPropertyName(inputId);
setNodePropertyAsInputOperation.setNodeName(nodeName);
EditorStepDefinitions.do_i_execute_the_operation(setNodePropertyAsInputOperation);
EditorStepDefinitions.do_i_save_the_topology();
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class InputService method onCopyConfiguration.
@EventListener
@Order(10)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
ApplicationEnvironment target = onDeploymentConfigCopyEvent.getTargetEnvironment();
DeploymentInputs deploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
if (deploymentInputs == null || MapUtils.isEmpty(deploymentInputs.getInputs())) {
// Nothing to copy
return;
}
Topology topology = topologyServiceCore.getOrFail(Csar.createId(target.getApplicationId(), target.getTopologyVersion()));
if (MapUtils.isNotEmpty(topology.getInputs())) {
Map<String, PropertyDefinition> inputsDefinitions = topology.getInputs();
Map<String, AbstractPropertyValue> inputsToCopy = deploymentInputs.getInputs().entrySet().stream().filter(inputEntry -> inputsDefinitions.containsKey(inputEntry.getKey())).filter(inputEntry -> {
// Copy only inputs which satisfy the new input definition
try {
if (!(inputEntry.getValue() instanceof FunctionPropertyValue)) {
ConstraintPropertyService.checkPropertyConstraint(inputEntry.getKey(), PropertyService.asPropertyValue(inputEntry.getValue()), inputsDefinitions.get(inputEntry.getKey()));
}
return true;
} catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) {
return false;
}
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if (MapUtils.isNotEmpty(inputsToCopy)) {
DeploymentInputs targetDeploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(target.getTopologyVersion(), target.getId()));
if (targetDeploymentInputs == null) {
targetDeploymentInputs = new DeploymentInputs(target.getTopologyVersion(), target.getId());
}
// Copy inputs from original topology
targetDeploymentInputs.setInputs(inputsToCopy);
deploymentConfigurationDao.save(targetDeploymentInputs);
}
}
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class ArchiveRootPostProcessor method processRepositoriesDefinitions.
private void processRepositoriesDefinitions(Map<String, RepositoryDefinition> repositories) {
if (MapUtils.isNotEmpty(repositories)) {
DataType credentialType = ToscaContext.get(DataType.class, NormativeCredentialConstant.DATA_TYPE);
repositories.values().forEach(repositoryDefinition -> {
if (repositoryDefinition.getCredential() != null) {
credentialType.getProperties().forEach((propertyName, propertyDefinition) -> {
// Fill with default value
if (!repositoryDefinition.getCredential().getValue().containsKey(propertyName)) {
AbstractPropertyValue defaultValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(propertyDefinition);
if (defaultValue instanceof PropertyValue) {
repositoryDefinition.getCredential().getValue().put(propertyName, ((PropertyValue) defaultValue).getValue());
}
}
});
Node credentialNode = ParsingContextExecution.getObjectToNodeMap().get(repositoryDefinition.getCredential());
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType(NormativeCredentialConstant.DATA_TYPE);
propertyValueChecker.checkProperty("credential", credentialNode, repositoryDefinition.getCredential(), propertyDefinition, repositoryDefinition.getId());
}
});
}
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class SuggestionService method setSuggestionIdOnPropertyDefinition.
/**
* Add the suggestion ID of the new suggestionEntry to the appropriate propertyDefinition.
*
* @param suggestionEntry entry of suggestion
*/
public void setSuggestionIdOnPropertyDefinition(SuggestionEntry suggestionEntry) {
Class<? extends AbstractInheritableToscaType> targetClass = (Class<? extends AbstractInheritableToscaType>) alienDAO.getTypesToClasses().get(suggestionEntry.getEsType());
// FIXME what if targetClass is null ?
Object array = toscaTypeSearchService.findAll(targetClass, suggestionEntry.getTargetElementId());
if (array != null) {
int length = Array.getLength(array);
for (int i = 0; i < length; i++) {
AbstractInheritableToscaType targetElement = ((AbstractInheritableToscaType) Array.get(array, i));
PropertyDefinition propertyDefinition = targetElement.getProperties().get(suggestionEntry.getTargetProperty());
if (propertyDefinition == null) {
throw new NotFoundException("Property [" + suggestionEntry.getTargetProperty() + "] not found for element [" + suggestionEntry.getTargetElementId() + "]");
} else {
switch(propertyDefinition.getType()) {
case ToscaTypes.VERSION:
case ToscaTypes.STRING:
propertyDefinition.setSuggestionId(suggestionEntry.getId());
alienDAO.save(targetElement);
break;
case ToscaTypes.LIST:
case ToscaTypes.MAP:
PropertyDefinition entrySchema = propertyDefinition.getEntrySchema();
if (entrySchema != null) {
entrySchema.setSuggestionId(suggestionEntry.getId());
alienDAO.save(targetElement);
} else {
throw new InvalidArgumentException("Cannot suggest a list / map type with no entry schema definition");
}
break;
default:
throw new InvalidArgumentException(propertyDefinition.getType() + " cannot be suggested, only property of type string list or map can be suggested");
}
}
}
}
}
Aggregations