Search in sources :

Example 66 with Application

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

the class ApplicationTopologyVersionController method delete.

@ApiOperation(value = "Delete an application topology version from its id", notes = "The logged-in user must have the application manager role for this application. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/{topologyVersion:.+}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Void> delete(@PathVariable String applicationId, @PathVariable String applicationVersionId, @PathVariable String topologyVersion) {
    Application application = applicationService.getOrFail(applicationId);
    AuthorizationUtil.checkAuthorizationForApplication(application, ApplicationRole.APPLICATION_MANAGER);
    applicationVersionService.deleteTopologyVersion(applicationId, applicationVersionId, topologyVersion);
    return RestResponseBuilder.<Void>builder().build();
}
Also used : Application(alien4cloud.model.application.Application) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 67 with Application

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

the class ApplicationVersionController method search.

/**
 * Search application versions for a given application id
 *
 * @param applicationId the targeted application id
 * @param searchRequest
 * @return A rest response that contains a {@link FacetedSearchResult} containing application versions for an application id sorted by version
 */
@ApiOperation(value = "Search application versions", notes = "Returns a search result with that contains application versions matching the request. A application version is returned only if the connected user has at least one application role in [ APPLICATION_MANAGER | APPLICATION_USER | APPLICATION_DEVOPS | DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/search", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<GetMultipleDataResult<ApplicationVersion>> search(@PathVariable String applicationId, @RequestBody FilteredSearchRequest searchRequest) {
    Application application = applicationService.getOrFail(applicationId);
    AuthorizationUtil.checkAuthorizationForApplication(application, ApplicationRole.values());
    GetMultipleDataResult<ApplicationVersion> searchResult = appVersionService.search(applicationId, searchRequest.getQuery(), searchRequest.getFrom(), searchRequest.getSize());
    return RestResponseBuilder.<GetMultipleDataResult<ApplicationVersion>>builder().data(searchResult).build();
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Application(alien4cloud.model.application.Application) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 68 with Application

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

the class ApplicationVersionController method create.

/**
 * Create a new application version for an application.
 *
 * @param request data to create an application environment
 * @return application environment id
 */
@ApiOperation(value = "Create a new application version.", notes = "If successfull returns a rest response with the id of the created application version in data. If not successful a rest response with an error content is returned. Application role required [ APPLICATIONS_MANAGER ]. " + "By default the application version creator will have application roles [APPLICATION_MANAGER]")
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(value = HttpStatus.CREATED)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<String> create(@PathVariable String applicationId, @RequestBody CreateApplicationVersionRequest request) {
    Application application = applicationService.getOrFail(applicationId);
    AuthorizationUtil.checkAuthorizationForApplication(application, ApplicationRole.APPLICATION_MANAGER);
    String originalId = request.getTopologyTemplateId();
    boolean originalIsAppVersion = false;
    if (originalId == null) {
        originalId = request.getFromVersionId();
        originalIsAppVersion = true;
    } else if (request.getFromVersionId() != null) {
        throw new IllegalArgumentException("topologyTemplateId and fromVersionId are mutually exclusive.");
    }
    ApplicationVersion appVersion = appVersionService.createApplicationVersion(applicationId, request.getVersion(), request.getDescription(), originalId, originalIsAppVersion);
    return RestResponseBuilder.<String>builder().data(appVersion.getId()).build();
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) Application(alien4cloud.model.application.Application) Audit(alien4cloud.audit.annotation.Audit) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 69 with Application

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

the class ApplicationVersionController method get.

/**
 * Get most recent snapshot application version for an application
 *
 * @param applicationId The application id.
 */
@ApiOperation(value = "Get the first snapshot application version for an application.", notes = "Return the first snapshot application version for an application. Application role required [ APPLICATION_MANAGER | APPLICATION_USER | APPLICATION_DEVOPS | DEPLOYMENT_MANAGER ]")
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<ApplicationVersion> get(@PathVariable String applicationId) {
    Application application = alienDAO.findById(Application.class, applicationId);
    AuthorizationUtil.checkAuthorizationForApplication(application, ApplicationRole.values());
    return RestResponseBuilder.<ApplicationVersion>builder().data(appVersionService.getLatestSnapshot(applicationId)).build();
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) Application(alien4cloud.model.application.Application) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 70 with Application

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

the class ApplicationsDeploymentStepDefinitions method I_should_not_get_a_deployment_if_I_ask_one_for_application.

@Then("^I should not get a deployment if I ask one for application \"([^\"]*)\" on orchestrator \"([^\"]*)\"$")
public void I_should_not_get_a_deployment_if_I_ask_one_for_application(String applicationName, String orchestrator) throws Throwable {
    String orchestratorId = Context.getInstance().getOrchestratorId(orchestrator);
    assertNotNull(ApplicationStepDefinitions.CURRENT_APPLICATIONS);
    Application app = ApplicationStepDefinitions.CURRENT_APPLICATIONS.get(applicationName);
    NameValuePair nvp = new BasicNameValuePair("sourceId", app.getId());
    NameValuePair nvp1 = new BasicNameValuePair("orchestratorId", orchestratorId);
    String responseString = Context.getRestClientInstance().getUrlEncoded("/rest/v1/deployments", Lists.newArrayList(nvp, nvp1));
    RestResponse<?> response = JsonUtil.read(responseString);
    assertNull(response.getError());
    List<DeploymentDTO> deployments = JsonUtil.toList(JsonUtil.toString(response.getData()), DeploymentDTO.class, Application.class, Context.getJsonMapper());
    Assert.assertTrue(CollectionUtils.isEmpty(deployments));
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) DeploymentDTO(alien4cloud.rest.deployment.DeploymentDTO) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Application(alien4cloud.model.application.Application) Then(cucumber.api.java.en.Then)

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