An open API service indexing awesome lists of open source software.

https://github.com/couchbaselabs/connect-fall-2017-demo

Source Code for the Couchbase Connect 2017 Technical Keynote Demonstration
https://github.com/couchbaselabs/connect-fall-2017-demo

couchbase couchbase-cluster couchbase-docker-container couchbase-lite couchbase-mobile couchbase-server couchbase-sync-gateway

Last synced: 19 days ago
JSON representation

Source Code for the Couchbase Connect 2017 Technical Keynote Demonstration

Awesome Lists containing this project

README

        

= Couchbase Connect Fall 2017 Demo

Application code for Couchbase Connect SF Fall 2017 demo talk.

== Credits

This project includes significant contributions from others.

The web client is based on link:https://github.com/misterGF/CoPilot[CoPilot] and
is used here under terms of the link:https://opensource.org/licenses/MIT[MIT License].

The Android source includes a port of link:https://jasonette.com/[Jasonette] and is
included here under terms of the link:https://opensource.org/licenses/MIT[MIT License].

Images used in the web client are copyright their respective owners.
Attributions are listed under web/client/static/img/README.md.

Other copyrights may apply.
Inclusion in this work does not imply additional rights beyond those granted by the copyright holders.

This overall project, as applicable, is released under terms of the Apache 2.0 License.
See `LICENSE` for details.

== Instructions

The instructions come in a few forms.

There are several scripts for both Unix command line and Docker-based installations to simplify setup.
Instructions based on using the scripts to come.

There's a short form of the instructions meant for easy copy and paste.

There's a longer form description that breaks down the steps for better understanding.

Finally, you can find a video walking through the entire setup using the link below.

link:https://youtu.be/RlSMLkd9vrg[Couchbase Connect SV 2017 Demo Setup Walkthrough]

video::RlSMLkd9vrg[youtube,width=640,height=360]

=== Tl;dr version

This will show how to configure the demo mostly using the command line.

(N.B. Command line examples are given for a Mac using Bash.)

==== Clone Repository and Set Working Directory

[source,shell]
----
git clone https://github.com/couchbaselabs/connect-fall-2017-demo.git
cd connect-fall-2017-demo
----

==== Couchbase Server

Download and install Couchbase version 5.5 or later.
Add the Couchbase Server tools directory to your command path.

[source,shell]
----
export PATH="$PATH:/path/to/install/Couchbase Server.app/Contents/Resources/couchbase-core/bin"
----

Start in the top level directory of the project (`connect-fall-2017-demo`).

Run Couchbase Server.
The following assumes you're running on `localhost`.
Configure the node via the command line.

[source,shell]
----
# Basic memory and service configuration
couchbase-cli cluster-init --cluster couchbase://127.0.0.1 --cluster-name cluster \
--cluster-username Administrator --cluster-password password \
--services data,index,query,fts,analytics,eventing --cluster-ramsize 256 --cluster-analytics-ramsize 1024 \
--cluster-index-ramsize 256 --cluster-fts-ramsize 256 --index-storage-setting default
# Main bucket creation
couchbase-cli bucket-create --cluster couchbase://127.0.0.1 -u Administrator -p password \
--bucket health --bucket-type couchbase --bucket-ramsize 100
# Role-Based Access Control
couchbase-cli user-manage --cluster couchbase://127.0.0.1 -u Administrator -p password \
--set --rbac-username admin --rbac-password password \
--rbac-name "J. R. Admin" --roles "Admin" --auth-domain local
----

Wait for the node to warm up (about 15 seconds or so).
Configure the rest of what Couchbase Server needs.

