Git Product home page Git Product logo

random-generator's Introduction

Random Number Generator Service

This repository holds a sample REST service used in most of the examples for the book "Kubernetes Patterns" by Bilgin Ibryam and Roland Huß.

It’s a very simple Spring Boot service with a handful of endpoints used to demonstrate Kubernetes concepts.

You can start it locally with with ./mvnw -pl spring spring-boot:run [1] and get a random number:

curl -sL http://localhost:8080/ | jq .
{
  "random": 838265052,
  "id": "58da4c5b-ba06-438e-84f8-1a30581baeb8"
}

In order to create a Docker image, just use ./mvnw -pl spring package docker:build. You can easly change the Docker repository and push it to your own account with -Dimage.repo:

./mvnw -Dimage.repo="rhuss" package docker:build push

Configuration

Property Env Var Description Pattern

version

---

Version of this application, created during build

Declarative Deployment

log.file

LOG_FILE

Path to a log file. If set, the write out the generated response values into a CSV file

many

log.url

LOG_URL

If given, send out an HTTP request with the results of a random number generation

Ambassador

build.type

BUILD_TYPE

Add some informations about how the image has been built

Image Builder

pattern

PATTERN

Descriptive label used in environment variables

Envvar Configuration, Configuration Resource

seed

SEED

Seed number to initialize the random number generator. Must be a long.

Configuration Resource

Endpoints

Endpoint Description Pattern

/

Return a random number and a unique id of this service

many

/info

Return information about configuration and system

many

/memory-eater

Allocate an array for eating up heap memory. Use parameter "mb" to specify the size in MegaByte

Predictable Demands

/toggle-live

Toggle the status of the Sprint Boot’s actuator health check between UP and DOWN

Health Probe

/toggle-ready

Add or remove the local file which indicates readiness of this service

Health Probe

/shutdown

Shutdown the Spring Boot service

Managed Lifecycle

/logs

Return the content of the logs

Stateful Service, Init Container

Batch

There is also a single class RandomRunner included which creates a list of random numbers into a file:

# Compile stuff first
./mvnw -pl spring compile

# Create a file with 100000 lines in /tmp/random_numbers.txt
java -cp target/classes RandomRunner /tmp/random_numbers.txt 100000

This command is used in the Batch Job and Periodic Job pattern example.

Building

Refer to the Image Builder pattern how this example is build from within a Kubernetes cluster.

For creating a tag 2.0 just use the profile -Pv2. This is used for creating images to be used the Declarative Deployment pattern.


1. Instead of the Maven wrapper mvnw you can also use a locally installed mvn

random-generator's People

Contributors

rhuss avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.