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());
}
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;
}
Aggregations