Monasca REST API
Go to file
cindy oneill f4f14c77fd streams definition POST, GET, GET (id), DELETE
This depends on ansible-monasca-schema changes here:
https://github.com/hpcloud-mon/ansible-monasca-schema/pull/17

Here are sample curl commands for POST, GET, and DELETE:
curl -i -X POST -H 'X-Auth-User: mini-mon' -H 'X-Auth-Token: 8c959d0296344c27a47b8e78dbf912ac' -H 'X-Auth-Key: password' -H 'Accept: application/json' -H 'User-Agent: python-monascaclient' -H 'Content-Tye: application/json' -d '{"fire_criteria": [{"event_type": "compute.instance.create.start"}, {"event_type": "compute.instance.create.end"}], "description": "provisioning duration", "name": "panda", "group_by": ["instance_id"], "expiration": 3, "select": [{"traits": {"tenant_id": "406904"}, "event_type": "compute.instance.create.*"}], "fire_actions": ["ed469bb9-2b4a-457a-9926-9da9f6ac75da"], "expire_actions":["ed469bb9-2b4a-457a-9926-9da9f6ac75da"]}' http://127.0.0.1:8080/v2.0/events/stream-definitions

curl -i -X GET -H 'X-Auth-User: mini-mon' -H 'X-Auth-Token: 8c959d0296344c27a47b8e78dbf912ac' -H 'X-Auth-Key: password' -H 'Accept: application/json' -H 'User-Agent: python-monascaclient' -H 'Content-Type: application/json' http://127.0.0.1:8080/v2.0/events/stream-definitions/

curl -i -X DELETE -H 'X-Auth-User: mini-mon' -H 'X-Auth-Token: 8c959d0296344c27a47b8e78dbf912ac' -H 'X-Auth-Key: password' -H 'Accept: application/json' -H 'User-Agent: python-monascaclient' -H 'Content-Type: application/json' http://127.0.0.1:8080/v2.0/events/stream-definitions/86177f0e-f811-4c42-a91a-1813251bf93f

Note: the limit parameter is passed into the streams_repository method for listing streams, but not yet used. We will open a separate Jira to to handle pagination with a user input limit parameter.

Note: fixed a few events problems. stevedore wasn't loading the driver, and missing some abstact function defs.  I tested stream-defintions and events, they both work now.  Had to change the URI for stream-definitions because it conflicted with events, and now is more RESTful.
Change-Id: I0b6dc385e1d095c1bd33867a038fe170ca277bfe
2015-04-24 15:55:20 -06:00
common Change to use maven 3 2015-03-13 11:43:55 -06:00
docs Update doc for value-meta value 2015-04-07 08:56:17 -06:00
etc streams definition POST, GET, GET (id), DELETE 2015-04-24 15:55:20 -06:00
java Merge "Allow unicode in metric definitions" 2015-04-23 14:11:07 +00:00
monasca streams definition POST, GET, GET (id), DELETE 2015-04-24 15:55:20 -06:00
.coveragerc initial python implementation 2014-09-15 13:18:10 -04:00
.gitignore Add more entries to .gitignore 2015-02-23 21:16:02 -07:00
.gitreview Get initial build to work. 2014-07-15 15:35:50 -06:00
.testr.conf initial python implementation 2014-09-15 13:18:10 -04:00
LICENSE Added license file 2014-05-01 16:22:11 -07:00
README.md Added option to define project for admin user 2015-03-17 16:37:45 -06:00
babel.cfg initial python implementation 2014-09-15 13:18:10 -04:00
es-impl-requirements.txt implementation specific requirement files 2014-12-09 09:08:25 -05:00
pom.xml Change to use maven 3 2015-03-13 11:43:55 -06:00
ref-impl-requirements.txt Remove peewee and replace with mysqldb 2014-12-16 13:12:58 -07:00
requirements.txt Added two GET api methods for events 2015-04-20 13:57:33 -06:00
run_maven.sh Added java -jar monasca-api.jar --version 2015-03-23 16:38:44 -06:00
setup.cfg streams definition POST, GET, GET (id), DELETE 2015-04-24 15:55:20 -06:00
setup.py initial python implementation 2014-09-15 13:18:10 -04:00
test-requirements.txt Add alarm history resource 2014-11-17 15:38:47 -07:00
tox.ini Add alarm history resource 2014-11-17 15:38:47 -07:00

README.md

Overview

monasca-api is a RESTful API server that is designed with a layered architecture layered architecture.

The full API Specification can be found in docs/monasca-api-spec.md

Java Build

Requires monasca-common from https://github.com/stackforge/monasca-common. Download and do mvn install. Then:

cd java
mvn clean package

StackForge Java Build

