| OLD | NEW |
| 1 /* | 1 /* |
| 2 Copyright 2016 The LUCI Authors. All rights reserved. | 2 Copyright 2016 The LUCI Authors. All rights reserved. |
| 3 Use of this source code is governed under the Apache License, Version 2.0 | 3 Use of this source code is governed under the Apache License, Version 2.0 |
| 4 that can be found in the LICENSE file. | 4 that can be found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 ///<reference path="logdog.ts" /> | 7 ///<reference path="logdog.ts" /> |
| 8 ///<reference path="../rpc/client.ts" /> | 8 ///<reference path="../rpc/client.ts" /> |
| 9 ///<reference path="../luci-operation/operation.ts" /> |
| 9 | 10 |
| 10 namespace LogDog { | 11 namespace LogDog { |
| 11 | 12 |
| 12 export type GetRequest = { | 13 export type GetRequest = { |
| 13 project: string; path: string; state: boolean; index: number; | 14 project: string; path: string; state: boolean; index: number; |
| 14 | 15 |
| 15 nonContiguous?: boolean; | 16 nonContiguous?: boolean; |
| 16 byteCount?: number; | 17 byteCount?: number; |
| 17 logCount?: number; | 18 logCount?: number; |
| 18 }; | 19 }; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 38 stream: LogDog.StreamPath; state?: LogDog.LogStreamState; | 39 stream: LogDog.StreamPath; state?: LogDog.LogStreamState; |
| 39 desc?: LogDog.LogStreamDescriptor; | 40 desc?: LogDog.LogStreamDescriptor; |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 export class Client { | 43 export class Client { |
| 43 debug = false; | 44 debug = false; |
| 44 | 45 |
| 45 constructor(private client: luci.Client) {} | 46 constructor(private client: luci.Client) {} |
| 46 | 47 |
| 47 /** Get executes a Get RPC. */ | 48 /** Get executes a Get RPC. */ |
| 48 async get(req: GetRequest): Promise<GetResponse> { | 49 async get(op: luci.Operation, req: GetRequest): Promise<GetResponse> { |
| 49 if (this.debug) { | 50 if (this.debug) { |
| 50 console.log('logdog.Logs.Get:', req); | 51 console.log('logdog.Logs.Get:', req); |
| 51 } | 52 } |
| 52 return this.client.call('logdog.Logs', 'Get', req); | 53 return this.client.callOp(op, 'logdog.Logs', 'Get', req); |
| 53 } | 54 } |
| 54 | 55 |
| 55 /** Tail executes a Tail RPC. */ | 56 /** Tail executes a Tail RPC. */ |
| 56 async tail(stream: StreamPath, state: boolean): Promise<GetResponse> { | 57 async tail(op: luci.Operation, stream: StreamPath, state: boolean): |
| 58 Promise<GetResponse> { |
| 57 let request: TailRequest = { | 59 let request: TailRequest = { |
| 58 project: stream.project, | 60 project: stream.project, |
| 59 path: stream.path, | 61 path: stream.path, |
| 60 state: state, | 62 state: state, |
| 61 }; | 63 }; |
| 62 | 64 |
| 63 if (this.debug) { | 65 if (this.debug) { |
| 64 console.log('logdog.Logs.Tail:', request); | 66 console.log('logdog.Logs.Tail:', request); |
| 65 } | 67 } |
| 66 return this.client.call('logdog.Logs', 'Tail', request); | 68 return this.client.callOp(op, 'logdog.Logs', 'Tail', request); |
| 67 } | 69 } |
| 68 | 70 |
| 69 /** | 71 /** |
| 70 * Query executes a Query RPC. | 72 * Query executes a Query RPC. |
| 71 * | 73 * |
| 72 * @param params The query request parameters. | 74 * @param params The query request parameters. |
| 73 * @param cursor The cursor to supply. Can be empty for no cursor. | 75 * @param cursor The cursor to supply. Can be empty for no cursor. |
| 74 * @param limit The maximum number of query results to return. | 76 * @param limit The maximum number of query results to return. |
| 75 * | 77 * |
| 76 * @return a Promise that resolves to the query results and continuation | 78 * @return a Promise that resolves to the query results and continuation |
| 77 * cursor. The cursor may be empty if the query finished. | 79 * cursor. The cursor may be empty if the query finished. |
| 78 */ | 80 */ |
| 79 async query(params: QueryRequest, cursor = '', limit = 0): | 81 async query( |
| 80 Promise<[QueryResult[], string]> { | 82 op: luci.Operation, params: QueryRequest, cursor = '', |
| 83 limit = 0): Promise<[QueryResult[], string]> { |
| 81 let project = params.project; | 84 let project = params.project; |
| 82 let body: any = { | 85 let body: any = { |
| 83 project: project, | 86 project: project, |
| 84 path: params.path, | 87 path: params.path, |
| 85 content_type: params.contentType, | 88 content_type: params.contentType, |
| 86 proto_version: params.protoVersion, | 89 proto_version: params.protoVersion, |
| 87 tags: params.tags, | 90 tags: params.tags, |
| 88 | 91 |
| 89 next: cursor, | 92 next: cursor, |
| 90 max_results: limit, | 93 max_results: limit, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 109 | 112 |
| 110 type responseType = { | 113 type responseType = { |
| 111 streams: { | 114 streams: { |
| 112 path: string, | 115 path: string, |
| 113 state: any, | 116 state: any, |
| 114 desc: any, | 117 desc: any, |
| 115 }[]; | 118 }[]; |
| 116 next: string; | 119 next: string; |
| 117 }; | 120 }; |
| 118 let resp: responseType = | 121 let resp: responseType = |
| 119 await this.client.call('logdog.Logs', 'Query', body); | 122 await this.client.callOp(op, 'logdog.Logs', 'Query', body); |
| 120 | 123 |
| 121 // Package the response in QueryResults. | 124 // Package the response in QueryResults. |
| 122 let results = (resp.streams || []).map(entry => { | 125 let results = (resp.streams || []).map(entry => { |
| 123 let res: QueryResult = { | 126 let res: QueryResult = { |
| 124 stream: new LogDog.StreamPath(project, entry.path), | 127 stream: new LogDog.StreamPath(project, entry.path), |
| 125 }; | 128 }; |
| 126 if (entry.state) { | 129 if (entry.state) { |
| 127 res.state = LogDog.LogStreamState.make(entry.state); | 130 res.state = LogDog.LogStreamState.make(entry.state); |
| 128 } | 131 } |
| 129 if (entry.desc) { | 132 if (entry.desc) { |
| 130 res.desc = LogDog.LogStreamDescriptor.make(entry.desc); | 133 res.desc = LogDog.LogStreamDescriptor.make(entry.desc); |
| 131 } | 134 } |
| 132 return res; | 135 return res; |
| 133 }); | 136 }); |
| 134 return [results, resp.next]; | 137 return [results, resp.next]; |
| 135 } | 138 } |
| 136 } | 139 } |
| 137 } | 140 } |
| OLD | NEW |