Skip to content

Commit dd40903

Browse files
committed
Add retry for network condition check
1 parent d106f19 commit dd40903

File tree

3 files changed

+69
-7
lines changed

3 files changed

+69
-7
lines changed

jccm/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "jccm",
33
"productName": "Juniper Cloud Connection Manager",
44
"description": "Juniper Cloud Connection Manager",
5-
"version": "1.2.7",
5+
"version": "1.2.8",
66
"main": ".webpack/main",
77
"scripts": {
88
"start": "pkill -9 node; nodemon --watch ./src --ext js,json --ignore ./src/Frontend/ --exec 'electron-forge start'",

jccm/src/Frontend/Layout/InventoryTreeMenuLocal.js

+13
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,19 @@ const InventoryTreeMenuLocal = () => {
811811
: 'No network condition test result available';
812812
const isConnectable = result.dns && result.route && result.access;
813813

814+
const TooltipContent = ({ message, extraMessage = '' }) => (
815+
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start' }}>
816+
<Text size={200} weight="regular" style={{ color: tokens.colorPaletteRedForeground3 }}>
817+
{message}
818+
</Text>
819+
{extraMessage && (
820+
<Text size={200} weight="regular" style={{ color: tokens.colorPaletteRedForeground3 }}>
821+
{extraMessage}
822+
</Text>
823+
)}
824+
</div>
825+
);
826+
814827
return (
815828
<div
816829
style={{

jccm/src/Services/ApiServer.js

+55-6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ import {
4545

4646
import { CloudInfo } from '../config';
4747
import { commitJunosSetConfig, executeJunosCommand, getDeviceFacts, getDeviceNetworkCondition } from './Device';
48+
49+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
50+
4851
const sshSessions = {};
4952

5053
const serverGetCloudInventory = async (targetOrgs = null, ignoreCaseInName = false) => {
@@ -718,9 +721,10 @@ export const setupApiHandlers = () => {
718721
ipcMain.handle('saGetDeviceFacts', async (event, args) => {
719722
console.log('main: saGetDeviceFacts');
720723

724+
const { address, port, username, password, timeout, upperSerialNumber, bastionHost } = args;
725+
721726
try {
722-
const { address, port, username, password, timeout, upperSerialNumber, bastionHost } = args;
723-
const reply = await getDeviceFacts(
727+
let reply = await getDeviceFacts(
724728
address,
725729
port,
726730
username,
@@ -730,8 +734,24 @@ export const setupApiHandlers = () => {
730734
bastionHost
731735
);
732736

737+
if (reply?.message?.toLowerCase().includes('reset by peer')) {
738+
console.log('Connection reset by peer, retrying in 3 seconds...');
739+
await sleep(3000); // Wait for 3 seconds before retrying
740+
741+
reply = await getDeviceFacts(
742+
address,
743+
port,
744+
username,
745+
password,
746+
timeout,
747+
upperSerialNumber,
748+
bastionHost
749+
);
750+
}
751+
733752
return { facts: true, reply };
734753
} catch (error) {
754+
console.error('Error getting device facts:', error);
735755
return { facts: false, reply: error };
736756
}
737757
});
@@ -1037,10 +1057,10 @@ export const setupApiHandlers = () => {
10371057
ipcMain.handle('get-device-network-condition', async (event, args) => {
10381058
console.log('main: saGetDeviceNetworkCondition');
10391059

1040-
try {
1041-
const { address, port, username, password, timeout, bastionHost, termServer, termPort } = args;
1060+
const { address, port, username, password, timeout, bastionHost, termServer, termPort } = args;
10421061

1043-
const reply = await getDeviceNetworkCondition(
1062+
try {
1063+
let reply = await getDeviceNetworkCondition(
10441064
address,
10451065
port,
10461066
username,
@@ -1051,12 +1071,41 @@ export const setupApiHandlers = () => {
10511071
termPort
10521072
);
10531073

1074+
if (reply?.message?.toLowerCase().includes('timed out')) {
1075+
console.log('Timeout detected, retrying in 3 seconds...');
1076+
await sleep(3000);
1077+
reply = await getDeviceNetworkCondition(
1078+
address,
1079+
port,
1080+
username,
1081+
password,
1082+
timeout,
1083+
bastionHost,
1084+
termServer,
1085+
termPort
1086+
);
1087+
} else if (reply?.message?.toLowerCase().includes('reset by peer')) {
1088+
console.log('Connection reset by peer detected, retrying in 3 seconds...');
1089+
await sleep(3000);
1090+
reply = await getDeviceNetworkCondition(
1091+
address,
1092+
port,
1093+
username,
1094+
password,
1095+
timeout,
1096+
bastionHost,
1097+
termServer,
1098+
termPort
1099+
);
1100+
}
1101+
10541102
return { networkConditionCollect: true, reply };
10551103
} catch (error) {
1104+
console.error('Network condition error:', error);
10561105
return { networkConditionCollect: false, reply: error };
10571106
}
10581107
});
1059-
1108+
10601109
ipcMain.on('restart-app', () => {
10611110
console.log('Received restart-app request...');
10621111
app.relaunch(); // Relaunch the Electron app

0 commit comments

Comments
 (0)