use of com.emc.storageos.driver.dellsc.scapi.objects.ScServerHba in project coprhd-controller by CoprHD.
the class DellSCProvisioning method populateVolumeExportInfo.
/**
* Fills in export information for a specific volume mapping.
*
* @param volumeId The volume instance ID.
* @param map The mapping.
* @param result The export info map.
* @param serverCache The server cache.
* @param serverPortCache The server HBA cache.
* @param portCache The controller port cache.
* @throws StorageCenterAPIException
*/
private void populateVolumeExportInfo(StorageCenterAPI api, String volumeId, ScMapping map, Map<String, HostExportInfo> result, Map<String, ScServer> serverCache, Map<String, Initiator> serverPortCache, Map<String, StoragePort> portCache) throws StorageCenterAPIException {
ScServer server;
Initiator initiator;
StoragePort port;
// Get our server info
if (serverCache.containsKey(map.server.instanceId)) {
server = serverCache.get(map.server.instanceId);
} else {
server = api.getServerDefinition(map.server.instanceId);
serverCache.put(server.instanceId, server);
}
// Find the server HBA
if (serverPortCache.containsKey(map.serverHba.instanceId)) {
initiator = serverPortCache.get(map.serverHba.instanceId);
} else {
ScServerHba hba = api.getServerHba(map.serverHba.instanceId);
initiator = getInitiatorInfo(api, server, hba);
serverPortCache.put(hba.instanceId, initiator);
}
// Get the controller port info
if (portCache.containsKey(map.controllerPort.instanceId)) {
port = portCache.get(map.controllerPort.instanceId);
} else {
ScControllerPort scPort = api.getControllerPort(map.controllerPort.instanceId);
port = util.getStoragePortForControllerPort(api, scPort);
portCache.put(scPort.instanceId, port);
}
String hostName = initiator.getHostName();
if (initiator.getInitiatorType() == Type.Cluster) {
hostName = initiator.getClusterName();
}
HostExportInfo exportInfo;
if (result.containsKey(hostName)) {
exportInfo = result.get(hostName);
} else {
exportInfo = new HostExportInfo(hostName, new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
}
// Now populate all the info
if (!exportInfo.getStorageObjectNativeIds().contains(volumeId)) {
exportInfo.getStorageObjectNativeIds().add(volumeId);
}
if (!exportInfo.getTargets().contains(port)) {
exportInfo.getTargets().add(port);
}
if (!exportInfo.getInitiators().contains(initiator)) {
exportInfo.getInitiators().add(initiator);
}
result.put(hostName, exportInfo);
}
use of com.emc.storageos.driver.dellsc.scapi.objects.ScServerHba in project coprhd-controller by CoprHD.
the class DellSCProvisioning method createOrFindScServer.
/**
* Finds an existing server definition or creates a new one.
*
* @param ssn The Storage Center to check.
* @param api The API connection.
* @param initiators The list of initiators.
* @param matchedHbas The ScServerHbas that matched the provided initiators.
* @param createIfNotFound Whether to create the server if it's not found.
* @return The server object or null.
*/
private ScServer createOrFindScServer(StorageCenterAPI api, String ssn, List<Initiator> initiators, List<ScServerHba> matchedHbas, boolean createIfNotFound) {
ScServerOperatingSystem os = null;
Map<String, ScServer> serverLookup = new HashMap<>();
for (Initiator init : initiators) {
if (os == null) {
os = findOsType(api, ssn, init.getHostOsType());
}
if (os == null) {
LOG.warn("Unable to find OS type for initiator {}, skipping...", init.getPort());
continue;
}
String iqnOrWwn = init.getPort();
if (init.getProtocol().equals(Protocol.FC)) {
// Make sure it's in the format we expect
iqnOrWwn = iqnOrWwn.replace(":", "").toUpperCase();
}
// Try our cache first
ScServer individualServer = serverLookup.get(init.getHostName());
if (individualServer == null) {
individualServer = api.findServer(ssn, iqnOrWwn);
if (individualServer != null) {
serverLookup.put(init.getHostName(), individualServer);
}
}
// See if we need to create it
if (individualServer == null && createIfNotFound) {
try {
individualServer = api.createServer(ssn, init.getHostName(), init.getProtocol().equals(Protocol.iSCSI), os.instanceId);
} catch (StorageCenterAPIException e) {
// Well that's rather unfortunate
LOG.warn(String.format("Error creating server: %s", e));
continue;
}
// Need to add this initiator to existing server definition
ScServerHba hba = api.addHbaToServer(individualServer.instanceId, iqnOrWwn, init.getProtocol().equals(Protocol.iSCSI));
if (hba != null && !matchedHbas.contains(hba)) {
matchedHbas.add(hba);
}
}
if (individualServer != null) {
serverLookup.put(init.getHostName(), individualServer);
}
}
if (serverLookup.size() != 1) {
LOG.warn("Looking for server returned {} servers.", serverLookup.size());
}
for (ScServer scServer : serverLookup.values()) {
// Just return the first one
return scServer;
}
return null;
}
use of com.emc.storageos.driver.dellsc.scapi.objects.ScServerHba in project coprhd-controller by CoprHD.
the class StorageCenterAPI method getServerHbas.
/**
* Gets all defined HBAs for a server definition.
*
* @param ssn The Storage Center serial number.
* @param serverInstanceId The server definition.
* @return The HBAs.
*/
public ScServerHba[] getServerHbas(String ssn, String serverInstanceId) {
PayloadFilter filter = new PayloadFilter();
filter.append("scSerialNumber", ssn);
filter.append("Server", serverInstanceId);
RestResult rr = restClient.post("StorageCenter/ScServerHba/GetList", filter.toJson());
if (checkResults(rr)) {
return gson.fromJson(rr.getResult(), ScServerHba[].class);
}
return new ScServerHba[0];
}
use of com.emc.storageos.driver.dellsc.scapi.objects.ScServerHba in project coprhd-controller by CoprHD.
the class StorageCenterAPI method findServer.
/**
* Find a server definition.
*
* @param ssn The Storage Center SN on which to check.
* @param iqnOrWwn The WWN or IQN.
* @return The server definition.
*/
public ScServer findServer(String ssn, String iqnOrWwn) {
ScServer result = null;
ScServerHba hba = findServerHba(ssn, iqnOrWwn);
// If the initiator has been seen but never used to define a server it will have a null server
if (hba != null && hba.server != null) {
RestResult rr = restClient.get(String.format("StorageCenter/ScServer/%s", hba.server.instanceId));
if (checkResults(rr)) {
result = gson.fromJson(rr.getResult(), ScServer.class);
}
}
return result;
}
use of com.emc.storageos.driver.dellsc.scapi.objects.ScServerHba 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;
}
Aggregations