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;
}
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);
}
}
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();
}
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);
}
Aggregations