diff --git a/src/main/java/io/floci/aws/services/cloudwatch/dashboards/CloudWatchDashboardsService.java b/src/main/java/io/floci/aws/services/cloudwatch/dashboards/CloudWatchDashboardsService.java
index ab528d1c49..7aec03206b 100644
--- a/src/main/java/io/floci/aws/services/cloudwatch/dashboards/CloudWatchDashboardsService.java
+++ b/src/main/java/io/floci/aws/services/cloudwatch/dashboards/CloudWatchDashboardsService.java
@@ -12,6 +12,8 @@ import io.floci.aws.core.common.AwsRegions;
import io.floci.aws.core.common.PaginatedResult;
import io.floci.aws.core.common.Pagination;
import io.floci.aws.core.common.RegionResolver;
+import io.floci.aws.core.storage.AccountAwareStorageBackend;
+import io.floci.aws.core.storage.AccountAwareStorageBackend.AccountEntry;
import io.floci.aws.core.storage.StorageBackend;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.cloudwatch.dashboards.model.Dashboard;
@@ -26,10 +28,20 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.TreeMap;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.regex.Pattern;
/**
* CloudWatch dashboards. Dashboards are pure metadata: the DashboardBody is an opaque JSON
* document that AWS stores and hands back verbatim, so there is no backing behaviour here.
+ *
+ *
Dashboards are global per account, as PutDashboard documents ("All dashboards in your account
+ * are global, not region-specific"), so they are keyed by name alone in the account's store and
+ * every Region of the account sees the same set. The Region a call arrives through only picks
+ * the partition of a new dashboard's ARN.
*/
@ApplicationScoped
public class CloudWatchDashboardsService {
@@ -41,6 +53,19 @@ public class CloudWatchDashboardsService {
/** AWS's documented ceiling for PutDashboard's Tags. */
private static final int MAX_TAGS = 50;
+ /** Separates the Region from the name in the keys dashboards were stored under before. */
+ private static final String LEGACY_SEPARATOR = "::";
+ // PutDashboard's DashboardName documentation: valid characters are A-Z, a-z, 0-9, "-", and "_".
+ private static final Pattern DASHBOARD_NAME = Pattern.compile("[A-Za-z0-9_-]+");
+
+ /**
+ * Orders the legacy copies of one name so the last is the one kept: the most recently
+ * modified, and on a tie the one whose key, so whose Region, sorts first.
+ */
+ private static final Comparator> LEGACY_WINNER_ORDER =
+ Comparator.>comparingLong(entry -> entry.getValue().getLastModified())
+ .thenComparing(Map.Entry::getKey, Comparator.reverseOrder());
+
private static final ObjectReader JSON = new ObjectMapper()
.enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
.readerFor(JsonNode.class);
@@ -53,6 +78,7 @@ public class CloudWatchDashboardsService {
this.dashboardStore = storageFactory.create("cloudwatchmetrics", "cwdashboards.json",
new TypeReference