Skip to content

Commit

Permalink
Add support for Remote System Information connection tests
Browse files Browse the repository at this point in the history
Introduced functionality to validate Remote System Information connection during device setup and diagnostics. Updated client, server, and shared-lib components to integrate this feature, including API endpoints, UI adjustments, and backend logic for connection testing.
  • Loading branch information
SquirrelDevelopper committed Feb 10, 2025
1 parent c47ffa5 commit ca50d84
Show file tree
Hide file tree
Showing 10 changed files with 417 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import {
import { Alert, Popover, Steps, Typography } from 'antd';
import { motion } from 'framer-motion';
import React, { useEffect, useRef, useState } from 'react';
import { API, SsmAnsible } from 'ssm-shared-lib';
import { API, SsmAgent, SsmAnsible } from 'ssm-shared-lib';

export type CheckDeviceConnectionProps = {
installMethod: SsmAgent.InstallMethods;
execId?: string;
dockerConnRes?: string;
dockerConnErrorMessage?: string;
rsiConnRes?: string;
rsiConnErrorMessage?: string;
};

const taskInit: TaskStatusTimelineType = {
Expand All @@ -34,11 +37,19 @@ const animationVariants = {
};

const CheckDeviceConnection: React.FC<CheckDeviceConnectionProps> = (props) => {
const { execId, dockerConnRes, dockerConnErrorMessage } = props;
const {
execId,
dockerConnRes,
dockerConnErrorMessage,
rsiConnErrorMessage,
rsiConnRes,
} = props;
const timerIdRef = useRef();
const [isPollingEnabled, setIsPollingEnabled] = useState(false);
const [playbookStatus, setPlaybookStatus] = useState('running...');
const [dockerStatus, setDockerStatus] = useState('running...');
const [rsiStatus, setRsiStatus] = useState('running...');

const [execRes, setExecRes] = useState(<></>);
const [smartFailure, setSmartFailure] = useState<
API.SmartFailure | undefined
Expand Down Expand Up @@ -108,6 +119,14 @@ const CheckDeviceConnection: React.FC<CheckDeviceConnectionProps> = (props) => {
}
}, [dockerConnRes]);

useEffect(() => {
if (rsiConnRes) {
setRsiStatus(rsiConnRes);
} else {
setRsiStatus('running...');
}
}, [rsiConnRes]);

useEffect(() => {
const pollingCallback = () => {
terminalHandler.pollingCallback(execId || '');
Expand Down Expand Up @@ -202,6 +221,38 @@ const CheckDeviceConnection: React.FC<CheckDeviceConnectionProps> = (props) => {
<LoadingOutlined />
),
},
...(props.installMethod === SsmAgent.InstallMethods.LESS
? [
{
title: 'Remote System Information Connection test',
description: (
<>
{rsiStatus}{' '}
{rsiStatus === 'failed' && (
<Popover
content={
<Typography.Text type="danger">
{rsiConnErrorMessage}
</Typography.Text>
}
title={'Remote System Information Connection Logs'}
>
<InfoCircleFilled />
</Popover>
)}
</>
),
icon:
rsiStatus === 'successful' ? (
<CheckCircleOutlined />
) : rsiStatus === 'failed' ? (
<CloseOutlined style={{ color: 'red' }} />
) : (
<LoadingOutlined />
),
},
]
: []),
]}
/>
{smartFailure && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { StreamlineComputerConnection } from '@/components/Icons/CustomIcons';
import {
getCheckDeviceAnsibleConnection,
getCheckDeviceDockerConnection,
getCheckDeviceRemoteSystemInformationConnection,
} from '@/services/rest/device';
import { Avatar, Button, Card, Col, Row } from 'antd';
import React, { useState } from 'react';
import { API } from 'ssm-shared-lib';
import { API, SsmAgent } from 'ssm-shared-lib';

type ConnectionTestTabProps = {
device: Partial<API.DeviceItem>;
Expand All @@ -21,6 +22,12 @@ const ExistingDeviceConnectionTest: React.FC<ConnectionTestTabProps> = ({
>();
const [dockerConnectionErrorMessage, setDockerConnectionErrorMessage] =
useState<string | undefined>();
const [rsiConnectionStatus, setRsiConnectionStatus] = useState<
string | undefined
>();
const [rsiConnectionErrorMessage, setRsiConnectionErrorMessage] = useState<
string | undefined
>();
const [testStarted, setTestStarted] = useState(false);
const asyncFetch = async () => {
if (!device.uuid) {
Expand All @@ -29,6 +36,8 @@ const ExistingDeviceConnectionTest: React.FC<ConnectionTestTabProps> = ({
setExecId(undefined);
setDockerConnectionErrorMessage(undefined);
setDockerConnectionStatus('running...');
setRsiConnectionErrorMessage(undefined);
setRsiConnectionStatus('running...');
setTestStarted(true);
await getCheckDeviceAnsibleConnection(device.uuid).then((e) => {
setExecId(e.data.taskId);
Expand All @@ -37,6 +46,14 @@ const ExistingDeviceConnectionTest: React.FC<ConnectionTestTabProps> = ({
setDockerConnectionStatus(e.data.connectionStatus);
setDockerConnectionErrorMessage(e.data.errorMessage);
});
if (device.agentType === SsmAgent.InstallMethods.LESS) {
await getCheckDeviceRemoteSystemInformationConnection(device.uuid).then(
(e) => {
setRsiConnectionStatus(e.data.connectionStatus);
setRsiConnectionErrorMessage(e.data.errorMessage);
},
);
}
};
return (
<Card
Expand Down Expand Up @@ -69,9 +86,12 @@ const ExistingDeviceConnectionTest: React.FC<ConnectionTestTabProps> = ({
>
{testStarted && (
<CheckDeviceConnection
installMethod={device.agentType as SsmAgent.InstallMethods}
execId={execId}
dockerConnRes={dockerConnectionStatus}
dockerConnErrorMessage={dockerConnectionErrorMessage}
rsiConnRes={rsiConnectionStatus}
rsiConnErrorMessage={rsiConnectionErrorMessage}
/>
)}
<Button style={{ marginBottom: 20 }} onClick={asyncFetch}>
Expand Down
Loading

0 comments on commit ca50d84

Please sign in to comment.