mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Refactoring some more system vm commands
This commit is contained in:
parent
dc45e9b08b
commit
934173db2e
@ -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<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 /////////////////////
|
||||
@ -62,30 +53,32 @@ public class RebootSystemVmCmd extends BaseCmd {
|
||||
public String getName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
public List<Pair<Enum, Boolean>> getProperties() {
|
||||
return s_properties;
|
||||
}
|
||||
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> 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<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 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<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 Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user