import {z} from 'zod' export type GetApiV1ProjectsProjectsIdLocationsLocationsIdSessionsSessionsIdSparkApplicationsSparkApplicationsIdAccessJobArgs = {projectsId: string, locationsId: string, sessionsId: string, sparkApplicationsId: string, jobId?: unknown | undefined, parent?: string | undefined}; export type GetApiV1ProjectsProjectsIdLocationsLocationsIdSessionsSessionsIdSparkApplicationsSparkApplicationsIdAccessJobOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const jobData = z.object({completionTime: z.string().optional(), description: z.string().optional(), jobGroup: z.string().optional(), jobId: z.string().optional(), killTasksSummary: z.record(z.string(), z.number().int()).optional(), name: z.string().optional(), numActiveStages: z.number().int().optional(), numActiveTasks: z.number().int().optional(), numCompletedIndices: z.number().int().optional(), numCompletedStages: z.number().int().optional(), numCompletedTasks: z.number().int().optional(), numFailedStages: z.number().int().optional(), numFailedTasks: z.number().int().optional(), numKilledTasks: z.number().int().optional(), numSkippedStages: z.number().int().optional(), numSkippedTasks: z.number().int().optional(), numTasks: z.number().int().optional(), skippedStages: z.array(z.number().int()).optional(), sqlExecutionId: z.string().optional(), stageIds: z.array(z.string()).optional(), status: z.enum(["JOB_EXECUTION_STATUS_UNSPECIFIED", "JOB_EXECUTION_STATUS_RUNNING", "JOB_EXECUTION_STATUS_SUCCEEDED", "JOB_EXECUTION_STATUS_FAILED", "JOB_EXECUTION_STATUS_UNKNOWN"]).optional(), submissionTime: z.string().optional()}); export const accessSessionSparkApplicationJobResponse = z.object({jobData: jobData.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Obtain data corresponding to a spark job for a Spark Application. * * GET /v1/projects/{projectsId}/locations/{locationsId}/sessions/{sessionsId}/sparkApplications/{sparkApplicationsId}:accessJob * * Also accepts auth: Oauth2 + Oauth2c, Oauth2 + Oauth2c */ export const getApiV1ProjectsProjectsIdLocationsLocationsIdSessionsSessionsIdSparkApplicationsSparkApplicationsIdAccessJob = async (args: GetApiV1ProjectsProjectsIdLocationsLocationsIdSessionsSessionsIdSparkApplicationsSparkApplicationsIdAccessJobArgs, options?: GetApiV1ProjectsProjectsIdLocationsLocationsIdSessionsSessionsIdSparkApplicationsSparkApplicationsIdAccessJobOptions) => { const {baseUrl = "https://dataproc.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.jobId != null) query.append("jobId", String(args.jobId)) if (args.parent != null) query.append("parent", String(args.parent)) if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectsId))}/locations/${encodeURIComponent(String(args.locationsId))}/sessions/${encodeURIComponent(String(args.sessionsId))}/sparkApplications/${encodeURIComponent(String(args.sparkApplicationsId))}:accessJob${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(accessSessionSparkApplicationJobResponse, await res.json()) };