├── .DS_Store ├── pics ├── splash.png ├── db-auth.png ├── db-ready.png ├── metrics.png ├── db-auth-raw.png ├── db-creation-1.png ├── db-creation-2.png ├── db-creation-3.png ├── db-creation-4.png ├── db-ready-raw.png ├── swagger-home.png ├── db-initializing.png ├── graphql-readdata.png ├── playground-home.png ├── swagger-addrows.png ├── swagger-doc-get.png ├── swagger-general.png ├── swagger-listrows.png ├── swagger-readrows.png ├── graphql-insertdata.png ├── swagger-deleterows.png ├── swagger-doc-create.png ├── swagger-doc-search.png ├── swagger-list-types.png ├── swagger-searchrows.png ├── db-initializing-raw.png ├── graphql-createtables.png ├── swagger-create-table.png ├── swagger-list-keyspace.png ├── swagger-list-tables.png ├── graphql-createkeyspace.png └── swagger-doc-listnamespaces.png ├── slides └── An OSS Api Layer for your Cassandra.pdf ├── docker-compose.yml └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/.DS_Store -------------------------------------------------------------------------------- /pics/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/splash.png -------------------------------------------------------------------------------- /pics/db-auth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/db-auth.png -------------------------------------------------------------------------------- /pics/db-ready.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/db-ready.png -------------------------------------------------------------------------------- /pics/metrics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/metrics.png -------------------------------------------------------------------------------- /pics/db-auth-raw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/db-auth-raw.png -------------------------------------------------------------------------------- /pics/db-creation-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/db-creation-1.png -------------------------------------------------------------------------------- /pics/db-creation-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/db-creation-2.png -------------------------------------------------------------------------------- /pics/db-creation-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/db-creation-3.png -------------------------------------------------------------------------------- /pics/db-creation-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/db-creation-4.png -------------------------------------------------------------------------------- /pics/db-ready-raw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/db-ready-raw.png -------------------------------------------------------------------------------- /pics/swagger-home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/swagger-home.png -------------------------------------------------------------------------------- /pics/db-initializing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/db-initializing.png -------------------------------------------------------------------------------- /pics/graphql-readdata.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/graphql-readdata.png -------------------------------------------------------------------------------- /pics/playground-home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/playground-home.png -------------------------------------------------------------------------------- /pics/swagger-addrows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/swagger-addrows.png -------------------------------------------------------------------------------- /pics/swagger-doc-get.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/swagger-doc-get.png -------------------------------------------------------------------------------- /pics/swagger-general.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/swagger-general.png -------------------------------------------------------------------------------- /pics/swagger-listrows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/swagger-listrows.png -------------------------------------------------------------------------------- /pics/swagger-readrows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/swagger-readrows.png -------------------------------------------------------------------------------- /pics/graphql-insertdata.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/graphql-insertdata.png -------------------------------------------------------------------------------- /pics/swagger-deleterows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/swagger-deleterows.png -------------------------------------------------------------------------------- /pics/swagger-doc-create.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/swagger-doc-create.png -------------------------------------------------------------------------------- /pics/swagger-doc-search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/swagger-doc-search.png -------------------------------------------------------------------------------- /pics/swagger-list-types.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/swagger-list-types.png -------------------------------------------------------------------------------- /pics/swagger-searchrows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/swagger-searchrows.png -------------------------------------------------------------------------------- /pics/db-initializing-raw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/db-initializing-raw.png -------------------------------------------------------------------------------- /pics/graphql-createtables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/graphql-createtables.png -------------------------------------------------------------------------------- /pics/swagger-create-table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/swagger-create-table.png -------------------------------------------------------------------------------- /pics/swagger-list-keyspace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/swagger-list-keyspace.png -------------------------------------------------------------------------------- /pics/swagger-list-tables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/swagger-list-tables.png -------------------------------------------------------------------------------- /pics/graphql-createkeyspace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/graphql-createkeyspace.png -------------------------------------------------------------------------------- /pics/swagger-doc-listnamespaces.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/pics/swagger-doc-listnamespaces.png -------------------------------------------------------------------------------- /slides/An OSS Api Layer for your Cassandra.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-apachecon-stargate/main/slides/An OSS Api Layer for your Cassandra.pdf -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | backend-1: 5 | image: cassandra:${CASSTAG} 6 | networks: 7 | - backend 8 | ports: 9 | - 9044:9042 10 | mem_limit: 2G 11 | environment: 12 | - HEAP_NEWSIZE=128M 13 | - MAX_HEAP_SIZE=1024M 14 | - CASSANDRA_SEEDS=backend-1 15 | - CASSANDRA_CLUSTER_NAME=c3-${CASSTAG}-cluster 16 | backend-2: 17 | image: cassandra:${CASSTAG} 18 | networks: 19 | - backend 20 | mem_limit: 2G 21 | depends_on: 22 | - backend-1 23 | environment: 24 | - HEAP_NEWSIZE=128M 25 | - MAX_HEAP_SIZE=1024M 26 | - CASSANDRA_SEEDS=backend-1 27 | - CASSANDRA_CLUSTER_NAME=c3-${CASSTAG}-cluster 28 | backend-3: 29 | image: cassandra:${CASSTAG} 30 | networks: 31 | - backend 32 | mem_limit: 2G 33 | depends_on: 34 | - backend-2 35 | environment: 36 | - HEAP_NEWSIZE=128M 37 | - MAX_HEAP_SIZE=1024M 38 | - CASSANDRA_SEEDS=backend-1 39 | - CASSANDRA_CLUSTER_NAME=c3-${CASSTAG}-cluster 40 | stargate: 41 | image: stargateio/stargate-3_11:${SGTAG} 42 | depends_on: 43 | - backend-1 44 | networks: 45 | - backend 46 | ports: 47 | - 9045:9042 48 | - 8080:8080 49 | - 8081:8081 50 | - 8082:8082 51 | - 8084:8084 52 | mem_limit: 2G 53 | environment: 54 | - JAVA_OPTS="-Xmx2G" 55 | - CLUSTER_NAME=c3-${CASSTAG}-cluster 56 | - CLUSTER_VERSION=3.11 57 | - SEED=backend-1 58 | - RACK_NAME=rack1 59 | - DATACENTER_NAME=datacenter1 60 | - ENABLE_AUTH=true 61 | networks: 62 | backend: 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 🎓🔥 An OSS Api Layer for your Cassandra 🔥🎓 2 | 3 | [![License Apache2](https://img.shields.io/hexpm/l/plug.svg)](http://www.apache.org/licenses/LICENSE-2.0) 4 | [![Discord](https://img.shields.io/discord/685554030159593522)](https://discord.com/widget?id=685554030159593522&theme=dark) 5 | 6 | ![image](pics/splash.png?raw=true) 7 | 8 | ## Table of content 9 | 10 | 1. [Prerequisites](#1-prerequisite-install-docker-and-docker-compose) 11 | 2. [Start the Demo](#2-start-the-demo) 12 | 3. [Use CQL API](#3-use-cql-api) 13 | 4. [Use REST API](#4-use-rest-api) 14 | 5. [Use Document API](#5-use-document-api-swagger) 15 | 6. [Use GraphQL API](#6-use-graphql-api-portal) 16 | 7. [Create an Astra Instance](#7-create-your-astra-instance) 17 | 18 | ## 1. Prerequisite, Install docker and docker-compose ## 19 | 20 | To run the demo you need `docker` and `docker-compose`. Skip this steps if you have them available already 21 | 22 | ### 1.1 Install Docker 23 | 24 | Docker is an open-source project that automates the deployment of software applications inside containers by providing an additional layer of abstraction and automation of OS-level virtualization on Linux. 25 | 26 | ![Windows](https://github.com/DataStax-Academy/kubernetes-workshop-online/blob/master/4-materials/images/windows32.png?raw=true) : To install on **windows** please use the following installer [Docker Desktop for Windows Installer](https://download.docker.com/win/stable/Docker%20Desktop%20Installer.exe) 27 | 28 | ![osx](https://github.com/DataStax-Academy/kubernetes-workshop-online/blob/master/4-materials/images/mac32.png?raw=true) : To install on **MAC OS** use [Docker Desktop for MAC Installer](https://download.docker.com/mac/stable/Docker.dmg) or [homebrew](https://docs.brew.sh/Installation) with following commands: 29 | ```bash 30 | # Fetch latest version of homebrew and formula. 31 | brew update 32 | # Tap the Caskroom/Cask repository from Github using HTTPS. 33 | brew tap caskroom/cask 34 | # Searches all known Casks for a partial or exact match. 35 | brew search docker 36 | # Displays information about the given Cask 37 | brew cask info docker 38 | # Install the given cask. 39 | brew cask install docker 40 | # Remove any older versions from the cellar. 41 | brew cleanup 42 | # Validate installation 43 | docker -v 44 | ``` 45 | 46 | ![linux](https://github.com/DataStax-Academy/kubernetes-workshop-online/blob/master/4-materials/images/linux32.png?raw=true) : To install on linux (centOS) you can use the following commands 47 | ```bash 48 | # Remove if already install 49 | sudo yum remove docker \ 50 | docker-client \ 51 | docker-client-latest \ 52 | docker-common \ 53 | docker-latest \ 54 | docker-latest-logrotate \ 55 | docker-logrotate \ 56 | docker-engine 57 | # Utils 58 | sudo yum install -y yum-utils 59 | 60 | # Add docker-ce repo 61 | sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo 62 | # Install 63 | sudo dnf -y install docker-ce --nobest 64 | # Enable service 65 | sudo systemctl enable --now docker 66 | # Get Status 67 | systemctl status docker 68 | 69 | # Logout....Lougin 70 | exit 71 | # Create user 72 | sudo usermod -aG docker $USER 73 | newgrp docker 74 | 75 | # Validation 76 | docker images 77 | docker run hello-world 78 | docker -v 79 | ``` 80 | [🏠 Back to Table of Contents](#Table-Of-content) 81 | 82 | ### 1.2 Install Docker Compose 83 | 84 | Docker Compose is a tool for defining and running multi-container Docker applications. It uses YAML files to configure the application's services and performs the creation and start-up process of all the containers with a single command. The `docker-compose` CLI utility allows users to run commands on multiple containers at once, for example, building images, scaling containers, running containers that were stopped, and more. Please refer to [Reference Documentation](https://docs.docker.com/compose/install/) if you have for more detailed instructions. 85 | 86 | ![Windows](https://github.com/DataStax-Academy/kubernetes-workshop-online/blob/master/4-materials/images/windows32.png?raw=true) : Already **included** in the previous package *Docker for Windows* 87 | 88 | ![osx](https://github.com/DataStax-Academy/kubernetes-workshop-online/blob/master/4-materials/images/mac32.png?raw=true) : Already **included** in the previous package *Docker for Mac* 89 | 90 | ![linux](https://github.com/DataStax-Academy/kubernetes-workshop-online/blob/master/4-materials/images/linux32.png?raw=true) : To install on linux (centOS) you can use the following commands 91 | 92 | ```bash 93 | # Download deliverable and move to target location 94 | sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose 95 | 96 | # Allow execution 97 | sudo chmod +x /usr/local/bin/docker-compose 98 | ``` 99 | 100 | ### 1.3 Install curl 101 | 102 | [Reference Article](https://help.ubidots.com/en/articles/2165289-learn-how-to-install-run-curl-on-windows-macosx-linux) 103 | 104 | ![Windows](https://github.com/DataStax-Academy/kubernetes-workshop-online/blob/master/4-materials/images/windows32.png?raw=true) : Already **included** as stated [here](https://www.thewindowsclub.com/how-to-install-curl-on-windows-10) 105 | 106 | ![osx](https://github.com/DataStax-Academy/kubernetes-workshop-online/blob/master/4-materials/images/mac32.png?raw=true) : Use brew 107 | 108 | ``` 109 | brew install curl 110 | ``` 111 | 112 | ![linux](https://github.com/DataStax-Academy/kubernetes-workshop-online/blob/master/4-materials/images/linux32.png?raw=true) :Use your package installer like `yum` or apt-get 113 | 114 | ``` 115 | sudo apt-get install curl 116 | ``` 117 | 118 | [🏠 Back to Table of Contents](#table-of-content) 119 | 120 | 121 | ## 2. Start the demo 122 | 123 | #### ✅ 2a. Clone the repository 124 | 125 | Download the repository as a zip [here](https://github.com/datastaxdevs/conference-2021-apachecon-stargate/archive/refs/heads/main.zip) or clone with the following git command 126 | 127 | ```bash 128 | git clone https://github.com/datastaxdevs/conference-2021-apachecon-stargate.git 129 | ``` 130 | 131 | #### ✅ 2b. Start `backend-1` 132 | 133 | We provide a `docker-compose.yaml` file ready to go with a `Cassandra 3.11.8` backend and stargate in version `1.0.34` 134 | 135 | ```bash 136 | export CASSTAG=3.11.8 137 | export SGTAG=v1.0.34 138 | docker-compose up -d backend-1 139 | ``` 140 | 141 | #### ✅ 2c. When the bootstrap is completed, Start node2 with `docker-compose` 142 | 143 | ```bash 144 | docker-compose up -d backend-2 145 | ``` 146 | 147 | #### ✅ 2d. When the bootstrap is completed, Start node3 with `docker-compose` 148 | 149 | ```bash 150 | docker-compose up -d backend-3 151 | ```` 152 | 153 | #### ✅ 2e. Check status of your nodes with `nodetool` 154 | 155 | ```bash 156 | docker exec -it `docker ps | grep backend-1 | cut -b 1-12` nodetool status 157 | ``` 158 | 159 | #### ✅ 2f. Extract IP of `backend-1` as variable `backend1ip` 160 | 161 | - Extract variable 162 | ```bash 163 | export backend1ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' `docker ps | grep backend-1 | cut -b 1-12`) 164 | ``` 165 | 166 | - Check that we are OK 167 | ```bash 168 | echo $backend1ip 169 | ``` 170 | 171 | #### ✅ 2g. Connect as `CQLSH` using the new created var 172 | 173 | ```bash 174 | docker exec -it `docker ps | grep backend-1 | cut -b 1-12` cqlsh $backend1ip -u cassandra -p cassandra 175 | ``` 176 | 177 | #### ✅ 2h. Create Keyspace `data_endpoint_auth` 178 | 179 | The stargate node executes query with `LOCAL_QUORUM`, the table handling the token `data_endpoint_auth` must have a replication factory of 3. 180 | The datacenter used everywhere is `datacenter1` 181 | Also here we create an sample keyspace `ks1` for tests. 182 | 183 | - Create keyspace 184 | 185 | ```sql 186 | DROP KEYSPACE IF EXISTS data_endpoint_auth; 187 | CREATE KEYSPACE data_endpoint_auth WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1': '3'} AND durable_writes = true; 188 | ``` 189 | 190 | - Exit CQLSH 191 | ``` 192 | exit 193 | ``` 194 | 195 | #### ✅ 2i. Start Stargate Node 196 | 197 | - Start the node 198 | ``` 199 | docker-compose up -d stargate 200 | ``` 201 | 202 | - Wait for the node to be up 203 | ``` 204 | echo "Waiting for stargate to start up..." 205 | while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:8082/health)" != "200" ]]; do 206 | printf '.' 207 | sleep 5 208 | done 209 | ``` 210 | 211 | #### ✅ 2j. Wait for the node to bootstrap and get IP 212 | 213 | - Extract variable 214 | ``` 215 | export stargateip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' `docker ps | grep stargateio | cut -b 1-12`) 216 | ``` 217 | 218 | - check we are OK 219 | ``` 220 | echo $stargateip 221 | ``` 222 | 223 | #### ✅ 2k. Check we are all GOOD 224 | 225 | ``` 226 | echo "Check Status...." 227 | echo "Backend-1 IP: $backend1ip" 228 | echo "Stargate IP: $stargateip" 229 | docker ps 230 | docker exec -it `docker ps | grep backend-1 | cut -b 1-12` nodetool status 231 | ``` 232 | 233 | **👁️ Expected output** 234 | 235 | ```bash 236 | Check Status.... 237 | Backend-1 IP: 172.19.0.2 238 | Stargate IP: 172.19.0.5 239 | 240 | PROMPT> docker ps 241 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 242 | 2200f5c86bfd stargateio/stargate-3_11:v1.0.34 "./starctl" 3 hours ago Up 3 hours 0.0.0.0:8080-8082->8080-8082/tcp, :::8080-8082->8080-8082/tcp, 0.0.0.0:8084->8084/tcp, :::8084->8084/tcp, 0.0.0.0:9045->9042/tcp, :::9045->9042/tcp cassandra-3_stargate_1 243 | 16cb48746e72 cassandra:3.11.8 "docker-entrypoint.s…" 3 hours ago Up 3 hours 7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp cassandra-3_backend-3_1 244 | 31bd64f67237 cassandra:3.11.8 "docker-entrypoint.s…" 3 hours ago Up 3 hours 7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp cassandra-3_backend-2_1 245 | 835408a3d2d0 cassandra:3.11.8 "docker-entrypoint.s…" 3 hours ago Up 3 hours 7000-7001/tcp, 7199/tcp, 9160/tcp, 0.0.0.0:9044->9042/tcp, :::9044->9042/tcp cassandra-3_backend-1_1 246 | 247 | PROMPT> docker exec -it `docker ps | grep backend-1 | cut -b 1-12` nodetool status 248 | 249 | Datacenter: datacenter1 250 | ======================= 251 | Status=Up/Down 252 | |/ State=Normal/Leaving/Joining/Moving 253 | -- Address Load Tokens Owns (effective) Host ID Rack 254 | UN 172.19.0.3 355.37 KiB 256 100.0% 75b42435-3197-42ed-bdd8-fdb00294865b rack1 255 | UN 172.19.0.2 331.99 KiB 256 100.0% 45a33f3a-9115-4878-a1c2-54d00b4c3ff0 rack1 256 | UN 172.19.0.4 320.44 KiB 256 100.0% 9cb00b9d-3bc6-44bb-95a8-e0152d9db9f8 rack1 257 | 258 | ``` 259 | 260 | - You should be able to access the GRAPHQL Playground on [http://localhost:8080/playground](http://localhost:8080/playground) 261 | 262 | **👁️ Expected output** 263 | ![image](pics/playground-home.png?raw=true) 264 | 265 | - You should be able to access the Swagger UI on [http://localhost:8082/swagger-ui/#/](http://localhost:8082/swagger-ui/#/) 266 | 267 | **👁️ Expected output** 268 | ![image](pics/swagger-home.png?raw=true) 269 | 270 | - You should be able to access the Metrics UI [http://localhost:8084/metrics](http://localhost:8084/metrics) 271 | 272 | **👁️ Expected output** 273 | ![image](pics/metrics.png?raw=true) 274 | 275 | [🏠 Back to Table of Contents](#table-of-content) 276 | 277 | ## 3. Use CQL API 278 | 279 | #### ✅ 3a. Start CQLSH 280 | 281 | - Use this IP to connect with a cqlsh. *Note that the stargate image itself does not provide it we use the cqlsh from backend-1 as a sample client.* 282 | 283 | ```bash 284 | docker exec -it `docker ps | grep backend-1 | cut -b 1-12` cqlsh $stargateip -u cassandra -p cassandra 285 | ``` 286 | 287 | #### ✅ 3b. Create your schema 288 | 289 | ```sql 290 | CREATE KEYSPACE ks1 WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1': '3'} AND durable_writes = true; 291 | 292 | use ks1; 293 | 294 | CREATE TYPE IF NOT EXISTS video_format ( 295 | width int, 296 | height int 297 | ); 298 | 299 | CREATE TABLE IF NOT EXISTS videos ( 300 | videoid uuid, 301 | title text, 302 | upload timestamp, 303 | email text, 304 | url text, 305 | tags set , 306 | frames list, 307 | formats map >, 308 | PRIMARY KEY (videoid) 309 | ); 310 | 311 | describe ks1 312 | ``` 313 | 314 | #### ✅ 3c. Populate some data 315 | 316 | - Insert value using plain CQL 317 | 318 | ```sql 319 | INSERT INTO videos(videoid, email, title, upload, url, tags, frames, formats) 320 | VALUES(uuid(), 'clu@sample.com', 'sample video', 321 | toTimeStamp(now()), 'http://google.fr', 322 | { 'cassandra','accelerate','2020'}, 323 | [ 1, 2, 3, 4], 324 | { 'mp4':{width:1,height:1},'ogg':{width:1,height:1}}); 325 | ``` 326 | 327 | - Insert Value using JSON 328 | 329 | ```sql 330 | INSERT INTO videos JSON '{ 331 | "videoid":"e466f561-4ea4-4eb7-8dcc-126e0fbfd573", 332 | "email":"clunven@sample.com", 333 | "title":"A Second videos", 334 | "upload":"2020-02-26 15:09:22 +00:00", 335 | "url": "http://google.fr", 336 | "frames": [1,2,3,4], 337 | "tags": [ "cassandra","accelerate", "2020"], 338 | "formats": { 339 | "mp4": {"width":1,"height":1}, 340 | "ogg": {"width":1,"height":1} 341 | } 342 | }'; 343 | ``` 344 | 345 | - Read values 346 | 347 | ```sql 348 | select * from videos; 349 | ``` 350 | 351 | - Read by id 352 | ```sql 353 | select * from videos where videoid=e466f561-4ea4-4eb7-8dcc-126e0fbfd573; 354 | ``` 355 | 356 | - Quit `cqlsh` 357 | 358 | ```sql 359 | exit 360 | ``` 361 | 362 | [🏠 Back to Table of Contents](#table-of-content) 363 | 364 | ## 4. Use REST API 365 | 366 | This walkthrough has been realized using the [REST API Quick Start](https://stargate.io/docs/stargate/0.1/quickstart/quick_start-rest.html). Here we will the the [DATA](http://localhost:8082/swagger-ui/#/data) or SwaggerUI 367 | 368 | ![image](pics/swagger-general.png?raw=true) 369 | 370 | #### ✅ 4a. Generate an auth token 371 | 372 | ```bash 373 | curl -L -X POST 'http://localhost:8081/v1/auth' \ 374 | -H 'Content-Type: application/json' \ 375 | --data-raw '{ 376 | "username": "cassandra", 377 | "password": "cassandra" 378 | }' 379 | ``` 380 | 381 | Copy the token value (here `74be42ef-3431-4193-b1c1-cd8bd9f48132`) in your clipboard. 382 | 383 | **👁️ Expected output** 384 | ``` 385 | {"authToken":"74be42ef-3431-4193-b1c1-cd8bd9f48132"} 386 | ``` 387 | 388 | #### ✅ 4b. List keyspaces 389 | 390 | - [`GET: /v2/schemas/keyspaces`](http://localhost:8082/swagger-ui/#/schemas/getAllKeyspaces) 391 | 392 | ![image](pics/swagger-list-keyspace.png?raw=true) 393 | 394 | - Click `Try it out` 395 | - Provide your token in the field `X-Cassandra-Token` 396 | - Click on `Execute` 397 | 398 | 399 | #### ✅ 4c. List Tables 400 | 401 | - [GET /v2/schemas/keyspaces/{keyspaceName}/tables](http://localhost:8082/swagger-ui/#/schemas/getAllTables) 402 | 403 | ![image](pics/swagger-list-tables.png?raw=true) 404 | 405 | - Click `Try it out` 406 | - Provide your token in the field `X-Cassandra-Token` 407 | - keyspace: `ks1` 408 | - Click on `Execute` 409 | 410 | 411 | #### ✅ 4d. List Types 412 | 413 | - [GET /v2/schemas/keyspaces/{keyspaceName}/types](http://localhost:8082/swagger-ui/#/schemas/findAll) 414 | 415 | ![image](pics/swagger-list-types.png?raw=true) 416 | 417 | - Click `Try it out` 418 | - X-Cassandra-Token: `` 419 | - keyspace: `ks1` 420 | - Click on `Execute` 421 | 422 | #### ✅ 4e Create a Table 423 | 424 | - [POST /v2/schemas/keyspaces/{keyspaceName}/tables](http://localhost:8082/swagger-ui/#/schemas/createTable) 425 | 426 | ![image](pics/swagger-create-table.png?raw=true) 427 | 428 | - Click `Try it out` 429 | - X-Cassandra-Token: `` 430 | - keyspace: `ks1` 431 | - Data 432 | ```json 433 | { 434 | "name": "users", 435 | "columnDefinitions": 436 | [ 437 | { 438 | "name": "firstname", 439 | "typeDefinition": "text" 440 | }, 441 | { 442 | "name": "lastname", 443 | "typeDefinition": "text" 444 | }, 445 | { 446 | "name": "email", 447 | "typeDefinition": "text" 448 | }, 449 | { 450 | "name": "color", 451 | "typeDefinition": "text" 452 | } 453 | ], 454 | "primaryKey": 455 | { 456 | "partitionKey": ["firstname"], 457 | "clusteringKey": ["lastname"] 458 | }, 459 | "tableOptions": 460 | { 461 | "defaultTimeToLive": 0, 462 | "clusteringExpression": 463 | [{ "column": "lastname", "order": "ASC" }] 464 | } 465 | } 466 | ``` 467 | 468 | **👁️ Expected output** 469 | 470 | ```json 471 | { 472 | "name": "users" 473 | } 474 | ``` 475 | 476 | #### ✅ 4f. Insert Rows 477 | 478 | *Notice than for the DML you move to `DATA`. Make sure you are using url with `V2`, `V1` would also work but this is NOT the same payload.* 479 | 480 | - [POST /v2/keyspaces/{keyspaceName}/{tableName}](http://localhost:8082/swagger-ui/#/data/createRow) 481 | 482 | ![image](pics/swagger-addrows.png?raw=true) 483 | 484 | - X-Cassandra-Token: `` 485 | - keyspaceName: `ks1` 486 | - tableName: `users` 487 | - Data 488 | ```json 489 | { 490 | "firstname": "Cedrick", 491 | "lastname": "Lunven", 492 | "email": "c.lunven@gmail.com", 493 | "color": "blue" 494 | } 495 | ``` 496 | 497 | You can note that the output code is `201` and return your primary key `{ "firstname": "Cedrick","lastname": "Lunven" } 498 | 499 | - You can add a second record changing only the payload 500 | ```json 501 | { 502 | "firstname": "David", 503 | "lastname": "Gilardi", 504 | "email": "d.gilardi@gmail.com", 505 | "color": "blue" 506 | } 507 | ``` 508 | 509 | - Add a third 510 | ```json 511 | { 512 | "firstname": "Kirsten", 513 | "lastname": "Hunter", 514 | "email": "k.hunter@gmail.com", 515 | "color": "pink" 516 | } 517 | ``` 518 | 519 | #### ✅ 4g. Read multiple rows 520 | 521 | - [GET /v2/keyspaces/{keyspaceName}/{tableName}/rows](http://localhost:8082/swagger-ui/#/data/getAllRows_1) 522 | ![image](pics/swagger-listrows.png?raw=true) 523 | 524 | - X-Cassandra-Token: `` 525 | - keyspaceName: `ks1` 526 | - tableName: `users` 527 | - Click Execute 528 | 529 | - Notice how now you can only limited return fields 530 | 531 | - fields: `firstname, lastname` 532 | 533 | #### ✅ 4h. Read a single partition 534 | 535 | - [GET /v2/keyspaces/{keyspaceName}/{tableName}/{primaryKey}](http://localhost:8082/swagger-ui/#/data/getRows_1) 536 | 537 | ![image](pics/swagger-readrows.png?raw=true) 538 | 539 | - X-Cassandra-Token: `` 540 | - keyspaceName: `ks1` 541 | - tableName: `users` 542 | - primaryKey; 'Cedrick` 543 | - Click Execute 544 | 545 | ```diff 546 | - Important: The Swagger user interface is limited as of now and you cannot test a composite key (here adding Lunven). This is a bug in the UI not the API. 547 | ``` 548 | 549 | #### ✅ 4i. Delete a row 550 | 551 | - [DELETE /v2/keyspaces/{keyspaceName}/{tableName}/{primaryKey}](http://localhost:8082/swagger-ui/#/data/deleteRows) 552 | 553 | ![image](pics/swagger-deleterows.png?raw=true) 554 | 555 | - X-Cassandra-Token: `` 556 | - keyspaceName: `ks1` 557 | - tableName: `users` 558 | - primaryKey; 'Cedrick` 559 | - Click Execute 560 | 561 | #### ✅ 4j. Searches 562 | 563 | - [GET /v2/keyspaces/{keyspaceName}/{tableName}](http://localhost:8082/swagger-ui/#/data/getRowWithWhere) 564 | 565 | ![image](pics/swagger-searchrows.png?raw=true) 566 | 567 | 568 | - X-Cassandra-Token: `` 569 | - keyspaceName: `ks1` 570 | - tableName: `users` 571 | - whereClause; '{"firstname": {"$eq":"David"}}` 572 | - Click Execute 573 | 574 | I let you try with `{"lastname": {"$eq":"Gilardi"}}`.. expected right ? 575 | 576 | 577 | [🏠 Back to Table of Contents](#table-of-content) 578 | 579 | ## 5. Use Document API (swagger+curl) 580 | 581 | This walkthrough has been realized using the [Quick Start](https://stargate.io/docs/stargate/0.1/quickstart/quick_start-document.html) 582 | 583 | 584 | 585 | **✅ 5a. List Namespaces** : 586 | 587 | ![image](pics/swagger-doc-listnamespaces.png?raw=true) 588 | 589 | 590 | **✅ 5b. Create a document** : 591 | 592 | *Note: operations requiring providing `namespace` and `collections` on the swagger UI seems not functional. We are switching to CURL the API is working, this is a documentation bug that has been notified to the development team.* 593 | 594 | ![image](pics/swagger-doc-create.png?raw=true) 595 | 596 | 597 | ```json 598 | { 599 | "videoid":"e466f561-4ea4-4eb7-8dcc-126e0fbfd573", 600 | "email":"clunven@sample.com", 601 | "title":"A Second videos", 602 | "upload":"2020-02-26 15:09:22 +00:00", 603 | "url": "http://google.fr", 604 | "frames": [1,2,3,4], 605 | "tags": [ "cassandra","accelerate", "2020"], 606 | "formats": { 607 | "mp4": {"width":1,"height":1}, 608 | "ogg": {"width":1,"height":1} 609 | } 610 | } 611 | ``` 612 | 613 | **✅ 5c. Retrieve documents** : 614 | 615 | ![image](pics/swagger-doc-search.png?raw=true) 616 | 617 | 618 | 619 | **✅ 5d. Retrieve 1 document** : 620 | 621 | ![image](pics/swagger-doc-get.png?raw=true) 622 | 623 | 624 | **✅ 5e. Search for document by properties** : 625 | 626 | 627 | ![image](pics/swagger-doc-search.png?raw=true) 628 | 629 | - WhereClause 630 | 631 | ```json 632 | {"email": {"$eq": "clunven@sample.com"}} 633 | ``` 634 | 635 | [🏠 Back to Table of Contents](#table-of-content) 636 | 637 | ## 6. Use GraphQL API (portal) 638 | 639 | This walkthrough has been realized using the [GraphQL Quick Start](https://stargate.io/docs/stargate/0.1/quickstart/quick_start-graphql.html) 640 | 641 | Same as Rest API generate a `auth token` 642 | 643 | **✅ 6a Generate Auth token** : 644 | ```bash 645 | curl -L -X POST 'http://localhost:8081/v1/auth' \ 646 | -H 'Content-Type: application/json' \ 647 | --data-raw '{ 648 | "username": "cassandra", 649 | "password": "cassandra" 650 | }' 651 | ``` 652 | 653 | Save output as an environment variable 654 | ``` 655 | export AUTH_TOKEN=7c37bda5-7360-4d39-96bc-9765db5773bc 656 | ``` 657 | 658 | **✅ 6b. Open GraphQL Playground** : 659 | 660 | - You should be able to access the GRAPH QL PORTAL on [http://localhost:8080/playground](http://localhost:8080/playground) 661 | 662 | You can check on the right of the playground that you have access to documentation and schema which is the neat part about graphQL 663 | 664 | **👁️ Expected output** 665 | ![image](pics/playground-home.png?raw=true) 666 | 667 | **✅ 6c. Creating a Table** : 668 | 669 | - Use this query 670 | ``` 671 | mutation { 672 | books: createTable( 673 | keyspaceName:"library", 674 | tableName:"books", 675 | partitionKeys: [ # The keys required to access your data 676 | { name: "title", type: {basic: TEXT} } 677 | ] 678 | values: [ # The values associated with the keys 679 | { name: "author", type: {basic: TEXT} } 680 | ] 681 | ) 682 | authors: createTable( 683 | keyspaceName:"library", 684 | tableName:"authors", 685 | partitionKeys: [ 686 | { name: "name", type: {basic: TEXT} } 687 | ] 688 | clusteringKeys: [ # Secondary key used to access values within the partition 689 | { name: "title", type: {basic: TEXT}, order: "ASC" } 690 | ] 691 | ) 692 | } 693 | ``` 694 | 695 | **👁️ Expected output** 696 | ![image](pics/graphql-createtables.png?raw=true) 697 | 698 | **✅ 6d. Populating Table** : 699 | 700 | Any of the created APIs can be used to interact with the GraphQL data, to write or read data. 701 | 702 | First, let’s navigate to your new keyspace `library` inside the playground. Change tab to `graphql` and pick url `/graphql/library`. 703 | 704 | - Use this query 705 | ``` 706 | mutation { 707 | moby: insertBooks(value: {title:"Moby Dick", author:"Herman Melville"}) { 708 | value { 709 | title 710 | } 711 | } 712 | catch22: insertBooks(value: {title:"Catch-22", author:"Joseph Heller"}) { 713 | value { 714 | title 715 | } 716 | } 717 | } 718 | ``` 719 | 720 | - Don't forget to update the header again 721 | ``` 722 | { 723 | "x-cassandra-token":"7c37bda5-7360-4d39-96bc-9765db5773bc" 724 | } 725 | ``` 726 | **👁️ Expected output** 727 | ![image](pics/graphql-insertdata.png?raw=true) 728 | 729 | 730 | **✅ 6e. Read data** : 731 | 732 | Stay on the same screen and sinmply update the query with 733 | ``` 734 | query oneBook { 735 | books (value: {title:"Moby Dick"}) { 736 | values { 737 | title 738 | author 739 | } 740 | } 741 | } 742 | ``` 743 | 744 | **👁️ Expected output** 745 | ![image](pics/graphql-readdata.png?raw=true) 746 | 747 | 748 | [🏠 Back to Table of Contents](#table-of-content) 749 | 750 | ## 7. Create your ASTRA Instance 751 | 752 | **✅ Create an free-forever Cassandra database with DataStax Astra**: [click here to get started](https://astra.datastax.com/register?utm_source=github&utm_medium=referral&utm_campaign=spring-petclinic-reactive) 🚀 753 | 754 | 755 | ![Astra Registration Screen](pics/db-auth.png?raw=true) 756 | 757 | 758 | **✅ Use the form to create new database** 759 | 760 | On the Astra home page locate the **Add Database** button 761 | 762 | ![Astra Database Creation Form](pics/db-creation-1.png?raw=true) 763 | 764 | Select the **free tier** plan, this is a true free tier, free forever and no payment method asked 🎉 🎉 765 | 766 | ![Astra Database Creation Form](pics/db-creation-2.png?raw=true) 767 | 768 | Select the proper region and click the `configure` button. The number of regions and cloud providers are limited in the free tier but please notice you can run the DB on any cloud with any VPC Peering. 769 | 770 | ![Astra Database Creation Form](pics/db-creation-3.png?raw=true) 771 | 772 | Fill the `database name`, `keyspace name`, `username` and `password`. *Please remember your password as you will be asked to provide it when application start the first time.* 773 | 774 | ![Astra Database Creation Form](pics/db-creation-4.png?raw=true) 775 | 776 | **✅ View your Database and connect** 777 | 778 | View your database. It may take 2-3 minutes for your database to spin up. You will receive an email at that point. 779 | 780 | **👁️ Expected output** 781 | 782 | *Initializing* 783 | 784 | ![my-pic](https://github.com/datastaxdevs/shared-assets/blob/master/astra/dashboard-pending-1000.png?raw=true) 785 | 786 | Once the database is ready, notice how the status changes from `pending` to `Active` and Astra enables the **connect** button. 787 | 788 | ![my-pic](https://github.com/datastaxdevs/shared-assets/blob/master/astra/dashboard-withdb-1000.png?raw=true) 789 | 790 | --------------------------------------------------------------------------------