Search in sources :

Example 16 with NotFoundException

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

the class RuntimeController method validateOperation.

private void validateOperation(Interface interfass, OperationExecRequest operationRequest, Set<CSARDependency> dependencies) throws ConstraintFunctionalException {
    Operation operation = interfass.getOperations().get(operationRequest.getOperationName());
    if (operation == null) {
        throw new NotFoundException("Operation [" + operationRequest.getOperationName() + "] is not defined in the interface [" + operationRequest.getInterfaceName() + "] of the node [" + operationRequest.getNodeTemplateName() + "]");
    }
    // validate parameters (value/type and required value)
    validateParameters(interfass, operationRequest, dependencies);
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) Operation(org.alien4cloud.tosca.model.definitions.Operation)

Example 17 with NotFoundException

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

the class RuntimeController method validateCommand.

private void validateCommand(OperationExecRequest operationRequest, Topology topology) throws ConstraintFunctionalException {
    NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operationRequest.getNodeTemplateName(), TopologyUtils.getNodeTemplates(topology));
    NodeType indexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), topology.getDependencies());
    Map<String, Interface> interfaces = IndexedModelUtils.mergeInterfaces(indexedNodeType.getInterfaces(), nodeTemplate.getInterfaces());
    if (interfaces == null || interfaces.get(operationRequest.getInterfaceName()) == null) {
        throw new NotFoundException("Interface [" + operationRequest.getInterfaceName() + "] not found in the node template [" + operationRequest.getNodeTemplateName() + "] related to [" + indexedNodeType.getId() + "]");
    }
    Interface interfass = interfaces.get(operationRequest.getInterfaceName());
    validateOperation(interfass, operationRequest, topology.getDependencies());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 18 with NotFoundException

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

the class RuntimeController method getDeployedTopology.

/**
 * Get runtime (deployed) topology of an application on a specific environment
 *
 * @param applicationId application id for which to get the topology
 * @param applicationEnvironmentId application environment for which to get the topology through the version
 * @return {@link RestResponse}<{@link TopologyDTO}> containing the requested runtime {@link Topology} and the
 *         {@link NodeType} related to his {@link NodeTemplate}s
 */
@ApiOperation(value = "Get runtime (deployed) topology of an application on a specific cloud.")
@RequestMapping(value = "/{applicationId:.+?}/environment/{applicationEnvironmentId:.+?}/topology", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<TopologyDTO> getDeployedTopology(@ApiParam(value = "Id of the application for which to get deployed topology.", required = true) @PathVariable String applicationId, @ApiParam(value = "Id of the environment for which to get deployed topology.", required = true) @PathVariable String applicationEnvironmentId) {
    ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(applicationId, applicationEnvironmentId);
    if (!environment.getApplicationId().equals(applicationId)) {
        throw new NotFoundException("Unable to find environment with id <" + applicationEnvironmentId + "> for application <" + applicationId + ">");
    }
    // Security check user must be authorized to deploy the environment (or be application manager)
    AuthorizationUtil.checkAuthorizationForEnvironment(applicationService.getOrFail(applicationId), environment);
    Deployment deployment = deploymentService.getActiveDeploymentOrFail(environment.getId());
    DeploymentTopology deploymentTopology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
    return RestResponseBuilder.<TopologyDTO>builder().data(topologyDTOBuilder.initTopologyDTO(deploymentTopology, new TopologyDTO())).build();
}
Also used : TopologyDTO(alien4cloud.topology.TopologyDTO) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) NotFoundException(alien4cloud.exception.NotFoundException) Deployment(alien4cloud.model.deployment.Deployment) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with NotFoundException

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

the class WorkflowEventHandler method checkDeploymentAuthorization.

private void checkDeploymentAuthorization(Authentication authentication, User a4cUser, String deploymentId) {
    Deployment deployment = alienDAO.findById(Deployment.class, deploymentId);
    switch(deployment.getSourceType()) {
        case APPLICATION:
            // check if the user has right for the environment associated with the deployment.
            ApplicationEnvironment environment = alienDAO.findById(ApplicationEnvironment.class, deployment.getEnvironmentId());
            if (environment == null) {
                log.error("Environment with id [{}] do not exist any more for deployment [{}]", deployment.getEnvironmentId(), deployment.getId());
                throw new NotFoundException("Environment with id [" + deployment.getEnvironmentId() + "] do not exist any more for deployment [" + deployment.getId() + "]");
            }
            AuthorizationUtil.checkAuthorization(a4cUser, environment, ApplicationRole.APPLICATION_MANAGER, ApplicationEnvironmentRole.values());
            break;
        case CSAR:
            AuthorizationUtil.checkHasOneRoleIn(authentication, Role.COMPONENTS_MANAGER);
    }
}
Also used : Deployment(alien4cloud.model.deployment.Deployment) NotFoundException(alien4cloud.exception.NotFoundException) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment)

Example 20 with NotFoundException

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

the class WorkflowPostProcessor method finalizeParsedWorkflows.

/**
 * Called after yaml parsing.
 */
private void finalizeParsedWorkflows(TopologyContext topologyContext, Node node) {
    if (MapUtils.isEmpty(topologyContext.getTopology().getWorkflows())) {
        return;
    }
    normalizeWorkflowNames(topologyContext.getTopology().getWorkflows());
    for (Workflow wf : topologyContext.getTopology().getWorkflows().values()) {
        wf.setStandard(WorkflowUtils.isStandardWorkflow(wf));
        if (wf.getSteps() != null) {
            for (WorkflowStep step : wf.getSteps().values()) {
                if (step.getOnSuccess() != null) {
                    Iterator<String> followingIds = step.getOnSuccess().iterator();
                    while (followingIds.hasNext()) {
                        String followingId = followingIds.next();
                        WorkflowStep followingStep = wf.getSteps().get(followingId);
                        if (followingStep == null) {
                            followingIds.remove();
                            ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKNWON_WORKFLOW_STEP, null, getSafeNodeStartMark(node), null, getSafeNodeEndMark(node), followingId));
                        } else {
                            followingStep.addPreceding(step.getName());
                        }
                    }
                }
            }
        }
        try {
            WorkflowUtils.fillHostId(wf, topologyContext);
        } catch (NotFoundException e) {
            log.trace("Not found exception during fill host id occurs when a relationship specified in workflow does not exist. This exception is ignored as the workflow validation trigger errors for such situations.", e);
        }
        int errorCount = workflowBuilderService.validateWorkflow(topologyContext, wf);
        if (errorCount > 0) {
            processWorkflowErrors(wf, wf.getErrors(), node);
        }
    }
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) NotFoundException(alien4cloud.exception.NotFoundException)

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