public static List<LongJobInventory> valueOf(Collection<LongJobVO> vos) { List<LongJobInventory> invs = new ArrayList<>(); for (LongJobVO vo : vos) { invs.add(valueOf(vo)); } return invs; }
public static APIQueryLongJobReply __example__() { APIQueryLongJobReply reply = new APIQueryLongJobReply(); LongJobInventory inv = new LongJobInventory(); inv.setUuid(uuid()); reply.setInventories(Arrays.asList(inv)); return reply; } }
public LongJobInventory(LongJobVO vo) { this.setUuid(vo.getUuid()); this.setName(vo.getName()); this.setState(vo.getState()); this.setApiId(vo.getApiId()); this.setJobData(vo.getJobData()); this.setJobResult(vo.getJobResult()); this.setJobName(vo.getJobName()); this.setCreateDate(vo.getCreateDate()); this.setLastOpDate(vo.getLastOpDate()); this.setExecuteTime(vo.getExecuteTime()); this.setDescription(vo.getDescription()); this.setTargetResourceUuid(vo.getTargetResourceUuid()); this.setManagementNodeUuid(vo.getManagementNodeUuid()); }
public static LongJobInventory valueOf(LongJobVO vo) { return new LongJobInventory(vo); }
@Override public void after(APIEvent evt) { if (evt.isSuccess()) { String uuid = ((APISubmitLongJobEvent)evt).getInventory().getUuid(); ntfy("Submitted long job[uuid:%s] for %s", uuid, jobName) .resource(uuid, LongJobVO.class.getSimpleName()) .messageAndEvent(that, evt).done(); } } };
public static APIRerunLongJobEvent __example__() { APIRerunLongJobEvent event = new APIRerunLongJobEvent(); LongJobInventory inv = new LongJobInventory(); inv.setUuid(uuid()); event.setInventory(inv); return event; } }
@Override public void run(SyncTaskChain chain) { SubmitLongJobReply reply = new SubmitLongJobReply(); LongJobVO vo = updateByUuid(msg.getJobUuid(), it -> it.setState(LongJobState.Running)); // launch the long job right now ThreadContext.put(Constants.THREAD_CONTEXT_API, vo.getApiId()); LongJob job = longJobFactory.getLongJob(vo.getJobName()); ThreadContext.put(Constants.THREAD_CONTEXT_TASK_NAME, job.getClass().toString()); doStartJob(job, vo, msg); reply.setInventory(LongJobInventory.valueOf(vo)); if (job.getAuditType() != null) { reply.setNeedAudit(true); } logger.info(String.format("longjob [uuid:%s, name:%s] has been started", vo.getUuid(), vo.getName())); bus.reply(msg, reply); chain.next(); }
public static APIUpdateClusterOSEvent __example__() { APIUpdateClusterOSEvent event = new APIUpdateClusterOSEvent(); LongJobInventory inv = new LongJobInventory(); inv.setUuid(uuid()); event.setInventory(inv); return event; } }
private void validate(APISubmitLongJobMsg msg) { Class<APIMessage> apiClass = apiMsgOfLongJob.get(msg.getJobName()); if (null == apiClass) { throw new ApiMessageInterceptionException(argerr("%s is not an API", msg.getJobName())); } APIMessage jobMsg = JSONObjectUtil.toObject(msg.getJobData(), apiClass); jobMsg.setSession(msg.getSession()); try { jobMsg = apiMediator.getProcesser().process(jobMsg); // may throw ApiMessageInterceptionException } catch (StopRoutingException e) { // if got stop routing exception persist a success long job and return event success LongJobVO vo = createSuccessLongJob(msg); APISubmitLongJobEvent evt = new APISubmitLongJobEvent(msg.getId()); evt.setInventory(LongJobInventory.valueOf(vo)); evt.setNeedAudit(false); bus.publish(evt); throw e; } msg.setJobData(JSONObjectUtil.toJsonString(jobMsg)); // msg may be changed during validation }
public static APISubmitLongJobEvent __example__() { APISubmitLongJobEvent event = new APISubmitLongJobEvent(); LongJobInventory inv = new LongJobInventory(); inv.setUuid(uuid()); event.setInventory(inv); event.setNeedAudit(false); return event; } }
private void validate(APIRerunLongJobMsg msg) { LongJobVO vo = Q.New(LongJobVO.class) .eq(LongJobVO_.uuid, msg.getUuid()) .find(); LongJobState state = vo.getState(); if (state != LongJobState.Succeeded && state != LongJobState.Canceled && state != LongJobState.Failed) { throw new ApiMessageInterceptionException(argerr("rerun longjob only when it's succeeded, canceled, or failed")); } Class<APIMessage> apiClass = apiMsgOfLongJob.get(vo.getJobName()); APIMessage jobMsg = JSONObjectUtil.toObject(vo.getJobData(), apiClass); jobMsg.setSession(msg.getSession()); try { apiMediator.getProcesser().process(jobMsg); // may throw ApiMessageInterceptionException } catch (StopRoutingException e) { APISubmitLongJobEvent evt = new APISubmitLongJobEvent(msg.getId()); evt.setInventory(LongJobInventory.valueOf(vo)); evt.setNeedAudit(false); bus.publish(evt); throw e; } dbf.updateAndRefresh(vo); }