Search in sources :

Example 31 with NotFoundException

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

the class AddRelationshipProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, AddRelationshipOperation operation, NodeTemplate sourceNode) {
    if (operation.getRelationshipName() == null || operation.getRelationshipName().isEmpty()) {
        throw new InvalidNameException("relationshipName", operation.getRelationshipName(), "Not null or empty");
    }
    if (AlienUtils.safe(sourceNode.getRelationships()).containsKey(operation.getRelationshipName())) {
        throw new AlreadyExistException("Relationship " + operation.getRelationshipName() + " already exist on node " + operation.getNodeName());
    }
    if (sourceNode.getRequirements() == null || sourceNode.getRequirements().get(operation.getRequirementName()) == null) {
        throw new NotFoundException("Unable to find requirement with name <" + operation.getRequirementName() + "> on the source node" + operation.getNodeName());
    }
    Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
    // ensure that the target node exists
    TopologyUtils.getNodeTemplate(topology.getId(), operation.getTarget(), nodeTemplates);
    // We don't use the tosca context as the relationship type may not be in dependencies yet (that's why we use the load type below).
    RelationshipType indexedRelationshipType = toscaTypeSearchService.find(RelationshipType.class, operation.getRelationshipType(), operation.getRelationshipVersion());
    if (indexedRelationshipType == null) {
        throw new NotFoundException(RelationshipType.class.getName(), operation.getRelationshipType() + ":" + operation.getRelationshipVersion(), "Unable to find relationship type to create template in topology.");
    }
    boolean upperBoundReachedSource = topologyRequirementBoundsValidationServices.isRequirementUpperBoundReachedForSource(sourceNode, operation.getRequirementName(), topology.getDependencies());
    if (upperBoundReachedSource) {
        // throw exception here
        throw new RequirementBoundException(operation.getNodeName(), operation.getRequirementName());
    }
    boolean upperBoundReachedTarget = topologyCapabilityBoundsValidationServices.isCapabilityUpperBoundReachedForTarget(operation.getTarget(), nodeTemplates, operation.getTargetedCapabilityName(), topology.getDependencies());
    // return with a rest response error
    if (upperBoundReachedTarget) {
        throw new CapabilityBoundException(operation.getTarget(), operation.getTargetedCapabilityName());
    }
    topologyService.loadType(topology, indexedRelationshipType);
    NodeTemplate newSourceNode = topology.getNodeTemplates().get(sourceNode.getName());
    if (sourceNode != newSourceNode) {
        // topology has been reloaded
        sourceNode = newSourceNode;
    }
    Map<String, RelationshipTemplate> relationships = sourceNode.getRelationships();
    if (relationships == null) {
        relationships = Maps.newHashMap();
        sourceNode.setRelationships(relationships);
    }
    RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
    relationshipTemplate.setName(operation.getRelationshipName());
    relationshipTemplate.setTarget(operation.getTarget());
    relationshipTemplate.setTargetedCapabilityName(operation.getTargetedCapabilityName());
    relationshipTemplate.setRequirementName(operation.getRequirementName());
    relationshipTemplate.setRequirementType(sourceNode.getRequirements().get(operation.getRequirementName()).getType());
    relationshipTemplate.setType(indexedRelationshipType.getElementId());
    relationshipTemplate.setArtifacts(newLinkedHashMap(indexedRelationshipType.getArtifacts()));
    relationshipTemplate.setAttributes(newLinkedHashMap(indexedRelationshipType.getAttributes()));
    Map<String, AbstractPropertyValue> properties = new LinkedHashMap<String, AbstractPropertyValue>();
    TemplateBuilder.fillProperties(properties, indexedRelationshipType.getProperties(), null);
    relationshipTemplate.setProperties(properties);
    relationships.put(operation.getRelationshipName(), relationshipTemplate);
    TopologyContext topologyContext = workflowBuilderService.buildTopologyContext(topology, csar);
    workflowBuilderService.addRelationship(topologyContext, operation.getNodeName(), operation.getRelationshipName());
    log.debug("Added relationship to the topology [" + topology.getId() + "], node name [" + operation.getNodeName() + "], relationship name [" + operation.getRelationshipName() + "]");
}
Also used : CapabilityBoundException(org.alien4cloud.tosca.editor.exception.CapabilityBoundException) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) NotFoundException(alien4cloud.exception.NotFoundException) LinkedHashMap(java.util.LinkedHashMap) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) InvalidNameException(alien4cloud.exception.InvalidNameException) RequirementBoundException(org.alien4cloud.tosca.editor.exception.RequirementBoundException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) TopologyContext(alien4cloud.paas.wf.TopologyContext) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 32 with NotFoundException

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

the class UnsetNodeCapabilityPropertyAsInputProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodeCapabilityPropertyAsInputOperation 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_input
    AbstractPropertyValue currentValue = capabilityTemplate.getProperties().get(operation.getPropertyName());
    if (!isGetInput(currentValue)) {
        throw new NotFoundException("Property {} of node {} is not associated to an input.", 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 association from property [ {} ] of capability template [ {} ] of node [ {} ] to an input 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 33 with NotFoundException

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

the class PreDeploymentTopologyValidator method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    DeploymentMatchingConfiguration matchingConfiguration = context.getConfiguration(DeploymentMatchingConfiguration.class, PreDeploymentTopologyValidator.class.getSimpleName()).orElseThrow(() -> new NotFoundException("Failed to find deployment configuration for pre-deployment validation."));
    OrchestratorDeploymentProperties orchestratorDeploymentProperties = context.getConfiguration(OrchestratorDeploymentProperties.class, PreDeploymentTopologyValidator.class.getSimpleName()).orElse(new OrchestratorDeploymentProperties(matchingConfiguration.getVersionId(), matchingConfiguration.getEnvironmentId(), matchingConfiguration.getOrchestratorId()));
    TopologyValidationResult validationResult = deploymentTopologyValidationService.validateProcessedDeploymentTopology(topology, matchingConfiguration, orchestratorDeploymentProperties);
    for (AbstractTask task : safe(validationResult.getTaskList())) {
        context.log().error(task);
    }
    for (AbstractTask task : safe(validationResult.getInfoList())) {
        context.log().info(task);
    }
    for (AbstractTask task : safe(validationResult.getWarningList())) {
        context.log().warn(task);
    }
}
Also used : TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) AbstractTask(alien4cloud.topology.task.AbstractTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) NotFoundException(alien4cloud.exception.NotFoundException) OrchestratorDeploymentProperties(org.alien4cloud.alm.deployment.configuration.model.OrchestratorDeploymentProperties)

