<commit_before>########
# Copyright (c) 2015 GigaSpaces Technologies Ltd. All rights reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
#    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    * See the License for the specific language governing permissions and
#    * limitations under the License.

# Built in Imports
import requests
import platform
import tempfile

# Cloudify Imports
from utils import run
from cloudify import ctx
from cloudify import exceptions
from cloudify.decorators import operation
from constants import (
    ELATIC_CO_BASE_URL,
    DEFAULT_DEB_URL,
    DEFAULT_RPM_URL,
    INSTALLED_UBUNTU,
    INSTALLED_CENTOS
)


@operation
def configure(conf, **_):
    """ Configure Logstash """

    if 'template' in conf['type']:
        if not conf.get('path'):
            raise exceptions.NonRecoverableError(
                'logstash property conf.path '
                'cannot be empty if conf.type is "template".')
        static_config = generate_static_config(conf.get('path'))
    elif 'static' in conf['type']:
        if not conf.get('path') and not conf.get('inline'):
            raise exceptions.NonRecoverableError(
                'either logstash property conf.path '
                'or conf.inline are required when conf.type is "static".')
        static_config = conf.get('path')
    else:
        raise exceptions.NonRecoverableError(
            'logstash property conf.type '
            'can only be "template" or "static".')

    upload_static_config(static_config, conf.get('destination_path'))


def generate_static_config(template_conf):

    ctx.logger.info('Generating static conf from temlate')

    raise NotImplemented


def upload_static_config(static_conf, conf_path):
    """ Upload the static config to the service. """

    ctx.logger.info('Copying config to {0}'.format(conf_path))

    try:
        downloaded_file = \
            ctx.download_resource(static_conf, tempfile.mktemp())
    except Exception as e:
        raise exceptions.NonRecoverableError(
            'conf.file was not found on manager. '
            'Error: {0}.'.format(str(e)))

    run('sudo cp {0} {1}'.format(downloaded_file, conf_path))


@operation
def start(command, **_):
    """starts logstash daemon"""

    ctx.logger.debug('Attempting to start log transport service.')

    output = run(command)

    if output.returncode != 0:
        raise exceptions.NonRecoverableError(
            'Unable to start log transport service: {0}'.format(output))<commit_msg>changing not implemented<commit_after>########
# Copyright (c) 2015 GigaSpaces Technologies Ltd. All rights reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
#    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    * See the License for the specific language governing permissions and
#    * limitations under the License.

# Built in Imports
import requests
import platform
import tempfile

# Cloudify Imports
from utils import run
from cloudify import ctx
from cloudify import exceptions
from cloudify.decorators import operation
from constants import (
    ELATIC_CO_BASE_URL,
    DEFAULT_DEB_URL,
    DEFAULT_RPM_URL,
    INSTALLED_UBUNTU,
    INSTALLED_CENTOS
)


@operation
def configure(conf, **_):
    """ Configure Logstash """

    if 'template' in conf['type']:
        if not conf.get('path'):
            raise exceptions.NonRecoverableError(
                'logstash property conf.path '
                'cannot be empty if conf.type is "template".')
        static_config = generate_static_config(conf.get('path'))
    elif 'static' in conf['type']:
        if not conf.get('path') and not conf.get('inline'):
            raise exceptions.NonRecoverableError(
                'either logstash property conf.path '
                'or conf.inline are required when conf.type is "static".')
        static_config = conf.get('path')
    else:
        raise exceptions.NonRecoverableError(
            'logstash property conf.type '
            'can only be "template" or "static".')

    upload_static_config(static_config, conf.get('destination_path'))


def generate_static_config(template_conf):

    ctx.logger.info('Generating static conf from template')

    raise NotImplementedError


def upload_static_config(static_conf, conf_path):
    """ Upload the static config to the service. """

    ctx.logger.info('Copying config to {0}'.format(conf_path))

    try:
        downloaded_file = \
            ctx.download_resource(static_conf, tempfile.mktemp())
    except Exception as e:
        raise exceptions.NonRecoverableError(
            'conf.file was not found on manager. '
            'Error: {0}.'.format(str(e)))

    run('sudo cp {0} {1}'.format(downloaded_file, conf_path))


@operation
def start(command, **_):
    """starts logstash daemon"""

    ctx.logger.debug('Attempting to start log transport service.')

    output = run(command)

    if output.returncode != 0:
        raise exceptions.NonRecoverableError(
            'Unable to start log transport service: {0}'.format(output))
{'fraction_non_alphanumeric': 0.09681351210168901, 'fraction_numerical': 0.004875500609437576, 'mean_word_length': 3.1353491720662348, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4193411', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1576, 'n_words': 525}