diff --git a/server/src/com/cloud/api/commands/RebootSystemVmCmd.java b/server/src/com/cloud/api/commands/RebootSystemVmCmd.java index f5baa46cc42..e07b3004d9a 100644 --- a/server/src/com/cloud/api/commands/RebootSystemVmCmd.java +++ b/server/src/com/cloud/api/commands/RebootSystemVmCmd.java @@ -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 RebootSystemVmCmd extends BaseCmd { +import com.cloud.api.BaseCmd.Manager; + +@Implementation(method="rebootSystemVM", manager=Manager.ManagementServer) +public class RebootSystemVmCmd extends BaseAsyncCmd { public static final Logger s_logger = Logger.getLogger(RebootSystemVmCmd.class.getName()); private static final String s_name = "rebootsystemvmresponse"; - private static final List> s_properties = new ArrayList>(); - - static { - s_properties.add(new Pair(BaseCmd.Properties.ID, Boolean.TRUE)); - } ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -62,30 +53,32 @@ public class RebootSystemVmCmd extends BaseCmd { public String getName() { return s_name; } - - public List> getProperties() { - return s_properties; - } - public List> execute(Map params) { - Long systemVmId = (Long)params.get(BaseCmd.Properties.ID.getName()); - - // verify parameters - VMInstanceVO systemVm = getManagementServer().findSystemVMById(systemVmId); - if (systemVm == null) { - throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a system vm with id " + systemVmId); - } - - long jobId = getManagementServer().rebootSystemVmAsync(systemVmId.longValue()); - if(jobId == 0) { - s_logger.warn("Unable to schedule async-job for RebootSystemVMCommand"); - } else { - if(s_logger.isDebugEnabled()) - s_logger.debug("RebootSystemVMCommand 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 systemVmId = (Long)params.get(BaseCmd.Properties.ID.getName()); +// +// // verify parameters +// VMInstanceVO systemVm = getManagementServer().findSystemVMById(systemVmId); +// if (systemVm == null) { +// throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a system vm with id " + systemVmId); +// } +// +// long jobId = getManagementServer().rebootSystemVmAsync(systemVmId.longValue()); +// if(jobId == 0) { +// s_logger.warn("Unable to schedule async-job for RebootSystemVMCommand"); +// } else { +// if(s_logger.isDebugEnabled()) +// s_logger.debug("RebootSystemVMCommand 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 Auto-generated method stub + return null; + } } diff --git a/server/src/com/cloud/api/commands/StopSystemVmCmd.java b/server/src/com/cloud/api/commands/StopSystemVmCmd.java index f35c2e63cb0..30ead9e99a4 100644 --- a/server/src/com/cloud/api/commands/StopSystemVmCmd.java +++ b/server/src/com/cloud/api/commands/StopSystemVmCmd.java @@ -18,23 +18,18 @@ package com.cloud.api.commands; -import java.util.ArrayList; -import java.util.List; - import org.apache.log4j.Logger; import com.cloud.api.BaseAsyncCmd; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.BaseCmd.Manager; -import com.cloud.utils.Pair; @Implementation(method="stopSystemVM", manager=Manager.ManagementServer) public class StopSystemVmCmd extends BaseAsyncCmd { 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>(); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/server/src/com/cloud/server/ManagementServer.java b/server/src/com/cloud/server/ManagementServer.java index 3188de9dbf7..633b80d5e07 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.CreatePortForwardingServiceRuleCmd; import com.cloud.api.commands.EnableAccountCmd; import com.cloud.api.commands.EnableUserCmd; import com.cloud.api.commands.GetCloudIdentifierCmd; +import com.cloud.api.commands.RebootSystemVmCmd; import com.cloud.api.commands.RegisterCmd; import com.cloud.api.commands.RemovePortForwardingServiceCmd; import com.cloud.api.commands.StartSystemVMCmd; @@ -1392,9 +1393,9 @@ public interface ManagementServer { boolean stopSystemVM(StopSystemVmCmd cmd); VMInstanceVO startSystemVM(StartSystemVMCmd cmd) throws InternalErrorException; long startSystemVmAsync(long instanceId); - long stopSystemVmAsync(long instanceId); - long rebootSystemVmAsync(long longValue); - boolean rebootSystemVM(long instanceId, long startEventId); +// long stopSystemVmAsync(long instanceId); +// long rebootSystemVmAsync(long longValue); + boolean rebootSystemVM(RebootSystemVmCmd cmd); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index e9753ee824a..4442b72ef39 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -73,6 +73,7 @@ import com.cloud.api.commands.EnableUserCmd; import com.cloud.api.commands.GetCloudIdentifierCmd; import com.cloud.api.commands.PrepareForMaintenanceCmd; import com.cloud.api.commands.PreparePrimaryStorageForMaintenanceCmd; +import com.cloud.api.commands.RebootSystemVmCmd; import com.cloud.api.commands.RegisterCmd; import com.cloud.api.commands.RemovePortForwardingServiceCmd; import com.cloud.api.commands.StartRouterCmd; @@ -8034,25 +8035,25 @@ public class ManagementServerImpl implements ManagementServer { } } - @Override - public long stopSystemVmAsync(long instanceId) { - VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(instanceId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm); - if (systemVm.getType().equals(VirtualMachine.Type.ConsoleProxy)){ - return stopConsoleProxyAsync(instanceId); - } else { - return stopSecondaryStorageVmAsync(instanceId); - } - } +// @Override +// public long stopSystemVmAsync(long instanceId) { +// VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(instanceId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm); +// if (systemVm.getType().equals(VirtualMachine.Type.ConsoleProxy)){ +// return stopConsoleProxyAsync(instanceId); +// } else { +// return stopSecondaryStorageVmAsync(instanceId); +// } +// } - @Override - public long rebootSystemVmAsync(long instanceId) { - VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(instanceId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm); - if (systemVm.getType().equals(VirtualMachine.Type.ConsoleProxy)){ - return rebootConsoleProxyAsync(instanceId); - } else { - return rebootSecondaryStorageVmAsync(instanceId); - } - } +// @Override +// public long rebootSystemVmAsync(long instanceId) { +// VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(instanceId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm); +// if (systemVm.getType().equals(VirtualMachine.Type.ConsoleProxy)){ +// return rebootConsoleProxyAsync(instanceId); +// } else { +// return rebootSecondaryStorageVmAsync(instanceId); +// } +// } @Override public long startSystemVmAsync(long instanceId) { @@ -8065,12 +8066,19 @@ public class ManagementServerImpl implements ManagementServer { } @Override - public boolean rebootSystemVM(long instanceId, long startEventId) { - VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(instanceId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm); + public boolean rebootSystemVM(RebootSystemVmCmd cmd) { + VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(cmd.getId(), VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm); + + if (systemVm == null) { + throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a system vm with id " + systemVm.getId()); + } + if (systemVm.getType().equals(VirtualMachine.Type.ConsoleProxy)){ - return rebootConsoleProxy(instanceId, startEventId); + long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_REBOOT, "Rebooting console proxy with Id: "+cmd.getId()); + return rebootConsoleProxy(cmd.getId(), eventId); } else { - return rebootSecondaryStorageVm(instanceId, startEventId); + long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_REBOOT, "Rebooting secondary storage vm with Id: "+cmd.getId()); + return rebootSecondaryStorageVm(cmd.getId(), eventId); } }