Skip to content

Commit d47be15

Browse files
authored
Create examples of the table admin APIs (GoogleCloudPlatform#4)
Add programs to create tables, list tables, and delete tables.
1 parent bc3aaec commit d47be15

18 files changed

Lines changed: 556 additions & 53 deletions

.appveyor.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: 1.0.{build}
2+
3+
pull_requests:
4+
do_not_increment_build_number: true
5+
6+
image: Visual Studio 2015
7+
8+
environment:
9+
APPVEYOR_SAVE_CACHE_ON_ERROR: true
10+
11+
cache:
12+
- c:\projects\vcpkg\installed -> bigtable\api\ci\install-windows.ps1
13+
14+
install:
15+
- git submodule update --init --recursive
16+
- powershell -exec bypass bigtable\api\ci\install-windows.ps1
17+
18+
build_script:
19+
- powershell -exec bypass bigtable\api\ci\build-windows.ps1

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bigtable/api/build/
2+
.git/

bigtable/api/CMakeLists.txt

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
#
1415

1516
cmake_minimum_required(VERSION 3.5)
1617

@@ -31,50 +32,76 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
3132
# and turn warnings into errors to stop the build if any warning is
3233
# emitted ...
3334
include(CheckCXXCompilerFlag)
34-
CHECK_CXX_COMPILER_FLAG(-Werror COMPILER_SUPPORTS_WERROR)
35-
if(COMPILER_SUPPORTS_WERROR)
36-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
37-
endif()
38-
CHECK_CXX_COMPILER_FLAG(-Wall COMPILER_SUPPORTS_WALL)
39-
if(COMPILER_SUPPORTS_WALL)
40-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
41-
endif()
42-
CHECK_CXX_COMPILER_FLAG(/WX COMPILER_SUPPORTS_WX)
43-
if(COMPILER_SUPPORTS_WX)
44-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
45-
endif()
46-
CHECK_CXX_COMPILER_FLAG(/W4 COMPILER_SUPPORTS_SWALL)
47-
if(COMPILER_SUPPORTS_SWALL)
48-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall")
35+
36+
if(NOT MSVC)
37+
CHECK_CXX_COMPILER_FLAG(-Werror COMPILER_SUPPORTS_WERROR)
38+
if(COMPILER_SUPPORTS_WERROR)
39+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
40+
endif()
41+
CHECK_CXX_COMPILER_FLAG(-Wall COMPILER_SUPPORTS_WALL)
42+
if(COMPILER_SUPPORTS_WALL)
43+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
44+
endif()
4945
endif()
5046

5147
# ... include the functions to compile proto files ...
5248
include(FindProtobuf)
5349

54-
# ... find the grpc and grpc++ libraries using pkg-config ...
55-
include(FindPkgConfig)
56-
pkg_check_modules(GRPCPP REQUIRED grpc++>=1.4.1)
57-
pkg_check_modules(GRPC REQUIRED grpc>=4.0)
58-
pkg_check_modules(PROTOBUF REQUIRED protobuf>=3.0)
59-
link_directories(${GRPCPP_LIBRARY_DIRS} ${GRPC_LIBRARY_DIRS} ${PROTOBUF_LIBRARY_DIRS})
60-
include_directories(${GRPCPP_INCLUDE_DIRS} ${GRPC_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS})
61-
62-
# ... define where the googleapis protos can be found, and add that
63-
# directory to the search path for header files ...
64-
# Typically you can generate these using:
65-
# $ make -C googleapis OUTPUT=$PWD/googleapis-gens
66-
set(GOOGLEAPIS_PATH "${CMAKE_SOURCE_DIR}/googleapis")
67-
set(GOOGLEAPIS_GENS_PATH "${GOOGLEAPIS_PATH}-gens")
68-
include_directories("${GOOGLEAPIS_GENS_PATH}")
50+
# ... find the grpc and grpc++ libraries ...
51+
if(WIN32)
52+
# ... use find_package and vcpkg on Windows ...
53+
find_package(GRPC REQUIRED grpc>=1.4)
54+
find_package(PROTOBUF REQUIRED protobuf>=3.0)
55+
link_directories(${GRPC_LIBRARY_DIRS} ${PROTOBUF_LIBRARY_DIRS})
56+
include_directories(${GRPC_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS})
57+
set(GRPC_LIBRARIES gRPC::grpc++ gRPC::grpc)
58+
set(PROTOBUF_LIBRARIES protobuf::libprotobuf)
59+
# Use the same settings that gRPC uses...
60+
add_definitions(-D_WIN32_WINNT=0x600 -D_SCL_SECURE_NO_WARNINGS)
61+
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS)
62+
if(MSVC)
63+
add_definitions(/wd4065 /wd4506 /wd4267 /wd4800 /wd4291 /wd4838)
64+
if(VCPKG_TARGET_TRIPLET MATCHES "-static$")
65+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
66+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
67+
endif()
68+
endif()
69+
else()
70+
# ... use pkg-config on Linux and Mac OSX ...
71+
include(FindPkgConfig)
72+
pkg_check_modules(GRPCPP REQUIRED grpc++>=1.4.1)
73+
pkg_check_modules(GRPC REQUIRED grpc>=4.0)
74+
pkg_check_modules(PROTOBUF REQUIRED protobuf>=3.0)
75+
link_directories(${GRPCPP_LIBRARY_DIRS} ${GRPC_LIBRARY_DIRS} ${PROTOBUF_LIBRARY_DIRS})
76+
include_directories(${GRPCPP_INCLUDE_DIRS} ${GRPC_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS})
77+
endif()
78+
79+
include(cmake/CompileProtos.cmake)
80+
81+
set(PROTOBUF_IMPORT_DIRS "${PROJECT_SOURCE_DIR}/googleapis")
82+
PROTOBUF_GENERATE_CPP(PROTO_SOURCES PROTO_HDRS
83+
${PROJECT_SOURCE_DIR}/googleapis/google/bigtable/admin/v2/bigtable_instance_admin.proto
84+
${PROJECT_SOURCE_DIR}/googleapis/google/bigtable/admin/v2/bigtable_table_admin.proto
85+
${PROJECT_SOURCE_DIR}/googleapis/google/bigtable/admin/v2/common.proto
86+
${PROJECT_SOURCE_DIR}/googleapis/google/bigtable/admin/v2/instance.proto
87+
${PROJECT_SOURCE_DIR}/googleapis/google/bigtable/admin/v2/table.proto
88+
${PROJECT_SOURCE_DIR}/googleapis/google/longrunning/operations.proto
89+
${PROJECT_SOURCE_DIR}/googleapis/google/rpc/status.proto
90+
${PROJECT_SOURCE_DIR}/googleapis/google/api/annotations.proto
91+
${PROJECT_SOURCE_DIR}/googleapis/google/api/auth.proto
92+
${PROJECT_SOURCE_DIR}/googleapis/google/api/http.proto)
93+
GRPC_GENERATE_CPP(GRPCPP_SOURCES GRPCPP_HDRS
94+
${PROJECT_SOURCE_DIR}/googleapis/google/bigtable/admin/v2/bigtable_instance_admin.proto
95+
${PROJECT_SOURCE_DIR}/googleapis/google/bigtable/admin/v2/bigtable_table_admin.proto
96+
${PROJECT_SOURCE_DIR}/googleapis/google/longrunning/operations.proto)
97+
include_directories("${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")
6998

