Skip to content

Commit

Permalink
Change the output of validation tools to an object
Browse files Browse the repository at this point in the history
Cherry-pick of existing commit.
orig-pr: #12357
orig-commit: a7744e0
orig-commit-author: David Zhu <david@alluxio.com>

pr-link: #12428
change-id: cid-302eeacbab095fcc5ba85cdcfbdc52631ddb1699
  • Loading branch information
alluxio-bot committed Oct 30, 2020
1 parent 7ffd7d8 commit ece77c2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
40 changes: 40 additions & 0 deletions core/common/src/main/java/alluxio/cli/ValidationResults.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/

package alluxio.cli;

import java.util.List;
import java.util.Map;

/**
* A container class for the validation results.
*/
public class ValidationResults {
private Map<ValidationUtils.State, List<ValidationTaskResult>> mResult;

/**
* Set validation results.
*
* @param result validation result
*/
public void setResult(Map<ValidationUtils.State, List<ValidationTaskResult>> result) {
mResult = result;
}

/**
* Get Validation Result.
*
* @return validation result
*/
public Map<ValidationUtils.State, List<ValidationTaskResult>> getResult() {
return mResult;
}
}
8 changes: 5 additions & 3 deletions core/common/src/main/java/alluxio/cli/ValidationTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ public interface ValidationTool {
* @param results a result from a validation tool
* @return a map representing the result input
*/
static Map<ValidationUtils.State, List<ValidationTaskResult>> convertResults(
static ValidationResults convertResults(
List<ValidationTaskResult> results) {
// group by state
Map<ValidationUtils.State, List<ValidationTaskResult>> map = new HashMap<>();
results.forEach(r -> map.computeIfAbsent(r.getState(), k -> new ArrayList<>()).add(r));
return map;
ValidationResults finalResults = new ValidationResults();
finalResults.setResult(map);
return finalResults;
}

/**
Expand All @@ -57,7 +59,7 @@ static Map<ValidationUtils.State, List<ValidationTaskResult>> convertResults(
* @param map result stored in a map
* @return a string containing json representation of the result
*/
static String toJson(Map<ValidationUtils.State, List<ValidationTaskResult>> map) {
static String toJson(ValidationResults map) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
return gson.toJson(map);
}
Expand Down
5 changes: 1 addition & 4 deletions core/common/src/main/java/alluxio/cli/ValidationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ public static String getErrorInfo(Throwable t) {
* */
public static boolean isHdfsScheme(String path) {
String scheme = new AlluxioURI(path).getScheme();
if (scheme == null || !scheme.startsWith("hdfs")) {
return false;
}
return true;
return scheme != null && scheme.startsWith("hdfs");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ public static HmsValidationTool create(Map<Object, Object> configMap) {
.getOrDefault(ValidationConfig.DATABASE_CONFIG_NAME, DEFAULT_DATABASE);
tables = (String) configMap
.getOrDefault(ValidationConfig.TABLES_CONFIG_NAME, "");
socketTimeout = (int) configMap
.getOrDefault(ValidationConfig.SOCKET_TIMEOUT_CONFIG_NAME, DEFAULT_SOCKET_TIMEOUT);
socketTimeout = Integer.parseInt(configMap
.getOrDefault(ValidationConfig.SOCKET_TIMEOUT_CONFIG_NAME, DEFAULT_SOCKET_TIMEOUT)
.toString());
} catch (RuntimeException e) {
// Try not to throw exception on the construction function
// The hms validation tool itself should return failed message if the given config is invalid
Expand Down

0 comments on commit ece77c2

Please sign in to comment.