mirror of https://github.com/apache/cloudstack.git
bug 5927: incremental checkin
This commit is contained in:
parent
f94299fe0c
commit
53e4db39ed
|
|
@ -615,8 +615,8 @@ public interface ManagementServer {
|
|||
* @volumeId
|
||||
* @throws InvalidParameterValueException, InternalErrorException
|
||||
*/
|
||||
void detachVolumeFromVM(long volumeId, long startEventId) throws InternalErrorException;
|
||||
long detachVolumeFromVMAsync(long volumeId) throws InvalidParameterValueException;
|
||||
void detachVolumeFromVM(long volumeId, long startEventId, long deviceId, long instanceId) throws InternalErrorException;
|
||||
long detachVolumeFromVMAsync(long volumeId, long deviceId, long instanceId) throws InvalidParameterValueException;
|
||||
|
||||
/**
|
||||
* Attaches an ISO to the virtual CDROM device of the specified VM. Will fail if the VM already has an ISO mounted.
|
||||
|
|
|
|||
|
|
@ -46,4 +46,5 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long> {
|
|||
List<VolumeVO> listRemovedButNotDestroyed();
|
||||
List<VolumeVO> findCreatedByInstance(long id);
|
||||
List<VolumeVO> findByPoolId(long poolId);
|
||||
List<VolumeVO> findByInstanceAndDeviceId(long instanceId, long deviceId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
|||
protected final GenericSearchBuilder<VolumeVO, Long> ActiveTemplateSearch;
|
||||
protected final SearchBuilder<VolumeVO> RemovedButNotDestroyedSearch;
|
||||
protected final SearchBuilder<VolumeVO> PoolIdSearch;
|
||||
protected final SearchBuilder<VolumeVO> InstanceAndDeviceIdSearch;
|
||||
|
||||
protected static final String SELECT_VM_SQL = "SELECT DISTINCT instance_id from volumes v where v.host_id = ? and v.mirror_state = ?";
|
||||
protected static final String SELECT_VM_ID_SQL = "SELECT DISTINCT instance_id from volumes v where v.host_id = ?";
|
||||
|
|
@ -117,6 +118,14 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
|||
sc.setParameters("instanceId", id);
|
||||
return listActiveBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VolumeVO> findByInstanceAndDeviceId(long instanceId, long deviceId){
|
||||
SearchCriteria<VolumeVO> sc = InstanceAndDeviceIdSearch.create();
|
||||
sc.setParameters("instanceId", instanceId);
|
||||
sc.setParameters("deviceId", deviceId);
|
||||
return listActiveBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VolumeVO> findByPoolId(long poolId) {
|
||||
|
|
@ -304,6 +313,11 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
|||
InstanceIdSearch.and("instanceId", InstanceIdSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
|
||||
InstanceIdSearch.done();
|
||||
|
||||
InstanceAndDeviceIdSearch = createSearchBuilder();
|
||||
InstanceAndDeviceIdSearch.and("instanceId", InstanceAndDeviceIdSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
|
||||
InstanceAndDeviceIdSearch.and("deviceId", InstanceAndDeviceIdSearch.entity().getDeviceId(), SearchCriteria.Op.EQ);
|
||||
InstanceAndDeviceIdSearch.done();
|
||||
|
||||
PoolIdSearch = createSearchBuilder();
|
||||
PoolIdSearch.and("poolId", PoolIdSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
|
||||
PoolIdSearch.done();
|
||||
|
|
|
|||
|
|
@ -37,7 +37,9 @@ public class DetachVolumeCmd extends BaseCmd {
|
|||
|
||||
static {
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DEVICE_ID, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.VIRTUAL_MACHINE_ID, Boolean.FALSE));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
@ -56,6 +58,22 @@ public class DetachVolumeCmd extends BaseCmd {
|
|||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
Account account = (Account) params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||
Long volumeId = (Long) params.get(BaseCmd.Properties.ID.getName());
|
||||
Long deviceId = (Long) params.get(BaseCmd.Properties.DEVICE_ID.getName());
|
||||
Long instanceId = (Long) params.get(BaseCmd.Properties.VIRTUAL_MACHINE_ID.getName());
|
||||
|
||||
if((volumeId==null && (deviceId==null && instanceId==null)) || (volumeId!=null && (deviceId!=null || instanceId!=null)) || (volumeId==null && (deviceId==null || instanceId==null)))
|
||||
{
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Please provide either a volume id, or a tuple(device id, instance id)");
|
||||
}
|
||||
|
||||
if(volumeId!=null)
|
||||
{
|
||||
deviceId = instanceId = Long.valueOf("0");
|
||||
}
|
||||
else
|
||||
{
|
||||
volumeId = Long.valueOf("0");;
|
||||
}
|
||||
|
||||
boolean isAdmin;
|
||||
if (account == null) {
|
||||
|
|
@ -82,7 +100,7 @@ public class DetachVolumeCmd extends BaseCmd {
|
|||
}
|
||||
|
||||
try {
|
||||
long jobId = getManagementServer().detachVolumeFromVMAsync(volumeId);
|
||||
long jobId = getManagementServer().detachVolumeFromVMAsync(volumeId,deviceId,instanceId);
|
||||
|
||||
if (jobId == 0) {
|
||||
s_logger.warn("Unable to schedule async-job for DetachVolume comamnd");
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class VolumeOperationExecutor extends BaseAsyncJobExecutor {
|
|||
eventType = EventTypes.EVENT_VOLUME_DETACH;
|
||||
failureDescription = "Failed to detach volume";
|
||||
|
||||
asyncMgr.getExecutorContext().getManagementServer().detachVolumeFromVM(param.getVolumeId(), param.getEventId());
|
||||
asyncMgr.getExecutorContext().getManagementServer().detachVolumeFromVM(param.getVolumeId(), param.getEventId(),param.getDeviceId(),param.getVmId());
|
||||
success = true;
|
||||
asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_SUCCEEDED, 0, null);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ public class VolumeOperationParam {
|
|||
// Used for Attach, Detach, and Delete
|
||||
private long volumeId;
|
||||
private long eventId;
|
||||
private Long deviceId;
|
||||
|
||||
private long deviceId;
|
||||
|
||||
public VolumeOperationParam() {
|
||||
}
|
||||
|
||||
|
|
@ -117,11 +117,11 @@ public class VolumeOperationParam {
|
|||
return eventId;
|
||||
}
|
||||
|
||||
public void setDeviceId(Long deviceId) {
|
||||
public void setDeviceId(long deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public Long getDeviceId() {
|
||||
public long getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1985,12 +1985,12 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void detachVolumeFromVM(long volumeId, long startEventId) throws InternalErrorException {
|
||||
_vmMgr.detachVolumeFromVM(volumeId, startEventId);
|
||||
public void detachVolumeFromVM(long volumeId, long startEventId, long deviceId, long instanceId) throws InternalErrorException {
|
||||
_vmMgr.detachVolumeFromVM(volumeId, startEventId, deviceId, instanceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long detachVolumeFromVMAsync(long volumeId) throws InvalidParameterValueException {
|
||||
public long detachVolumeFromVMAsync(long volumeId, long deviceId, long instanceId) throws InvalidParameterValueException {
|
||||
VolumeVO volume = _volumeDao.findById(volumeId);
|
||||
|
||||
// Check that the volume is a data volume
|
||||
|
|
@ -2022,6 +2022,8 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
param.setAccountId(volume.getAccountId());
|
||||
param.setOp(VolumeOp.Detach);
|
||||
param.setVolumeId(volumeId);
|
||||
param.setDeviceId(deviceId);
|
||||
param.setVmId(instanceId);
|
||||
param.setEventId(eventId);
|
||||
|
||||
Gson gson = GsonHelper.getBuilder().create();
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ public interface UserVmManager extends Manager, VirtualMachineManager<UserVmVO>
|
|||
* @param volumeId
|
||||
* @throws InternalErrorException
|
||||
*/
|
||||
void detachVolumeFromVM(long volumeId, long startEventId) throws InternalErrorException;
|
||||
void detachVolumeFromVM(long volumeId, long startEventId, long deviceId, long instanceId) throws InternalErrorException;
|
||||
|
||||
/**
|
||||
* Attaches an ISO to the virtual CDROM device of the specified VM. Will eject any existing virtual CDROM if isoPath is null.
|
||||
|
|
|
|||
|
|
@ -418,10 +418,28 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void detachVolumeFromVM(long volumeId, long startEventId) throws InternalErrorException {
|
||||
VolumeVO volume = _volsDao.findById(volumeId);
|
||||
public void detachVolumeFromVM(long volumeId, long startEventId, long deviceId, long instanceId) throws InternalErrorException {
|
||||
VolumeVO volume = null;
|
||||
|
||||
Long vmId = volume.getInstanceId();
|
||||
if(volumeId!=0)
|
||||
{
|
||||
volume = _volsDao.findById(volumeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
volume = _volsDao.findByInstanceAndDeviceId(instanceId, deviceId).get(0);
|
||||
}
|
||||
|
||||
Long vmId = null;
|
||||
|
||||
if(instanceId!=0)
|
||||
{
|
||||
vmId = volume.getInstanceId();
|
||||
}
|
||||
else
|
||||
{
|
||||
vmId = instanceId;
|
||||
}
|
||||
|
||||
if (vmId == null) {
|
||||
return;
|
||||
|
|
@ -454,7 +472,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||
Answer answer = null;
|
||||
|
||||
if (sendCommand) {
|
||||
AttachVolumeCommand cmd = new AttachVolumeCommand(false, vm.getInstanceName(), volume.getPoolType(), volume.getFolder(), volume.getPath(), volume.getName(), volume.getDeviceId());
|
||||
AttachVolumeCommand cmd = new AttachVolumeCommand(false, vm.getInstanceName(), volume.getPoolType(), volume.getFolder(), volume.getPath(), volume.getName(), deviceId!=0 ? deviceId : volume.getDeviceId());
|
||||
|
||||
try {
|
||||
answer = _agentMgr.send(vm.getHostId(), cmd);
|
||||
|
|
|
|||
Loading…
Reference in New Issue