Search in sources :

Example 1 with CloseableIterator

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();
    }
}
Also used : StoragePortGroup(com.emc.storageos.db.client.model.StoragePortGroup) ExportMask(com.emc.storageos.db.client.model.ExportMask) CIMObjectPath(javax.cim.CIMObjectPath) ArrayList(java.util.ArrayList) AccessProfile(com.emc.storageos.plugins.AccessProfile) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) CloseableIterator(javax.wbem.CloseableIterator) Iterator(java.util.Iterator) WBEMClient(javax.wbem.client.WBEMClient) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

ExportMask (com.emc.storageos.db.client.model.ExportMask)1 StoragePortGroup (com.emc.storageos.db.client.model.StoragePortGroup)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 AccessProfile (com.emc.storageos.plugins.AccessProfile)1 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 CIMInstance (javax.cim.CIMInstance)1 CIMObjectPath (javax.cim.CIMObjectPath)1 CloseableIterator (javax.wbem.CloseableIterator)1 WBEMClient (javax.wbem.client.WBEMClient)1