@kapeta/local-cluster-service 0.16.6 → 0.16.8
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.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/src/instanceManager.js +30 -0
- package/dist/cjs/src/providerManager.d.ts +1 -2
- package/dist/cjs/src/providerManager.js +24 -3
- package/dist/esm/src/instanceManager.js +31 -1
- package/dist/esm/src/providerManager.d.ts +1 -2
- package/dist/esm/src/providerManager.js +24 -3
- package/package.json +1 -1
- package/src/instanceManager.ts +33 -7
- package/src/providerManager.ts +28 -6
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## [0.16.8](https://github.com/kapetacom/local-cluster-service/compare/v0.16.7...v0.16.8) (2023-08-30)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* Gracefully handled instances that have been deleted ([#64](https://github.com/kapetacom/local-cluster-service/issues/64)) ([e26ed35](https://github.com/kapetacom/local-cluster-service/commit/e26ed353e474b7417939008fb1eadec891d5ead9))
|
7
|
+
|
8
|
+
## [0.16.7](https://github.com/kapetacom/local-cluster-service/compare/v0.16.6...v0.16.7) (2023-08-24)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* Load JS from provider endpoints if not available locally ([#63](https://github.com/kapetacom/local-cluster-service/issues/63)) ([83c7cb4](https://github.com/kapetacom/local-cluster-service/commit/83c7cb4a176a2b23ee5bf5e8a312e8a64abd9ea6))
|
14
|
+
|
1
15
|
## [0.16.6](https://github.com/kapetacom/local-cluster-service/compare/v0.16.5...v0.16.6) (2023-08-21)
|
2
16
|
|
3
17
|
|
@@ -480,6 +480,36 @@ class InstanceManager {
|
|
480
480
|
if (instance.ref) {
|
481
481
|
instance.ref = (0, utils_1.normalizeKapetaUri)(instance.ref);
|
482
482
|
}
|
483
|
+
if (instance.desiredStatus === types_1.DesiredInstanceStatus.RUN) {
|
484
|
+
// Check if the plan still exists and the instance is still in the plan
|
485
|
+
// - and that the block definition exists
|
486
|
+
try {
|
487
|
+
const plan = await assetManager_1.assetManager.getAsset(instance.systemId, true, false);
|
488
|
+
if (!plan) {
|
489
|
+
instance.desiredStatus = types_1.DesiredInstanceStatus.STOP;
|
490
|
+
changed = true;
|
491
|
+
return;
|
492
|
+
}
|
493
|
+
const planData = plan.data;
|
494
|
+
const planInstance = planData?.spec?.blocks?.find((b) => b.id === instance.instanceId);
|
495
|
+
if (!planInstance || !planInstance?.block?.ref) {
|
496
|
+
instance.desiredStatus = types_1.DesiredInstanceStatus.STOP;
|
497
|
+
changed = true;
|
498
|
+
return;
|
499
|
+
}
|
500
|
+
const blockDef = await assetManager_1.assetManager.getAsset(instance.ref, true, false);
|
501
|
+
if (!blockDef) {
|
502
|
+
instance.desiredStatus = types_1.DesiredInstanceStatus.STOP;
|
503
|
+
changed = true;
|
504
|
+
return;
|
505
|
+
}
|
506
|
+
}
|
507
|
+
catch (e) {
|
508
|
+
console.warn('Failed to check assets', instance.systemId, e);
|
509
|
+
instance.desiredStatus = types_1.DesiredInstanceStatus.STOP;
|
510
|
+
return;
|
511
|
+
}
|
512
|
+
}
|
483
513
|
const newStatus = await this.requestInstanceStatus(instance);
|
484
514
|
/*
|
485
515
|
console.log('Check instance %s %s: [current: %s, new: %s, desired: %s]',
|
@@ -1,7 +1,6 @@
|
|
1
|
-
/// <reference types="node" />
|
2
1
|
declare class ProviderManager {
|
3
2
|
getWebProviders(): import("@kapeta/local-cluster-config").DefinitionInfo[];
|
4
|
-
getProviderWebJS(handle: string, name: string, version: string, sourceMap?: boolean): Promise<
|
3
|
+
getProviderWebJS(handle: string, name: string, version: string, sourceMap?: boolean): Promise<unknown>;
|
5
4
|
}
|
6
5
|
export declare const providerManager: ProviderManager;
|
7
6
|
export {};
|
@@ -6,9 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.providerManager = void 0;
|
7
7
|
const path_1 = __importDefault(require("path"));
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
9
|
-
const repositoryManager_1 = require("./repositoryManager");
|
10
9
|
const definitionsManager_1 = require("./definitionsManager");
|
11
10
|
const cacheManager_1 = require("./cacheManager");
|
11
|
+
const request_1 = __importDefault(require("request"));
|
12
|
+
const PROVIDER_FILE_BASE = 'https://providers.kapeta.com/files';
|
12
13
|
class ProviderManager {
|
13
14
|
getWebProviders() {
|
14
15
|
return definitionsManager_1.definitionsManager.getProviderDefinitions().filter((providerDefinition) => providerDefinition.hasWeb);
|
@@ -21,7 +22,6 @@ class ProviderManager {
|
|
21
22
|
if (file && (await fs_extra_1.default.pathExists(file))) {
|
22
23
|
return fs_extra_1.default.readFile(file, 'utf8');
|
23
24
|
}
|
24
|
-
await repositoryManager_1.repositoryManager.ensureAsset(handle, name, version, true);
|
25
25
|
const installedProvider = this.getWebProviders().find((providerDefinition) => {
|
26
26
|
return providerDefinition.definition.metadata.name === fullName && providerDefinition.version === version;
|
27
27
|
});
|
@@ -33,7 +33,28 @@ class ProviderManager {
|
|
33
33
|
return fs_extra_1.default.readFile(path);
|
34
34
|
}
|
35
35
|
}
|
36
|
-
|
36
|
+
if (version === 'local') {
|
37
|
+
return null;
|
38
|
+
}
|
39
|
+
const url = `${PROVIDER_FILE_BASE}/${id}`;
|
40
|
+
return new Promise((resolve, reject) => {
|
41
|
+
console.log('Loading provider from %s', url);
|
42
|
+
request_1.default.get(url, (error, response, body) => {
|
43
|
+
if (error) {
|
44
|
+
reject(error);
|
45
|
+
return;
|
46
|
+
}
|
47
|
+
if (response.statusCode === 404) {
|
48
|
+
resolve(null);
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
if (response.statusCode !== 200) {
|
52
|
+
reject(new Error(`Failed to load provider from ${url}: ${body}`));
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
resolve(body);
|
56
|
+
});
|
57
|
+
});
|
37
58
|
}
|
38
59
|
}
|
39
60
|
const providerDefinitions = definitionsManager_1.definitionsManager.getProviderDefinitions();
|
@@ -3,7 +3,7 @@ import request from 'request';
|
|
3
3
|
import AsyncLock from 'async-lock';
|
4
4
|
import { BlockInstanceRunner } from './utils/BlockInstanceRunner';
|
5
5
|
import { storageService } from './storageService';
|
6
|
-
import { EVENT_INSTANCE_CREATED, EVENT_INSTANCE_EXITED, EVENT_STATUS_CHANGED, socketManager
|
6
|
+
import { EVENT_INSTANCE_CREATED, EVENT_INSTANCE_EXITED, EVENT_STATUS_CHANGED, socketManager } from './socketManager';
|
7
7
|
import { serviceManager } from './serviceManager';
|
8
8
|
import { assetManager } from './assetManager';
|
9
9
|
import { containerManager, HEALTH_CHECK_TIMEOUT } from './containerManager';
|
@@ -474,6 +474,36 @@ export class InstanceManager {
|
|
474
474
|
if (instance.ref) {
|
475
475
|
instance.ref = normalizeKapetaUri(instance.ref);
|
476
476
|
}
|
477
|
+
if (instance.desiredStatus === DesiredInstanceStatus.RUN) {
|
478
|
+
// Check if the plan still exists and the instance is still in the plan
|
479
|
+
// - and that the block definition exists
|
480
|
+
try {
|
481
|
+
const plan = await assetManager.getAsset(instance.systemId, true, false);
|
482
|
+
if (!plan) {
|
483
|
+
instance.desiredStatus = DesiredInstanceStatus.STOP;
|
484
|
+
changed = true;
|
485
|
+
return;
|
486
|
+
}
|
487
|
+
const planData = plan.data;
|
488
|
+
const planInstance = planData?.spec?.blocks?.find((b) => b.id === instance.instanceId);
|
489
|
+
if (!planInstance || !planInstance?.block?.ref) {
|
490
|
+
instance.desiredStatus = DesiredInstanceStatus.STOP;
|
491
|
+
changed = true;
|
492
|
+
return;
|
493
|
+
}
|
494
|
+
const blockDef = await assetManager.getAsset(instance.ref, true, false);
|
495
|
+
if (!blockDef) {
|
496
|
+
instance.desiredStatus = DesiredInstanceStatus.STOP;
|
497
|
+
changed = true;
|
498
|
+
return;
|
499
|
+
}
|
500
|
+
}
|
501
|
+
catch (e) {
|
502
|
+
console.warn('Failed to check assets', instance.systemId, e);
|
503
|
+
instance.desiredStatus = DesiredInstanceStatus.STOP;
|
504
|
+
return;
|
505
|
+
}
|
506
|
+
}
|
477
507
|
const newStatus = await this.requestInstanceStatus(instance);
|
478
508
|
/*
|
479
509
|
console.log('Check instance %s %s: [current: %s, new: %s, desired: %s]',
|
@@ -1,7 +1,6 @@
|
|
1
|
-
/// <reference types="node" />
|
2
1
|
declare class ProviderManager {
|
3
2
|
getWebProviders(): import("@kapeta/local-cluster-config").DefinitionInfo[];
|
4
|
-
getProviderWebJS(handle: string, name: string, version: string, sourceMap?: boolean): Promise<
|
3
|
+
getProviderWebJS(handle: string, name: string, version: string, sourceMap?: boolean): Promise<unknown>;
|
5
4
|
}
|
6
5
|
export declare const providerManager: ProviderManager;
|
7
6
|
export {};
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import Path from 'path';
|
2
2
|
import FSExtra from 'fs-extra';
|
3
|
-
import { repositoryManager } from './repositoryManager';
|
4
3
|
import { definitionsManager } from './definitionsManager';
|
5
4
|
import { cacheManager } from './cacheManager';
|
5
|
+
import request from 'request';
|
6
|
+
const PROVIDER_FILE_BASE = 'https://providers.kapeta.com/files';
|
6
7
|
class ProviderManager {
|
7
8
|
getWebProviders() {
|
8
9
|
return definitionsManager.getProviderDefinitions().filter((providerDefinition) => providerDefinition.hasWeb);
|
@@ -15,7 +16,6 @@ class ProviderManager {
|
|
15
16
|
if (file && (await FSExtra.pathExists(file))) {
|
16
17
|
return FSExtra.readFile(file, 'utf8');
|
17
18
|
}
|
18
|
-
await repositoryManager.ensureAsset(handle, name, version, true);
|
19
19
|
const installedProvider = this.getWebProviders().find((providerDefinition) => {
|
20
20
|
return providerDefinition.definition.metadata.name === fullName && providerDefinition.version === version;
|
21
21
|
});
|
@@ -27,7 +27,28 @@ class ProviderManager {
|
|
27
27
|
return FSExtra.readFile(path);
|
28
28
|
}
|
29
29
|
}
|
30
|
-
|
30
|
+
if (version === 'local') {
|
31
|
+
return null;
|
32
|
+
}
|
33
|
+
const url = `${PROVIDER_FILE_BASE}/${id}`;
|
34
|
+
return new Promise((resolve, reject) => {
|
35
|
+
console.log('Loading provider from %s', url);
|
36
|
+
request.get(url, (error, response, body) => {
|
37
|
+
if (error) {
|
38
|
+
reject(error);
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
if (response.statusCode === 404) {
|
42
|
+
resolve(null);
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
if (response.statusCode !== 200) {
|
46
|
+
reject(new Error(`Failed to load provider from ${url}: ${body}`));
|
47
|
+
return;
|
48
|
+
}
|
49
|
+
resolve(body);
|
50
|
+
});
|
51
|
+
});
|
31
52
|
}
|
32
53
|
}
|
33
54
|
const providerDefinitions = definitionsManager.getProviderDefinitions();
|
package/package.json
CHANGED
package/src/instanceManager.ts
CHANGED
@@ -3,13 +3,7 @@ import request from 'request';
|
|
3
3
|
import AsyncLock from 'async-lock';
|
4
4
|
import { BlockInstanceRunner } from './utils/BlockInstanceRunner';
|
5
5
|
import { storageService } from './storageService';
|
6
|
-
import {
|
7
|
-
EVENT_INSTANCE_CREATED,
|
8
|
-
EVENT_INSTANCE_EXITED,
|
9
|
-
EVENT_INSTANCE_LOG,
|
10
|
-
EVENT_STATUS_CHANGED,
|
11
|
-
socketManager,
|
12
|
-
} from './socketManager';
|
6
|
+
import { EVENT_INSTANCE_CREATED, EVENT_INSTANCE_EXITED, EVENT_STATUS_CHANGED, socketManager } from './socketManager';
|
13
7
|
import { serviceManager } from './serviceManager';
|
14
8
|
import { assetManager } from './assetManager';
|
15
9
|
import { containerManager, HEALTH_CHECK_TIMEOUT } from './containerManager';
|
@@ -606,6 +600,38 @@ export class InstanceManager {
|
|
606
600
|
instance.ref = normalizeKapetaUri(instance.ref);
|
607
601
|
}
|
608
602
|
|
603
|
+
if (instance.desiredStatus === DesiredInstanceStatus.RUN) {
|
604
|
+
// Check if the plan still exists and the instance is still in the plan
|
605
|
+
// - and that the block definition exists
|
606
|
+
try {
|
607
|
+
const plan = await assetManager.getAsset(instance.systemId, true, false);
|
608
|
+
if (!plan) {
|
609
|
+
instance.desiredStatus = DesiredInstanceStatus.STOP;
|
610
|
+
changed = true;
|
611
|
+
return;
|
612
|
+
}
|
613
|
+
|
614
|
+
const planData = plan.data as Plan;
|
615
|
+
const planInstance = planData?.spec?.blocks?.find((b) => b.id === instance.instanceId);
|
616
|
+
if (!planInstance || !planInstance?.block?.ref) {
|
617
|
+
instance.desiredStatus = DesiredInstanceStatus.STOP;
|
618
|
+
changed = true;
|
619
|
+
return;
|
620
|
+
}
|
621
|
+
|
622
|
+
const blockDef = await assetManager.getAsset(instance.ref, true, false);
|
623
|
+
if (!blockDef) {
|
624
|
+
instance.desiredStatus = DesiredInstanceStatus.STOP;
|
625
|
+
changed = true;
|
626
|
+
return;
|
627
|
+
}
|
628
|
+
} catch (e) {
|
629
|
+
console.warn('Failed to check assets', instance.systemId, e);
|
630
|
+
instance.desiredStatus = DesiredInstanceStatus.STOP;
|
631
|
+
return;
|
632
|
+
}
|
633
|
+
}
|
634
|
+
|
609
635
|
const newStatus = await this.requestInstanceStatus(instance);
|
610
636
|
/*
|
611
637
|
console.log('Check instance %s %s: [current: %s, new: %s, desired: %s]',
|
package/src/providerManager.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
import Path from 'path';
|
2
2
|
import FSExtra from 'fs-extra';
|
3
|
-
import { repositoryManager } from './repositoryManager';
|
4
|
-
import ClusterConfiguration from '@kapeta/local-cluster-config';
|
5
|
-
import { StringMap } from './types';
|
6
3
|
import { definitionsManager } from './definitionsManager';
|
7
4
|
import { cacheManager } from './cacheManager';
|
5
|
+
import request from 'request';
|
6
|
+
|
7
|
+
const PROVIDER_FILE_BASE = 'https://providers.kapeta.com/files';
|
8
8
|
|
9
9
|
class ProviderManager {
|
10
10
|
getWebProviders() {
|
@@ -22,8 +22,6 @@ class ProviderManager {
|
|
22
22
|
return FSExtra.readFile(file, 'utf8');
|
23
23
|
}
|
24
24
|
|
25
|
-
await repositoryManager.ensureAsset(handle, name, version, true);
|
26
|
-
|
27
25
|
const installedProvider = this.getWebProviders().find((providerDefinition) => {
|
28
26
|
return providerDefinition.definition.metadata.name === fullName && providerDefinition.version === version;
|
29
27
|
});
|
@@ -37,7 +35,31 @@ class ProviderManager {
|
|
37
35
|
}
|
38
36
|
}
|
39
37
|
|
40
|
-
|
38
|
+
if (version === 'local') {
|
39
|
+
return null;
|
40
|
+
}
|
41
|
+
|
42
|
+
const url = `${PROVIDER_FILE_BASE}/${id}`;
|
43
|
+
return new Promise((resolve, reject) => {
|
44
|
+
console.log('Loading provider from %s', url);
|
45
|
+
request.get(url, (error, response, body) => {
|
46
|
+
if (error) {
|
47
|
+
reject(error);
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
if (response.statusCode === 404) {
|
51
|
+
resolve(null);
|
52
|
+
return;
|
53
|
+
}
|
54
|
+
|
55
|
+
if (response.statusCode !== 200) {
|
56
|
+
reject(new Error(`Failed to load provider from ${url}: ${body}`));
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
|
60
|
+
resolve(body);
|
61
|
+
});
|
62
|
+
});
|
41
63
|
}
|
42
64
|
}
|
43
65
|
|