Package com.cloud.vm.VirtualMachine

Examples of com.cloud.vm.VirtualMachine.State


                if (record.isControlDomain || record.isASnapshot || record.isATemplate) {
                    continue; // Skip DOM0
                }
                String vm_name = record.nameLabel;
                VmPowerState ps = record.powerState;
                final State state = convertToState(ps);
                Host host = record.residentOn;
                String host_uuid = null;
                if( ! isRefNull(host) ) {
                    host_uuid = host.getUuid(conn);
                    synchronized (_cluster.intern()) {
                        s_vms.put(_cluster, host_uuid, vm_name, state);
                    }
                }
                if (s_logger.isTraceEnabled()) {
                    s_logger.trace("VM " + vm_name + ": powerstate = " + ps + "; vm state=" + state.toString());
                }
            }
        } catch (final Throwable e) {
            String msg = "Unable to get vms through host " + _host.uuid + " due to to " + e.toString();     
            s_logger.warn(msg, e);
View Full Code Here


 
  @Override
  public synchronized StartAnswer execute(StartCommand cmd) {
    VirtualMachineTO vmSpec = cmd.getVirtualMachine();
    String vmName = vmSpec.getName();
    State state = State.Stopped;
    OvmVm.Details vmDetails = null;
    try {
      synchronized (_vms) {
        _vms.put(vmName, State.Starting);
      }
View Full Code Here

  }
 
  @Override
  public StopAnswer execute(StopCommand cmd) {
    String vmName = cmd.getVmName();
    State state = null;
        synchronized(_vms) {
            state = _vms.get(vmName);
            _vms.put(vmName, State.Stopping);
        }
       
View Full Code Here

        }
    }
  }
 
  private State toState(String vmName, String s) {
    State state = _stateMaps.get(s);
    if (state == null) {
      s_logger.debug("Unkown state " + s + " for " + vmName);
      state = State.Unknown;
    }
    return state;
View Full Code Here

 
  protected HashMap<String, State> getAllVms() throws XmlRpcException {
    final HashMap<String, State> vmStates = new HashMap<String, State>();
    Map<String, String> vms = OvmHost.getAllVms(_conn);
    for (final Map.Entry<String, String> entry : vms.entrySet()) {
          State state = toState(entry.getKey(), entry.getValue());
          vmStates.put(entry.getKey(), state);
        }
    return vmStates;
  }
View Full Code Here

        for (final Map.Entry<String, State> entry : newStates
            .entrySet()) {
          final String vm = entry.getKey();

          State newState = entry.getValue();
          final State oldState = oldStates.remove(vm);

                    if (s_logger.isTraceEnabled()) {
                        s_logger.trace("VM " + vm + ": ovm has state " + newState + " and we have state " + (oldState != null ? oldState.toString() : "null"));
          }

          /*
           * TODO: what is migrating ??? if
           * (vm.startsWith("migrating")) {
           * s_logger.debug("Migrating from xen detected.  Skipping");
           * continue; }
           */

          if (oldState == null) {
            _vms.put(vm, newState);
            s_logger.debug("Detecting a new state but couldn't find a old state so adding it to the changes: "
                + vm);
            changes.put(vm, newState);
          } else if (oldState == State.Starting) {
            if (newState == State.Running) {
              _vms.put(vm, newState);
            } else if (newState == State.Stopped) {
              s_logger.debug("Ignoring vm " + vm
                  + " because of a lag in starting the vm.");
            }
          } else if (oldState == State.Migrating) {
            if (newState == State.Running) {
              s_logger.debug("Detected that an migrating VM is now running: "
                  + vm);
              _vms.put(vm, newState);
            }
          } else if (oldState == State.Stopping) {
            if (newState == State.Stopped) {
              _vms.put(vm, newState);
            } else if (newState == State.Running) {
              s_logger.debug("Ignoring vm " + vm
                  + " because of a lag in stopping the vm. ");
            }
          } else if (oldState != newState) {
            _vms.put(vm, newState);
            if (newState == State.Stopped) {
              //TODO: need anything here?
            }
            changes.put(vm, newState);
          }
        }

                for (final Map.Entry<String, State> entry : oldStates.entrySet()) {
                    final String vm = entry.getKey();
                    final State oldState = entry.getValue();

                    if (s_logger.isTraceEnabled()) {
                        s_logger.trace("VM " + vm + " is now missing from ovm server so reporting stopped");
                    }

                    if (oldState == State.Stopping) {
                        s_logger.debug("Ignoring VM " + vm + " in transition state stopping.");
                        _vms.remove(vm);
                    } else if (oldState == State.Starting) {
                        s_logger.debug("Ignoring VM " + vm + " in transition state starting.");
                    } else if (oldState == State.Stopped) {
                        _vms.remove(vm);
                    } else if (oldState == State.Migrating) {
                        s_logger.debug("Ignoring VM " + vm + " in migrating state.");
                    } else {
                        _vms.remove(vm);
                        State state = State.Stopped;
                        // TODO: need anything here???
                        changes.put(entry.getKey(), state);
                    }
                }
            }
