Skip to content

Commit

Permalink
Add retry for network condition check
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrho committed Oct 24, 2024
1 parent d106f19 commit dd40903
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
2 changes: 1 addition & 1 deletion jccm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jccm",
"productName": "Juniper Cloud Connection Manager",
"description": "Juniper Cloud Connection Manager",
"version": "1.2.7",
"version": "1.2.8",
"main": ".webpack/main",
"scripts": {
"start": "pkill -9 node; nodemon --watch ./src --ext js,json --ignore ./src/Frontend/ --exec 'electron-forge start'",
Expand Down
13 changes: 13 additions & 0 deletions jccm/src/Frontend/Layout/InventoryTreeMenuLocal.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,19 @@ const InventoryTreeMenuLocal = () => {
: 'No network condition test result available';
const isConnectable = result.dns && result.route && result.access;

const TooltipContent = ({ message, extraMessage = '' }) => (
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start' }}>
<Text size={200} weight="regular" style={{ color: tokens.colorPaletteRedForeground3 }}>
{message}
</Text>
{extraMessage && (
<Text size={200} weight="regular" style={{ color: tokens.colorPaletteRedForeground3 }}>
{extraMessage}
</Text>
)}
</div>
);

return (
<div
style={{
Expand Down
61 changes: 55 additions & 6 deletions jccm/src/Services/ApiServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ import {

import { CloudInfo } from '../config';
import { commitJunosSetConfig, executeJunosCommand, getDeviceFacts, getDeviceNetworkCondition } from './Device';

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

const sshSessions = {};

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

const { address, port, username, password, timeout, upperSerialNumber, bastionHost } = args;

try {
const { address, port, username, password, timeout, upperSerialNumber, bastionHost } = args;
const reply = await getDeviceFacts(
let reply = await getDeviceFacts(
address,
port,
username,
Expand All @@ -730,8 +734,24 @@ export const setupApiHandlers = () => {
bastionHost
);

if (reply?.message?.toLowerCase().includes('reset by peer')) {
console.log('Connection reset by peer, retrying in 3 seconds...');
await sleep(3000); // Wait for 3 seconds before retrying

reply = await getDeviceFacts(
address,
port,
username,
password,
timeout,
upperSerialNumber,
bastionHost
);
}

return { facts: true, reply };
} catch (error) {
console.error('Error getting device facts:', error);
return { facts: false, reply: error };
}
});
Expand Down Expand Up @@ -1037,10 +1057,10 @@ export const setupApiHandlers = () => {
ipcMain.handle('get-device-network-condition', async (event, args) => {
console.log('main: saGetDeviceNetworkCondition');

try {
const { address, port, username, password, timeout, bastionHost, termServer, termPort } = args;
const { address, port, username, password, timeout, bastionHost, termServer, termPort } = args;

const reply = await getDeviceNetworkCondition(
try {
let reply = await getDeviceNetworkCondition(
address,
port,
username,
Expand All @@ -1051,12 +1071,41 @@ export const setupApiHandlers = () => {
termPort
);

if (reply?.message?.toLowerCase().includes('timed out')) {
console.log('Timeout detected, retrying in 3 seconds...');
await sleep(3000);
reply = await getDeviceNetworkCondition(
address,
port,
username,
password,
timeout,
bastionHost,
termServer,
termPort
);
} else if (reply?.message?.toLowerCase().includes('reset by peer')) {
console.log('Connection reset by peer detected, retrying in 3 seconds...');
await sleep(3000);
reply = await getDeviceNetworkCondition(
address,
port,
username,
password,
timeout,
bastionHost,
termServer,
termPort
);
}

return { networkConditionCollect: true, reply };
} catch (error) {
console.error('Network condition error:', error);
return { networkConditionCollect: false, reply: error };
}
});

ipcMain.on('restart-app', () => {
console.log('Received restart-app request...');
app.relaunch(); // Relaunch the Electron app
Expand Down

0 comments on commit dd40903

Please sign in to comment.