use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.
the class LocalFileReader method scanReadables.
@Override
protected List<Readable> scanReadables() {
File file = FileUtils.getFile(this.source().path());
checkExistAndReadable(file);
FileFilter filter = this.source().filter();
List<Readable> files = new ArrayList<>();
if (file.isFile()) {
if (!filter.reserved(file.getName())) {
throw new LoadException("Please check file name and extensions, ensure " + "that at least one file is available for reading");
}
files.add(new LocalFile(file));
} else {
assert file.isDirectory();
File[] subFiles = file.listFiles();
if (subFiles == null) {
throw new LoadException("Error while listing the files of " + "path '%s'", file);
}
for (File subFile : subFiles) {
if (filter.reserved(subFile.getName())) {
files.add(new LocalFile(subFile));
}
}
}
return files;
}
use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.
the class ParquetFileLineFetcher method fetchNextPage.
private boolean fetchNextPage() {
try {
this.pages = this.reader.readNextRowGroup();
if (this.pages == null) {
return false;
}
} catch (IOException e) {
throw new LoadException("Failed to read next page for '%s'", e);
}
GroupRecordConverter converter = new GroupRecordConverter(this.schema);
this.recordReader = this.columnIO.getRecordReader(this.pages, converter);
this.pagesRowCount = this.pages.getRowCount();
this.currRowOffset = 0L;
return this.currRowOffset < this.pagesRowCount;
}
use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.
the class HugeClientHolder method create.
public static HugeClient create(LoadOptions options) {
boolean useHttps = options.protocol != null && options.protocol.equals(LoadOptions.HTTPS_SCHEMA);
String address = options.host + ":" + options.port;
if (!options.host.startsWith(Constants.HTTP_PREFIX) && !options.host.startsWith(Constants.HTTPS_PREFIX)) {
if (useHttps) {
address = Constants.HTTPS_PREFIX + address;
} else {
address = Constants.HTTP_PREFIX + address;
}
}
String username = options.username != null ? options.username : options.graph;
HugeClientBuilder builder;
try {
builder = HugeClient.builder(address, options.graph).configUser(username, options.token).configTimeout(options.timeout).configPool(options.maxConnections, options.maxConnectionsPerRoute);
if (useHttps) {
String trustFile;
if (options.trustStoreFile == null) {
String homePath = System.getProperty("loader.home.path");
E.checkArgument(StringUtils.isNotEmpty(homePath), "The system property 'loader.home.path' " + "can't be null or empty when enable " + "https protocol");
trustFile = Paths.get(homePath, Constants.TRUST_STORE_FILE).toString();
} else {
trustFile = options.trustStoreFile;
}
// Hard code: "hugegraph"
String token = options.trustStoreToken == null ? "hugegraph" : options.trustStoreToken;
builder.configSSL(trustFile, token);
}
return builder.build();
} catch (IllegalStateException e) {
String message = e.getMessage();
if (message != null && message.startsWith("The version")) {
throw new LoadException("The version of hugegraph-client and " + "hugegraph-server don't match", e);
}
throw e;
} catch (ServerException e) {
String message = e.getMessage();
if (Constants.STATUS_UNAUTHORIZED == e.status() || (message != null && message.startsWith("Authentication"))) {
throw new LoadException("Incorrect username or password", e);
}
throw e;
} catch (ClientException e) {
Throwable cause = e.getCause();
if (cause == null || cause.getMessage() == null) {
throw e;
}
String message = cause.getMessage();
if (message.contains("Connection refused")) {
throw new LoadException("The service %s:%s is unavailable", e, options.host, options.port);
} else if (message.contains("java.net.UnknownHostException") || message.contains("Host name may not be null")) {
throw new LoadException("The host %s is unknown", e, options.host);
} else if (message.contains("connect timed out")) {
throw new LoadException("Connect service %s:%s timeout, " + "please check service is available " + "and network is unobstructed", e, options.host, options.port);
}
throw e;
}
}
use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.
the class DBUtil method connect.
public void connect(String database) {
this.close();
String url = String.format("%s/%s?%s", this.url, database, "useSSL=false");
try {
Class.forName(this.driver);
this.conn = DriverManager.getConnection(url, this.user, this.pass);
} catch (ClassNotFoundException e) {
throw new LoadException("Invalid driver class '%s'", e, this.driver);
} catch (SQLException e) {
throw new LoadException("Failed to connect database via '%s'", e, this.url);
}
}
use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.
the class DBUtil method connect.
public void connect() {
try {
Class.forName(this.driver);
String url = String.format("%s?%s", this.url, "useSSL=false");
this.conn = DriverManager.getConnection(url, this.user, this.pass);
} catch (ClassNotFoundException e) {
throw new LoadException("Invalid driver class '%s'", e, this.driver);
} catch (SQLException e) {
throw new LoadException("Failed to connect database via '%s'", e, this.url);
}
}
Aggregations