7099
################################################################
71100
# Create targets here ...
72101

73102
# ... discover all the generated Google API files and turn them into a
74103
# static library ...
75-
file(GLOB_RECURSE GOOGLEAPIS_SRCS ${GOOGLEAPIS_GENS_PATH}/*.pb.cc)
76-
file(GLOB_RECURSE GOOGLEAPIS_HDRS ${GOOGLEAPIS_GENS_PATH}/*.pb.h)
77-
add_library(googleapis ${GOOGLEAPIS_SRCS} ${GOOGLEAPIS_HDRS})
104+
add_library(googleapis ${PROTO_SOURCES} ${PROTO_HDRS} ${GRPCPP_SOURCES} ${GRPCPP_HDRS})
78105

79106
add_executable(list_instances list_instances.cc)
80107
target_link_libraries(list_instances googleapis ${GRPCPP_LIBRARIES} ${GRPC_LIBRARIES} ${PROTOBUF_LIBRARIES})
@@ -84,3 +111,12 @@ target_link_libraries(create_instance googleapis ${GRPCPP_LIBRARIES} ${GRPC_LIBR
84111

85112
add_executable(delete_instance delete_instance.cc)
86113
target_link_libraries(delete_instance googleapis ${GRPCPP_LIBRARIES} ${GRPC_LIBRARIES} ${PROTOBUF_LIBRARIES})
114+
115+
add_executable(create_table create_table.cc)
116+
target_link_libraries(create_table googleapis ${GRPCPP_LIBRARIES} ${GRPC_LIBRARIES} ${PROTOBUF_LIBRARIES})
117+
118+
add_executable(delete_table delete_table.cc)
119+
target_link_libraries(delete_table googleapis ${GRPCPP_LIBRARIES} ${GRPC_LIBRARIES} ${PROTOBUF_LIBRARIES})
120+
121+
add_executable(list_tables list_tables.cc)
122+
target_link_libraries(list_tables googleapis ${GRPCPP_LIBRARIES} ${GRPC_LIBRARIES} ${PROTOBUF_LIBRARIES})

bigtable/api/README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Bigtable Samples.
22

3+
[![Build Status](https://travis-ci.org/coryan/cpp-docs-samples.svg?branch=master)](https://travis-ci.org/coryan/cpp-docs-samples) [![Build status](https://ci.appveyor.com/api/projects/status/51melcqj0g1whoug?svg=true)](https://ci.appveyor.com/project/coryan/cpp-docs-samples)
4+
35
These samples demonstrate how to call the [Google Cloud Bigtable API](https://cloud.google.com/bigtable/) using C++.
46

57
## Build and Run
@@ -68,12 +70,26 @@ These samples demonstrate how to call the [Google Cloud Bigtable API](https://cl
6870
6971
1. **Run the examples**
7072
```console
71-
# for example: list_instance my-project
72-
./list_instances <project_id>
73+
# This should be the name of the project you enabled billing and the APIs for.
74+
PROJECT=<your project here>
75+
76+
# ... outside GCE you may need to set:
77+
# export GOOGLE_APPLICATION_CREDENTIALS=<path to service account private key file>
78+
79+
./list_instances $PROJECT
80+
81+
./create_instance $PROJECT bt-test-instance cluster-00 us-east1-c
82+
83+
./list_instances $PROJECT
7384
74-
# for example: create_instance my-project bt-test-instance cluster00 us-east1-c
75-
./create_instance <project_id> <instance_id> <cluster_id> <zone>
85+
./create_table $PROJECT bt-test-instance my-table
7686
77-
./list_instances <project_id>
78-
./delete_instance <project_id> <instance_id>
87+
./list_tables $PROJECT bt-test-instance
88+
89+
./delete_table $PROJECT bt-test-instance my-table
90+
91+
./delete_instance $PROJECT bt-test-instance
92+
93+
./list_instances $PROJECT
7994
```
95+

bigtable/api/ci/build-linux.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if [ "x${DOCKER_BUILD}" != "xyes" ]; then
88
fi
99

1010
IMAGE="cached-${DISTRO?}-${DISTRO_VERSION?}"
11-
latest_id=$(sudo docker inspect -f '{{ .Id }}' ${IMAGE?}:latest >/dev/null || echo "")
11+
latest_id=$(sudo docker inspect -f '{{ .Id }}' ${IMAGE?}:latest 2>/dev/null || echo "")
1212

1313
echo IMAGE = $IMAGE
1414
echo IMAGE LATEST ID = $latest_id

bigtable/api/ci/build-macosx.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ cmake ..
2121
make -j 2
2222

2323
exit 0
24-

bigtable/api/ci/build-windows.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env powershell
2+
3+
$dir = Split-Path (Get-Item -Path ".\" -Verbose).FullName
4+
if (Test-Path variable:env:APPVEYOR_BUILD_FOLDER) {
5+
$dir = Split-Path $env:APPVEYOR_BUILD_FOLDER
6+
}
7+
8+
$integrate = "$dir\vcpkg\vcpkg.exe integrate install"
9+
Invoke-Expression $integrate
10+
11+
cd bigtable\api
12+
mkdir build
13+
cd build
14+
cmake -DCMAKE_TOOLCHAIN_FILE="$dir\vcpkg\scripts\buildsystems\vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x86-windows-static ..
15+
cmake --build .

bigtable/api/ci/install-macosx.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,4 @@ fi
99

1010
brew install grpc protobuf
1111

12-
echo "DEBUG output for install script"
13-
brew info grpc | grep '^/usr/local/Cellar' | awk '{print $1}'
14-
brew info protobuf | grep '^/usr/local/Cellar' | awk '{print $1}'
15-
16-
pkg-config --cflags protobuf
17-
pkg-config --cflags grpc
18-
1912
exit 0
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env powershell
2+
3+
# Using relative paths works both on appveyor and in development workstations
4+
cd ..
5+
6+
# ... update or clone the vcpkg package manager ...
7+
if (Test-Path vcpkg\.git) {
8+
cd vcpkg
9+
git pull
10+
} elseif (Test-Path vcpkg\installed) {
11+
move vcpkg vcpkg-tmp
12+
git clone https://github.com/Microsoft/vcpkg
13+
move vcpkg-tmp\installed vcpkg
14+
cd vcpkg
15+
} else {
16+
git clone https://github.com/Microsoft/vcpkg
17+
cd vcpkg
18+
}
19+
20+
# ... build the tool each time, it is fast to do so ...
21+
powershell -exec bypass scripts\bootstrap.ps1
22+
23+
# ... integrate installed packages into the build environment ...
24+
.\vcpkg integrate install
25+
26+
# ... if necessary, install grpc again. Normally the packages are
27+
# cached by the CI system (appveyor) so this is not too painful ...
28+
.\vcpkg install zlib:x86-windows-static
29+
.\vcpkg install openssl:x86-windows-static
30+
.\vcpkg install protobuf:x86-windows-static
31+
.\vcpkg install grpc:x86-windows-static
32+
33+
cd ..\cpp-docs-samples

0 commit comments

Comments
 (0)