mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-21 10:01:55 +00:00
Merge pull request #1229 from balena-io/application-manager
Application manager improvements
This commit is contained in:
commit
d5767b647d
@ -68,11 +68,11 @@ createApplicationManagerRouter = (applications) ->
|
||||
|
||||
return router
|
||||
|
||||
module.exports = class ApplicationManager extends EventEmitter
|
||||
exports.ApplicationManager = class ApplicationManager extends EventEmitter
|
||||
constructor: ({ @logger, @config, @db, @eventTracker, @deviceState }) ->
|
||||
@docker = new Docker()
|
||||
@images = new Images({ @docker, @logger, @db, @config })
|
||||
@services = new ServiceManager({ @docker, @logger, @images, @config })
|
||||
@services = new ServiceManager({ @docker, @logger, @config })
|
||||
@networks = new NetworkManager({ @docker, @logger })
|
||||
@volumes = new VolumeManager({ @docker, @logger })
|
||||
@proxyvisor = new Proxyvisor({ @config, @logger, @db, @docker, @images, applications: this })
|
||||
@ -152,13 +152,9 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
|
||||
# Returns the status of applications and their services
|
||||
getStatus: =>
|
||||
@config.get('localMode').then (localMode) =>
|
||||
@_getStatus(localMode)
|
||||
|
||||
_getStatus: (localMode) =>
|
||||
Promise.join(
|
||||
@services.getStatus()
|
||||
@images.getStatus(localMode)
|
||||
@images.getStatus()
|
||||
@config.get('currentCommit')
|
||||
(services, images, currentCommit) ->
|
||||
apps = {}
|
||||
@ -328,7 +324,7 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
|
||||
return { removePairs, installPairs, updatePairs }
|
||||
|
||||
_compareNetworksOrVolumesForUpdate: (model, { current, target }, appId) ->
|
||||
_compareNetworksOrVolumesForUpdate: (model, { current, target }) ->
|
||||
outputPairs = []
|
||||
currentNames = _.keys(current)
|
||||
targetNames = _.keys(target)
|
||||
@ -351,11 +347,11 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
|
||||
return outputPairs
|
||||
|
||||
compareNetworksForUpdate: ({ current, target }, appId) =>
|
||||
@_compareNetworksOrVolumesForUpdate(@networks, { current, target }, appId)
|
||||
compareNetworksForUpdate: ({ current, target }) =>
|
||||
@_compareNetworksOrVolumesForUpdate(@networks, { current, target })
|
||||
|
||||
compareVolumesForUpdate: ({ current, target }, appId) =>
|
||||
@_compareNetworksOrVolumesForUpdate(@volumes, { current, target }, appId)
|
||||
compareVolumesForUpdate: ({ current, target }) =>
|
||||
@_compareNetworksOrVolumesForUpdate(@volumes, { current, target })
|
||||
|
||||
# Checks if a service is using a network or volume that is about to be updated
|
||||
_hasCurrentNetworksOrVolumes: (service, networkPairs, volumePairs) ->
|
||||
@ -542,9 +538,8 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
targetApp.services[0].config.labels['io.balena.service-id'] = currentApp.services[0].config.labels['io.balena.service-id']
|
||||
targetApp.services[0].serviceId = currentApp.services[0].serviceId
|
||||
|
||||
appId = targetApp.appId ? currentApp.appId
|
||||
networkPairs = @compareNetworksForUpdate({ current: currentApp.networks, target: targetApp.networks }, appId)
|
||||
volumePairs = @compareVolumesForUpdate({ current: currentApp.volumes, target: targetApp.volumes }, appId)
|
||||
networkPairs = @compareNetworksForUpdate({ current: currentApp.networks, target: targetApp.networks })
|
||||
volumePairs = @compareVolumesForUpdate({ current: currentApp.volumes, target: targetApp.volumes })
|
||||
{ removePairs, installPairs, updatePairs } = @compareServicesForUpdate(currentApp.services, targetApp.services, containerIds)
|
||||
steps = []
|
||||
# All removePairs get a 'kill' action
|
||||
@ -575,6 +570,7 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
target: targetApp.commit
|
||||
})
|
||||
|
||||
appId = targetApp.appId ? currentApp.appId
|
||||
return _.map(steps, (step) -> _.assign({}, step, { appId }))
|
||||
|
||||
normaliseAppForDB: (app) =>
|
||||
@ -691,9 +687,9 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
appClone.source = source
|
||||
return appClone
|
||||
Promise.map(appsArray, @normaliseAppForDB)
|
||||
.tap (appsForDB) =>
|
||||
.then (appsForDB) =>
|
||||
@targetStateWrapper.setTargetApps(appsForDB, trx)
|
||||
.then (appsForDB) ->
|
||||
.then ->
|
||||
trx('app').where({ source }).whereNotIn('appId',
|
||||
# Use apps here, rather than filteredApps, to
|
||||
# avoid removing a release from the database
|
||||
@ -856,7 +852,6 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
# We also don't want to remove cloud volumes when
|
||||
# switching to local mode
|
||||
# multi-app warning: this will break
|
||||
oldApps = null
|
||||
if !localMode
|
||||
currentAppIds = _.keys(current.local.apps).map((n) -> checkInt(n))
|
||||
targetAppIds = _.keys(target.local.apps).map((n) -> checkInt(n))
|
||||
@ -968,7 +963,7 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
@config.get('localMode').then (localMode) =>
|
||||
Promise.props({
|
||||
cleanupNeeded: @images.isCleanupNeeded()
|
||||
availableImages: @images.getAvailable(localMode)
|
||||
availableImages: @images.getAvailable()
|
||||
downloading: @images.getDownloadingImageIds()
|
||||
supervisorNetworkReady: @networks.supervisorNetworkReady()
|
||||
delta: @config.get('delta')
|
||||
|
2
src/application-manager.d.ts
vendored
2
src/application-manager.d.ts
vendored
@ -121,4 +121,4 @@ class ApplicationManager extends EventEmitter {
|
||||
public localModeSwitchCompletion(): Promise<void>;
|
||||
}
|
||||
|
||||
export = ApplicationManager;
|
||||
export { ApplicationManager };
|
||||
|
@ -2,7 +2,7 @@ import * as _ from 'lodash';
|
||||
|
||||
import Config from '../config';
|
||||
|
||||
import ApplicationManager = require('../application-manager');
|
||||
import { ApplicationManager } from '../application-manager';
|
||||
import Images, { Image } from './images';
|
||||
import Network from './network';
|
||||
import Service from './service';
|
||||
@ -129,7 +129,7 @@ interface CompositionCallbacks {
|
||||
fetchStart: () => void;
|
||||
fetchEnd: () => void;
|
||||
fetchTime: (time: number) => void;
|
||||
stateReport: (state: Dictionary<unknown>) => Promise<void>;
|
||||
stateReport: (state: Dictionary<unknown>) => boolean;
|
||||
bestDeltaSource: (image: Image, available: Image[]) => string | null;
|
||||
}
|
||||
|
||||
|
@ -465,7 +465,10 @@ export class Images extends (EventEmitter as new () => ImageEventEmitter) {
|
||||
}
|
||||
}
|
||||
|
||||
public static isSameImage(image1: Image, image2: Image): boolean {
|
||||
public static isSameImage(
|
||||
image1: Pick<Image, 'name'>,
|
||||
image2: Pick<Image, 'name'>,
|
||||
): boolean {
|
||||
return (
|
||||
image1.name === image2.name ||
|
||||
Images.hasSameDigest(image1.name, image2.name)
|
||||
|
4
src/device-api/common.d.ts
vendored
4
src/device-api/common.d.ts
vendored
@ -25,6 +25,6 @@ declare function serviceAction(
|
||||
action: string,
|
||||
serviceId: number,
|
||||
current: Service,
|
||||
target: Service,
|
||||
options: any,
|
||||
target?: Service,
|
||||
options?: any,
|
||||
): ServiceAction;
|
||||
|
@ -3,7 +3,7 @@ import { NextFunction, Request, Response, Router } from 'express';
|
||||
import * as _ from 'lodash';
|
||||
import { fs } from 'mz';
|
||||
|
||||
import ApplicationManager = require('../application-manager');
|
||||
import { ApplicationManager } from '../application-manager';
|
||||
import { Service } from '../compose/service';
|
||||
import {
|
||||
appNotFoundMessage,
|
||||
|
@ -25,7 +25,7 @@ import * as updateLock from './lib/update-lock';
|
||||
import * as validation from './lib/validation';
|
||||
import * as network from './network';
|
||||
|
||||
import ApplicationManager = require('./application-manager');
|
||||
import { ApplicationManager } from './application-manager';
|
||||
import DeviceConfig, { ConfigStep } from './device-config';
|
||||
import { log } from './lib/supervisor-console';
|
||||
import {
|
||||
|
@ -45,7 +45,7 @@ const DELTA_TOKEN_TIMEOUT = 10 * 60 * 1000;
|
||||
export class DockerUtils extends DockerToolbelt {
|
||||
public dockerProgress: DockerProgress;
|
||||
|
||||
public constructor(opts: Dockerode.DockerOptions) {
|
||||
public constructor(opts?: Dockerode.DockerOptions) {
|
||||
super(opts);
|
||||
this.dockerProgress = new DockerProgress({ dockerToolbelt: this });
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import * as rimraf from 'rimraf';
|
||||
const mkdirpAsync = Bluebird.promisify(mkdirp);
|
||||
const rimrafAsync = Bluebird.promisify(rimraf);
|
||||
|
||||
import ApplicationManager = require('../application-manager');
|
||||
import { ApplicationManager } from '../application-manager';
|
||||
import Config from '../config';
|
||||
import Database, { Transaction } from '../db';
|
||||
import DeviceState from '../device-state';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import ApplicationManager = require('./application-manager');
|
||||
import { ApplicationManager } from './application-manager';
|
||||
import Config from './config';
|
||||
import Database, { Transaction } from './db';
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user