There is a pom.xml in the base directory that should only be used for the StackForge build. The StackForge build is a rather strange build because of the limitations of the current StackForge java jobs and infrastructure. We have found that the API runs faster if built with maven 3 but the StackForge nodes only have maven 2. This build checks the version of maven and if not maven 3, it downloads a version of maven 3 and uses it. This build depends on jars that are from monasca-common. That StrackForge build uploads the completed jars to http://tarballs.openstack.org/ci/monasca-common, but they are just regular jars, and not in a maven repository and sometimes zuul takes a long time to do the upload. Hence, the first thing the maven build from the base project does is invoke build_common.sh in the common directory. This script clones monasca-common and then invokes maven 3 to build monasca-common in the common directory and install the jars in the local maven repository.

Since this is all rather complex, that part of the build only works on StackForge so follow the simple instruction above if you are building your own monasca-api.

Currently this build is executed on the bare-precise nodes in StackForge and they only have maven 2. So, this build must be kept compatible with Maven 2. If another monasca-common jar is added as a dependency to java/pom.xml, it must also be added to download/download.sh.

Combining monasca-common, monasca-thresh, monasaca-api and monasca-persister into one build would vastly simplify the builds but that is a future task.`

Usage

java -jar target/monasca-api.jar server config-file.yml

Keystone Configuration

For secure operation of the Monasca API, the API must be configured to use Keystone in the configuration file under the middleware section. Monasca only works with a Keystone v3 server. The important parts of the configuration are explained below:

  • serverVIP - This is the hostname or IP Address of the Keystone server
  • serverPort - The port for the Keystone server
  • useHttps - Whether to use https when making requests of the Keystone API
  • truststore - If useHttps is true and the Keystone server is not using a certificate signed by a public CA recognized by Java, the CA certificate can be placed in a truststore so the Monasca API will trust it, otherwise it will reject the https connection. This must be a JKS truststore
  • truststorePassword - The password for the above truststore
  • connSSLClientAuth - If the Keystone server requires the SSL client used by the Monasca server to have a specific client certificate, this should be true, false otherwise
  • keystore - The keystore holding the SSL Client certificate if connSSLClientAuth is true
  • keystorePassword - The password for the keystore
  • defaultAuthorizedRoles - An array of roles that authorize a user to access the complete Monasca API. User must have at least one of these roles. See below
  • agentAuthorizedRoles - An array of roles that authorize only the posting of metrics. See Keystone Roles below
  • adminAuthMethod - "password" if the Monasca API should adminUser and adminPassword to login to the Keystone server to check the user's token, "token" if the Monasca API should use adminToken
  • adminUser - Admin user name
  • adminPassword - Admin user password
  • adminProjectId - Specify the project ID the api should use to request an admin token. Defaults to the admin user's default project. The adminProjectId option takes precedence over adminProjectName.
  • adminProjectName - Specify the project name the api should use to request an admin token. Defaults to the admin user's default project. The adminProjectId option takes precedence over adminProjectName.
  • adminToken - A valid admin user token if adminAuthMethod is token
  • timeToCacheToken - How long the Monasca API should cache the user's token before checking it again

Keystone Roles

The Monasca API has two levels of access:

Full access - user can read/write metrics and Alarm Definitions and Alarms

Agent access - user can only write metrics

The reason for the "Agent access" level is because the Monasca Agent must be configured to use a Keystone user. Since the user and password are configured onto the all of the systems running the Monasca Agent, this user is most in danger of being compromised. If this user is limited to only writing metrics, then the damage can be limited.

To configure the user to have full access, the user must have a role that is listed in defaultAuthorizedRoles. To configure a user to have only "Agent access", the user must have a role in agentAuthorizedRoles and none of the roles in defaultAuthorizedRoles.

Design Overview

Architectural layers

Requests flow through the following architectural layers from top to bottom:

  • Resource
    • Serves as the entrypoint into the service.
    • Responsible for handling web service requests, and performing structural request validation.
  • Application
    • Responsible for providing application level implementations for specific use cases.
  • Domain
    • Contains the technology agnostic core domain model and domain service definitions.
    • Responsible for upholding invariants and defining state transitions.
  • Infrastructure
    • Contains technology specific implementations of domain services.

Documentation

python monasca api implementation

To install the python api implementation, git clone the source and run the following command::

sudo python setup.py install

If it installs successfully, you will need to make changes to the following two files to reflect your system settings, especially where kafka server is located::

/etc/monasca/monasca.ini
/etc/monasca/monasca.conf

Once the configurations are modified to match your environment, you can start up the server by following the following instructions.

To start the server, run the following command:

Running the server in foreground mode
gunicorn -k eventlet --worker-connections=2000 --backlog=1000
         --paste /etc/monasca/monasca.ini

Running the server as daemons
gunicorn -k eventlet --worker-connections=2000 --backlog=1000
         --paste /etc/monasca/monasca.ini -D

To check if the code follows python coding style, run the following command from the root directory of this project

tox -e pep8

To run all the unit test cases, run the following command from the root directory of this project

tox -e py27   (or -e py26, -e py33)

License

Copyright (c) 2014 Hewlett-Packard Development Company, L.P.

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.