22
33import com .google .gson .reflect .TypeToken ;
44import com .jayway .jsonpath .TypeRef ;
5- import com .netflix .graphql .dgs .client .GraphQLResponse ;
65import com .netflix .graphql .dgs .client .codegen .GraphQLQueryRequest ;
76import io .litmuschaos .exception .LitmusApiException ;
87import io .litmuschaos .generated .client .*;
1716import java .util .HashMap ;
1817import java .util .List ;
1918import java .util .Map ;
19+ import java .util .concurrent .TimeUnit ;
2020
2121import static io .litmuschaos .constants .ApiEndpoints .*;
2222import static io .litmuschaos .constants .OperationNames .*;
@@ -36,13 +36,37 @@ public class LitmusClient implements AutoCloseable {
3636 private final LitmusGraphQLClient graphQLClient ;
3737
3838 public LitmusClient (String host , String token ) {
39+ this (host , token , LitmusConfig .DEFAULT );
40+ }
41+
42+ public LitmusClient (String host , String token , LitmusConfig config ){
3943 String sanitizedHost = sanitizeURL (host );
4044 this .token = token ;
41- okHttpClient = new OkHttpClient (); // TODO : apply detail options
45+ okHttpClient = buildOkHttpClient ( config );
4246 this .httpClient = new LitmusHttpClient (okHttpClient , sanitizedHost + AUTH );
4347 this .graphQLClient = new LitmusGraphQLClient (okHttpClient , sanitizedHost + API_QUERY , this .token );
4448 }
4549
50+ public static OkHttpClient buildOkHttpClient (LitmusConfig config ){
51+
52+ final OkHttpClient .Builder okHttpClient = new OkHttpClient .Builder ();
53+
54+ if (config .getHttpClientReadTimeoutMillis () != null ){
55+ okHttpClient .readTimeout (config .getHttpClientReadTimeoutMillis (), TimeUnit .MILLISECONDS );
56+ }
57+ if (config .getHttpClientWriteTimeoutMillis () != null ){
58+ okHttpClient .writeTimeout (config .getHttpClientWriteTimeoutMillis (), TimeUnit .MILLISECONDS );
59+ }
60+ if (config .getHttpClientCallTimeoutMillis () != null ){
61+ okHttpClient .callTimeout (config .getHttpClientCallTimeoutMillis (), TimeUnit .MILLISECONDS );
62+ }
63+ if (config .getHttpClientConnectTimeoutMillis () != null ){
64+ okHttpClient .connectTimeout (config .getHttpClientConnectTimeoutMillis (), TimeUnit .MILLISECONDS );
65+ }
66+
67+ return okHttpClient .build ();
68+ }
69+
4670 /**
4771 * Returns all the api tokens for the user.
4872 *
@@ -1314,33 +1338,8 @@ public GetManifestWithInfraIDResponse getManifestWithInfraID(GetManifestWithInfr
13141338 // TODO: subscription is not supported in current version
13151339
13161340// public InfraEventResponse getInfraEvents(GetInfraEventsGraphQLQuery query, GetInfraEventsProjectionRoot projectionRoot){
1317- // String request = new GraphQLQueryRequest(query, projectionRoot).serialize();
1318- // GraphQLResponse response = graphQLClient.query(request);
1319- // return response.extractValueAsObject("getInfraEvents", new TypeRef<InfraEventResponse>(){});
1320- // }
1321- //
1322- // public KubeNamespaceResponse getKubeNamespace(GetKubeNamespaceGraphQLQuery query, GetKubeNamespaceProjectionRoot projectionRoot){
1323- // String request = new GraphQLQueryRequest(query,projectionRoot).serialize();
1324- // GraphQLResponse response = graphQLClient.query(request);
1325- // return response.extractValueAsObject("getKubeNamespace", new TypeRef<KubeNamespaceResponse>(){});
1326- // }
1327- //
1328- // public KubeObjectResponse getKubeObject(GetKubeObjectGraphQLQuery query, GetKubeObjectProjectionRoot projectionRoot){
1329- // String request = new GraphQLQueryRequest(query, projectionRoot).serialize();
1330- // GraphQLResponse response = graphQLClient.query(request);
1331- // return response.extractValueAsObject("getKubeObject", new TypeRef<KubeObjectResponse>(){});
1332- // }
1333- //
1334- // public PodLogResponse getPodLog(GetPodLogGraphQLQuery query, GetPodLogProjectionRoot projectionRoot){
1335- // String request = new GraphQLQueryRequest(query, projectionRoot).serialize();
1336- // GraphQLResponse response = graphQLClient.query(request);
1337- // return response.extractValueAsObject("getPodLog", new TypeRef<PodLogResponse>(){});
1338- // }
1339- //
1340- // public InfraActionResponse infraConnect(InfraConnectGraphQLQuery query, InfraConnectProjectionRoot projectionRoot){
1341- // String request = new GraphQLQueryRequest(query, projectionRoot).serialize();
1342- // GraphQLResponse response = graphQLClient.query(request);
1343- // return response.extractValueAsObject("infraConnect", new TypeRef<InfraActionResponse>(){});
1341+ // String request = new GraphQLQueryRequest(query).serialize();
1342+ // return graphQLClient.query(request, "getInfraEvents", new TypeRef<InfraEventResponse>(){});
13441343// }
13451344
13461345 private String sanitizeURL (String url ) {
0 commit comments