private void updateRuntimeTopology(DeploymentTopology runtimeTopo, PaaSInstancePersistentResourceMonitorEvent persistentResourceEvent, Map<String, Object> persistentProperties) { NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(runtimeTopo, persistentResourceEvent.getNodeTemplateId()); log.info("Updating Runtime topology: Storage NodeTemplate <{}.{}> to add a new volumeId", runtimeTopo.getId(), persistentResourceEvent.getNodeTemplateId()); for (String key : persistentProperties.keySet()) { nodeTemplate.getProperties().put(key, getPropertyValue(persistentProperties.get(key))); log.debug("Property [ {} ] to update: [ {} ]. New value is [ {} ]", key, persistentResourceEvent.getPersistentProperties().get(key), persistentProperties.get(key)); } alienMonitorDao.save(runtimeTopo); }
private static void injectTargetPropertiesAsInputs(PaaSNodeTemplate target, Map<String, Interface> interfaces) { // input name: TARGET_<propertyName> injectPropertiesAsInputs(ToscaFunctionConstants.TARGET, null, target.getTemplate().getProperties(), interfaces, baseName -> StringUtils.joinWith(AlienUtils.DEFAULT_PREFIX_SEPARATOR, ToscaFunctionConstants.TARGET, baseName)); }
private List<Violations> validateNodeFilterProperties(NodeFilter nodeFilter, NodeTemplate target, NodeType targetType, boolean skipInputs) { if (nodeFilter.getProperties() == null || nodeFilter.getProperties().isEmpty()) { return Lists.newArrayList(); } Map<String, List<PropertyConstraint>> propertyFilters = nodeFilter.getProperties(); Map<String, AbstractPropertyValue> propertyValues = target.getProperties(); return validatePropertyFilters(propertyFilters, propertyValues, targetType.getProperties(), skipInputs); }
private static void injectSourcePropertiesAsInputs(PaaSNodeTemplate source, Map<String, Interface> interfaces) { // input name: SOURCE_<propertyName> injectPropertiesAsInputs(ToscaFunctionConstants.SOURCE, null, source.getTemplate().getProperties(), interfaces, baseName -> StringUtils.joinWith(AlienUtils.DEFAULT_PREFIX_SEPARATOR, ToscaFunctionConstants.SOURCE, baseName)); }
private Map<String, Object> getAggregatedVolumeIds(DeploymentTopology topology, String nodeTemplateId, Map<String, Object> persistentProperties) { NodeTemplate nodeTemplate; try { nodeTemplate = TopologyUtils.getNodeTemplate(topology, nodeTemplateId); } catch (NotFoundException e) { log.warn("Fail to update volumeIds for node " + nodeTemplateId, e); return null; } Map<String, Object> aggregatedProperties = Maps.newHashMap(); Map<String, Object> concernedNodeProperties = extractConcernedNodeProperties(nodeTemplate.getName(), nodeTemplate.getProperties(), persistentProperties.keySet()); List<Map<String, String>> splittedNodeProperties = splitNodePropertiesValue(concernedNodeProperties); if (!persistentPropertiesAlreadyExist(persistentProperties, splittedNodeProperties)) { aggregatedProperties = buildAggregatedProperties(persistentProperties, concernedNodeProperties); } return aggregatedProperties; }
private void setNodePropertyPathValue(Csar csar, Topology topology, NodeTemplate nodeTemplate, String propertyPath, AbstractPropertyValue propertyValue, boolean lastPropertyIsAList) { Map<String, AbstractPropertyValue> propertyValues = nodeTemplate.getProperties(); String nodePropertyName = feedPropertyValue(propertyValues, propertyPath, propertyValue, lastPropertyIsAList); Object nodePropertyValue = propertyValues.get(nodePropertyName); UpdateNodePropertyValueOperation updateNodePropertyValueOperation = new UpdateNodePropertyValueOperation(); updateNodePropertyValueOperation.setNodeName(nodeTemplate.getName()); updateNodePropertyValueOperation.setPropertyName(nodePropertyName); // TODO: can be necessary to serialize value before setting it in case of different types updateNodePropertyValueOperation.setPropertyValue(nodePropertyValue); updateNodePropertyValueProcessor.process(csar, topology, updateNodePropertyValueOperation); }
@Override protected void processNodeOperation(Csar csar, Topology topology, SetNodePropertyAsOutputOperation operation, NodeTemplate nodeTemplate) { // check if the property exists Map<String, AbstractPropertyValue> properties = nodeTemplate.getProperties(); if (!AlienUtils.safe(properties).containsKey(operation.getPropertyName())) { throw new NotFoundException("Property " + operation.getPropertyName() + "not found in node template " + operation.getNodeName() + "."); } Map<String, Set<String>> outputs = topology.getOutputProperties(); if (outputs == null) { outputs = Maps.newHashMap(); } if (outputs.containsKey(operation.getNodeName())) { outputs.get(operation.getNodeName()).add(operation.getPropertyName()); } else { outputs.put(operation.getNodeName(), Sets.newHashSet(operation.getPropertyName())); } topology.setOutputProperties(outputs); log.debug("Set node [ {} ]'s property [ {} ] as output for the topology [ {} ].", operation.getNodeName(), operation.getPropertyName(), topology.getId()); }
@Override protected void processNodeOperation(Csar csar, Topology topology, UnsetNodePropertyAsInputOperation operation, NodeTemplate nodeTemplate) { // check if the node property value is a get_input AbstractPropertyValue currentValue = nodeTemplate.getProperties().get(operation.getPropertyName()); if (!isGetInput(currentValue)) { throw new NotFoundException("Property {} of node {} is not associated to an input.", operation.getPropertyName(), operation.getNodeName()); } NodeType nodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType()); PropertyDefinition nodePropertyDefinition = getOrFail(nodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName()); AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(nodePropertyDefinition); nodeTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue); log.debug("Remove association from property [ {} ] of the node template [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), topology.getId()); } }
@Override protected void processNodeOperation(Csar csar, Topology topology, UnsetNodePropertyAsSecretOperation operation, NodeTemplate nodeTemplate) { // check if the node property value is a get_secret AbstractPropertyValue currentValue = nodeTemplate.getProperties().get(operation.getPropertyName()); if (currentValue != null && !isGetSecret(currentValue)) { throw new NotFoundException("Property {} of node {} is not associated to an secret.", operation.getPropertyName(), operation.getNodeName()); } NodeType nodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType()); PropertyDefinition nodePropertyDefinition = getOrFail(nodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName()); AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(nodePropertyDefinition); nodeTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue); log.debug("Remove secret property [ {} ] of the node template [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), topology.getId()); } }
public ServiceNodeTemplate(NodeTemplate nodeTemplate, Map<String, String> attributeValues) { super(nodeTemplate.getType(), nodeTemplate.getProperties(), nodeTemplate.getAttributes(), nodeTemplate.getRelationships(), nodeTemplate.getRequirements(), nodeTemplate.getCapabilities(), nodeTemplate.getInterfaces(), nodeTemplate.getArtifacts()); this.attributeValues = attributeValues; }
@SuppressWarnings("unchecked") private void check(UnSetNodePropertyAsOutputOperation operation, Topology topology, NodeTemplate nodeTemplate) { Map<String, AbstractPropertyValue> properties = nodeTemplate.getProperties(); if (!AlienUtils.safe(properties).containsKey(operation.getPropertyName())) { throw new NotFoundException("Property " + operation.getPropertyName() + "not found in node template " + operation.getNodeName() + "."); } Set<String> values = (Set<String>) MapUtil.get(topology.getOutputProperties(), operation.getNodeName()); if (!AlienUtils.safe(values).contains(operation.getPropertyName())) { throw new NotFoundException("Node " + operation.getNodeName() + " 's property " + operation.getPropertyName() + " not found in outputs"); } }
@Then("^The topology should contain a nodetemplate named \"([^\"]*)\" with property \"([^\"]*)\" set to \"([^\"]*)\"$") public void The_topology_should_contain_a_nodetemplate_named_with_property_set_to(String nodeTemplateName, String propertyName, String propertyValue) throws Throwable { The_topology_should_contain_a_nodetemplate_named(nodeTemplateName); String topologyResponseText = Context.getInstance().getRestResponse(); NodeTemplate nodeTemp = JsonUtil.read(topologyResponseText, TopologyDTO.class, Context.getJsonMapper()).getData().getTopology().getNodeTemplates() .get(nodeTemplateName); assertNotNull(nodeTemp.getProperties()); if (propertyValue != null) { assertNotNull(nodeTemp.getProperties().get(propertyName)); } assertEquals(propertyValue, PropertyUtil.getScalarValue(nodeTemp.getProperties().get(propertyName))); }
@Override protected void processNodeOperation(Csar csar, Topology topology, SetNodePropertyAsSecretOperation operation, NodeTemplate nodeTemplate) { NodeType indexedNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType()); getOrFail(indexedNodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName()); if (operation.getPropertyName().equals(FORBIDDEN_PROPERTY)) { throw new UnsupportedSecretException("We cannot set a secret on the property " + operation.getPropertyName()); } if ("".equals(operation.getSecretPath())) { throw new InvalidSecretPathException("The secret path to the property " + operation.getPropertyName() + " is null."); } FunctionPropertyValue getSecret = new FunctionPropertyValue(); getSecret.setFunction(ToscaFunctionConstants.GET_SECRET); getSecret.setParameters(Arrays.asList(operation.getSecretPath())); nodeTemplate.getProperties().put(operation.getPropertyName(), getSecret); log.debug("Associate the property [ {} ] of the node template [ {} ] as secret [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), operation.getSecretPath(), topology.getId()); } }
@Then("^The node \"([^\"]*)\" in the deployment topology should have the property \"([^\"]*)\" with a secret function having a secret path \"([^\"]*)\"$") public void theNodeInTheDeploymentTopologyShouldHaveThePropertyWithASecretFunctionHavingASecretPath(String nodeName, String propertyName, String secretPath) throws Throwable { DeploymentTopologyDTO dto = getDeploymentTopologyDTO(); NodeTemplate node = dto.getTopology().getNodeTemplates().get(nodeName); FunctionPropertyValue actualPropertyValue = (FunctionPropertyValue) node.getProperties().get(propertyName); FunctionPropertyValue expectedPropertyValue = new FunctionPropertyValue(); expectedPropertyValue.setFunction(ToscaFunctionConstants.GET_SECRET); expectedPropertyValue.setParameters(Arrays.asList(secretPath)); Assert.assertEquals(actualPropertyValue, expectedPropertyValue); }
private void assertNodePropertyValueEquals(NodeTemplate node, String propertyName, String expectedPropertyValue) { assertNotNull(node); AbstractPropertyValue abstractProperty = MapUtils.getObject(node.getProperties(), propertyName); assertEquals(expectedPropertyValue, PropertyUtil.getScalarValue(abstractProperty)); }
@Override public void process(Csar csar, Topology topology, UpdateNodePropertyValueOperation operation) { Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology); NodeTemplate nodeTemp = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates); String propertyName = operation.getPropertyName(); Object propertyValue = operation.getPropertyValue(); NodeType node = ToscaContext.getOrFail(NodeType.class, nodeTemp.getType()); PropertyDefinition propertyDefinition = node.getProperties().get(propertyName); if (propertyDefinition == null) { throw new NotFoundException( "Property <" + propertyName + "> doesn't exists for node <" + operation.getNodeName() + "> of type <" + nodeTemp.getType() + ">"); } log.debug("Updating property [ {} ] of the Node template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", propertyName, operation.getNodeName(), topology.getId(), nodeTemp.getProperties().get(propertyName), propertyValue); try { propertyService.setPropertyValue(nodeTemp, propertyDefinition, propertyName, propertyValue); } catch (ConstraintFunctionalException e) { throw new PropertyValueException("Error when setting node " + operation.getNodeName() + " property.", e, propertyName, propertyValue); } } }
@And("^The topology should have the property \"([^\"]*)\" of a node \"([^\"]*)\" defined as a secret with a secret path \"([^\"]*)\"$") public void theTopologyShouldHaveThePropertyDefinedAsASecretWithASecretPath(String propertyName, String nodeName, String secretPath) throws Throwable { String response = Context.getRestClientInstance().get("/rest/v1/topologies/" + Context.getInstance().getTopologyId()); JavaType restResponseType = Context.getJsonMapper().getTypeFactory().constructParametricType(RestResponse.class, TopologyDTO.class); TopologyDTO topologyDTO = ((RestResponse<TopologyDTO>) Context.getJsonMapper().readValue(response, restResponseType)).getData(); FunctionPropertyValue functionPropertyValue = (FunctionPropertyValue) topologyDTO.getTopology().getNodeTemplates().get(nodeName).getProperties().get(propertyName); Assert.assertEquals(secretPath, functionPropertyValue.getParameters().get(0)); }
@Override protected void processNodeOperation(Csar csar, Topology topology, SetNodePropertyAsInputOperation operation, NodeTemplate nodeTemplate) { PropertyDefinition inputPropertyDefinition = getOrFail(topology.getInputs(), operation.getInputName(), "Input {} not found in topology", operation.getInputName()); NodeType indexedNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType()); PropertyDefinition nodePropertyDefinition = getOrFail(indexedNodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName()); // Check that the property definition of the input is indeed compatible with the property definition of the capability. inputPropertyDefinition.checkIfCompatibleOrFail(nodePropertyDefinition); FunctionPropertyValue getInput = new FunctionPropertyValue(); getInput.setFunction(ToscaFunctionConstants.GET_INPUT); getInput.setParameters(Arrays.asList(operation.getInputName())); nodeTemplate.getProperties().put(operation.getPropertyName(), getInput); log.debug("Associate the property [ {} ] of the node template [ {} ] to input [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), operation.getInputName(), topology.getId()); } }
private String getVolumeId(String propertyName, String nodeName, String appName) throws IOException { String topologyResponseText = Context.getRestClientInstance().get( "/rest/v1/applications/" + Context.getInstance().getApplicationId(appName) + "/environments/" + Context.getInstance().getDefaultApplicationEnvironmentId(appName) + "/deployment-topology"); RestResponse<DeploymentTopologyDTO> topologyResponse = JsonUtil.read(topologyResponseText, DeploymentTopologyDTO.class, Context.getJsonMapper()); String volumeId = PropertyUtil.getScalarValue(topologyResponse.getData().getTopology().getNodeTemplates().get(nodeName).getProperties() .get(propertyName)); Assert.assertNotNull(volumeId); int indexOfEndRegion = volumeId.indexOf('/'); if (indexOfEndRegion > 0) { volumeId = volumeId.substring(indexOfEndRegion + 1); } return volumeId; }
public String duplicate(String serviceId) throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException { ServiceResource serviceResource = getOrFail(serviceId); if (serviceResource.getEnvironmentId() != null) { throw new UnsupportedOperationException("Alien managed services cannot be duplicated."); } // TODO: better naming deduplicate strategy String serviceName = serviceResource.getName() + "_copy"; String serviceVersion = serviceResource.getVersion(); String description = serviceResource.getDescription(); String nodeType = serviceResource.getNodeInstance().getNodeTemplate().getType(); String nodeVersion = serviceResource.getNodeInstance().getTypeVersion(); String newServiceId = create(serviceName, serviceVersion, nodeType, nodeVersion); Map<String, String> attributeValues = serviceResource.getNodeInstance().getAttributeValues(); attributeValues.put(ToscaNodeLifecycleConstants.ATT_STATE, ToscaNodeLifecycleConstants.INITIAL); NodeTemplate nodeTemplate = serviceResource.getNodeInstance().getNodeTemplate(); update(newServiceId, serviceName, serviceVersion, description, nodeType, nodeVersion, nodeTemplate.getProperties(), nodeTemplate.getCapabilities(), attributeValues, serviceResource.getLocationIds(), null, null); return newServiceId; }