Search in sources :

Example 16 with Application

use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.

the class EditorStepDefs method init.

@Before
public void init() throws IOException {
    thrownException = null;
    GetMultipleDataResult<Application> apps = alienDAO.search(Application.class, "", null, 100);
    for (Application application : apps.getData()) {
        applicationService.delete(application.getId());
    }
    FacetedSearchResult<Topology> searchResult = catalogService.search(Topology.class, "", 100, null);
    Topology[] topologies = searchResult.getData();
    for (Topology topology : topologies) {
        try {
            csarService.forceDeleteCsar(topology.getId());
        } catch (NotFoundException e) {
            // Some previous tests may create topology without creating any archive, if so catch the exception
            alienDAO.delete(Topology.class, topology.getId());
        }
    }
    topologyIds.clear();
    editionContextManager.clearCache();
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) Topology(org.alien4cloud.tosca.model.templates.Topology) Application(alien4cloud.model.application.Application) Before(cucumber.api.java.Before)

Example 17 with Application

use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.

the class VariableResolverTest method setUp.

@Before
public void setUp() throws Exception {
    Resource yamlApp = new FileSystemResource("src/test/resources/alien/variables/variables_app_test.yml");
    Resource yamlEnvType = new FileSystemResource("src/test/resources/alien/variables/variables_env_type_test.yml");
    Resource yamlEnv = new FileSystemResource("src/test/resources/alien/variables/variables_env_test.yml");
    AlienContextVariables alienContextVariables = new AlienContextVariables();
    Application application = new Application();
    application.setName("originalAppName");
    alienContextVariables.setApplication(application);
    resolver = new VariableResolver(PropertiesYamlParser.ToProperties.from(yamlApp), PropertiesYamlParser.ToProperties.from(yamlEnvType), PropertiesYamlParser.ToProperties.from(yamlEnv), alienContextVariables);
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) Application(alien4cloud.model.application.Application) Before(org.junit.Before)

Example 18 with Application

use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.

the class AlienContextVariablesTest method setUp.

@Before
public void setUp() throws Exception {
    alienContextVariables = new AlienContextVariables();
    Application app = new Application();
    app.setTags(Arrays.asList(new Tag("tagName", "tagValue"), new Tag("yolo", "oloy")));
    app.setMetaProperties(ImmutableMap.of("meta1", "meta1 value", "meta2", "meta2 value"));
    alienContextVariables.setApplication(app);
    Location location = new Location();
    location.setMetaProperties(ImmutableMap.of("loc_meta1", "meta1 value", "loc_meta2", "meta2 value"));
    alienContextVariables.setLocation(location);
}
Also used : Tag(alien4cloud.model.common.Tag) Application(alien4cloud.model.application.Application) Location(alien4cloud.model.orchestrators.locations.Location) Before(org.junit.Before)

Example 19 with Application

use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.

the class RuntimeController method executeOperation.

