mirror of https://github.com/apache/cloudstack.git
Switch hypervisor resources to use power state
This commit is contained in:
parent
d72af4bd0f
commit
534345e8aa
|
|
@ -29,12 +29,12 @@ import com.cloud.agent.api.Answer;
|
|||
import com.cloud.agent.api.CheckNetworkAnswer;
|
||||
import com.cloud.agent.api.CheckNetworkCommand;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.HostVmStateReportEntry;
|
||||
import com.cloud.agent.api.PingCommand;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.api.StartupRoutingCommand;
|
||||
import com.cloud.agent.api.StartupStorageCommand;
|
||||
import com.cloud.agent.api.StoragePoolInfo;
|
||||
import com.cloud.agent.api.StartupRoutingCommand.VmState;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
|
|
@ -162,7 +162,7 @@ public class DummyResource implements ServerResource {
|
|||
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
Map<String, VmState> changes = null;
|
||||
Map<String, HostVmStateReportEntry> changes = null;
|
||||
|
||||
final List<Object> info = getHostInfo();
|
||||
|
||||
|
|
|
|||
|
|
@ -16,24 +16,24 @@
|
|||
// under the License.
|
||||
package com.cloud.agent.api;
|
||||
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
|
||||
public class CheckVirtualMachineAnswer extends Answer {
|
||||
|
||||
Integer vncPort;
|
||||
State state;
|
||||
PowerState state;
|
||||
|
||||
|
||||
protected CheckVirtualMachineAnswer() {
|
||||
}
|
||||
|
||||
public CheckVirtualMachineAnswer(CheckVirtualMachineCommand cmd, State state, Integer vncPort, String detail) {
|
||||
public CheckVirtualMachineAnswer(CheckVirtualMachineCommand cmd, PowerState state, Integer vncPort, String detail) {
|
||||
super(cmd, true, detail);
|
||||
this.state = state;
|
||||
this.vncPort = vncPort;
|
||||
}
|
||||
|
||||
public CheckVirtualMachineAnswer(CheckVirtualMachineCommand cmd, State state, Integer vncPort) {
|
||||
public CheckVirtualMachineAnswer(CheckVirtualMachineCommand cmd, PowerState state, Integer vncPort) {
|
||||
this(cmd, state, vncPort, null);
|
||||
}
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ public class CheckVirtualMachineAnswer extends Answer {
|
|||
return vncPort;
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
public PowerState getState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,22 +19,22 @@ package com.cloud.agent.api;
|
|||
import java.util.Map;
|
||||
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
|
||||
public class PingRoutingCommand extends PingCommand {
|
||||
Map<String, State> newStates;
|
||||
Map<String, PowerState> newStates;
|
||||
boolean _gatewayAccessible = true;
|
||||
boolean _vnetAccessible = true;
|
||||
|
||||
protected PingRoutingCommand() {
|
||||
}
|
||||
|
||||
public PingRoutingCommand(Host.Type type, long id, Map<String, State> states) {
|
||||
public PingRoutingCommand(Host.Type type, long id, Map<String, PowerState> states) {
|
||||
super(type, id);
|
||||
this.newStates = states;
|
||||
}
|
||||
|
||||
public Map<String, State> getNewStates() {
|
||||
public Map<String, PowerState> getNewStates() {
|
||||
return newStates;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import java.util.Map;
|
|||
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
|
||||
|
||||
public class PingRoutingWithNwGroupsCommand extends PingRoutingCommand {
|
||||
|
|
@ -31,7 +31,7 @@ public class PingRoutingWithNwGroupsCommand extends PingRoutingCommand {
|
|||
super();
|
||||
}
|
||||
|
||||
public PingRoutingWithNwGroupsCommand(Host.Type type, long id, Map<String, State> states, HashMap<String, Pair<Long, Long>> nwGrpStates) {
|
||||
public PingRoutingWithNwGroupsCommand(Host.Type type, long id, Map<String, PowerState> states, HashMap<String, Pair<Long, Long>> nwGrpStates) {
|
||||
super(type, id, states);
|
||||
newGroupStates = nwGrpStates;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import java.util.Map;
|
|||
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
|
||||
public class PingRoutingWithOvsCommand extends PingRoutingCommand {
|
||||
List<Pair<String, Long>> states;
|
||||
|
|
@ -31,7 +31,7 @@ public class PingRoutingWithOvsCommand extends PingRoutingCommand {
|
|||
}
|
||||
|
||||
public PingRoutingWithOvsCommand(Host.Type type, long id,
|
||||
Map<String, State> states, List<Pair<String, Long>> ovsStates) {
|
||||
Map<String, PowerState> states, List<Pair<String, Long>> ovsStates) {
|
||||
super(type, id, states);
|
||||
this.states = ovsStates;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ import com.cloud.utils.script.Script2;
|
|||
import com.cloud.utils.script.Script2.ParamType;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
|
|
@ -314,13 +315,13 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
|
|||
}
|
||||
}
|
||||
|
||||
protected Map<String, State> fullSync() {
|
||||
Map<String, State> states = new HashMap<String, State>();
|
||||
protected Map<String, PowerState> fullSync() {
|
||||
Map<String, PowerState> states = new HashMap<String, PowerState>();
|
||||
if (hostId != null) {
|
||||
vmDao = ComponentContext.getComponent(VMInstanceDao.class);
|
||||
final List<? extends VMInstanceVO> vms = vmDao.listByHostId(hostId);
|
||||
for (VMInstanceVO vm : vms) {
|
||||
states.put(vm.getInstanceName(), vm.getState());
|
||||
states.put(vm.getInstanceName(), vm.getState() == State.Running ? PowerState.PowerOn : PowerState.PowerOff);
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
|
@ -411,7 +412,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
|
|||
}
|
||||
|
||||
protected CheckVirtualMachineAnswer execute(final CheckVirtualMachineCommand cmd) {
|
||||
return new CheckVirtualMachineAnswer(cmd, State.Stopped, null);
|
||||
return new CheckVirtualMachineAnswer(cmd, PowerState.PowerOff, null);
|
||||
}
|
||||
|
||||
protected Answer execute(IpmiBootorResetCommand cmd) {
|
||||
|
|
@ -563,8 +564,8 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource
|
|||
}
|
||||
}
|
||||
|
||||
protected HashMap<String, State> deltaSync() {
|
||||
final HashMap<String, State> changes = new HashMap<String, State>();
|
||||
protected HashMap<String, PowerState> deltaSync() {
|
||||
final HashMap<String, PowerState> changes = new HashMap<String, PowerState>();
|
||||
/*
|
||||
* Disable sync until we find a way that only tracks status but not does
|
||||
* action
|
||||
|
|
|
|||
|
|
@ -38,14 +38,10 @@ import com.cloud.agent.api.ReadyAnswer;
|
|||
import com.cloud.agent.api.ReadyCommand;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.api.StartupExternalDhcpCommand;
|
||||
import com.cloud.agent.api.StartupPxeServerCommand;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.resource.ServerResource;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.script.Script;
|
||||
import com.cloud.utils.ssh.SSHCmdHelper;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.trilead.ssh2.SCPClient;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
|
||||
public class BaremetalDhcpResourceBase extends ManagerBase implements ServerResource {
|
||||
private static final Logger s_logger = Logger.getLogger(BaremetalDhcpResourceBase.class);
|
||||
|
|
@ -129,7 +125,7 @@ public class BaremetalDhcpResourceBase extends ManagerBase implements ServerReso
|
|||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
//TODO: check server
|
||||
return new PingRoutingCommand(getType(), id, new HashMap<String, State>());
|
||||
return new PingRoutingCommand(getType(), id, new HashMap<String, PowerState>());
|
||||
}
|
||||
|
||||
protected ReadyAnswer execute(ReadyCommand cmd) {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ import com.cloud.agent.api.PingRoutingCommand;
|
|||
import com.cloud.agent.api.routing.DhcpEntryCommand;
|
||||
import com.cloud.utils.script.Script;
|
||||
import com.cloud.utils.ssh.SSHCmdHelper;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
import com.trilead.ssh2.SCPClient;
|
||||
|
||||
public class BaremetalDhcpdResource extends BaremetalDhcpResourceBase {
|
||||
|
|
@ -105,7 +105,7 @@ public class BaremetalDhcpdResource extends BaremetalDhcpResourceBase {
|
|||
return null;
|
||||
} else {
|
||||
SSHCmdHelper.releaseSshConnection(sshConnection);
|
||||
return new PingRoutingCommand(getType(), id, new HashMap<String, State>());
|
||||
return new PingRoutingCommand(getType(), id, new HashMap<String, PowerState>());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import com.cloud.agent.api.PingRoutingCommand;
|
|||
import com.cloud.agent.api.routing.DhcpEntryCommand;
|
||||
import com.cloud.utils.script.Script;
|
||||
import com.cloud.utils.ssh.SSHCmdHelper;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.trilead.ssh2.SCPClient;
|
||||
|
||||
|
|
@ -98,7 +99,7 @@ public class BaremetalDnsmasqResource extends BaremetalDhcpResourceBase {
|
|||
return null;
|
||||
} else {
|
||||
SSHCmdHelper.releaseSshConnection(sshConnection);
|
||||
return new PingRoutingCommand(getType(), id, new HashMap<String, State>());
|
||||
return new PingRoutingCommand(getType(), id, new HashMap<String, PowerState>());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import com.cloud.agent.api.routing.VmDataCommand;
|
|||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.script.Script;
|
||||
import com.cloud.utils.ssh.SSHCmdHelper;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
import com.trilead.ssh2.SCPClient;
|
||||
|
||||
public class BaremetalKickStartPxeResource extends BaremetalPxeResourceBase {
|
||||
|
|
@ -106,7 +106,7 @@ public class BaremetalKickStartPxeResource extends BaremetalPxeResourceBase {
|
|||
return null;
|
||||
} else {
|
||||
SSHCmdHelper.releaseSshConnection(sshConnection);
|
||||
return new PingRoutingCommand(getType(), id, new HashMap<String, State>());
|
||||
return new PingRoutingCommand(getType(), id, new HashMap<String, PowerState>());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import com.cloud.agent.api.baremetal.prepareCreateTemplateCommand;
|
|||
import com.cloud.agent.api.routing.VmDataCommand;
|
||||
import com.cloud.utils.script.Script;
|
||||
import com.cloud.utils.ssh.SSHCmdHelper;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
import com.trilead.ssh2.SCPClient;
|
||||
|
||||
public class BaremetalPingPxeResource extends BaremetalPxeResourceBase {
|
||||
|
|
@ -142,7 +142,7 @@ public class BaremetalPingPxeResource extends BaremetalPxeResourceBase {
|
|||
return null;
|
||||
} else {
|
||||
SSHCmdHelper.releaseSshConnection(sshConnection);
|
||||
return new PingRoutingCommand(getType(), id, new HashMap<String, State>());
|
||||
return new PingRoutingCommand(getType(), id, new HashMap<String, PowerState>());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -241,6 +241,7 @@ import com.cloud.utils.script.OutputInterpreter;
|
|||
import com.cloud.utils.script.Script;
|
||||
import com.cloud.vm.DiskProfile;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
import com.ceph.rados.Rados;
|
||||
|
|
@ -378,21 +379,21 @@ ServerResource {
|
|||
protected int _timeout;
|
||||
protected int _cmdsTimeout;
|
||||
protected int _stopTimeout;
|
||||
protected static HashMap<DomainInfo.DomainState, State> s_statesTable;
|
||||
protected static HashMap<DomainInfo.DomainState, PowerState> s_statesTable;
|
||||
static {
|
||||
s_statesTable = new HashMap<DomainInfo.DomainState, State>();
|
||||
s_statesTable = new HashMap<DomainInfo.DomainState, PowerState>();
|
||||
s_statesTable.put(DomainInfo.DomainState.VIR_DOMAIN_SHUTOFF,
|
||||
State.Stopped);
|
||||
PowerState.PowerOff);
|
||||
s_statesTable.put(DomainInfo.DomainState.VIR_DOMAIN_PAUSED,
|
||||
State.Running);
|
||||
PowerState.PowerOn);
|
||||
s_statesTable.put(DomainInfo.DomainState.VIR_DOMAIN_RUNNING,
|
||||
State.Running);
|
||||
PowerState.PowerOn);
|
||||
s_statesTable.put(DomainInfo.DomainState.VIR_DOMAIN_BLOCKED,
|
||||
State.Running);
|
||||
PowerState.PowerOn);
|
||||
s_statesTable.put(DomainInfo.DomainState.VIR_DOMAIN_NOSTATE,
|
||||
State.Unknown);
|
||||
PowerState.PowerUnknown);
|
||||
s_statesTable.put(DomainInfo.DomainState.VIR_DOMAIN_SHUTDOWN,
|
||||
State.Stopping);
|
||||
PowerState.PowerOff);
|
||||
}
|
||||
|
||||
protected HashMap<String, State> _vms = new HashMap<String, State>(20);
|
||||
|
|
@ -2778,18 +2779,18 @@ ServerResource {
|
|||
return new ReadyAnswer(cmd);
|
||||
}
|
||||
|
||||
protected State convertToState(DomainInfo.DomainState ps) {
|
||||
final State state = s_statesTable.get(ps);
|
||||
return state == null ? State.Unknown : state;
|
||||
protected PowerState convertToState(DomainInfo.DomainState ps) {
|
||||
final PowerState state = s_statesTable.get(ps);
|
||||
return state == null ? PowerState.PowerUnknown : state;
|
||||
}
|
||||
|
||||
protected State getVmState(Connect conn, final String vmName) {
|
||||
protected PowerState getVmState(Connect conn, final String vmName) {
|
||||
int retry = 3;
|
||||
Domain vms = null;
|
||||
while (retry-- > 0) {
|
||||
try {
|
||||
vms = conn.domainLookupByName(vmName);
|
||||
State s = convertToState(vms.getInfo().state);
|
||||
PowerState s = convertToState(vms.getInfo().state);
|
||||
return s;
|
||||
} catch (final LibvirtException e) {
|
||||
s_logger.warn("Can't get vm state " + vmName + e.getMessage()
|
||||
|
|
@ -2804,15 +2805,15 @@ ServerResource {
|
|||
}
|
||||
}
|
||||
}
|
||||
return State.Stopped;
|
||||
return PowerState.PowerOff;
|
||||
}
|
||||
|
||||
private Answer execute(CheckVirtualMachineCommand cmd) {
|
||||
try {
|
||||
Connect conn = LibvirtConnection.getConnectionByVmName(cmd.getVmName());
|
||||
final State state = getVmState(conn, cmd.getVmName());
|
||||
final PowerState state = getVmState(conn, cmd.getVmName());
|
||||
Integer vncPort = null;
|
||||
if (state == State.Running) {
|
||||
if (state == PowerState.PowerOn) {
|
||||
vncPort = getVncPort(conn, cmd.getVmName());
|
||||
|
||||
synchronized (_vms) {
|
||||
|
|
@ -3930,7 +3931,7 @@ ServerResource {
|
|||
|
||||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
final HashMap<String, State> newStates = sync();
|
||||
final HashMap<String, PowerState> newStates = sync();
|
||||
|
||||
if (!_can_bridge_firewall) {
|
||||
return new PingRoutingCommand(com.cloud.host.Host.Type.Routing, id,
|
||||
|
|
@ -3961,7 +3962,7 @@ ServerResource {
|
|||
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
Map<String, State> changes = null;
|
||||
Map<String, PowerState> changes = null;
|
||||
|
||||
synchronized (_vms) {
|
||||
_vms.clear();
|
||||
|
|
@ -4009,120 +4010,16 @@ ServerResource {
|
|||
return new StartupCommand[] { cmd };
|
||||
}
|
||||
}
|
||||
|
||||
protected HashMap<String, State> sync() {
|
||||
HashMap<String, State> newStates;
|
||||
HashMap<String, State> oldStates = null;
|
||||
|
||||
final HashMap<String, State> changes = new HashMap<String, State>();
|
||||
|
||||
synchronized (_vms) {
|
||||
newStates = getAllVms();
|
||||
if (newStates == null) {
|
||||
s_logger.debug("Unable to get the vm states so no state sync at this point.");
|
||||
return changes;
|
||||
}
|
||||
|
||||
oldStates = new HashMap<String, State>(_vms.size());
|
||||
oldStates.putAll(_vms);
|
||||
|
||||
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 (newState == State.Stopped && oldState != State.Stopping
|
||||
&& oldState != null && oldState != State.Stopped) {
|
||||
newState = getRealPowerState(vm);
|
||||
}
|
||||
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("VM " + vm + ": libvirt has state "
|
||||
+ newState + " and we have state "
|
||||
+ (oldState != null ? oldState.toString() : "null"));
|
||||
}
|
||||
|
||||
if (vm.startsWith("migrating")) {
|
||||
s_logger.debug("Migration 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) {
|
||||
if (_vmsKilled.remove(vm)) {
|
||||
s_logger.debug("VM " + vm
|
||||
+ " has been killed for storage. ");
|
||||
newState = State.Error;
|
||||
}
|
||||
}
|
||||
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 libvirt 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;
|
||||
if (_vmsKilled.remove(entry.getKey())) {
|
||||
s_logger.debug("VM " + vm
|
||||
+ " has been killed by storage monitor");
|
||||
state = State.Error;
|
||||
}
|
||||
changes.put(entry.getKey(), state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return changes;
|
||||
|
||||
protected HashMap<String, PowerState> sync() {
|
||||
HashMap<String, PowerState> newStates = getAllVms();
|
||||
if(newStates != null)
|
||||
return newStates;
|
||||
|
||||
return new HashMap<String, PowerState>();
|
||||
}
|
||||
|
||||
protected State getRealPowerState(String vm) {
|
||||
protected PowerState getRealPowerState(String vm) {
|
||||
int i = 0;
|
||||
s_logger.trace("Checking on the HALTED State");
|
||||
Domain dm = null;
|
||||
|
|
@ -4154,7 +4051,7 @@ ServerResource {
|
|||
s_logger.trace("Ignoring InterruptedException.", e);
|
||||
}
|
||||
}
|
||||
return State.Stopped;
|
||||
return PowerState.PowerOff;
|
||||
}
|
||||
|
||||
protected List<String> getAllVmNames(Connect conn) {
|
||||
|
|
@ -4197,8 +4094,8 @@ ServerResource {
|
|||
return la;
|
||||
}
|
||||
|
||||
private HashMap<String, State> getAllVms() {
|
||||
final HashMap<String, State> vmStates = new HashMap<String, State>();
|
||||
private HashMap<String, PowerState> getAllVms() {
|
||||
final HashMap<String, PowerState> vmStates = new HashMap<String, PowerState>();
|
||||
Connect conn = null;
|
||||
|
||||
if (_hypervisorType == HypervisorType.LXC) {
|
||||
|
|
@ -4222,8 +4119,8 @@ ServerResource {
|
|||
return vmStates;
|
||||
}
|
||||
|
||||
private HashMap<String, State> getAllVms(Connect conn) {
|
||||
final HashMap<String, State> vmStates = new HashMap<String, State>();
|
||||
private HashMap<String, PowerState> getAllVms(Connect conn) {
|
||||
final HashMap<String, PowerState> vmStates = new HashMap<String, PowerState>();
|
||||
|
||||
String[] vms = null;
|
||||
int[] ids = null;
|
||||
|
|
@ -4248,7 +4145,7 @@ ServerResource {
|
|||
|
||||
DomainInfo.DomainState ps = dm.getInfo().state;
|
||||
|
||||
final State state = convertToState(ps);
|
||||
final PowerState state = convertToState(ps);
|
||||
|
||||
s_logger.trace("VM " + dm.getName() + ": powerstate = " + ps
|
||||
+ "; vm state=" + state.toString());
|
||||
|
|
@ -4273,7 +4170,7 @@ ServerResource {
|
|||
dm = conn.domainLookupByName(vms[i]);
|
||||
|
||||
DomainInfo.DomainState ps = dm.getInfo().state;
|
||||
final State state = convertToState(ps);
|
||||
final PowerState state = convertToState(ps);
|
||||
String vmName = dm.getName();
|
||||
s_logger.trace("VM " + vmName + ": powerstate = " + ps
|
||||
+ "; vm state=" + state.toString());
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ import com.cloud.utils.script.Script;
|
|||
import com.cloud.utils.ssh.SSHCmdHelper;
|
||||
import com.cloud.vm.DiskProfile;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.trilead.ssh2.SCPClient;
|
||||
|
||||
|
|
@ -154,16 +155,16 @@ public class OvmResourceBase implements ServerResource, HypervisorResource {
|
|||
static boolean _isHeartBeat = false;
|
||||
List<String> _bridges = null;
|
||||
protected HashMap<String, State> _vms = new HashMap<String, State>(50);
|
||||
static HashMap<String, State> _stateMaps;
|
||||
static HashMap<String, PowerState> _stateMaps;
|
||||
private final Map<String, Pair<Long, Long>> _vmNetworkStats= new ConcurrentHashMap<String, Pair<Long, Long>>();
|
||||
private static String _ovsAgentPath = "/opt/ovs-agent-latest";
|
||||
|
||||
static {
|
||||
_stateMaps = new HashMap<String, State>();
|
||||
_stateMaps.put("RUNNING", State.Running);
|
||||
_stateMaps.put("DOWN", State.Stopped);
|
||||
_stateMaps.put("ERROR", State.Error);
|
||||
_stateMaps.put("SUSPEND", State.Stopped);
|
||||
_stateMaps = new HashMap<String, PowerState>();
|
||||
_stateMaps.put("RUNNING", PowerState.PowerOn);
|
||||
_stateMaps.put("DOWN", PowerState.PowerOff);
|
||||
_stateMaps.put("ERROR", PowerState.PowerUnknown);
|
||||
_stateMaps.put("SUSPEND", PowerState.PowerOff);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -378,7 +379,7 @@ public class OvmResourceBase implements ServerResource, HypervisorResource {
|
|||
try {
|
||||
StartupRoutingCommand cmd = new StartupRoutingCommand();
|
||||
fillHostInfo(cmd);
|
||||
Map<String, State> changes = null;
|
||||
Map<String, PowerState> changes = null;
|
||||
synchronized (_vms) {
|
||||
_vms.clear();
|
||||
changes = sync();
|
||||
|
|
@ -396,7 +397,7 @@ public class OvmResourceBase implements ServerResource, HypervisorResource {
|
|||
public PingCommand getCurrentStatus(long id) {
|
||||
try {
|
||||
OvmHost.ping(_conn);
|
||||
HashMap<String, State> newStates = sync();
|
||||
HashMap<String, PowerState> newStates = sync();
|
||||
return new PingRoutingCommand(getType(), id, newStates);
|
||||
} catch (XmlRpcException e) {
|
||||
s_logger.debug("Check agent status failed", e);
|
||||
|
|
@ -776,125 +777,35 @@ public class OvmResourceBase implements ServerResource, HypervisorResource {
|
|||
}
|
||||
}
|
||||
|
||||
private State toState(String vmName, String s) {
|
||||
State state = _stateMaps.get(s);
|
||||
private PowerState toState(String vmName, String s) {
|
||||
PowerState state = _stateMaps.get(s);
|
||||
if (state == null) {
|
||||
s_logger.debug("Unkown state " + s + " for " + vmName);
|
||||
state = State.Unknown;
|
||||
state = PowerState.PowerUnknown;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
protected HashMap<String, State> getAllVms() throws XmlRpcException {
|
||||
final HashMap<String, State> vmStates = new HashMap<String, State>();
|
||||
protected HashMap<String, PowerState> getAllVms() throws XmlRpcException {
|
||||
final HashMap<String, PowerState> vmStates = new HashMap<String, PowerState>();
|
||||
Map<String, String> vms = OvmHost.getAllVms(_conn);
|
||||
for (final Map.Entry<String, String> entry : vms.entrySet()) {
|
||||
State state = toState(entry.getKey(), entry.getValue());
|
||||
PowerState state = toState(entry.getKey(), entry.getValue());
|
||||
vmStates.put(entry.getKey(), state);
|
||||
}
|
||||
return vmStates;
|
||||
}
|
||||
|
||||
protected HashMap<String, State> sync() {
|
||||
HashMap<String, State> newStates;
|
||||
HashMap<String, State> oldStates = null;
|
||||
|
||||
try {
|
||||
final HashMap<String, State> changes = new HashMap<String, State>();
|
||||
newStates = getAllVms();
|
||||
if (newStates == null) {
|
||||
s_logger.debug("Unable to get the vm states so no state sync at this point.");
|
||||
return null;
|
||||
}
|
||||
|
||||
synchronized (_vms) {
|
||||
oldStates = new HashMap<String, State>(_vms.size());
|
||||
oldStates.putAll(_vms);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return changes;
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("Ovm full sync failed", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
protected HashMap<String, PowerState> sync() {
|
||||
try {
|
||||
HashMap<String, PowerState> newStates = getAllVms();
|
||||
|
||||
if(newStates != null)
|
||||
return newStates;
|
||||
} catch(Exception e) {
|
||||
}
|
||||
return new HashMap<String, PowerState>();
|
||||
}
|
||||
|
||||
protected GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) {
|
||||
try {
|
||||
|
|
@ -1017,14 +928,14 @@ public class OvmResourceBase implements ServerResource, HypervisorResource {
|
|||
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);
|
||||
HashMap<String, PowerState> states = getAllVms();
|
||||
PowerState vmState = states.get(vmName);
|
||||
if (vmState == null) {
|
||||
s_logger.warn("Check state of " + vmName + " return null in CheckVirtualMachineCommand");
|
||||
vmState = State.Stopped;
|
||||
vmState = PowerState.PowerOff;
|
||||
}
|
||||
|
||||
if (vmState == State.Running) {
|
||||
if (vmState == PowerState.PowerOn) {
|
||||
synchronized (_vms) {
|
||||
_vms.put(vmName, State.Running);
|
||||
}
|
||||
|
|
@ -1033,7 +944,7 @@ public class OvmResourceBase implements ServerResource, HypervisorResource {
|
|||
return new CheckVirtualMachineAnswer(cmd, vmState, vncPort);
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("Check migration for " + vmName + " failed", e);
|
||||
return new CheckVirtualMachineAnswer(cmd, State.Stopped, null);
|
||||
return new CheckVirtualMachineAnswer(cmd, PowerState.PowerOff, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ import com.cloud.utils.Ternary;
|
|||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -347,7 +348,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
|
|||
}
|
||||
|
||||
txn.commit();
|
||||
return new CheckVirtualMachineAnswer(cmd, vm.getState(), vm.getVncPort());
|
||||
return new CheckVirtualMachineAnswer(cmd, vm.getState() == State.Running ? PowerState.PowerOn : PowerState.PowerOff, vm.getVncPort());
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to fetch vm state " + cmd.getVmName(), ex);
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ import com.cloud.simulator.MockVMVO;
|
|||
import com.cloud.storage.Storage.StorageResourceType;
|
||||
import com.cloud.storage.template.TemplateProp;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
public class AgentRoutingResource extends AgentStorageResource {
|
||||
|
|
@ -112,17 +113,29 @@ public class AgentRoutingResource extends AgentStorageResource {
|
|||
_vms.putAll(_simMgr.getVmStates(hostGuid));
|
||||
}
|
||||
}
|
||||
final HashMap<String, State> newStates = sync();
|
||||
final HashMap<String, PowerState> newStates = sync();
|
||||
HashMap<String, Pair<Long, Long>> nwGrpStates = _simMgr.syncNetworkGroups(hostGuid);
|
||||
return new PingRoutingWithNwGroupsCommand(getType(), id, newStates, nwGrpStates);
|
||||
}
|
||||
|
||||
private HashMap<String, PowerState> getVmStates() {
|
||||
Map<String, State> rawStates = _simMgr.getVmStates(this.hostGuid);
|
||||
if(rawStates != null) {
|
||||
HashMap<String, PowerState> states = new HashMap<String, PowerState>();
|
||||
for(Map.Entry<String, State> entry : rawStates.entrySet()) {
|
||||
states.put(entry.getKey(), entry.getValue() == State.Running ? PowerState.PowerOn : PowerState.PowerOff);
|
||||
}
|
||||
return states;
|
||||
}
|
||||
return new HashMap<String, PowerState>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
synchronized (_vms) {
|
||||
_vms.clear();
|
||||
}
|
||||
Map<String, State> changes = _simMgr.getVmStates(this.hostGuid);
|
||||
Map<String, PowerState> changes = getVmStates();
|
||||
Map<String, MockVMVO> vmsMaps = _simMgr.getVms(this.hostGuid);
|
||||
totalCpu = agentHost.getCpuCount() * agentHost.getCpuSpeed();
|
||||
totalMem = agentHost.getMemorySize();
|
||||
|
|
@ -251,8 +264,8 @@ public class AgentRoutingResource extends AgentStorageResource {
|
|||
protected CheckVirtualMachineAnswer execute(final CheckVirtualMachineCommand cmd) {
|
||||
final String vmName = cmd.getVmName();
|
||||
CheckVirtualMachineAnswer result = (CheckVirtualMachineAnswer)_simMgr.simulate(cmd, hostGuid);
|
||||
State state = result.getState();
|
||||
if (state == State.Running) {
|
||||
PowerState state = result.getState();
|
||||
if (state == PowerState.PowerOn) {
|
||||
synchronized (_vms) {
|
||||
_vms.put(vmName, State.Running);
|
||||
}
|
||||
|
|
@ -275,72 +288,9 @@ public class AgentRoutingResource extends AgentStorageResource {
|
|||
|
||||
return info;
|
||||
}
|
||||
|
||||
protected HashMap<String, State> sync() {
|
||||
Map<String, State> newStates;
|
||||
Map<String, State> oldStates = null;
|
||||
|
||||
HashMap<String, State> changes = new HashMap<String, State>();
|
||||
|
||||
synchronized (_vms) {
|
||||
oldStates = new HashMap<String, State>(_vms.size());
|
||||
oldStates.putAll(_vms);
|
||||
newStates = new HashMap<String, State>(_vms.size());
|
||||
newStates.putAll(_vms);
|
||||
|
||||
for (Map.Entry<String, State> entry : newStates.entrySet()) {
|
||||
String vm = entry.getKey();
|
||||
|
||||
State newState = entry.getValue();
|
||||
State oldState = oldStates.remove(vm);
|
||||
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("VM " + vm + ": has state " + newState + " and we have state " + (oldState != null ? oldState.toString() : "null"));
|
||||
}
|
||||
|
||||
if (oldState == null) {
|
||||
_vms.put(vm, newState);
|
||||
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.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);
|
||||
changes.put(vm, newState);
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<String, State> entry : oldStates.entrySet()) {
|
||||
String vm = entry.getKey();
|
||||
State oldState = entry.getValue();
|
||||
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("VM " + vm + " is now missing from simulator agent 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 {
|
||||
changes.put(entry.getKey(), State.Stopped);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return changes;
|
||||
|
||||
protected HashMap<String, PowerState> sync() {
|
||||
return this.getVmStates();
|
||||
}
|
||||
|
||||
private Answer execute(ShutdownCommand cmd) {
|
||||
|
|
|
|||
|
|
@ -329,6 +329,7 @@ import com.cloud.utils.net.NetUtils;
|
|||
import com.cloud.utils.ssh.SshHelper;
|
||||
import com.cloud.vm.DiskProfile;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachineName;
|
||||
import com.cloud.vm.VmDetailConstants;
|
||||
|
|
@ -386,12 +387,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
protected StorageSubsystemCommandHandler storageHandler;
|
||||
|
||||
protected static HashMap<VirtualMachinePowerState, State> s_statesTable;
|
||||
protected static HashMap<VirtualMachinePowerState, PowerState> s_statesTable;
|
||||
static {
|
||||
s_statesTable = new HashMap<VirtualMachinePowerState, State>();
|
||||
s_statesTable.put(VirtualMachinePowerState.POWERED_ON, State.Running);
|
||||
s_statesTable.put(VirtualMachinePowerState.POWERED_OFF, State.Stopped);
|
||||
s_statesTable.put(VirtualMachinePowerState.SUSPENDED, State.Stopped);
|
||||
s_statesTable = new HashMap<VirtualMachinePowerState, PowerState>();
|
||||
s_statesTable.put(VirtualMachinePowerState.POWERED_ON, PowerState.PowerOn);
|
||||
s_statesTable.put(VirtualMachinePowerState.POWERED_OFF, PowerState.PowerOff);
|
||||
s_statesTable.put(VirtualMachinePowerState.SUSPENDED, PowerState.PowerOn);
|
||||
}
|
||||
|
||||
public Gson getGson() {
|
||||
|
|
@ -2552,7 +2553,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
long requestedMaxMemoryInMb = vmSpec.getMaxRam() / (1024 * 1024);
|
||||
|
||||
// Check if VM is really running on hypervisor host
|
||||
if (getVmState(vmMo) != State.Running) {
|
||||
if (getVmState(vmMo) != PowerState.PowerOn) {
|
||||
throw new CloudRuntimeException("Found that the VM " + vmMo.getVmName() + " is not running. Unable to scale-up this VM");
|
||||
}
|
||||
|
||||
|
|
@ -2632,7 +2633,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
boolean hasSnapshot = false;
|
||||
if (vmMo != null) {
|
||||
s_logger.info("VM " + vmInternalCSName + " already exists, tear down devices for reconfiguration");
|
||||
if (getVmState(vmMo) != State.Stopped)
|
||||
if (getVmState(vmMo) != PowerState.PowerOff)
|
||||
vmMo.safePowerOff(_shutdown_waitMs);
|
||||
|
||||
// retrieve disk information before we tear down
|
||||
|
|
@ -2655,7 +2656,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
takeVmFromOtherHyperHost(hyperHost, vmInternalCSName);
|
||||
|
||||
if (getVmState(vmMo) != State.Stopped)
|
||||
if (getVmState(vmMo) != PowerState.PowerOff)
|
||||
vmMo.safePowerOff(_shutdown_waitMs);
|
||||
|
||||
diskInfoBuilder = vmMo.getDiskInfoBuilder();
|
||||
|
|
@ -3773,7 +3774,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
HashMap<String, VmStatsEntry> vmStatsMap = null;
|
||||
|
||||
try {
|
||||
HashMap<String, State> newStates = getVmStates();
|
||||
HashMap<String, PowerState> newStates = getVmStates();
|
||||
|
||||
// getVmNames should return all i-x-y values.
|
||||
List<String> requestedVmNames = cmd.getVmNames();
|
||||
|
|
@ -3854,7 +3855,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
try {
|
||||
vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK, "0");
|
||||
|
||||
if (getVmState(vmMo) != State.Stopped) {
|
||||
if (getVmState(vmMo) != PowerState.PowerOff) {
|
||||
if (vmMo.safePowerOff(_shutdown_waitMs)) {
|
||||
state = State.Stopped;
|
||||
return new StopAnswer(cmd, "Stop VM " + cmd.getVmName() + " Succeed", 0, true);
|
||||
|
|
@ -3965,7 +3966,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
|
||||
final String vmName = cmd.getVmName();
|
||||
State state = State.Unknown;
|
||||
PowerState state = PowerState.PowerUnknown;
|
||||
Integer vncPort = null;
|
||||
|
||||
VmwareContext context = getServiceContext();
|
||||
|
|
@ -3975,7 +3976,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
|
||||
if (vmMo != null) {
|
||||
state = getVmState(vmMo);
|
||||
if (state == State.Running) {
|
||||
if (state == PowerState.PowerOn) {
|
||||
synchronized (_vms) {
|
||||
_vms.put(vmName, State.Running);
|
||||
}
|
||||
|
|
@ -5428,7 +5429,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
List<NetworkDetails> networks = vmMo.getNetworksWithDetails();
|
||||
|
||||
// tear down all devices first before we destroy the VM to avoid accidently delete disk backing files
|
||||
if (getVmState(vmMo) != State.Stopped)
|
||||
if (getVmState(vmMo) != PowerState.PowerOff)
|
||||
vmMo.safePowerOff(_shutdown_waitMs);
|
||||
vmMo.tearDownDevices(new Class<?>[] { /* VirtualDisk.class, */ VirtualEthernetCard.class });
|
||||
vmMo.destroy();
|
||||
|
|
@ -5754,7 +5755,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
try {
|
||||
HashMap<String, State> newStates = sync();
|
||||
HashMap<String, PowerState> newStates = sync();
|
||||
if (newStates == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -5868,7 +5869,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
StartupRoutingCommand cmd = new StartupRoutingCommand();
|
||||
fillHostInfo(cmd);
|
||||
|
||||
Map<String, State> changes = null;
|
||||
Map<String, PowerState> changes = null;
|
||||
synchronized (_vms) {
|
||||
_vms.clear();
|
||||
changes = sync();
|
||||
|
|
@ -6029,112 +6030,13 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
details.put("NativeHA", "true");
|
||||
}
|
||||
}
|
||||
|
||||
protected HashMap<String, State> sync() {
|
||||
HashMap<String, State> changes = new HashMap<String, State>();
|
||||
HashMap<String, State> oldStates = null;
|
||||
|
||||
try {
|
||||
synchronized (_vms) {
|
||||
HashMap<String, State> newStates = getVmStates();
|
||||
oldStates = new HashMap<String, State>(_vms.size());
|
||||
oldStates.putAll(_vms);
|
||||
|
||||
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 + ": vSphere has state " + newState + " and we have state " + (oldState != null ? oldState.toString() : "null"));
|
||||
}
|
||||
|
||||
if (vm.startsWith("migrating")) {
|
||||
s_logger.debug("Migrating 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) {
|
||||
/*
|
||||
* if (_vmsKilled.remove(vm)) { s_logger.debug("VM " + vm + " has been killed for storage. ");
|
||||
* newState = State.Error; }
|
||||
*/
|
||||
}
|
||||
changes.put(vm, newState);
|
||||
}
|
||||
}
|
||||
|
||||
for (final Map.Entry<String, State> entry : oldStates.entrySet()) {
|
||||
final String vm = entry.getKey();
|
||||
final State oldState = entry.getValue();
|
||||
|
||||
if (isVmInCluster(vm)) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("VM " + vm + " is now missing from host report but we detected that it might be migrated to other host by vCenter");
|
||||
}
|
||||
|
||||
if(oldState != State.Starting && oldState != State.Migrating) {
|
||||
s_logger.debug("VM " + vm + " is now missing from host report and VM is not at starting/migrating state, remove it from host VM-sync map, oldState: " + oldState);
|
||||
_vms.remove(vm);
|
||||
} else {
|
||||
s_logger.debug("VM " + vm + " is missing from host report, but we will ignore VM " + vm + " in transition state " + oldState);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("VM " + vm + " is now missing from host report");
|
||||
}
|
||||
|
||||
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 {
|
||||
State state = State.Stopped;
|
||||
changes.put(entry.getKey(), state);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
s_logger.error("Unable to perform sync information collection process at this point due to " + VmwareHelper.getExceptionMessage(e), e);
|
||||
return null;
|
||||
}
|
||||
return changes;
|
||||
|
||||
protected HashMap<String, PowerState> sync() {
|
||||
try {
|
||||
return getVmStates();
|
||||
} catch(Exception e) {
|
||||
return new HashMap<String, PowerState>();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isVmInCluster(String vmName) throws Exception {
|
||||
|
|
@ -6234,7 +6136,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
return VirtualMachineGuestOsIdentifier.OTHER_GUEST;
|
||||
}
|
||||
|
||||
private HashMap<String, State> getVmStates() throws Exception {
|
||||
private HashMap<String, PowerState> getVmStates() throws Exception {
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
|
||||
int key = ((HostMO)hyperHost).getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
|
|
@ -6247,7 +6149,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
// the internal CS name, but the custom field CLOUD_VM_INTERNAL_NAME always stores the internal CS name.
|
||||
ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new String[] { "name", "runtime.powerState", "config.template", instanceNameCustomField });
|
||||
|
||||
HashMap<String, State> newStates = new HashMap<String, State>();
|
||||
HashMap<String, PowerState> newStates = new HashMap<String, PowerState>();
|
||||
if (ocs != null && ocs.length > 0) {
|
||||
for (ObjectContent oc : ocs) {
|
||||
List<DynamicProperty> objProps = oc.getPropSet();
|
||||
|
|
@ -6511,11 +6413,11 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
return connect(vmname, ipAddress, 3922);
|
||||
}
|
||||
|
||||
private static State convertState(VirtualMachinePowerState powerState) {
|
||||
private static PowerState convertState(VirtualMachinePowerState powerState) {
|
||||
return s_statesTable.get(powerState);
|
||||
}
|
||||
|
||||
public static State getVmState(VirtualMachineMO vmMo) throws Exception {
|
||||
public static PowerState getVmState(VirtualMachineMO vmMo) throws Exception {
|
||||
VirtualMachineRuntimeInfo runtimeInfo = vmMo.getRuntimeInfo();
|
||||
return convertState(runtimeInfo.getPowerState());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ import com.cloud.storage.template.VmdkProcessor;
|
|||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.Ternary;
|
||||
import com.cloud.utils.script.Script;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.google.gson.Gson;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
|
|
@ -1491,7 +1492,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||
List<NetworkDetails> networks = vmMo.getNetworksWithDetails();
|
||||
|
||||
// tear down all devices first before we destroy the VM to avoid accidently delete disk backing files
|
||||
if (this.resource.getVmState(vmMo) != State.Stopped) {
|
||||
if (this.resource.getVmState(vmMo) != PowerState.PowerOff) {
|
||||
vmMo.safePowerOff(_shutdown_waitMs);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -214,6 +214,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
|||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.DiskProfile;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.snapshot.VMSnapshot;
|
||||
import com.google.gson.Gson;
|
||||
|
|
@ -372,14 +373,14 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
}
|
||||
}
|
||||
|
||||
protected static HashMap<Types.VmPowerState, State> s_statesTable;
|
||||
protected static HashMap<Types.VmPowerState, PowerState> s_statesTable;
|
||||
static {
|
||||
s_statesTable = new HashMap<Types.VmPowerState, State>();
|
||||
s_statesTable.put(Types.VmPowerState.HALTED, State.Stopped);
|
||||
s_statesTable.put(Types.VmPowerState.PAUSED, State.Running);
|
||||
s_statesTable.put(Types.VmPowerState.RUNNING, State.Running);
|
||||
s_statesTable.put(Types.VmPowerState.SUSPENDED, State.Running);
|
||||
s_statesTable.put(Types.VmPowerState.UNRECOGNIZED, State.Unknown);
|
||||
s_statesTable = new HashMap<Types.VmPowerState, PowerState>();
|
||||
s_statesTable.put(Types.VmPowerState.HALTED, PowerState.PowerOff);
|
||||
s_statesTable.put(Types.VmPowerState.PAUSED, PowerState.PowerOn);
|
||||
s_statesTable.put(Types.VmPowerState.RUNNING, PowerState.PowerOn);
|
||||
s_statesTable.put(Types.VmPowerState.SUSPENDED, PowerState.PowerOn);
|
||||
s_statesTable.put(Types.VmPowerState.UNRECOGNIZED, PowerState.PowerUnknown);
|
||||
}
|
||||
|
||||
public XsHost getHost() {
|
||||
|
|
@ -2861,13 +2862,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
.valueOf(_pollingIntervalInSeconds), "startTime", startTime);
|
||||
}
|
||||
|
||||
protected State convertToState(Types.VmPowerState ps) {
|
||||
final State state = s_statesTable.get(ps);
|
||||
return state == null ? State.Unknown : state;
|
||||
protected PowerState convertToState(Types.VmPowerState ps) {
|
||||
final PowerState state = s_statesTable.get(ps);
|
||||
return state == null ? PowerState.PowerUnknown : state;
|
||||
}
|
||||
|
||||
protected HashMap<String, Pair<String, State>> getAllVms(Connection conn) {
|
||||
final HashMap<String, Pair<String, State>> vmStates = new HashMap<String, Pair<String, State>>();
|
||||
protected HashMap<String, Pair<String, PowerState>> getAllVms(Connection conn) {
|
||||
final HashMap<String, Pair<String, PowerState>> vmStates = new HashMap<String, Pair<String, PowerState>>();
|
||||
Map<VM, VM.Record> vm_map = null;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
try {
|
||||
|
|
@ -2892,7 +2893,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
}
|
||||
|
||||
VmPowerState ps = record.powerState;
|
||||
final State state = convertToState(ps);
|
||||
final PowerState state = convertToState(ps);
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("VM " + record.nameLabel + ": powerstate = " + ps + "; vm state=" + state.toString());
|
||||
}
|
||||
|
|
@ -2908,14 +2909,14 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
} catch (XmlRpcException e) {
|
||||
s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
|
||||
}
|
||||
vmStates.put(record.nameLabel, new Pair<String, State>(host_uuid, state));
|
||||
vmStates.put(record.nameLabel, new Pair<String, PowerState>(host_uuid, state));
|
||||
}
|
||||
}
|
||||
|
||||
return vmStates;
|
||||
}
|
||||
|
||||
protected State getVmState(Connection conn, final String vmName) {
|
||||
protected PowerState getVmState(Connection conn, final String vmName) {
|
||||
int retry = 3;
|
||||
while (retry-- > 0) {
|
||||
try {
|
||||
|
|
@ -2952,15 +2953,15 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
}
|
||||
}
|
||||
|
||||
return State.Stopped;
|
||||
return PowerState.PowerOff;
|
||||
}
|
||||
|
||||
protected CheckVirtualMachineAnswer execute(final CheckVirtualMachineCommand cmd) {
|
||||
Connection conn = getConnection();
|
||||
final String vmName = cmd.getVmName();
|
||||
final State state = getVmState(conn, vmName);
|
||||
final PowerState state = getVmState(conn, vmName);
|
||||
Integer vncPort = null;
|
||||
if (state == State.Running) {
|
||||
if (state == PowerState.PowerOn) {
|
||||
synchronized (_cluster.intern()) {
|
||||
s_vms.put(_cluster, _name, vmName, State.Running);
|
||||
}
|
||||
|
|
@ -3280,7 +3281,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
|
||||
}
|
||||
|
||||
protected State getRealPowerState(Connection conn, String label) {
|
||||
protected PowerState getRealPowerState(Connection conn, String label) {
|
||||
int i = 0;
|
||||
s_logger.trace("Checking on the HALTED State");
|
||||
for (; i < 20; i++) {
|
||||
|
|
@ -3309,7 +3310,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
return State.Stopped;
|
||||
return PowerState.PowerOff;
|
||||
}
|
||||
|
||||
protected Pair<VM, VM.Record> getControlDomain(Connection conn) throws XenAPIException, XmlRpcException {
|
||||
|
|
@ -4877,7 +4878,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
|
||||
Host.Record hostr = poolr.master.getRecord(conn);
|
||||
if (_host.uuid.equals(hostr.uuid)) {
|
||||
HashMap<String, Pair<String, State>> allStates=fullClusterSync(conn);
|
||||
HashMap<String, Pair<String, PowerState>> allStates=fullClusterSync(conn);
|
||||
cmd.setClusterVMStateChanges(allStates);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
|
|
@ -8004,12 +8005,14 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
s_logger.warn("Check for master failed, failing the Cluster sync command");
|
||||
return new Answer(cmd);
|
||||
}
|
||||
HashMap<String, Pair<String, State>> newStates = deltaClusterSync(conn);
|
||||
|
||||
HashMap<String, Pair<String, State>> newStates = new HashMap<String, Pair<String, State>>();
|
||||
// HashMap<String, Pair<String, State>> newStates = deltaClusterSync(conn);
|
||||
return new ClusterSyncAnswer(cmd.getClusterId(), newStates);
|
||||
}
|
||||
|
||||
|
||||
protected HashMap<String, Pair<String, State>> fullClusterSync(Connection conn) {
|
||||
protected HashMap<String, Pair<String, PowerState>> fullClusterSync(Connection conn) {
|
||||
synchronized (_cluster.intern()) {
|
||||
s_vms.clear(_cluster);
|
||||
}
|
||||
|
|
@ -8021,13 +8024,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
}
|
||||
String vm_name = record.nameLabel;
|
||||
VmPowerState ps = record.powerState;
|
||||
final State state = convertToState(ps);
|
||||
final PowerState 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);
|
||||
s_vms.put(_cluster, host_uuid, vm_name, state == PowerState.PowerOn ? State.Running : State.Stopped);
|
||||
}
|
||||
}
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
|
|
@ -8039,117 +8042,19 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
s_logger.warn(msg, e);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
return s_vms.getClusterVmState(_cluster);
|
||||
}
|
||||
|
||||
|
||||
protected HashMap<String, Pair<String, State>> deltaClusterSync(Connection conn) {
|
||||
final HashMap<String, Pair<String, State>> changes = new HashMap<String, Pair<String, State>>();
|
||||
|
||||
|
||||
synchronized (_cluster.intern()) {
|
||||
HashMap<String, Pair<String, State>> newStates = getAllVms(conn);
|
||||
if (newStates == null) {
|
||||
s_logger.warn("Unable to get the vm states so no state sync at this point.");
|
||||
return null;
|
||||
}
|
||||
HashMap<String, Pair<String, State>> oldStates = new HashMap<String, Pair<String, State>>(s_vms.size(_cluster));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<String, Pair<String, PowerState>> states = new HashMap<String, Pair<String, PowerState>> ();
|
||||
|
||||
HashMap<String, Pair<String, State>> rawStates = s_vms.getClusterVmState(_cluster);
|
||||
if(rawStates != null) {
|
||||
for(Map.Entry<String, Pair<String, State>> entry : rawStates.entrySet()) {
|
||||
states.put(entry.getKey(), new Pair<String, PowerState>(
|
||||
entry.getValue().first(),
|
||||
entry.getValue().second() == State.Running ? PowerState.PowerOn : PowerState.PowerOff));
|
||||
}
|
||||
}
|
||||
return changes;
|
||||
|
||||
return states;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
|
||||
public class XenServerPoolVms {
|
||||
private static final Logger s_logger = Logger.getLogger(XenServerPoolVms.class);
|
||||
private final Map<String/* clusterId */, HashMap<String/* vm name */, Pair<String/* host uuid */, State/* vm state */>>> _cluster_vms =
|
||||
|
|
@ -83,4 +82,3 @@ public class XenServerPoolVms {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import com.cloud.host.Host;
|
|||
import com.cloud.host.Status;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
@Local(value=Investigator.class)
|
||||
|
|
@ -57,7 +58,7 @@ public class CheckOnAgentInvestigator extends AdapterBase implements Investigato
|
|||
}
|
||||
|
||||
s_logger.debug("Agent responded with state " + answer.getState().toString());
|
||||
return answer.getState() == State.Running;
|
||||
return answer.getState() == PowerState.PowerOn;
|
||||
} catch (AgentUnavailableException e) {
|
||||
s_logger.debug("Unable to reach the agent for " + vm.toString() + ": " + e.getMessage());
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ import javax.naming.ConfigurationException;
|
|||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.HostVmStateReportEntry;
|
||||
import com.cloud.agent.api.PingCommand;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.api.StartupRoutingCommand;
|
||||
import com.cloud.agent.api.StartupRoutingCommand.VmState;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.resource.ServerResource;
|
||||
|
|
@ -46,7 +46,7 @@ public class KvmDummyResourceBase extends ServerResourceBase implements ServerRe
|
|||
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
StartupRoutingCommand cmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.KVM, new HashMap<String, String>(), new HashMap<String, VmState>());
|
||||
StartupRoutingCommand cmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.KVM, new HashMap<String, String>(), new HashMap<String, HostVmStateReportEntry>());
|
||||
cmd.setDataCenter(_zoneId);
|
||||
cmd.setPod(_podId);
|
||||
cmd.setCluster(_clusterId);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import com.cloud.host.Host.Type;
|
|||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.utils.net.MacAddress;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.PowerState;
|
||||
|
||||
public class DummyHostServerResource extends ServerResourceBase {
|
||||
|
||||
|
|
@ -56,7 +57,7 @@ public class DummyHostServerResource extends ServerResourceBase {
|
|||
|
||||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
HashMap<String, VirtualMachine.State> newStates = new HashMap<String, VirtualMachine.State>();
|
||||
HashMap<String, PowerState> newStates = new HashMap<String, PowerState>();
|
||||
return new PingRoutingCommand(com.cloud.host.Host.Type.Routing, id, newStates);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue