Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit 58419e2

Browse files
authored
Merge pull request #25 from snyk/feat/custom_timeout_wating_analysis_results
feat: added param "waiting results" timeout [ROAD-389]
2 parents 7536ce7 + cd6a757 commit 58419e2

File tree

6 files changed

+32
-49
lines changed

6 files changed

+32
-49
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [2.1.11] - 2020-10-05
2+
- added param: "waiting results" timeout.
3+
14
## [2.0.18] - 2020-10-05
25
- fix exception when Null markers received.
36

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66

77
group = "io.snyk.code.sdk"
88
archivesBaseName = "snyk-code-client"
9-
version = "2.1.10"
9+
version = "2.1.11"
1010

1111
repositories {
1212
mavenCentral()

src/integTest/java/ai/deepcode/javaclient/DeepCodeRestApiTest.java

+5-18
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,11 @@ public class DeepCodeRestApiTest {
4949
@Test
5050
public void _010_newLogin() {
5151
System.out.println("\n--------------New Login----------------\n");
52-
LoginResponse response = null;
53-
response = DeepCodeRestApi.newLogin(userAgent);
54-
assertEquals(200, response.getStatusCode());
55-
assertTrue(response.getLoginURL().contains(response.getSessionToken()));
56-
System.out.printf(
57-
"New login request passed with returned: \nsession token: %1$s \nlogin URL: %2$s\n",
58-
response.getSessionToken(), response.getLoginURL());
52+
try {
53+
DeepCodeRestApi.newLogin(userAgent);
54+
} catch (UnsupportedOperationException e) {
55+
System.out.printf(e.getMessage());
56+
}
5957
}
6058

6159
@Test
@@ -157,17 +155,6 @@ public void _031_createBundle_wrong_request() {
157155
"Create Bundle call with malformed token [%1$s] is not accepted by server with Status code [%2$d].\n",
158156
brokenToken, response.getStatusCode());
159157

160-
final String incompleteLoginToken = DeepCodeRestApi.newLogin(userAgent).getSessionToken();
161-
response = DeepCodeRestApi.createBundle(incompleteLoginToken, files);
162-
assertNotNull(response);
163-
assertEquals(
164-
"Create Bundle call with incomplete login token should not be accepted by server",
165-
401,
166-
response.getStatusCode());
167-
System.out.printf(
168-
"Create Bundle call with incomplete login token is not accepted by server with Status code [%2$d].\n",
169-
brokenToken, response.getStatusCode());
170-
171158
// seems to be a bug on server: it returns 200
172159
/*
173160
response =

src/main/java/ai/deepcode/javaclient/DeepCodeRestApi.java

+3-21
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public final class DeepCodeRestApi {
3838

3939
private DeepCodeRestApi() {}
4040

41-
private static final String API_URL = "https://www.deepcode.ai/";
41+
private static final String API_URL = "https://deeproxy.snyk.io/";
4242

4343
private static Retrofit retrofit = buildRetrofit(API_URL, false);
4444

@@ -113,26 +113,8 @@ private interface LoginCall {
113113
* @return {@link LoginResponse} instance
114114
*/
115115
@NotNull
116-
public static LoginResponse newLogin(@NotNull String userAgent) {
117-
final LoginCall loginCall = retrofit.create(LoginCall.class);
118-
try {
119-
final SourceString source = new SourceString(userAgent);
120-
final Response<LoginResponse> retrofitResponse = loginCall.doNewLogin(source).execute();
121-
LoginResponse result = retrofitResponse.body();
122-
if (result == null) return new LoginResponse();
123-
result.setStatusCode(retrofitResponse.code());
124-
switch (retrofitResponse.code()) {
125-
case 200:
126-
result.setStatusDescription("The new login request was successful");
127-
break;
128-
default:
129-
result.setStatusDescription("Unknown Status Code: " + retrofitResponse.code());
130-
break;
131-
}
132-
return result;
133-
} catch (IOException e) {
134-
return new LoginResponse();
135-
}
116+
public static LoginResponse newLogin(@NotNull String userAgent) throws UnsupportedOperationException {
117+
throw new UnsupportedOperationException("login request is not handled anymore");
136118
}
137119

138120
private interface CheckSessionCall {

src/main/java/ai/deepcode/javaclient/core/AnalysisDataBase.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ private GetAnalysisResponse doGetAnalysis(
548548
List<String> filesToAnalyse) {
549549
GetAnalysisResponse response;
550550
int counter = 0;
551-
final int timeout = 100; // seconds
552-
final int attempts = timeout * 1000 / pdUtils.DEFAULT_DELAY;
551+
final long timeout = deepCodeParams.getTimeoutForGettingAnalysesMs();
552+
final long attempts = timeout / pdUtils.DEFAULT_DELAY;
553553
do {
554554
if (counter > 0) pdUtils.delay(pdUtils.DEFAULT_DELAY, progress);
555555
response =
@@ -566,19 +566,20 @@ private GetAnalysisResponse doGetAnalysis(
566566
return new GetAnalysisResponse();
567567

568568
double responseProgress = response.getProgress();
569-
if (responseProgress <= 0 || responseProgress > 1)
569+
if (responseProgress <= 0 || responseProgress > 1) {
570570
responseProgress = ((double) counter) / attempts;
571+
}
571572
pdUtils.progressSetFraction(progress, responseProgress);
572573
pdUtils.progressSetText(
573574
progress, WAITING_FOR_ANALYSIS_TEXT + (int) (responseProgress * 100) + "% done");
574575

575576
if (counter >= attempts) {
576577
dcLogger.logWarn("Timeout expire for waiting analysis results.");
577-
/*
578-
DeepCodeNotifications.showWarn(
579-
"Can't get analysis results from the server. Network or server internal error. Please, try again later.",
580-
project);
581-
*/
578+
pdUtils.showWarn(
579+
"Can't get analysis results from the server. Timeout of " + timeout/1000 + " sec. is reached." +
580+
" Please, increase timeout or try again later.",
581+
project,
582+
false);
582583
break;
583584
}
584585

src/main/java/ai/deepcode/javaclient/core/DeepCodeParamsBase.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import ai.deepcode.javaclient.DeepCodeRestApi;
44
import org.jetbrains.annotations.NotNull;
55

6+
import java.util.function.Supplier;
7+
68
public abstract class DeepCodeParamsBase {
79

810
// Settings
@@ -16,6 +18,7 @@ public abstract class DeepCodeParamsBase {
1618
// Inner params
1719
private String loginUrl;
1820
private String ideProductName;
21+
private Supplier<Long> getTimeoutForGettingAnalysesMs;
1922

2023
protected DeepCodeParamsBase(
2124
boolean isEnable,
@@ -25,7 +28,9 @@ protected DeepCodeParamsBase(
2528
int minSeverity,
2629
String sessionToken,
2730
String loginUrl,
28-
String ideProductName) {
31+
String ideProductName,
32+
Supplier<Long> getTimeoutForGettingAnalysesMs
33+
) {
2934
this.isEnable = isEnable;
3035
this.apiUrl = apiUrl;
3136
this.disableSslVerification = disableSslVerification;
@@ -34,6 +39,7 @@ protected DeepCodeParamsBase(
3439
this.sessionToken = sessionToken;
3540
this.loginUrl = loginUrl;
3641
this.ideProductName = ideProductName;
42+
this.getTimeoutForGettingAnalysesMs = getTimeoutForGettingAnalysesMs;
3743
}
3844

3945
public void clearLoginParams() {
@@ -116,4 +122,8 @@ public void setEnable(boolean isEnable) {
116122
public String getIdeProductName() {
117123
return ideProductName;
118124
}
125+
126+
public long getTimeoutForGettingAnalysesMs() {
127+
return getTimeoutForGettingAnalysesMs.get();
128+
}
119129
}

0 commit comments

Comments
 (0)