use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class SmisCommandHelper method removeVolumeFromStorageGroupsIfVolumeIsNotInAnyMV.
/**
* Removes the volume from storage groups if the volume is not in any Masking View.
* This will be called just before deleting the volume (for VMAX2).
*
* @param storageSystem
* the storage system
* @param volume
* the volume
*/
public void removeVolumeFromStorageGroupsIfVolumeIsNotInAnyMV(StorageSystem storage, BlockObject bo) {
/**
* If Volume is not associated with any MV, then remove the volume from its associated SGs.
*/
CloseableIterator<CIMObjectPath> mvPathItr = null;
CloseableIterator<CIMInstance> sgInstancesItr = null;
boolean isSGInAnyMV = true;
try {
_log.info("Checking if device {} needs to be removed from Storage Groups which is not in any Masking View", bo.getNativeGuid());
CIMObjectPath volumePath = _cimPath.getBlockObjectPath(storage, bo);
// See if Volume is associated with MV
mvPathItr = getAssociatorNames(storage, volumePath, null, SYMM_LUN_MASKING_VIEW, null, null);
if (!mvPathItr.hasNext()) {
isSGInAnyMV = false;
}
if (!isSGInAnyMV) {
_log.info("Device {} is not in any Masking View, hence removing it from Storage Groups if any", bo.getNativeGuid());
boolean forceFlag = ExportUtils.useEMCForceFlag(_dbClient, bo.getId());
// Get all the storage groups associated with this volume
sgInstancesItr = getAssociatorInstances(storage, volumePath, null, SmisConstants.SE_DEVICE_MASKING_GROUP, null, null, PS_ELEMENT_NAME);
while (sgInstancesItr.hasNext()) {
CIMInstance sgPath = sgInstancesItr.next();
String storageGroupName = CIMPropertyFactory.getPropertyValue(sgPath, SmisConstants.CP_ELEMENT_NAME);
// Double check: check if SG is part of MV
if (!checkStorageGroupInAnyMaskingView(storage, sgPath.getObjectPath())) {
// if last volume, dis-associate FAST
int sgVolumeCount = getVMAXStorageGroupVolumeCount(storage, storageGroupName);
if (sgVolumeCount == 1) {
WBEMClient client = getConnection(storage).getCimClient();
removeVolumeGroupFromPolicyAndLimitsAssociation(client, storage, sgPath.getObjectPath());
}
removeVolumesFromStorageGroup(storage, storageGroupName, Collections.singletonList(bo.getId()), forceFlag);
// If there was only one volume in the SG, it would be empty after removing that last volume.
if (sgVolumeCount == 1) {
_log.info("Deleting Empty Storage Group {}", storageGroupName);
deleteMaskingGroup(storage, storageGroupName, SmisCommandHelper.MASKING_GROUP_TYPE.SE_DeviceMaskingGroup);
}
}
}
} else {
_log.info("Found that Device {} is part of Masking View {}", bo.getNativeGuid(), mvPathItr.next());
}
} catch (Exception e) {
_log.warn("Exception while trying to remove device {} from Storage Groups which is not in any Masking View", bo.getNativeGuid(), e);
} finally {
closeCIMIterator(mvPathItr);
closeCIMIterator(sgInstancesItr);
}
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class SmisCommandHelper method getInstances.
/**
* This is a wrapper for the WBEMClient enumerateInstances method.
*
* @param storage
* - StorageArray reference, will be used to lookup SMI-S connection
* @param namespace
* - Namespace to use
* @param className
* - Name of the class on the provider to query
* @param deep
* - If true, this specifies that, for each returned Instance of the Class, all
* properties of the Instance must be present (subject to constraints imposed by the
* other parameters), including any which were added by subclassing the specified
* Class. If false, each returned Instance includes only properties defined for the
* specified Class in path.
* @param localOnly
* - If true, only elements values that were instantiated in the instance is
* returned.
* @param includeClassOrigin
* - The class origin attribute is the name of the class that first defined the
* property. If true, the class origin attribute will be present for each property on
* all returned CIMInstances. If false, the class origin will not be present.
* @param propertyList
* - An array of property names used to filter what is contained in the instances
* returned. Each instance returned only contains elements for the properties of the
* names specified. Duplicate and invalid property names are ignored and the request
* is otherwise processed normally. An empty array indicates that no properties
* should be returned. A null value indicates that all properties should be returned.
* @return - CloseableIterator of CIMInstance values representing the instances of the specified
* class.
* @throws Exception
*/
public CloseableIterator<CIMInstance> getInstances(StorageSystem storage, String namespace, String className, boolean deep, boolean localOnly, boolean includeClassOrigin, String[] propertyList) throws Exception {
CloseableIterator<CIMInstance> cimInstances;
CimConnection connection = _cimConnection.getConnection(storage);
WBEMClient client = connection.getCimClient();
String classKey = namespace + className;
CIMObjectPath cimObjectPath = CIM_OBJECT_PATH_HASH_MAP.get(classKey);
if (cimObjectPath == null) {
cimObjectPath = CimObjectPathCreator.createInstance(className, namespace);
CIM_OBJECT_PATH_HASH_MAP.putIfAbsent(classKey, cimObjectPath);
}
cimInstances = client.enumerateInstances(cimObjectPath, deep, localOnly, includeClassOrigin, propertyList);
return cimInstances;
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class SmisCommandHelper method checkConnectionliveness.
public boolean checkConnectionliveness(StorageSystem storageDevice) {
boolean isLive = false;
try {
CimConnection connection = getConnection(storageDevice);
WBEMClient client = connection.getCimClient();
// Call the provider to get computer systems.
client.enumerateInstanceNames(_cop);
isLive = true;
} catch (Exception wbemEx) {
_log.error("Invalid connection found for Provider: {}", storageDevice.getActiveProviderURI());
}
return isLive;
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class IBMCIMObjectPathFactory method executeQuery.
/**
* Executes query
*
* @param storageSystem
* @param query
* @param queryLanguage
* @return list of matched instances
*/
public List<CIMInstance> executeQuery(StorageSystem storageSystem, CIMObjectPath objectPath, String query, String queryLanguage) {
CloseableIterator<CIMInstance> iterator = null;
CimConnection connection = _cimConnection.getConnection(storageSystem);
WBEMClient client = connection.getCimClient();
_log.info(String.format("Executing query: %s, objectPath: %s, query language: %s", query, objectPath, queryLanguage));
List<CIMInstance> instanceList = new ArrayList<CIMInstance>();
try {
iterator = client.execQuery(objectPath, query, queryLanguage);
while (iterator.hasNext()) {
CIMInstance instance = iterator.next();
instanceList.add(instance);
}
} catch (WBEMException we) {
_log.error("Caught an error while attempting to execute query and process query result. Query: " + query, we);
} finally {
if (iterator != null) {
iterator.close();
}
}
return instanceList;
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class XIVSmisCommandHelper method getInstance.
/*
* Return CIM instance of the given object path.
*/
public CIMInstance getInstance(StorageSystem storage, CIMObjectPath objectPath, boolean propagated, boolean includeClassOrigin, String[] propertyList) throws Exception {
CimConnection connection = _cimConnection.getConnection(storage);
WBEMClient client = connection.getCimClient();
// CTRL-9069 workaround CIM_BAD_REQUEST error
CIMInstance instance = null;
int retryCount = 0;
while (true) {
try {
_log.info("Calling getInstance, attempt {}", retryCount);
instance = client.getInstance(objectPath, propagated, includeClassOrigin, propertyList);
} catch (WBEMException e) {
if (CIM_BAD_REQUEST.equals(e.getMessage())) {
if (retryCount < CIM_MAX_RETRY_COUNT) {
_log.warn("Encountered 'request-not-well-formed' error. Retry...");
retryCount++;
try {
Thread.sleep(CIM_RETRY_WAIT_INTERVAL);
} catch (InterruptedException ie) {
_log.warn("Thread: " + Thread.currentThread().getName() + " interrupted.");
throw e;
}
continue;
}
_log.warn("Exhausted {} retries", CIM_MAX_RETRY_COUNT);
}
// other WBEMException, or reach the max retry count
throw e;
}
// no exception
break;
}
return instance;
}
Aggregations