Search in sources :

Example 1 with EventHandlingException

use of com.openmeap.event.EventHandlingException in project OpenMEAP by OpenMEAP.

the class ServiceManagementServlet method handleArchiveEvent.

@SuppressWarnings(value = { "rawtypes", "unchecked" })
private Result handleArchiveEvent(EventHandler eventHandler, Event event, Map<Object, Object> paramMap) throws IOException {
    String hash = firstValue(UrlParamConstants.APPARCH_HASH, paramMap);
    String hashType = firstValue(UrlParamConstants.APPARCH_HASH_ALG, paramMap);
    logger.info("Received request archive upload notification {}:{}", hashType, hash);
    Result result = null;
    if (hash != null && hashType != null) {
        ApplicationArchive arch = new ApplicationArchive();
        arch.setHash(hash);
        arch.setHashAlgorithm(hashType);
        try {
            paramMap.put("archive", arch);
            eventHandler.handle(event);
            result = new Result(Result.Status.SUCCESS);
        } catch (EventHandlingException che) {
            String msg = "Exception occurred handing the ArchiveUploadEvent";
            logger.error(msg, che);
            result = new Result(Result.Status.FAILURE, msg);
        }
    } else {
        String msg = "Either the hash(" + hash + ") or the hashType(" + hashType + ") was null.  Both are needed to process an archive event";
        logger.error(msg);
        result = new Result(Result.Status.FAILURE, msg);
    }
    return result;
}
Also used : EventHandlingException(com.openmeap.event.EventHandlingException) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive) Result(com.openmeap.services.dto.Result)

Example 2 with EventHandlingException

use of com.openmeap.event.EventHandlingException in project OpenMEAP by OpenMEAP.

the class ArchiveFileDeleteHandler method handle.

@Override
public <E extends Event<Map>> void handle(E event) throws EventHandlingException {
    if (logger.isTraceEnabled()) {
        logger.trace("entering handle()");
    }
    ApplicationArchive archive = (ApplicationArchive) event.getPayload().get("archive");
    File file = archive.getFile(getFileSystemStoragePathPrefix());
    if (file.exists()) {
        if (!file.delete()) {
            logger.error("Failed to delete archive " + archive.getFile(getFileSystemStoragePathPrefix()));
        }
    } else {
        logger.warn("Failed to find archive " + archive.getFile(getFileSystemStoragePathPrefix()) + ".  It may have yet to be deployed.");
    }
    File directory = archive.getExplodedPath(getFileSystemStoragePathPrefix());
    if (directory.exists()) {
        try {
            FileUtils.deleteDirectory(directory);
        } catch (IOException ioe) {
            String msg = "Unable to delete directory " + directory;
            logger.error(msg);
            throw new EventHandlingException(msg, ioe);
        }
    }
    if (logger.isTraceEnabled()) {
        logger.trace("exiting handle()");
    }
}
Also used : EventHandlingException(com.openmeap.event.EventHandlingException) IOException(java.io.IOException) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive) File(java.io.File)

Example 3 with EventHandlingException

use of com.openmeap.event.EventHandlingException 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);
    }
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) ModelEntityEvent(com.openmeap.model.event.ModelEntityEvent) HashMap(java.util.HashMap) ClusterNotificationException(com.openmeap.cluster.ClusterNotificationException) Deployment(com.openmeap.model.dto.Deployment) GlobalSettings(com.openmeap.model.dto.GlobalSettings) MapPayloadEvent(com.openmeap.model.event.MapPayloadEvent) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive) EventHandlingException(com.openmeap.event.EventHandlingException)

Aggregations

EventHandlingException (com.openmeap.event.EventHandlingException)3 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)3 ClusterNotificationException (com.openmeap.cluster.ClusterNotificationException)1 ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)1 Deployment (com.openmeap.model.dto.Deployment)1 GlobalSettings (com.openmeap.model.dto.GlobalSettings)1 MapPayloadEvent (com.openmeap.model.event.MapPayloadEvent)1 ModelEntityEvent (com.openmeap.model.event.ModelEntityEvent)1 Result (com.openmeap.services.dto.Result)1 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1