Search in sources :

Example 11 with Deployment

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;
}
Also used : Anchor(com.openmeap.web.html.Anchor) ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) ArrayList(java.util.ArrayList) MessagesEvent(com.openmeap.event.MessagesEvent) AddSubNavAnchorEvent(com.openmeap.admin.web.events.AddSubNavAnchorEvent) Deployment(com.openmeap.model.dto.Deployment) ProcessingEvent(com.openmeap.event.ProcessingEvent) Application(com.openmeap.model.dto.Application)

Example 12 with Deployment

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;
}
Also used : InvalidPropertiesException(com.openmeap.model.InvalidPropertiesException) EventNotificationException(com.openmeap.event.EventNotificationException) ArrayList(java.util.ArrayList) PersistenceException(javax.persistence.PersistenceException) Deployment(com.openmeap.model.dto.Deployment)

Example 13 with Deployment

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;
}
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 14 with Deployment

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;
    }
}
Also used : Query(javax.persistence.Query) Deployment(com.openmeap.model.dto.Deployment) NoResultException(javax.persistence.NoResultException)

Example 15 with Deployment

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

Deployment (com.openmeap.model.dto.Deployment)16 Application (com.openmeap.model.dto.Application)8 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)4 GlobalSettings (com.openmeap.model.dto.GlobalSettings)4 MessagesEvent (com.openmeap.event.MessagesEvent)3 ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)3 Anchor (com.openmeap.web.html.Anchor)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 NoResultException (javax.persistence.NoResultException)3 Query (javax.persistence.Query)3 Test (org.junit.Test)3 AddSubNavAnchorEvent (com.openmeap.admin.web.events.AddSubNavAnchorEvent)2 ProcessingEvent (com.openmeap.event.ProcessingEvent)2 InvalidPropertiesException (com.openmeap.model.InvalidPropertiesException)2 WebServiceException (com.openmeap.protocol.WebServiceException)2 List (java.util.List)2 PersistenceException (javax.persistence.PersistenceException)2 ClusterNotificationException (com.openmeap.cluster.ClusterNotificationException)1 DigestException (com.openmeap.digest.DigestException)1