diff --git a/api/src/org/apache/cloudstack/context/CallContext.java b/api/src/org/apache/cloudstack/context/CallContext.java index dbeb5c7ea21..0457c332b1b 100644 --- a/api/src/org/apache/cloudstack/context/CallContext.java +++ b/api/src/org/apache/cloudstack/context/CallContext.java @@ -131,7 +131,10 @@ public class CallContext { protected static CallContext register(User callingUser, Account callingAccount, Long userId, Long accountId, String contextId) { /* +<<<<<<< HEAD Unit tests will have multiple times of setup/tear-down call to this, remove assertions to all unit test to run +======= +>>>>>>> a7a8a19... BUG-ID: CS-19295: add job path to help associate an API job to related internal job. Reviewed-By: Self assert s_currentContext.get() == null : "There's a context already so what does this new register context mean? " + s_currentContext.get().toString(); if (s_currentContext.get() != null) { // FIXME: This should be removed soon. I added this check only to surface all the places that have this problem. throw new CloudRuntimeException("There's a context already so what does this new register context mean? " + s_currentContext.get().toString()); @@ -154,6 +157,14 @@ public class CallContext { return callingContext; } + public static CallContext registerPlaceHolderContext() { + CallContext context = new CallContext(0, 0, UUID.randomUUID().toString()); + s_currentContext.set(context); + + s_currentContextStack.get().push(context); + return context; + } + public static CallContext register(User callingUser, Account callingAccount) { return register(callingUser, callingAccount, UUID.randomUUID().toString()); } diff --git a/api/src/org/apache/cloudstack/context/CallContextListener.java b/api/src/org/apache/cloudstack/context/CallContextListener.java index 49866e07733..ab9a8c30046 100644 --- a/api/src/org/apache/cloudstack/context/CallContextListener.java +++ b/api/src/org/apache/cloudstack/context/CallContextListener.java @@ -32,10 +32,9 @@ public class CallContextListener implements ManagedContextListener { @Override public Object onEnterContext(boolean reentry) { - if (!reentry) { + if (!reentry && CallContext.current() == null) { CallContext.registerSystemCallContextOnceOnly(); } - return null; } diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java index 457fad26324..5a33df40bca 100755 --- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -4436,7 +4436,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac workJob.setStep(VmWorkJobVO.Step.Starting); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkStart workInfo = new VmWorkStart(callingUser.getId(), callingAccount.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER); @@ -4493,7 +4493,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac workJob.setStep(VmWorkJobVO.Step.Prepare); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkStop workInfo = new VmWorkStop(user.getId(), account.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, cleanup); @@ -4549,7 +4549,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac workJob.setStep(VmWorkJobVO.Step.Prepare); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkReboot workInfo = new VmWorkReboot(user.getId(), account.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, params); @@ -4604,7 +4604,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac workJob.setUserId(user.getId()); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkMigrate workInfo = new VmWorkMigrate(user.getId(), account.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, srcHostId, dest); @@ -4656,7 +4656,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac workJob.setUserId(user.getId()); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkMigrateAway workInfo = new VmWorkMigrateAway(user.getId(), account.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, srcHostId); @@ -4713,7 +4713,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac workJob.setUserId(user.getId()); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkMigrateWithStorage workInfo = new VmWorkMigrateWithStorage(user.getId(), account.getId(), vm.getId(), @@ -4770,7 +4770,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac workJob.setUserId(user.getId()); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkMigrateForScale workInfo = new VmWorkMigrateForScale(user.getId(), account.getId(), vm.getId(), @@ -4827,7 +4827,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac workJob.setUserId(user.getId()); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkStorageMigration workInfo = new VmWorkStorageMigration(user.getId(), account.getId(), vm.getId(), @@ -4883,7 +4883,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac workJob.setUserId(user.getId()); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkAddVmToNetwork workInfo = new VmWorkAddVmToNetwork(user.getId(), account.getId(), vm.getId(), @@ -4937,7 +4937,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac workJob.setUserId(user.getId()); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkRemoveNicFromVm workInfo = new VmWorkRemoveNicFromVm(user.getId(), account.getId(), vm.getId(), @@ -4991,7 +4991,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac workJob.setUserId(user.getId()); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkRemoveVmFromNetwork workInfo = new VmWorkRemoveVmFromNetwork(user.getId(), account.getId(), vm.getId(), @@ -5047,7 +5047,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac workJob.setUserId(user.getId()); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkReconfigure workInfo = new VmWorkReconfigure(user.getId(), account.getId(), vm.getId(), diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java b/engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java index 31b2d9ca2d2..f3020021840 100644 --- a/engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java +++ b/engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java @@ -96,10 +96,14 @@ public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatch return; } - CallContext.register(work.getUserId(), work.getAccountId(), job.getRelated()); + CallContext.register(work.getUserId(), work.getAccountId()); - Pair result = handler.handleVmWorkJob(work); - _asyncJobMgr.completeAsyncJob(job.getId(), result.first(), 0, result.second()); + try { + Pair result = handler.handleVmWorkJob(work); + _asyncJobMgr.completeAsyncJob(job.getId(), result.first(), 0, result.second()); + } finally { + CallContext.unregister(); + } } finally { if (s_logger.isDebugEnabled()) s_logger.debug("Done with run of VM work job: " + cmd + " for VM " + work.getVmId() + ", job origin: " + job.getRelated()); @@ -109,8 +113,6 @@ public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatch RuntimeException ex = new RuntimeException("Job failed due to exception " + e.getMessage()); _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, 0, _asyncJobMgr.marshallResultObject(ex)); - } finally { - CallContext.unregister(); } } } diff --git a/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java b/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java index b6c1692805e..129d9cae52c 100644 --- a/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java +++ b/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java @@ -204,7 +204,11 @@ public class AsyncJobExecutionContext { s_currentExectionContext.set(currentContext); } - public static String getOriginJobContextId() { - return String.valueOf(CallContext.current().getContextId()); + public static String getOriginJobId() { + AsyncJobExecutionContext context = AsyncJobExecutionContext.getCurrentExecutionContext(); + if (context != null && context.getJob() != null) + return "Job-" + context.getJob().getId(); + + return ""; } } diff --git a/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java b/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java index 86e62dc5a6e..2be27860f07 100644 --- a/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java +++ b/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java @@ -34,8 +34,10 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.log4j.Logger; +import org.apache.log4j.NDC; import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.framework.config.ConfigDepot; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; @@ -428,6 +430,24 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, private Runnable getExecutorRunnable(final AsyncJob job) { return new ManagedContextRunnable() { + + @Override + public void run() { + // register place-holder context to avoid installing system account call context + if (CallContext.current() == null) + CallContext.registerPlaceHolderContext(); + + if (job.getRelated() != null && !job.getRelated().isEmpty()) + NDC.push("Job-" + job.getRelated() + "/" + "Job-" + job.getId()); + else + NDC.push("Job-" + job.getId()); + try { + super.run(); + } finally { + NDC.pop(); + } + } + @Override protected void runInContext() { long runNumber = getJobRunNumber(); diff --git a/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobVO.java b/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobVO.java index 24af392f0f4..d1ee2df7598 100644 --- a/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobVO.java +++ b/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobVO.java @@ -132,7 +132,7 @@ public class AsyncJobVO implements AsyncJob, JobInfo { public AsyncJobVO() { uuid = UUID.randomUUID().toString(); - related = UUID.randomUUID().toString(); + related = ""; status = Status.IN_PROGRESS; } diff --git a/framework/managed-context/src/main/java/org/apache/cloudstack/managed/context/ManagedContextRunnable.java b/framework/managed-context/src/main/java/org/apache/cloudstack/managed/context/ManagedContextRunnable.java index d33521501f4..b4a9758420b 100644 --- a/framework/managed-context/src/main/java/org/apache/cloudstack/managed/context/ManagedContextRunnable.java +++ b/framework/managed-context/src/main/java/org/apache/cloudstack/managed/context/ManagedContextRunnable.java @@ -42,7 +42,7 @@ public abstract class ManagedContextRunnable implements Runnable { } @Override - final public void run() { + public void run() { getContext().runWithContext(new Runnable() { @Override public void run() { diff --git a/server/src/com/cloud/api/ApiAsyncJobDispatcher.java b/server/src/com/cloud/api/ApiAsyncJobDispatcher.java index 71ac616cbfc..f037f2e81a7 100644 --- a/server/src/com/cloud/api/ApiAsyncJobDispatcher.java +++ b/server/src/com/cloud/api/ApiAsyncJobDispatcher.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.framework.jobs.AsyncJob; import org.apache.cloudstack.framework.jobs.AsyncJobDispatcher; import org.apache.cloudstack.framework.jobs.AsyncJobManager; import org.apache.cloudstack.jobs.JobInfo; -import org.apache.cloudstack.managed.context.ManagedContext; import com.cloud.user.Account; import com.cloud.user.User; @@ -54,23 +53,12 @@ public class ApiAsyncJobDispatcher extends AdapterBase implements AsyncJobDispat private AsyncJobManager _asyncJobMgr; @Inject private EntityManager _entityMgr; - @Inject - ManagedContext _managedContext; public ApiAsyncJobDispatcher() { } @Override public void runJob(final AsyncJob job) { - _managedContext.runWithContext(new Runnable() { - @Override - public void run() { - runJobInContext(job); - } - }); - } - - protected void runJobInContext(AsyncJob job) { BaseAsyncCmd cmdObj = null; try { Class cmdClass = Class.forName(job.getCmd()); @@ -106,7 +94,7 @@ public class ApiAsyncJobDispatcher extends AdapterBase implements AsyncJobDispat accountObject = _entityMgr.findById(Account.class, Long.parseLong(acctIdStr)); } - CallContext.register(user, accountObject, job.getRelated()); + CallContext.register(user, accountObject); try { // dispatch could ultimately queue the job _dispatcher.dispatch(cmdObj, params, true); diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index ba58b52d385..25792fbdc85 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -522,9 +522,9 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer params.put("cmdEventType", asyncCmd.getEventType().toString()); Long instanceId = (objectId == null) ? asyncCmd.getInstanceId() : objectId; - AsyncJobVO job = - new AsyncJobVO(ctx.getContextId(), callerUserId, caller.getId(), cmdObj.getClass().getName(), ApiGsonHelper.getBuilder().create().toJson(params), - instanceId, asyncCmd.getInstanceType() != null ? asyncCmd.getInstanceType().toString() : null); + AsyncJobVO job = new AsyncJobVO("", callerUserId, caller.getId(), cmdObj.getClass().getName(), + ApiGsonHelper.getBuilder().create().toJson(params), instanceId, + asyncCmd.getInstanceType() != null ? asyncCmd.getInstanceType().toString() : null); job.setDispatcher(_asyncDispatcher.getName()); long jobId = _asyncMgr.submitAsyncJob(job); diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index a64f15cafc2..8404cabcad0 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.TimeZone; -import java.util.UUID; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -106,6 +105,7 @@ import com.cloud.agent.api.to.StaticNatRuleTO; import com.cloud.agent.manager.Commands; import com.cloud.alert.AlertManager; import com.cloud.api.ApiAsyncJobDispatcher; +import com.cloud.api.ApiDispatcher; import com.cloud.api.ApiGsonHelper; import com.cloud.cluster.ManagementServerHostVO; import com.cloud.cluster.dao.ManagementServerHostDao; @@ -4194,26 +4194,26 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V return (Version.compare(trimmedVersion, MinVRVersion) >= 0); } - private List rebootRouters(final List routers) { - final List jobIds = new ArrayList(); - for (final DomainRouterVO router : routers) { - if (!checkRouterVersion(router)) { - s_logger.debug("Upgrading template for router: " + router.getId()); - final Map params = new HashMap(); - params.put("ctxUserId", "1"); - params.put("ctxAccountId", "" + router.getAccountId()); + private List rebootRouters(List routers){ + List jobIds = new ArrayList(); + for(DomainRouterVO router: routers){ + if(!checkRouterVersion(router)){ + s_logger.debug("Upgrading template for router: "+router.getId()); + ApiDispatcher.getInstance(); + Map params = new HashMap(); + params.put("ctxUserId", "1"); + params.put("ctxAccountId", "" + router.getAccountId()); - final RebootRouterCmd cmd = new RebootRouterCmd(); - ComponentContext.inject(cmd); - params.put("id", "" + router.getId()); - params.put("ctxStartEventId", "1"); - final AsyncJobVO job = - new AsyncJobVO(UUID.randomUUID().toString(), User.UID_SYSTEM, router.getAccountId(), RebootRouterCmd.class.getName(), ApiGsonHelper.getBuilder() - .create() - .toJson(params), router.getId(), cmd.getInstanceType() != null ? cmd.getInstanceType().toString() : null); - job.setDispatcher(_asyncDispatcher.getName()); - final long jobId = _asyncMgr.submitAsyncJob(job); - jobIds.add(jobId); + RebootRouterCmd cmd = new RebootRouterCmd(); + ComponentContext.inject(cmd); + params.put("id", ""+router.getId()); + params.put("ctxStartEventId", "1"); + AsyncJobVO job = new AsyncJobVO("", User.UID_SYSTEM, router.getAccountId(), RebootRouterCmd.class.getName(), + ApiGsonHelper.getBuilder().create().toJson(params), router.getId(), + cmd.getInstanceType() != null ? cmd.getInstanceType().toString() : null); + job.setDispatcher(_asyncDispatcher.getName()); + long jobId = _asyncMgr.submitAsyncJob(job); + jobIds.add(jobId); } else { s_logger.debug("Router: " + router.getId() + " is already at the latest version. No upgrade required"); } diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java index 184be3806ec..a94ebab2e98 100644 --- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java @@ -2141,7 +2141,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic workJob.setStep(VmWorkJobVO.Step.Starting); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkAttachVolume workInfo = new VmWorkAttachVolume(callingUser.getId(), callingAccount.getId(), vm.getId(), @@ -2192,7 +2192,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic workJob.setStep(VmWorkJobVO.Step.Starting); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkDetachVolume workInfo = new VmWorkDetachVolume(callingUser.getId(), callingAccount.getId(), vm.getId(), @@ -2242,7 +2242,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic workJob.setStep(VmWorkJobVO.Step.Starting); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkResizeVolume workInfo = new VmWorkResizeVolume(callingUser.getId(), callingAccount.getId(), vm.getId(), @@ -2291,7 +2291,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic workJob.setStep(VmWorkJobVO.Step.Starting); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkMigrateVolume workInfo = new VmWorkMigrateVolume(callingUser.getId(), callingAccount.getId(), vm.getId(), @@ -2340,7 +2340,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic workJob.setStep(VmWorkJobVO.Step.Starting); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkTakeVolumeSnapshot workInfo = new VmWorkTakeVolumeSnapshot( diff --git a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java index 315905953a6..183a13a7cbe 100644 --- a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java @@ -22,7 +22,6 @@ import java.util.List; import java.util.Map; import java.util.Timer; import java.util.TimerTask; -import java.util.UUID; import javax.ejb.Local; import javax.inject.Inject; @@ -261,10 +260,9 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu params.put("id", "" + cmd.getEntityId()); params.put("ctxStartEventId", "1"); - AsyncJobVO job = - new AsyncJobVO(UUID.randomUUID().toString(), User.UID_SYSTEM, volume.getAccountId(), CreateSnapshotCmd.class.getName(), ApiGsonHelper.getBuilder() - .create() - .toJson(params), cmd.getEntityId(), cmd.getInstanceType() != null ? cmd.getInstanceType().toString() : null); + AsyncJobVO job = new AsyncJobVO("", User.UID_SYSTEM, volume.getAccountId(), CreateSnapshotCmd.class.getName(), + ApiGsonHelper.getBuilder().create().toJson(params), cmd.getEntityId(), + cmd.getInstanceType() != null ? cmd.getInstanceType().toString() : null); job.setDispatcher(_asyncDispatcher.getName()); long jobId = _asyncMgr.submitAsyncJob(job); diff --git a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java index 4bae4d063f4..9d7a9528cca 100644 --- a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java +++ b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java @@ -875,7 +875,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana workJob.setStep(VmWorkJobVO.Step.Starting); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkCreateVMSnapshot workInfo = new VmWorkCreateVMSnapshot(callingUser.getId(), callingAccount.getId(), vm.getId(), @@ -923,7 +923,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana workJob.setStep(VmWorkJobVO.Step.Starting); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkDeleteVMSnapshot workInfo = new VmWorkDeleteVMSnapshot(callingUser.getId(), callingAccount.getId(), vm.getId(), @@ -971,7 +971,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana workJob.setStep(VmWorkJobVO.Step.Starting); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkRevertToVMSnapshot workInfo = new VmWorkRevertToVMSnapshot(callingUser.getId(), callingAccount.getId(), vm.getId(), @@ -1019,7 +1019,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana workJob.setStep(VmWorkJobVO.Step.Starting); workJob.setVmType(VirtualMachine.Type.Instance); workJob.setVmInstanceId(vm.getId()); - workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId()); + workJob.setRelated(AsyncJobExecutionContext.getOriginJobId()); // save work context info (there are some duplications) VmWorkDeleteAllVMSnapshots workInfo = new VmWorkDeleteAllVMSnapshots(callingUser.getId(), callingAccount.getId(), vm.getId(),