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:
Felipe Lalanne 2021-08-25 15:31:54 +00:00
parent 063bd400a4
commit 0b19dee511
4 changed files with 10 additions and 54 deletions

View File

@ -34,7 +34,6 @@ import { CompositionStep, generateStep } from './composition-steps';
import {
InstancedAppState,
TargetApps,
DeviceStatus,
DeviceReportFields,
} from '../types/state';
import { checkTruthy } from '../lib/validation';
@ -157,14 +156,14 @@ function reportCurrentState(data?: Partial<InstancedAppState>) {
}
export async function getRequiredSteps(
currentApps: InstancedAppState,
targetApps: InstancedAppState,
ignoreImages: boolean = false,
): Promise<CompositionStep[]> {
// get some required data
const [downloading, availableImages, currentApps] = await Promise.all([
const [downloading, availableImages] = await Promise.all([
imageManager.getDownloadingImageNames(),
imageManager.getAvailable(),
getCurrentApps(),
]);
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> {
const volumes = _.groupBy(await volumeManager.getAll(), 'appId');
const networks = _.groupBy(await networkManager.getAll(), 'appId');

View File

@ -10,7 +10,6 @@ import { EnvVarObject } from './types';
import { UnitNotLoadedError } from './lib/errors';
import { checkInt, checkTruthy } from './lib/validation';
import log from './lib/supervisor-console';
import { DeviceStatus } from './types/state';
import * as configUtils from './config/utils';
import { SchemaTypeKey } from './config/schema-type';
import { matchesAnyBootConfig } from './config/backends';
@ -560,19 +559,11 @@ async function isRebootRequired() {
}
export async function getRequiredSteps(
currentState: DeviceStatus,
targetState: { local?: { config?: Dictionary<string> } },
currentState: { local?: { config?: EnvVarObject } },
targetState: { local?: { config: EnvVarObject } },
): Promise<ConfigStep[]> {
const current: Dictionary<string> = _.get(
currentState,
['local', 'config'],
{},
);
const target: Dictionary<string> = _.get(
targetState,
['local', 'config'],
{},
);
const current = currentState?.local?.config ?? {};
const target = targetState?.local?.config ?? {};
const configSteps = getConfigSteps(current, target);
const steps = [

View File

@ -42,7 +42,7 @@ import {
InstancedDeviceState,
TargetState,
InstancedAppState,
} from './types/state';
} from './types';
import * as dbFormat from './device-state/db-format';
import * as apiKeys from './lib/api-keys';
@ -569,26 +569,6 @@ export async function getCurrentForReport(): Promise<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> {
const [name, devConfig, apps, dependent] = await Promise.all([
config.get('name'),
@ -768,7 +748,7 @@ export const applyTarget = async ({
return usingInferStepsLock(async () => {
const [currentState, targetState] = await Promise.all([
getCurrentForComparison(),
getCurrentState(),
getTarget({ initial, intermediate }),
]);
const deviceConfigSteps = await deviceConfig.getRequiredSteps(
@ -788,6 +768,7 @@ export const applyTarget = async ({
steps = deviceConfigSteps;
} else {
const appSteps = await applicationManager.getRequiredSteps(
currentState.local.apps,
targetState.local.apps,
);

View File

@ -9,7 +9,7 @@ import { InternalInconsistencyError, StatusError } from '../lib/errors';
import { getRequestInstance } from '../lib/request';
import * as sysInfo from '../lib/system-info';
import { DeviceStatus } from '../types/state';
import { DeviceStatus } from '../types';
import * as config from '../config';
import { SchemaTypeKey, SchemaReturn } from '../config/schema-type';
import * as eventTracker from '../event-tracker';