<commit_before>{%- from 'cloudera/manager/settings.sls' import cloudera_manager with context %}
{%- from 'gateway/settings.sls' import gateway with context %}
{%- from 'postgresql/settings.sls' import postgresql with context %}

init-cloudera-manager-db:
  cmd.run:
    - name: /opt/cloudera/cm/schema/scm_prepare_database.sh -h {{ cloudera_manager.cloudera_manager_database.host }} {{ cloudera_manager.cloudera_manager_database.subprotocol }} {{ cloudera_manager.cloudera_manager_database.databaseName }} $user $pass && echo $(date +%Y-%m-%d:%H:%M:%S) >> /var/log/init-cloudera-manager-db-executed
    - unless: test -f /var/log/init-cloudera-manager-db-executed
    - env:
        - user: {{ cloudera_manager.cloudera_manager_database.connectionUserName }}
        - pass: {{ cloudera_manager.cloudera_manager_database.connectionPassword }}

#Configure JDBC URL for CM if client side certification validation is enabled for the Datalake cluster
{% if postgresql.ssl_enabled == True and salt['pillar.get']('telemetry:clusterType') == "datalake" %}
replace-db-connection-url:
  file.replace:
    - name: /etc/cloudera-scm-server/db.properties
    - pattern: "(#UPDATED BY CDP CP:\n)?com.cloudera.cmf.orm.hibernate.connection.url=.*"
    - repl: "#UPDATED BY CDP CP:\ncom.cloudera.cmf.orm.hibernate.connection.url=jdbc:{{ cloudera_manager.cloudera_manager_database.subprotocol }}://{{ cloudera_manager.cloudera_manager_database.host }}/{{ cloudera_manager.cloudera_manager_database.databaseName }}?sslmode=verify-full&sslrootcert={{ postgresql.root_certs_file }}"
    - append_if_not_found: True
    - require:
        - cmd: init-cloudera-manager-db
{% endif %}

# We need to restart the CM if the frontend URL has been changed (e.g. switching to PEM based DNS name)

{% if salt['pillar.get']('gateway:userfacingfqdn') is defined and salt['pillar.get']('gateway:userfacingfqdn')|length > 1 %}
update_frontend_url_of_cm:
  file.replace:
      - name: /etc/cloudera-scm-server/cm.settings
      - pattern: 'setsettings FRONTEND_URL.*'
      - repl: 'setsettings FRONTEND_URL https://{{ salt['pillar.get']('gateway:userfacingfqdn') }}/'
      - unless: grep "^setsettings FRONTEND_URL https://{{ salt['pillar.get']('gateway:userfacingfqdn') }}/$" /etc/cloudera-scm-server/cm.settings

restart_cm_after_fronted_url_change:
  service.running:
    - name: cloudera-scm-server
{% if "ipa_member" in grains.get('roles', []) %}
    - require:
        - pkg: ipa_packages_install
{% endif %}
    - watch:
      - file: update_frontend_url_of_cm
{% endif %}

{% if salt['pillar.get']('cloudera-manager:mgmt_service_directories') is defined and salt['pillar.get']('cloudera-manager:mgmt_service_directories')|length > 0 %}
ensure_owners:
  file.directory:
    - names:
{%- for dir in salt['pillar.get']('cloudera-manager:mgmt_service_directories') %}
        - {{ dir }}
{%- endfor %}
    - user: cloudera-scm
    - group: cloudera-scm
    - recurse:
        - user
        - group
{% endif %}

start_server:
  service.running:
    - enable: True
    - name: cloudera-scm-server
{% if "ipa_member" in grains.get('roles', []) %}
    - require:
        - pkg: ipa_packages_install
{% endif %}<commit_msg>CB-10519 Modify directories' owner only if directory exists<commit_after>{%- from 'cloudera/manager/settings.sls' import cloudera_manager with context %}
{%- from 'gateway/settings.sls' import gateway with context %}
{%- from 'postgresql/settings.sls' import postgresql with context %}

