use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class VmaxExportOperations method createInitiatorGroupWithInitiators.
private CIMObjectPath createInitiatorGroupWithInitiators(StorageSystem storage, String groupName, List<Initiator> initiatorList, boolean consistentLUNs, TaskCompleter taskCompleter) throws Exception {
_log.debug("{} createInitiatorGroupWithInitiators START...", storage.getSerialNumber());
CIMObjectPath initiatorGroupPath = null;
String[] initiators = _helper.getInitiatorNames(initiatorList, storage);
CIMArgument[] inArgs = _helper.getCreateInitiatorGroupInputArguments(storage, groupName, initiators, consistentLUNs);
CIMArgument[] outArgs = new CIMArgument[5];
try {
CIMObjectPath cigPath = _helper.getInitiatorGroupPath(storage, groupName);
CIMInstance igInstance = _helper.checkExists(storage, cigPath, false, false);
if (igInstance == null) {
_helper.invokeMethod(storage, _cimPath.getControllerConfigSvcPath(storage), "CreateGroup", inArgs, outArgs);
initiatorGroupPath = _cimPath.getCimObjectPathFromOutputArgs(outArgs, "MaskingGroup");
ExportOperationContext.insertContextOperation(taskCompleter, VmaxExportOperationContext.OPERATION_CREATE_INITIATOR_GROUP, groupName, initiatorList, initiatorGroupPath);
_log.info("createInitiatorGroupWithInitiators - IG doesn't exist, " + "creating new one {}", initiatorGroupPath);
} else {
initiatorGroupPath = igInstance.getObjectPath();
_log.info("createInitiatorGroupWithInitiators - IG {} already exists, " + "will reuse it for initiators", initiatorGroupPath);
// Only add initiators if they don't already exist in the IG. This is
// used to validate this scenario.
Set<String> hwIds = new HashSet<String>();
CloseableIterator<CIMInstance> initiatorIterator = _helper.getAssociatorInstances(storage, initiatorGroupPath, null, SmisConstants.CP_SE_STORAGE_HARDWARE_ID, null, null, SmisConstants.PS_STORAGE_ID);
if (initiatorIterator != null) {
while (initiatorIterator.hasNext()) {
CIMInstance cimInstance = initiatorIterator.next();
if (cimInstance != null) {
String hwId = CIMPropertyFactory.getPropertyValue(cimInstance, SmisConstants.CP_STORAGE_ID);
hwIds.add(hwId);
}
}
initiatorIterator.close();
Iterator<Initiator> it = initiatorList.iterator();
while (it.hasNext()) {
Initiator init = it.next();
String hwId = Initiator.normalizePort(init.getInitiatorPort());
if (hwIds.contains(hwId)) {
it.remove();
}
}
}
if (!initiatorList.isEmpty()) {
addInitiatorsToInitiatorGroup(storage, initiatorList, initiatorGroupPath, taskCompleter);
}
return initiatorGroupPath;
}
if (hasInitiatorHPUX(initiatorList)) {
setVSAFlagForIG(storage, initiatorGroupPath, true);
}
} catch (WBEMException we) {
_log.info("{} Problem when trying to create createInitiatorGroupWithInitiators ... going to look up initiator group.", storage.getSystemType(), we);
initiatorGroupPath = handleCreateMaskingGroupException(storage, groupName, inArgs, SmisCommandHelper.MASKING_GROUP_TYPE.SE_InitiatorMaskingGroup);
if (initiatorGroupPath == null) {
_log.info("{} Problem looking up initiator group.", storage.getSerialNumber(), we);
throw we;
} else {
_log.info("{} Found initiator group with expected members.", storage.getSerialNumber());
}
}
_log.debug("{} createInitiatorGroupWithInitiators END...", storage.getSerialNumber());
return initiatorGroupPath;
}
use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class VmaxExportOperations method addVolumeGroupToAutoTieringPolicy.
private CIMObjectPath addVolumeGroupToAutoTieringPolicy(StorageSystem storage, String policyName, CIMObjectPath volumeGroupPath, TaskCompleter taskCompleter) throws Exception {
_log.debug("{} addVolumeGroupToAutoTierPolicy START...", storage.getSerialNumber());
CIMObjectPath cascadedVolumeGroupObjectPath = null;
CIMObjectPath[] volumeGroupPaths = new CIMObjectPath[] { volumeGroupPath };
CIMArgument[] inArgs = _helper.getVolumeGroupToTierInputArguments(storage, policyName, volumeGroupPaths);
CIMArgument[] outArgs = new CIMArgument[5];
try {
_helper.invokeMethod(storage, _cimPath.getTierPolicySvcPath(storage), "ModifyStorageTierPolicyRule", inArgs, outArgs);
cascadedVolumeGroupObjectPath = _cimPath.getCimObjectPathFromOutputArgs(outArgs, "MaskingGroup");
ExportOperationContext.insertContextOperation(taskCompleter, VmaxExportOperationContext.OPERATION_ADD_TIER_TO_STORAGE_GROUP, policyName, volumeGroupPaths);
} catch (WBEMException we) {
// If the VG by the same name exists, the WBEM exception thrown is CIM_ERR_FAILED.
throw we;
}
_log.debug("{} addVolumeGroupToAutoTierPolicy END...", storage.getSerialNumber());
return cascadedVolumeGroupObjectPath;
}
use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class VmaxExportOperations method refreshExportMask.
@Override
public ExportMask refreshExportMask(StorageSystem storage, ExportMask mask) throws DeviceControllerException {
long startTime = System.currentTimeMillis();
try {
CIMInstance instance = _helper.getSymmLunMaskingView(storage, mask);
if (instance != null) {
StringBuilder builder = new StringBuilder();
WBEMClient client = _helper.getConnection(storage).getCimClient();
String name = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_ELEMENT_NAME);
// Get volumes and initiators for the masking instance
Map<String, Integer> discoveredVolumes = _helper.getVolumesFromLunMaskingInstance(client, instance);
List<String> discoveredPorts = _helper.getInitiatorsFromLunMaskingInstance(client, instance);
Set existingInitiators = (mask.getExistingInitiators() != null) ? mask.getExistingInitiators() : Collections.emptySet();
Set existingVolumes = (mask.getExistingVolumes() != null) ? mask.getExistingVolumes().keySet() : Collections.emptySet();
builder.append(String.format("%nXM existing objects: %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())));
List<String> initiatorsToAddToExisting = new ArrayList<String>();
List<Initiator> initiatorsToAddToUserAddedAndInitiatorList = new ArrayList<Initiator>();
/**
* For the newly discovered initiators, if they are ViPR discovered ports and belong to same resource
* add them to user added and initiators list, otherwise add to existing list.
*/
for (String port : discoveredPorts) {
String normalizedPort = Initiator.normalizePort(port);
if (!mask.hasExistingInitiator(normalizedPort) && !mask.hasUserInitiator(normalizedPort)) {
Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), _dbClient);
// Don't add additional initiator to initiators list if it belongs to different host/cluster
if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(mask, existingInitiator)) {
_log.info("Initiator {}->{} belonging to same compute, adding to userAdded and initiator list.", normalizedPort, existingInitiator.getId());
initiatorsToAddToUserAddedAndInitiatorList.add(existingInitiator);
} else {
initiatorsToAddToExisting.add(normalizedPort);
}
}
}
/**
* Get the existing initiators from the mask and remove the non-discovered ports because
* they are not discovered and are stale.
*
* If the mask has existing initiators but if they are discovered and belongs to same compute resource, then the
* initiators has to get added to user Added and initiators list, and removed from existing list.
*/
List<String> initiatorsToRemoveFromExistingList = new ArrayList<String>();
if (mask.getExistingInitiators() != null && !mask.getExistingInitiators().isEmpty()) {
for (String existingInitiatorStr : mask.getExistingInitiators()) {
if (!discoveredPorts.contains(existingInitiatorStr)) {
initiatorsToRemoveFromExistingList.add(existingInitiatorStr);
} else {
Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(existingInitiatorStr), _dbClient);
if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(mask, existingInitiator)) {
_log.info("Initiator {}->{} belonging to same compute, removing from existing," + " and adding to userAdded and initiator list", existingInitiatorStr, existingInitiator.getId());
initiatorsToAddToUserAddedAndInitiatorList.add(existingInitiator);
initiatorsToRemoveFromExistingList.add(existingInitiatorStr);
}
}
}
}
/**
* Get all the initiators from the mask and remove all the ViPR discovered ports.
* The remaining list has to be removed from user Added and initiator list, because they are not available in ViPR
* but has to be moved to existing list.
*/
List<URI> initiatorsToRemoveFromUserAddedAndInitiatorList = new ArrayList<URI>();
if (mask.getInitiators() != null && !mask.getInitiators().isEmpty()) {
initiatorsToRemoveFromUserAddedAndInitiatorList.addAll(transform(mask.getInitiators(), CommonTransformerFunctions.FCTN_STRING_TO_URI));
for (String port : discoveredPorts) {
String normalizedPort = Initiator.normalizePort(port);
Initiator initiatorDiscoveredInViPR = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), _dbClient);
if (initiatorDiscoveredInViPR != null) {
initiatorsToRemoveFromUserAddedAndInitiatorList.remove(initiatorDiscoveredInViPR.getId());
} else if (!mask.hasExistingInitiator(normalizedPort)) {
_log.info("Initiator {} not found in database, removing from user Added and initiator list," + " and adding to existing list.", port);
initiatorsToAddToExisting.add(normalizedPort);
}
}
}
boolean removeInitiators = !initiatorsToRemoveFromExistingList.isEmpty() || !initiatorsToRemoveFromUserAddedAndInitiatorList.isEmpty();
boolean addInitiators = !initiatorsToAddToUserAddedAndInitiatorList.isEmpty() || !initiatorsToAddToExisting.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 the volume is in export mask's user added volumes and also in the existing volumes, remove from existing volumes
for (String wwn : discoveredVolumes.keySet()) {
if (mask.hasExistingVolume(wwn)) {
URIQueryResultList volumeList = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeWwnConstraint(wwn), volumeList);
if (volumeList.iterator().hasNext()) {
URI volumeURI = volumeList.iterator().next();
if (mask.hasUserCreatedVolume(volumeURI)) {
builder.append(String.format("\texisting volumes contain wwn %s, but it is also in the " + "export mask's user added volumes, so removing from existing volumes", wwn));
volumesToRemove.add(wwn);
}
}
}
}
if (mask.getExistingVolumes() != null && !mask.getExistingVolumes().isEmpty()) {
volumesToRemove.addAll(mask.getExistingVolumes().keySet());
volumesToRemove.removeAll(discoveredVolumes.keySet());
removeVolumes = !volumesToRemove.isEmpty();
}
// Update user added volume's HLU information in ExportMask and ExportGroup
ExportMaskUtils.updateHLUsInExportMask(mask, discoveredVolumes, _dbClient);
// Grab the storage ports that have been allocated for this
// existing mask and update them.
List<String> storagePorts = _helper.getStoragePortsFromLunMaskingInstance(client, instance);
List<String> storagePortURIs = ExportUtils.storagePortNamesToURIs(_dbClient, storagePorts);
// Check the storagePorts and update the lists as necessary
boolean addStoragePorts = false;
List<String> storagePortsToAdd = new ArrayList<>();
if (mask.getStoragePorts() == null) {
mask.setStoragePorts(new ArrayList<String>());
}
for (String portID : storagePortURIs) {
if (!mask.getStoragePorts().contains(portID)) {
storagePortsToAdd.add(portID);
addStoragePorts = true;
}
}
boolean removeStoragePorts = false;
List<String> storagePortsToRemove = new ArrayList<String>();
if (mask.getStoragePorts() != null && !mask.getStoragePorts().isEmpty()) {
storagePortsToRemove.addAll(mask.getStoragePorts());
storagePortsToRemove.removeAll(storagePortURIs);
removeStoragePorts = !storagePortsToRemove.isEmpty();
}
builder.append(String.format("XM refresh: %s existing initiators; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(initiatorsToAddToExisting), Joiner.on(',').join(initiatorsToRemoveFromExistingList)));
builder.append(String.format("XM refresh: %s user added and initiator list; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(initiatorsToAddToUserAddedAndInitiatorList), Joiner.on(',').join(initiatorsToRemoveFromUserAddedAndInitiatorList)));
builder.append(String.format("XM refresh: %s volumes; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(volumesToAdd.keySet()), Joiner.on(',').join(volumesToRemove)));
builder.append(String.format("XM refresh: %s ports; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(storagePortsToAdd), Joiner.on(',').join(storagePortsToRemove)));
// Any changes indicated, then update the mask and persist it
if (addInitiators || removeInitiators || addVolumes || removeVolumes || addStoragePorts || removeStoragePorts) {
mask.removeFromExistingInitiators(initiatorsToRemoveFromExistingList);
if (!initiatorsToRemoveFromUserAddedAndInitiatorList.isEmpty()) {
mask.removeInitiatorURIs(initiatorsToRemoveFromUserAddedAndInitiatorList);
mask.removeFromUserAddedInitiatorsByURI(initiatorsToRemoveFromUserAddedAndInitiatorList);
}
// https://coprhd.atlassian.net/browse/COP-17224 - For those cases where InitiatorGroups are shared
// by
// MaskingViews, if CoprHD processes one ExportMask by updating it with new initiators, then it
// could
// affect another ExportMasks. Consider that this refreshExportMask is against that other
// ExportMask.
// We shouldn't read the initiators that we find as 'existing' (that is created outside of CoprHD),
// instead we should consider them userAdded for this ExportMask, as well.
List<Initiator> userAddedInitiators = ExportMaskUtils.findIfInitiatorsAreUserAddedInAnotherMask(mask, initiatorsToAddToUserAddedAndInitiatorList, _dbClient);
mask.addToUserCreatedInitiators(userAddedInitiators);
builder.append(String.format("XM refresh: %s user added initiators; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(userAddedInitiators), Joiner.on(',').join(initiatorsToRemoveFromUserAddedAndInitiatorList)));
mask.addInitiators(initiatorsToAddToUserAddedAndInitiatorList);
mask.addToUserCreatedInitiators(initiatorsToAddToUserAddedAndInitiatorList);
mask.addToExistingInitiatorsIfAbsent(initiatorsToAddToExisting);
mask.removeFromExistingInitiators(initiatorsToRemoveFromExistingList);
mask.removeFromExistingVolumes(volumesToRemove);
mask.addToExistingVolumesIfAbsent(volumesToAdd);
mask.getStoragePorts().addAll(storagePortsToAdd);
mask.getStoragePorts().removeAll(storagePortsToRemove);
URI pgURI = mask.getPortGroup();
if (!NullColumnValueGetter.isNullURI(pgURI) && (!storagePortsToAdd.isEmpty() || !storagePortsToRemove.isEmpty())) {
StoragePortGroup portGroup = _dbClient.queryObject(StoragePortGroup.class, pgURI);
portGroup.getStoragePorts().addAll(storagePortsToAdd);
portGroup.getStoragePorts().removeAll(storagePortsToRemove);
_dbClient.updateObject(portGroup);
}
ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, mask);
builder.append("XM refresh: There are changes to mask, " + "updating it...\n");
_dbClient.updateObject(mask);
} else {
builder.append("XM refresh: There are no changes to the mask\n");
}
_networkDeviceController.refreshZoningMap(mask, transform(initiatorsToRemoveFromUserAddedAndInitiatorList, CommonTransformerFunctions.FCTN_URI_TO_STRING), 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);
}
} finally {
long totalTime = System.currentTimeMillis() - startTime;
_log.info(String.format("refreshExportMask took %f seconds", (double) totalTime / (double) 1000));
}
return mask;
}
use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class VmaxExportOperations method createInitiatorGroupWithInitiatorGroups.
private CIMObjectPath createInitiatorGroupWithInitiatorGroups(StorageSystem storage, ExportMask mask, String groupName, List<CIMObjectPath> initiatorGroupPaths, boolean consistentLUNs, TaskCompleter taskCompleter) throws Exception {
_log.debug("{} createInitiatorGroupWithInitiatorGroups START...", storage.getSerialNumber());
CIMObjectPath initiatorGroupPath = null;
CIMArgument[] inArgs;
CIMArgument[] outArgs;
boolean enableVSA = hasIGWithVSASet(storage, initiatorGroupPaths);
if (enableVSA) {
// If we are trying to create a cascaded IG with VSA enabled child IGs, we first
// have to create an empty parent IG and enable VSA on it. The SMI-S provider
// does not allow adding of VSA enabled IGs to a non-VSA enabled IG.
inArgs = _helper.getCreateEmptyIGWithInitiatorGroupsInputArguments(groupName);
} else {
inArgs = _helper.getCreateInitiatorGroupWithInitiatorGroupsInputArguments(groupName, initiatorGroupPaths, consistentLUNs);
}
outArgs = new CIMArgument[5];
try {
CIMObjectPath cigPath = _helper.getInitiatorGroupPath(storage, groupName);
CIMInstance cigInstance = findCascadingInitiatorGroup(storage, mask, cigPath, initiatorGroupPaths);
if (cigInstance == null) {
_helper.invokeMethod(storage, _cimPath.getControllerConfigSvcPath(storage), "CreateGroup", inArgs, outArgs);
initiatorGroupPath = _cimPath.getCimObjectPathFromOutputArgs(outArgs, "MaskingGroup");
_log.info("createInitiatorGroupWithInitiatorGroups - Created new CIG {}", initiatorGroupPath);
ExportOperationContext.insertContextOperation(taskCompleter, VmaxExportOperationContext.OPERATION_CREATE_CASCADED_INITIATOR_GROUP, groupName, initiatorGroupPath);
} else {
initiatorGroupPath = cigInstance.getObjectPath();
_log.info("createInitiatorGroupWithInitiatorGroups - Reusing CIG {}", initiatorGroupPath);
// Create a list of child initiator instance Ids,
// so that we can check if the IG already exists in the cascaded
// initiator group.
Set<String> childIGs = new HashSet<String>();
CloseableIterator<CIMObjectPath> childIGIterator = _helper.getAssociatorNames(storage, initiatorGroupPath, null, SmisConstants.SE_INITIATOR_MASKING_GROUP, null, null);
if (childIGIterator != null) {
while (childIGIterator.hasNext()) {
CIMObjectPath path = childIGIterator.next();
if (path != null) {
String instanceId = path.getKey(SmisConstants.CP_INSTANCE_ID).getValue().toString();
childIGs.add(instanceId);
}
}
childIGIterator.close();
}
for (CIMObjectPath childIGPath : initiatorGroupPaths) {
String instanceId = childIGPath.getKey(SmisConstants.CP_INSTANCE_ID).getValue().toString();
if (!childIGs.contains(instanceId)) {
addInitiatorGroupToInitiatorGroup(storage, childIGPath, initiatorGroupPath, taskCompleter);
} else {
_log.info("createInitiatorGroupWithInitiatorGroups - ChildIG {}" + " is already in {}", childIGPath, initiatorGroupPath);
}
}
return initiatorGroupPath;
}
if (enableVSA) {
setVSAFlagForIG(storage, initiatorGroupPath, true);
// Now go ahead and add the members..
for (CIMObjectPath childIGPath : initiatorGroupPaths) {
addInitiatorGroupToInitiatorGroup(storage, childIGPath, initiatorGroupPath, taskCompleter);
}
}
} catch (WBEMException we) {
_log.info("{} Problem when trying to create initiator group ... going to look up initiator group.", storage.getSystemType(), we);
initiatorGroupPath = handleCreateMaskingGroupException(storage, groupName, inArgs, SmisCommandHelper.MASKING_GROUP_TYPE.SE_InitiatorMaskingGroup);
if (initiatorGroupPath == null) {
_log.info("{} Problem looking up initiator group.", storage.getSerialNumber(), we);
throw we;
} else {
_log.info("{} Found initiator group with expected members.", storage.getSerialNumber());
}
}
return initiatorGroupPath;
}
use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class SmisCommandHelper method setRecoverPointTagInternal.
/**
* Method will add or remove the EMCRecoverPointEnabled flag from the device masking group for
* VMAX.
*
* @param deviceGroupPath
* [in] - CIMObjectPath referencing the volume
*/
private boolean setRecoverPointTagInternal(StorageSystem storage, List<CIMObjectPath> volumeMemberList, boolean tag) throws Exception {
boolean tagSet = false;
try {
_log.info("Attempting to {} RecoverPoint tag on Volume: {}", tag ? "enable" : "disable", Joiner.on(",").join(volumeMemberList));
CimConnection connection = _cimConnection.getConnection(storage);
WBEMClient client = connection.getCimClient();
if (storage.getUsingSmis80()) {
CIMObjectPath configSvcPath = _cimPath.getConfigSvcPath(storage);
CIMArgument[] inArgs = getRecoverPointInputArguments(storage, volumeMemberList, tag);
CIMArgument[] outArgs = new CIMArgument[5];
SmisJob job = null;
invokeMethodSynchronously(storage, configSvcPath, EMC_SETUNSET_RECOVERPOINT, inArgs, outArgs, job);
} else {
for (CIMObjectPath volumeMember : volumeMemberList) {
CIMInstance toUpdate = new CIMInstance(volumeMember, new CIMProperty[] { _cimProperty.bool(EMC_RECOVERPOINT_ENABLED, tag) });
_log.debug("Params: " + toUpdate.toString());
client.modifyInstance(toUpdate, CP_EMC_RECOVERPOINT_ENABLED);
}
}
_log.info(String.format("RecoverPoint tag has been successfully %s Volume", tag ? "applied to" : "removed from"));
tagSet = true;
} catch (WBEMException e) {
if (e.getMessage().contains("is already set to the requested state")) {
_log.info("Found the volume was already in the proper RecoverPoint tag state");
tagSet = true;
} else {
_log.error(String.format("Encountered an error while trying to %s the RecoverPoint tag", tag ? "enable" : "disable"), e);
}
}
return tagSet;
}
Aggregations