cninfra

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2017 License: Apache-2.0 Imports: 0 Imported by: 0

README

CN-Infra

Build Status Coverage Status Go Report Card GoDoc GitHub license

CN-Infra (cloud-native infrastructure) is a Golang platform for building cloud-native microservices. Although it was originally intended for development/implementation of custom management/control plane agents for cloud-native Virtual Network Functions (VNFs), it can be used to develop any microservice.

Architecture

Each management/control plane app built on top of the CN-Infra platform is basically a set of modules called "plugins" in CN-Infra lingo, where each plugin provides a very specific/focused functionality. Some plugins are provided by the CN-Infra platform itself, some are written by the app's implementors. In other words, the CN-Infra platform itself is implemented as a set of plugins that together provide the platform's functionality, such as logging, health checks, messaging (e.g. Kafka), a common front-end API and back-end connectivity to various KV data stores (Etcd, Cassandra, Redis, ...), and REST and gRPC APIs.

The architecture of the CN-Infra platform is shown in the following figure.

arch

The CN-Infra platform consists of a Core that provides plugin lifecycle management (initialization and graceful shutdown of plugins) and a set of platform plugins. Note that the figure shows not only CN-Infra plugins that are a part of the CN-Infra platform, but also app plugins that use the platform. CN-Infra platform plugins provide APIs that are consumed by app plugins. App plugins themselves may provide their own APIs consumed by external clients.

The platform is modular and extensible. Plugins supporting new functionality (e.g. another KV store or another message bus) can be easily added to the existing set of CN-Infra platform plugins. Moreover, CN-Infra based apps can be built in layers: a set of app plugins together with CN-Infra plugins can form a new platform providing APIs/services to higher layer apps. This approach was used in the VPP Agent - a management/control agent for VPP based software data planes.,

Extending the code base does not mean that all plugins end up in all apps - app writers can pick and choose only those platform plugins that are required by their app; for example, if an app does not need a KV store, the CN-Infra platform KV data store plugins would not be included in the app. All plugins used in an app are statically linked into the app.

CN-Infra Plugins

A CN-Infra plugin is typically implemented as a library providing the plugin's functionality/APIs wrapped in a plugin wrapper. A CN-Infra library can also be used standalone in 3rd party apps that do not use the CN-Infra platform. The plugin wrapper provides lifecycle management for the plugin component.

Platform plugins in the current CN-Infra release provide functionality in one of the following functional areas:

  • RPC - allows to expose application's API via REST or gRPC:

    • REST - HTTP requests and allows app plugins to define their own REST APIs.
  • Data Stores - provides a common data store API for app plugins (the Data Broker) and back-end clients for Etcd, Redis and Cassandra. The data store related plugin are as follows:

    • Etcd - implements keyval skeleton provides access to etcd
    • Redis - implements keyval skeleton provides access to redis
    • Casssandra - implements sql skeleton provides access to cassandra
  • Messaging - provides a common API and connectivity to message buses:

    • Kafka - provides access to a Kafka broker (Sarama)
  • Logging:

    • Logrus wrapper - implements logging skeleton using the Logrus library. An app writer can create multiple loggers - for example, each app plugin can have its own logger. Log level for each logger can be controlled individually at run time through the Log Manager REST API.
    • Log Manager - allows the operator to set log level for each logger using a REST API.
  • Health - Self health check mechanism between plugins plus RPCs:

    • StatusCheck - allows to monitor the status of plugins and exposes it via HTTP
    • Probes (callable remotely from K8s)
  • Miscellaneous - value-add plugins supporting the operation of a CN-Infra based application:

    • Config - helpers for loading plugin configuration.
    • Datasync - provides data resynchronization after HA events (restart or connectivity restoration after an outage) for data stores, gRPC and REST.
    • Flavors - predefined reusable collection of plugins.
    • IDX Map - reusable thread-safe map with advanced features:
      • multiple subscribers for watching changes in the map
      • secondary indexes
    • ServiceLabel - provides setting and retrieval of a unique identifier for a CN-Infra based app. A cloud app typically needs a unique identifier so that it can differentiated from other instances of the same app or from other apps (e.g. to have its own space in a kv data store).

Quickstart

