Package org.apache.cloudstack.context

Examples of org.apache.cloudstack.context.CallContext


    }

    public Outcome<VirtualMachine> addVmToNetworkThroughJobQueue(
            final VirtualMachine vm, final Network network, final NicProfile requested) {

        final CallContext context = CallContext.current();
        final User user = context.getCallingUser();
        final Account account = context.getCallingAccount();

        Object[] result = Transaction.execute(new TransactionCallback<Object[]>() {
            @Override
            public Object[] doInTransaction(TransactionStatus status) {

                _vmDao.lockRow(vm.getId(), true);

                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
                        VirtualMachine.Type.Instance, vm.getId(),
                        VmWorkAddVmToNetwork.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(VmWorkAddVmToNetwork.class.getName());

                    workJob.setAccountId(account.getId());
View Full Code Here


    }

    public Outcome<VirtualMachine> removeNicFromVmThroughJobQueue(
            final VirtualMachine vm, final Nic nic) {

        final CallContext context = CallContext.current();
        final User user = context.getCallingUser();
        final Account account = context.getCallingAccount();

        Object[] result = Transaction.execute(new TransactionCallback<Object[]>() {
            @Override
            public Object[] doInTransaction(TransactionStatus status) {

                _vmDao.lockRow(vm.getId(), true);

                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
                        VirtualMachine.Type.Instance, vm.getId(),
                        VmWorkRemoveNicFromVm.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(VmWorkRemoveNicFromVm.class.getName());

                    workJob.setAccountId(account.getId());
View Full Code Here

    }

    public Outcome<VirtualMachine> removeVmFromNetworkThroughJobQueue(
            final VirtualMachine vm, final Network network, final URI broadcastUri) {

        final CallContext context = CallContext.current();
        final User user = context.getCallingUser();
        final Account account = context.getCallingAccount();

        Object[] result = Transaction.execute(new TransactionCallback<Object[]>() {
            @Override
            public Object[] doInTransaction(TransactionStatus status) {

                _vmDao.lockRow(vm.getId(), true);

                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
                        VirtualMachine.Type.Instance, vm.getId(),
                        VmWorkRemoveVmFromNetwork.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(VmWorkRemoveVmFromNetwork.class.getName());

                    workJob.setAccountId(account.getId());
View Full Code Here

    }

    public Outcome<VirtualMachine> reconfigureVmThroughJobQueue(
            final String vmUuid, final ServiceOffering newServiceOffering, final boolean reconfiguringOnExistingHost) {

        final CallContext context = CallContext.current();
        final User user = context.getCallingUser();
        final Account account = context.getCallingAccount();

        final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);

        Object[] result = Transaction.execute(new TransactionCallback<Object[]>() {
            @Override
            public Object[] doInTransaction(TransactionStatus status) {

                _vmDao.lockRow(vm.getId(), true);

                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
                        VirtualMachine.Type.Instance, vm.getId(),
                        VmWorkReconfigure.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(VmWorkReconfigure.class.getName());

                    workJob.setAccountId(account.getId());
View Full Code Here

    @Override
    @ActionEvent(eventType = EventTypes.EVENT_VM_DESTROY, eventDescription = "destroying Vm", async = true)
    public UserVm destroyVm(DestroyVMCmd cmd)
            throws ResourceUnavailableException, ConcurrentOperationException {
        CallContext ctx = CallContext.current();
        long vmId = cmd.getId();
        boolean expunge = cmd.getExpunge();

        if (!_accountMgr.isAdmin(ctx.getCallingAccount().getType()) && expunge) {
            throw new PermissionDeniedException("Parameter " + ApiConstants.EXPUNGE + " can be passed by Admin only");
        }

        UserVm destroyedVm = destroyVm(vmId);
        if (expunge) {
            UserVmVO vm = _vmDao.findById(vmId);
            if (!expunge(vm, ctx.getCallingUserId(), ctx.getCallingAccount())) {
                throw new CloudRuntimeException("Failed to expunge vm " + destroyedVm);
            }
        }

        return destroyedVm;
View Full Code Here

    public void finalizeStop(VirtualMachineProfile profile, Answer answer) {
        VirtualMachine vm = profile.getVirtualMachine();
        // release elastic IP here
        IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId());
        if (ip != null && ip.getSystem()) {
            CallContext ctx = CallContext.current();
            try {
                long networkId = ip.getAssociatedWithNetworkId();
                Network guestNetwork = _networkDao.findById(networkId);
                NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId());
                assert (offering.getAssociatePublicIP() == true) : "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 (Exception ex) {
                s_logger.warn(
                        "Failed to disable static nat and release system ip "
                                + ip + " as a part of vm "
                                + profile.getVirtualMachine()
View Full Code Here

    @Override
    public void finalizeStop(VirtualMachineProfile profile, Answer answer) {
        //release elastic IP here
        IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId());
        if (ip != null && ip.getSystem()) {
            CallContext ctx = CallContext.current();
            try {
                _rulesMgr.disableStaticNat(ip.getId(), ctx.getCallingAccount(), ctx.getCallingUserId(), true);
            } catch (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);
            }
        }
View Full Code Here

    @Override
    public boolean isDisplay(){

        // Get entity Class from the event name. Eg. - Volume.class
        final CallContext ctx = CallContext.current();
        Class entityClass = EventTypes.getEntityClassForEvent(getEventType());
        boolean isDisplay = true;

        try{
            // If the entity Class implements Displayable interface then see the flag from VO
            if (entityClass != null && Displayable.class.isAssignableFrom(entityClass)){
                Object objVO =_entityMgr.findById(entityClass, (Long)ctx.getContextParameter(entityClass.getName()));
                isDisplay = ((Displayable)objVO).isDisplay();
                ctx.setEventDisplayEnabled(isDisplay);
            }
        }catch (Exception e){
           s_logger.trace("Caught exception while finding the display property, defaulting to true and moving on " +e);
        }
View Full Code Here

    /**
     * display flag is used to control the display of the resource only to the end user. It doesnt affect Root Admin.
     * @return display flag
     */
    public boolean isDisplay(){
        CallContext context = CallContext.current();
        Map<Object, Object> contextMap = context.getContextParameters();
        boolean isDisplay = true;

        // Iterate over all the first class entities in context and check their display property.
        for(Map.Entry<Object, Object> entry : contextMap.entrySet()){
            try{
                Object key = entry.getKey();
                Class clz = Class.forName((String)key);
                if(Displayable.class.isAssignableFrom(clz)){
                    final Object objVO = getEntityVO(clz, entry.getValue());
                    isDisplay = ((Displayable) objVO).isDisplay();
                }

                // If the flag is false break immediately
                if(!isDisplay)
                    break;
            } catch (Exception e){
                s_logger.trace("Caught exception while checking first class entities for display property, continuing on", e);
            }
        }

        context.setEventDisplayEnabled(isDisplay);
        return isDisplay;

    }
View Full Code Here

    @Override
    public void orchestrateStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy, DeploymentPlanner planner)
            throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {

        CallContext cctxt = CallContext.current();
        Account account = cctxt.getCallingAccount();
        User caller = cctxt.getCallingUser();

        VMInstanceVO vm = _vmDao.findByUuid(vmUuid);

        VirtualMachineGuru vmGuru = getVmGuru(vm);
View Full Code Here

TOP

Related Classes of org.apache.cloudstack.context.CallContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.