use of com.cloud.api.BaseAsyncCreateCmd in project cosmic by MissionCriticalCloud.
the class CommandCreationWorkerTest method testHandle.
@Test
public void testHandle() throws ResourceAllocationException {
// Prepare
final BaseAsyncCreateCmd asyncCreateCmd = mock(BaseAsyncCreateCmd.class);
final Map<String, String> params = new HashMap<>();
final Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
final UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, account);
// Execute
final CommandCreationWorker creationWorker = new CommandCreationWorker();
creationWorker.handle(new DispatchTask(asyncCreateCmd, params));
// Assert
verify(asyncCreateCmd, times(1)).create();
}
use of com.cloud.api.BaseAsyncCreateCmd in project cosmic by MissionCriticalCloud.
the class CommandCreationWorker method handle.
@Override
public void handle(final DispatchTask task) {
final BaseCmd cmd = task.getCmd();
if (cmd instanceof BaseAsyncCreateCmd) {
try {
CallContext.current().setEventDisplayEnabled(cmd.isDisplay());
((BaseAsyncCreateCmd) cmd).create();
} catch (final ResourceAllocationException e) {
throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, e.getMessage(), e);
}
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ATTEMP_TO_CREATE_NON_CREATION_CMD);
}
}
use of com.cloud.api.BaseAsyncCreateCmd in project cosmic by MissionCriticalCloud.
the class ParamProcessWorker method doAccessChecks.
private void doAccessChecks(final BaseCmd cmd, final Map<Object, AccessType> entitiesToAccess) {
final Account caller = CallContext.current().getCallingAccount();
// due to deleteAccount design flaw CLOUDSTACK-6588, we should still include those removed account as well to clean up leftover resources from that account
final Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
if (cmd instanceof BaseAsyncCreateCmd) {
// check that caller can access the owner account.
_accountMgr.checkAccess(caller, null, false, owner);
}
if (!entitiesToAccess.isEmpty()) {
// check that caller can access the owner account.
_accountMgr.checkAccess(caller, null, false, owner);
for (final Map.Entry<Object, AccessType> entry : entitiesToAccess.entrySet()) {
final Object entity = entry.getKey();
if (entity instanceof ControlledEntity) {
_accountMgr.checkAccess(caller, entry.getValue(), true, (ControlledEntity) entity);
} else if (entity instanceof InfrastructureEntity) {
// FIXME: Move this code in adapter, remove code from
// Account manager
}
}
}
}
Aggregations