Search in sources :

Example 1 with UcsCookie

use of com.cloud.ucs.structure.UcsCookie in project cloudstack by apache.

the class UcsManagerImpl method getCookie.

private String getCookie(Long ucsMgrId) {
    try {
        UcsCookie ucsCookie = cookies.get(ucsMgrId);
        long currentTime = System.currentTimeMillis();
        UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
        UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
        String cmd = null;
        if (ucsCookie == null) {
            cmd = UcsCommands.loginCmd(mgrvo.getUsername(), mgrvo.getPassword());
        } else {
            String cookie = ucsCookie.getCookie();
            long cookieStartTime = ucsCookie.getStartTime();
            if (currentTime - cookieStartTime > COOKIE_TTL) {
                cmd = UcsCommands.loginCmd(mgrvo.getUsername(), mgrvo.getPassword());
            } else if (currentTime - cookieStartTime > COOKIE_REFRESH_TTL) {
                cmd = UcsCommands.refreshCmd(mgrvo.getUsername(), mgrvo.getPassword(), cookie);
            }
        }
        if (!(cmd == null)) {
            String ret = client.call(cmd);
            XmlObject xo = XmlObjectParser.parseFromString(ret);
            String cookie = xo.get("outCookie");
            ucsCookie = new UcsCookie(cookie, currentTime);
            cookies.put(ucsMgrId, ucsCookie);
        // cookiesTime.put(cookie, currentTime); //This is currentTime on purpose, and not latest time.
        }
        return ucsCookie.getCookie();
    } catch (Exception e) {
        throw new CloudRuntimeException("Cannot get cookie", e);
    }
}
Also used : UcsManagerVO(com.cloud.ucs.database.UcsManagerVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UcsCookie(com.cloud.ucs.structure.UcsCookie) XmlObject(com.cloud.utils.xmlobject.XmlObject) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

UcsManagerVO (com.cloud.ucs.database.UcsManagerVO)1 UcsCookie (com.cloud.ucs.structure.UcsCookie)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 XmlObject (com.cloud.utils.xmlobject.XmlObject)1 ConfigurationException (javax.naming.ConfigurationException)1