/
context.ts
196 lines (172 loc) · 5.72 KB
/
context.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import { EventEmitter } from 'events';
import { Logger } from '@terascope/utils';
import { OpConfig } from './jobs';
import { ExecutionContextAPI } from '../execution-context';
export interface ClusterStateConfig {
connection: string|'default';
}
export type RolloverFrequency = 'daily'|'montly'|'yearly';
export interface IndexRolloverFrequency {
state: RolloverFrequency;
analytics: RolloverFrequency;
}
export type ClusterManagerType = 'native'|'kubernetes';
export interface TerasliceConfig {
action_timeout: number|300000;
analytics_rate: number|60000;
api_response_timeout?: number|300000;
assets_directory?: string[] | string;
assets_volume?: string;
cluster_manager_type: ClusterManagerType;
/** This will only be available in the context of k8s */
cpu?: number;
/** This will only be available in the context of k8s */
cpu_execution_controller?: number|0.5;
/** This will only be available in the context of k8s */
ephemeral_storage?: boolean|false;
execution_controller_targets?: ExecutionControllerTargets[];
hostname: string;
index_rollover_frequency: IndexRolloverFrequency;
kubernetes_api_poll_delay?: number|1000;
kubernetes_config_map_name?: string|'teraslice-worker';
kubernetes_image_pull_secret?: string|'';
kubernetes_image?: string|'terascope/teraslice';
kubernetes_namespace?: string|'default';
kubernetes_overrides_enabled?: boolean|false;
kubernetes_priority_class_name?: string|'';
kubernetes_worker_antiaffinity?: boolean|false;
master_hostname: string|'localhost';
master: boolean|false;
/** This will only be available in the context of k8s */
memory?: number;
/** This will only be available in the context of k8s */
memory_execution_controller?: number|512000000; // 512 MB
name: string|'teracluster';
network_latency_buffer: number|15000;
node_disconnect_timeout: number|300000;
node_state_interval: number|5000;
port: number|5678;
shutdown_timeout: number|number;
slicer_allocation_attempts: number|3;
slicer_port_range: string|'45679:46678';
slicer_timeout: number|180000;
state: ClusterStateConfig;
env_vars: { [key: string]: string };
worker_disconnect_timeout: number|300000;
workers: number|4;
}
export interface TerafoundationConfig {
connectors: Record<string, any>;
asset_storage_connection_type?: string;
asset_storage_connection?: string;
asset_storage_bucket?: string;
}
export interface SysConfig {
terafoundation: TerafoundationConfig;
teraslice: TerasliceConfig;
_nodeName: string;
}
export interface ConnectionConfig {
endpoint: string;
cached?: boolean;
type: string;
}
export type ClientFactoryFn = (
config: Record<string, any>,
logger: Logger,
options: ConnectionConfig
) => { client: any };
export type CreateClientFactoryFn = (
config: Record<string, any>,
logger: Logger,
options: ConnectionConfig
) => Promise<{ client: any }>;
export interface ExecutionControllerTargets {
key: string;
value: string;
}
export interface FoundationApis {
makeLogger(...params: any[]): Logger;
getSystemEvents(): EventEmitter;
getConnection(config: ConnectionConfig): { client: any };
createClient(config: ConnectionConfig): Promise<{ client: any }>;
}
export interface LegacyFoundationApis {
makeLogger(...params: any[]): Logger;
getEventEmitter(): EventEmitter;
getConnection(config: ConnectionConfig): { client: any };
}
export interface ContextApis {
readonly foundation: FoundationApis;
registerAPI(namespace: string, apis: any): void;
[namespace: string]: any;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ContextAPIs extends ContextApis {}
export interface GetClientConfig {
connection?: string;
endpoint?: string;
connection_cache?: boolean;
}
/*
* This will request a connection based on the 'connection' attribute of
* an opConfig. Intended as a context API endpoint.
* If there is an error getting the connection, it will not throw an error
* it will log it and emit `client:initialization:error`
*/
export interface OpRunnerAPI {
getClient(config: GetClientConfig, type: string): any;
getClientAsync(config: GetClientConfig, type: string): Promise<any>;
}
export interface JobRunnerAPI {
/** Get the first opConfig from an operation name */
getOpConfig(name: string): OpConfig|undefined;
}
export interface AssetsAPI {
/* Get the asset path from a asset name or ID */
getPath(name: string): Promise<string>;
}
/**
* WorkerContext includes the type definitions for
* the APIs available to Worker or Slicer.
* This extends the Terafoundation Context.
*/
export interface WorkerContextAPIs extends ContextAPIs {
/**
* Includes an API for getting a client from Terafoundation
*/
assets: AssetsAPI;
/**
* Includes an API for getting a client from Terafoundation
*/
op_runner: OpRunnerAPI;
/**
* Includes an API for getting a opConfig from the job
*/
job_runner: JobRunnerAPI;
/**
* An API for registering and loading the new Job APIs
*/
executionContext: ExecutionContextAPI;
}
export interface WorkerContext extends Context {
apis: WorkerContextAPIs;
assignment: 'execution_controller'|'worker';
}
export interface Context {
apis: ContextAPIs;
arch: string;
assignment: Assignment;
foundation: LegacyFoundationApis;
logger: Logger;
name: string;
platform: string;
sysconfig: SysConfig;
cluster: ContextClusterConfig;
}
export interface ContextClusterConfig {
worker: {
id: string;
};
}
export type Assignment = 'assets_service'|'cluster_master'|'node_master'|'execution_controller'|'worker';