Search in sources :

Example 26 with LoadException

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;
}
Also used : ArrayList(java.util.ArrayList) Readable(com.baidu.hugegraph.loader.reader.Readable) FileFilter(com.baidu.hugegraph.loader.source.file.FileFilter) File(java.io.File) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Example 27 with LoadException

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;
}
Also used : GroupRecordConverter(org.apache.parquet.example.data.simple.convert.GroupRecordConverter) IOException(java.io.IOException) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Example 28 with LoadException

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;
    }
}
Also used : ServerException(com.baidu.hugegraph.exception.ServerException) ClientException(com.baidu.hugegraph.rest.ClientException) HugeClientBuilder(com.baidu.hugegraph.driver.HugeClientBuilder) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Example 29 with LoadException

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);
    }
}
Also used : SQLException(java.sql.SQLException) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Example 30 with LoadException

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);
    }
}
Also used : SQLException(java.sql.SQLException) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Aggregations

LoadException (com.baidu.hugegraph.loader.exception.LoadException)32 IOException (java.io.IOException)18 File (java.io.File)10 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 FileFilter (com.baidu.hugegraph.loader.source.file.FileFilter)3 Path (org.apache.hadoop.fs.Path)3 ServerException (com.baidu.hugegraph.exception.ServerException)2 InitException (com.baidu.hugegraph.loader.exception.InitException)2 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)2 LoadSummary (com.baidu.hugegraph.loader.metrics.LoadSummary)2 Readable (com.baidu.hugegraph.loader.reader.Readable)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 CompressorInputStream (org.apache.commons.compress.compressors.CompressorInputStream)2 CompressionInputStream (org.apache.hadoop.io.compress.CompressionInputStream)2 HugeClient (com.baidu.hugegraph.driver.HugeClient)1 HugeClientBuilder (com.baidu.hugegraph.driver.HugeClientBuilder)1 GroovyExecutor (com.baidu.hugegraph.loader.executor.GroovyExecutor)1 InputStruct (com.baidu.hugegraph.loader.mapping.InputStruct)1