Skip to content

Commit

Permalink
Merge pull request #99 from playground/oh-mesh
Browse files Browse the repository at this point in the history
refactor unregisterMeshAgent
  • Loading branch information
playground authored Feb 21, 2024
2 parents 22422bf + 74e8662 commit 1b08cfc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hzn-cli",
"version": "0.7.5",
"version": "0.7.6",
"description": "Open Horizon CLI toolkit helps streamline the process of preparing node agents and perform tasks between orgs environments",
"main": "./build/index.js",
"bin": {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { existsSync } from 'fs';

import { Hzn, utils } from '../common/src/hzn';
import { customRun, IHznParam, justRun, loop, promptForUpdate, runDirectly } from '../common/src/interface';
import { IAutoParam } from '../common/src/interface/hzn-model';
import { IAutoParam, justRunCliOptional } from '../common/src/interface/hzn-model';

import type { Arguments, CommandBuilder } from 'yargs';
type Options = {
Expand Down Expand Up @@ -91,7 +91,7 @@ export const handler = (argv: Arguments<Options>): void => {
} as IHznParam;
const hzn = new Hzn(hznModel);

hzn.init()
hzn.init(justRunCliOptional.indexOf(action) >= 0)
.subscribe({
complete: () => {
if(loop.includes(action)) {
Expand Down
28 changes: 16 additions & 12 deletions src/common/src/hzn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Hzn {
this.mmsPattern = param.mmsPattern;
}

init() {
init(cliOptional = false) {
return new Observable((observer) => {
this.envVar.init()
.subscribe({
Expand Down Expand Up @@ -102,16 +102,20 @@ export class Hzn {
}
})
} else {
this.preInstallHznCli()
.subscribe({
complete: () => {
console.log('done installing hzn.');
observer.complete();
},
error: (err) => {
observer.error(err);
}
})
if(cliOptional == true) {
observer.complete();
} else {
this.preInstallHznCli()
.subscribe({
complete: () => {
console.log('done installing hzn.');
observer.complete();
},
error: (err) => {
observer.error(err);
}
})
}
}
} else {
observer.error(err);
Expand Down Expand Up @@ -210,7 +214,7 @@ export class Hzn {
return utils.registerMeshAgent();
}
unregisterMeshAgent() {
return utils.unregisterMeshAgent();
return this.param.name.length > 0 ? utils.unregisterMeshAgent(this.param) : of('Please specify agent name')
}
unregisterAgent() {
return utils.unregisterAgent(true)
Expand Down
3 changes: 3 additions & 0 deletions src/common/src/interface/hzn-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export const justRun = [
'register', 'removeDeploymentPolicy', 'removeObject', 'removeOrg',
'removeNode', 'removeService', 'reviewPolicy', 'reviewServiceDefinition', 'unregisterMeshAgent', "registerMeshAgent"
];
export const justRunCliOptional = [
'registerMeshAgent', 'unregisterMeshAgent'
];
export const promptForUpdate = [
'setup', 'test', 'buildAndPublish', 'buildPublishAndRegister',
'buildMMSImage', 'buildServiceImage', 'editDeploymentPoicy', 'editNodePolicy', 'editServicePolicy', 'publishAndRegister',
Expand Down
6 changes: 4 additions & 2 deletions src/common/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -979,9 +979,11 @@ export class Utils {
uninstallK3s() {
return this.shell(`sudo systemctl stop k3s && /usr/local/bin/k3s-uninstall.sh`);
}
unregisterMeshAgent() {
unregisterMeshAgent(params: IHznParam) {
const pEnv = process.env;
const arg = `curl -sL --insecure -u $HZN_ORG_ID/$HZN_EXCHANGE_USER_AUTH -X DELETE ${pEnv.MESH_ENDPOINT}/v1/orgs/${pEnv.HZN_ORG_ID}/nodes/${pEnv.HZN_DEVICE_ID}`;
//const arg = `curl -sL --insecure -u $HZN_ORG_ID/$HZN_EXCHANGE_USER_AUTH -X DELETE ${pEnv.MESH_ENDPOINT}/v1/orgs/${pEnv.HZN_ORG_ID}/nodes/${pEnv.HZN_DEVICE_ID}`;
//const arg = `kubectl -n ohmesh3-frontend-ns exec -i agent-769d687ff9-8kssh -- hzn unregister -r -f --timeout 3`;
const arg = `kubectl -n ${pEnv.AGENT_NAMESPACE} exec -i ${params.name} -- hzn unregister -r -f --timeout 3`;
return this.shell(arg);
}
installK3s(params: IAutoParam) {
Expand Down

0 comments on commit 1b08cfc

Please sign in to comment.