diff --git a/server/src/com/cloud/api/commands/StopSystemVmCmd.java b/server/src/com/cloud/api/commands/StopSystemVmCmd.java index 6788be63f51..75ceacba0a3 100644 --- a/server/src/com/cloud/api/commands/StopSystemVmCmd.java +++ b/server/src/com/cloud/api/commands/StopSystemVmCmd.java @@ -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> s_properties = new ArrayList>(); - - static { - s_properties.add(new Pair(BaseCmd.Properties.ID, Boolean.TRUE)); - } ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -63,29 +62,31 @@ public class StopSystemVmCmd extends BaseCmd { return s_name; } - public List> getProperties() { - return s_properties; - } - - public List> execute(Map 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> returnValues = new ArrayList>(); - returnValues.add(new Pair(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId))); - return returnValues; - } +// public List> execute(Map 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> returnValues = new ArrayList>(); +// returnValues.add(new Pair(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId))); +// return returnValues; +// } + + @Override + public String getResponse() { + // TODO Construct the response object (refer executor) + return null; + } } diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 787a295aef1..858928a2d4e 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -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; } } diff --git a/server/src/com/cloud/server/ManagementServer.java b/server/src/com/cloud/server/ManagementServer.java index 7b89eac9eb3..c106ab396af 100644 --- a/server/src/com/cloud/server/ManagementServer.java +++ b/server/src/com/cloud/server/ManagementServer.java @@ -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); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index bc77e6f40b6..f53100528a0 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -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); } }