mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Refactoring StopSystemVmCmd
This commit is contained in:
parent
716271fca1
commit
c58749b917
@ -25,20 +25,19 @@ import java.util.Map;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseCmd;
|
||||
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 static final Logger s_logger = Logger.getLogger(StopSystemVmCmd.class.getName());
|
||||
|
||||
private static final String s_name = "stopsystemvmresponse";
|
||||
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 /////////////////////
|
||||
@ -63,29 +62,31 @@ public class StopSystemVmCmd extends BaseCmd {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
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 systemVM = getManagementServer().findSystemVMById(sysVmId);
|
||||
if (systemVM == null) {
|
||||
throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a system vm with id " + sysVmId);
|
||||
}
|
||||
|
||||
long jobId = getManagementServer().stopSystemVmAsync(sysVmId.longValue());
|
||||
if(jobId == 0) {
|
||||
s_logger.warn("Unable to schedule async-job for StopSystemVM comamnd");
|
||||
} else {
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("StopSystemVM 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 systemVM = getManagementServer().findSystemVMById(sysVmId);
|
||||
// if (systemVM == null) {
|
||||
// throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a system vm with id " + sysVmId);
|
||||
// }
|
||||
//
|
||||
// long jobId = getManagementServer().stopSystemVmAsync(sysVmId.longValue());
|
||||
// if(jobId == 0) {
|
||||
// s_logger.warn("Unable to schedule async-job for StopSystemVM comamnd");
|
||||
// } else {
|
||||
// if(s_logger.isDebugEnabled())
|
||||
// s_logger.debug("StopSystemVM 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 the response object (refer executor)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1965,7 +1965,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager,
|
||||
return stop(proxy, startEventId);
|
||||
} catch (AgentUnavailableException e) {
|
||||
if (s_logger.isDebugEnabled())
|
||||
s_logger.debug("Stopping console proxy " + proxy.getName() + " faled : exception " + e.toString());
|
||||
s_logger.debug("Stopping console proxy " + proxy.getName() + " failed : exception " + e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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.StopSystemVmCmd;
|
||||
import com.cloud.api.commands.UpdateAccountCmd;
|
||||
import com.cloud.api.commands.UpdateDomainCmd;
|
||||
import com.cloud.api.commands.UpdateTemplateCmd;
|
||||
@ -1459,7 +1460,7 @@ public interface ManagementServer {
|
||||
String getConsoleAccessUrlRoot(long vmId);
|
||||
ConsoleProxyVO findConsoleProxyById(long instanceId);
|
||||
VMInstanceVO findSystemVMById(long instanceId);
|
||||
boolean stopSystemVM(long instanceId, long startEventId);
|
||||
boolean stopSystemVM(StopSystemVmCmd cmd);
|
||||
VMInstanceVO startSystemVM(long instanceId, long startEventId) throws InternalErrorException;
|
||||
long startSystemVmAsync(long instanceId);
|
||||
long stopSystemVmAsync(long instanceId);
|
||||
|
||||
@ -81,6 +81,7 @@ import com.cloud.api.commands.ReconnectHostCmd;
|
||||
import com.cloud.api.commands.StartRouterCmd;
|
||||
import com.cloud.api.commands.StartSystemVMCmd;
|
||||
import com.cloud.api.commands.StartVMCmd;
|
||||
import com.cloud.api.commands.StopSystemVmCmd;
|
||||
import com.cloud.api.commands.UpdateAccountCmd;
|
||||
import com.cloud.api.commands.UpdateDomainCmd;
|
||||
import com.cloud.api.commands.UpdateIsoPermissionsCmd;
|
||||
@ -7939,12 +7940,22 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopSystemVM(long instanceId, long startEventId) {
|
||||
VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(instanceId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);
|
||||
public boolean stopSystemVM(StopSystemVmCmd cmd) {
|
||||
Long id = cmd.getId();
|
||||
|
||||
// verify parameters
|
||||
VMInstanceVO systemVM = findSystemVMById(id);
|
||||
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)){
|
||||
return stopConsoleProxy(instanceId, startEventId);
|
||||
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);
|
||||
} else {
|
||||
return stopSecondaryStorageVm(instanceId, startEventId);
|
||||
long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_STOP, "stopping secondary storage Vm Id: "+id);
|
||||
return stopSecondaryStorageVm(id, eventId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user