mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-5672: Fix VM work job serialization issues in Add/Remove nic
This commit is contained in:
parent
87381d4236
commit
0965adb003
@ -16,6 +16,7 @@
|
||||
// under the License.
|
||||
package com.cloud.network;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -33,7 +34,7 @@ import com.cloud.utils.fsm.StateObject;
|
||||
/**
|
||||
* 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 {
|
||||
Shared, Isolated
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
// under the License.
|
||||
package com.cloud.vm;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
|
||||
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.vm.Nic.ReservationStrategy;
|
||||
|
||||
public class NicProfile implements InternalIdentity {
|
||||
public class NicProfile implements InternalIdentity, Serializable {
|
||||
private static final long serialVersionUID = 4997005771736090304L;
|
||||
|
||||
long id;
|
||||
long networkId;
|
||||
BroadcastDomainType broadcastType;
|
||||
|
||||
@ -58,7 +58,6 @@ import org.apache.cloudstack.framework.jobs.AsyncJobManager;
|
||||
import org.apache.cloudstack.framework.jobs.Outcome;
|
||||
import org.apache.cloudstack.framework.jobs.dao.VmWorkJobDao;
|
||||
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.VmWorkJobVO;
|
||||
import org.apache.cloudstack.framework.messagebus.MessageBus;
|
||||
@ -3097,25 +3096,21 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
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 {
|
||||
Object jobException = _jobMgr.unmarshallResultObject(outcome.getJob());
|
||||
if (jobException != null) {
|
||||
if (jobException instanceof ResourceUnavailableException)
|
||||
throw (ResourceUnavailableException)jobException;
|
||||
else if (jobException instanceof ConcurrentOperationException)
|
||||
throw (ConcurrentOperationException)jobException;
|
||||
else if (jobException instanceof InsufficientCapacityException)
|
||||
throw (InsufficientCapacityException)jobException;
|
||||
else if (jobException instanceof RuntimeException)
|
||||
throw (RuntimeException)jobException;
|
||||
}
|
||||
throw new RuntimeException("Job failed with unhandled exception");
|
||||
Object jobException = _jobMgr.unmarshallResultObject(outcome.getJob());
|
||||
if (jobException != null) {
|
||||
if (jobException instanceof ResourceUnavailableException)
|
||||
throw (ResourceUnavailableException)jobException;
|
||||
else if (jobException instanceof ConcurrentOperationException)
|
||||
throw (ConcurrentOperationException)jobException;
|
||||
else if (jobException instanceof InsufficientCapacityException)
|
||||
throw (InsufficientCapacityException)jobException;
|
||||
else if (jobException instanceof RuntimeException)
|
||||
throw (RuntimeException)jobException;
|
||||
else if (jobException instanceof Long)
|
||||
return requested;
|
||||
}
|
||||
|
||||
throw new RuntimeException("Unexpected job execution result");
|
||||
}
|
||||
}
|
||||
|
||||
@ -3204,24 +3199,19 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
throw new RuntimeException("Execution excetion", e);
|
||||
}
|
||||
|
||||
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 {
|
||||
Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
|
||||
if (jobResult != null) {
|
||||
if (jobResult instanceof ResourceUnavailableException)
|
||||
throw (ResourceUnavailableException)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");
|
||||
Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
|
||||
if (jobResult != null) {
|
||||
if (jobResult instanceof ResourceUnavailableException)
|
||||
throw (ResourceUnavailableException)jobResult;
|
||||
else if (jobResult instanceof ConcurrentOperationException)
|
||||
throw (ConcurrentOperationException)jobResult;
|
||||
else if (jobResult instanceof RuntimeException)
|
||||
throw (RuntimeException)jobResult;
|
||||
else if (jobResult instanceof Boolean)
|
||||
return (Boolean)jobResult;
|
||||
}
|
||||
|
||||
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)
|
||||
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));
|
||||
|
||||
_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)
|
||||
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));
|
||||
|
||||
_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());
|
||||
}
|
||||
assert (vm != null);
|
||||
NicProfile nic = orchestrateAddVmToNetwork(vm, work.getNetwork(),
|
||||
|
||||
Network network = _networkDao.findById(work.getNetworkId());
|
||||
NicProfile nic = orchestrateAddVmToNetwork(vm, network,
|
||||
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 {
|
||||
@ -4779,7 +4772,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
s_logger.info("Unable to find vm " + work.getVmId());
|
||||
}
|
||||
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,
|
||||
_jobMgr.marshallResultObject(new Boolean(result)));
|
||||
}
|
||||
|
||||
@ -16,24 +16,22 @@
|
||||
// under the License.
|
||||
package com.cloud.vm;
|
||||
|
||||
import com.cloud.network.Network;
|
||||
|
||||
public class VmWorkAddVmToNetwork extends VmWork {
|
||||
private static final long serialVersionUID = 8861516006586736813L;
|
||||
|
||||
Network network;
|
||||
Long networkId;
|
||||
NicProfile requstedNicProfile;
|
||||
|
||||
public VmWorkAddVmToNetwork(long userId, long accountId, long vmId, String handlerName,
|
||||
Network network, NicProfile requested) {
|
||||
Long networkId, NicProfile requested) {
|
||||
super(userId, accountId, vmId, handlerName);
|
||||
|
||||
this.network = network;
|
||||
this.networkId = networkId;
|
||||
requstedNicProfile = requested;
|
||||
}
|
||||
|
||||
public Network getNetwork() {
|
||||
return network;
|
||||
public Long getNetworkId() {
|
||||
return networkId;
|
||||
}
|
||||
|
||||
public NicProfile getRequestedNicProfile() {
|
||||
|
||||
@ -19,15 +19,15 @@ package com.cloud.vm;
|
||||
public class VmWorkRemoveNicFromVm extends VmWork {
|
||||
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);
|
||||
|
||||
this.nic = nic;
|
||||
this.nicId = nicId;
|
||||
}
|
||||
|
||||
public Nic getNic() {
|
||||
return nic;
|
||||
public Long getNicId() {
|
||||
return nicId;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user