mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge branch '2.1.refactor' of ssh://git.cloud.com/var/lib/git/cloudstack-oss into 2.1.refactor
Conflicts: server/src/com/cloud/storage/StorageManagerImpl.java
This commit is contained in:
commit
46c331b54b
@ -26,24 +26,19 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
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.user.Account;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
|
||||
|
||||
@Implementation(method="startVirtualMachine", manager=Manager.UserVmManager)
|
||||
public class StartVMCmd extends BaseCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(StartVMCmd.class.getName());
|
||||
|
||||
private static final String s_name = "startvirtualmachineresponse";
|
||||
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));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.USER_ID, Boolean.FALSE));
|
||||
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
@ -71,50 +66,52 @@ public class StartVMCmd extends BaseCmd {
|
||||
public static String getResultObjectName() {
|
||||
return "virtualmachine";
|
||||
}
|
||||
|
||||
public List<Pair<Enum, Boolean>> getProperties() {
|
||||
return s_properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
Long vmId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||
Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
||||
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||
|
||||
//if account is removed, return error
|
||||
if(account!=null && account.getRemoved() != null)
|
||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "The account " + account.getId()+" is removed");
|
||||
|
||||
//Verify input parameters
|
||||
UserVmVO vmInstanceCheck = getManagementServer().findUserVMInstanceById(vmId.longValue());
|
||||
if (vmInstanceCheck == null) {
|
||||
throw new ServerApiException (BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + vmId);
|
||||
}
|
||||
|
||||
if (account != null) {
|
||||
if (!isAdmin(account.getType()) && (account.getId().longValue() != vmInstanceCheck.getAccountId())) {
|
||||
throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + vmId + " for this account");
|
||||
} else if (!getManagementServer().isChildDomain(account.getDomainId(), vmInstanceCheck.getDomainId())) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid virtual machine id (" + vmId + ") given, unable to start virtual machine.");
|
||||
}
|
||||
}
|
||||
|
||||
if (userId == null) {
|
||||
userId = Long.valueOf(1);
|
||||
}
|
||||
|
||||
long jobId = getManagementServer().startVirtualMachineAsync(userId.longValue(), vmId.longValue(), null);
|
||||
if(jobId == 0) {
|
||||
s_logger.warn("Unable to schedule async-job for StartVM comamnd");
|
||||
} else {
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("StartVM 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 List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
// Long vmId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||
// Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
||||
// Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||
//
|
||||
// //if account is removed, return error
|
||||
// if(account!=null && account.getRemoved() != null)
|
||||
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "The account " + account.getId()+" is removed");
|
||||
//
|
||||
// //Verify input parameters
|
||||
// UserVmVO vmInstanceCheck = getManagementServer().findUserVMInstanceById(vmId.longValue());
|
||||
// if (vmInstanceCheck == null) {
|
||||
// throw new ServerApiException (BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + vmId);
|
||||
// }
|
||||
//
|
||||
// if (account != null) {
|
||||
// if (!isAdmin(account.getType()) && (account.getId().longValue() != vmInstanceCheck.getAccountId())) {
|
||||
// throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + vmId + " for this account");
|
||||
// } else if (!getManagementServer().isChildDomain(account.getDomainId(), vmInstanceCheck.getDomainId())) {
|
||||
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid virtual machine id (" + vmId + ") given, unable to start virtual machine.");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (userId == null) {
|
||||
// userId = Long.valueOf(1);
|
||||
// }
|
||||
//
|
||||
// long jobId = getManagementServer().startVirtualMachineAsync(userId.longValue(), vmId.longValue(), null);
|
||||
// if(jobId == 0) {
|
||||
// s_logger.warn("Unable to schedule async-job for StartVM comamnd");
|
||||
// } else {
|
||||
// if(s_logger.isDebugEnabled())
|
||||
// s_logger.debug("StartVM 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 Add the response object as per executor
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,30 +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.user.Account;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
|
||||
public class StopVMCmd extends BaseCmd {
|
||||
import com.cloud.api.BaseCmd.Manager;
|
||||
|
||||
@Implementation(method="stopVirtualMachine", manager=Manager.UserVmManager)
|
||||
public class StopVMCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(StopVMCmd.class.getName());
|
||||
|
||||
private static final String s_name = "stopvirtualmachineresponse";
|
||||
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));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.USER_ID, Boolean.FALSE));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
@ -66,46 +54,48 @@ public class StopVMCmd extends BaseCmd {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
public List<Pair<Enum, Boolean>> getProperties() {
|
||||
return s_properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||
Long vmId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||
Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
||||
|
||||
// Verify input parameters
|
||||
UserVmVO vmInstance = getManagementServer().findUserVMInstanceById(vmId.longValue());
|
||||
if (vmInstance == null) {
|
||||
throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + vmId);
|
||||
}
|
||||
|
||||
if (account != null) {
|
||||
if (!isAdmin(account.getType()) && (account.getId().longValue() != vmInstance.getAccountId())) {
|
||||
throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + vmId + " for this account");
|
||||
} else if (!getManagementServer().isChildDomain(account.getDomainId(), vmInstance.getDomainId())) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid virtual machine id (" + vmId + ") given, unable to sop virtual machine.");
|
||||
}
|
||||
}
|
||||
|
||||
// If command is executed via 8096 port, set userId to the id of System account (1)
|
||||
if (userId == null) {
|
||||
userId = Long.valueOf(1);
|
||||
}
|
||||
|
||||
long jobId = getManagementServer().stopVirtualMachineAsync(userId.longValue(), vmId.longValue());
|
||||
if (jobId == 0) {
|
||||
s_logger.warn("Unable to schedule async-job for StopVM comamnd");
|
||||
} else {
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("StopVM 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 List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
// Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||
// Long vmId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||
// Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
||||
//
|
||||
// // Verify input parameters
|
||||
// UserVmVO vmInstance = getManagementServer().findUserVMInstanceById(vmId.longValue());
|
||||
// if (vmInstance == null) {
|
||||
// throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + vmId);
|
||||
// }
|
||||
//
|
||||
// if (account != null) {
|
||||
// if (!isAdmin(account.getType()) && (account.getId().longValue() != vmInstance.getAccountId())) {
|
||||
// throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + vmId + " for this account");
|
||||
// } else if (!getManagementServer().isChildDomain(account.getDomainId(), vmInstance.getDomainId())) {
|
||||
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid virtual machine id (" + vmId + ") given, unable to sop virtual machine.");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // If command is executed via 8096 port, set userId to the id of System account (1)
|
||||
// if (userId == null) {
|
||||
// userId = Long.valueOf(1);
|
||||
// }
|
||||
//
|
||||
// long jobId = getManagementServer().stopVirtualMachineAsync(userId.longValue(), vmId.longValue());
|
||||
// if (jobId == 0) {
|
||||
// s_logger.warn("Unable to schedule async-job for StopVM comamnd");
|
||||
// } else {
|
||||
// if(s_logger.isDebugEnabled())
|
||||
// s_logger.debug("StopVM 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 Auto-generated method stub
|
||||
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;
|
||||
@ -1460,7 +1461,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;
|
||||
@ -7934,12 +7935,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -61,6 +61,7 @@ import com.cloud.alert.AlertManager;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.commands.DeletePoolCmd;
|
||||
import com.cloud.api.commands.StopVMCmd;
|
||||
import com.cloud.api.commands.UpdateStoragePoolCmd;
|
||||
import com.cloud.async.AsyncInstanceCreateStatus;
|
||||
import com.cloud.async.AsyncJobExecutor;
|
||||
@ -1949,8 +1950,10 @@ public class StorageManagerImpl implements StorageManager {
|
||||
//if the instance is of type uservm, call the user vm manager
|
||||
if(vmInstance.getType().equals(VirtualMachine.Type.User))
|
||||
{
|
||||
//create a dummy event
|
||||
long eventId = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_VM_STOP, "stopping user vm with Id: "+vmInstance.getId());
|
||||
|
||||
if(!_userVmMgr.stopVirtualMachine(userId, vmInstance.getId()))
|
||||
if(!_userVmMgr.stopVirtualMachine(userId, vmInstance.getId(),eventId))
|
||||
{
|
||||
s_logger.warn("There was an error stopping the user vm id: "+vmInstance.getId()+" ,cannot enable storage maintenance");
|
||||
primaryStorage.setStatus(Status.ErrorInMaintenance);
|
||||
|
||||
@ -22,6 +22,8 @@ import java.util.List;
|
||||
|
||||
import com.cloud.agent.api.VmStatsEntry;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.commands.StartVMCmd;
|
||||
import com.cloud.api.commands.StopVMCmd;
|
||||
import com.cloud.api.commands.UpdateVMCmd;
|
||||
import com.cloud.api.commands.UpgradeVMCmd;
|
||||
import com.cloud.async.executor.DestroyVMExecutor;
|
||||
@ -154,14 +156,17 @@ public interface UserVmManager extends Manager, VirtualMachineManager<UserVmVO>
|
||||
* @throws ConcurrentOperationException
|
||||
*/
|
||||
UserVmVO startVirtualMachine(long userId, long vmId, String password, String isoPath, long startEventId) throws ExecutionException, StorageUnavailableException, ConcurrentOperationException;
|
||||
UserVmVO startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, ExecutionException, ConcurrentOperationException;
|
||||
|
||||
/**
|
||||
* Stops the virtual machine
|
||||
* @param userId the id of the user performing the action
|
||||
* @param vmId
|
||||
* @param eventId -- id of the scheduled event for stopping vm
|
||||
* @return true if stopped; false if problems.
|
||||
*/
|
||||
boolean stopVirtualMachine(long userId, long vmId);
|
||||
boolean stopVirtualMachine(long userId, long vmId, long eventId);
|
||||
boolean stopVirtualMachine(StopVMCmd cmd) throws ServerApiException;
|
||||
OperationResponse executeStopVM(StopVMExecutor executor, VMOperationParam param);
|
||||
void completeStopCommand(long userId, UserVmVO vm, Event e, long startEventId);
|
||||
|
||||
|
||||
@ -66,6 +66,8 @@ import com.cloud.agent.manager.AgentManager;
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.commands.StartVMCmd;
|
||||
import com.cloud.api.commands.StopVMCmd;
|
||||
import com.cloud.api.commands.UpdateVMCmd;
|
||||
import com.cloud.api.commands.UpgradeVMCmd;
|
||||
import com.cloud.async.AsyncJobExecutor;
|
||||
@ -914,8 +916,9 @@ public class UserVmManagerImpl implements UserVmManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopVirtualMachine(long userId, long vmId) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
public boolean stopVirtualMachine(long userId, long vmId, long eventId) {
|
||||
boolean status = false;
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Stopping vm=" + vmId);
|
||||
}
|
||||
|
||||
@ -926,8 +929,21 @@ public class UserVmManagerImpl implements UserVmManager {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
EventUtils.saveStartedEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_STOP, "stopping Vm with Id: "+vmId, eventId);
|
||||
|
||||
return stop(userId, vm, 0);
|
||||
status = stop(userId, vm, 0);
|
||||
|
||||
if(status)
|
||||
{
|
||||
EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_STOP, "Successfully stopped VM instance : " + vmId);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_STOP, "Error stopping VM instance : " + vmId);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -3121,4 +3137,54 @@ public class UserVmManagerImpl implements UserVmManager {
|
||||
EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_INFO, type, description, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopVirtualMachine(StopVMCmd cmd) throws ServerApiException{
|
||||
|
||||
//Input validation
|
||||
Account account = (Account)UserContext.current().getAccountObject();
|
||||
Long userId = UserContext.current().getUserId();
|
||||
Long id = cmd.getId();
|
||||
|
||||
//if account is removed, return error
|
||||
if(account!=null && account.getRemoved() != null)
|
||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "The account " + account.getId()+" is removed");
|
||||
|
||||
UserVmVO vmInstance = _userVmDao.findById(id.longValue());
|
||||
if (vmInstance == null) {
|
||||
throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + id);
|
||||
}
|
||||
|
||||
long eventId = EventUtils.saveScheduledEvent(userId, vmInstance.getAccountId(), EventTypes.EVENT_VM_STOP, "stopping Vm with Id: "+id);
|
||||
|
||||
userId = accountAndUserValidation(id, account, userId, vmInstance);
|
||||
|
||||
return stopVirtualMachine(userId, id, eventId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVmVO startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, ExecutionException, ConcurrentOperationException {
|
||||
//Input validation
|
||||
Account account = (Account)UserContext.current().getAccountObject();
|
||||
Long userId = UserContext.current().getUserId();
|
||||
Long id = cmd.getId();
|
||||
|
||||
//if account is removed, return error
|
||||
if(account!=null && account.getRemoved() != null)
|
||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "The account " + account.getId()+" is removed");
|
||||
|
||||
UserVmVO vmInstance = _userVmDao.findById(id.longValue());
|
||||
if (vmInstance == null) {
|
||||
throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + id);
|
||||
}
|
||||
|
||||
long eventId = EventUtils.saveScheduledEvent(userId, vmInstance.getAccountId(), EventTypes.EVENT_VM_START, "Starting Vm with Id: "+id);
|
||||
|
||||
userId = accountAndUserValidation(id, account, userId, vmInstance);
|
||||
|
||||
return startVirtualMachine(userId, id, null, null, eventId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user