use of com.aws.greengrass.deployment.DeploymentService in project aws-greengrass-nucleus by aws-greengrass.
the class FleetStatusService method uploadFleetStatusServiceData.
private void uploadFleetStatusServiceData(Set<GreengrassService> greengrassServiceSet, OverallStatus overAllStatus, DeploymentInformation deploymentInformation) {
if (!isConnected.get()) {
logger.atDebug().log("Not updating fleet status data since MQTT connection is interrupted.");
return;
}
List<ComponentStatusDetails> components = new ArrayList<>();
long sequenceNumber;
synchronized (greengrassServiceSet) {
// If there are no Greengrass services to be updated, do not send an update.
if (greengrassServiceSet.isEmpty()) {
return;
}
// When a component version is bumped up, FSS may have pointers to both old and new service instances
// Filtering out the old version and only sending the update for the new version
Set<GreengrassService> filteredServices = new HashSet<>();
greengrassServiceSet.forEach(service -> {
try {
GreengrassService runningService = kernel.locate(service.getName());
filteredServices.add(runningService);
} catch (ServiceLoadException e) {
// not able to find service, service might be removed.
filteredServices.add(service);
}
});
Topics componentsToGroupsTopics = null;
HashSet<String> allGroups = new HashSet<>();
DeploymentService deploymentService = null;
try {
GreengrassService deploymentServiceLocateResult = this.kernel.locate(DeploymentService.DEPLOYMENT_SERVICE_TOPICS);
if (deploymentServiceLocateResult instanceof DeploymentService) {
deploymentService = (DeploymentService) deploymentServiceLocateResult;
componentsToGroupsTopics = deploymentService.getConfig().lookupTopics(COMPONENTS_TO_GROUPS_TOPICS);
}
} catch (ServiceLoadException e) {
logger.atError().cause(e).log("Unable to locate {} service while uploading FSS data", DeploymentService.DEPLOYMENT_SERVICE_TOPICS);
}
Topics finalComponentsToGroupsTopics = componentsToGroupsTopics;
DeploymentService finalDeploymentService = deploymentService;
filteredServices.forEach(service -> {
if (isSystemLevelService(service)) {
return;
}
List<String> componentGroups = new ArrayList<>();
if (finalComponentsToGroupsTopics != null) {
Topics groupsTopics = finalComponentsToGroupsTopics.findTopics(service.getName());
if (groupsTopics != null) {
groupsTopics.children.values().stream().map(n -> (Topic) n).map(Topic::getName).forEach(groupName -> {
componentGroups.add(groupName);
// Get all the group names from the user components.
allGroups.add(groupName);
});
}
}
Topic versionTopic = service.getServiceConfig().findLeafChild(KernelConfigResolver.VERSION_CONFIG_KEY);
ComponentStatusDetails componentStatusDetails = ComponentStatusDetails.builder().componentName(service.getName()).state(service.getState()).version(Coerce.toString(versionTopic)).fleetConfigArns(componentGroups).isRoot(finalDeploymentService.isComponentRoot(service.getName())).build();
components.add(componentStatusDetails);
});
filteredServices.forEach(service -> {
if (!isSystemLevelService(service)) {
return;
}
Topic versionTopic = service.getServiceConfig().findLeafChild(KernelConfigResolver.VERSION_CONFIG_KEY);
ComponentStatusDetails componentStatusDetails = ComponentStatusDetails.builder().componentName(service.getName()).state(service.getState()).version(Coerce.toString(versionTopic)).fleetConfigArns(new ArrayList<>(allGroups)).isRoot(// Set false for all system level services.
false).build();
components.add(componentStatusDetails);
});
greengrassServiceSet.clear();
Topic sequenceNumberTopic = getSequenceNumberTopic();
sequenceNumber = Coerce.toLong(sequenceNumberTopic);
sequenceNumberTopic.withValue(sequenceNumber + 1);
}
FleetStatusDetails fleetStatusDetails = FleetStatusDetails.builder().overallStatus(overAllStatus).architecture(this.architecture).platform(this.platform).thing(thingName).ggcVersion(deviceConfiguration.getNucleusVersion()).sequenceNumber(sequenceNumber).deploymentInformation(deploymentInformation).build();
publisher.publish(fleetStatusDetails, components);
logger.atInfo().event("fss-status-update-published").log("Status update published to FSS");
}
Aggregations