Skip to content

Commit

Permalink
coda format & clean tools(in Java & XML files)
Browse files Browse the repository at this point in the history
  • Loading branch information
returnToInnocence committed Mar 21, 2024
1 parent 76b0295 commit 83e216f
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public <R> R retry(Supplier<R> supplier, String description) {
} catch (Exception e) {
if (retries == this.retry) {
throw new ToolsException(
"Exception occurred while %s(after %s retries)",
e, description, this.retry);
"Exception occurred while %s(after %s retries)",
e, description, this.retry);
}
// Ignore exception and retry
continue;
Expand Down Expand Up @@ -89,7 +89,7 @@ public void shutdown(String taskType) {
this.pool.awaitTermination(24, TimeUnit.HOURS);
} catch (InterruptedException e) {
throw new ToolsException(
"Exception appears in %s threads", e, taskType);
"Exception appears in %s threads", e, taskType);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,27 @@ protected String graph() {
}

@SuppressWarnings("unchecked")
protected <T> List<T> readList(String key, Class<T> clazz,
String content) {
protected <T> List<T> readList(String key, Class<T> clazz,
String content) {
ObjectMapper mapper = this.client.mapper();
try {
JsonNode root = mapper.readTree(content);
JsonNode element = root.get(key);
if (element == null) {
throw new SerializeException(
"Can't find value of the key: %s in json.", key);
"Can't find value of the key: %s in json.", key);
} else {
JavaType t = mapper.getTypeFactory()
.constructParametricType(List.class, clazz);
return (List<T>) mapper.readValue(element.toString(), t);
}
} catch (IOException e) {
throw new SerializeException(
"Failed to deserialize %s", e, content);
"Failed to deserialize %s", e, content);
}
}

public void close () {
public void close() {
this.client.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public class HugeGraphCommand {

@ParametersDelegate
private SubCommands.TrustStoreFile trustStoreFile =
new SubCommands.TrustStoreFile();
new SubCommands.TrustStoreFile();

@ParametersDelegate
private SubCommands.TrustStorePassword trustStorePassword =
new SubCommands.TrustStorePassword();
new SubCommands.TrustStorePassword();

@ParametersDelegate
private SubCommands.ThrowMode throwMode = new SubCommands.ThrowMode();
Expand Down Expand Up @@ -397,7 +397,7 @@ private void execute(String subCmd, JCommander jCommander) {
break;
default:
throw new ParameterException(String.format(
"Invalid sub-command: %s", subCmd));
"Invalid sub-command: %s", subCmd));
}
}

Expand All @@ -417,30 +417,30 @@ private void checkMainParams() {
private <T extends ToolManager> T manager(Class<T> clz) {
try {
ToolClient.ConnectionInfo info = new ToolClient.ConnectionInfo(this.url(), this.graph(),
this.username(),
this.password(),
this.timeout(),
this.trustStoreFile(),
this.trustStorePassword());
this.username(),
this.password(),
this.timeout(),
this.trustStoreFile(),
this.trustStorePassword());
T toolManager = clz.getConstructor(ToolClient.ConnectionInfo.class)
.newInstance(info);
this.taskManagers.add(toolManager);
return toolManager;
} catch (Exception e) {
throw new RuntimeException(String.format(
"Construct manager failed for class '%s', please make " +
"sure global arguments set correctly: " +
"--url=%s,--graph=%s,--user=%s,--password=%s," +
"--timeout=%s,--trust-store-file=%s," +
"--trust-store-password=%s", clz.getSimpleName(),
this.url(), this.graph(), this.username(),
this.password(), this.timeout(),
this.trustStoreFile(), this.trustStorePassword()), e);
"Construct manager failed for class '%s', please make " +
"sure global arguments set correctly: " +
"--url=%s,--graph=%s,--user=%s,--password=%s," +
"--timeout=%s,--trust-store-file=%s," +
"--trust-store-password=%s", clz.getSimpleName(),
this.url(), this.graph(), this.username(),
this.password(), this.timeout(),
this.trustStoreFile(), this.trustStorePassword()), e);
}
}

