Examples of StopAnswer


Examples of com.cloud.agent.api.StopAnswer

        }
    }

    @Override
    public StopAnswer execute(StopCommand cmd) {
        StopAnswer answer = super.execute(cmd);
        String vmName = cmd.getVmName();
        if (vmName.startsWith("v-")) {
            Connection conn = getConnection();
            callHostPlugin(conn, "vmops", "setDNATRule", "add", "false");
        }
View Full Code Here

Examples of com.cloud.agent.api.StopAnswer

            OvmVm.Details vm = null;
            try {
                vm = OvmVm.getDetails(_conn, vmName);
            } catch (XmlRpcException e) {
                s_logger.debug("Unable to get details of vm: " + vmName + ", treating it as stopped", e);
                return new StopAnswer(cmd, "success", true);
            }

            deleteAllNetworkRulesForVm(vmName);
            OvmVm.stop(_conn, vmName);
            cleanup(vm);

            state = State.Stopped;
            return new StopAnswer(cmd, "success", true);
        } catch (Exception e) {
            s_logger.debug("Stop " + vmName + "failed", e);
            return new StopAnswer(cmd, e.getMessage(), false);
        } finally {
            synchronized (_vms) {
                if (state != null) {
                    _vms.put(vmName, state);
                } else {
View Full Code Here

Examples of com.cloud.agent.api.StopAnswer

            if (vmMo != null) {
                if (cmd.checkBeforeCleanup()) {
                    if (getVmPowerState(vmMo) != PowerState.PowerOff) {
                        String msg = "StopCommand is sent for cleanup and VM " + cmd.getVmName() + " is current running. ignore it.";
                        s_logger.warn(msg);
                        return new StopAnswer(cmd, msg, false);
                    } else {
                        String msg = "StopCommand is sent for cleanup and VM " + cmd.getVmName() + " is indeed stopped already.";
                        s_logger.info(msg);
                        return new StopAnswer(cmd, msg, true);
                    }
                }

                State state = null;
                synchronized (_vms) {
                    state = _vms.get(cmd.getVmName());
                    _vms.put(cmd.getVmName(), State.Stopping);
                }

                try {
                    vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK, "0");

                    if (getVmPowerState(vmMo) != PowerState.PowerOff) {
                        if (vmMo.safePowerOff(_shutdownWaitMs)) {
                            state = State.Stopped;
                            return new StopAnswer(cmd, "Stop VM " + cmd.getVmName() + " Succeed", true);
                        } else {
                            String msg = "Have problem in powering off VM " + cmd.getVmName() + ", let the process continue";
                            s_logger.warn(msg);
                            return new StopAnswer(cmd, msg, true);
                        }
                    } else {
                        state = State.Stopped;
                    }

                    String msg = "VM " + cmd.getVmName() + " is already in stopped state";
                    s_logger.info(msg);
                    return new StopAnswer(cmd, msg, true);
                } finally {
                    synchronized (_vms) {
                        _vms.put(cmd.getVmName(), state);
                    }
                }
            } else {
                synchronized (_vms) {
                    _vms.remove(cmd.getVmName());
                }

                String msg = "VM " + cmd.getVmName() + " is no longer in vSphere";
                s_logger.info(msg);
                return new StopAnswer(cmd, msg, true);
            }
        } catch (Exception e) {
            if (e instanceof RemoteException) {
                s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
                invalidateServiceContext();
            }

            String msg = "StopCommand failed due to " + VmwareHelper.getExceptionMessage(e);
            s_logger.error(msg);
            return new StopAnswer(cmd, msg, false);
        }
    }
View Full Code Here

