Add application status endpoint

Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2018-12-03 17:38:52 +00:00
parent d863326783
commit 769e2f3c51
No known key found for this signature in database
GPG Key ID: 49690ED87032539F

View File

@ -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,56 @@ export function createV2Api(router: Router, applications: ApplicationManager) {
});
}
});
router.get('/v2/state/status', async (_req, res) => {
const localMode = await applications.config.get('localMode');
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,
});
});
}