Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 56 additions & 32 deletions vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,27 @@ public void connect(String url, String userName, String password) throws Excepti
@SuppressWarnings("unchecked")
Map<String, List<String>> headers = (Map<String, List<String>>)((BindingProvider)vimPort).getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
List<String> cookies = headers.get("Set-cookie");

vimPort.login(serviceContent.getSessionManager(), userName, password, null);

if (cookies == null) {
// Get the cookie from the response header. See vmware sample program com.vmware.httpfileaccess.GetVMFiles
@SuppressWarnings("unchecked")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why suppress? please add a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to suppress the warnings for the unchecked cast from Object to Map<String,List> on extracting the http response headers from the response context. This is also set on vmware sample programs.

Map<String, List<String>> responseHeaders = (Map<String, List<String>>)((BindingProvider)vimPort).getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
cookies = responseHeaders.get("Set-cookie");
if (cookies == null) {
String msg = "Login successful, but failed to get server cookies from url :[" + url + "]";
s_logger.error(msg);
throw new Exception(msg);
}
}

String cookieValue = cookies.get(0);
StringTokenizer tokenizer = new StringTokenizer(cookieValue, ";");
cookieValue = tokenizer.nextToken();
String pathData = "$" + tokenizer.nextToken();
serviceCookie = "$Version=\"1\"; " + cookieValue + "; " + pathData;

vimPort.login(serviceContent.getSessionManager(), userName, password, null);
isConnected = true;
}

Expand Down Expand Up @@ -577,41 +591,51 @@ public ManagedObjectReference getDecendentMoRef(ManagedObjectReference root, Str
return null;
}

// Create PropertySpecs
PropertySpec pSpec = new PropertySpec();
pSpec.setType(type);
pSpec.setAll(false);
pSpec.getPathSet().add("name");

ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(root);
oSpec.setSkip(false);
oSpec.getSelectSet().addAll(constructCompleteTraversalSpec());

PropertyFilterSpec spec = new PropertyFilterSpec();
spec.getPropSet().add(pSpec);
spec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>();
specArr.add(spec);

List<ObjectContent> ocary = vimPort.retrieveProperties(getPropCol(), specArr);

if (ocary == null || ocary.size() == 0) {
return null;
}
try {
// Create PropertySpecs
PropertySpec pSpec = new PropertySpec();
pSpec.setType(type);
pSpec.setAll(false);
pSpec.getPathSet().add("name");

ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(root);
oSpec.setSkip(false);
oSpec.getSelectSet().addAll(constructCompleteTraversalSpec());

PropertyFilterSpec spec = new PropertyFilterSpec();
spec.getPropSet().add(pSpec);
spec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>();
specArr.add(spec);

ManagedObjectReference propCollector = getPropCol();
List<ObjectContent> ocary = vimPort.retrieveProperties(propCollector, specArr);

if (ocary == null || ocary.size() == 0) {
return null;
}

// filter through retrieved objects to get the first match.
for (ObjectContent oc : ocary) {
ManagedObjectReference mor = oc.getObj();
List<DynamicProperty> propary = oc.getPropSet();
if (type == null || type.equals(mor.getType())) {
if (propary.size() > 0) {
String propval = (String)propary.get(0).getVal();
if (propval != null && name.equalsIgnoreCase(propval))
return mor;
// filter through retrieved objects to get the first match.
for (ObjectContent oc : ocary) {
ManagedObjectReference mor = oc.getObj();
List<DynamicProperty> propary = oc.getPropSet();
if (type == null || type.equals(mor.getType())) {
if (propary.size() > 0) {
String propval = (String)propary.get(0).getVal();
if (propval != null && name.equalsIgnoreCase(propval))
return mor;
}
}
}
} catch (InvalidPropertyFaultMsg invalidPropertyException) {
s_logger.debug("Failed to get Vmware ManagedObjectReference for name: " + name + " and type: " + type + " due to " + invalidPropertyException.getMessage());
throw invalidPropertyException;
} catch (RuntimeFaultFaultMsg runtimeFaultException) {
s_logger.debug("Failed to get Vmware ManagedObjectReference for name: " + name + " and type: " + type + " due to " + runtimeFaultException.getMessage());
throw runtimeFaultException;
}

return null;
}

Expand Down