Search in sources :

Example 66 with CallContext

use of com.cloud.context.CallContext in project cosmic by MissionCriticalCloud.

the class SystemVmLoadScanner method getCapacityScanTask.

private Runnable getCapacityScanTask() {
    return new ManagedContextRunnable() {

        @Override
        protected void runInContext() {
            final CallContext callContext = CallContext.current();
            AsyncJobExecutionContext.registerPseudoExecutionContext(callContext.getCallingAccountId(), callContext.getCallingUserId());
            reallyRun();
            AsyncJobExecutionContext.unregister();
        }

        private void reallyRun() {
            loadScan();
        }
    };
}
Also used : ManagedContextRunnable(com.cloud.managed.context.ManagedContextRunnable) CallContext(com.cloud.context.CallContext)

Example 67 with CallContext

use of com.cloud.context.CallContext in project cosmic by MissionCriticalCloud.

the class UserVmManagerImpl method finalizeStop.

@Override
public void finalizeStop(final VirtualMachineProfile profile, final Answer answer) {
    final VirtualMachine vm = profile.getVirtualMachine();
    // release elastic IP here
    final IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId());
    if (ip != null && ip.getSystem()) {
        final CallContext ctx = CallContext.current();
        try {
            final long networkId = ip.getAssociatedWithNetworkId();
            final Network guestNetwork = _networkDao.findById(networkId);
            final NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId());
            assert offering.getAssociatePublicIP() : "User VM should not have system owned public IP associated with it when offering configured not to associate " + "public IP.";
            _rulesMgr.disableStaticNat(ip.getId(), ctx.getCallingAccount(), ctx.getCallingUserId(), true);
        } catch (final Exception ex) {
            s_logger.warn("Failed to disable static nat and release system ip " + ip + " as a part of vm " + profile.getVirtualMachine() + " stop due to exception ", ex);
        }
    }
    final List<NicVO> nics = _nicDao.listByVmId(vm.getId());
    for (final NicVO nic : nics) {
        final NetworkVO network = _networkDao.findById(nic.getNetworkId());
        if (network.getTrafficType() == TrafficType.Guest) {
            if (nic.getBroadcastUri() != null && nic.getBroadcastUri().getScheme().equals("pvlan")) {
                final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, "pvlan-nic");
                setupVmForPvlan(false, vm.getHostId(), nicProfile);
            }
        }
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) IPAddressVO(com.cloud.network.dao.IPAddressVO) CallContext(com.cloud.context.CallContext) ExecutionException(com.cloud.utils.exception.ExecutionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineMigrationException(com.cloud.exception.VirtualMachineMigrationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudException(com.cloud.exception.CloudException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) ManagementServerException(com.cloud.exception.ManagementServerException)

Example 68 with CallContext

use of com.cloud.context.CallContext in project cosmic by MissionCriticalCloud.

the class VMSnapshotManagerImpl method deleteAllVMSnapshotsThroughJobQueue.

public Outcome<VirtualMachine> deleteAllVMSnapshotsThroughJobQueue(final Long vmId, final VMSnapshot.Type type) {
    final CallContext context = CallContext.current();
    final User callingUser = context.getCallingUser();
    final Account callingAccount = context.getCallingAccount();
    final VMInstanceVO vm = _vmInstanceDao.findById(vmId);
    final VmWorkJobVO workJob = new VmWorkJobVO(context.getContextId());
    workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
    workJob.setCmd(VmWorkDeleteAllVMSnapshots.class.getName());
    workJob.setAccountId(callingAccount.getId());
    workJob.setUserId(callingUser.getId());
    workJob.setStep(VmWorkJobVO.Step.Starting);
    workJob.setVmType(VirtualMachine.Type.Instance);
    workJob.setVmInstanceId(vm.getId());
    workJob.setRelated(AsyncJobExecutionContext.getOriginJobId());
    // save work context info (there are some duplications)
    final VmWorkDeleteAllVMSnapshots workInfo = new VmWorkDeleteAllVMSnapshots(callingUser.getId(), callingAccount.getId(), vm.getId(), VMSnapshotManagerImpl.VM_WORK_JOB_HANDLER, type);
    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
    _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
    AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
    return new VmJobVirtualMachineOutcome(workJob, vmId);
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) VMInstanceVO(com.cloud.vm.VMInstanceVO) CallContext(com.cloud.context.CallContext) VmWorkJobVO(com.cloud.framework.jobs.impl.VmWorkJobVO)

Example 69 with CallContext

use of com.cloud.context.CallContext in project cosmic by MissionCriticalCloud.

the class VMSnapshotManagerImpl method deleteVMSnapshotThroughJobQueue.

public Outcome<VMSnapshot> deleteVMSnapshotThroughJobQueue(final Long vmId, final Long vmSnapshotId) {
    final CallContext context = CallContext.current();
    final User callingUser = context.getCallingUser();
    final Account callingAccount = context.getCallingAccount();
    final VMInstanceVO vm = _vmInstanceDao.findById(vmId);
    final VmWorkJobVO workJob = new VmWorkJobVO(context.getContextId());
    workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
    workJob.setCmd(VmWorkDeleteVMSnapshot.class.getName());
    workJob.setAccountId(callingAccount.getId());
    workJob.setUserId(callingUser.getId());
    workJob.setStep(VmWorkJobVO.Step.Starting);
    workJob.setVmType(VirtualMachine.Type.Instance);
    workJob.setVmInstanceId(vm.getId());
    workJob.setRelated(AsyncJobExecutionContext.getOriginJobId());
    // save work context info (there are some duplications)
    final VmWorkDeleteVMSnapshot workInfo = new VmWorkDeleteVMSnapshot(callingUser.getId(), callingAccount.getId(), vm.getId(), VMSnapshotManagerImpl.VM_WORK_JOB_HANDLER, vmSnapshotId);
    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
    _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
    AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
    return new VmJobVMSnapshotOutcome(workJob, vmSnapshotId);
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) VMInstanceVO(com.cloud.vm.VMInstanceVO) CallContext(com.cloud.context.CallContext) VmWorkJobVO(com.cloud.framework.jobs.impl.VmWorkJobVO)

Example 70 with CallContext

use of com.cloud.context.CallContext in project cosmic by MissionCriticalCloud.

the class VMSnapshotManagerImpl method createVMSnapshotThroughJobQueue.

public Outcome<VMSnapshot> createVMSnapshotThroughJobQueue(final Long vmId, final Long vmSnapshotId, final boolean quiesceVm) {
    final CallContext context = CallContext.current();
    final User callingUser = context.getCallingUser();
    final Account callingAccount = context.getCallingAccount();
    final VMInstanceVO vm = _vmInstanceDao.findById(vmId);
    final VmWorkJobVO workJob = new VmWorkJobVO(context.getContextId());
    workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
    workJob.setCmd(VmWorkCreateVMSnapshot.class.getName());
    workJob.setAccountId(callingAccount.getId());
    workJob.setUserId(callingUser.getId());
    workJob.setStep(VmWorkJobVO.Step.Starting);
    workJob.setVmType(VirtualMachine.Type.Instance);
    workJob.setVmInstanceId(vm.getId());
    workJob.setRelated(AsyncJobExecutionContext.getOriginJobId());
    // save work context info (there are some duplications)
    final VmWorkCreateVMSnapshot workInfo = new VmWorkCreateVMSnapshot(callingUser.getId(), callingAccount.getId(), vm.getId(), VMSnapshotManagerImpl.VM_WORK_JOB_HANDLER, vmSnapshotId, quiesceVm);
    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
    _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
    AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
    return new VmJobVMSnapshotOutcome(workJob, vmSnapshotId);
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) VMInstanceVO(com.cloud.vm.VMInstanceVO) CallContext(com.cloud.context.CallContext) VmWorkJobVO(com.cloud.framework.jobs.impl.VmWorkJobVO)

Aggregations

CallContext (com.cloud.context.CallContext)72 Account (com.cloud.user.Account)41 User (com.cloud.user.User)26 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)26 VmWorkJobVO (com.cloud.framework.jobs.impl.VmWorkJobVO)22 ActionEvent (com.cloud.event.ActionEvent)20 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)19 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)19 DB (com.cloud.utils.db.DB)12 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)10 VMInstanceVO (com.cloud.vm.VMInstanceVO)10 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)9 ServerApiException (com.cloud.api.ServerApiException)8 FirewallRule (com.cloud.network.rules.FirewallRule)8 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)6 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)6 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)6 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)6 Network (com.cloud.network.Network)6 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)5