heat_template_version: pike

description: >
  OpenStack Ceilometer Collector service configured with Puppet
  This service is deprecated and will be removed in future releases.

parameters:
  ServiceNetMap:
    default: {}
    description: Mapping of service_name -> network name. Typically set
                 via parameter_defaults in the resource registry.  This
                 mapping overrides those in ServiceNetMapDefaults.
    type: json
  DefaultPasswords:
    default: {}
    type: json
  RoleName:
    default: ''
    description: Role name on which the service is applied
    type: string
  RoleParameters:
    default: {}
    description: Parameters specific to the role
    type: json
  EndpointMap:
    default: {}
    description: Mapping of service endpoint -> protocol. Typically set
                 via parameter_defaults in the resource registry.
    type: json
  CeilometerBackend:
    default: 'mongodb'
    description: The ceilometer backend type.
    type: string
  CeilometerPassword:
    description: The password for the ceilometer service account.
    type: string
    hidden: true
  MonitoringSubscriptionCeilometerCollector:
    default: 'overcloud-ceilometer-collector'
    type: string
  CeilometerCollectorLoggingSource:
    type: json
    default:
      tag: openstack.ceilometer.collector
      path: /var/log/ceilometer/collector.log
  CeilometerMeterDispatcher:
    default: ['gnocchi']
    description: Comma-seperated list of Dispatcher to process meter data
                 Note that database option is deprecated and will not be
                 supported in future.
    type: comma_delimited_list
    constraints:
    - allowed_values: ['gnocchi', 'database']
  CeilometerEventDispatcher:
    default: ['panko', 'gnocchi']
    description: Comma-separated list of Dispatchers to process events data
                 Note that database option is deprecated and will not be
                 supported in future.
    type: comma_delimited_list
    constraints:
    - allowed_values: ['panko', 'gnocchi', 'database']
  CeilometerEventTTL:
    default: '86400'
    description: Number of seconds that events are kept in the database for
                 (<= 0 means forever)
    type: string
  CeilometerMeteringTTL:
    default: '86400'
    description: Number of seconds that samples are kept in the database for
                 (<= 0 means forever)
    type: string
resources:
  CeilometerServiceBase:
    type: ./ceilometer-base.yaml
    properties:
      ServiceNetMap: {get_param: ServiceNetMap}
      DefaultPasswords: {get_param: DefaultPasswords}
      EndpointMap: {get_param: EndpointMap}
      RoleName: {get_param: RoleName}
      RoleParameters: {get_param: RoleParameters}

  MongoDbBase:
    type: ./database/mongodb-base.yaml
    properties:
      ServiceNetMap: {get_param: ServiceNetMap}
      DefaultPasswords: {get_param: DefaultPasswords}
      EndpointMap: {get_param: EndpointMap}
      RoleName: {get_param: RoleName}
      RoleParameters: {get_param: RoleParameters}

outputs:
  role_data:
    description: Role data for the Ceilometer Collector role.
    value:
      service_name: ceilometer_collector
      monitoring_subscription: {get_param: MonitoringSubscriptionCeilometerCollector}
      logging_source: {get_param: CeilometerCollectorLoggingSource}
      logging_groups:
        - ceilometer
      config_settings:
        map_merge:
          - get_attr: [MongoDbBase, role_data, config_settings]
          - get_attr: [CeilometerServiceBase, role_data, config_settings]
          - ceilometer::db::database_connection:
              make_url:
                scheme: {get_param: [EndpointMap, MysqlInternal, protocol]}
                username: ceilometer
                password: {get_param: CeilometerPassword}
                host: {get_param: [EndpointMap, MysqlInternal, host]}
                path: /ceilometer
                query:
                  read_default_file: /etc/my.cnf.d/tripleo.cnf
                  read_default_group: tripleo
            ceilometer_backend: {get_param: CeilometerBackend}
            ceilometer::event_time_to_live: {get_param: CeilometerEventTTL}
            ceilometer::metering_time_to_live: {get_param: CeilometerMeteringTTL}
            # we include db_sync class in puppet-tripleo
            ceilometer::db::sync_db: false
            ceilometer::db::database_db_max_retries: -1
            ceilometer::db::database_max_retries: -1
            ceilometer::collector::meter_dispatcher: {get_param: CeilometerMeterDispatcher}
            ceilometer::collector::event_dispatcher: {get_param: CeilometerEventDispatcher}
      service_config_settings:
        get_attr: [CeilometerServiceBase, role_data, service_config_settings]
      step_config: |
        include ::tripleo::profile::base::ceilometer::collector
      upgrade_tasks:
        - name: Check if ceilometer_collector is deployed
          command: systemctl is-enabled openstack-ceilometer-collector
          tags: common
          ignore_errors: True
          register: ceilometer_collector_enabled
        - name: "PreUpgrade step0,validation: Check service openstack-ceilometer-collector is running"
          shell: /usr/bin/systemctl show 'openstack-ceilometer-collector' --property ActiveState | grep '\bactive\b'
          when: ceilometer_collector_enabled.rc == 0
          tags: step0,validation
        - name: Stop ceilometer_collector service
          tags: step1
          when: ceilometer_collector_enabled.rc == 0
          service: name=openstack-ceilometer-collector state=stopped