Search in sources :

Example 1 with BaseAsyncCreateCmd

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();
}
Also used : Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) HashMap(java.util.HashMap) BaseAsyncCreateCmd(com.cloud.api.BaseAsyncCreateCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 2 with BaseAsyncCreateCmd

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);
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) BaseAsyncCreateCmd(com.cloud.api.BaseAsyncCreateCmd) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) BaseCmd(com.cloud.api.BaseCmd)

Example 3 with BaseAsyncCreateCmd

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
            }
        }
    }
}
Also used : Account(com.cloud.user.Account) ControlledEntity(com.cloud.acl.ControlledEntity) BaseAsyncCreateCmd(com.cloud.api.BaseAsyncCreateCmd) InfrastructureEntity(com.cloud.acl.InfrastructureEntity) HashMap(java.util.HashMap) Map(java.util.Map) AccessType(com.cloud.acl.SecurityChecker.AccessType)

Aggregations

BaseAsyncCreateCmd (com.cloud.api.BaseAsyncCreateCmd)3 Account (com.cloud.user.Account)2 HashMap (java.util.HashMap)2 ControlledEntity (com.cloud.acl.ControlledEntity)1 InfrastructureEntity (com.cloud.acl.InfrastructureEntity)1 AccessType (com.cloud.acl.SecurityChecker.AccessType)1 BaseCmd (com.cloud.api.BaseCmd)1 ServerApiException (com.cloud.api.ServerApiException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1 AccountVO (com.cloud.user.AccountVO)1 UserVO (com.cloud.user.UserVO)1 Map (java.util.Map)1 Test (org.junit.Test)1