use of com.emc.storageos.model.block.export.VolumeParam in project coprhd-controller by CoprHD.
the class ExportGroupService method validateClientsAndUpdate.
/**
* This helper function is used by {@link #updateExportGroup(URI, ExportUpdateParam)} to
* validate the user input and compute the updated lists of initiators, hosts and clusters.
*
* @param exportGroup the export group being updated.
* @param project the export group project
* @param storageSystems the storage systems where the export group volumes exist
* @param param the input parameter
* @param newClusters a list to be populated with the updated list of clusters
* @param newHosts a list to be populated with the updated list of hosts
* @param newInitiators a list to be populated with the updated list of initiators
* @param addedClusters new clusters to be added to the given Export Group
* @param removedClusters Clusters to be removed from the given Export Group
* @param addedHosts New hosts to be added to the give Export Group
* @param removedHosts Hosts to be removed from the give Export Group
* @param addedInitiators New initiators to be added to the given Export Group
* @param removedInitiators Initiators to be removed from the given Export Group
*/
void validateClientsAndUpdate(ExportGroup exportGroup, Project project, Collection<URI> storageSystems, ExportUpdateParam param, List<URI> newClusters, List<URI> newHosts, List<URI> newInitiators, Set<URI> addedClusters, Set<URI> removedClusters, Set<URI> addedHosts, Set<URI> removedHosts, Set<URI> addedInitiators, Set<URI> removedInitiators) {
if (param.getClusters() != null) {
if (!CollectionUtils.isEmpty(param.getClusters().getRemove())) {
for (URI uri : param.getClusters().getRemove()) {
if (!removedClusters.contains(uri)) {
removedClusters.add(uri);
// removeClusterData(uri, newHosts, newInitiators);
}
}
}
if (!CollectionUtils.isEmpty(param.getClusters().getAdd())) {
for (URI uri : param.getClusters().getAdd()) {
Cluster cluster = queryObject(Cluster.class, uri, true);
validateClusterData(cluster, exportGroup, storageSystems, project, newHosts, newInitiators);
if (!addedClusters.contains(uri)) {
addedClusters.add(uri);
}
}
}
}
_log.info("Updated list of Added clusters: {}", addedClusters.toArray());
_log.info("Updated list of Removed clusters: {}", removedClusters.toArray());
if (param.getHosts() != null) {
if (!CollectionUtils.isEmpty(param.getHosts().getRemove())) {
for (URI uri : param.getHosts().getRemove()) {
removedHosts.add(uri);
// removeHostData(uri, newInitiators);
}
}
if (!CollectionUtils.isEmpty(param.getHosts().getAdd())) {
for (URI uri : param.getHosts().getAdd()) {
Host host = queryObject(Host.class, uri, true);
// If the export type is cluster
if (exportGroup.forCluster()) {
// make sure the host belongs to one of the group's clusters
if (!hasItems(newClusters) || !newClusters.contains(host.getCluster())) {
throw APIException.badRequests.invalidParameterHostNotInCluster(host.getHostName());
}
}
validateHostData(host, exportGroup, storageSystems, project, newInitiators);
if (!addedHosts.contains(uri)) {
addedHosts.add(uri);
}
}
}
}
_log.info("Updated list of Added Hosts: {}", addedHosts.toArray());
_log.info("Updated list of Removed Hosts: {}", removedHosts.toArray());
if (param.getInitiators() != null) {
if (!CollectionUtils.isEmpty(param.getInitiators().getRemove())) {
for (URI uri : param.getInitiators().getRemove()) {
removedInitiators.add(uri);
}
}
if (!CollectionUtils.isEmpty(param.getInitiators().getAdd())) {
// TODO - Temporarily commented out for backward compatibility
URI initiatorHostUri = getInitiatorExportGroupHost(exportGroup);
for (URI uri : param.getInitiators().getAdd()) {
Initiator initiator = queryObject(Initiator.class, uri, true);
if (exportGroup.forInitiator()) {
if (initiatorHostUri == null) {
initiatorHostUri = initiator.getHost();
} else {
if (!initiatorHostUri.equals(initiator.getHost())) {
throw APIException.badRequests.initiatorExportGroupInitiatorsBelongToSameHost();
}
}
}
validateInitiatorRegistered(initiator);
validateInitiatorNetworkRegistered(initiator, exportGroup.getVirtualArray());
validateInitiatorData(initiator, exportGroup);
if (exportGroup.forCluster() || exportGroup.forHost()) {
if (!newHosts.isEmpty() && !newHosts.contains(initiator.getHost())) {
throw APIException.badRequests.invalidParameterExportGroupInitiatorNotInHost(initiator.getId());
}
}
if (!addedInitiators.contains(uri)) {
addedInitiators.add(uri);
}
}
}
}
validateInitiatorHostOS(addedInitiators);
List<URI> connectStorageSystems = new ArrayList<>();
newInitiators.addAll(addedInitiators);
newInitiators.removeAll(removedInitiators);
filterOutInitiatorsNotAssociatedWithVArray(exportGroup, storageSystems, connectStorageSystems, newInitiators);
// Validate if we're adding new Volumes to the export. If so, we want to make sure that there
// connections from the volumes to the StorageSystems. If the newInitiators list is empty, then
// it would mean that not all StorageSystems are connected to the initiators. In which case,
// the add volumes should fail. The user would need to make sure that the StorageSystem has
// the necessary connections before proceeding.
List<VolumeParam> addVolumeParams = param.getVolumes().getAdd();
if (exportGroup.hasInitiators() && !CollectionUtils.isEmpty(addVolumeParams) && CollectionUtils.isEmpty(newInitiators)) {
Set<URI> uniqueStorageSystemSet = new HashSet<>();
for (VolumeParam addVolumeParam : addVolumeParams) {
BlockObject blockObject = BlockObject.fetch(_dbClient, addVolumeParam.getId());
if (blockObject != null) {
uniqueStorageSystemSet.add(blockObject.getStorageController());
}
}
List<String> storageSystemNames = new ArrayList<>();
for (URI storageSystemURI : uniqueStorageSystemSet) {
// Check if it's in the list of connected StorageSystems. If so, then skip it.
if (connectStorageSystems.contains(storageSystemURI)) {
continue;
}
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemURI);
if (storageSystem != null) {
storageSystemNames.add(storageSystem.getNativeGuid());
}
}
throw APIException.badRequests.storageSystemsNotConnectedForAddVolumes(Joiner.on(',').join(storageSystemNames));
}
_log.info("Updated list of initiators: {}", Joiner.on(',').join(newInitiators));
}
use of com.emc.storageos.model.block.export.VolumeParam in project coprhd-controller by CoprHD.
the class ExportGroupService method validateBlockSnapshotsForExportGroupUpdate.
/**
* Validate the BlockSnapshot exports being added from the request param.
*
* @param param the export group update request param.
* @param exportGroup the existing export group being updated.
*/
private void validateBlockSnapshotsForExportGroupUpdate(ExportUpdateParam param, ExportGroup exportGroup) {
if (param != null && exportGroup != null) {
List<URI> blockObjToAdd = new ArrayList<URI>();
List<URI> blockObjExisting = new ArrayList<URI>();
List<URI> blockObjURIs = new ArrayList<URI>();
List<VolumeParam> addVolumeParams = param.getVolumes().getAdd();
// We only care about the BlockObjects we are adding, not removing
if (addVolumeParams != null && !addVolumeParams.isEmpty()) {
// Collect the block objects being added from the request param
for (VolumeParam volParam : addVolumeParams) {
blockObjToAdd.add(volParam.getId());
blockObjURIs.add(volParam.getId());
}
// Validate VPLEX backend snapshots for export.
validateVPLEXBlockSnapshotsForExport(blockObjURIs);
// easily through validation.
if (exportGroup.getVolumes() != null) {
for (Map.Entry<String, String> entry : exportGroup.getVolumes().entrySet()) {
URI uri = URI.create(entry.getKey());
blockObjURIs.add(uri);
blockObjExisting.add(uri);
}
}
// validate the RP BlockSnapshots for ExportGroup create
validateDuplicateRPBlockSnapshotsForExport(blockObjURIs);
}
// Validate any RP BlockSnapshots being added to ensure no corresponding target volumes
// have already been exported.
validateSnapshotTargetNotExported(blockObjToAdd, blockObjExisting);
}
}
use of com.emc.storageos.model.block.export.VolumeParam in project coprhd-controller by CoprHD.
the class ExportGroupService method updateExportGroup.
/**
* Update an export group which includes:
* <ol>
* <li>Add/Remove block objects (volumes, mirrors and snapshots)</li>
* <li>Add/remove clusters</li>
* <li>Add/remove hosts</li>
* <li>Add/remove initiators</li>
* </ol>
* Depending on the export group type (Initiator, Host or Cluster), the
* request is restricted to enforce the same rules as {@link #createExportGroup(ExportCreateParam)}:
* <ol>
* <li>For initiator type groups, only initiators are accepted in the request. Further the initiators must be in the same host as the
* existing initiators.</li>
* <li>For host type groups, only hosts and initiators that belong to existing hosts will be accepted.</li>
* <li>For cluster type groups, only clusters, hosts and initiators will be accepted. Hosts and initiators must belong to existing
* clusters and hosts.</li>
* </ol>
* <b>Note:</b> The export group name, project and varray can not be modified.
*
* @param id the URN of a ViPR export group to be updated
* @param param the request parameter
* @brief Update block export
* @return the update job tracking task id
* @throws ControllerException
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep updateExportGroup(@PathParam("id") URI id, ExportUpdateParam 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());
}
Project project = queryObject(Project.class, exportGroup.getProject().getURI(), true);
validateUpdateInputForExportType(param, exportGroup);
validateUpdateRemoveInitiators(param, exportGroup);
validateUpdateIsNotForVPlexBackendVolumes(param, exportGroup);
validateBlockSnapshotsForExportGroupUpdate(param, exportGroup);
validateExportGroupNoPendingEvents(exportGroup);
/**
* ExportGroup Add/Remove volume should have valid nativeId
*/
List<URI> boURIList = new ArrayList<>();
if (param.getVolumes() != null) {
if (param.getVolumes().getAdd() != null) {
for (VolumeParam volParam : param.getVolumes().getAdd()) {
boURIList.add(volParam.getId());
}
}
if (param.getVolumes().getRemove() != null) {
for (URI volURI : param.getVolumes().getRemove()) {
boURIList.add(volURI);
}
validateVolumesNotMounted(exportGroup, param.getVolumes().getRemove());
}
}
validateBlockObjectNativeId(boURIList);
if (param.getExportPathParameters() != null) {
// Only [RESTRICTED_]SYSTEM_ADMIN may override the Vpool export parameters
ExportPathParameters pathParam = param.getExportPathParameters();
if ((pathParam.getMaxPaths() != null || pathParam.getMinPaths() != null || pathParam.getPathsPerInitiator() != null) && !_permissionsHelper.userHasGivenRole(getUserFromContext(), null, Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN)) {
throw APIException.forbidden.onlySystemAdminsCanOverrideVpoolPathParameters(exportGroup.getLabel());
}
}
// call the controller to handle all updated
String task = UUID.randomUUID().toString();
Operation op = initTaskStatus(exportGroup, task, Operation.Status.pending, ResourceOperationTypeEnum.UPDATE_EXPORT_GROUP);
// persist the export group to the database
_dbClient.persistObject(exportGroup);
auditOp(OperationTypeEnum.UPDATE_EXPORT_GROUP, true, AuditLogManager.AUDITOP_BEGIN, exportGroup.getLabel(), exportGroup.getId().toString(), exportGroup.getVirtualArray().toString(), exportGroup.getProject().toString());
TaskResourceRep taskRes = toTask(exportGroup, task, op);
CreateExportGroupUpdateSchedulingThread.executeApiTask(this, _asyncTaskService.getExecutorService(), _dbClient, project, exportGroup, param, task, taskRes);
_log.info("Kicked off thread to perform export update scheduling. Returning task: " + taskRes.getId());
return taskRes;
}
use of com.emc.storageos.model.block.export.VolumeParam in project coprhd-controller by CoprHD.
the class AddHostAndVolumeToExportNoWait method doExecute.
@Override
protected Task<ExportGroupRestRep> doExecute() throws Exception {
ExportUpdateParam exportUpdateParam = new ExportUpdateParam();
List<VolumeParam> volumes = new ArrayList<VolumeParam>();
if (!NullColumnValueGetter.isNullURI(volumeId)) {
VolumeParam volume = new VolumeParam(volumeId);
volume.setLun(-1);
if (hlu != null && !hlu.equals(ExportVMwareBlockVolumeHelper.USE_EXISTING_HLU)) {
volume.setLun(hlu);
}
volumes.add(volume);
exportUpdateParam.setVolumes(new VolumeUpdateParam(volumes, new ArrayList<URI>()));
}
if (!NullColumnValueGetter.isNullURI(hostId)) {
exportUpdateParam.setHosts(new HostsUpdateParam());
exportUpdateParam.getHosts().getAdd().add(hostId);
}
if (!NullColumnValueGetter.isNullURI(portGroup)) {
ExportPathParameters exportPathParameters = new ExportPathParameters();
exportPathParameters.setPortGroup(portGroup);
exportUpdateParam.setExportPathParameters(exportPathParameters);
}
return getClient().blockExports().update(exportId, exportUpdateParam);
}
use of com.emc.storageos.model.block.export.VolumeParam in project coprhd-controller by CoprHD.
the class AddVolumesToExport method doExecute.
@Override
protected Task<ExportGroupRestRep> doExecute() throws Exception {
ExportUpdateParam export = new ExportUpdateParam();
List<VolumeParam> volumes = new ArrayList<VolumeParam>();
Integer currentHlu = hlu;
for (URI volumeId : volumeIds) {
VolumeParam volume = new VolumeParam(volumeId);
if (currentHlu != null) {
if (currentHlu.equals(ExportVMwareBlockVolumeHelper.USE_EXISTING_HLU) && volumeHlus != null) {
Integer volumeHlu = volumeHlus.get(volume.getId());
if (volumeHlu == null) {
volume.setLun(-1);
} else {
volume.setLun(volumeHlu);
}
} else {
volume.setLun(currentHlu);
}
}
if ((currentHlu != null) && (currentHlu > -1)) {
currentHlu++;
}
volumes.add(volume);
}
export.setVolumes(new VolumeUpdateParam(volumes, new ArrayList<URI>()));
// Only add the export path parameters to the call if we have to
boolean addExportPathParameters = false;
ExportPathParameters exportPathParameters = new ExportPathParameters();
if (minPaths != null && maxPaths != null && pathsPerInitiator != null) {
exportPathParameters.setMinPaths(minPaths);
exportPathParameters.setMaxPaths(maxPaths);
exportPathParameters.setPathsPerInitiator(pathsPerInitiator);
addExportPathParameters = true;
}
if (portGroup != null) {
exportPathParameters.setPortGroup(portGroup);
addExportPathParameters = true;
}
if (addExportPathParameters) {
export.setExportPathParameters(exportPathParameters);
}
return getClient().blockExports().update(exportId, export);
}
Aggregations