private int getNextVolumeDeviceId(String vmUuid) { SimpleQuery<VolumeVO> q = dbf.createQuery(VolumeVO.class); q.select(VolumeVO_.deviceId); q.add(VolumeVO_.vmInstanceUuid, Op.EQ, vmUuid); q.add(VolumeVO_.deviceId, Op.NOT_NULL); q.orderBy(VolumeVO_.deviceId, Od.ASC); List<Integer> devIds = q.listValue(); BitSet full = new BitSet(devIds.size() + 1); devIds.forEach(full::set); return full.nextClearBit(0); }
public Integer getNextVolumeDeviceId(String vmUuid) { SimpleQuery<VolumeVO> q = dbf.createQuery(VolumeVO.class); q.select(VolumeVO_.deviceId); q.add(VolumeVO_.vmInstanceUuid, SimpleQuery.Op.EQ, vmUuid); q.add(VolumeVO_.deviceId, SimpleQuery.Op.NOT_NULL); q.add(VolumeVO_.isShareable, SimpleQuery.Op.EQ, false); q.orderBy(VolumeVO_.deviceId, SimpleQuery.Od.ASC); List<Integer> devIds = q.listValue(); for (BeforeGetNextVolumeDeviceIdExtensionPoint e : pluginRgty.getExtensionList(BeforeGetNextVolumeDeviceIdExtensionPoint.class)) { e.beforeGetNextVolumeDeviceId(vmUuid, devIds); } BitSet full = new BitSet(devIds.size() + 1); devIds.forEach(full::set); return full.nextClearBit(0); } }
private int getNextDeviceId() { SimpleQuery<VolumeVO> q = dbf.createQuery(VolumeVO.class); q.select(VolumeVO_.deviceId); q.add(VolumeVO_.vmInstanceUuid, Op.EQ, spec.getVmInventory().getUuid()); q.add(VolumeVO_.deviceId, Op.NOT_NULL); q.orderBy(VolumeVO_.deviceId, Od.ASC); List<Integer> devIds = q.listValue(); for (BeforeGetNextVolumeDeviceIdExtensionPoint e : pluginRgty.getExtensionList(BeforeGetNextVolumeDeviceIdExtensionPoint.class)) { e.beforeGetNextVolumeDeviceId(spec.getVmInventory().getUuid(), devIds); } BitSet full = new BitSet(devIds.size()+1); for (Integer id : devIds) { full.set(id); } return full.nextClearBit(0); }
protected WorkFlowContext carryOnRestart() throws WorkFlowException { SimpleQuery<WorkFlowVO> query = dbf.createQuery(WorkFlowVO.class); query.add(WorkFlowVO_.chainUuid, Op.EQ, chainvo.getUuid()); query.orderBy(WorkFlowVO_.position, Od.DESC); List<WorkFlowVO> vos = query.list(); WorkFlowVO last = vos.get(0); assert last.getState() == WorkFlowState.Done || last.getState() == WorkFlowState.Processing : String.format("How can work flow[%s] in %s state when restart workflow chain[uuid:%s] !!?", last.getName(), last.getState(), chainvo.getUuid()); return run(WorkFlowContext.fromBytes(last.getContext()), last); }
protected ContinueStrategy getContinueStrategy() { if (chainvo.getState() == WorkFlowChainState.ProcessDone || chainvo.getState() == WorkFlowChainState.RollbackDone) { return ContinueStrategy.Nothing; } else if (chainvo.getState() == WorkFlowChainState.ProcessFailed) { return ContinueStrategy.Rollback; } else if (chainvo.getState() == WorkFlowChainState.Processing) { SimpleQuery<WorkFlowVO> query = dbf.createQuery(WorkFlowVO.class); query.add(WorkFlowVO_.chainUuid, Op.EQ, chainvo.getUuid()); query.orderBy(WorkFlowVO_.position, Od.DESC); List<WorkFlowVO> vos = query.list(); if (vos.isEmpty()) { return ContinueStrategy.Restart; } WorkFlowVO last = vos.get(0); if (last.getState() == WorkFlowState.Processing) { return ContinueStrategy.Restart; } else if (last.getState() == WorkFlowState.Done) { return last.getPosition() == chainvo.getTotalWorkFlows() - 1 ? ContinueStrategy.Nothing : ContinueStrategy.Restart; } else if (last.getState() == WorkFlowState.RollbackDone) { WorkFlowVO first = vos.get(vos.size() - 1); return first.getState() == WorkFlowState.RollbackDone ? ContinueStrategy.Nothing : ContinueStrategy.Rollback; } else if (last.getState() == WorkFlowState.Failed) { return ContinueStrategy.Rollback; } } throw new CloudRuntimeException(String.format("Program error: cannot find ContinueStrategy for work flow chain[uuid:%s]", chainvo.getUuid())); }
public void rollback() { SimpleQuery<WorkFlowVO> query = dbf.createQuery(WorkFlowVO.class); query.add(WorkFlowVO_.chainUuid, Op.EQ, chainvo.getUuid()); query.orderBy(WorkFlowVO_.position, Od.DESC); List<WorkFlowVO> vos = query.list(); logger.debug(String.format("starting to rollback AsyncWorkFlowChain[name: %s, owner: %s]", name, owner)); for (WorkFlowVO vo : vos) { if (vo.getState() == WorkFlowState.RollbackDone) { /* when this is called from carryOn(), some flows may have been rolled back, skip them */ continue; } rollbackFlow(vo); } chainvo.setState(chainStates.getNextState(chainvo.getState(), WorkFlowChainStateEvent.rollbackDone)); chainvo = dbf.updateAndRefresh(chainvo); logger.debug(String.format("Rolled back all flows in AsyncWorkFlow chain[%s]", getName())); }
protected ContinueStrategy getContinueStrategy() { if (chainvo.getState() == WorkFlowChainState.ProcessDone || chainvo.getState() == WorkFlowChainState.RollbackDone) { return ContinueStrategy.Nothing; } else if (chainvo.getState() == WorkFlowChainState.ProcessFailed) { return ContinueStrategy.Rollback; } else if (chainvo.getState() == WorkFlowChainState.Processing) { SimpleQuery<WorkFlowVO> query = dbf.createQuery(WorkFlowVO.class); query.add(WorkFlowVO_.chainUuid, Op.EQ, chainvo.getUuid()); query.orderBy(WorkFlowVO_.position, Od.DESC); List<WorkFlowVO> vos = query.list(); if (vos.isEmpty()) { return ContinueStrategy.Restart; } WorkFlowVO last = vos.get(0); if (last.getState() == WorkFlowState.Processing) { return ContinueStrategy.Restart; } else if (last.getState() == WorkFlowState.Done) { return last.getPosition() == chainvo.getTotalWorkFlows() - 1 ? ContinueStrategy.Nothing : ContinueStrategy.Restart; } else if (last.getState() == WorkFlowState.RollbackDone) { WorkFlowVO first = vos.get(vos.size() - 1); return first.getState() == WorkFlowState.RollbackDone ? ContinueStrategy.Nothing : ContinueStrategy.Rollback; } else if (last.getState() == WorkFlowState.Failed) { return ContinueStrategy.Rollback; } } throw new CloudRuntimeException(String.format("Program error: cannot find ContinueStrategy for work flow chain[uuid:%s]", chainvo.getUuid())); }
protected void carryOnRestart() throws WorkFlowException { SimpleQuery<WorkFlowVO> query = dbf.createQuery(WorkFlowVO.class); query.add(WorkFlowVO_.chainUuid, Op.EQ, chainvo.getUuid()); query.orderBy(WorkFlowVO_.position, Od.DESC); List<WorkFlowVO> vos = query.list(); WorkFlowVO last = vos.get(0); assert last.getState() == WorkFlowState.Done || last.getState() == WorkFlowState.Processing : String.format("How can work flow[%s] in %s state when restart workflow chain[uuid:%s] !!?", last.getName(), last.getState(), chainvo.getUuid()); int startPosition; WorkFlowVO startVO; if (last.getState() == WorkFlowState.Done) { startPosition = last.getPosition() + 1; startVO = null; } else { startPosition = last.getPosition(); startVO = last; } logger.debug(String.format("Restart flows in work flow chain[uuid:%s], start position is %s", chainvo.getUuid(), startPosition)); WorkFlowContext ctx = WorkFlowContext.fromBytes(last.getContext()); AsyncWorkFlow flow = flows.get(startPosition); this.currentPosition = startPosition; processFlow(flow, ctx, startVO, startPosition); }
protected void rollback() { SimpleQuery<WorkFlowVO> query = dbf.createQuery(WorkFlowVO.class); query.add(WorkFlowVO_.chainUuid, Op.EQ, chainvo.getUuid()); query.orderBy(WorkFlowVO_.position, Od.DESC); List<WorkFlowVO> vos = query.list(); for (WorkFlowVO vo : vos) { if (vo.getState() == WorkFlowState.RollbackDone) { /* when this is called from carryOn(), some flows may have been rolled back, skip them */ continue; } rollbackFlow(vo); } chainvo.setState(chainStates.getNextState(chainvo.getState(), WorkFlowChainStateEvent.rollbackDone)); chainvo = dbf.updateAndRefresh(chainvo); logger.debug(String.format("Rolled back all flows in workflow chain[%s]", getName())); }
q.add(JobQueueEntryVO_.state, SimpleQuery.Op.IN, JobState.Pending, JobState.Processing); q.add(JobQueueEntryVO_.jobQueueId, SimpleQuery.Op.EQ, qvo.getId()); q.orderBy(JobQueueEntryVO_.id, SimpleQuery.Od.ASC); long count = q.count(); if (count == 0) {