You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by fr...@apache.org on 2013/07/19 01:34:12 UTC
[1/2] git commit: updated refs/heads/master to 49e3278
Updated Branches:
refs/heads/master 6e0439a67 -> 49e3278c4
CLOUDSTACK-3426
UCS: Session cookie refresh must be supported.
add missing plugins/hypervisors/ucs/src/com/cloud/ucs/structure/UcsCookie.java
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/49e3278c
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/49e3278c
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/49e3278c
Branch: refs/heads/master
Commit: 49e3278c42f316f035e181459ed8098b767820c6
Parents: 9379190
Author: frank <fr...@citrix.com>
Authored: Thu Jul 18 16:42:24 2013 -0700
Committer: frank <fr...@citrix.com>
Committed: Thu Jul 18 16:43:21 2013 -0700
----------------------------------------------------------------------
.../src/com/cloud/ucs/structure/UcsCookie.java | 38 ++++++++++++++++++++
1 file changed, 38 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/49e3278c/plugins/hypervisors/ucs/src/com/cloud/ucs/structure/UcsCookie.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/structure/UcsCookie.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/structure/UcsCookie.java
new file mode 100644
index 0000000..560f584
--- /dev/null
+++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/structure/UcsCookie.java
@@ -0,0 +1,38 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+package com.cloud.ucs.structure;
+
+/* Class to store cookie and associated timestamp for communication with UCS manager*/
+public class UcsCookie {
+ private final String cookie;
+ private final Long startTime;
+
+ public UcsCookie(String cookie, Long startTime) {
+ this.cookie = cookie;
+ this.startTime = startTime;
+ }
+
+ public String getCookie() {
+ return cookie;
+ }
+
+ public Long getStartTime() {
+ return startTime;
+ }
+
+}
[2/2] git commit: updated refs/heads/master to 49e3278
Posted by fr...@apache.org.
CLOUDSTACK-3426
UCS: Session cookie refresh must be supported.
fixed resolved
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9379190d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9379190d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9379190d
Branch: refs/heads/master
Commit: 9379190da9be5cb18b3985b0997aace57dfa8b75
Parents: 6e0439a
Author: frank <fr...@citrix.com>
Authored: Thu Jul 18 16:30:56 2013 -0700
Committer: frank <fr...@citrix.com>
Committed: Thu Jul 18 16:43:21 2013 -0700
----------------------------------------------------------------------
.../src/com/cloud/ucs/manager/UcsCommands.java | 12 +++-
.../com/cloud/ucs/manager/UcsManagerImpl.java | 69 +++++++++++---------
2 files changed, 48 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9379190d/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java
index f6cc57f..c0753f4 100644
--- a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java
+++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java
@@ -5,9 +5,9 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -27,6 +27,14 @@ public class UcsCommands {
return cmd.dump();
}
+ public static String refreshCmd(String username, String password, String cookie) {
+ XmlObject cmd = new XmlObject("aaaRefresh");
+ cmd.putElement("inName", username);
+ cmd.putElement("inPassword", password);
+ cmd.putElement("inCookie", cookie);
+ return cmd.dump();
+ }
+
public static String listComputeBlades(String cookie) {
XmlObject cmd = new XmlObject("configResolveClass");
cmd.putElement("classId", "computeBlade");
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9379190d/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java
index e2bd31d..ee75f1b 100755
--- a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java
+++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java
@@ -5,9 +5,9 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -17,8 +17,6 @@
//
package com.cloud.ucs.manager;
-import java.io.File;
-import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -29,26 +27,18 @@ import java.util.concurrent.TimeUnit;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Unmarshaller;
+
+import org.apache.log4j.Logger;
import org.apache.cloudstack.api.AddUcsManagerCmd;
-import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.AssociateUcsProfileToBladeCmd;
-import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.ListUcsBladeCmd;
import org.apache.cloudstack.api.ListUcsManagerCmd;
import org.apache.cloudstack.api.ListUcsProfileCmd;
-import org.apache.cloudstack.api.ResponseGenerator;
-import org.apache.cloudstack.api.ServerApiException;
-import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.UcsBladeResponse;
import org.apache.cloudstack.api.response.UcsManagerResponse;
import org.apache.cloudstack.api.response.UcsProfileResponse;
-import org.apache.cxf.helpers.FileUtils;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
import com.cloud.dc.ClusterDetailsDao;
import com.cloud.dc.DataCenterVO;
@@ -56,14 +46,13 @@ import com.cloud.dc.dao.ClusterDao;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.org.Cluster;
import com.cloud.resource.ResourceService;
import com.cloud.ucs.database.UcsBladeDao;
import com.cloud.ucs.database.UcsBladeVO;
import com.cloud.ucs.database.UcsManagerDao;
import com.cloud.ucs.database.UcsManagerVO;
import com.cloud.ucs.structure.ComputeBlade;
+import com.cloud.ucs.structure.UcsCookie;
import com.cloud.ucs.structure.UcsProfile;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.SearchCriteria.Op;
@@ -71,13 +60,14 @@ import com.cloud.utils.db.SearchCriteria2;
import com.cloud.utils.db.SearchCriteriaService;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.script.Script;
import com.cloud.utils.xmlobject.XmlObject;
import com.cloud.utils.xmlobject.XmlObjectParser;
@Local(value = { UcsManager.class })
public class UcsManagerImpl implements UcsManager {
public static final Logger s_logger = Logger.getLogger(UcsManagerImpl.class);
+ public static final Long COOKIE_TTL = TimeUnit.MILLISECONDS.convert(100L, TimeUnit.MINUTES);
+ public static final Long COOKIE_REFRESH_TTL = TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES);
@Inject
private UcsManagerDao ucsDao;
@@ -94,7 +84,7 @@ public class UcsManagerImpl implements UcsManager {
@Inject
private DataCenterDao dcDao;
- private Map<Long, String> cookies = new HashMap<Long, String>();
+ private final Map<Long, UcsCookie> cookies = new HashMap<Long, UcsCookie>();
private String name;
private int runLevel;
private Map<String, Object> params;
@@ -166,23 +156,38 @@ public class UcsManagerImpl implements UcsManager {
private String getCookie(Long ucsMgrId) {
try {
- String cookie = cookies.get(ucsMgrId);
- if (cookie == null) {
- UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
- UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
- String login = UcsCommands.loginCmd(mgrvo.getUsername(), mgrvo.getPassword());
- String ret = client.call(login);
+ 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);
- cookie = xo.get("outCookie");
- cookies.put(ucsMgrId, cookie);
+ 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 cookie;
+ return ucsCookie.getCookie();
} catch (Exception e) {
throw new CloudRuntimeException("Cannot get cookie", e);
}
}
-
+
private List<ComputeBlade> listBlades(Long ucsMgrId) {
String cookie = getCookie(ucsMgrId);
UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
@@ -234,6 +239,7 @@ public class UcsManagerImpl implements UcsManager {
String cmd = UcsCommands.configResolveDn(cookie, dn);
String res = client.call(cmd);
XmlObject xo = XmlObjectParser.parseFromString(res);
+ s_logger.debug(String.format("association response is %s", res));
return xo.get("outConfig.computeBlade.association").equals("associated");
}
@@ -335,6 +341,7 @@ public class UcsManagerImpl implements UcsManager {
return rsp;
}
+ @Override
public ListResponse<UcsBladeResponse> listUcsBlades(ListUcsBladeCmd cmd) {
SearchCriteriaService<UcsBladeVO, UcsBladeVO> serv = SearchCriteria2.create(UcsBladeVO.class);
serv.addAnd(serv.getEntity().getUcsManagerId(), Op.EQ, cmd.getUcsManagerId());
@@ -364,7 +371,7 @@ public class UcsManagerImpl implements UcsManager {
@Override
public Map<String, Object> getConfigParams() {
- return this.params;
+ return params;
}
@Override
@@ -374,7 +381,7 @@ public class UcsManagerImpl implements UcsManager {
@Override
public void setRunLevel(int level) {
- this.runLevel = level;
+ runLevel = level;
}
@Override