Microservice SDK Overview
The Microservice SDK provides the steps and detailed understanding needed to start creating microservices for Oracle Communications Unified Assurance.
The SDK consists of a Unified Assurance package called sdk-lib that you install manually as described in Installing the SDK. Most of the steps in this document assume you are building on a single-server development instance of Unified Assurance. While this document is helpful for starting your development, Oracle recommends attending training courses for microservices to gain a firm grasp of all the details necessary.
The sdk-lib package includes the following examples:
-
goexample provides examples of several different capabilities, including connecting to the Pulsar message bus, connecting to the database and making queries, and making a request to the Unified Assurance REST API. It is not a fully functional microservice, but an introduction to those capabilities.
-
gotemplate is an example template that you can use to start developing a microservice. The build examples below use this template.
Architecture
For information about the microservice cluster architecture, see Understanding Microservices in Unified Assurance Concepts. You should have a firm understanding of each component in the solution.
Container Image Recommendations
Build the container image with a multi-stage build:
-
In the first stage, build microservice images by requiring all the build dependencies
-
In the second stage, save only the necessary applications and files.
Helm Chart Additions
Unified Assurance has an opinionated set of additions to the standard configuration of Helm charts:
-
global.ImageRegistry: The image registry to use for Unified Assurance microservices. You must include this variable, set to the primary presentation server WebFQDN, during the installation of a Helm release. All references to images in the yaml templates must be prefixed with the imageRegistry variable.
-
configData: An array of key/value pairs used to provide configuration to your microservice. The keys should be all upper-case with words separated by underscores, following the convention for environment variables.
See the Helm documentation for more information about Helm charts.
Microservice Requirements
Before building your microservice, you must understand the requirements and recommendations described in this section.
Programming Language Recommendations
Because microservices are language-agnostic, you can use any programing language. Oracle recommends the following options, depending on your needs:
-
Go (GoLang): Recommended for its ability handle concurrency and compile down to small application binaries.
-
Node.js: Recommended for its vast module library and familiarity by a wide range of developers.
-
Python: Recommended when the need is for machine learning and analytic libraries.
Note:
You can alternatively use the Java Microservices SDK to create microservices in Java. See Java Microservice SDK.
Application Requirements
When developing microservice, you must meet the requirements described in this section in order to fit seamlessly into the Unified Assurance Hyperscale Architecture. Oracle also recommends following the twelve-factor app methodology. See 12factor.net for information.
-
Configuration:
Microservices need to gather configurations about the location of Unified Assurance API and database servers and support configurations specific to the microservice itself. All Kubernetes pods will automatically bind a ConfigMap for the Unified Assurance configuration located at /config/assure1.yaml. Microservice configurations should support sane defaults that can be overridden with environment variables.
-
Certificates:
Microservices need to use certificates and keys, located in /cert/a1, for validating the Unified Assurance services being connected to and authenticating to those services. Additionally, each Kubernetes namespace will have a wildcard certificate and key, located in /cert/ns, available for serving content if needed.
-
Logging:
Microservices need to log to stderr (stdout alternatively) in Newline Delimited JSON (http://ndjson.org/) format. Required fields include:
-
@timestamp: in RFC3339 format
-
level: a string, one of the following: FATAL, ERROR, WARN, INFO, DEBUG, TRACE
-
message
-
app
-
-
Instrumentation:
Microservices need to gather internal metrics about the health, processing, and their own state by exposing Prometheus metrics. The default recommended port is 8080 at the /metrics endpoint.
Developing a Microservice
To develop your microservice:
-
Build the microservice. This involves preparing the template based on the SDK sample, coding the microservice, and building the image and Helm chart.
-
Distribute the microservice. This involves adding the microservice image and Helm chart to the Helm repository, and creating a Unified Assurance package to distribute the microservice to other servers in your environment.
-
Deploy the microservice. This involves installing the microservice on the cluster in your Unified Assurance environment.
Building the Microservice
-
Prepare the template:
-
Set standard environment variables:
source <UA_home>/.bashrcBy default, <UA_home> is /opt/assure1/. If you used a custom home directory, this will be different.
-
Set the following variables to values that are appropriate for your project:
export APPNAME=<microservice_name> export APPVERSION=<application_version> export CHARTVERSION=<chart_version> export DEVELDIR=$A1BASEDIR/tmp/$APPNAME export PRESWEBFQDN=<presentation_server_web_FQDN>APPVERSION and CHARTVERSION should match semantic versions.
-
Copy the template to your development directory and replace the template name with your microservice name:
cp -a $A1BASEDIR/sdk/microservice/gotemplate $DEVELDIR cd $DEVELDIR find . -type f -exec sed -i -e "s/gotemplate/$APPNAME/g" {} \;
-
-
Code the microservice, add configurations, and adjust the Helm chart as needed.
-
Update the list of dependencies:
go get -u ./... -
Build the container image by running the following command as the assure1 user:
a1podman build -t assure1/$APPNAME:$APPVERSION . -
Package the Helm chart:
a1helm package helm --app-version $APPVERSION --version $CHARTVERSION -
Proceed to Distributing the Microservice.
Distributing the Microservice
You can distribute the image locally or remotely.
Manual Local Distribution
If you are building and testing on your local development instance of Unified Assurance, run the following commands as the assure1 user:
a1podman tag assure1/$APPNAME:$APPVERSION $PRESWEBFQDN/assure1/$APPNAME:$APPVERSION
a1podman push $PRESWEBFQDN/assure1/$APPNAME:$APPVERSION
a1podman rmi assure1/$APPNAME:$APPVERSION
cp $APPNAME-$CHARTVERSION.tgz $A1BASEDIR/var/chartmuseum
a1helm repo update
This tags the image with the appropriate repository, pushes it to the repository, removes the local image, copies the chart to the chartmuseum, and updates the repository with the chart.
Proceed to Creating the Unified Assurance Package
Manual Remote Distribution
If you are building on your local development instance but will distribute and deploy on a separate instance, run the following commands to push the image to the presentation server repository:
-
Locally, zip up the image by running the following command as the assure1 user:
a1podman save assure1/$APPNAME:$APPVERSION | gzip --stdout > $APPNAME-$APPVERSION.tgz -
Copy the archived image ($APPNAME-$APPVERSION.tgz) and chart ($APPNAME-$CHARTVERSION.tgz) to your presentation server.
-
On the presentation server, run the following commands as the assure1 user:
a1podman load --input $APPNAME-$APPVERSION.tgz a1podman tag assure1/$APPNAME:$APPVERSION $PRESWEBFQDN/assure1/$APPNAME:$APPVERSION a1podman push $PRESWEBFQDN/assure1/$APPNAME:$APPVERSION a1podman rmi assure1/$APPNAME:$APPVERSION cp $APPNAME-$CHARTVERSION.tgz $A1BASEDIR/var/chartmuseum a1helm repo updateThis loads the image into container storage, tags the image with the appropriate repository, pushes it to the repository, and removes the local image, copies the chart to the chartmuseum, and updates the repository with the chart.
-
Proceed to Creating the Unified Assurance Package
Creating the Unified Assurance Package
You can create a Unified Assurance package to distribute microservice images and Helm charts. See Package in Unified Assurance Implementation Guide for complete information about the Package application.
To create the Unified Assurance package:
-
Prepare the package directory by running the following commands as the assure1 user:
export PACKAGENAME=<microservice_package_name>-img mkdir $DEVELDIR/$PACKAGENAME/img mkdir $DEVELDIR/$PACKAGENAME/helm a1podman save assure1/$APPNAME:$APPVERSION | gzip --stdout > $DEVELDIR/$PACKAGENAME/img/IMAGES.tgz echo assure1/$APPNAME-$APPVERSION >> $DEVELDIR/$PACKAGENAME/img/IMAGES.txt cp $APPNAME-$CHARTVERSION.tgz $DEVELDIR/$PACKAGENAME/helmThis creates the required directories and saves the image and helm chart to them.
-
Create a custom Package.def file. See About Package.def Files in the Core Interface SDK documentation for information about the required schema for Package.def files, and use the following values in your microservice package:
-
For the Version value, make sure to use the correct semantic version.
-
For the Directory key, use the following array, replacing <microservice_package_name> as appropriate for your new microservice package:
"Directory": [ { "Type": "img", "Directory": "distrib/images/<microservice_package_name>" }, { "Type": "helm", "Directory": "var/chartmuseum" } ], -
For the PostInstall key, use the following array:
"PostInstall": [ "podmanLoadImages('$PACKAGEDIR_img/IMAGES.tgz')", "registryLoadImages('$PACKAGEDIR_img/IMAGES.txt')", "remove('$PACKAGEDIR_img/IMAGES.tgz')" ],Note:
$PACKAGEDIR is a token supported by the Unified Assurance Package application. It is replaced dynamically when creating the package with the values from the Directory key.
-
-
Create the package:
$A1BASEDIR/bin/Package create $DEVELDIR/$PACKAGENAME
You can distribute the package to other servers and use the Package install command to install it.
Deploying the Microservice
To deploy the new microservice to an existing Unified Assurance microservice cluster, run the following commands:
a1helm repo update
a1helm install $APPNAME assure1/$APPNAME -n a1-zone1-pri --set global.imageRegistry=$PRESWEBFQDN
You can also use the Unified Assurance UI to deploy microservices. See Microservice Cluster Setup and Deploying a Microservice by Using the UI in Unified Assurance Implementation Guide for more information about setting up the microservice cluster and deploying microservices.