use of com.emc.storageos.volumecontroller.impl.VolumeURIHLU in project coprhd-controller by CoprHD.
the class VmaxExportOperations method getVolumesThatAreNotAlreadyInSG.
private VolumeURIHLU[] getVolumesThatAreNotAlreadyInSG(StorageSystem storage, CIMObjectPath groupPath, String groupName, VolumeURIHLU[] volumeURIHLUs) throws WBEMException {
VolumeURIHLU[] result = null;
// Build a mapping of BlockObject.deviceID to VolumeURIHLU object
HashMap<String, VolumeURIHLU> deviceIdMap = new HashMap<String, VolumeURIHLU>();
for (VolumeURIHLU vuh : volumeURIHLUs) {
BlockObject bo = BlockObject.fetch(_dbClient, vuh.getVolumeURI());
deviceIdMap.put(bo.getNativeId(), vuh);
}
// Query the provider for the CIM_Volume instances associated with the
// StorageGroup. Remove any deviceIdMap entry that shows up
CloseableIterator<CIMInstance> volumeInstances = _helper.getAssociatorInstances(storage, groupPath, null, SmisConstants.CIM_STORAGE_VOLUME, null, null, SmisConstants.PS_DEVICE_ID);
while (volumeInstances.hasNext()) {
CIMInstance volInstance = volumeInstances.next();
String deviceId = CIMPropertyFactory.getPropertyValue(volInstance, SmisConstants.CP_DEVICE_ID);
deviceIdMap.remove(deviceId);
}
// devices that need to be added to the StorageGroup.
if (!deviceIdMap.isEmpty()) {
result = new VolumeURIHLU[deviceIdMap.size()];
int index = 0;
for (Map.Entry<String, VolumeURIHLU> entry : deviceIdMap.entrySet()) {
result[index++] = entry.getValue();
}
_log.info(String.format("Requested %d volumes to be added to %s. After " + "processing %d volumes need to be added to the StorageGroup", volumeURIHLUs.length, groupName, result.length));
} else {
_log.info("StorageGroup {} has the requested volumes " + "to add in it already.", groupName);
}
return result;
}
use of com.emc.storageos.volumecontroller.impl.VolumeURIHLU in project coprhd-controller by CoprHD.
the class ExternalDeviceExportOperations method createExportMask.
@Override
public void createExportMask(StorageSystem storage, URI exportMaskUri, VolumeURIHLU[] volumeURIHLUs, List<URI> targetURIList, List<com.emc.storageos.db.client.model.Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
log.info("{} createExportMask START...", storage.getSerialNumber());
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));
BlockStorageDriver driver = externalDevice.getDriver(storage.getSystemType());
ExportMask exportMask = (ExportMask) dbClient.queryObject(exportMaskUri);
// Get export group uri from task completer
URI exportGroupUri = taskCompleter.getId();
ExportGroup exportGroup = (ExportGroup) dbClient.queryObject(exportGroupUri);
Set<URI> volumeUris = new HashSet<>();
for (VolumeURIHLU volumeURIHLU : volumeURIHLUs) {
URI volumeURI = volumeURIHLU.getVolumeURI();
volumeUris.add(volumeURI);
}
// Prepare volumes
List<StorageVolume> driverVolumes = new ArrayList<>();
Map<String, String> driverVolumeToHLUMap = new HashMap<>();
Map<String, URI> volumeNativeIdToUriMap = new HashMap<>();
prepareVolumes(storage, volumeURIHLUs, driverVolumes, driverVolumeToHLUMap, volumeNativeIdToUriMap);
// Prepare initiators
List<Initiator> driverInitiators = new ArrayList<>();
prepareInitiators(initiatorList, exportGroup.forCluster(), driverInitiators);
// Prepare target storage ports
List<StoragePort> recommendedPorts = new ArrayList<>();
List<StoragePort> availablePorts = new ArrayList<>();
List<StoragePort> selectedPorts = new ArrayList<>();
// Prepare ports for driver call. Populate lists of recommended and available ports.
Map<String, com.emc.storageos.db.client.model.StoragePort> nativeIdToAvailablePortMap = new HashMap<>();
preparePorts(storage, exportMaskUri, targetURIList, recommendedPorts, availablePorts, nativeIdToAvailablePortMap);
ExportPathParams pathParams = blockScheduler.calculateExportPathParamForVolumes(volumeUris, exportGroup.getNumPaths(), storage.getId(), exportGroupUri);
StorageCapabilities capabilities = new StorageCapabilities();
// Prepare num paths to send to driver
prepareCapabilities(pathParams, capabilities);
MutableBoolean usedRecommendedPorts = new MutableBoolean(true);
// Ready to call driver
DriverTask task = driver.exportVolumesToInitiators(driverInitiators, driverVolumes, driverVolumeToHLUMap, recommendedPorts, availablePorts, capabilities, usedRecommendedPorts, selectedPorts);
// todo: need to implement support for async case.
if (task.getStatus() == DriverTask.TaskStatus.READY) {
// If driver used recommended ports, we are done.
// Otherwise, if driver did not use recommended ports, we have to get ports selected by driver
// and use them in export mask and zones.
// We will verify driver selected ports against available ports list.
String msg = String.format("createExportMask -- Created export: %s . Used recommended ports: %s .", task.getMessage(), usedRecommendedPorts);
log.info(msg);
log.info("Recommended ports: {}", recommendedPorts);
log.info("Available ports: {}", availablePorts);
log.info("Selected ports: {}", selectedPorts);
if (usedRecommendedPorts.isFalse()) {
// process driver selected ports
if (validateSelectedPorts(availablePorts, selectedPorts, pathParams.getMinPaths())) {
List<com.emc.storageos.db.client.model.StoragePort> selectedPortsForMask = new ArrayList<>();
for (StoragePort driverPort : selectedPorts) {
com.emc.storageos.db.client.model.StoragePort port = nativeIdToAvailablePortMap.get(driverPort.getNativeId());
selectedPortsForMask.add(port);
}
updateStoragePortsInExportMask(exportMask, exportGroup, selectedPortsForMask);
// Update volumes Lun Ids in export mask based on driver selection
for (String volumeNativeId : driverVolumeToHLUMap.keySet()) {
String targetLunId = driverVolumeToHLUMap.get(volumeNativeId);
URI volumeUri = volumeNativeIdToUriMap.get(volumeNativeId);
exportMask.getVolumes().put(volumeUri.toString(), targetLunId);
}
dbClient.updateObject(exportMask);
taskCompleter.ready(dbClient);
} else {
// selected ports are not valid. failure
String errorMsg = "createExportMask -- Ports selected by driver failed validation.";
log.error("createExportMask -- Ports selected by driver failed validation.");
ServiceError serviceError = ExternalDeviceException.errors.createExportMaskFailed("createExportMask", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} else {
// Update volumes Lun Ids in export mask based on driver selection
for (String volumeNativeId : driverVolumeToHLUMap.keySet()) {
String targetLunId = driverVolumeToHLUMap.get(volumeNativeId);
URI volumeUri = volumeNativeIdToUriMap.get(volumeNativeId);
exportMask.getVolumes().put(volumeUri.toString(), targetLunId);
}
dbClient.updateObject(exportMask);
taskCompleter.ready(dbClient);
}
} else {
String errorMsg = String.format("createExportMask -- Failed to create export: %s .", task.getMessage());
log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.createExportMaskFailed("createExportMask", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} catch (Exception ex) {
log.error("Problem in createExportMask: ", ex);
log.error("createExportMask -- Failed to create export mask. ", ex);
ServiceError serviceError = ExternalDeviceException.errors.createExportMaskFailed("createExportMask", ex.getMessage());
taskCompleter.error(dbClient, serviceError);
}
log.info("{} createExportMask END...", storage.getSerialNumber());
}
use of com.emc.storageos.volumecontroller.impl.VolumeURIHLU in project coprhd-controller by CoprHD.
the class ExternalDeviceExportOperations method addVolumes.
@Override
public void addVolumes(StorageSystem storage, URI exportMaskUri, VolumeURIHLU[] volumeURIHLUs, List<com.emc.storageos.db.client.model.Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
log.info("{} addVolumes START...", storage.getSerialNumber());
try {
log.info("addVolumes: Export mask id: {}", exportMaskUri);
log.info("addVolumes: New volumes to add: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
if (initiatorList != null) {
log.info("addVolumes: initiators: {}", Joiner.on(',').join(initiatorList));
}
BlockStorageDriver driver = externalDevice.getDriver(storage.getSystemType());
ExportMask exportMask = (ExportMask) dbClient.queryObject(exportMaskUri);
StringSet maskInitiators = exportMask.getInitiators();
List<String> maskInitiatorList = new ArrayList<>();
for (String initiatorUri : maskInitiators) {
maskInitiatorList.add(initiatorUri);
}
log.info("Export mask existing initiators: {} ", Joiner.on(',').join(maskInitiatorList));
StringSet storagePorts = exportMask.getStoragePorts();
List<URI> portList = new ArrayList<>();
for (String portUri : storagePorts) {
portList.add(URI.create(portUri));
}
log.info("Export mask existing storage ports: {} ", Joiner.on(',').join(portList));
// Get export group uri from task completer
URI exportGroupUri = taskCompleter.getId();
ExportGroup exportGroup = (ExportGroup) dbClient.queryObject(exportGroupUri);
Set<URI> volumeUris = new HashSet<>();
for (VolumeURIHLU volumeURIHLU : volumeURIHLUs) {
URI volumeURI = volumeURIHLU.getVolumeURI();
volumeUris.add(volumeURI);
}
// Prepare volumes. We send to driver only new volumes for the export mask.
List<StorageVolume> driverVolumes = new ArrayList<>();
Map<String, String> driverVolumeToHLUMap = new HashMap<>();
Map<String, URI> volumeNativeIdToUriMap = new HashMap<>();
prepareVolumes(storage, volumeURIHLUs, driverVolumes, driverVolumeToHLUMap, volumeNativeIdToUriMap);
// Prepare initiators
Set<com.emc.storageos.db.client.model.Initiator> initiators = ExportMaskUtils.getInitiatorsForExportMask(dbClient, exportMask, null);
List<Initiator> driverInitiators = new ArrayList<>();
prepareInitiators(initiators, exportGroup.forCluster(), driverInitiators);
// Prepare target storage ports
List<StoragePort> recommendedPorts = new ArrayList<>();
List<StoragePort> availablePorts = new ArrayList<>();
List<StoragePort> selectedPorts = new ArrayList<>();
// Prepare ports for driver call. Populate lists of recommended and available ports.
Map<String, com.emc.storageos.db.client.model.StoragePort> nativeIdToAvailablePortMap = new HashMap<>();
// We use existing ports in the mask as recommended ports.
preparePorts(storage, exportMaskUri, portList, recommendedPorts, availablePorts, nativeIdToAvailablePortMap);
log.info("varray ports: {}", nativeIdToAvailablePortMap);
// For add volumes to existing export mask, we do not allow storage port change in the mask.
// Only ports in the mask are available for driver call.
availablePorts = recommendedPorts;
ExportPathParams pathParams = blockScheduler.calculateExportPathParamForVolumes(volumeUris, exportGroup.getNumPaths(), storage.getId(), exportGroupUri);
StorageCapabilities capabilities = new StorageCapabilities();
// Prepare num paths to send to driver
prepareCapabilities(pathParams, capabilities);
MutableBoolean usedRecommendedPorts = new MutableBoolean(true);
// Ready to call driver
DriverTask task = driver.exportVolumesToInitiators(driverInitiators, driverVolumes, driverVolumeToHLUMap, recommendedPorts, availablePorts, capabilities, usedRecommendedPorts, selectedPorts);
// todo: need to implement support for async case.
if (task.getStatus() == DriverTask.TaskStatus.READY) {
String msg = String.format("Created export for volumes: %s . Used recommended ports: %s .", task.getMessage(), usedRecommendedPorts);
log.info(msg);
log.info("Driver selected storage ports: {} ", Joiner.on(',').join(selectedPorts));
// auto san zoning is enabled, we will fail the request.
if (usedRecommendedPorts.isFalse() && !selectedPorts.containsAll(recommendedPorts)) {
// for auto san zoning enabled we can not support case when selected ports do not include ports which are already in the mask
VirtualArray varray = dbClient.queryObject(VirtualArray.class, exportGroup.getVirtualArray());
log.info("AutoSanZoning for varray {} is {} ", varray.getLabel(), varray.getAutoSanZoning());
if (varray.getAutoSanZoning()) {
String errorMsg = String.format("AutoSanZoning is enabled and driver selected ports do not contain ports from the export mask: %s .", task.getMessage());
log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.addVolumesToExportMaskFailed("addVolumes", errorMsg);
taskCompleter.error(dbClient, serviceError);
} else {
// auto san zoning is disabled --- add new selected ports to the mask
// we do not care about zoning map in this case
List<com.emc.storageos.db.client.model.StoragePort> selectedPortsForMask = new ArrayList<>();
for (StoragePort driverPort : selectedPorts) {
log.info("Driver selected port: {}", driverPort);
com.emc.storageos.db.client.model.StoragePort port = nativeIdToAvailablePortMap.get(driverPort.getNativeId());
if (port != null) {
// add all ports, StringSet in the mask will ignore duplicates
log.info("System port: {}", port);
selectedPortsForMask.add(port);
}
}
for (com.emc.storageos.db.client.model.StoragePort port : selectedPortsForMask) {
exportMask.addTarget(port.getId());
}
dbClient.updateObject(exportMask);
taskCompleter.ready(dbClient);
}
} else {
// Update volumes Lun Ids in export mask based on driver selection
for (String volumeNativeId : driverVolumeToHLUMap.keySet()) {
String targetLunId = driverVolumeToHLUMap.get(volumeNativeId);
URI volumeUri = volumeNativeIdToUriMap.get(volumeNativeId);
exportMask.getVolumes().put(volumeUri.toString(), targetLunId);
}
dbClient.updateObject(exportMask);
taskCompleter.ready(dbClient);
}
} else {
String errorMsg = String.format("Failed to add volumes to export mask: %s .", task.getMessage());
log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.addVolumesToExportMaskFailed("addVolumes", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} catch (Exception ex) {
log.error("Problem in addVolumes: ", ex);
String errorMsg = String.format("Failed to add volumes to export mask: %s .", ex.getMessage());
log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.addVolumesToExportMaskFailed("addVolumes", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
log.info("{} addVolumes END...", storage.getSerialNumber());
}
use of com.emc.storageos.volumecontroller.impl.VolumeURIHLU in project coprhd-controller by CoprHD.
the class HDSExportOperations method getVolumeURIHLUFromExportMask.
/**
* Return VolumeURIHLU from the exportMask userAddedVolume.
* should we add existing volumes also in case if the environment is not green field?
*
* @param exportMask
* @return
*/
private VolumeURIHLU[] getVolumeURIHLUFromExportMask(ExportMask exportMask) {
VolumeURIHLU[] volumeURIHLU = null;
if (null != exportMask && null != exportMask.getUserAddedVolumes() && !exportMask.getUserAddedVolumes().isEmpty()) {
Set<String> userAddedVolumeSet = new HashSet<String>(exportMask.getUserAddedVolumes().values());
volumeURIHLU = new VolumeURIHLU[userAddedVolumeSet.size()];
int index = 0;
for (String userAddedVolume : userAddedVolumeSet) {
URI userAddedVolumeURI = URI.create(userAddedVolume);
BlockObject volume = BlockObject.fetch(dbClient, userAddedVolumeURI);
if (null != volume && !volume.getInactive()) {
String hlu = exportMask.getVolumes().get(userAddedVolume);
volumeURIHLU[index++] = new VolumeURIHLU(userAddedVolumeURI, hlu, null, volume.getLabel());
}
}
}
return volumeURIHLU;
}
use of com.emc.storageos.volumecontroller.impl.VolumeURIHLU in project coprhd-controller by CoprHD.
the class VnxExportOperations method addVolumes.
/*
* (non-Javadoc)
*
* @see
* com.emc.storageos.volumecontroller.impl.smis.ExportMaskOperations#addVolume(com.emc.storageos.db.client.model.
* StorageSystem, java.net.URI, com.emc.storageos.volumecontroller.impl.VolumeURIHLU[],
* com.emc.storageos.volumecontroller.TaskCompleter)
*/
@Override
public void addVolumes(StorageSystem storage, URI exportMaskURI, VolumeURIHLU[] volumeURIHLUs, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
_log.info("{} addVolumes START...", storage.getSerialNumber());
try {
_log.info("addVolumes: Export mask id: {}", exportMaskURI);
_log.info("addVolumes: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
if (initiatorList != null) {
_log.info("addVolumes: initiators impacted: {}", Joiner.on(',').join(initiatorList));
}
ExportOperationContext context = new VnxExportOperationContext();
// Prime the context object
taskCompleter.updateWorkflowStepContext(context);
// Determine if the volume is already in the masking view.
// If so, log and remove from volumes we need to process.
ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
CIMInstance maskingView = _helper.getLunMaskingProtocolController(storage, mask);
Map<String, Integer> discoveredVolumes = new HashMap<String, Integer>();
if (maskingView != null) {
WBEMClient client = _helper.getConnection(storage).getCimClient();
// Get volumes for the masking instance
discoveredVolumes = _helper.getVolumesFromLunMaskingInstance(client, maskingView);
}
List<VolumeURIHLU> removeURIs = new ArrayList<>();
for (VolumeURIHLU volumeUriHLU : volumeURIHLUs) {
BlockObject bo = BlockObject.fetch(_dbClient, volumeUriHLU.getVolumeURI());
if (discoveredVolumes.keySet().contains(bo.getNativeId())) {
_log.info("Found volume {} is already associated with masking view. Assuming this is from a previous operation.", bo.getLabel());
removeURIs.add(volumeUriHLU);
}
}
// Create the new array of volumes that don't exist yet in the masking view.
VolumeURIHLU[] addVolumeURIHLUs = new VolumeURIHLU[volumeURIHLUs.length - removeURIs.size()];
int index = 0;
for (VolumeURIHLU volumeUriHLU : volumeURIHLUs) {
if (!removeURIs.contains(volumeUriHLU)) {
addVolumeURIHLUs[index++] = volumeUriHLU;
}
}
CIMObjectPath[] protocolControllers = createOrGrowStorageGroup(storage, exportMaskURI, addVolumeURIHLUs, null, null, taskCompleter);
CimConnection cimConnection = _helper.getConnection(storage);
ExportMaskOperationsHelper.populateDeviceNumberFromProtocolControllers(_dbClient, cimConnection, exportMaskURI, addVolumeURIHLUs, protocolControllers, taskCompleter);
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_002);
taskCompleter.ready(_dbClient);
} catch (Exception e) {
_log.error("Unexpected error: addVolumes failed.", e);
ServiceError error = DeviceControllerErrors.smis.methodFailed("addVolumes", e.getMessage());
taskCompleter.error(_dbClient, error);
}
_log.info("{} addVolumes END...", storage.getSerialNumber());
}
Aggregations