in source/packages/services/greengrass2-provisioning/src/cores/cores.service.ts [151:248]
public async get(name: string): Promise<CoreItem> {
logger.debug(`cores.service get: in: name:${name}`);
ow(name, ow.string.nonEmpty);
const coreFuture = this.coresDao.get(name);
const installedComponentsFuture = this.ggv2.send(
new ListInstalledComponentsCommand({
coreDeviceThingName: name,
// TODO: manage pagination of installed components
})
);
const coreDeviceFuture = this.ggv2.send(
new GetCoreDeviceCommand({
coreDeviceThingName: name,
})
);
const effectiveDeploymentsFuture = this.ggv2.send(
new ListEffectiveDeploymentsCommand({
coreDeviceThingName: name,
})
);
const [core, components, coreDevice, effectiveDeployments] = await Promise.allSettled([
coreFuture,
installedComponentsFuture,
coreDeviceFuture,
effectiveDeploymentsFuture,
]);
logger.silly(`cores.service get: components:${JSON.stringify(components)}`);
logger.silly(`cores.service get: coreDevice:${JSON.stringify(coreDevice)}`);
logger.silly(
`cores.service get: effectiveDeployments:${JSON.stringify(effectiveDeployments)}`
);
const response = (core as PromiseFulfilledResult<CoreItem>).value;
if (response === undefined) {
return undefined;
}
response.device = {
installedComponents: [],
effectiveDeployments: [],
};
if (components.status === 'fulfilled') {
const ics = (
components as PromiseFulfilledResult<ListInstalledComponentsCommandOutput>
).value;
if ((ics?.installedComponents?.length ?? 0) > 0) {
for (const ic of ics.installedComponents) {
response.device.installedComponents.push({
name: ic.componentName,
version: ic.componentVersion,
// TODO: determine whether installed component matches what is on template or not
});
}
}
}
if (coreDevice.status === 'fulfilled') {
const cd = (coreDevice as PromiseFulfilledResult<GetCoreDeviceCommandOutput>).value;
const rd = response.device;
rd.coreVersion = cd.coreVersion;
rd.platform = cd.platform;
rd.architecture = cd.architecture;
rd.status = cd.status;
rd.lastStatusUpdateTimestamp = cd.lastStatusUpdateTimestamp;
rd.tags = cd.tags;
} else {
response.device.status = 'UNKNOWN';
}
if (effectiveDeployments.status === 'fulfilled') {
const eds = (
effectiveDeployments as PromiseFulfilledResult<ListEffectiveDeploymentsCommandOutput>
).value;
if ((eds?.effectiveDeployments?.length ?? 0) > 0) {
for (const ed of eds.effectiveDeployments) {
response.device.effectiveDeployments.push({
deploymentId: ed.deploymentId,
deploymentName: ed.deploymentName,
iotJobId: ed.iotJobId,
iotJobArn: ed.iotJobArn,
description: ed.description,
targetArn: ed.targetArn,
coreDeviceExecutionStatus: ed.coreDeviceExecutionStatus,
reason: ed.reason,
createdAt: ed.creationTimestamp,
updatedAt: ed.modifiedTimestamp,
});
}
}
}
logger.debug(`cores.service get: exit: ${JSON.stringify(response)}`);
return response;
}