The following code shows the initialization/start of a simple agent application built on the CN-Infra platform. The code for this example can be found here.

func main() {
	flavor := rpc.FlavorRPC{}
	agent := core.NewAgent(logroot.Logger(), 15*time.Second, flavor.Plugins()...)

	err := core.EventLoopWithInterrupt(agent, nil)
	if err != nil {
		os.Exit(1)
	}
}

You can run this example code by using pre-build Docker images:

For quick start with the VPP Agent, you can use pre-build Docker images with the Agent and VPP on Dockerhub.

  1. Run ETCD and Kafka on your host (e.g. in Docker using this procedure).

  2. Run cn-infra example simple-agent.

docker pull ligato/dev-cn-infra
docker run -it --name dev-cn-infra --rm ligato/dev-cn-infra

Documentation

GoDoc can be browsed online.

Contributing

If you are interested in contributing, please see the contribution guidelines.

Documentation

Overview

Copyright (c) 2017 Cisco and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package cninfra is the parent package for all packages that are parts of the CN-Infra platform - a Golang platform for building cloud-native microservices.

The CN-Infra platform is a modular platform comprising a core and a set of plugins. The core provides lifecycle management for plugins, the plugins provide the functionality of the platform. A plugin can consist of one or more Golang packages. Out of the box, the CN-Infra platform provides reusable plugins for logging, health checks, messaging (e.g. Kafka), a common front-end API and back-end connectivity to various data stores (Etcd, Cassandra, Redis, ...), and REST and gRPC APIs.

The CN-Infra platform can be extended by adding a new platform plugin, for example a new data store client or a message bus adapter. Also, each application built on top of the platform is basically just a set of application-specific plugins.

Directories

