/** * Gets the custom attributes. * * @param entity the entity * @return the custom attributes */ private Map<String,String> getCustomAttributes(ManagedEntity entity) { final Map<String,String> attributes = new TreeMap<String,String>(); logger.debug("Getting custom attributes from VMware management server {} : ManagedEntity {} (ID: {})", request.getHostname(), entity.getName(), entity.getMOR().getVal()); CustomFieldDef[] defs = new CustomFieldDef[0]; try { defs = entity.getAvailableField(); } catch (RemoteException e) { logger.warn("Cannot fetch attributes for entity '{}' (ID: {})", entity.getName(), entity.getMOR().getVal()); logger.warn("Exception thrown while fetching attributes: {}", e); return attributes; } CustomFieldValue[] values = entity.getCustomValue(); for (int i = 0; defs != null && i < defs.length; i++) { String key = defs[i].getName(); int targetIndex = defs[i].getKey(); for (int j = 0; values != null && j < values.length; j++) { if (targetIndex == values[j].getKey()) { attributes.put(key, ((CustomFieldStringValue) values[j]).getValue()); } } } return attributes; }
/** * Gets the custom attributes. * * @param entity the entity * @return the custom attributes */ private Map<String,String> getCustomAttributes(ManagedEntity entity) { final Map<String,String> attributes = new TreeMap<String,String>(); logger.debug("Getting custom attributes from VMware management server {} : ManagedEntity {} (ID: {})", request.getHostname(), entity.getName(), entity.getMOR().getVal()); CustomFieldDef[] defs = new CustomFieldDef[0]; try { defs = entity.getAvailableField(); } catch (RemoteException e) { logger.warn("Cannot fetch attributes for entity '{}' (ID: {})", entity.getName(), entity.getMOR().getVal()); logger.warn("Exception thrown while fetching attributes: {}", e); return attributes; } CustomFieldValue[] values = entity.getCustomValue(); for (int i = 0; defs != null && i < defs.length; i++) { String key = defs[i].getName(); int targetIndex = defs[i].getKey(); for (int j = 0; values != null && j < values.length; j++) { if (targetIndex == values[j].getKey()) { attributes.put(key, ((CustomFieldStringValue) values[j]).getValue()); } } } return attributes; }