Search in sources :

Example 6 with JobHistory

use of com.runwaysdk.system.scheduler.JobHistory in project geoprism-registry by terraframe.

the class PatchExistsAndInvalid method patchMasterlistVersions.

private void patchMasterlistVersions() {
    final Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
    MasterListVersionQuery query = new MasterListVersionQuery(new QueryFactory());
    try (OIterator<? extends MasterListVersion> it = query.getIterator()) {
        for (MasterListVersion version : it) {
            // ServerGeoObjectType type = version.getMasterlist().getGeoObjectType();
            // We are accessing it in this weird way because MasterList was changed to have new localized attributes. If we run this patch
            // before masterlist is patched then simply instantiating a MasterList object will throw an error when it tries to load the structs.
            BusinessDAO versionDAO = (BusinessDAO) BusinessDAO.get(version.getOid());
            String masterListOid = versionDAO.getValue(MasterListVersion.MASTERLIST);
            BusinessDAO masterListDAO = (BusinessDAO) BusinessDAO.get(masterListOid);
            String universalOid = masterListDAO.getValue(MasterList.UNIVERSAL);
            ServerGeoObjectType type = ServerGeoObjectType.get(Universal.get(universalOid));
            // Patch metadata
            // AttributeType existsAttr = type.getAttribute(DefaultAttribute.EXISTS.getName()).get();
            // MasterListVersion.createMdAttributeFromAttributeType(version, type, existsAttr, locales);
            AttributeType invalidAttr = type.getAttribute(DefaultAttribute.INVALID.getName()).get();
            MasterListVersion.createMdAttributeFromAttributeType(version, type, invalidAttr, locales);
            // Instance data is too hard to patch. We're just going to republish all the lists
            logger.info("Master list version [" + version.getKey() + "] has been queued for republishing.");
            PublishMasterListVersionJob job = new PublishMasterListVersionJob();
            job.setMasterListVersion(version);
            job.setMasterListId(masterListOid);
            job.apply();
            // job.start();
            // JobHistory history = job.createNewHistory();
            JobHistory history = new JobHistory();
            history.setStartTime(new Date());
            history.addStatus(AllJobStatus.QUEUED);
            history.apply();
            JobHistoryRecord record = new JobHistoryRecord(job, history);
            record.apply();
        }
    }
}
Also used : Locale(java.util.Locale) QueryFactory(com.runwaysdk.query.QueryFactory) BusinessDAO(com.runwaysdk.dataaccess.BusinessDAO) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) JobHistory(com.runwaysdk.system.scheduler.JobHistory) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) MasterListVersion(net.geoprism.registry.MasterListVersion) PublishMasterListVersionJob(net.geoprism.registry.etl.PublishMasterListVersionJob) Date(java.util.Date) MasterListVersionQuery(net.geoprism.registry.MasterListVersionQuery) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) JobHistoryRecord(com.runwaysdk.system.scheduler.JobHistoryRecord)

Example 7 with JobHistory

use of com.runwaysdk.system.scheduler.JobHistory in project geoprism-registry by terraframe.

the class ListTypeService method publishVersion.

@Request(RequestType.SESSION)
public JsonObject publishVersion(String sessionId, String oid) {
    ListTypeVersion version = ListTypeVersion.get(oid);
    // Only a working version can be republished.
    if (!version.getWorking()) {
        throw new UnsupportedOperationException();
    }
    this.enforceReadPermissions(version.getListType());
    QueryFactory factory = new QueryFactory();
    PublishListTypeVersionJobQuery query = new PublishListTypeVersionJobQuery(factory);
    query.WHERE(query.getVersion().EQ(version));
    JobHistoryQuery q = new JobHistoryQuery(factory);
    q.WHERE(q.getStatus().containsAny(AllJobStatus.NEW, AllJobStatus.QUEUED, AllJobStatus.RUNNING));
    q.AND(q.job(query));
    if (q.getCount() > 0) {
        throw new DuplicateJobException("This version has already been queued for publishing");
    }
    PublishListTypeVersionJob job = new PublishListTypeVersionJob();
    job.setRunAsUserId(Session.getCurrentSession().getUser().getOid());
    job.setVersion(version);
    job.setListType(version.getListType());
    job.apply();
    NotificationFacade.queue(new GlobalNotificationMessage(MessageType.PUBLISH_JOB_CHANGE, null));
    final JobHistory history = job.start();
    JsonObject resp = new JsonObject();
    resp.addProperty("jobOid", history.getOid());
    return resp;
}
Also used : PublishListTypeVersionJob(net.geoprism.registry.etl.PublishListTypeVersionJob) QueryFactory(com.runwaysdk.query.QueryFactory) JobHistoryQuery(com.runwaysdk.system.scheduler.JobHistoryQuery) DuplicateJobException(net.geoprism.registry.etl.DuplicateJobException) JobHistory(com.runwaysdk.system.scheduler.JobHistory) PublishListTypeVersionJobQuery(net.geoprism.registry.etl.PublishListTypeVersionJobQuery) JsonObject(com.google.gson.JsonObject) ListTypeVersion(net.geoprism.registry.ListTypeVersion) GlobalNotificationMessage(net.geoprism.registry.ws.GlobalNotificationMessage) Request(com.runwaysdk.session.Request)

