Skip to content

Commit 58a3df1

Browse files
committed
tunnel upgrade to V3
1 parent b2adcb1 commit 58a3df1

File tree

4 files changed

+90
-94
lines changed

4 files changed

+90
-94
lines changed

src/main/java/com/lambdatest/jenkins/freestyle/api/Constant.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface Constant {
2828
String ANALYTICS_URL = "https://backend.lambdatest.com/api/analytics/automation-plugin-usage";
2929
String APP_URL = "https://automation.lambdatest.com";
3030
String HUB_URL = "@hub.lambdatest.com/wd/hub";
31-
31+
3232
interface Stage {
3333
String APP_URL = "https://stage-automation.lambdatest.com";
3434
String HUB_URL = "@stage-hub.lambdatest.com/wd/hub";
@@ -53,47 +53,47 @@ interface Dev {
5353
String DEV = "dev";
5454
String BETA = "beta";
5555

56-
String MAC_HASH_URL = "https://downloads.lambdatest.com/tunnel/mac/64bit/latest";
57-
String MAC_BINARY_URL = "https://downloads.lambdatest.com/tunnel/mac/64bit/ltcomponent.zip";
56+
String MAC_HASH_URL = "https://downloads.lambdatest.com/tunnel/v3/mac/64bit/latest";
57+
String MAC_BINARY_URL = "https://downloads.lambdatest.com/tunnel/v3/mac/64bit/LT_Mac.zip";
5858

59-
String LINUX_HASH_URL = "https://downloads.lambdatest.com/tunnel/linux/64bit/latest";
60-
String LINUX_BINARY_URL = "https://downloads.lambdatest.com/tunnel/linux/64bit/ltcomponent.zip";
59+
String LINUX_HASH_URL = "https://downloads.lambdatest.com/tunnel/v3/linux/64bit/latest";
60+
String LINUX_BINARY_URL = "https://downloads.lambdatest.com/tunnel/v3/linux/64bit/LT_Linux.zip";
6161

62-
String WIN_HASH_URL = "https://downloads.lambdatest.com/tunnel/windows/64bit/latest";
63-
String WIN_BINARY_URL = "https://downloads.lambdatest.com/tunnel/windows/64bit/ltcomponent.zip";
62+
String WIN_HASH_URL = "https://downloads.lambdatest.com/tunnel/v3/windows/64bit/latest";
63+
String WIN_BINARY_URL = "https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip";
6464

6565
String DEFAULT_TUNNEL_NAME = "jenkins-tunnel";
6666
String DEFAULT_TUNNEL_FOLDER_NAME= "lambda-tunnel";
6767
String LT_TUNNEL_NAME = "LT_TUNNEL_NAME";
6868

6969
String LT_ICON_FILE_NAME = Jenkins.RESOURCE_PATH + "/plugin/lambdatest-automation/images/logo.png";
70-
71-
70+
71+
7272
//New Binary Path for UnderPass Tunnel
73-
String DOWNLOAD_ALPHA_TUNNEL_LINK= "https://downloads.lambdatest.com/tunnel/alpha";
73+
String DOWNLOAD_ALPHA_TUNNEL_LINK= "https://downloads.lambdatest.com/tunnel";
7474
String MAC_WS_HASH_URL = DOWNLOAD_ALPHA_TUNNEL_LINK +"/mac/64bit/latest";
75-
String MAC_WS_BINARY_URL = DOWNLOAD_ALPHA_TUNNEL_LINK +"/mac/64bit/LT_Mac.zip";
75+
String MAC_WS_BINARY_URL = DOWNLOAD_ALPHA_TUNNEL_LINK +"/mac/64bit/ltcomponent.zip";
7676

7777
String LINUX_WS_HASH_URL = DOWNLOAD_ALPHA_TUNNEL_LINK +"/linux/64bit/latest";
78-
String LINUX_WS_BINARY_URL = DOWNLOAD_ALPHA_TUNNEL_LINK +"/linux/64bit/LT_Linux.zip";
78+
String LINUX_WS_BINARY_URL = DOWNLOAD_ALPHA_TUNNEL_LINK +"/linux/64bit/ltcomponent.zip";
7979

8080
String WIN_WS_HASH_URL = DOWNLOAD_ALPHA_TUNNEL_LINK +"/windows/64bit/latest";
81-
String WIN_WS_BINARY_URL = DOWNLOAD_ALPHA_TUNNEL_LINK +"/windows/64bit/LT_Windows.zip";
82-
81+
String WIN_WS_BINARY_URL = DOWNLOAD_ALPHA_TUNNEL_LINK +"/windows/64bit/ltcomponent.zip";
82+
8383
interface Type {
8484
String HASH = "hash";
8585
String BINARY = "binary";
8686
}
87-
87+
8888
interface OS {
8989
String UNIX = "unix";
9090
String MAC = "mac";
9191
String WIN = "win";
9292
}
93-
93+
9494
interface Arch {
9595
String x32 = "32bit";
9696
String x64 = "64bit";
9797
}
98-
98+
9999
}

src/main/java/com/lambdatest/jenkins/freestyle/service/LambdaTunnelService.java

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class LambdaTunnelService {
3535
private static String tunnelFolderName = "/";
3636

3737
public static Process setUp(String user, String key, LocalTunnel localTunnel, String buildnumber, String tunnelName,
38-
FilePath workspacePath) {
38+
FilePath workspacePath) {
3939
if (OSValidator.isUnix()) {
4040
logger.info("Jenkins configured on Unix/Linux, getting latest hash");
4141
try {
@@ -118,25 +118,25 @@ public static Process setUp(String user, String key, LocalTunnel localTunnel, St
118118
logger.info("Tunnel Directory :" + tunnelBinaryDirLocation);
119119
// Verify Latest binary version
120120
if (!tunnelBinaryDirLocation.isEmpty()) {
121-
String tunnelBinaryLocation = tunnelBinaryDirLocation + latestHash;
122-
logger.info("Tunnel Binary Location :" + tunnelBinaryLocation);
123-
File tunnelBinary = new File(tunnelBinaryLocation);
124-
if (tunnelBinary.exists()) {
125-
logger.info("Tunnel Binary already exists");
126-
} else {
127-
String binaryURL = Constant.WIN_BINARY_URL;
128-
logger.info("Tunnel Binary doesn't exists, Downloading new binary from ..."+ binaryURL);
129-
downloadAndUnZipBinaryFile(tunnelBinaryDirLocation, latestHash,
130-
binaryURL);
131-
logger.info("Tunnel Binary downloaded from " + binaryURL);
132-
}
133-
// Get Tunnel Log path name
134-
String tunnelLogPath = getTunnelLogPathForWindows(workspacePath, buildnumber);
135-
logger.info("Tunnel Log Path:" + tunnelLogPath);
136-
return runCommandLine(tunnelBinaryLocation, tunnelLogPath, user, key, tunnelName,localTunnel,Constant.OS.WIN);
121+
String tunnelBinaryLocation = tunnelBinaryDirLocation + latestHash;
122+
logger.info("Tunnel Binary Location :" + tunnelBinaryLocation);
123+
File tunnelBinary = new File(tunnelBinaryLocation);
124+
if (tunnelBinary.exists()) {
125+
logger.info("Tunnel Binary already exists");
137126
} else {
138-
logger.warning("tunnelFolderPath empty");
127+
String binaryURL = Constant.WIN_BINARY_URL;
128+
logger.info("Tunnel Binary doesn't exists, Downloading new binary from ..."+ binaryURL);
129+
downloadAndUnZipBinaryFile(tunnelBinaryDirLocation, latestHash,
130+
binaryURL);
131+
logger.info("Tunnel Binary downloaded from " + binaryURL);
139132
}
133+
// Get Tunnel Log path name
134+
String tunnelLogPath = getTunnelLogPathForWindows(workspacePath, buildnumber);
135+
logger.info("Tunnel Log Path:" + tunnelLogPath);
136+
return runCommandLine(tunnelBinaryLocation, tunnelLogPath, user, key, tunnelName,localTunnel,Constant.OS.WIN);
137+
} else {
138+
logger.warning("tunnelFolderPath empty");
139+
}
140140
} catch (Exception e) {
141141
logger.warning(e.getMessage());
142142
}
@@ -145,7 +145,7 @@ public static Process setUp(String user, String key, LocalTunnel localTunnel, St
145145
}
146146
return null;
147147
}
148-
148+
149149
private static String getTunnelBinaryDirLocation(LocalTunnel localTunnel, FilePath workspacePath) {
150150
String tunnelBinaryDirLocation = "";
151151
if(localTunnel!=null && localTunnel.isUseWorkspacePath()) {
@@ -166,7 +166,7 @@ private static String getTunnelBinaryDirLocation(LocalTunnel localTunnel, FilePa
166166
}
167167
}
168168
}
169-
169+
170170
if(localTunnel!=null && !localTunnel.getDownloadTunnelPath().isEmpty()) {
171171
return localTunnel.getDownloadTunnelPath();
172172
}
@@ -210,7 +210,7 @@ private static String getTunnelLogPath(FilePath workspacePath, String buildnumbe
210210
}
211211
return tunnelLogPath;
212212
}
213-
213+
214214
private static String getTunnelLogPathForWindows(FilePath workspacePath, String buildnumber) {
215215
String tunnelLogPath = "tunnel.log";
216216
try {
@@ -327,31 +327,31 @@ public static void unZipIt(String tunnelBinaryZipFileName, String tunnelBinaryFi
327327
}
328328

329329
public static Process runCommandLine(String filePath, String tunnelLogPath, String user, String key,
330-
String tunnelName, LocalTunnel localTunnel,String ...args) throws IOException {
330+
String tunnelName, LocalTunnel localTunnel,String ...args) throws IOException {
331331
try {
332332
int availablePort= PortAvailabilityUtils.randomFreePort();
333333
//Updating permissions
334334
if(args.length < 1) {
335335
Runtime.getRuntime().exec("chmod 777 " + filePath);
336336
}
337-
338-
// creating list of process
339-
List<String> list = new ArrayList<String>();
340-
list.add(filePath);list.add("-user");list.add(user);
341-
list.add("-key");list.add(key);list.add("-logFile");list.add(tunnelLogPath);
342-
list.add("-tunnelName");list.add(tunnelName);list.add("-controller");list.add("jenkins");
343-
if(localTunnel!=null && localTunnel.isSharedTunnel()) {
344-
list.add("-shared-tunnel");
337+
338+
// creating list of process
339+
List<String> list = new ArrayList<String>();
340+
list.add(filePath);list.add("--user");list.add(user);
341+
list.add("--key");list.add(key);list.add("--logFile");list.add(tunnelLogPath);
342+
list.add("--tunnelName");list.add(tunnelName);list.add("--controller");list.add("jenkins");
343+
if(localTunnel!=null && localTunnel.isSharedTunnel()) {
344+
list.add("--shared-tunnel");
345+
}
346+
if(availablePort > 0) {
347+
list.add("--port");list.add(availablePort+"");
345348
}
346-
if(availablePort > 0) {
347-
list.add("-port");list.add(availablePort+"");
348-
}
349349
if(localTunnel!=null && !localTunnel.getTunnelExtCommand().isEmpty()) {
350350
String[] extCommands=localTunnel.getTunnelExtCommand().split(" ");
351351
list.addAll(Arrays.asList(extCommands));
352352
}
353353
list.add("-v");
354-
354+
355355
// create the process
356356
ProcessBuilder processBuilder = new ProcessBuilder(list);
357357
logger.info("Tunnel Binary Command "+processBuilder.command());

src/main/java/com/lambdatest/jenkins/freestyle/service/LambdaWebSocketTunnelService.java

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class LambdaWebSocketTunnelService {
3434
private static String tunnelFolderName = "/";
3535

3636
public static Process setUp(String user, String key, LocalTunnel localTunnel, String buildnumber, String tunnelName,
37-
FilePath workspacePath) {
37+
FilePath workspacePath) {
3838
logger.info("LambdaWebSocketTunnelService.setup process --start");
3939
if (OSValidator.isUnix()) {
4040
logger.info("Jenkins configured on Unix/Linux, getting latest hash");
@@ -167,7 +167,7 @@ private static String getTunnelBinaryDirLocation(LocalTunnel localTunnel, FilePa
167167
}
168168
}
169169
}
170-
170+
171171
if(localTunnel!=null && !localTunnel.getDownloadTunnelPath().isEmpty()) {
172172
return localTunnel.getDownloadTunnelPath();
173173
}
@@ -185,37 +185,33 @@ private static String getTunnelLogPath(FilePath workspacePath, String buildnumbe
185185
String tunnelLogPath = "tunnel.log";
186186
try {
187187
if (workspacePath != null) {
188-
return workspacePath.getRemote();
189-
190-
191188
// Create Tunnel Log Path
192-
// tunnelLogPath = new StringBuilder("tunnel").append("-").append(buildnumber).append(".log").toString();
193-
//
194-
// // Create a Folder in workspace
195-
// FilePath tunnelFolderPath = new FilePath(workspacePath, Constant.DEFAULT_TUNNEL_FOLDER_NAME);
196-
// File folder = new File(tunnelFolderPath.getRemote());
197-
// if (!folder.exists()) {
198-
// if (folder.mkdir()) {
199-
// logger.info("Directory is created! at " + tunnelFolderPath.getRemote());
200-
// FilePath tunnelPath = new FilePath(tunnelFolderPath, tunnelLogPath);
201-
// return tunnelPath.getRemote();
202-
// } else {
203-
// logger.info("Failed to create directory! at " + tunnelFolderPath.getRemote());
204-
// FilePath tunnelPath = new FilePath(workspacePath, tunnelLogPath);
205-
// return tunnelPath.getRemote();
206-
// }
207-
// } else {
208-
// return tunnelFolderPath.getRemote();
209-
//// FilePath tunnelPath = new FilePath(tunnelFolderPath, tunnelLogPath);
210-
//// return tunnelPath.getRemote();
211-
// }
189+
tunnelLogPath = new StringBuilder("tunnel").append("-").append(buildnumber).append(".log").toString();
190+
191+
// Create a Folder in workspace
192+
FilePath tunnelFolderPath = new FilePath(workspacePath, Constant.DEFAULT_TUNNEL_FOLDER_NAME);
193+
File folder = new File(tunnelFolderPath.getRemote());
194+
if (!folder.exists()) {
195+
if (folder.mkdir()) {
196+
logger.info("Directory is created! at " + tunnelFolderPath.getRemote());
197+
FilePath tunnelPath = new FilePath(tunnelFolderPath, tunnelLogPath);
198+
return tunnelPath.getRemote();
199+
} else {
200+
logger.info("Failed to create directory! at " + tunnelFolderPath.getRemote());
201+
FilePath tunnelPath = new FilePath(workspacePath, tunnelLogPath);
202+
return tunnelPath.getRemote();
203+
}
204+
} else {
205+
FilePath tunnelPath = new FilePath(tunnelFolderPath, tunnelLogPath);
206+
return tunnelPath.getRemote();
207+
}
212208
}
213209
} catch (Exception e) {
214210
logger.info(e.getMessage());
215211
}
216212
return tunnelLogPath;
217213
}
218-
214+
219215
private static String getTunnelLogPathForWindows(FilePath workspacePath, String buildnumber) {
220216
String tunnelLogPath = "tunnel.log";
221217
try {
@@ -332,27 +328,27 @@ public static void unZipIt(String tunnelBinaryZipFileName, String tunnelBinaryFi
332328
}
333329

334330
public static Process runCommandLine(String filePath, String tunnelLogPath, String user, String key,
335-
String tunnelName, LocalTunnel localTunnel,String ...args) throws IOException {
331+
String tunnelName, LocalTunnel localTunnel,String ...args) throws IOException {
336332
try {
337333
//Updating permissions
338334
if(args.length < 1) {
339335
Runtime.getRuntime().exec("chmod 777 " + filePath);
340336
}
341-
342-
// creating list of process
343-
List<String> list = new ArrayList<String>();
344-
list.add(filePath);list.add("--user");list.add(user);
345-
list.add("--key");list.add(key);list.add("--logFile");list.add(tunnelLogPath);
346-
list.add("--tunnelName");list.add(tunnelName);list.add("--controller");list.add("jenkins");
347-
if(localTunnel!=null && localTunnel.isSharedTunnel()) {
348-
list.add("--shared-tunnel");
337+
338+
// creating list of process
339+
List<String> list = new ArrayList<String>();
340+
list.add(filePath);list.add("--user");list.add(user);
341+
list.add("--key");list.add(key);list.add("--logFile");list.add(tunnelLogPath);
342+
list.add("--tunnelName");list.add(tunnelName);list.add("--controller");list.add("jenkins");
343+
if(localTunnel!=null && localTunnel.isSharedTunnel()) {
344+
list.add("--shared-tunnel");
349345
}
350346
if(localTunnel!=null && !localTunnel.getTunnelExtCommand().isEmpty()) {
351347
String[] extCommands=localTunnel.getTunnelExtCommand().split(" ");
352348
list.addAll(Arrays.asList(extCommands));
353349
}
354-
list.add("--verbose");
355-
350+
list.add("--v");
351+
356352
// create the process
357353
ProcessBuilder processBuilder = new ProcessBuilder(list);
358354
logger.info("Tunnel Binary Command "+processBuilder.command());

src/main/resources/com/lambdatest/jenkins/freestyle/MagicPlugBuildWrapper/config.jelly

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
Creates a text field that shows the value of the "name" property.
1717
When submitted, it will be passed to the corresponding constructor parameter.
1818
-->
19-
19+
2020
<f:block>
2121
<f:validateButton title="Ping LambdaTest" progress="${%Checking availability of API...}" method="ping" />
2222
<!--<f:entry name="choice" title="Choose Environment" field="choice">
2323
<select name="choice">
2424
<option value="beta">beta</option>
2525
<option value="stage">stage</option>
26-
<option value="dev">dev</option>
26+
<option value="dev">dev</option>
2727
</select>
2828
</f:entry> -->
2929
<f:entry title="Selenium Tests">
@@ -47,7 +47,7 @@
4747
</div>
4848
</f:entry>
4949
</table>
50-
</f:repeatable>
50+
</f:repeatable>
5151
</f:entry>
5252
<f:optionalBlock title="Use Local Tunnel" field="localTunnel" checked="${instance.useLocalTunnel}">
5353
<f:entry title="Tunnel Name" field="tunnelName">
@@ -56,9 +56,9 @@
5656
<f:nested>
5757
<table>
5858
<f:optionalBlock title="Start Shared Tunnel" field="sharedTunnel" inline="true" checked="${instance.sharedTunnel}" />
59-
<f:optionalBlock title="Enable Websocket Mode" field="websocketTunnel" inline="true" checked="${instance.websocketTunnel}" />
59+
<f:optionalBlock title="Use Legacy Tunnel" field="websocketTunnel" inline="true" checked="${instance.websocketTunnel}" />
6060
</table>
61-
</f:nested>
61+
</f:nested>
6262
<f:entry title="Optional Tunnel Command" field="tunnelExtCommand">
6363
<f:textbox field="tunnelExtCommand" value="${instance.tunnelExtCommand()}" />
6464
</f:entry>
@@ -69,7 +69,7 @@
6969
<table>
7070
<f:optionalBlock title="Use Workspace Path" field="useWorkspacePath" inline="true" checked="${instance.useWorkspacePath}" />
7171
</table>
72-
</f:nested>
72+
</f:nested>
7373
</f:optionalBlock>
7474
</f:block>
7575
<f:block>

0 commit comments

Comments
 (0)