use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.
the class SmisUtils method updateStoragePoolCapacity.
public static void updateStoragePoolCapacity(DbClient dbClient, WBEMClient client, URI storagePoolURI) {
StorageSystem storageSystem = null;
try {
StoragePool storagePool = dbClient.queryObject(StoragePool.class, storagePoolURI);
storageSystem = dbClient.queryObject(StorageSystem.class, storagePool.getStorageDevice());
_log.info(String.format("Old storage pool capacity data for %n pool %s/%s --- %n free capacity: %s; subscribed capacity: %s", storageSystem.getId(), storagePoolURI, storagePool.calculateFreeCapacityWithoutReservations(), storagePool.getSubscribedCapacity()));
// Get cim object path factory from context
CIMObjectPathFactory objectPathFactory = null;
// FIXME Shouldn't have hardcoded bean references here
if (storageSystem.getSystemType().equals(StorageSystem.Type.vmax.toString())) {
objectPathFactory = (CIMObjectPathFactory) ControllerServiceImpl.getBean("vmaxCIMObjectPathFactoryAdapter");
} else if (storageSystem.getSystemType().equals(StorageSystem.Type.vnxblock.toString())) {
objectPathFactory = (CIMObjectPathFactory) ControllerServiceImpl.getBean("vnxCIMObjectPathFactory");
} else {
String msg = String.format("Unexpected storage system type: %s for storage system %s ", storageSystem.getSystemType(), storageSystem.getId());
_log.error(msg);
throw new RuntimeException(msg);
}
CIMObjectPath poolPath = objectPathFactory.getStoragePoolPath(storageSystem, storagePool);
CIMInstance poolInstance = client.getInstance(poolPath, true, false, null);
// Get capacity properties.
Long freePoolCapacity = getFreeCapacity(poolInstance);
String subscribedCapacity = getCIMPropertyValue(poolInstance, SmisConstants.CP_SUBSCRIBEDCAPACITY);
// Update storage pool and save to data base
storagePool.setFreeCapacity(freePoolCapacity);
if (null != subscribedCapacity) {
storagePool.setSubscribedCapacity(ControllerUtils.convertBytesToKBytes(subscribedCapacity));
}
_log.info(String.format("New storage pool capacity data for pool %n %s/%s --- %n free capacity: %s; subscribed capacity: %s", storageSystem.getId(), storagePoolURI, storagePool.getFreeCapacity(), storagePool.getSubscribedCapacity()));
dbClient.persistObject(storagePool);
} catch (Exception e) {
_log.error(String.format("Failed to update capacity of storage pool after volume provisioning operation. %n Storage system: %s, storage pool %s .", storageSystem.getId(), storagePoolURI), e);
}
}
use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.
the class XIVExportOperations method createSMISExportMask.
private void createSMISExportMask(StorageSystem storage, URI exportMaskURI, VolumeURIHLU[] volumeURIHLUs, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
_log.info("{} createExportMask START...", storage.getLabel());
try {
_log.info("createExportMask: Export mask id: {}", exportMaskURI);
_log.info("createExportMask: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
_log.info("createExportMask: initiators: {}", Joiner.on(',').join(initiatorList));
_log.info("createExportMask: assignments: {}", Joiner.on(',').join(targetURIList));
CIMInstance controllerInst = null;
boolean createdBySystem = true;
Map<String, Initiator> initiatorMap = _helper.getInitiatorMap(initiatorList);
String[] initiatorNames = initiatorMap.keySet().toArray(new String[] {});
List<Initiator> userAddedInitiators = new ArrayList<Initiator>();
Map<String, CIMObjectPath> existingHwStorageIds = getStorageHardwareIds(storage);
// note - the initiator list maybe just a subset of all initiators on a host, need to
// get all the initiators from the host, and check here
// a special case is that there is a host on array side with i1 and i2,
// while there is a host with initiator i2 and i3 on ViPR side,
// we will not be able to match the two hosts if there is common initiator(s)
// if an HBA get moved from one host to another, it need to be removed on array side manually
List<Initiator> allInitiators;
Host host = null;
Initiator firstInitiator = initiatorList.get(0);
String label;
if (initiatorList.get(0).getHost() != null) {
allInitiators = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Initiator.class, ContainmentConstraint.Factory.getContainedObjectsConstraint(firstInitiator.getHost(), Initiator.class, "host"));
host = _dbClient.queryObject(Host.class, firstInitiator.getHost());
label = host.getLabel();
} else {
allInitiators = CustomQueryUtility.queryActiveResourcesByAltId(_dbClient, Initiator.class, "hostname", firstInitiator.getHostName());
label = firstInitiator.getHostName();
}
for (Initiator initiator : allInitiators) {
String normalizedPortName = Initiator.normalizePort(initiator.getInitiatorPort());
CIMObjectPath initiatorPath = existingHwStorageIds.get(normalizedPortName);
if (initiatorPath != null) {
_log.info(String.format("Initiator %s already exists", initiator.getInitiatorPort()));
createdBySystem = false;
// get controller instance
controllerInst = getSCSIProtocolControllerInstanceByHwId(storage, initiatorPath);
if (controllerInst == null) {
_log.debug("createExportMask failed. No protocol controller created.");
ServiceError error = DeviceControllerErrors.smis.noProtocolControllerCreated();
taskCompleter.error(_dbClient, error);
_log.info("{} createExportMask END...", storage.getLabel());
return;
}
// get initiators
Map<String, CIMObjectPath> initiatorPortPaths = _helper.getInitiatorsFromScsiProtocolController(storage, controllerInst.getObjectPath());
Set<String> existingInitiatorPorts = initiatorPortPaths.keySet();
// check if initiators need to be added
List<String> initiatorsToAdd = new ArrayList<String>();
for (String port : initiatorNames) {
if (!existingInitiatorPorts.contains(port)) {
initiatorsToAdd.add(port);
userAddedInitiators.add(initiatorMap.get(port));
}
}
if (!initiatorsToAdd.isEmpty()) {
// add initiator to host on array side
CIMObjectPath specificCollectionPath = getSystemSpecificCollectionPathByHwId(storage, initiatorPath);
CIMArgument[] outArgs = new CIMArgument[5];
_helper.addHardwareIDsToCollection(storage, specificCollectionPath, initiatorsToAdd.toArray(new String[] {}), outArgs);
if (outArgs[0] == null) {
Set<String> hwIds = hasHwIdsInCollection(storage, specificCollectionPath);
if (!hwIds.containsAll(initiatorsToAdd)) {
throw new Exception("Failed to add initiator: " + Joiner.on(',').join(initiatorsToAdd));
}
}
}
// same host/controller on both ViPR and array sides
break;
}
}
// no matched initiator on array side, now try to find host with the given name
if (controllerInst == null) {
String query = String.format("Select * From %s Where ElementName=\"%s\"", IBMSmisConstants.CP_SYSTEM_SPECIFIC_COLLECTION, label);
CIMObjectPath hostPath = CimObjectPathCreator.createInstance(IBMSmisConstants.CP_SYSTEM_SPECIFIC_COLLECTION, Constants.IBM_NAMESPACE, null);
List<CIMInstance> hostInstances = _helper.executeQuery(storage, hostPath, query, "WQL");
if (!hostInstances.isEmpty()) {
CIMObjectPath specificCollectionPath = hostInstances.get(0).getObjectPath();
if (!hasHwIdInCollection(storage, specificCollectionPath)) {
createdBySystem = false;
userAddedInitiators = initiatorList;
// re-use the empty host
CIMArgument[] outArgs = new CIMArgument[5];
_helper.addHardwareIDsToCollection(storage, specificCollectionPath, initiatorNames, outArgs);
if (outArgs[0] == null) {
Set<String> hwIds = hasHwIdsInCollection(storage, specificCollectionPath);
if (!hwIds.containsAll(new ArrayList<String>(Arrays.asList(initiatorNames)))) {
throw new Exception("Failed to add initiator: " + Joiner.on(',').join(initiatorNames));
}
}
controllerInst = getSCSIProtocolControllerInstanceByIdCollection(storage, specificCollectionPath);
if (controllerInst == null) {
_log.debug("createExportMask failed. No protocol controller created.");
ServiceError error = DeviceControllerErrors.smis.noProtocolControllerCreated();
taskCompleter.error(_dbClient, error);
_log.info("{} createExportMask END...", storage.getLabel());
return;
}
}
}
}
// create new protocol controller
if (controllerInst == null) {
// create host first so that the desired host label could be used
CIMObjectPath sysSpecificCollectionPath = getSystemSpecificCollectionPath(storage, label, initiatorNames);
if (sysSpecificCollectionPath == null) {
_log.debug("createExportMask failed. No host created.");
ServiceError error = DeviceControllerErrors.smis.noProtocolControllerCreated();
taskCompleter.error(_dbClient, error);
_log.info("{} createExportMask END...", storage.getLabel());
return;
}
controllerInst = getSCSIProtocolControllerInstanceByIdCollection(storage, sysSpecificCollectionPath);
}
if (controllerInst != null) {
String elementName = CIMPropertyFactory.getPropertyValue(controllerInst, SmisConstants.CP_ELEMENT_NAME);
// set host tag is needed
if (host != null) {
if (label.equals(elementName)) {
_helper.unsetTag(host, storage.getSerialNumber());
} else {
_helper.setTag(host, storage.getSerialNumber(), elementName);
}
}
CIMObjectPath controller = controllerInst.getObjectPath();
ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
if (!createdBySystem) {
exportMask.setCreatedBySystem(createdBySystem);
exportMask.addToUserCreatedInitiators(userAddedInitiators);
}
// SCSIProtocolController.ElementName
exportMask.setMaskName(elementName);
// is the same as
// SystemSpecificCollection.ElementName
exportMask.setLabel(elementName);
CIMProperty<String> deviceId = (CIMProperty<String>) controller.getKey(IBMSmisConstants.CP_DEVICE_ID);
exportMask.setNativeId(deviceId.getValue());
_dbClient.persistObject(exportMask);
CIMArgument[] inArgs = _helper.getExposePathsInputArguments(volumeURIHLUs, null, controller);
CIMArgument[] outArgs = new CIMArgument[5];
// don't care if the volumes/initiators have already been in the
// mask
_helper.invokeMethod(storage, _cimPath.getControllerConfigSvcPath(storage), IBMSmisConstants.EXPOSE_PATHS, inArgs, outArgs);
CIMObjectPath[] protocolControllers = _cimPath.getProtocolControllersFromOutputArgs(outArgs);
CIMObjectPath protocolController = protocolControllers[0];
// for debug only
if (_log.isDebugEnabled()) {
List<String> targetEndpoints = getTargetEndpoints(protocolController, storage);
_log.debug(String.format("ProtocolController %s with target ports: %s", protocolController.getObjectName(), Joiner.on(',').join(targetEndpoints)));
}
CimConnection cimConnection = _helper.getConnection(storage);
// Call populateDeviceNumberFromProtocolControllers only after
// initiators
// have been added. HLU's will not be reported till the Device
// is Host visible
ExportMaskOperationsHelper.populateDeviceNumberFromProtocolControllers(_dbClient, cimConnection, exportMaskURI, volumeURIHLUs, protocolControllers, taskCompleter);
taskCompleter.ready(_dbClient);
} else {
_log.debug("createExportMask failed. No protocol controller created.");
ServiceError error = DeviceControllerErrors.smis.noProtocolControllerCreated();
taskCompleter.error(_dbClient, error);
}
} catch (Exception e) {
_log.error("Unexpected error: createExportMask failed.", e);
ServiceError error = DeviceControllerErrors.smis.methodFailed("createExportMask", e.getMessage());
taskCompleter.error(_dbClient, error);
}
_log.info("{} createExportMask END...", storage.getLabel());
}
use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.
the class XIVExportOperations method getTargetEndpoints.
/**
* Looks up the targets that are associated with the protocol controller (if any).
*
* @param protocolController
* [in] - CIMObjectPath representing protocol controller to lookup target endpoints (StoragePorts) for
* @param storage
* [in] - StorageSystem object representing the array
* @return List or StoragePort URIs that were found to be end points for the protocol controller
* @throws Exception
*/
private List<String> getTargetEndpoints(CIMObjectPath protocolController, StorageSystem storage) throws Exception {
List<String> endpoints = new ArrayList<String>();
CloseableIterator<CIMInstance> fcPortIter = null;
try {
fcPortIter = _helper.getAssociatorInstances(storage, protocolController, IBMSmisConstants.CP_PROTOCOL_CONTROLLER_FOR_PORT, IBMSmisConstants.CP_LOGICALPORT, null, null, IBMSmisConstants.PS_PERMANENT_ADDRESS);
while (fcPortIter.hasNext()) {
CIMInstance instance = fcPortIter.next();
String targetPortId = CIMPropertyFactory.getPropertyValue(instance, IBMSmisConstants.CP_PERMANENT_ADDRESS);
List<StoragePort> storagePorts = CustomQueryUtility.queryActiveResourcesByAltId(_dbClient, StoragePort.class, IBMSmisConstants.PORT_NETWORK_ID, WWNUtility.getWWNWithColons(targetPortId));
for (StoragePort port : storagePorts) {
endpoints.add(port.getNativeGuid());
}
}
} finally {
if (fcPortIter != null) {
fcPortIter.close();
}
}
_log.info(String.format("SPC %s has these target endpoints: [ %s ]", protocolController.toString(), Joiner.on(',').join(endpoints)));
return endpoints;
}
use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.
the class XIVExportOperations method refreshSMISExportMask.
private ExportMask refreshSMISExportMask(StorageSystem storage, ExportMask mask) {
try {
CIMInstance instance = _helper.getSCSIProtocolController(storage, mask);
if (instance != null) {
StringBuilder builder = new StringBuilder();
String name = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_NAME);
// Get volumes and initiators for the masking instance
CIMObjectPath controllerPath = instance.getObjectPath();
Map<String, Integer> discoveredVolumes = _helper.getVolumesFromScsiProtocolController(storage, controllerPath);
Map<String, CIMObjectPath> discoveredPortPaths = _helper.getInitiatorsFromScsiProtocolController(storage, instance.getObjectPath());
Set<String> discoveredPorts = discoveredPortPaths.keySet();
Set existingInitiators = (mask.getExistingInitiators() != null) ? mask.getExistingInitiators() : Collections.emptySet();
Set existingVolumes = (mask.getExistingVolumes() != null) ? mask.getExistingVolumes().keySet() : Collections.emptySet();
builder.append(String.format("%nXM object: %s I{%s} V:{%s}%n", name, Joiner.on(',').join(existingInitiators), Joiner.on(',').join(existingVolumes)));
builder.append(String.format("XM discovered: %s I:{%s} V:{%s}%n", name, Joiner.on(',').join(discoveredPorts), Joiner.on(',').join(discoveredVolumes.keySet())));
// Check the initiators and update the lists as necessary
boolean addInitiators = false;
List<String> initiatorsToAdd = new ArrayList<String>();
for (String port : discoveredPorts) {
String normalizedPort = Initiator.normalizePort(port);
if (!mask.hasExistingInitiator(normalizedPort) && !mask.hasUserInitiator(normalizedPort)) {
initiatorsToAdd.add(normalizedPort);
addInitiators = true;
}
}
boolean removeInitiators = false;
List<String> initiatorsToRemove = new ArrayList<String>();
if (mask.getExistingInitiators() != null && !mask.getExistingInitiators().isEmpty()) {
initiatorsToRemove.addAll(mask.getExistingInitiators());
initiatorsToRemove.removeAll(discoveredPorts);
removeInitiators = !initiatorsToRemove.isEmpty();
}
// Check the volumes and update the lists as necessary
Map<String, Integer> volumesToAdd = ExportMaskUtils.diffAndFindNewVolumes(mask, discoveredVolumes);
boolean addVolumes = !volumesToAdd.isEmpty();
boolean removeVolumes = false;
List<String> volumesToRemove = new ArrayList<String>();
if (mask.getExistingVolumes() != null && !mask.getExistingVolumes().isEmpty()) {
volumesToRemove.addAll(mask.getExistingVolumes().keySet());
volumesToRemove.removeAll(discoveredVolumes.keySet());
removeVolumes = !volumesToRemove.isEmpty();
}
boolean changeName = false;
if (!mask.getMaskName().equals(name)) {
changeName = true;
mask.setLabel(name);
mask.setMaskName(name);
// update host label
StringSet initiators = mask.getInitiators();
if (initiators != null) {
Iterator<String> itr = initiators.iterator();
if (itr.hasNext()) {
Initiator initiator = _dbClient.queryObject(Initiator.class, URI.create(itr.next()));
Host host = _dbClient.queryObject(Host.class, initiator.getHost());
String label = host.getLabel();
if (label.equals(name)) {
_helper.unsetTag(host, storage.getSerialNumber());
} else {
_helper.setTag(host, storage.getSerialNumber(), name);
}
}
}
}
builder.append(String.format("XM refresh: %s initiators; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(initiatorsToAdd), Joiner.on(',').join(initiatorsToRemove)));
builder.append(String.format("XM refresh: %s volumes; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(volumesToAdd.keySet()), Joiner.on(',').join(volumesToRemove)));
// Any changes indicated, then update the mask and persist it
if (addInitiators || removeInitiators || addVolumes || removeVolumes || changeName) {
builder.append("XM refresh: There are changes to mask, " + "updating it...\n");
mask.removeFromExistingInitiators(initiatorsToRemove);
mask.addToExistingInitiatorsIfAbsent(initiatorsToAdd);
mask.removeFromExistingVolumes(volumesToRemove);
mask.addToExistingVolumesIfAbsent(volumesToAdd);
ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, mask);
_dbClient.updateAndReindexObject(mask);
} else {
builder.append("XM refresh: There are no changes to the mask\n");
}
_networkDeviceController.refreshZoningMap(mask, initiatorsToRemove, Collections.EMPTY_LIST, (addInitiators || removeInitiators), true);
_log.info(builder.toString());
}
} catch (Exception e) {
boolean throwException = true;
if (e instanceof WBEMException) {
WBEMException we = (WBEMException) e;
// Only throw exception if code is not CIM_ERROR_NOT_FOUND
throwException = (we.getID() != WBEMException.CIM_ERR_NOT_FOUND);
}
if (throwException) {
String msg = "Error when attempting to query LUN masking information: " + e.getMessage();
_log.error(MessageFormat.format("Encountered an SMIS error when attempting to refresh existing exports: {0}", msg), e);
throw SmisException.exceptions.refreshExistingMaskFailure(msg, e);
}
}
return mask;
}
use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.
the class XIVSmisCommandHelper method getInstances.
/**
* 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
*/
private 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;
}
Aggregations