Search in sources :

Example 1 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class UnsetNodeCapabilityPropertyAsSecretProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodeCapabilityPropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
    Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} do not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
    // check if the node property value is a get_secret
    AbstractPropertyValue currentValue = capabilityTemplate.getProperties().get(operation.getPropertyName());
    if (currentValue != null && !isGetSecret(currentValue)) {
        throw new NotFoundException("Property {} of node {} is not an secret.", operation.getPropertyName(), operation.getNodeName());
    }
    CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType());
    PropertyDefinition capabilityPropertyDefinition = getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName());
    AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(capabilityPropertyDefinition);
    capabilityTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
    log.debug("Remove secret property [ {} ] of capability template [ {} ] of node [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) NotFoundException(alien4cloud.exception.NotFoundException) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 2 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class ToscaTypeConverter method toPropertyValue.

@SuppressWarnings("unchecked")
public PropertyValue toPropertyValue(Object resolvedPropertyValue, PropertyDefinition propertyDefinition) {
    if (resolvedPropertyValue == null) {
        return null;
    }
    if (ToscaTypes.isSimple(propertyDefinition.getType())) {
        return new ScalarPropertyValue(resolvedPropertyValue.toString());
    }
    switch(propertyDefinition.getType()) {
        case ToscaTypes.MAP:
            if (resolvedPropertyValue instanceof Map) {
                Map<String, Object> map = (Map<String, Object>) resolvedPropertyValue;
                Map<String, Object> resultMap = Maps.newHashMap();
                map.forEach((key, value) -> resultMap.put(key, toPropertyValue(value, propertyDefinition.getEntrySchema())));
                return new ComplexPropertyValue(resultMap);
            } else {
                throw new IllegalStateException("Property value: expected type [" + Map.class.getSimpleName() + "] but got [" + resolvedPropertyValue.getClass().getName() + "]");
            }
        case ToscaTypes.LIST:
            if (resolvedPropertyValue instanceof Collection) {
                List list = (List) resolvedPropertyValue;
                List resultList = new LinkedList();
                for (Object item : list) {
                    resultList.add(toPropertyValue(item, propertyDefinition.getEntrySchema()));
                }
                return new ListPropertyValue(resultList);
            } else {
                throw new IllegalStateException("Property value: expected type [" + Collection.class.getSimpleName() + "] but got [" + resolvedPropertyValue.getClass().getName() + "]");
            }
        default:
            DataType dataType = findDataType(propertyDefinition.getType());
            if (dataType == null) {
                throw new NotFoundException("Data type  [" + propertyDefinition.getType() + "] cannot be found");
            }
            if (dataType.isDeriveFromSimpleType()) {
                return new ScalarPropertyValue(resolvedPropertyValue.toString());
            } else if (resolvedPropertyValue instanceof Map) {
                Map<String, Object> map = (Map<String, Object>) resolvedPropertyValue;
                /*
                 * Map<String, Object> resultMap = Maps.newHashMap();
                 * 
                 * map.forEach((key, value) -> {
                 * PropertyDefinition entryDefinition = dataType.getProperties().get(key);
                 * if(entryDefinition == null){
                 * throw new IllegalStateException("DataType [" + propertyDefinition.getType() + "] does not contains any definition for entry [" + key + "]");
                 * }
                 * resultMap.put(key, toPropertyValue(value, entryDefinition));
                 * });
                 * return new ComplexPropertyValue(resultMap);
                 */
                return new ComplexPropertyValue(map);
            } else {
                throw new IllegalStateException("Property value: expected type [" + propertyDefinition.getType() + "] but got [" + resolvedPropertyValue.getClass().getName() + "]");
            }
    }
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) LinkedList(java.util.LinkedList) Collection(java.util.Collection) ListPropertyValue(org.alien4cloud.tosca.model.definitions.ListPropertyValue) DataType(org.alien4cloud.tosca.model.types.DataType) PrimitiveDataType(org.alien4cloud.tosca.model.types.PrimitiveDataType) List(java.util.List) LinkedList(java.util.LinkedList) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) Map(java.util.Map)

Example 3 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class AddCapabilitySubstitutionTypeProcessor method process.

