Search in sources :

Example 1 with User

use of com.cloud.legacymodel.user.User in project cosmic by MissionCriticalCloud.

the class CallContext method register.

public static CallContext register(final long callingUserId, final long callingAccountId, final String contextId) throws CloudAuthenticationException {
    final Account account = s_entityMgr.findById(Account.class, callingAccountId);
    if (account == null) {
        throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, Long.toString(callingAccountId));
    }
    final User user = s_entityMgr.findById(User.class, callingUserId);
    if (user == null) {
        throw new CloudAuthenticationException("The user is no longer current.").add(User.class, Long.toString(callingUserId));
    }
    return register(user, account, contextId);
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) CloudAuthenticationException(com.cloud.legacymodel.exceptions.CloudAuthenticationException)

Example 2 with User

use of com.cloud.legacymodel.user.User in project cosmic by MissionCriticalCloud.

the class CallContext method register.

public static CallContext register(final long callingUserId, final long callingAccountId) throws CloudAuthenticationException {
    final Account account = s_entityMgr.findById(Account.class, callingAccountId);
    if (account == null) {
        throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, Long.toString(callingAccountId));
    }
    final User user = s_entityMgr.findById(User.class, callingUserId);
    if (user == null) {
        throw new CloudAuthenticationException("The user is no longer current.").add(User.class, Long.toString(callingUserId));
    }
    return register(user, account);
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) CloudAuthenticationException(com.cloud.legacymodel.exceptions.CloudAuthenticationException)

Example 3 with User

use of com.cloud.legacymodel.user.User in project cosmic by MissionCriticalCloud.

the class LogContext method register.

public static LogContext register(final String callingUserUuid, final String callingAccountUuid) {
    final Account account = s_entityMgr.findByUuid(Account.class, callingAccountUuid);
    if (account == null) {
        throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, callingAccountUuid);
    }
    final User user = s_entityMgr.findByUuid(User.class, callingUserUuid);
    if (user == null) {
        throw new CloudAuthenticationException("The user is no longer current.").add(User.class, callingUserUuid);
    }
    return register(user, account);
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) CloudAuthenticationException(com.cloud.legacymodel.exceptions.CloudAuthenticationException)

Example 4 with User

use of com.cloud.legacymodel.user.User in project cosmic by MissionCriticalCloud.

the class VirtualMachineManagerImpl method migrateVmWithStorageThroughJobQueue.

public Outcome<VirtualMachine> migrateVmWithStorageThroughJobQueue(final String vmUuid, final long srcHostId, final long destHostId, final Map<Long, Long> volumeToPool) {
    final CallContext context = CallContext.current();
    final User user = context.getCallingUser();
    final Account account = context.getCallingAccount();
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    final List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(VirtualMachineType.Instance, vm.getId(), VmWorkMigrateWithStorage.class.getName());
    VmWorkJobVO workJob = null;
    if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
        assert pendingWorkJobs.size() == 1;
        workJob = pendingWorkJobs.get(0);
    } else {
        workJob = new VmWorkJobVO(context.getContextId());
        workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
        workJob.setCmd(VmWorkMigrateWithStorage.class.getName());
        workJob.setAccountId(account.getId());
        workJob.setUserId(user.getId());
        workJob.setVmType(VirtualMachineType.Instance);
        workJob.setVmInstanceId(vm.getId());
        workJob.setRelated(AsyncJobExecutionContext.getOriginJobId());
        // save work context info (there are some duplications)
        final VmWorkMigrateWithStorage workInfo = new VmWorkMigrateWithStorage(user.getId(), account.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, srcHostId, destHostId, volumeToPool);
        workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
        _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
    }
    AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
    return new VmStateSyncOutcome(workJob, VirtualMachine.PowerState.PowerOn, vm.getId(), destHostId);
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) CallContext(com.cloud.context.CallContext) VmWorkJobVO(com.cloud.framework.jobs.impl.VmWorkJobVO)

Example 5 with User

use of com.cloud.legacymodel.user.User in project cosmic by MissionCriticalCloud.

the class VirtualMachineManagerImpl method startVmThroughJobQueue.

// 
// PowerState report handling for out-of-band changes and handling of left-over transitional VM states
// 
// 
// VM operation based on new sync model
// 
// 
// TODO build a common pattern to reduce code duplication in following methods
// no time for this at current iteration
// 
public Outcome<VirtualMachine> startVmThroughJobQueue(final String vmUuid, final Map<VirtualMachineProfile.Param, Object> params, final DeploymentPlan planToDeploy, final DeploymentPlanner planner) {
    final CallContext context = CallContext.current();
    final User callingUser = context.getCallingUser();
    final Account callingAccount = context.getCallingAccount();
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    VmWorkJobVO workJob = null;
    final List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(VirtualMachineType.Instance, vm.getId(), VmWorkStart.class.getName());
    if (pendingWorkJobs.size() > 0) {
        assert pendingWorkJobs.size() == 1;
        workJob = pendingWorkJobs.get(0);
    } else {
        workJob = new VmWorkJobVO(context.getContextId());
        workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
        workJob.setCmd(VmWorkStart.class.getName());
        workJob.setAccountId(callingAccount.getId());
        workJob.setUserId(callingUser.getId());
        workJob.setStep(VmWorkJobVO.Step.Starting);
        workJob.setVmType(VirtualMachineType.Instance);
        workJob.setVmInstanceId(vm.getId());
        workJob.setRelated(AsyncJobExecutionContext.getOriginJobId());
        // save work context info (there are some duplications)
        final VmWorkStart workInfo = new VmWorkStart(callingUser.getId(), callingAccount.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER);
        workInfo.setPlan(planToDeploy);
        workInfo.setParams(params);
        if (planner != null) {
            workInfo.setDeploymentPlanner(planner.getName());
        }
        workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
        _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
    }
    AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
    return new VmStateSyncOutcome(workJob, VirtualMachine.PowerState.PowerOn, vm.getId(), null);
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) CallContext(com.cloud.context.CallContext) VmWorkJobVO(com.cloud.framework.jobs.impl.VmWorkJobVO)

Aggregations

User (com.cloud.legacymodel.user.User)83 Account (com.cloud.legacymodel.user.Account)71 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)31 CallContext (com.cloud.context.CallContext)27 VmWorkJobVO (com.cloud.framework.jobs.impl.VmWorkJobVO)22 ActionEvent (com.cloud.event.ActionEvent)17 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)17 VMInstanceVO (com.cloud.vm.VMInstanceVO)14 UserAccount (com.cloud.legacymodel.user.UserAccount)12 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)9 ArrayList (java.util.ArrayList)9 CloudAuthenticationException (com.cloud.legacymodel.exceptions.CloudAuthenticationException)8 DomainRouterVO (com.cloud.vm.DomainRouterVO)8 ReservationContext (com.cloud.vm.ReservationContext)7 ReservationContextImpl (com.cloud.vm.ReservationContextImpl)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 ServerApiException (com.cloud.api.ServerApiException)6 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)6 InsufficientCapacityException (com.cloud.legacymodel.exceptions.InsufficientCapacityException)6