mirror of https://github.com/apache/cloudstack.git
added forced paramter to stop apis
This commit is contained in:
parent
fb8b895a0a
commit
b92fc074aa
|
|
@ -61,6 +61,7 @@ public class ApiConstants {
|
|||
public static final String END_PORT = "endport";
|
||||
public static final String ENTRY_TIME = "entrytime";
|
||||
public static final String FIRSTNAME = "firstname";
|
||||
public static final String FORCED = "forced";
|
||||
public static final String FORMAT = "format";
|
||||
public static final String FOR_VIRTUAL_NETWORK = "forvirtualnetwork";
|
||||
public static final String GATEWAY = "gateway";
|
||||
|
|
|
|||
|
|
@ -47,6 +47,9 @@ public class StopRouterCmd extends BaseAsyncCmd {
|
|||
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the router")
|
||||
private Long id;
|
||||
|
||||
@Parameter(name=ApiConstants.FORCED, type=CommandType.BOOLEAN, required=false, description="Force stop the VM. The caller knows the VM is stopped.")
|
||||
private Boolean forced;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
|
|
@ -79,23 +82,29 @@ public class StopRouterCmd extends BaseAsyncCmd {
|
|||
public String getEventType() {
|
||||
return EventTypes.EVENT_ROUTER_STOP;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "stopping router: " + getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncJob.Type getInstanceType() {
|
||||
return AsyncJob.Type.DomainRouter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getInstanceId() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
public boolean isForced() {
|
||||
return (forced != null) ? forced : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws ConcurrentOperationException, ResourceUnavailableException{
|
||||
VirtualRouter result = _routerService.stopRouter(this.getId());
|
||||
VirtualRouter result = _routerService.stopRouter(getId(), isForced());
|
||||
if (result != null){
|
||||
DomainRouterResponse response =_responseGenerator.createDomainRouterResponse(result);
|
||||
response.setResponseName(getCommandName());
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ import com.cloud.api.ServerApiException;
|
|||
import com.cloud.api.response.SystemVmResponse;
|
||||
import com.cloud.async.AsyncJob;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
|
@ -46,6 +48,9 @@ public class StopSystemVmCmd extends BaseAsyncCmd {
|
|||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the system virtual machine")
|
||||
private Long id;
|
||||
|
||||
@Parameter(name=ApiConstants.FORCED, type=CommandType.BOOLEAN, required=false, description="Force stop the VM. The caller knows the VM is stopped.")
|
||||
private Boolean forced;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -83,16 +88,22 @@ public class StopSystemVmCmd extends BaseAsyncCmd {
|
|||
return "stopping system vm: " + getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncJob.Type getInstanceType() {
|
||||
return AsyncJob.Type.SystemVm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getInstanceId() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
public boolean isForced() {
|
||||
return (forced != null) ? forced : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
public void execute() throws ResourceUnavailableException, ConcurrentOperationException {
|
||||
VirtualMachine result = _mgr.stopSystemVM(this);
|
||||
if (result != null) {
|
||||
SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ public class StopVMCmd extends BaseAsyncCmd {
|
|||
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
|
||||
private Long id;
|
||||
|
||||
@Parameter(name=ApiConstants.FORCED, type=CommandType.BOOLEAN, required=false, description="Force stop the VM. The caller knows the VM is stopped.")
|
||||
private Boolean forced;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
|
|
@ -87,18 +90,24 @@ public class StopVMCmd extends BaseAsyncCmd {
|
|||
return "stopping user vm: " + getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncJob.Type getInstanceType() {
|
||||
return AsyncJob.Type.VirtualMachine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getInstanceId() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
public boolean isForced() {
|
||||
return (forced != null) ? forced : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws ServerApiException, ConcurrentOperationException{
|
||||
UserContext.current().setEventDetails("Vm Id: "+getId());
|
||||
UserVm result = _userVmService.stopVirtualMachine(this);
|
||||
UserVm result = _userVmService.stopVirtualMachine(getId(), isForced());
|
||||
if (result != null) {
|
||||
UserVmResponse response = _responseGenerator.createUserVmResponse(result);
|
||||
response.setResponseName(getCommandName());
|
||||
|
|
|
|||
|
|
@ -46,12 +46,13 @@ public interface VirtualNetworkApplianceService{
|
|||
|
||||
/**
|
||||
* Stops domain router
|
||||
* @param id of the router
|
||||
* @param id of the router
|
||||
* @param forced just do it. caller knows best.
|
||||
* @return router if successful, null otherwise
|
||||
* @throws ConcurrentOperationException
|
||||
* @throws ResourceUnavailableException
|
||||
* @throws InvalidParameterValueException, PermissionDeniedException
|
||||
*/
|
||||
VirtualRouter stopRouter(long routerId) throws InvalidParameterValueException, PermissionDeniedException, ResourceUnavailableException, ConcurrentOperationException;
|
||||
VirtualRouter stopRouter(long routerId, boolean forced) throws InvalidParameterValueException, PermissionDeniedException, ResourceUnavailableException, ConcurrentOperationException;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import com.cloud.utils.component.Adapter;
|
|||
public interface RemoteAccessVpnElement extends Adapter {
|
||||
String[] applyVpnUsers(RemoteAccessVpn vpn, List<? extends VpnUser> users) throws ResourceUnavailableException;
|
||||
|
||||
boolean start(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException;
|
||||
boolean startVpn(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException;
|
||||
|
||||
boolean stop(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException;
|
||||
boolean stopVpn(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,9 +83,11 @@ import com.cloud.dc.Pod;
|
|||
import com.cloud.dc.Vlan;
|
||||
import com.cloud.domain.Domain;
|
||||
import com.cloud.event.Event;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
|
|
@ -218,7 +220,7 @@ public interface ManagementService {
|
|||
*/
|
||||
List<? extends GuestOsCategory> listGuestOSCategoriesByCriteria(ListGuestOsCategoriesCmd cmd);
|
||||
|
||||
VirtualMachine stopSystemVM(StopSystemVmCmd cmd);
|
||||
VirtualMachine stopSystemVM(StopSystemVmCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException;
|
||||
VirtualMachine startSystemVM(StartSystemVMCmd cmd);
|
||||
VirtualMachine rebootSystemVM(RebootSystemVmCmd cmd);
|
||||
VirtualMachine destroySystemVM(DestroySystemVmCmd cmd);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import java.util.List;
|
|||
|
||||
import javax.naming.InsufficientResourcesException;
|
||||
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.commands.AttachVolumeCmd;
|
||||
import com.cloud.api.commands.CreateTemplateCmd;
|
||||
import com.cloud.api.commands.CreateVMGroupCmd;
|
||||
|
|
@ -34,7 +33,6 @@ import com.cloud.api.commands.RebootVMCmd;
|
|||
import com.cloud.api.commands.RecoverVMCmd;
|
||||
import com.cloud.api.commands.ResetVMPasswordCmd;
|
||||
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.exception.ConcurrentOperationException;
|
||||
|
|
@ -92,7 +90,6 @@ public interface UserVmService {
|
|||
Volume detachVolumeFromVM(DetachVolumeCmd cmmd);
|
||||
|
||||
UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, ExecutionException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException;
|
||||
UserVm stopVirtualMachine(StopVMCmd cmd) throws ServerApiException, ConcurrentOperationException;
|
||||
UserVm rebootVirtualMachine(RebootVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException;
|
||||
UserVm updateVirtualMachine(UpdateVMCmd cmd);
|
||||
UserVm recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException;
|
||||
|
|
@ -157,7 +154,7 @@ public interface UserVmService {
|
|||
*/
|
||||
UserVm upgradeVirtualMachine(UpgradeVMCmd cmd);
|
||||
|
||||
UserVm stopVirtualMachine(long vmId) throws ConcurrentOperationException;
|
||||
UserVm stopVirtualMachine(long vmId, boolean forced) throws ConcurrentOperationException;
|
||||
|
||||
UserVm startVirtualMachine(long vmId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
|
||||
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ public class DhcpElement extends AdapterBase implements NetworkElement, Password
|
|||
if (router == null) {
|
||||
return true;
|
||||
}
|
||||
return (_routerMgr.stopRouter(router.getId()) != null);
|
||||
return (_routerMgr.stop(router, false, context.getCaller(), context.getAccount()) != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
|
|||
|
||||
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
|
||||
|
||||
@Inject NetworkDao _networkConfigDao;
|
||||
@Inject NetworkDao _networksDao;
|
||||
@Inject NetworkManager _networkMgr;
|
||||
@Inject LoadBalancingRulesManager _lbMgr;
|
||||
@Inject NetworkOfferingDao _networkOfferingDao;
|
||||
|
|
@ -204,7 +204,7 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
|
|||
|
||||
@Override
|
||||
public String[] applyVpnUsers(RemoteAccessVpn vpn, List<? extends VpnUser> users) throws ResourceUnavailableException{
|
||||
Network network = _networkConfigDao.findById(vpn.getNetworkId());
|
||||
Network network = _networksDao.findById(vpn.getNetworkId());
|
||||
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
|
||||
if (canHandle(network.getGuestType(),dc)) {
|
||||
return _routerMgr.applyVpnUsers(network, users);
|
||||
|
|
@ -215,7 +215,7 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean start(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException {
|
||||
public boolean startVpn(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException {
|
||||
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
|
||||
if (canHandle(network.getGuestType(),dc)) {
|
||||
return _routerMgr.startRemoteAccessVpn(network, vpn);
|
||||
|
|
@ -226,7 +226,7 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean stop(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException {
|
||||
public boolean stopVpn(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException {
|
||||
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
|
||||
if (canHandle(network.getGuestType(),dc)) {
|
||||
return _routerMgr.deleteRemoteAccessVpn(network, vpn);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import com.cloud.network.VirtualNetworkApplianceService;
|
|||
import com.cloud.network.VpnUser;
|
||||
import com.cloud.network.lb.LoadBalancingRule;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.vm.NicProfile;
|
||||
|
|
@ -86,4 +87,5 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA
|
|||
|
||||
VirtualRouter getRouterForNetwork(long networkId);
|
||||
|
||||
VirtualRouter stop(VirtualRouter router, boolean forced, User callingUser, Account callingAccount) throws ConcurrentOperationException, ResourceUnavailableException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -273,14 +273,12 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
|
||||
int _routerRamSize;
|
||||
int _retry = 2;
|
||||
String _domain;
|
||||
String _instance;
|
||||
String _mgmt_host;
|
||||
|
||||
int _routerCleanupInterval = 3600;
|
||||
int _routerStatsInterval = 300;
|
||||
private ServiceOfferingVO _offering;
|
||||
String _networkDomain;
|
||||
|
||||
ScheduledExecutorService _executor;
|
||||
|
||||
|
|
@ -414,7 +412,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
|
||||
|
||||
@Override
|
||||
public VirtualRouter stopRouter(long routerId) throws ResourceUnavailableException, ConcurrentOperationException {
|
||||
public VirtualRouter stopRouter(long routerId, boolean forced) throws ResourceUnavailableException, ConcurrentOperationException {
|
||||
UserContext context = UserContext.current();
|
||||
Account account = context.getCaller();
|
||||
|
||||
|
|
@ -428,7 +426,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
|
||||
UserVO user = _userDao.findById(UserContext.current().getCallerUserId());
|
||||
|
||||
return this.stop(router, user, account);
|
||||
return stop(router, forced, user, account);
|
||||
}
|
||||
|
||||
@DB
|
||||
|
|
@ -505,7 +503,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
|
||||
@Override
|
||||
public VirtualRouter rebootRouter(long routerId, boolean restartNetwork) throws InvalidParameterValueException, PermissionDeniedException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
|
||||
Account account = UserContext.current().getCaller();
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
// verify parameters
|
||||
DomainRouterVO router = _routerDao.findById(routerId);
|
||||
|
|
@ -513,7 +511,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
throw new InvalidParameterValueException("Unable to find domain router with id " + routerId + ".");
|
||||
}
|
||||
|
||||
if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), router.getDomainId())) {
|
||||
if ((caller != null) && !_domainDao.isChildDomain(caller.getDomainId(), router.getDomainId())) {
|
||||
throw new PermissionDeniedException("Unable to reboot domain router with id " + routerId + ". Permission denied");
|
||||
}
|
||||
|
||||
|
|
@ -523,9 +521,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
throw new ResourceUnavailableException("Unable to reboot domR, it is not in right state " + router.getState(), DataCenter.class, router.getDataCenterId());
|
||||
}
|
||||
|
||||
UserVO user = _userDao.findById(UserContext.current().getCallerUserId());
|
||||
s_logger.debug("Stopping and starting router " + router + " as a part of router reboot");
|
||||
|
||||
if (stopRouter(routerId) != null) {
|
||||
if (stop(router, false, user, caller) != null) {
|
||||
return startRouter(routerId, restartNetwork);
|
||||
} else {
|
||||
throw new CloudRuntimeException("Failed to reboot router " + router);
|
||||
|
|
@ -543,7 +542,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
|
||||
|
||||
_mgmt_host = configs.get("host");
|
||||
_routerRamSize = NumbersUtil.parseInt(configs.get("router.ram.size"), 128);
|
||||
_routerRamSize = NumbersUtil.parseInt(configs.get(Config.RouterRamSize.key()), DEFAULT_ROUTER_VM_RAMSIZE);
|
||||
|
||||
String value = configs.get("start.retry");
|
||||
_retry = NumbersUtil.parseInt(value, 2);
|
||||
|
|
@ -554,18 +553,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
value = configs.get("router.cleanup.interval");
|
||||
_routerCleanupInterval = NumbersUtil.parseInt(value, 3600);
|
||||
|
||||
_domain = configs.get("domain");
|
||||
if (_domain == null) {
|
||||
_domain = "foo.com";
|
||||
}
|
||||
|
||||
_instance = configs.get("instance.name");
|
||||
if (_instance == null) {
|
||||
_instance = "DEFAULT";
|
||||
}
|
||||
|
||||
_networkDomain = configs.get("guest.domain.suffix");
|
||||
|
||||
s_logger.info("Router configurations: " + "ramsize=" + _routerRamSize);
|
||||
|
||||
final UserStatisticsDao statsDao = locator.getDao(UserStatisticsDao.class);
|
||||
|
|
@ -626,23 +618,22 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final List<Long> ids = findLonelyRouters();
|
||||
Long size;
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
size = 0L;
|
||||
} else {
|
||||
size = Long.valueOf(ids.size());
|
||||
List<Long> ids = findLonelyRouters();
|
||||
|
||||
s_logger.trace("Found " + ids.size() + " routers to stop. ");
|
||||
|
||||
for (Long id : ids) {
|
||||
try {
|
||||
DomainRouterVO router = _routerDao.findById(id);
|
||||
if (stop(router, false, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()) != null) {
|
||||
s_logger.info("Successfully stopped a rather lonely " + router);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to stop router " + id, e);
|
||||
}
|
||||
}
|
||||
|
||||
s_logger.info("Found " + size + " routers to stop. ");
|
||||
|
||||
if (ids != null) {
|
||||
for (final Long id : ids) {
|
||||
stopRouter(id);
|
||||
}
|
||||
}
|
||||
|
||||
s_logger.info("Done my job. Time to rest.");
|
||||
s_logger.trace("Done my job. Time to rest.");
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to stop routers. Will retry. ", e);
|
||||
}
|
||||
|
|
@ -1174,12 +1165,17 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
}
|
||||
}
|
||||
|
||||
private DomainRouterVO stop(DomainRouterVO router, User user, Account caller) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
@Override
|
||||
public DomainRouterVO stop(VirtualRouter router, boolean forced, User user, Account caller) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
s_logger.debug("Stopping router " + router);
|
||||
if (_itMgr.stop(router, user, caller)) {
|
||||
return _routerDao.findById(router.getId());
|
||||
} else {
|
||||
return null;
|
||||
try {
|
||||
if (_itMgr.advanceStop((DomainRouterVO)router, forced, user, caller)) {
|
||||
return _routerDao.findById(router.getId());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (OperationTimedoutException e) {
|
||||
throw new CloudRuntimeException("Unable to stop " + router, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag
|
|||
boolean success = false;
|
||||
try {
|
||||
for (RemoteAccessVpnElement element : elements) {
|
||||
if (element.stop(network, vpn)) {
|
||||
if (element.stopVpn(network, vpn)) {
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -312,7 +312,7 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag
|
|||
boolean started = false;
|
||||
try {
|
||||
for (RemoteAccessVpnElement element : elements) {
|
||||
if (element.start(network, vpn)) {
|
||||
if (element.startVpn(network, vpn)) {
|
||||
started = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -269,6 +269,7 @@ import com.cloud.vm.UserVmVO;
|
|||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachineManager;
|
||||
import com.cloud.vm.dao.ConsoleProxyDao;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.InstanceGroupDao;
|
||||
|
|
@ -319,6 +320,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
private final NicDao _nicDao;
|
||||
private final NetworkDao _networkDao;
|
||||
private final StorageManager _storageMgr;
|
||||
private final VirtualMachineManager _itMgr;
|
||||
|
||||
private final Adapters<UserAuthenticator> _userAuthenticators;
|
||||
private final HostPodDao _hostPodDao;
|
||||
|
|
@ -342,8 +344,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
|
||||
private final Map<String, String> _configs;
|
||||
|
||||
private String _domain;
|
||||
|
||||
private final int _routerRamSize;
|
||||
private final int _proxyRamSize;
|
||||
private final int _ssRamSize;
|
||||
|
|
@ -407,20 +407,13 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
_tmpltMgr = locator.getManager(TemplateManager.class);
|
||||
_uploadMonitor = locator.getManager(UploadMonitor.class);
|
||||
_sshKeyPairDao = locator.getDao(SSHKeyPairDao.class);
|
||||
_itMgr = locator.getManager(VirtualMachineManager.class);
|
||||
|
||||
_userAuthenticators = locator.getAdapters(UserAuthenticator.class);
|
||||
if (_userAuthenticators == null || !_userAuthenticators.isSet()) {
|
||||
s_logger.error("Unable to find an user authenticator.");
|
||||
}
|
||||
|
||||
_domain = _configs.get("domain");
|
||||
if (_domain == null) {
|
||||
_domain = ".myvm.com";
|
||||
}
|
||||
if (!_domain.startsWith(".")) {
|
||||
_domain = "." + _domain;
|
||||
}
|
||||
|
||||
String value = _configs.get("account.cleanup.interval");
|
||||
int cleanup = NumbersUtil.parseInt(value, 60 * 60 * 24); // 1 hour.
|
||||
|
||||
|
|
@ -3996,21 +3989,29 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VMInstanceVO stopSystemVM(StopSystemVmCmd cmd) {
|
||||
public VMInstanceVO stopSystemVM(StopSystemVmCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException {
|
||||
Long id = cmd.getId();
|
||||
|
||||
// verify parameters
|
||||
VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(id, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);
|
||||
if (systemVm == null) {
|
||||
throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a system vm with id " + id);
|
||||
throw new InvalidParameterValueException("unable to find a system vm with id " + id);
|
||||
}
|
||||
|
||||
User caller = _userDao.findById(UserContext.current().getCallerUserId());
|
||||
|
||||
// FIXME: We need to return the system VM from this method, so what do we do with the boolean response from stopConsoleProxy and stopSecondaryStorageVm?
|
||||
if (systemVm.getType().equals(VirtualMachine.Type.ConsoleProxy)){
|
||||
return stopConsoleProxy(id);
|
||||
} else {
|
||||
return stopSecondaryStorageVm(id);
|
||||
}
|
||||
try {
|
||||
if (_itMgr.advanceStop(systemVm, cmd.isForced(), caller, UserContext.current().getCaller())) {
|
||||
if (systemVm.getType() == VirtualMachine.Type.ConsoleProxy) {
|
||||
return _consoleProxyDao.findById(systemVm.getId());
|
||||
} else if (systemVm.getType() == VirtualMachine.Type.SecondaryStorageVm) {
|
||||
return _secStorageVmDao.findById(systemVm.getId());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (OperationTimedoutException e) {
|
||||
throw new CloudRuntimeException("Unable to stop " + systemVm, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -64,7 +64,6 @@ import com.cloud.api.commands.RebootVMCmd;
|
|||
import com.cloud.api.commands.RecoverVMCmd;
|
||||
import com.cloud.api.commands.ResetVMPasswordCmd;
|
||||
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.AsyncInstanceCreateStatus;
|
||||
|
|
@ -1611,11 +1610,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
return _vmDao.findById(id);
|
||||
}
|
||||
|
||||
@Override @ActionEvent (eventType=EventTypes.EVENT_VM_STOP, eventDescription="stopping Vm", async=true)
|
||||
public UserVm stopVirtualMachine(StopVMCmd cmd) throws ServerApiException, ConcurrentOperationException{
|
||||
return stopVirtualMachine(cmd.getId());
|
||||
}
|
||||
|
||||
@Override @ActionEvent (eventType=EventTypes.EVENT_VM_START, eventDescription="starting Vm", async=true)
|
||||
public UserVm startVirtualMachine(StartVMCmd cmd) throws ExecutionException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
|
||||
return startVirtualMachine(cmd.getId());
|
||||
|
|
@ -2259,8 +2253,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
return findById(VirtualMachineName.getVmId(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVm stopVirtualMachine(long vmId) throws ConcurrentOperationException {
|
||||
@Override @ActionEvent (eventType=EventTypes.EVENT_VM_STOP, eventDescription="stopping Vm", async=true)
|
||||
public UserVm stopVirtualMachine(long vmId, boolean forced) throws ConcurrentOperationException {
|
||||
|
||||
//Input validation
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
|
@ -2280,9 +2274,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
UserVO user = _userDao.findById(userId);
|
||||
|
||||
try {
|
||||
_itMgr.stop(vm, user, caller);
|
||||
_itMgr.advanceStop(vm, forced, user, caller);
|
||||
} catch (ResourceUnavailableException e) {
|
||||
throw new CloudRuntimeException("Unable to contact the agent to stop the virtual machine " + vm, e);
|
||||
} catch (OperationTimedoutException e) {
|
||||
throw new CloudRuntimeException("Unable to contact the agent to stop the virtual machine " + vm, e);
|
||||
}
|
||||
|
||||
return _vmDao.findById(vmId);
|
||||
|
|
|
|||
|
|
@ -76,8 +76,6 @@ import com.cloud.deploy.DeploymentPlan;
|
|||
import com.cloud.deploy.DeploymentPlanner;
|
||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.event.UsageEventVO;
|
||||
import com.cloud.event.dao.UsageEventDao;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
|
|
@ -1035,7 +1033,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, StateLi
|
|||
throw new AgentUnavailableException("Operation timed out: ", dstHostId);
|
||||
} finally {
|
||||
if (!migrated) {
|
||||
s_logger.info("Migration was unsuccessful. Cleaning up: " + vm.toString());
|
||||
s_logger.info("Migration was unsuccessful. Cleaning up: " + vm);
|
||||
|
||||
_alertMgr.sendAlert(alertType, fromHost.getDataCenterId(), fromHost.getPodId(), "Unable to migrate vm " + vm.getName() + " from host " + fromHost.getName() + " in zone " + dest.getDataCenter().getName() + " and pod " + dest.getPod().getName(), "Migrate Command failed. Please check logs.");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue