@alwaysai/device-agent 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/lib/application-control/config.js +1 -1
  2. package/lib/application-control/config.js.map +1 -1
  3. package/lib/application-control/install.d.ts.map +1 -1
  4. package/lib/application-control/install.js +2 -2
  5. package/lib/application-control/install.js.map +1 -1
  6. package/lib/cloud-connection/base-message-handler.d.ts.map +1 -1
  7. package/lib/cloud-connection/base-message-handler.js +5 -4
  8. package/lib/cloud-connection/base-message-handler.js.map +1 -1
  9. package/lib/cloud-connection/connection-manager.js +2 -2
  10. package/lib/cloud-connection/connection-manager.js.map +1 -1
  11. package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
  12. package/lib/cloud-connection/device-agent-cloud-connection.js +3 -8
  13. package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
  14. package/lib/cloud-connection/device-agent-message-handler.d.ts.map +1 -1
  15. package/lib/cloud-connection/device-agent-message-handler.js +19 -18
  16. package/lib/cloud-connection/device-agent-message-handler.js.map +1 -1
  17. package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
  18. package/lib/cloud-connection/live-updates-handler.js +11 -4
  19. package/lib/cloud-connection/live-updates-handler.js.map +1 -1
  20. package/lib/cloud-connection/passthrough-handler.d.ts +3 -3
  21. package/lib/cloud-connection/passthrough-handler.d.ts.map +1 -1
  22. package/lib/cloud-connection/passthrough-handler.js +97 -74
  23. package/lib/cloud-connection/passthrough-handler.js.map +1 -1
  24. package/lib/cloud-connection/shadow-handler.js +3 -3
  25. package/lib/cloud-connection/shadow-handler.js.map +1 -1
  26. package/lib/cloud-connection/shadow.d.ts.map +1 -1
  27. package/lib/cloud-connection/shadow.js +1 -1
  28. package/lib/cloud-connection/shadow.js.map +1 -1
  29. package/lib/cloud-connection/transaction-manager.d.ts.map +1 -1
  30. package/lib/cloud-connection/transaction-manager.js +17 -7
  31. package/lib/cloud-connection/transaction-manager.js.map +1 -1
  32. package/lib/cloud-connection/transaction-manager.test.js +52 -44
  33. package/lib/cloud-connection/transaction-manager.test.js.map +1 -1
  34. package/lib/device-control/device-control.d.ts.map +1 -1
  35. package/lib/device-control/device-control.js +13 -9
  36. package/lib/device-control/device-control.js.map +1 -1
  37. package/lib/docker/docker-compose.d.ts.map +1 -1
  38. package/lib/docker/docker-compose.js +1 -1
  39. package/lib/docker/docker-compose.js.map +1 -1
  40. package/lib/environment.d.ts.map +1 -1
  41. package/lib/environment.js +1 -1
  42. package/lib/environment.js.map +1 -1
  43. package/lib/index.js +12 -0
  44. package/lib/index.js.map +1 -1
  45. package/lib/infrastructure/config-check-utility.js +2 -2
  46. package/lib/infrastructure/config-check-utility.js.map +1 -1
  47. package/lib/infrastructure/legacy-migration/legacy-migration.d.ts.map +1 -1
  48. package/lib/infrastructure/legacy-migration/legacy-migration.js +6 -10
  49. package/lib/infrastructure/legacy-migration/legacy-migration.js.map +1 -1
  50. package/lib/local-connection/rabbitmq-container.d.ts +6 -0
  51. package/lib/local-connection/rabbitmq-container.d.ts.map +1 -0
  52. package/lib/local-connection/rabbitmq-container.js +111 -0
  53. package/lib/local-connection/rabbitmq-container.js.map +1 -0
  54. package/lib/local-connection/rabbitmq-container.test.d.ts +2 -0
  55. package/lib/local-connection/rabbitmq-container.test.d.ts.map +1 -0
  56. package/lib/local-connection/rabbitmq-container.test.js +219 -0
  57. package/lib/local-connection/rabbitmq-container.test.js.map +1 -0
  58. package/lib/subcommands/device/clean.d.ts.map +1 -1
  59. package/lib/subcommands/device/clean.js +15 -17
  60. package/lib/subcommands/device/clean.js.map +1 -1
  61. package/lib/subcommands/device/index.d.ts.map +1 -1
  62. package/lib/subcommands/device/index.js +3 -1
  63. package/lib/subcommands/device/index.js.map +1 -1
  64. package/lib/subcommands/device/local-connection.d.ts +2 -0
  65. package/lib/subcommands/device/local-connection.d.ts.map +1 -0
  66. package/lib/subcommands/device/local-connection.js +17 -0
  67. package/lib/subcommands/device/local-connection.js.map +1 -0
  68. package/lib/subcommands/index.d.ts +4 -1
  69. package/lib/subcommands/index.d.ts.map +1 -1
  70. package/lib/subcommands/index.js +1 -3
  71. package/lib/subcommands/index.js.map +1 -1
  72. package/lib/util/check-for-updates.d.ts.map +1 -1
  73. package/lib/util/check-for-updates.js +2 -2
  74. package/lib/util/check-for-updates.js.map +1 -1
  75. package/lib/util/file.d.ts.map +1 -1
  76. package/lib/util/file.js +6 -1
  77. package/lib/util/file.js.map +1 -1
  78. package/lib/util/file.test.js +1 -1
  79. package/lib/util/file.test.js.map +1 -1
  80. package/lib/util/get-device-id.d.ts.map +1 -1
  81. package/lib/util/get-device-id.js +1 -1
  82. package/lib/util/get-device-id.js.map +1 -1
  83. package/package.json +2 -2
  84. package/src/application-control/config.ts +1 -1
  85. package/src/application-control/install.ts +3 -2
  86. package/src/cloud-connection/base-message-handler.ts +10 -5
  87. package/src/cloud-connection/connection-manager.ts +2 -2
  88. package/src/cloud-connection/device-agent-cloud-connection.ts +6 -10
  89. package/src/cloud-connection/device-agent-message-handler.ts +10 -7
  90. package/src/cloud-connection/live-updates-handler.ts +12 -5
  91. package/src/cloud-connection/passthrough-handler.ts +79 -38
  92. package/src/cloud-connection/shadow-handler.ts +3 -3
  93. package/src/cloud-connection/shadow.ts +3 -1
  94. package/src/cloud-connection/transaction-manager.test.ts +60 -41
  95. package/src/cloud-connection/transaction-manager.ts +26 -12
  96. package/src/device-control/device-control.ts +23 -13
  97. package/src/docker/docker-compose.ts +3 -1
  98. package/src/environment.ts +1 -2
  99. package/src/index.ts +19 -0
  100. package/src/infrastructure/config-check-utility.ts +2 -2
  101. package/src/infrastructure/legacy-migration/legacy-migration.ts +8 -13
  102. package/src/local-connection/rabbitmq-container.test.ts +255 -0
  103. package/src/local-connection/rabbitmq-container.ts +151 -0
  104. package/src/subcommands/device/clean.ts +20 -19
  105. package/src/subcommands/device/index.ts +3 -1
  106. package/src/subcommands/device/local-connection.ts +16 -0
  107. package/src/subcommands/index.ts +1 -3
  108. package/src/util/check-for-updates.ts +4 -2
  109. package/src/util/file.test.ts +1 -1
  110. package/src/util/file.ts +7 -1
  111. package/src/util/get-device-id.ts +3 -1
  112. package/lib/local-connection/rabbitmq-connection.d.ts +0 -7
  113. package/lib/local-connection/rabbitmq-connection.d.ts.map +0 -1
  114. package/lib/local-connection/rabbitmq-connection.js +0 -95
  115. package/lib/local-connection/rabbitmq-connection.js.map +0 -1
  116. package/lib/subcommands/rabbitmq-connection.d.ts +0 -2
  117. package/lib/subcommands/rabbitmq-connection.d.ts.map +0 -1
  118. package/lib/subcommands/rabbitmq-connection.js +0 -14
  119. package/lib/subcommands/rabbitmq-connection.js.map +0 -1
  120. package/src/local-connection/rabbitmq-connection.ts +0 -124
  121. package/src/subcommands/rabbitmq-connection.ts +0 -11
@@ -0,0 +1,16 @@
1
+ import { CliLeaf } from '@alwaysai/alwayscli';
2
+ import { stopRabbitMQContainer } from '../../local-connection/rabbitmq-container';
3
+ import { logger } from '../../util/logger';
4
+ import { getDeviceAgentDockerComposePath } from '../../util/directories';
5
+
6
+ export const stopLocalConnectionCliLeaf = CliLeaf({
7
+ name: 'stop-local-connection',
8
+ description: 'Stop the Device Agent local connection container',
9
+ async action(_, opts) {
10
+ if ((await stopRabbitMQContainer()) === false) {
11
+ logger.error(
12
+ `You may need to manually stop the container by running docker-compose down in the following directory: ${getDeviceAgentDockerComposePath()}`
13
+ );
14
+ }
15
+ }
16
+ });
@@ -3,13 +3,11 @@ import { configBranch } from './config';
3
3
  import { deviceCliBranch } from './device';
4
4
  import { getModelPackageCliLeaf } from './get-model-package';
5
5
  import { loginCliLeaf } from './login';
6
- import { stopRabbitMQContainerCliLeaf } from './rabbitmq-connection';
7
6
 
8
7
  export const subcommands = [
9
8
  loginCliLeaf,
10
9
  configBranch,
11
10
  appCliBranch,
12
11
  deviceCliBranch,
13
- getModelPackageCliLeaf,
14
- stopRabbitMQContainerCliLeaf
12
+ getModelPackageCliLeaf
15
13
  ];
