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