CLOUDSTACK-5672: Fix VM work job serialization issues in Add/Remove nic

This commit is contained in:
Kelven Yang 2014-01-03 17:20:09 -08:00
parent 87381d4236
commit 0965adb003
5 changed files with 51 additions and 55 deletions

View File

@ -16,6 +16,7 @@
// under the License. // under the License.
package com.cloud.network; package com.cloud.network;
import java.io.Serializable;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -33,7 +34,7 @@ import com.cloud.utils.fsm.StateObject;
/** /**
* owned by an account. * owned by an account.
*/ */
public interface Network extends ControlledEntity, StateObject<Network.State>, InternalIdentity, Identity { public interface Network extends ControlledEntity, StateObject<Network.State>, InternalIdentity, Identity, Serializable {
public enum GuestType { public enum GuestType {
Shared, Isolated Shared, Isolated

View File

@ -16,6 +16,7 @@
// under the License. // under the License.
package com.cloud.vm; package com.cloud.vm;
import java.io.Serializable;
import java.net.URI; import java.net.URI;
import org.apache.cloudstack.api.InternalIdentity; import org.apache.cloudstack.api.InternalIdentity;
@ -27,7 +28,9 @@ import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType; import com.cloud.network.Networks.TrafficType;
import com.cloud.vm.Nic.ReservationStrategy; import com.cloud.vm.Nic.ReservationStrategy;
public class NicProfile implements InternalIdentity { public class NicProfile implements InternalIdentity, Serializable {
private static final long serialVersionUID = 4997005771736090304L;
long id; long id;
long networkId; long networkId;
BroadcastDomainType broadcastType; BroadcastDomainType broadcastType;

View File

@ -58,7 +58,6 @@ import org.apache.cloudstack.framework.jobs.AsyncJobManager;
import org.apache.cloudstack.framework.jobs.Outcome; import org.apache.cloudstack.framework.jobs.Outcome;
import org.apache.cloudstack.framework.jobs.dao.VmWorkJobDao; import org.apache.cloudstack.framework.jobs.dao.VmWorkJobDao;
import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO; import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
import org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper;
import org.apache.cloudstack.framework.jobs.impl.OutcomeImpl; import org.apache.cloudstack.framework.jobs.impl.OutcomeImpl;
import org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO; import org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO;
import org.apache.cloudstack.framework.messagebus.MessageBus; import org.apache.cloudstack.framework.messagebus.MessageBus;
@ -3097,25 +3096,21 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
throw new RuntimeException("Execution excetion", e); throw new RuntimeException("Execution excetion", e);
} }
AsyncJobVO jobVo = _entityMgr.findById(AsyncJobVO.class, outcome.getJob().getId()); Object jobException = _jobMgr.unmarshallResultObject(outcome.getJob());
if (jobVo.getResultCode() == JobInfo.Status.SUCCEEDED.ordinal()) { if (jobException != null) {
if (jobException instanceof ResourceUnavailableException)
NicProfile nic = (NicProfile)JobSerializerHelper.fromObjectSerializedString(jobVo.getResult()); throw (ResourceUnavailableException)jobException;
return nic; else if (jobException instanceof ConcurrentOperationException)
} else { throw (ConcurrentOperationException)jobException;
Object jobException = _jobMgr.unmarshallResultObject(outcome.getJob()); else if (jobException instanceof InsufficientCapacityException)
if (jobException != null) { throw (InsufficientCapacityException)jobException;
if (jobException instanceof ResourceUnavailableException) else if (jobException instanceof RuntimeException)
throw (ResourceUnavailableException)jobException; throw (RuntimeException)jobException;
else if (jobException instanceof ConcurrentOperationException) else if (jobException instanceof Long)
throw (ConcurrentOperationException)jobException; return requested;
else if (jobException instanceof InsufficientCapacityException)
throw (InsufficientCapacityException)jobException;
else if (jobException instanceof RuntimeException)
throw (RuntimeException)jobException;
}
throw new RuntimeException("Job failed with unhandled exception");
} }
throw new RuntimeException("Unexpected job execution result");
} }
} }
@ -3204,24 +3199,19 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
throw new RuntimeException("Execution excetion", e); throw new RuntimeException("Execution excetion", e);
} }
AsyncJobVO jobVo = _entityMgr.findById(AsyncJobVO.class, outcome.getJob().getId()); Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
if (jobResult != null) {
if (jobVo.getResultCode() == JobInfo.Status.SUCCEEDED.ordinal()) { if (jobResult instanceof ResourceUnavailableException)
Boolean result = (Boolean)JobSerializerHelper.fromObjectSerializedString(jobVo.getResult()); throw (ResourceUnavailableException)jobResult;
return result; else if (jobResult instanceof ConcurrentOperationException)
} else { throw (ConcurrentOperationException)jobResult;
Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob()); else if (jobResult instanceof RuntimeException)
if (jobResult != null) { throw (RuntimeException)jobResult;
if (jobResult instanceof ResourceUnavailableException) else if (jobResult instanceof Boolean)
throw (ResourceUnavailableException)jobResult; return (Boolean)jobResult;
else if (jobResult instanceof ConcurrentOperationException)
throw (ConcurrentOperationException)jobResult;
else if (jobResult instanceof RuntimeException)
throw (RuntimeException)jobResult;
}
throw new RuntimeException("Job failed with un-handled exception");
} }
throw new RuntimeException("Job failed with un-handled exception");
} }
} }
@ -4529,7 +4519,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
// save work context info (there are some duplications) // save work context info (there are some duplications)
VmWorkAddVmToNetwork workInfo = new VmWorkAddVmToNetwork(user.getId(), account.getId(), vm.getId(), VmWorkAddVmToNetwork workInfo = new VmWorkAddVmToNetwork(user.getId(), account.getId(), vm.getId(),
VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, network, requested); VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, network.getId(), requested);
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo)); workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
_jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId()); _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
@ -4578,7 +4568,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
// save work context info (there are some duplications) // save work context info (there are some duplications)
VmWorkRemoveNicFromVm workInfo = new VmWorkRemoveNicFromVm(user.getId(), account.getId(), vm.getId(), VmWorkRemoveNicFromVm workInfo = new VmWorkRemoveNicFromVm(user.getId(), account.getId(), vm.getId(),
VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, nic); VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, nic.getId());
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo)); workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
_jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId()); _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
@ -4768,9 +4758,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
s_logger.info("Unable to find vm " + work.getVmId()); s_logger.info("Unable to find vm " + work.getVmId());
} }
assert (vm != null); assert (vm != null);
NicProfile nic = orchestrateAddVmToNetwork(vm, work.getNetwork(),
Network network = _networkDao.findById(work.getNetworkId());
NicProfile nic = orchestrateAddVmToNetwork(vm, network,
work.getRequestedNicProfile()); work.getRequestedNicProfile());
return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, _jobMgr.marshallResultObject(nic));
return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, _jobMgr.marshallResultObject(new Long(nic.getId())));
} }
private Pair<JobInfo.Status, String> orchestrateRemoveNicFromVm(VmWorkRemoveNicFromVm work) throws Exception { private Pair<JobInfo.Status, String> orchestrateRemoveNicFromVm(VmWorkRemoveNicFromVm work) throws Exception {
@ -4779,7 +4772,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
s_logger.info("Unable to find vm " + work.getVmId()); s_logger.info("Unable to find vm " + work.getVmId());
} }
assert (vm != null); assert (vm != null);
boolean result = orchestrateRemoveNicFromVm(vm, work.getNic()); NicVO nic = _entityMgr.findById(NicVO.class, work.getNicId());
boolean result = orchestrateRemoveNicFromVm(vm, nic);
return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED,
_jobMgr.marshallResultObject(new Boolean(result))); _jobMgr.marshallResultObject(new Boolean(result)));
} }

