use of com.emc.storageos.storagedriver.model.StoragePort in project coprhd-controller by CoprHD.
the class HP3PARIngestHelper method getBlockObjectExportInfoForHosts.
public Map<String, HostExportInfo> getBlockObjectExportInfoForHosts(String storageSystemId, String wwn, String objectName, StorageBlockObject object, Registry registry) {
try {
_log.info("3PARDriver: getBlockObjectExportInfoForHosts Running");
Map<String, HostExportInfo> resultMap = new HashMap<String, HostExportInfo>();
// get the vlun associated with the volume at consideration.
HP3PARApi hp3parApi = hp3parUtil.getHP3PARDeviceFromNativeId(storageSystemId, registry);
VirtualLunsList vlunsOfVolume = hp3parApi.getVLunsOfVolume(wwn);
// Check which of the storage ports discovered, matches the
// node:portpos:cardport
// combination of the VLUN
List<StoragePort> storPortsOfStorage = new ArrayList<>();
hp3parUtil.discoverStoragePortsById(storageSystemId, storPortsOfStorage, registry);
// for (int index = 0; index < vlunsOfVolume.getTotal(); index++) {
for (VirtualLun objVirtualLun : vlunsOfVolume.getMembers()) {
if (!objVirtualLun.isActive()) {
if (objVirtualLun.getType() == 5) {
String exportPath = storageSystemId + objectName + objVirtualLun.getHostname();
_log.info("3PARDriver:Ingestion {} for registry entry", exportPath);
// Make a registry entry for ingested volume if it is
// exported to host set
Map<String, List<String>> attributes = new HashMap<>();
List<String> expValue = new ArrayList<>();
List<String> lunValue = new ArrayList<>();
expValue.add(exportPath);
attributes.put("EXPORT_PATH", expValue);
lunValue.add(objVirtualLun.getLun().toString());
attributes.put(objectName, lunValue);
registry.setDriverAttributesForKey(HP3PARConstants.DRIVER_NAME, exportPath, attributes);
_log.info("3PARDriver:Ingestion {} for attributes entry", attributes);
}
continue;
}
_log.debug("objVirtualLun.toString() {}", objVirtualLun.toString());
List<String> volumeIds = new ArrayList<>();
List<Initiator> initiators = new ArrayList<Initiator>();
List<StoragePort> storageports = new ArrayList<>();
// To volumeIds we need to add the native id of volume
// and for hp3par volume name would be the native id
volumeIds.add(objVirtualLun.getVolumeName());
Initiator hostInitiator = new Initiator();
// hp3par returns remote name in the format like
// 10000000C98F5C79.
// we now convert this to the format 10:00:00:00:C9:8F:5C:79
String portId = SanUtils.formatWWN(objVirtualLun.getRemoteName());
String nativeId = String.format("%s:%s:%s", objVirtualLun.getPortPos().getNode(), objVirtualLun.getPortPos().getSlot(), objVirtualLun.getPortPos().getCardPort());
for (StoragePort port : storPortsOfStorage) {
if (port.getNativeId().equals(nativeId)) {
storageports.add(port);
break;
}
}
hostInitiator.setHostName(objVirtualLun.getHostname());
hostInitiator.setPort(portId);
initiators.add(hostInitiator);
HostExportInfo exportInfo = null;
if (resultMap.containsKey(objVirtualLun.getHostname())) {
exportInfo = resultMap.get(objVirtualLun.getHostname());
for (int i1 = 0; i1 < storageports.size(); i1++) {
StoragePort ob1 = storageports.get(i1);
if (!exportInfo.getTargets().contains(ob1)) {
exportInfo.getTargets().add(ob1);
}
}
for (int i1 = 0; i1 < initiators.size(); i1++) {
Initiator ob1 = initiators.get(i1);
if (!exportInfo.getInitiators().contains(ob1)) {
exportInfo.getInitiators().add(ob1);
}
}
} else {
exportInfo = new HostExportInfo(objVirtualLun.getHostname(), volumeIds, initiators, storageports);
}
resultMap.put(objVirtualLun.getHostname(), exportInfo);
}
_log.info("Resultmap of GetVolumeExportInfo {}", resultMap);
_log.info("3PARDriver: Leaving getBlockObjectExportInfoForHosts");
return resultMap;
} catch (Exception e) {
String msg = String.format("3PARDriver: Unable to get export info of the storage objet %s in storage system native id is %s; Error: %s.\n", objectName, storageSystemId, e.getMessage());
_log.error(msg);
e.printStackTrace();
}
return null;
}
use of com.emc.storageos.storagedriver.model.StoragePort in project coprhd-controller by CoprHD.
the class DellSCProvisioning method exportVolumesToInitiators.
/**
* Export volumes to initiators through a given set of ports. If ports are
* not provided, use port requirements from ExportPathsServiceOption
* storage capability.
*
* @param initiators The initiators to export to.
* @param volumes The volumes to export.
* @param volumeToHLUMap Map of volume nativeID to requested HLU. HLU
* value of -1 means that HLU is not defined and will
* be assigned by array.
* @param recommendedPorts List of storage ports recommended for the export.
* Optional.
* @param availablePorts List of ports available for the export.
* @param capabilities The storage capabilities.
* @param usedRecommendedPorts True if driver used recommended and only
* recommended ports for the export, false
* otherwise.
* @param selectedPorts Ports selected for the export (if recommended ports
* have not been used).
* @return The export task.
* @throws DellSCDriverException
*/
public DriverTask exportVolumesToInitiators(List<Initiator> initiators, List<StorageVolume> volumes, Map<String, String> volumeToHLUMap, List<StoragePort> recommendedPorts, List<StoragePort> availablePorts, StorageCapabilities capabilities, MutableBoolean usedRecommendedPorts, List<StoragePort> selectedPorts) {
LOG.info("Exporting volumes to inititators");
DellSCDriverTask task = new DellSCDriverTask("exportVolumes");
ScServer server = null;
List<ScServerHba> preferredHbas = new ArrayList<>();
StringBuilder errBuffer = new StringBuilder();
int volumesMapped = 0;
Set<StoragePort> usedPorts = new HashSet<>();
String preferredController = null;
// Cache of controller port instance IDs to StoragePort objects
Map<String, StoragePort> discoveredPorts = new HashMap<>();
// See if a max port count has been specified
int maxPaths = -1;
List<ExportPathsServiceOption> pathOptions = capabilities.getCommonCapabilitis().getExportPathParams();
for (ExportPathsServiceOption pathOption : pathOptions) {
// List but appears to only ever have one option?
maxPaths = pathOption.getMaxPath();
}
// Get the recommended server ports to use
List<String> recommendedServerPorts = new ArrayList<>();
for (StoragePort port : recommendedPorts) {
recommendedServerPorts.add(port.getNativeId());
}
for (StorageVolume volume : volumes) {
String ssn = volume.getStorageSystemId();
try {
StorageCenterAPI api = connectionManager.getConnection(ssn);
// Find our actual volume
ScVolume scVol = null;
int dotCount = StringUtils.countMatches(volume.getNativeId(), ".");
if (dotCount == 2) {
// Not actually a volume
scVol = api.createReplayView(volume.getNativeId(), String.format("View of %s", volume.getNativeId()));
} else {
// Normal volume instance ID
scVol = api.getVolume(volume.getNativeId());
}
if (scVol == null) {
throw new DellSCDriverException(String.format("Unable to find volume %s", volume.getNativeId()));
}
// Look up the server if needed
if (server == null) {
server = createOrFindScServer(api, ssn, initiators, preferredHbas);
}
if (server == null) {
// Unable to find or create the server, can't continue
throw new DellSCDriverException(SERVER_CREATE_FAIL_MSG);
}
// See if we have a preferred controller
if (preferredController == null && scVol.active) {
// At least first volume is active somewhere, so we need to try to
// use that controller for all mappings
ScVolumeConfiguration volConfig = api.getVolumeConfig(scVol.instanceId);
if (volConfig != null) {
preferredController = volConfig.controller.instanceId;
}
}
// Next try to get a preferred controller based on what's requested
if (preferredController == null && !recommendedPorts.isEmpty()) {
try {
ScControllerPort scPort = api.getControllerPort(recommendedPorts.get(0).getNativeId());
preferredController = scPort.controller.instanceId;
} catch (Exception e) {
LOG.warn("Failed to get recommended port controller.", e);
}
}
int preferredLun = -1;
if (volumeToHLUMap.containsKey(volume.getNativeId())) {
String hlu = volumeToHLUMap.get(volume.getNativeId());
try {
preferredLun = Integer.parseInt(hlu);
} catch (NumberFormatException e) {
LOG.warn("Unable to parse preferred LUN {}", hlu);
}
}
ScMappingProfile profile;
// See if the volume is already mapped
ScMappingProfile[] mappingProfiles = api.getServerVolumeMapping(scVol.instanceId, server.instanceId);
if (mappingProfiles.length > 0) {
// This one is already mapped
profile = mappingProfiles[0];
} else {
profile = api.createVolumeMappingProfile(scVol.instanceId, server.instanceId, preferredLun, new String[0], maxPaths, preferredController);
}
ScMapping[] maps = api.getMappingProfileMaps(profile.instanceId);
for (ScMapping map : maps) {
volumeToHLUMap.put(volume.getNativeId(), String.valueOf(map.lun));
StoragePort port;
if (discoveredPorts.containsKey(map.controllerPort.instanceId)) {
port = discoveredPorts.get(map.controllerPort.instanceId);
} else {
ScControllerPort scPort = api.getControllerPort(map.controllerPort.instanceId);
port = util.getStoragePortForControllerPort(api, scPort);
discoveredPorts.put(map.controllerPort.instanceId, port);
}
usedPorts.add(port);
}
volumesMapped++;
LOG.info("Volume '{}' exported to server '{}'", scVol.name, server.name);
} catch (StorageCenterAPIException | DellSCDriverException dex) {
String error = String.format("Error mapping volume %s: %s", volume.getDisplayName(), dex);
LOG.error(error);
errBuffer.append(String.format("%s%n", error));
if (SERVER_CREATE_FAIL_MSG.equals(dex.getMessage())) {
// Game over
break;
}
}
}
// See if we were able to use all of the recommended ports
// TODO: Expand this to do more accurate checking
usedRecommendedPorts.setValue(recommendedPorts.size() == usedPorts.size());
if (!usedRecommendedPorts.isTrue()) {
selectedPorts.addAll(usedPorts);
}
task.setMessage(errBuffer.toString());
if (volumesMapped == volumes.size()) {
task.setStatus(TaskStatus.READY);
} else if (volumesMapped == 0) {
task.setStatus(TaskStatus.FAILED);
} else {
task.setStatus(TaskStatus.PARTIALLY_FAILED);
}
return task;
}
use of com.emc.storageos.storagedriver.model.StoragePort in project coprhd-controller by CoprHD.
the class StorageDriverSimulator method generateExportDataForVolumeReplica.
private void generateExportDataForVolumeReplica(StorageVolume volume, StorageBlockObject replica) {
Map<String, List<HostExportInfo>> volumeToExportInfoMap = arrayToVolumeToVolumeExportInfoMap.get(volume.getStorageSystemId());
if (volumeToExportInfoMap != null) {
List<HostExportInfo> volumeExportInfoList = volumeToExportInfoMap.get(volume.getNativeId());
if (volumeExportInfoList != null && !volumeExportInfoList.isEmpty()) {
List<HostExportInfo> replicaExportInfoList = new ArrayList<>();
// build replica export info from info of parent volume
for (HostExportInfo hostExportInfo : volumeExportInfoList) {
List<String> snapIds = new ArrayList<>();
snapIds.add(replica.getNativeId());
List<Initiator> hostInitiators = hostExportInfo.getInitiators();
List<StoragePort> exportPorts = hostExportInfo.getTargets();
HostExportInfo exportInfo = new HostExportInfo(hostExportInfo.getHostName(), snapIds, hostInitiators, exportPorts);
replicaExportInfoList.add(exportInfo);
}
_log.info("Export Info for replica: {} --- {}", replica.getNativeId(), replicaExportInfoList);
volumeToExportInfoMap.put(replica.getNativeId(), replicaExportInfoList);
}
}
}
Aggregations