@ApiOperation(value = "Trigger a custom command on a specific node template of a topology .", authorizations = { @Authorization("APPLICATION_MANAGER") }, notes = "Returns a response with no errors and the command response as data in success case. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/{applicationId:.+?}/operations", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("isAuthenticated()")
@Audit(bodyHiddenFields = { "secretProviderCredentials" })
public DeferredResult<RestResponse<Object>> executeOperation(@PathVariable String applicationId, @RequestBody @Valid OperationExecRequest operationRequest) {
    final DeferredResult<RestResponse<Object>> result = new DeferredResult<>(15L * 60L * 1000L);
    Application application = applicationService.getOrFail(applicationId);
    ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(applicationId, operationRequest.getApplicationEnvironmentId());
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
    Topology topology = deploymentRuntimeStateService.getRuntimeTopologyFromEnvironment(operationRequest.getApplicationEnvironmentId());
    // validate the operation request
    try {
        validateCommand(operationRequest, topology);
    } catch (ConstraintViolationException e) {
        result.setErrorResult(RestResponseBuilder.<Object>builder().data(e.getConstraintInformation()).error(new RestError(RestErrorCode.PROPERTY_CONSTRAINT_VIOLATION_ERROR.getCode(), e.getMessage())).build());
        return result;
    } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
        result.setErrorResult(RestResponseBuilder.<Object>builder().data(e.getConstraintInformation()).error(new RestError(RestErrorCode.PROPERTY_TYPE_VIOLATION_ERROR.getCode(), e.getMessage())).build());
        return result;
    } catch (ConstraintRequiredParameterException e) {
        result.setErrorResult(RestResponseBuilder.<Object>builder().data(e.getConstraintInformation()).error(new RestError(RestErrorCode.PROPERTY_REQUIRED_VIOLATION_ERROR.getCode(), e.getMessage())).build());
        return result;
    } catch (ConstraintFunctionalException e) {
        result.setErrorResult(RestResponseBuilder.<Object>builder().data(e.getConstraintInformation()).error(new RestError(RestErrorCode.PROPERTY_UNKNOWN_VIOLATION_ERROR.getCode(), e.getMessage())).build());
        return result;
    }
    // try to trigger the execution of the operation
    try {
        deploymentRuntimeService.triggerOperationExecution(operationRequest, new IPaaSCallback<Map<String, String>>() {

            @Override
            public void onSuccess(Map<String, String> data) {
                result.setResult(RestResponseBuilder.<Object>builder().data(data).build());
            }

            @Override
            public void onFailure(Throwable throwable) {
                result.setErrorResult(RestResponseBuilder.<Object>builder().error(new RestError(RestErrorCode.NODE_OPERATION_EXECUTION_ERROR.getCode(), throwable.getMessage())).build());
            }
        });
    } catch (OperationExecutionException e) {
        result.setErrorResult(RestResponseBuilder.<Object>builder().error(new RestError(RestErrorCode.NODE_OPERATION_EXECUTION_ERROR.getCode(), e.getMessage())).build());
    } catch (OrchestratorDisabledException e) {
        result.setErrorResult(RestResponseBuilder.<Object>builder().error(new RestError(RestErrorCode.CLOUD_DISABLED_ERROR.getCode(), e.getMessage())).build());
    }
    return result;
}
Also used : ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) RestResponse(alien4cloud.rest.model.RestResponse) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) RestError(alien4cloud.rest.model.RestError) OperationExecutionException(alien4cloud.paas.exception.OperationExecutionException) ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) Application(alien4cloud.model.application.Application) Map(java.util.Map) ConstraintRequiredParameterException(org.alien4cloud.tosca.exceptions.ConstraintRequiredParameterException) DeferredResult(org.springframework.web.context.request.async.DeferredResult) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 20 with Application

use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.

the class DeploymentTopologyController method updateSubstitutionProperty.

@ApiOperation(value = "Update node substitution's property.", authorizations = { @Authorization("ADMIN") })
@RequestMapping(value = "/substitutions/{nodeId}/properties", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<?> updateSubstitutionProperty(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String nodeId, @RequestBody UpdatePropertyRequest updateRequest) {
    try {
        Application application = applicationService.getOrFail(appId);
        ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId);
        AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
        ApplicationTopologyVersion topologyVersion = applicationVersionService.getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion());
        Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId());
        DeploymentTopologyDTO dto = deploymentTopologyDTOBuilder.prepareDeployment(topology, () -> matchedNodePropertiesConfigService.updateProperty(application, environment, topology, nodeId, Optional.empty(), updateRequest.getPropertyName(), updateRequest.getPropertyValue()));
        return RestResponseBuilder.<DeploymentTopologyDTO>builder().data(dto).build();
    } catch (ConstraintTechnicalException e) {
        if (e.getCause() instanceof ConstraintFunctionalException) {
            return RestConstraintValidator.fromException((ConstraintFunctionalException) e.getCause(), updateRequest.getPropertyName(), updateRequest.getPropertyValue());
        }
        throw e;
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Application (alien4cloud.model.application.Application)103 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)45 ApiOperation (io.swagger.annotations.ApiOperation)43 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)39 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)38 Audit (alien4cloud.audit.annotation.Audit)28 List (java.util.List)14 Topology (org.alien4cloud.tosca.model.templates.Topology)14 Set (java.util.Set)12 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)11 RestResponse (alien4cloud.rest.model.RestResponse)11 Collectors (java.util.stream.Collectors)11 Map (java.util.Map)10 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)9 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)9 Arrays (java.util.Arrays)9 When (cucumber.api.java.en.When)8 Deployment (alien4cloud.model.deployment.Deployment)7 RestResponseBuilder (alien4cloud.rest.model.RestResponseBuilder)7 ApplicationEnvironmentAuthorizationDTO (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationDTO)7