Skip to content

Commit

Permalink
Use Rawls for bucket location
Browse files Browse the repository at this point in the history
rp fixes
  • Loading branch information
trholdridge committed Nov 15, 2024
1 parent aff5975 commit f094494
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/libs/ajax/GoogleStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const checkRequesterPaysError = async (response): Promise<RequesterPaysErrorInfo
};

export const responseContainsRequesterPaysError = (responseText) => {
return _.includes('requester pays', responseText);
return _.includes('to user project', responseText);
};

// requesterPaysError may be set on responses from requests to the GCS API that are wrapped in withRequesterPays.
Expand Down
10 changes: 9 additions & 1 deletion src/libs/ajax/workspaces/Workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { jsonBody } from '@terra-ui-packages/data-client-core';
import _ from 'lodash/fp';
import * as qs from 'qs';
import { authOpts } from 'src/auth/auth-session';
import { getLocationType } from 'src/components/region-common';
import { fetchOrchestration, fetchRawls } from 'src/libs/ajax/ajax-common';
import { Entity, EntityQueryResponse } from 'src/libs/ajax/data-table-providers/DataTableProvider';
import { fetchOk } from 'src/libs/ajax/fetch/fetch-core';
Expand Down Expand Up @@ -173,7 +174,14 @@ export const Workspaces = (signal?: AbortSignal) => ({

checkBucketAccess: GoogleStorage(signal).checkBucketAccess,

checkBucketLocation: GoogleStorage(signal).checkBucketLocation,
checkBucketLocation: async (userProject?) => {
const res = await fetchRawls(
`${root}/bucketOptions${userProject ? `?userProject=${userProject}` : ''}`,
_.merge(authOpts(), { signal })
);
const obj = await res.json();
return _.merge(obj, { locationType: getLocationType(obj.location) });
},

details: async (fields: FieldsArg): Promise<WorkspaceWrapper> => {
const res = await fetchRawls(
Expand Down
8 changes: 4 additions & 4 deletions src/workspaces/common/state/useWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type { InitializedWorkspaceWrapper } from 'src/libs/state';
export interface StorageDetails {
googleBucketLocation: string; // historically returns defaultLocation if bucket location cannot be retrieved or Azure
googleBucketType: string; // historically returns locationTypes.default if bucket type cannot be retrieved or Azure
fetchedGoogleBucketLocation: 'SUCCESS' | 'ERROR' | undefined; // undefined: still fetching
fetchedGoogleBucketLocation: 'SUCCESS' | 'ERROR' | 'RPERROR' | undefined; // undefined: still fetching
azureContainerRegion?: string;
azureContainerUrl?: string;
azureContainerSasUrl?: string;
Expand All @@ -46,7 +46,7 @@ export const useWorkspace = (namespace, name): WorkspaceDetails => {
const workspace = useStore(workspaceStore);

const [{ location, locationType, fetchedLocation }, setGoogleStorage] = useState<{
fetchedLocation: 'SUCCESS' | 'ERROR' | undefined;
fetchedLocation: 'SUCCESS' | 'ERROR' | 'RPERROR' | undefined;
location: string;
locationType: string;
}>({
Expand Down Expand Up @@ -115,7 +115,7 @@ export const useWorkspace = (namespace, name): WorkspaceDetails => {
if (responseContainsRequesterPaysError(errorText)) {
// loadGoogleBucketLocation will not get called in this case because checkBucketReadAccess fails first,
// but it would also fail with the requester pays error.
setGoogleStorage({ fetchedLocation: 'ERROR', location, locationType });
setGoogleStorage({ fetchedLocation: 'RPERROR', location, locationType });
updateWorkspaceInStore(workspace, true);
} else {
updateWorkspaceInStore(workspace, false);
Expand Down Expand Up @@ -145,7 +145,7 @@ export const useWorkspace = (namespace, name): WorkspaceDetails => {
try {
const storageDetails = await Workspaces(signal)
.workspace(namespace, name)
.checkBucketLocation(workspace.workspace.googleProject, workspace.workspace.bucketName);
.checkBucketLocation(workspace.workspace.googleProject);
storageDetails.fetchedLocation = 'SUCCESS';
setGoogleStorage(storageDetails);
} catch (error) {
Expand Down
26 changes: 14 additions & 12 deletions src/workspaces/dashboard/BucketLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import { getRegionInfo } from 'src/components/region-common';
import { TooltipCell } from 'src/components/table';
import { Metrics } from 'src/libs/ajax/Metrics';
import { Workspaces } from 'src/libs/ajax/workspaces/Workspaces';
import { reportError } from 'src/libs/error';
import Events, { extractWorkspaceDetails } from 'src/libs/events';
import { useCancellation } from 'src/libs/react-utils';
import { requesterPaysProjectStore } from 'src/libs/state';
import { isBucketErrorRequesterPays, requesterPaysWrapper } from 'src/workspaces/common/requester-pays/bucket-utils';
import { requesterPaysWrapper } from 'src/workspaces/common/requester-pays/bucket-utils';
import { RequesterPaysModal } from 'src/workspaces/common/requester-pays/RequesterPaysModal';
import { StorageDetails } from 'src/workspaces/common/state/useWorkspace';
import { GoogleWorkspace } from 'src/workspaces/utils';
Expand All @@ -36,22 +35,21 @@ export const BucketLocation = requesterPaysWrapper({ onDismiss: _.noop })((props
setLoading(true);
try {
const {
workspace: { namespace, name, googleProject, bucketName },
workspace: { namespace, name, googleProject },
} = workspace;
const response = await Workspaces(signal)
.workspace(namespace, name)
.checkBucketLocation(googleProject, bucketName);
const project = needsRequesterPaysProject ? requesterPaysProjectStore.get() : googleProject;
const response = await Workspaces(signal).workspace(namespace, name).checkBucketLocation(project);
setBucketLocation(response);
} catch (error) {
if (isBucketErrorRequesterPays(error)) {
setNeedsRequesterPaysProject(true);
} else {
reportError('Unable to get bucket location.', error);
}
// if (error) {
setNeedsRequesterPaysProject(true);
// } else {
// reportError('Unable to get bucket location.', error);
// }
} finally {
setLoading(false);
}
}, [workspace, signal]);
}, [workspace, signal, needsRequesterPaysProject]);

useEffect(() => {
if (workspace?.workspaceInitialized) {
Expand All @@ -60,6 +58,9 @@ export const BucketLocation = requesterPaysWrapper({ onDismiss: _.noop })((props
// while storageDetails.googleBucketLocation will contain the default value.
// In the case of requester pays workspaces, we wish to show the user more information in this case and allow them to link a workspace.
loadGoogleBucketLocation();
} else if (storageDetails.fetchedGoogleBucketLocation === 'RPERROR') {
setNeedsRequesterPaysProject(true);
setLoading(false);
} else if (storageDetails.fetchedGoogleBucketLocation === 'SUCCESS') {
setBucketLocation({
location: storageDetails.googleBucketLocation,
Expand All @@ -71,6 +72,7 @@ export const BucketLocation = requesterPaysWrapper({ onDismiss: _.noop })((props
}, [
loadGoogleBucketLocation,
setBucketLocation,
needsRequesterPaysProject,
// Explicit dependencies to avoid extra calls to loadGoogleBucketLocation
workspace?.workspaceInitialized,
storageDetails.fetchedGoogleBucketLocation,
Expand Down

0 comments on commit f094494

Please sign in to comment.