Skip to content

Commit

Permalink
changed the binary run sample apps to yugastore-java (#107)
Browse files Browse the repository at this point in the history
* changed the binary run sample apps to yugastore-java

* updated the cql compatibility faq as per karthik's feedback
  • Loading branch information
schoudhury authored May 30, 2019
1 parent c5827ad commit 2590c11
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ This repository has a Spring Boot example that implements a simple REST API serv

The source for the above application can be found in the [repo](https://github.com/YugaByte/orm-examples/tree/master/java/spring/src/main/java/com/yugabyte/springdemo).

There are a number of options that can be customized in the properties file located at `src/main/resources/application.properties`. Note that the `spring.datasource.url` defaults to the YSQL JDBC url `jdbc:postgresql://localhost:5433/postgres`.
There are a number of options that can be customized in the properties file located at `src/main/resources/application.properties`. Given YSQL's compatibility with the PostgreSQL language, the `spring.jpa.database` property is set to `POSTGRESQL` and the `spring.datasource.url` is set to the YSQL JDBC url `jdbc:postgresql://localhost:5433/postgres`.


## Build the app
Expand Down Expand Up @@ -242,4 +242,8 @@ $ curl http://localhost:8080/orders
],
...
}
```
```

## Explore the source

As highlighted earlier, the source for the above application can be found in the [orm-examples](https://github.com/YugaByte/orm-examples/tree/master/java/spring/src/main/java/com/yugabyte/springdemo) repo.
24 changes: 22 additions & 2 deletions docs/content/latest/faq/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ showAsideToc: true

API compatibility refers to the fact that the database APIs offered by YugaByte DB servers implement the same wire protocol and modeling/query language as that of an existing database. Since client drivers, command line shells, IDE integrations and other ecosystem integrations of the existing database rely on this wire protocol and modeling/query language, they are expected to work with YugaByte DB without major modifications.

For example, the [YSQL](../../api/ysql) API is compatible with PostgreSQL. This means PostgreSQL client drivers, psql command line shell, IDE integrations such as TablePlus and DBWeaver and more can be used with YugaByte DB. The same concept applies to [YCQL](../../api/ycql) in the context of the Apache Cassandra Query Language.
{{< note title="Note" >}}
The [YSQL](../../api/ysql) API is compatible with PostgreSQL. This means PostgreSQL client drivers, psql command line shell, IDE integrations such as TablePlus and DBWeaver and more can be used with YugaByte DB. The same concept applies to [YCQL](../../api/ycql) in the context of the Apache Cassandra Query Language.
{{< /note >}}

## Why are YugaByte DB APIs compatible with popular DB languages?

Expand All @@ -43,6 +45,24 @@ YugaByte DB's goal is to remain as compatible with PostgreSQL as possible. If yo

## YCQL Compatibility with Apache Cassandra QL

### List the features where YCQL goes beyond Apache Cassandra QL.

- Following are the features that are present in YCQL but not present in Apache Cassandra QL.

1. [JSONB](../../develop/learn/data-types/) column type for modeling document data
2. [Distributed transactions](../../develop/learn/acid-transactions/) for multi-row ACID transactions
3. [Official Jepsen tests](https://blog.yugabyte.com/yugabyte-db-1-2-passes-jepsen-testing/) to prove correctness under extreme failure conditions

- Following are the features that are present in both YCQL and Apache Cassandra QL but YCQL provides stricter guarantees.

1. [Secondary indexes](../../develop/learn/data-modeling/) are by default strongly consistent since internally they use distributed transactions.
2. [INTEGER](../../api/ycql/type_int/) and [COUNTER](../../api/ycql/type_int/) datatypes are equivalent and both can be incremented without any lightweight transactions.

- Following are the features that are either unnecessary or disallowed in YCQL.

1. Lightweight transactions for compare-and-swap operations (such as increment) are unnecessary because YCQL achieves single row linearizability by default.
2. Tunable write consistency is disallowed in YCQL because writes are committed at quorum using Raft replication protocol.

### Do INSERTs do “upserts” by default? How do I insert data only if it is absent?

By default, inserts overwrite data on primary key collisions. So INSERTs do an upsert. This an intended CQL feature. In order to insert data only if the primary key is not already present, add a clause "IF NOT EXISTS" to the INSERT statement. This will cause the INSERT fail if the row exists.
Expand All @@ -63,7 +83,7 @@ Yes, you can have collection data types as primary keys as long as they are mark

Unlike Apache Cassandra, YugaByte COUNTER type is almost the same as INTEGER types. There is no need of lightweight transactions requiring 4 round trips to perform increments in YugaByte - these are efficiently performed with just one round trip.

### How is 'USING TIMESTAMP' different in YugaByte?
### How is 'USING TIMESTAMP' different in YugaByte DB?

In Apache Cassandra, the highest timestamp provided always wins. Example:

Expand Down
3 changes: 1 addition & 2 deletions docs/content/latest/quick-start/binary/explore-ysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
Run ysqlsh to connect to the service.

```sh
$ ./bin/ysqlsh -h 127.0.0.1 -p 5433 -U postgres --echo-queries
$ ./bin/ysqlsh --echo-queries
```

```
ysqlsh (11.2)
Type "help" for help.
Expand Down
110 changes: 72 additions & 38 deletions docs/content/latest/quick-start/binary/run-sample-apps.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,125 @@
[Yugastore-java](https://github.com/YugaByte/yugastore-java) app is an end-to-end ecommerce application built using a microservices design pattern. React UI, Spring Boot app framework and YugaByte DB (both YSQL and YCQL) are used as the underlying technology stack.

## 1. Create cluster

Create a cluster.

```sh
$ ./bin/yb-ctl --rf 3 create
$ ./bin/yb-ctl create
```
Clients can now connect to the YSQL API at `localhost:5433` and YCQL API at `localhost:9042`.

Setup the redis_keyspace keyspace and the .redis table so that this cluster becomes ready for redis clients. Detailed output for the setup_redis command is available in the [yb-ctl Reference](../../admin/yb-ctl/#setup-redis).
## 2. Install Yugastore

Clone the repo.
```sh
$ ./bin/yb-ctl setup_redis
$ git clone https://github.com/YugaByte/yugastore-java.git
```

Clients can now connect to the YSQL API at `localhost:5433`, YCQL API at `localhost:9042` and YEDIS API at `localhost:6379`.

## 2. Install Yugastore

You can do this as shown below.

```sh
$ git clone https://github.com/YugaByte/yugastore.git
$ cd yugastore-java
```

Create the app binaries.
```sh
$ cd yugastore
$ mvn -DskipTests package
```

Create the app's schema in YugaByte DB.
```sh
$ npm install
$ cd resources
```

Note that the `config.json` in the `yugastore` directory stores the connection parameters for YugaByte DB. If you are running YugaByte DB in a different configuration, then you will need to change these parameters.

```sh
$ $YUGABYTE_HOME/bin/ysqlsh -f schema.sql
```
{
"DB_HOST": "127.0.0.1",
"APP_HOST": "localhost",
"APP_PORT": "3001"
}
```sh
$ $YUGABYTE_HOME/bin/cqlsh -f schema.cql
```

Load the initial data of the Yugastore app into YugaByte DB.
Load the initial data.
```sh
$ node models/yugabyte/db_init.js
$ ./dataload.sh
```

Start the REST API server.
## 3. Start the app

Start the Eureka discovery service. After starting, verify that the service is running at http://localhost:8761/.
```sh
$ npm start
$ cd eureka-server-local/ && mvn spring-boot:run
```

Start the web server.
Start the API gateway microservice.
```sh
$ cd api-gateway-microservice/ && mvn spring-boot:run
```

Start the products microservice.
```sh
$ cd ./ui
$ cd products-microservice/ && mvn spring-boot:run
```

Start the checkout microservice.
```sh
$ npm install
$ cd checkout-microservice/ && mvn spring-boot:run
```

Start the UI service. After starting, browse the app at http://localhost:8080/.
```sh
$ npm start
$ cd react-ui/ && mvn spring-boot:run
```

## 4. Add items to the cart

Add two items to the cart as shown below.

You can see the Yugastore app at http://localhost:3001.
![yugastore-java checkout](/images/quick_start/binary-yugastore-java-checkout.png)

![Yugastore app screenshot](/images/develop/realworld-apps/ecommerce-app/yugastore-app-screenshots.png)
Verify that your cart is now stored inside the YSQL `shopping_cart` table. From your YugaByte DB local cluster home, run the following.

## 3. Run a load tester

```sh
$ node test/sample-user.js
$ ./bin/ysqlsh
```
```sh
postgres=# select * from shopping_cart;
```
```
cart_key | user_id | asin | time_added | quantity
------------------+---------+------------+-------------------------+----------
u1001-0001048236 | u1001 | 0001048236 | 2019-05-29T13:46:54.046 | 1
u1001-0001048775 | u1001 | 0001048775 | 2019-05-29T13:46:56.055 | 1
(2 rows)
```

## 5. Verify the completed order

## 4. Observe effects of load on YugaByte DB Admin UI
Now complete the checkout and observe the order number generated.

Now you can observe the effects of the read/write operations generated by the load tester by simply going to the YugaByte DB Admin UI at http://127.0.0.1:7000.
![yugastore-java order confirmation](/images/quick_start/binary-yugastore-java-orderconfirmation.png)

![yugastore running](/images/quick_start/binary-yugastore-running.png)

## 5. Review Yugastore architecture and code
Verify that this order number is now in the YCQL `orders` table.
```sh
$ ./bin/cqlsh localhost
```
```sh
cqlsh> select * from cronos.orders;
```
```
order_id | user_id | order_details | order_time | order_total
--------------------------------------+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------+-------------
119b96dc-7d1a-4f2f-a1dd-36def25348e0 | 1 | Customer bought these Items: Product: The Sherlock Holmes Audio Collection, Quantity: 1; Product: Measure for Measure: Complete &amp; Unabridged, Quantity: 1; Order Total is : 741.95 | 2019-05-29T13:54:04.093 | 741.95

Details of Yugastore architecture are documented [here](../../develop/realworld-apps/ecommerce-app/). Source code is available in the [Yugastore GitHub repo](https://github.com/YugaByte/yugastore).
```
Verify that there are no active shopping carts in YSQL at this point.
```sh
postgres=# select * from shopping_cart;
```
```
cart_key | user_id | asin | time_added | quantity
----------+---------+------+------------+----------
(0 rows)
```
## 6. Run IoT Fleet Management app
Expand Down
4 changes: 3 additions & 1 deletion docs/content/latest/quick-start/docker/run-sample-apps.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[Yugastore](https://github.com/YugaByte/yugastore) app is a sample ecommerce application built using a microservices design pattern. React UI, Node.js Express app framework and YugaByte DB (YCQL and YEDIS) are used as the underlying technology stack.

## 1. Create a cluster

Create a cluster. The YEDIS API is initialized along with cluster creation so nothing additional needs to be done.

```sh
$ ./yb-docker-ctl create --rf 3
$ ./yb-docker-ctl -rf 3 create
```

Clients can now connect to the YSQL API at `localhost:5433`, YCQL API at `localhost:9042` and YEDIS API at `localhost:6379`.
Expand Down
2 changes: 2 additions & 0 deletions docs/content/latest/quick-start/kubernetes/run-sample-apps.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[Yugastore](https://github.com/YugaByte/yugastore) app is a sample ecommerce application built using a microservices design pattern. React UI, Node.js Express app framework and YugaByte DB (YCQL and YEDIS) are used as the underlying technology stack.

## 1. Create a cluster

Create a cluster.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/latest/quick-start/run-sample-apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ isTocNested: false
showAsideToc: true
---

After [creating a local cluster](../create-local-cluster/), follow the instructions below to run [Yugastore](https://github.com/YugaByte/yugastore), one of simplest sample apps we have created for YugaByte DB. Yugastore is a fully open source, online bookstore app built using React, Express, NodeJS and is powered by the YCQL and YEDIS APIs of YugaByte DB. YSQL support is coming soon. You can review Yugastore's architecture and data model [here](../../develop/realworld-apps/ecommerce-app/).
After [creating a local cluster](../create-local-cluster/), follow the instructions below to run the Yugastore app.

After running Yugastore, we recommend running the [IoT Fleet Management](../../develop/realworld-apps/iot-spark-kafka-ksql/) app. This app is built on top of YugaByte DB as the database (using the YCQL API), Confluent Kafka as the message broker, KSQL or Apache Spark Streaming for real-time analytics and Spring Boot as the application framework.

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2590c11

Please sign in to comment.