<commit_before>#!/usr/bin/env python

from os.path import (
    basename,
    dirname,
    join,
)

from cloudify import ctx

ctx.download_resource(
    join('components', 'utils.py'),
    join(dirname(__file__), 'utils.py'))
import utils  # NOQA


CONFIG_PATH = 'components/logstash/config'
LOGSTASH_SERVICE_NAME = 'logstash'

ctx_properties = utils.ctx_factory.create(LOGSTASH_SERVICE_NAME)


def install_logstash():

    logstash_unit_override = '/etc/systemd/system/logstash.service.d'

    logstash_source_url = ctx_properties['logstash_rpm_source_url']
    postgresql_jdbc_driver_url = (
        'https://jdbc.postgresql.org/download/postgresql-9.4.1212.jar'
    )

    logstash_log_path = '/var/log/cloudify/logstash'

    ctx.logger.info('Installing Logstash...')
    utils.set_selinux_permissive()
    utils.copy_notice(LOGSTASH_SERVICE_NAME)

    utils.yum_install(logstash_source_url, service_name=LOGSTASH_SERVICE_NAME)

    ctx.logger.info('Installing logstash-output-jdbc plugin...')
    utils.run([
        'sudo', '-u', 'logstash',
        '/opt/logstash/bin/plugin', 'install', 'logstash-output-jdbc',
    ])

    ctx.logger.info('Installing PostgreSQL JDBC driver...')
    utils.download_file(
        postgresql_jdbc_driver_url,
        join(
            '/opt/logstash/vendor/jar/jdbc',
            basename(postgresql_jdbc_driver_url),
        ),
    )
    utils.chown('logstash', 'logstash', '/opt/logstash/vendor/jar')

    ctx.logger.info('Creating PostgreSQL tables...')
    for table_name in ['logs', 'events']:
        utils.run([
            'sudo', '-u', 'postgres',
            'psql', 'cloudify_db', '-c',
            (
                'CREATE TABLE {0} (timestamp TIMESTAMP, message TEXT);'
                'ALTER TABLE {0} OWNER TO cloudify;'
                .format(table_name)
            )
        ])
<commit_msg>CFY-6090 Create directory before downloading file<commit_after>#!/usr/bin/env python

from os.path import (
    basename,
    dirname,
    join,
)

from cloudify import ctx

ctx.download_resource(
    join('components', 'utils.py'),
    join(dirname(__file__), 'utils.py'))
import utils  # NOQA


CONFIG_PATH = 'components/logstash/config'
LOGSTASH_SERVICE_NAME = 'logstash'

ctx_properties = utils.ctx_factory.create(LOGSTASH_SERVICE_NAME)


def install_logstash():

    logstash_unit_override = '/etc/systemd/system/logstash.service.d'

    logstash_source_url = ctx_properties['logstash_rpm_source_url']
    postgresql_jdbc_driver_url = (
        'https://jdbc.postgresql.org/download/postgresql-9.4.1212.jar'
    )

    logstash_log_path = '/var/log/cloudify/logstash'

    ctx.logger.info('Installing Logstash...')
    utils.set_selinux_permissive()
    utils.copy_notice(LOGSTASH_SERVICE_NAME)

    utils.yum_install(logstash_source_url, service_name=LOGSTASH_SERVICE_NAME)

    ctx.logger.info('Installing logstash-output-jdbc plugin...')
    utils.run([
        'sudo', '-u', 'logstash',
        '/opt/logstash/bin/plugin', 'install', 'logstash-output-jdbc',
    ])

    ctx.logger.info('Installing PostgreSQL JDBC driver...')
    jar_path = '/opt/logstash/vendor/jar'
    jdbc_path = join(jar_path, 'jdbc')
    utils.mkdir(jdbc_path)
    utils.chown('logstash', 'logstash', '/opt/logstash/vendor/jar')
    utils.download_file(
        postgresql_jdbc_driver_url,
        join(jdbc_path, basename(postgresql_jdbc_driver_url)),
    )

    ctx.logger.info('Creating PostgreSQL tables...')
    for table_name in ['logs', 'events']:
        utils.run([
            'sudo', '-u', 'postgres',
            'psql', 'cloudify_db', '-c',
            (
                'CREATE TABLE {0} (timestamp TIMESTAMP, message TEXT);'
                'ALTER TABLE {0} OWNER TO cloudify;'
                .format(table_name)
            )
        ])

{'fraction_non_alphanumeric': 0.13500660501981507, 'fraction_numerical': 0.005284015852047556, 'mean_word_length': 2.9478623566214806, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5091885', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1289, 'n_words': 196}