Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEL - Pi Management Console #64

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
43d796d
feat(tel-server): outline of pi management backend
davidbeechey Dec 28, 2023
eb115fb
feat(tel-server): current git branch endpoint
davidbeechey Dec 28, 2023
c020521
feat(tel-server): add uncommitted changes to git branch response
davidbeechey Dec 28, 2023
60bca50
Merge branch 'master' into tel-pi_mgt
davidbeechey Jan 26, 2024
bdb4db7
feat(tel-server): rename folder, change path
davidbeechey Jan 26, 2024
ea6dac2
add shadcn/ui table component
davidbeechey Jan 26, 2024
8d497d2
feat(tel-ui): Pi management console outline
davidbeechey Jan 29, 2024
8cb5ee7
feat(tel-ui): add more table features
davidbeechey Jan 29, 2024
a4d2595
feat(tel-ui): add Pi online/offline status
davidbeechey Jan 29, 2024
6b05c1f
feat(tel-ui): update individual pis
davidbeechey Jan 29, 2024
5da9ee1
fix server packages
davidbeechey Feb 12, 2024
90cc6de
Merge branch 'master' into tel-pi_mgt
davidbeechey Feb 19, 2024
a554406
tel(pi-mgt): fix errors after merge
davidbeechey Feb 19, 2024
7a0c805
fix(tel-pi): fix build/lint errors
davidbeechey Feb 19, 2024
72af897
wip(tel-pi): add TODOs
davidbeechey Feb 19, 2024
def662b
wip(tel-pi): move files to `views` folder, podId
davidbeechey Feb 19, 2024
fade2c5
fix(tel-pi): formatting
davidbeechey Feb 19, 2024
7492d73
wip(tel-pi): simulate delay
davidbeechey Feb 19, 2024
c0a0a4d
wip(tel-pi): start working on connecting to Pi
davidbeechey Feb 22, 2024
ea004d3
Merge branch 'master' into tel-pi_mgt
davidbeechey Feb 29, 2024
c124bfc
wip(tel-ui): changes to data fetching
davidbeechey Mar 14, 2024
618d6cd
wip(tel-ui): start working on branch selection
davidbeechey Mar 15, 2024
789f548
wip(tel-ui): add branch selector
davidbeechey Mar 15, 2024
78d3192
Merge branch 'master' into tel-pi_mgt
davidbeechey Apr 28, 2024
6668a44
feat(tel-server): pi management server implemented?
davidbeechey Apr 29, 2024
c553386
Merge branch 'master' into tel-pi_mgt
davidbeechey May 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions telemetry/packages/constants/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export type { PodStateType, PodStateCategoryType } from './pods/states';
export { MODES, MODE_EXCLUDED_STATES } from './pods/modes';
export type { ModeType } from './pods/modes';
export { openMctObjectTypes } from './openmct/object-types/object-types';

export * as socket from './socket';

export { FAULT_LEVEL } from './faults/levels';
export type { FaultLevel } from './faults/levels';
13 changes: 13 additions & 0 deletions telemetry/packages/constants/src/pods/pods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ export const pods: Pods = {
sampling_time: 500,
},
},
pis: {},
},

