Skip to content

Commit

Permalink
Update support information for extension descriptors
Browse files Browse the repository at this point in the history
In support of quarkusio#8021, process the supported-by attribute to find a supporter name, then create or update an attribute with the supporter id, name with the status(es) for the extension supporter.  If there are existing tags ending with `-support`, a support entry will be created / updated for the supporter(s).  If any
of the support entries are missing a status, the default value of `stable` will be used.

Signed-off-by:Nathan Erwin <[email protected]>
  • Loading branch information
nderwin committed Oct 10, 2023
1 parent 6b6b4a6 commit 3cdba66
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -145,30 +147,55 @@ public static Map<String, Collection<String>> getSyntheticMetadata(Extension ext
if (getMetadataValue(extension, "status").isEmpty()) {
extendedMetadata.put("status", "stable");
}

// existing support metadata
@SuppressWarnings("unchecked")
final Collection<String> supporters = (Collection<String>) extendedMetadata.getOrDefault("supported-by",
new ArrayList<String>());
final Map<String, Object> supportStatuses = extendedMetadata.entrySet().stream()
.filter(e -> e.getKey().endsWith("-support"))
.collect(Collectors.toMap(
k -> k.getKey(),
v -> v.getValue()));

supportStatuses.entrySet().forEach((e) -> {
String supporter = e.getKey().replace("-support", "");

if (!supporters.contains(supporter)) {
supporters.add(supporter);
}
});
extendedMetadata.put("supported-by", supporters);

for (String s : supporters) {
if (!supportStatuses.keySet().contains(s + "-support")) {
supportStatuses.put(s + "-support", "stable");
}
}
extendedMetadata.putAll(supportStatuses);
final Collection<Map<String, Object>> supportList = (Collection<Map<String, Object>>) extendedMetadata
.getOrDefault("support", new ArrayList<>());

/*
* map legacy style
*
* x-support: stable
* y-support:
* - stable
*
* to
*
* support:
* - id: x
* status: [stable]
* - id: y
* status: [stable]
*/
final List<Map<String, Object>> supportStatuses = extendedMetadata.entrySet().stream()
.filter(entry -> entry.getKey().endsWith("-support"))
.map((entry) -> {
final Map<String, Object> supporter = new LinkedHashMap<>();

supporter.put("id", entry.getKey().replace("-support", ""));

if (entry.getValue() instanceof List) {
supporter.put("status", entry.getValue());
} else {
supporter.put("status", Arrays.asList(entry.getValue()));
}

return supporter;
})
.collect(Collectors.toList());

// merge them together - do we need to worry about duplicates?
supportList.addAll(supportStatuses);

// make sure we have a default status for each supporter
supportList.stream()
.filter((map) -> !map.containsKey("status"))
.forEach((map) -> {
map.put("status", Arrays.asList("stable"));
});

extendedMetadata.put("support", supportList);

return extendedMetadata.entrySet().stream()
.map(e -> new AbstractMap.SimpleImmutableEntry<>(e.getKey(), (new MetadataValue(e.getValue()).asStringList())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;

final class MetadataValue {
private static final MetadataValue EMPTY_METADATA_VALUE = new MetadataValue(null);
Expand Down Expand Up @@ -59,6 +60,14 @@ public List<String> asStringList() {
} else if (val instanceof List && !((List<?>) val).isEmpty()
&& ((List<?>) val).get(0) instanceof String) {
return (List<String>) val;
} else if (val instanceof List && !((List<?>) val).isEmpty()
&& ((List<?>) val).get(0) instanceof Map) {
return ((List<Map>) val).stream()
.map((entry) -> {
// crude, but effective
return entry.toString();
})
.collect(Collectors.toList());
}
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

import org.junit.jupiter.api.Test;
Expand All @@ -20,8 +21,7 @@ public void testNoSupportData() throws Exception {
.fromFile(Path.of(ExtensionProcessorTest.class.getResource("/resteasy-extension.yaml").toURI()));
Map<String, Collection<String>> metadata = ExtensionProcessor.getSyntheticMetadata(extension);

assertFalse(metadata.keySet().contains("supported-by"));
assertFalse(metadata.keySet().stream().anyMatch((k) -> k.endsWith("-support")));
assertFalse(metadata.keySet().contains("support"));
}

@Test
Expand All @@ -30,8 +30,10 @@ public void testFullSupportData() throws Exception {
.fromFile(Path.of(ExtensionProcessorTest.class.getResource("/rest-client-mutiny-extension.yaml").toURI()));
Map<String, Collection<String>> metadata = ExtensionProcessor.getSyntheticMetadata(extension);

assertEquals(Arrays.asList("xyz"), metadata.get("supported-by"));
assertEquals(Arrays.asList("techpreview", "deprecated"), metadata.get("xyz-support"));
assertTrue(metadata.keySet().contains("support"));
String supporter = metadata.get("support").iterator().next();
assertTrue(supporter.contains("id=xyz"));
assertTrue(supporter.contains("status=[techpreview, deprecated]"));
}

@Test
Expand All @@ -40,8 +42,10 @@ public void testLegacySupportData() throws Exception {
.fromFile(Path.of(ExtensionProcessorTest.class.getResource("/agroal-extension.yaml").toURI()));
Map<String, Collection<String>> metadata = ExtensionProcessor.getSyntheticMetadata(extension);

assertEquals(Arrays.asList("redhat"), metadata.get("supported-by"));
assertEquals(Arrays.asList("stable"), metadata.get("redhat-support"));
assertTrue(metadata.keySet().contains("support"));
String supporter = metadata.get("support").iterator().next();
assertTrue(supporter.contains("id=redhat"));
assertTrue(supporter.contains("status=[stable]"));
}

@Test
Expand All @@ -50,9 +54,16 @@ public void testComplexSupportData() throws Exception {
.fromFile(Path.of(ExtensionProcessorTest.class.getResource("/datasource-extension.yaml").toURI()));
Map<String, Collection<String>> metadata = ExtensionProcessor.getSyntheticMetadata(extension);

assertEquals(Arrays.asList("Red Hat", "xyz"), metadata.get("supported-by"));
assertEquals(Arrays.asList("stable", "awesome"), metadata.get("Red Hat-support"));
assertEquals(Arrays.asList("none"), metadata.get("xyz-support"));
assertTrue(metadata.keySet().contains("support"));
Collection<String> supporters = metadata.get("support");
assertEquals(2, supporters.size());
Iterator<String> it = supporters.iterator();
String supporter1 = it.next();
String supporter2 = it.next();
assertTrue(supporter1.contains("name=Red Hat"));
assertTrue(supporter1.contains("status=[stable, awesome]"));
assertTrue(supporter2.contains("id=xyz"));
assertTrue(supporter2.contains("status=[none]"));
}

@Test
Expand All @@ -61,9 +72,16 @@ public void testSupporterWithoutStatus() throws Exception {
.fromFile(Path.of(ExtensionProcessorTest.class.getResource("/flyway-extension.yaml").toURI()));
Map<String, Collection<String>> metadata = ExtensionProcessor.getSyntheticMetadata(extension);

assertEquals(Arrays.asList("xyz", "abc"), metadata.get("supported-by"));
assertEquals(Arrays.asList("stable"), metadata.get("xyz-support"));
assertEquals(Arrays.asList("stable"), metadata.get("abc-support"));
assertTrue(metadata.keySet().contains("support"));
Collection<String> supporters = metadata.get("support");
assertEquals(2, supporters.size());
Iterator<String> it = supporters.iterator();
String supporter1 = it.next();
String supporter2 = it.next();
assertTrue(supporter1.contains("id=xyz"));
assertTrue(supporter1.contains("status=[stable]"));
assertTrue(supporter2.contains("id=abc"));
assertTrue(supporter2.contains("status=[stable]"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ metadata:
categories:
- "data"
status: "stable"
redhat-support: "stable"
support:
- id: redhat
status:
- stable
config:
- "quarkus.datasource."
built-with-quarkus-core: "999-SNAPSHOT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ metadata:
status: "stable"
supported-by:
- "Red Hat"
Red Hat-support:
- "stable"
- "awesome"
support:
- id: redhat
name: Red Hat
status:
- stable
- awesome
xyz-support:
- "none"
unlisted: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ metadata:
categories:
- "data"
status: "stable"
supported-by:
- "xyz"
- "abc"
support:
- id: xyz
name: Xyz Co.
- id: abc
name: Abc, LLC
config:
- "quarkus.flyway."
built-with-quarkus-core: "999-SNAPSHOT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ metadata:
- "web"
- "reactive"
status: "deprecated"
supported-by:
- "xyz"
xyz-support:
- "techpreview"
- "deprecated"
support:
- id: xyz
name: Xyz
status: [techpreview, deprecated]
built-with-quarkus-core: "999-SNAPSHOT"
extension-dependencies:
- "io.quarkus:quarkus-rest-client"
Expand Down

0 comments on commit 3cdba66

Please sign in to comment.