├── .coveragerc ├── .gitignore ├── .gitreview ├── .stestr.conf ├── .zuul.yaml ├── CONTRIBUTING.rst ├── LICENSE ├── README.rst ├── api-ref ├── locale │ └── .gitkeep └── source │ ├── conf.py │ └── index.rst ├── babel.cfg ├── bindep.txt ├── common └── build_common.sh ├── config-generator ├── README.rst ├── __init__.py ├── monasca-api.conf └── policy.conf ├── contrib └── post_test_hook.sh ├── devstack ├── README.md ├── Vagrantfile ├── files │ ├── cassandra │ │ └── monasca_schema.cql │ ├── debs │ │ └── monasca-api │ ├── elasticsearch │ │ └── elasticsearch.yml │ ├── grafana │ │ ├── dashboards.d │ │ │ ├── 08-openstack.json │ │ │ ├── 09-monasca.json │ │ │ ├── 11-maradb.json │ │ │ ├── 12-api.json │ │ │ ├── 13-storm.json │ │ │ ├── 14-persister.json │ │ │ ├── 15-influxdb.json │ │ │ ├── 16-zookeper.json │ │ │ ├── 17-notification.json │ │ │ ├── 18-kafka.json │ │ │ ├── 19-statsd.json │ │ │ ├── 20-kibana.json │ │ │ ├── 22-logtransformer.json │ │ │ ├── 23-logtmetrics.json │ │ │ └── 24-logpersister.json │ │ ├── grafana-init.py │ │ ├── grafana-server │ │ └── grafana.ini │ ├── influxdb │ │ ├── influxdb │ │ └── influxdb.conf │ ├── kafka │ │ ├── kafka-server-start.sh │ │ ├── kafka.service │ │ └── server.properties │ ├── kibana │ │ └── kibana.yml │ ├── monasca-agent │ │ ├── elastic.yaml │ │ ├── host_alive.yaml │ │ ├── http_check.yaml │ │ ├── kafka_consumer.yaml │ │ ├── monasca-reconfigure │ │ ├── mysql.yaml │ │ ├── process.yaml │ │ └── zk.yaml │ ├── monasca-api │ │ ├── apache-monasca-api.template │ │ ├── api-config.yml │ │ └── monasca-api.service │ ├── monasca-log-agent │ │ └── agent.conf │ ├── monasca-log-metrics │ │ └── log-metrics.conf │ ├── monasca-log-persister │ │ └── persister.conf │ ├── monasca-log-transformer │ │ └── transformer.conf │ ├── monasca-persister │ │ └── persister.yml │ ├── monasca-thresh │ │ ├── monasca-thresh │ │ └── thresh-config.yml │ ├── schema │ │ └── influxdb_setup.py │ ├── storm.yaml │ ├── vertica │ │ ├── mon_alarms.sql │ │ ├── mon_metrics.sql │ │ ├── roles.sql │ │ └── users.sql │ └── zookeeper │ │ ├── log4j.properties │ │ ├── zoo.cfg │ │ └── zookeeper.service ├── lib │ ├── client.sh │ ├── constants.sh │ ├── monasca-log.sh │ ├── notification.sh │ ├── persister.sh │ ├── profile.sh │ ├── storm.sh │ ├── ui.sh │ └── zookeeper.sh ├── override-defaults ├── plugin.sh └── settings ├── doc ├── api-samples │ ├── .gitkeep │ └── empty.json ├── requirements.txt └── source │ ├── .gitkeep │ ├── _static │ └── images │ │ ├── architecture.png │ │ └── architecture.svg │ ├── admin │ └── index.rst │ ├── cli │ └── index.rst │ ├── conf.py │ ├── configuration │ └── sample.rst │ ├── contributor │ ├── .gitignore │ ├── code.rst │ ├── contributing.rst │ ├── db_migrations.rst │ └── index.rst │ ├── glossary.rst │ ├── index.rst │ ├── install │ └── index.rst │ └── user │ └── index.rst ├── docker ├── Dockerfile ├── README.rst ├── api-config.ini.j2 ├── api-gunicorn.conf.j2 ├── api-logging.conf.j2 ├── build_image.sh ├── health_check.py ├── monasca-api.conf.j2 └── start.sh ├── docs ├── java.md └── monasca-api-spec.md ├── etc ├── api-config.ini ├── api-logging.conf └── api-uwsgi.ini ├── java ├── pom.xml └── src │ ├── assembly │ └── tar.xml │ ├── deb │ ├── control │ │ ├── control │ │ └── prerm │ └── etc │ │ └── api-config.yml-sample │ ├── main │ ├── java │ │ └── monasca │ │ │ └── api │ │ │ ├── ApiConfig.java │ │ │ ├── MonApiApplication.java │ │ │ ├── MonApiModule.java │ │ │ ├── app │ │ │ ├── AlarmDefinitionService.java │ │ │ ├── AlarmService.java │ │ │ ├── ApplicationModule.java │ │ │ ├── MetricService.java │ │ │ ├── command │ │ │ │ ├── CreateAlarmDefinitionCommand.java │ │ │ │ ├── CreateMetricCommand.java │ │ │ │ ├── CreateNotificationMethodCommand.java │ │ │ │ ├── PatchAlarmDefinitionCommand.java │ │ │ │ ├── PatchNotificationMethodCommand.java │ │ │ │ ├── UpdateAlarmCommand.java │ │ │ │ ├── UpdateAlarmDefinitionCommand.java │ │ │ │ └── UpdateNotificationMethodCommand.java │ │ │ ├── package-info.java │ │ │ └── validation │ │ │ │ ├── AlarmValidation.java │ │ │ │ ├── DimensionValidation.java │ │ │ │ ├── MetricNameValidation.java │ │ │ │ ├── NotificationMethodValidation.java │ │ │ │ ├── Validation.java │ │ │ │ └── ValueMetaValidation.java │ │ │ ├── domain │ │ │ ├── DomainModule.java │ │ │ ├── exception │ │ │ │ ├── EntityExistsException.java │ │ │ │ ├── EntityNotFoundException.java │ │ │ │ ├── InvalidEntityException.java │ │ │ │ └── MultipleMetricsException.java │ │ │ ├── model │ │ │ │ ├── alarm │ │ │ │ │ ├── Alarm.java │ │ │ │ │ ├── AlarmCount.java │ │ │ │ │ └── AlarmRepo.java │ │ │ │ ├── alarmdefinition │ │ │ │ │ ├── AlarmDefinition.java │ │ │ │ │ └── AlarmDefinitionRepo.java │ │ │ │ ├── alarmstatehistory │ │ │ │ │ ├── AlarmStateHistory.java │ │ │ │ │ └── AlarmStateHistoryRepo.java │ │ │ │ ├── common │ │ │ │ │ ├── Link.java │ │ │ │ │ ├── Linked.java │ │ │ │ │ └── Paged.java │ │ │ │ ├── dimension │ │ │ │ │ ├── DimensionBase.java │ │ │ │ │ ├── DimensionName.java │ │ │ │ │ ├── DimensionRepo.java │ │ │ │ │ └── DimensionValue.java │ │ │ │ ├── measurement │ │ │ │ │ ├── MeasurementRepo.java │ │ │ │ │ └── Measurements.java │ │ │ │ ├── metric │ │ │ │ │ ├── MetricDefinitionRepo.java │ │ │ │ │ └── MetricName.java │ │ │ │ ├── notificationmethod │ │ │ │ │ ├── NotificationMethod.java │ │ │ │ │ ├── NotificationMethodRepo.java │ │ │ │ │ ├── NotificationMethodType.java │ │ │ │ │ └── NotificationMethodTypesRepo.java │ │ │ │ ├── statistic │ │ │ │ │ ├── StatisticRepo.java │ │ │ │ │ └── Statistics.java │ │ │ │ └── version │ │ │ │ │ ├── Version.java │ │ │ │ │ └── VersionRepo.java │ │ │ ├── package-info.java │ │ │ └── service │ │ │ │ └── impl │ │ │ │ └── VersionRepoImpl.java │ │ │ ├── infrastructure │ │ │ ├── InfrastructureModule.java │ │ │ ├── middleware │ │ │ │ └── MiddlewareConfiguration.java │ │ │ ├── package-info.java │ │ │ ├── persistence │ │ │ │ ├── DimensionQueries.java │ │ │ │ ├── PersistUtils.java │ │ │ │ ├── SubAlarmDefinitionQueries.java │ │ │ │ ├── Utils.java │ │ │ │ ├── hibernate │ │ │ │ │ ├── AlarmDefinitionSqlRepoImpl.java │ │ │ │ │ ├── AlarmHibernateUtils.java │ │ │ │ │ ├── AlarmSqlRepoImpl.java │ │ │ │ │ ├── BaseSqlRepo.java │ │ │ │ │ ├── NotificationMethodSqlRepoImpl.java │ │ │ │ │ └── NotificationMethodTypesSqlRepoImpl.java │ │ │ │ ├── influxdb │ │ │ │ │ ├── InfluxV9AlarmStateHistoryRepo.java │ │ │ │ │ ├── InfluxV9DimensionRepo.java │ │ │ │ │ ├── InfluxV9MeasurementRepo.java │ │ │ │ │ ├── InfluxV9MetricDefinitionRepo.java │ │ │ │ │ ├── InfluxV9RepoReader.java │ │ │ │ │ ├── InfluxV9StatisticRepo.java │ │ │ │ │ ├── InfluxV9Utils.java │ │ │ │ │ └── Series.java │ │ │ │ ├── mysql │ │ │ │ │ ├── AlarmDefinitionMySqlRepoImpl.java │ │ │ │ │ ├── AlarmMySqlRepoImpl.java │ │ │ │ │ ├── MySQLUtils.java │ │ │ │ │ ├── NotificationMethodMySqlRepoImpl.java │ │ │ │ │ └── NotificationMethodTypesMySqlRepoImpl.java │ │ │ │ └── vertica │ │ │ │ │ ├── AlarmStateHistoryVerticaRepoImpl.java │ │ │ │ │ ├── DimensionVerticaRepoImpl.java │ │ │ │ │ ├── MeasurementVerticaRepoImpl.java │ │ │ │ │ ├── MetricDefinitionVerticaRepoImpl.java │ │ │ │ │ ├── MetricQueries.java │ │ │ │ │ ├── StatisticVerticaRepoImpl.java │ │ │ │ │ └── VerticaDataSourceFactory.java │ │ │ └── servlet │ │ │ │ ├── MockAuthenticationFilter.java │ │ │ │ ├── PostAuthenticationFilter.java │ │ │ │ ├── PreAuthenticationFilter.java │ │ │ │ └── RoleAuthorizationFilter.java │ │ │ └── resource │ │ │ ├── AlarmDefinitionResource.java │ │ │ ├── AlarmResource.java │ │ │ ├── DimensionResource.java │ │ │ ├── Links.java │ │ │ ├── MeasurementResource.java │ │ │ ├── MetricResource.java │ │ │ ├── NotificationMethodResource.java │ │ │ ├── NotificationMethodTypesResource.java │ │ │ ├── StatisticResource.java │ │ │ ├── VersionResource.java │ │ │ ├── annotation │ │ │ └── PATCH.java │ │ │ ├── exception │ │ │ ├── ConstraintViolationExceptionMapper.java │ │ │ ├── EntityExistsExceptionMapper.java │ │ │ ├── EntityNotFoundExceptionMapper.java │ │ │ ├── ErrorMessage.java │ │ │ ├── Exceptions.java │ │ │ ├── IllegalArgumentExceptionMapper.java │ │ │ ├── InvalidEntityExceptionMapper.java │ │ │ ├── JsonMappingExceptionManager.java │ │ │ ├── JsonProcessingExceptionMapper.java │ │ │ ├── MultipleMetricsExceptionMapper.java │ │ │ └── ThrowableExceptionMapper.java │ │ │ └── serialization │ │ │ └── SubAlarmExpressionSerializer.java │ └── resources │ │ └── api-config.yml │ └── test │ ├── java │ └── monasca │ │ └── api │ │ ├── app │ │ ├── AlarmDefinitionServiceTest.java │ │ ├── command │ │ │ ├── CreateAlarmDefinitionCommandTest.java │ │ │ └── CreateNotificationMethodTest.java │ │ └── validation │ │ │ ├── AlarmExpressionsTest.java │ │ │ ├── DimensionsTest.java │ │ │ ├── ValidationTest.java │ │ │ └── ValueMetaValidationTest.java │ │ ├── domain │ │ └── model │ │ │ ├── AbstractModelTest.java │ │ │ ├── AlarmDefinitionTest.java │ │ │ ├── NotificationMethodTest.java │ │ │ └── VersionTest.java │ │ ├── infrastructure │ │ └── persistence │ │ │ ├── PersistUtilsTest.java │ │ │ ├── SubAlarmDefinitionQueriesTest.java │ │ │ ├── hibernate │ │ │ ├── AlarmDefinitionSqlRepositoryImplTest.java │ │ │ ├── AlarmHibernateUtilsTest.java │ │ │ ├── AlarmSqlRepositoryImplTest.java │ │ │ ├── HibernateUtil.java │ │ │ ├── NotificationMethodSqlRepositoryImplTest.java │ │ │ ├── NotificationMethodTypesSqlRepositoryImplTest.java │ │ │ └── TestHelper.java │ │ │ ├── influxdb │ │ │ └── InfluxV9UtilsTest.java │ │ │ ├── mysql │ │ │ ├── AlarmDefinitionMySqlRepositoryImplTest.java │ │ │ ├── AlarmMySqlRepositoryImplTest.java │ │ │ ├── NotificationMethodMySqlRepositoryImplTest.java │ │ │ └── NotificationMethodTypeMySqlRepositoryImplTest.java │ │ │ └── vertica │ │ │ ├── AlarmStateHistoryVerticaRepositoryImplTest.java │ │ │ ├── MeasurementVerticaRepositoryImplTest.java │ │ │ ├── MetricDefinitionVerticaRepositoryImplTest.java │ │ │ └── MetricQueriesTest.java │ │ ├── integration │ │ ├── AlarmIntegrationTest.java │ │ ├── MetricIntegrationTest.java │ │ ├── NotificationMethodIntegrationTest.java │ │ └── docker │ │ │ └── ITInfluxDBTest.java │ │ └── resource │ │ ├── AbstractMonApiResourceTest.java │ │ ├── AlarmDefinitionResourceTest.java │ │ ├── DimensionResourceTest.java │ │ ├── LinksTest.java │ │ ├── MetricResourceTest.java │ │ ├── NotificationMethodResourceTest.java │ │ ├── NotificationMethodTypeResourceTest.java │ │ ├── StatisticResourceTest.java │ │ ├── VersionResourceTest.java │ │ └── exception │ │ └── ErrorMessages.java │ └── resources │ ├── fixtures │ ├── alarm.json │ ├── metricSet.json │ ├── metricWithoutDimensionName.json │ ├── metricWithoutName.json │ ├── metricWithoutTimestamp.json │ ├── metricWithoutValue.json │ ├── newAlarm.json │ ├── newNotificationMethod.json │ ├── newNotificationMethodWithInvalidEnum.json │ ├── newNotificationMethodWithLowercaseEnum.json │ ├── newNotificationMethodWithPeriod.json │ ├── notificationMethod.json │ └── version.json │ ├── monasca-api-config.yml │ └── monasca │ └── api │ └── infrastructure │ └── persistence │ ├── mysql │ ├── alarm.sql │ ├── notification_method.sql │ └── notification_method_type.sql │ └── vertica │ └── metrics.sql ├── monasca_api ├── __init__.py ├── api │ ├── __init__.py │ ├── alarm_definitions_api_v2.py │ ├── alarms_api_v2.py │ ├── core │ │ ├── __init__.py │ │ ├── log │ │ │ ├── __init__.py │ │ │ ├── exceptions.py │ │ │ ├── log_publisher.py │ │ │ ├── model.py │ │ │ └── validation.py │ │ ├── request.py │ │ └── request_context.py │ ├── healthcheck_api.py │ ├── logs_api.py │ ├── metrics_api_v2.py │ ├── notifications_api_v2.py │ ├── notificationstype_api_v2.py │ ├── server.py │ ├── versions_api.py │ └── wsgi.py ├── cmd │ ├── __init__.py │ ├── monasca_db.py │ └── status.py ├── common │ ├── __init__.py │ ├── messaging │ │ ├── __init__.py │ │ ├── exceptions.py │ │ ├── fake_publisher.py │ │ ├── kafka_publisher.py │ │ ├── message_formats │ │ │ ├── __init__.py │ │ │ └── metrics.py │ │ └── publisher.py │ ├── policy │ │ ├── __init__.py │ │ ├── i18n.py │ │ └── policy_engine.py │ ├── repositories │ │ ├── __init__.py │ │ ├── alarm_definitions_repository.py │ │ ├── alarms_repository.py │ │ ├── cassandra │ │ │ ├── __init__.py │ │ │ └── metrics_repository.py │ │ ├── constants.py │ │ ├── exceptions.py │ │ ├── fake │ │ │ ├── __init__.py │ │ │ └── metrics_repository.py │ │ ├── influxdb │ │ │ ├── __init__.py │ │ │ └── metrics_repository.py │ │ ├── metrics_repository.py │ │ ├── model │ │ │ ├── __init__.py │ │ │ └── sub_alarm_definition.py │ │ ├── notification_method_type_repository.py │ │ ├── notifications_repository.py │ │ └── sqla │ │ │ ├── __init__.py │ │ │ ├── alarm_definitions_repository.py │ │ │ ├── alarms_repository.py │ │ │ ├── models.py │ │ │ ├── notification_method_type_repository.py │ │ │ ├── notifications_repository.py │ │ │ └── sql_repository.py │ └── rest │ │ ├── __init__.py │ │ ├── exceptions.py │ │ └── utils.py ├── conf │ ├── __init__.py │ ├── cassandra.py │ ├── dispatcher.py │ ├── global.py │ ├── influxdb.py │ ├── kafka.py │ ├── log_publisher.py │ ├── messaging.py │ ├── repositories.py │ ├── security.py │ └── types.py ├── config.py ├── db │ ├── README │ ├── __init__.py │ ├── alembic.ini │ ├── alembic │ │ ├── __init__.py │ │ ├── env.py │ │ ├── script.py.mako │ │ └── versions │ │ │ ├── 00597b5c8325_initial.py │ │ │ ├── 0cce983d957a_deterministic_alarms.py │ │ │ ├── 26083b298bb7_remove_builtin_notification_types.py │ │ │ ├── 30181b42434b_remove_event_and_migration_tables.py │ │ │ ├── 6b2b88f3cab4_add_sub_alarm_state.py │ │ │ ├── 8781a256f0c1_add_inhibited_and_silenced_to_alarms.py │ │ │ ├── c2f85438d6f3_period_notifications.py │ │ │ ├── d8b801498850_remove_stream_action_types.py │ │ │ └── f69cb3152a76_remove_inhibited_silenced_from_alarms.py │ └── fingerprint.py ├── expression_parser │ ├── __init__.py │ └── alarm_expr_parser.py ├── hacking │ ├── __init__.py │ └── checks.py ├── healthcheck │ ├── __init__.py │ ├── alarms_db_check.py │ ├── base.py │ ├── kafka_check.py │ ├── keystone_protocol.py │ └── metrics_db_check.py ├── healthchecks.py ├── policies │ ├── __init__.py │ ├── alarms.py │ ├── delegate.py │ ├── healthcheck.py │ ├── logs.py │ ├── metrics.py │ ├── notifications.py │ └── versions.py ├── tests │ ├── __init__.py │ ├── base.py │ ├── cmd │ │ ├── __init__.py │ │ └── test_status.py │ ├── config.py │ ├── db │ │ ├── __init__.py │ │ └── test_fingerprint.py │ ├── policy │ │ ├── __init__.py │ │ ├── base.py │ │ └── test_policy.py │ ├── sqlite_alarm.sql │ ├── test_a_repository.py │ ├── test_ad_repository.py │ ├── test_alarm_expression.py │ ├── test_alarms.py │ ├── test_alarms_db_health_check.py │ ├── test_config_types.py │ ├── test_healthchecks.py │ ├── test_helpers.py │ ├── test_kafka_health_check.py │ ├── test_keystone_protocol.py │ ├── test_log_publisher.py │ ├── test_logs.py │ ├── test_message_formats.py │ ├── test_metrics.py │ ├── test_metrics_db_health_check.py │ ├── test_models_repository.py │ ├── test_nm_repository.py │ ├── test_notifications.py │ ├── test_policy.py │ ├── test_query_helpers.py │ ├── test_repositories.py │ ├── test_request.py │ ├── test_rest.py │ ├── test_sub_alarm_definition.py │ ├── test_validation.py │ └── test_versions.py ├── v2 │ ├── __init__.py │ ├── common │ │ ├── __init__.py │ │ ├── bulk_processor.py │ │ ├── exceptions.py │ │ ├── helpers.py │ │ ├── schemas │ │ │ ├── __init__.py │ │ │ ├── alarm_definition_request_body_schema.py │ │ │ ├── alarm_update_schema.py │ │ │ ├── exceptions.py │ │ │ └── notifications_request_body_schema.py │ │ ├── utils.py │ │ └── validation.py │ └── reference │ │ ├── __init__.py │ │ ├── alarm_definitions.py │ │ ├── alarming.py │ │ ├── alarms.py │ │ ├── helpers.py │ │ ├── logs.py │ │ ├── metrics.py │ │ ├── notifications.py │ │ ├── notificationstype.py │ │ ├── resource.py │ │ ├── version_2_0.py │ │ └── versions.py └── version.py ├── perf ├── README.md └── monasca_query_test.jmx ├── playbooks └── docker-publish.yml ├── pom.xml ├── releasenotes ├── locale │ └── .gitkeep ├── notes │ ├── add-cassandra-loadbalancing-policy-4d5d0e7e8064a870.yaml │ ├── add-monasca-status-upgrade-check-c37e6910c2eb0150.yaml │ ├── add_legacy_kafka_client_enabled_option-7be9bc4e0fcecc70.yaml │ ├── alarms-count-dimensions-f746ca6c725335b2.yaml │ ├── apache-kafka-101-d5f3454fd445c727.yaml │ ├── cassandra-connectiontimeout-option-13bc68e2fcd56580.yaml │ ├── config_gen-ead0282db82e6c0f.yaml │ ├── deprecate-json-formatted-policy-file-2f00c9efa9e274af.yaml │ ├── disable-legacy-kafka-client-16dd1ac1894fe7a0.yaml │ ├── drop-py-2-7-aee58a9afab0e4b9.yaml │ ├── elasticsearch-cluster-upgrade-4b7bdc9c17e0169f.yaml │ ├── enable-disk-tsi-40f29262a0301531.yaml │ ├── fix-cassandra-cluster-port.yaml │ ├── fix-db-migration-issue-2006984-6676bd3a8a34c9ae.yaml │ ├── influx_1.3.3-1be2009139641336.yaml │ ├── influx_1.3.8-e6b0be63d7d7222f.yaml │ ├── influxdb-support-for-db-per-tenant-6ada0c3979de6df8.yaml │ ├── influxdb_1.3.9-666fc98a5357890d.yaml │ ├── mergeapis-baa6905c7b8fd070.yaml │ ├── os-docs-550ce9ad68a4a29e.yaml │ ├── oslo-policy-345ff286820badc6.yaml │ ├── oslo-policy-aebaebd218b9d2ff.yaml │ ├── relax-constraints-for-setting-periodic-notifications-68f6c2ed6f89ebc0.yaml │ ├── remove-database-url-option-efd6c09b771063c0.yaml │ ├── stop_pre_populating_built_in_monasca_notification_plugins_in_db-140ece49106b4a5a.yaml │ ├── storm_1.1.3-4aa16a9c648cd89b.yaml │ ├── support-configuring-kafka-post-size-4baa10353e859b8a.yaml │ ├── support-timerange-for-dimension-names-and-values-e5a2ba64700dcd0b.yaml │ ├── upgrade-influxdb-3fa94ef4b15c8217.yaml │ ├── upgrade-storm-7b4f262d3783d589.yaml │ ├── upgrade_kafka_2.0.1-b53f180d751e47f5.yaml │ └── use-standard-config-file-path-a4c1a29d9d3fcc07.yaml └── source │ ├── conf.py │ ├── index.rst │ ├── pike.rst │ ├── queens.rst │ ├── rocky.rst │ ├── stein.rst │ ├── train.rst │ ├── unreleased.rst │ ├── ussuri.rst │ ├── victoria.rst │ ├── wallaby.rst │ ├── xena.rst │ └── yoga.rst ├── requirements.txt ├── run_maven.sh ├── setup.cfg ├── setup.py ├── test-requirements.txt ├── tools └── bashate.sh └── tox.ini /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | branch = True 3 | source = monasca_api 4 | omit = monasca_api/tests/* 5 | 6 | [report] 7 | ignore_errors = True 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[co] 2 | *~ 3 | docs/build/* 4 | dist 5 | build 6 | cover* 7 | .coverage 8 | *.egg 9 | *.egg-info 10 | .testrepository 11 | .stestr 12 | .tox 13 | ChangeLog 14 | MANIFEST 15 | monasca.log 16 | 17 | 18 | *.swp 19 | *.iml 20 | .DS_Store 21 | .cache 22 | .classpath 23 | .idea 24 | .project 25 | .target/ 26 | java/debs/* 27 | .settings/ 28 | target 29 | test-output/ 30 | logs/ 31 | *config*.yml 32 | db/config.yml 33 | virtenv/* 34 | .vagrant 35 | AUTHORS 36 | 37 | *.sample 38 | -------------------------------------------------------------------------------- /.gitreview: -------------------------------------------------------------------------------- 1 | [gerrit] 2 | host=review.opendev.org 3 | port=29418 4 | project=openstack/monasca-api 5 | -------------------------------------------------------------------------------- /.stestr.conf: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | test_path=$OS_TEST_PATH 3 | top_dir=./ 4 | group_regex=monasca_api\.tests(?:\.|_)([^_]+) 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | The source repository for this project can be found at: 2 | 3 | https://opendev.org/openstack/monasca-api.git 4 | 5 | Pull requests submitted through GitHub are not monitored. 6 | 7 | To start contributing to OpenStack, follow the steps in the contribution guide 8 | to set up and use Gerrit: 9 | 10 | https://docs.openstack.org/contributors/code-and-documentation/quick-start.html 11 | 12 | Bugs should be filed on Storyboard: 13 | 14 | https://storyboard.openstack.org/#!/project/863 15 | 16 | For more specific information about contributing to this repository, see the 17 | Monasca contributor guide: 18 | 19 | https://docs.openstack.org/monasca-api/latest/contributor/contributing.html 20 | -------------------------------------------------------------------------------- /api-ref/locale/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/api-ref/locale/.gitkeep -------------------------------------------------------------------------------- /api-ref/source/index.rst: -------------------------------------------------------------------------------- 1 | :tocdepth: 2 2 | 3 | .. 4 | Copyright 2017 Fujitsu LIMITED 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); you may 7 | not use this file except in compliance with the License. You may obtain 8 | a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | License for the specific language governing permissions and limitations 16 | under the License. 17 | 18 | ======================= 19 | Monitoring Service APIs 20 | ======================= 21 | 22 | .. rest_expand_all:: 23 | -------------------------------------------------------------------------------- /babel.cfg: -------------------------------------------------------------------------------- 1 | [python: **.py] 2 | 3 | -------------------------------------------------------------------------------- /bindep.txt: -------------------------------------------------------------------------------- 1 | # This is a cross-platform list tracking distribution packages needed for install and tests; 2 | # see http://docs.openstack.org/infra/bindep/ for additional information. 3 | 4 | maven 5 | openjdk-8-jdk 6 | libssl-dev [platform:dpkg] 7 | -------------------------------------------------------------------------------- /common/build_common.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -x 3 | ME=`whoami` 4 | echo "Running as user: $ME" 5 | MVN=$1 6 | VERSION=$2 7 | BRANCH=$3 8 | 9 | check_user() { 10 | ME=$1 11 | if [ "${ME}" != "zuul" ]; then 12 | echo "\nERROR: Download monasca-common and do a mvn install to install the monasca-commom jars\n" 1>&2 13 | exit 1 14 | fi 15 | } 16 | 17 | BUILD_COMMON=false 18 | POM_FILE=~/.m2/repository/monasca-common/monasca-common/${VERSION}/monasca-common-${VERSION}.pom 19 | if [ ! -r "${POM_FILE}" ]; then 20 | check_user "${ME}" 21 | BUILD_COMMON=true 22 | fi 23 | 24 | # This should only be done on the stack forge system 25 | if [ "${BUILD_COMMON}" = "true" ]; then 26 | git clone -b ${BRANCH} https://git.openstack.org/openstack/monasca-common --depth 1 27 | cd monasca-common 28 | ${MVN} clean 29 | ${MVN} install 30 | fi 31 | -------------------------------------------------------------------------------- /config-generator/README.rst: -------------------------------------------------------------------------------- 1 | ================ 2 | config-generator 3 | ================ 4 | 5 | To generate sample configuration file execute:: 6 | 7 | tox -e genconfig 8 | 9 | To generate the sample policies execute:: 10 | 11 | tox -e genpolicy 12 | 13 | After generation you will have sample available in 14 | ``etc/api-policy.yaml.sample``. It contains default values for all policies. 15 | After you change it to suit your needs you will need to change monasca-api 16 | configuration to look for the new policy configuration with specific file name. 17 | Head to ``monasca-api.conf`` file and then you will need to replace 18 | in ``[oslo_policy]`` section ``policy_file`` to your desired file name 19 | (like ``api-policy.yaml``). 20 | -------------------------------------------------------------------------------- /config-generator/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/config-generator/__init__.py -------------------------------------------------------------------------------- /config-generator/monasca-api.conf: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | output_file = etc/monasca-api.conf.sample 3 | wrap_width = 79 4 | format = ini 5 | summarize = True 6 | namespace = monasca_api 7 | namespace = oslo.log 8 | namespace = oslo.db 9 | namespace = oslo.policy 10 | namespace = keystonemiddleware.auth_token 11 | -------------------------------------------------------------------------------- /config-generator/policy.conf: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | output_file = etc/api-policy.yaml.sample 3 | format = yaml 4 | namespace = monasca_api 5 | -------------------------------------------------------------------------------- /devstack/files/debs/monasca-api: -------------------------------------------------------------------------------- 1 | openjdk-8-jdk # dist:xenial,bionic,focal,jammy,noble 2 | openjdk-8-jre-headless # dist:bionic,focal,jammy,noble 3 | maven # dist:xenial,bionic,focal,jammy,noble 4 | jq # dist:xenial,bionic,focal,jammy,noble 5 | python-dev # dist:xenial,bionic,focal 6 | python3-dev # dist:jammy,noble 7 | build-essential # dist:xenial,bionic,focal,jammy,noble 8 | mailutils # dist:xenial,bionic,focal,jammy,noble 9 | python-is-python3 # dist:focal,jammy,noble -------------------------------------------------------------------------------- /devstack/files/grafana/grafana.ini: -------------------------------------------------------------------------------- 1 | [auth.keystone] 2 | enabled = true 3 | auth_url = '%KEYSTONE_AUTH_URI%' 4 | 5 | [paths] 6 | plugins = /var/lib/grafana/plugins 7 | 8 | [session] 9 | session_life_time = 1800 10 | gc_interval_time = 1800 11 | 12 | [security] 13 | login_remember_days = 0 14 | -------------------------------------------------------------------------------- /devstack/files/influxdb/influxdb: -------------------------------------------------------------------------------- 1 | # 2 | # (C) Copyright 2015 Hewlett Packard Enterprise Development Company LP 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | #    http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | # implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | # Logging 19 | STDERR="/var/log/influxdb/influxd.log" 20 | -------------------------------------------------------------------------------- /devstack/files/kafka/kafka-server-start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | if [ $# -lt 1 ]; 18 | then 19 | echo "USAGE: $0 [-daemon] server.properties" 20 | exit 1 21 | fi 22 | base_dir=$(dirname $0) 23 | export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$base_dir/../config/log4j.properties" 24 | export KAFKA_HEAP_OPTS="-Xms256m -Xmx256m" 25 | 26 | EXTRA_ARGS="-name kafkaServer -loggc" 27 | 28 | COMMAND=$1 29 | case $COMMAND in 30 | -daemon) 31 | EXTRA_ARGS="-daemon "$EXTRA_ARGS 32 | shift 33 | ;; 34 | *) 35 | ;; 36 | esac 37 | 38 | exec $base_dir/kafka-run-class.sh $EXTRA_ARGS kafka.Kafka $@ 39 | -------------------------------------------------------------------------------- /devstack/files/kafka/kafka.service: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 10 | # implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | # 14 | 15 | [Unit] 16 | Description=Kafka 17 | Requires=network.target 18 | After=network.target zookeeper.service 19 | 20 | [Service] 21 | User=kafka 22 | Group=kafka 23 | LimitNOFILE=32768:32768 24 | Environment="LOG_DIR=/var/log/kafka" 25 | Environment="KAFKA_HEAP_OPTS=-Xmx128m" 26 | ExecStart=/opt/kafka/bin/kafka-server-start.sh /etc/kafka/server.properties 27 | Restart=on-failure 28 | 29 | [Install] 30 | WantedBy=multi-user.target 31 | -------------------------------------------------------------------------------- /devstack/files/monasca-agent/elastic.yaml: -------------------------------------------------------------------------------- 1 | init_config: 2 | instances: 3 | - url: http://{{IP}}:9200 4 | cluster_stats: true 5 | pshard_stats: true 6 | index_stats: true 7 | pending_task_stats: true -------------------------------------------------------------------------------- /devstack/files/monasca-agent/host_alive.yaml: -------------------------------------------------------------------------------- 1 | init_config: 2 | ping_timeout: 1 3 | ssh_port: 22 4 | ssh_timeout: 0.5 5 | instances: 6 | - alive_test: ssh 7 | host_name: 127.0.0.1 8 | name: 127.0.0.1 9 | -------------------------------------------------------------------------------- /devstack/files/monasca-agent/http_check.yaml: -------------------------------------------------------------------------------- 1 | init_config: null 2 | instances: 3 | - name: keystone 4 | dimensions: 5 | service: keystone 6 | timeout: 3 7 | url: http://127.0.0.1/identity 8 | - name: mysql 9 | dimensions: 10 | service: mysql 11 | timeout: 3 12 | url: http://127.0.0.1:3306 13 | - name: influxdb 14 | dimensions: 15 | service: influxdb 16 | timeout: 3 17 | url: http://127.0.0.1:8086/ping 18 | - name: elasticsearch 19 | dimensions: 20 | service: elasticsearch 21 | timeout: 3 22 | url: http://{{IP}}:9200/_cat/health 23 | - name: kibana 24 | dimensions: 25 | service: kibana 26 | timeout: 3 27 | url: http://{{IP}}:5601/api/status 28 | -------------------------------------------------------------------------------- /devstack/files/monasca-agent/kafka_consumer.yaml: -------------------------------------------------------------------------------- 1 | init_config: 2 | 3 | instances: 4 | - built_by: Kafka 5 | consumer_groups: 6 | 1_metrics: 7 | metrics: [] 8 | thresh-event: 9 | events: [] 10 | thresh-metric: 11 | metrics: [] 12 | kafka_connect_str: 127.0.0.1:9092 13 | name: 127.0.0.1:9092 14 | per_partition: false 15 | -------------------------------------------------------------------------------- /devstack/files/monasca-agent/monasca-reconfigure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | '/opt/monasca-agent/bin/monasca-setup' \ 3 | -u 'monasca-agent' \ 4 | -p 'password' \ 5 | -s '%MONASCA_SERVICE_TYPE%' \ 6 | \ 7 | --keystone_url '%KEYSTONE_AUTH_URI%' \ 8 | --project_name 'mini-mon' \ 9 | --project_domain_name '%SERVICE_DOMAIN_NAME%' \ 10 | --user_domain_name '%SERVICE_DOMAIN_NAME%' \ 11 | \ 12 | --service_type '%MONASCA_SERVICE_TYPE%' \ 13 | --endpoint_type 'public' \ 14 | --region_name '%REGION_NAME%' \ 15 | \ 16 | --check_frequency '15' \ 17 | --log_level 'DEBUG' \ 18 | --overwrite \ 19 | --system_only \ 20 | --monasca_statsd_port %MONASCA_STATSD_PORT% -------------------------------------------------------------------------------- /devstack/files/monasca-agent/mysql.yaml: -------------------------------------------------------------------------------- 1 | init_config: 2 | instances: 3 | - built_by: MySQL 4 | name: mysql 5 | server: 127.0.0.1 6 | port: 3306 7 | user: root 8 | pass: secretdatabase 9 | -------------------------------------------------------------------------------- /devstack/files/monasca-agent/zk.yaml: -------------------------------------------------------------------------------- 1 | init_config: 2 | 3 | instances: 4 | - host: 127.0.0.1 5 | port: 2181 6 | timeout: 3 7 | -------------------------------------------------------------------------------- /devstack/files/monasca-api/apache-monasca-api.template: -------------------------------------------------------------------------------- 1 | Listen %PUBLICPORT% 2 | 3 | 4 | WSGIDaemonProcess monasca-api user=%USER% processes=%APIWORKERS% threads=1 display-name=%{GROUP} %VIRTUALENV% 5 | WSGIProcessGroup monasca-api 6 | WSGIScriptAlias / %PUBLICWSGI%/wsgi.py 7 | WSGIApplicationGroup %{GLOBAL} 8 | 9 | WSGIPassAuthorization On 10 | 11 | LogLevel info 12 | ErrorLog /var/log/%APACHE_NAME%/monasca-api.log 13 | CustomLog /var/log/%APACHE_NAME%/monasca-api_access.log combined 14 | 15 | SetEnv no-gzip 1 16 | AddDefaultCharset utf-8 17 | 18 | -------------------------------------------------------------------------------- /devstack/files/monasca-api/monasca-api.service: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 10 | # implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | # 14 | 15 | # Startup script for the Monasca API 16 | 17 | [Unit] 18 | Description=Monasca API Java app 19 | Requires=network.target 20 | After=network.target kafka.service influxdb.service mysql.service 21 | 22 | [Service] 23 | User=mon-api 24 | Group=monasca 25 | ExecStart=/usr/bin/java -Dfile.encoding=UTF-8 -Xmx128m -cp /opt/monasca/monasca-api.jar monasca.api.MonApiApplication server /etc/monasca/api-config.yml 26 | Restart=on-failure 27 | 28 | [Install] 29 | WantedBy=multi-user.target 30 | -------------------------------------------------------------------------------- /devstack/files/monasca-log-agent/agent.conf: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 FUJITSU LIMITED 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | # implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | input { 18 | file { 19 | add_field => { "dimensions" => { "service" => "system" }} 20 | path => "/var/log/syslog" 21 | tags => ["syslog"] 22 | codec => multiline { 23 | negate => "true" 24 | pattern => "^%{SYSLOGTIMESTAMP}" 25 | what => "previous" 26 | } 27 | } 28 | } 29 | 30 | output { 31 | monasca_log_api { 32 | monasca_log_api_url => "%MONASCA_API_URI_V2%" 33 | keystone_api_url => "%KEYSTONE_AUTH_URI%" 34 | project_name => "mini-mon" 35 | username => "monasca-agent" 36 | password => "password" 37 | user_domain_name => "default" 38 | project_domain_name => "default" 39 | dimensions => [ "hostname:devstack" ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /devstack/files/vertica/mon_alarms.sql: -------------------------------------------------------------------------------- 1 | CREATE SCHEMA MonAlarms; 2 | 3 | CREATE TABLE MonAlarms.StateHistory( 4 | id AUTO_INCREMENT, 5 | tenant_id VARCHAR, 6 | alarm_id VARCHAR, 7 | metrics VARCHAR (65000), 8 | old_state VARCHAR, 9 | new_state VARCHAR, 10 | sub_alarms VARCHAR (65000), 11 | reason VARCHAR(65000), 12 | reason_data VARCHAR(65000), 13 | time_stamp TIMESTAMP NOT NULL 14 | ) PARTITION BY EXTRACT('year' FROM time_stamp)*10000 + EXTRACT('month' FROM time_stamp)*100 + EXTRACT('day' FROM time_stamp); 15 | -------------------------------------------------------------------------------- /devstack/files/vertica/roles.sql: -------------------------------------------------------------------------------- 1 | CREATE ROLE monasca_persister; 2 | CREATE ROLE monasca_api; 3 | 4 | GRANT USAGE ON SCHEMA MonMetrics TO monasca_persister; 5 | GRANT USAGE ON SCHEMA MonAlarms TO monasca_persister; 6 | GRANT ALL ON TABLE MonMetrics.Measurements TO monasca_persister; 7 | GRANT ALL ON TABLE MonMetrics.Definitions TO monasca_persister; 8 | GRANT ALL ON TABLE MonMetrics.Dimensions TO monasca_persister; 9 | GRANT ALL ON TABLE MonMetrics.DefinitionDimensions TO monasca_persister; 10 | GRANT ALL ON TABLE MonAlarms.StateHistory TO monasca_persister; 11 | 12 | GRANT USAGE ON SCHEMA MonMetrics TO monasca_api; 13 | GRANT USAGE ON SCHEMA MonAlarms TO monasca_api; 14 | GRANT SELECT ON TABLE MonMetrics.Measurements TO monasca_api; 15 | GRANT SELECT ON TABLE MonMetrics.Definitions TO monasca_api; 16 | GRANT SELECT ON TABLE MonMetrics.Dimensions TO monasca_api; 17 | GRANT SELECT ON TABLE MonMetrics.DefinitionDimensions TO monasca_api; 18 | GRANT ALL ON TABLE MonAlarms.StateHistory TO monasca_api; 19 | -------------------------------------------------------------------------------- /devstack/files/vertica/users.sql: -------------------------------------------------------------------------------- 1 | CREATE USER mon_api IDENTIFIED BY 'password'; 2 | GRANT monasca_api TO mon_api; 3 | ALTER USER mon_api DEFAULT ROLE monasca_api; 4 | 5 | CREATE USER mon_persister IDENTIFIED BY 'password'; 6 | GRANT monasca_persister TO mon_persister; 7 | ALTER USER mon_persister DEFAULT ROLE monasca_persister; 8 | -------------------------------------------------------------------------------- /devstack/files/zookeeper/zookeeper.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Zookeeper Daemon 3 | Documentation=http://zookeeper.apache.org 4 | Requires=network.target 5 | After=network.target 6 | 7 | [Service] 8 | Type=forking 9 | WorkingDirectory=/opt/zookeeper 10 | User=zookeeper 11 | Group=zookeeper 12 | Environment=ZOO_LOG_DIR=/var/log/zookeeper 13 | ExecStart=/opt/zookeeper/bin/zkServer.sh start /opt/zookeeper/conf/zoo.cfg 14 | ExecStop=/opt/zookeeper/bin/zkServer.sh stop /opt/zookeeper/conf/zoo.cfg 15 | ExecReload=/opt/zookeeper/bin/zkServer.sh restart /opt/zookeeper/conf/zoo.cfg 16 | TimeoutSec=30 17 | Restart=on-failure 18 | 19 | [Install] 20 | WantedBy=default.target 21 | -------------------------------------------------------------------------------- /devstack/lib/client.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2017 FUJITSU LIMITED 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 6 | # not use this file except in compliance with the License. You may obtain 7 | # a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | 17 | _XTRACE_MON_CLIENT=$(set +o | grep xtrace) 18 | set +o xtrace 19 | 20 | install_monascaclient() { 21 | if python3_enabled; then 22 | enable_python3_package python-monascaclient 23 | fi 24 | git_clone $MONASCA_CLIENT_REPO $MONASCA_CLIENT_DIR $MONASCA_CLIENT_BRANCH 25 | setup_dev_lib "python-monascaclient" 26 | 27 | # install completion file 28 | monasca complete > /tmp/monasca.bash_completion 29 | sudo install -D -m 0644 -o $STACK_USER /tmp/monasca.bash_completion $MONASCA_COMPLETION_FILE 30 | rm -rf /tmp/monasca.bash_completion 31 | } 32 | 33 | clean_monascaclient() { 34 | sudo rm -rf $MONASCA_COMPLETION_FILE 35 | } 36 | 37 | ${_XTRACE_MON_CLIENT} 38 | -------------------------------------------------------------------------------- /devstack/lib/constants.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2017 FUJITSU LIMITED 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 6 | # not use this file except in compliance with the License. You may obtain 7 | # a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | 17 | _XTRACE_MON_CONST=$(set +o | grep xtrace) 18 | set +o xtrace 19 | 20 | # Location of python-monascaclient completion file 21 | MONASCA_COMPLETION_FILE=/etc/bash_completion.d/monasca.bash_completion 22 | 23 | # Location of monasca-profile 24 | MONASCA_PROFILE_FILE=/etc/profile.d/monasca.sh 25 | 26 | # monasca_service_type, used in: 27 | # keystone endpoint creation 28 | # configuration files 29 | MONASCA_SERVICE_TYPE=monitoring 30 | 31 | ${_XTRACE_MON_CONST} 32 | -------------------------------------------------------------------------------- /devstack/lib/profile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2017 FUJITSU LIMITED 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 6 | # not use this file except in compliance with the License. You may obtain 7 | # a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | 17 | _XTRACE_MON_PROFILE=$(set +o | grep xtrace) 18 | set +o xtrace 19 | 20 | function install_monasca_profile { 21 | 22 | echo_summary "Install Monasca Bash Profile" 23 | 24 | touch /tmp/monasca_cli.sh 25 | cat > /tmp/monasca_cli.sh << EOF 26 | # signalize we're in shape to use monasca here 27 | export PS1='[\u@\h \W(monasca)]\$ ' 28 | # set monasca client bash_completion 29 | source ${MONASCA_COMPLETION_FILE} 30 | # set OS_* variables 31 | source $TOP_DIR/openrc mini-mon mini-mon 32 | # override password for mini-mon (guy is not using SERVICE_PASSWORD) 33 | export OS_PASSWORD=password 34 | EOF 35 | 36 | if [[ "${MONASCA_METRICS_DB,,}" == 'cassandra' ]]; then 37 | cat >> /tmp/monasca_cli.sh << EOF 38 | # allow to use cassandra cli 39 | export CQLSH_NO_BUNDLED=true 40 | export CQLSH_HOST=${SERVICE_HOST} 41 | EOF 42 | fi 43 | 44 | sudo install -D -m 0644 -o ${STACK_USER} \ 45 | /tmp/monasca_cli.sh ${MONASCA_PROFILE_FILE} 46 | rm /tmp/monasca_cli.sh 47 | } 48 | 49 | function clean_monasca_profile { 50 | echo_summary "Clean Monasca CLI Creds" 51 | sudo rm -f ${MONASCA_PROFILE_FILE} 52 | } 53 | 54 | ${_XTRACE_DASHBOARD} 55 | -------------------------------------------------------------------------------- /devstack/override-defaults: -------------------------------------------------------------------------------- 1 | if [[ "${MONASCA_API_IMPLEMENTATION_LANG,,}" == 'java' ]]; then 2 | WSGI_MODE=mod_wsgi 3 | fi 4 | -------------------------------------------------------------------------------- /doc/api-samples/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/doc/api-samples/.gitkeep -------------------------------------------------------------------------------- /doc/api-samples/empty.json: -------------------------------------------------------------------------------- 1 | { 2 | "test": {} 3 | } 4 | -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | # documentation 2 | sphinx>=2.0.0,!=2.1.0 # BSD 3 | os-api-ref>=1.4.0 # Apache-2.0 4 | reno>=3.1.0 # Apache-2.0 5 | openstackdocstheme>=2.2.1 # Apache-2.0 6 | SQLAlchemy>=1.3.0 # MIT 7 | oslo.config>=6.8.0 # Apache-2.0 8 | -------------------------------------------------------------------------------- /doc/source/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/doc/source/.gitkeep -------------------------------------------------------------------------------- /doc/source/_static/images/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/doc/source/_static/images/architecture.png -------------------------------------------------------------------------------- /doc/source/cli/index.rst: -------------------------------------------------------------------------------- 1 | ====================== 2 | Command Line Interface 3 | ====================== 4 | 5 | monasca (python-monascaclient) 6 | ============================== 7 | This is the main command line interface for working with the 8 | Monasca services, including retrieving metrics from storage. 9 | 10 | See the https://docs.openstack.org/python-monascaclient/latest/ for details. 11 | 12 | 13 | monasca_db 14 | ========== 15 | CLI for Monasca database management. 16 | :: 17 | 18 | usage: api [-h] [--config-dir DIR] [--config-file PATH] [--version] 19 | {fingerprint,detect-revision,stamp,upgrade,version} ... 20 | 21 | 22 | monasca-status 23 | ============== 24 | CLI for checking the status of Monasca. 25 | 26 | Use the command `monasca-status upgrade check` to check 27 | the readiness of the system for an upgrade. 28 | 29 | **Return Codes** 30 | 31 | .. list-table:: 32 | :widths: 20 80 33 | :header-rows: 1 34 | 35 | * - Return code 36 | - Description 37 | * - 0 38 | - All upgrade readiness checks passed successfully and there is nothing 39 | to do. 40 | * - 1 41 | - At least one check encountered an issue and requires further 42 | investigation. This is considered a warning but the upgrade may be OK. 43 | * - 2 44 | - There was an upgrade status check failure that needs to be 45 | investigated. This should be considered something that stops an 46 | upgrade. 47 | * - 255 48 | - An unexpected error occurred. 49 | 50 | **History** 51 | 52 | Introduced in the Stein cycle as part of the OpenStack Community wide goal. 53 | https://governance.openstack.org/tc/goals/stein/upgrade-checkers.html 54 | -------------------------------------------------------------------------------- /doc/source/configuration/sample.rst: -------------------------------------------------------------------------------- 1 | .. _sample-configuration: 2 | 3 | ------- 4 | Samples 5 | ------- 6 | 7 | The following sections show sample configuration files for monasca-api and 8 | related utilities. These are generated from the code 9 | (apart from the samples for logging and paster) and reflect the current state 10 | of code in the monasca-api repository. 11 | 12 | 13 | .. _sample-configuration-api: 14 | 15 | Sample Configuration For Application 16 | ------------------------------------ 17 | 18 | This sample configuration can also be viewed in `monasca-api.conf.sample 19 | <../_static/monasca-api.conf.sample>`_. 20 | 21 | .. literalinclude:: ../_static/monasca-api.conf.sample 22 | 23 | .. _sample-configuration-logging: 24 | 25 | Sample Configuration For Logging 26 | -------------------------------- 27 | 28 | This sample configuration can also be viewed in `api-logging.conf 29 | `_. 30 | 31 | .. literalinclude:: ../../../etc/api-logging.conf 32 | 33 | 34 | Sample Configuration For Paster 35 | ------------------------------- 36 | 37 | This sample configuration can also be viewed in `api-config.ini 38 | `_. 39 | 40 | .. literalinclude:: ../../../etc/api-config.ini 41 | -------------------------------------------------------------------------------- /doc/source/contributor/.gitignore: -------------------------------------------------------------------------------- 1 | # codebase documentation is autogenerated 2 | # do not track it 3 | api/ 4 | -------------------------------------------------------------------------------- /doc/source/contributor/code.rst: -------------------------------------------------------------------------------- 1 | .. _codedocs: 2 | 3 | ====================== 4 | Codebase documentation 5 | ====================== 6 | 7 | Following section contains codebase documenation generated with, a little 8 | bit of assistance, `sphinx.ext.autodoc`_. 9 | 10 | .. _`sphinx.ext.autodoc`: http://www.sphinx-doc.org/en/stable/ext/autodoc.html 11 | 12 | Modules 13 | ======= 14 | 15 | .. toctree:: 16 | :maxdepth: 2 17 | -------------------------------------------------------------------------------- /doc/source/contributor/db_migrations.rst: -------------------------------------------------------------------------------- 1 | Database Migrations 2 | ------------------- 3 | 4 | Monasca uses `Alembic `_ 5 | migrations to set up its configuration database. If you need to change the 6 | configuration database's schema, you need to create a migration to adjust the 7 | database accordingly, as follows:: 8 | 9 | cd monasca_api/db/ 10 | alembic revision 11 | 12 | This will create a new skeleton revision for you to edit. You will find 13 | existing revisions to use for inspiration in the 14 | ``/monasca_api/db/alembic/versions/`` directory. 15 | 16 | Measurement data stored in a Time Series database (such as InfluxDB) would 17 | be migrated to a new version using standard practice for a given TSDB. 18 | -------------------------------------------------------------------------------- /doc/source/contributor/index.rst: -------------------------------------------------------------------------------- 1 | ========================== 2 | Contribution documentation 3 | ========================== 4 | 5 | .. toctree:: 6 | :maxdepth: 1 7 | 8 | contributing.rst 9 | db_migrations.rst 10 | code.rst 11 | -------------------------------------------------------------------------------- /doc/source/glossary.rst: -------------------------------------------------------------------------------- 1 | ======== 2 | Glossary 3 | ======== 4 | -------------------------------------------------------------------------------- /doc/source/install/index.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Installation 3 | ============ 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | -------------------------------------------------------------------------------- /doc/source/user/index.rst: -------------------------------------------------------------------------------- 1 | ========== 2 | User guide 3 | ========== 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | -------------------------------------------------------------------------------- /docker/api-config.ini.j2: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | name = monasca_api 3 | 4 | [pipeline:main] 5 | pipeline = request_id auth api 6 | 7 | [app:api] 8 | paste.app_factory = monasca_api.api.server:launch 9 | 10 | [filter:auth] 11 | paste.filter_factory = monasca_api.healthcheck.keystone_protocol:filter_factory 12 | 13 | [filter:request_id] 14 | paste.filter_factory = oslo_middleware.request_id:RequestId.factory 15 | 16 | [server:main] 17 | use = egg:gunicorn#main 18 | host = 0.0.0.0 19 | port = {{ MONASCA_CONTAINER_API_PORT }} 20 | workers = 9 21 | worker-connections = 2000 22 | worker-class = eventlet 23 | timeout = 30 24 | backlog = 2048 25 | keepalive = 2 26 | proc_name = monasca_api 27 | #loglevel = DEBUG 28 | -------------------------------------------------------------------------------- /docker/api-gunicorn.conf.j2: -------------------------------------------------------------------------------- 1 | bind = '0.0.0.0:{{ MONASCA_CONTAINER_API_PORT }}' 2 | proc_name = 'monasca-api' 3 | 4 | backlog = {{ GUNICORN_BACKLOG | int }} 5 | workers = {{ GUNICORN_WORKERS | int }} 6 | worker_class = '{{ GUNICORN_WORKER_CLASS }}' 7 | worker_connections = '{{ GUNICORN_WORKER_CONNECTIONS }}' 8 | timeout = {{ GUNICORN_TIMEOUT | int }} 9 | 10 | {% if ADD_ACCESS_LOG == true %} 11 | accesslog = '-' 12 | {% endif %} 13 | access_log_format = '{{ ACCESS_LOG_FIELDS }}' 14 | 15 | capture_output = True 16 | -------------------------------------------------------------------------------- /docker/api-logging.conf.j2: -------------------------------------------------------------------------------- 1 | [default] 2 | disable_existing_loggers = 0 3 | 4 | [loggers] 5 | keys = root, gunicorn.access, sqlalchemy, kafka, kafka.consumer, urllib3 6 | 7 | [handlers] 8 | keys = console, console_access 9 | 10 | [formatters] 11 | keys = context, generic 12 | 13 | [logger_root] 14 | level = {{ LOG_LEVEL_ROOT }} 15 | handlers = console 16 | 17 | [logger_gunicorn.access] 18 | level = INFO 19 | handlers = console_access 20 | propagate = 0 21 | qualname = gunicorn.access 22 | 23 | [logger_sqlalchemy] 24 | qualname = sqlalchemy.engine 25 | # "level = INFO" logs SQL queries. 26 | # "level = DEBUG" logs SQL queries and results. 27 | # "level = WARN" logs neither. (Recommended for production systems.) 28 | level = ERROR 29 | handlers = console 30 | propagate=0 31 | 32 | [logger_kafka.consumer] 33 | qualname = kafka.consumer 34 | level = INFO 35 | formatter = default 36 | handlers = console 37 | propagate = 0 38 | 39 | [logger_kafka] 40 | qualname = monasca_common.kafka_lib 41 | level = INFO 42 | formatter = default 43 | handlers = console 44 | propagate = 0 45 | 46 | [logger_urllib3] 47 | qualname = urllib3.connectionpool 48 | level = INFO 49 | formatter = default 50 | handlers = console 51 | propagate = 0 52 | 53 | [handler_console] 54 | class = logging.StreamHandler 55 | args = (sys.stdout,) 56 | level = {{ LOG_LEVEL_CONSOLE }} 57 | formatter = context 58 | 59 | [handler_console_access] 60 | class = logging.StreamHandler 61 | args = (sys.stdout,) 62 | level = {{ LOG_LEVEL_ACCESS }} 63 | formatter = generic 64 | 65 | [formatter_context] 66 | class = oslo_log.formatters.ContextFormatter 67 | 68 | [formatter_generic] 69 | format={{ ACCESS_LOG_FORMAT }} 70 | datefmt=%Y-%m-%d %H:%M:%S 71 | class=logging.Formatter 72 | -------------------------------------------------------------------------------- /docker/health_check.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | # (C) Copyright 2018 FUJITSU LIMITED 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 7 | # not use this file except in compliance with the License. You may obtain 8 | # a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | # License for the specific language governing permissions and limitations 16 | # under the License. 17 | 18 | """Health check will returns 0 when service is working properly.""" 19 | 20 | import logging 21 | import os 22 | import sys 23 | from urllib import request 24 | 25 | 26 | LOG_LEVEL = logging.getLevelName(os.environ.get('LOG_LEVEL', 'INFO')) 27 | logging.basicConfig(level=LOG_LEVEL) 28 | logger = logging.getLogger(__name__) 29 | 30 | API_PORT = os.environ.get('MONASCA_CONTAINER_API_PORT', '8070') 31 | url = "http://localhost:" + API_PORT + "/healthcheck" 32 | 33 | 34 | def main(): 35 | """Send health check request to health check endpoint of Monasca API.""" 36 | logger.debug('Send health check request to %s', url) 37 | try: 38 | request.urlopen(url=url) 39 | except Exception as ex: 40 | logger.error('Exception during request handling: ' + repr(ex)) 41 | sys.exit(1) 42 | 43 | 44 | if __name__ == '__main__': 45 | main() 46 | -------------------------------------------------------------------------------- /docker/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | # Starting script. 16 | # All checks and configuration templating you need to do before service 17 | # could be safely started should be added in this file. 18 | 19 | set -eo pipefail # Exit the script if any statement returns error. 20 | 21 | # Test services we need before starting our service. 22 | echo "Start script: waiting for needed services" 23 | python3 /kafka_wait_for_topics.py 24 | python3 /mysql_check.py 25 | 26 | # Template all config files before start, it will use env variables. 27 | # Read usage examples: https://pypi.org/project/Templer/ 28 | echo "Start script: creating config files from templates" 29 | templer -v -f /etc/monasca/monasca-api.conf.j2 /etc/monasca/monasca-api.conf 30 | templer -v -f /etc/monasca/api-config.ini.j2 /etc/monasca/api-config.ini 31 | templer -v -f /etc/monasca/api-logging.conf.j2 /etc/monasca/api-logging.conf 32 | templer -v -f /etc/monasca/api-gunicorn.conf.j2 /etc/monasca/api-gunicorn.conf 33 | 34 | # Start our service. 35 | echo "Start script: starting container" 36 | gunicorn \ 37 | --config /etc/monasca/api-gunicorn.conf \ 38 | --paste /etc/monasca/api-config.ini 39 | 40 | # Allow server to stay alive in case of failure for 2 hours for debugging. 41 | RESULT=$? 42 | if [ $RESULT != 0 ] && [ "$STAY_ALIVE_ON_FAILURE" = "true" ]; then 43 | echo "Service died, waiting 120 min before exiting" 44 | sleep 7200 45 | fi 46 | exit $RESULT 47 | -------------------------------------------------------------------------------- /etc/api-config.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | name = monasca_api 3 | 4 | [pipeline:main] 5 | pipeline = request_id auth api 6 | 7 | [app:api] 8 | paste.app_factory = monasca_api.api.server:launch 9 | 10 | [filter:auth] 11 | paste.filter_factory = monasca_api.healthcheck.keystone_protocol:filter_factory 12 | 13 | [filter:request_id] 14 | paste.filter_factory = oslo_middleware.request_id:RequestId.factory 15 | 16 | [server:main] 17 | use = egg:gunicorn#main 18 | host = 127.0.0.1 19 | port = 8070 20 | workers = 9 21 | worker-connections = 2000 22 | worker-class = eventlet 23 | timeout = 30 24 | backlog = 2048 25 | keepalive = 2 26 | proc_name = monasca-api 27 | loglevel = DEBUG 28 | -------------------------------------------------------------------------------- /etc/api-logging.conf: -------------------------------------------------------------------------------- 1 | [loggers] 2 | keys = root, sqlalchemy, kafka, kafkalib 3 | 4 | [handlers] 5 | keys = console, file 6 | 7 | [formatters] 8 | keys = context 9 | 10 | [logger_root] 11 | level = DEBUG 12 | handlers = console, file 13 | 14 | [logger_sqlalchemy] 15 | qualname = sqlalchemy.engine 16 | # "level = INFO" logs SQL queries. 17 | # "level = DEBUG" logs SQL queries and results. 18 | # "level = WARN" logs neither. (Recommended for production systems.) 19 | level = DEBUG 20 | handlers = console, file 21 | propagate=0 22 | 23 | [logger_kafka] 24 | qualname = kafka 25 | level = DEBUG 26 | handlers = console, file 27 | propagate = 0 28 | 29 | [logger_kafkalib] 30 | qualname = monasca_common.kafka_lib 31 | level = INFO 32 | handlers = console, file 33 | propagate = 0 34 | 35 | [handler_console] 36 | class = logging.StreamHandler 37 | args = (sys.stderr,) 38 | level = DEBUG 39 | formatter = context 40 | 41 | [handler_file] 42 | class = logging.handlers.RotatingFileHandler 43 | level = DEBUG 44 | formatter = context 45 | # store up to 5*100MB of logs 46 | args = ('/var/log/monasca/api/monasca-api.log', 'a', 104857600, 5) 47 | 48 | [formatter_context] 49 | class = oslo_log.formatters.ContextFormatter -------------------------------------------------------------------------------- /etc/api-uwsgi.ini: -------------------------------------------------------------------------------- 1 | [uwsgi] 2 | wsgi-file = /usr/local/bin/monasca-api-wsgi 3 | 4 | # Versions of mod_proxy_uwsgi>=2.0.6 should use a UNIX socket, see 5 | # http://uwsgi-docs.readthedocs.org/en/latest/Apache.html#mod-proxy-uwsgi 6 | uwsgi-socket = 127.0.0.1:8070 7 | 8 | # Override the default size for headers from the 4k default. 9 | buffer-size = 65535 10 | 11 | # This is running standalone 12 | master = true 13 | 14 | enable-threads = true 15 | 16 | # Tune this to your environment. 17 | processes = 4 18 | 19 | # uwsgi recommends this to prevent thundering herd on accept. 20 | thunder-lock = true 21 | 22 | plugins = python 23 | 24 | # This ensures that file descriptors aren't shared between keystone processes. 25 | lazy-apps = true -------------------------------------------------------------------------------- /java/src/assembly/tar.xml: -------------------------------------------------------------------------------- 1 | 4 | tar 5 | 6 | tar.gz 7 | 8 | 9 | 10 | ${project.basedir} 11 | / 12 | 13 | README* 14 | LICENSE* 15 | 16 | 17 | 18 | 19 | 20 | ${project.build.directory}/${shadedJarName}.jar 21 | / 22 | monasca-api.jar 23 | 24 | 25 | ${project.basedir}/src/deb/etc/api-config.yml-sample 26 | examples 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /java/src/deb/control/control: -------------------------------------------------------------------------------- 1 | Package: [[name]] 2 | Section: misc 3 | Priority: optional 4 | Architecture: all 5 | Depends: openjdk-7-jre-headless | openjdk-7-jre 6 | Version: [[version]]-[[timestamp]]-[[buildNumber]] 7 | Maintainer: Monasca Team 8 | Description: Monasca-API 9 | RESTful API for all Monasca data. 10 | -------------------------------------------------------------------------------- /java/src/deb/control/prerm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | case "$1" in 4 | remove) 5 | stop monasca-api 6 | ;; 7 | esac 8 | 9 | exit 0 10 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/app/ApplicationModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.app; 15 | 16 | import javax.inject.Singleton; 17 | 18 | import com.google.inject.AbstractModule; 19 | 20 | /** 21 | * Application layer bindings. 22 | */ 23 | public class ApplicationModule extends AbstractModule { 24 | @Override 25 | protected void configure() { 26 | bind(MetricService.class).in(Singleton.class); 27 | bind(AlarmDefinitionService.class).in(Singleton.class); 28 | bind(AlarmService.class).in(Singleton.class); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/app/command/UpdateAlarmCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.app.command; 15 | 16 | import javax.validation.constraints.NotNull; 17 | 18 | import monasca.common.model.alarm.AlarmState; 19 | 20 | public class UpdateAlarmCommand { 21 | 22 | @NotNull 23 | public AlarmState state; 24 | @NotNull 25 | public String lifecycleState; 26 | @NotNull 27 | public String link; 28 | 29 | public UpdateAlarmCommand() {} 30 | 31 | public UpdateAlarmCommand(AlarmState state, String lifecycleState, String link) { 32 | this.state = state; 33 | this.lifecycleState = lifecycleState; 34 | this.link = link; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/app/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | /** 16 | * Houses the application/service layer. 17 | * 18 | * @see http://martinfowler.com/eaaCatalog/serviceLayer.html 19 | */ 20 | package monasca.api.app; 21 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/DomainModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain; 15 | 16 | import javax.inject.Singleton; 17 | 18 | import com.google.inject.AbstractModule; 19 | import monasca.api.domain.model.version.VersionRepo; 20 | import monasca.api.domain.service.impl.VersionRepoImpl; 21 | 22 | /** 23 | * Domain layer bindings. 24 | */ 25 | public class DomainModule extends AbstractModule { 26 | @Override 27 | protected void configure() { 28 | bind(VersionRepo.class).to(VersionRepoImpl.class).in(Singleton.class); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/exception/EntityExistsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.exception; 15 | 16 | /** 17 | * Indicates that a domain entity already exists. 18 | */ 19 | public class EntityExistsException extends RuntimeException { 20 | private static final long serialVersionUID = 1L; 21 | 22 | public EntityExistsException(Exception ex, String msg) { 23 | super(msg, ex); 24 | } 25 | 26 | public EntityExistsException(Exception ex, String msg, Object... args) { 27 | super(String.format(msg, args), ex); 28 | } 29 | 30 | public EntityExistsException(String msg) { 31 | super(msg); 32 | } 33 | 34 | public EntityExistsException(String msg, Object... args) { 35 | super(String.format(msg, args)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/exception/EntityNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.exception; 15 | 16 | /** 17 | * Indicates that a domain entity is unknown. 18 | */ 19 | public class EntityNotFoundException extends RuntimeException { 20 | private static final long serialVersionUID = 1L; 21 | 22 | public EntityNotFoundException(Exception ex, String msg) { 23 | super(msg, ex); 24 | } 25 | 26 | public EntityNotFoundException(Exception ex, String msg, Object... args) { 27 | super(String.format(msg, args), ex); 28 | } 29 | 30 | public EntityNotFoundException(String msg) { 31 | super(msg); 32 | } 33 | 34 | public EntityNotFoundException(String msg, Object... args) { 35 | super(String.format(msg, args)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/exception/InvalidEntityException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.exception; 15 | 16 | /** 17 | * Indicates that an entity is invalid. 18 | */ 19 | public class InvalidEntityException extends RuntimeException { 20 | private static final long serialVersionUID = 1L; 21 | 22 | public InvalidEntityException(Exception ex, String msg) { 23 | super(msg, ex); 24 | } 25 | 26 | public InvalidEntityException(Exception ex, String msg, Object... args) { 27 | super(String.format(msg, args), ex); 28 | } 29 | 30 | public InvalidEntityException(String msg) { 31 | super(msg); 32 | } 33 | 34 | public InvalidEntityException(String msg, Object... args) { 35 | super(String.format(msg, args)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/model/alarmstatehistory/AlarmStateHistoryRepo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.model.alarmstatehistory; 15 | 16 | import monasca.api.domain.exception.EntityNotFoundException; 17 | import org.joda.time.DateTime; 18 | 19 | import javax.annotation.Nullable; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | /** 24 | * Repository for alarm state history. 25 | */ 26 | public interface AlarmStateHistoryRepo { 27 | /** 28 | * @throws EntityNotFoundException if an alarm cannot be found for the {@code alarmId} 29 | */ 30 | List findById(String tenantId, String alarmId, String offset, int limit) throws Exception; 31 | 32 | /** 33 | * Finds AlarmStateHistory for the given criteria. 34 | */ 35 | List find(String tenantId, Map dimensions, 36 | DateTime startTime, @Nullable DateTime endTime, @Nullable String offset, int limit) throws Exception; 37 | } 38 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/model/common/Link.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.model.common; 15 | 16 | public class Link { 17 | public String rel; 18 | 19 | public String href; 20 | 21 | public Link() {} 22 | 23 | public Link(String rel, String href) { 24 | this.rel = rel; 25 | this.href = href; 26 | } 27 | 28 | @Override 29 | public boolean equals(Object obj) { 30 | if (this == obj) 31 | return true; 32 | if (obj == null) 33 | return false; 34 | if (getClass() != obj.getClass()) 35 | return false; 36 | Link other = (Link) obj; 37 | if (href == null) { 38 | if (other.href != null) 39 | return false; 40 | } else if (!href.equals(other.href)) 41 | return false; 42 | if (rel == null) { 43 | if (other.rel != null) 44 | return false; 45 | } else if (!rel.equals(other.rel)) 46 | return false; 47 | return true; 48 | } 49 | 50 | @Override 51 | public int hashCode() { 52 | final int prime = 31; 53 | int result = 1; 54 | result = prime * result + ((href == null) ? 0 : href.hashCode()); 55 | result = prime * result + ((rel == null) ? 0 : rel.hashCode()); 56 | return result; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return String.format("Link [rel=%s, href=%s]", rel, href); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/model/common/Linked.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.model.common; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * Defines a type that can be described via a set of links. 20 | */ 21 | public interface Linked { 22 | List getLinks(); 23 | 24 | void setLinks(List links); 25 | } 26 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/model/dimension/DimensionRepo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2016 Hewlett Packard Enterprise Development LP 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.model.dimension; 15 | 16 | import javax.annotation.Nullable; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * Repository for dimensions. 22 | */ 23 | public interface DimensionRepo { 24 | /** 25 | * Finds dimension values given a dimension name and 26 | * optional metric name. 27 | */ 28 | List findValues(String metricName, 29 | String tenantId, 30 | String dimensionName, 31 | @Nullable String offset, 32 | int limit) 33 | throws Exception; 34 | 35 | /** 36 | * Finds dimension names given an optional metric name. 37 | */ 38 | List findNames(String metricName, 39 | String tenantId, 40 | @Nullable String offset, 41 | int limit) 42 | throws Exception; 43 | } 44 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/model/measurement/MeasurementRepo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, 2016 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.model.measurement; 15 | 16 | import org.joda.time.DateTime; 17 | 18 | import javax.annotation.Nullable; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | /** 23 | * Repository for measurements. 24 | */ 25 | public interface MeasurementRepo { 26 | /** 27 | * Finds measurements for the given criteria. 28 | */ 29 | List find(String tenantId, String name, Map dimensions, 30 | DateTime startTime, @Nullable DateTime endTime, @Nullable String offset, 31 | int limit, Boolean mergeMetricsFlag, List groupBy) 32 | throws Exception; 33 | } 34 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/model/metric/MetricDefinitionRepo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.model.metric; 15 | 16 | import monasca.common.model.metric.MetricDefinition; 17 | 18 | import org.joda.time.DateTime; 19 | 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | /** 24 | * Repository for metrics. 25 | */ 26 | public interface MetricDefinitionRepo { 27 | 28 | /** 29 | * Finds metrics for the given criteria. 30 | */ 31 | List find(String tenantId, String name, Map dimensions, 32 | DateTime startTime, DateTime endTime, String offset, int limit) 33 | throws Exception; 34 | 35 | List findNames(String tenantId, Map dimensions, String offset, int limit) throws Exception; 36 | } 37 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/model/notificationmethod/NotificationMethodType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2016 Hewlett Packard Enterprise Development LP 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.model.notificationmethod; 15 | 16 | import monasca.common.model.domain.common.AbstractEntity; 17 | 18 | public class NotificationMethodType extends AbstractEntity{ 19 | 20 | private String type; 21 | 22 | 23 | public NotificationMethodType() { 24 | } 25 | 26 | public NotificationMethodType(String type) { 27 | this.type = type.toUpperCase(); 28 | } 29 | 30 | public String getType() { 31 | return type; 32 | } 33 | 34 | public void setType(String type) { 35 | this.type = type; 36 | } 37 | 38 | public String getId() {return type;} 39 | 40 | @Override 41 | public int hashCode() { 42 | final int prime = 31; 43 | int result = super.hashCode(); 44 | result = prime * result + ((type == null) ? 0 : type.hashCode()); 45 | return result; 46 | } 47 | 48 | @Override 49 | public boolean equals(Object obj) { 50 | if (this == obj) 51 | return true; 52 | if (!super.equals(obj)) 53 | return false; 54 | if (getClass() != obj.getClass()) 55 | return false; 56 | NotificationMethodType other = (NotificationMethodType) obj; 57 | if (type == null) { 58 | if (other.type != null) 59 | return false; 60 | } else if (!type.equals(other.type)) 61 | return false; 62 | return true; 63 | } 64 | 65 | 66 | } -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/model/notificationmethod/NotificationMethodTypesRepo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2014,2016 Hewlett Packard Enterprise Development LP 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.model.notificationmethod; 15 | 16 | import java.util.List; 17 | 18 | 19 | 20 | /** 21 | * Repository for notification methods. 22 | */ 23 | public interface NotificationMethodTypesRepo { 24 | 25 | List listNotificationMethodTypes(); 26 | } 27 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/model/statistic/StatisticRepo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, 2016 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.model.statistic; 15 | 16 | import org.joda.time.DateTime; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | import javax.annotation.Nullable; 22 | 23 | /** 24 | * Repository for statistics. 25 | */ 26 | public interface StatisticRepo { 27 | 28 | /** 29 | * Finds statistics for the given criteria. 30 | */ 31 | List find(String tenantId, String name, Map dimensions, 32 | DateTime startTime, @Nullable DateTime endTime, List statistics, 33 | int period, String offset, int limit, Boolean mergeMetricsFlag, 34 | List groupBy) 35 | throws Exception; 36 | } 37 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/model/statistic/Statistics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.model.statistic; 15 | 16 | import com.fasterxml.jackson.annotation.JsonProperty; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import monasca.api.domain.model.measurement.Measurements; 23 | 24 | /** 25 | * Encapsulates a metric measurements. 26 | */ 27 | public class Statistics extends Measurements { 28 | 29 | public Statistics() { 30 | super(); 31 | } 32 | 33 | public Statistics(String name, Map dimensions, List columns) { 34 | super(name, dimensions); 35 | this.columns = columns; 36 | 37 | } 38 | 39 | @Override 40 | @JsonProperty("statistics") 41 | public List> getMeasurements() { 42 | return this.measurements; 43 | } 44 | 45 | public void setColumns(List columns) { 46 | this.columns = columns; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return String.format("Statistics [name=%s, dimensions=%s,statistics=%s]", name, dimensions, 52 | measurements); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/model/version/Version.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.model.version; 15 | 16 | import java.util.List; 17 | 18 | import org.joda.time.DateTime; 19 | 20 | import monasca.common.model.domain.common.AbstractEntity; 21 | import monasca.api.domain.model.common.Link; 22 | import monasca.api.domain.model.common.Linked; 23 | 24 | public class Version extends AbstractEntity implements Linked { 25 | private List links; 26 | public VersionStatus status; 27 | public DateTime updated; 28 | 29 | public enum VersionStatus { 30 | CURRENT, DEPRECATED, OBSOLETE; 31 | } 32 | 33 | public Version() {} 34 | 35 | public Version(String id, VersionStatus status, DateTime updated) { 36 | this.id = id; 37 | this.status = status; 38 | this.updated = updated; 39 | } 40 | 41 | public String getId() { 42 | return id; 43 | } 44 | 45 | @Override 46 | public List getLinks() { 47 | return links; 48 | } 49 | 50 | @Override 51 | public void setLinks(List links) { 52 | this.links = links; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/model/version/VersionRepo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.model.version; 15 | 16 | import monasca.api.domain.exception.EntityNotFoundException; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * Repository for versions. 22 | */ 23 | public interface VersionRepo { 24 | List find(); 25 | 26 | /** 27 | * @throws EntityNotFoundException a version cannot be found for the {@code versionId} 28 | */ 29 | Version findById(String versionId); 30 | } 31 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | /** 16 | * Houses the domain layer. 17 | */ 18 | package monasca.api.domain; 19 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/domain/service/impl/VersionRepoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.domain.service.impl; 15 | 16 | import java.util.Arrays; 17 | import java.util.List; 18 | 19 | import org.joda.time.DateTime; 20 | import org.joda.time.DateTimeZone; 21 | 22 | import monasca.api.domain.exception.EntityNotFoundException; 23 | import monasca.api.domain.model.version.Version; 24 | import monasca.api.domain.model.version.Version.VersionStatus; 25 | import monasca.api.domain.model.version.VersionRepo; 26 | 27 | /** 28 | * Version repository implementation. 29 | */ 30 | public class VersionRepoImpl implements VersionRepo { 31 | private static final Version v2_0 = new Version("v2.0", VersionStatus.CURRENT, new DateTime( 32 | DateTimeZone.UTC)); 33 | 34 | @Override 35 | public List find() { 36 | return Arrays.asList(v2_0); 37 | } 38 | 39 | @Override 40 | public Version findById(String versionId) { 41 | if ("v2.0".equals(versionId)) 42 | return v2_0; 43 | throw new EntityNotFoundException("No version exists for %s", versionId); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/infrastructure/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | /** 16 | * Houses the infrastructure layer. 17 | */ 18 | package monasca.api.infrastructure; 19 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/infrastructure/persistence/vertica/VerticaDataSourceFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.infrastructure.persistence.vertica; 15 | 16 | import com.fasterxml.jackson.annotation.JsonProperty; 17 | import io.dropwizard.db.DataSourceFactory; 18 | 19 | public class VerticaDataSourceFactory extends DataSourceFactory { 20 | 21 | @JsonProperty 22 | String dbHint = ""; 23 | 24 | public String getDbHint() { 25 | return dbHint; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/resource/annotation/PATCH.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.resource.annotation; 15 | 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | import javax.ws.rs.HttpMethod; 22 | 23 | @Target({ElementType.METHOD}) 24 | @Retention(RetentionPolicy.RUNTIME) 25 | @HttpMethod("PATCH") 26 | public @interface PATCH { 27 | } 28 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/resource/exception/ConstraintViolationExceptionMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.resource.exception; 15 | 16 | import io.dropwizard.jersey.validation.ValidationErrorMessage; 17 | 18 | import javax.validation.ConstraintViolationException; 19 | import javax.ws.rs.core.MediaType; 20 | import javax.ws.rs.core.Response; 21 | import javax.ws.rs.ext.ExceptionMapper; 22 | import javax.ws.rs.ext.Provider; 23 | 24 | import monasca.api.resource.exception.Exceptions.FaultType; 25 | 26 | @Provider 27 | public class ConstraintViolationExceptionMapper implements 28 | ExceptionMapper { 29 | private static final int UNPROCESSABLE_ENTITY = 422; 30 | 31 | @Override 32 | public Response toResponse(ConstraintViolationException exception) { 33 | final ValidationErrorMessage message = 34 | new ValidationErrorMessage(exception.getConstraintViolations()); 35 | String msg = 36 | message.getErrors().isEmpty() ? exception.getMessage() : message.getErrors().toString(); 37 | return Response.status(UNPROCESSABLE_ENTITY).type(MediaType.APPLICATION_JSON) 38 | .entity(Exceptions.buildLoggedErrorMessage(FaultType.UNPROCESSABLE_ENTITY, msg)).build(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/resource/exception/EntityExistsExceptionMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.resource.exception; 15 | 16 | import javax.ws.rs.core.MediaType; 17 | import javax.ws.rs.core.Response; 18 | import javax.ws.rs.core.Response.Status; 19 | import javax.ws.rs.ext.ExceptionMapper; 20 | import javax.ws.rs.ext.Provider; 21 | 22 | import monasca.api.domain.exception.EntityExistsException; 23 | import monasca.api.resource.exception.Exceptions.FaultType; 24 | 25 | @Provider 26 | public class EntityExistsExceptionMapper implements ExceptionMapper { 27 | @Override 28 | public Response toResponse(EntityExistsException e) { 29 | return Response.status(Status.CONFLICT).type(MediaType.APPLICATION_JSON) 30 | .entity(Exceptions.buildLoggedErrorMessage(FaultType.CONFLICT, e.getMessage())).build(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/resource/exception/EntityNotFoundExceptionMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.resource.exception; 15 | 16 | import javax.ws.rs.core.MediaType; 17 | import javax.ws.rs.core.Response; 18 | import javax.ws.rs.core.Response.Status; 19 | import javax.ws.rs.ext.ExceptionMapper; 20 | import javax.ws.rs.ext.Provider; 21 | 22 | import monasca.api.domain.exception.EntityNotFoundException; 23 | import monasca.api.resource.exception.Exceptions.FaultType; 24 | 25 | @Provider 26 | public class EntityNotFoundExceptionMapper implements ExceptionMapper { 27 | @Override 28 | public Response toResponse(EntityNotFoundException e) { 29 | return Response.status(Status.NOT_FOUND).type(MediaType.APPLICATION_JSON) 30 | .entity(Exceptions.buildLoggedErrorMessage(FaultType.NOT_FOUND, e.getMessage())).build(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/resource/exception/ErrorMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.resource.exception; 15 | 16 | import com.fasterxml.jackson.annotation.JsonProperty; 17 | import com.google.common.base.Preconditions; 18 | 19 | public class ErrorMessage { 20 | public int code; 21 | public String message; 22 | public String details; 23 | @JsonProperty("internal_code") 24 | public String internalCode; 25 | 26 | ErrorMessage() {} 27 | 28 | public ErrorMessage(int code, String message, String details, String internalCode) { 29 | Preconditions.checkNotNull(internalCode, "internalCode"); 30 | 31 | this.code = code; 32 | this.message = message == null ? "" : message; 33 | this.details = details == null ? "" : details; 34 | this.internalCode = internalCode; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/resource/exception/IllegalArgumentExceptionMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.resource.exception; 15 | 16 | import javax.ws.rs.core.MediaType; 17 | import javax.ws.rs.core.Response; 18 | import javax.ws.rs.core.Response.Status; 19 | import javax.ws.rs.ext.ExceptionMapper; 20 | import javax.ws.rs.ext.Provider; 21 | 22 | import monasca.api.resource.exception.Exceptions.FaultType; 23 | 24 | @Provider 25 | public class IllegalArgumentExceptionMapper implements ExceptionMapper { 26 | @Override 27 | public Response toResponse(IllegalArgumentException e) { 28 | return Response.status(Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON) 29 | .entity(Exceptions.buildLoggedErrorMessage(FaultType.BAD_REQUEST, e.getMessage())).build(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/resource/exception/InvalidEntityExceptionMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.resource.exception; 15 | 16 | import javax.ws.rs.core.MediaType; 17 | import javax.ws.rs.core.Response; 18 | import javax.ws.rs.ext.ExceptionMapper; 19 | import javax.ws.rs.ext.Provider; 20 | 21 | import monasca.api.domain.exception.InvalidEntityException; 22 | import monasca.api.resource.exception.Exceptions.FaultType; 23 | 24 | @Provider 25 | public class InvalidEntityExceptionMapper implements ExceptionMapper { 26 | @Override 27 | public Response toResponse(InvalidEntityException e) { 28 | return Response.status(FaultType.BAD_REQUEST.statusCode).type(MediaType.APPLICATION_JSON) 29 | .entity(Exceptions.buildLoggedErrorMessage(FaultType.BAD_REQUEST, e.getMessage())).build(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/resource/exception/JsonMappingExceptionManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.resource.exception; 15 | 16 | import javax.ws.rs.core.MediaType; 17 | import javax.ws.rs.core.Response; 18 | import javax.ws.rs.ext.ExceptionMapper; 19 | import javax.ws.rs.ext.Provider; 20 | 21 | import com.fasterxml.jackson.databind.JsonMappingException; 22 | import monasca.api.resource.exception.Exceptions.FaultType; 23 | 24 | /** 25 | * Adapted from Dropwizard's JsonMappingExceptionManager. 26 | */ 27 | @Provider 28 | public class JsonMappingExceptionManager implements ExceptionMapper { 29 | @Override 30 | public Response toResponse(JsonMappingException exception) { 31 | return Response 32 | .status(FaultType.UNPROCESSABLE_ENTITY.statusCode) 33 | .type(MediaType.APPLICATION_JSON) 34 | .entity( 35 | Exceptions.buildLoggedErrorMessage(FaultType.UNPROCESSABLE_ENTITY, 36 | "Unable to process the provided JSON", 37 | Exceptions.stripLocationFromStacktrace(exception.getMessage()), null)).build(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /java/src/main/java/monasca/api/resource/exception/ThrowableExceptionMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package monasca.api.resource.exception; 15 | 16 | import javax.ws.rs.WebApplicationException; 17 | import javax.ws.rs.core.MediaType; 18 | import javax.ws.rs.core.Response; 19 | import javax.ws.rs.core.Response.Status; 20 | import javax.ws.rs.ext.ExceptionMapper; 21 | import javax.ws.rs.ext.Provider; 22 | 23 | import monasca.api.resource.exception.Exceptions.FaultType; 24 | 25 | /** 26 | * Adapted from Dropwizard's LoggingExceptionMapper. 27 | * 28 | * @param Exception type 29 | */ 30 | @Provider 31 | public class ThrowableExceptionMapper implements ExceptionMapper { 32 | @Override 33 | public Response toResponse(E exception) { 34 | if (exception instanceof WebApplicationException) 35 | return ((WebApplicationException) exception).getResponse(); 36 | 37 | return Response 38 | .status(Status.INTERNAL_SERVER_ERROR) 39 | .type(MediaType.APPLICATION_JSON) 40 | .entity( 41 | Exceptions.buildLoggedErrorMessage(FaultType.SERVER_ERROR, 42 | "An internal server error occurred", null, exception)).build(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /java/src/test/java/monasca/api/app/command/CreateAlarmDefinitionCommandTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2014,2016 Hewlett Packard Enterprise Development LP 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package monasca.api.app.command; 16 | 17 | import static monasca.common.dropwizard.JsonHelpers.jsonFixture; 18 | import static org.testng.Assert.assertEquals; 19 | 20 | import java.util.Arrays; 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | import org.testng.annotations.Test; 25 | 26 | import monasca.api.domain.model.AbstractModelTest; 27 | 28 | @Test 29 | public class CreateAlarmDefinitionCommandTest extends AbstractModelTest { 30 | public void shouldDeserializeFromJson() throws Exception { 31 | Map dimensions = new HashMap(); 32 | dimensions.put("instanceId", "392633"); 33 | /** todo: Check the null value to get works **/ 34 | CreateAlarmDefinitionCommand newAlarm = 35 | new CreateAlarmDefinitionCommand("Disk Exceeds 1k Operations", null, 36 | "avg(hpcs.compute:cpu:1:{instance_id=5}) > 5", null, null, Arrays.asList("123345345", 37 | "23423"), null, null); 38 | 39 | String json = jsonFixture("fixtures/newAlarm.json"); 40 | CreateAlarmDefinitionCommand alarm = fromJson(json, CreateAlarmDefinitionCommand.class); 41 | assertEquals(alarm, newAlarm); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /java/src/test/java/monasca/api/app/validation/ValidationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package monasca.api.app.validation; 16 | 17 | import static org.testng.Assert.assertEquals; 18 | 19 | import org.testng.annotations.Test; 20 | 21 | import java.util.Map; 22 | 23 | @Test 24 | public class ValidationTest { 25 | public void testSimpleParseAndValidateDimensions() { 26 | final Map dimensions = Validation.parseAndValidateDimensions("aa:bb,cc:dd"); 27 | assertEquals(dimensions.size(), 2); 28 | assertEquals(dimensions.get("aa"), "bb"); 29 | assertEquals(dimensions.get("cc"), "dd"); 30 | } 31 | 32 | public void testParseAndValidateDimensionsWithColon() { 33 | final Map dimensions = Validation.parseAndValidateDimensions("aa:bb,url:http://localhost:8081/healthcheck"); 34 | assertEquals(dimensions.size(), 2); 35 | assertEquals(dimensions.get("aa"), "bb"); 36 | assertEquals(dimensions.get("url"), "http://localhost:8081/healthcheck"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /java/src/test/java/monasca/api/domain/model/NotificationMethodTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package monasca.api.domain.model; 16 | 17 | import static monasca.common.dropwizard.JsonHelpers.jsonFixture; 18 | import static org.testng.Assert.assertEquals; 19 | 20 | import java.util.Arrays; 21 | 22 | import org.testng.annotations.Test; 23 | 24 | import monasca.api.domain.model.common.Link; 25 | import monasca.api.domain.model.notificationmethod.NotificationMethod; 26 | 27 | 28 | @Test 29 | public class NotificationMethodTest extends AbstractModelTest { 30 | private final NotificationMethod notificationMethod; 31 | 32 | public NotificationMethodTest() { 33 | notificationMethod = 34 | new NotificationMethod("123", "MyEmail", "EMAIL", "a@b", 0); 35 | notificationMethod.setLinks(Arrays.asList(new Link("self", 36 | "https://cloudsvc.example.com/v1.0"))); 37 | } 38 | 39 | public void shouldSerializeToJson() throws Exception { 40 | String json = toJson(notificationMethod); 41 | assertEquals(json, jsonFixture("fixtures/notificationMethod.json")); 42 | } 43 | 44 | public void shouldDeserializeFromJson() throws Exception { 45 | String json = jsonFixture("fixtures/notificationMethod.json"); 46 | NotificationMethod detail = fromJson(json, NotificationMethod.class); 47 | assertEquals(notificationMethod, detail); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /java/src/test/java/monasca/api/domain/model/VersionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package monasca.api.domain.model; 16 | 17 | import static monasca.common.dropwizard.JsonHelpers.jsonFixture; 18 | import static org.testng.Assert.assertEquals; 19 | 20 | import java.util.Arrays; 21 | 22 | import org.joda.time.DateTime; 23 | import org.joda.time.DateTimeZone; 24 | import org.testng.annotations.Test; 25 | 26 | import monasca.api.domain.model.common.Link; 27 | import monasca.api.domain.model.version.Version; 28 | import monasca.api.domain.model.version.Version.VersionStatus; 29 | 30 | @Test 31 | public class VersionTest extends AbstractModelTest { 32 | private final Version version; 33 | 34 | public VersionTest() { 35 | version = 36 | new Version("1.0", VersionStatus.CURRENT, new DateTime(1355253328000L, DateTimeZone.UTC)); 37 | version.setLinks(Arrays.asList(new Link("self", 38 | "https://cloudsvc.example.com/v1.0"))); 39 | } 40 | 41 | public void shouldSerializeToJson() throws Exception { 42 | String json = toJson(version); 43 | assertEquals(json, jsonFixture("fixtures/version.json")); 44 | } 45 | 46 | public void shouldDeserializeFromJson() throws Exception { 47 | String json = jsonFixture("fixtures/version.json"); 48 | Version detail = fromJson(json, Version.class); 49 | assertEquals(version, detail); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /java/src/test/java/monasca/api/infrastructure/persistence/hibernate/TestHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 FUJITSU LIMITED 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | * 14 | */ 15 | 16 | package monasca.api.infrastructure.persistence.hibernate; 17 | 18 | import java.util.Random; 19 | 20 | import org.joda.time.DateTime; 21 | 22 | class TestHelper { 23 | private static final int SLEEP_TIME_RANDOM_BYTE_ARRAY = 30; 24 | 25 | private TestHelper() { 26 | } 27 | 28 | static byte[] randomByteArray(final int length) { 29 | return randomByteArray(length, true); 30 | } 31 | 32 | static byte[] randomByteArray(final int length, final boolean sleep) { 33 | if (sleep) { 34 | try { 35 | Thread.sleep(SLEEP_TIME_RANDOM_BYTE_ARRAY); 36 | } catch (InterruptedException e) { 37 | System.err.println(e.getLocalizedMessage()); 38 | throw new RuntimeException(e); 39 | } 40 | } 41 | byte[] b = new byte[length]; 42 | new Random(DateTime.now().getMillis()).nextBytes(b); 43 | return b; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /java/src/test/resources/fixtures/alarm.json: -------------------------------------------------------------------------------- 1 | {"id":"123","links":[{"rel":"self","href":"https://cloudsvc.example.com/v1.0"}],"name":"90% CPU","description":"","expression":"avg(hpcs.compute{instance_id=666, image_id=345}) >= 90","deterministic":false,"match_by":[],"severity":"LOW","actions_enabled":false,"alarm_actions":["123345345","23423"],"ok_actions":null,"undetermined_actions":null} 2 | -------------------------------------------------------------------------------- /java/src/test/resources/fixtures/metricSet.json: -------------------------------------------------------------------------------- 1 | [{"name":"user1","dimensions":{"instance_id": "392633"},"value":127},{"name":"user2","dimensions":{"instance_id": "392633"},"value":127}] -------------------------------------------------------------------------------- /java/src/test/resources/fixtures/metricWithoutDimensionName.json: -------------------------------------------------------------------------------- 1 | {"name":"foo","dimensions":{"": "392633"},"timestamp":1366178760,"value":127} -------------------------------------------------------------------------------- /java/src/test/resources/fixtures/metricWithoutName.json: -------------------------------------------------------------------------------- 1 | {"dimensions":{"instance_id": "392633"},"timestamp":1366178760,"value":127} -------------------------------------------------------------------------------- /java/src/test/resources/fixtures/metricWithoutTimestamp.json: -------------------------------------------------------------------------------- 1 | {"name":"user_name","dimensions":{"instance_id": "392633"},"value":128} -------------------------------------------------------------------------------- /java/src/test/resources/fixtures/metricWithoutValue.json: -------------------------------------------------------------------------------- 1 | {"name":"user_name","dimensions":{"instance_id": "392633"},"timestamp":1366178760} -------------------------------------------------------------------------------- /java/src/test/resources/fixtures/newAlarm.json: -------------------------------------------------------------------------------- 1 | {"name":"Disk Exceeds 1k Operations","expression":"avg(hpcs.compute:cpu:1:{instance_id=5}) > 5","alarm_actions":["123345345","23423"]}} -------------------------------------------------------------------------------- /java/src/test/resources/fixtures/newNotificationMethod.json: -------------------------------------------------------------------------------- 1 | {"name":"MyEmail","type":"EMAIL","address":"a@b"} 2 | -------------------------------------------------------------------------------- /java/src/test/resources/fixtures/newNotificationMethodWithInvalidEnum.json: -------------------------------------------------------------------------------- 1 | {"name":"MyEmail","type":"invalid_enum","address":"a@b"} 2 | -------------------------------------------------------------------------------- /java/src/test/resources/fixtures/newNotificationMethodWithLowercaseEnum.json: -------------------------------------------------------------------------------- 1 | {"name":"MyEmail","type":"email","address":"a@b"} 2 | -------------------------------------------------------------------------------- /java/src/test/resources/fixtures/newNotificationMethodWithPeriod.json: -------------------------------------------------------------------------------- 1 | {"name":"MyWebhook","type":"webhook","address":"http://somedomain.com","period":"60"} -------------------------------------------------------------------------------- /java/src/test/resources/fixtures/notificationMethod.json: -------------------------------------------------------------------------------- 1 | {"id":"123","links":[{"rel":"self","href":"https://cloudsvc.example.com/v1.0"}],"name":"MyEmail","type":"EMAIL","address":"a@b", "period":0} 2 | -------------------------------------------------------------------------------- /java/src/test/resources/fixtures/version.json: -------------------------------------------------------------------------------- 1 | {"id":"1.0","links":[{"rel":"self","href":"https://cloudsvc.example.com/v1.0"}],"status":"CURRENT","updated":"2012-12-11T19:15:28.000Z"} 2 | -------------------------------------------------------------------------------- /java/src/test/resources/monasca/api/infrastructure/persistence/mysql/notification_method.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `notification_method` ( 2 | `id` varchar(36) NOT NULL, 3 | `tenant_id` varchar(36) NOT NULL DEFAULT '', 4 | `name` varchar(250) NOT NULL DEFAULT '', 5 | `type` varchar(10) NOT NULL DEFAULT 'EMAIL' check type in ('EMAIL', 'WEBHOOK', 'PAGERDUTY'), 6 | `address` varchar(100) NOT NULL DEFAULT '', 7 | `period` int NOT NULL DEFAULT 0, 8 | `created_at` datetime NOT NULL, 9 | `updated_at` datetime NOT NULL, 10 | PRIMARY KEY (`id`) 11 | ); 12 | -------------------------------------------------------------------------------- /java/src/test/resources/monasca/api/infrastructure/persistence/mysql/notification_method_type.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `notification_method_type` ( 2 | `name` varchar(20) NOT NULL DEFAULT '', 3 | PRIMARY KEY (`name`) 4 | ); 5 | -------------------------------------------------------------------------------- /monasca_api/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/__init__.py -------------------------------------------------------------------------------- /monasca_api/api/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/api/__init__.py -------------------------------------------------------------------------------- /monasca_api/api/alarm_definitions_api_v2.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Hewlett-Packard 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from oslo_log import log 16 | 17 | LOG = log.getLogger(__name__) 18 | 19 | 20 | class AlarmDefinitionsV2API(object): 21 | def __init__(self): 22 | super(AlarmDefinitionsV2API, self).__init__() 23 | LOG.info('Initializing AlarmDefinitionsV2API!') 24 | 25 | def on_post(self, req, res): 26 | res.status = '501 Not Implemented' 27 | 28 | def on_get(self, req, res, alarm_definition_id): 29 | res.status = '501 Not Implemented' 30 | 31 | def on_put(self, req, res, alarm_definition_id): 32 | res.status = '501 Not Implemented' 33 | 34 | def on_patch(self, req, res, alarm_definition_id): 35 | res.status = '501 Not Implemented' 36 | 37 | def on_delete(self, req, res, alarm_definition_id): 38 | res.status = '501 Not Implemented' 39 | -------------------------------------------------------------------------------- /monasca_api/api/alarms_api_v2.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2016 Hewlett Packard Enterprise Development Company LP 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from oslo_log import log 16 | 17 | LOG = log.getLogger(__name__) 18 | 19 | 20 | class AlarmsV2API(object): 21 | def __init__(self): 22 | super(AlarmsV2API, self).__init__() 23 | LOG.info('Initializing AlarmsV2API!') 24 | 25 | def on_put(self, req, res, alarm_id): 26 | res.status = '501 Not Implemented' 27 | 28 | def on_patch(self, req, res, alarm_id): 29 | res.status = '501 Not Implemented' 30 | 31 | def on_delete(self, req, res, alarm_id): 32 | res.status = '501 Not Implemented' 33 | 34 | def on_get(self, req, res, alarm_id): 35 | res.status = '501 Not Implemented' 36 | 37 | 38 | class AlarmsCountV2API(object): 39 | def __init__(self): 40 | super(AlarmsCountV2API, self).__init__() 41 | 42 | def on_get(self, req, res): 43 | res.status = '501 Not Implemented' 44 | 45 | 46 | class AlarmsStateHistoryV2API(object): 47 | def __init__(self): 48 | super(AlarmsStateHistoryV2API, self).__init__() 49 | LOG.info('Initializing AlarmsStateHistoryV2API!') 50 | 51 | def on_get(self, req, res, alarm_id): 52 | res.status = '501 Not Implemented' 53 | -------------------------------------------------------------------------------- /monasca_api/api/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/api/core/__init__.py -------------------------------------------------------------------------------- /monasca_api/api/core/log/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/api/core/log/__init__.py -------------------------------------------------------------------------------- /monasca_api/api/core/log/exceptions.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 FUJITSU LIMITED 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | import falcon 15 | 16 | 17 | HTTP_422 = '422 Unprocessable Entity' 18 | 19 | 20 | class HTTPUnprocessableEntity(falcon.HTTPError): 21 | """HTTPUnprocessableEntity http error. 22 | 23 | HTTPError that comes with '422 Unprocessable Entity' status 24 | 25 | :argument: message(str) - meaningful description of what caused an error 26 | :argument: kwargs - any other option defined in 27 | :py:class:`falcon.HTTPError` 28 | """ 29 | def __init__(self, message, **kwargs): 30 | falcon.HTTPError.__init__(self, 31 | HTTP_422, 32 | 'unprocessable_entity', 33 | message, 34 | **kwargs 35 | ) 36 | -------------------------------------------------------------------------------- /monasca_api/api/core/request_context.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 FUJITSU LIMITED 2 | # Copyright 2018 OP5 AB 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | # not use this file except in compliance with the License. You may obtain 6 | # a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | # License for the specific language governing permissions and limitations 14 | # under the License. 15 | 16 | from oslo_context import context 17 | 18 | from monasca_api.common.policy import policy_engine as policy 19 | from monasca_api import policies 20 | 21 | policy.POLICIES = policies 22 | 23 | 24 | class RequestContext(context.RequestContext): 25 | """RequestContext. 26 | 27 | RequestContext is customized version of 28 | :py:class:oslo_context.context.RequestContext. 29 | """ 30 | 31 | def can(self, action, target=None): 32 | if target is None: 33 | target = {'project_id': self.project_id, 34 | 'user_id': self.user_id} 35 | 36 | return policy.authorize(self, action=action, target=target) 37 | -------------------------------------------------------------------------------- /monasca_api/api/healthcheck_api.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 FUJITSU LIMITED 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | import falcon 16 | from oslo_log import log 17 | 18 | LOG = log.getLogger(__name__) 19 | 20 | 21 | class HealthCheckApi(object): 22 | """HealthCheck Api. 23 | 24 | HealthCheckApi server information regarding health of the Api. 25 | 26 | """ 27 | 28 | def __init__(self): 29 | super(HealthCheckApi, self).__init__() 30 | LOG.info('Initializing HealthCheckApi') 31 | 32 | def on_get(self, req, res): 33 | """Complex healthcheck report on GET 34 | 35 | Returns complex report regarding API health 36 | and all dependent services 37 | 38 | :param falcon.Request req: current request 39 | :param falcon.Response res: current response 40 | """ 41 | res.status = falcon.HTTP_501 # pragma: no cover 42 | 43 | def on_head(self, req, res): 44 | """Simple healthcheck report on HEAD. 45 | 46 | In opposite to :py:meth:`.HealthCheckApi.on_get`, this 47 | method is supposed to execute ASAP to inform user that 48 | API is up and running. 49 | 50 | :param falcon.Request req: current request 51 | :param falcon.Response res: current response 52 | """ 53 | res.status = falcon.HTTP_501 # pragma: no cover 54 | -------------------------------------------------------------------------------- /monasca_api/api/notifications_api_v2.py: -------------------------------------------------------------------------------- 1 | # (C) Copyright 2014,2016 Hewlett Packard Enterprise Development LP 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from oslo_log import log 16 | 17 | LOG = log.getLogger(__name__) 18 | 19 | 20 | class NotificationsV2API(object): 21 | def __init__(self): 22 | super(NotificationsV2API, self).__init__() 23 | LOG.info('Initializing NotificationsV2API!') 24 | 25 | def on_post(self, req, res): 26 | res.status = '501 Not Implemented' 27 | 28 | def on_delete(self, req, res, notification_method_id): 29 | res.status = '501 Not Implemented' 30 | 31 | def on_get(self, req, res, notification_method_id): 32 | res.status = '501 Not Implemented' 33 | 34 | def on_put(self, req, res, notification_method_id): 35 | res.status = '501 Not Implemented' 36 | 37 | def on_patch(self, req, res, notification_method_id): 38 | res.status = '501 Not Implemented' 39 | -------------------------------------------------------------------------------- /monasca_api/api/notificationstype_api_v2.py: -------------------------------------------------------------------------------- 1 | # (C) Copyright 2016 Hewlett Packard Enterprise Development LP 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from oslo_log import log 16 | 17 | LOG = log.getLogger(__name__) 18 | 19 | 20 | class NotificationsTypeV2API(object): 21 | def __init__(self): 22 | super(NotificationsTypeV2API, self).__init__() 23 | LOG.info('Initializing NotificationsTypeV2API!') 24 | 25 | def on_post(self, req, res): 26 | res.status = '501 Not Implemented' 27 | 28 | def on_delete(self, req, res): 29 | res.status = '501 Not Implemented' 30 | 31 | def on_get(self, req, res): 32 | res.status = '501 Not Implemented' 33 | 34 | def on_put(self, req, res): 35 | res.status = '501 Not Implemented' 36 | 37 | def on_patch(self, req, res): 38 | res.status = '501 Not Implemented' 39 | -------------------------------------------------------------------------------- /monasca_api/api/versions_api.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Hewlett-Packard 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from oslo_log import log 16 | 17 | LOG = log.getLogger(__name__) 18 | 19 | 20 | class VersionsAPI(object): 21 | def __init__(self): 22 | super(VersionsAPI, self).__init__() 23 | LOG.info('Initializing VersionsAPI!') 24 | 25 | def on_get(self, req, res, id): 26 | res.status = '501 Not Implemented' 27 | -------------------------------------------------------------------------------- /monasca_api/api/wsgi.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 FUJITSU LIMITED 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | # extremely simple way to setup of monasca-api 16 | # with wsgi 17 | 18 | from monasca_api.api import server 19 | 20 | 21 | def main(): 22 | return server.get_wsgi_app(config_base_path='/etc/monasca') 23 | 24 | 25 | if __name__ == '__main__' or __name__.startswith('_mod_wsgi'): 26 | application = main() 27 | -------------------------------------------------------------------------------- /monasca_api/cmd/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/cmd/__init__.py -------------------------------------------------------------------------------- /monasca_api/common/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/common/__init__.py -------------------------------------------------------------------------------- /monasca_api/common/messaging/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/common/messaging/__init__.py -------------------------------------------------------------------------------- /monasca_api/common/messaging/exceptions.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Hewlett-Packard 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | 16 | class MessageQueueException(Exception): 17 | pass 18 | -------------------------------------------------------------------------------- /monasca_api/common/messaging/fake_publisher.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Hewlett-Packard 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from monasca_api.common.messaging import publisher 16 | 17 | 18 | class FakePublisher(publisher.Publisher): 19 | 20 | def __init__(self, topic): 21 | pass 22 | 23 | def send_message(self, message): 24 | pass 25 | -------------------------------------------------------------------------------- /monasca_api/common/messaging/message_formats/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/common/messaging/message_formats/__init__.py -------------------------------------------------------------------------------- /monasca_api/common/messaging/message_formats/metrics.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Hewlett-Packard 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from oslo_utils import timeutils 16 | 17 | from monasca_api.common.rest import utils as rest_utils 18 | 19 | 20 | def transform(metrics, tenant_id, region): 21 | transformed_metric = {'metric': {}, 22 | 'meta': {'tenantId': tenant_id, 'region': region}, 23 | 'creation_time': timeutils.utcnow_ts()} 24 | 25 | if isinstance(metrics, list): 26 | transformed_metrics = [] 27 | for metric in metrics: 28 | transformed_metric['metric'] = metric 29 | transformed_metrics.append(rest_utils.as_json(transformed_metric)) 30 | return transformed_metrics 31 | else: 32 | transformed_metric['metric'] = metrics 33 | return [rest_utils.as_json(transformed_metric)] 34 | -------------------------------------------------------------------------------- /monasca_api/common/messaging/publisher.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Hewlett-Packard 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | import abc 16 | 17 | import six 18 | 19 | 20 | @six.add_metaclass(abc.ABCMeta) 21 | class Publisher(object): 22 | @abc.abstractmethod 23 | def send_message(self, message): 24 | return 25 | -------------------------------------------------------------------------------- /monasca_api/common/policy/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/common/policy/__init__.py -------------------------------------------------------------------------------- /monasca_api/common/policy/i18n.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 IBM Corp. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | """oslo.i18n integration module. 16 | 17 | See https://docs.openstack.org/oslo.i18n/latest/user/index.html 18 | 19 | """ 20 | 21 | import oslo_i18n 22 | 23 | DOMAIN = 'monasca' 24 | 25 | _translators = oslo_i18n.TranslatorFactory(domain=DOMAIN) 26 | 27 | # The primary translation function using the well-known name "_" 28 | _ = _translators.primary 29 | 30 | # Translators for log levels. 31 | # 32 | # The abbreviated names are meant to reflect the usual use of a short 33 | # name like '_'. The "L" is for "log" and the other letter comes from 34 | # the level. 35 | _LI = _translators.log_info 36 | _LW = _translators.log_warning 37 | _LE = _translators.log_error 38 | _LC = _translators.log_critical 39 | 40 | 41 | def translate(value, user_locale): 42 | return oslo_i18n.translate(value, user_locale) 43 | 44 | 45 | def get_available_languages(): 46 | return oslo_i18n.get_available_languages(DOMAIN) 47 | -------------------------------------------------------------------------------- /monasca_api/common/repositories/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/common/repositories/__init__.py -------------------------------------------------------------------------------- /monasca_api/common/repositories/alarms_repository.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2016 Hewlett Packard Enterprise Development Company LP 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | import abc 16 | 17 | import six 18 | 19 | 20 | @six.add_metaclass(abc.ABCMeta) 21 | class AlarmsRepository(object): 22 | 23 | def __init__(self): 24 | 25 | super(AlarmsRepository, self).__init__() 26 | 27 | @abc.abstractmethod 28 | def get_alarm_metrics(self, alarm_id): 29 | pass 30 | 31 | @abc.abstractmethod 32 | def get_sub_alarms(self, tenant_id, alarm_id): 33 | pass 34 | 35 | @abc.abstractmethod 36 | def update_alarm(self, tenant_id, alarm_id, state, lifecycle_state, link): 37 | pass 38 | 39 | @abc.abstractmethod 40 | def delete_alarm(self, tenant_id, id): 41 | pass 42 | 43 | @abc.abstractmethod 44 | def get_alarm(self, tenant_id, id): 45 | pass 46 | 47 | @abc.abstractmethod 48 | def get_alarms(self, tenant_id, query_parms, offset, limit): 49 | pass 50 | 51 | @abc.abstractmethod 52 | def get_alarms_count(self, tenant_id, query_parms, offset, limit): 53 | pass 54 | -------------------------------------------------------------------------------- /monasca_api/common/repositories/cassandra/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/common/repositories/cassandra/__init__.py -------------------------------------------------------------------------------- /monasca_api/common/repositories/constants.py: -------------------------------------------------------------------------------- 1 | PAGE_LIMIT = 10000 2 | -------------------------------------------------------------------------------- /monasca_api/common/repositories/exceptions.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Hewlett-Packard 2 | # (C) Copyright 2015 Hewlett Packard Enterprise Development Company LP 3 | # Copyright 2016 FUJITSU LIMITED 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 6 | # not use this file except in compliance with the License. You may obtain 7 | # a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | 17 | from monasca_common.repositories.exceptions import AlreadyExistsException 18 | from monasca_common.repositories.exceptions import DoesNotExistException 19 | from monasca_common.repositories.exceptions import InvalidUpdateException 20 | from monasca_common.repositories.exceptions import RepositoryException 21 | 22 | 23 | class MultipleMetricsException(RepositoryException): 24 | pass 25 | 26 | 27 | class UnsupportedDriverException(Exception): 28 | pass 29 | 30 | 31 | __all__ = ( 32 | 'AlreadyExistsException', 33 | 'DoesNotExistException', 34 | 'InvalidUpdateException', 35 | 'RepositoryException', 36 | 'MultipleMetricsException', 37 | 'UnsupportedDriverException' 38 | ) 39 | -------------------------------------------------------------------------------- /monasca_api/common/repositories/fake/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/common/repositories/fake/__init__.py -------------------------------------------------------------------------------- /monasca_api/common/repositories/fake/metrics_repository.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Hewlett-Packard 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from monasca_api.common.repositories import metrics_repository 16 | 17 | 18 | class MetricsRepository(metrics_repository.AbstractMetricsRepository): 19 | def __init__(self): 20 | return 21 | 22 | def list_metrics(self, tenant_id, name, dimensions, offset, limit): 23 | return {} 24 | -------------------------------------------------------------------------------- /monasca_api/common/repositories/influxdb/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/common/repositories/influxdb/__init__.py -------------------------------------------------------------------------------- /monasca_api/common/repositories/model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/common/repositories/model/__init__.py -------------------------------------------------------------------------------- /monasca_api/common/repositories/notification_method_type_repository.py: -------------------------------------------------------------------------------- 1 | # (C) Copyright 2016 Hewlett Packard Enterprise Development LP 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | import abc 16 | 17 | import six 18 | 19 | 20 | @six.add_metaclass(abc.ABCMeta) 21 | class NotificationMethodTypeRepository(object): 22 | 23 | @abc.abstractmethod 24 | def list_notification_method_types(self): 25 | return 26 | -------------------------------------------------------------------------------- /monasca_api/common/repositories/notifications_repository.py: -------------------------------------------------------------------------------- 1 | # (C) Copyright 2014-2016 Hewlett Packard Enterprise Development Company LP 2 | # Copyright 2016 FUJITSU LIMITED 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | # not use this file except in compliance with the License. You may obtain 6 | # a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | # License for the specific language governing permissions and limitations 14 | # under the License. 15 | 16 | import abc 17 | 18 | import six 19 | 20 | 21 | @six.add_metaclass(abc.ABCMeta) 22 | class NotificationsRepository(object): 23 | 24 | @abc.abstractmethod 25 | def create_notification(self, tenant_id, name, notification_type, 26 | address, period): 27 | return 28 | 29 | @abc.abstractmethod 30 | def list_notifications(self, tenant_id, sort_by, offset, limit): 31 | return 32 | 33 | @abc.abstractmethod 34 | def delete_notification(self, tenant_id, notification_id): 35 | return 36 | 37 | @abc.abstractmethod 38 | def list_notification(self, tenant_id, notification_id): 39 | return 40 | 41 | @abc.abstractmethod 42 | def update_notification(self, notification_id, tenant_id, name, notification_type, 43 | address, period): 44 | return 45 | -------------------------------------------------------------------------------- /monasca_api/common/repositories/sqla/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/common/repositories/sqla/__init__.py -------------------------------------------------------------------------------- /monasca_api/common/repositories/sqla/notification_method_type_repository.py: -------------------------------------------------------------------------------- 1 | # (C) Copyright 2016 Hewlett Packard Enterprise Development LP 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | 16 | from monasca_api.common.repositories import notification_method_type_repository as nr 17 | from monasca_api.common.repositories.sqla import models 18 | from monasca_api.common.repositories.sqla import sql_repository 19 | from sqlalchemy import MetaData 20 | from sqlalchemy import select 21 | 22 | 23 | class NotificationMethodTypeRepository(sql_repository.SQLRepository, 24 | nr.NotificationMethodTypeRepository): 25 | def __init__(self): 26 | 27 | super(NotificationMethodTypeRepository, self).__init__() 28 | 29 | metadata = MetaData() 30 | self.nmt = models.create_nmt_model(metadata) 31 | 32 | nmt = self.nmt 33 | self._nmt_query = select(nmt.c.name) 34 | 35 | @sql_repository.sql_try_catch_block 36 | def list_notification_method_types(self): 37 | 38 | with self._db_engine.connect() as conn: 39 | notification_method_types = conn.execute(self._nmt_query).fetchall() 40 | 41 | return [row[0] for row in notification_method_types] 42 | -------------------------------------------------------------------------------- /monasca_api/common/rest/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/common/rest/__init__.py -------------------------------------------------------------------------------- /monasca_api/common/rest/exceptions.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 FUJITSU LIMITED 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | 16 | class UnsupportedContentTypeException(Exception): 17 | """Exception thrown if content type is not supported.""" 18 | pass 19 | 20 | 21 | class UnreadableContentError(IOError): 22 | """Exception thrown if reading data fails 23 | 24 | :py:class`.UnreadableContentError` may be thrown 25 | if data was impossible to read from input 26 | 27 | """ 28 | pass 29 | 30 | 31 | class DataConversionException(Exception): 32 | """Exception thrown if data transformation fails 33 | 34 | :py:class`.DataConversionException` may be thrown 35 | if data was impossible to transform into target 36 | representation according to content_type classifier. 37 | 38 | """ 39 | pass 40 | -------------------------------------------------------------------------------- /monasca_api/conf/global.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 IBM Corp. 2 | # Copyright 2016-2017 FUJITSU LIMITED 3 | # (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 6 | # not use this file except in compliance with the License. You may obtain 7 | # a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | 17 | from oslo_config import cfg 18 | 19 | _DEFAULT_NOTIF_PERIODS = [0, 60] 20 | 21 | global_opts = [ 22 | cfg.StrOpt('region', sample_default='RegionOne', 23 | help=''' 24 | Region that API is running in 25 | '''), 26 | cfg.ListOpt('valid_notification_periods', default=_DEFAULT_NOTIF_PERIODS, 27 | item_type=int, 28 | help=''' 29 | Valid periods for notification methods 30 | '''), 31 | cfg.BoolOpt('enable_metrics_api', default='true', 32 | help=''' 33 | Enable Metrics api endpoints'''), 34 | cfg.BoolOpt('enable_logs_api', default='false', 35 | help=''' 36 | Enable Logs api endpoints''') 37 | ] 38 | 39 | 40 | def register_opts(conf): 41 | conf.register_opts(global_opts) 42 | 43 | 44 | def list_opts(): 45 | return 'DEFAULT', global_opts 46 | -------------------------------------------------------------------------------- /monasca_api/conf/influxdb.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 IBM Corp. 2 | # Copyright 2016-2017 FUJITSU LIMITED 3 | # (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | # implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | from oslo_config import cfg 19 | 20 | influxdb_opts = [ 21 | cfg.StrOpt('database_name', default='mon', 22 | help=''' 23 | Database name where metrics are stored 24 | '''), 25 | cfg.BoolOpt('db_per_tenant', default=False, 26 | help=''' 27 | Whether to use a separate database per tenant 28 | '''), 29 | cfg.HostAddressOpt('ip_address', default='127.0.0.1', 30 | help=''' 31 | IP address to Influxdb server 32 | '''), 33 | cfg.PortOpt('port', default=8086, 34 | help='Port to Influxdb server'), 35 | cfg.StrOpt('user', required=True, 36 | sample_default='monasca-api', help=''' 37 | Influxdb user 38 | '''), 39 | cfg.StrOpt('password', secret=True, sample_default='password', 40 | help=''' 41 | Influxdb password 42 | ''') 43 | ] 44 | 45 | influxdb_group = cfg.OptGroup(name='influxdb', title='influxdb') 46 | 47 | 48 | def register_opts(conf): 49 | conf.register_group(influxdb_group) 50 | conf.register_opts(influxdb_opts, influxdb_group) 51 | 52 | 53 | def list_opts(): 54 | return influxdb_group, influxdb_opts 55 | -------------------------------------------------------------------------------- /monasca_api/conf/log_publisher.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 FUJITSU LIMITED 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from oslo_config import cfg 16 | 17 | _MAX_MESSAGE_SIZE = 1048576 18 | _DEFAULT_MAX_LOG_SIZE = 1024 * 1024 19 | 20 | log_publisher_opts = [ 21 | cfg.IntOpt('max_message_size', 22 | default=_MAX_MESSAGE_SIZE, 23 | required=True, 24 | help=''' 25 | Message max size that can be sent to kafka, default to %d bytes 26 | ''' % _MAX_MESSAGE_SIZE), 27 | cfg.StrOpt('region', 28 | default='Region;', 29 | help=''' 30 | Region 31 | '''), 32 | cfg.IntOpt('max_log_size', 33 | default=_DEFAULT_MAX_LOG_SIZE, 34 | help=''' 35 | Refers to payload/envelope size. If either is exceeded API will throw an error 36 | ''') 37 | ] 38 | 39 | log_publisher_group = cfg.OptGroup(name='log_publisher', title='log_publisher') 40 | 41 | 42 | def register_opts(conf): 43 | conf.register_group(log_publisher_group) 44 | conf.register_opts(log_publisher_opts, log_publisher_group) 45 | 46 | 47 | def list_opts(): 48 | return log_publisher_group, log_publisher_opts 49 | -------------------------------------------------------------------------------- /monasca_api/conf/messaging.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 IBM Corp. 2 | # Copyright 2016-2017 FUJITSU LIMITED 3 | # (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 6 | # not use this file except in compliance with the License. You may obtain 7 | # a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | 17 | from oslo_config import cfg 18 | 19 | messaging_opts = [ 20 | cfg.StrOpt('driver', help=''' 21 | The message queue driver to use 22 | '''), 23 | cfg.StrOpt('metrics_message_format', default='reference', 24 | deprecated_for_removal=True, 25 | deprecated_since="2.1.0", 26 | deprecated_reason=''' 27 | Option is not used anywhere in the codebase 28 | ''', 29 | help=''' 30 | The type of metrics message format to publish to the message queue 31 | '''), 32 | cfg.StrOpt('events_message_format', default='reference', 33 | deprecated_for_removal=True, 34 | deprecated_since='2.1.0', 35 | deprecated_reason=''' 36 | Option is not used anywhere in the codebase 37 | ''', 38 | help=''' 39 | The type of events message format to publish to the message queue 40 | ''') 41 | ] 42 | 43 | messaging_group = cfg.OptGroup(name='messaging', title='messaging') 44 | 45 | 46 | def register_opts(conf): 47 | conf.register_group(messaging_group) 48 | conf.register_opts(messaging_opts, messaging_group) 49 | 50 | 51 | def list_opts(): 52 | return messaging_group, messaging_opts 53 | -------------------------------------------------------------------------------- /monasca_api/db/README: -------------------------------------------------------------------------------- 1 | This directory contains the plumbing for the Alembic migrations that modify the 2 | Monasca database. 3 | 4 | If you need to add a new migration, run 5 | 6 | alembic revision -m '' 7 | 8 | in this directory, where is a short description for what 9 | your migration does such as 'Add volume field to alarm'. Alembic will then 10 | create a revision script in the alembic/versions/ directory. You will need to 11 | edit this script to add upwards and downwards migrations for the change you 12 | want to make. 13 | -------------------------------------------------------------------------------- /monasca_api/db/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/db/__init__.py -------------------------------------------------------------------------------- /monasca_api/db/alembic.ini: -------------------------------------------------------------------------------- 1 | # A generic, single database configuration. 2 | 3 | [alembic] 4 | # path to migration scripts 5 | script_location = %(here)s/alembic 6 | 7 | # template used to generate migration files 8 | # file_template = %%(rev)s_%%(slug)s 9 | 10 | # timezone to use when rendering the date 11 | # within the migration file as well as the filename. 12 | # string value is passed to dateutil.tz.gettz() 13 | # leave blank for localtime 14 | # timezone = 15 | 16 | # max length of characters to apply to the 17 | # "slug" field 18 | #truncate_slug_length = 40 19 | 20 | # set to 'true' to run the environment during 21 | # the 'revision' command, regardless of autogenerate 22 | # revision_environment = false 23 | 24 | # set to 'true' to allow .pyc and .pyo files without 25 | # a source .py file to be detected as revisions in the 26 | # versions/ directory 27 | # sourceless = false 28 | 29 | # version location specification; this defaults 30 | # to alembic/versions. When using multiple version 31 | # directories, initial revisions must be specified with --version-path 32 | # version_locations = %(here)s/bar %(here)s/bat alembic/versions 33 | 34 | # the output encoding used when revision files 35 | # are written from script.py.mako 36 | # output_encoding = utf-8 37 | 38 | # sqlalchemy.url = driver://user:pass@localhost/dbname 39 | 40 | 41 | # Logging configuration 42 | [loggers] 43 | keys = root,sqlalchemy,alembic 44 | 45 | [handlers] 46 | keys = console 47 | 48 | [formatters] 49 | keys = generic 50 | 51 | [logger_root] 52 | level = WARN 53 | handlers = console 54 | qualname = 55 | 56 | [logger_sqlalchemy] 57 | level = WARN 58 | handlers = 59 | qualname = sqlalchemy.engine 60 | 61 | [logger_alembic] 62 | level = INFO 63 | handlers = 64 | qualname = alembic 65 | 66 | [handler_console] 67 | class = StreamHandler 68 | args = (sys.stderr,) 69 | level = NOTSET 70 | formatter = generic 71 | 72 | [formatter_generic] 73 | format = %(levelname)-5.5s [%(name)s] %(message)s 74 | datefmt = %H:%M:%S 75 | -------------------------------------------------------------------------------- /monasca_api/db/alembic/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/db/alembic/__init__.py -------------------------------------------------------------------------------- /monasca_api/db/alembic/script.py.mako: -------------------------------------------------------------------------------- 1 | """${message} 2 | 3 | Revision ID: ${up_revision} 4 | Revises: ${down_revision | comma,n} 5 | Create Date: ${create_date} 6 | 7 | """ 8 | from alembic import op 9 | import sqlalchemy as sa 10 | ${imports if imports else ""} 11 | 12 | # revision identifiers, used by Alembic. 13 | revision = ${repr(up_revision)} 14 | down_revision = ${repr(down_revision)} 15 | branch_labels = ${repr(branch_labels)} 16 | depends_on = ${repr(depends_on)} 17 | 18 | 19 | def upgrade(): 20 | ${upgrades if upgrades else "pass"} 21 | 22 | 23 | def downgrade(): 24 | ${downgrades if downgrades else "pass"} 25 | -------------------------------------------------------------------------------- /monasca_api/db/alembic/versions/0cce983d957a_deterministic_alarms.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 SUSE Linux GmbH 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | """ Add flag for deterministic alarms (Git revision 0cce983d957a3d780b6d206ad25df1271a812b4a). 16 | 17 | Revision ID: 0cce983d957a 18 | Revises: 00597b5c8325 19 | Create Date: 2018-04-23 13:57:32.951669 20 | 21 | """ 22 | from alembic import op 23 | import sqlalchemy as sa 24 | 25 | 26 | # revision identifiers, used by Alembic. 27 | revision = '0cce983d957a' 28 | down_revision = '00597b5c8325' 29 | branch_labels = None 30 | depends_on = None 31 | 32 | 33 | def upgrade(): 34 | op.add_column('sub_alarm_definition', 35 | sa.Column('is_deterministic', 36 | sa.Boolean(), 37 | nullable=False, 38 | server_default='0')) 39 | 40 | 41 | def downgrade(): 42 | op.drop_column('sub_alarm_definition', 'is_deterministic') 43 | -------------------------------------------------------------------------------- /monasca_api/db/alembic/versions/6b2b88f3cab4_add_sub_alarm_state.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 SUSE Linux GmbH 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | """Add sub alarm state (Git revision 6b2b88f3cab46cd442369b22da3624611b871169) 16 | 17 | Revision ID: 6b2b88f3cab4 18 | Revises: 30181b42434b 19 | Create Date: 2018-04-24 12:16:15.812274 20 | 21 | """ 22 | from alembic import op 23 | import sqlalchemy as sa 24 | 25 | 26 | # revision identifiers, used by Alembic. 27 | revision = '6b2b88f3cab4' 28 | down_revision = '30181b42434b' 29 | branch_labels = None 30 | depends_on = None 31 | 32 | 33 | def upgrade(): 34 | op.add_column( 35 | 'sub_alarm', 36 | sa.Column('state', 37 | sa.String(length=20), 38 | sa.ForeignKey('alarm_state.name'), 39 | nullable=False, 40 | server_default='OK')) 41 | 42 | 43 | def downgrade(): 44 | op.drop_column('sub_alarm', 'state') 45 | -------------------------------------------------------------------------------- /monasca_api/db/alembic/versions/8781a256f0c1_add_inhibited_and_silenced_to_alarms.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 SUSE Linux GmbH 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | """Add inhibited and silenced to alarms (Git revision 8781a256f0c19662b81f04b014e2b769e625bd6b) 16 | 17 | Revision ID: 8781a256f0c1 18 | Revises: d8b801498850 19 | Create Date: 2018-04-24 13:16:04.157977 20 | 21 | """ 22 | from alembic import op 23 | import sqlalchemy as sa 24 | 25 | 26 | # revision identifiers, used by Alembic. 27 | revision = '8781a256f0c1' 28 | down_revision = 'd8b801498850' 29 | branch_labels = None 30 | depends_on = None 31 | 32 | 33 | def upgrade(): 34 | op.add_column('alarm', 35 | sa.Column('inhibited', 36 | sa.Boolean(), 37 | nullable=False, 38 | server_default='0')) 39 | op.add_column('alarm', 40 | sa.Column('silenced', 41 | sa.Boolean(), 42 | nullable=False, 43 | server_default='0')) 44 | 45 | 46 | def downgrade(): 47 | op.drop_column('alarm', 'inhibited') 48 | op.drop_column('alarm', 'silenced') 49 | -------------------------------------------------------------------------------- /monasca_api/db/alembic/versions/c2f85438d6f3_period_notifications.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 SUSE Linux GmbH 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | """Add period to notifications (Git revision c2f85438d6f3b0fd2e1f86d84eee6e9967025eb6) 16 | 17 | Revision ID: c2f85438d6f3 18 | Revises: 0cce983d957a 19 | Create Date: 2018-04-23 14:47:49.413502 20 | 21 | """ 22 | from alembic import op 23 | import sqlalchemy as sa 24 | 25 | 26 | # revision identifiers, used by Alembic. 27 | revision = 'c2f85438d6f3' 28 | down_revision = '0cce983d957a' 29 | branch_labels = None 30 | depends_on = None 31 | 32 | 33 | def upgrade(): 34 | op.add_column('notification_method', 35 | sa.Column('period', 36 | sa.Integer(), 37 | nullable=False, 38 | server_default='0')) 39 | 40 | 41 | def downgrade(): 42 | op.drop_column('notification_method', 'period') 43 | -------------------------------------------------------------------------------- /monasca_api/db/alembic/versions/d8b801498850_remove_stream_action_types.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 SUSE Linux GmbH 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | """Remove stream action types (Git revision d8b80149885016ede0ee403cf9bb07f9b7253297) 16 | 17 | Revision ID: d8b801498850 18 | Revises: 6b2b88f3cab4 19 | Create Date: 2018-04-24 12:53:02.342849 20 | 21 | """ 22 | from alembic import op 23 | import sqlalchemy as sa 24 | 25 | 26 | # revision identifiers, used by Alembic. 27 | revision = 'd8b801498850' 28 | down_revision = '6b2b88f3cab4' 29 | branch_labels = None 30 | depends_on = None 31 | 32 | 33 | def upgrade(): 34 | op.drop_table('stream_actions_action_type') 35 | 36 | 37 | def downgrade(): 38 | stream_action_types = op.create_table( 39 | 'stream_actions_action_type', 40 | sa.Column('name', 41 | sa.String(length=20), 42 | nullable=False), 43 | sa.PrimaryKeyConstraint('name'), 44 | mysql_charset='utf8mb4', 45 | mysql_collate='utf8mb4_unicode_ci') 46 | 47 | op.bulk_insert(stream_action_types, 48 | [{'name': 'FIRE'}, 49 | {'name': 'EXPIRE'}]) 50 | -------------------------------------------------------------------------------- /monasca_api/db/alembic/versions/f69cb3152a76_remove_inhibited_silenced_from_alarms.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 SUSE Linux GmbH 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | """Remove inhibited and silenced from alarms (Git revision f69cb3152a76e7c586dcc9a03600d1d4ed32c4e6) 16 | 17 | Revision ID: f69cb3152a76 18 | Revises: 8781a256f0c1 19 | Create Date: 2018-04-24 13:16:04.157977 20 | 21 | """ 22 | from alembic import op 23 | import sqlalchemy as sa 24 | 25 | 26 | # revision identifiers, used by Alembic. 27 | revision = 'f69cb3152a76' 28 | down_revision = '8781a256f0c1' 29 | branch_labels = None 30 | depends_on = None 31 | 32 | 33 | def upgrade(): 34 | op.drop_column('alarm', 'inhibited') 35 | op.drop_column('alarm', 'silenced') 36 | 37 | 38 | def downgrade(): 39 | op.add_column('alarm', 40 | sa.Column('inhibited', 41 | sa.Boolean(), 42 | nullable=False, 43 | server_default='0')) 44 | op.add_column('alarm', 45 | sa.Column('silenced', 46 | sa.Boolean(), 47 | nullable=False, 48 | server_default='0')) 49 | -------------------------------------------------------------------------------- /monasca_api/expression_parser/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/expression_parser/__init__.py -------------------------------------------------------------------------------- /monasca_api/hacking/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/hacking/__init__.py -------------------------------------------------------------------------------- /monasca_api/hacking/checks.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 FUJITSU LIMITED 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | import re 16 | 17 | from hacking import core 18 | 19 | assert_no_xrange_re = re.compile(r"\s*xrange\s*\(") 20 | 21 | 22 | @core.flake8ext 23 | def no_xrange(logical_line): 24 | """Do not use 'xrange' 25 | B319 26 | """ 27 | if assert_no_xrange_re.match(logical_line): 28 | yield (0, "B319: Do not use xrange().") 29 | -------------------------------------------------------------------------------- /monasca_api/healthcheck/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/healthcheck/__init__.py -------------------------------------------------------------------------------- /monasca_api/healthcheck/alarms_db_check.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 FUJITSU LIMITED 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from oslo_log import log 16 | from sqlalchemy import text 17 | 18 | from monasca_api.common.repositories.sqla import sql_repository 19 | from monasca_api.healthcheck import base 20 | 21 | LOG = log.getLogger(__name__) 22 | 23 | 24 | class AlarmsDbHealthCheck(base.BaseHealthCheck, 25 | sql_repository.SQLRepository): 26 | """Evaluates alarm db health 27 | 28 | Healthcheck verifies if: 29 | * database is up and running, it is possible to establish connection 30 | * sample sql query can be executed 31 | 32 | If following conditions are met health check return healthy status. 33 | Otherwise unhealthy status is returned with explanation. 34 | """ 35 | 36 | def health_check(self): 37 | status = self.check_db_status() 38 | return base.CheckResult(healthy=status[0], 39 | message=status[1]) 40 | 41 | def check_db_status(self): 42 | try: 43 | with self._db_engine.connect() as con: 44 | query = text('SELECT 1') 45 | con.execute(query) 46 | except Exception as ex: 47 | LOG.exception(str(ex)) 48 | return False, str(ex) 49 | return True, 'OK' 50 | -------------------------------------------------------------------------------- /monasca_api/healthcheck/base.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 FUJITSU LIMITED 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | import abc 16 | import collections 17 | 18 | import six 19 | 20 | 21 | class CheckResult(collections.namedtuple('CheckResult', ['healthy', 'message'])): 22 | """Result for the health check 23 | 24 | healthy - boolean 25 | message - string 26 | """ 27 | 28 | 29 | @six.add_metaclass(abc.ABCMeta) 30 | class BaseHealthCheck(object): 31 | """Abstract class implemented by the monasca-api healthcheck classes""" 32 | 33 | @abc.abstractmethod 34 | def health_check(self): 35 | """Evaluate health of given service""" 36 | raise NotImplementedError # pragma: no cover 37 | -------------------------------------------------------------------------------- /monasca_api/healthcheck/metrics_db_check.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 FUJITSU LIMITED 2 | # (C) Copyright 2017 Hewlett Packard Enterprise Development LP 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | # not use this file except in compliance with the License. You may obtain 6 | # a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | # License for the specific language governing permissions and limitations 14 | # under the License. 15 | 16 | from monasca_common.simport import simport 17 | from oslo_config import cfg 18 | from oslo_log import log 19 | 20 | from monasca_api.healthcheck import base 21 | 22 | CONF = cfg.CONF 23 | LOG = log.getLogger(__name__) 24 | 25 | 26 | class MetricsDbCheck(base.BaseHealthCheck): 27 | """Evaluates metrics db health 28 | 29 | Healthcheck what type of database is used (InfluxDB, Cassandra) 30 | and provide health according to the given db. 31 | 32 | If following conditions are met health check return healthy status. 33 | Otherwise unhealthy status is returned with explanation. 34 | """ 35 | 36 | def __init__(self): 37 | try: 38 | self._metrics_repo = simport.load( 39 | CONF.repositories.metrics_driver) 40 | 41 | except Exception as ex: 42 | LOG.exception(ex) 43 | raise 44 | 45 | def health_check(self): 46 | status = self._metrics_repo.check_status() 47 | return base.CheckResult(healthy=status[0], 48 | message=status[1]) 49 | -------------------------------------------------------------------------------- /monasca_api/policies/delegate.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 OP5 AB 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from oslo_config import cfg 16 | from oslo_policy import policy 17 | 18 | from monasca_api import policies 19 | 20 | DELEGATE_AUTHORIZED_ROLES = policies.roles_list_to_check_str( 21 | cfg.CONF.security.delegate_authorized_roles) 22 | 23 | rules = [ 24 | policy.RuleDefault( 25 | name='api:delegate', 26 | check_str=DELEGATE_AUTHORIZED_ROLES, 27 | description='The rules which allow to access the API on' 28 | ' behalf of another project (tenant).', 29 | 30 | ) 31 | ] 32 | 33 | 34 | def list_rules(): 35 | return rules 36 | -------------------------------------------------------------------------------- /monasca_api/policies/healthcheck.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 OP5 AB 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from oslo_config import cfg 16 | from oslo_policy import policy 17 | 18 | from monasca_api import policies 19 | 20 | CONF = cfg.CONF 21 | HEALTHCHECK_ROLES = policies.roles_list_to_check_str(cfg.CONF.security.healthcheck_roles) 22 | 23 | rules = [ 24 | policy.DocumentedRuleDefault( 25 | name='api:healthcheck', 26 | check_str=HEALTHCHECK_ROLES, 27 | description='Check healthiness.', 28 | operations=[ 29 | {'path': '/healthcheck', 'method': 'GET'} 30 | ] 31 | ), 32 | policy.DocumentedRuleDefault( 33 | name='api:healthcheck:head', 34 | check_str=HEALTHCHECK_ROLES, 35 | description='Healthcheck head rule', 36 | operations=[ 37 | {'path': '/healthcheck', 'method': 'HEAD'} 38 | ] 39 | ) 40 | ] 41 | 42 | 43 | def list_rules(): 44 | return rules 45 | -------------------------------------------------------------------------------- /monasca_api/policies/logs.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 OP5 AB 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from monasca_api import policies 16 | from oslo_config import cfg 17 | from oslo_policy import policy 18 | 19 | 20 | DEFAULT_AUTHORIZED_ROLES = policies.roles_list_to_check_str( 21 | cfg.CONF.security.default_authorized_roles) 22 | AGENT_AUTHORIZED_ROLES = policies.roles_list_to_check_str( 23 | cfg.CONF.security.agent_authorized_roles) 24 | DELEGATE_AUTHORIZED_ROLES = policies.roles_list_to_check_str( 25 | cfg.CONF.security.delegate_authorized_roles) 26 | 27 | rules = [ 28 | policy.DocumentedRuleDefault( 29 | name='api:logs:post', 30 | check_str=' or '.join(filter(None, [AGENT_AUTHORIZED_ROLES, 31 | DEFAULT_AUTHORIZED_ROLES, 32 | DELEGATE_AUTHORIZED_ROLES])), 33 | description='Logs post rule', 34 | operations=[ 35 | {'path': '/logs', 'method': 'POST'}, 36 | ] 37 | ) 38 | ] 39 | 40 | 41 | def list_rules(): 42 | return rules 43 | -------------------------------------------------------------------------------- /monasca_api/policies/versions.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 OP5 AB 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from oslo_config import cfg 16 | from oslo_policy import policy 17 | 18 | from monasca_api import policies 19 | 20 | CONF = cfg.CONF 21 | VERSIONS_ROLES = policies.roles_list_to_check_str(cfg.CONF.security.versions_roles) 22 | 23 | rules = [ 24 | policy.DocumentedRuleDefault( 25 | name='api:versions', 26 | check_str=VERSIONS_ROLES, 27 | description='List supported versions ' 28 | 'or get the details about the specified version of Monasca API.', 29 | operations=[ 30 | {'path': '/', 'method': 'GET'}, 31 | {'path': '/v2.0', 'method': 'GET'} 32 | ] 33 | ), 34 | ] 35 | 36 | 37 | def list_rules(): 38 | return rules 39 | -------------------------------------------------------------------------------- /monasca_api/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/tests/__init__.py -------------------------------------------------------------------------------- /monasca_api/tests/cmd/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/tests/cmd/__init__.py -------------------------------------------------------------------------------- /monasca_api/tests/cmd/test_status.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018 NEC, Corp. 2 | # Copyright (c) 2018 SUSE LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | # not use this file except in compliance with the License. You may obtain 6 | # a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | # License for the specific language governing permissions and limitations 14 | # under the License. 15 | 16 | import unittest 17 | 18 | from oslo_config import cfg 19 | from oslo_upgradecheck.upgradecheck import Code 20 | 21 | from monasca_api.cmd import status 22 | 23 | 24 | class TestUpgradeChecks(unittest.TestCase): 25 | 26 | def setUp(self): 27 | super(TestUpgradeChecks, self).setUp() 28 | self.cmd = status.Checks() 29 | cfg.CONF(args=[], project='magnum') 30 | 31 | def test_checks(self): 32 | for name, func in self.cmd._upgrade_checks: 33 | if isinstance(func, tuple): 34 | func_name, kwargs = func 35 | result = func_name(self, **kwargs) 36 | else: 37 | result = func(self) 38 | self.assertEqual(Code.SUCCESS, result.code) 39 | -------------------------------------------------------------------------------- /monasca_api/tests/config.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 FUJITSU LIMITED 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from unittest import mock 16 | 17 | from monasca_api import config 18 | from monasca_api.tests import base 19 | 20 | 21 | class TestConfig(base.BaseTestCase): 22 | 23 | @mock.patch('monasca_log_api.config.sys') 24 | def test_should_return_true_if_runs_under_gunicorn(self, sys_patch): 25 | sys_patch.argv = [ 26 | '/bin/gunicorn', 27 | '--capture-output', 28 | '--paste', 29 | 'etc/monasca/log-api-paste.ini', 30 | '--workers', 31 | '1' 32 | ] 33 | sys_patch.executable = '/bin/python' 34 | self.assertTrue(config._is_running_under_gunicorn()) 35 | 36 | @mock.patch('monasca_log_api.config.sys') 37 | def test_should_return_false_if_runs_without_gunicorn(self, sys_patch): 38 | sys_patch.argv = ['/bin/monasca-log-api'] 39 | sys_patch.executable = '/bin/python' 40 | self.assertFalse(config._is_running_under_gunicorn()) 41 | -------------------------------------------------------------------------------- /monasca_api/tests/db/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/tests/db/__init__.py -------------------------------------------------------------------------------- /monasca_api/tests/policy/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/tests/policy/__init__.py -------------------------------------------------------------------------------- /monasca_api/tests/test_keystone_protocol.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 FUJITSU LIMITED 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from unittest import mock 16 | 17 | from monasca_api.healthcheck import keystone_protocol 18 | from monasca_api.tests import base 19 | 20 | _CONF = {} 21 | 22 | 23 | class TestKeystoneProtocol(base.BaseTestCase): 24 | 25 | def test_should_return_none_if_healthcheck(self): 26 | mocked_api = mock.Mock() 27 | instance = keystone_protocol.SkippingAuthProtocol(mocked_api, _CONF) 28 | request = mock.Mock() 29 | request.path = '/healthcheck' 30 | 31 | ret_val = instance.process_request(request) 32 | 33 | self.assertIsNone(ret_val) 34 | 35 | @mock.patch('keystonemiddleware.auth_token.AuthProtocol.process_request') 36 | def test_should_enter_keystone_auth_if_not_healthcheck(self, proc_request): 37 | mocked_api = mock.Mock() 38 | instance = keystone_protocol.SkippingAuthProtocol(mocked_api, _CONF) 39 | request = mock.Mock() 40 | request.path = '/v2.0/logs/single' 41 | 42 | instance.process_request(request) 43 | 44 | self.assertTrue(proc_request.called) 45 | -------------------------------------------------------------------------------- /monasca_api/v2/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/v2/__init__.py -------------------------------------------------------------------------------- /monasca_api/v2/common/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/v2/common/__init__.py -------------------------------------------------------------------------------- /monasca_api/v2/common/exceptions.py: -------------------------------------------------------------------------------- 1 | # (C) Copyright 2015,2016,2017 Hewlett Packard Enterprise Development Company LP 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from falcon.http_error import HTTPError 16 | 17 | 18 | class HTTPUnprocessableEntityError(HTTPError): 19 | def __init__(self, title, description, **kwargs): 20 | HTTPError.__init__( 21 | self, 22 | '422 Unprocessable Entity', 23 | title=title, 24 | description=description, 25 | **kwargs 26 | ) 27 | 28 | 29 | class HTTPBadRequestError(HTTPError): 30 | def __init__(self, title, description, **kwargs): 31 | HTTPError.__init__( 32 | self, 33 | '400 Bad Request', 34 | title=title, 35 | description=description, 36 | **kwargs 37 | ) 38 | -------------------------------------------------------------------------------- /monasca_api/v2/common/schemas/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/v2/common/schemas/__init__.py -------------------------------------------------------------------------------- /monasca_api/v2/common/schemas/alarm_update_schema.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Hewlett-Packard 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | from oslo_log import log 16 | import six 17 | import voluptuous 18 | 19 | from monasca_api.v2.common.schemas import exceptions 20 | 21 | 22 | LOG = log.getLogger(__name__) 23 | 24 | alarm_update_schema = { 25 | voluptuous.Optional('state'): voluptuous.All( 26 | voluptuous.Any('OK', 'ALARM', 'UNDETERMINED')), 27 | voluptuous.Optional('lifecycle_state'): voluptuous.All( 28 | voluptuous.Any(str, six.text_type), voluptuous.Length(max=50)), 29 | voluptuous.Optional('link'): voluptuous.All( 30 | voluptuous.Any(str, six.text_type), voluptuous.Length(max=512)) 31 | } 32 | 33 | 34 | request_body_schema = voluptuous.Schema(alarm_update_schema, required=True, 35 | extra=True) 36 | 37 | 38 | def validate(msg): 39 | try: 40 | request_body_schema(msg) 41 | except Exception as ex: 42 | LOG.debug(ex) 43 | raise exceptions.ValidationException(str(ex)) 44 | -------------------------------------------------------------------------------- /monasca_api/v2/common/schemas/exceptions.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Hewlett-Packard 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | 16 | class ValidationException(Exception): 17 | pass 18 | -------------------------------------------------------------------------------- /monasca_api/v2/common/utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Hewlett-Packard 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | 16 | def date_handler(obj): 17 | return obj.isoformat() if hasattr(obj, 'isoformat') else obj 18 | -------------------------------------------------------------------------------- /monasca_api/v2/reference/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/monasca_api/v2/reference/__init__.py -------------------------------------------------------------------------------- /monasca_api/v2/reference/notificationstype.py: -------------------------------------------------------------------------------- 1 | # (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP 2 | # Copyright 2018 OP5 AB 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | # not use this file except in compliance with the License. You may obtain 6 | # a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | # License for the specific language governing permissions and limitations 14 | # under the License. 15 | 16 | import falcon 17 | from monasca_common.simport import simport 18 | from oslo_config import cfg 19 | 20 | from monasca_api.api import notificationstype_api_v2 21 | from monasca_api.v2.reference import helpers 22 | from monasca_api.v2.reference import resource 23 | 24 | 25 | class NotificationsType(notificationstype_api_v2.NotificationsTypeV2API): 26 | def __init__(self): 27 | super(NotificationsType, self).__init__() 28 | self._notification_method_type_repo = simport.load( 29 | cfg.CONF.repositories.notification_method_type_driver)() 30 | 31 | def _list_notifications(self, uri, limit): 32 | rows = self._notification_method_type_repo.list_notification_method_types() 33 | result = [dict(type=row) for row in rows] 34 | return helpers.paginate(result, uri, limit) 35 | 36 | @resource.resource_try_catch_block 37 | def on_get(self, req, res): 38 | helpers.validate_authorization(req, ['api:notifications:type']) 39 | # This is to provide consistency. Pagination is not really supported here as there 40 | # are not that many rows 41 | result = self._list_notifications(req.uri, req.limit) 42 | 43 | res.text = helpers.to_json(result) 44 | res.status = falcon.HTTP_200 45 | -------------------------------------------------------------------------------- /monasca_api/v2/reference/version_2_0.py: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Hewlett Packard Enterprise Development Company, L.P. 2 | # Copyright 2018 OP5 AB 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | # not use this file except in compliance with the License. You may obtain 6 | # a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | # License for the specific language governing permissions and limitations 14 | # under the License. 15 | 16 | from oslo_utils import encodeutils 17 | 18 | from monasca_api.v2.reference import helpers 19 | 20 | 21 | class Version2(object): 22 | def __init__(self): 23 | super(Version2, self).__init__() 24 | 25 | def on_get(self, req, res): 26 | helpers.validate_authorization(req, 27 | ['api:versions']) 28 | result = { 29 | 'id': 'v2.0', 30 | 'links': [{ 31 | 'rel': 'self', 32 | 'href': encodeutils.safe_decode(req.uri, 'utf-8') 33 | }], 34 | 'status': 'CURRENT', 35 | 'updated': "2013-03-06T00:00:00.000Z" 36 | } 37 | res.text = helpers.to_json(result) 38 | -------------------------------------------------------------------------------- /monasca_api/version.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 FUJITSU LIMITED 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | import pbr.version 16 | 17 | version_info = pbr.version.VersionInfo('monasca-api') 18 | version_str = version_info.version_string() 19 | -------------------------------------------------------------------------------- /perf/README.md: -------------------------------------------------------------------------------- 1 | 2 | monasca-api performance benchmarking 3 | ============= 4 | 5 | Recommended Configuration 6 | ============= 7 | 8 | Install 9 | ======= 10 | 11 | Install JMeter 12 | 13 | JMeter can be found at http://jmeter.apache.org/download_jmeter.cgi 14 | 15 | add JMeter bin to the path: PATH=$PATH:~/.../bin 16 | 17 | Monasca-query performance test 18 | ============================== 19 | 20 | This test is designed to work with data created from persister-perf performance test but 21 | can work with any monasca-api/db configuration. 22 | monasca-api will need to have region configured to support test data. 23 | JMeter uses monasca-api to query db backend. 24 | 25 | Load monasca_query_test.jmx into jmeter. 26 | Setup user defined variables for your environment. 27 | 28 | keystone_server keystone server ip address 29 | monasca-api_server monasca-api server ip address 30 | keystone_user admin keystone user with monitoring permissions 31 | keystone_password secretadmin password for keystone user 32 | tenant_id tenant_1 tenant id set in monascas-api/keystone. 33 | 34 | Run tests. 35 | -------------------------------------------------------------------------------- /playbooks/docker-publish.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: all 3 | tasks: 4 | - name: Login to Dockerhub 5 | command: "docker login -u {{ doker_hub_login_api.user }} -p {{ doker_hub_login_api.password }}" 6 | no_log: true 7 | 8 | - name: List images 9 | shell: "docker images --format '{% raw %}{{ .Repository }}:{{ .Tag }}{% endraw %}' | grep monasca" 10 | 11 | - name: Push to Docker Hub all tags 12 | shell: "docker push monasca/api:{{ zuul.tag if zuul.pipeline == 'release' else 'master'}}" 13 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | monasca 6 | monasca-api-base 7 | 1.2.1-SNAPSHOT 8 | https://github.com/openstack/monasca-api 9 | pom 10 | 11 | 12 | 13 | ${version} ${sun.java.command} 14 | true 15 | UTF-8 16 | UTF-8 17 | 18 | 19 | 20 | scm:git:git@github.com:openstack/monasca-api 21 | scm:git:git@github.com:openstack/monasca-api 22 | 23 | 24 | 25 | 26 | 27 | org.codehaus.mojo 28 | exec-maven-plugin 29 | 1.1.1 30 | 31 | 32 | package-execution 33 | package 34 | 35 | exec 36 | 37 | 38 | 39 | clean-execution 40 | clean 41 | 42 | exec 43 | 44 | 45 | 46 | 47 | run_maven.sh 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /releasenotes/locale/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openstack/monasca-api/7811ac8c4758505aa6bf30dd83249583d87b2f8a/releasenotes/locale/.gitkeep -------------------------------------------------------------------------------- /releasenotes/notes/add-cassandra-loadbalancing-policy-4d5d0e7e8064a870.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | features: 3 | - | 4 | support cassandra cluster configuration with loadbalancing policy DCAwareRoundRobinPolicy. 5 | 'local_data_center' defalut value is ''. 6 | -------------------------------------------------------------------------------- /releasenotes/notes/add-monasca-status-upgrade-check-c37e6910c2eb0150.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | features: 3 | - | 4 | Added new tool ``monasca-status upgrade check``. 5 | New framework for ``monasca-status upgrade check`` command is added. 6 | This framework allows adding various checks which can be run before a 7 | Monasca upgrade to ensure if the upgrade can be performed safely. 8 | upgrade: 9 | - | 10 | Operator can now use new CLI tool ``monasca-status upgrade check`` 11 | to check if the Monasca deployment can be safely upgraded from 12 | N-1 to N release. 13 | -------------------------------------------------------------------------------- /releasenotes/notes/add_legacy_kafka_client_enabled_option-7be9bc4e0fcecc70.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | Configuration option `legacy_kafka_client_enabled` added to allow working 5 | with both legacy kafka-python and new Confluent Kafka client. Please set 6 | message format version for the Kafka brokers to 0.9.0.0 to avoid 7 | performance issues until all consumers are upgraded. 8 | -------------------------------------------------------------------------------- /releasenotes/notes/alarms-count-dimensions-f746ca6c725335b2.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | features: 3 | - | 4 | Allow metric_dimensions filter to filter on multiple dimension values, 5 | on alarms count endpoint (IE metric_dimension=hostname:host1|host2). 6 | This brings the query parameters into parity between the alarms list 7 | and alarms count endpoints. This also restores functionality that was 8 | available on the deprecated java api. 9 | -------------------------------------------------------------------------------- /releasenotes/notes/apache-kafka-101-d5f3454fd445c727.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | Apache Kafka has been upgraded to version 1.0.1 in devstack. It is the 5 | recommended version for Monasca. Because of existing old consumers, Kafka 6 | log message format option `log.message.format.version` should be set to 7 | 0.9.0. 8 | -------------------------------------------------------------------------------- /releasenotes/notes/cassandra-connectiontimeout-option-13bc68e2fcd56580.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | features: 3 | - | 4 | Support cassandra connection timeout option which set timeout when creating a new connection. 5 | -------------------------------------------------------------------------------- /releasenotes/notes/config_gen-ead0282db82e6c0f.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | other: 3 | - | 4 | Removed maintaining the example of configuration file. The file was 5 | removed from the tree, however it can be generated using oslo.config 6 | generator feature. Devstack plugin has been also migrated to use it. -------------------------------------------------------------------------------- /releasenotes/notes/deprecate-json-formatted-policy-file-2f00c9efa9e274af.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | The default value of ``[oslo_policy] policy_file`` config option has 5 | been changed from ``policy.json`` to ``policy.yaml``. 6 | Operators who are utilizing customized or previously generated 7 | static policy JSON files (which are not needed by default), should 8 | generate new policy files or convert them in YAML format. Use the 9 | `oslopolicy-convert-json-to-yaml 10 | `_ 11 | tool to convert a JSON to YAML formatted policy file in 12 | backward compatible way. 13 | deprecations: 14 | - | 15 | Use of JSON policy files was deprecated by the ``oslo.policy`` library 16 | during the Victoria development cycle. As a result, this deprecation is 17 | being noted in the Wallaby cycle with an anticipated future removal of support 18 | by ``oslo.policy``. As such operators will need to convert to YAML policy 19 | files. Please see the upgrade notes for details on migration of any 20 | custom policy files. 21 | -------------------------------------------------------------------------------- /releasenotes/notes/disable-legacy-kafka-client-16dd1ac1894fe7a0.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | The default value of ``kafka.legacy_kafka_client_enabled`` has changed 5 | from ``True`` to ``False``. The use of new Confluent Kafka client is 6 | recommended. 7 | -------------------------------------------------------------------------------- /releasenotes/notes/drop-py-2-7-aee58a9afab0e4b9.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | Python 2.7 support has been dropped. Last release of monasca-api 5 | to support python 2.7 is OpenStack Train. The minimum version of Python now 6 | supported by monasca-api is Python 3.6. 7 | -------------------------------------------------------------------------------- /releasenotes/notes/elasticsearch-cluster-upgrade-4b7bdc9c17e0169f.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | Guide to upgrading to Elasticsearch 7.x can be found here: 5 | https://www.elastic.co/guide/en/cloud/current/ec-upgrading-v7.html 6 | -------------------------------------------------------------------------------- /releasenotes/notes/enable-disk-tsi-40f29262a0301531.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | Changes InfluxDB data from in-memory to disk storage 5 | (see https://docs.influxdata.com/influxdb/v1.7/concepts/time-series-index/). 6 | If upgrading an existing InfluxDB install please follow the instructions 7 | for migrating existing data here: 8 | https://docs.influxdata.com/influxdb/v1.7/administration/upgrading/#upgrading-influxdb-1-3-1-4-no-tsi-preview-to-1-7-x-tsi-enabled 9 | -------------------------------------------------------------------------------- /releasenotes/notes/fix-cassandra-cluster-port.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | features: 3 | - | 4 | User can configure Cassandra cluster port via configuration option. Default value for port number is ``9042``. -------------------------------------------------------------------------------- /releasenotes/notes/fix-db-migration-issue-2006984-6676bd3a8a34c9ae.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | fixes: 3 | - | 4 | An issue with migrating the DB schema in the Stein release 5 | which can cause an upgrade to fail. See `story 6 | 2006984 `__ 7 | -------------------------------------------------------------------------------- /releasenotes/notes/influx_1.3.3-1be2009139641336.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | Upgrade InfluxDB to 1.3.3 from 1.3.1. It provides couple of 5 | bug fixes as in https://docs.influxdata.com/influxdb/v1.3/about_the_project/releasenotes-changelog/#v1-3-3-2017-08-10. 6 | -------------------------------------------------------------------------------- /releasenotes/notes/influx_1.3.8-e6b0be63d7d7222f.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | Upgrade InfluxDB to 1.3.8 from 1.3.5. It provides couple of 5 | bug fixes as in https://docs.influxdata.com/influxdb/v1.3/about_the_project/releasenotes-changelog/#v1-3-9-2018-01-19 6 | -------------------------------------------------------------------------------- /releasenotes/notes/influxdb-support-for-db-per-tenant-6ada0c3979de6df8.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | features: 3 | - | 4 | Configuration option `db_per_tenant` added for InfluxDB to allow 5 | data points to be written to dedicated tenant database where the 6 | `database_name` prefixes the tenant ID, e.g. monasca_tenantid. 7 | -------------------------------------------------------------------------------- /releasenotes/notes/influxdb_1.3.9-666fc98a5357890d.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | Upgrade InfluxDB to 1.3.9 from 1.3.8. It provides the bugfix which improves 5 | performance when writes exceed `max-values-per-tag` or `max-series` 6 | https://docs.influxdata.com/influxdb/v1.3/about_the_project/releasenotes-changelog/#v1-3-9-2018-01-19 7 | -------------------------------------------------------------------------------- /releasenotes/notes/mergeapis-baa6905c7b8fd070.yaml: -------------------------------------------------------------------------------- 1 | 2 | features: 3 | - | 4 | Merge monasca-log-api source code into the monasca-api and enable logs endpoints. 5 | - | 6 | Introduce configuration options that allow to enable/disable metrics and logs endpoints. 7 | 8 | other: 9 | - | 10 | Unified response when content-type is incorect. Changed response for log part from 415 to 11 | 400 (Bad request, message - Bad content type. Must be application/json). -------------------------------------------------------------------------------- /releasenotes/notes/os-docs-550ce9ad68a4a29e.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | upgrade: 4 | - Documentation handling of monasca-api has been migrated 5 | to match OpenStack process. Note that this is just 6 | initial migration and entire transition will be completed 7 | in future. 8 | -------------------------------------------------------------------------------- /releasenotes/notes/oslo-policy-345ff286820badc6.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | ``agent_authorized_roles`` default value changed to ``monasca-agent`` to be 5 | consistent with rest of Monasca, was configured by default to ``agent`` so 6 | old policy configuration should be checked and adjusted accordingly. 7 | -------------------------------------------------------------------------------- /releasenotes/notes/oslo-policy-aebaebd218b9d2ff.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | features: 3 | - | 4 | Use of oslo mechanisms for defining and enforcing policy. 5 | A command line entry point that allow the user to generate a sample policy file. 6 | -------------------------------------------------------------------------------- /releasenotes/notes/relax-constraints-for-setting-periodic-notifications-68f6c2ed6f89ebc0.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | features: 3 | - | 4 | Adds support for configuring periodic notifications for all notification types. 5 | -------------------------------------------------------------------------------- /releasenotes/notes/remove-database-url-option-efd6c09b771063c0.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | Deprecated configuration option ``database.url`` has been removed. Please 5 | use ``database.connection`` instead. 6 | -------------------------------------------------------------------------------- /releasenotes/notes/stop_pre_populating_built_in_monasca_notification_plugins_in_db-140ece49106b4a5a.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - The concept of built-in monasca-notification plugins has been removed 4 | and the built-in plugins are no longer pre-populated in the database. If 5 | you were using the PAGERDUTY, EMAIL or WEBHOOK notification plugin you 6 | should explicitly enable it in the monasca-notification config file. 7 | -------------------------------------------------------------------------------- /releasenotes/notes/storm_1.1.3-4aa16a9c648cd89b.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | Upgrade Storm to 1.1.3 from 1.1.1. It provides security fix for 5 | http://www.securityfocus.com/bid/104399 6 | -------------------------------------------------------------------------------- /releasenotes/notes/support-configuring-kafka-post-size-4baa10353e859b8a.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | features: 3 | - A new config option, queue_buffering_max_messages, has been added to 4 | support controlling the size of posts to Kafka from the Monasca API. 5 | -------------------------------------------------------------------------------- /releasenotes/notes/support-timerange-for-dimension-names-and-values-e5a2ba64700dcd0b.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | features: 3 | - | 4 | Dimensions names and values can be scoped by a timerange which can make 5 | dimension related queries to large databases much faster because only the 6 | relevant shards are searched. Users that upgrade their Monasca Grafana 7 | Datasource plugin to version 1.3.0 will benefit from this feature. 8 | -------------------------------------------------------------------------------- /releasenotes/notes/upgrade-influxdb-3fa94ef4b15c8217.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | Upgrade InfluxDB to 1.7.6 from 1.3.9. This provides a number of stability, 5 | performance and bug fix improvements. Full release notes available here: 6 | https://docs.influxdata.com/influxdb/v1.7/about_the_project/releasenotes-changelog/#v1-7-6-2019-04-16 7 | security: 8 | - | 9 | InfluxDB 1.7.6 fixes a security issue in which monasca-api leaks 10 | dimensions across projects. 11 | -------------------------------------------------------------------------------- /releasenotes/notes/upgrade-storm-7b4f262d3783d589.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | Upgrade Storm to 1.2.2 from 1.1.3. 5 | 6 | -------------------------------------------------------------------------------- /releasenotes/notes/upgrade_kafka_2.0.1-b53f180d751e47f5.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | upgrade: 3 | - | 4 | Upgrade Apache Kafka from version 1.0.1 to 2.0.1. Please consult official 5 | `upgrading notes `_ 6 | for complete information on upgrading from previous versions. 7 | -------------------------------------------------------------------------------- /releasenotes/notes/use-standard-config-file-path-a4c1a29d9d3fcc07.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | deprecations: 3 | - | 4 | Configuration file path /etc/monasca/api-config.conf and 5 | /etc/monasca/api.conf are deprecated. Use the standard path 6 | /etc/monasca/monasca-api.conf or the configuration dir (supported via 7 | oslo.config) /etc/monasca/monasca-api.conf.d/any_config_name.conf 8 | -------------------------------------------------------------------------------- /releasenotes/source/index.rst: -------------------------------------------------------------------------------- 1 | ============================ 2 | Monitoring API Release Notes 3 | ============================ 4 | 5 | Contents: 6 | 7 | .. toctree:: 8 | :maxdepth: 1 9 | 10 | unreleased 11 | yoga 12 | xena 13 | wallaby 14 | victoria 15 | ussuri 16 | train 17 | stein 18 | rocky 19 | queens 20 | pike 21 | -------------------------------------------------------------------------------- /releasenotes/source/pike.rst: -------------------------------------------------------------------------------- 1 | =================================== 2 | Pike Series Release Notes 3 | =================================== 4 | 5 | .. release-notes:: 6 | :branch: stable/pike 7 | -------------------------------------------------------------------------------- /releasenotes/source/queens.rst: -------------------------------------------------------------------------------- 1 | =================================== 2 | Queens Series Release Notes 3 | =================================== 4 | 5 | .. release-notes:: 6 | :branch: stable/queens 7 | -------------------------------------------------------------------------------- /releasenotes/source/rocky.rst: -------------------------------------------------------------------------------- 1 | =================================== 2 | Rocky Series Release Notes 3 | =================================== 4 | 5 | .. release-notes:: 6 | :branch: stable/rocky 7 | -------------------------------------------------------------------------------- /releasenotes/source/stein.rst: -------------------------------------------------------------------------------- 1 | =================================== 2 | Stein Series Release Notes 3 | =================================== 4 | 5 | .. release-notes:: 6 | :branch: stable/stein 7 | -------------------------------------------------------------------------------- /releasenotes/source/train.rst: -------------------------------------------------------------------------------- 1 | ========================== 2 | Train Series Release Notes 3 | ========================== 4 | 5 | .. release-notes:: 6 | :branch: stable/train 7 | -------------------------------------------------------------------------------- /releasenotes/source/unreleased.rst: -------------------------------------------------------------------------------- 1 | ============================== 2 | Current Series Release Notes 3 | ============================== 4 | 5 | .. release-notes:: 6 | -------------------------------------------------------------------------------- /releasenotes/source/ussuri.rst: -------------------------------------------------------------------------------- 1 | =========================== 2 | Ussuri Series Release Notes 3 | =========================== 4 | 5 | .. release-notes:: 6 | :branch: stable/ussuri 7 | -------------------------------------------------------------------------------- /releasenotes/source/victoria.rst: -------------------------------------------------------------------------------- 1 | ============================= 2 | Victoria Series Release Notes 3 | ============================= 4 | 5 | .. release-notes:: 6 | :branch: stable/victoria 7 | -------------------------------------------------------------------------------- /releasenotes/source/wallaby.rst: -------------------------------------------------------------------------------- 1 | ============================ 2 | Wallaby Series Release Notes 3 | ============================ 4 | 5 | .. release-notes:: 6 | :branch: stable/wallaby 7 | -------------------------------------------------------------------------------- /releasenotes/source/xena.rst: -------------------------------------------------------------------------------- 1 | ========================= 2 | Xena Series Release Notes 3 | ========================= 4 | 5 | .. release-notes:: 6 | :branch: stable/xena 7 | -------------------------------------------------------------------------------- /releasenotes/source/yoga.rst: -------------------------------------------------------------------------------- 1 | ========================= 2 | Yoga Series Release Notes 3 | ========================= 4 | 5 | .. release-notes:: 6 | :branch: unmaintained/yoga 7 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # Requirements lower bounds listed here are our best effort to keep them up to 2 | # date but we do not test them so no guarantee of having them all correct. If 3 | # you find any incorrect lower bounds, let us know or propose a fix. 4 | 5 | # The order of packages is significant, because pip processes them in the order 6 | # of appearance. Changing the order has an impact on the overall integration 7 | # process, which may cause wedges in the gate later. 8 | oslo.db>=6.0.0 # Apache-2.0 9 | oslo.config>=6.8.0 # Apache-2.0 10 | oslo.context>=2.22.0 # Apache-2.0 11 | oslo.log>=3.36.0 # Apache-2.0 12 | oslo.middleware>=3.31.0 # Apache-2.0 13 | oslo.policy>=3.6.0 # Apache-2.0 14 | oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 15 | oslo.upgradecheck>=1.3.0 # Apache-2.0 16 | oslo.utils>=4.5.0 # Apache-2.0 17 | 18 | python-keystoneclient>=3.8.0 # Apache-2.0 19 | 20 | falcon>=2.0.0 # Apache-2.0 21 | keystonemiddleware>=4.17.0 # Apache-2.0 22 | Paste>=2.0.2 # MIT 23 | PasteDeploy>=1.5.0 # MIT 24 | pbr!=2.1.0,>=2.0.0 # Apache-2.0 25 | six>=1.12.0 # MIT 26 | pyparsing>=3.0.6 # MIT 27 | voluptuous>=0.11.1 # BSD License 28 | eventlet!=0.18.3,!=0.20.1,!=0.21.0,!=0.23.0,!=0.25.0,>=0.18.2 # MIT 29 | monasca-common>=2.16.0 # Apache-2.0 30 | SQLAlchemy>=1.3.0 # MIT 31 | simplejson>=3.8.1 # MIT 32 | -------------------------------------------------------------------------------- /run_maven.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x 3 | env 4 | # Download maven 3 if the system maven isn't maven 3 5 | VERSION=`mvn -v | grep "Apache Maven 3"` 6 | if [ -z "${VERSION}" ]; then 7 | curl https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz > apache-maven-3.9.9-bin.tar.gz 8 | tar -xvzf apache-maven-3.9.9-bin.tar.gz 9 | MVN=${PWD}/apache-maven-3.9.9/bin/mvn 10 | else 11 | MVN=mvn 12 | fi 13 | 14 | # Get the expected common version 15 | COMMON_VERSION=$1 16 | # Get rid of the version argument 17 | shift 18 | 19 | # Get rid of the java property name containing the args 20 | shift 21 | 22 | RUN_BUILD=false 23 | for ARG in $*; do 24 | if [ "$ARG" = "package" ]; then 25 | RUN_BUILD=true 26 | fi 27 | if [ "$ARG" = "install" ]; then 28 | RUN_BUILD=true 29 | fi 30 | done 31 | 32 | if [ $RUN_BUILD = "true" ]; then 33 | if [ ! -z "$ZUUL_BRANCH" ]; then 34 | BRANCH=${ZUUL_BRANCH} 35 | else 36 | BRANCH=${ZUUL_REF} 37 | fi 38 | 39 | ( cd common; ./build_common.sh ${MVN} ${COMMON_VERSION} ${BRANCH} ) 40 | RC=$? 41 | if [ $RC != 0 ]; then 42 | exit $RC 43 | fi 44 | fi 45 | 46 | # Invoke the maven 3 on the real pom.xml 47 | ( cd java; ${MVN} -DgitRevision=`git rev-list HEAD --max-count 1 --abbrev=0 --abbrev-commit` $* ) 48 | 49 | RC=$? 50 | 51 | # Copy the jars where the publisher will find them 52 | if [ $RUN_BUILD = "true" ]; then 53 | if [ ! -L target ]; then 54 | ln -sf java/target target 55 | fi 56 | fi 57 | 58 | rm -fr apache-maven-3.9.9* 59 | exit $RC 60 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = monasca-api 3 | 4 | summary = OpenStack Monitoring as a Service 5 | description_file = 6 | README.rst 7 | author = OpenStack 8 | author_email = openstack-discuss@lists.openstack.org 9 | home_page = https://docs.openstack.org/monasca-api/latest/ 10 | python_requires = >=3.8 11 | classifier = 12 | Environment :: OpenStack 13 | Intended Audience :: Information Technology 14 | Intended Audience :: System Administrators 15 | License :: OSI Approved :: Apache Software License 16 | Operating System :: POSIX :: Linux 17 | Programming Language :: Python 18 | Programming Language :: Python :: Implementation :: CPython 19 | Programming Language :: Python :: 3 :: Only 20 | Programming Language :: Python :: 3.8 21 | Programming Language :: Python :: 3.9 22 | Programming Language :: Python :: 3.10 23 | Programming Language :: Python :: 3.11 24 | 25 | [files] 26 | packages = 27 | monasca_api 28 | 29 | data_files = 30 | /etc/monasca = 31 | etc/api-logging.conf 32 | etc/api-config.ini 33 | 34 | [extras] 35 | influxdb = 36 | influxdb>=2.9.2 # MIT 37 | cassandra = 38 | cassandra-driver!=3.6.0,>=3.3.0 # Apache-2.0 39 | 40 | [entry_points] 41 | console_scripts = 42 | monasca-api = monasca_api.api.server:launch 43 | monasca_db = monasca_api.cmd.monasca_db:main 44 | monasca-status = monasca_api.cmd.status:main 45 | 46 | wsgi_scripts = 47 | monasca-api-wsgi = monasca_api.api.wsgi:main 48 | 49 | oslo.config.opts = 50 | monasca_api = monasca_api.conf:list_opts 51 | 52 | oslo.policy.policies = 53 | monasca_api = monasca_api.policies:list_rules 54 | 55 | [pbr] 56 | autodoc_index_modules = True 57 | autodoc_exclude_modules = 58 | monasca_api.api.wsgi* 59 | monasca_api.conf.* 60 | monasca_api.tests.* 61 | monasca_tempest_tests.* 62 | api_doc_dir = contributor/api 63 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 Hewlett-Packard Development Company, L.P. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | # implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | import setuptools 17 | 18 | setuptools.setup( 19 | setup_requires=['pbr>=2.0.0'], 20 | pbr=True) 21 | -------------------------------------------------------------------------------- /test-requirements.txt: -------------------------------------------------------------------------------- 1 | # The order of packages is significant, because pip processes them in the order 2 | # of appearance. Changing the order has an impact on the overall integration 3 | # process, which may cause wedges in the gate later. 4 | # Hacking already pins down pep8, pyflakes and flake8 5 | bandit>=1.1.0 # Apache-2.0 6 | bashate>=0.5.1 # Apache-2.0 7 | hacking>=3.0.1,<3.1.0 # Apache-2.0 8 | Babel!=2.4.0,>=2.3.4 # BSD 9 | coverage>=4.4.1 # Apache-2.0 10 | cassandra-driver!=3.6.0,>=3.3.0 # Apache-2.0 11 | fixtures>=3.0.0 # Apache-2.0/BSD 12 | httplib2>=0.9.1 # MIT 13 | influxdb>=2.9.2 # MIT 14 | oslotest>=3.2.0 # Apache-2.0 15 | requests-mock>=1.2.0 # Apache-2.0 16 | stestr>=1.0.0 # Apache-2.0 17 | python-subunit>=1.0.0 # Apache-2.0/BSD 18 | 19 | # tempest 20 | testrepository>=0.0.18 # Apache-2.0/BSD 21 | testscenarios>=0.4 # Apache-2.0/BSD 22 | testtools>=2.2.0 # MIT 23 | tempest>=17.1.0 # Apache-2.0 24 | 25 | doc8>=0.6.0 # Apache-2.0 26 | oslo.config>=6.8.0 # Apache-2.0 -------------------------------------------------------------------------------- /tools/bashate.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Ignore too long lines error E006 from bashate and treat 4 | # E005, E042 as errors. 5 | SH_FILES=$(find ./devstack -type d -name files -prune -o -type f -name '*.sh' -print) 6 | bashate -v -iE006 -eE005,E042 ${SH_FILES:-''} 7 | --------------------------------------------------------------------------------