use of javax.cim.CIMProperty in project coprhd-controller by CoprHD.
the class CimQueuedIndicationTest method testCimQueuedIndication.
/**
* Tests the CimQueuedIndication class.
*/
@SuppressWarnings("rawtypes")
@Test
public void testCimQueuedIndication() {
CIMObjectPath objPath = CimObjectPathCreator.createInstance(OBJ_PATH_CLASS_NAME);
CIMProperty[] properties = new CIMProperty[0];
_instance = new CIMInstance(objPath, properties);
CimQueuedIndication indication = new CimQueuedIndication(INDICATION_URL, _instance);
Assert.assertEquals(indication.getURL(), INDICATION_URL);
Assert.assertEquals(indication.getIndication(), _instance);
}
use of javax.cim.CIMProperty in project coprhd-controller by CoprHD.
the class EcomIndicationProcessorTest method createAlertIndication.
/**
* Creates a CIMInstance representing an alert indication.
*
* @return A CIMInstance representing an alert indication.
*/
@SuppressWarnings("rawtypes")
private CIMInstance createAlertIndication() {
CIMObjectPath objPath = CimObjectPathCreator.createInstance(ALERT_INDICATION_CLASS_NAME);
CIMProperty[] properties = new CIMProperty[] { new CIMProperty<String>(ALERTING_MANGED_ELEMENT_KEY, CIMDataType.STRING_T, ALERTING_MANGED_ELEMENT_VALUE) };
CIMInstance indication = new CIMInstance(objPath, properties);
return indication;
}
use of javax.cim.CIMProperty in project coprhd-controller by CoprHD.
the class VnxExportOperations method updateStorageGroupPolicyAndLimits.
/**
* Updates Auto-tiering policy for the given volumes.
*
* @param storage
* the storage
* @param exportMask
* the export mask
* @param volumeURIs
* the volume uris
* @param newVirtualPool
* the new virtual pool where policy name can be obtained
* @param rollback
* boolean to know if it is called as a roll back step from workflow.
* @param taskCompleter
* @throws Exception
* the exception
*/
@Override
public void updateStorageGroupPolicyAndLimits(StorageSystem storage, ExportMask exportMask, List<URI> volumeURIs, VirtualPool newVirtualPool, boolean rollback, TaskCompleter taskCompleter) throws Exception {
String message = rollback ? ("updateAutoTieringPolicy" + "(rollback)") : ("updateAutoTieringPolicy");
_log.info("{} {} START...", storage.getSerialNumber(), message);
_log.info("{} : volumeURIs: {}", message, volumeURIs);
try {
String newPolicyName = ControllerUtils.getFastPolicyNameFromVirtualPool(_dbClient, storage, newVirtualPool);
_log.info("{} : AutoTieringPolicy: {}", message, newPolicyName);
List<Volume> volumes = _dbClient.queryObject(Volume.class, volumeURIs);
/**
* get tier methodology for policy name
* volume has tier methodology as '4' when no policy set (START_HIGH_THEN_AUTO_TIER).
*
* For VNX, Policy is set on Volumes during creation.
*/
int storageTierMethodologyId = DEFAULT_STORAGE_TIER_METHODOLOGY;
if (!Constants.NONE.equalsIgnoreCase(newPolicyName)) {
storageTierMethodologyId = getStorageTierMethodologyFromPolicyName(newPolicyName);
}
// Build list of native ids
Set<String> nativeIds = new HashSet<String>();
for (Volume volume : volumes) {
nativeIds.add(volume.getNativeId());
}
_log.info("Native Ids of Volumes: {}", nativeIds);
CimConnection connection = _helper.getConnection(storage);
WBEMClient client = connection.getCimClient();
// CIMObjectPath replicationSvc = _cimPath.getControllerReplicationSvcPath(storage);
String[] memberNames = nativeIds.toArray(new String[nativeIds.size()]);
CIMObjectPath[] volumePaths = _cimPath.getVolumePaths(storage, memberNames);
CIMProperty[] inArgs = _helper.getModifyStorageTierMethodologyIdInputArguments(storageTierMethodologyId);
for (CIMObjectPath volumeObject : volumePaths) {
if (_helper.getVolumeStorageTierMethodologyId(storage, volumeObject) == storageTierMethodologyId) {
_log.info("Current and new Storage Tier Methodology Ids are same '{}'." + " No need to update it on Volume Object Path {}.", storageTierMethodologyId, volumeObject);
} else {
CIMInstance modifiedSettingInstance = new CIMInstance(volumeObject, inArgs);
_log.info("Updating Storage Tier Methodology ({}) on Volume Object Path {}.", storageTierMethodologyId, volumeObject);
client.modifyInstance(modifiedSettingInstance, SmisConstants.PS_EMC_STORAGE_TIER_METHODOLOGY);
}
}
taskCompleter.ready(_dbClient);
} catch (Exception e) {
String errMsg = String.format("An error occurred while updating Auto-tiering policy for Volumes %s", volumeURIs);
_log.error(errMsg, e);
ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(errMsg, e);
taskCompleter.error(_dbClient, serviceError);
}
_log.info("{} {} END...", storage.getSerialNumber(), message);
}
use of javax.cim.CIMProperty in project coprhd-controller by CoprHD.
the class VmaxExportOperations method findExportMasks.
/**
* This call can be used to look up the passed in initiator/port names and find (if
* any) to which export masks they belong on the 'storage' array.
*
* @param storage
* [in] - StorageSystem object representing the array
* @param initiatorNames
* [in] - Port identifiers (WWPN or iSCSI name)
* @param mustHaveAllInitiators
* [in] - Indicates if true, *all* the passed in initiators
* have to be in the existing matching mask. If false,
* a mask with *any* of the specified initiators will be
* considered a hit.
* @return Map of port name to Set of ExportMask URIs
*/
@Override
public Map<String, Set<URI>> findExportMasks(StorageSystem storage, List<String> initiatorNames, boolean mustHaveAllInitiators) throws DeviceControllerException {
long startTime = System.currentTimeMillis();
Map<String, Set<URI>> matchingMasks = new HashMap<String, Set<URI>>();
Map<URI, ExportMask> maskMap = new HashMap<>();
CloseableIterator<CIMInstance> maskInstanceItr = null;
try {
// Get a mapping of the initiator port names to their CIMObjectPaths on the provider
WBEMClient client = _helper.getConnection(storage).getCimClient();
HashMap<String, CIMObjectPath> initiatorPathsMap = _cimPath.getInitiatorToInitiatorPath(storage, initiatorNames);
// 'maskNames' will be used to do one-time operations against the ExportMask
List<String> maskNames = new ArrayList<String>();
Set<String> maskNamesFromArray = new HashSet<>();
// Iterate through each port name ...
for (String initiatorName : initiatorPathsMap.keySet()) {
CIMObjectPath initiatorPath = initiatorPathsMap.get(initiatorName);
// Find out if there is a MaskingView associated with the initiator ...
maskInstanceItr = _helper.getAssociatorInstances(storage, initiatorPath, null, SmisConstants.SYMM_LUN_MASKING_VIEW, null, null, SmisConstants.PS_LUN_MASKING_CNTRL_NAME_AND_ROLE);
while (maskInstanceItr.hasNext()) {
// Found a MaskingView ...
CIMInstance instance = maskInstanceItr.next();
String systemName = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_SYSTEM_NAME);
if (!systemName.contains(storage.getSerialNumber())) {
// SMISProvider pointed to by 'storage' system.
continue;
}
String name = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_ELEMENT_NAME);
CIMProperty<String> deviceIdProperty = (CIMProperty<String>) instance.getObjectPath().getKey(SmisConstants.CP_DEVICE_ID);
// Look up ExportMask by deviceId/name and storage URI
ExportMask exportMask = ExportMaskUtils.getExportMaskByName(_dbClient, storage.getId(), name);
boolean foundMaskInDb = (exportMask != null);
maskNamesFromArray.add(name);
// then create a new one
if (!foundMaskInDb) {
exportMask = new ExportMask();
exportMask.setMaskName(name);
exportMask.setNativeId(deviceIdProperty.getValue());
exportMask.setStorageDevice(storage.getId());
exportMask.setId(URIUtil.createId(ExportMask.class));
exportMask.setCreatedBySystem(false);
}
// Do some one-time updates for the ExportMask
if (!maskNames.contains(name)) {
// https://coprhd.atlassian.net/browse/COP-20149
// Find all the initiators associated with the MaskingView and add them
List<String> initiatorPorts = _helper.getInitiatorsFromLunMaskingInstance(client, instance);
if (!CollectionUtils.isEmpty(exportMask.getExistingInitiators())) {
exportMask.getExistingInitiators().clear();
}
exportMask.addToExistingInitiatorsIfAbsent(initiatorPorts);
// Update the initiator list to include existing initiators if we know about them (and remove from existing)
for (String portName : initiatorPorts) {
Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(portName), _dbClient);
if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(exportMask, existingInitiator)) {
exportMask.addInitiator(existingInitiator);
exportMask.addToUserCreatedInitiators(existingInitiator);
exportMask.removeFromExistingInitiators(existingInitiator);
}
}
// Update the tracking containers
Map<String, Integer> volumeWWNs = _helper.getVolumesFromLunMaskingInstance(client, instance);
if (!CollectionUtils.isEmpty(exportMask.getExistingVolumes())) {
exportMask.getExistingVolumes().clear();
}
exportMask.addToExistingVolumesIfAbsent(volumeWWNs);
// Update the volumes list to include existing volumes if we know about them (and remove from existing)
if (volumeWWNs != null) {
for (Entry<String, Integer> entry : volumeWWNs.entrySet()) {
String wwn = entry.getKey();
URIQueryResultList results = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeWwnConstraint(wwn.toUpperCase()), results);
if (results != null) {
Iterator<URI> resultsIter = results.iterator();
if (resultsIter.hasNext()) {
Volume volume = _dbClient.queryObject(Volume.class, resultsIter.next());
if (volume != null) {
Integer hlu = volumeWWNs.get(wwn);
if (hlu == null) {
_log.warn(String.format("The HLU for %s could not be found from the provider. Setting this to -1 (Unknown).", wwn));
hlu = -1;
}
exportMask.addVolume(volume.getId(), hlu);
exportMask.removeFromExistingVolumes(volume);
}
}
}
}
}
// Grab the storage ports that have been allocated for this
// existing mask and add them.
List<String> storagePorts = _helper.getStoragePortsFromLunMaskingInstance(client, instance);
List<String> storagePortURIs = ExportUtils.storagePortNamesToURIs(_dbClient, storagePorts);
exportMask.setStoragePorts(storagePortURIs);
// Get port group for the new exportMask
if (!foundMaskInDb) {
StoragePortGroup portGroup = null;
_log.info("Setting port group for the export mask");
String portGroupName = _helper.getPortGroupForGivenMaskingView(name, storage);
String guid = String.format("%s+%s", storage.getNativeGuid(), portGroupName);
URIQueryResultList result = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getPortGroupNativeGuidConstraint(guid), result);
Iterator<URI> it = result.iterator();
if (it.hasNext()) {
URI pgURI = it.next();
portGroup = _dbClient.queryObject(StoragePortGroup.class, pgURI);
} else {
portGroup = new StoragePortGroup();
portGroup.setId(URIUtil.createId(StoragePortGroup.class));
portGroup.setLabel(portGroupName);
portGroup.setNativeGuid(guid);
portGroup.setStorageDevice(storage.getId());
portGroup.setInactive(false);
portGroup.setStoragePorts(new StringSet(storagePortURIs));
_dbClient.createObject(portGroup);
}
exportMask.setPortGroup(portGroup.getId());
if (isUsePortGroupEnabled()) {
portGroup.setRegistrationStatus(RegistrationStatus.REGISTERED.name());
portGroup.setMutable(false);
} else {
portGroup.setRegistrationStatus(RegistrationStatus.UNREGISTERED.name());
portGroup.setMutable(true);
}
_dbClient.updateObject(portGroup);
}
// Add the mask name to the list for which volumes are already updated
maskNames.add(name);
}
// Update the maskMap with the latest in-memory exportMask reference.
maskMap.put(exportMask.getId(), exportMask);
if (foundMaskInDb) {
ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, exportMask);
_dbClient.updateObject(exportMask);
} else {
_dbClient.createObject(exportMask);
}
// Update our results map
Set<URI> maskURIs = matchingMasks.get(initiatorName);
if (maskURIs == null) {
maskURIs = new HashSet<>();
matchingMasks.put(initiatorName, maskURIs);
}
maskURIs.add(exportMask.getId());
}
}
// COP-19514 - After we've found all ExportMasks that are related to a given set of initiators, we
// need to eliminate any that do not have all the initiators if mustHaveAllInitiators=true. The
// masksNotContainingAllInitiators set is used to hold references to those ExportMasks that do not
// match the criteria of having all the initiators.
Set<URI> masksNotContainingAllInitiators = new HashSet<>();
if (mustHaveAllInitiators) {
// Check if each ExportMask has all the ports. If not, add it to masksNotContainingAllInitiators
for (URI exportMaskURI : maskMap.keySet()) {
ExportMask mask = maskMap.get(exportMaskURI);
if (!matchesSearchCriteria(mask, initiatorNames, true)) {
masksNotContainingAllInitiators.add(exportMaskURI);
}
}
}
// Skip the masking views whose IGs can be reused to create a new Masking view instead.
Set<URI> masksWithReusableIGs = getMasksWhoseIGsCanBeReused(storage, maskMap, initiatorNames);
// Adjust the matchingMap if there are any masksNotContainingAllInitiators / singleIGContainedMasks
if (!masksNotContainingAllInitiators.isEmpty() || !masksWithReusableIGs.isEmpty()) {
_log.info("ExportMasks not containing all initiators requested: {}", masksNotContainingAllInitiators);
_log.info("ExportMasks whose IGs can be reused to create new masking view: {}", masksWithReusableIGs);
// Remove references to the ExportMask URIs from the matchingMasks map entries
Iterator<Entry<String, Set<URI>>> matchingMapEntryIterator = matchingMasks.entrySet().iterator();
while (matchingMapEntryIterator.hasNext()) {
Entry<String, Set<URI>> matchingMapEntry = matchingMapEntryIterator.next();
Set<URI> maskURIs = matchingMapEntry.getValue();
maskURIs.removeAll(masksNotContainingAllInitiators);
maskURIs.removeAll(masksWithReusableIGs);
// If all the ExportMask keys are cleared out, then we need to remove the whole entry
if (maskURIs.isEmpty()) {
matchingMapEntryIterator.remove();
}
}
}
StringBuilder builder = new StringBuilder();
for (URI exportMaskURI : maskMap.keySet()) {
ExportMask exportMask = maskMap.get(exportMaskURI);
String qualifier = (masksNotContainingAllInitiators.contains(exportMaskURI)) ? ", but not containing all initiators we're looking for" : (masksWithReusableIGs.contains(exportMaskURI) ? ", but it's IGs can be reused to create new masking view" : SmisConstants.EMPTY_STRING);
builder.append(String.format("\nXM:%s is matching%s: ", exportMask.getMaskName(), qualifier)).append('\n').append(exportMask.toString());
}
/**
* Needs to clean up stale EM from ViPR DB.
*/
ExportUtils.cleanStaleExportMasks(storage, maskNamesFromArray, initiatorNames, _dbClient);
_log.info(builder.toString());
} catch (Exception e) {
String msg = "Error when attempting to query LUN masking information: " + e.getMessage();
_log.error(MessageFormat.format("Encountered an SMIS error when attempting to query existing exports: {0}", msg), e);
throw SmisException.exceptions.queryExistingMasksFailure(msg, e);
} finally {
if (maskInstanceItr != null) {
maskInstanceItr.close();
}
long totalTime = System.currentTimeMillis() - startTime;
_log.info(String.format("findExportMasks took %f seconds", (double) totalTime / (double) 1000));
}
return matchingMasks;
}
use of javax.cim.CIMProperty in project coprhd-controller by CoprHD.
the class SmisCreateMetaVolumeHeadJob method updateStatus.
/**
* Called to update the job status when the create meta volume head job completes.
* Sets native device ID to meta head volume.
*
* @param jobContext The job context.
*/
public void updateStatus(JobContext jobContext) throws Exception {
CloseableIterator<CIMObjectPath> iterator = null;
DbClient dbClient = jobContext.getDbClient();
JobStatus jobStatus = getJobStatus();
try {
if (jobStatus == Job.JobStatus.IN_PROGRESS) {
return;
}
String opId = getTaskCompleter().getOpId();
StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating post processing status of job %s to %s, task: %s", this.getJobName(), jobStatus.name(), opId));
CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
iterator = client.associatorNames(getCimJob(), null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
Calendar now = Calendar.getInstance();
Volume metaHead = dbClient.queryObject(Volume.class, _metaHeadId);
if (jobStatus == Job.JobStatus.SUCCESS) {
CIMObjectPath volumePath = iterator.next();
CIMProperty<String> deviceID = (CIMProperty<String>) volumePath.getKey(SmisConstants.CP_DEVICE_ID);
String headNativeID = deviceID.getValue();
metaHead.setCreationTime(now);
metaHead.setNativeId(headNativeID);
metaHead.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(dbClient, metaHead));
dbClient.persistObject(metaHead);
logMsgBuilder.append("\n");
logMsgBuilder.append(String.format("%n Task %s created meta head volume: %s with device ID: %s", opId, metaHead.getLabel(), headNativeID));
_log.info(logMsgBuilder.toString());
} else if (jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
logMsgBuilder.append("\n");
logMsgBuilder.append(String.format("Task %s failed to create meta head volume: %s caused by: %s", opId, metaHead.getLabel(), _errorDescription));
Volume volume = dbClient.queryObject(Volume.class, _metaHeadId);
volume.setInactive(true);
dbClient.persistObject(volume);
_log.error(logMsgBuilder.toString());
setFailedStatus(logMsgBuilder.toString());
}
} catch (Exception e) {
_log.error("Caught an exception while trying to process status for " + this.getJobName(), e);
setPostProcessingErrorStatus("Encountered an internal error during " + this.getJobName() + " job status processing : " + e.getMessage());
} finally {
if (iterator != null) {
iterator.close();
}
_metaVolumeTaskCompleter.setLastStepStatus(jobStatus);
if (isJobInTerminalFailedState()) {
super.updateStatus(jobContext);
}
}
}
Aggregations