From 1dda0caa889aab7b9c52e1f20aa4b281d620967c Mon Sep 17 00:00:00 2001 From: Elliott Clark Date: Mon, 4 Apr 2016 13:52:05 -0700 Subject: [PATCH] HBASE-14855 Connect to regionserver --- hbase-native-client/core/BUCK | 31 ++++++++++-- hbase-native-client/core/client-dispatcher.cc | 53 ++++++++++++++++++++ hbase-native-client/core/client-dispatcher.h | 41 ++++++++++++++++ hbase-native-client/core/client.cc | 16 +++--- hbase-native-client/core/client.h | 16 +++++- hbase-native-client/core/connection-factory.cc | 52 ++++++++++++++++++++ hbase-native-client/core/connection-factory.h | 39 +++++++++++++++ hbase-native-client/core/get-request.cc | 19 ++++++++ hbase-native-client/core/get-request.h | 34 +++++++++++++ hbase-native-client/core/get-result.cc | 19 ++++++++ hbase-native-client/core/get-result.h | 32 ++++++++++++ hbase-native-client/core/header-handler.cc | 57 ++++++++++++++++++++++ hbase-native-client/core/header-handler.h | 34 +++++++++++++ hbase-native-client/core/location-cache-test.cc | 18 +++++++ hbase-native-client/core/location-cache.cc | 18 +++++++ hbase-native-client/core/location-cache.h | 18 +++++++ hbase-native-client/core/native-client-test-env.cc | 6 +-- hbase-native-client/core/pipeline.cc | 45 +++++++++++++++++ hbase-native-client/core/pipeline.h | 32 ++++++++++++ hbase-native-client/core/request-encoder.h | 35 +++++++++++++ hbase-native-client/core/request.h | 33 +++++++++++++ hbase-native-client/core/response-decoder.h | 35 +++++++++++++ hbase-native-client/core/response.h | 34 +++++++++++++ hbase-native-client/core/service.h | 26 ++++++++++ hbase-native-client/core/simple-client.cc | 56 +++++++++++++++++++++ .../core/simple-native-client-test.cc | 5 +- hbase-native-client/core/table-name.cc | 19 ++++++++ hbase-native-client/core/table-name.h | 32 ++++++++++++ hbase-native-client/if/BUCK | 24 +++++++-- hbase-native-client/third-party/BUCK | 51 ++++++++++--------- 30 files changed, 883 insertions(+), 47 deletions(-) create mode 100644 hbase-native-client/core/client-dispatcher.cc create mode 100644 hbase-native-client/core/client-dispatcher.h create mode 100644 hbase-native-client/core/connection-factory.cc create mode 100644 hbase-native-client/core/connection-factory.h create mode 100644 hbase-native-client/core/get-request.cc create mode 100644 hbase-native-client/core/get-request.h create mode 100644 hbase-native-client/core/get-result.cc create mode 100644 hbase-native-client/core/get-result.h create mode 100644 hbase-native-client/core/header-handler.cc create mode 100644 hbase-native-client/core/header-handler.h create mode 100644 hbase-native-client/core/pipeline.cc create mode 100644 hbase-native-client/core/pipeline.h create mode 100644 hbase-native-client/core/request-encoder.h create mode 100644 hbase-native-client/core/request.h create mode 100644 hbase-native-client/core/response-decoder.h create mode 100644 hbase-native-client/core/response.h create mode 100644 hbase-native-client/core/service.h create mode 100644 hbase-native-client/core/simple-client.cc create mode 100644 hbase-native-client/core/table-name.cc create mode 100644 hbase-native-client/core/table-name.h diff --git a/hbase-native-client/core/BUCK b/hbase-native-client/core/BUCK index d1e89d1..a108ece 100644 --- a/hbase-native-client/core/BUCK +++ b/hbase-native-client/core/BUCK @@ -16,29 +16,48 @@ # limitations under the License. cxx_library(name="core", - headers=[ + exported_headers=[ "admin.h", + "client-dispatcher.h", "client.h", + "connection-factory.h", "connection.h", "connection_attr.h", "delete.h", + "get-request.h", + "get-result.h", "get.h", + "header-handler.h", "hbase_macros.h", + "location-cache.h", "mutation.h", + "pipeline.h", "put.h", + "request-encoder.h", + "request.h", + "response-decoder.h", + "response.h", "scanner.h", - "location-cache.h", + "service.h", + "table-name.h", ], srcs=[ "admin.cc", + "client-dispatcher.cc", "client.cc", + "connection-factory.cc", "connection.cc", + "delete.cc", + "get-request.cc", + "get-result.cc", + "header-handler.cc", "get.cc", + "location-cache.cc", "mutation.cc", + "pipeline.cc", "put.cc", - "delete.cc", "scanner.cc", - "location-cache.cc", + "table-name.cc", ], deps=[ "//if:if", @@ -68,3 +87,7 @@ cxx_test(name="location-cache-test", ":core", ], run_test_separately=True, ) +cxx_binary(name="simple-client", + srcs=["simple-client.cc",], + deps=[":core",], +) diff --git a/hbase-native-client/core/client-dispatcher.cc b/hbase-native-client/core/client-dispatcher.cc new file mode 100644 index 0000000..ed16718 --- /dev/null +++ b/hbase-native-client/core/client-dispatcher.cc @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "client-dispatcher.h" + +using namespace folly; +using namespace hbase; +using namespace wangle; + +void ClientDispatcher::read(Context *ctx, Response in) { + auto call_id = in.call_id(); + auto search = requests_.find(call_id); + CHECK(search != requests_.end()); + auto p = std::move(search->second); + requests_.erase(call_id); + + // TODO: check if the response is an exception. If it is then set that. + p.setValue(in); +} + +Future ClientDispatcher::operator()(Request arg) { + auto call_id = current_call_id_++; + arg.set_call_id(call_id); + auto &p = requests_[call_id]; + auto f = p.getFuture(); + p.setInterruptHandler([call_id, this](const folly::exception_wrapper &e) { + this->requests_.erase(call_id); + }); + this->pipeline_->write(arg); + + return f; +} + +Future ClientDispatcher::close() { return ClientDispatcherBase::close(); } + +Future ClientDispatcher::close(Context *ctx) { + return ClientDispatcherBase::close(ctx); +} diff --git a/hbase-native-client/core/client-dispatcher.h b/hbase-native-client/core/client-dispatcher.h new file mode 100644 index 0000000..262ba90 --- /dev/null +++ b/hbase-native-client/core/client-dispatcher.h @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once + +#include + +#include "pipeline.h" +#include "request.h" +#include "response.h" + +namespace hbase { +class ClientDispatcher + : public wangle::ClientDispatcherBase { +public: + void read(Context *ctx, Response in) override; + folly::Future operator()(Request arg) override; + folly::Future close(Context *ctx) override; + folly::Future close() override; + +private: + std::unordered_map> requests_; + uint32_t current_call_id_ = 1; +}; +} // hbase diff --git a/hbase-native-client/core/client.cc b/hbase-native-client/core/client.cc index a04daee..5e9e7bb 100644 --- a/hbase-native-client/core/client.cc +++ b/hbase-native-client/core/client.cc @@ -24,19 +24,17 @@ #include #include +#include + #include "if/ZooKeeper.pb.h" +#include "core/connection-factory.h" using namespace folly; +using namespace std; using namespace hbase::pb; -int main(int argc, char *argv[]) { - MetaRegionServer mrs; - google::ParseCommandLineFlags(&argc, &argv, true); - google::InitGoogleLogging(argv[0]); +namespace hbase { - FB_LOG_EVERY_MS(INFO, 10000) << "Hello"; - for (long i = 0; i < 10000000; i++) { - FB_LOG_EVERY_MS(INFO, 1) << Random::rand32(); - } - return 0; +Client::Client(string quorum_spec) + : location_cache(quorum_spec, wangle::getCPUExecutor()) {} } diff --git a/hbase-native-client/core/client.h b/hbase-native-client/core/client.h index 35a3bd8..f386d3b 100644 --- a/hbase-native-client/core/client.h +++ b/hbase-native-client/core/client.h @@ -20,7 +20,21 @@ #pragma once #include +#include #include "if/Cell.pb.h" -class Client {}; +#include "get-request.h" +#include "get-result.h" + +namespace hbase { +class Client { +public: + explicit Client(std::string quorum_spec); + folly::Future get(const GetRequest &get_request); + +private: + LocationCache location_cache; +}; + +} /* hbase */ diff --git a/hbase-native-client/core/connection-factory.cc b/hbase-native-client/core/connection-factory.cc new file mode 100644 index 0000000..6e42392 --- /dev/null +++ b/hbase-native-client/core/connection-factory.cc @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "connection-factory.h" + +#include +#include +#include +#include +#include + +#include "client-dispatcher.h" +#include "pipeline.h" +#include "request.h" +#include "response.h" +#include "service.h" + +using namespace folly; +using namespace hbase; +using namespace wangle; + +ConnectionFactory::ConnectionFactory() { + bootstrap_.group(std::make_shared(1)); + bootstrap_.pipelineFactory(std::make_shared()); +} + +Future ConnectionFactory::make_connection(std::string host, + int port) { + auto srv = bootstrap_.connect(SocketAddress(host, port, true)) + .then([](ClientPipeline *pipeline) { + ClientDispatcher dispatcher; + dispatcher.setPipeline(pipeline); + return dispatcher; + }); + return srv; +} diff --git a/hbase-native-client/core/connection-factory.h b/hbase-native-client/core/connection-factory.h new file mode 100644 index 0000000..53c55ef --- /dev/null +++ b/hbase-native-client/core/connection-factory.h @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#pragma once + +#include +#include + +#include "service.h" +#include "pipeline.h" +#include "request.h" +#include "response.h" +#include "client-dispatcher.h" + +namespace hbase { +class ConnectionFactory { +public: + ConnectionFactory(); + folly::Future make_connection(std::string host, int port); + +private: + wangle::ClientBootstrap bootstrap_; +}; +} // hbase diff --git a/hbase-native-client/core/get-request.cc b/hbase-native-client/core/get-request.cc new file mode 100644 index 0000000..fe86080 --- /dev/null +++ b/hbase-native-client/core/get-request.cc @@ -0,0 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "get-request.h" diff --git a/hbase-native-client/core/get-request.h b/hbase-native-client/core/get-request.h new file mode 100644 index 0000000..3fbb3cd --- /dev/null +++ b/hbase-native-client/core/get-request.h @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#pragma once + +#include +#include "table-name.h" + +namespace hbase { + +class GetRequest { +public: + GetRequest(TableName table_name, std::string key); + +private: + TableName table_name_; + std::string key_; +}; +} diff --git a/hbase-native-client/core/get-result.cc b/hbase-native-client/core/get-result.cc new file mode 100644 index 0000000..4c979c4 --- /dev/null +++ b/hbase-native-client/core/get-result.cc @@ -0,0 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "get-result.h" diff --git a/hbase-native-client/core/get-result.h b/hbase-native-client/core/get-result.h new file mode 100644 index 0000000..8fe1bc5 --- /dev/null +++ b/hbase-native-client/core/get-result.h @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#pragma once + +#include + +namespace hbase { + +class GetResult { +public: + explicit GetResult(std::string key); + +private: + std::string key_; +}; +} diff --git a/hbase-native-client/core/header-handler.cc b/hbase-native-client/core/header-handler.cc new file mode 100644 index 0000000..a2a267f --- /dev/null +++ b/hbase-native-client/core/header-handler.cc @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "core/header-handler.h" + +#include "if/HBase.pb.h" +#include "if/RPC.pb.h" + +using namespace hbase; + +const static std::string PREAMBLE = "HBas"; + +folly::Future +HeaderHandler::write(Context *ctx, std::unique_ptr msg) { + printf("CTX -> %p", ctx); + if (need_send_header_) { + need_send_header_ = false; + write_header(ctx); + } + return ctx->fireWrite(std::move(msg)); +} + +folly::Future HeaderHandler::write_header(Context *ctx) { + pb::ConnectionHeader h; + h.mutable_user_info()->set_effective_user("elliott"); + h.set_service_name("ClientService"); + + auto magic = folly::IOBuf::copyBuffer(PREAMBLE); + auto buf = folly::IOBuf::create(6); + auto msg = folly::IOBuf::copyBuffer(h.SerializeAsString()); + + buf->append(6); + folly::io::RWPrivateCursor c(buf.get()); + c.write((uint8_t)0); + c.write((uint8_t)80); + c.write((uint32_t)h.ByteSize()); + + buf->prependChain(std::move(msg)); + magic->prependChain(std::move(buf)); + + return ctx->fireWrite(std::move(magic)); +} diff --git a/hbase-native-client/core/header-handler.h b/hbase-native-client/core/header-handler.h new file mode 100644 index 0000000..64878e4 --- /dev/null +++ b/hbase-native-client/core/header-handler.h @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#pragma once + +#include + +namespace hbase { + +class HeaderHandler : public wangle::OutboundBytesToBytesHandler { +public: + folly::Future write(Context *ctx, + std::unique_ptr msg) override; + +private: + folly::Future write_header(Context *ctx); + bool need_send_header_{true}; +}; +} // hbase diff --git a/hbase-native-client/core/location-cache-test.cc b/hbase-native-client/core/location-cache-test.cc index 3106e36..ceae361 100644 --- a/hbase-native-client/core/location-cache-test.cc +++ b/hbase-native-client/core/location-cache-test.cc @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ #include #include #include diff --git a/hbase-native-client/core/location-cache.cc b/hbase-native-client/core/location-cache.cc index cf61e24..a87c3c7 100644 --- a/hbase-native-client/core/location-cache.cc +++ b/hbase-native-client/core/location-cache.cc @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ #include "location-cache.h" #include diff --git a/hbase-native-client/core/location-cache.h b/hbase-native-client/core/location-cache.h index 8dc2760..bf9a7a0 100644 --- a/hbase-native-client/core/location-cache.h +++ b/hbase-native-client/core/location-cache.h @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ #pragma once #include diff --git a/hbase-native-client/core/native-client-test-env.cc b/hbase-native-client/core/native-client-test-env.cc index 07f30a6..0269a43 100644 --- a/hbase-native-client/core/native-client-test-env.cc +++ b/hbase-native-client/core/native-client-test-env.cc @@ -22,7 +22,7 @@ namespace { class NativeClientTestEnv : public ::testing::Environment { - public: +public: void SetUp() override { // start local HBase cluster to be reused by all tests auto result = system("bin/start_local_hbase_and_wait.sh"); @@ -36,9 +36,9 @@ class NativeClientTestEnv : public ::testing::Environment { } }; -} // anonymous +} // anonymous -int main(int argc, char** argv) { +int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); ::testing::AddGlobalTestEnvironment(new NativeClientTestEnv()); return RUN_ALL_TESTS(); diff --git a/hbase-native-client/core/pipeline.cc b/hbase-native-client/core/pipeline.cc new file mode 100644 index 0000000..2ca0831 --- /dev/null +++ b/hbase-native-client/core/pipeline.cc @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "pipeline.h" + +#include +#include + +#include "header-handler.h" +#include "request-encoder.h" +#include "response-decoder.h" + +using namespace folly; +using namespace hbase; +using namespace wangle; + +ClientPipeline::Ptr +RpcPipelineFactory::newPipeline(std::shared_ptr sock) { + auto pipeline = ClientPipeline::create(); + pipeline->addBack(AsyncSocketHandler(sock)); + pipeline->addBack(OutputBufferingHandler()); + pipeline->addBack(EventBaseHandler()); + + pipeline->addBack(HeaderHandler()); + pipeline->addBack(ResponseDecoder()); + pipeline->addBack(RequestEncoder()); + + pipeline->finalize(); + return std::move(pipeline); +} diff --git a/hbase-native-client/core/pipeline.h b/hbase-native-client/core/pipeline.h new file mode 100644 index 0000000..2ec91f3 --- /dev/null +++ b/hbase-native-client/core/pipeline.h @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#pragma once + +#include +#include "request.h" + +namespace hbase { +using ClientPipeline = wangle::Pipeline; + +class RpcPipelineFactory : public wangle::PipelineFactory { +public: + ClientPipeline::Ptr + newPipeline(std::shared_ptr sock) override; +}; +} // hbase diff --git a/hbase-native-client/core/request-encoder.h b/hbase-native-client/core/request-encoder.h new file mode 100644 index 0000000..879b57c --- /dev/null +++ b/hbase-native-client/core/request-encoder.h @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#pragma once + +#include + +#include "request.h" + +namespace hbase { + +class RequestEncoder : public wangle::MessageToByteEncoder { +public: + std::unique_ptr encode(Request &req) override { + printf("Encoding\n"); + std::string out{"test"}; + return folly::IOBuf::copyBuffer(out); + } +}; +} diff --git a/hbase-native-client/core/request.h b/hbase-native-client/core/request.h new file mode 100644 index 0000000..4246467 --- /dev/null +++ b/hbase-native-client/core/request.h @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#pragma once + +#include + +namespace hbase { +class Request { +public: + Request() : call_id_(0) {} + uint32_t call_id() { return call_id_; } + void set_call_id(uint32_t call_id) { call_id_ = call_id; } + +private: + uint32_t call_id_; +}; +} diff --git a/hbase-native-client/core/response-decoder.h b/hbase-native-client/core/response-decoder.h new file mode 100644 index 0000000..335075d --- /dev/null +++ b/hbase-native-client/core/response-decoder.h @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#pragma once + +#include + +#include "response.h" + +namespace hbase { + +class ResponseDecoder : public wangle::ByteToMessageDecoder { +public: + bool decode(Context *ctx, folly::IOBufQueue &buf, Response &result, + size_t &size) { + printf("Decoding size = %zu", size); + return false; + } +}; +} diff --git a/hbase-native-client/core/response.h b/hbase-native-client/core/response.h new file mode 100644 index 0000000..f92abe2 --- /dev/null +++ b/hbase-native-client/core/response.h @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#pragma once + +#include + +namespace hbase { + +class Response { +public: + Response() : call_id_(0) {} + uint32_t call_id() { return call_id_; } + void set_call_id(uint32_t call_id) { call_id_ = call_id; } + +private: + uint32_t call_id_; +}; +} diff --git a/hbase-native-client/core/service.h b/hbase-native-client/core/service.h new file mode 100644 index 0000000..a82b4af --- /dev/null +++ b/hbase-native-client/core/service.h @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#pragma once + +#include "request.h" +#include "response.h" + +namespace hbase { +using HBaseService = wangle::Service; +} diff --git a/hbase-native-client/core/simple-client.cc b/hbase-native-client/core/simple-client.cc new file mode 100644 index 0000000..7eadbeb --- /dev/null +++ b/hbase-native-client/core/simple-client.cc @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#include +#include +#include +#include + +#include + +#include "if/ZooKeeper.pb.h" +#include "core/connection-factory.h" +#include "core/client.h" + +using namespace folly; +using namespace std; +using namespace hbase::pb; + +int main(int argc, char *argv[]) { + google::ParseCommandLineFlags(&argc, &argv, true); + google::InitGoogleLogging(argv[0]); + + // Show that we can create a client + //hbase::Client client{"localhost:2181"}; + + // Create a connection factory + hbase::ConnectionFactory cf; + + // Create a connection to the local host + auto conn = cf.make_connection("localhost", 16010).get(); + + // Send the request + hbase::Request r; + conn(r).get(); + + conn.close(); + + return 0; +} diff --git a/hbase-native-client/core/simple-native-client-test.cc b/hbase-native-client/core/simple-native-client-test.cc index ef564f7..ee39986 100644 --- a/hbase-native-client/core/simple-native-client-test.cc +++ b/hbase-native-client/core/simple-native-client-test.cc @@ -22,7 +22,4 @@ /** * Sample test. */ -TEST(SampleTest, sample) { - EXPECT_TRUE(true); -} - +TEST(SampleTest, sample) { EXPECT_TRUE(true); } diff --git a/hbase-native-client/core/table-name.cc b/hbase-native-client/core/table-name.cc new file mode 100644 index 0000000..3a528f2 --- /dev/null +++ b/hbase-native-client/core/table-name.cc @@ -0,0 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "table-name.h" diff --git a/hbase-native-client/core/table-name.h b/hbase-native-client/core/table-name.h new file mode 100644 index 0000000..0fcf327 --- /dev/null +++ b/hbase-native-client/core/table-name.h @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#pragma once + +#include + +#include "location-cache.h" +namespace hbase { + +// This is the core class of a HBase client. +class TableName { +public: + explicit TableName(std::string tableName); + explicit TableName(std::string namespaceName, std::string tableName); +}; +} // hbase diff --git a/hbase-native-client/if/BUCK b/hbase-native-client/if/BUCK index 9b989b5..5ff617d 100644 --- a/hbase-native-client/if/BUCK +++ b/hbase-native-client/if/BUCK @@ -1,3 +1,21 @@ +## +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + PROTO_SRCS = glob(['*.proto']) HEADER_FILENAMES = [ x.replace('.proto','.pb.h') for x in PROTO_SRCS] CC_FILENAMES = [ x.replace('.proto', '.pb.cc') for x in PROTO_SRCS] @@ -20,7 +38,7 @@ for cc_filename in CC_FILENAMES: genrule( name = cc_filename, cmd = 'mkdir -p `dirname $OUT` ' - ' && cp $(location :generate-proto-sources)/{} $OUT ' + ' && cp $(location :generate-proto-sources)/*.cc `dirname $OUT` ' ' && cp $(location :generate-proto-sources)/*.h `dirname $OUT`'.format(cc_filename), out = cc_filename, ) @@ -29,9 +47,7 @@ cxx_library( name = 'if', exported_headers = [':' + x for x in HEADER_FILENAMES], srcs = [':' + x for x in CC_FILENAMES], - deps = [ '//third-party:protobuf'] - + [':' + x for x in CC_FILENAMES] - + [ ':' + x for x in HEADER_FILENAMES ], + deps = [ '//third-party:protobuf'], visibility = [ 'PUBLIC', ], exported_deps = ['//third-party:protobuf'] ) diff --git a/hbase-native-client/third-party/BUCK b/hbase-native-client/third-party/BUCK index 6548695..ae3fab1 100644 --- a/hbase-native-client/third-party/BUCK +++ b/hbase-native-client/third-party/BUCK @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. - def add_system_libs(names=[], lib_dir="/usr/lib/x86_64-linux-gnu", deps=[], @@ -23,6 +22,7 @@ def add_system_libs(names=[], exported_linker_flags=[]): rules = [] for name in names: + rule_visibility = ['PUBLIC'] gen_rule_name = "gen_lib{}".format(name) genrule(name=gen_rule_name, out=gen_rule_name, @@ -32,10 +32,19 @@ def add_system_libs(names=[], lib_name=name, lib_dir='$(location :{})'.format(gen_rule_name), deps=deps, - force_static = True, + force_static = True, exported_deps=exported_deps, - visibility=['PUBLIC'], - exported_linker_flags=exported_linker_flags, ) + visibility=rule_visibility,) + rules.append(":" + name) + return rules + +def add_dynamic_libs(names=[]): + rules = [] + for name in names: + prebuilt_cxx_library(name=name, + header_only = True, + exported_linker_flags=["-l"+name], + visibility=["PUBLIC"],) rules.append(":" + name) return rules @@ -54,28 +63,29 @@ local_libs = [ "glog", "protobuf", ] - - - -tp_dep_rules = add_system_libs(system_libs) \ - + add_system_libs(local_libs, lib_dir = "/usr/local/lib") +dynamic_libs = [ + "stdc++", + "pthread", + "ssl", + "crypto", + "dl", + "atomic", +] +dynamic_rules =add_dynamic_libs(dynamic_libs) +tp_dep_rules = add_system_libs(system_libs,) \ + + add_system_libs(local_libs, lib_dir = "/usr/local/lib") \ + + dynamic_rules zookeeper = add_system_libs(["zookeeper_mt"], lib_dir = "/usr/local/lib") folly = add_system_libs(['folly'], lib_dir='/usr/local/lib', - exported_deps=tp_dep_rules, - exported_linker_flags=["-pthread", - "-lstdc++", ]) + exported_deps=tp_dep_rules,) folly_bench = add_system_libs(['follybenchmark'], lib_dir='/usr/local/lib', - exported_deps=tp_dep_rules + folly, - exported_linker_flags=["-pthread", - "-lstdc++", ]) + exported_deps=folly+tp_dep_rules,) wangle = add_system_libs(['wangle'], lib_dir='/usr/local/lib', - exported_deps=tp_dep_rules + folly, - exported_linker_flags=["-pthread", - "-lstdc++", ]) + exported_deps=folly + tp_dep_rules) genrule( @@ -101,10 +111,7 @@ cxx_library( ('googletest/googlemock', 'src/*.h'), ('googletest/googlemock', 'src/*.cc'), ]), - exported_linker_flags = [ - "-pthread", - "-lstdc++", - ], + exported_deps=dynamic_rules, visibility = [ 'PUBLIC', ], -- 2.8.0-rc2