use of javax.wbem.CloseableIterator in project coprhd-controller by CoprHD.
the class VmaxPortGroupProcessor method processResult.
@SuppressWarnings("unchecked")
@Override
public void processResult(Operation operation, Object resultObj, Map<String, Object> keyMap) throws BaseCollectionException {
log.info("Process port group");
try {
AccessProfile profile = (AccessProfile) keyMap.get(Constants.ACCESSPROFILE);
String serialID = (String) keyMap.get(Constants._serialID);
dbClient = (DbClient) keyMap.get(Constants.dbClient);
WBEMClient client = SMICommunicationInterface.getCIMClient(keyMap);
StorageSystem device = dbClient.queryObject(StorageSystem.class, profile.getSystemId());
boolean hasVolume = hasAnyVolume(device.getId());
final Iterator<CIMInstance> it = (Iterator<CIMInstance>) resultObj;
while (it.hasNext()) {
CIMInstance groupInstance = it.next();
CIMObjectPath groupPath = groupInstance.getObjectPath();
if (groupPath.toString().contains(serialID)) {
String portGroupName = groupInstance.getPropertyValue(Constants.ELEMENTNAME).toString();
if (StringUtils.isEmpty(portGroupName)) {
log.info(String.format("The port group %s name is null, skip", groupPath.toString()));
continue;
}
log.info(String.format("Got the port group: %s", portGroupName));
List<String> storagePorts = new ArrayList<String>();
CloseableIterator<CIMInstance> iterator = client.associatorInstances(groupPath, null, Constants.CIM_PROTOCOL_ENDPOINT, null, null, false, Constants.PS_NAME);
while (iterator.hasNext()) {
CIMInstance cimInstance = iterator.next();
String portName = CIMPropertyFactory.getPropertyValue(cimInstance, Constants._Name);
String fixedName = Initiator.toPortNetworkId(portName);
log.debug("Storage Port: {}", fixedName);
storagePorts.add(fixedName);
}
if (!storagePorts.isEmpty()) {
StoragePortGroup portGroup = getPortGroupInDB(portGroupName, device);
if (portGroup == null) {
// discovery after the upgrade.
if (hasVolume) {
List<ExportMask> masks = getExportMasksForPortGroup(client, groupPath, portGroupName, device);
boolean viprCreated = (!masks.isEmpty());
portGroup = createPortGroup(portGroupName, device, viprCreated);
for (ExportMask mask : masks) {
mask.setPortGroup(portGroup.getId());
}
dbClient.updateObject(masks);
} else {
portGroup = createPortGroup(portGroupName, device, false);
}
}
allPortGroupNativeGuids.add(portGroup.getNativeGuid());
List<URI> storagePortURIs = new ArrayList<URI>();
storagePortURIs.addAll(transform(ExportUtils.storagePortNamesToURIs(dbClient, storagePorts), CommonTransformerFunctions.FCTN_STRING_TO_URI));
portGroup.setStoragePorts(StringSetUtil.uriListToStringSet(storagePortURIs));
dbClient.updateObject(portGroup);
} else {
// no storage ports in the port group, remove it
log.info(String.format("The port group %s does not have any storage ports, ignore", portGroupName));
}
}
}
if (!allPortGroupNativeGuids.isEmpty()) {
doBookKeeping(device.getId());
} else {
log.info("Did not get any port group, skip book keeping");
}
} catch (Exception e) {
log.error("port group discovery failed ", e);
} finally {
allPortGroupNativeGuids.clear();
}
}
Aggregations