Skip to content

Commit

Permalink
fix: store hostAddresses properly (#224)
Browse files Browse the repository at this point in the history
store hostAddresses in runtime config without extra nesting
  • Loading branch information
jcosentino11 authored and MikeDombo committed Mar 3, 2023
1 parent 193bbf6 commit 7e1348f
Showing 1 changed file with 7 additions and 19 deletions.
Expand Up @@ -11,7 +11,6 @@
import com.aws.greengrass.config.Node;
import com.aws.greengrass.config.Topic;
import com.aws.greengrass.config.Topics;
import com.aws.greengrass.config.UpdateBehaviorTree;
import com.aws.greengrass.util.Coerce;
import lombok.NonNull;

Expand Down Expand Up @@ -265,14 +264,8 @@ public Stream<CertificateV1DTO> getAllCertificatesV1() {
* @param hostAddresses host addresses
*/
public void putHostAddressForSource(String source, Set<HostAddress> hostAddresses) {
Map<String, Object> hostAddressesToMerge = new HashMap<>();
hostAddressesToMerge.put(
source,
hostAddresses.stream().map(HostAddress::getHost).collect(Collectors.toList()));
config.lookupTopics(HOST_ADDRESSES_KEY, source)
.updateFromMap(hostAddressesToMerge,
new UpdateBehaviorTree(UpdateBehaviorTree.UpdateBehavior.REPLACE,
System.currentTimeMillis()));
config.lookup(HOST_ADDRESSES_KEY, source)
.withValue(hostAddresses.stream().map(HostAddress::getHost).collect(Collectors.toList()));
}

/**
Expand All @@ -287,20 +280,15 @@ public Set<HostAddress> getAggregatedHostAddresses() {
}

Set<HostAddress> connectivityInfo = new HashSet<>();
for (Object addrsBySource : hostAddressesTopics.toPOJO().values()) {
if (!(addrsBySource instanceof Map)) {
for (Object addrs : hostAddressesTopics.toPOJO().values()) {
if (!(addrs instanceof Collection)) {
continue;
}
for (Object addrs : ((Map<?,?>) addrsBySource).values()) {
if (!(addrs instanceof Collection)) {
for (Object addr : (Collection<?>) addrs) {
if (!(addr instanceof String)) {
continue;
}
for (Object addr : (Collection<?>) addrs) {
if (!(addr instanceof String)) {
continue;
}
connectivityInfo.add(HostAddress.of((String) addr));
}
connectivityInfo.add(HostAddress.of((String) addr));
}
}
return connectivityInfo;
Expand Down

0 comments on commit 7e1348f

Please sign in to comment.