@kapeta/local-cluster-service 0.20.4 → 0.21.0
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 +7 -0
- package/dist/cjs/src/assetManager.js +5 -6
- package/dist/cjs/src/clusterService.js +2 -2
- package/dist/cjs/src/codeGeneratorManager.js +2 -2
- package/dist/cjs/src/config/routes.js +13 -2
- package/dist/cjs/src/configManager.js +10 -10
- package/dist/cjs/src/definitionsManager.js +2 -3
- package/dist/cjs/src/instanceManager.js +18 -15
- package/dist/cjs/src/middleware/kapeta.js +3 -3
- package/dist/cjs/src/networkManager.js +6 -6
- package/dist/cjs/src/operatorManager.js +3 -3
- package/dist/cjs/src/repositoryManager.js +2 -2
- package/dist/cjs/src/serviceManager.d.ts +1 -0
- package/dist/cjs/src/serviceManager.js +9 -9
- package/dist/cjs/src/socketManager.js +3 -3
- package/dist/cjs/src/utils/BlockInstanceRunner.js +32 -14
- package/dist/cjs/src/utils/utils.d.ts +0 -1
- package/dist/cjs/src/utils/utils.js +1 -13
- package/dist/cjs/test/proxy/types/rest.test.js +16 -17
- package/dist/esm/src/assetManager.js +5 -6
- package/dist/esm/src/clusterService.js +2 -2
- package/dist/esm/src/codeGeneratorManager.js +2 -2
- package/dist/esm/src/config/routes.js +13 -2
- package/dist/esm/src/configManager.js +10 -10
- package/dist/esm/src/definitionsManager.js +2 -3
- package/dist/esm/src/instanceManager.js +18 -15
- package/dist/esm/src/middleware/kapeta.js +3 -3
- package/dist/esm/src/networkManager.js +6 -6
- package/dist/esm/src/operatorManager.js +3 -3
- package/dist/esm/src/repositoryManager.js +2 -2
- package/dist/esm/src/serviceManager.d.ts +1 -0
- package/dist/esm/src/serviceManager.js +9 -9
- package/dist/esm/src/socketManager.js +3 -3
- package/dist/esm/src/utils/BlockInstanceRunner.js +32 -14
- package/dist/esm/src/utils/utils.d.ts +0 -1
- package/dist/esm/src/utils/utils.js +1 -13
- package/dist/esm/test/proxy/types/rest.test.js +16 -17
- package/package.json +1 -1
- package/src/assetManager.ts +1 -2
- package/src/clusterService.ts +1 -1
- package/src/codeGeneratorManager.ts +1 -1
- package/src/config/routes.ts +17 -6
- package/src/configManager.ts +2 -2
- package/src/definitionsManager.ts +1 -2
- package/src/instanceManager.ts +8 -3
- package/src/middleware/kapeta.ts +1 -2
- package/src/networkManager.ts +1 -1
- package/src/operatorManager.ts +3 -3
- package/src/repositoryManager.ts +1 -1
- package/src/serviceManager.ts +2 -2
- package/src/socketManager.ts +1 -1
- package/src/utils/BlockInstanceRunner.ts +65 -30
- package/src/utils/utils.ts +0 -13
- package/test/proxy/types/rest.test.ts +22 -22
@@ -9,7 +9,7 @@ const socketManager_1 = require("./socketManager");
|
|
9
9
|
const nodejs_registry_utils_1 = require("@kapeta/nodejs-registry-utils");
|
10
10
|
const definitionsManager_1 = require("./definitionsManager");
|
11
11
|
const taskManager_1 = require("./taskManager");
|
12
|
-
const
|
12
|
+
const nodejs_utils_1 = require("@kapeta/nodejs-utils");
|
13
13
|
const progressListener_1 = require("./progressListener");
|
14
14
|
const RepositoryWatcher_1 = require("./RepositoryWatcher");
|
15
15
|
const cacheManager_1 = require("./cacheManager");
|
@@ -96,7 +96,7 @@ class RepositoryManager extends node_events_1.EventEmitter {
|
|
96
96
|
if (!ref) {
|
97
97
|
continue;
|
98
98
|
}
|
99
|
-
ref = (0,
|
99
|
+
ref = (0, nodejs_utils_1.normalizeKapetaUri)(ref);
|
100
100
|
if (await definitionsManager_1.definitionsManager.exists(ref)) {
|
101
101
|
continue;
|
102
102
|
}
|
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.serviceManager = void 0;
|
6
|
+
exports.serviceManager = exports.DEFAULT_PORT_TYPE = void 0;
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
8
8
|
const clusterService_1 = require("./clusterService");
|
9
9
|
const storageService_1 = require("./storageService");
|
10
|
-
const
|
11
|
-
|
10
|
+
const nodejs_utils_1 = require("@kapeta/nodejs-utils");
|
11
|
+
exports.DEFAULT_PORT_TYPE = 'rest';
|
12
12
|
class ServiceManager {
|
13
13
|
_systems;
|
14
14
|
constructor() {
|
@@ -42,7 +42,7 @@ class ServiceManager {
|
|
42
42
|
return `http://${host}:${port}/${path}`;
|
43
43
|
}
|
44
44
|
_ensureSystem(systemId) {
|
45
|
-
systemId = (0,
|
45
|
+
systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
|
46
46
|
if (!this._systems[systemId]) {
|
47
47
|
this._systems[systemId] = {};
|
48
48
|
}
|
@@ -55,10 +55,10 @@ class ServiceManager {
|
|
55
55
|
}
|
56
56
|
return system[serviceId];
|
57
57
|
}
|
58
|
-
async ensureServicePort(systemId, blockInstanceId, portType = DEFAULT_PORT_TYPE) {
|
59
|
-
systemId = (0,
|
58
|
+
async ensureServicePort(systemId, blockInstanceId, portType = exports.DEFAULT_PORT_TYPE) {
|
59
|
+
systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
|
60
60
|
if (!portType) {
|
61
|
-
portType = DEFAULT_PORT_TYPE;
|
61
|
+
portType = exports.DEFAULT_PORT_TYPE;
|
62
62
|
}
|
63
63
|
const service = this._ensureService(systemId, blockInstanceId);
|
64
64
|
if (!service[portType]) {
|
@@ -79,7 +79,7 @@ class ServiceManager {
|
|
79
79
|
*
|
80
80
|
*/
|
81
81
|
getConsumerAddress(systemId, consumerInstanceId, consumerResourceName, portType, environmentType) {
|
82
|
-
systemId = (0,
|
82
|
+
systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
|
83
83
|
const port = clusterService_1.clusterService.getClusterServicePort();
|
84
84
|
const path = clusterService_1.clusterService.getProxyPath(systemId, consumerInstanceId, consumerResourceName, portType);
|
85
85
|
return this._forLocal(port, path, environmentType);
|
@@ -93,7 +93,7 @@ class ServiceManager {
|
|
93
93
|
*
|
94
94
|
*/
|
95
95
|
async getProviderAddress(systemId, providerInstanceId, portType) {
|
96
|
-
systemId = (0,
|
96
|
+
systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
|
97
97
|
const port = await this.ensureServicePort(systemId, providerInstanceId, portType);
|
98
98
|
return this._forLocal(port);
|
99
99
|
}
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.socketManager = exports.SocketManager = exports.EVENT_LOG = exports.EVENT_SYSTEM_LOG = exports.EVENT_INSTANCE_LOG = exports.EVENT_INSTANCE_EXITED = exports.EVENT_INSTANCE_CREATED = exports.EVENT_STATUS_CHANGED = void 0;
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
8
|
-
const
|
8
|
+
const nodejs_utils_1 = require("@kapeta/nodejs-utils");
|
9
9
|
const containerManager_1 = require("./containerManager");
|
10
10
|
exports.EVENT_STATUS_CHANGED = 'status-changed';
|
11
11
|
exports.EVENT_INSTANCE_CREATED = 'instance-created';
|
@@ -47,7 +47,7 @@ class SocketManager {
|
|
47
47
|
this.io.emit(type, payload);
|
48
48
|
}
|
49
49
|
emitSystemEvent(systemId, type, payload) {
|
50
|
-
systemId = (0,
|
50
|
+
systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
|
51
51
|
try {
|
52
52
|
const contextId = `system-events/${encodeURIComponent(systemId)}`;
|
53
53
|
this.emit(contextId, type, payload);
|
@@ -57,7 +57,7 @@ class SocketManager {
|
|
57
57
|
}
|
58
58
|
}
|
59
59
|
emitInstanceLog(systemId, instanceId, payload) {
|
60
|
-
systemId = (0,
|
60
|
+
systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
|
61
61
|
try {
|
62
62
|
this.emit(`instance-logs/${encodeURIComponent(systemId)}/${encodeURIComponent(instanceId)}`, exports.EVENT_INSTANCE_LOG, payload);
|
63
63
|
}
|
@@ -34,12 +34,19 @@ async function getProvider(uri) {
|
|
34
34
|
return (0, nodejs_utils_1.parseKapetaUri)(ref).id === uri.id;
|
35
35
|
});
|
36
36
|
}
|
37
|
-
function getProviderPorts(assetVersion) {
|
38
|
-
|
37
|
+
function getProviderPorts(assetVersion, providerVersion) {
|
38
|
+
const out = assetVersion.definition?.spec?.providers
|
39
39
|
?.map((provider) => {
|
40
40
|
return provider.spec?.port?.type;
|
41
41
|
})
|
42
|
-
.filter((t) => !!t) ?? []
|
42
|
+
.filter((t) => !!t) ?? [];
|
43
|
+
if (out.length === 0) {
|
44
|
+
if (providerVersion.definition.spec?.defaultPort?.type) {
|
45
|
+
return [providerVersion.definition.spec?.defaultPort?.type];
|
46
|
+
}
|
47
|
+
return [serviceManager_1.DEFAULT_PORT_TYPE];
|
48
|
+
}
|
49
|
+
return out;
|
43
50
|
}
|
44
51
|
class BlockInstanceRunner {
|
45
52
|
_systemId;
|
@@ -49,7 +56,7 @@ class BlockInstanceRunner {
|
|
49
56
|
* @type {string}
|
50
57
|
* @private
|
51
58
|
*/
|
52
|
-
this._systemId = (0,
|
59
|
+
this._systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
|
53
60
|
}
|
54
61
|
/**
|
55
62
|
* Start a block
|
@@ -92,7 +99,7 @@ class BlockInstanceRunner {
|
|
92
99
|
}
|
93
100
|
else {
|
94
101
|
//We need a port type to know how to connect to the block consistently
|
95
|
-
const portTypes = getProviderPorts(assetVersion);
|
102
|
+
const portTypes = getProviderPorts(assetVersion, providerVersion);
|
96
103
|
if (blockUri.version === 'local') {
|
97
104
|
processInfo = await this._startLocalProcess(blockInstance, blockUri, env, assetVersion);
|
98
105
|
}
|
@@ -117,14 +124,19 @@ class BlockInstanceRunner {
|
|
117
124
|
if (!assetVersion.definition.spec?.target?.kind) {
|
118
125
|
throw new Error('Missing target kind in block definition');
|
119
126
|
}
|
120
|
-
const kindUri = (0, nodejs_utils_1.parseKapetaUri)(assetVersion.definition.
|
121
|
-
const
|
127
|
+
const kindUri = (0, nodejs_utils_1.parseKapetaUri)(assetVersion.definition.kind);
|
128
|
+
const providerVersion = await getProvider(kindUri);
|
129
|
+
if (!providerVersion) {
|
130
|
+
throw new Error(`Block type not found: ${kindUri.id}`);
|
131
|
+
}
|
132
|
+
const targetKindUri = (0, nodejs_utils_1.parseKapetaUri)(assetVersion.definition.spec?.target?.kind);
|
133
|
+
const targetVersion = await getProvider(targetKindUri);
|
122
134
|
if (!targetVersion) {
|
123
|
-
throw new Error(`Target not found: ${
|
135
|
+
throw new Error(`Target not found: ${targetKindUri.id}`);
|
124
136
|
}
|
125
137
|
const localContainer = targetVersion.definition.spec.local;
|
126
138
|
if (!localContainer) {
|
127
|
-
throw new Error(`Missing local container information from target: ${
|
139
|
+
throw new Error(`Missing local container information from target: ${targetKindUri.id}`);
|
128
140
|
}
|
129
141
|
const dockerImage = localContainer.image;
|
130
142
|
if (!dockerImage) {
|
@@ -141,7 +153,7 @@ class BlockInstanceRunner {
|
|
141
153
|
delete localContainer.HostConfig;
|
142
154
|
delete localContainer.Labels;
|
143
155
|
delete localContainer.Env;
|
144
|
-
const { PortBindings, ExposedPorts, addonEnv } = await this.getDockerPortBindings(blockInstance, assetVersion);
|
156
|
+
const { PortBindings, ExposedPorts, addonEnv } = await this.getDockerPortBindings(blockInstance, assetVersion, providerVersion);
|
145
157
|
let HealthCheck = undefined;
|
146
158
|
if (localContainer.healthcheck) {
|
147
159
|
HealthCheck = containerManager_1.containerManager.toDockerHealth({ cmd: localContainer.healthcheck });
|
@@ -194,7 +206,12 @@ class BlockInstanceRunner {
|
|
194
206
|
if (!dockerImage) {
|
195
207
|
throw new Error(`Missing docker image information: ${JSON.stringify(versionInfo?.artifact?.details)}`);
|
196
208
|
}
|
197
|
-
const
|
209
|
+
const kindUri = (0, nodejs_utils_1.parseKapetaUri)(assetVersion.definition.kind);
|
210
|
+
const providerVersion = await getProvider(kindUri);
|
211
|
+
if (!providerVersion) {
|
212
|
+
throw new Error(`Block type not found: ${kindUri.id}`);
|
213
|
+
}
|
214
|
+
const { PortBindings, ExposedPorts, addonEnv } = await this.getDockerPortBindings(blockInstance, assetVersion, providerVersion);
|
198
215
|
const containerName = (0, utils_1.getBlockInstanceContainerName)(this._systemId, blockInstance.id);
|
199
216
|
// For windows we need to default to root
|
200
217
|
const innerHome = process.platform === 'win32' ? '/root/.kapeta' : local_cluster_config_1.default.getKapetaBasedir();
|
@@ -252,7 +269,8 @@ class BlockInstanceRunner {
|
|
252
269
|
const PortBindings = {};
|
253
270
|
let HealthCheck = undefined;
|
254
271
|
let Mounts = [];
|
255
|
-
const
|
272
|
+
const localPorts = spec.local.ports;
|
273
|
+
const promises = Object.entries(localPorts).map(async ([portType, value]) => {
|
256
274
|
const dockerPort = `${value.port}/${value.type}`;
|
257
275
|
ExposedPorts[dockerPort] = {};
|
258
276
|
addonEnv[`KAPETA_LOCAL_SERVER_PORT_${portType.toUpperCase()}`] = value.port;
|
@@ -315,12 +333,12 @@ class BlockInstanceRunner {
|
|
315
333
|
}
|
316
334
|
return out;
|
317
335
|
}
|
318
|
-
async getDockerPortBindings(blockInstance, assetVersion) {
|
336
|
+
async getDockerPortBindings(blockInstance, assetVersion, providerVersion) {
|
319
337
|
const bindHost = (0, utils_1.getBindHost)();
|
320
338
|
const ExposedPorts = {};
|
321
339
|
const addonEnv = {};
|
322
340
|
const PortBindings = {};
|
323
|
-
const portTypes = getProviderPorts(assetVersion);
|
341
|
+
const portTypes = getProviderPorts(assetVersion, providerVersion);
|
324
342
|
let port = 80;
|
325
343
|
const promises = portTypes.map(async (portType) => {
|
326
344
|
const publicPort = await serviceManager_1.serviceManager.ensureServicePort(this._systemId, blockInstance.id, portType);
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { EntityList } from '@kapeta/schemas';
|
2
2
|
import { AnyMap } from '../types';
|
3
3
|
export declare function getBlockInstanceContainerName(systemId: string, instanceId: string): string;
|
4
|
-
export declare function normalizeKapetaUri(uri: string): string;
|
5
4
|
export declare function readYML(path: string): any;
|
6
5
|
export declare function isWindows(): boolean;
|
7
6
|
export declare function isMac(): boolean;
|
@@ -3,27 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.getResolvedConfiguration = exports.getBindHost = exports.isLinux = exports.isMac = exports.isWindows = exports.readYML = exports.
|
6
|
+
exports.getResolvedConfiguration = exports.getBindHost = exports.isLinux = exports.isMac = exports.isWindows = exports.readYML = exports.getBlockInstanceContainerName = void 0;
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
8
8
|
const yaml_1 = __importDefault(require("yaml"));
|
9
|
-
const nodejs_utils_1 = require("@kapeta/nodejs-utils");
|
10
9
|
const md5_1 = __importDefault(require("md5"));
|
11
10
|
const lodash_1 = __importDefault(require("lodash"));
|
12
11
|
function getBlockInstanceContainerName(systemId, instanceId) {
|
13
12
|
return `kapeta-block-instance-${(0, md5_1.default)(systemId + instanceId)}`;
|
14
13
|
}
|
15
14
|
exports.getBlockInstanceContainerName = getBlockInstanceContainerName;
|
16
|
-
function normalizeKapetaUri(uri) {
|
17
|
-
if (!uri) {
|
18
|
-
return '';
|
19
|
-
}
|
20
|
-
const uriObj = (0, nodejs_utils_1.parseKapetaUri)(uri);
|
21
|
-
if (!uriObj.version) {
|
22
|
-
return `kapeta://${(0, nodejs_utils_1.parseKapetaUri)(uri).fullName}`;
|
23
|
-
}
|
24
|
-
return `kapeta://${(0, nodejs_utils_1.parseKapetaUri)(uri).id}`;
|
25
|
-
}
|
26
|
-
exports.normalizeKapetaUri = normalizeKapetaUri;
|
27
15
|
function readYML(path) {
|
28
16
|
const rawYaml = node_fs_1.default.readFileSync(path);
|
29
17
|
try {
|
@@ -4,42 +4,41 @@ const rest_1 = require("../../../src/proxy/types/rest");
|
|
4
4
|
describe('getRestMethodId', () => {
|
5
5
|
it('should match @Query in url', () => {
|
6
6
|
const restResource = new TestResource();
|
7
|
-
const restMethodId = (0, rest_1.getRestMethodId)(restResource,
|
7
|
+
const restMethodId = (0, rest_1.getRestMethodId)(restResource, 'POST', '/names?name=Ib');
|
8
8
|
expect(restMethodId).toBeDefined();
|
9
9
|
});
|
10
10
|
});
|
11
11
|
class TestResource {
|
12
|
-
kind =
|
12
|
+
kind = '';
|
13
13
|
metadata = new TestResourceMetaData();
|
14
14
|
get spec() {
|
15
15
|
return {
|
16
16
|
methods: [
|
17
17
|
{
|
18
18
|
responseType: {
|
19
|
-
ref:
|
19
|
+
ref: 'Name[]',
|
20
20
|
},
|
21
|
-
method:
|
22
|
-
path:
|
23
|
-
arguments: {}
|
21
|
+
method: 'GET',
|
22
|
+
path: '/names',
|
23
|
+
arguments: {},
|
24
24
|
},
|
25
25
|
{
|
26
26
|
responseType: {
|
27
|
-
ref:
|
27
|
+
ref: 'Name',
|
28
28
|
},
|
29
|
-
method:
|
30
|
-
path:
|
29
|
+
method: 'POST',
|
30
|
+
path: '/names',
|
31
31
|
arguments: {
|
32
32
|
name: {
|
33
|
-
type:
|
34
|
-
transport:
|
35
|
-
}
|
36
|
-
}
|
37
|
-
}
|
38
|
-
]
|
33
|
+
type: 'string',
|
34
|
+
transport: 'QUERY',
|
35
|
+
},
|
36
|
+
},
|
37
|
+
},
|
38
|
+
],
|
39
39
|
};
|
40
40
|
}
|
41
|
-
;
|
42
41
|
}
|
43
42
|
class TestResourceMetaData {
|
44
|
-
name =
|
43
|
+
name = '';
|
45
44
|
}
|
package/package.json
CHANGED
package/src/assetManager.ts
CHANGED
@@ -4,12 +4,11 @@ import YAML from 'yaml';
|
|
4
4
|
import { Definition, DefinitionInfo } from '@kapeta/local-cluster-config';
|
5
5
|
import { codeGeneratorManager } from './codeGeneratorManager';
|
6
6
|
import { ProgressListener } from './progressListener';
|
7
|
-
import { parseKapetaUri } from '@kapeta/nodejs-utils';
|
7
|
+
import { normalizeKapetaUri, parseKapetaUri } from '@kapeta/nodejs-utils';
|
8
8
|
import { repositoryManager } from './repositoryManager';
|
9
9
|
import { BlockDefinition, BlockInstance, Plan } from '@kapeta/schemas';
|
10
10
|
import { Actions } from '@kapeta/nodejs-registry-utils';
|
11
11
|
import { definitionsManager } from './definitionsManager';
|
12
|
-
import { normalizeKapetaUri } from './utils/utils';
|
13
12
|
import { taskManager } from './taskManager';
|
14
13
|
import { SourceOfChange } from './types';
|
15
14
|
import { cacheManager } from './cacheManager';
|
package/src/clusterService.ts
CHANGED
@@ -4,7 +4,7 @@ import { BlockDefinition } from '@kapeta/schemas';
|
|
4
4
|
import { definitionsManager } from './definitionsManager';
|
5
5
|
import { Definition } from '@kapeta/local-cluster-config';
|
6
6
|
import { assetManager } from './assetManager';
|
7
|
-
import { normalizeKapetaUri } from '
|
7
|
+
import { normalizeKapetaUri } from '@kapeta/nodejs-utils';
|
8
8
|
import { repositoryManager } from './repositoryManager';
|
9
9
|
|
10
10
|
const TARGET_KIND = 'core/language-target';
|
package/src/config/routes.ts
CHANGED
@@ -8,8 +8,6 @@ import { kapetaHeaders, KapetaRequest } from '../middleware/kapeta';
|
|
8
8
|
import { stringBody } from '../middleware/stringBody';
|
9
9
|
import { AnyMap, KapetaBodyRequest } from '../types';
|
10
10
|
import { Response } from 'express';
|
11
|
-
import { getResolvedConfiguration, normalizeKapetaUri } from '../utils/utils';
|
12
|
-
import { assetManager } from '../assetManager';
|
13
11
|
|
14
12
|
const router = Router();
|
15
13
|
|
@@ -122,10 +120,23 @@ router.get('/identity', async (req: KapetaRequest, res) => {
|
|
122
120
|
* already called the endpoint the same port is returned.
|
123
121
|
*/
|
124
122
|
router.get('/provides/:type', async (req: KapetaRequest, res) => {
|
125
|
-
|
126
|
-
|
127
|
-
''
|
128
|
-
|
123
|
+
if (req.kapeta!.environment === 'docker' && ['web', 'rest'].includes(req.params.type)) {
|
124
|
+
// Happens when starting a local container with no providers.
|
125
|
+
res.send('80');
|
126
|
+
return;
|
127
|
+
}
|
128
|
+
|
129
|
+
try {
|
130
|
+
const port = await serviceManager.ensureServicePort(
|
131
|
+
req.kapeta!.systemId,
|
132
|
+
req.kapeta!.instanceId,
|
133
|
+
req.params.type
|
134
|
+
);
|
135
|
+
res.send('' + port);
|
136
|
+
} catch (err: any) {
|
137
|
+
console.warn('Failed to resolve service port: ' + req.params.type, err);
|
138
|
+
res.status(400).send({ error: err.message });
|
139
|
+
}
|
129
140
|
});
|
130
141
|
|
131
142
|
/**
|
package/src/configManager.ts
CHANGED
@@ -2,8 +2,8 @@ import { EnrichedAsset } from './assetManager';
|
|
2
2
|
import { BlockInstance } from '@kapeta/schemas';
|
3
3
|
import { storageService } from './storageService';
|
4
4
|
import { assetManager } from './assetManager';
|
5
|
-
import { parseKapetaUri } from '@kapeta/nodejs-utils';
|
6
|
-
import { getResolvedConfiguration
|
5
|
+
import { normalizeKapetaUri, parseKapetaUri } from '@kapeta/nodejs-utils';
|
6
|
+
import { getResolvedConfiguration } from './utils/utils';
|
7
7
|
|
8
8
|
export const SYSTEM_ID = '$plan';
|
9
9
|
type AnyMap = { [key: string]: any };
|
@@ -1,10 +1,9 @@
|
|
1
1
|
import ClusterConfiguration, { DefinitionInfo } from '@kapeta/local-cluster-config';
|
2
|
-
import { parseKapetaUri } from '@kapeta/nodejs-utils';
|
2
|
+
import { parseKapetaUri, normalizeKapetaUri } from '@kapeta/nodejs-utils';
|
3
3
|
import { cacheManager, doCached } from './cacheManager';
|
4
4
|
import { KapetaAPI } from '@kapeta/nodejs-api-client';
|
5
5
|
import { Plan } from '@kapeta/schemas';
|
6
6
|
import FS from 'fs-extra';
|
7
|
-
import { normalizeKapetaUri } from './utils/utils';
|
8
7
|
import YAML from 'yaml';
|
9
8
|
import { Actions } from '@kapeta/nodejs-registry-utils';
|
10
9
|
import { ProgressListener } from './progressListener';
|
package/src/instanceManager.ts
CHANGED
@@ -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,
|
6
|
+
import { EVENT_INSTANCE_CREATED, EVENT_STATUS_CHANGED, socketManager } from './socketManager';
|
7
7
|
import { serviceManager } from './serviceManager';
|
8
8
|
import { assetManager } from './assetManager';
|
9
9
|
import {
|
@@ -15,9 +15,9 @@ import {
|
|
15
15
|
import { configManager } from './configManager';
|
16
16
|
import { DesiredInstanceStatus, InstanceInfo, InstanceOwner, InstanceStatus, InstanceType, LogEntry } from './types';
|
17
17
|
import { BlockDefinitionSpec, BlockInstance, Plan } from '@kapeta/schemas';
|
18
|
-
import { getBlockInstanceContainerName, getResolvedConfiguration
|
18
|
+
import { getBlockInstanceContainerName, getResolvedConfiguration } from './utils/utils';
|
19
19
|
import { KIND_OPERATOR, operatorManager } from './operatorManager';
|
20
|
-
import { parseKapetaUri } from '@kapeta/nodejs-utils';
|
20
|
+
import { normalizeKapetaUri, parseKapetaUri } from '@kapeta/nodejs-utils';
|
21
21
|
import { definitionsManager } from './definitionsManager';
|
22
22
|
import { Task, taskManager } from './taskManager';
|
23
23
|
|
@@ -222,10 +222,15 @@ export class InstanceManager {
|
|
222
222
|
if (info.type) {
|
223
223
|
instance.type = info.type;
|
224
224
|
}
|
225
|
+
|
225
226
|
if (healthUrl) {
|
226
227
|
instance.health = healthUrl;
|
227
228
|
}
|
228
229
|
|
230
|
+
if (info.portType) {
|
231
|
+
instance.portType = info.portType;
|
232
|
+
}
|
233
|
+
|
229
234
|
socketManager.emitSystemEvent(systemId, EVENT_STATUS_CHANGED, instance);
|
230
235
|
} else {
|
231
236
|
//If instance was not found - then we're receiving an externally started instance
|
package/src/middleware/kapeta.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import { NextFunction, Request, Response } from 'express';
|
2
2
|
import { EnvironmentType } from '../types';
|
3
|
-
import {
|
4
|
-
import { normalizeKapetaUri } from '../utils/utils';
|
3
|
+
import { normalizeKapetaUri } from '@kapeta/nodejs-utils';
|
5
4
|
|
6
5
|
export interface KapetaRequest extends Request {
|
7
6
|
kapeta?: {
|
package/src/networkManager.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Connection } from '@kapeta/schemas';
|
2
2
|
import uuid from 'node-uuid';
|
3
3
|
import { SimpleRequest, SimpleResponse } from './types';
|
4
|
-
import { normalizeKapetaUri } from '
|
4
|
+
import { normalizeKapetaUri } from '@kapeta/nodejs-utils';
|
5
5
|
|
6
6
|
class NetworkManager {
|
7
7
|
private _connections: { [systemId: string]: { [connectionId: string]: Traffic[] } };
|
package/src/operatorManager.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
import
|
1
|
+
import { DefinitionInfo } from '@kapeta/local-cluster-config';
|
2
2
|
import Path from 'path';
|
3
3
|
import md5 from 'md5';
|
4
|
-
import { parseKapetaUri } from '@kapeta/nodejs-utils';
|
5
4
|
import { serviceManager } from './serviceManager';
|
6
5
|
import { storageService } from './storageService';
|
7
6
|
import {
|
@@ -15,7 +14,8 @@ import FSExtra from 'fs-extra';
|
|
15
14
|
import { AnyMap, EnvironmentType, OperatorInfo, StringMap } from './types';
|
16
15
|
import { BlockInstance, Resource } from '@kapeta/schemas';
|
17
16
|
import { definitionsManager } from './definitionsManager';
|
18
|
-
import { getBindHost
|
17
|
+
import { getBindHost } from './utils/utils';
|
18
|
+
import { parseKapetaUri, normalizeKapetaUri } from '@kapeta/nodejs-utils';
|
19
19
|
import _ from 'lodash';
|
20
20
|
import AsyncLock from 'async-lock';
|
21
21
|
import { taskManager } from './taskManager';
|
package/src/repositoryManager.ts
CHANGED
@@ -4,7 +4,7 @@ import { Dependency } from '@kapeta/schemas';
|
|
4
4
|
import { Actions, Config, RegistryService } from '@kapeta/nodejs-registry-utils';
|
5
5
|
import { definitionsManager } from './definitionsManager';
|
6
6
|
import { Task, taskManager } from './taskManager';
|
7
|
-
import { normalizeKapetaUri } from '
|
7
|
+
import { normalizeKapetaUri } from '@kapeta/nodejs-utils';
|
8
8
|
import { ProgressListener } from './progressListener';
|
9
9
|
import { RepositoryWatcher } from './RepositoryWatcher';
|
10
10
|
import { SourceOfChange } from './types';
|
package/src/serviceManager.ts
CHANGED
@@ -2,9 +2,9 @@ import _ from 'lodash';
|
|
2
2
|
import { clusterService } from './clusterService';
|
3
3
|
import { storageService } from './storageService';
|
4
4
|
import { EnvironmentType } from './types';
|
5
|
-
import { normalizeKapetaUri } from '
|
5
|
+
import { normalizeKapetaUri } from '@kapeta/nodejs-utils';
|
6
6
|
|
7
|
-
const DEFAULT_PORT_TYPE = 'rest';
|
7
|
+
export const DEFAULT_PORT_TYPE = 'rest';
|
8
8
|
|
9
9
|
class ServiceManager {
|
10
10
|
private _systems: any;
|
package/src/socketManager.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import _ from 'lodash';
|
2
2
|
import { Socket, Server } from 'socket.io';
|
3
|
-
import { normalizeKapetaUri } from '
|
3
|
+
import { normalizeKapetaUri } from '@kapeta/nodejs-utils';
|
4
4
|
import { LogEntry } from './types';
|
5
5
|
import { containerManager } from './containerManager';
|
6
6
|
export const EVENT_STATUS_CHANGED = 'status-changed';
|