Search in sources :

Example 21 with GlobalSettings

use of com.openmeap.model.dto.GlobalSettings 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)

Example 22 with GlobalSettings

use of com.openmeap.model.dto.GlobalSettings in project OpenMEAP by OpenMEAP.

the class ModelServiceRefreshNotifierTest method testHandlePostSaveOrUpdate.

@Test
public void testHandlePostSaveOrUpdate() throws Exception {
    try {
        new NonStrictExpectations() {

            {
            }
        };
    } catch (Exception e) {
    }
    ;
    MockHttpRequestExecuter.setResponseCode(200);
    MockHttpRequestExecuter.setResponseText("");
    MockHttpRequestExecuter httpExecuter = new MockHttpRequestExecuter();
    final ModelManager modelManager = new MockModelManager();
    final GlobalSettings globalSettings = new GlobalSettings();
    globalSettings.setServiceManagementAuthSalt(UUID.randomUUID().toString());
    ClusterNode clusterNode = new ClusterNode();
    clusterNode.setServiceWebUrlPrefix("http://www.openmeap.com/openmeap-services-web");
    globalSettings.addClusterNode(clusterNode);
    new NonStrictExpectations(globalSettings, modelManager) {

        {
            modelManager.getGlobalSettings();
            result = globalSettings;
        }
    };
    Application app = new Application();
    app.setName("Happy Name");
    app.setId(1L);
    ModelServiceRefreshNotifier notifier = new ModelServiceRefreshNotifier();
    notifier.setModelManager(modelManager);
    notifier.setHttpRequestExecuter(httpExecuter);
    notifier.notify(new ModelEntityModifyEvent(app), null);
    String lastPostUrl = MockHttpRequestExecuter.getLastPostUrl();
    Map<String, Object> lastPostData = MockHttpRequestExecuter.getLastPostData();
    String uri = lastPostUrl;
    String type = (String) lastPostData.get("type");
    String auth = (String) lastPostData.get("auth");
    String id = (String) lastPostData.get("id").toString();
    Assert.assertTrue(uri.equals("http://www.openmeap.com/openmeap-services-web/service-management/"));
    Assert.assertTrue(id.equals("1"));
    Assert.assertTrue(type.equals("Application"));
    Assert.assertTrue(AuthTokenProvider.validateAuthToken(globalSettings.getServiceManagementAuthSalt(), auth));
}
Also used : ClusterNode(com.openmeap.model.dto.ClusterNode) GlobalSettings(com.openmeap.model.dto.GlobalSettings) ModelManager(com.openmeap.model.ModelManager) MockHttpRequestExecuter(com.openmeap.util.MockHttpRequestExecuter) NonStrictExpectations(mockit.NonStrictExpectations) Application(com.openmeap.model.dto.Application) ModelEntityModifyEvent(com.openmeap.model.event.ModelEntityModifyEvent) Test(org.junit.Test)

Aggregations

GlobalSettings (com.openmeap.model.dto.GlobalSettings)22 ClusterNode (com.openmeap.model.dto.ClusterNode)7 File (java.io.File)7 PersistenceException (javax.persistence.PersistenceException)7 Application (com.openmeap.model.dto.Application)6 ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)6 IOException (java.io.IOException)6 MessagesEvent (com.openmeap.event.MessagesEvent)5 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)5 HashMap (java.util.HashMap)5 DigestException (com.openmeap.digest.DigestException)4 Deployment (com.openmeap.model.dto.Deployment)4 GenericRuntimeException (com.openmeap.util.GenericRuntimeException)4 FileOperationException (com.openmeap.file.FileOperationException)3 InvalidPropertiesException (com.openmeap.model.InvalidPropertiesException)3 ModelManager (com.openmeap.model.ModelManager)3 FileInputStream (java.io.FileInputStream)3 ArrayList (java.util.ArrayList)3 ClusterNotificationException (com.openmeap.cluster.ClusterNotificationException)2 EventNotificationException (com.openmeap.event.EventNotificationException)2