Search in sources :

Example 1 with AfterLocationDeleted

use of alien4cloud.orchestrators.locations.events.AfterLocationDeleted in project alien4cloud by alien4cloud.

the class ServiceResourceServiceTest method testHandleLocationDeleted.

@Test
public void testHandleLocationDeleted() {
    ServiceResource serviceResource = new ServiceResource();
    serviceResource.setId("service1");
    serviceResource.setLocationIds(new String[] { "location1", "location2" });
    alienDao.save(serviceResource);
    serviceResourceService.handleLocationDeleted(new AfterLocationDeleted(this, "location3"));
    serviceResource = serviceResourceService.getOrFail("service1");
    Assert.assertArrayEquals(new String[] { "location1", "location2" }, serviceResource.getLocationIds());
    serviceResourceService.handleLocationDeleted(new AfterLocationDeleted(this, "location1"));
    serviceResource = serviceResourceService.getOrFail("service1");
    Assert.assertArrayEquals(new String[] { "location2" }, serviceResource.getLocationIds());
}
Also used : ServiceResource(alien4cloud.model.service.ServiceResource) AfterLocationDeleted(alien4cloud.orchestrators.locations.events.AfterLocationDeleted) Test(org.junit.Test)

Example 2 with AfterLocationDeleted

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

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