pod_2024: {
Expand Down Expand Up @@ -875,5 +876,17 @@ export const pods: Pods = {
sampling_time: 500,
},
},
pis: {
pi_1: {
id: 'pi_1',
ip: '192.168.1.41',
hostname: 'pi-1',
},
pi_2: {
id: 'pi_2',
ip: '192.168.1.42',
hostname: 'pi-2',
},
},
},
};
6 changes: 4 additions & 2 deletions telemetry/packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,24 @@
"@nestjs/websockets": "^9.4.2",
"dotenv": "^16.0.3",
"env-var": "^7.3.0",
"is-reachable": "^5.2.1",
"mqtt": "^4.3.7",
"nanoid": "^3.3.6",
"nest-mqtt": "^0.2.0",
"nest-winston": "^1.9.1",
"node-scp": "^0.0.23",
"random": "^3.0.6",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.0",
"socket.io": "^4.6.2",
"socket.io-client": "^4.6.2",
"winston": "^3.8.2",
"winston-transport": "^4.6.0",
"winston-transport": "^4.7.0",
"zod": "^3.21.4"
},
"devDependencies": {
"@hyped/telemetry-types": "workspace:*",
"@hyped/eslint-config": "workspace:*",
"@hyped/telemetry-types": "workspace:*",
"@hyped/tsconfig": "workspace:*",
"@nestjs/cli": "^9.1.8",
"@nestjs/schematics": "^9.0.4",
Expand Down
22 changes: 22 additions & 0 deletions telemetry/packages/server/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@ import { AppService } from './app.service';
export class AppController {
constructor(private readonly appService: AppService) {}

@Get('/info/git/current-branch')
public async getBranch() {
return {
branch: await this.appService.getBranch(),
uncommittedChanges: await this.appService.getUncommittedChanges(),
};
}

@Get('/info/git/commit-sha')
public async getCommitSha() {
return {
sha: await this.appService.getCommitSha(),
};
}

@Get('/info/git/all-branches')
public async getAllBranches() {
return {
branches: await this.appService.getAllBranches(),
};
}

@Get('ping')
getPing(): string {
return this.appService.getPing();
Expand Down
2 changes: 2 additions & 0 deletions telemetry/packages/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { WarningsModule } from './modules/warnings/Warnings.module';
import { RemoteLogsModule } from './modules/remote-logs/RemoteLogs.module';
import { PublicDataModule } from './modules/public-data/PublicData.module';
import { LiveLogsGateway } from './modules/live-logs/LiveLogs.gateway';
import { PiManagementModule } from './modules/pi-management/PiManagement.module';

@Module({
imports: [
Expand All @@ -27,6 +28,7 @@ import { LiveLogsGateway } from './modules/live-logs/LiveLogs.gateway';
WarningsModule,
RemoteLogsModule,
PublicDataModule,
PiManagementModule,
],
controllers: [AppController],
providers: [AppService, LiveLogsGateway],
Expand Down
71 changes: 71 additions & 0 deletions telemetry/packages/server/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,78 @@
import { Injectable } from '@nestjs/common';
import { exec } from 'child_process';

@Injectable()
export class AppService {
/**
* Gets the current branch which the base station is using (i.e. the branch that this code is currently running on).
* Should be main but could be something else if we're testing something or if we're in a feature branch.
*/
public getBranch() {
return new Promise<string>((resolve, reject) => {
exec('git rev-parse --abbrev-ref HEAD', (err, stdout) => {
if (err) {
reject(err);
} else {
resolve(stdout.trim());
}
});
});
}

/**
* Checks whether there are uncommitted changes on the current branch.
* TODO: we probably don't need this because we'll be cloning a temporary
* repository for the purposes of building?
* @returns `true` if there are uncommitted changes, `false` otherwise.
*/
public getUncommittedChanges() {
return new Promise<boolean>((resolve, reject) => {
exec('git status --porcelain', (err, stdout) => {
if (err) {
reject(err);
} else {
resolve(stdout.trim().length > 0);
}
});
});
}

/**
* Gets the commit SHA of the current branch.
*/
public getCommitSha() {
return new Promise<string>((resolve, reject) => {
exec('git rev-parse HEAD', (err, stdout) => {
if (err) {
reject(err);
} else {
resolve(stdout.trim());
}
});
});
}

/**
* Gets all of the possible branches we could build and deploy to the pis.
* (Including remote branches, not just local ones.)
*/
public getAllBranches() {
return new Promise<string[]>((resolve, reject) => {
exec('git branch -a --format="%(refname:short)"', (err, stdout) => {
if (err) {
reject(err);
} else {
resolve(
stdout
.split('\n')
.map((branch) => branch.trim())
.filter((branch) => branch.length > 0),
);
}
});
});
}

getPing(): string {
return 'pong';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { POD_IDS, PodId } from '@hyped/telemetry-constants';
import { HttpException } from '@nestjs/common';

/**
* Validates that the pod ID is valid (exists in the pods object)
* @param podId Pod ID to validate
*/
export function validatePodId(podId: string): asserts podId is PodId {
if (!POD_IDS.includes(podId as PodId)) {
throw new HttpException(`Unknown pod ID: ${podId}`, 400);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {
Controller,
Get,
HttpException,
Param,
Post,
Query,
} from '@nestjs/common';
import { PiManagementService } from './PiManagement.service';
import { validatePodId } from '../common/utils/validatePodId';
import { PodId, pods } from '@hyped/telemetry-constants';

@Controller('pods/:podId/pis')
export class PiManagementController {
constructor(private piManagementService: PiManagementService) {}

@Get()
async getAllPis(
@Param('podId') podId: string,
@Query('compareBranch') compareBranch: string,
) {
validatePodId(podId);
return this.piManagementService.getAllPis(podId, compareBranch);
}

@Get(':piId')
async getPi(
@Param('podId') podId: string,
@Param('piId') piId: string,
@Query('compareBranch') compareBranch: string,
) {
validatePodId(podId);
this.validatePiId(podId, piId);
return this.piManagementService.getPi(podId, piId, compareBranch);
}

@Post(':piId/update-binary')
async updatePiBinary(
@Param('podId') podId: string,
@Param('piId') piId: string,
@Query('compareBranch') compareBranch: string,
) {
validatePodId(podId);
this.validatePiId(podId, piId);
return this.piManagementService.updatePiBinary(podId, piId, compareBranch);
}

@Post(':piId/update-config')
async updatePiConfig(
@Param('podId') podId: string,
@Param('piId') piId: string,
@Query('compareBranch') compareBranch: string,
) {
validatePodId(podId);
this.validatePiId(podId, piId);
return this.piManagementService.updatePiConfig(podId, piId, compareBranch);
}

private validatePiId(podId: PodId, piId: string) {
const pi = pods[podId].pis[piId];
if (!pi) {
throw new HttpException(`Unknown pi ID: ${piId} on pod ${podId}`, 400);
}
return pi;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { PiManagementController } from './PiManagement.controller';
import { PiManagementService } from './PiManagement.service';

@Module({
controllers: [PiManagementController],
providers: [PiManagementService],
})
export class PiManagementModule {}
Loading
Loading