Search in sources :

Example 46 with Location

use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.

the class LocationResourceService method saveResource.

/*
     * (non-Javadoc)
     * 
     * @see
     * alien4cloud.orchestrators.locations.services.ILocationResourceService#saveResource(alien4cloud.model.orchestrators.locations.LocationResourceTemplate)
     */
@Override
public void saveResource(AbstractLocationResourceTemplate resourceTemplate) {
    Location location = locationService.getOrFail(resourceTemplate.getLocationId());
    saveResource(location, resourceTemplate);
}
Also used : Location(alien4cloud.model.orchestrators.locations.Location)

Example 47 with Location

use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.

the class LocationResourceService method deleteGeneratedResources.

/*
     * (non-Javadoc)
     * 
     * @see alien4cloud.orchestrators.locations.services.ILocationResourceService#deleteGeneratedResources(java.lang.String)
     */
@Override
public void deleteGeneratedResources(String locationId) {
    QueryBuilder locationIdQuery = QueryBuilders.termQuery("locationId", locationId);
    QueryBuilder generatedFieldQuery = QueryBuilders.termQuery("generated", true);
    // QueryBuilder builder = QueryBuilders.filteredQuery(locationIdQuery, filterBuilder);
    QueryBuilder builder = QueryBuilders.boolQuery().must(locationIdQuery).must(generatedFieldQuery);
    Location location = locationService.getOrFail(locationId);
    alienDAO.delete(LocationResourceTemplate.class, builder);
    alienDAO.save(location);
}
Also used : QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Location(alien4cloud.model.orchestrators.locations.Location)

Example 48 with Location

use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.

the class LocationService method delete.

/**
 * Delete a locations.
 *
 * @param id id of the locations to delete.
 * @return true if the location was successfully , false if not.
 */
public synchronized boolean delete(String orchestratorId, String id) {
    Orchestrator orchestrator = orchestratorService.getOrFail(orchestratorId);
    if (alienDAO.count(Deployment.class, null, fromKeyValueCouples("orchestratorId", orchestratorId, "locationIds", id, "endDate", null)) > 0) {
        return false;
    }
    Location location = getOrFail(id);
    publisher.publishEvent(new BeforeLocationDeleted(this, location.getId()));
    // delete all location resources for the given location
    alienDAO.delete(LocationResourceTemplate.class, QueryBuilders.termQuery("locationId", id));
    // delete the location
    alienDAO.delete(Location.class, id);
    // delete all archives associated with this location only, if possible of course
    Map<Csar, List<Usage>> usages = locationArchiveIndexer.deleteArchives(orchestrator, location);
    if (MapUtils.isNotEmpty(usages)) {
        // TODO what to do when some archives were not deleted?
        log.warn("Some archives for location were not deleted! \n" + usages);
    }
    publisher.publishEvent(new AfterLocationDeleted(this, location.getId()));
    return true;
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) BeforeLocationDeleted(alien4cloud.orchestrators.locations.events.BeforeLocationDeleted) Deployment(alien4cloud.model.deployment.Deployment) List(java.util.List) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) Location(alien4cloud.model.orchestrators.locations.Location) AfterLocationDeleted(alien4cloud.orchestrators.locations.events.AfterLocationDeleted)

Example 49 with Location

use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.

the class LocationService method create.

/**
 * Add a new locations for a given orchestrator.
 */
public String create(String orchestratorId, String locationName, String infrastructureType) {
    Orchestrator orchestrator = orchestratorService.getOrFail(orchestratorId);
    if (!OrchestratorState.CONNECTED.equals(orchestrator.getState())) {
    // we cannot configure locations for orchestrator that are not connected.
    // TODO throw exception
    }
    ensureMultipleLocations(orchestratorId);
    Location location = new Location();
    location.setId(UUID.randomUUID().toString());
    location.setName(locationName);
    location.setOrchestratorId(orchestratorId);
    createLocation(orchestrator, location, infrastructureType);
    publisher.publishEvent(new AfterLocationCreated(this, location));
    return location.getId();
}
Also used : AfterLocationCreated(alien4cloud.orchestrators.locations.events.AfterLocationCreated) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) Location(alien4cloud.model.orchestrators.locations.Location)

Example 50 with Location

use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.

the class LocationService method findByIds.

/**
 * Retrieve location given a list of ids, and a specific context
 *
 * @param fetchContext The fetch context to recover only the required field (Note that this should be simplified to directly use the given field...).
 * @param ids array of id of the applications to find
 * @return Map of locations that has the given ids and (key is application Id), or null if no location matching the
 *         request is found.
 */
public Map<String, Location> findByIds(String fetchContext, String... ids) {
    List<Location> results = alienDAO.findByIdsWithContext(Location.class, fetchContext, ids);
    if (results == null) {
        return null;
    }
    Map<String, Location> locations = Maps.newHashMap();
    for (Location location : results) {
        locations.put(location.getId(), location);
    }
    return locations.isEmpty() ? null : locations;
}
Also used : Location(alien4cloud.model.orchestrators.locations.Location)

Aggregations

Location (alien4cloud.model.orchestrators.locations.Location)80 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)31 ApiOperation (io.swagger.annotations.ApiOperation)30 List (java.util.List)28 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)28 Audit (alien4cloud.audit.annotation.Audit)21 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)15 LocationService (alien4cloud.orchestrators.locations.services.LocationService)13 Set (java.util.Set)13 Collectors (java.util.stream.Collectors)13 Application (alien4cloud.model.application.Application)12 AbstractLocationResourceTemplate (alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate)12 RestResponse (alien4cloud.rest.model.RestResponse)12 RestResponseBuilder (alien4cloud.rest.model.RestResponseBuilder)12 GroupDTO (alien4cloud.rest.orchestrator.model.GroupDTO)12 UserDTO (alien4cloud.rest.orchestrator.model.UserDTO)12 Resource (javax.annotation.Resource)12 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)11 ResourcePermissionService (alien4cloud.authorization.ResourcePermissionService)11 ApplicationEnvironmentAuthorizationUpdateRequest (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationUpdateRequest)11