Sign inSign up

cerberus237/adaptable-teastore-persistence

By cerberus237

Updated about 1 year ago

The Persistence service for the Adaptable TeaStore

Image
Developer tools
Web servers
1

620

cerberus237/adaptable-teastore-persistence repository overview

Adaptable TeaStore Persistence Service Documentation

1. Overview of the Component

Description

The Adaptable TeaStore Persistence service is responsible for managing data storage and retrieval within the Adaptable TeaStore application. It interfaces with a MariaDB or MySQL database to ensure that user and product data is stored reliably and can be accessed efficiently.

Architecture

The Persistence service operates as a microservice in the Adaptable TeaStore ecosystem. It communicates with other services, such as the Recommender and Auth services, to provide necessary data for user interactions and operations. This architecture allows it to scale independently and handle varying levels of data access.

Role in the Adaptable TeaStore
  • Data Management: Handles all CRUD (Create, Read, Update, Delete) operations for the application's data.
  • Database Connectivity: Connects to a MariaDB or MySQL database, ensuring data persistence.
  • Integration: Works closely with other services to deliver a seamless user experience.

2. Helpful Docker Command

To start the Adaptable TeaStore Persistence service, you can use the following command:

docker run -e "REGISTRY_HOST=10.1.2.3" -e "REGISTRY_PORT=10000" -e "HOST_NAME=10.1.2.30" -e "SERVICE_PORT=1111" -e "DB_HOST=10.1.2.20" -e "DB_PORT=3306" -p 1111:8080 -d cerberus237/adaptable-teastore-persistence
Explanation of Command:
  • docker run: Command to create and run a new container.
  • -e "REGISTRY_HOST=10.1.2.3": Sets the environment variable for the registry host.
  • -e "REGISTRY_PORT=10000": Sets the environment variable for the registry port.
  • -e "HOST_NAME=10.1.2.30": Defines the host name for the service.
  • -e "SERVICE_PORT=1111": Sets the port number for the service.
  • -e "DB_HOST=10.1.2.20": Specifies the database host.
  • -e "DB_PORT=3306": Specifies the database port.
  • -p 1111:8080: Maps port 1111 of the host to port 8080 of the container.
  • -d: Runs the container in detached mode.
  • cerberus237/adaptable-teastore-persistence: The name of the Docker image.

3. Sample Docker-Compose Code

Here’s a sample docker-compose.yml file to run the Adaptable TeaStore Persistence service using Docker Compose:

version: '3'
services:
  persistence:
    image: cerberus237/adaptable-teastore-persistence
    expose:
      - "8080"
    environment:
      HOST_NAME: "persistence"
      REGISTRY_HOST: "registry"
      DB_HOST: "db"
      DB_PORT: "3306"
Explanation of Directives:
  • version: '3': Specifies the Docker Compose file format version.
  • services: Defines the services to be run.
    • persistence: The name of the service.
      • image: Specifies the Docker image to use for the service.
      • expose: Makes the specified port accessible to linked services (not to the host).
      • environment: Sets environment variables needed for the service.

4. Overview of the Dockerfile

The Dockerfile for the Adaptable TeaStore Persistence service is designed to set up the environment for running the service. Below is an overview of its structure and components:

FROM cerberus237/adaptable-teastore-base:latest
LABEL org.opencontainers.image.authors="Inria R&D engineer <[email protected]>"