@@ -20,7 +20,9 @@ export async function getDeviceAgentVersion(): Promise<string> {
20
20
  daVersion = parsed.version;
21
21
  } catch (e) {
22
22
  logger.error(
23
- `Could not retrieve the Device Agent version!\n${stringifyError(e)}`
23
+ `Could not retrieve the Device Agent version! Error:\n${stringifyError(
24
+ e
25
+ )}`
24
26
  );
25
27
  }
26
28
  return daVersion;
@@ -48,6 +50,6 @@ export async function checkForUpdatesAndPrompt() {
48
50
  );
49
51
  }
50
52
  } catch (e) {
51
- logger.error(`Could not check for updates!\n${stringifyError(e)}`);
53
+ logger.error(`Could not check for updates! Error:\n${stringifyError(e)}`);
52
54
  }
53
55
  }
@@ -80,7 +80,7 @@ describe('pruneDir function', () => {
80
80
 
81
81
  const result = await pruneDir({ path: rootPath, recurse: false });
82
82
 
83
- expect(result).toBe(true);
83
+ expect(result).toBe(false);
84
84
  expect(readdir).toHaveBeenCalledWith(rootPath);
85
85
  expect(stat).toHaveBeenCalledTimes(2); // Called for file1.txt and subdir
86
86
  expect(unlink).toHaveBeenCalledWith(`${rootPath}/file1.txt`);
package/src/util/file.ts CHANGED
@@ -65,6 +65,10 @@ export async function pruneDir({
65
65
  } else {
66
66
  canPruneParent = false;
67
67
  }
68
+ } else {
69
+ // Directory encountered but recursion is not allowed, parent cannot be pruned
70
+ logger.debug(`Skipping directory ${filePath} as recurse is false.`);
71
+ canPruneParent = false;
68
72
  }
69
73
  } else {
70
74
  await unlink(filePath);
@@ -72,7 +76,9 @@ export async function pruneDir({
72
76
  }
73
77
  return canPruneParent;
74
78
  } catch (e) {
75
- logger.error(`Error pruning directory ${path}!\n${stringifyError(e)}`);
79
+ logger.error(
80
+ `Error pruning directory ${path}! Error:\n${stringifyError(e)}`
81
+ );
76
82
  return false;
77
83
  }
78
84
  }
@@ -12,7 +12,9 @@ export function getDeviceUuid() {
12
12
  const cfg = deviceCfgFile.read();
13
13
  return cfg.deviceUuid;
14
14
  } catch (e) {
15
- logger.error(`Failed to read device configuration!\n${stringifyError(e)}`);
15
+ logger.error(
16
+ `Failed to read device configuration! Error:\n${stringifyError(e)}`
17
+ );
16
18
  throw new AaiError('Failed to read device configuration', {
17
19
  cause: deviceCfgFile.getErrors()
18
20
  });
@@ -1,7 +0,0 @@
1
- export declare const rabbitMQServiceName = "alwaysAIRabbitMQ";
2
- export declare const rabbitMQContainerName = "alwaysAIRabbitMQContainer";
3
- export declare function checkRabbitMQContainerRunning(): Promise<boolean>;
4
- export declare function writeRabbitMQDockerComposeFile(): Promise<void>;
5
- export declare function setupRabbitMQContainer(): Promise<void>;
6
- export declare function stopRabbitMQContainer(): Promise<void>;
7
- //# sourceMappingURL=rabbitmq-connection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rabbitmq-connection.d.ts","sourceRoot":"","sources":["../../src/local-connection/rabbitmq-connection.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,mBAAmB,qBAAqB,CAAC;AACtD,eAAO,MAAM,qBAAqB,8BAA8B,CAAC;AAEjE,wBAAsB,6BAA6B,qBAwBlD;AAED,wBAAsB,8BAA8B,kBAgCnD;AAED,wBAAsB,sBAAsB,kBA+B3C;AAED,wBAAsB,qBAAqB,kBAgB1C"}
@@ -1,95 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stopRabbitMQContainer = exports.setupRabbitMQContainer = exports.writeRabbitMQDockerComposeFile = exports.checkRabbitMQContainerRunning = exports.rabbitMQContainerName = exports.rabbitMQServiceName = void 0;
4
- const util_1 = require("alwaysai/lib/util");
5
- const YAML = require("yaml");
6
- const docker_compose_1 = require("../docker/docker-compose");
7
- const directories_1 = require("../util/directories");
8
- const logger_1 = require("../util/logger");
9
- const sleep_1 = require("../util/sleep");
10
- const constants_1 = require("./constants");
11
- exports.rabbitMQServiceName = 'alwaysAIRabbitMQ';
12
- exports.rabbitMQContainerName = 'alwaysAIRabbitMQContainer';
13
- async function checkRabbitMQContainerRunning() {
14
- logger_1.logger.debug('Checking alwaysAI Local Connection Container status');
15
- const spawner = (0, util_1.JsSpawner)();
16
- if (!(await spawner.exists((0, directories_1.getDeviceAgentDockerComposePath)()))) {
17
- logger_1.logger.warn('alwaysAI Location Connection configuration file is not present');
18
- return false;
19
- }
20
- const containerData = await docker_compose_1.compose.ps({ cwd: (0, directories_1.getDeviceAgentConfigPath)() });
21
- if (containerData !== undefined) {
22
- const rabbitmqService = containerData.data.services[0];
23
- if ((rabbitmqService === null || rabbitmqService === void 0 ? void 0 : rabbitmqService.name) === exports.rabbitMQContainerName &&
24
- rabbitmqService.state.includes('Up')) {
25
- logger_1.logger.debug('alwaysAI Local Connection Container is up');
26
- return true;
27
- }
28
- logger_1.logger.debug('alwaysAI Local Connection Container is not up');
29
- return false;
30
- }
31
- logger_1.logger.warn('alwaysAI Local Connection Container is undefined');
32
- return false;
33
- }
34
- exports.checkRabbitMQContainerRunning = checkRabbitMQContainerRunning;
35
- async function writeRabbitMQDockerComposeFile() {
36
- const spawner = (0, util_1.JsSpawner)();
37
- if (!(await spawner.exists((0, directories_1.getDeviceAgentConfigPath)()))) {
38
- await (0, util_1.JsSpawner)().mkdirp((0, directories_1.getDeviceAgentConfigPath)());
39
- }
40
- logger_1.logger.debug(`Writing Local Connection Docker compose files with Local Connection port: ${constants_1.LOCAL_CONNECTION_PORT}`);
41
- const rabbitmqDockerComposeCmd = {
42
- services: {
43
- [exports.rabbitMQServiceName]: {
44
- container_name: exports.rabbitMQContainerName,
45
- image: 'rabbitmq:3.11',
46
- ports: [`${constants_1.LOCAL_CONNECTION_PORT}:${constants_1.LOCAL_CONNECTION_PORT}`],
47
- hostname: 'my-rabbit',
48
- restart: 'on-failure',
49
- environment: [`RABBITMQ_NODE_PORT=${constants_1.LOCAL_CONNECTION_PORT}`],
50
- volumes: [
51
- './rabbitmq/:/var/lib/rabbitmq/',
52
- './rabbitmq/log/:/var/log/rabbitmq/'
53
- ]
54
- }
55
- }
56
- };
57
- const RabbitMQDockerComposeYaml = YAML.stringify(rabbitmqDockerComposeCmd);
58
- await spawner.writeFile((0, directories_1.getDeviceAgentDockerComposePath)(), RabbitMQDockerComposeYaml);
59
- }
60
- exports.writeRabbitMQDockerComposeFile = writeRabbitMQDockerComposeFile;
61
- async function setupRabbitMQContainer() {
62
- logger_1.logger.debug('Attempting to start the alwaysAI Local Connection Container');
63
- try {
64
- await writeRabbitMQDockerComposeFile();
65
- }
66
- catch (e) {
67
- logger_1.logger.error(`An error occurred setting up docker-compose.yaml for Device Agent pass through!\n${(0, util_1.stringifyError)(e)}`);
68
- }
69
- try {
70
- const upOut = await docker_compose_1.compose.upAll({
71
- cwd: (0, directories_1.getDeviceAgentConfigPath)()
72
- });
73
- logger_1.logger.debug(`Docker compose up for alwaysAI Local Connection:\n${JSON.stringify(upOut)}`);
74
- // check if the container is up
75
- while (!(await checkRabbitMQContainerRunning())) {
76
- await (0, sleep_1.default)(10);
77
- }
78
- }
79
- catch (e) {
80
- logger_1.logger.error(`Unable to start alwaysAI Device Agent Local Connection Container!\n${(0, util_1.stringifyError)(e)}`);
81
- }
82
- }
83
- exports.setupRabbitMQContainer = setupRabbitMQContainer;
84
- async function stopRabbitMQContainer() {
85
- try {
86
- const downOut = await docker_compose_1.compose.down({ cwd: (0, directories_1.getDeviceAgentConfigPath)() });
87
- logger_1.logger.debug(`Stopping alwaysAI Local Connection container`);
88
- logger_1.logger.debug(`Docker compose down for alwaysAI Local Connection:\n${JSON.stringify(downOut)}`);
89
- }
90
- catch (e) {
91
- logger_1.logger.error(`Unable to stop alwaysAI Device Agent Local Connection Container!\n${(0, util_1.stringifyError)(e)}`);
92
- }
93
- }
94
- exports.stopRabbitMQContainer = stopRabbitMQContainer;
95
- //# sourceMappingURL=rabbitmq-connection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rabbitmq-connection.js","sourceRoot":"","sources":["../../src/local-connection/rabbitmq-connection.ts"],"names":[],"mappings":";;;AAAA,4CAA8D;AAC9D,6BAA6B;AAC7B,6DAAmD;AACnD,qDAG6B;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C/C,MAAM,IAAA,eAAK,EAAC,EAAE,CAAC,CAAC;SACjB;KACF;IAAC,OAAO,CAAC,EAAE;QACV,eAAM,CAAC,KAAK,CACV,sEAAsE,IAAA,qBAAc,EAClF,CAAC,CACF,EAAE,CACJ,CAAC;KACH;AACH,CAAC;AA/BD,wDA+BC;AAEM,KAAK,UAAU,qBAAqB;IACzC,IAAI;QACF,MAAM,OAAO,GAAG,MAAM,wBAAO,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAA,sCAAwB,GAAE,EAAE,CAAC,CAAC;QACxE,eAAM,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAC7D,eAAM,CAAC,KAAK,CACV,uDAAuD,IAAI,CAAC,SAAS,CACnE,OAAO,CACR,EAAE,CACJ,CAAC;KACH;IAAC,OAAO,CAAC,EAAE;QACV,eAAM,CAAC,KAAK,CACV,qEAAqE,IAAA,qBAAc,EACjF,CAAC,CACF,EAAE,CACJ,CAAC;KACH;AACH,CAAC;AAhBD,sDAgBC"}
@@ -1,2 +0,0 @@
1
- export declare const stopRabbitMQContainerCliLeaf: import("@alwaysai/alwayscli/lib/types").CliLeaf<import("@alwaysai/alwayscli").CliInput<undefined, false>, import("@alwaysai/alwayscli/lib/types").AnyNamedInputs, import("@alwaysai/alwayscli").CliInput<undefined, false>>;
2
- //# sourceMappingURL=rabbitmq-connection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rabbitmq-connection.d.ts","sourceRoot":"","sources":["../../src/subcommands/rabbitmq-connection.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,4BAA4B,6NAOvC,CAAC"}
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stopRabbitMQContainerCliLeaf = void 0;
4
- const alwayscli_1 = require("@alwaysai/alwayscli");
5
- const rabbitmq_connection_1 = require("../local-connection/rabbitmq-connection");
6
- exports.stopRabbitMQContainerCliLeaf = (0, alwayscli_1.CliLeaf)({
7
- name: 'stop-analytics-pass-through',
8
- description: 'Stop the Device Agent connection to edgeIQ',
9
- hidden: true,
10
- async action(_, opts) {
11
- await (0, rabbitmq_connection_1.stopRabbitMQContainer)();
12
- }
13
- });
14
- //# sourceMappingURL=rabbitmq-connection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rabbitmq-connection.js","sourceRoot":"","sources":["../../src/subcommands/rabbitmq-connection.ts"],"names":[],"mappings":";;;AAAA,mDAA8C;AAC9C,iFAAgF;AAEnE,QAAA,4BAA4B,GAAG,IAAA,mBAAO,EAAC;IAClD,IAAI,EAAE,6BAA6B;IACnC,WAAW,EAAE,4CAA4C;IACzD,MAAM,EAAE,IAAI;IACZ,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI;QAClB,MAAM,IAAA,2CAAqB,GAAE,CAAC;IAChC,CAAC;CACF,CAAC,CAAC"}
@@ -1,124 +0,0 @@
1
- import { JsSpawner, stringifyError } from 'alwaysai/lib/util';
2
- import * as YAML from 'yaml';
3
- import { compose } from '../docker/docker-compose';
4
- import {
5
- getDeviceAgentConfigPath,
6
- getDeviceAgentDockerComposePath
7
- } from '../util/directories';
8
- import { logger } from '../util/logger';
9
- import sleep from '../util/sleep';
10
- import { LOCAL_CONNECTION_PORT } from './constants';
11
-
12
- export const rabbitMQServiceName = 'alwaysAIRabbitMQ';
13
- export const rabbitMQContainerName = 'alwaysAIRabbitMQContainer';
14
-
15
- export async function checkRabbitMQContainerRunning() {
16
- logger.debug('Checking alwaysAI Local Connection Container status');
17
- const spawner = JsSpawner();
18
- if (!(await spawner.exists(getDeviceAgentDockerComposePath()))) {
19
- logger.warn(
20
- 'alwaysAI Location Connection configuration file is not present'
21
- );
22
- return false;
23
- }
24
- const containerData = await compose.ps({ cwd: getDeviceAgentConfigPath() });
25
- if (containerData !== undefined) {
26
- const rabbitmqService = containerData.data.services[0];
27
- if (
28
- rabbitmqService?.name === rabbitMQContainerName &&
29
- rabbitmqService.state.includes('Up')
30
- ) {
31
- logger.debug('alwaysAI Local Connection Container is up');
32
- return true;
33
- }
34
- logger.debug('alwaysAI Local Connection Container is not up');
35
- return false;
36
- }
37
- logger.warn('alwaysAI Local Connection Container is undefined');
38
- return false;
39
- }
40
-
41
- export async function writeRabbitMQDockerComposeFile() {
42
- const spawner = JsSpawner();
43
- if (!(await spawner.exists(getDeviceAgentConfigPath()))) {
44
- await JsSpawner().mkdirp(getDeviceAgentConfigPath());
45
- }
46
-
47
- logger.debug(
48
- `Writing Local Connection Docker compose files with Local Connection port: ${LOCAL_CONNECTION_PORT}`
49
- );
50
-
51
- const rabbitmqDockerComposeCmd = {
52
- services: {
53
- [rabbitMQServiceName]: {
54
- container_name: rabbitMQContainerName,
55
- image: 'rabbitmq:3.11',
56
- ports: [`${LOCAL_CONNECTION_PORT}:${LOCAL_CONNECTION_PORT}`],
57
- hostname: 'my-rabbit',
58
- restart: 'on-failure',
59
- environment: [`RABBITMQ_NODE_PORT=${LOCAL_CONNECTION_PORT}`],
60
- volumes: [
61
- './rabbitmq/:/var/lib/rabbitmq/',
62
- './rabbitmq/log/:/var/log/rabbitmq/'
63
- ]
64
- }
65
- }
66
- };
67
-
68
- const RabbitMQDockerComposeYaml = YAML.stringify(rabbitmqDockerComposeCmd);
69
- await spawner.writeFile(
70
- getDeviceAgentDockerComposePath(),
71
- RabbitMQDockerComposeYaml
72
- );
73
- }
74
-
75
- export async function setupRabbitMQContainer() {
76
- logger.debug('Attempting to start the alwaysAI Local Connection Container');
77
- try {
78
- await writeRabbitMQDockerComposeFile();
79
- } catch (e) {
80
- logger.error(
81
- `An error occurred setting up docker-compose.yaml for Device Agent pass through!\n${stringifyError(
82
- e
83
- )}`
84
- );
85
- }
86
- try {
87
- const upOut = await compose.upAll({
88
- cwd: getDeviceAgentConfigPath()
89
- });
90
- logger.debug(
91
- `Docker compose up for alwaysAI Local Connection:\n${JSON.stringify(
92
- upOut
93
- )}`
94
- );
95
- // check if the container is up
96
- while (!(await checkRabbitMQContainerRunning())) {
97
- await sleep(10);
98
- }
99
- } catch (e) {
100
- logger.error(
101
- `Unable to start alwaysAI Device Agent Local Connection Container!\n${stringifyError(
102
- e
103
- )}`
104
- );
105
- }
106
- }
107
-
108
- export async function stopRabbitMQContainer() {
109
- try {
110
- const downOut = await compose.down({ cwd: getDeviceAgentConfigPath() });
111
- logger.debug(`Stopping alwaysAI Local Connection container`);
112
- logger.debug(
113
- `Docker compose down for alwaysAI Local Connection:\n${JSON.stringify(
114
- downOut
115
- )}`
116
- );
117
- } catch (e) {
118
- logger.error(
119
- `Unable to stop alwaysAI Device Agent Local Connection Container!\n${stringifyError(
120
- e
121
- )}`
122
- );
123
- }
124
- }
@@ -1,11 +0,0 @@
1
- import { CliLeaf } from '@alwaysai/alwayscli';
2
- import { stopRabbitMQContainer } from '../local-connection/rabbitmq-connection';
3
-
4
- export const stopRabbitMQContainerCliLeaf = CliLeaf({
5
- name: 'stop-analytics-pass-through',
6
- description: 'Stop the Device Agent connection to edgeIQ',
7
- hidden: true,
8
- async action(_, opts) {
9
- await stopRabbitMQContainer();
10
- }
11
- });