Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bigtable: 00. Add a couple of developer helper scripts #2841

Merged
merged 7 commits into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions google-cloud-bigtable/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/deps
27 changes: 27 additions & 0 deletions google-cloud-bigtable/autogen_files.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
src/test/java/com/google/cloud/bigtable/data/v2/MockBigtable.java
src/test/java/com/google/cloud/bigtable/data/v2/BaseBigtableDataClientTest.java
src/test/java/com/google/cloud/bigtable/data/v2/MockBigtableImpl.java
src/main/java/com/google/cloud/bigtable/data/v2/BaseBigtableDataClient.java
src/main/java/com/google/cloud/bigtable/data/v2/BaseBigtableDataSettings.java
src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableStubSettings.java
src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableStub.java
src/main/java/com/google/cloud/bigtable/data/v2/stub/GrpcBigtableStub.java
src/main/java/com/google/cloud/bigtable/data/v2/package-info.java
src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableInstanceAdminImpl.java
src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableInstanceAdmin.java
src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableTableAdminImpl.java
src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java
src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java
src/test/java/com/google/cloud/bigtable/admin/v2/MockBigtableTableAdmin.java
src/main/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettings.java
src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettings.java
src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableTableAdminStub.java
src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableInstanceAdminStub.java
src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableTableAdminStubSettings.java
src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableInstanceAdminStubSettings.java
src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableInstanceAdminStub.java
src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableTableAdminStub.java
src/main/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClient.java
src/main/java/com/google/cloud/bigtable/admin/v2/PagedResponseWrappers.java
src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java
src/main/java/com/google/cloud/bigtable/admin/v2/package-info.java
Empty file.
14 changes: 14 additions & 0 deletions google-cloud-bigtable/scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Developer Scripts

This directory contains scripts to help in development of this client. Specifically to test out
changes in the autogenerated protobufs and GAPIC client before publishing the changes to googleapis.

- update-deps.sh downloads dependencies needed to regenerate the protobufs and the GAPIC client.
It will stage everything in `deps/`. It can be run again to refresh the dependencies. It will
try rebase any changes that are committed locally in the dependency.

- regenerate.sh is used to regenerate the base GAPIC layer. It will regenerate the protobufs and
all of the GAPIC classes in this project.

- autogen_files.lst and handwritten_files.lst track the origin of the files in `src/`, they will be
updated when `regenerate.sh` is run
135 changes: 135 additions & 0 deletions google-cloud-bigtable/scripts/regenerate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/usr/bin/env bash

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


# This script is used to regenerate protos & GAPIC stubs.
# It stages all of the generated code in deps/ and then installs it into the local maven repo.
# It is meant to be used to test changes to the gapic config before publishing
# To pull in upstream changes, please use update-deps.sh

set -o errexit -o errtrace

handle_error() {
echo "Failed, exiting. See deps/output.log for more details"
exit 1
}
trap 'handle_error' ERR


PROJECT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
WORKDIR="$PROJECT_DIR/deps"
LOG="$WORKDIR/output.log"

DOCKER_IMAGE=googleapis/artman:stable
TOOLKIT="$WORKDIR/toolkit"

function run {
run_artman
copy_api_client_staging
copy_google_cloud_java
install_protos

echo "Successfully completed!"
}

