1
1
import axios , { AxiosInstance } from 'axios' ;
2
2
import { plainToClass } from 'class-transformer' ;
3
3
import { decode } from 'jsonwebtoken' ;
4
- import { Request } from 'express' ;
5
4
6
5
import { RdiClient } from 'src/modules/rdi/client/rdi.client' ;
7
6
import {
@@ -14,10 +13,10 @@ import {
14
13
import {
15
14
RdiDryRunJobDto ,
16
15
RdiDryRunJobResponseDto ,
16
+ RdiTemplateResponseDto ,
17
17
RdiTestConnectionsResponseDto ,
18
18
} from 'src/modules/rdi/dto' ;
19
19
import {
20
- RdiPipelineDeployFailedException ,
21
20
RdiPipelineInternalServerErrorException ,
22
21
wrapRdiPipelineError ,
23
22
} from 'src/modules/rdi/exceptions' ;
@@ -29,8 +28,7 @@ import {
29
28
} from 'src/modules/rdi/models' ;
30
29
import { convertKeysToCamelCase } from 'src/utils/base.helper' ;
31
30
import { RdiPipelineTimeoutException } from 'src/modules/rdi/exceptions/rdi-pipeline.timeout-error.exception' ;
32
-
33
- const RDI_DEPLOY_FAILED_STATUS = 'failed' ;
31
+ import * as https from 'https' ;
34
32
35
33
export class ApiRdiClient extends RdiClient {
36
34
protected readonly client : AxiosInstance ;
@@ -42,6 +40,9 @@ export class ApiRdiClient extends RdiClient {
42
40
this . client = axios . create ( {
43
41
baseURL : rdi . url ,
44
42
timeout : RDI_TIMEOUT ,
43
+ httpsAgent : new https . Agent ( {
44
+ rejectUnauthorized : false ,
45
+ } ) ,
45
46
} ) ;
46
47
}
47
48
@@ -72,25 +73,32 @@ export class ApiRdiClient extends RdiClient {
72
73
}
73
74
}
74
75
75
- async getTemplate ( options : object ) : Promise < object > {
76
+ async getConfigTemplate ( pipelineType : string , dbType : string ) : Promise < RdiTemplateResponseDto > {
76
77
try {
77
- const response = await this . client . get ( RdiUrl . GetTemplate , { params : options } ) ;
78
+ const response = await this . client . get ( ` ${ RdiUrl . GetConfigTemplate } / ${ pipelineType } / ${ dbType } ` ) ;
78
79
return response . data ;
79
80
} catch ( error ) {
80
81
throw wrapRdiPipelineError ( error ) ;
81
82
}
82
83
}
83
84
84
- async deploy ( pipeline : RdiPipeline ) : Promise < void > {
85
- let response ;
85
+ async getJobTemplate ( pipelineType : string ) : Promise < RdiTemplateResponseDto > {
86
86
try {
87
- response = await this . client . post ( RdiUrl . Deploy , { ...pipeline } ) ;
87
+ const response = await this . client . get ( `${ RdiUrl . GetJobTemplate } /${ pipelineType } ` ) ;
88
+ return response . data ;
88
89
} catch ( error ) {
89
- throw wrapRdiPipelineError ( error , error . response . data . message ) ;
90
+ throw wrapRdiPipelineError ( error ) ;
90
91
}
92
+ }
91
93
92
- if ( response . data ?. status === RDI_DEPLOY_FAILED_STATUS ) {
93
- throw new RdiPipelineDeployFailedException ( undefined , { error : response . data ?. error } ) ;
94
+ async deploy ( pipeline : RdiPipeline ) : Promise < void > {
95
+ try {
96
+ const response = await this . client . post ( RdiUrl . Deploy , { ...pipeline } ) ;
97
+ const actionId = response . data . action_id ;
98
+
99
+ return this . pollActionStatus ( actionId ) ;
100
+ } catch ( error ) {
101
+ throw wrapRdiPipelineError ( error , error . response . data . message ) ;
94
102
}
95
103
}
96
104
@@ -103,21 +111,14 @@ export class ApiRdiClient extends RdiClient {
103
111
}
104
112
}
105
113
106
- async testConnections ( config : string , req : Request ) : Promise < RdiTestConnectionsResponseDto > {
114
+ async testConnections ( config : object ) : Promise < RdiTestConnectionsResponseDto > {
107
115
try {
108
- const abortController = new AbortController ( ) ;
109
- req . socket . on ( 'close' , ( ) => {
110
- abortController . abort ( ) ;
111
- } ) ;
112
116
const response = await this . client . post (
113
117
RdiUrl . TestConnections ,
114
118
config ,
115
- { signal : abortController . signal } ,
116
119
) ;
117
120
118
- const actionId = response . data . action_id ;
119
-
120
- return this . pollActionStatus ( actionId , abortController . signal ) ;
121
+ return response . data ;
121
122
} catch ( e ) {
122
123
throw wrapRdiPipelineError ( e ) ;
123
124
}
@@ -147,7 +148,7 @@ export class ApiRdiClient extends RdiClient {
147
148
148
149
async getJobFunctions ( ) : Promise < object > {
149
150
try {
150
- const response = await this . client . post ( RdiUrl . JobFunctions ) ;
151
+ const response = await this . client . get ( RdiUrl . JobFunctions ) ;
151
152
return response . data ;
152
153
} catch ( e ) {
153
154
throw wrapRdiPipelineError ( e ) ;
@@ -178,10 +179,10 @@ export class ApiRdiClient extends RdiClient {
178
179
}
179
180
}
180
181
181
- private async pollActionStatus ( actionId : string , abortSignal : AbortSignal ) : Promise < any > {
182
+ private async pollActionStatus ( actionId : string , abortSignal ? : AbortSignal ) : Promise < any > {
182
183
const startTime = Date . now ( ) ;
183
184
while ( true ) {
184
- if ( abortSignal . aborted ) {
185
+ if ( abortSignal ? .aborted ) {
185
186
throw new RdiPipelineInternalServerErrorException ( ) ;
186
187
}
187
188
if ( Date . now ( ) - startTime > MAX_POLLING_TIME ) {
0 commit comments