Example 34 with NotFoundException

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

the class SetMatchedNodePropertyModifier method setNodeCapabilityProperty.

private void setNodeCapabilityProperty(FlowExecutionContext context, LocationResourceTemplate locationResourceTemplate, NodeTemplate nodeTemplate, String capabilityName, DeploymentMatchingConfiguration matchingConfiguration) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
    Capability locationResourceCapability = locationResourceTemplate.getTemplate().getCapabilities().get(capabilityName);
    if (locationResourceCapability == null) {
        throw new NotFoundException("The capability <" + capabilityName + "> cannot be found on node template <" + templateId + "> of type <" + locationResourceTemplate.getTemplate().getType() + ">");
    }
    PropertyDefinition propertyDefinition = ToscaContext.getOrFail(CapabilityType.class, locationResourceCapability.getType()).getProperties().get(propertyName);
    if (propertyDefinition == null) {
        throw new NotFoundException("No property with name <" + propertyName + "> can be found on capability <" + capabilityName + "> of type <" + locationResourceCapability.getType() + ">");
    }
    AbstractPropertyValue locationResourcePropertyValue = locationResourceTemplate.getTemplate().getCapabilities().get(capabilityName).getProperties().get(propertyName);
    ensureNotSet(locationResourcePropertyValue, "by the admin in the Location Resource Template", propertyName, propertyValue);
    AbstractPropertyValue originalNodePropertyValue = safe(nodeTemplate.getCapabilities().get(capabilityName).getProperties()).get(propertyName);
    ensureNotSet(originalNodePropertyValue, "in the portable topology", propertyName, propertyValue);
    // Update the configuration
    NodePropsOverride nodePropsOverride = getTemplatePropsOverride(matchingConfiguration);
    if (propertyValue == null && nodePropsOverride.getCapabilities().get(capabilityName) != null) {
        nodePropsOverride.getCapabilities().get(capabilityName).getProperties().remove(propertyName);
    } else {
        // Set check constraints
        ConstraintPropertyService.checkPropertyConstraint(propertyName, propertyValue, propertyDefinition);
        NodeCapabilitiesPropsOverride nodeCapabilitiesPropsOverride = nodePropsOverride.getCapabilities().computeIfAbsent(capabilityName, k -> new NodeCapabilitiesPropsOverride());
        nodeCapabilitiesPropsOverride.getProperties().put(propertyName, PropertyService.asPropertyValue(propertyValue));
    }
    context.saveConfiguration(matchingConfiguration);
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability) NodePropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodePropsOverride) NotFoundException(alien4cloud.exception.NotFoundException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) NodeCapabilitiesPropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodeCapabilitiesPropsOverride)

Example 35 with NotFoundException

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

the class TopologyService method loadType.

/**
 * Load a type into the topology (add dependency for this new type, upgrade if necessary ...)
 *
 * If the dependency added has been upgraded into the topology, then recover the topology
 *
 * @param topology the topology
 * @param element the element to load
 * @param <T> tosca element type
 * @return The real loaded element if element given in argument is from older archive than topology's dependencies
 */
@SuppressWarnings("unchecked")
public <T extends AbstractToscaType> T loadType(Topology topology, T element) {
    String type = element.getElementId();
    String archiveName = element.getArchiveName();
    String archiveVersion = element.getArchiveVersion();
    CSARDependency toLoadDependency = csarDependencyLoader.buildDependencyBean(archiveName, archiveVersion);
    // FIXME Transitive dependencies could change here and thus types be affected ?
    ToscaTypeLoader typeLoader = initializeTypeLoader(topology, true);
    boolean upgraded = typeLoader.loadType(type, toLoadDependency);
    ToscaContext.get().resetDependencies(typeLoader.getLoadedDependencies());
    // Validate does not induce missing types
    try {
        this.checkForMissingTypes(topology);
    } catch (NotFoundException e) {
        // Revert changes made to the Context then throw.
        ToscaContext.get().resetDependencies(topology.getDependencies());
        throw new VersionConflictException("Adding the type [" + element.getId() + "] from archive [" + element.getArchiveName() + ":" + element.getArchiveVersion() + "] changes the topology dependencies and induces missing types. " + "Try with another version instead. Not found : [" + e.getMessage() + "].", e);
    }
    topology.setDependencies(typeLoader.getLoadedDependencies());
    // recover the topology if needed
    if (upgraded) {
        recover(topology, toLoadDependency);
    }
    return ToscaContext.getOrFail((Class<T>) element.getClass(), type);
}
Also used : VersionConflictException(alien4cloud.exception.VersionConflictException) ToscaTypeLoader(alien4cloud.tosca.container.ToscaTypeLoader) NotFoundException(alien4cloud.exception.NotFoundException) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

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