1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
1
import * as fs from 'fs' ;
3
2
import * as path from 'path' ;
4
3
import AwsService from './aws.service' ;
5
4
import { WorkflowSettings } from './opensearch-domain.service' ;
6
5
7
6
export default class OpenSearchRollupService extends AwsService {
8
- public async createOrUpdateRollupJob ( settings : WorkflowSettings ) : Promise < any > {
7
+ public async createOrUpdateRollupJob (
8
+ settings : WorkflowSettings ,
9
+ ) : Promise < any > {
9
10
const templateDir = path . resolve (
10
11
__dirname ,
11
12
'../../configuration-opensearch/rollup_index_jobs' ,
@@ -15,25 +16,38 @@ export default class OpenSearchRollupService extends AwsService {
15
16
if ( ! filePath . endsWith ( '.json' ) ) {
16
17
continue ;
17
18
}
18
- const rollupJobName = path . basename ( filePath , '.json' ) ;
19
- let rollupJobPath = `/_plugins/_rollup/jobs/${ rollupJobName } ` ;
19
+ const rollupJobName = path . basename ( filePath , '.json' ) ;
20
+ let rollupJobPath = `/_plugins/_rollup/jobs/${ rollupJobName } ` ;
20
21
const exists = await this . checkRollupJobExists ( settings , rollupJobName ) ;
21
- const rollupConfig = JSON . parse ( fs . readFileSync ( path . join ( templateDir , filePath ) , 'utf8' ) ) ;
22
+ const rollupConfig = JSON . parse (
23
+ fs . readFileSync ( path . join ( templateDir , filePath ) , 'utf8' ) ,
24
+ ) ;
22
25
23
26
if ( exists ) {
24
27
rollupJobPath += '?if_seq_no=1&if_primary_term=1' ;
25
28
console . log ( `Updating existing rollup job: ${ rollupJobName } ` ) ;
26
- return this . executeRollupRequest ( 'PUT' , settings , rollupJobPath , rollupConfig )
27
- . then ( ( res ) => {
28
- console . log ( `PUT ${ rollupJobPath } \n[${ res . statusCode } ] Rollup job updated` ) ;
29
+ return this . executeRollupRequest (
30
+ 'PUT' ,
31
+ settings ,
32
+ rollupJobPath ,
33
+ rollupConfig ,
34
+ ) . then ( ( res ) => {
35
+ console . log (
36
+ `PUT ${ rollupJobPath } \n[${ res . statusCode } ] Rollup job updated` ,
37
+ ) ;
29
38
} ) ;
30
- }
31
- else {
39
+ } else {
32
40
console . log ( `Creating new rollup job: ${ rollupJobName } ` ) ;
33
- return this . executeRollupRequest ( 'PUT' , settings , rollupJobPath , rollupConfig )
34
- . then ( ( res ) => {
35
- console . log ( `PUT ${ rollupJobPath } \n[${ res . statusCode } ] Rollup job created` ) ;
36
- } ) ;
41
+ return this . executeRollupRequest (
42
+ 'PUT' ,
43
+ settings ,
44
+ rollupJobPath ,
45
+ rollupConfig ,
46
+ ) . then ( ( res ) => {
47
+ console . log (
48
+ `PUT ${ rollupJobPath } \n[${ res . statusCode } ] Rollup job created` ,
49
+ ) ;
50
+ } ) ;
37
51
}
38
52
}
39
53
}
@@ -42,35 +56,39 @@ export default class OpenSearchRollupService extends AwsService {
42
56
method : string ,
43
57
settings : WorkflowSettings ,
44
58
path : string ,
45
- body ?: any
59
+ body ?: any ,
46
60
) : Promise < any > {
47
-
48
61
const [ pathWithoutQuery , queryString ] = path . split ( '?' ) ;
49
62
const queryParams = queryString
50
- ? Object . fromEntries ( new URLSearchParams ( queryString ) . entries ( ) )
51
- : undefined ;
63
+ ? Object . fromEntries ( new URLSearchParams ( queryString ) . entries ( ) )
64
+ : undefined ;
52
65
const requestOptions = {
53
66
method,
54
67
headers : {
55
68
'Content-Type' : 'application/json' ,
56
69
host : settings . hostname ,
57
70
} ,
58
71
hostname : settings . hostname ,
59
- path :pathWithoutQuery ,
72
+ path : pathWithoutQuery ,
60
73
query : queryParams ,
61
74
body : body ? JSON . stringify ( body ) : undefined ,
62
75
} ;
63
-
76
+
64
77
return this . executeSignedHttpRequest ( requestOptions )
65
78
. then ( ( res ) => this . waitAndReturnResponseBody ( res ) )
66
79
. catch ( ( err ) => {
67
- console . error ( `Error during ${ method } request to ${ path } : ${ err . message } ` ) ;
80
+ console . error (
81
+ `Error during ${ method } request to ${ path } : ${ err . message } ` ,
82
+ ) ;
68
83
throw err ;
69
84
} ) ;
70
85
}
71
86
72
87
// check if the rollup job exists
73
- private async checkRollupJobExists ( settings : WorkflowSettings , jobName : string ) : Promise < boolean > {
88
+ private async checkRollupJobExists (
89
+ settings : WorkflowSettings ,
90
+ jobName : string ,
91
+ ) : Promise < boolean > {
74
92
const rollupJobPath = `/_plugins/_rollup/jobs/${ jobName } ` ;
75
93
return this . executeRollupRequest ( 'GET' , settings , rollupJobPath )
76
94
. then ( ( res ) => {
@@ -93,5 +111,4 @@ export default class OpenSearchRollupService extends AwsService {
93
111
throw err ;
94
112
} ) ;
95
113
}
96
-
97
114
}
0 commit comments