use of com.emc.storageos.model.block.export.ExportPathsAdjustmentPreviewRestRep in project coprhd-controller by CoprHD.
the class ExportGroupService method pathsAdjustmentPreview.
/**
* Paths Adjustment Preview
*
* This call does a PORT Allocation which is used for a path adjustment preview operation.
* If the user is satisfied with the ports that are selected, they will invoke the provisioning through a
* separate API.
*
* Inputs are the the Export Group URI, Storage System URI, an optional Varray URI, and the ExportPath parameters.
* There is also a boolean that specifies the allocation should start assuming the existing paths are used (or not).
*
* @param id the URN of a ViPR export group to be updated; ports will be allocated in this context
* @param param -- ExportPortAllocateParam block containing Storage System URI, Varray URI, ExportPathParameters
*
* @brief Preview port allocation paths for export
* @return a PortAllocatePreviewRestRep rest response which contains the new or existing paths that will be provisioned
* or kept; the removed paths; and any other Export Groups that will be affected.
* @throws ControllerException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/paths-adjustment-preview")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public ExportPathsAdjustmentPreviewRestRep pathsAdjustmentPreview(@PathParam("id") URI id, ExportPathsAdjustmentPreviewParam param) throws ControllerException {
// Basic validation of ExportGroup and update request
ExportGroup exportGroup = queryObject(ExportGroup.class, id, true);
if (exportGroup.checkInternalFlags(DataObject.Flag.DELETION_IN_PROGRESS)) {
throw BadRequestException.badRequests.deletionInProgress(exportGroup.getClass().getSimpleName(), exportGroup.getLabel());
}
validateExportGroupNoPendingEvents(exportGroup);
validateHostsInExportGroup(exportGroup, param.getHosts());
// Validate storage system
ArgValidator.checkUri(param.getStorageSystem());
StorageSystem system = queryObject(StorageSystem.class, param.getStorageSystem(), true);
// Get the virtual array, default to Export Group varray. Validate it matches.
URI varray = param.getVirtualArray();
if (varray != null) {
boolean validVarray = varray.equals(exportGroup.getVirtualArray());
if (exportGroup.getAltVirtualArrays() != null && varray.toString().equals(exportGroup.getAltVirtualArrays().get(system.getId().toString()))) {
validVarray = true;
}
if (!validVarray) {
throw APIException.badRequests.varrayNotInExportGroup(varray.toString());
}
} else {
varray = exportGroup.getVirtualArray();
}
// Validate the hosts, if supplied.
for (URI hostId : param.getHosts()) {
// Throw exception of thoe hostId is invalid
queryObject(Host.class, hostId, true);
}
// Get the initiators and validate the ExportMasks are usable.
ExportPathsAdjustmentPreviewRestRep response = new ExportPathsAdjustmentPreviewRestRep();
String storageSystem = system.getNativeGuid();
if (Type.vplex.equals(Type.valueOf(system.getSystemType()))) {
String vplexCluster = ConnectivityUtil.getVplexClusterForVarray(varray, system.getId(), _dbClient);
storageSystem = storageSystem + STORAGE_SYSTEM_CLUSTER + vplexCluster;
}
response.setStorageSystem(storageSystem);
List<Initiator> initiators = getInitiators(exportGroup);
StringSetMap existingPathMap = new StringSetMap();
StringSet storagePorts = new StringSet();
validatePathAdjustment(exportGroup, initiators, system, varray, param.getHosts(), response, existingPathMap, param.getUseExistingPaths(), storagePorts);
try {
// Manufacture an ExportPathParams structure from the REST ExportPathParameters structure
ExportPathParams pathParam = new ExportPathParams(param.getExportPathParameters(), exportGroup);
if (!storagePorts.isEmpty()) {
// check if storage ports are specified
StringSet paramPorts = pathParam.getStoragePorts();
if (paramPorts != null && !paramPorts.isEmpty()) {
if (!storagePorts.containsAll(paramPorts)) {
_log.error("Selected ports are not in the port group");
throw APIException.badRequests.pathAdjustmentSelectedPortsNotInPortGroup(Joiner.on(',').join(paramPorts), Joiner.on(',').join(storagePorts));
}
} else {
pathParam.setStoragePorts(storagePorts);
}
}
// Call the storage port allocator/assigner for all initiators (host or cluster) in
// the Export Group. Pass in the existing paths if requested in the parameters.
List<URI> volumes = StringSetUtil.stringSetToUriList(exportGroup.getVolumes().keySet());
Map<URI, List<URI>> zoningMap = _blockStorageScheduler.assignStoragePorts(system, varray, initiators, pathParam, (param.getUseExistingPaths() ? existingPathMap : new StringSetMap()), volumes);
for (Entry<URI, List<URI>> entry : zoningMap.entrySet()) {
InitiatorPortMapRestRep zone = new InitiatorPortMapRestRep();
Initiator initiator = queryObject(Initiator.class, entry.getKey(), false);
zone.setInitiator(HostMapper.map(initiator));
for (URI portURI : entry.getValue()) {
StoragePort port = queryObject(StoragePort.class, portURI, false);
zone.getStoragePorts().add(toNamedRelatedResource(port, port.getPortName()));
}
response.getAdjustedPaths().add(zone);
}
addRetainedPathsFromHosts(response, existingPathMap, param.getHosts());
Collections.sort(response.getAdjustedPaths(), response.new InitiatorPortMapRestRepComparator());
calculateRemovedPaths(response, zoningMap, exportGroup, system, varray, param.getHosts());
response.logResponse(_log);
return response;
} catch (ControllerException ex) {
_log.error(ex.getLocalizedMessage());
throw (ex);
}
}
Aggregations