use of com.emc.storageos.storagedriver.model.StoragePort in project coprhd-controller by CoprHD.
the class StorageDriverSimulator method generateExportDataForVolume.
private void generateExportDataForVolume(String hostName, String storageSystemId, String volumeId, int volumeIndex, List<StoragePort> ports, int page) {
Map<String, List<HostExportInfo>> volumeToExportInfoMap = arrayToVolumeToVolumeExportInfoMap.get(storageSystemId);
if (volumeToExportInfoMap == null) {
volumeToExportInfoMap = new HashMap<>();
arrayToVolumeToVolumeExportInfoMap.put(storageSystemId, volumeToExportInfoMap);
}
List<HostExportInfo> volumeToHostExportInfoList = volumeToExportInfoMap.get(volumeId);
if (volumeToHostExportInfoList == null) {
volumeToHostExportInfoList = new ArrayList<>();
volumeToExportInfoMap.put(volumeId, volumeToHostExportInfoList);
}
// build volume export info
HostExportInfo exportInfo;
// get volume info
List<String> volumeIds = new ArrayList<>();
volumeIds.add(volumeId);
// for initiators we only know port network id and host name
List<String> hostInitiatorIds = hostToInitiatorPortIdMap.get(hostName);
List<Initiator> initiators = new ArrayList<>();
for (String initiatorId : hostInitiatorIds) {
Initiator initiator = new Initiator();
initiator.setHostName(hostName);
initiator.setPort(initiatorId);
initiators.add(initiator);
}
// decide about ports.
if (page % 2 == 1) {
// for odd pages we generate invalid masks for volumes (to test negative scenarios)
int portIndex = volumeIndex < ports.size() ? volumeIndex : ports.size() - 1;
List<StoragePort> exportPorts = Collections.singletonList(ports.get(portIndex));
exportInfo = new HostExportInfo(hostName, volumeIds, initiators, exportPorts);
} else {
exportInfo = new HostExportInfo(hostName, volumeIds, initiators, ports);
}
volumeToHostExportInfoList.add(exportInfo);
_log.info("VolumeToHostExportInfo: " + volumeToHostExportInfoList);
}
use of com.emc.storageos.storagedriver.model.StoragePort in project coprhd-controller by CoprHD.
the class StorageDriverSimulator method discoverStoragePorts.
@Override
public DriverTask discoverStoragePorts(StorageSystem storageSystem, List<StoragePort> storagePorts) {
_log.info("Discovery of storage ports for storage system {} .", storageSystem.getNativeId());
int index = 0;
// Get "portIndexes" attribute map
Map<String, List<String>> portIndexes = driverRegistry.getDriverAttributesForKey("simulatordriver", "portIndexes");
if (portIndexes != null) {
List<String> indexes = portIndexes.get(storageSystem.getNativeId());
if (indexes != null) {
index = Integer.parseInt(indexes.get(0));
_log.info("Storage ports index for storage system {} is {} .", storageSystem.getNativeId(), index);
}
}
if (index == 0) {
// get the last used index and increment by 1 to generate an index
if (portIndexes != null) {
List<String> indexes = portIndexes.get("lastIndex");
if (indexes != null) {
index = Integer.parseInt(indexes.get(0)) + 1;
} else {
index++;
}
} else {
index++;
}
// set this index for the system in registry
driverRegistry.addDriverAttributeForKey("simulatordriver", "portIndexes", storageSystem.getNativeId(), Collections.singletonList(String.valueOf(index)));
driverRegistry.addDriverAttributeForKey("simulatordriver", "portIndexes", "lastIndex", Collections.singletonList(String.valueOf(index)));
_log.info("Storage ports index for storage system {} is {} .", storageSystem.getNativeId(), index);
}
// Create ports with network
for (int i = 0; i <= 2; i++) {
StoragePort port = new StoragePort();
port.setNativeId("port-1234577-" + i + storageSystem.getNativeId());
port.setStorageSystemId(storageSystem.getNativeId());
_log.info("Discovered Port {}, storageSystem {}", port.getNativeId(), port.getStorageSystemId());
port.setDeviceLabel("er-port-1234577" + i + storageSystem.getNativeId());
port.setPortName(port.getDeviceLabel());
// port.setNetworkId("er-network77"+ storageSystem.getNativeId());
port.setNetworkId("11");
port.setTransportType(StoragePort.TransportType.FC);
// port.setTransportType(StoragePort.TransportType.IP);
port.setPortNetworkId("6" + Integer.toHexString(index) + ":FE:FE:FE:FE:FE:FE:1" + i);
port.setOperationalStatus(StoragePort.OperationalStatus.OK);
port.setPortHAZone("zone-" + i);
storagePorts.add(port);
}
// Create ports without network
for (int i = 3; i <= 6; i++) {
StoragePort port = new StoragePort();
port.setNativeId("port-1234577-" + i + storageSystem.getNativeId());
port.setStorageSystemId(storageSystem.getNativeId());
_log.info("Discovered Port {}, storageSystem {}", port.getNativeId(), port.getStorageSystemId());
port.setDeviceLabel("er-port-1234577" + i + storageSystem.getNativeId());
port.setPortName(port.getDeviceLabel());
// port.setNetworkId("er-network77"+ storageSystem.getNativeId());
port.setTransportType(StoragePort.TransportType.FC);
port.setPortNetworkId("6" + Integer.toHexString(index) + ":FE:FE:FE:FE:FE:FE:1" + i);
port.setOperationalStatus(StoragePort.OperationalStatus.OK);
port.setPortHAZone("zone-with-many-ports");
storagePorts.add(port);
}
String taskType = "discover-storage-ports";
String taskId = String.format("%s+%s+%s", DRIVER_NAME, taskType, UUID.randomUUID().toString());
DriverTask task = new DriverSimulatorTask(taskId);
task.setStatus(DriverTask.TaskStatus.READY);
_log.info("StorageDriver: discoverStoragePorts information for storage system {}, nativeId {} - end", storageSystem.getIpAddress(), storageSystem.getNativeId());
return task;
}
use of com.emc.storageos.storagedriver.model.StoragePort in project coprhd-controller by CoprHD.
the class ExternalDeviceCommunicationInterface method discoverStoragePorts.
private Map<String, List<com.emc.storageos.db.client.model.StoragePort>> discoverStoragePorts(DiscoveryDriver driver, Set<Network> networksToUpdate, AccessProfile accessProfile) throws BaseCollectionException {
URI storageSystemId = accessProfile.getSystemId();
com.emc.storageos.db.client.model.StorageSystem storageSystem = _dbClient.queryObject(com.emc.storageos.db.client.model.StorageSystem.class, storageSystemId);
Map<String, List<com.emc.storageos.db.client.model.StoragePort>> storagePorts = new HashMap<>();
Map<StoragePort, com.emc.storageos.db.client.model.StoragePort> driverPortsToDBPorts = new HashMap<>();
List<com.emc.storageos.db.client.model.StoragePort> newStoragePorts = new ArrayList<>();
List<com.emc.storageos.db.client.model.StoragePort> existingStoragePorts = new ArrayList<>();
List<String> endpoints = new ArrayList<>();
StorageSystem driverStorageSystem = initStorageSystem(storageSystem);
// Discover storage ports
try {
_log.info("discoverPorts for storage system {} - start", storageSystemId);
List<StoragePort> driverStoragePorts = new ArrayList<>();
// Call driver.
DriverTask task = driver.discoverStoragePorts(driverStorageSystem, driverStoragePorts);
// todo: need to implement support for async case.
if (task.getStatus() == DriverTask.TaskStatus.READY) {
for (StoragePort driverPort : driverStoragePorts) {
com.emc.storageos.db.client.model.StoragePort storagePort = null;
String portNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem, driverPort.getNativeId(), NativeGUIDGenerator.PORT);
// Check if storage port was already discovered
@SuppressWarnings("deprecation") List<URI> portURIs = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePortByNativeGuidConstraint(portNativeGuid));
for (URI portUri : portURIs) {
com.emc.storageos.db.client.model.StoragePort port = _dbClient.queryObject(com.emc.storageos.db.client.model.StoragePort.class, portUri);
if (port.getStorageDevice().equals(storageSystemId) && !port.getInactive()) {
storagePort = port;
break;
}
}
// Verify that discovered port has mandatory identifier "portNetworkId"
if (driverPort.getPortNetworkId() == null) {
if (storagePort == null) {
_log.error("No portNetworkId for new discovered port {}, skip discovery of this port.", portNativeGuid);
} else {
_log.error("No portNetworkId for previously discovered port {}, skip discovery of this port.", portNativeGuid);
}
continue;
}
if (storagePort == null) {
// New port processing
storagePort = new com.emc.storageos.db.client.model.StoragePort();
prepareNewPort(storagePort, driverPort);
storagePort.setNativeGuid(portNativeGuid);
storagePort.setStorageDevice(storageSystemId);
if (driverPort.getNetworkId() != null) {
// Get or create Network object for this port
Network portNetwork = getNetworkForStoragePort(driverPort);
storagePort.setNetwork(portNetwork.getId());
// Add endpoint to the network.
// Process this for all ports (existing port got a network or changed network cases)
// TODO: should we check if existing port was in other network and delete the endpoint from the old network?
portNetwork.addEndpoints(new ArrayList<>(Arrays.asList(driverPort.getPortNetworkId())), true);
networksToUpdate.add(portNetwork);
}
storagePort.setTcpPortNumber(driverPort.getTcpPortNumber());
storagePort.setRegistrationStatus(DiscoveredDataObject.RegistrationStatus.REGISTERED.toString());
_log.info("Creating new storage port using NativeGuid : {}", portNativeGuid);
newStoragePorts.add(storagePort);
} else {
existingStoragePorts.add(storagePort);
}
storagePort.setPortNetworkId(driverPort.getPortNetworkId());
if (driverPort.getTransportType() != null && driverPort.getTransportType().equalsIgnoreCase(StoragePort.TransportType.IP.toString())) {
storagePort.setIpAddress(driverPort.getIpAddress());
}
storagePort.setDiscoveryStatus(DiscoveredDataObject.DiscoveryStatus.VISIBLE.name());
storagePort.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
storagePort.setOperationalStatus(driverPort.getOperationalStatus());
storagePort.setAvgBandwidth(driverPort.getAvgBandwidth());
storagePort.setPortSpeed(driverPort.getPortSpeed());
// Set usage metric for the port
if (driverPort.getUtilizationMetric() != null) {
StringMap usageMetrics = storagePort.getMetrics();
MetricsKeys.putDouble(MetricsKeys.portMetric, driverPort.getUtilizationMetric(), usageMetrics);
storagePort.setMetrics(usageMetrics);
}
driverPortsToDBPorts.put(driverPort, storagePort);
}
storagePorts.put(NEW, newStoragePorts);
storagePorts.put(EXISTING, existingStoragePorts);
// Create storage ha domains for ports
processStorageHADomains(storageSystem, Collections.unmodifiableMap(driverPortsToDBPorts));
} else {
String errorMsg = String.format("Failed to discover storage ports for system %s of type %s. \n" + " Driver task message: %s", accessProfile.getSystemId(), accessProfile.getSystemType(), task.getMessage());
throw new ExternalDeviceCollectionException(false, ServiceCode.DISCOVERY_ERROR, null, errorMsg, null, null);
}
String message = String.format("Storage ports of storage array %s with native id %s were discovered successfully.", storageSystem.getId(), storageSystem.getNativeGuid());
_log.info(message);
return storagePorts;
} catch (Exception e) {
String message = String.format("Failed to discover storage ports of storage array %s with native id %s : %s .", storageSystem.getId(), storageSystem.getNativeGuid(), e.getMessage());
_log.error(message, e);
storageSystem.setLastDiscoveryStatusMessage(message);
throw e;
} finally {
_dbClient.updateObject(storageSystem);
_log.info("Discovery of storage ports of storage system {} of type {} - end", accessProfile.getSystemId(), accessProfile.getSystemType());
}
}
use of com.emc.storageos.storagedriver.model.StoragePort in project coprhd-controller by CoprHD.
the class ExternalDeviceCommunicationInterface method processStorageHADomains.
private void processStorageHADomains(com.emc.storageos.db.client.model.StorageSystem storageSystem, Map<StoragePort, com.emc.storageos.db.client.model.StoragePort> driverPortsToDBPorts) {
// Map ha zone names to driver ports
Map<String, Set<StoragePort>> haZoneNameToDriverPorts = new HashMap<>();
Set<StoragePort> driverPorts = driverPortsToDBPorts.keySet();
for (StoragePort driverPort : driverPorts) {
if (driverPort.getPortHAZone() != null && !driverPort.getPortHAZone().isEmpty()) {
Set<StoragePort> haZonePorts = haZoneNameToDriverPorts.get(driverPort.getPortHAZone());
if (haZonePorts == null) {
haZonePorts = new HashSet<>();
haZoneNameToDriverPorts.put(driverPort.getPortHAZone(), haZonePorts);
}
haZonePorts.add(driverPort);
}
}
for (Map.Entry<String, Set<StoragePort>> haZoneNameToDriverPort : haZoneNameToDriverPorts.entrySet()) {
String portHAZone = haZoneNameToDriverPort.getKey();
Set<StoragePort> haZoneDriverPorts = haZoneNameToDriverPort.getValue();
if (portHAZone != null) {
String haDomainNativeGUID = NativeGUIDGenerator.generateNativeGuid(storageSystem, portHAZone, NativeGUIDGenerator.ADAPTER);
_log.info("HA Domain Native Guid : {}", haDomainNativeGUID);
@SuppressWarnings("deprecation") List<URI> uriHaList = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStorageHADomainByNativeGuidConstraint(haDomainNativeGUID));
StorageHADomain haDomain;
if (uriHaList.isEmpty()) {
haDomain = new StorageHADomain();
haDomain.setId(URIUtil.createId(StorageHADomain.class));
haDomain.setNativeGuid(haDomainNativeGUID);
haDomain.setName(portHAZone);
haDomain.setAdapterName(portHAZone);
haDomain.setStorageDeviceURI(storageSystem.getId());
haDomain.setNumberofPorts(String.valueOf(haZoneDriverPorts.size()));
_dbClient.createObject(haDomain);
} else {
haDomain = _dbClient.queryObject(StorageHADomain.class, uriHaList.get(0));
haDomain.setNumberofPorts(String.valueOf(haZoneDriverPorts.size()));
_dbClient.updateObject(haDomain);
}
for (StoragePort driverPort : haZoneDriverPorts) {
com.emc.storageos.db.client.model.StoragePort port = driverPortsToDBPorts.get(driverPort);
port.setStorageHADomain(haDomain.getId());
}
}
}
}
use of com.emc.storageos.storagedriver.model.StoragePort in project coprhd-controller by CoprHD.
the class ExternalDeviceExportOperations method addInitiators.
@Override
public void addInitiators(StorageSystem storage, URI exportMaskUri, List<URI> volumeURIs, List<com.emc.storageos.db.client.model.Initiator> initiatorList, List<URI> targetURIList, TaskCompleter taskCompleter) throws DeviceControllerException {
log.info("{} addInitiators START...", storage.getSerialNumber());
try {
log.info("addInitiators: Export mask id: {}", exportMaskUri);
if (volumeURIs != null) {
log.info("addInitiators: volumes : {}", Joiner.on(',').join(volumeURIs));
}
log.info("addInitiators: initiators : {}", Joiner.on(',').join(initiatorList));
log.info("addInitiators: targets : {}", 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);
List<URI> volumeUris = ExportMaskUtils.getVolumeURIs(exportMask);
// Prepare volumes
List<StorageVolume> driverVolumes = new ArrayList<>();
Map<String, String> driverVolumeToHLUMap = new HashMap<>();
Map<String, String> volumeNativeIdToUriMap = new HashMap<>();
prepareVolumes(storage, exportMask.getVolumes(), 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
prepareCapabilitiesForAddInitiators(pathParams, exportMask.getZoningMap(), exportGroup.getVirtualArray(), initiatorList, 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("addInitiators -- Added initiators: %s . Used recommended ports: %s .", task.getMessage(), usedRecommendedPorts);
log.info(msg);
if (usedRecommendedPorts.isFalse()) {
// process driver selected ports
log.info("Ports selected by driver: {}", selectedPorts);
if (validateSelectedPorts(availablePorts, selectedPorts, pathParams.getPathsPerInitiator())) {
List<com.emc.storageos.db.client.model.StoragePort> selectedPortsForMask = new ArrayList<>();
URI varrayUri = exportGroup.getVirtualArray();
for (StoragePort driverPort : selectedPorts) {
com.emc.storageos.db.client.model.StoragePort port = nativeIdToAvailablePortMap.get(driverPort.getNativeId());
selectedPortsForMask.add(port);
}
updateStoragePortsForAddInitiators((ExportMaskAddInitiatorCompleter) taskCompleter, storage, exportMask, initiatorList, selectedPortsForMask, varrayUri, pathParams);
taskCompleter.ready(dbClient);
} else {
// selected ports are not valid. failure
String errorMsg = "addInitiators -- Ports selected by driver failed validation.";
log.error("addInitiators -- Ports selected by driver failed validation.");
ServiceError serviceError = ExternalDeviceException.errors.addInitiatorsToExportMaskFailed("addInitiators", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} else {
// Used recommended ports.
taskCompleter.ready(dbClient);
}
} else {
String errorMsg = String.format("addInitiators -- Failed to add initiators to export mask: %s .", task.getMessage());
log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.addInitiatorsToExportMaskFailed("addInitiators", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} catch (Exception ex) {
log.error("addInitiators -- Failed to add initiators to export mask. ", ex);
ServiceError serviceError = ExternalDeviceException.errors.addInitiatorsToExportMaskFailed("addInitiators", ex.getMessage());
taskCompleter.error(dbClient, serviceError);
}
log.info("{} addInitiators END...", storage.getSerialNumber());
}
Aggregations