View File

@ -16,24 +16,22 @@
// under the License. // under the License.
package com.cloud.vm; package com.cloud.vm;
import com.cloud.network.Network;
public class VmWorkAddVmToNetwork extends VmWork { public class VmWorkAddVmToNetwork extends VmWork {
private static final long serialVersionUID = 8861516006586736813L; private static final long serialVersionUID = 8861516006586736813L;
Network network; Long networkId;
NicProfile requstedNicProfile; NicProfile requstedNicProfile;
public VmWorkAddVmToNetwork(long userId, long accountId, long vmId, String handlerName, public VmWorkAddVmToNetwork(long userId, long accountId, long vmId, String handlerName,
Network network, NicProfile requested) { Long networkId, NicProfile requested) {
super(userId, accountId, vmId, handlerName); super(userId, accountId, vmId, handlerName);
this.network = network; this.networkId = networkId;
requstedNicProfile = requested; requstedNicProfile = requested;
} }
public Network getNetwork() { public Long getNetworkId() {
return network; return networkId;
} }
public NicProfile getRequestedNicProfile() { public NicProfile getRequestedNicProfile() {

View File

@ -19,15 +19,15 @@ package com.cloud.vm;
public class VmWorkRemoveNicFromVm extends VmWork { public class VmWorkRemoveNicFromVm extends VmWork {
private static final long serialVersionUID = -4265657031064437923L; private static final long serialVersionUID = -4265657031064437923L;
Nic nic; Long nicId;
public VmWorkRemoveNicFromVm(long userId, long accountId, long vmId, String handlerName, Nic nic) { public VmWorkRemoveNicFromVm(long userId, long accountId, long vmId, String handlerName, Long nicId) {
super(userId, accountId, vmId, handlerName); super(userId, accountId, vmId, handlerName);
this.nic = nic; this.nicId = nicId;
} }
public Nic getNic() { public Long getNicId() {
return nic; return nicId;
} }
} }