use of com.openmeap.model.dto.Deployment in project OpenMEAP by OpenMEAP.
the class ApplicationVersionListingsBacking method process.
public Collection<ProcessingEvent> process(ProcessingContext context, Map<Object, Object> templateVariables, Map<Object, Object> parameterMap) {
List<ProcessingEvent> events = new ArrayList<ProcessingEvent>();
if (ParameterMapUtils.notEmpty(FormConstants.APP_ID, parameterMap)) {
Application app = modelManager.getModelService().findByPrimaryKey(Application.class, Long.valueOf(ParameterMapUtils.firstValue(FormConstants.APP_ID, parameterMap)));
if (app != null) {
setupMayCreateDeployments(templateVariables, app, events);
Deployment lastDeployment = modelManager.getModelService().getLastDeployment(app);
String currentVersionId = null;
if (lastDeployment != null && lastDeployment.getVersionIdentifier() != null) {
currentVersionId = lastDeployment.getVersionIdentifier();
}
currentVersionId = currentVersionId != null ? currentVersionId : "";
templateVariables.put("application", app);
templateVariables.put(FormConstants.PROCESS_TARGET, ProcessingTargets.DEPLOYMENTS);
templateVariables.put("currentVersionId", currentVersionId);
if (app.getVersions() != null && app.getVersions().size() > 0) {
createVersionsDisplayLists(app, templateVariables);
} else {
events.add(new MessagesEvent("Application with id " + ParameterMapUtils.firstValue(FormConstants.APP_ID, parameterMap) + " has no versions associated to it"));
}
if (modelManager.getAuthorizer().may(Authorizer.Action.CREATE, new ApplicationVersion())) {
events.add(new AddSubNavAnchorEvent(new Anchor("?bean=addModifyAppVersionPage&applicationId=" + app.getId(), "Create new version", "Create new version")));
}
events.add(new AddSubNavAnchorEvent(new Anchor("?bean=addModifyAppPage&applicationId=" + app.getId(), "View/Modify Application", "View/Modify Application")));
Anchor deploymentHistoryAnchor = new Anchor("?bean=deploymentListingsPage&applicationId=" + app.getId(), "Deployment History", "Deployment History");
templateVariables.put("deploymentsAnchor", deploymentHistoryAnchor);
events.add(new AddSubNavAnchorEvent(deploymentHistoryAnchor));
} else {
events.add(new MessagesEvent("Application with id " + ParameterMapUtils.firstValue(FormConstants.APP_ID, parameterMap) + " not found"));
}
} else {
events.add(new MessagesEvent("An application must be selected"));
}
return events;
}
use of com.openmeap.model.dto.Deployment in project OpenMEAP by OpenMEAP.
the class DeploymentAddModifyNotifier method maintainDeploymentHistoryLength.
/**
* Trim the deployment history table. Deleting old archives as we go.
* @param app
* @throws EventNotificationException
* @throws PersistenceException
* @throws InvalidPropertiesException
*/
private Boolean maintainDeploymentHistoryLength(Application app, List<ProcessingEvent> events) throws EventNotificationException {
getModelManager().getModelService().refresh(app);
Integer lengthToMaintain = app.getDeploymentHistoryLength();
List<Deployment> deployments = app.getDeployments();
if (deployments != null && deployments.size() > lengthToMaintain) {
Integer currentSize = deployments.size();
List<Deployment> newDeployments = new ArrayList<Deployment>(deployments.subList(currentSize - lengthToMaintain, currentSize));
List<Deployment> oldDeployments = new ArrayList<Deployment>(deployments.subList(0, currentSize - lengthToMaintain));
for (Deployment deployment : oldDeployments) {
getModelManager().delete(deployment, events);
}
for (Deployment deployment : newDeployments) {
app.getDeployments().add(deployment);
}
try {
getModelManager().addModify(app, events);
} catch (InvalidPropertiesException e) {
throw new EventNotificationException(e);
} catch (PersistenceException e) {
throw new EventNotificationException(e);
}
return true;
}
return false;
}
use of com.openmeap.model.dto.Deployment 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.Deployment in project OpenMEAP by OpenMEAP.
the class ModelServiceImpl method getLastDeployment.
@Override
public Deployment getLastDeployment(Application app) {
Query q = entityManager.createQuery("select distinct d " + "from Deployment d join d.application " + "where d.application.id=:id " + "order by d.createDate desc");
q.setParameter("id", app.getId());
q.setMaxResults(1);
try {
Object o = q.getSingleResult();
return (Deployment) o;
} catch (NoResultException nre) {
return null;
}
}
use of com.openmeap.model.dto.Deployment 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);
}
}
Aggregations