import {z} from 'zod' export type GetApiV1ProjectsProjectsIdLocationsLocationsIdBatchesBatchesIdSparkApplicationsSparkApplicationsIdSearchJobsArgs = {projectsId: string, locationsId: string, batchesId: string, sparkApplicationsId: string, jobStatus?: ('JOB_EXECUTION_STATUS_UNSPECIFIED' | 'JOB_EXECUTION_STATUS_RUNNING' | 'JOB_EXECUTION_STATUS_SUCCEEDED' | 'JOB_EXECUTION_STATUS_FAILED' | 'JOB_EXECUTION_STATUS_UNKNOWN') | undefined, pageSize?: number | undefined, pageToken?: string | undefined, parent?: string | undefined}; export type GetApiV1ProjectsProjectsIdLocationsLocationsIdBatchesBatchesIdSparkApplicationsSparkApplicationsIdSearchJobsOptions = {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 searchSparkApplicationJobsResponse = z.object({nextPageToken: z.string().optional(), sparkApplicationJobs: z.array(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 list of spark jobs corresponding to a Spark Application. * * GET /v1/projects/{projectsId}/locations/{locationsId}/batches/{batchesId}/sparkApplications/{sparkApplicationsId}:searchJobs * * Also accepts auth: Oauth2 + Oauth2c, Oauth2 + Oauth2c */ export const getApiV1ProjectsProjectsIdLocationsLocationsIdBatchesBatchesIdSparkApplicationsSparkApplicationsIdSearchJobs = async (args: GetApiV1ProjectsProjectsIdLocationsLocationsIdBatchesBatchesIdSparkApplicationsSparkApplicationsIdSearchJobsArgs, options?: GetApiV1ProjectsProjectsIdLocationsLocationsIdBatchesBatchesIdSparkApplicationsSparkApplicationsIdSearchJobsOptions) => { 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.jobStatus != null) query.append("jobStatus", String(args.jobStatus)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) 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))}/batches/${encodeURIComponent(String(args.batchesId))}/sparkApplications/${encodeURIComponent(String(args.sparkApplicationsId))}:searchJobs${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(searchSparkApplicationJobsResponse, await res.json()) };