Administration Service

Introduction

Every self-respecting application provides some form of administrative console. In this article, we will build the Administration Service to provide a service façade that implements a basic set of administrative-level functions. We will accomplish this through a combination of service proxying, and orchestrated calls to other services functions within the application. The Administration Service provides the following basic application administrative features:

  • User Search- provides a user search facility.
  • User Status control- allows an administrator to enable/disable a user's account.
  • History Events- provides a user event history search
  • Service Status- provides the current status of each of the applications deployed service instances.


Requirements

Before you get started, you will need the following:
  • Java
  • Maven
  • Docker
  • Docker-Compose
Refer to the Development Toolbox article if you do not have these installed locally.

Building the Administration Service

Administration Hexagonal diagram

The source

Maven pom.xml

loading...

Service Configuration

bootstrap.yml

loading...

Not much different in this bootstrap file except for the spring.application.name

appliction.yml

loading...

Administration Controller

loading...

The Administration Controller provides the REST endpoint for our service implementation. Is exposes four methods:
  • getUserProfiles- returns a paged list of user Account Profiles
  • setUserActiveStatus- enables or disables a user account. When disabled, the user will not be authenticated.
  • getServiceInstanceList- returns a list of each active service instance in the application.
  • findByAccountId- returns a paged list of client telemetry data for a give account id.

User Admin Service

loading...

The UserAdminService provides the implementation for accessing Account information. It is composed of three public methods:

  • findUserProfilesByPage- This method retrieves a paged list of account profiles from the AccountProfileService, and then queries the AuthorizationService to retrieve each AccountProfile's account status to enrich the response. Both external service calls are made via the restTemplate client.
  • findTelemetryByPage- returns a paged list of client telemetry data for a specific user account.
  • setUserActiveStatus- performs a client call to the AuthenticationService to set a given user's active status.

Discovery Service

loading...

The DiscoveryService contains a single method getAllServiceInstances. This method invokes the Spring framework's DiscoveryClient to obtain the collection of registered services. The client response is then converted to a stream, sorted, and collected to a List of type NamedServiceInstance.

Docker Compose

We continue the process of extending our Docker-Compose file. Here we include our Administration Service

loading...

Administration Service In Action

We can copy the Docker-Compose file above to your local machine and run it from the command prompt:

docker-compose -f ./dc-11-administration.yml up -d


Exercising the Swagger Interface

Once all the services have started, navigate to the following url: http://localhost:9999/swagger-ui.html

Administration Service methods

Swagger-UI service methods

Administration Service models

Swagger-UI service models

get User Profile method form

The getUserProfile method form allows the caller to supply page number, page offset, sort field, and an optional like regex field to constrain the result.

Swagger-UI getUserProfiles form

get User Profile method response

The response displays the result of our query. The content field contains an array of Account Profile instances that matched the query.

Swagger-UI getUserProfiles response

get service instance list method form

The getServiceInstanceList takes no parameters but does require that we supply an authorization header containing a valid token.

Swagger-UI getServiceInstanceList form

get service instance list response

The response consists of an array of service instances currently registered with the discovery service. Each service instance contains a serviceName representing the type of service as well as an array containing details for (1-n) deployed instances of that service type.

Swagger-UI getServiceInstanceList response

set user active status method form

The setUserActiveStatus method allows the caller to change the active status for the supplied account. This method enables or disables the account's ability to authenticate.

Swagger-UI setUserActiveStatus form

set user active status response

The response value contains the account's post-method invocation activeStatus value.

Swagger-UI setUserActiveStatus response

Metrics and Monitoring

The Administration Service generates the following service-level metrics:
  • administration.user.query.total
  • administration.user.status.disbled.total
  • administration.telemetry.query.total
these metrics will allow us to administration queries, user status change totals, and telemetry query totals.

To visualize this data we will import the AdministrationDashboard.json file from the ThinkMicroservices Github Dashboards repository. The dashboard should appear as:

Administration Dashboard

Resources



Coming Up

In our next article, we will be implementing the TelemetryService. This service provides a schema-less repository for telemetry data transmitted from application clients.