use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class SmisWaitForSynchronizedJob method poll.
@Override
public JobPollResult poll(JobContext jobContext, long trackingPeriodInMillis) {
JobPollResult pollResult = new JobPollResult();
DbClient dbClient = jobContext.getDbClient();
CIMConnectionFactory factory = jobContext.getCimConnectionFactory();
WBEMClient client = getWBEMClient(dbClient, factory);
TaskCompleter completer = getTaskCompleter();
BlockObject target = dbClient.queryObject(clazz, completer.getId());
CloseableIterator<CIMInstance> references = null;
try {
pollResult.setJobName(getJobName());
pollResult.setJobId(SmisConstants.CP_PERCENT_SYNCED);
pollResult.setJobStatus(JobStatus.IN_PROGRESS);
CIMObjectPath path = getTargetPath();
// no corresponding sync obj, set to complete
if (SmisConstants.NULL_IBM_CIM_OBJECT_PATH.equals(path)) {
log.info("Sync complete");
pollResult.setJobPercentComplete(100);
pollResult.setJobStatus(JobStatus.SUCCESS);
completer.ready(dbClient);
return pollResult;
}
references = client.referenceInstances(getTargetPath(), SmisConstants.CIM_STORAGE_SYNCHRONIZED, null, false, null);
if (references.hasNext()) {
CIMInstance syncInstance = references.next();
String state = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_SYNC_STATE);
String type = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_SYNC_TYPE);
String percent = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_PERCENT_SYNCED);
String status = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_PROGRESS_STATUS);
String msg = String.format("Target=%s, State=%s, Type=%s, Percent=%s, Status=%s", target.getId(), state, type, percent, status);
log.info(msg);
pollResult.setJobPercentComplete(Integer.parseInt(percent));
if (COMPLETE.equals(percent)) {
pollResult.setJobStatus(JobStatus.SUCCESS);
completer.ready(dbClient);
}
} else {
pollResult.setJobStatus(JobStatus.FAILED);
}
} catch (Exception e) {
log.error("Failed to update synchronization", e);
pollResult.setJobStatus(JobStatus.FAILED);
completer.error(dbClient, DeviceControllerException.errors.jobFailed(e));
} finally {
if (references != null) {
references.close();
}
}
return pollResult;
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class Util method getMethod.
/**
* get Method to execute If operation.Argument Objects size ==
* Method.Parameters size, then select the Method.
*
* @param methodName
* : Method.
* @param operation
* : Domain logic operation.
* @param instance
* : CIMCLient or Request or any 3rd party..
* @return Method.
*/
public final Method getMethod(final Operation operation, final String methodName, final Object instance, final String endPoint) {
Method method = null;
try {
Class[] parameterTypeClasses = getParameterTypesFromConfiguration(operation, endPoint);
if (null == parameterTypeClasses || parameterTypeClasses.length == 0) {
Method[] methods = instance.getClass().getMethods();
for (Method m : methods) {
if (instance instanceof WBEMClient) {
if (m.getName().equalsIgnoreCase(methodName) && operation.getArguments().size() == m.getParameterTypes().length) {
method = m;
_logger.debug("Method found :" + m.getName());
break;
}
} else {
if (m.getName().equalsIgnoreCase(methodName)) {
method = m;
break;
}
}
}
} else {
// find Overloaded Methods by passing expected Argument Classes
method = instance.getClass().getMethod(methodName, parameterTypeClasses);
_logger.debug("Method found :" + method.getName());
}
} catch (SecurityException e) {
_logger.error("Method Not found due to Security Exception : {} -->{}", methodName, e);
} catch (NoSuchMethodException e) {
_logger.error("Method Not found due to NoSuchMethodException :{} -->{}", methodName, e);
} catch (ClassNotFoundException e) {
_logger.error("Method Not found due to ClassNotFoundException :{} -->{}", methodName, e);
}
return method;
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class CimSubscriptionManager method deleteStaleSubscriptions.
/**
* Deletes stale instances on the CIM provider that are associated with
* stale subscriptions. The connection manager can be configured to
* optionally call this function when establishing a connection to the
* provider for the purpose of cleaning up old subscriptions from previous
* connections to the provider that were not properly cleaned up.
*
* @throws WBEMException Enumerating the subscription instances on the
* provider.
*/
public void deleteStaleSubscriptions() throws WBEMException {
CIMInstance subscription;
CIMProperty<?> property;
CIMObjectPath subscriptionHandlerPath;
CIMObjectPath subscriptionFilterPath;
String subscriptionFilterName;
String subscriptionHandlerName;
Set<CIMObjectPath> staleSubscriptionSet = new HashSet<CIMObjectPath>();
Map<String, CIMObjectPath> staleFilterMap = new HashMap<String, CIMObjectPath>();
Map<String, CIMObjectPath> staleHandlerMap = new HashMap<String, CIMObjectPath>();
// Get and loop over all subscriptions.
WBEMClient cimClient = _connection.getCimClient();
CIMObjectPath subscriptionPath = CimObjectPathCreator.createInstance(CimConstants.CIM_SUBSCRIPTION_NAME, _connection.getInteropNamespace());
CloseableIterator<CIMInstance> subscriptionIter = null;
try {
subscriptionIter = cimClient.enumerateInstances(subscriptionPath, true, true, false, null);
while (subscriptionIter.hasNext()) {
subscription = subscriptionIter.next();
// Get the handler for the subscription.
property = subscription.getProperty(CimConstants.SUBSCRIPTION_PROP_HANDLER);
subscriptionHandlerPath = (CIMObjectPath) property.getValue();
// If the name of the handler contains the passed subscription
// identifier then this is a stale subscription to be deleted.
// Note that subscriptions themselves are not assigned names
// when they are created. However, both the handler and filter
// associated with the subscription are assigned names, and the
// name contains the subscription identifier configured for
// the connection manager. Therefore, we could check either the
// handler or the filter.
subscriptionHandlerName = subscriptionHandlerPath.getKey(CimConstants.NAME_KEY).getValue().toString();
if (subscriptionHandlerName.contains(_subscriptionsIdentifier)) {
// Add the subscription to the stale subscription set.
staleSubscriptionSet.add(subscription.getObjectPath());
// handler.
if (!staleHandlerMap.keySet().contains(subscriptionHandlerName)) {
staleHandlerMap.put(subscriptionHandlerName, subscriptionHandlerPath);
}
// Now get and add the filter for the subscription to the stale
// filters map. Again, it is possible that multiple
// subscriptions reference the same filter.
property = subscription.getProperty(CimConstants.SUBSCRIPTION_PROP_FILTER);
subscriptionFilterPath = (CIMObjectPath) property.getValue();
subscriptionFilterName = subscriptionFilterPath.getKey(CimConstants.NAME_KEY).getValue().toString();
if (!staleFilterMap.keySet().contains(subscriptionFilterName)) {
staleFilterMap.put(subscriptionFilterName, subscriptionFilterPath);
}
}
}
// Delete the stale subscriptions first, which reference the filters and
// handlers.
Iterator<CIMObjectPath> pathsIter = staleSubscriptionSet.iterator();
while (pathsIter.hasNext()) {
deleteInstance(pathsIter.next());
}
// Next delete the stale filters.
pathsIter = staleFilterMap.values().iterator();
while (pathsIter.hasNext()) {
deleteInstance(pathsIter.next());
}
// Finally, delete the stale handlers.
pathsIter = staleHandlerMap.values().iterator();
while (pathsIter.hasNext()) {
deleteInstance(pathsIter.next());
}
} finally {
if (subscriptionIter != null) {
subscriptionIter.close();
}
}
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class SMICommunicationInterface method getCIMClient.
/**
* Creates a new WEBClient for a given IP, based on AccessProfile
*
* @param accessProfile
* : AccessProfile for the providers
* @throws WBEMException
* : if WBEMException while creating the WBEMClient
* @throws SMIPluginException
* @return WBEMClient : initialized instance of WBEMClientCIMXML
*/
private static WBEMClient getCIMClient(AccessProfile accessProfile) throws SMIPluginException {
WBEMClient cimClient = null;
try {
final CIMConnectionFactory connectionFactory = (CIMConnectionFactory) accessProfile.getCimConnectionFactory();
CimConnection cxn = connectionFactory.getConnection(accessProfile.getIpAddress(), accessProfile.getProviderPort());
if (cxn == null) {
throw new SMIPluginException(String.format("Not able to get CimConnection to SMISProvider %s on port %s", accessProfile.getIpAddress(), accessProfile.getProviderPort()), SMIPluginException.ERRORCODE_NO_WBEMCLIENT);
}
cimClient = cxn.getCimClient();
if (null == cimClient) {
throw new SMIPluginException("Not able to get CIMOM client", SMIPluginException.ERRORCODE_NO_WBEMCLIENT);
}
} catch (final IllegalStateException ex) {
_logger.error("Not able to get CIMOM Client instance for ip {} due to ", accessProfile.getIpAddress(), ex);
throw new SMIPluginException(SMIPluginException.ERRORCODE_NO_WBEMCLIENT, ex.fillInStackTrace(), ex.getMessage());
}
return cimClient;
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class LunMaskingProcessor method processResult.
@Override
public void processResult(Operation operation, Object resultObj, Map<String, Object> keyMap) throws BaseCollectionException {
@SuppressWarnings("unchecked") final Iterator<CIMObjectPath> it = (Iterator<CIMObjectPath>) resultObj;
Map<String, VolHostIOObject> volToIolimits = new HashMap<String, VolHostIOObject>();
List<CIMObjectPath> processedSGCoPs = new ArrayList<CIMObjectPath>();
Map<String, String> volToFastPolicy = new HashMap<String, String>();
WBEMClient client = SMICommunicationInterface.getCIMClient(keyMap);
CIMObjectPath maskingViewPath = getObjectPathfromCIMArgument(_args);
_dbClient = (DbClient) keyMap.get(Constants.dbClient);
AccessProfile profile = (AccessProfile) keyMap.get(Constants.ACCESSPROFILE);
URI systemId = profile.getSystemId();
try {
StorageSystem device = _dbClient.queryObject(StorageSystem.class, systemId);
while (it.hasNext()) {
CIMObjectPath path = it.next();
// use io limit on child always
if (path.toString().contains(SmisCommandHelper.MASKING_GROUP_TYPE.SE_DeviceMaskingGroup.name())) {
List<CIMObjectPath> paths = getChildGroupsifCascaded(path, client);
if (!paths.isEmpty()) {
_logger.info("Cascaded SG Detected");
CIMInstance csgInstance = client.getInstance(path, false, true, SmisConstants.PS_HOST_IO);
String parentHostIoBw = String.valueOf(csgInstance.getPropertyValue(SmisConstants.EMC_MAX_BANDWIDTH));
String parentHostIoPs = String.valueOf(csgInstance.getPropertyValue(SmisConstants.EMC_MAX_IO));
for (CIMObjectPath childPath : paths) {
addIoLimitsOnVolume(client, childPath, volToIolimits, volToFastPolicy, parentHostIoBw, parentHostIoPs);
}
processedSGCoPs.addAll(paths);
} else {
_logger.info("Non cascaded SG Detected");
addIoLimitsOnVolume(client, path, volToIolimits, volToFastPolicy, "0", "0");
processedSGCoPs.add(path);
}
}
// Clar_LunMaskingSCSIProtocolController-->StorageVolume, if volume entry is there,
// then consider those as exported Volumes.
String systemName = (String) maskingViewPath.getKey(Constants.SYSTEMNAME).getValue();
if (systemName.toLowerCase().contains(Constants.CLARIION) && path.toString().toLowerCase().contains(STORAGE_VOLUME_PREFIX)) {
String volumeNativeGuid = getVolumeNativeGuid(path);
VolHostIOObject obj = new VolHostIOObject();
obj.setVolNativeGuid(volumeNativeGuid);
obj.setHostIoBw("0");
obj.setHostIops("0");
volToIolimits.put(volumeNativeGuid, obj);
}
}
// will be used to filter out already exported Volumes
if (!keyMap.containsKey(Constants.EXPORTED_VOLUMES)) {
keyMap.put(Constants.EXPORTED_VOLUMES, volToIolimits);
} else {
@SuppressWarnings("unchecked") Map<String, VolHostIOObject> alreadyExportedVolumes = (Map<String, VolHostIOObject>) keyMap.get(Constants.EXPORTED_VOLUMES);
alreadyExportedVolumes.putAll(volToIolimits);
}
if (device.checkIfVmax3()) {
// SLO Names.
if (!keyMap.containsKey(Constants.STORAGE_GROUPS_PROCESSED)) {
keyMap.put(Constants.STORAGE_GROUPS_PROCESSED, processedSGCoPs);
} else {
List<CIMObjectPath> volumesWithFastPolicy = (List<CIMObjectPath>) keyMap.get(Constants.STORAGE_GROUPS_PROCESSED);
volumesWithFastPolicy.addAll(processedSGCoPs);
}
// Set the volumesWithSLO in the keyMap for further processing.
if (!keyMap.containsKey(Constants.VOLUMES_WITH_SLOS)) {
keyMap.put(Constants.VOLUMES_WITH_SLOS, volToFastPolicy);
} else {
Map<String, String> volumesWithFastPolicy = (Map<String, String>) keyMap.get(Constants.VOLUMES_WITH_SLOS);
volumesWithFastPolicy.putAll(volToFastPolicy);
}
}
} catch (Exception e) {
_logger.error("Extracting already exported Volumes failed", e);
}
}
Aggregations