private static SubCommands.Backup convMigrate2Backup(
SubCommands.Migrate migrate) {
SubCommands.Migrate migrate) {
SubCommands.Backup backup = new SubCommands.Backup();
backup.splitSize(migrate.splitSize());
backup.directory(migrate.directory());
Expand All @@ -452,8 +452,8 @@ private static SubCommands.Backup convMigrate2Backup(
}

private static SubCommands.Restore convMigrate2Restore(
SubCommands.Migrate migrate,
String directory) {
SubCommands.Migrate migrate,
String directory) {
SubCommands.Restore restore = new SubCommands.Restore();
restore.clean(!migrate.keepData());
restore.directory(directory);
Expand Down Expand Up @@ -488,7 +488,7 @@ public JCommander parseCommand(String[] args) {
String subCommand = jCommander.getParsedCommand();
if (subCommand == null) {
throw ExitException.normal(ToolUtil.commandsCategory(
jCommander),
jCommander),
"No sub-command found");
}
return jCommander;
Expand Down Expand Up @@ -518,7 +518,7 @@ public boolean parseHelp(String[] args, JCommander jCommander) {
Map<String, JCommander> commands = jCommander.getCommands();
if (commands.containsKey(subCommand)) {
throw ExitException.normal(ToolUtil.commandUsage(
commands.get(subCommand)),
commands.get(subCommand)),
"Command : hugegragh help %s",
subCommand);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public void properties(List<String> properties) {
"if needed. For example:" +
"-Dfs.default.name=hdfs://localhost:9000")
public static class Restore extends BackupRestore {

@Parameter(names = {"--clean"},
description = "Whether to remove the directory of " +
"graph data after restored")
Expand Down Expand Up @@ -412,10 +413,12 @@ public String cloneGraphName() {

@Parameters(commandDescription = "List all graphs")
public static class GraphList {

}

@Parameters(commandDescription = "Get graph info")
public static class GraphGet {

}

@Parameters(commandDescription = "Clear graph schema and data")
Expand Down Expand Up @@ -453,6 +456,7 @@ public GraphMode mode() {

@Parameters(commandDescription = "Get graph mode")
public static class GraphModeGet {

}

@Parameters(commandDescription = "Execute Gremlin statements")
Expand Down Expand Up @@ -621,10 +625,12 @@ public static class Clear {
@Parameters(commandDescription = "Stop HugeGraph-Server and " +
"HugeGraph-Studio")
public static class StopAll {

}

@Parameters(commandDescription = "Print usage")
public static class Help {

}

public static class BackupRestore {
Expand Down Expand Up @@ -962,6 +968,7 @@ public void hdfsConf(Map<String, String> hdfsConf) {
}

public static class AuthBackup extends AuthBackupRestore {

}

public static class AuthRestore extends AuthBackupRestore {
Expand Down Expand Up @@ -1017,7 +1024,7 @@ public static class AuthTypes {
}

public static class GraphModeConverter
implements IStringConverter<GraphMode> {
implements IStringConverter<GraphMode> {

@Override
public GraphMode convert(String value) {
Expand All @@ -1028,7 +1035,7 @@ public GraphMode convert(String value) {
}

public static class HugeTypeListConverter
implements IStringConverter<List<HugeType>> {
implements IStringConverter<List<HugeType>> {

public static final List<HugeType> ALL_TYPES = ImmutableList.of(
HugeType.PROPERTY_KEY, HugeType.VERTEX_LABEL,
Expand Down Expand Up @@ -1058,17 +1065,17 @@ public List<HugeType> convert(String value) {
hugeTypes.add(HugeType.valueOf(type.toUpperCase()));
} catch (IllegalArgumentException e) {
throw new ParameterException(String.format(
"Invalid --type '%s', valid value is 'all' or " +
"combination of 'vertex,edge,vertex_label," +
"edge_label,property_key,index_label'", type));
"Invalid --type '%s', valid value is 'all' or " +
"combination of 'vertex,edge,vertex_label," +
"edge_label,property_key,index_label'", type));
}
}
return hugeTypes;
}
}

public static class AuthHugeTypeConverter
implements IStringConverter<List<HugeType>> {
implements IStringConverter<List<HugeType>> {

public static final List<HugeType> AUTH_ALL_TYPES = ImmutableList.of(
HugeType.TARGET, HugeType.GROUP,
Expand Down Expand Up @@ -1101,20 +1108,20 @@ public List<HugeType> convert(String value) {
hugeTypes.add(HugeType.valueOf(type.toUpperCase()));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(String.format(
"Invalid --type '%s', valid value is 'all' or " +
"combination of [user,group,target," +
"belong,access]", type));
"Invalid --type '%s', valid value is 'all' or " +
"combination of [user,group,target," +
"belong,access]", type));
}
}
return hugeTypes;
}
}

public static class AuthStrategyConverter
implements IStringConverter<AuthRestoreConflictStrategy> {
implements IStringConverter<AuthRestoreConflictStrategy> {

public static final AuthRestoreConflictStrategy STRATEGY =
AuthRestoreConflictStrategy.STOP;
AuthRestoreConflictStrategy.STOP;

@Override
public AuthRestoreConflictStrategy convert(String value) {
Expand All @@ -1128,7 +1135,7 @@ public AuthRestoreConflictStrategy convert(String value) {
}

public static class MapConverter
implements IStringConverter<Map<String, String>> {
implements IStringConverter<Map<String, String>> {

@Override
public Map<String, String> convert(String value) {
Expand All @@ -1148,21 +1155,21 @@ public Map<String, String> convert(String value) {
}

public static class FileNameToContentConverter
implements IStringConverter<String> {
implements IStringConverter<String> {

@Override
public String convert(String value) {
File file = FileUtils.getFile(value);
if (!file.exists() || !file.isFile() || !file.canRead()) {
throw new ParameterException(String.format(
"'%s' must be existed readable file", value));
"'%s' must be existed readable file", value));
}
String content;
try {
content = FileUtils.readFileToString(file, API.CHARSET);
} catch (IOException e) {
throw new ParameterException(String.format(
"Read file '%s' error", value), e);
"Read file '%s' error", value), e);
}
return content;
}
Expand All @@ -1178,8 +1185,8 @@ public static class FormatValidator implements IParameterValidator {
public void validate(String name, String value) {
if (!FORMATS.contains(value.toUpperCase())) {
throw new ParameterException(String.format(
"Invalid --format '%s', valid value is %s",
value, FORMATS));
"Invalid --format '%s', valid value is %s",
value, FORMATS));
}
}
}
Expand All @@ -1194,8 +1201,8 @@ public static class ProtocolValidator implements IParameterValidator {
public void validate(String name, String value) {
if (!PROTOCOLS.contains(value.toUpperCase())) {
throw new ParameterException(String.format(
"Invalid --protocol '%s', valid value is %s",
value, PROTOCOLS));
"Invalid --protocol '%s', valid value is %s",
value, PROTOCOLS));
}
}
}
Expand All @@ -1206,8 +1213,8 @@ public static class TaskStatusValidator implements IParameterValidator {
public void validate(String name, String value) {
if (!TasksManager.TASK_STATUSES.contains(value.toUpperCase())) {
throw new ParameterException(String.format(
"Invalid --status '%s', valid value is %s",
value, TasksManager.TASK_STATUSES));
"Invalid --status '%s', valid value is %s",
value, TasksManager.TASK_STATUSES));
}
}
}
Expand All @@ -1227,7 +1234,7 @@ public void validate(String name, String value) {
":([0-9]|[1-9]\\d{1,3}|[1-5]\\d{4}|6[0-5]{2}[0-3][0-5])$";
if (!value.matches(regex)) {
throw new ParameterException(String.format(
"Invalid url value of args '%s': '%s'", name, value));
"Invalid url value of args '%s': '%s'", name, value));
}
}
}
Expand All @@ -1239,7 +1246,7 @@ public void validate(String name, String value) {
File file = new File(value);
if (!file.exists() || !file.isDirectory()) {
throw new ParameterException(String.format(
"Invalid value of argument '%s': '%s'", name, value));
"Invalid value of argument '%s': '%s'", name, value));
}
}
}
Expand All @@ -1251,8 +1258,8 @@ public void validate(String name, String value) {
int retry = Integer.parseInt(value);
if (retry <= 0) {
throw new ParameterException(
"Parameter " + name + " should be positive, " +
"but got " + value);
"Parameter " + name + " should be positive, " +
"but got " + value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ComputeSign {
private String inputEncoding;

public ComputeSign(String tradeValueFile, String inputEncode)
throws IOException {
throws IOException {

File file = new File(tradeValueFile);
Long fileLen = file.length();
Expand Down Expand Up @@ -65,7 +65,7 @@ protected boolean removeEldestEntry(Map.Entry<String, String> e) {
}

public synchronized String computeSeqNum(String entPlain)
throws UnsupportedEncodingException {
throws UnsupportedEncodingException {
String seqNum = "0";
if (entPlain2Id.containsKey(entPlain)) {
seqNum = entPlain2Id.get(entPlain);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public String dump(JsonGraph.JsonVertex vertex) throws Exception {
}

private String dumpEntity(JsonGraph.JsonVertex vertex)
throws UnsupportedEncodingException {
throws UnsupportedEncodingException {
if (vertex == null) {
return "";
}
Expand Down Expand Up @@ -113,7 +113,7 @@ private String dumpEntity(JsonGraph.JsonVertex vertex)
}

private String dumpMemtion(JsonGraph.JsonVertex vertex)
throws UnsupportedEncodingException {
throws UnsupportedEncodingException {
if (vertex == null) {
return "";
}
Expand Down
Loading

0 comments on commit 83e216f

Please sign in to comment.