init-cloudera-manager-db:
  cmd.run:
    - name: /opt/cloudera/cm/schema/scm_prepare_database.sh -h {{ cloudera_manager.cloudera_manager_database.host }} {{ cloudera_manager.cloudera_manager_database.subprotocol }} {{ cloudera_manager.cloudera_manager_database.databaseName }} $user $pass && echo $(date +%Y-%m-%d:%H:%M:%S) >> /var/log/init-cloudera-manager-db-executed
    - unless: test -f /var/log/init-cloudera-manager-db-executed
    - env:
        - user: {{ cloudera_manager.cloudera_manager_database.connectionUserName }}
        - pass: {{ cloudera_manager.cloudera_manager_database.connectionPassword }}

#Configure JDBC URL for CM if client side certification validation is enabled for the Datalake cluster
{% if postgresql.ssl_enabled == True and salt['pillar.get']('telemetry:clusterType') == "datalake" %}
replace-db-connection-url:
  file.replace:
    - name: /etc/cloudera-scm-server/db.properties
    - pattern: "(#UPDATED BY CDP CP:\n)?com.cloudera.cmf.orm.hibernate.connection.url=.*"
    - repl: "#UPDATED BY CDP CP:\ncom.cloudera.cmf.orm.hibernate.connection.url=jdbc:{{ cloudera_manager.cloudera_manager_database.subprotocol }}://{{ cloudera_manager.cloudera_manager_database.host }}/{{ cloudera_manager.cloudera_manager_database.databaseName }}?sslmode=verify-full&sslrootcert={{ postgresql.root_certs_file }}"
    - append_if_not_found: True
    - require:
        - cmd: init-cloudera-manager-db
{% endif %}

# We need to restart the CM if the frontend URL has been changed (e.g. switching to PEM based DNS name)

{% if salt['pillar.get']('gateway:userfacingfqdn') is defined and salt['pillar.get']('gateway:userfacingfqdn')|length > 1 %}
update_frontend_url_of_cm:
  file.replace:
      - name: /etc/cloudera-scm-server/cm.settings
      - pattern: 'setsettings FRONTEND_URL.*'
      - repl: 'setsettings FRONTEND_URL https://{{ salt['pillar.get']('gateway:userfacingfqdn') }}/'
      - unless: grep "^setsettings FRONTEND_URL https://{{ salt['pillar.get']('gateway:userfacingfqdn') }}/$" /etc/cloudera-scm-server/cm.settings

restart_cm_after_fronted_url_change:
  service.running:
    - name: cloudera-scm-server
{% if "ipa_member" in grains.get('roles', []) %}
    - require:
        - pkg: ipa_packages_install
{% endif %}
    - watch:
      - file: update_frontend_url_of_cm
{% endif %}

{% if salt['pillar.get']('cloudera-manager:mgmt_service_directories') is defined and salt['pillar.get']('cloudera-manager:mgmt_service_directories')|length > 0 %}
{%- for dir in salt['pillar.get']('cloudera-manager:mgmt_service_directories') %}
ensure_owners_{{ dir }}:
  file.directory:
    - name: {{ dir }}
    - user: cloudera-scm
    - group: cloudera-scm
    - recurse:
      - user
      - group
    - onlyif: test -d {{ dir }}

{%- endfor %}
{% endif %}

start_server:
  service.running:
    - enable: True
    - name: cloudera-scm-server
{% if "ipa_member" in grains.get('roles', []) %}
    - require:
        - pkg: ipa_packages_install
{% endif %}
{'fraction_non_alphanumeric': 0.14936473504803222, 'fraction_numerical': 0.0013944840409048653, 'mean_word_length': 4.127084988085782, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3752774', 'n_tokens_mistral': 2425, 'n_tokens_neox': 2313, 'n_words': 390}