mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-31 08:25:36 +00:00
Convert application-manager.coffee to javascript
Change-type: patch
This commit is contained in:
parent
2be3322fc0
commit
a2ec35456b
2
entry.sh
2
entry.sh
@ -55,7 +55,7 @@ modprobe ip6_tables || true
|
|||||||
|
|
||||||
if [ "${LIVEPUSH}" -eq "1" ]; then
|
if [ "${LIVEPUSH}" -eq "1" ]; then
|
||||||
exec npx nodemon --watch src --watch typings --ignore tests \
|
exec npx nodemon --watch src --watch typings --ignore tests \
|
||||||
--exec node -r ts-node/register/transpile-only -r coffeescript/register src/app.ts
|
--exec node -r ts-node/register/transpile-only src/app.ts
|
||||||
else
|
else
|
||||||
exec node /usr/src/app/dist/app.js
|
exec node /usr/src/app/dist/app.js
|
||||||
fi
|
fi
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "./entry.sh",
|
"start": "./entry.sh",
|
||||||
"build": "npm run typescript:release && webpack",
|
"build": "npm run typescript:release && webpack",
|
||||||
"build:debug": "npm run typescript:release && npm run coffeescript:release && npm run packagejson:copy",
|
"build:debug": "npm run typescript:release && npm run packagejson:copy",
|
||||||
"lint": "npm run lint:coffee && npm run lint:typescript",
|
"lint": "npm run lint:coffee && npm run lint:typescript",
|
||||||
"test": "npm run lint && npm run test-nolint",
|
"test": "npm run lint && npm run test-nolint",
|
||||||
"test-nolint": "npm run test:build && TEST=1 JUNIT_REPORT_PATH=report.xml istanbul cover _mocha && npm run coverage",
|
"test-nolint": "npm run test:build && TEST=1 JUNIT_REPORT_PATH=report.xml istanbul cover _mocha && npm run coverage",
|
||||||
@ -22,10 +22,9 @@
|
|||||||
"typescript:test-build": "tsc --project tsconfig.json",
|
"typescript:test-build": "tsc --project tsconfig.json",
|
||||||
"typescript:release": "tsc --project tsconfig.release.json && cp -r build/src/* build && rm -rf build/src",
|
"typescript:release": "tsc --project tsconfig.release.json && cp -r build/src/* build && rm -rf build/src",
|
||||||
"coffeescript:test": "coffee -m -c -o build .",
|
"coffeescript:test": "coffee -m -c -o build .",
|
||||||
"coffeescript:release": "coffee -m -c -o build src",
|
|
||||||
"packagejson:copy": "cp package.json build/",
|
"packagejson:copy": "cp package.json build/",
|
||||||
"testitems:copy": "cp -r test/data build/test/",
|
"testitems:copy": "cp -r test/data build/test/",
|
||||||
"lint:coffee": "balena-lint src/ test/",
|
"lint:coffee": "balena-lint test/",
|
||||||
"lint:typescript": "balena-lint -e ts -e js --typescript src/ test/ typings/ && tsc --noEmit && tsc --noEmit --project tsconfig.js.json",
|
"lint:typescript": "balena-lint -e ts -e js --typescript src/ test/ typings/ && tsc --noEmit && tsc --noEmit --project tsconfig.js.json",
|
||||||
"sync": "ts-node sync/sync.ts"
|
"sync": "ts-node sync/sync.ts"
|
||||||
},
|
},
|
||||||
|
File diff suppressed because it is too large
Load Diff
5
src/application-manager.d.ts
vendored
5
src/application-manager.d.ts
vendored
@ -76,6 +76,7 @@ class ApplicationManager extends EventEmitter {
|
|||||||
db: DB,
|
db: DB,
|
||||||
eventTracker: EventTracker,
|
eventTracker: EventTracker,
|
||||||
deviceState: DeviceState,
|
deviceState: DeviceState,
|
||||||
|
apiBinder: APIBinder,
|
||||||
});
|
});
|
||||||
|
|
||||||
public init(): Promise<void>;
|
public init(): Promise<void>;
|
||||||
@ -95,7 +96,7 @@ class ApplicationManager extends EventEmitter {
|
|||||||
dependent: any,
|
dependent: any,
|
||||||
source: string,
|
source: string,
|
||||||
transaction: Knex.Transaction,
|
transaction: Knex.Transaction,
|
||||||
): Promise<void>;
|
): Bluebird<void>;
|
||||||
|
|
||||||
public getStatus(): Promise<{
|
public getStatus(): Promise<{
|
||||||
local: DeviceStatus.local.apps;
|
local: DeviceStatus.local.apps;
|
||||||
@ -107,7 +108,7 @@ class ApplicationManager extends EventEmitter {
|
|||||||
public stopAll(opts: { force?: boolean; skipLock?: boolean }): Promise<void>;
|
public stopAll(opts: { force?: boolean; skipLock?: boolean }): Promise<void>;
|
||||||
|
|
||||||
public serviceNameFromId(serviceId: number): Bluebird<string>;
|
public serviceNameFromId(serviceId: number): Bluebird<string>;
|
||||||
public imageForService(svc: any): Promise<Image>;
|
public imageForService(svc: any): Image;
|
||||||
public getDependentTargets(): Promise<any>;
|
public getDependentTargets(): Promise<any>;
|
||||||
public getCurrentForComparison(): Promise<any>;
|
public getCurrentForComparison(): Promise<any>;
|
||||||
public getDependentState(): Promise<any>;
|
public getDependentState(): Promise<any>;
|
||||||
|
1727
src/application-manager.js
Normal file
1727
src/application-manager.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -38,7 +38,7 @@ interface FetchProgressEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Image {
|
export interface Image {
|
||||||
id: number;
|
id?: number;
|
||||||
// image registry/repo@digest or registry/repo:tag
|
// image registry/repo@digest or registry/repo:tag
|
||||||
name: string;
|
name: string;
|
||||||
appId: number;
|
appId: number;
|
||||||
@ -48,9 +48,9 @@ export interface Image {
|
|||||||
imageId: number;
|
imageId: number;
|
||||||
releaseId: number;
|
releaseId: number;
|
||||||
dependent: number;
|
dependent: number;
|
||||||
dockerImageId: string;
|
dockerImageId?: string;
|
||||||
status: 'Downloading' | 'Downloaded' | 'Deleting';
|
status?: 'Downloading' | 'Downloaded' | 'Deleting';
|
||||||
downloadProgress: Nullable<number>;
|
downloadProgress?: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove the need for this type...
|
// TODO: Remove the need for this type...
|
||||||
@ -309,7 +309,10 @@ export class Images extends (EventEmitter as new () => ImageEventEmitter) {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const ids = _.map(imagesToRemove, 'id');
|
const ids = _(imagesToRemove)
|
||||||
|
.map('id')
|
||||||
|
.compact()
|
||||||
|
.value();
|
||||||
await this.db
|
await this.db
|
||||||
.models('image')
|
.models('image')
|
||||||
.del()
|
.del()
|
||||||
|
@ -164,7 +164,7 @@ export function createV2Api(router: Router, applications: ApplicationManager) {
|
|||||||
commit: string;
|
commit: string;
|
||||||
services: {
|
services: {
|
||||||
[serviceName: string]: {
|
[serviceName: string]: {
|
||||||
status: string;
|
status?: string;
|
||||||
releaseId: number;
|
releaseId: number;
|
||||||
downloadProgress: number | null;
|
downloadProgress: number | null;
|
||||||
};
|
};
|
||||||
@ -200,7 +200,7 @@ export function createV2Api(router: Router, applications: ApplicationManager) {
|
|||||||
return service.imageId === img.imageId;
|
return service.imageId === img.imageId;
|
||||||
});
|
});
|
||||||
|
|
||||||
let status: string;
|
let status: string | undefined;
|
||||||
if (svc == null) {
|
if (svc == null) {
|
||||||
status = img.status;
|
status = img.status;
|
||||||
} else {
|
} else {
|
||||||
|
@ -26,6 +26,7 @@ import * as updateLock from './lib/update-lock';
|
|||||||
import * as validation from './lib/validation';
|
import * as validation from './lib/validation';
|
||||||
import * as network from './network';
|
import * as network from './network';
|
||||||
|
|
||||||
|
import APIBinder from './api-binder';
|
||||||
import { ApplicationManager } from './application-manager';
|
import { ApplicationManager } from './application-manager';
|
||||||
import DeviceConfig, { ConfigStep } from './device-config';
|
import DeviceConfig, { ConfigStep } from './device-config';
|
||||||
import { log } from './lib/supervisor-console';
|
import { log } from './lib/supervisor-console';
|
||||||
@ -179,6 +180,7 @@ interface DeviceStateConstructOpts {
|
|||||||
config: Config;
|
config: Config;
|
||||||
eventTracker: EventTracker;
|
eventTracker: EventTracker;
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
|
apiBinder: APIBinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DeviceStateEvents {
|
interface DeviceStateEvents {
|
||||||
@ -243,7 +245,13 @@ export class DeviceState extends (EventEmitter as new () => DeviceStateEventEmit
|
|||||||
public connected: boolean;
|
public connected: boolean;
|
||||||
public router: express.Router;
|
public router: express.Router;
|
||||||
|
|
||||||
constructor({ db, config, eventTracker, logger }: DeviceStateConstructOpts) {
|
constructor({
|
||||||
|
db,
|
||||||
|
config,
|
||||||
|
eventTracker,
|
||||||
|
logger,
|
||||||
|
apiBinder,
|
||||||
|
}: DeviceStateConstructOpts) {
|
||||||
super();
|
super();
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
@ -260,6 +268,7 @@ export class DeviceState extends (EventEmitter as new () => DeviceStateEventEmit
|
|||||||
db: this.db,
|
db: this.db,
|
||||||
eventTracker: this.eventTracker,
|
eventTracker: this.eventTracker,
|
||||||
deviceState: this,
|
deviceState: this,
|
||||||
|
apiBinder,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.on('error', err => log.error('deviceState error: ', err));
|
this.on('error', err => log.error('deviceState error: ', err));
|
||||||
|
@ -65,7 +65,7 @@ export async function loadTargetFromFile(
|
|||||||
releaseId: app.releaseId,
|
releaseId: app.releaseId,
|
||||||
appId,
|
appId,
|
||||||
};
|
};
|
||||||
images.push(await deviceState.applications.imageForService(svc));
|
images.push(deviceState.applications.imageForService(svc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ const LABEL_NAME_REGEX = /^[a-zA-Z][a-zA-Z0-9\.\-]*$/;
|
|||||||
export function checkInt(
|
export function checkInt(
|
||||||
s: unknown,
|
s: unknown,
|
||||||
options: CheckIntOptions = {},
|
options: CheckIntOptions = {},
|
||||||
): number | void {
|
): number | undefined {
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -40,12 +40,6 @@ export class Supervisor {
|
|||||||
this.config = new Config({ db: this.db });
|
this.config = new Config({ db: this.db });
|
||||||
this.eventTracker = new EventTracker();
|
this.eventTracker = new EventTracker();
|
||||||
this.logger = new Logger({ db: this.db, eventTracker: this.eventTracker });
|
this.logger = new Logger({ db: this.db, eventTracker: this.eventTracker });
|
||||||
this.deviceState = new DeviceState({
|
|
||||||
config: this.config,
|
|
||||||
db: this.db,
|
|
||||||
eventTracker: this.eventTracker,
|
|
||||||
logger: this.logger,
|
|
||||||
});
|
|
||||||
this.apiBinder = new APIBinder({
|
this.apiBinder = new APIBinder({
|
||||||
config: this.config,
|
config: this.config,
|
||||||
db: this.db,
|
db: this.db,
|
||||||
@ -53,12 +47,17 @@ export class Supervisor {
|
|||||||
eventTracker: this.eventTracker,
|
eventTracker: this.eventTracker,
|
||||||
logger: this.logger,
|
logger: this.logger,
|
||||||
});
|
});
|
||||||
|
this.deviceState = new DeviceState({
|
||||||
|
config: this.config,
|
||||||
|
db: this.db,
|
||||||
|
eventTracker: this.eventTracker,
|
||||||
|
logger: this.logger,
|
||||||
|
apiBinder: this.apiBinder,
|
||||||
|
});
|
||||||
|
|
||||||
// FIXME: rearchitect proxyvisor to avoid this circular dependency
|
// FIXME: rearchitect proxyvisor to avoid this circular dependency
|
||||||
// by storing current state and having the APIBinder query and report it / provision devices
|
// by storing current state and having the APIBinder query and report it / provision devices
|
||||||
this.deviceState.applications.proxyvisor.bindToAPI(this.apiBinder);
|
this.deviceState.applications.proxyvisor.bindToAPI(this.apiBinder);
|
||||||
// We could also do without the below dependency, but it's part of a much larger refactor
|
|
||||||
this.deviceState.applications.apiBinder = this.apiBinder;
|
|
||||||
|
|
||||||
this.api = new SupervisorAPI({
|
this.api = new SupervisorAPI({
|
||||||
config: this.config,
|
config: this.config,
|
||||||
|
@ -48,7 +48,7 @@ export class TargetStateAccessor {
|
|||||||
return _.find(this.targetState, app => app.appId === appId);
|
return _.find(this.targetState, app => app.appId === appId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getTargetApps(): Promise<DatabaseApp> {
|
public async getTargetApps(): Promise<DatabaseApps> {
|
||||||
if (this.targetState == null) {
|
if (this.targetState == null) {
|
||||||
const { apiEndpoint, localMode } = await this.config.getMany([
|
const { apiEndpoint, localMode } = await this.config.getMany([
|
||||||
'apiEndpoint',
|
'apiEndpoint',
|
||||||
|
@ -232,6 +232,7 @@ describe('deviceState', () => {
|
|||||||
config,
|
config,
|
||||||
eventTracker: eventTracker as any,
|
eventTracker: eventTracker as any,
|
||||||
logger: logger as any,
|
logger: logger as any,
|
||||||
|
apiBinder: null as any,
|
||||||
});
|
});
|
||||||
|
|
||||||
stub(deviceState.applications.docker, 'getNetworkGateway').returns(
|
stub(deviceState.applications.docker, 'getNetworkGateway').returns(
|
||||||
|
@ -29,13 +29,6 @@ const initModels = async (obj: Dictionary<any>, filename: string) => {
|
|||||||
},
|
},
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
obj.deviceState = new DeviceState({
|
|
||||||
db: obj.db,
|
|
||||||
config: obj.config,
|
|
||||||
eventTracker: obj.eventTracker,
|
|
||||||
logger: obj.logger,
|
|
||||||
});
|
|
||||||
|
|
||||||
obj.apiBinder = new ApiBinder({
|
obj.apiBinder = new ApiBinder({
|
||||||
db: obj.db,
|
db: obj.db,
|
||||||
config: obj.config,
|
config: obj.config,
|
||||||
@ -43,6 +36,14 @@ const initModels = async (obj: Dictionary<any>, filename: string) => {
|
|||||||
eventTracker: obj.eventTracker,
|
eventTracker: obj.eventTracker,
|
||||||
deviceState: obj.deviceState,
|
deviceState: obj.deviceState,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
obj.deviceState = new DeviceState({
|
||||||
|
db: obj.db,
|
||||||
|
config: obj.config,
|
||||||
|
eventTracker: obj.eventTracker,
|
||||||
|
logger: obj.logger,
|
||||||
|
apiBinder: obj.apiBinder,
|
||||||
|
});
|
||||||
await obj.db.init();
|
await obj.db.init();
|
||||||
await obj.config.init();
|
await obj.config.init();
|
||||||
await obj.apiBinder.initClient(); // Initializes the clients but doesn't trigger provisioning
|
await obj.apiBinder.initClient(); // Initializes the clients but doesn't trigger provisioning
|
||||||
|
@ -224,7 +224,7 @@ describe 'ApplicationManager', ->
|
|||||||
expect(steps).to.eventually.deep.equal([{
|
expect(steps).to.eventually.deep.equal([{
|
||||||
action: 'kill'
|
action: 'kill'
|
||||||
current: current.local.apps['1234'].services[1]
|
current: current.local.apps['1234'].services[1]
|
||||||
target: null
|
target: undefined
|
||||||
serviceId: 24
|
serviceId: 24
|
||||||
appId: 1234
|
appId: 1234
|
||||||
options: {}
|
options: {}
|
||||||
@ -358,7 +358,7 @@ describe 'ApplicationManager', ->
|
|||||||
{
|
{
|
||||||
action: 'kill'
|
action: 'kill'
|
||||||
current: current.local.apps['1234'].services[0]
|
current: current.local.apps['1234'].services[0]
|
||||||
target: null
|
target: undefined
|
||||||
serviceId: 23
|
serviceId: 23
|
||||||
appId: 1234
|
appId: 1234
|
||||||
options: {}
|
options: {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user