1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { dialogActions } from '~/store/dialog/dialog-actions';
6 import { RootState } from '~/store/store';
7 import { Dispatch } from 'redux';
8 import { ResourceKind, extractUuidKind } from '~/models/resource';
9 import { getResource } from '~/store/resources/resources';
10 import { GroupContentsResourcePrefix } from '~/services/groups-service/groups-service';
11 import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
12 import { ContainerRequestResource } from '~/models/container-request';
13 import { CollectionResource } from '~/models/collection';
14 import { ProjectResource } from '~/models/project';
15 import { ServiceRepository } from '~/services/services';
16 import { FilterBuilder } from '~/services/api/filter-builder';
18 export const ADVANCED_TAB_DIALOG = 'advancedTabDialog';
20 export interface AdvancedTabDialogData {
24 pythonExample: string;
26 cliGetExample: string;
27 cliUpdateHeader: string;
28 cliUpdateExample: string;
34 COLLECTION = 'collection',
35 STORAGE_CLASSES_CONFIRMED = 'storage_classes_confirmed'
39 CONTAINER_REQUEST = 'container_request',
40 OUTPUT_NAME = 'output_name'
45 DELETE_AT = 'delete_at'
48 export const openAdvancedTabDialog = (uuid: string) =>
49 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
50 const { resources } = getState();
51 const kind = extractUuidKind(uuid);
52 const data = getResource<any>(uuid)(resources);
53 const metadata = await services.linkService.list({
54 filters: new FilterBuilder()
55 .addEqual('headUuid', uuid)
59 if (kind === ResourceKind.COLLECTION) {
60 const dataCollection: AdvancedTabDialogData = {
61 apiResponse: collectionApiResponse(data),
63 pythonHeader: pythonHeader(CollectionData.COLLECTION),
64 pythonExample: pythonExample(data.uuid, GroupContentsResourcePrefix.COLLECTION),
65 cliGetHeader: cliGetHeader(CollectionData.COLLECTION),
66 cliGetExample: cliGetExample(data.uuid, GroupContentsResourcePrefix.COLLECTION),
67 cliUpdateHeader: cliUpdateHeader(CollectionData.COLLECTION, CollectionData.STORAGE_CLASSES_CONFIRMED),
68 cliUpdateExample: cliUpdateExample(data.uuid, CollectionData.COLLECTION, data.storageClassesConfirmed, CollectionData.STORAGE_CLASSES_CONFIRMED),
69 curlHeader: curlHeader(CollectionData.COLLECTION, CollectionData.STORAGE_CLASSES_CONFIRMED),
70 curlExample: curlExample(data.uuid, GroupContentsResourcePrefix.COLLECTION, data.storageClassesConfirmed, CollectionData.COLLECTION, CollectionData.STORAGE_CLASSES_CONFIRMED)
72 dispatch(dialogActions.OPEN_DIALOG({ id: ADVANCED_TAB_DIALOG, data: dataCollection }));
73 } else if (kind === ResourceKind.PROCESS) {
74 const dataProcess: AdvancedTabDialogData = {
75 apiResponse: containerRequestApiResponse(data),
77 pythonHeader: pythonHeader(ProcessData.CONTAINER_REQUEST),
78 pythonExample: pythonExample(data.uuid, GroupContentsResourcePrefix.PROCESS),
79 cliGetHeader: cliGetHeader(ProcessData.CONTAINER_REQUEST),
80 cliGetExample: cliGetExample(data.uuid, GroupContentsResourcePrefix.PROCESS),
81 cliUpdateHeader: cliUpdateHeader(ProcessData.CONTAINER_REQUEST, ProcessData.OUTPUT_NAME),
82 cliUpdateExample: cliUpdateExample(data.uuid, ProcessData.CONTAINER_REQUEST, data.outputName, ProcessData.OUTPUT_NAME),
83 curlHeader: curlHeader(ProcessData.CONTAINER_REQUEST, ProcessData.OUTPUT_NAME),
84 curlExample: curlExample(data.uuid, GroupContentsResourcePrefix.PROCESS, data.outputName, ProcessData.CONTAINER_REQUEST, ProcessData.OUTPUT_NAME)
86 dispatch(dialogActions.OPEN_DIALOG({ id: ADVANCED_TAB_DIALOG, data: dataProcess }));
87 } else if (kind === ResourceKind.PROJECT) {
88 const dataProject: AdvancedTabDialogData = {
89 apiResponse: groupRequestApiResponse(data),
91 pythonHeader: pythonHeader(ProjectData.GROUP),
92 pythonExample: pythonExample(data.uuid, GroupContentsResourcePrefix.PROJECT),
93 cliGetHeader: cliGetHeader(ProjectData.GROUP),
94 cliGetExample: cliGetExample(data.uuid, GroupContentsResourcePrefix.PROJECT),
95 cliUpdateHeader: cliUpdateHeader(ProjectData.GROUP, ProjectData.DELETE_AT),
96 cliUpdateExample: cliUpdateExample(data.uuid, ProjectData.GROUP, data.deleteAt, ProjectData.DELETE_AT),
97 curlHeader: curlHeader(ProjectData.GROUP, ProjectData.DELETE_AT),
98 curlExample: curlExample(data.uuid, GroupContentsResourcePrefix.PROJECT, data.deleteAt, ProjectData.GROUP, ProjectData.DELETE_AT)
100 dispatch(dialogActions.OPEN_DIALOG({ id: ADVANCED_TAB_DIALOG, data: dataProject }));
103 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Could not open advanced tab for this resource.", hideDuration: 2000, kind: SnackbarKind.ERROR }));
107 const pythonHeader = (resourceKind: string) =>
108 `An example python command to get a ${resourceKind} using its uuid:`;
110 const pythonExample = (uuid: string, resourcePrefix: string) => {
111 const pythonExample = `import arvados
113 x = arvados.api().${resourcePrefix}().get(uuid='${uuid}').execute()`;
115 return pythonExample;
118 const cliGetHeader = (resourceKind: string) =>
119 `An example arv command to get a ${resourceKind} using its uuid:`;
121 const cliGetExample = (uuid: string, resourcePrefix: string) => {
122 const cliGetExample = `arv ${resourcePrefix} get \\
125 return cliGetExample;
128 const cliUpdateHeader = (resourceKind: string, resourceName: string) =>
129 `An example arv command to update the "${resourceName}" attribute for the current ${resourceKind}:`;
131 const cliUpdateExample = (uuid: string, resourceKind: string, resource: string | string[], resourceName: string) => {
132 const CLIUpdateCollectionExample = `arv ${resourceKind} update \\
134 --${resourceKind} '{"${resourceName}":${resource}}'`;
136 return CLIUpdateCollectionExample;
139 const curlHeader = (resourceKind: string, resource: string) =>
140 `An example curl command to update the "${resource}" attribute for the current ${resourceKind}:`;
142 const curlExample = (uuid: string, resourcePrefix: string, resource: string | string[], resourceKind: string, resourceName: string) => {
143 const curlExample = `curl -X PUT \\
144 -H "Authorization: OAuth2 $ARVADOS_API_TOKEN" \\
145 --data-urlencode ${resourceKind}@/dev/stdin \\
146 https://$ARVADOS_API_HOST/arvados/v1/${resourcePrefix}/${uuid} \\
149 "${resourceName}": ${resource}
156 const stringify = (item: string | null | number | boolean) =>
157 JSON.stringify(item) || 'null';
159 const stringifyObject = (item: any) =>
160 JSON.stringify(item, null, 2) || 'null';
162 const containerRequestApiResponse = (apiResponse: ContainerRequestResource) => {
163 const { uuid, ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid, name, description, properties, state, requestingContainerUuid, containerUuid,
164 containerCountMax, mounts, runtimeConstraints, containerImage, environment, cwd, command, outputPath, priority, expiresAt, filters, containerCount,
165 useExisting, schedulingParameters, outputUuid, logUuid, outputName, outputTtl } = apiResponse;
166 const response = `"uuid": "${uuid}",
167 "owner_uuid": "${ownerUuid}",
168 "created_at": "${createdAt}",
169 "modified_at": ${stringify(modifiedAt)},
170 "modified_by_client_uuid": ${stringify(modifiedByClientUuid)},
171 "modified_by_user_uuid": ${stringify(modifiedByUserUuid)},
172 "name": ${stringify(name)},
173 "description": ${stringify(description)},
174 "properties": ${stringifyObject(properties)},
175 "state": ${stringify(state)},
176 "requesting_container_uuid": ${stringify(requestingContainerUuid)},
177 "container_uuid": ${stringify(containerUuid)},
178 "container_count_max": ${stringify(containerCountMax)},
179 "mounts": ${stringifyObject(mounts)},
180 "runtime_constraints": ${stringifyObject(runtimeConstraints)},
181 "container_image": "${stringify(containerImage)}",
182 "environment": ${stringifyObject(environment)},
183 "cwd": ${stringify(cwd)},
184 "command": ${stringifyObject(command)},
185 "output_path": ${stringify(outputPath)},
186 "priority": ${stringify(priority)},
187 "expires_at": ${stringify(expiresAt)},
188 "filters": ${stringify(filters)},
189 "container_count": ${stringify(containerCount)},
190 "use_existing": ${stringify(useExisting)},
191 "scheduling_parameters": ${stringifyObject(schedulingParameters)},
192 "output_uuid": ${stringify(outputUuid)},
193 "log_uuid": ${stringify(logUuid)},
194 "output_name": ${stringify(outputName)},
195 "output_ttl": ${stringify(outputTtl)}`;
200 const collectionApiResponse = (apiResponse: CollectionResource) => {
201 const { uuid, ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid, name, description, properties, portableDataHash, replicationDesired,
202 replicationConfirmedAt, replicationConfirmed, manifestText, deleteAt, trashAt, isTrashed, storageClassesDesired,
203 storageClassesConfirmed, storageClassesConfirmedAt } = apiResponse;
204 const response = `"uuid": "${uuid}",
205 "owner_uuid": "${ownerUuid}",
206 "created_at": "${createdAt}",
207 "modified_by_client_uuid": ${stringify(modifiedByClientUuid)},
208 "modified_by_user_uuid": ${stringify(modifiedByUserUuid)},
209 "modified_at": ${stringify(modifiedAt)},
210 "portable_data_hash": ${stringify(portableDataHash)},
211 "replication_desired": ${stringify(replicationDesired)},
212 "replication_confirmed_at": ${stringify(replicationConfirmedAt)},
213 "replication_confirmed": ${stringify(replicationConfirmed)},
214 "manifest_text": ${stringify(manifestText)},
215 "name": ${stringify(name)},
216 "description": ${stringify(description)},
217 "properties": ${stringifyObject(properties)},
218 "delete_at": ${stringify(deleteAt)},
219 "trash_at": ${stringify(trashAt)},
220 "is_trashed": ${stringify(isTrashed)},
221 "storage_classes_desired": ${JSON.stringify(storageClassesDesired, null, 2)},
222 "storage_classes_confirmed": ${JSON.stringify(storageClassesConfirmed, null, 2)},
223 "storage_classes_confirmed_at": ${stringify(storageClassesConfirmedAt)}`;
228 const groupRequestApiResponse = (apiResponse: ProjectResource) => {
229 const { uuid, ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid, name, description, groupClass, trashAt, isTrashed, deleteAt, properties } = apiResponse;
230 const response = `"uuid": "${uuid}",
231 "owner_uuid": "${ownerUuid}",
232 "created_at": "${createdAt}",
233 "modified_by_client_uuid": ${stringify(modifiedByClientUuid)},
234 "modified_by_user_uuid": ${stringify(modifiedByUserUuid)},
235 "modified_at": ${stringify(modifiedAt)},
236 "name": ${stringify(name)},
237 "description": ${stringify(description)},
238 "group_class": ${stringify(groupClass)},
239 "trash_at": ${stringify(trashAt)},
240 "is_trashed": ${stringify(isTrashed)},
241 "delete_at": ${stringify(deleteAt)},
242 "properties": ${stringifyObject(properties)}`;