Skip to content

Commit c75b004

Browse files
committed
CLOUDSTACK-5765: cleanup internal serialization and exception propagation issues
1 parent 5a8ea8a commit c75b004

14 files changed

Lines changed: 180 additions & 107 deletions

File tree

‎api/src/com/cloud/deploy/DeployDestination.java‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package com.cloud.deploy;
1818

19+
import java.io.Serializable;
1920
import java.util.Map;
2021

2122
import com.cloud.dc.DataCenter;
@@ -26,7 +27,9 @@
2627
import com.cloud.storage.Volume;
2728
import com.cloud.utils.NumbersUtil;
2829

29-
public class DeployDestination {
30+
public class DeployDestination implements Serializable {
31+
private static final long serialVersionUID = 7113840781939014695L;
32+
3033
DataCenter _dc;
3134
Pod _pod;
3235
Cluster _cluster;
@@ -76,28 +79,28 @@ public int hashCode() {
7679
@Override
7780
public boolean equals(Object obj) {
7881
DeployDestination that = (DeployDestination) obj;
79-
if (this._dc == null || that._dc == null) {
82+
if (_dc == null || that._dc == null) {
8083
return false;
8184
}
82-
if (this._dc.getId() != that._dc.getId()) {
85+
if (_dc.getId() != that._dc.getId()) {
8386
return false;
8487
}
85-
if (this._pod == null || that._pod == null) {
88+
if (_pod == null || that._pod == null) {
8689
return false;
8790
}
88-
if (this._pod.getId() != that._pod.getId()) {
91+
if (_pod.getId() != that._pod.getId()) {
8992
return false;
9093
}
91-
if (this._cluster == null || that._cluster == null) {
94+
if (_cluster == null || that._cluster == null) {
9295
return false;
9396
}
94-
if (this._cluster.getId() != that._cluster.getId()) {
97+
if (_cluster.getId() != that._cluster.getId()) {
9598
return false;
9699
}
97-
if (this._host == null || that._host == null) {
100+
if (_host == null || that._host == null) {
98101
return false;
99102
}
100-
return this._host.getId() == that._host.getId();
103+
return _host.getId() == that._host.getId();
101104
}
102105

103106
@Override

‎api/src/com/cloud/deploy/DeploymentPlanner.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package com.cloud.deploy;
1818

19+
import java.io.Serializable;
1920
import java.util.Collection;
2021
import java.util.HashSet;
2122
import java.util.Set;
@@ -93,7 +94,9 @@ public enum PlannerResourceUsage {
9394
Shared, Dedicated;
9495
}
9596

96-
public static class ExcludeList {
97+
public static class ExcludeList implements Serializable {
98+
private static final long serialVersionUID = -482175549460148301L;
99+
97100
private Set<Long> _dcIds;
98101
private Set<Long> _podIds;
99102
private Set<Long> _clusterIds;

‎api/src/com/cloud/exception/CloudException.java‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
*/
2828

2929
public class CloudException extends Exception {
30+
private static final long serialVersionUID = 8784427323859682503L;
3031

31-
// This holds a list of uuids and their names. Add uuid:fieldname pairs
32+
// This holds a list of uuids and their names. Add uuid:fieldname pairs
3233
protected ArrayList<String> idList = new ArrayList<String>();
3334

3435
protected Integer csErrorCode;
@@ -43,8 +44,6 @@ public CloudException(String message, Throwable cause) {
4344
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
4445
}
4546

46-
47-
4847
public CloudException() {
4948
super();
5049
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
@@ -60,10 +59,10 @@ public ArrayList<String> getIdProxyList() {
6059
}
6160

6261
public void setCSErrorCode(int cserrcode) {
63-
this.csErrorCode = cserrcode;
62+
csErrorCode = cserrcode;
6463
}
6564

6665
public int getCSErrorCode() {
67-
return this.csErrorCode;
66+
return csErrorCode;
6867
}
6968
}

‎api/src/com/cloud/exception/OperationTimedoutException.java‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,21 @@
2424
*/
2525
public class OperationTimedoutException extends CloudException {
2626
private static final long serialVersionUID = SerialVersionUID.OperationTimedoutException;
27-
27+
2828
long _agentId;
2929
long _seqId;
3030
int _time;
31-
Command[] _cmds;
31+
32+
// TODO
33+
// I did a reference search on usage of getCommands() and found none
34+
//
35+
// to prevent serialization problems across boundaries, I'm disabling serialization of _cmds here
36+
// getCommands() will still be available within the same serialization boundary, but it will be lost
37+
// when exception is propagated across job boundaries.
38+
//
39+
transient Command[] _cmds;
3240
boolean _isActive;
33-
41+
3442
public OperationTimedoutException(Command[] cmds, long agentId, long seqId, int time, boolean isActive) {
3543
super("Commands " + seqId + " to Host " + agentId + " timed out after " + time);
3644
_agentId = agentId;
@@ -39,23 +47,23 @@ public OperationTimedoutException(Command[] cmds, long agentId, long seqId, int
3947
_cmds = cmds;
4048
_isActive = isActive;
4149
}
42-
50+
4351
public long getAgentId() {
4452
return _agentId;
4553
}
46-
54+
4755
public long getSequenceId() {
4856
return _seqId;
4957
}
50-
58+
5159
public int getWaitTime() {
5260
return _time;
5361
}
54-
62+
5563
public Command[] getCommands() {
5664
return _cmds;
5765
}
58-
66+
5967
public boolean isActive() {
6068
return _isActive;
6169
}

‎engine/api/src/com/cloud/vm/VirtualMachineManager.java‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.LinkedHashMap;
2121
import java.util.Map;
2222

23+
import org.apache.cloudstack.framework.config.ConfigKey;
24+
2325
import com.cloud.agent.api.to.NicTO;
2426
import com.cloud.agent.api.to.VirtualMachineTO;
2527
import com.cloud.deploy.DeployDestination;
@@ -41,7 +43,6 @@
4143
import com.cloud.utils.Pair;
4244
import com.cloud.utils.component.Manager;
4345
import com.cloud.utils.fsm.NoTransitionException;
44-
import org.apache.cloudstack.framework.config.ConfigKey;
4546

4647
/**
4748
* Manages allocating resources to vms.
@@ -56,12 +57,12 @@ public interface VirtualMachineManager extends Manager {
5657
public interface Topics {
5758
public static final String VM_POWER_STATE = "vm.powerstate";
5859
}
59-
60+
6061
/**
6162
* Allocates a new virtual machine instance in the CloudStack DB. This
6263
* orchestrates the creation of all virtual resources needed in CloudStack
6364
* DB to bring up a VM.
64-
*
65+
*
6566
* @param vmInstanceName Instance name of the VM. This name uniquely
6667
* a VM in CloudStack's deploy environment. The caller gets to
6768
* define this VM but it must be unqiue for all of CloudStack.
@@ -121,23 +122,23 @@ void orchestrateStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> pa
121122
void migrateAway(String vmUuid, long hostId, DeploymentPlanner planner) throws InsufficientServerCapacityException;
122123

123124
void migrate(String vmUuid, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException;
124-
125+
125126
void migrateWithStorage(String vmUuid, long srcId, long destId, Map<Volume, StoragePool> volumeToPool) throws ResourceUnavailableException, ConcurrentOperationException;
126-
127+
127128
void reboot(String vmUuid, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException;
128129

129130
void advanceReboot(String vmUuid, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException,
130131
ConcurrentOperationException, OperationTimedoutException;
131132

132133
/**
133134
* Check to see if a virtual machine can be upgraded to the given service offering
134-
*
135+
*
135136
* @param vm
136137
* @param offering
137138
* @return true if the host can handle the upgrade, false otherwise
138139
*/
139140
boolean isVirtualMachineUpgradable(final VirtualMachine vm, final ServiceOffering offering);
140-
141+
141142
VirtualMachine findById(long vmId);
142143

143144
void storageMigration(String vmUuid, StoragePool storagePoolId);
@@ -166,7 +167,7 @@ void advanceReboot(String vmUuid, Map<VirtualMachineProfile.Param, Object> param
166167
*/
167168
NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException,
168169
ResourceUnavailableException, InsufficientCapacityException;
169-
170+
170171
/**
171172
* @param vm
172173
* @param nic
@@ -185,7 +186,7 @@ NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile request
185186
* @throws ConcurrentOperationException
186187
*/
187188
boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException;
188-
189+
189190
/**
190191
* @param nic
191192
* @param hypervisorType
@@ -200,8 +201,9 @@ NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile request
200201
*/
201202
VirtualMachineTO toVmTO(VirtualMachineProfile profile);
202203

203-
VirtualMachine reConfigureVm(String vmUuid, ServiceOffering newServiceOffering, boolean sameHost) throws ResourceUnavailableException, ConcurrentOperationException;
204-
204+
VirtualMachine reConfigureVm(String vmUuid, ServiceOffering newServiceOffering, boolean sameHost) throws ResourceUnavailableException, ConcurrentOperationException,
205+
InsufficientServerCapacityException;
206+
205207
void findHostAndMigrate(String vmUuid, Long newSvcOfferingId, DeploymentPlanner.ExcludeList excludeHostList) throws InsufficientCapacityException,
206208
ConcurrentOperationException, ResourceUnavailableException;
207209

‎engine/components-api/src/com/cloud/vm/VmWorkJobHandlerProxy.java‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,18 @@ public Pair<JobInfo.Status, String> handleVmWorkJob(VmWork work) throws Exceptio
116116

117117
// legacy CloudStack code relies on checked exception for error handling
118118
// we need to re-throw the real exception here
119-
if (e.getCause() != null && e.getCause() instanceof Exception)
119+
if (e.getCause() != null && e.getCause() instanceof Exception) {
120+
s_logger.info("Rethrow exception " + e.getCause());
120121
throw (Exception)e.getCause();
122+
}
121123

122124
throw e;
123125
}
124126
} else {
125127
s_logger.error("Unable to find handler for VM work job: " + work.getClass().getName() + _gsonLogger.toJson(work));
126128

127-
RuntimeException e = new RuntimeException("Unsupported VM work job: " + work.getClass().getName() + _gsonLogger.toJson(work));
128-
String exceptionJson = JobSerializerHelper.toSerializedString(e);
129-
130-
s_logger.error("Serialize exception object into json: " + exceptionJson);
131-
return new Pair<JobInfo.Status, String>(JobInfo.Status.FAILED, exceptionJson);
129+
RuntimeException ex = new RuntimeException("Unable to find handler for VM work job: " + work.getClass().getName());
130+
return new Pair<JobInfo.Status, String>(JobInfo.Status.FAILED, JobSerializerHelper.toObjectSerializedString(ex));
132131
}
133132
}
134133
}

‎engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java‎

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@
4040
import javax.inject.Inject;
4141
import javax.naming.ConfigurationException;
4242

43-
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
4443
import org.apache.log4j.Logger;
4544

4645
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
4746
import org.apache.cloudstack.context.CallContext;
4847
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
4948
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
5049
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
50+
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
5151
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
5252
import org.apache.cloudstack.framework.config.ConfigDepot;
5353
import org.apache.cloudstack.framework.config.ConfigKey;
@@ -336,7 +336,7 @@ public void setHostAllocators(List<HostAllocator> _hostAllocators) {
336336

337337
// TODO, remove it after transient period is over
338338
static final ConfigKey<Boolean> VmJobEnabled = new ConfigKey<Boolean>("Advanced",
339-
Boolean.class, "vm.job.enabled", "true",
339+
Boolean.class, "vm.job.enabled", "false",
340340
"True to enable new VM sync model. false to use the old way", false);
341341

342342
static final ConfigKey<Long> VmJobCheckInterval = new ConfigKey<Long>("Advanced",
@@ -3698,7 +3698,7 @@ public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, Reserv
36983698
@Override
36993699
public VMInstanceVO reConfigureVm(String vmUuid, ServiceOffering oldServiceOffering,
37003700
boolean reconfiguringOnExistingHost)
3701-
throws ResourceUnavailableException, ConcurrentOperationException {
3701+
throws ResourceUnavailableException, InsufficientServerCapacityException, ConcurrentOperationException {
37023702

37033703
AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
37043704
if (!VmJobEnabled.value() || jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
@@ -3716,20 +3716,21 @@ public VMInstanceVO reConfigureVm(String vmUuid, ServiceOffering oldServiceOffer
37163716
throw new RuntimeException("Execution excetion", e);
37173717
}
37183718

3719-
AsyncJobVO jobVo = _entityMgr.findById(AsyncJobVO.class, outcome.getJob().getId());
3720-
if(jobVo.getResultCode() == JobInfo.Status.SUCCEEDED.ordinal()) {
3721-
return _entityMgr.findById(VMInstanceVO.class, vm.getId());
3722-
} else {
3723-
Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
3724-
if (jobResult != null) {
3725-
if (jobResult instanceof ResourceUnavailableException)
3726-
throw (ResourceUnavailableException)jobResult;
3727-
else if (jobResult instanceof ConcurrentOperationException)
3728-
throw (ConcurrentOperationException)jobResult;
3729-
}
3719+
Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
3720+
if (jobResult != null) {
3721+
if (jobResult instanceof ResourceUnavailableException)
3722+
throw (ResourceUnavailableException)jobResult;
3723+
else if (jobResult instanceof ConcurrentOperationException)
3724+
throw (ConcurrentOperationException)jobResult;
3725+
else if (jobResult instanceof InsufficientServerCapacityException)
3726+
throw (InsufficientServerCapacityException)jobResult;
3727+
else if (jobResult instanceof Throwable) {
3728+
s_logger.error("Unhandled exception", (Throwable)jobResult);
3729+
throw new RuntimeException("Unhandled exception", (Throwable)jobResult);
3730+
}
3731+
}
37303732

3731-
throw new RuntimeException("Failed with un-handled exception");
3732-
}
3733+
return (VMInstanceVO)vm;
37333734
}
37343735
}
37353736

@@ -4668,7 +4669,7 @@ public Object[] doInTransaction(TransactionStatus status) {
46684669
}
46694670

46704671
public Outcome<VirtualMachine> reconfigureVmThroughJobQueue(
4671-
final String vmUuid, final ServiceOffering oldServiceOffering, final boolean reconfiguringOnExistingHost) {
4672+
final String vmUuid, final ServiceOffering newServiceOffering, final boolean reconfiguringOnExistingHost) {
46724673

46734674
final CallContext context = CallContext.current();
46744675
final User user = context.getCallingUser();
@@ -4705,7 +4706,7 @@ public Object[] doInTransaction(TransactionStatus status) {
47054706

47064707
// save work context info (there are some duplications)
47074708
VmWorkReconfigure workInfo = new VmWorkReconfigure(user.getId(), account.getId(), vm.getId(),
4708-
VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, oldServiceOffering, reconfiguringOnExistingHost);
4709+
VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, newServiceOffering.getId(), reconfiguringOnExistingHost);
47094710
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
47104711

47114712
_jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
@@ -4833,7 +4834,10 @@ private Pair<JobInfo.Status, String> orchestrateReconfigure(VmWorkReconfigure wo
48334834
s_logger.info("Unable to find vm " + work.getVmId());
48344835
}
48354836
assert (vm != null);
4836-
reConfigureVm(vm.getUuid(), work.getNewServiceOffering(),
4837+
4838+
ServiceOffering newServiceOffering = _offeringDao.findById(vm.getId(), work.getNewServiceOfferingId());
4839+
4840+
reConfigureVm(vm.getUuid(), newServiceOffering,
48374841
work.isSameHost());
48384842
return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, null);
48394843
}

‎engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.cloudstack.framework.jobs.AsyncJob;
2727
import org.apache.cloudstack.framework.jobs.AsyncJobDispatcher;
2828
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
29-
import org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper;
3029
import org.apache.cloudstack.jobs.JobInfo;
3130

3231
import com.cloud.utils.Pair;
@@ -104,9 +103,8 @@ public void runJob(AsyncJob job) {
104103
} catch(Throwable e) {
105104
s_logger.error("Unable to complete " + job + ", job origin:" + job.getRelated(), e);
106105

107-
String exceptionJson = JobSerializerHelper.toSerializedString(e);
108-
s_logger.info("Serialize exception object into json: " + exceptionJson + ", job origin: " + job.getRelated());
109-
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, 0, exceptionJson);
106+
RuntimeException ex = new RuntimeException("Job failed due to exception " + e.getMessage());
107+
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, 0, _asyncJobMgr.marshallResultObject(ex));
110108
} finally {
111109
CallContext.unregister();
112110
}

0 commit comments

Comments
 (0)