Valor code is a simulator for back-end technologies.
The technologies is going to be used:
-
Docker for deployment
-
Kubernetes with kustomized. Configurations for minkube
-
kafka for queuing/event sourcing
-
PostgreSQL and Cassandra
Of course, Java
Settings can be put in java command optional -D<prop>=<value>
-
spring.datasource.url
- For database URL of PostgreSQL -
spring.datasource.username
- For connecting to PostgreSQL -
spring.datasource.password
- For connecting to PostgreSQL -
spring.data.cassandra.keyspace-name
- The keyspace on which this application is using -
spring.data.cassandra.contact-points
- For connecting to Cassandra -
spring.data.cassandra.local-datacenter
- For name of data center -
spring.kafka.bootstrap-servers
- For connecting to Kafka -
spring.kafka.consumer.group-id
- The group id of consumer
-
valor.farming.duration.too-long-scheduled-activities
(default:PT5M
) - The Duration string(e.g.PT5M
) for some of activities are kept same status since update time.
cd farming
mvn -DskipTests=true package
docker build --build-arg JAR_FILE=target/*.jar -t valor-code/farming .
In ./kustomize directory, you can use kustomize to intialize cluster in Minikube.
kubectl kustomize ./kustomize | kubectl apply -l -f -
The cluster contains nodes by default:
-
Two nodes of Kafka
-
Depends on one node of Zookeeper
-
-
Two nodes of Cassandra
Don’t forget to set up PostgreSQL by your favor environment.
By Maven plugin of Liquibase.
cd farming
mvn liquibase:update -Ddb.url= -Ddb.username= -Ddb.password=
Required properties:
-
db.url
- As the URL of PostgreSQL -
db.username
- For connecting to PostgreSQL -
db.password
- For connecting to PostgreSQL
By cassandra-migrate(Built by Python language)
cd farming/cassandra
cassandra-migrate -H cassandra-0 migrate
In ./scripts directory, there are some scripts to perform testing.
-
new-lands.sh - Creates 10 lands
-
ask-sowing.sh - Ask random number of blocks for sowing; every land will get asked.
-
ask-cleaning.sh - Ask random number of blocks for cleaning; every land will get asked.
A land is place with following attributes:
-
A land has an unique name over universe.
-
The number of squares this land holds.
-
The climates:
tropical
,dry
,mild
,continental
,polar
A land contains 1:N
blocks for cultivating crops.
Block status:
-
A scheduled(sow, harvest, or clean) block cannot be change anymore until the process handle it.
-
A empty block can be scheduled for sowing
-
A occupied and mature block can be scheduled for harvesting
-
A occupied block can be scheduled for cleaning
A few crops can be grown on land:
-
manioc
,rice
,yams
- can be grown in tropical, mild, or continental land. -
grape
,tomatoe
,pumpkin
- can be grown in mild, continental, dry land. -
kale
,spinach
,lettuce
- can be grown in mild, continental, polar land.
Crop | Sowing time(seconds) | Growing time(seconds) | Harvest time(seconds) | Harvest quantity |
---|---|---|---|---|
manioc |
2 ~ 5 |
15 ~ 20 |
2 ~ 5 |
5 ~ 10 |
rice |
2 ~ 5 |
17 ~ 23 |
2 ~ 5 |
10 ~ 20 |
yams |
2 ~ 5 |
15 ~ 25 |
2 ~ 5 |
10 ~ 15 |
grape |
3 ~ 8 |
10 ~ 20 |
3 ~ 7 |
5 ~ 15 |
tomato |
3 ~ 8 |
10 ~ 20 |
3 ~ 7 |
15 ~ 30 |
pumpkin |
3 ~ 8 |
10 ~ 15 |
3 ~ 7 |
3 ~ 8 |
kale |
4 ~ 10 |
10 ~ 20 |
2 ~ 5 |
5 ~ 12 |
spinach |
4 ~ 10 |
10 ~ 25 |
5 ~ 10 |
10 ~ 30 |
lettuce |
4 ~ 10 |
5 ~ 12 |
5 ~ 10 |
10 ~ 20 |
See API documention
-
Land and blocks are created by API.
-
Sowing API would scheduled available blocks on a land for target crop.
-
Harvesting service would search matured crops and scheduled it for harvesting.
-
Cron service would search scheduled blocks that their 'update_time' is old than certain duration.
-
See property value of
valor.farming.duration.too-long-scheduled-activities
-
-
DEFAULT(unit test)
-
db.database
- valor_farming_ut -
db.cassandra.keyspace
- valor_farming_ut
Verify by single IT classmvn -P it-dev -q verify -Dit.test=BlockControllerIT
-
-
it-dev
- Skips*Test.java
, used with Maven verify. -
it-database
- Different PostgreSQL database and Cassandra keyspace .Used by full-started application-
db.database
- valor_farming -
db.cassandra.keyspace
- valor_farming
Used with full-started applicationmvn -P it-database spring-boot:start mvn -P it-database spring-boot:run
-
Listening properties:
Setting-up
-
Assign multiple IP addresses on host of minicube. Setting up Multiple IPs on Ubuntu
-
Adds entries to
/etc/hosts
:/etc/hosts<ip-1> kafka-0.kafka.default.svc.cluster.local kafka-0 <ip-2> kafka-1.kafka.default.svc.cluster.local kafka-1 <ip-3> kafka-2.kafka.default.svc.cluster.local kafka-2 <ip-1> cassandra-0.cassandra.default.svc.cluster.local cassandra-0 <ip-2> cassandra-1.cassandra.default.svc.cluster.local cassandra-1 <ip-3> cassandra-2.cassandra.default.svc.cluster.local cassandra-2
-
Start
port-forward
kubectl port-forward --address=<ip-0> po/kafka-0 9092:kafka & kubectl port-forward --address=<ip-1> po/kafka-1 9092:kafka & kubectl port-forward --address=<ip-2> po/kafka-2 9092:kafka & kubectl port-forward --address=<ip-0> po/cassandra-0 9092:cassandra & kubectl port-forward --address=<ip-1> po/cassandra-1 9092:cassandra & kubectl port-forward --address=<ip-2> po/cassandra-2 9092:cassandra &
With above tech, you can use kafka-0
, kafak-1
, cassandra-0
, etc., to bootstrap client of Kafka.
./kafka-topics.sh --bootstrap-server kafka-0:9092 --create --topic sample-topic-1
If you are using WSL, you may like to modify the file of %WINDIR%\System32\drivers\etc\hosts
.