mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Refactoring startsystemvm cmd
This commit is contained in:
parent
6ca1ceb769
commit
66f51effd9
@ -18,27 +18,18 @@
|
||||
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
|
||||
public class StartSystemVMCmd extends BaseCmd {
|
||||
import com.cloud.api.BaseCmd.Manager;
|
||||
|
||||
@Implementation(method="stopSystemVM", manager=Manager.ManagementServer)
|
||||
public class StartSystemVMCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(StartSystemVMCmd.class.getName());
|
||||
|
||||
private static final String s_name = "startsystemvmresponse";
|
||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
||||
|
||||
static {
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
@ -66,30 +57,32 @@ public class StartSystemVMCmd extends BaseCmd {
|
||||
public static String getResultObjectName() {
|
||||
return "systemvm";
|
||||
}
|
||||
|
||||
public List<Pair<Enum, Boolean>> getProperties() {
|
||||
return s_properties;
|
||||
}
|
||||
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
Long sysvmId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||
|
||||
// verify parameters
|
||||
VMInstanceVO sysVm = getManagementServer().findSystemVMById(sysvmId);
|
||||
if (sysVm == null) {
|
||||
throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a system vm with id " + sysvmId);
|
||||
}
|
||||
|
||||
long jobId = getManagementServer().startSystemVmAsync(sysvmId.longValue());
|
||||
if(jobId == 0) {
|
||||
s_logger.warn("Unable to schedule async-job for StartSystemVM comamnd");
|
||||
} else {
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("StartSystemVM command has been accepted, job id: " + jobId);
|
||||
}
|
||||
|
||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId)));
|
||||
return returnValues;
|
||||
}
|
||||
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
// Long sysvmId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||
//
|
||||
// // verify parameters
|
||||
// VMInstanceVO sysVm = getManagementServer().findSystemVMById(sysvmId);
|
||||
// if (sysVm == null) {
|
||||
// throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a system vm with id " + sysvmId);
|
||||
// }
|
||||
//
|
||||
// long jobId = getManagementServer().startSystemVmAsync(sysvmId.longValue());
|
||||
// if(jobId == 0) {
|
||||
// s_logger.warn("Unable to schedule async-job for StartSystemVM comamnd");
|
||||
// } else {
|
||||
// if(s_logger.isDebugEnabled())
|
||||
// s_logger.debug("StartSystemVM command has been accepted, job id: " + jobId);
|
||||
// }
|
||||
//
|
||||
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId)));
|
||||
// return returnValues;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String getResponse() {
|
||||
// TODO COnstruct response based on executor
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ import java.util.Map;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
@ -35,7 +36,7 @@ import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
|
||||
@Implementation(method="startVirtualMachine", manager=Manager.UserVmManager)
|
||||
public class StartVMCmd extends BaseCmd {
|
||||
public class StartVMCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(StartVMCmd.class.getName());
|
||||
|
||||
private static final String s_name = "startvirtualmachineresponse";
|
||||
|
||||
@ -20,20 +20,17 @@ package com.cloud.api.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.BaseCmd.Manager;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
|
||||
@Implementation(method="stopSystemVM", manager=Manager.ManagementServer)
|
||||
public class StopSystemVmCmd extends BaseCmd {
|
||||
public class StopSystemVmCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(StopSystemVmCmd.class.getName());
|
||||
|
||||
private static final String s_name = "stopsystemvmresponse";
|
||||
|
||||
@ -29,6 +29,7 @@ import com.cloud.api.commands.CreateDomainCmd;
|
||||
import com.cloud.api.commands.EnableAccountCmd;
|
||||
import com.cloud.api.commands.EnableUserCmd;
|
||||
import com.cloud.api.commands.GetCloudIdentifierCmd;
|
||||
import com.cloud.api.commands.StartSystemVMCmd;
|
||||
import com.cloud.api.commands.StopSystemVmCmd;
|
||||
import com.cloud.api.commands.UpdateAccountCmd;
|
||||
import com.cloud.api.commands.UpdateDomainCmd;
|
||||
@ -675,7 +676,7 @@ public interface ManagementServer {
|
||||
* @throws StorageUnavailableException
|
||||
* @throws ConcurrentOperationException
|
||||
*/
|
||||
UserVm startVirtualMachine(long userId, long vmId, String isoPath) throws InternalErrorException, ExecutionException, StorageUnavailableException, ConcurrentOperationException;
|
||||
//UserVm startVirtualMachine(long userId, long vmId, String isoPath) throws InternalErrorException, ExecutionException, StorageUnavailableException, ConcurrentOperationException;
|
||||
long startVirtualMachineAsync(long userId, long vmId, String isoPath);
|
||||
|
||||
/**
|
||||
@ -685,7 +686,7 @@ public interface ManagementServer {
|
||||
* @param vmId
|
||||
* @return true if successfully stopped, false otherwise
|
||||
*/
|
||||
boolean stopVirtualMachine(long userId, long vmId);
|
||||
//boolean stopVirtualMachine(long userId, long vmId);
|
||||
long stopVirtualMachineAsync(long userId, long vmId);
|
||||
|
||||
/**
|
||||
@ -1461,7 +1462,7 @@ public interface ManagementServer {
|
||||
ConsoleProxyVO findConsoleProxyById(long instanceId);
|
||||
VMInstanceVO findSystemVMById(long instanceId);
|
||||
boolean stopSystemVM(StopSystemVmCmd cmd);
|
||||
VMInstanceVO startSystemVM(long instanceId, long startEventId) throws InternalErrorException;
|
||||
VMInstanceVO startSystemVM(StartSystemVMCmd cmd) throws InternalErrorException;
|
||||
long startSystemVmAsync(long instanceId);
|
||||
long stopSystemVmAsync(long instanceId);
|
||||
long rebootSystemVmAsync(long longValue);
|
||||
|
||||
@ -2571,10 +2571,10 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
return _asyncMgr.submitAsyncJob(job);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVm startVirtualMachine(long userId, long vmId, String isoPath) throws InternalErrorException, ExecutionException, StorageUnavailableException, ConcurrentOperationException {
|
||||
return _vmMgr.startVirtualMachine(userId, vmId, isoPath, 0);
|
||||
}
|
||||
// @Override
|
||||
// public UserVm startVirtualMachine(long userId, long vmId, String isoPath) throws InternalErrorException, ExecutionException, StorageUnavailableException, ConcurrentOperationException {
|
||||
// return _vmMgr.startVirtualMachine(userId, vmId, isoPath, 0);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public long startVirtualMachineAsync(long userId, long vmId, String isoPath) {
|
||||
@ -2595,10 +2595,10 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
return _asyncMgr.submitAsyncJob(job, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopVirtualMachine(long userId, long vmId) {
|
||||
return _vmMgr.stopVirtualMachine(userId, vmId);
|
||||
}
|
||||
// @Override
|
||||
// public boolean stopVirtualMachine(long userId, long vmId) {
|
||||
// return _vmMgr.stopVirtualMachine(userId, vmId);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public long stopVirtualMachineAsync(long userId, long vmId) {
|
||||
@ -7939,17 +7939,38 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
return _secStorageVmDao.findById(instanceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VMInstanceVO startSystemVM(StartSystemVMCmd cmd) throws InternalErrorException {
|
||||
|
||||
//verify input
|
||||
Long id = cmd.getId();
|
||||
|
||||
VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(id, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);
|
||||
if (systemVm == null) {
|
||||
throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a system vm with id " + id);
|
||||
}
|
||||
|
||||
if (systemVm.getType().equals(VirtualMachine.Type.ConsoleProxy)){
|
||||
long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_START, "Starting console proxy with Id: "+id);
|
||||
return startConsoleProxy(id, eventId);
|
||||
} else {
|
||||
long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_START, "Starting secondary storage Vm Id: "+id);
|
||||
return startSecondaryStorageVm(id, eventId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean stopSystemVM(StopSystemVmCmd cmd) {
|
||||
Long id = cmd.getId();
|
||||
|
||||
// verify parameters
|
||||
VMInstanceVO systemVM = findSystemVMById(id);
|
||||
if (systemVM == null) {
|
||||
// verify parameters
|
||||
VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(id, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);
|
||||
if (systemVm == null) {
|
||||
throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a system vm with id " + id);
|
||||
}
|
||||
|
||||
VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(id, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);
|
||||
if (systemVm.getType().equals(VirtualMachine.Type.ConsoleProxy)){
|
||||
long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_STOP, "stopping console proxy with Id: "+id);
|
||||
return stopConsoleProxy(id, eventId);
|
||||
@ -7989,16 +8010,6 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VMInstanceVO startSystemVM(long instanceId, long startEventId) throws InternalErrorException {
|
||||
VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(instanceId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);
|
||||
if (systemVm.getType().equals(VirtualMachine.Type.ConsoleProxy)){
|
||||
return startConsoleProxy(instanceId, startEventId);
|
||||
} else {
|
||||
return startSecondaryStorageVm(instanceId, startEventId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rebootSystemVM(long instanceId, long startEventId) {
|
||||
VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(instanceId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user