Skip to content

Commit

Permalink
Add "Property Overrides" to Web Interface: #111
Browse files Browse the repository at this point in the history
  • Loading branch information
dstreev committed Sep 11, 2024
1 parent aaa258f commit 6abc80a
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<groupId>com.cloudera.utils.hadoop</groupId>
<artifactId>hms-mirror</artifactId>
<version>2.2.0.9.2</version>
<version>2.2.0.9.4</version>
<packaging>jar</packaging>

<name>hms-mirror</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
};
}

Expand All @@ -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);
};
}

Expand All @@ -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);
};
}

Expand Down
43 changes: 32 additions & 11 deletions src/main/java/com/cloudera/utils/hms/mirror/domain/Overrides.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,59 @@

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;

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<String, String> left = null;
private Map<String, Map<SideType, String>> properties = new TreeMap<String, Map<SideType, String>>();

private Map<String, String> right = null;
public void addProperty(String key, String value, SideType side) {
if (!properties.containsKey(key)) {
properties.put(key, new TreeMap<SideType, String>());
}
properties.get(key).put(side, value);
}

@JsonIgnore
public Map<String, String> getLeft() {
if (isNull(left))
left = new TreeMap<String, String>();
Map<String, String> left = new TreeMap<String, String>();
for (Map.Entry<String, Map<SideType, String>> 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<String, String> getRight() {
if (isNull(right))
right = new TreeMap<String, String>();
Map<String, String> right = new TreeMap<String, String>();
for (Map.Entry<String, Map<SideType, String>> 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 {
Expand All @@ -72,6 +95,4 @@ public void setPropertyOverridesStr(String[] inPropsStr, Side side) {
}
}

public enum Side {BOTH, LEFT, RIGHT}

}
Original file line number Diff line number Diff line change
@@ -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}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static void allEnumsForMap(DataStrategyEnum dataStrategy, Map<String, Obj
enumForMap(com.cloudera.utils.hms.mirror.domain.support.TableType.class, map);
enumForMap(com.cloudera.utils.hms.mirror.domain.support.StageEnum.class, map);
enumForMap(com.cloudera.utils.hms.mirror.domain.support.CollectionEnum.class, map);
enumForMap(com.cloudera.utils.hms.mirror.domain.support.SideType.class, map);
enumForMap(com.cloudera.utils.hms.mirror.domain.support.DataStrategyEnum.class, map);
enumForMap(com.cloudera.utils.hms.mirror.domain.support.DistcpFlowEnum.class, map);
enumForMap(com.cloudera.utils.hms.mirror.domain.support.TranslationTypeEnum.class, map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

import com.cloudera.utils.hms.mirror.domain.HmsMirrorConfig;
import com.cloudera.utils.hms.mirror.domain.Translator;
import com.cloudera.utils.hms.mirror.domain.support.DataStrategyEnum;
import com.cloudera.utils.hms.mirror.domain.support.Environment;
import com.cloudera.utils.hms.mirror.domain.support.ExecuteSession;
import com.cloudera.utils.hms.mirror.domain.support.PersistContainer;
import com.cloudera.utils.hms.mirror.domain.support.*;
import com.cloudera.utils.hms.mirror.exceptions.EncryptionException;
import com.cloudera.utils.hms.mirror.exceptions.SessionException;
import com.cloudera.utils.hms.mirror.service.*;
Expand All @@ -33,11 +30,9 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.io.File;
import java.io.IOException;
import java.util.Set;
Expand Down Expand Up @@ -437,4 +432,33 @@ public String view(Model model,
return "config/view";
}

@RequestMapping(value = "/optimization/overrides/add", method = RequestMethod.POST)
public String addOverrideProperty(Model model,
@RequestParam(value = PROPERTY, required = true) String property,
@RequestParam(value = VALUE, required = true) String value,
@RequestParam(value = SIDE, required = true) SideType side) throws SessionException {
ExecuteSession session = executeSessionService.getSession();
HmsMirrorConfig config = session.getConfig();
config.getOptimization().getOverrides().addProperty(property, value, side);

return "redirect:/config/view";
}

@RequestMapping(value = "/optimization/overrides/{property}/{side}/delete", method = RequestMethod.GET)
public String deleteOverride(Model model,
@PathVariable @NotNull String property,
@PathVariable @NotNull SideType side) throws SessionException {
executeSessionService.closeSession();

ExecuteSession session = executeSessionService.getSession();
HmsMirrorConfig config = session.getConfig();
try {
config.getOptimization().getOverrides().getProperties().get(property).remove(side);
} catch (Exception e) {
log.error("Error deleting property: {}", e.getMessage());
}

return "redirect:/config/view";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@ public interface ControllerReferences {
String TABLE_TYPE = "TABLE_TYPE";
String SOURCE = "SOURCE";
String TARGET = "TARGET";
String PROPERTY = "PROPERTY";
String SIDE = "SIDE";
String VALUE = "VALUE";
}
1 change: 1 addition & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ config.translator=Translator
warehouse.plan.add=Add Warehouse Plan
warehouse.plans=Warehouse Plans
warehouse.plan=Warehouse Plan
property.overrides=Property Overrides
global.location.maps.user=User Global Location Maps
global.location.maps.user.empty=No User Global Location Maps Defined
global.location.maps.auto=Auto Built Global Location Maps
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/css/pure.css
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ since IE8 won't execute CSS that contains a CSS3 selector.
.pure-form textarea[disabled] {
cursor: not-allowed;
background-color: #eaeded;
color: #cad2d3;
color: #305868;
}

/*
Expand Down
102 changes: 102 additions & 0 deletions src/main/resources/templates/fragments/config/propOverrides.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!--
~ 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.
~
-->

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<head>
<title>Load Create</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" th:href="@{/css/pure.css}">
<link rel="stylesheet" type="text/css" th:href="@{/css/grids-responsive.css}">
<link rel="stylesheet" type="text/css" th:href="@{/css/base.css}">
<link rel="stylesheet" type="text/css" th:href="@{/css/tree.css}">
<link rel="stylesheet" type="text/css" th:href="@{/css/mirror.css}">
<link rel="stylesheet" type="text/css" th:href="@{/css/modal.css}">
</head>
<body>
<div th:fragment="view">
<form class="pure-form pure-form-aligned" id="propertyOptimizations">
<fieldset>
<legend th:text="#{property.overrides}"/>
<table class="pure-table">
<!-- th:if="${CONFIG.optimization.overrides.properties.size() > 0}"-->
<thead>
<tr>
<th></th>
<th>Property</th>
<th>Value</th>
<th>Cluster Application</th>
</tr>
</thead>
<tbody>
<th:block
th:each="property: ${CONFIG.optimization.overrides.properties}">
<th:block th:each="side: ${property.value}">

<tr>
<td>
<a class="pure-button"
th:href="@{/config/optimization/overrides/__${property.key}__/__${side.key}__/delete}"
th:text="#{delete}"/>
</td>
<td><input type="text" th:value="${property.key}" th:disabled="true"/></td>
<td><input type="text" th:value="${side.value}" th:disabled="true"/></td>
<td><input type="text" th:value="${side.key}" th:disabled="true"/></td>
</tr>
</th:block>
</th:block>
<tr>
<!-- Add form button to add new property -->
<!-- First field is the property, second is the value, and the third is the application (BOTH, LEFT, RIGHT) -->
<td>
<button class="pure-button"
th:formmethod="post"
th:formaction="@{/config/optimization/overrides/add}"
th:text="#{button.add}"/>
</td>
<td><input type="text" id="property" name="PROPERTY"/></td>
<td><input type="text" id="value" name="VALUE"/></td>
<td>
<div class="pure-control-group">
<select id="side" name="SIDE">
<option th:each="side: ${sidetypes}"
th:value="${side}"
th:text="${side}"
th:selected="${side.equals('BOTH')}"/>
</select>
</div>

</td>
</tr>
</tbody>
</table>
<!-- </div>-->
<!-- </div>-->
<!-- <div class="pure-control-group">-->
<!-- <a id="whModalBtn" class="pure-button pure-button-primary"-->
<!-- th:if="${('UNDETERMINED WAREHOUSE_PLANS').contains(CONFIG.getDatabaseFilterType().toString())}"-->
<!-- th:href="@{/warehouse/plan/add}"-->
<!-- th:text="#{button.add}"/>-->
<!-- &lt;!&ndash; th:formmethod="get"&ndash;&gt;-->
<!-- </div>-->
<!-- <div th:replace="fragments/modal::modal1('whAddModal', 'whModalBtn', 'Please wait. Gathering database list.')">-->
<!-- </div>-->
</fieldset>
</form>
</div>
</body>
</html>
10 changes: 9 additions & 1 deletion src/main/resources/templates/fragments/config/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
<a th:text="#{optimizations}" href="#" class="pure-menu-link"
onclick="openSection(event, 'optimizations')"/>
</li>
<li class="pure-menu-item">
<a th:text="#{property.overrides}" href="#" class="pure-menu-link"
onclick="openSection(event, 'propertyOverrides')"/>
</li>
</ul>
</li>
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover no-border">
Expand Down Expand Up @@ -147,7 +151,6 @@
onclick="openSection(event, 'sources')"/>
</li>
</ul>

</li>
<!-- <li class="pure-menu-item no-border">-->
<!-- <a th:text="#{password.management}" href="#" class="pure-menu-link"-->
Expand Down Expand Up @@ -199,6 +202,11 @@
th:insert="fragments/config/cluster::main('RIGHT')">
</div>
</form>
<div id="propertyOverrides" class="tabcontent">
<div th:insert="fragments/config/propOverrides::view">

</div>
</div>
<div id="glmBuild" class="tabcontent">
<div th:insert="fragments/config/glmBuild::view">

Expand Down

0 comments on commit 6abc80a

Please sign in to comment.