Path Synopsis
Package config contains helper functions for parsing of configuration files.
Package config contains helper functions for parsing of configuration files.
Package core manages the lifecycle of all plugins (start, graceful shutdown) and defines the core lifecycle SPI.
Package core manages the lifecycle of all plugins (start, graceful shutdown) and defines the core lifecycle SPI.
Package datasync defines the datasync API, which abstracts the data transport between app plugins and backend data sources.
Package datasync defines the datasync API, which abstracts the data transport between app plugins and backend data sources.
grpcsync
Package grpcsync implements (in ALPHA VERSION) the gRPC transport client and server that satisfy the datasync API.
Package grpcsync implements (in ALPHA VERSION) the gRPC transport client and server that satisfy the datasync API.
kvdbsync
Package kvdbsync implements the key-value data store client and server that satisfythe datasync API.
Package kvdbsync implements the key-value data store client and server that satisfythe datasync API.
kvdbsync/local
Package local implements DB Transactions for the local "in memory" transport.
Package local implements DB Transactions for the local "in memory" transport.
restsync
Package restsync implements (in ALPHA VERSION) the datasync API for the HTTP/REST transport.
Package restsync implements (in ALPHA VERSION) the datasync API for the HTTP/REST transport.
resync
Package resync implements the mechanism to notify previously registered plugins that the resync procedure needs to start.
Package resync implements the mechanism to notify previously registered plugins that the resync procedure needs to start.
syncbase
Package syncbase defines common structures used in multiple datasync transports.
Package syncbase defines common structures used in multiple datasync transports.
syncbase/msg
Package msg is a generated protocol buffer package.
Package msg is a generated protocol buffer package.
db
Package db is the parent package for the Data Broker client implementations for various key-value and SQL data stores.
Package db is the parent package for the Data Broker client implementations for various key-value and SQL data stores.
keyval
Package keyval provides an abstraction of a key-value data store and defines the keyval data broker API.
Package keyval provides an abstraction of a key-value data store and defines the keyval data broker API.
keyval/etcdv3
Package etcdv3 implements the key-value Data Broker client API for the etcdv3 key-value data store.
Package etcdv3 implements the key-value Data Broker client API for the etcdv3 key-value data store.
keyval/etcdv3/mocks
Package mocks implements an embedded etcdv3 mock used in unit & integration tests.
Package mocks implements an embedded etcdv3 mock used in unit & integration tests.
keyval/kvproto
Package kvproto provides a wrapper that simplifies the storing and retrieving of proto-modelled data into/from a key-value data store.
Package kvproto provides a wrapper that simplifies the storing and retrieving of proto-modelled data into/from a key-value data store.
keyval/plugin
Package plugin contains a keyval plugin skeleton used in various key-value data store clients (e.g.
Package plugin contains a keyval plugin skeleton used in various key-value data store clients (e.g.
keyval/redis
Package redis is the implementation of the key-value Data Broker client API for the Redis key-value data store.
Package redis is the implementation of the key-value Data Broker client API for the Redis key-value data store.
sql
Package sql provides an abstraction of a data store that supports an SQL-like query language and defines the SQL data broker API.
Package sql provides an abstraction of a data store that supports an SQL-like query language and defines the SQL data broker API.
sql/cassandra
Package cassandra is the implementation of the SQL Data Broker client API for the Cassandra data store.
Package cassandra is the implementation of the SQL Data Broker client API for the Cassandra data store.
Package examples contains examples that demonstrate the usage of various cn-infra components.
Package examples contains examples that demonstrate the usage of various cn-infra components.
etcdv3_lib/model/phonebook
Package phonebook is a generated protocol buffer package.
Package phonebook is a generated protocol buffer package.
etcdv3_lib/view
Package view contains an example that shows how to read data from etcdv3.
Package view contains an example that shows how to read data from etcdv3.
model
Package etcd_example is a generated protocol buffer package.
Package etcd_example is a generated protocol buffer package.
redis_lib/airport/model
Package flight is a generated protocol buffer package.
Package flight is a generated protocol buffer package.
Package flavors contains predefined cn-infra flavors.
Package flavors contains predefined cn-infra flavors.
rpc
health
probe
Package probe implements the K8s readiness and liveliness probe handlers.
Package probe implements the K8s readiness and liveliness probe handlers.
statuscheck
Package statuscheck defines the status report API for other CN-Infra plugins and implements the health status aggregator/exporter.
Package statuscheck defines the status report API for other CN-Infra plugins and implements the health status aggregator/exporter.
statuscheck/model/status
Package status is a generated protocol buffer package.
Package status is a generated protocol buffer package.
Package idxmap defines a mapping structure which supports mapping change notifications and retrieval of items by fields in the value structure.
Package idxmap defines a mapping structure which supports mapping change notifications and retrieval of items by fields in the value structure.
mem
Package mem provides in-memory implementation of the mapping with multiple indexes.
Package mem provides in-memory implementation of the mapping with multiple indexes.
Package logging defines the logging API.
Package logging defines the logging API.
logmanager
Package logmanager implements the log manager that allows users to set log levels at run-time via a REST API.
Package logmanager implements the log manager that allows users to set log levels at run-time via a REST API.
logroot
Package logroot contains the default global logger.
Package logroot contains the default global logger.
logrus
Package logrus implements the logging API based on the Logrus logger.
Package logrus implements the logging API based on the Logrus logger.
Package messaging is the parent package for implementations of various messaging clients, e.g.
Package messaging is the parent package for implementations of various messaging clients, e.g.
kafka
Package kafka implements a client for the Kafka broker.
Package kafka implements a client for the Kafka broker.
kafka/client
Package client implements the synchronous and asynchronous kafka Producers and the kafka Consumer.
Package client implements the synchronous and asynchronous kafka Producers and the kafka Consumer.
kafka/mux
Package mux implements the session multiplexer that allows multiple plugins to share a single connection to a Kafka broker.
Package mux implements the session multiplexer that allows multiple plugins to share a single connection to a Kafka broker.
rpc
rest
Package rest implements the HTTP server through which plugins can expose their REST APIs to the outside world.
Package rest implements the HTTP server through which plugins can expose their REST APIs to the outside world.
Package servicelabel provides support for creating/retrieving an identifier (a service label) for a CN-Infra based app.
Package servicelabel provides support for creating/retrieving an identifier (a service label) for a CN-Infra based app.
tests
utils
addrs
Package addrs contains helpers for ip and mac address conversion.
Package addrs contains helpers for ip and mac address conversion.
safeclose
Package safeclose provides utilities for safe closing of I/O resources.
Package safeclose provides utilities for safe closing of I/O resources.
structs
Package structs provides reflection utilities to inspect structures.
Package structs provides reflection utilities to inspect structures.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL