use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3HypervisorSupport method execute.
/* check "the" virtual machine */
public CheckVirtualMachineAnswer execute(final CheckVirtualMachineCommand cmd) {
LOGGER.debug("CheckVirtualMachineCommand: " + cmd.getVmName());
String vmName = cmd.getVmName();
try {
CloudstackPlugin plug = new CloudstackPlugin(c);
Integer vncPort = Integer.valueOf(plug.getVncPort(vmName));
if (vncPort == 0) {
LOGGER.warn("No VNC port for " + vmName);
}
/* we already have the state ftw */
Map<String, State> states = getAllVmStates(vmStateMap);
State vmState = states.get(vmName);
if (vmState == null) {
LOGGER.warn("Check state of " + vmName + " return null in CheckVirtualMachineCommand");
vmState = State.Stopped;
}
synchronized (vmStateMap) {
vmStateMap.put(vmName, State.Running);
}
return new CheckVirtualMachineAnswer(cmd, convertStateToPower(vmState), vncPort);
} catch (Ovm3ResourceException e) {
LOGGER.debug("Check migration for " + vmName + " failed", e);
return new CheckVirtualMachineAnswer(cmd, convertStateToPower(State.Stopped), null);
}
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3HypervisorSupport method masterCheck.
/**
* materCheck
*
* @return
*/
public boolean masterCheck() {
if ("".equals(config.getOvm3PoolVip())) {
LOGGER.debug("No cluster vip, not checking for master");
return false;
}
try {
CloudstackPlugin cSp = new CloudstackPlugin(c);
if (cSp.dom0HasIp(config.getOvm3PoolVip())) {
LOGGER.debug(config.getAgentHostname() + " is a master, already has vip " + config.getOvm3PoolVip());
config.setAgentIsMaster(true);
} else if (cSp.ping(config.getOvm3PoolVip())) {
LOGGER.debug(config.getAgentHostname() + " has a master, someone has vip " + config.getOvm3PoolVip());
config.setAgentHasMaster(true);
} else {
LOGGER.debug(config.getAgentHostname() + " becomes a master, no one has vip " + config.getOvm3PoolVip());
config.setAgentIsMaster(true);
}
} catch (Ovm3ResourceException e) {
LOGGER.debug(config.getAgentHostname() + " can't reach master: " + e.getMessage());
config.setAgentHasMaster(false);
}
return config.getAgentIsMaster();
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3HypervisorSupport method execute.
public CheckOnHostAnswer execute(CheckOnHostCommand cmd) {
LOGGER.debug("CheckOnHostCommand");
CloudstackPlugin csp = new CloudstackPlugin(c);
try {
Boolean alive = csp.dom0CheckStorageHealth(config.getAgentScriptsDir(), config.getAgentCheckStorageScript(), cmd.getHost().getGuid(), config.getAgentStorageCheckTimeout());
String msg = "";
if (alive == null) {
msg = "storage check failed for " + cmd.getHost().getGuid();
} else if (alive) {
msg = "storage check ok for " + cmd.getHost().getGuid();
} else {
msg = "storage dead for " + cmd.getHost().getGuid();
}
LOGGER.debug(msg);
return new CheckOnHostAnswer(cmd, alive, msg);
} catch (Ovm3ResourceException e) {
return new CheckOnHostAnswer(cmd, false, "Error while checking storage for " + cmd.getHost().getGuid() + ": " + e.getMessage());
}
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3HypervisorSupport method syncState.
private Map<String, State> syncState(Map<String, State> vmStateMap) throws Ovm3ResourceException {
Map<String, State> newStates;
Map<String, State> oldStates = null;
final Map<String, State> changes = new HashMap<String, State>();
try {
newStates = getAllVmStates(vmStateMap);
} catch (Ovm3ResourceException e) {
LOGGER.error("Ovm3 full sync failed: ", e);
throw e;
}
synchronized (vmStateMap) {
oldStates = new HashMap<String, State>(vmStateMap.size());
oldStates.putAll(vmStateMap);
for (final Map.Entry<String, State> entry : newStates.entrySet()) {
final String vmName = entry.getKey();
State newState = entry.getValue();
final State oldState = oldStates.remove(vmName);
LOGGER.trace("state for " + vmName + ", old: " + oldState + ", new: " + newState);
/* eurh ? */
if (newState == State.Stopped && oldState != State.Stopping && oldState != null && oldState != State.Stopped) {
LOGGER.trace("Getting power state....");
newState = State.Running;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("VM " + vmName + ": ovm has state " + newState + " and we have state " + (oldState != null ? oldState.toString() : "null"));
}
if (newState == State.Migrating) {
LOGGER.trace(vmName + " is migrating, skipping state check");
continue;
}
if (oldState == null) {
vmStateMap.put(vmName, newState);
LOGGER.debug("New state without old state: " + vmName);
changes.put(vmName, newState);
} else if (oldState == State.Starting) {
if (newState == State.Running) {
vmStateMap.put(vmName, newState);
} else if (newState == State.Stopped) {
LOGGER.debug("Ignoring vm " + vmName + " because of a lag in starting the vm.");
}
} else if (oldState == State.Migrating) {
if (newState == State.Running) {
LOGGER.debug("Detected that a migrating VM is now running: " + vmName);
vmStateMap.put(vmName, newState);
}
} else if (oldState == State.Stopping) {
if (newState == State.Stopped) {
vmStateMap.put(vmName, newState);
} else if (newState == State.Running) {
LOGGER.debug("Ignoring vm " + vmName + " because of a lag in stopping the vm. ");
/* should kill it hard perhaps ? */
}
} else if (oldState != newState) {
vmStateMap.put(vmName, newState);
if (newState == State.Stopped) {
// For now leave it be.
}
changes.put(vmName, newState);
}
}
for (final Map.Entry<String, State> entry : oldStates.entrySet()) {
final String vmName = entry.getKey();
final State oldState = entry.getValue();
if (oldState == State.Stopping) {
LOGGER.debug("Removing VM " + vmName + " in transition state stopping.");
vmStateMap.remove(vmName);
} else if (oldState == State.Starting) {
LOGGER.debug("Removing VM " + vmName + " in transition state starting.");
vmStateMap.remove(vmName);
} else if (oldState == State.Stopped) {
LOGGER.debug("Stopped VM " + vmName + " removing.");
vmStateMap.remove(vmName);
} else if (oldState == State.Migrating) {
/*
* do something smarter here.. newstate should say stopping
* already
*/
LOGGER.debug("Ignoring VM " + vmName + " in migrating state.");
} else {
/* if it's not there name it stopping */
State state = State.Stopping;
LOGGER.debug("VM " + vmName + " is now missing from ovm3 server so removing it");
changes.put(vmName, state);
vmStateMap.remove(vmName);
vmStateMap.put(vmName, state);
}
}
}
return changes;
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3HypervisorNetwork method isNetworkSetupByName.
/**/
private boolean isNetworkSetupByName(String nameTag) {
if (nameTag != null) {
LOGGER.debug("Looking for network setup by name " + nameTag);
try {
Network net = new Network(c);
net.getInterfaceList();
if (net.getBridgeByName(nameTag) != null) {
LOGGER.debug("Found bridge with name: " + nameTag);
return true;
}
} catch (Ovm3ResourceException e) {
LOGGER.debug("Unxpected error looking for name: " + nameTag, e);
return false;
}
}
LOGGER.debug("No bridge with name: " + nameTag);
return false;
}
Aggregations