use of com.openmeap.model.event.ModelEntityEvent in project OpenMEAP by OpenMEAP.
the class DeploymentDeleteNotifier method onAfterOperation.
@Override
public <E extends Event<Deployment>> void onAfterOperation(E event, List<ProcessingEvent> events) throws EventNotificationException {
//public <E extends Event<Deployment>> void onInCommitBeforeCommit(E event, List<ProcessingEvent> events) throws EventNotificationException {
Deployment deployment2Delete = (Deployment) event.getPayload();
ApplicationArchive archive = deployment2Delete.getApplicationArchive();
// if there are any other deployments with this hash,
// then we cannot yet delete it's archive yet at all.
List<Deployment> deployments = archiveDeleteHandler.getModelManager().getModelService().findDeploymentsByApplicationArchive(archive);
if (deployments.size() != 0) {
return;
} else {
int deplCount = archiveDeleteHandler.getModelManager().getModelService().countDeploymentsByHashAndHashAlg(archive.getHash(), archive.getHashAlgorithm());
if (deplCount == 0) {
// use the archive delete notifier to cleanup to cluster nodes
archiveDeleteNotifier.notify(new ModelEntityEvent(ModelServiceOperation.DELETE, archive), events);
}
}
// if there are any application versions with this archive,
// then we cannot delete it's archive.
List<ApplicationVersion> versions = archiveDeleteHandler.getModelManager().getModelService().findVersionsByApplicationArchive(archive);
if (versions.size() != 0) {
return;
}
// OK TO DELETE THIS APPLICATION'S COPY OF THE ARCHIVE,
// but possibly not the archive file...as it may be in use by another app
// use the archive delete handler to cleanup localhost
Map<String, Object> map = new HashMap<String, Object>();
map.put("archive", archive);
try {
int archivesWithHashAndAlg = archiveDeleteHandler.getModelManager().getModelService().countApplicationArchivesByHashAndHashAlg(archive.getHash(), archive.getHashAlgorithm());
if (archivesWithHashAndAlg == 1) {
// use the delete handler to cleanup the admin servers copy
GlobalSettings settings = archiveDeleteHandler.getModelManager().getGlobalSettings();
archiveDeleteHandler.setFileSystemStoragePathPrefix(settings.getTemporaryStoragePath());
archiveDeleteHandler.handle(new MapPayloadEvent(map));
}
archiveDeleteHandler.getModelManager().delete(archive, events);
} catch (EventHandlingException e) {
throw new ClusterNotificationException("An event handling exception occured", e);
}
}
Aggregations