@Override
public void process(Csar csar, Topology topology, AddCapabilitySubstitutionTypeOperation operation) {
    if (topology.getNodeTemplates() == null || !topology.getNodeTemplates().containsKey(operation.getNodeTemplateName())) {
        throw new NotFoundException("Node " + operation.getNodeTemplateName() + " do not exist");
    }
    NodeTemplate nodeTemplate = topology.getNodeTemplates().get(operation.getNodeTemplateName());
    if (nodeTemplate.getCapabilities() == null || !nodeTemplate.getCapabilities().containsKey(operation.getCapabilityId())) {
        throw new NotFoundException("Capability " + operation.getCapabilityId() + " do not exist for node " + operation.getNodeTemplateName());
    }
    if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) {
        throw new NotFoundException("No substitution type has been found");
    }
    Map<String, SubstitutionTarget> substitutionCapabilities = topology.getSubstitutionMapping().getCapabilities();
    if (substitutionCapabilities == null) {
        substitutionCapabilities = Maps.newHashMap();
        topology.getSubstitutionMapping().setCapabilities(substitutionCapabilities);
    } else if (substitutionCapabilities.containsKey(operation.getSubstitutionCapabilityId())) {
        // ensure name unicity
        throw new AlreadyExistException(String.format("A substitution with capability id <%s> already exists", operation.getSubstitutionCapabilityId()));
    }
    substitutionCapabilities.put(operation.getSubstitutionCapabilityId(), new SubstitutionTarget(operation.getNodeTemplateName(), operation.getCapabilityId()));
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NotFoundException(alien4cloud.exception.NotFoundException) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) AlreadyExistException(alien4cloud.exception.AlreadyExistException)

Example 4 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class AddSubstitutionTypeProcessor method process.

@Override
public void process(Csar csar, Topology topology, AddSubstitutionTypeOperation operation) {
    if (topology.getSubstitutionMapping() == null) {
        topology.setSubstitutionMapping(new SubstitutionMapping());
    }
    NodeType nodeType = toscaTypeSearchService.getElementInDependencies(NodeType.class, operation.getElementId(), topology.getDependencies());
    // if not null the node type exists in the dependencies, there is no choices for this type version
    if (nodeType == null) {
        // the node type does'nt exist in this topology dependencies
        // we need to find the latest version of this component and use it as default
        nodeType = toscaTypeSearchService.findMostRecent(NodeType.class, operation.getElementId());
        if (nodeType == null) {
            throw new NotFoundException("Node type with name <" + operation.getElementId() + "> cannot be found in the catalog.");
        }
        topologyService.loadType(topology, nodeType);
    }
    topology.getSubstitutionMapping().setSubstitutionType(operation.getElementId());
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException) SubstitutionMapping(org.alien4cloud.tosca.model.templates.SubstitutionMapping)

Example 5 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class RemoveCapabilitySubstitutionTypeProcessor method process.

@Override
public void process(Csar csar, Topology topology, RemoveCapabilitySubstitutionTypeOperation operation) {
    if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) {
        throw new NotFoundException("No substitution type has been found");
    }
    Map<String, SubstitutionTarget> substitutionCapabilities = topology.getSubstitutionMapping().getCapabilities();
    if (substitutionCapabilities == null) {
        throw new NotFoundException("No substitution capabilities has been found");
    }
    SubstitutionTarget target = substitutionCapabilities.remove(operation.getSubstitutionCapabilityId());
    if (target == null) {
        throw new NotFoundException("No substitution capability has been found for key " + operation.getSubstitutionCapabilityId());
    }
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget)

Aggregations

NotFoundException (alien4cloud.exception.NotFoundException)88 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)17 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)12 Map (java.util.Map)10 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)10 AlreadyExistException (alien4cloud.exception.AlreadyExistException)9 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)9 Capability (org.alien4cloud.tosca.model.templates.Capability)9 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)8 SubstitutionTarget (org.alien4cloud.tosca.model.templates.SubstitutionTarget)8 Topology (org.alien4cloud.tosca.model.templates.Topology)7 Deployment (alien4cloud.model.deployment.Deployment)6 ApiOperation (io.swagger.annotations.ApiOperation)6 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)6 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)6 InvalidNameException (alien4cloud.exception.InvalidNameException)5 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5