mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-06-20 08:13:46 +00:00
Cleanup current state reporting methods
Removed redundant `getCurrentAppsForReport` and `getCurrentForComparison` since the behavior of these methods is already handled by `getCurrentApps` and `getCurrentState`.
This commit is contained in:
@ -34,7 +34,6 @@ import { CompositionStep, generateStep } from './composition-steps';
|
|||||||
import {
|
import {
|
||||||
InstancedAppState,
|
InstancedAppState,
|
||||||
TargetApps,
|
TargetApps,
|
||||||
DeviceStatus,
|
|
||||||
DeviceReportFields,
|
DeviceReportFields,
|
||||||
} from '../types/state';
|
} from '../types/state';
|
||||||
import { checkTruthy } from '../lib/validation';
|
import { checkTruthy } from '../lib/validation';
|
||||||
@ -157,14 +156,14 @@ function reportCurrentState(data?: Partial<InstancedAppState>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getRequiredSteps(
|
export async function getRequiredSteps(
|
||||||
|
currentApps: InstancedAppState,
|
||||||
targetApps: InstancedAppState,
|
targetApps: InstancedAppState,
|
||||||
ignoreImages: boolean = false,
|
ignoreImages: boolean = false,
|
||||||
): Promise<CompositionStep[]> {
|
): Promise<CompositionStep[]> {
|
||||||
// get some required data
|
// get some required data
|
||||||
const [downloading, availableImages, currentApps] = await Promise.all([
|
const [downloading, availableImages] = await Promise.all([
|
||||||
imageManager.getDownloadingImageNames(),
|
imageManager.getDownloadingImageNames(),
|
||||||
imageManager.getAvailable(),
|
imageManager.getAvailable(),
|
||||||
getCurrentApps(),
|
|
||||||
]);
|
]);
|
||||||
const containerIdsByAppId = await getAppContainerIds(currentApps);
|
const containerIdsByAppId = await getAppContainerIds(currentApps);
|
||||||
|
|
||||||
@ -352,21 +351,6 @@ export async function stopAll({ force = false, skipLock = false } = {}) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCurrentAppsForReport(): Promise<
|
|
||||||
NonNullable<DeviceStatus['local']>['apps']
|
|
||||||
> {
|
|
||||||
const apps = await getCurrentApps();
|
|
||||||
|
|
||||||
const appsToReport: NonNullable<DeviceStatus['local']>['apps'] = {};
|
|
||||||
for (const appId of Object.getOwnPropertyNames(apps)) {
|
|
||||||
appsToReport[appId] = {
|
|
||||||
services: {},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return appsToReport;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getCurrentApps(): Promise<InstancedAppState> {
|
export async function getCurrentApps(): Promise<InstancedAppState> {
|
||||||
const volumes = _.groupBy(await volumeManager.getAll(), 'appId');
|
const volumes = _.groupBy(await volumeManager.getAll(), 'appId');
|
||||||
const networks = _.groupBy(await networkManager.getAll(), 'appId');
|
const networks = _.groupBy(await networkManager.getAll(), 'appId');
|
||||||
|
@ -10,7 +10,6 @@ import { EnvVarObject } from './types';
|
|||||||
import { UnitNotLoadedError } from './lib/errors';
|
import { UnitNotLoadedError } from './lib/errors';
|
||||||
import { checkInt, checkTruthy } from './lib/validation';
|
import { checkInt, checkTruthy } from './lib/validation';
|
||||||
import log from './lib/supervisor-console';
|
import log from './lib/supervisor-console';
|
||||||
import { DeviceStatus } from './types/state';
|
|
||||||
import * as configUtils from './config/utils';
|
import * as configUtils from './config/utils';
|
||||||
import { SchemaTypeKey } from './config/schema-type';
|
import { SchemaTypeKey } from './config/schema-type';
|
||||||
import { matchesAnyBootConfig } from './config/backends';
|
import { matchesAnyBootConfig } from './config/backends';
|
||||||
@ -560,19 +559,11 @@ async function isRebootRequired() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getRequiredSteps(
|
export async function getRequiredSteps(
|
||||||
currentState: DeviceStatus,
|
currentState: { local?: { config?: EnvVarObject } },
|
||||||
targetState: { local?: { config?: Dictionary<string> } },
|
targetState: { local?: { config: EnvVarObject } },
|
||||||
): Promise<ConfigStep[]> {
|
): Promise<ConfigStep[]> {
|
||||||
const current: Dictionary<string> = _.get(
|
const current = currentState?.local?.config ?? {};
|
||||||
currentState,
|
const target = targetState?.local?.config ?? {};
|
||||||
['local', 'config'],
|
|
||||||
{},
|
|
||||||
);
|
|
||||||
const target: Dictionary<string> = _.get(
|
|
||||||
targetState,
|
|
||||||
['local', 'config'],
|
|
||||||
{},
|
|
||||||
);
|
|
||||||
|
|
||||||
const configSteps = getConfigSteps(current, target);
|
const configSteps = getConfigSteps(current, target);
|
||||||
const steps = [
|
const steps = [
|
||||||
|
@ -42,7 +42,7 @@ import {
|
|||||||
InstancedDeviceState,
|
InstancedDeviceState,
|
||||||
TargetState,
|
TargetState,
|
||||||
InstancedAppState,
|
InstancedAppState,
|
||||||
} from './types/state';
|
} from './types';
|
||||||
import * as dbFormat from './device-state/db-format';
|
import * as dbFormat from './device-state/db-format';
|
||||||
import * as apiKeys from './lib/api-keys';
|
import * as apiKeys from './lib/api-keys';
|
||||||
|
|
||||||
@ -569,26 +569,6 @@ export async function getCurrentForReport(): Promise<DeviceStatus> {
|
|||||||
return theState as DeviceStatus;
|
return theState as DeviceStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCurrentForComparison(): Promise<
|
|
||||||
DeviceStatus & { local: { name: string } }
|
|
||||||
> {
|
|
||||||
const [name, devConfig, apps, dependent] = await Promise.all([
|
|
||||||
config.get('name'),
|
|
||||||
deviceConfig.getCurrent(),
|
|
||||||
applicationManager.getCurrentAppsForReport(),
|
|
||||||
applicationManager.getDependentState(),
|
|
||||||
]);
|
|
||||||
return {
|
|
||||||
local: {
|
|
||||||
name,
|
|
||||||
config: devConfig,
|
|
||||||
apps,
|
|
||||||
},
|
|
||||||
|
|
||||||
dependent,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getCurrentState(): Promise<InstancedDeviceState> {
|
export async function getCurrentState(): Promise<InstancedDeviceState> {
|
||||||
const [name, devConfig, apps, dependent] = await Promise.all([
|
const [name, devConfig, apps, dependent] = await Promise.all([
|
||||||
config.get('name'),
|
config.get('name'),
|
||||||
@ -768,7 +748,7 @@ export const applyTarget = async ({
|
|||||||
|
|
||||||
return usingInferStepsLock(async () => {
|
return usingInferStepsLock(async () => {
|
||||||
const [currentState, targetState] = await Promise.all([
|
const [currentState, targetState] = await Promise.all([
|
||||||
getCurrentForComparison(),
|
getCurrentState(),
|
||||||
getTarget({ initial, intermediate }),
|
getTarget({ initial, intermediate }),
|
||||||
]);
|
]);
|
||||||
const deviceConfigSteps = await deviceConfig.getRequiredSteps(
|
const deviceConfigSteps = await deviceConfig.getRequiredSteps(
|
||||||
@ -788,6 +768,7 @@ export const applyTarget = async ({
|
|||||||
steps = deviceConfigSteps;
|
steps = deviceConfigSteps;
|
||||||
} else {
|
} else {
|
||||||
const appSteps = await applicationManager.getRequiredSteps(
|
const appSteps = await applicationManager.getRequiredSteps(
|
||||||
|
currentState.local.apps,
|
||||||
targetState.local.apps,
|
targetState.local.apps,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import { InternalInconsistencyError, StatusError } from '../lib/errors';
|
|||||||
import { getRequestInstance } from '../lib/request';
|
import { getRequestInstance } from '../lib/request';
|
||||||
import * as sysInfo from '../lib/system-info';
|
import * as sysInfo from '../lib/system-info';
|
||||||
|
|
||||||
import { DeviceStatus } from '../types/state';
|
import { DeviceStatus } from '../types';
|
||||||
import * as config from '../config';
|
import * as config from '../config';
|
||||||
import { SchemaTypeKey, SchemaReturn } from '../config/schema-type';
|
import { SchemaTypeKey, SchemaReturn } from '../config/schema-type';
|
||||||
import * as eventTracker from '../event-tracker';
|
import * as eventTracker from '../event-tracker';
|
||||||
|
Reference in New Issue
Block a user