Examples of StartAnswer


Examples of com.cloud.agent.api.StartAnswer

                throw new Exception("Failed to start VM. vmName: " + vmInternalCSName + " with hostname " + vmNameOnVcenter);
            }

            state = State.Running;

            StartAnswer startAnswer = new StartAnswer(cmd);

            startAnswer.setIqnToPath(iqnToPath);

            return startAnswer;
        } catch (Throwable e) {
            if (e instanceof RemoteException) {
                s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
                invalidateServiceContext();
            }

            String msg = "StartCommand failed due to " + VmwareHelper.getExceptionMessage(e);
            s_logger.warn(msg, e);
            return new StartAnswer(cmd, msg);
        } finally {
            synchronized (_vms) {
                if (state != State.Stopped) {
                    _vms.put(vmInternalCSName, state);
                } else {
View Full Code Here

Examples of com.cloud.agent.api.StartAnswer

            conn = LibvirtConnection.getConnectionByType(vm.getHvsType());

            createVbd(conn, vmSpec, vmName, vm);

            if (!_storagePoolMgr.connectPhysicalDisksViaVmSpec(vmSpec)) {
                return new StartAnswer(cmd, "Failed to connect physical disks to host");
            }

            createVifs(vmSpec, vm);

            s_logger.debug("starting " + vmName + ": " + vm.toString());
            startVM(conn, vmName, vm.toString());

            NicTO[] nics = vmSpec.getNics();
            for (NicTO nic : nics) {
                if (nic.isSecurityGroupEnabled() || (nic.getIsolationUri() != null && nic.getIsolationUri().getScheme().equalsIgnoreCase(IsolationType.Ec2.toString()))) {
                    if (vmSpec.getType() != VirtualMachine.Type.User) {
                        default_network_rules_for_systemvm(conn, vmName);
                        break;
                    } else {
                        List<String> nicSecIps = nic.getNicSecIps();
                        String secIpsStr;
                        StringBuilder sb = new StringBuilder();
                        if (nicSecIps != null) {
                            for (String ip : nicSecIps) {
                                sb.append(ip).append(":");
                            }
                            secIpsStr = sb.toString();
                        } else {
                            secIpsStr = "0:";
                        }
                        default_network_rules(conn, vmName, nic, vmSpec.getId(), secIpsStr);
                    }
                }
            }

            // pass cmdline info to system vms
            if (vmSpec.getType() != VirtualMachine.Type.User) {
                if ((conn.getVersion() < 1001000)) { // CLOUDSTACK-2823: try passCmdLine some times if kernel < 2.6.34 and qemu < 1.1.0 on hypervisor (for instance, CentOS 6.4)
                    //wait for 5 minutes at most
                    String controlIp = null;
                    for (NicTO nic : nics) {
                        if (nic.getType() == TrafficType.Control) {
                            controlIp = nic.getIp();
                        }
                    }
                    for (int count = 0; count < 30; count++) {
                        passCmdLine(vmName, vmSpec.getBootArgs());
                        //check router is up?
                        boolean result = _virtRouterResource.connect(controlIp, 1, 5000);
                        if (result) {
                            break;
                        }
                    }
                } else {
                    passCmdLine(vmName, vmSpec.getBootArgs());
                }
            }

            state = State.Running;
            return new StartAnswer(cmd);
        } catch (LibvirtException e) {
            s_logger.warn("LibvirtException ", e);
            if (conn != null) {
                handleVmStartFailure(conn, vmName, vm);
            }
            return new StartAnswer(cmd, e.getMessage());
        } catch (InternalErrorException e) {
            s_logger.warn("InternalErrorException ", e);
            if (conn != null) {
                handleVmStartFailure(conn, vmName, vm);
            }
            return new StartAnswer(cmd, e.getMessage());
        } catch (URISyntaxException e) {
            s_logger.warn("URISyntaxException ", e);
            if (conn != null) {
                handleVmStartFailure(conn, vmName, vm);
            }
            return new StartAnswer(cmd, e.getMessage());
        } finally {
            synchronized (_vms) {
                if (state != State.Stopped) {
                    _vms.put(vmName, state);
                } else {
View Full Code Here

Examples of com.cloud.agent.api.StartAnswer

                    }
                }
            }
     
      state = State.Running;
      return new StartAnswer(cmd);
    } catch (Exception e ) {
      s_logger.debug("Start vm " + vmName + " failed", e);
      cleanup(vmDetails);
      return new StartAnswer(cmd, e.getMessage());
    } finally {
      synchronized (_vms) {
        //FIXME: where to come to Stopped???
        if (state != State.Stopped) {
          _vms.put(vmName, state);
View Full Code Here

Examples of com.cloud.agent.api.StartAnswer

                    _uservmDetailsDao.addDetail(vm.getId(), "cpuOvercommitRatio", cluster_detail_cpu.getValue(), true);
                    _uservmDetailsDao.addDetail(vm.getId(), "memoryOvercommitRatio", cluster_detail_ram.getValue(), true);
                }
                vmProfile.setCpuOvercommitRatio(Float.parseFloat(cluster_detail_cpu.getValue()));
                vmProfile.setMemoryOvercommitRatio(Float.parseFloat(cluster_detail_ram.getValue()));
                StartAnswer startAnswer = null;

                try {
                    if (!changeState(vm, Event.OperationRetry, destHostId, work, Step.Prepare)) {
                        throw new ConcurrentOperationException("Unable to update the state of the Virtual Machine");
                    }
                } catch (NoTransitionException e1) {
                    throw new ConcurrentOperationException(e1.getMessage());
                }

                try {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("VM is being created in podId: " + vm.getPodIdToDeployIn());
                    }
                    _networkMgr.prepare(vmProfile, dest, ctx);
                    if (vm.getHypervisorType() != HypervisorType.BareMetal) {
                        volumeMgr.prepare(vmProfile, dest);
                    }
                    //since StorageMgr succeeded in volume creation, reuse Volume for further tries until current cluster has capacity
                    if (!reuseVolume) {
                        reuseVolume = true;
                    }

                    Commands cmds = null;
                    vmGuru.finalizeVirtualMachineProfile(vmProfile, dest, ctx);

                    VirtualMachineTO vmTO = hvGuru.implement(vmProfile);

                    handlePath(vmTO.getDisks(), vm.getHypervisorType());

                    cmds = new Commands(Command.OnError.Stop);

                    cmds.addCommand(new StartCommand(vmTO, dest.getHost(), getExecuteInSequence(vm.getHypervisorType())));


                    vmGuru.finalizeDeployment(cmds, vmProfile, dest, ctx);

                    work = _workDao.findById(work.getId());
                    if (work == null || work.getStep() != Step.Prepare) {
                        throw new ConcurrentOperationException("Work steps have been changed: " + work);
                    }

                    _workDao.updateStep(work, Step.Starting);

                    _agentMgr.send(destHostId, cmds);

                    _workDao.updateStep(work, Step.Started);

                    startAnswer = cmds.getAnswer(StartAnswer.class);
                    if (startAnswer != null && startAnswer.getResult()) {
                        handlePath(vmTO.getDisks(), startAnswer.getIqnToPath());
                        String host_guid = startAnswer.getHost_guid();
                        if (host_guid != null) {
                            HostVO finalHost = _resourceMgr.findHostByGuid(host_guid);
                            if (finalHost == null) {
                                throw new CloudRuntimeException("Host Guid " + host_guid + " doesn't exist in DB, something wrong here");
                            }
                            destHostId = finalHost.getId();
                        }
                        if (vmGuru.finalizeStart(vmProfile, destHostId, cmds, ctx)) {
                            syncDiskChainChange(startAnswer);

                            if (!changeState(vm, Event.OperationSucceeded, destHostId, work, Step.Done)) {
                                throw new ConcurrentOperationException("Unable to transition to a new state.");
                            }

                            // Update GPU device capacity
                            GPUDeviceTO gpuDevice = startAnswer.getVirtualMachine().getGpuDevice();
                            if (gpuDevice != null) {
                                _resourceMgr.updateGPUDetails(destHostId, gpuDevice.getGroupDetails());
                            }

                            startedVm = vm;
                            if (s_logger.isDebugEnabled()) {
                                s_logger.debug("Start completed for VM " + vm);
                            }
                            return;
                        } else {
                            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");
                        }
                    }
                    s_logger.info("Unable to start VM on " + dest.getHost() + " due to " + (startAnswer == null ? " no start answer" : startAnswer.getDetails()));

                } catch (OperationTimedoutException e) {
                    s_logger.debug("Unable to send the start command to host " + dest.getHost());
                    if (e.isActive()) {
                        _haMgr.scheduleStop(vm, destHostId, WorkType.CheckStop);
                    }
                    canRetry = false;
                    throw new AgentUnavailableException("Unable to start " + vm.getHostName(), destHostId, e);
                } catch (ResourceUnavailableException e) {
                    s_logger.info("Unable to contact resource.", e);
                    if (!avoids.add(e)) {
                        if (e.getScope() == Volume.class || e.getScope() == Nic.class) {
                            throw e;
                        } else {
                            s_logger.warn("unexpected ResourceUnavailableException : " + e.getScope().getName(), e);
                            throw e;
                        }
                    }
                } catch (InsufficientCapacityException e) {
                    s_logger.info("Insufficient capacity ", e);
                    if (!avoids.add(e)) {
                        if (e.getScope() == Volume.class || e.getScope() == Nic.class) {
                            throw e;
                        } else {
                            s_logger.warn("unexpected InsufficientCapacityException : " + e.getScope().getName(), e);
                        }
                    }
                } catch (Exception e) {
                    s_logger.error("Failed to start instance " + vm, e);
                    throw new AgentUnavailableException("Unable to start instance due to " + e.getMessage(), destHostId, e);
                } finally {
                    if (startedVm == null && canRetry) {
                        Step prevStep = work.getStep();
                        _workDao.updateStep(work, Step.Release);
                        // If previous step was started/ing && we got a valid answer
                        if ((prevStep == Step.Started || prevStep == Step.Starting) && (startAnswer != null && startAnswer.getResult())) {  //TODO check the response of cleanup and record it in DB for retry
                            cleanup(vmGuru, vmProfile, work, Event.OperationFailed, false);
                        } else {
                            //if step is not starting/started, send cleanup command with force=true
                            cleanup(vmGuru, vmProfile, work, Event.OperationFailed, true);
                        }
View Full Code Here

Examples of com.cloud.agent.api.StartAnswer

                "\"broadcastUri\":\"vlan://261\"," +
                "\"isolationUri\":\"vlan://261\"," +
                "\"isSecurityGroupEnabled\":false}" + "]},\"contextMap\":{},\"wait\":0}";

        StartCommand cmd = s_gson.fromJson(sampleStart, StartCommand.class);
        StartAnswer ans = (StartAnswer)s_hypervresource.executeRequest(cmd);
        Assert.assertFalse(ans.getDetails(), ans.getResult());
    }
View Full Code Here

Examples of com.cloud.agent.api.StartAnswer

    }

    @Test
    public final void testStartStopCommand() {
        String sample = getSampleStartCommand();
        StartAnswer sans = simpleVmStart(sample);
        Assert.assertTrue(sans.getDetails(), sans.getResult());
        StopAnswer stopAns = simpleVmStop();
        Assert.assertTrue(stopAns.getDetails(), stopAns.getResult());
    }
View Full Code Here

Examples of com.cloud.agent.api.StartAnswer

    @Test
    public final void testStartStartCommand() {
        String sample = getSampleStartCommand();

        StartAnswer sans = simpleVmStart(sample);
        Assert.assertTrue(sans.getDetails(), sans.getResult());
        simpleVmStart(sample);

        StopAnswer ans = simpleVmStop();
        Assert.assertTrue(ans.getDetails(), ans.getResult());
    }
View Full Code Here

Examples of com.cloud.agent.api.StartAnswer

    }

    private StartAnswer simpleVmStart(final String sample) {
        StartCommand cmd = s_gson.fromJson(sample, StartCommand.class);
        s_logger.info("StartCommand sample " + s_gson.toJson(cmd));
        StartAnswer ans = (StartAnswer)s_hypervresource.executeRequest(cmd);
        return ans;
    }
View Full Code Here

Examples of com.cloud.agent.api.StartAnswer

        try {
            changeVmState(vm.getName(), State.Starting);

            OutputInterpreter.AllLinesParser interpreter = new OutputInterpreter.AllLinesParser();
            if (!doScript(_getStatusCommand, interpreter)) {
                return new StartAnswer(cmd, "Cannot get current power status of " + _name);
            }

            if (isPowerOn(interpreter.getLines())) {
                if (!doScript(_rebootCommand)) {
                    return new StartAnswer(cmd, "IPMI reboot failed");
                }
            } else {
                if (!doScript(_powerOnCommand)) {
                    return new StartAnswer(cmd, "IPMI power on failed");
                }
            }

            if (_isEchoScAgent) {
                SecurityGroupHttpClient hc = new SecurityGroupHttpClient();
                boolean echoRet = hc.echo(vm.getNics()[0].getIp(), TimeUnit.MINUTES.toMillis(30), TimeUnit.MINUTES.toMillis(1));
                if (!echoRet) {
                    return new StartAnswer(cmd, String.format("Call security group agent on vm[%s] timeout", vm.getNics()[0].getIp()));
                }
            }

            s_logger.debug("Start bare metal vm " + vm.getName() + "successfully");
            state = State.Running;
            _vmName = vm.getName();
            return new StartAnswer(cmd);
        } finally {
            if (state != State.Stopped) {
                changeVmState(vm.getName(), state);
            } else {
                removeVmState(vm.getName());
View Full Code Here

Examples of com.cloud.agent.api.StartAnswer

    protected synchronized Answer execute(StartCommand cmd) throws IllegalArgumentException {
        VirtualMachineTO vmSpec = cmd.getVirtualMachine();
        String vmName = vmSpec.getName();
        if (this.totalCpu < (vmSpec.getCpus() * vmSpec.getMaxSpeed() + this.usedCpu) || this.totalMem < (vmSpec.getMaxRam() + this.usedMem)) {
            return new StartAnswer(cmd, "Not enough resource to start the vm");
        }
        State state = State.Stopped;
        synchronized (_vms) {
            _vms.put(vmName, State.Starting);
        }

        try {
            Answer result = _simMgr.simulate(cmd, hostGuid);
            if (!result.getResult()) {
                return new StartAnswer(cmd, result.getDetails());
            }

            this.usedCpu += vmSpec.getCpus() * vmSpec.getMaxSpeed();
            this.usedMem += vmSpec.getMaxRam();
            _runningVms.put(vmName, new Pair<Long, Long>(Long.valueOf(vmSpec.getCpus() * vmSpec.getMaxSpeed()), vmSpec.getMaxRam()));
            state = State.Running;

        } finally {
            synchronized (_vms) {
                _vms.put(vmName, state);
            }
        }

        return new StartAnswer(cmd);

    }
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.