Search in sources :

Example 41 with Application

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

the class TopologyLocationMatchingController method match.

@ApiOperation(value = "Retrieve the list of locations on which the current user can deploy the topology.")
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<List<ILocationMatch>> match(@PathVariable String topologyId, @RequestParam(required = false) String environmentId) {
    List<ILocationMatch> matchedLocation;
    if (StringUtils.isNotBlank(environmentId)) {
        ApplicationEnvironment environment = applicationEnvironmentService.getOrFail(environmentId);
        Application application = applicationService.getOrFail(environment.getApplicationId());
        AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.DEPLOYMENT_MANAGER);
        matchedLocation = locationMatchingService.match(topologyId, environment);
    } else {
        matchedLocation = locationMatchingService.match(topologyId, null);
    }
    return RestResponseBuilder.<List<ILocationMatch>>builder().data(matchedLocation).build();
}
Also used : ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) List(java.util.List) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) 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 42 with Application

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

the class TopologyService method checkAuthorizations.

/**
 * Check that the user has enough rights for a given topology.
 *
 * @param topology The topology for which to check roles.
 * @param applicationRoles The roles required to edit the topology for an application.
 */
private void checkAuthorizations(Topology topology, ApplicationRole[] applicationRoles, Role[] roles) {
    Csar relatedCsar = ToscaContext.get().getArchive(topology.getArchiveName(), topology.getArchiveVersion());
    if (Objects.equals(relatedCsar.getDelegateType(), ArchiveDelegateType.APPLICATION.toString())) {
        String applicationId = relatedCsar.getDelegateId();
        Application application = appService.getOrFail(applicationId);
        AuthorizationUtil.checkAuthorizationForApplication(application, applicationRoles);
    } else {
        AuthorizationUtil.checkHasOneRoleIn(roles);
    }
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Application(alien4cloud.model.application.Application)

Example 43 with Application

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

the class ApplicationService method update.

/**
 * Update the name and description of an application.
 *
 * @param applicationId The application id.
 * @param newName The new name for the application.
 * @param newDescription The new description for the application.
 */
public void update(String applicationId, String newName, String newDescription) {
    Application application = checkAndGetApplication(applicationId, ApplicationRole.APPLICATION_MANAGER);
    if (newName != null && !newName.isEmpty() && !application.getName().equals(newName)) {
        checkApplicationName(newName);
        application.setName(newName);
    }
    if (newDescription != null) {
        application.setDescription(newDescription);
    }
    alienDAO.save(application);
}
Also used : Application(alien4cloud.model.application.Application)

Example 44 with Application

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

the class ApplicationService method create.

/**
 * Create a new application and return it's id
 *
 * @param user The user that is creating the application (will be APPLICATION_MANAGER)
 * @param archiveName The unique archive name (and if for the application).
 * @param name The name of the new application.
 * @param description The description of the new application.
 * @return The id of the newly created application.
 */
public String create(String user, String archiveName, String name, String description) {
    checkApplicationId(archiveName);
    checkApplicationName(name);
    Application application = new Application();
    application.setId(archiveName);
    Map<String, Set<String>> userRoles = Maps.newHashMap();
    userRoles.put(user, Sets.newHashSet(ApplicationRole.APPLICATION_MANAGER.toString()));
    application.setUserRoles(userRoles);
    application.setName(name);
    application.setDescription(description);
    application.setTags(Lists.newArrayList());
    application.setMetaProperties(Maps.newHashMap());
    alienDAO.save(application);
    resourceUpdateInterceptor.runOnNewApplication(application);
    return archiveName;
}
Also used : Set(java.util.Set) Application(alien4cloud.model.application.Application)

Example 45 with Application

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

the class SecuredResourceStepDefinition method getResourceRequest.

private String getResourceRequest(String resourceTypeId, String resourceName) throws Throwable {
    String request = null;
    String orchestratorName = LocationsDefinitionsSteps.DEFAULT_ORCHESTRATOR_NAME;
    switch(RESOURCE_TYPE.valueOf(resourceTypeId)) {
        case APPLICATION:
            request = "/rest/v1/applications/" + Context.getInstance().getApplicationId(resourceName);
            break;
        case ENVIRONMENT:
            Application application = ApplicationStepDefinitions.CURRENT_APPLICATION;
            request = "/rest/v1/applications/" + Context.getInstance().getApplicationId(resourceName) + "/environments/" + Context.getInstance().getApplicationEnvironmentId(application.getName(), resourceName);
            break;
        case LOCATION:
            request = "/rest/v1/orchestrators/" + Context.getInstance().getOrchestratorId(orchestratorName) + "/locations/" + LocationsDefinitionsSteps.getLocationIdFromName(orchestratorName, resourceName);
            break;
        case ORCHESTRATOR:
            request = "/rest/v1/orchestrators/" + Context.getInstance().getOrchestratorId(orchestratorName);
            break;
        default:
    }
    return request;
}
Also used : Application(alien4cloud.model.application.Application)

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