Source:
<code>public void doPolling(Guid cmdId, List<Guid> childCmdIds) { boolean isRunning = false; MergeCommand<MergeParameters> command = getCommand(cmdId); VMStatus vmStatus = DbFacade.getInstance().getVmDynamicDao().get(command.getParameters().getVmId()).getStatus(); List<VmJob> vmJobs = DbFacade.getInstance().getVmJobDao().getAllForVmDisk( command.getParameters().getVmId(), command.getParameters().getImageGroupId()); VmJob vmJob = null; if (command.getParameters().getVmJobId() == null) { vmJob = vmJobs.stream(). filter(job -> job.getJobType() == VmJobType.BLOCK).map(VmBlockJob.class::cast). filter(job -> job.getBlockJobType() == <START> VmBlockJobType.UNKNOWN). <END> filter(job -> job.getImageGroupId().equals(command.getParameters().getImageGroupId())). findFirst(). orElse(null); if (vmJob != null) { command.getParameters().setVmJobId(vmJob.getId()); command.persistCommand(command.getParameters().getParentCommand(), true); } } else { vmJob = vmJobs.stream().filter(job -> job.getId().equals(command.getParameters().getVmJobId())).findFirst().orElse(null); } if (vmJob != null) { if (vmStatus == VMStatus.Down) { DbFacade.getInstance().getVmJobDao().remove(vmJob.getId()); log.info("VM '{}' is down, Merge command '{}' removed", command.getParameters().getVmId(), vmJob.getId()); } else { log.info("Waiting on merge command to complete"); isRunning = true; } } if (!isRunning) { command.setSucceeded(true); command.setCommandStatus(CommandStatus.SUCCEEDED); command.persistCommand(command.getParameters().getParentCommand(), true); log.info("Merge command has completed for images '{}'..'{}'", command.getParameters().getBaseImage().getImageId(), command.getParameters().getTopImage().getImageId()); } }</code><technical_language>for job of unknown block type; this get filled in if stats result specifies type, consider a valid merge job</technical_language>

Target:
public void doPolling(Guid cmdId, List<Guid> childCmdIds) { boolean isRunning = false; MergeCommand<MergeParameters> command = getCommand(cmdId); VMStatus vmStatus = DbFacade.getInstance().getVmDynamicDao().get(command.getParameters().getVmId()).getStatus(); List<VmJob> vmJobs = DbFacade.getInstance().getVmJobDao().getAllForVmDisk( command.getParameters().getVmId(), command.getParameters().getImageGroupId()); VmJob vmJob; if (command.getParameters().getVmJobId() == null) { vmJob = vmJobs.stream(). filter(job -> job.getJobType() == VmJobType.BLOCK).map(VmBlockJob.class::cast). filter(job -> job.getImageGroupId().equals(command.getParameters().getImageGroupId())). findFirst(). orElse(null); if (vmJob != null) { command.getParameters().setVmJobId(vmJob.getId()); command.persistCommand(command.getParameters().getParentCommand(), true); } } else { vmJob = vmJobs.stream().filter(job -> job.getId().equals(command.getParameters().getVmJobId())).findFirst().orElse(null); } if (vmJob != null) { if (vmStatus == VMStatus.Down) { DbFacade.getInstance().getVmJobDao().remove(vmJob.getId()); log.info("VM '{}' is down, Merge command '{}' removed", command.getParameters().getVmId(), vmJob.getId()); } else { log.info("Waiting on merge command to complete"); isRunning = true; } } if (!isRunning) { command.setSucceeded(true); command.setCommandStatus(CommandStatus.SUCCEEDED); command.persistCommand(command.getParameters().getParentCommand(), true); log.info("Merge command has completed for images '{}'..'{}'", command.getParameters().getBaseImage().getImageId(), command.getParameters().getTopImage().getImageId()); } }