Example 8 with JobHistory

use of com.runwaysdk.system.scheduler.JobHistory in project geoprism-registry by terraframe.

the class SchedulerTestUtils method waitUntilStatus.

@Request
public static void waitUntilStatus(String histId, AllJobStatus status) throws InterruptedException {
    int waitTime = 0;
    while (true) {
        JobHistory hist = JobHistory.get(histId);
        if (hist.getStatus().get(0) == status) {
            break;
        } else if (hist.getStatus().get(0) == AllJobStatus.SUCCESS || hist.getStatus().get(0) == AllJobStatus.FAILURE || hist.getStatus().get(0) == AllJobStatus.FEEDBACK || hist.getStatus().get(0) == AllJobStatus.CANCELED || hist.getStatus().get(0) == AllJobStatus.STOPPED || hist.getStatus().get(0) == AllJobStatus.WARNING) {
            String extra = "";
            if (hist.getStatus().get(0).equals(AllJobStatus.FEEDBACK)) {
                extra = new ETLService().getImportErrors(Session.getCurrentSession().getOid(), hist.getOid(), false, 10, 1).toString();
                String validationProblems = new ETLService().getValidationProblems(Session.getCurrentSession().getOid(), hist.getOid(), false, 10, 1).toString();
                extra = extra + " " + validationProblems;
            }
            Assert.fail("Job has a finished status [" + hist.getStatus().get(0) + "] which is not what we expected. " + extra);
        }
        Thread.sleep(10);
        waitTime += 10;
        if (waitTime > 200000) {
            String extra = "";
            if (hist.getStatus().get(0).equals(AllJobStatus.FEEDBACK)) {
                extra = new ETLService().getImportErrors(Session.getCurrentSession().getOid(), hist.getOid(), false, 10, 1).toString();
                String validationProblems = new ETLService().getValidationProblems(Session.getCurrentSession().getOid(), hist.getOid(), false, 10, 1).toString();
                extra = extra + " " + validationProblems;
            }
            Assert.fail("Job was never scheduled (status is " + hist.getStatus().get(0).getEnumName() + "). " + extra);
            return;
        }
    }
    Thread.sleep(100);
    waitTime += 100;
}
Also used : JobHistory(com.runwaysdk.system.scheduler.JobHistory) ETLService(net.geoprism.registry.etl.ETLService) Request(com.runwaysdk.session.Request)

Aggregations

JobHistory (com.runwaysdk.system.scheduler.JobHistory)8 JsonObject (com.google.gson.JsonObject)4 QueryFactory (com.runwaysdk.query.QueryFactory)4 Request (com.runwaysdk.session.Request)4 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)4 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 GeoprismUser (net.geoprism.GeoprismUser)3 MasterList (net.geoprism.registry.MasterList)3 MasterListVersion (net.geoprism.registry.MasterListVersion)3 JSONException (org.json.JSONException)3 JobHistoryQuery (com.runwaysdk.system.scheduler.JobHistoryQuery)2 JobHistoryRecord (com.runwaysdk.system.scheduler.JobHistoryRecord)2 PublishListTypeVersionJobQuery (net.geoprism.registry.etl.PublishListTypeVersionJobQuery)2 BusinessDAO (com.runwaysdk.dataaccess.BusinessDAO)1 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)1 SynonymQuery (com.runwaysdk.system.gis.geo.SynonymQuery)1 ExecutableJob (com.runwaysdk.system.scheduler.ExecutableJob)1 JobHistoryRecordQuery (com.runwaysdk.system.scheduler.JobHistoryRecordQuery)1 Date (java.util.Date)1