Skip to content

Commit c42c69d

Browse files
committed
Uplift api version
1 parent 1f17c63 commit c42c69d

File tree

4 files changed

+40
-24
lines changed

4 files changed

+40
-24
lines changed

src/main/java/com/cisco/trex/stateful/TRexAstfClient.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,21 @@ protected void serverAPISync() throws TRexConnectionException {
5555
TRexClientResult<ApiVersionHandler> result =
5656
callMethod("api_sync_v2", apiVers, ApiVersionHandler.class);
5757

58+
int majorVersion = Constants.ASTF_API_VERSION_MAJOR;
59+
int minorVersion = Constants.ASTF_API_VERSION_MINOR;
60+
// Currently the etrex server has the NBC issue to uplift the ASTF_API_VERSION_MAJOR version
61+
// This if-block is a temporary solution to support uplift the ASTF_API_VERSION_MAJOR version ,
62+
// if the etrex server does not uplift its version ,the cilent will continue use the old api, if
63+
// the server uplift, the client will use the new api.
5864
if (!StringUtils.isBlank(result.getError()) && result.getError().contains("Version mismatch")) {
59-
String regrexString = "server: '([0-9]*)\\.([0-9]*)', client: '([0-9]*)\\.([0-9]*)'";
65+
String regrexString = "server: '([0-9]+)\\.([0-9]+)', client: '([0-9]+)\\.([0-9]+)'";
6066
Pattern pattern = Pattern.compile(regrexString);
6167
Matcher matcher = pattern.matcher(result.getError());
6268
if (matcher.find()) {
63-
Constants.ASTF_API_VERSION_MAJOR = Integer.parseInt(matcher.group(1));
64-
Constants.ASTF_API_VERSION_MINOR = Integer.parseInt(matcher.group(2));
65-
apiVers.put("major", Constants.ASTF_API_VERSION_MAJOR);
66-
apiVers.put("minor", Constants.ASTF_API_VERSION_MINOR);
69+
majorVersion = Integer.parseInt(matcher.group(1));
70+
minorVersion = Integer.parseInt(matcher.group(2));
71+
apiVers.put("major", majorVersion);
72+
apiVers.put("minor", minorVersion);
6773
result = callMethod("api_sync_v2", apiVers, ApiVersionHandler.class);
6874
}
6975
}
@@ -72,9 +78,9 @@ protected void serverAPISync() throws TRexConnectionException {
7278
TRexConnectionException e =
7379
new TRexConnectionException(
7480
"Unable to connect to TRex server. Required API version is "
75-
+ Constants.ASTF_API_VERSION_MAJOR
81+
+ majorVersion
7682
+ "."
77-
+ Constants.ASTF_API_VERSION_MINOR);
83+
+ minorVersion);
7884
LOGGER.error("Unable to sync client with TRex server due to: API_H is null.", e.getMessage());
7985
throw e;
8086
}

src/main/java/com/cisco/trex/stateless/TRexClient.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,21 @@ protected void serverAPISync() throws TRexConnectionException {
110110
TRexClientResult<ApiVersionHandler> result =
111111
callMethod("api_sync_v2", parameters, ApiVersionHandler.class);
112112

113+
int majorVersion = Constants.STL_API_VERSION_MAJOR;
114+
int minorVersion = Constants.STL_API_VERSION_MINOR;
115+
// Currently the etrex server has the NBC issue to uplift the STL_API_VERSION_MAJOR version
116+
// This if-block is a temporary solution to support uplift the STL_API_VERSION_MAJOR version ,
117+
// if the etrex server does not uplift its version ,the cilent will continue use the old api, if
118+
// the server uplift, the client will use the new api.
113119
if (!StringUtils.isBlank(result.getError()) && result.getError().contains("Version mismatch")) {
114-
String regrexString = "server: '([0-9]*)\\.([0-9]*)', client: '([0-9]*)\\.([0-9]*)'";
120+
String regrexString = "server: '([0-9]+)\\.([0-9]+)', client: '([0-9]+)\\.([0-9]+)'";
115121
Pattern pattern = Pattern.compile(regrexString);
116122
Matcher matcher = pattern.matcher(result.getError());
117123
if (matcher.find()) {
118-
Constants.STL_API_VERSION_MAJOR = Integer.parseInt(matcher.group(1));
119-
Constants.STL_API_VERSION_MINOR = Integer.parseInt(matcher.group(2));
120-
parameters.put("major", Constants.STL_API_VERSION_MAJOR);
121-
parameters.put("minor", Constants.STL_API_VERSION_MINOR);
124+
majorVersion = Integer.parseInt(matcher.group(1));
125+
minorVersion = Integer.parseInt(matcher.group(2));
126+
parameters.put("major", majorVersion);
127+
parameters.put("minor", minorVersion);
122128
result = callMethod("api_sync_v2", parameters, ApiVersionHandler.class);
123129
}
124130
}
@@ -128,9 +134,7 @@ protected void serverAPISync() throws TRexConnectionException {
128134
new TRexConnectionException(
129135
MessageFormat.format(
130136
"Unable to connect to TRex server. Required API version is {0}.{1}. Error: {2}",
131-
Constants.STL_API_VERSION_MAJOR,
132-
Constants.STL_API_VERSION_MINOR,
133-
result.getError()));
137+
majorVersion, minorVersion, result.getError()));
134138
LOGGER.error("Unable to sync client with TRex server due to: API_H is null.", e.getMessage());
135139
throw e;
136140
}

