Search in sources :

Example 1 with ConsoleProxyConnectionInfo

use of com.cloud.info.ConsoleProxyConnectionInfo 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)

Aggregations

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