Skip to content

Commit

Permalink
fix: resolve confict and improve common version
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxxoo committed Jan 11, 2022
1 parent 6d47fd2 commit 697e0de
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.apache.tinkerpop.gremlin.server.auth.AuthenticationException;
import org.apache.tinkerpop.gremlin.server.util.MetricManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.RateLimiter;

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.structure.*;
import org.apache.tinkerpop.gremlin.structure.io.Io;
import org.apache.tinkerpop.gremlin.structure.util.AbstractThreadLocalTransaction;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import org.slf4j.Logger;

/**
* StandardHugeGraph is the entrance of the graph system, you can modify or
* query the schema/vertex/edge data through this class.
Expand Down Expand Up @@ -947,7 +940,6 @@ public void drop() {
@Override
public HugeConfig cloneConfig(String newGraph) {
HugeConfig config = (HugeConfig) this.configuration().clone();
config.setDelimiterParsingDisabled(true);
this.storeProvider.onCloneConfig(config, newGraph);
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import java.util.concurrent.Callable;

import javax.security.sasl.AuthenticationException;
import javax.ws.rs.ForbiddenException;

import jakarta.ws.rs.ForbiddenException;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Map;

import javax.crypto.SecretKey;
import javax.ws.rs.NotAuthorizedException;
import jakarta.ws.rs.NotAuthorizedException;

import com.baidu.hugegraph.config.AuthOptions;
import com.baidu.hugegraph.config.HugeConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
import java.util.function.Consumer;
import java.util.function.Function;

import javax.ws.rs.ForbiddenException;

import jakarta.ws.rs.ForbiddenException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Element;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.List;
import java.util.Map;

import javax.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.MultivaluedMap;

import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import javax.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.MultivaluedMap;

import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.util.Map;
import java.util.Set;

import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap;

import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.tinkerpop.gremlin.structure.Edge;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap;

import org.apache.commons.collections.CollectionUtils;
import org.apache.tinkerpop.gremlin.structure.Edge;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Map;
import java.util.Set;

import javax.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.MultivaluedMap;

import org.apache.tinkerpop.gremlin.structure.Edge;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Map;
import java.util.Set;

import javax.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.MultivaluedMap;

import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Set;
import java.util.function.BiConsumer;

import javax.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.MultivaluedMap;

import com.baidu.hugegraph.HugeGraph;
import com.baidu.hugegraph.backend.id.Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,34 @@

package com.baidu.hugegraph.util;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.CharArrayReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.StringReader;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.tree.ConfigurationNode;
import org.apache.commons.configuration2.FileBasedConfiguration;
import org.apache.commons.configuration2.HierarchicalConfiguration;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.YAMLConfiguration;
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
import org.apache.commons.configuration2.builder.fluent.Configurations;
import org.apache.commons.configuration2.builder.fluent.Parameters;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.configuration2.tree.ImmutableNode;
import org.apache.commons.configuration2.tree.NodeHandler;
import org.apache.commons.configuration2.tree.NodeModel;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.tinkerpop.gremlin.util.config.YamlConfiguration;
import org.apache.logging.log4j.core.config.yaml.YamlConfiguration;
import org.slf4j.Logger;

import com.baidu.hugegraph.HugeException;
Expand All @@ -50,24 +62,35 @@ public final class ConfigUtil {
private static final String CHARSET = "UTF-8";

public static void checkGremlinConfig(String conf) {
YamlConfiguration yamlConfig = new YamlConfiguration();
Parameters params = new Parameters();
try {
yamlConfig.load(conf);

FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
new FileBasedConfigurationBuilder(YAMLConfiguration.class)
.configure(params.fileBased().setFileName(conf));
YAMLConfiguration config = (YAMLConfiguration) builder
.getConfiguration();

List<HierarchicalConfiguration<ImmutableNode>> nodes =
config.childConfigurationsAt(
NODE_GRAPHS);
E.checkArgument(nodes == null || nodes.size() == 1,
"Not allowed to specify multiple '%s' nodes in " +
"config file '%s'", NODE_GRAPHS, conf);

ImmutableNode root = null;
NodeModel<ImmutableNode> nodeModel = null;
NodeHandler<ImmutableNode> nodeHandler = null;
for (HierarchicalConfiguration<ImmutableNode> node : nodes) {
E.checkArgument((nodeModel = node.getNodeModel()) != null
&& (nodeHandler = nodeModel.getNodeHandler()) != null
&& (root = nodeHandler.getRootNode()) != null,
"Node '%s' must contain root", node);
}
} catch (ConfigurationException e) {
throw new HugeException("Failed to load yaml config file '%s'",
conf);
}
List<ConfigurationNode> nodes = yamlConfig.getRootNode()
.getChildren(NODE_GRAPHS);
E.checkArgument(nodes == null || nodes.size() == 1,
"Not allowed to specify multiple '%s' nodes in " +
"config file '%s'", NODE_GRAPHS, conf);
if (nodes != null) {
List<ConfigurationNode> graphNames = nodes.get(0).getChildren();
E.checkArgument(graphNames.isEmpty(),
"Don't allow to fill value for '%s' node in " +
"config file '%s'", NODE_GRAPHS, conf);
}
}

public static Map<String, String> scanGraphsDir(String graphsDirPath) {
Expand Down Expand Up @@ -96,18 +119,17 @@ public static void writeToFile(String dir, String graphName,
E.checkArgument(FileUtils.getFile(dir).exists(),
"The directory '%s' must exist", dir);
String fileName = Paths.get(dir, graphName + CONF_SUFFIX).toString();
try (OutputStream os = new FileOutputStream(fileName)) {
config.save(os, CHARSET);
config.setFileName(fileName);
try {
config.save(new File(fileName));
LOG.info("Write HugeConfig to file: '{}'", fileName);
} catch (IOException | ConfigurationException e) {
} catch (ConfigurationException e) {
throw new HugeException("Failed to write HugeConfig to file '%s'",
e, fileName);
e, fileName);
}
}

public static void deleteFile(File file) {
if (!file.exists()) {
if (file == null || !file.exists()) {
return;
}
try {
Expand All @@ -123,10 +145,8 @@ public static PropertiesConfiguration buildConfig(String configText) {
"The config text can't be null or empty");
PropertiesConfiguration propConfig = new PropertiesConfiguration();
try {
InputStream in = new ByteArrayInputStream(configText.getBytes(
CHARSET));
propConfig.setDelimiterParsingDisabled(true);
propConfig.load(in);
Reader in = new StringReader(configText);
propConfig.read(in);
} catch (Exception e) {
throw new IllegalStateException("Failed to read config options", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,6 @@ public static void main(String[] args) throws Exception {
RegisterUtil.registerPlugins();
RegisterUtil.registerServer();

Parameters params = new Parameters();
FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
new FileBasedConfigurationBuilder(YAMLConfiguration.class).
configure(params.fileBased().setFileName(gremlinConfFile));
YAMLConfiguration config = (YAMLConfiguration) builder.getConfiguration();

// List<HierarchicalConfiguration<ImmutableNode>> nodes =
// config.childConfigurationsAt(GRAPHS);
// E.checkArgument(nodes.size() >= 1,
// "Must contain one '%s' node in config file '%s'",
// GRAPHS, gremlinConfFile);
//
// ImmutableNode root = null;
// NodeModel<ImmutableNode> nodeModel = null;
// NodeHandler<ImmutableNode> nodeHandler = null;
// for (HierarchicalConfiguration<ImmutableNode> node : nodes) {
// E.checkArgument((nodeModel = node.getNodeModel()) != null
// && (nodeHandler = nodeModel.getNodeHandler()) != null
// && (root = nodeHandler.getRootNode()) != null,
// "Node '%s' must contain root", node);
// HugeFactory.checkGraphName(root.getNodeName(), "gremlin-server.yaml");
// String configPath = root.getValue().toString();
// initGraph(configPath);
// }

HugeConfig restServerConfig = new HugeConfig(restConf);
String graphsDir = restServerConfig.get(ServerOptions.GRAPHS);
Map<String, String> graphs = ConfigUtil.scanGraphsDir(graphsDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

import java.util.Map;

import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;

import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.rest.AbstractRestClient;
import com.baidu.hugegraph.rest.RestClient;
import com.google.common.collect.ImmutableMap;
import jakarta.ws.rs.core.Response;

public class PaloHttpClient {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public FakeObjects() {
}

public static HugeConfig newConfig() {
Configuration conf = Mockito.mock(PropertiesConfiguration.class);
Mockito.when(conf.getKeys()).thenReturn(Collections.emptyIterator());
Configuration conf = new PropertiesConfiguration();
return new HugeConfig(conf);
}

Expand Down
Loading

0 comments on commit 697e0de

Please sign in to comment.