Exemplo n.º 1
0
void HdfsFile::configure(base::ConfigurationMap &conf) {
    GET_PARAMETER(hdfsConfigurationFile_, std::string, "hdfsConfigurationFile");

    try {
        overwrite_ = boost::any_cast<bool>(conf["overwrite"]);
    }
    catch(...) {
        // PASS
        //LOG(INFO) << "overwrite not specified. Defaulting to false";
    }

    /* Setup webhdfs config */
    DLOG(INFO) << "Reading HDFS config: " << hdfsConfigurationFile_;

    char *error = NULL;
    conf_ = webhdfs_conf_load(hdfsConfigurationFile_.c_str(), &error);
    if(!conf_) {
        std::ostringstream os;
        os << "Error reading hdfs config: " << hdfsConfigurationFile_ << " : ";
        std::string errorStr(os.str());
        if (error) {
            errorStr += std::string(error);
            free(error);
        }
        throw std::runtime_error(errorStr);
    }

    /* Connect to WebHDFS */
    fs_ = webhdfs_connect(conf_);
    if(!fs_) {
        throw std::runtime_error("error in webhdfs_connect");
    }

    f_ = webhdfs_file_open(fs_, filename_.c_str());

    if(!f_) {
        throw std::runtime_error("error in webhdfs_file_open");
    }

    GET_PARAMETER(fileStatCache_, boost::shared_ptr<base::Cache>, "fileStatCache");

    configured_ = true;
}
Exemplo n.º 2
0
int main (int argc, char **argv) {
    webhdfs_conf_t *conf;
    webhdfs_t *fs;

    /* Setup webhdfs config */
    conf = webhdfs_conf_alloc();
    webhdfs_conf_set_server(conf, "localhost", 50007, 0);
    webhdfs_conf_set_user(conf, "th30z");

    /* Connect to WebHDFS */
    fs = webhdfs_connect(conf);

    webhdfs_mkdir(fs, "/test", 0644);

    /* Disconnect from WebHDFS */
    webhdfs_disconnect(fs);
    webhdfs_conf_free(conf);

    return(0);
}