Search in sources :

Example 16 with ApplicationArchive

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

the class ApplicationManagementServiceImpl method connectionOpen.

public ConnectionOpenResponse connectionOpen(ConnectionOpenRequest request) throws WebServiceException {
    String reqAppArchHashVal = StringUtils.trimToNull(request.getApplication().getHashValue());
    String reqAppVerId = StringUtils.trimToNull(request.getApplication().getVersionId());
    String reqAppName = StringUtils.trimToNull(request.getApplication().getName());
    ConnectionOpenResponse response = new ConnectionOpenResponse();
    GlobalSettings settings = modelManager.getGlobalSettings();
    if (StringUtils.isBlank(settings.getExternalServiceUrlPrefix()) && logger.isWarnEnabled()) {
        logger.warn("The external service url prefix configured in the admin interface is blank.  " + "This will probably cause issues downloading application archives.");
    }
    Application application = getApplication(reqAppName, reqAppVerId);
    // Generate a new auth token for the device to present to the proxy
    String authToken;
    try {
        authToken = AuthTokenProvider.newAuthToken(application.getProxyAuthSalt());
    } catch (DigestException e) {
        throw new GenericRuntimeException(e);
    }
    response.setAuthToken(authToken);
    // If there is a deployment, 
    // and the version of that deployment differs in hash value or identifier
    // then return an update in the response
    Deployment lastDeployment = modelManager.getModelService().getLastDeployment(application);
    Boolean reqAppVerDiffers = lastDeployment != null && !lastDeployment.getVersionIdentifier().equals(reqAppVerId);
    Boolean reqAppArchHashValDiffers = lastDeployment != null && reqAppArchHashVal != null && !lastDeployment.getApplicationArchive().getHash().equals(reqAppArchHashVal);
    //   the app hash value is different than reported
    if (reqAppVerDiffers || reqAppArchHashValDiffers) {
        // TODO: I'm not happy with the discrepancies between the model and schema
        // ...besides, this update header should be encapsulated somewhere else
        ApplicationArchive currentVersionArchive = lastDeployment.getApplicationArchive();
        UpdateHeader uh = new UpdateHeader();
        uh.setVersionIdentifier(lastDeployment.getVersionIdentifier());
        uh.setInstallNeeds(Long.valueOf(currentVersionArchive.getBytesLength() + currentVersionArchive.getBytesLengthUncompressed()));
        uh.setStorageNeeds(Long.valueOf(currentVersionArchive.getBytesLengthUncompressed()));
        uh.setType(UpdateType.fromValue(lastDeployment.getType().toString()));
        uh.setUpdateUrl(currentVersionArchive.getDownloadUrl(settings));
        uh.setHash(new Hash());
        uh.getHash().setAlgorithm(HashAlgorithm.fromValue(currentVersionArchive.getHashAlgorithm()));
        uh.getHash().setValue(currentVersionArchive.getHash());
        response.setUpdate(uh);
    }
    return response;
}
Also used : DigestException(com.openmeap.digest.DigestException) Deployment(com.openmeap.model.dto.Deployment) UpdateHeader(com.openmeap.protocol.dto.UpdateHeader) GlobalSettings(com.openmeap.model.dto.GlobalSettings) ConnectionOpenResponse(com.openmeap.protocol.dto.ConnectionOpenResponse) GenericRuntimeException(com.openmeap.util.GenericRuntimeException) Hash(com.openmeap.protocol.dto.Hash) Application(com.openmeap.model.dto.Application) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive)

Example 17 with ApplicationArchive

use of com.openmeap.model.dto.ApplicationArchive 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 18 with ApplicationArchive

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

the class EntityRelationshipsTest method testModel.

@Test
public void testModel() {
    assertInserts(em);
    makeModifications(em);
    ApplicationArchive aa = null;
    ApplicationVersion av = null;
    Application app = null;
    // Verify that deleting an application version 
    // deletes only the version and archive
    av = em.find(ApplicationVersion.class, 1L);
    app = em.find(Application.class, 1L);
    em.getTransaction().begin();
    app.removeVersion(av);
    em.remove(av);
    em.getTransaction().commit();
    app = em.find(Application.class, 1L);
    aa = em.find(ApplicationArchive.class, 1L);
    Assert.assertTrue(app != null);
    Assert.assertTrue(aa != null);
    // Verify that deleting an application deletes all the crap associated to it
    app = em.find(Application.class, 1L);
    Assert.assertTrue(app != null);
    em.getTransaction().begin();
    em.remove(app);
    em.getTransaction().commit();
    av = em.find(ApplicationVersion.class, 2L);
    Assert.assertTrue(av != null);
    em.clear();
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive) Application(com.openmeap.model.dto.Application)

Example 19 with ApplicationArchive

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

the class ModelServiceImplTest method testGetApplicationArchiveByDeployment.

public void testGetApplicationArchiveByDeployment() {
    Application app = modelService.findApplicationByName("Application.name");
    Deployment d = modelService.getLastDeployment(app);
    ApplicationArchive a = modelService.getApplicationArchiveByDeployment(d);
    Assert.assertNotNull(a);
}
Also used : Deployment(com.openmeap.model.dto.Deployment) Application(com.openmeap.model.dto.Application) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive)

Aggregations

ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)19 File (java.io.File)6 MessagesEvent (com.openmeap.event.MessagesEvent)5 Application (com.openmeap.model.dto.Application)5 GlobalSettings (com.openmeap.model.dto.GlobalSettings)5 ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)4 Deployment (com.openmeap.model.dto.Deployment)4 IOException (java.io.IOException)4 PersistenceException (javax.persistence.PersistenceException)4 DigestException (com.openmeap.digest.DigestException)3 EventHandlingException (com.openmeap.event.EventHandlingException)3 InvalidPropertiesException (com.openmeap.model.InvalidPropertiesException)3 ClusterNotificationException (com.openmeap.cluster.ClusterNotificationException)2 GenericRuntimeException (com.openmeap.util.GenericRuntimeException)2 FileInputStream (java.io.FileInputStream)2 ZipFile (java.util.zip.ZipFile)2 FileItem (org.apache.commons.fileupload.FileItem)2 ClusterHandlingException (com.openmeap.cluster.ClusterHandlingException)1 ModelEntity (com.openmeap.model.ModelEntity)1 ModelManager (com.openmeap.model.ModelManager)1