<commit_before># Used for configuring zuun to manage mongo installation
import sys
import chef
import base64


MONGO_DATA_CONF = """net:
  bindIp: 0.0.0.0
  http:
    RESTInterfaceEnabled: true
    enabled: true
  port: 27018
operationProfiling: {{}}
processManagement:
  fork: "true"
  pidFilePath: /var/run/mongodb/mongodb.pid
{parameters}
{replication}
storage:
  dbPath: /volr/
  engine: wiredTiger
  systemLog:
    destination: file
    logAppend: true
    path: /mongologs/mongodb.log"""


MONGO_CFG_CONF = """net:
  bindIp: 0.0.0.0
  http:
    RESTInterfaceEnabled: true
    enabled: true
  port: 27019
operationProfiling: {}
processManagement:
  fork: "true"
  pidFilePath: /var/run/mongodb/mongodb.pid
{sharding}
{parameters}
{replication}
storage:
  dbPath: /volr
  engine: wiredTiger
systemLog:
  destination: file
  logAppend: true
  path: /mongologs/mongodb.log"""


MONGO_ROUTER_CONF = """net:
  bindIp: 0.0.0.0
  port: 27017
operationProfiling: {}
processManagement:
  fork: "true"
  pidFilePath: /var/run/mongodb/mongodb.pid
{sharding}
{parameters}
systemLog:
  destination: file
  logAppend: true
  path: /mongologs/mongodb.log"""


def generate_mongo_conf(node):
    replication = ''
    try:
        if node.expanded_replica_set:
            replication = 'replication:\n  replSetName: {}'.format(node.expanded_replica_set)
    except AttributeError:
        pass

    parameters = []

    if node.CHEF_MONGODB_TYPE == 'config' and node.environment != 'prod':
        parameters.append('recoverShardingState: false')

    parameters = 'setParameter:{params}'.format(params='\n  '.join(parameters)) if parameters else ''
    

    sharding = []

    if node.CHEF_MONGODB_TYPE == 'config':
        sharding.append('clusterRole: configsvr')
    elif node.CHEF_MONGODB_TYPE == 'router':
        sharding.append('configDB: {configDB}'.format(configDB=node.mongodb_configDB))      
    
    sharding = 'sharding:{params}'.format(params='\n  '.join(sharding)) if sharding else ''
    
    template = None

    template = {'data': MONGO_DATA_CONF,
                'conf': MONGO_CFG_CONF,
                'router': MONGO_ROUTER_CONF}[node.CHEF_MONGODB_TYPE]

    return template.format(replication=replication, sharding=sharding, parameters=parameters)


def update_data_bag_item(node):
    data_bag_item_name = 'deployment_{}'.format(
        node.CHEF_ATTRIBUTES['zuun']['deployment'])
    data_bag_item_node_data = {
        'version': node.mongodb_version,
        'conf': base64.b64encode(generate_mongo_conf(node))
    }<commit_msg>Fixed a couple typos in the MongoDB confs<commit_after># Used for configuring zuun to manage mongo installation
import sys
import chef
import base64


MONGO_DATA_CONF = """net:
  bindIp: 0.0.0.0
  http:
    RESTInterfaceEnabled: true
    enabled: true
  port: 27018
operationProfiling: {{}}
processManagement:
  fork: "true"
  pidFilePath: /var/run/mongodb/mongodb.pid
{parameters}
{replication}
storage:
  dbPath: /volr/
  engine: wiredTiger
systemLog:
  destination: file
  logAppend: true
  path: /mongologs/mongodb.log"""


MONGO_CFG_CONF = """net:
  bindIp: 0.0.0.0
  http:
    RESTInterfaceEnabled: true
    enabled: true
  port: 27019
operationProfiling: {{}}
processManagement:
  fork: "true"
  pidFilePath: /var/run/mongodb/mongodb.pid
{sharding}
{parameters}
{replication}
storage:
  dbPath: /volr
  engine: wiredTiger
systemLog:
  destination: file
  logAppend: true
  path: /mongologs/mongodb.log"""


MONGO_ROUTER_CONF = """net:
  bindIp: 0.0.0.0
  port: 27017
operationProfiling: {{}}
processManagement:
  fork: "true"
  pidFilePath: /var/run/mongodb/mongodb.pid
{sharding}
{parameters}
systemLog:
  destination: file
  logAppend: true
  path: /mongologs/mongodb.log"""


def generate_mongo_conf(node):
    replication = ''
    try:
        if node.expanded_replica_set:
            replication = 'replication:\n  replSetName: {}'.format(node.expanded_replica_set)
    except AttributeError:
        pass

    parameters = []

    if node.CHEF_MONGODB_TYPE == 'config' and node.environment != 'prod':
        parameters.append('recoverShardingState: false')

    parameters = 'setParameter:{params}'.format(params='\n  '.join(parameters)) if parameters else ''
    

    sharding = []

    if node.CHEF_MONGODB_TYPE == 'config':
        sharding.append('clusterRole: configsvr')
    elif node.CHEF_MONGODB_TYPE == 'router':
        sharding.append('configDB: {configDB}'.format(configDB=node.mongodb_configDB))      
    
    sharding = 'sharding:{params}'.format(params='\n  '.join(sharding)) if sharding else ''
    
    template = None

    template = {'data': MONGO_DATA_CONF,
                'config': MONGO_CFG_CONF,
                'router': MONGO_ROUTER_CONF}[node.CHEF_MONGODB_TYPE]

    return template.format(replication=replication, sharding=sharding, parameters=parameters)


def update_data_bag_item(node):
    data_bag_item_name = 'deployment_{}'.format(
        node.CHEF_ATTRIBUTES['zuun']['deployment'])
    data_bag_item_node_data = {
        'version': node.mongodb_version,
        'conf': base64.b64encode(generate_mongo_conf(node))
    }
{'fraction_non_alphanumeric': 0.1210464662241312, 'fraction_numerical': 0.012885591565794611, 'mean_word_length': 3.7, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, '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': '782980', 'n_tokens_mistral': 1849, 'n_tokens_neox': 1732, 'n_words': 341}