Examples of com.cloud.agent.api.StopAnswer

        if (cmd.checkBeforeCleanup()) {
            try {
                Connect conn = LibvirtConnection.getConnectionByVmName(vmName);
                Domain vm = conn.domainLookupByName(cmd.getVmName());
                if (vm != null && vm.getInfo().state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING) {
                    return new StopAnswer(cmd, "vm is still running on host", false);
                }
            } catch (Exception e) {
                s_logger.debug("Failed to get vm status in case of checkboforecleanup is true", e);
            }
        }

        State state = null;
        synchronized (_vms) {
            state = _vms.get(vmName);
            _vms.put(vmName, State.Stopping);
        }
        try {
            Connect conn = LibvirtConnection.getConnectionByVmName(vmName);

            List<DiskDef> disks = getDisks(conn, vmName);
            List<InterfaceDef> ifaces = getInterfaces(conn, vmName);

            destroy_network_rules_for_vm(conn, vmName);
            String result = stopVM(conn, vmName);
            if (result == null) {
                for (DiskDef disk : disks) {
                    cleanupDisk(disk);
                }
                for (InterfaceDef iface : ifaces) {
                    // We don't know which "traffic type" is associated with
                    // each interface at this point, so inform all vif drivers
                    for (VifDriver vifDriver : getAllVifDrivers()) {
                        vifDriver.unplug(iface);
                    }
                }
            }

            state = State.Stopped;
            return new StopAnswer(cmd, result, true);
        } catch (LibvirtException e) {
            return new StopAnswer(cmd, e.getMessage(), false);
        } finally {
            synchronized (_vms) {
                if (state != null) {
                    _vms.put(vmName, state);
                } else {
View Full Code Here

Examples of com.cloud.agent.api.StopAnswer

          OvmVm.Details vm = null;
          try {
            vm = OvmVm.getDetails(_conn, vmName);  
          } catch (XmlRpcException e) {
            s_logger.debug("Unable to get details of vm: " + vmName + ", treating it as stopped", e);
            return new StopAnswer(cmd, "success", true);
          }
         
          deleteAllNetworkRulesForVm(vmName);   
          OvmVm.stop(_conn, vmName);
          cleanup(vm);
         
          state = State.Stopped;
          return new StopAnswer(cmd, "success", true);
        } catch (Exception e) {
          s_logger.debug("Stop " + vmName + "failed", e);
          return new StopAnswer(cmd, e.getMessage(), false);
        } finally {
          synchronized(_vms) {
                if (state != null) {
                    _vms.put(vmName, state);
                } else {
View Full Code Here

Examples of com.cloud.agent.api.StopAnswer

    @Test
    public void testSendStopWithOkAnswer() throws Exception {
        VirtualMachineGuru guru = mock(VirtualMachineGuru.class);
        VirtualMachine vm = mock(VirtualMachine.class);
        VirtualMachineProfile profile = mock(VirtualMachineProfile.class);
        StopAnswer answer = new StopAnswer(new StopCommand(vm, false, false), "ok", true);
        when(profile.getVirtualMachine()).thenReturn(vm);
        when(vm.getHostId()).thenReturn(1L);
        when(_agentMgr.send(anyLong(), (Command)any())).thenReturn(answer);

        boolean actual = _vmMgr.sendStop(guru, profile, false, false);
View Full Code Here

Examples of com.cloud.agent.api.StopAnswer

    @Test
    public void testSendStopWithFailAnswer() throws Exception {
        VirtualMachineGuru guru = mock(VirtualMachineGuru.class);
        VirtualMachine vm = mock(VirtualMachine.class);
        VirtualMachineProfile profile = mock(VirtualMachineProfile.class);
        StopAnswer answer = new StopAnswer(new StopCommand(vm, false, false), "fail", false);
        when(profile.getVirtualMachine()).thenReturn(vm);
        when(vm.getHostId()).thenReturn(1L);
        when(_agentMgr.send(anyLong(), (Command)any())).thenReturn(answer);

        boolean actual = _vmMgr.sendStop(guru, profile, false, false);
View Full Code Here

Examples of com.cloud.agent.api.StopAnswer

                            if (s_logger.isDebugEnabled()) {
                                s_logger.info("The guru did not like the answers so stopping " + vm);
                            }

                            StopCommand cmd = new StopCommand(vm, getExecuteInSequence(vm.getHypervisorType()), false);
                            StopAnswer answer = (StopAnswer) _agentMgr.easySend(destHostId, cmd);
                            if ( answer != null ) {

                                if (vm.getType() == VirtualMachine.Type.User) {
                                    String platform = answer.getPlatform();
                                    if (platform != null) {
                                        Map<String,String> vmmetadata = new HashMap<String,String>();
                                        vmmetadata.put(vm.getInstanceName(), platform);
                                        syncVMMetaData(vmmetadata);
                                    }
                                }
                            }

                            if (answer == null || !answer.getResult()) {
                                s_logger.warn("Unable to stop " + vm + " due to " + (answer != null ? answer.getDetails() : "no answers"));
                                _haMgr.scheduleStop(vm, destHostId, WorkType.ForceStop);
                                throw new ExecutionException("Unable to stop " + vm + " so we are unable to retry the start operation");
                            }
                            throw new ExecutionException("Unable to start " + vm + " due to error in finalizeStart, not retrying");
                        }
View Full Code Here

Examples of com.cloud.agent.api.StopAnswer

    protected boolean sendStop(VirtualMachineGuru guru, VirtualMachineProfile profile, boolean force, boolean checkBeforeCleanup) {
        VirtualMachine vm = profile.getVirtualMachine();
        StopCommand stop = new StopCommand(vm, getExecuteInSequence(vm.getHypervisorType()), checkBeforeCleanup);
        try {
            StopAnswer answer = (StopAnswer)_agentMgr.send(vm.getHostId(), stop);
            if (answer != null) {
                if (vm.getType() == VirtualMachine.Type.User) {
                    String platform = answer.getPlatform();
                    if (platform != null) {
                        UserVmVO userVm = _userVmDao.findById(vm.getId());
                        _userVmDao.loadDetails(userVm);
                        userVm.setDetail("platform", platform);
                        _userVmDao.saveDetails(userVm);
                    }
                }

                GPUDeviceTO gpuDevice = stop.getGpuDevice();
                if (gpuDevice != null) {
                    _resourceMgr.updateGPUDetails(vm.getHostId(), gpuDevice.getGroupDetails());
                }
                if (!answer.getResult()) {
                    s_logger.debug("Unable to stop VM due to " + answer.getDetails());
                    return false;
                }

                guru.finalizeStop(profile, answer);
            } else {
View Full Code Here

Examples of com.cloud.agent.api.StopAnswer

        vmGuru.prepareStop(profile);

        StopCommand stop = new StopCommand(vm, getExecuteInSequence(vm.getHypervisorType()), false);

        boolean stopped = false;
        StopAnswer answer = null;
        try {
            answer = (StopAnswer)_agentMgr.send(vm.getHostId(), stop);
            if (answer != null) {
                if (vm.getType() == VirtualMachine.Type.User) {
                    String platform = answer.getPlatform();
                    if (platform != null) {
                        UserVmVO userVm = _userVmDao.findById(vm.getId());
                        _userVmDao.loadDetails(userVm);
                        userVm.setDetail("platform", platform);
                        _userVmDao.saveDetails(userVm);
                    }
                }
                stopped = answer.getResult();
                if (!stopped) {
                    throw new CloudRuntimeException("Unable to stop the virtual machine due to " + answer.getDetails());
                }
                vmGuru.finalizeStop(profile, answer);
                GPUDeviceTO gpuDevice = stop.getGpuDevice();
                if (gpuDevice != null) {
                    _resourceMgr.updateGPUDetails(vm.getHostId(), gpuDevice.getGroupDetails());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.