mirror of https://github.com/apache/cloudstack.git
more changes in the api
This commit is contained in:
parent
5356d165ff
commit
25e4ed6997
|
|
@ -18,17 +18,18 @@
|
|||
|
||||
package com.cloud.exception;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
/**
|
||||
* @author chiradeep
|
||||
*
|
||||
*/
|
||||
public class InvalidParameterValueException extends ManagementServerException {
|
||||
public class InvalidParameterValueException extends CloudRuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -2232066904895010203L;
|
||||
|
||||
public InvalidParameterValueException(String message) {
|
||||
super(message);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,11 +17,13 @@
|
|||
*/
|
||||
package com.cloud.exception;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
/**
|
||||
* @author chiradeep
|
||||
*
|
||||
*/
|
||||
public class PermissionDeniedException extends ManagementServerException {
|
||||
public class PermissionDeniedException extends CloudRuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -4631412831814398074L;
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ import com.cloud.user.AccountManager;
|
|||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.UserVmManager;
|
||||
import com.cloud.vm.UserVmService;
|
||||
|
||||
/**
|
||||
* A class that dispatches API commands to the appropriate manager for execution.
|
||||
|
|
@ -65,7 +65,7 @@ public class ApiDispatcher {
|
|||
private SnapshotManager _snapshotMgr;
|
||||
private StorageManager _storageMgr;
|
||||
private TemplateManager _templateMgr;
|
||||
private UserVmManager _userVmMgr;
|
||||
private UserVmService _userVmMgr;
|
||||
private DomainRouterService _domainRouterService;
|
||||
|
||||
// singleton class
|
||||
|
|
@ -87,7 +87,7 @@ public class ApiDispatcher {
|
|||
_snapshotMgr = locator.getManager(SnapshotManager.class);
|
||||
_storageMgr = locator.getManager(StorageManager.class);
|
||||
_templateMgr = locator.getManager(TemplateManager.class);
|
||||
_userVmMgr = locator.getManager(UserVmManager.class);
|
||||
_userVmMgr = locator.getManager(UserVmService.class);
|
||||
_domainRouterService = locator.getManager(DomainRouterService.class);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public class CancelMaintenanceCmd extends BaseAsyncCmd {
|
|||
|
||||
@Override
|
||||
public long getAccountId() {
|
||||
Account account = (Account)UserContext.current().getAccount();
|
||||
Account account = UserContext.current().getAccount();
|
||||
if (account != null) {
|
||||
return account.getId();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ public class DeployVmCmd extends BaseAsyncCmd {
|
|||
|
||||
@Override
|
||||
public long getAccountId() {
|
||||
Account account = (Account)UserContext.current().getAccount();
|
||||
Account account = UserContext.current().getAccount();
|
||||
if ((account == null) || isAdmin(account.getType())) {
|
||||
if ((domainId != null) && (accountName != null)) {
|
||||
Account userAccount = ApiDBUtils.findAccountByNameDomain(accountName, domainId);
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class PrepareForMaintenanceCmd extends BaseAsyncCmd {
|
|||
|
||||
@Override
|
||||
public long getAccountId() {
|
||||
Account account = (Account)UserContext.current().getAccount();
|
||||
Account account = UserContext.current().getAccount();
|
||||
if (account != null) {
|
||||
return account.getId();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ public class ReconnectHostCmd extends BaseAsyncCmd {
|
|||
|
||||
@Override
|
||||
public long getAccountId() {
|
||||
Account account = (Account)UserContext.current().getAccount();
|
||||
Account account = UserContext.current().getAccount();
|
||||
if (account != null) {
|
||||
return account.getId();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,5 +39,5 @@ public interface DomainRouterService extends Manager {
|
|||
* @return router if successful, null otherwise
|
||||
* @throws InvalidParameterValueException, PermissionDeniedException
|
||||
*/
|
||||
DomainRouterVO stopRouter(StopRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
|
||||
DomainRouterVO stopRouter(StopRouterCmd cmd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,23 +21,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
|
||||
import com.cloud.agent.api.VmStatsEntry;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.commands.AttachVolumeCmd;
|
||||
import com.cloud.api.commands.CreateTemplateCmd;
|
||||
import com.cloud.api.commands.CreateVMGroupCmd;
|
||||
import com.cloud.api.commands.DeleteVMGroupCmd;
|
||||
import com.cloud.api.commands.DeployVmCmd;
|
||||
import com.cloud.api.commands.DestroyVMCmd;
|
||||
import com.cloud.api.commands.DetachVolumeCmd;
|
||||
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.executor.OperationResponse;
|
||||
import com.cloud.async.executor.RebootVMExecutor;
|
||||
import com.cloud.async.executor.StartVMExecutor;
|
||||
import com.cloud.async.executor.StopVMExecutor;
|
||||
import com.cloud.async.executor.VMOperationParam;
|
||||
|
|
@ -46,10 +30,7 @@ import com.cloud.exception.ConcurrentOperationException;
|
|||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientStorageCapacityException;
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.network.security.NetworkGroupVO;
|
||||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
|
|
@ -101,38 +82,10 @@ public interface UserVmManager extends Manager, VirtualMachineManager<UserVmVO>
|
|||
|
||||
UserVmVO createDirectlyAttachedVMExternal(Long vmId, long userId, AccountVO account, DataCenterVO dc, ServiceOfferingVO offering, VMTemplateVO template, DiskOfferingVO diskOffering, String displayName, String userData, List<StoragePoolVO> a, List<NetworkGroupVO> networkGroupVO, long startEventId, long size) throws InternalErrorException, ResourceAllocationException;
|
||||
|
||||
/**
|
||||
* Destroys one virtual machine
|
||||
* @param userId the id of the user performing the action
|
||||
* @param vmId the id of the virtual machine.
|
||||
*/
|
||||
boolean destroyVm(DestroyVMCmd cmd);
|
||||
boolean destroyVirtualMachine(long userId, long vmId);
|
||||
// OperationResponse executeDestroyVM(DestroyVMExecutor executor, VMOperationParam param);
|
||||
|
||||
|
||||
/**
|
||||
* Resets the password of a virtual machine.
|
||||
* @param cmd - the command specifying vmId, password
|
||||
* @return the VM if reset worked successfully, null otherwise
|
||||
*/
|
||||
UserVm resetVMPassword(ResetVMPasswordCmd cmd);
|
||||
|
||||
/**
|
||||
* Attaches the specified volume to the specified VM
|
||||
* @param cmd - the command specifying volumeId and vmId
|
||||
* @throws InternalErrorException, InvalidParameterValueException, PermissionDeniedException
|
||||
*/
|
||||
void attachVolumeToVM(AttachVolumeCmd cmd) throws InternalErrorException, InvalidParameterValueException, PermissionDeniedException;
|
||||
|
||||
/**
|
||||
* Detaches the specified volume from the VM it is currently attached to.
|
||||
* @param cmd - the command specifying volumeId
|
||||
* @throws InternalErrorException
|
||||
* @throws InvalidParameterValueException
|
||||
*/
|
||||
void detachVolumeFromVM(DetachVolumeCmd cmmd) throws InternalErrorException, InvalidParameterValueException;
|
||||
|
||||
/**
|
||||
* Attaches an ISO to the virtual CDROM device of the specified VM. Will eject any existing virtual CDROM if isoPath is null.
|
||||
* @param vmId
|
||||
|
|
@ -165,7 +118,6 @@ 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
|
||||
|
|
@ -175,19 +127,9 @@ public interface UserVmManager extends Manager, VirtualMachineManager<UserVmVO>
|
|||
* @return true if stopped; false if problems.
|
||||
*/
|
||||
boolean stopVirtualMachine(long userId, long vmId, long eventId);
|
||||
UserVmVO stopVirtualMachine(StopVMCmd cmd) throws ServerApiException;
|
||||
OperationResponse executeStopVM(StopVMExecutor executor, VMOperationParam param);
|
||||
void completeStopCommand(long userId, UserVmVO vm, Event e, long startEventId);
|
||||
|
||||
|
||||
/**
|
||||
* upgrade the service offering of the virtual machine
|
||||
* @param cmd - the command specifying vmId and new serviceOfferingId
|
||||
* @return the vm
|
||||
* @throws InvalidParameterValueException
|
||||
*/
|
||||
UserVm upgradeVirtualMachine(UpgradeVMCmd cmd) throws ServerApiException, InvalidParameterValueException;
|
||||
|
||||
/**
|
||||
* Obtains statistics for a list of host or VMs; CPU and network utilization
|
||||
* @param host ID
|
||||
|
|
@ -198,28 +140,6 @@ public interface UserVmManager extends Manager, VirtualMachineManager<UserVmVO>
|
|||
*/
|
||||
HashMap<Long, VmStatsEntry> getVirtualMachineStatistics(long hostId, String hostName, List<Long> vmIds) throws InternalErrorException;
|
||||
|
||||
boolean rebootVirtualMachine(RebootVMCmd cmd);
|
||||
OperationResponse executeRebootVM(RebootVMExecutor executor, VMOperationParam param);
|
||||
|
||||
boolean recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException, InternalErrorException;
|
||||
|
||||
/**
|
||||
* Create a template database record in preparation for creating a private template.
|
||||
* @param cmd the command object that defines the name, display text, snapshot/volume, bits, public/private, etc.
|
||||
* for the private template
|
||||
* @return the vm template object if successful, null otherwise
|
||||
* @throws InvalidParameterValueException, PermissionDeniedException
|
||||
*/
|
||||
VMTemplateVO createPrivateTemplateRecord(CreateTemplateCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
|
||||
|
||||
/**
|
||||
* Creates a private template from a snapshot of a VM
|
||||
* @param cmd - the command specifying snapshotId, name, description
|
||||
* @return a template if successfully created, null otherwise
|
||||
* @throws InvalidParameterValueException
|
||||
*/
|
||||
VMTemplateVO createPrivateTemplate(CreateTemplateCmd cmd) throws InternalErrorException;
|
||||
|
||||
boolean destroyTemplateSnapshot(Long userId, long snapshotId);
|
||||
|
||||
/**
|
||||
|
|
@ -235,14 +155,6 @@ public interface UserVmManager extends Manager, VirtualMachineManager<UserVmVO>
|
|||
*/
|
||||
void releaseGuestIpAddress(UserVmVO userVm);
|
||||
|
||||
/**
|
||||
* Creates a vm group.
|
||||
* @param name - name of the group
|
||||
* @param accountId - accountId
|
||||
*/
|
||||
InstanceGroupVO createVmGroup(CreateVMGroupCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
|
||||
|
||||
boolean deleteVmGroup(DeleteVMGroupCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
|
||||
boolean deleteVmGroup(long groupId);
|
||||
|
||||
boolean addInstanceToGroup(long userVmId, String group);
|
||||
|
|
@ -250,10 +162,8 @@ public interface UserVmManager extends Manager, VirtualMachineManager<UserVmVO>
|
|||
InstanceGroupVO getGroupForVm(long vmId);
|
||||
|
||||
void removeInstanceFromGroup(long vmId);
|
||||
|
||||
@Deprecated
|
||||
OperationResponse executeStopVM(StopVMExecutor executor, VMOperationParam param);
|
||||
|
||||
void updateVirtualMachine(UpdateVMCmd cmd);
|
||||
|
||||
UserVm createVirtualMachine(DeployVmCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
UserVm startVirtualMachine(DeployVmCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -202,8 +202,8 @@ import com.cloud.vm.dao.InstanceGroupDao;
|
|||
import com.cloud.vm.dao.InstanceGroupVMMapDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
|
||||
@Local(value={UserVmManager.class})
|
||||
public class UserVmManagerImpl implements UserVmManager {
|
||||
@Local(value={UserVmManager.class, UserVmService.class})
|
||||
public class UserVmManagerImpl implements UserVmManager, UserVmService {
|
||||
private static final Logger s_logger = Logger.getLogger(UserVmManagerImpl.class);
|
||||
private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 3; // 3 seconds
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,128 @@
|
|||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.vm;
|
||||
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.commands.AttachVolumeCmd;
|
||||
import com.cloud.api.commands.CreateTemplateCmd;
|
||||
import com.cloud.api.commands.CreateVMGroupCmd;
|
||||
import com.cloud.api.commands.DeleteVMGroupCmd;
|
||||
import com.cloud.api.commands.DeployVmCmd;
|
||||
import com.cloud.api.commands.DestroyVMCmd;
|
||||
import com.cloud.api.commands.DetachVolumeCmd;
|
||||
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.executor.OperationResponse;
|
||||
import com.cloud.async.executor.RebootVMExecutor;
|
||||
import com.cloud.async.executor.VMOperationParam;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.exception.ExecutionException;
|
||||
|
||||
public interface UserVmService extends Manager {
|
||||
/**
|
||||
* Destroys one virtual machine
|
||||
* @param userId the id of the user performing the action
|
||||
* @param vmId the id of the virtual machine.
|
||||
*/
|
||||
boolean destroyVm(DestroyVMCmd cmd);
|
||||
|
||||
/**
|
||||
* Resets the password of a virtual machine.
|
||||
* @param cmd - the command specifying vmId, password
|
||||
* @return the VM if reset worked successfully, null otherwise
|
||||
*/
|
||||
UserVm resetVMPassword(ResetVMPasswordCmd cmd);
|
||||
|
||||
/**
|
||||
* Attaches the specified volume to the specified VM
|
||||
* @param cmd - the command specifying volumeId and vmId
|
||||
* @throws InternalErrorException, InvalidParameterValueException, PermissionDeniedException
|
||||
*/
|
||||
void attachVolumeToVM(AttachVolumeCmd cmd) throws InternalErrorException, InvalidParameterValueException, PermissionDeniedException;
|
||||
|
||||
/**
|
||||
* Detaches the specified volume from the VM it is currently attached to.
|
||||
* @param cmd - the command specifying volumeId
|
||||
* @throws InternalErrorException
|
||||
* @throws InvalidParameterValueException
|
||||
*/
|
||||
void detachVolumeFromVM(DetachVolumeCmd cmmd) throws InternalErrorException, InvalidParameterValueException;
|
||||
|
||||
UserVmVO startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, ExecutionException, ConcurrentOperationException;
|
||||
UserVmVO stopVirtualMachine(StopVMCmd cmd) throws ServerApiException;
|
||||
boolean rebootVirtualMachine(RebootVMCmd cmd);
|
||||
|
||||
@Deprecated
|
||||
OperationResponse executeRebootVM(RebootVMExecutor executor, VMOperationParam param);
|
||||
|
||||
boolean recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException, InternalErrorException;
|
||||
|
||||
/**
|
||||
* Create a template database record in preparation for creating a private template.
|
||||
* @param cmd the command object that defines the name, display text, snapshot/volume, bits, public/private, etc.
|
||||
* for the private template
|
||||
* @return the vm template object if successful, null otherwise
|
||||
* @throws InvalidParameterValueException, PermissionDeniedException
|
||||
*/
|
||||
VMTemplateVO createPrivateTemplateRecord(CreateTemplateCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
|
||||
|
||||
/**
|
||||
* Creates a private template from a snapshot of a VM
|
||||
* @param cmd - the command specifying snapshotId, name, description
|
||||
* @return a template if successfully created, null otherwise
|
||||
* @throws InvalidParameterValueException
|
||||
*/
|
||||
VMTemplateVO createPrivateTemplate(CreateTemplateCmd cmd) throws InternalErrorException;
|
||||
|
||||
void updateVirtualMachine(UpdateVMCmd cmd);
|
||||
|
||||
UserVm createVirtualMachine(DeployVmCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
UserVm startVirtualMachine(DeployVmCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
|
||||
/**
|
||||
* Creates a vm group.
|
||||
* @param name - name of the group
|
||||
* @param accountId - accountId
|
||||
*/
|
||||
InstanceGroupVO createVmGroup(CreateVMGroupCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
|
||||
|
||||
boolean deleteVmGroup(DeleteVMGroupCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
|
||||
|
||||
/**
|
||||
* upgrade the service offering of the virtual machine
|
||||
* @param cmd - the command specifying vmId and new serviceOfferingId
|
||||
* @return the vm
|
||||
* @throws InvalidParameterValueException
|
||||
*/
|
||||
UserVm upgradeVirtualMachine(UpgradeVMCmd cmd) throws ServerApiException, InvalidParameterValueException;
|
||||
}
|
||||
Loading…
Reference in New Issue