public DataUpdateRequest updates(List<? extends Update> updates) { update = Update.update(updates); return this; }
execution.setStatus(MigrationJob.STATE_ACTIVE); updateRequest.updates(Update.update(Update.set("status", MigrationJob.STATE_ACTIVE), Update.set("jobExecutions", Literal.emptyArray()), Update.append("jobExecutions", Literal.emptyObject()), Update.set("jobExecutions.-1.ownerName", execution.getOwnerName()). execution.setStatus(MigrationJob.STATE_COMPLETED); updateRequest.updates(Update.update(Update.set("status", execution.getStatus()), Update.forEach("jobExecutions", Query.withValue("activeExecutionId", Query.eq, activeExecution.get_id()), Update.set("status", execution.getStatus()). more("errorMsg", execution.getErrorMsg() == null ? "" : execution.getErrorMsg()). more("processedDocumentCount", execution.getProcessedDocumentCount()).
public static Update update(ContainerNode node) { return new Update(node); }
private void update(List<MigrationJob> mjList) throws Exception { batchCreate(mjList); DataUpdateRequest upd = new DataUpdateRequest("migrationConfiguration", null); upd.where(Query.withValue("_id", Query.eq, migrationConfiguration.get_id())); upd.updates(Update.set("timestampInitialValue", Literal.value(migrationConfiguration.getTimestampInitialValue()))); lbClient.data(upd); }
@Override public JsonNode getBodyJson() { ObjectNode node = (ObjectNode) super.getBodyJson(); if (projection != null) { node.set("projection", projection.toJson()); } if (query != null) { node.set("query", query.toJson()); } if (update != null) { node.set("update", update.toJson()); } appendRangeToJson(node, begin, maxResults); appendUpdateIfCurrentToJson(node); return node; }
/** * Creates an update like so: $set: toJson(pojo) * * @param pojo * @return */ public static Update updatePojo(Object pojo) { Objects.requireNonNull(pojo, "Pojo cannot be null"); ObjectNode set = JsonNodeFactory.instance.objectNode(); JsonNode pojoAsJson = JSON.toJsonNode(pojo); if (!(pojoAsJson instanceof ObjectNode)) { throw new IllegalArgumentException(pojo+" is not a pojo!"); } set.set("$set", pojoAsJson); return new Update(set); }
public void enableStuckJobs(LightblueClient cli, Date enableBefore) { DataFindRequest findRequest = new DataFindRequest("migrationJob", null); // Find active jobs that's been sitting for too long findRequest.where(Query.and(Query.withValue("status", Query.eq, MigrationJob.STATE_ACTIVE), Query.arrayMatch("jobExecutions", Query.and(Query.withValue("status", Query.eq, MigrationJob.STATE_ACTIVE), Query.withValue("actualStartDate", Query.lt, new Literal(enableBefore)))))); findRequest.select(Projection.includeField("_id")); findRequest.range(0, 250); LOGGER.debug("Re-enabling stuck jobs"); for (int loop = 0; loop < 10; loop++) { try { MigrationJob[] jobs = cli.data(findRequest, MigrationJob[].class); if (jobs != null && jobs.length > 0) { LOGGER.warn("Re-enabling {} active stuck jobs", jobs.length); DataUpdateRequest upd = new DataUpdateRequest("migrationJob", null); upd.where(Query.withValues("_id", Query.in, ids(jobs))); upd.updates(Update.set("status", MigrationJob.STATE_AVAILABLE)); LOGGER.debug("update:{}", upd.getBodyJson()); cli.data(upd); } else { break; } } catch (Exception e) { LOGGER.error("Error re-activating jobs", e); } } }
public DataUpdateRequest updates(Update... updates) { update = Update.update(updates); return this; }
/** * <pre> * { $foreach : { field: { q }, $update: u } } * </pre> */ public static Update forEach(String field, UpdateQuery q, ForEachUpdate u) { Update x = new Update(false); ObjectNode fe = JsonNodeFactory.instance.objectNode(); fe.set(field, q.toJson()); fe.set("$update", u.toJson()); ((ObjectNode) x.node).set("$foreach", fe); return x; } }