Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove extra nesting for hostAddresses config #224

Merged
merged 3 commits into from Mar 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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