COPY target/*.war /usr/local/tomcat/webapps/
Explanation of Dockerfile Components:
  • FROM cerberus237/adaptable-teastore-base:latest: Specifies the base image to use, which is the latest version of the Adaptable TeaStore base image.
  • LABEL: Provides metadata about the image, including the author's contact information.
  • COPY target/*.war /usr/local/tomcat/webapps/: Copies the compiled WAR file of the Persistence service to the Tomcat webapps directory for deployment.

5. Instrumented Adaptation Actions and Metrics Collectors

5.1 Available Collectors

The Persistence service provides a family of collectors to support various system metrics:

CategoryCollectors (Local & Remote)
CPU UsageLocalCpuUsageCollector, RemoteCpuUsageCollector, RemoteCpuUsagePerInstanceCollector, RemoteCpuUsageAllLoadBalancedServiceCollector, RemoteCpuUsageAllServiceCollector
Memory UsageLocalMemoryUsageCollector, RemoteMemoryUsageCollector, RemoteMemoryUsagePerInstanceCollector, RemoteMemoryUsageAllLoadBalancedServiceCollector, RemoteMemoryUsageAllServiceCollector, RemoteRegistryMemoryUsageCollector
RequestsLocalRequestMetricsCollector, RemoteRequestMetricsCollector, RemoteRequestMetricsPerInstanceCollector, RemoteRequestMetricsAllLoadBalancedServiceCollector, RemoteRequestMetricsAllServiceCollector
Response TimeRemoteResponseTimeCollector, RemoteResponseTimePerInstanceCollector, RemoteResponseTimeAllLoadBalancedServiceCollector, RemoteResponseTimeAllServiceCollector
Service StateRemoteServiceStateCollector, RemoteServiceStatePerInstanceCollector, RemoteServiceStateAllLoadBalancedCollector, RemoteServiceStateAllServiceCollector
Service StatusRemoteServiceStatusCollector, RemoteServiceStatusPerInstanceCollector, RemoteServiceStatusAllLoadBalancedCollector, RemoteServiceStatusAllServiceCollector

Each collector is designed to either:

  • Collect local system metrics from a running service.
  • Fetch remote metrics via REST API calls.
5.2 Usage Examples
Local CPU Usage Collection

The LocalCpuUsageCollector retrieves CPU usage metrics from the Java Management Extensions (JMX).

Example: Collecting Local CPU Usage
LocalCpuUsageCollector cpuUsageCollector = new LocalCpuUsageCollector();
double currentCpuUsage = cpuUsageCollector.get();
System.out.println("Current CPU Usage: " + currentCpuUsage + "%");
Remote CPU Usage Collection

The RemoteCpuUsageCollector fetches CPU metrics from a remote service using a REST API call.

RemoteCpuUsageCollector cpuUsageCollector = new RemoteCpuUsageCollector(Service.AUTH, "metrics/cpu");
double currentCpuUsage = cpuUsageCollector.get();
System.out.println("Current Remote CPU Usage: " + currentCpuUsage + "%");
5.3 REST API Endpoints for Metrics Collection

Note: Each service in the Adaptable TeaStore exposes a REST API endpoint to provide its metrics.

Example API Endpoints
MetricEndpointHTTP Method
CPU Usage/metrics/cpuGET
Memory Usage/metrics/memoryGET
Request Count/metrics/requestsGET
Response Time/metrics/statusGET
Service State/metrics/stateGET
Service Status/metrics/statusGET
Example: Fetching CPU Usage from a Remote Service
curl -X GET http://service-instance:8080/metrics/cpu

6. Adaptation Actions

6.1 Available Adaptation Actions
Adaptation ActionDescription
OpenCircuitBreakerOpens the circuit breaker to prevent service failures during high load or errors.
CloseCircuitBreakerCloses the circuit breaker to resume normal operation once conditions stabilize.
DatabaseAvailableEventBroadcastBroadcasts an alert when the database becomes available after downtime.
DatabaseUnavailableEventBroadcastBroadcasts an alert when the database is detected as unavailable.
EnableCacheActivates caching mechanisms to optimize data retrieval.
DisableCacheDeactivates caching mechanisms to force fresh data retrieval.
MonitorMaliciousTrafficInitiates monitoring for potential malicious traffic patterns affecting the persistence service.

7. Summary

The Adaptable TeaStore Persistence service is a critical component for managing data storage and retrieval within the application. It can be easily deployed using Docker commands or Docker Compose and integrates seamlessly with other services in the Adaptable TeaStore architecture. The provided Dockerfile ensures a well-configured environment for running the service, while the instrumented adaptation actions and metrics collectors enable effective adaptability and monitoring capabilities. For further details, refer to the Getting Started documentation.

Tag summary

Content type

Image

Digest

sha256:742835e07

Size

283.2 MB

Last updated

about 1 year ago

docker pull cerberus237/adaptable-teastore-persistence