Search in sources :

Example 6 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class DCNMDialog method getClient.

/**
 * Initialize the client interface.
 *
 * @param ipaddress
 * @param username
 * @param password
 * @param smisport
 * @return WBEMClient
 */
public WBEMClient getClient(String ipaddress, String username, String password, Integer smisport) {
    try {
        WBEMClient client = WBEMClientFactory.getClient(WBEMClientConstants.PROTOCOL_CIMXML);
        CIMObjectPath path = CimObjectPathCreator.createInstance("http", ipaddress, smisport.toString(), _namespace, null, null);
        final Subject subject = new Subject();
        subject.getPrincipals().add(new UserPrincipal(username));
        subject.getPrivateCredentials().add(new PasswordCredential(password));
        client.initialize(path, subject, new Locale[] { Locale.US });
        _client = client;
        return client;
    } catch (WBEMException ex) {
        _log.error("Can't open client: WBEMException: " + ex.getLocalizedMessage());
        return null;
    }
}
Also used : CIMObjectPath(javax.cim.CIMObjectPath) PasswordCredential(javax.wbem.client.PasswordCredential) WBEMClient(javax.wbem.client.WBEMClient) WBEMException(javax.wbem.WBEMException) Subject(javax.security.auth.Subject) UserPrincipal(javax.wbem.client.UserPrincipal)

Example 7 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class SRDFStorageSyncProcessor method processResult.

@Override
public void processResult(Operation operation, Object resultObj, Map<String, Object> keyMap) throws BaseCollectionException {
    CloseableIterator<CIMObjectPath> synchronizedInstancePaths = null;
    EnumerateResponse<CIMObjectPath> synchronizedInstancePathChunks = null;
    WBEMClient client = SMICommunicationInterface.getCIMClient(keyMap);
    try {
        synchronizedInstancePathChunks = (EnumerateResponse<CIMObjectPath>) resultObj;
        synchronizedInstancePaths = synchronizedInstancePathChunks.getResponses();
        processStorageSynchronizedPaths(operation, synchronizedInstancePaths, resultObj, keyMap);
        while (!synchronizedInstancePathChunks.isEnd()) {
            synchronizedInstancePathChunks = client.getInstancePaths(Constants.SYNC_PATH, synchronizedInstancePathChunks.getContext(), Constants.SYNC_BATCH_SIZE);
            processStorageSynchronizedPaths(operation, synchronizedInstancePathChunks.getResponses(), resultObj, keyMap);
        }
    }// 
     catch (Exception e) {
        _log.error("Processing Storage Synchronized Realtions for SRDF failed : ", e);
    } finally {
        if (null != synchronizedInstancePaths) {
            synchronizedInstancePaths.close();
        }
        if (null != synchronizedInstancePathChunks) {
            try {
                client.closeEnumeration(Constants.SYNC_PATH, synchronizedInstancePathChunks.getContext());
            } catch (Exception e) {
                _log.debug("Exception occurred while closing enumeration", e);
            }
        }
    }
    resultObj = null;
}
Also used : CIMObjectPath(javax.cim.CIMObjectPath) WBEMClient(javax.wbem.client.WBEMClient) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException)

Example 8 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class StorageVolumeViewProcessor method processResult.