function run_artman {
rm -rf artman-genfiles/*

run_gapic "google/bigtable/artman_bigtable.yaml"
run_gapic "google/bigtable/admin/artman_bigtableadmin.yaml"
}

function run_gapic {
CONFIG="$1"

log "Running gapic for $CONFIG"

INNER_CMD="artman --local \
--config /googleapis/$CONFIG \
--root-dir /googleapis \
--output /tmp/artman-genfiles \
generate java_gapic"

DOCKER_CMD="docker run --name igor-artman --rm -it \
-e RUNNING_IN_ARTMAN_DOCKER=True \
-e HOST_USER_ID=$UID -e HOST_GROUP_ID=`id -g` \
-v $WORKDIR/googleapis:/googleapis \
-v $WORKDIR/artman-genfiles:/tmp/artman-genfiles"

if [ -n "$TOOLKIT" ]; then
DOCKER_CMD="$DOCKER_CMD -v $WORKDIR/toolkit:/toolkit"
fi

FULL_CMD="$DOCKER_CMD $DOCKER_IMAGE $INNER_CMD"
log "$FULL_CMD"
$FULL_CMD >>$LOG 2>&1
}

function copy_api_client_staging {
log "Copying files to api-client-staging"

rm -rf \
"$WORKDIR/api-client-staging/generated/java/proto-google-cloud-bigtable-v2" \
"$WORKDIR/api-client-staging/generated/java/proto-google-cloud-bigtable-admin-v2" \
"$WORKDIR/api-client-staging/generated/java/grpc-google-cloud-bigtable-v2" \
"$WORKDIR/api-client-staging/generated/java/grpc-google-cloud-bigtable-admin-v2" \
"$WORKDIR/api-client-staging/generated/java/gapic-google-cloud-bigtable-v2" \
"$WORKDIR/api-client-staging/generated/java/gapic-google-cloud-bigtable-admin-v2"

cp -r \
"$WORKDIR/artman-genfiles/java/grpc-google-cloud-bigtable-v2" \
"$WORKDIR/artman-genfiles/java/grpc-google-cloud-bigtable-admin-v2" \
"$WORKDIR/artman-genfiles/java/proto-google-cloud-bigtable-v2" \
"$WORKDIR/artman-genfiles/java/proto-google-cloud-bigtable-admin-v2" \
"$WORKDIR/api-client-staging/generated/java/"

cp -r \
"$WORKDIR/artman-genfiles/java/google-cloud-bigtable" \
"$WORKDIR/api-client-staging/generated/java/gapic-google-cloud-bigtable-v2"
cp -r \
"$WORKDIR/artman-genfiles/java/google-cloud-bigtable-admin" \
"$WORKDIR/api-client-staging/generated/java/gapic-google-cloud-bigtable-admin-v2"
}

function copy_google_cloud_java {
log "Copying google-cloud-java"

# Delete old files
xargs rm < autogen_files.lst
cat /dev/null > autogen_files.lst

# Update manual files
find src -type f > $PROJECT_DIR/handwritten_files.lst

# Generate a list of new files
# Data
pushd "$WORKDIR/artman-genfiles/java/google-cloud-bigtable"
find src -type f >> $PROJECT_DIR/autogen_files.lst
cp -r "src" "$PROJECT_DIR"
popd
# Admin
pushd "$WORKDIR/artman-genfiles/java/google-cloud-bigtable-admin"
find src -type f >> $PROJECT_DIR/autogen_files.lst
cp -r "src" "$PROJECT_DIR"
popd
}

function install_protos {
log "Installing protos from api-client-staging"

pushd "$WORKDIR/api-client-staging/generated/java" > /dev/null
./gradlew \
:proto-google-cloud-bigtable-v2:install \
:grpc-google-cloud-bigtable-v2:install \
:proto-google-cloud-bigtable-admin-v2:install \
:grpc-google-cloud-bigtable-admin-v2:install \
-x javadoc \
>>$LOG 2>&1

popd > /dev/null
}

function log {
echo ">>>>>>> $@"
echo ">>>>>>> $@" >> $LOG
}

run
81 changes: 81 additions & 0 deletions google-cloud-bigtable/scripts/update-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash

# This script pulls in upstream updates from the veneer code generator and rebases your local
# changes on top.
#
# Specifically it:
# - fetches changes from googleapis for updated protos
# - fetches changes from toolkit for updates to the code generator
# - fetches api-client-staging to use as a staging area for the generated grpc stubs
#
# This is meant to be used conjunction with update-deps.sh to regenerate the underlying client with
# the latest upstream changes.

set -o errexit -o errtrace

handle_error() {
echo "Failed, exiting. See deps/output.log for more details"
exit 1
}
trap 'handle_error' ERR

PROJECT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
WORKDIR="$PROJECT_DIR/deps"
LOG="$WORKDIR/output.log"

DIRS=( googleapis toolkit api-client-staging )

DOCKER_IMAGE=googleapis/artman:stable

function run {
init
update
}

# Make sure all of the dependencies are checked out
function init() {
mkdir -p "$WORKDIR"
echo "" > $WORKDIR/output.log

log "Pulling docker image"
docker pull "$DOCKER_IMAGE" >>$LOG 2>&1

if [ ! -d "$WORKDIR/googleapis" ]; then
log "Fetching googleapis"
git clone "https://github.com/googleapis/googleapis.git" "$WORKDIR/googleapis" >>$LOG 2>&1
fi

if [ ! -d "$WORKDIR/toolkit" ]; then
log "Fetching toolkit"
git clone "https://github.com/googleapis/toolkit.git" "$WORKDIR/toolkit" >>$LOG 2>&1
fi

if [ ! -d "$WORKDIR/api-client-staging" ]; then
log "Fetching api-client-staging"
git clone "https://github.com/googleapis/api-client-staging.git" "$WORKDIR/api-client-staging" >>$LOG 2>&1
fi
}

function update() {
for DIR in "${DIRS[@]}"; do
log "Updating $DIR"
DIR="$WORKDIR/$DIR"

log "Fetching upstream"
git -C "$DIR" fetch origin >>$LOG 2>&1

log "Dropping uncommitted local changes"
git -C "$DIR" reset --hard HEAD >>$LOG 2>&1

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

git -C "$DIR" clean -f >>$LOG 2>&1

log "Rebasing local changes"
git -C "$DIR" rebase origin/master >>$LOG 2>&1
done
}

function log {
echo ">>>>>>> $@"
echo ">>>>>>> $@" >> $LOG
}

run