Remove unnecessary code from application-manager

Change-type: patch
This commit is contained in:
Pagan Gazzard 2020-03-26 23:50:53 +00:00
parent 2a50a4262d
commit 686f72ecf7

View File

@ -72,7 +72,7 @@ exports.ApplicationManager = class ApplicationManager extends EventEmitter
constructor: ({ @logger, @config, @db, @eventTracker, @deviceState }) -> constructor: ({ @logger, @config, @db, @eventTracker, @deviceState }) ->
@docker = new Docker() @docker = new Docker()
@images = new Images({ @docker, @logger, @db, @config }) @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 }) @networks = new NetworkManager({ @docker, @logger })
@volumes = new VolumeManager({ @docker, @logger }) @volumes = new VolumeManager({ @docker, @logger })
@proxyvisor = new Proxyvisor({ @config, @logger, @db, @docker, @images, applications: this }) @proxyvisor = new Proxyvisor({ @config, @logger, @db, @docker, @images, applications: this })
@ -152,13 +152,9 @@ exports.ApplicationManager = class ApplicationManager extends EventEmitter
# Returns the status of applications and their services # Returns the status of applications and their services
getStatus: => getStatus: =>
@config.get('localMode').then (localMode) =>
@_getStatus(localMode)
_getStatus: (localMode) =>
Promise.join( Promise.join(
@services.getStatus() @services.getStatus()
@images.getStatus(localMode) @images.getStatus()
@config.get('currentCommit') @config.get('currentCommit')
(services, images, currentCommit) -> (services, images, currentCommit) ->
apps = {} apps = {}
@ -328,7 +324,7 @@ exports.ApplicationManager = class ApplicationManager extends EventEmitter
return { removePairs, installPairs, updatePairs } return { removePairs, installPairs, updatePairs }
_compareNetworksOrVolumesForUpdate: (model, { current, target }, appId) -> _compareNetworksOrVolumesForUpdate: (model, { current, target }) ->
outputPairs = [] outputPairs = []
currentNames = _.keys(current) currentNames = _.keys(current)
targetNames = _.keys(target) targetNames = _.keys(target)
@ -351,11 +347,11 @@ exports.ApplicationManager = class ApplicationManager extends EventEmitter
return outputPairs return outputPairs
compareNetworksForUpdate: ({ current, target }, appId) => compareNetworksForUpdate: ({ current, target }) =>
@_compareNetworksOrVolumesForUpdate(@networks, { current, target }, appId) @_compareNetworksOrVolumesForUpdate(@networks, { current, target })
compareVolumesForUpdate: ({ current, target }, appId) => compareVolumesForUpdate: ({ current, target }) =>
@_compareNetworksOrVolumesForUpdate(@volumes, { current, target }, appId) @_compareNetworksOrVolumesForUpdate(@volumes, { current, target })
# Checks if a service is using a network or volume that is about to be updated # Checks if a service is using a network or volume that is about to be updated
_hasCurrentNetworksOrVolumes: (service, networkPairs, volumePairs) -> _hasCurrentNetworksOrVolumes: (service, networkPairs, volumePairs) ->
@ -542,9 +538,8 @@ exports.ApplicationManager = 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].config.labels['io.balena.service-id'] = currentApp.services[0].config.labels['io.balena.service-id']
targetApp.services[0].serviceId = currentApp.services[0].serviceId targetApp.services[0].serviceId = currentApp.services[0].serviceId
appId = targetApp.appId ? currentApp.appId networkPairs = @compareNetworksForUpdate({ current: currentApp.networks, target: targetApp.networks })
networkPairs = @compareNetworksForUpdate({ current: currentApp.networks, target: targetApp.networks }, appId) volumePairs = @compareVolumesForUpdate({ current: currentApp.volumes, target: targetApp.volumes })
volumePairs = @compareVolumesForUpdate({ current: currentApp.volumes, target: targetApp.volumes }, appId)
{ removePairs, installPairs, updatePairs } = @compareServicesForUpdate(currentApp.services, targetApp.services, containerIds) { removePairs, installPairs, updatePairs } = @compareServicesForUpdate(currentApp.services, targetApp.services, containerIds)
steps = [] steps = []
# All removePairs get a 'kill' action # All removePairs get a 'kill' action
@ -575,6 +570,7 @@ exports.ApplicationManager = class ApplicationManager extends EventEmitter
target: targetApp.commit target: targetApp.commit
}) })
appId = targetApp.appId ? currentApp.appId
return _.map(steps, (step) -> _.assign({}, step, { appId })) return _.map(steps, (step) -> _.assign({}, step, { appId }))
normaliseAppForDB: (app) => normaliseAppForDB: (app) =>
@ -691,9 +687,9 @@ exports.ApplicationManager = class ApplicationManager extends EventEmitter
appClone.source = source appClone.source = source
return appClone return appClone
Promise.map(appsArray, @normaliseAppForDB) Promise.map(appsArray, @normaliseAppForDB)
.tap (appsForDB) => .then (appsForDB) =>
@targetStateWrapper.setTargetApps(appsForDB, trx) @targetStateWrapper.setTargetApps(appsForDB, trx)
.then (appsForDB) -> .then ->
trx('app').where({ source }).whereNotIn('appId', trx('app').where({ source }).whereNotIn('appId',
# Use apps here, rather than filteredApps, to # Use apps here, rather than filteredApps, to
# avoid removing a release from the database # avoid removing a release from the database
@ -856,7 +852,6 @@ exports.ApplicationManager = class ApplicationManager extends EventEmitter
# We also don't want to remove cloud volumes when # We also don't want to remove cloud volumes when
# switching to local mode # switching to local mode
# multi-app warning: this will break # multi-app warning: this will break
oldApps = null
if !localMode if !localMode
currentAppIds = _.keys(current.local.apps).map((n) -> checkInt(n)) currentAppIds = _.keys(current.local.apps).map((n) -> checkInt(n))
targetAppIds = _.keys(target.local.apps).map((n) -> checkInt(n)) targetAppIds = _.keys(target.local.apps).map((n) -> checkInt(n))
@ -968,7 +963,7 @@ exports.ApplicationManager = class ApplicationManager extends EventEmitter
@config.get('localMode').then (localMode) => @config.get('localMode').then (localMode) =>
Promise.props({ Promise.props({
cleanupNeeded: @images.isCleanupNeeded() cleanupNeeded: @images.isCleanupNeeded()
availableImages: @images.getAvailable(localMode) availableImages: @images.getAvailable()
downloading: @images.getDownloadingImageIds() downloading: @images.getDownloadingImageIds()
supervisorNetworkReady: @networks.supervisorNetworkReady() supervisorNetworkReady: @networks.supervisorNetworkReady()
delta: @config.get('delta') delta: @config.get('delta')