src/main/java/com/cisco/trex/util/Constants.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
/** Class for constants */
44
public final class Constants {
55
public static final String JSON_RPC_VERSION = "2.0";
6-
public static int ASTF_API_VERSION_MAJOR = 2;
7-
public static int ASTF_API_VERSION_MINOR = 0;
8-
public static int STL_API_VERSION_MAJOR = 5;
9-
public static int STL_API_VERSION_MINOR = 0;
6+
public static final int ASTF_API_VERSION_MAJOR = 2;
7+
public static final int ASTF_API_VERSION_MINOR = 0;
8+
public static final int STL_API_VERSION_MAJOR = 5;
9+
public static final int STL_API_VERSION_MINOR = 0;
1010
}

src/main/java/com/cisco/trex/util/TRexClientUtil.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,30 @@ public static TRexServerMode getMode(String host, String port) {
3232
TRexCommand command = buildCommand("api_sync_v2", parameters);
3333
response = transport.sendCommand(command);
3434

35+
// Currently the etrex server has the NBC issue to uplift the ASTF_API_VERSION_MAJOR
36+
// version
37+
// This if-block is a temporary solution to support uplift the ASTF_API_VERSION_MAJOR version
38+
// ,
39+
// if the etrex server does not uplift its version ,the cilent will continue use the old api,
40+
// if the server uplift, the client will use the new api.
3541
String errorMessage =
3642
response.getError() == null ? null : response.getError().getSpecificErr();
3743
if (!StringUtils.isBlank(errorMessage) && errorMessage.contains("Version mismatch")) {
38-
String regrexString = "server: '([0-9]*)\\.([0-9]*)', client: '([0-9]*)\\.([0-9]*)'";
44+
String regrexString = "server: '([0-9]+)\\.([0-9]+)', client: '([0-9]+)\\.([0-9]+)'";
3945
Pattern pattern = Pattern.compile(regrexString);
4046
Matcher matcher = pattern.matcher(errorMessage);
4147
if (matcher.find()) {
42-
Constants.ASTF_API_VERSION_MAJOR = Integer.parseInt(matcher.group(1));
43-
Constants.ASTF_API_VERSION_MINOR = Integer.parseInt(matcher.group(2));
44-
parameters.put("major", Constants.ASTF_API_VERSION_MAJOR);
45-
parameters.put("minor", Constants.ASTF_API_VERSION_MINOR);
48+
parameters.put("major", Integer.parseInt(matcher.group(1)));
49+
parameters.put("minor", Integer.parseInt(matcher.group(2)));
4650
command = buildCommand("api_sync_v2", parameters);
4751
response = transport.sendCommand(command);
4852
}
4953
}
5054
} catch (IOException | NullPointerException e) {
5155
LOGGER.debug("Unable to sync client with TRex server .", e);
5256
return TRexServerMode.UNKNOWN;
57+
} finally {
58+
transport.close();
5359
}
5460
if (!response.isFailed()) {
5561
return TRexServerMode.ASTF;

0 commit comments

Comments
 (0)