go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/common/services/swarming.ts (about)

     1  // Copyright 2023 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  /**
    16   * Manually coded type definition and classes for swarming services.
    17   * source: https://chromium.googlesource.com/infra/luci/luci-py/+/HEAD/appengine/swarming/proto/api_v2/swarming.proto
    18   */
    19  
    20  import { StringPair } from '@/common/services/common';
    21  import { PrpcClientExt } from '@/generic_libs/tools/prpc_client_ext';
    22  
    23  export const enum NullableBool {
    24    Null = 'NULL',
    25    False = 'FALSE',
    26    TRUE = 'TRUE',
    27  }
    28  
    29  export interface BotsRequest {
    30    readonly limit: number;
    31    readonly cursor?: string;
    32    readonly dimensions?: readonly StringPair[];
    33    readonly quarantined?: NullableBool;
    34    readonly isDead?: NullableBool;
    35    readonly isBusy?: NullableBool;
    36  }
    37  
    38  export interface BotInfo {
    39    readonly botId: string;
    40    readonly taskId?: string;
    41    readonly externalIp: string;
    42    readonly authenticatedAs: string;
    43    readonly firstSeenTs: string;
    44    readonly isDead: boolean;
    45    readonly lastSeenTs: string;
    46    readonly quarantined: boolean;
    47    readonly maintenanceMsg?: string;
    48    readonly dimensions: readonly StringPair[];
    49    readonly taskName: string;
    50    readonly version: string;
    51    readonly state: string;
    52    readonly deleted: boolean;
    53  }
    54  
    55  export interface BotInfoListResponse {
    56    readonly cursor?: string;
    57    readonly items?: readonly BotInfo[];
    58    readonly now: string;
    59    readonly deathTimeout: number;
    60  }
    61  
    62  export class BotsService {
    63    static readonly SERVICE = 'swarming.v2.Bots';
    64  
    65    private readonly callFn: (
    66      method: string,
    67      message: object,
    68    ) => Promise<unknown>;
    69  
    70    constructor(client: PrpcClientExt) {
    71      this.callFn = (method: string, message: object) =>
    72        client.call(BotsService.SERVICE, method, message);
    73    }
    74  
    75    async listBots(req: BotsRequest) {
    76      return (await this.callFn('ListBots', req)) as BotInfoListResponse;
    77    }
    78  }
    79  
    80  export interface TaskIdRequest {
    81    readonly taskId: string;
    82  }
    83  
    84  export interface TaskRequestResponse {
    85    readonly tags?: readonly string[];
    86  }
    87  
    88  export class TasksServices {
    89    static readonly SERVICE = 'swarming.v2.Tasks';
    90  
    91    private readonly callFn: (
    92      method: string,
    93      message: object,
    94    ) => Promise<unknown>;
    95  
    96    constructor(client: PrpcClientExt) {
    97      this.callFn = (method: string, message: object) =>
    98        client.call(TasksServices.SERVICE, method, message);
    99    }
   100  
   101    async getRequest(req: TaskIdRequest) {
   102      return (await this.callFn('GetRequest', req)) as TaskRequestResponse;
   103    }
   104  }