mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-30 02:28:53 +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 DB from './db';
|
||||||
|
|
||||||
import { Service } from './compose/service';
|
import { Service } from './compose/service';
|
||||||
|
import Config from './config';
|
||||||
|
|
||||||
declare interface Options {
|
declare interface Options {
|
||||||
force?: boolean;
|
force?: boolean;
|
||||||
@ -38,6 +39,7 @@ export class ApplicationManager extends EventEmitter {
|
|||||||
public eventTracker: EventTracker;
|
public eventTracker: EventTracker;
|
||||||
|
|
||||||
public services: ServiceManager;
|
public services: ServiceManager;
|
||||||
|
public config: Config;
|
||||||
public db: DB;
|
public db: DB;
|
||||||
public images: Images;
|
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) {
|
if (svc == null) {
|
||||||
status = img.status;
|
status = img.status;
|
||||||
} else {
|
} else {
|
||||||
status = svc.status;
|
status = svc.status || img.status;
|
||||||
}
|
}
|
||||||
response[appName].services[img.serviceName] = {
|
response[appName].services[img.serviceName] = {
|
||||||
status,
|
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