You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ke...@apache.org on 2013/12/18 02:11:24 UTC
[2/2] git commit: updated refs/heads/4.3 to ed2125e
CLOUDSTACK-669: convert volume attach/detach flows to make them be serialized with other VM operations
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/ed2125ec
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/ed2125ec
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/ed2125ec
Branch: refs/heads/4.3
Commit: ed2125ec340c8d3e77136dfb39a97111630af420
Parents: d0abf3f
Author: Kelven Yang <ke...@gmail.com>
Authored: Tue Dec 17 16:46:36 2013 -0800
Committer: Kelven Yang <ke...@gmail.com>
Committed: Tue Dec 17 17:11:05 2013 -0800
----------------------------------------------------------------------
.../src/com/cloud/vm/VmWorkConstants.java | 23 +
.../src/com/cloud/vm/VmWorkJobHandler.java | 26 +
.../src/com/cloud/vm/VmWorkSerializer.java | 75 +++
...spring-engine-orchestration-core-context.xml | 5 +-
.../com/cloud/vm/VirtualMachineManagerImpl.java | 528 ++++++++++---------
.../src/com/cloud/vm/VmWorkJobDispatcher.java | 77 ---
.../src/com/cloud/vm/VmWorkJobHandler.java | 26 -
.../src/com/cloud/vm/VmWorkSerializer.java | 75 ---
.../framework/jobs/impl/OutcomeImpl.java | 2 -
.../com/cloud/storage/VmWorkAttachVolume.java | 40 ++
.../com/cloud/storage/VmWorkDetachVolume.java | 34 ++
.../com/cloud/storage/VolumeApiServiceImpl.java | 283 +++++++++-
12 files changed, 737 insertions(+), 457 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ed2125ec/engine/components-api/src/com/cloud/vm/VmWorkConstants.java
----------------------------------------------------------------------
diff --git a/engine/components-api/src/com/cloud/vm/VmWorkConstants.java b/engine/components-api/src/com/cloud/vm/VmWorkConstants.java
new file mode 100644
index 0000000..20e40b7
--- /dev/null
+++ b/engine/components-api/src/com/cloud/vm/VmWorkConstants.java
@@ -0,0 +1,23 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.vm;
+
+public interface VmWorkConstants {
+ public static final String VM_WORK_QUEUE = "VmWorkJobQueue";
+ public static final String VM_WORK_JOB_DISPATCHER = "VmWorkJobDispatcher";
+ public static final String VM_WORK_JOB_WAKEUP_DISPATCHER = "VmWorkJobWakeupDispatcher";
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ed2125ec/engine/components-api/src/com/cloud/vm/VmWorkJobHandler.java
----------------------------------------------------------------------
diff --git a/engine/components-api/src/com/cloud/vm/VmWorkJobHandler.java b/engine/components-api/src/com/cloud/vm/VmWorkJobHandler.java
new file mode 100644
index 0000000..6ab1bbc
--- /dev/null
+++ b/engine/components-api/src/com/cloud/vm/VmWorkJobHandler.java
@@ -0,0 +1,26 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.vm;
+
+import org.apache.cloudstack.framework.jobs.AsyncJob;
+import org.apache.cloudstack.jobs.JobInfo;
+
+import com.cloud.utils.Pair;
+
+public interface VmWorkJobHandler {
+ Pair<JobInfo.Status, String> handleVmWorkJob(AsyncJob job, VmWork work) throws Exception;
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ed2125ec/engine/components-api/src/com/cloud/vm/VmWorkSerializer.java
----------------------------------------------------------------------
diff --git a/engine/components-api/src/com/cloud/vm/VmWorkSerializer.java b/engine/components-api/src/com/cloud/vm/VmWorkSerializer.java
new file mode 100644
index 0000000..9a1aaac
--- /dev/null
+++ b/engine/components-api/src/com/cloud/vm/VmWorkSerializer.java
@@ -0,0 +1,75 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.vm;
+
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+
+public class VmWorkSerializer {
+ static class StringMapTypeAdapter implements JsonDeserializer<Map> {
+
+ @Override
+ public Map deserialize(JsonElement src, Type srcType, JsonDeserializationContext context) throws JsonParseException {
+
+ Map<String, String> obj = new HashMap<String, String>();
+ JsonObject json = src.getAsJsonObject();
+
+ for (Entry<String, JsonElement> entry : json.entrySet()) {
+ obj.put(entry.getKey(), entry.getValue().getAsString());
+ }
+
+ return obj;
+ }
+ }
+
+ protected static Gson s_gson;
+ static {
+ GsonBuilder gBuilder = new GsonBuilder();
+ gBuilder.setVersion(1.3);
+ gBuilder.registerTypeAdapter(Map.class, new StringMapTypeAdapter());
+ s_gson = gBuilder.create();
+ }
+
+ public static String serialize(VmWork work) {
+ // TODO: there are way many generics, too tedious to get serialization work under GSON
+ // use java binary serialization instead
+ //
+ return JobSerializerHelper.toObjectSerializedString(work);
+ // return s_gson.toJson(work);
+ }
+
+ public static <T extends VmWork> T deserialize(Class<?> clazz, String workInJsonText) {
+ // TODO: there are way many generics, too tedious to get serialization work under GSON
+ // use java binary serialization instead
+ //
+ return (T)JobSerializerHelper.fromObjectSerializedString(workInJsonText);
+ // return (T)s_gson.fromJson(workInJsonText, clazz);
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ed2125ec/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml
----------------------------------------------------------------------
diff --git a/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml b/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml
index 49cb9cd..2e35ae5 100644
--- a/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml
+++ b/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml
@@ -75,17 +75,18 @@
<bean id= "vmWorkJobDispatcher" class="com.cloud.vm.VmWorkJobDispatcher">
<property name="name">
- <util:constant static-field="com.cloud.vm.VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER"/>
+ <util:constant static-field="com.cloud.vm.VmWorkConstants.VM_WORK_JOB_DISPATCHER"/>
</property>
<property name="handlers">
<map>
<entry key="VirtualMachineManagerImpl" value-ref="clusteredVirtualMachineManagerImpl" />
+ <entry key="VolumeApiServiceImpl" value-ref="volumeApiServiceImpl" />
</map>
</property>
</bean>
<bean id= "vmWorkJobWakeupDispatcher" class="com.cloud.vm.VmWorkJobWakeupDispatcher">
<property name="name">
- <util:constant static-field="com.cloud.vm.VmWorkJobDispatcher.VM_WORK_JOB_WAKEUP_DISPATCHER"/>
+ <util:constant static-field="com.cloud.vm.VmWorkConstants.VM_WORK_JOB_WAKEUP_DISPATCHER"/>
</property>
</bean>
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ed2125ec/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 4a5c2cc..124ae81 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -211,7 +211,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
public static final String VM_WORK_JOB_HANDLER = VirtualMachineManagerImpl.class.getSimpleName();
private static final String VM_SYNC_ALERT_SUBJECT = "VM state sync alert";
-
+
@Inject
DataStoreManager dataStoreMgr;
@Inject
@@ -310,7 +310,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
@Inject protected VirtualMachinePowerStateSync _syncMgr;
@Inject protected VmWorkJobDao _workJobDao;
@Inject protected AsyncJobManager _jobMgr;
-
+
Map<VirtualMachine.Type, VirtualMachineGuru> _vmGurus = new HashMap<VirtualMachine.Type, VirtualMachineGuru>();
protected StateMachine2<State, VirtualMachine.Event, VirtualMachine> _stateMachine;
@@ -330,10 +330,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
"On destroy, force-stop takes this value ", true);
static final ConfigKey<Integer> ClusterDeltaSyncInterval = new ConfigKey<Integer>("Advanced", Integer.class, "sync.interval", "60", "Cluster Delta sync interval in seconds",
false);
-
+
+ // TODO, remove it after transient period is over
static final ConfigKey<Boolean> VmJobEnabled = new ConfigKey<Boolean>("Advanced",
Boolean.class, "vm.job.enabled", "false",
"True to enable new VM sync model. false to use the old way", false);
+
static final ConfigKey<Long> VmJobCheckInterval = new ConfigKey<Long>("Advanced",
Long.class, "vm.job.check.interval", "3000",
"Interval in milliseconds to check if the job is complete", false);
@@ -386,17 +388,17 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
if (s_logger.isDebugEnabled()) {
s_logger.debug("Allocating nics for " + vmFinal);
}
-
+
try {
_networkMgr.allocate(vmProfile, auxiliaryNetworks);
} catch (ConcurrentOperationException e) {
throw new CloudRuntimeException("Concurrent operation while trying to allocate resources for the VM", e);
}
-
+
if (s_logger.isDebugEnabled()) {
s_logger.debug("Allocating disks for " + vmFinal);
}
-
+
if (template.getFormat() == ImageFormat.ISO) {
volumeMgr.allocateRawVolume(Type.ROOT, "ROOT-" + vmFinal.getId(), rootDiskOffering.first(), rootDiskOffering.second(), vmFinal, template, owner);
} else if (template.getFormat() == ImageFormat.BAREMETAL) {
@@ -404,7 +406,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
} else {
volumeMgr.allocateTemplatedVolume(Type.ROOT, "ROOT-" + vmFinal.getId(), rootDiskOffering.first(), template, vmFinal, owner);
}
-
+
for (Map.Entry<? extends DiskOffering, Long> offering : dataDiskOfferingsFinal.entrySet()) {
volumeMgr.allocateRawVolume(Type.DATADISK, "DATA-" + vmFinal.getId(), offering.getKey(), offering.getValue(), vmFinal, template, owner);
}
@@ -624,7 +626,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
return new Ternary<VMInstanceVO, ReservationContext, ItWorkVO>(null, null, work);
}
});
-
+
work = result.third();
if (result.first() != null)
return result;
@@ -696,21 +698,21 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
@Override
public void advanceStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params)
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
-
+
advanceStart(vmUuid, params, null);
}
@Override
public void advanceStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy) throws InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException {
-
+
AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
- if(!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER)) {
+ if (!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
// avoid re-entrance
orchestrateStart(vmUuid, params, planToDeploy);
} else {
Outcome<VirtualMachine> outcome = startVmThroughJobQueue(vmUuid, params, planToDeploy);
-
+
try {
VirtualMachine vm = outcome.get();
} catch (InterruptedException e) {
@@ -718,8 +720,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
} catch (java.util.concurrent.ExecutionException e) {
throw new RuntimeException("Execution excetion", e);
}
-
- Throwable jobException = retriveExecutionException(outcome.getJob());
+
+ Throwable jobException = retrieveExecutionException(outcome.getJob());
if(jobException != null) {
if(jobException instanceof ConcurrentOperationException)
throw (ConcurrentOperationException)jobException;
@@ -728,10 +730,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
}
}
-
+
private void orchestrateStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy) throws InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException {
-
+
CallContext cctxt = CallContext.current();
Account account = cctxt.getCallingAccount();
User caller = cctxt.getCallingUser();
@@ -1225,14 +1227,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
@Override
public void advanceStop(String vmUuid, boolean cleanUpEvenIfUnableToStop)
throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException {
-
+
AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
- if(!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER)) {
+ if (!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
// avoid re-entrance
orchestrateStop(vmUuid, cleanUpEvenIfUnableToStop);
} else {
Outcome<VirtualMachine> outcome = stopVmThroughJobQueue(vmUuid, cleanUpEvenIfUnableToStop);
-
+
try {
VirtualMachine vm = outcome.get();
} catch (InterruptedException e) {
@@ -1240,8 +1242,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
} catch (java.util.concurrent.ExecutionException e) {
throw new RuntimeException("Execution excetion", e);
}
-
- Throwable jobException = retriveExecutionException(outcome.getJob());
+
+ Throwable jobException = retrieveExecutionException(outcome.getJob());
if(jobException != null) {
if(jobException instanceof AgentUnavailableException)
throw (AgentUnavailableException)jobException;
@@ -1513,16 +1515,16 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
return true;
}
-
+
@Override
public void storageMigration(String vmUuid, StoragePool destPool) {
AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
- if(!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER)) {
+ if (!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
// avoid re-entrance
orchestrateStorageMigration(vmUuid, destPool);
} else {
Outcome<VirtualMachine> outcome = migrateVmStorageThroughJobQueue(vmUuid, destPool);
-
+
try {
VirtualMachine vm = outcome.get();
} catch (InterruptedException e) {
@@ -1530,8 +1532,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
} catch (java.util.concurrent.ExecutionException e) {
throw new RuntimeException("Execution excetion", e);
}
-
- Throwable jobException = retriveExecutionException(outcome.getJob());
+
+ Throwable jobException = retrieveExecutionException(outcome.getJob());
if(jobException != null) {
if(jobException instanceof RuntimeException)
throw (RuntimeException)jobException;
@@ -1597,14 +1599,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
@Override
public void migrate(String vmUuid, long srcHostId, DeployDestination dest)
throws ResourceUnavailableException, ConcurrentOperationException {
-
+
AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
- if(!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER)) {
+ if (!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
// avoid re-entrance
orchestrateMigrate(vmUuid, srcHostId, dest);
} else {
Outcome<VirtualMachine> outcome = migrateVmThroughJobQueue(vmUuid, srcHostId, dest);
-
+
try {
VirtualMachine vm = outcome.get();
} catch (InterruptedException e) {
@@ -1612,8 +1614,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
} catch (java.util.concurrent.ExecutionException e) {
throw new RuntimeException("Execution excetion", e);
}
-
- Throwable jobException = retriveExecutionException(outcome.getJob());
+
+ Throwable jobException = retrieveExecutionException(outcome.getJob());
if(jobException != null) {
if(jobException instanceof ResourceUnavailableException)
throw (ResourceUnavailableException)jobException;
@@ -1624,7 +1626,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
}
}
-
+
private void orchestrateMigrate(String vmUuid, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException {
VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
if (vm == null) {
@@ -1868,14 +1870,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
@Override
public void migrateWithStorage(String vmUuid, long srcHostId, long destHostId, Map<Volume, StoragePool> volumeToPool)
throws ResourceUnavailableException, ConcurrentOperationException {
-
+
AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
- if(!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER)) {
+ if (!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
// avoid re-entrance
orchestrateMigrateWithStorage(vmUuid, srcHostId, destHostId, volumeToPool);
} else {
Outcome<VirtualMachine> outcome = migrateVmWithStorageThroughJobQueue(vmUuid, srcHostId, destHostId, volumeToPool);
-
+
try {
VirtualMachine vm = outcome.get();
} catch (InterruptedException e) {
@@ -1884,7 +1886,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
throw new RuntimeException("Execution excetion", e);
}
- Throwable jobException = retriveExecutionException(outcome.getJob());
+ Throwable jobException = retrieveExecutionException(outcome.getJob());
if(jobException != null) {
if(jobException instanceof ResourceUnavailableException)
throw (ResourceUnavailableException)jobException;
@@ -1893,10 +1895,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
}
}
-
+
private void orchestrateMigrateWithStorage(String vmUuid, long srcHostId, long destHostId, Map<Volume, StoragePool> volumeToPool) throws ResourceUnavailableException,
ConcurrentOperationException {
-
+
VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
HostVO srcHost = _hostDao.findById(srcHostId);
@@ -2143,18 +2145,18 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
throw new CloudRuntimeException("Unable to reboot a VM due to concurrent operation", e);
}
}
-
+
@Override
public void advanceReboot(String vmUuid, Map<VirtualMachineProfile.Param, Object> params)
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
-
+
AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
- if(!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER)) {
+ if (!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
// avoid re-entrance
orchestrateReboot(vmUuid, params);
} else {
Outcome<VirtualMachine> outcome = rebootVmThroughJobQueue(vmUuid, params);
-
+
try {
VirtualMachine vm = outcome.get();
} catch (InterruptedException e) {
@@ -2162,8 +2164,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
} catch (java.util.concurrent.ExecutionException e) {
throw new RuntimeException("Execution excetion", e);
}
-
- Throwable jobException = retriveExecutionException(outcome.getJob());
+
+ Throwable jobException = retrieveExecutionException(outcome.getJob());
if(jobException != null) {
if(jobException instanceof ResourceUnavailableException)
throw (ResourceUnavailableException)jobException;
@@ -2174,7 +2176,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
}
}
-
+
private void orchestrateReboot(String vmUuid, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ConcurrentOperationException,
ResourceUnavailableException {
VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
@@ -2823,13 +2825,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
}
}
-
+
if(VmJobEnabled.value()) {
if(ping.getHostVmStateReport() != null && ping.getHostVmStateReport().size() > 0) {
_syncMgr.processHostVmStatePingReport(agentId, ping.getHostVmStateReport());
}
}
-
+
// take the chance to scan VMs that are stuck in transitional states
// and are missing from the report
scanStalledVMInTransitionStateOnUpHost(agentId);
@@ -2854,14 +2856,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
if (!(cmd instanceof StartupRoutingCommand)) {
return;
}
-
+
if(s_logger.isDebugEnabled())
s_logger.debug("Received startup command from hypervisor host. host id: " + agent.getId());
if(VmJobEnabled.value()) {
_syncMgr.resetHostSyncState(agent.getId());
}
-
+
if (forRebalance) {
s_logger.debug("Not processing listener " + this + " as connect happens on rebalance process");
return;
@@ -2968,7 +2970,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
this.vm = vm;
hostUuid = host;
this.platform = platform;
-
+
}
public AgentVmInfo(String name, VMInstanceVO vm, State state, String host) {
@@ -2982,7 +2984,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
public String getHostUuid() {
return hostUuid;
}
-
+
public String getPlatform() {
return platform;
}
@@ -3066,18 +3068,18 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
vmForUpdate.setServiceOfferingId(newSvcOff.getId());
return _vmDao.update(vmId, vmForUpdate);
}
-
+
@Override
public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
-
+
AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
- if(!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER)) {
+ if (!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
// avoid re-entrance
return orchestrateAddVmToNetwork(vm, network,requested);
} else {
Outcome<VirtualMachine> outcome = addVmToNetworkThroughJobQueue(vm, network, requested);
-
+
try {
outcome.get();
} catch (InterruptedException e) {
@@ -3085,14 +3087,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
} catch (java.util.concurrent.ExecutionException e) {
throw new RuntimeException("Execution excetion", e);
}
-
+
AsyncJobVO jobVo = _entityMgr.findById(AsyncJobVO.class, outcome.getJob().getId());
if(jobVo.getResultCode() == JobInfo.Status.SUCCEEDED.ordinal()) {
-
+
NicProfile nic = (NicProfile)JobSerializerHelper.fromObjectSerializedString(jobVo.getResult());
return nic;
} else {
- Throwable jobException = retriveExecutionException(outcome.getJob());
+ Throwable jobException = retrieveExecutionException(outcome.getJob());
if(jobException != null) {
if(jobException instanceof ResourceUnavailableException)
throw (ResourceUnavailableException)jobException;
@@ -3107,7 +3109,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
}
}
-
+
private NicProfile orchestrateAddVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
CallContext cctx = CallContext.current();
@@ -3173,18 +3175,18 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
NicTO nicTO = hvGuru.toNicTO(nic);
return nicTO;
}
-
+
@Override
public boolean removeNicFromVm(VirtualMachine vm, Nic nic)
throws ConcurrentOperationException, ResourceUnavailableException {
-
+
AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
- if(!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER)) {
+ if (!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
// avoid re-entrance
return orchestrateRemoveNicFromVm(vm, nic);
} else {
Outcome<VirtualMachine> outcome = removeNicFromVmThroughJobQueue(vm, nic);
-
+
try {
outcome.get();
} catch (InterruptedException e) {
@@ -3194,12 +3196,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
AsyncJobVO jobVo = _entityMgr.findById(AsyncJobVO.class, outcome.getJob().getId());
-
+
if(jobVo.getResultCode() == JobInfo.Status.SUCCEEDED.ordinal()) {
Boolean result = (Boolean)JobSerializerHelper.fromObjectSerializedString(jobVo.getResult());
return result;
} else {
- Throwable jobException = retriveExecutionException(outcome.getJob());
+ Throwable jobException = retrieveExecutionException(outcome.getJob());
if(jobException != null) {
if(jobException instanceof ResourceUnavailableException)
throw (ResourceUnavailableException)jobException;
@@ -3208,7 +3210,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
else if(jobException instanceof RuntimeException)
throw (RuntimeException)jobException;
}
-
+
throw new RuntimeException("Job failed with un-handled exception");
}
}
@@ -3277,7 +3279,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
// TODO will serialize on the VM object later to resolve operation conflicts
return orchestrateRemoveVmFromNetwork(vm, network, broadcastUri);
}
-
+
@DB
private boolean orchestrateRemoveVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException {
CallContext cctx = CallContext.current();
@@ -3415,17 +3417,17 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
throw e;
}
}
-
+
@Override
public void migrateForScale(String vmUuid, long srcHostId, DeployDestination dest, Long oldSvcOfferingId)
throws ResourceUnavailableException, ConcurrentOperationException {
AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
- if(!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER)) {
+ if (!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
// avoid re-entrance
orchestrateMigrateForScale(vmUuid, srcHostId, dest, oldSvcOfferingId);
} else {
Outcome<VirtualMachine> outcome = migrateVmForScaleThroughJobQueue(vmUuid, srcHostId, dest, oldSvcOfferingId);
-
+
try {
VirtualMachine vm = outcome.get();
} catch (InterruptedException e) {
@@ -3433,8 +3435,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
} catch (java.util.concurrent.ExecutionException e) {
throw new RuntimeException("Execution excetion", e);
}
-
- Throwable jobException = retriveExecutionException(outcome.getJob());
+
+ Throwable jobException = retrieveExecutionException(outcome.getJob());
if(jobException != null) {
if(jobException instanceof ResourceUnavailableException)
throw (ResourceUnavailableException)jobException;
@@ -3446,7 +3448,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
private void orchestrateMigrateForScale(String vmUuid, long srcHostId, DeployDestination dest, Long oldSvcOfferingId)
throws ResourceUnavailableException, ConcurrentOperationException {
-
+
VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
s_logger.info("Migrating " + vm + " to " + dest);
@@ -3662,19 +3664,19 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
return result;
}
-
+
@Override
public VMInstanceVO reConfigureVm(String vmUuid, ServiceOffering oldServiceOffering,
boolean reconfiguringOnExistingHost)
throws ResourceUnavailableException, ConcurrentOperationException {
AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
- if(!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER)) {
+ if (!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
// avoid re-entrance
return orchestrateReConfigureVm(vmUuid, oldServiceOffering, reconfiguringOnExistingHost);
} else {
Outcome<VirtualMachine> outcome = reconfigureVmThroughJobQueue(vmUuid, oldServiceOffering, reconfiguringOnExistingHost);
-
+
VirtualMachine vm = null;
try {
vm = outcome.get();
@@ -3688,19 +3690,19 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
if(jobVo.getResultCode() == JobInfo.Status.SUCCEEDED.ordinal()) {
return _entityMgr.findById(VMInstanceVO.class, vm.getId());
} else {
- Throwable jobException = retriveExecutionException(outcome.getJob());
+ Throwable jobException = retrieveExecutionException(outcome.getJob());
if(jobException != null) {
if(jobException instanceof ResourceUnavailableException)
throw (ResourceUnavailableException)jobException;
else if(jobException instanceof ConcurrentOperationException)
throw (ConcurrentOperationException)jobException;
}
-
+
throw new RuntimeException("Failed with un-handled exception");
}
}
}
-
+
private VMInstanceVO orchestrateReConfigureVm(String vmUuid, ServiceOffering oldServiceOffering, boolean reconfiguringOnExistingHost) throws ResourceUnavailableException,
ConcurrentOperationException {
VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
@@ -3775,16 +3777,16 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
_storagePoolAllocators = storagePoolAllocators;
}
-
+
//
// PowerState report handling for out-of-band changes and handling of left-over transitional VM states
//
-
+
@MessageHandler(topic = Topics.VM_POWER_STATE)
private void HandlePownerStateReport(Object target, String subject, String senderAddress, Object args) {
assert(args != null);
Long vmId = (Long)args;
-
+
List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
VirtualMachine.Type.Instance, vmId);
if(pendingWorkJobs.size() == 0) {
@@ -3795,7 +3797,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
case PowerOn :
handlePowerOnReportWithNoPendingJobsOnVM(vm);
break;
-
+
case PowerOff :
handlePowerOffReportWithNoPendingJobsOnVM(vm);
break;
@@ -3815,7 +3817,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
// we will skip it for nows
}
}
-
+
private void handlePowerOnReportWithNoPendingJobsOnVM(VMInstanceVO vm) {
//
// 1) handle left-over transitional VM states
@@ -3830,12 +3832,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
} catch(NoTransitionException e) {
s_logger.warn("Unexpected VM state transition exception, race-condition?", e);
}
-
+
// we need to alert admin or user about this risky state transition
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_SYNC, vm.getDataCenterId(), vm.getPodIdToDeployIn(),
VM_SYNC_ALERT_SUBJECT, "VM " + vm.getHostName() + "(" + vm.getInstanceName() + ") state is sync-ed (Starting -> Running) from out-of-context transition. VM network environment may need to be reset");
break;
-
+
case Running :
try {
if(vm.getHostId() != null && vm.getHostId().longValue() != vm.getPowerHostId().longValue())
@@ -3845,7 +3847,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
s_logger.warn("Unexpected VM state transition exception, race-condition?", e);
}
break;
-
+
case Stopping :
case Stopped :
try {
@@ -3856,13 +3858,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_SYNC, vm.getDataCenterId(), vm.getPodIdToDeployIn(),
VM_SYNC_ALERT_SUBJECT, "VM " + vm.getHostName() + "(" + vm.getInstanceName() + ") state is sync-ed (" + vm.getState() + " -> Running) from out-of-context transition. VM network environment may need to be reset");
break;
-
+
case Destroyed :
case Expunging :
s_logger.info("Receive power on report when VM is in destroyed or expunging state. vm: "
+ vm.getId() + ", state: " + vm.getState());
break;
-
+
case Migrating :
try {
stateTransitTo(vm, VirtualMachine.Event.FollowAgentPowerOnReport, vm.getPowerHostId());
@@ -3870,7 +3872,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
s_logger.warn("Unexpected VM state transition exception, race-condition?", e);
}
break;
-
+
case Error :
default :
s_logger.info("Receive power on report when VM is in error or unexpected state. vm: "
@@ -3878,7 +3880,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
break;
}
}
-
+
private void handlePowerOffReportWithNoPendingJobsOnVM(VMInstanceVO vm) {
// 1) handle left-over transitional VM states
@@ -3898,18 +3900,18 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
VM_SYNC_ALERT_SUBJECT, "VM " + vm.getHostName() + "(" + vm.getInstanceName() + ") state is sync-ed (" + vm.getState() + " -> Stopped) from out-of-context transition.");
// TODO: we need to forcely release all resource allocation
break;
-
+
case Running :
case Destroyed :
case Expunging :
break;
-
+
case Error :
default :
break;
}
}
-
+
private void scanStalledVMInTransitionStateOnUpHost(long hostId) {
//
// Check VM that is stuck in Starting, Stopping, Migrating states, we won't check
@@ -3926,7 +3928,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
// Therefor, we will scan thoses VMs on UP host based on last update timestamp, if the host is UP
// and a VM stalls for status update, we will consider them to be powered off
// (which is relatively safe to do so)
-
+
long stallThresholdInMs = VmJobStateReportInterval.value() + (VmJobStateReportInterval.value() >> 1);
Date cutTime = new Date(DateUtil.currentGMTTime().getTime() - stallThresholdInMs);
List<Long> mostlikelyStoppedVMs = listStalledVMInTransitionStateOnUpHost(hostId, cutTime);
@@ -3935,7 +3937,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
assert(vm != null);
handlePowerOffReportWithNoPendingJobsOnVM(vm);
}
-
+
List<Long> vmsWithRecentReport = listVMInTransitionStateWithRecentReportOnUpHost(hostId, cutTime);
for(Long vmId : vmsWithRecentReport) {
VMInstanceVO vm = _vmDao.findById(vmId);
@@ -3946,36 +3948,36 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
handlePowerOffReportWithNoPendingJobsOnVM(vm);
}
}
-
+
private void scanStalledVMInTransitionStateOnDisconnectedHosts() {
Date cutTime = new Date(DateUtil.currentGMTTime().getTime() - VmOpWaitInterval.value()*1000);
List<Long> stuckAndUncontrollableVMs = listStalledVMInTransitionStateOnDisconnectedHosts(cutTime);
for(Long vmId : stuckAndUncontrollableVMs) {
VMInstanceVO vm = _vmDao.findById(vmId);
-
+
// We now only alert administrator about this situation
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_SYNC, vm.getDataCenterId(), vm.getPodIdToDeployIn(),
VM_SYNC_ALERT_SUBJECT, "VM " + vm.getHostName() + "(" + vm.getInstanceName() + ") is stuck in " + vm.getState() + " state and its host is unreachable for too long");
}
}
-
-
+
+
// VMs that in transitional state without recent power state report
private List<Long> listStalledVMInTransitionStateOnUpHost(long hostId, Date cutTime) {
String sql = "SELECT i.* FROM vm_instance as i, host as h WHERE h.status = 'UP' " +
"AND h.id = ? AND i.power_state_update_time < ? AND i.host_id = h.id " +
"AND (i.state ='Starting' OR i.state='Stopping' OR i.state='Migrating') " +
"AND i.id NOT IN (SELECT w.vm_instance_id FROM vm_work_job AS w JOIN async_job AS j ON w.id = j.id WHERE j.job_status = ?)";
-
+
List<Long> l = new ArrayList<Long>();
TransactionLegacy txn = null;
try {
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
-
+
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql);
-
+
pstmt.setLong(1, hostId);
pstmt.setString(2, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cutTime));
pstmt.setInt(3, JobInfo.Status.IN_PROGRESS.ordinal());
@@ -3986,21 +3988,21 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
} catch (SQLException e) {
} catch (Throwable e) {
}
-
+
} finally {
if(txn != null)
txn.close();
}
return l;
}
-
+
// VMs that in transitional state and recently have power state update
private List<Long> listVMInTransitionStateWithRecentReportOnUpHost(long hostId, Date cutTime) {
String sql = "SELECT i.* FROM vm_instance as i, host as h WHERE h.status = 'UP' " +
"AND h.id = ? AND i.power_state_update_time > ? AND i.host_id = h.id " +
"AND (i.state ='Starting' OR i.state='Stopping' OR i.state='Migrating') " +
"AND i.id NOT IN (SELECT w.vm_instance_id FROM vm_work_job AS w JOIN async_job AS j ON w.id = j.id WHERE j.job_status = ?)";
-
+
List<Long> l = new ArrayList<Long>();
TransactionLegacy txn = null;
try {
@@ -4008,7 +4010,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql);
-
+
pstmt.setLong(1, hostId);
pstmt.setString(2, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cutTime));
pstmt.setInt(3, JobInfo.Status.IN_PROGRESS.ordinal());
@@ -4025,13 +4027,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
txn.close();
}
}
-
+
private List<Long> listStalledVMInTransitionStateOnDisconnectedHosts(Date cutTime) {
String sql = "SELECT i.* FROM vm_instance as i, host as h WHERE h.status != 'UP' " +
"AND i.power_state_update_time < ? AND i.host_id = h.id " +
"AND (i.state ='Starting' OR i.state='Stopping' OR i.state='Migrating') " +
"AND i.id NOT IN (SELECT w.vm_instance_id FROM vm_work_job AS w JOIN async_job AS j ON w.id = j.id WHERE j.job_status = ?)";
-
+
List<Long> l = new ArrayList<Long>();
TransactionLegacy txn = null;
try {
@@ -4039,7 +4041,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql);
-
+
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cutTime));
pstmt.setInt(2, JobInfo.Status.IN_PROGRESS.ordinal());
ResultSet rs = pstmt.executeQuery();
@@ -4055,11 +4057,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
txn.close();
}
}
-
+
//
// VM operation based on new sync model
//
-
+
public class VmStateSyncOutcome extends OutcomeImpl<VirtualMachine> {
private long _vmId;
@@ -4093,7 +4095,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
assert(jobVo != null);
if(jobVo == null || jobVo.getStatus() != JobInfo.Status.IN_PROGRESS)
return true;
-
+
return false;
}
}, AsyncJob.Topics.JOB_STATE);
@@ -4105,21 +4107,21 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
return _vmDao.findById(_vmId);
}
}
-
- public Throwable retriveExecutionException(AsyncJob job) {
+
+ public Throwable retrieveExecutionException(AsyncJob job) {
assert(job != null);
- assert(job.getDispatcher().equals(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER));
-
+ assert (job.getDispatcher().equals(VmWorkConstants.VM_WORK_JOB_DISPATCHER));
+
AsyncJobVO jobVo = _entityMgr.findById(AsyncJobVO.class, job.getId());
if(jobVo != null && jobVo.getResult() != null) {
Object obj = JobSerializerHelper.fromSerializedString(job.getResult());
-
+
if(obj != null && obj instanceof Throwable)
return (Throwable)obj;
}
return null;
}
-
+
//
// TODO build a common pattern to reduce code duplication in following methods
// no time for this at current iteration
@@ -4127,7 +4129,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
public Outcome<VirtualMachine> startVmThroughJobQueue(final String vmUuid,
final Map<VirtualMachineProfile.Param, Object> params,
final DeploymentPlan planToDeploy) {
-
+
final CallContext context = CallContext.current();
final User callingUser = context.getCallingUser();
final Account callingAccount = context.getCallingAccount();
@@ -4138,18 +4140,18 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
VmWorkJobVO workJob = null;
-
+
_vmDao.lockRow(vm.getId(), true);
List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(VirtualMachine.Type.Instance,
vm.getId(), VmWorkStart.class.getName());
-
+
if (pendingWorkJobs.size() > 0) {
assert (pendingWorkJobs.size() == 1);
workJob = pendingWorkJobs.get(0);
} else {
workJob = new VmWorkJobVO(context.getContextId());
- workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+ workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
workJob.setCmd(VmWorkStart.class.getName());
workJob.setAccountId(callingAccount.getId());
@@ -4164,61 +4166,61 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
workInfo.setParams(params);
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
- _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+ _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
}
-
+
// Transaction syntax sugar has a cost here
context.putContextParameter("workJob", workJob);
context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
-
+
final long jobId = (Long)context.getContextParameter("jobId");
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-
+
return new VmStateSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"),
VirtualMachine.PowerState.PowerOn, vm.getId(), null);
}
-
+
public Outcome<VirtualMachine> stopVmThroughJobQueue(final String vmUuid, final boolean cleanup) {
final CallContext context = CallContext.current();
final Account account = context.getCallingAccount();
final User user = context.getCallingUser();
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
-
+
Transaction.execute(new TransactionCallbackNoReturn () {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
_vmDao.lockRow(vm.getId(), true);
-
+
List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
VirtualMachine.Type.Instance, vm.getId(),
VmWorkStop.class.getName());
-
+
VmWorkJobVO workJob = null;
if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
assert (pendingWorkJobs.size() == 1);
workJob = pendingWorkJobs.get(0);
} else {
workJob = new VmWorkJobVO(context.getContextId());
-
- workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+
+ workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
workJob.setCmd(VmWorkStop.class.getName());
-
+
workJob.setAccountId(account.getId());
workJob.setUserId(user.getId());
workJob.setStep(VmWorkJobVO.Step.Prepare);
workJob.setVmType(vm.getType());
workJob.setVmInstanceId(vm.getId());
-
+
// save work context info (there are some duplications)
VmWorkStop workInfo = new VmWorkStop(user.getId(), account.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, cleanup);
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-
- _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+
+ _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
}
-
+
context.putContextParameter("workJob", workJob);
context.putContextParameter("jobId", new Long(workJob.getId()));
}
@@ -4226,52 +4228,52 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
final long jobId = (Long)context.getContextParameter("jobId");
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-
+
return new VmStateSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"),
VirtualMachine.PowerState.PowerOff, vm.getId(), null);
}
-
+
public Outcome<VirtualMachine> rebootVmThroughJobQueue(final String vmUuid,
final Map<VirtualMachineProfile.Param, Object> params) {
-
+
final CallContext context = CallContext.current();
final Account account = context.getCallingAccount();
final User user = context.getCallingUser();
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
-
+
Transaction.execute(new TransactionCallbackNoReturn () {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
_vmDao.lockRow(vm.getId(), true);
-
+
List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
VirtualMachine.Type.Instance, vm.getId(),
VmWorkReboot.class.getName());
-
+
VmWorkJobVO workJob = null;
if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
assert (pendingWorkJobs.size() == 1);
workJob = pendingWorkJobs.get(0);
} else {
workJob = new VmWorkJobVO(context.getContextId());
-
- workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+
+ workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
workJob.setCmd(VmWorkReboot.class.getName());
-
+
workJob.setAccountId(account.getId());
workJob.setUserId(user.getId());
workJob.setStep(VmWorkJobVO.Step.Prepare);
workJob.setVmType(vm.getType());
workJob.setVmInstanceId(vm.getId());
-
+
// save work context info (there are some duplications)
VmWorkReboot workInfo = new VmWorkReboot(user.getId(), account.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, params);
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-
- _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+
+ _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
}
-
+
context.putContextParameter("workJob", workJob);
context.putContextParameter("jobId", new Long(workJob.getId()));
}
@@ -4279,11 +4281,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
final long jobId = (Long)context.getContextParameter("jobId");
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-
+
return new VmJobSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"),
vm.getId());
}
-
+
public Outcome<VirtualMachine> migrateVmThroughJobQueue(final String vmUuid, final long srcHostId, final DeployDestination dest) {
final CallContext context = CallContext.current();
final User user = context.getCallingUser();
@@ -4294,51 +4296,51 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
Transaction.execute(new TransactionCallbackNoReturn () {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
-
+
_vmDao.lockRow(vm.getId(), true);
-
+
List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
VirtualMachine.Type.Instance, vm.getId(),
VmWorkMigrate.class.getName());
-
+
VmWorkJobVO workJob = null;
if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
assert (pendingWorkJobs.size() == 1);
workJob = pendingWorkJobs.get(0);
} else {
-
+
workJob = new VmWorkJobVO(context.getContextId());
-
- workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+
+ workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
workJob.setCmd(VmWorkMigrate.class.getName());
-
+
workJob.setAccountId(account.getId());
workJob.setUserId(user.getId());
workJob.setVmType(vm.getType());
workJob.setVmInstanceId(vm.getId());
-
+
// 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);
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-
- _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+
+ _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
-
+
final long jobId = (Long)context.getContextParameter("jobId");
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-
+
return new VmStateSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"),
VirtualMachine.PowerState.PowerOn, vm.getId(), vm.getPowerHostId());
}
-
+
public Outcome<VirtualMachine> migrateVmWithStorageThroughJobQueue(
final String vmUuid, final long srcHostId, final long destHostId,
final Map<Volume, StoragePool> volumeToPool) {
-
+
final CallContext context = CallContext.current();
final User user = context.getCallingUser();
final Account account = context.getCallingAccount();
@@ -4348,51 +4350,51 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
Transaction.execute(new TransactionCallbackNoReturn () {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
-
+
_vmDao.lockRow(vm.getId(), true);
-
+
List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
VirtualMachine.Type.Instance, vm.getId(),
VmWorkMigrateWithStorage.class.getName());
-
+
VmWorkJobVO workJob = null;
if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
assert (pendingWorkJobs.size() == 1);
workJob = pendingWorkJobs.get(0);
} else {
-
+
workJob = new VmWorkJobVO(context.getContextId());
-
- workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+
+ workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
workJob.setCmd(VmWorkMigrate.class.getName());
-
+
workJob.setAccountId(account.getId());
workJob.setUserId(user.getId());
workJob.setVmType(vm.getType());
workJob.setVmInstanceId(vm.getId());
-
+
// save work context info (there are some duplications)
VmWorkMigrateWithStorage workInfo = new VmWorkMigrateWithStorage(user.getId(), account.getId(), vm.getId(),
VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, srcHostId, destHostId, volumeToPool);
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-
- _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+
+ _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
-
+
final long jobId = (Long)context.getContextParameter("jobId");
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-
+
return new VmStateSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"),
VirtualMachine.PowerState.PowerOn, vm.getId(), destHostId);
}
-
+
public Outcome<VirtualMachine> migrateVmForScaleThroughJobQueue(
final String vmUuid, final long srcHostId, final DeployDestination dest, final Long newSvcOfferingId) {
-
+
final CallContext context = CallContext.current();
final User user = context.getCallingUser();
final Account account = context.getCallingAccount();
@@ -4402,50 +4404,50 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
Transaction.execute(new TransactionCallbackNoReturn () {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
-
+
_vmDao.lockRow(vm.getId(), true);
-
+
List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
VirtualMachine.Type.Instance, vm.getId(),
VmWorkMigrateForScale.class.getName());
-
+
VmWorkJobVO workJob = null;
if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
assert (pendingWorkJobs.size() == 1);
workJob = pendingWorkJobs.get(0);
} else {
-
+
workJob = new VmWorkJobVO(context.getContextId());
-
- workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+
+ workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
workJob.setCmd(VmWorkMigrate.class.getName());
-
+
workJob.setAccountId(account.getId());
workJob.setUserId(user.getId());
workJob.setVmType(vm.getType());
workJob.setVmInstanceId(vm.getId());
-
+
// save work context info (there are some duplications)
VmWorkMigrateForScale workInfo = new VmWorkMigrateForScale(user.getId(), account.getId(), vm.getId(),
VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, srcHostId, dest, newSvcOfferingId);
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-
- _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+
+ _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
-
+
final long jobId = (Long)context.getContextParameter("jobId");
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-
+
return new VmJobSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"), vm.getId());
}
-
+
public Outcome<VirtualMachine> migrateVmStorageThroughJobQueue(
final String vmUuid, final StoragePool destPool) {
-
+
final CallContext context = CallContext.current();
final User user = context.getCallingUser();
final Account account = context.getCallingAccount();
@@ -4455,50 +4457,50 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
Transaction.execute(new TransactionCallbackNoReturn () {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
-
+
_vmDao.lockRow(vm.getId(), true);
-
+
List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
VirtualMachine.Type.Instance, vm.getId(),
VmWorkStorageMigration.class.getName());
-
+
VmWorkJobVO workJob = null;
if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
assert (pendingWorkJobs.size() == 1);
workJob = pendingWorkJobs.get(0);
} else {
-
+
workJob = new VmWorkJobVO(context.getContextId());
-
- workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+
+ workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
workJob.setCmd(VmWorkStorageMigration.class.getName());
-
+
workJob.setAccountId(account.getId());
workJob.setUserId(user.getId());
workJob.setVmType(vm.getType());
workJob.setVmInstanceId(vm.getId());
-
+
// save work context info (there are some duplications)
VmWorkStorageMigration workInfo = new VmWorkStorageMigration(user.getId(), account.getId(), vm.getId(),
VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, destPool);
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-
- _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+
+ _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
-
+
final long jobId = (Long)context.getContextParameter("jobId");
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-
+
return new VmJobSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"), vm.getId());
}
-
+
public Outcome<VirtualMachine> addVmToNetworkThroughJobQueue(
final VirtualMachine vm, final Network network, final NicProfile requested) {
-
+
final CallContext context = CallContext.current();
final User user = context.getCallingUser();
final Account account = context.getCallingAccount();
@@ -4506,50 +4508,50 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
Transaction.execute(new TransactionCallbackNoReturn () {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
-
+
_vmDao.lockRow(vm.getId(), true);
-
+
List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
VirtualMachine.Type.Instance, vm.getId(),
VmWorkAddVmToNetwork.class.getName());
-
+
VmWorkJobVO workJob = null;
if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
assert (pendingWorkJobs.size() == 1);
workJob = pendingWorkJobs.get(0);
} else {
-
+
workJob = new VmWorkJobVO(context.getContextId());
-
- workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+
+ workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
workJob.setCmd(VmWorkAddVmToNetwork.class.getName());
-
+
workJob.setAccountId(account.getId());
workJob.setUserId(user.getId());
workJob.setVmType(vm.getType());
workJob.setVmInstanceId(vm.getId());
-
+
// save work context info (there are some duplications)
VmWorkAddVmToNetwork workInfo = new VmWorkAddVmToNetwork(user.getId(), account.getId(), vm.getId(),
VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, network, requested);
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-
- _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+
+ _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
-
+
final long jobId = (Long)context.getContextParameter("jobId");
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-
+
return new VmJobSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"), vm.getId());
}
-
+
public Outcome<VirtualMachine> removeNicFromVmThroughJobQueue(
final VirtualMachine vm, final Nic nic) {
-
+
final CallContext context = CallContext.current();
final User user = context.getCallingUser();
final Account account = context.getCallingAccount();
@@ -4557,50 +4559,50 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
Transaction.execute(new TransactionCallbackNoReturn () {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
-
+
_vmDao.lockRow(vm.getId(), true);
-
+
List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
VirtualMachine.Type.Instance, vm.getId(),
VmWorkRemoveNicFromVm.class.getName());
-
+
VmWorkJobVO workJob = null;
if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
assert (pendingWorkJobs.size() == 1);
workJob = pendingWorkJobs.get(0);
} else {
-
+
workJob = new VmWorkJobVO(context.getContextId());
-
- workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+
+ workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
workJob.setCmd(VmWorkRemoveNicFromVm.class.getName());
-
+
workJob.setAccountId(account.getId());
workJob.setUserId(user.getId());
workJob.setVmType(vm.getType());
workJob.setVmInstanceId(vm.getId());
-
+
// save work context info (there are some duplications)
VmWorkRemoveNicFromVm workInfo = new VmWorkRemoveNicFromVm(user.getId(), account.getId(), vm.getId(),
VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, nic);
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-
- _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+
+ _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
-
+
final long jobId = (Long)context.getContextParameter("jobId");
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-
+
return new VmJobSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"), vm.getId());
}
public Outcome<VirtualMachine> removeVmFromNetworkThroughJobQueue(
final VirtualMachine vm, final Network network, final URI broadcastUri) {
-
+
final CallContext context = CallContext.current();
final User user = context.getCallingUser();
final Account account = context.getCallingAccount();
@@ -4608,50 +4610,50 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
Transaction.execute(new TransactionCallbackNoReturn () {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
-
+
_vmDao.lockRow(vm.getId(), true);
-
+
List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
VirtualMachine.Type.Instance, vm.getId(),
VmWorkRemoveVmFromNetwork.class.getName());
-
+
VmWorkJobVO workJob = null;
if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
assert (pendingWorkJobs.size() == 1);
workJob = pendingWorkJobs.get(0);
} else {
-
+
workJob = new VmWorkJobVO(context.getContextId());
-
- workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+
+ workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
workJob.setCmd(VmWorkRemoveVmFromNetwork.class.getName());
-
+
workJob.setAccountId(account.getId());
workJob.setUserId(user.getId());
workJob.setVmType(vm.getType());
workJob.setVmInstanceId(vm.getId());
-
+
// save work context info (there are some duplications)
VmWorkRemoveVmFromNetwork workInfo = new VmWorkRemoveVmFromNetwork(user.getId(), account.getId(), vm.getId(),
VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, network, broadcastUri);
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-
- _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+
+ _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
-
+
final long jobId = (Long)context.getContextParameter("jobId");
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-
+
return new VmJobSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"), vm.getId());
}
-
+
public Outcome<VirtualMachine> reconfigureVmThroughJobQueue(
final String vmUuid, final ServiceOffering oldServiceOffering, final boolean reconfiguringOnExistingHost) {
-
+
final CallContext context = CallContext.current();
final User user = context.getCallingUser();
final Account account = context.getCallingAccount();
@@ -4661,47 +4663,47 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
Transaction.execute(new TransactionCallbackNoReturn () {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
-
+
_vmDao.lockRow(vm.getId(), true);
-
+
List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
VirtualMachine.Type.Instance, vm.getId(),
VmWorkReconfigure.class.getName());
-
+
VmWorkJobVO workJob = null;
if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
assert (pendingWorkJobs.size() == 1);
workJob = pendingWorkJobs.get(0);
} else {
-
+
workJob = new VmWorkJobVO(context.getContextId());
-
- workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+
+ workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
workJob.setCmd(VmWorkReconfigure.class.getName());
-
+
workJob.setAccountId(account.getId());
workJob.setUserId(user.getId());
workJob.setVmType(vm.getType());
workJob.setVmInstanceId(vm.getId());
-
+
// save work context info (there are some duplications)
VmWorkReconfigure workInfo = new VmWorkReconfigure(user.getId(), account.getId(), vm.getId(),
VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, oldServiceOffering, reconfiguringOnExistingHost);
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-
- _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+
+ _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
}
context.putContextParameter("workJob", workJob);
context.putContextParameter("jobId", new Long(workJob.getId()));
}
});
-
+
final long jobId = (Long)context.getContextParameter("jobId");
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-
+
return new VmJobSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"), vm.getId());
}
-
+
@Override
public Pair<JobInfo.Status, String> handleVmWorkJob(AsyncJob job, VmWork work) throws Exception {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ed2125ec/engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java b/engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java
index 00eb1ed..2ad548e 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java
@@ -36,10 +36,6 @@ import com.cloud.vm.dao.VMInstanceDao;
public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatcher {
private static final Logger s_logger = Logger.getLogger(VmWorkJobDispatcher.class);
- public static final String VM_WORK_QUEUE = "VmWorkJobQueue";
- public static final String VM_WORK_JOB_DISPATCHER = "VmWorkJobDispatcher";
- public static final String VM_WORK_JOB_WAKEUP_DISPATCHER = "VmWorkJobWakeupDispatcher";
-
@Inject private VirtualMachineManagerImpl _vmMgr;
@Inject private AsyncJobManager _asyncJobMgr;
@Inject private VMInstanceDao _instanceDao;
@@ -103,79 +99,6 @@ public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatch
Pair<JobInfo.Status, String> result = handler.handleVmWorkJob(job, work);
_asyncJobMgr.completeAsyncJob(job.getId(), result.first(), 0, result.second());
-/*
- VMInstanceVO vm = _instanceDao.findById(work.getVmId());
- if (vm == null) {
- s_logger.info("Unable to find vm " + work.getVmId());
- }
- assert(vm != null);
- if(work instanceof VmWorkStart) {
- VmWorkStart workStart = (VmWorkStart)work;
- _vmMgr.orchestrateStart(vm.getUuid(), workStart.getParams(), workStart.getPlan());
- _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
- } else if(work instanceof VmWorkStop) {
- VmWorkStop workStop = (VmWorkStop)work;
- _vmMgr.orchestrateStop(vm.getUuid(), workStop.isCleanup());
- _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
- } else if(work instanceof VmWorkMigrate) {
- VmWorkMigrate workMigrate = (VmWorkMigrate)work;
- _vmMgr.orchestrateMigrate(vm.getUuid(), workMigrate.getSrcHostId(), workMigrate.getDeployDestination());
- _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
- } else if(work instanceof VmWorkMigrateWithStorage) {
- VmWorkMigrateWithStorage workMigrateWithStorage = (VmWorkMigrateWithStorage)work;
- _vmMgr.orchestrateMigrateWithStorage(vm.getUuid(),
- workMigrateWithStorage.getSrcHostId(),
- workMigrateWithStorage.getDestHostId(),
- workMigrateWithStorage.getVolumeToPool());
- _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
- } else if(work instanceof VmWorkMigrateForScale) {
- VmWorkMigrateForScale workMigrateForScale = (VmWorkMigrateForScale)work;
- _vmMgr.orchestrateMigrateForScale(vm.getUuid(),
- workMigrateForScale.getSrcHostId(),
- workMigrateForScale.getDeployDestination(),
- workMigrateForScale.getNewServiceOfferringId());
- _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
- } else if(work instanceof VmWorkReboot) {
- VmWorkReboot workReboot = (VmWorkReboot)work;
- _vmMgr.orchestrateReboot(vm.getUuid(), workReboot.getParams());
- _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
- } else if(work instanceof VmWorkAddVmToNetwork) {
- VmWorkAddVmToNetwork workAddVmToNetwork = (VmWorkAddVmToNetwork)work;
- NicProfile nic = _vmMgr.orchestrateAddVmToNetwork(vm, workAddVmToNetwork.getNetwork(),
- workAddVmToNetwork.getRequestedNicProfile());
- _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0,
- JobSerializerHelper.toObjectSerializedString(nic));
- } else if(work instanceof VmWorkRemoveNicFromVm) {
- VmWorkRemoveNicFromVm workRemoveNicFromVm = (VmWorkRemoveNicFromVm)work;
- boolean result = _vmMgr.orchestrateRemoveNicFromVm(vm, workRemoveNicFromVm.getNic());
- _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0,
- JobSerializerHelper.toObjectSerializedString(new Boolean(result)));
- } else if(work instanceof VmWorkRemoveVmFromNetwork) {
- VmWorkRemoveVmFromNetwork workRemoveVmFromNetwork = (VmWorkRemoveVmFromNetwork)work;
- boolean result = _vmMgr.orchestrateRemoveVmFromNetwork(vm,
- workRemoveVmFromNetwork.getNetwork(), workRemoveVmFromNetwork.getBroadcastUri());
- _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0,
- JobSerializerHelper.toObjectSerializedString(new Boolean(result)));
- } else if(work instanceof VmWorkReconfigure) {
- VmWorkReconfigure workReconfigure = (VmWorkReconfigure)work;
- _vmMgr.reConfigureVm(vm.getUuid(), workReconfigure.getNewServiceOffering(),
- workReconfigure.isSameHost());
- _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
- } else if(work instanceof VmWorkStorageMigration) {
- VmWorkStorageMigration workStorageMigration = (VmWorkStorageMigration)work;
- _vmMgr.orchestrateStorageMigration(vm.getUuid(), workStorageMigration.getDestStoragePool());
- _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
- } else {
- assert(false);
- s_logger.error("Unhandled VM work command: " + job.getCmd());
-
- RuntimeException e = new RuntimeException("Unsupported VM work command: " + job.getCmd());
- String exceptionJson = JobSerializerHelper.toSerializedString(e);
- s_logger.error("Serialize exception object into json: " + exceptionJson);
- _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, 0, exceptionJson);
- }
- */
-
} catch(Throwable e) {
s_logger.error("Unable to complete " + job, e);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ed2125ec/engine/orchestration/src/com/cloud/vm/VmWorkJobHandler.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkJobHandler.java b/engine/orchestration/src/com/cloud/vm/VmWorkJobHandler.java
deleted file mode 100644
index 6ab1bbc..0000000
--- a/engine/orchestration/src/com/cloud/vm/VmWorkJobHandler.java
+++ /dev/null
@@ -1,26 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.vm;
-
-import org.apache.cloudstack.framework.jobs.AsyncJob;
-import org.apache.cloudstack.jobs.JobInfo;
-
-import com.cloud.utils.Pair;
-
-public interface VmWorkJobHandler {
- Pair<JobInfo.Status, String> handleVmWorkJob(AsyncJob job, VmWork work) throws Exception;
-}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ed2125ec/engine/orchestration/src/com/cloud/vm/VmWorkSerializer.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkSerializer.java b/engine/orchestration/src/com/cloud/vm/VmWorkSerializer.java
deleted file mode 100644
index 9a1aaac..0000000
--- a/engine/orchestration/src/com/cloud/vm/VmWorkSerializer.java
+++ /dev/null
@@ -1,75 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.vm;
-
-import java.lang.reflect.Type;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParseException;
-
-public class VmWorkSerializer {
- static class StringMapTypeAdapter implements JsonDeserializer<Map> {
-
- @Override
- public Map deserialize(JsonElement src, Type srcType, JsonDeserializationContext context) throws JsonParseException {
-
- Map<String, String> obj = new HashMap<String, String>();
- JsonObject json = src.getAsJsonObject();
-
- for (Entry<String, JsonElement> entry : json.entrySet()) {
- obj.put(entry.getKey(), entry.getValue().getAsString());
- }
-
- return obj;
- }
- }
-
- protected static Gson s_gson;
- static {
- GsonBuilder gBuilder = new GsonBuilder();
- gBuilder.setVersion(1.3);
- gBuilder.registerTypeAdapter(Map.class, new StringMapTypeAdapter());
- s_gson = gBuilder.create();
- }
-
- public static String serialize(VmWork work) {
- // TODO: there are way many generics, too tedious to get serialization work under GSON
- // use java binary serialization instead
- //
- return JobSerializerHelper.toObjectSerializedString(work);
- // return s_gson.toJson(work);
- }
-
- public static <T extends VmWork> T deserialize(Class<?> clazz, String workInJsonText) {
- // TODO: there are way many generics, too tedious to get serialization work under GSON
- // use java binary serialization instead
- //
- return (T)JobSerializerHelper.fromObjectSerializedString(workInJsonText);
- // return (T)s_gson.fromJson(workInJsonText, clazz);
- }
-}
-