@Override
public void processResult(Operation operation, Object resultObj, Map<String, Object> keyMap) throws BaseCollectionException {
    EnumerateResponse<CIMInstance> volumeInstanceChunks = (EnumerateResponse<CIMInstance>) resultObj;
    WBEMClient client = SMICommunicationInterface.getCIMClient(keyMap);
    _dbClient = (DbClient) keyMap.get(Constants.dbClient);
    _updateVolumes = new ArrayList<Volume>();
    _updateSnapShots = new ArrayList<BlockSnapshot>();
    _updateMirrors = new ArrayList<BlockMirror>();
    CloseableIterator<CIMInstance> volumeInstances = null;
    try {
        _metaVolumeViewPaths = (List<CIMObjectPath>) keyMap.get(Constants.META_VOLUMES_VIEWS);
        if (_metaVolumeViewPaths == null) {
            _metaVolumeViewPaths = new ArrayList<CIMObjectPath>();
            keyMap.put(Constants.META_VOLUMES_VIEWS, _metaVolumeViewPaths);
        }
        // create empty place holder list for meta volume paths (cannot define this in xml)
        List<CIMObjectPath> metaVolumePaths = (List<CIMObjectPath>) keyMap.get(Constants.META_VOLUMES);
        if (metaVolumePaths == null) {
            keyMap.put(Constants.META_VOLUMES, new ArrayList<CIMObjectPath>());
        }
        CIMObjectPath storagePoolPath = getObjectPathfromCIMArgument(_args);
        volumeInstances = volumeInstanceChunks.getResponses();
        processVolumes(volumeInstances, keyMap);
        while (!volumeInstanceChunks.isEnd()) {
            _logger.info("Processing Next Volume Chunk of size {}", BATCH_SIZE);
            volumeInstanceChunks = client.getInstancesWithPath(storagePoolPath, volumeInstanceChunks.getContext(), new UnsignedInteger32(BATCH_SIZE));
            processVolumes(volumeInstanceChunks.getResponses(), keyMap);
        }
        // if list empty, this method returns back immediately.
        // partition size might not be used in this context, as batch size < partition size.
        // TODO metering might need some extra work to push volumes in batches, hence not changing this method
        // signature
        _partitionManager.updateInBatches(_updateVolumes, getPartitionSize(keyMap), _dbClient, VOLUME);
        _partitionManager.updateInBatches(_updateSnapShots, getPartitionSize(keyMap), _dbClient, BLOCK_SNAPSHOT);
        _partitionManager.updateInBatches(_updateMirrors, getPartitionSize(keyMap), _dbClient, BLOCK_MIRROR);
    } catch (Exception e) {
        _logger.error("Processing Volumes and Snapshots failed", e);
    } finally {
        _updateVolumes = null;
        _updateSnapShots = null;
        _updateMirrors = null;
        if (null != volumeInstances) {
            volumeInstances.close();
        }
    }
}
Also used : BlockMirror(com.emc.storageos.db.client.model.BlockMirror) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CIMObjectPath(javax.cim.CIMObjectPath) UnsignedInteger32(javax.cim.UnsignedInteger32) CIMInstance(javax.cim.CIMInstance) IOException(java.io.IOException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) List(java.util.List) WBEMClient(javax.wbem.client.WBEMClient) EnumerateResponse(javax.wbem.client.EnumerateResponse)

Example 9 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class MetaVolumeMembersProcessor method processResult.

@Override
public void processResult(Operation operation, Object resultObj, Map<String, Object> keyMap) throws BaseCollectionException {
    try {
        DbClient dbClient = (DbClient) keyMap.get(Constants.dbClient);
        WBEMClient client = SMICommunicationInterface.getCIMClient(keyMap);
        CIMObjectPath[] metaMembersPaths = (CIMObjectPath[]) getFromOutputArgs((CIMArgument[]) resultObj, "OutElements");
        if (metaMembersPaths == null || (metaMembersPaths.length == 0)) {
            _logger.info(String.format("There are no meta members to process"));
        } else {
            _logger.debug(String.format("Processing meta members: %s", Arrays.toString(metaMembersPaths)));
            // Get volume from db
            _logger.debug(String.format("Args size: %s", _args.size()));
            Object[] arguments = (Object[]) _args.get(0);
            CIMArgument theElement = ((CIMArgument[]) arguments[2])[1];
            _logger.info(String.format("TheElement: %s, type %s", theElement.getValue().toString(), theElement.getValue().getClass().toString()));
            CIMObjectPath theElementPath = (CIMObjectPath) theElement.getValue();
            UnManagedVolume preExistingVolume = null;
            String isMetaVolume = "true";
            String nativeGuid;
            // Check if storage volume exists in db (the method is called from re-discovery context).
            nativeGuid = getVolumeNativeGuid(theElementPath);
            Volume storageVolume = checkStorageVolumeExistsInDB(nativeGuid, dbClient);
            if (null == storageVolume || storageVolume.getInactive()) {
                // Check if unmanaged volume exists in db (the method is called from unmanaged volumes discovery context).
                nativeGuid = getUnManagedVolumeNativeGuidFromVolumePath(theElementPath);
                _logger.debug("Volume nativeguid :" + nativeGuid);
                preExistingVolume = checkUnManagedVolumeExistsInDB(nativeGuid, dbClient);
                if (null == preExistingVolume) {
                    _logger.debug("Volume Info Object not found :" + nativeGuid);
                    return;
                }
                isMetaVolume = preExistingVolume.getVolumeCharacterstics().get(UnManagedVolume.SupportedVolumeCharacterstics.IS_METAVOLUME.toString());
            } else {
                _logger.debug("Volume managed by Bourne :" + storageVolume.getNativeGuid());
                isMetaVolume = storageVolume.getIsComposite().toString();
            }
            if (isMetaVolume.equalsIgnoreCase("false")) {
                _logger.error(String.format("MetaVolumeMembersProcessor called for regular volume: %s", nativeGuid));
                return;
            }
            Integer membersCount = metaMembersPaths.length;
            // get meta member size. use second member --- the first member will show size of meta volume itself.
            CIMObjectPath metaMemberPath = metaMembersPaths[1];
            CIMInstance cimVolume = client.getInstance(metaMemberPath, false, false, META_MEMBER_SIZE_INFO);
            CIMProperty consumableBlocks = cimVolume.getProperty(SmisConstants.CP_CONSUMABLE_BLOCKS);
            CIMProperty blockSize = cimVolume.getProperty(SmisConstants.CP_BLOCK_SIZE);
            // calculate size = consumableBlocks * block size
            Long size = Long.valueOf(consumableBlocks.getValue().toString()) * Long.valueOf(blockSize.getValue().toString());
            // set meta member count and meta members size for meta volume (required for volume expansion)
            if (null != preExistingVolume) {
                StringSet metaMembersCount = new StringSet();
                metaMembersCount.add(membersCount.toString());
                preExistingVolume.putVolumeInfo(UnManagedVolume.SupportedVolumeInformation.META_MEMBER_COUNT.toString(), metaMembersCount);
                StringSet metaMemberSize = new StringSet();
                metaMemberSize.add(size.toString());
                preExistingVolume.putVolumeInfo(UnManagedVolume.SupportedVolumeInformation.META_MEMBER_SIZE.toString(), metaMemberSize);
                // persist unmanaged volume in db
                dbClient.persistObject(preExistingVolume);
            } else {
                storageVolume.setMetaMemberCount(membersCount);
                storageVolume.setMetaMemberSize(size);
                storageVolume.setTotalMetaMemberCapacity(membersCount * size);
                // persist volume in db
                dbClient.persistObject(storageVolume);
            }
            _logger.info(String.format("Meta member info: meta member count --- %s, blocks --- %s, block size --- %s, size --- %s .", membersCount, consumableBlocks.getValue().toString(), blockSize.getValue().toString(), size));
        }
    } catch (Exception e) {
        _logger.error("Processing meta volume  information failed :", e);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) CIMObjectPath(javax.cim.CIMObjectPath) CIMInstance(javax.cim.CIMInstance) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) CIMProperty(javax.cim.CIMProperty) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) StringSet(com.emc.storageos.db.client.model.StringSet) WBEMClient(javax.wbem.client.WBEMClient) CIMArgument(javax.cim.CIMArgument)

