|
5 | 5 |
|
6 | 6 | package com.aws.greengrass.device;
|
7 | 7 |
|
| 8 | +import com.aws.greengrass.config.Node; |
8 | 9 | import com.aws.greengrass.config.Topics;
|
| 10 | +import com.aws.greengrass.config.WhatHappened; |
9 | 11 | import com.aws.greengrass.dependency.ImplementsService;
|
| 12 | +import com.aws.greengrass.device.configuration.GroupConfiguration; |
| 13 | +import com.aws.greengrass.device.configuration.GroupManager; |
10 | 14 | import com.aws.greengrass.lifecyclemanager.PluginService;
|
| 15 | +import com.fasterxml.jackson.databind.MapperFeature; |
| 16 | +import com.fasterxml.jackson.databind.ObjectMapper; |
11 | 17 |
|
12 | 18 | import javax.inject.Inject;
|
13 | 19 |
|
| 20 | +import static com.aws.greengrass.componentmanager.KernelConfigResolver.CONFIGURATION_CONFIG_KEY; |
| 21 | + |
14 | 22 | @ImplementsService(name = DeviceSupportService.DEVICE_SUPPORT_SERVICE_NAME)
|
| 23 | +@SuppressWarnings("PMD.UnusedPrivateField") |
15 | 24 | public class DeviceSupportService extends PluginService {
|
16 | 25 | public static final String DEVICE_SUPPORT_SERVICE_NAME = "aws.greengrass.DeviceSupport";
|
| 26 | + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper() |
| 27 | + .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); |
| 28 | + |
| 29 | + private final GroupManager groupManager; |
| 30 | + |
| 31 | + private final SessionManager sessionManager; |
| 32 | + |
| 33 | + private final Topics configurationTopics; |
17 | 34 |
|
18 | 35 | /**
|
19 | 36 | * Constructor.
|
20 | 37 | *
|
21 |
| - * @param topics Root Configuration topic for this service |
| 38 | + * @param topics Root Configuration topic for this service |
| 39 | + * @param groupManager Group configuration management |
| 40 | + * @param sessionManager Session management |
22 | 41 | */
|
23 | 42 | @Inject
|
24 |
| - public DeviceSupportService(Topics topics) { |
| 43 | + public DeviceSupportService(Topics topics, GroupManager groupManager, SessionManager sessionManager) { |
25 | 44 | super(topics);
|
| 45 | + this.groupManager = groupManager; |
| 46 | + this.sessionManager = sessionManager; |
| 47 | + |
| 48 | + //handleConfiguration |
| 49 | + this.configurationTopics = topics.lookupTopics(CONFIGURATION_CONFIG_KEY); |
| 50 | + this.configurationTopics.subscribe(this::handleConfigurationChange); |
| 51 | + } |
| 52 | + |
| 53 | + @SuppressWarnings("PMD.UnusedFormalParameter") |
| 54 | + private void handleConfigurationChange(WhatHappened whatHappened, Node childNode) { |
| 55 | + try { |
| 56 | + groupManager.setGroupConfiguration( |
| 57 | + OBJECT_MAPPER.convertValue(configurationTopics.toPOJO(), GroupConfiguration.class)); |
| 58 | + } catch (IllegalArgumentException e) { |
| 59 | + logger.atError().kv("service", DEVICE_SUPPORT_SERVICE_NAME).kv("event", whatHappened) |
| 60 | + .kv("node", configurationTopics.getFullName()).kv("value", configurationTopics).setCause(e) |
| 61 | + .log("Unable to parse group configuration"); |
| 62 | + } |
26 | 63 | }
|
27 | 64 | }
|
0 commit comments