[source,shell]
----
# Indexes for query optimization
cbq -u admin -p password -q --script="CREATE INDEX \`resource-idx\` ON health(resourceType, id);"
cbq -u admin -p password -q --script="CREATE INDEX \`observation-idx\` ON health(subject.reference, issued DESC, valueQuantity.\`value\`)"
cbq -u admin -p password -q --script="CREATE INDEX \`location-idx\` ON health(type.coding[0].code) WHERE resourceType = 'Location';"
# cURL site whitelist
curl -X POST -u admin:password -d "@scripts/config/curl" http://127.0.0.1:8091/settings/querySettings/curlWhitelist
# Full-Text Search index
curl -u admin:password -T "scripts/config/fts-index.json" http://127.0.0.1:8094/api/index/diagnosis
# Eventing Service meta-data bucket creation
couchbase-cli bucket-create --cluster couchbase://127.0.0.1 -u Administrator -p password \
--bucket eventing --bucket-type couchbase --bucket-ramsize 100
# Eventing Service function
curl -X POST -u admin:password -d "@scripts/config/eventing" http://127.0.0.1:8096/api/v1/functions/monitor
# Analytics Service indexes for query optimization
cat scripts/config/analytics | while read query
do
curl -u admin:password --data-urlencode "statement=${query}" http://127.0.0.1:8095/analytics/service
done
# Load sample data
for file in data/*.json
do
cbimport json -c couchbase://127.0.0.1:8091 -d file://${file} -g '%id%' -f lines -b health -u admin -p password
done
----

==== Web Client and Server

Start in the top level directory of the project (`connect-fall-2017-demo`).

[source,shell]
----
# Build Vue.js web client
cd web/client
npm install
npm run build
# Build and run Node.js web server
cd ../server
npm install
cat > .env <
----

=== Detailed Version

This is a work in progress.

=== On the machine that will host the web server

Install node. Note the server requires version 7 or higher. I recommend using nvm to manage Node versions if you have an existing installation. (The nvm installation guide can be found link:https://github.com/creationix/nvm/blob/master/README.md=install-script[here].

Clone the repo

[source,shell]
----
git clone https://github.com/couchbaselabs/connect-fall-2017-demo.git
----

==== Configuring the server

[source,shell]
----
cat > .env
UA_APPLICATION_KEY=''
UA_APPLICATION_MASTER_SECRET=''
CLUSTER='couchbase://localhost'
CLUSTER_USER=''
CLUSTER_PASSWORD=''
CLUSTER_CBAS='localhost:8095'
----

==== Running the server

Build requires a package to compile the native part of the Couchbase Node client. Install if needed.

[source,shell]
----
npm install -g node-gyp
----

You may also need to install the native compilation tools (e.g. g++). On Redhat

[source,shell]
----
yum group install "Development Tools"
----

In the directory demo/web/server install Node packages.

[source,shell]
----
npm install
----

Run the server.

[source,shell]
----
node ./bin/www
----

Or, for simple crash resilience, run a script.

[source,shell]
----
#! /usr/bin/env bash

while true
do
node ./bin/www
done
----

To prevent some systems from killing the process when you log out, run with nohup, like this.

[source,shell]
----
nohup ./server.sh < /dev/null >& server.log &
----

==== Configuring the client

Under `src/config` in the client code, update `serverURI` in the `index.js` file to point to your web server.

==== Building the client

Shift to the directory demo/web/client. Install the Node packages.

[source,shell]
----
npm install
----

Decide if you want to run the production version or development version. The development version supports hot
reloading, but currently requires running a separate development server.

To use the development server:

[source,shell]
----
npm run dev
----

You should find the pages served up on localhost:8080.

To run a production version:

[source,shell]
----
npm run build
----

You should find the pages served on localhost:3000

==== Enabling push notifications

The Node web server reads configuration parameters for Urban Airship from the shell environment. In the shell, before running the server, export the keys as follows.

[source,shell]
----
export UA_APPLICATION_KEY=
export UA_APPLICATION_MASTER_SECRET=
----

These keys come from your Urban Airship project.

=== Couchbase Server

==== Data

The file `augment-data.json` contains records hand written to work with the demo. To add these to a bucket, use (e.g.)

[source,shell]
----
cbimport json -u admin -p password -b health -c couchbase://127.0.0.1:8091 -d file://augment-data.json -g '%id%' -f lines
----

On Macs look for cbimport in `/Applications/Couchbase\ Server.app/Contents/Resources/couchbase-core/bin/`

==== Whitelisting sites for curl

The curl functionality in N1QL requires sites to be white/black listed. For this application, whitelist the Google
geocoding endpoint by creating

`/opt/couchbase/var/lib/couchbase/n1qlcerts/curl_whitelist.json`

with contents

[source,shell]
----
{
"all_access":false,
"allowed_urls":["https://maps.googleapis.com/maps/api/geocode/json"]
}
----

==== Indexes

Several queries examine resourceType and id:

[source,shell]
----
CREATE INDEX `resource-idx` ON health(resourceType, id);
----

Mapping hospitals queries on location resources and specific type codes:

[source,shell]
----
CREATE INDEX `location-idx` ON `health`(type.coding[0].code) WHERE resourceType = 'Location';
----

Monitoring incoming observations from our select patient:

[source,shell]
----
CREATE INDEX `observation-idx` ON `health`((`subject`.`reference`),`issued` DESC,(`valueQuantity`.`value`))
----

Full text search:

The full text search index definition can be found in `demo/models/fts-index.json`. Load it with something like this.

[source,shell]
----
curl -T fts-index.json http://admin:password@localhost:8094/api/index/diagnosis
----

=== Installing Couchnode from GitHub

To install from the latest

[source,shell]
----
npm install --save git+https://[email protected]/brett19/couchnode.git
----

To pin the installation to a specific commit

[source,shell]
----
npm install --save git+https://[email protected]/brett19/couchnode.git#dba79ef33b1f4e7d5e88906538624c65caf3d841
----