Search in sources :

Example 1 with ConsoleProxyStatus

use of com.cloud.info.ConsoleProxyStatus in project cloudstack by apache.

the class ConsoleProxyManagerImpl method hasPreviousSession.

private boolean hasPreviousSession(ConsoleProxyVO proxy, VMInstanceVO vm) {
    ConsoleProxyStatus status = null;
    try {
        GsonBuilder gb = new GsonBuilder();
        gb.setVersion(1.3);
        Gson gson = gb.create();
        byte[] details = proxy.getSessionDetails();
        status = gson.fromJson(details != null ? new String(details, Charset.forName("US-ASCII")) : null, ConsoleProxyStatus.class);
    } catch (Throwable e) {
        s_logger.warn("Unable to parse proxy session details : " + Arrays.toString(proxy.getSessionDetails()));
    }
    if (status != null && status.getConnections() != null) {
        ConsoleProxyConnectionInfo[] connections = status.getConnections();
        for (int i = 0; i < connections.length; i++) {
            long taggedVmId = 0;
            if (connections[i].tag != null) {
                try {
                    taggedVmId = Long.parseLong(connections[i].tag);
                } catch (NumberFormatException e) {
                    s_logger.warn("Unable to parse console proxy connection info passed through tag: " + connections[i].tag, e);
                }
            }
            if (taggedVmId == vm.getId()) {
                return true;
            }
        }
        //
        if (DateUtil.currentGMTTime().getTime() - vm.getProxyAssignTime().getTime() < _proxySessionTimeoutValue) {
            return true;
        }
        return false;
    } else {
        s_logger.error("No proxy load info on an overloaded proxy ?");
        return false;
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) ConsoleProxyConnectionInfo(com.cloud.info.ConsoleProxyConnectionInfo) Gson(com.google.gson.Gson) ConsoleProxyStatus(com.cloud.info.ConsoleProxyStatus)

Example 2 with ConsoleProxyStatus

use of com.cloud.info.ConsoleProxyStatus in project cloudstack by apache.

the class ConsoleProxyManagerImpl method onLoadAnswer.

public void onLoadAnswer(ConsoleProxyLoadAnswer answer) {
    if (answer.getDetails() == null) {
        return;
    }
    ConsoleProxyStatus status = null;
    try {
        GsonBuilder gb = new GsonBuilder();
        gb.setVersion(1.3);
        Gson gson = gb.create();
        status = gson.fromJson(answer.getDetails(), ConsoleProxyStatus.class);
    } catch (Throwable e) {
        s_logger.warn("Unable to parse load info from proxy, proxy vm id : " + answer.getProxyVmId() + ", info : " + answer.getDetails());
    }
    if (status != null) {
        int count = 0;
        if (status.getConnections() != null) {
            count = status.getConnections().length;
        }
        byte[] details = null;
        if (answer.getDetails() != null) {
            details = answer.getDetails().getBytes(Charset.forName("US-ASCII"));
        }
        _consoleProxyDao.update(answer.getProxyVmId(), count, DateUtil.currentGMTTime(), details);
    } else {
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("Unable to get console proxy load info, id : " + answer.getProxyVmId());
        }
        _consoleProxyDao.update(answer.getProxyVmId(), 0, DateUtil.currentGMTTime(), null);
    // TODO : something is wrong with the VM, restart it?
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) ConsoleProxyStatus(com.cloud.info.ConsoleProxyStatus)

Aggregations

ConsoleProxyStatus (com.cloud.info.ConsoleProxyStatus)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 ConsoleProxyConnectionInfo (com.cloud.info.ConsoleProxyConnectionInfo)1