Search in sources :

Example 1 with ClusterNotificationException

use of com.openmeap.cluster.ClusterNotificationException in project OpenMEAP by OpenMEAP.

the class ModelServiceRefreshNotifier method makeRequest.

/**
	 * This MUST remain state-less
	 * 
	 * @param <T>
	 * @param thisUrl
	 * @param obj
	 */
@Override
protected void makeRequest(final URL url, final Event<ModelEntity> mesg) throws ClusterNotificationException {
    com.openmeap.http.HttpResponse httpResponse = null;
    String simpleName = null;
    String thisUrl = url.toString() + "/" + ServletNameConstants.SERVICE_MANAGEMENT + "/";
    ModelEntity obj = mesg.getPayload();
    // I am not using obj.getClass().getSimpleName() because of Hibernate Proxy object wrapping
    if (obj instanceof Application)
        simpleName = "Application";
    else if (obj instanceof ApplicationVersion)
        simpleName = "ApplicationVersion";
    else if (obj instanceof ApplicationArchive)
        simpleName = "ApplicationArchive";
    else if (obj instanceof ApplicationInstallation)
        simpleName = "ApplicationInstallation";
    else if (obj instanceof GlobalSettings)
        simpleName = "GlobalSettings";
    else
        return;
    Hashtable<String, Object> parms = new Hashtable<String, Object>();
    parms.put(UrlParamConstants.ACTION, ModelEntityEventAction.MODEL_REFRESH.getActionName());
    parms.put(UrlParamConstants.AUTH_TOKEN, newAuthToken());
    parms.put(UrlParamConstants.REFRESH_TYPE, simpleName);
    parms.put(UrlParamConstants.REFRESH_OBJ_PKID, obj.getPk());
    try {
        logger.debug("Refresh post to {} for {} with id {}", new Object[] { thisUrl, simpleName, obj.getPk() });
        httpResponse = getHttpRequestExecuter().postData(thisUrl, parms);
        Utils.consumeInputStream(httpResponse.getResponseBody());
        int statusCode = httpResponse.getStatusCode();
        if (statusCode != 200) {
            String exMesg = "HTTP " + statusCode + " returned for refresh post to " + thisUrl + " for " + simpleName + " with id " + obj.getPk();
            logger.error(exMesg);
            throw new ClusterNotificationException(url, exMesg);
        }
    } catch (Exception e) {
        String exMesg = "Refresh post to " + thisUrl + " for " + simpleName + " with id " + obj.getPk() + " threw an exception";
        logger.error(exMesg, e);
        throw new ClusterNotificationException(url, exMesg, e);
    }
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) Hashtable(java.util.Hashtable) ClusterNotificationException(com.openmeap.cluster.ClusterNotificationException) GlobalSettings(com.openmeap.model.dto.GlobalSettings) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive) ClusterNotificationException(com.openmeap.cluster.ClusterNotificationException) ApplicationInstallation(com.openmeap.model.dto.ApplicationInstallation) ModelEntity(com.openmeap.model.ModelEntity) Application(com.openmeap.model.dto.Application)

Example 2 with ClusterNotificationException

use of com.openmeap.cluster.ClusterNotificationException in project OpenMEAP by OpenMEAP.

the class AbstractModelServiceClusterServiceMgmtNotifier method makeRequest.

@Override
protected void makeRequest(URL url, Event<T> message) throws ClusterNotificationException {
    try {
        ModelEntityEvent event = (ModelEntityEvent) message;
        T modelEntity = (T) event.getPayload();
        String authToken = newAuthToken();
        Hashtable<String, Object> parms = new Hashtable<String, Object>();
        ;
        parms.put(UrlParamConstants.CLUSTERNODE_KEY, url.toString());
        String sendUrl = url.toString() + "/" + ServletNameConstants.SERVICE_MANAGEMENT + "/?" + UrlParamConstants.ACTION + "=" + getEventActionName() + "&" + UrlParamConstants.AUTH_TOKEN + "=" + authToken;
        addRequestParameters(modelEntity, parms);
        logger.debug("Notification to {} with params {}", sendUrl, parms);
        HttpResponse response = this.getHttpRequestExecuter().postData(sendUrl, parms);
        int statusCode = response.getStatusCode();
        logger.debug("Notification to {} returned status code {}", sendUrl, statusCode);
        if (statusCode != 200) {
            String responseText = Utils.readInputStream(response.getResponseBody(), FormConstants.CHAR_ENC_DEFAULT);
            logger.error(responseText);
            throw new ClusterNotificationException(url, String.format("Notification to %s returned status code %s and response text was ", sendUrl, statusCode));
        } else {
            Utils.consumeInputStream(response.getResponseBody());
        }
    } catch (Exception e) {
        throw new ClusterNotificationException(url, e.getMessage(), e);
    }
}
Also used : ModelEntityEvent(com.openmeap.model.event.ModelEntityEvent) Hashtable(java.util.Hashtable) ClusterNotificationException(com.openmeap.cluster.ClusterNotificationException) HttpResponse(com.openmeap.http.HttpResponse) ClusterNotificationException(com.openmeap.cluster.ClusterNotificationException) EventNotificationException(com.openmeap.event.EventNotificationException)

Example 3 with ClusterNotificationException

use of com.openmeap.cluster.ClusterNotificationException 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

ClusterNotificationException (com.openmeap.cluster.ClusterNotificationException)3 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)2 ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)2 GlobalSettings (com.openmeap.model.dto.GlobalSettings)2 ModelEntityEvent (com.openmeap.model.event.ModelEntityEvent)2 Hashtable (java.util.Hashtable)2 EventHandlingException (com.openmeap.event.EventHandlingException)1 EventNotificationException (com.openmeap.event.EventNotificationException)1 HttpResponse (com.openmeap.http.HttpResponse)1 ModelEntity (com.openmeap.model.ModelEntity)1 Application (com.openmeap.model.dto.Application)1 ApplicationInstallation (com.openmeap.model.dto.ApplicationInstallation)1 Deployment (com.openmeap.model.dto.Deployment)1 MapPayloadEvent (com.openmeap.model.event.MapPayloadEvent)1 HashMap (java.util.HashMap)1