mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-20 14:13:08 +00:00
Merge pull request #828 from balena-io/add-status-endpoint
Add application status endpoint
This commit is contained in:
commit
b606332312
2
src/application-manager.d.ts
vendored
2
src/application-manager.d.ts
vendored
@ -11,6 +11,7 @@ import ServiceManager from './compose/service-manager';
|
||||
import DB from './db';
|
||||
|
||||
import { Service } from './compose/service';
|
||||
import Config from './config';
|
||||
|
||||
declare interface Options {
|
||||
force?: boolean;
|
||||
@ -38,6 +39,7 @@ export class ApplicationManager extends EventEmitter {
|
||||
public eventTracker: EventTracker;
|
||||
|
||||
public services: ServiceManager;
|
||||
public config: Config;
|
||||
public db: DB;
|
||||
public images: Images;
|
||||
|
||||
|
@ -667,3 +667,5 @@ export class ServiceManager extends (EventEmitter as {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default ServiceManager;
|
||||
|
@ -206,7 +206,7 @@ export function createV2Api(router: Router, applications: ApplicationManager) {
|
||||
if (svc == null) {
|
||||
status = img.status;
|
||||
} else {
|
||||
status = svc.status;
|
||||
status = svc.status || img.status;
|
||||
}
|
||||
response[appName].services[img.serviceName] = {
|
||||
status,
|
||||
@ -382,4 +382,58 @@ export function createV2Api(router: Router, applications: ApplicationManager) {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/v2/state/status', async (_req, res) => {
|
||||
const localMode = await applications.config.get('localMode');
|
||||
const currentRelease = await applications.config.get('currentCommit');
|
||||
|
||||
const pending = applications.deviceState.applyInProgress;
|
||||
const containerStates = (await applications.services.getAll()).map(svc =>
|
||||
_.pick(
|
||||
svc,
|
||||
'status',
|
||||
'serviceName',
|
||||
'appId',
|
||||
'imageId',
|
||||
'serviceId',
|
||||
'containerId',
|
||||
'createdAt',
|
||||
),
|
||||
);
|
||||
|
||||
let downloadProgressTotal = 0;
|
||||
let downloads = 0;
|
||||
const imagesStates = (await applications.images.getStatus(localMode)).map(
|
||||
img => {
|
||||
if (img.downloadProgress != null) {
|
||||
downloadProgressTotal += img.downloadProgress;
|
||||
downloads += 1;
|
||||
}
|
||||
return _.pick(
|
||||
img,
|
||||
'name',
|
||||
'appId',
|
||||
'serviceName',
|
||||
'imageId',
|
||||
'dockerImageId',
|
||||
'status',
|
||||
'downloadProgress',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
let overallDownloadProgress = null;
|
||||
if (downloads > 0) {
|
||||
overallDownloadProgress = downloadProgressTotal / downloads;
|
||||
}
|
||||
|
||||
return res.status(200).send({
|
||||
status: 'success',
|
||||
appState: pending ? 'applying' : 'applied',
|
||||
overallDownloadProgress,
|
||||
containers: containerStates,
|
||||
images: imagesStates,
|
||||
release: currentRelease,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user