View Full Code Here

        }
    }
   
    protected MigrateAnswer execute(final MigrateCommand cmd) {
        final String vmName = cmd.getVmName();
        State state = null;
       
        synchronized (_vms) {
            state = _vms.get(vmName);
            _vms.put(vmName, State.Stopping);
        }
View Full Code Here

        final String vmName = cmd.getVmName();
        try {
          Map<String, String> res = OvmVm.register(_conn, vmName);
          Integer vncPort = Integer.parseInt(res.get("vncPort"));
          HashMap<String, State> states = getAllVms();
          State vmState = states.get(vmName);
          if (vmState == null) {
            s_logger.warn("Check state of " + vmName + " return null in CheckVirtualMachineCommand");
            vmState = State.Stopped;
          }
         
View Full Code Here

            oldStates.putAll(s_vms.getClusterVmState(_cluster));

            for (final Map.Entry<String, Pair<String, State>> entry : newStates.entrySet()) {
                final String vm = entry.getKey();

                State newState = entry.getValue().second();
                String host_uuid = entry.getValue().first();
                final Pair<String, State> oldState = oldStates.remove(vm);

                //check if host is changed
                if (host_uuid != null && oldState != null){
                    if (!host_uuid.equals(oldState.first()) && newState != State.Stopped && newState != State.Stopping){
                        s_logger.warn("Detecting a change in host for " + vm);
                        changes.put(vm, new Pair<String, State>(host_uuid, newState));

                        s_logger.debug("11. The VM " + vm + " is in " + newState + " state");
                        s_vms.put(_cluster, host_uuid, vm, newState);
                        continue;
                    }
                }

                if (newState == State.Stopped  && oldState != null && oldState.second() != State.Stopping && oldState.second() != State.Stopped) {
                    newState = getRealPowerState(conn, vm);
                }

                if (s_logger.isTraceEnabled()) {
                    s_logger.trace("VM " + vm + ": xen has state " + newState + " and we have state " + (oldState != null ? oldState.toString() : "null"));
                }

                if (vm.startsWith("migrating")) {
                    s_logger.warn("Migrating from xen detected.  Skipping");
                    continue;
                }
                if (oldState == null) {
                    s_vms.put(_cluster, host_uuid, vm, newState);
                    s_logger.warn("Detecting a new state but couldn't find a old state so adding it to the changes: " + vm);
                    changes.put(vm, new Pair<String, State>(host_uuid, newState));
                } else if (oldState.second() == State.Starting) {
                    if (newState == State.Running) {
                        s_logger.debug("12. The VM " + vm + " is in " + State.Running + " state");
                        s_vms.put(_cluster, host_uuid, vm, newState);
                    } else if (newState == State.Stopped) {
                        s_logger.warn("Ignoring vm " + vm + " because of a lag in starting the vm.");
                    }
                } else if (oldState.second() == State.Migrating) {
                    if (newState == State.Running) {
                        s_logger.debug("Detected that an migrating VM is now running: " + vm);
                        s_vms.put(_cluster, host_uuid, vm, newState);
                    }
                } else if (oldState.second() == State.Stopping) {
                    if (newState == State.Stopped) {
                        s_logger.debug("13. The VM " + vm + " is in " + State.Stopped + " state");
                        s_vms.put(_cluster, host_uuid, vm, newState);
                    } else if (newState == State.Running) {
                        s_logger.warn("Ignoring vm " + vm + " because of a lag in stopping the vm. ");
                    }
                } else if (oldState.second() != newState) {
                    s_logger.debug("14. The VM " + vm + " is in " + newState + " state was " + oldState.second());
                    s_vms.put(_cluster, host_uuid, vm, newState);
                    if (newState == State.Stopped) {
                        /*
                         * if (s_vmsKilled.remove(vm)) { s_logger.debug("VM " + vm + " has been killed for storage. ");
                         * newState = State.Error; }
                         */
                    }
                    changes.put(vm, new Pair<String, State>(host_uuid, newState));
                }
            }

            for (final Map.Entry<String, Pair<String, State>> entry : oldStates.entrySet()) {
                final String vm = entry.getKey();
                final State oldState = entry.getValue().second();
                String host_uuid = entry.getValue().first();

                if (s_logger.isTraceEnabled()) {
                    s_logger.trace("VM " + vm + " is now missing from xen so reporting stopped");
                }

                if (oldState == State.Stopping) {
                    s_logger.warn("Ignoring VM " + vm + " in transition state stopping.");
                    s_vms.remove(_cluster, host_uuid, vm);
                } else if (oldState == State.Starting) {
                    s_logger.warn("Ignoring VM " + vm + " in transition state starting.");
                } else if (oldState == State.Stopped) {
                    s_logger.debug("VM missing " + vm + " old state stopped so removing.");
                    s_vms.remove(_cluster, host_uuid, vm);
                } else if (oldState == State.Migrating) {
                    s_logger.warn("Ignoring VM " + vm + " in migrating state.");
                } else {
                    State newState = State.Stopped;
                    s_logger.warn("The VM is now missing marking it as Stopped " + vm);
                    changes.put(vm, new Pair<String, State>(host_uuid, newState));
                }
            }
        }
View Full Code Here

        Pair<String, String> names = composeVmNames(vmSpec);
        String vmInternalCSName = names.first();
        String vmNameOnVcenter = names.second();
       
        // Thus, vmInternalCSName always holds i-x-y, the cloudstack generated internal VM name.
        State state = State.Stopped;
        VmwareContext context = getServiceContext();
        try {
            VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);

            // mark VM as starting state so that sync() can know not to report stopped too early
View Full Code Here

TOP

Related Classes of com.cloud.vm.VirtualMachine.State

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.