From 6abc80af80a776163a90e39cd91a3c8f4ad24e86 Mon Sep 17 00:00:00 2001 From: "David W. Streever" Date: Wed, 11 Sep 2024 12:19:05 -0400 Subject: [PATCH] Add "Property Overrides" to Web Interface: https://github.com/cloudera-labs/hms-mirror/issues/111 --- pom.xml | 2 +- .../cli/HmsMirrorCommandLineOptions.java | 7 +- .../utils/hms/mirror/domain/Overrides.java | 43 ++++++-- .../hms/mirror/domain/support/SideType.java | 20 ++++ .../utils/hms/mirror/util/ModelUtils.java | 1 + .../web/controller/ConfigMVController.java | 40 +++++-- .../web/controller/ControllerReferences.java | 3 + src/main/resources/messages.properties | 1 + src/main/resources/static/css/pure.css | 2 +- .../fragments/config/propOverrides.html | 102 ++++++++++++++++++ .../templates/fragments/config/view.html | 10 +- 11 files changed, 205 insertions(+), 26 deletions(-) create mode 100644 src/main/java/com/cloudera/utils/hms/mirror/domain/support/SideType.java create mode 100644 src/main/resources/templates/fragments/config/propOverrides.html diff --git a/pom.xml b/pom.xml index df644ceb..df05a0a5 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ com.cloudera.utils.hadoop hms-mirror - 2.2.0.9.2 + 2.2.0.9.4 jar hms-mirror diff --git a/src/main/java/com/cloudera/utils/hms/mirror/cli/HmsMirrorCommandLineOptions.java b/src/main/java/com/cloudera/utils/hms/mirror/cli/HmsMirrorCommandLineOptions.java index 21b2bf25..a37e7255 100644 --- a/src/main/java/com/cloudera/utils/hms/mirror/cli/HmsMirrorCommandLineOptions.java +++ b/src/main/java/com/cloudera/utils/hms/mirror/cli/HmsMirrorCommandLineOptions.java @@ -18,7 +18,6 @@ package com.cloudera.utils.hms.mirror.cli; import com.cloudera.utils.hms.mirror.domain.HmsMirrorConfig; -import com.cloudera.utils.hms.mirror.domain.Overrides; import com.cloudera.utils.hms.mirror.domain.Warehouse; import com.cloudera.utils.hms.mirror.domain.support.*; import com.cloudera.utils.hms.mirror.reporting.ReportingConf; @@ -912,7 +911,7 @@ CommandLineRunner configPropertyOverrides(HmsMirrorConfig hmsMirrorConfig, @Valu log.info("property-overrides: {}", value); String[] overrides = value.split(","); if (nonNull(overrides)) - hmsMirrorConfig.getOptimization().getOverrides().setPropertyOverridesStr(overrides, Overrides.Side.BOTH); + hmsMirrorConfig.getOptimization().getOverrides().setPropertyOverridesStr(overrides, SideType.BOTH); }; } @@ -925,7 +924,7 @@ CommandLineRunner configPropertyOverridesLeft(HmsMirrorConfig hmsMirrorConfig, @ log.info("property-overrides-left: {}", value); String[] overrides = value.split(","); if (nonNull(overrides)) - hmsMirrorConfig.getOptimization().getOverrides().setPropertyOverridesStr(overrides, Overrides.Side.LEFT); + hmsMirrorConfig.getOptimization().getOverrides().setPropertyOverridesStr(overrides, SideType.LEFT); }; } @@ -938,7 +937,7 @@ CommandLineRunner configPropertyOverridesRight(HmsMirrorConfig hmsMirrorConfig, log.info("property-overrides-right: {}", value); String[] overrides = value.split(","); if (nonNull(overrides)) - hmsMirrorConfig.getOptimization().getOverrides().setPropertyOverridesStr(overrides, Overrides.Side.RIGHT); + hmsMirrorConfig.getOptimization().getOverrides().setPropertyOverridesStr(overrides, SideType.RIGHT); }; } diff --git a/src/main/java/com/cloudera/utils/hms/mirror/domain/Overrides.java b/src/main/java/com/cloudera/utils/hms/mirror/domain/Overrides.java index 55692e92..df13b019 100644 --- a/src/main/java/com/cloudera/utils/hms/mirror/domain/Overrides.java +++ b/src/main/java/com/cloudera/utils/hms/mirror/domain/Overrides.java @@ -17,6 +17,9 @@ package com.cloudera.utils.hms.mirror.domain; +import com.cloudera.utils.hms.mirror.domain.support.SideType; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -24,29 +27,49 @@ import java.util.Map; import java.util.TreeMap; -import static java.util.Objects.isNull; - @Slf4j @Getter @Setter +@JsonIgnoreProperties(ignoreUnknown = true) public class Overrides { - private Map left = null; + private Map> properties = new TreeMap>(); - private Map right = null; + public void addProperty(String key, String value, SideType side) { + if (!properties.containsKey(key)) { + properties.put(key, new TreeMap()); + } + properties.get(key).put(side, value); + } + @JsonIgnore public Map getLeft() { - if (isNull(left)) - left = new TreeMap(); + Map left = new TreeMap(); + for (Map.Entry> entry : properties.entrySet()) { + if (entry.getValue().containsKey(SideType.LEFT)) { + left.put(entry.getKey(), entry.getValue().get(SideType.LEFT)); + } + if (entry.getValue().containsKey(SideType.BOTH)) { + left.put(entry.getKey(), entry.getValue().get(SideType.BOTH)); + } + } return left; } + @JsonIgnore public Map getRight() { - if (isNull(right)) - right = new TreeMap(); + Map right = new TreeMap(); + for (Map.Entry> entry : properties.entrySet()) { + if (entry.getValue().containsKey(SideType.RIGHT)) { + right.put(entry.getKey(), entry.getValue().get(SideType.RIGHT)); + } + if (entry.getValue().containsKey(SideType.BOTH)) { + right.put(entry.getKey(), entry.getValue().get(SideType.BOTH)); + } + } return right; } - public void setPropertyOverridesStr(String[] inPropsStr, Side side) { + public void setPropertyOverridesStr(String[] inPropsStr, SideType side) { if (inPropsStr != null) { for (String property : inPropsStr) { try { @@ -72,6 +95,4 @@ public void setPropertyOverridesStr(String[] inPropsStr, Side side) { } } - public enum Side {BOTH, LEFT, RIGHT} - } diff --git a/src/main/java/com/cloudera/utils/hms/mirror/domain/support/SideType.java b/src/main/java/com/cloudera/utils/hms/mirror/domain/support/SideType.java new file mode 100644 index 00000000..4058eda1 --- /dev/null +++ b/src/main/java/com/cloudera/utils/hms/mirror/domain/support/SideType.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024. Cloudera, Inc. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.cloudera.utils.hms.mirror.domain.support; + +public enum SideType {BOTH, LEFT, RIGHT} diff --git a/src/main/java/com/cloudera/utils/hms/mirror/util/ModelUtils.java b/src/main/java/com/cloudera/utils/hms/mirror/util/ModelUtils.java index 9506331d..ae95be27 100644 --- a/src/main/java/com/cloudera/utils/hms/mirror/util/ModelUtils.java +++ b/src/main/java/com/cloudera/utils/hms/mirror/util/ModelUtils.java @@ -37,6 +37,7 @@ public static void allEnumsForMap(DataStrategyEnum dataStrategy, Map + + + + + Load Create + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyValueCluster Application
+ +
+ +
+ +
+ +
+ + + + + + + + + + + +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/fragments/config/view.html b/src/main/resources/templates/fragments/config/view.html index 2e8d3878..e910718e 100644 --- a/src/main/resources/templates/fragments/config/view.html +++ b/src/main/resources/templates/fragments/config/view.html @@ -115,6 +115,10 @@ +
  • + +
  • @@ -147,7 +151,6 @@ onclick="openSection(event, 'sources')"/>
  • - @@ -199,6 +202,11 @@ th:insert="fragments/config/cluster::main('RIGHT')"> +
    +
    + +
    +