Example 10 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class MetaVolumeTypeProcessor method processResult.

@Override
public void processResult(Operation operation, Object resultObj, Map<String, Object> keyMap) throws BaseCollectionException {
    try {
        DbClient dbClient = (DbClient) keyMap.get(Constants.dbClient);
        WBEMClient client = SMICommunicationInterface.getCIMClient(keyMap);
        CIMObjectPath metaVolumePath = getObjectPathfromCIMArgument(_args);
        if (metaVolumePath == null) {
            _logger.info(String.format("MetaVolumePath is null."));
        } else {
            _logger.info(String.format("Processing EMC_Meta for meta volume: %s", metaVolumePath));
            UnManagedVolume preExistingVolume = null;
            String isMetaVolume = "true";
            String nativeGuid;
            // Check if storage volume exists in db (the method is called from re-discovery context).
            nativeGuid = getVolumeNativeGuid(metaVolumePath);
            Volume storageVolume = checkStorageVolumeExistsInDB(nativeGuid, dbClient);
            if (null == storageVolume || storageVolume.getInactive()) {
                // Check if unmanaged volume exists in db (the method is called from unmanaged volumes discovery context).
                nativeGuid = getUnManagedVolumeNativeGuidFromVolumePath(metaVolumePath);
                _logger.debug("Meta volume nativeguid :" + nativeGuid);
                preExistingVolume = checkUnManagedVolumeExistsInDB(nativeGuid, dbClient);
                if (null == preExistingVolume) {
                    _logger.debug("Volume Info Object not found :" + nativeGuid);
                    return;
                }
                isMetaVolume = preExistingVolume.getVolumeCharacterstics().get(UnManagedVolume.SupportedVolumeCharacterstics.IS_METAVOLUME.toString());
            } else {
                _logger.debug("Volume managed by Bourne :" + storageVolume.getNativeGuid());
                isMetaVolume = storageVolume.getIsComposite().toString();
            }
            if (isMetaVolume.equalsIgnoreCase("false")) {
                _logger.error(String.format("MetaVolumeTypeProcessor called for regular volume: %s", nativeGuid));
                return;
            }
            final Iterator<?> it = (Iterator<?>) resultObj;
            if (it.hasNext()) {
                final CIMObjectPath symmMetaPath = (CIMObjectPath) it.next();
                _logger.debug(String.format("Processing EMC_Meta: %s", symmMetaPath));
                CIMInstance cimMeta = client.getInstance(symmMetaPath, false, false, STRIPE_EXTENTS_NUMBER);
                CIMProperty stripeLengthProperty = cimMeta.getProperty(SmisConstants.CP_EXTENT_STRIPE_LENGTH);
                Long stripeLength = Long.valueOf(stripeLengthProperty.getValue().toString());
                String metaVolumeType;
                if (stripeLength < 1) {
                    _logger.error(String.format("Stripe length for EMC_Meta is less than 1: %s", stripeLength));
                    return;
                } else if (stripeLength == 1) {
                    // this is concatenated meta volume
                    _logger.debug(String.format("Stripe length for EMC_Meta is : %s. Type is concatenated.", stripeLength));
                    metaVolumeType = Volume.CompositionType.CONCATENATED.toString();
                } else {
                    // this is striped meta volume
                    _logger.debug(String.format("Stripe length for EMC_Meta is : %s. Type is striped.", stripeLength));
                    metaVolumeType = Volume.CompositionType.STRIPED.toString();
                }
                _logger.info(String.format("Meta volume: %s, type: %s", metaVolumePath, metaVolumeType));
                if (null == preExistingVolume) {
                    // storage volume update
                    storageVolume.setCompositionType(metaVolumeType);
                    // persist volume in db
                    dbClient.persistObject(storageVolume);
                } else {
                    // unmanaged volume update
                    StringSet metaVolumeTypeSet = new StringSet();
                    metaVolumeTypeSet.add(metaVolumeType);
                    preExistingVolume.putVolumeInfo(UnManagedVolume.SupportedVolumeInformation.META_VOLUME_TYPE.toString(), metaVolumeTypeSet);
                    // for this volume.
                    if (Volume.CompositionType.STRIPED.toString().equalsIgnoreCase(metaVolumeType)) {
                        URI storageSystemUri = preExistingVolume.getStorageSystemUri();
                        StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, storageSystemUri);
                        if (DiscoveredDataObject.Type.vmax.toString().equalsIgnoreCase(storageSystem.getSystemType())) {
                            _logger.info("Check matched vpool list for vmax striped meta volume and remove fastExpansion vpools.");
                            StringSet matchedVirtualPools = preExistingVolume.getSupportedVpoolUris();
                            if (matchedVirtualPools != null && !matchedVirtualPools.isEmpty()) {
                                _logger.debug("Matched Pools :" + Joiner.on("\t").join(matchedVirtualPools));
                                StringSet newMatchedPools = new StringSet();
                                boolean needToReplace = false;
                                for (String vPoolUriStr : matchedVirtualPools) {
                                    URI vPoolUri = new URI(vPoolUriStr);
                                    VirtualPool virtualPool = dbClient.queryObject(VirtualPool.class, vPoolUri);
                                    // null check since supported vPool list in UnManagedVolume may contain inactive vPool
                                    if (virtualPool != null && !virtualPool.getFastExpansion()) {
                                        newMatchedPools.add(vPoolUriStr);
                                    } else {
                                        needToReplace = true;
                                    }
                                }
                                if (needToReplace) {
                                    matchedVirtualPools.replace(newMatchedPools);
                                    _logger.info("Replaced VPools : {}", Joiner.on("\t").join(preExistingVolume.getSupportedVpoolUris()));
                                }
                            }
                        }
                    }
                    // persist volume in db
                    dbClient.updateAndReindexObject(preExistingVolume);
                }
            }
        }
    } catch (Exception e) {
        _logger.error("Processing meta volume type information failed :", e);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) CIMObjectPath(javax.cim.CIMObjectPath) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) CIMProperty(javax.cim.CIMProperty) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Iterator(java.util.Iterator) StringSet(com.emc.storageos.db.client.model.StringSet) WBEMClient(javax.wbem.client.WBEMClient) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

WBEMClient (javax.wbem.client.WBEMClient)110 CIMObjectPath (javax.cim.CIMObjectPath)75 CIMInstance (javax.cim.CIMInstance)69 WBEMException (javax.wbem.WBEMException)42 ArrayList (java.util.ArrayList)39 URI (java.net.URI)35 DbClient (com.emc.storageos.db.client.DbClient)29 Volume (com.emc.storageos.db.client.model.Volume)29 CIMConnectionFactory (com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory)27 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)25 HashSet (java.util.HashSet)25 CimConnection (com.emc.storageos.cimadapter.connections.cim.CimConnection)24 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)18 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)18 HashMap (java.util.HashMap)17 ExportMask (com.emc.storageos.db.client.model.ExportMask)16 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)16 CIMProperty (javax.cim.CIMProperty)14 UnsignedInteger32 (javax.cim.UnsignedInteger32)14 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)13