Search in sources :

Example 1 with BeforeLocationDeleted

use of alien4cloud.orchestrators.locations.events.BeforeLocationDeleted 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)

Aggregations

Deployment (alien4cloud.model.deployment.Deployment)1 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)1 Location (alien4cloud.model.orchestrators.locations.Location)1 AfterLocationDeleted (alien4cloud.orchestrators.locations.events.AfterLocationDeleted)1 BeforeLocationDeleted (alien4cloud.orchestrators.locations.events.BeforeLocationDeleted)1 List (java.util.List)1 Csar (org.alien4cloud.tosca.model.Csar)1