All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openstreetmap.atlas.utilities.cli.operations.AbstractHDFSOperation Maven / Gradle / Ivy

There is a newer version: 7.0.8
Show newest version
package org.openstreetmap.atlas.utilities.cli.operations;

import java.util.Optional;

import org.openstreetmap.atlas.utilities.cli.operations.base.SSHOperation;

/**
 * Brings all of the common argument values for remote HDFS operations into a single superclass
 * along with permitting custom hadoop configuration settings
 *
 * @author cstaylor
 */
public abstract class AbstractHDFSOperation extends AbstractOperation
{
    private Optional customConfiguration;

    private Optional customHostname;

    protected AbstractHDFSOperation()
    {
        this.customConfiguration = Optional.empty();
        this.customHostname = Optional.empty();
    }

    public AbstractHDFSOperation withConfiguration(final String configuration)
    {
        this.customConfiguration = Optional.ofNullable(configuration);
        return this;
    }

    public AbstractHDFSOperation withCustomHostname(final String customHostname)
    {
        this.customHostname = Optional.ofNullable(customHostname);
        return this;
    }

    protected String preparePath(final String input)
    {
        if (input == null || input.startsWith("hdfs://"))
        {
            return input;
        }
        if (this.customHostname.isPresent())
        {
            return String.format("hdfs://%s%s", this.customHostname.get(), input);
        }
        return input;
    }

    protected SSHOperation prepareSSH()
    {
        final SSHOperation returnValue = this.ssh();
        returnValue.addArgs("hdfs");
        this.customConfiguration.ifPresent(configuration ->
        {
            returnValue.addArgs("--config", configuration);
        });
        returnValue.addArgs("dfs");
        return returnValue;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy