Search in sources :

Example 6 with CloudstackPlugin

use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.

the class Ovm3HypervisorSupport method execute.

public Answer execute(GetHostStatsCommand cmd) {
    try {
        CloudstackPlugin cSp = new CloudstackPlugin(c);
        Map<String, String> stats = cSp.ovsDom0Stats(config.getAgentPublicNetworkName());
        Double cpuUtil = Double.parseDouble(stats.get("cpu"));
        Double rxBytes = Double.parseDouble(stats.get("rx"));
        Double txBytes = Double.parseDouble(stats.get("tx"));
        Double totalMemory = Double.parseDouble(stats.get("total"));
        Double freeMemory = Double.parseDouble(stats.get("free"));
        HostStatsEntry hostStats = new HostStatsEntry(cmd.getHostId(), cpuUtil, rxBytes, txBytes, "host", totalMemory, freeMemory, 0, 0);
        return new GetHostStatsAnswer(cmd, hostStats);
    } catch (Exception e) {
        LOGGER.debug("Unable to get host stats for: " + cmd.getHostName(), e);
        return new Answer(cmd, false, e.getMessage());
    }
}
Also used : FenceAnswer(com.cloud.agent.api.FenceAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) Answer(com.cloud.agent.api.Answer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) HostStatsEntry(com.cloud.agent.api.HostStatsEntry) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 7 with CloudstackPlugin

use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.

the class Ovm3VirtualRoutingSupport method execute.

public CheckSshAnswer execute(CheckSshCommand cmd) {
    String vmName = cmd.getName();
    String privateIp = cmd.getIp();
    int cmdPort = cmd.getPort();
    int interval = cmd.getInterval();
    int retries = cmd.getRetries();
    try {
        CloudstackPlugin cSp = new CloudstackPlugin(c);
        if (!cSp.dom0CheckPort(privateIp, cmdPort, retries, interval)) {
            String msg = "Port " + cmdPort + " not reachable for " + vmName + ": " + config.getAgentHostname();
            LOGGER.info(msg);
            return new CheckSshAnswer(cmd, msg);
        }
    } catch (Exception e) {
        String msg = "Can not reach port " + cmdPort + " on System vm " + vmName + ": " + config.getAgentHostname() + " due to exception: " + e;
        LOGGER.error(msg);
        return new CheckSshAnswer(cmd, msg);
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Ping " + cmdPort + " succeeded for vm " + vmName + ": " + config.getAgentHostname() + " " + cmd);
    }
    return new CheckSshAnswer(cmd);
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)

Example 8 with CloudstackPlugin

use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin in project cloudstack by apache.

the class Ovm3VmSupport method getVmStat.

private VmStatsEntry getVmStat(String vmName) {
    CloudstackPlugin cSp = new CloudstackPlugin(c);
    Map<String, String> oldVmStats = null;
    Map<String, String> newVmStats = null;
    VmStatsEntry stats = new VmStatsEntry();
    try {
        if (vmStats.containsKey(vmName)) {
            oldVmStats = new HashMap<String, String>();
            oldVmStats.putAll(vmStats.get(vmName));
        }
        newVmStats = cSp.ovsDomUStats(vmName);
    } catch (Ovm3ResourceException e) {
        LOGGER.info("Unable to retrieve stats from " + vmName, e);
        return stats;
    }
    if (oldVmStats == null) {
        LOGGER.debug("No old stats retrieved stats from " + vmName);
        stats.setNumCPUs(1);
        stats.setNetworkReadKBs(0);
        stats.setNetworkWriteKBs(0);
        stats.setDiskReadKBs(0);
        stats.setDiskWriteKBs(0);
        stats.setDiskReadIOs(0);
        stats.setDiskWriteIOs(0);
        stats.setCPUUtilization(0);
        stats.setEntityType("vm");
    } else {
        LOGGER.debug("Retrieved new stats from " + vmName);
        int cpus = Integer.parseInt(newVmStats.get("vcpus"));
        stats.setNumCPUs(cpus);
        stats.setNetworkReadKBs(doubleMin(newVmStats.get("rx_bytes"), oldVmStats.get("rx_bytes")));
        stats.setNetworkWriteKBs(doubleMin(newVmStats.get("tx_bytes"), oldVmStats.get("tx_bytes")));
        stats.setDiskReadKBs(doubleMin(newVmStats.get("rd_bytes"), oldVmStats.get("rd_bytes")));
        stats.setDiskWriteKBs(doubleMin(newVmStats.get("rw_bytes"), oldVmStats.get("rw_bytes")));
        stats.setDiskReadIOs(doubleMin(newVmStats.get("rd_ops"), oldVmStats.get("rd_ops")));
        stats.setDiskWriteIOs(doubleMin(newVmStats.get("rw_ops"), oldVmStats.get("rw_ops")));
        Double dCpu = doubleMin(newVmStats.get("cputime"), oldVmStats.get("cputime"));
        Double dTime = doubleMin(newVmStats.get("uptime"), oldVmStats.get("uptime"));
        Double cpupct = dCpu / dTime * 100 * cpus;
        stats.setCPUUtilization(cpupct);
        stats.setEntityType("vm");
    }
    ((ConcurrentHashMap<String, Map<String, String>>) vmStats).put(vmName, newVmStats);
    return stats;
}
Also used : Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) VmStatsEntry(com.cloud.agent.api.VmStatsEntry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)

Example 9 with CloudstackPlugin

use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin 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);
    }
}
Also used : BigInteger(java.math.BigInteger) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) PowerState(com.cloud.vm.VirtualMachine.PowerState) State(com.cloud.vm.VirtualMachine.State) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)

Example 10 with CloudstackPlugin

use of com.cloud.hypervisor.ovm3.objects.CloudstackPlugin 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());
    }
}
Also used : Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)

Aggregations

CloudstackPlugin (com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)16 Ovm3ResourceException (com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)13 ConfigurationException (javax.naming.ConfigurationException)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 CheckOnHostAnswer (com.cloud.agent.api.CheckOnHostAnswer)2 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)2 DataTO (com.cloud.agent.api.to.DataTO)2 Linux (com.cloud.hypervisor.ovm3.objects.Linux)2 ExecutionResult (com.cloud.utils.ExecutionResult)2 State (com.cloud.vm.VirtualMachine.State)2 IOException (java.io.IOException)2 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)2 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)2 Answer (com.cloud.agent.api.Answer)1 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)1 FenceAnswer (com.cloud.agent.api.FenceAnswer)1 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)1 HostStatsEntry (com.cloud.agent.api.HostStatsEntry)1 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)1 PingRoutingCommand (com.cloud.agent.api.PingRoutingCommand)1