<commit_before>#
# Cookbook Name:: mongodb
# Definition:: mongodb
#
# Copyright 2011, edelight GmbH
# Authors:
#       <NAME> <<EMAIL>>
#
# 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.
#

define :mongodb_instance,
    :mongodb_type  => "mongod",
    :action        => [:enable, :start],
    :logpath       => "/var/log/mongodb",
    :dbpath        => "/data",
    :configserver  => [],
    :replicaset    => nil,
    :notifies      => [] do

  if !["mongod", "shard", "configserver", "mongos"].include?(params[:mongodb_type])
    raise ArgumentError, ":mongodb_type must be 'mongod', 'shard', 'configserver' or 'mongos'; was #{params[:mongodb_type].inspect}"
  end

  require 'ostruct'

  new_resource = OpenStruct.new

  new_resource.name                       = params[:name]
  new_resource.configserver_nodes         = params[:configserver]
  new_resource.dbpath                     = params[:dbpath]
  new_resource.logpath                    = params[:logpath]
  new_resource.replicaset                 = params[:replicaset]
  new_resource.service_action             = params[:action]
  new_resource.service_notifies           = params[:notifies]
  new_resource.type                       = params[:mongodb_type]

  # TODO(jh): parameterize so we can make a resource provider
  new_resource.auto_configure_replicaset  = node['mongodb']['auto_configure']['replicaset']
  new_resource.auto_configure_sharding    = node['mongodb']['auto_configure']['sharding']
  new_resource.bind_ip                    = node['mongodb']['config']['bind_ip']
  new_resource.cluster_name               = node['mongodb']['cluster_name']
  new_resource.config                     = node['mongodb']['config']
  new_resource.dbconfig_file              = node['mongodb']['dbconfig_file']
  new_resource.dbconfig_file_template     = node['mongodb']['dbconfig_file_template']
  new_resource.init_dir                   = node['mongodb']['init_dir']
  new_resource.init_script_template       = node['mongodb']['init_script_template']
  new_resource.is_replicaset              = node['mongodb']['is_replicaset']
  new_resource.is_shard                   = node['mongodb']['is_shard']
  new_resource.mongodb_group              = node['mongodb']['group']
  new_resource.mongodb_user               = node['mongodb']['user']
  new_resource.replicaset_name            = node['mongodb']['replicaset_name']
  new_resource.port                       = node['mongodb']['config']['port']
  new_resource.root_group                 = node['mongodb']['root_group']
  new_resource.shard_name                 = node['mongodb']['shard_name']
  new_resource.sharded_collections        = node['mongodb']['sharded_collections']
  new_resource.sysconfig_file             = node['mongodb']['sysconfig_file']
  new_resource.sysconfig_file_template    = node['mongodb']['sysconfig_file_template']
  new_resource.sysconfig_vars             = node['mongodb']['sysconfig']
  new_resource.template_cookbook          = node['mongodb']['template_cookbook']
  new_resource.ulimit                     = node['mongodb']['ulimit']

  KNOWN_RELOAD_ACTIONS = %w(restart nothing)
  if KNOWN_RELOAD_ACTIONS.include?(action = node['mongodb']['reload_action'].to_s)
    new_resource.reload_action = action
  else
    Chef::Log.info "Unknown mongodb.reload_action #{action}, should be 'restart' or 'nothing'. Defaulting to 'nothing'"
    new_resource.reload_action = 'nothing'
  end

  if node['mongodb']['apt_repo'] == "ubuntu-upstart"
    new_resource.init_file = File.join(node['mongodb']['init_dir'], "#{new_resource.name}.conf")
    mode = "0644"
  else
    new_resource.init_file = File.join(node['mongodb']['init_dir'], new_resource.name)
    mode = "0755"
  end

  # TODO(jh): reimplement using polymorphism
  if new_resource.is_replicaset
    if new_resource.replicaset_name
      # trust a predefined replicaset name
      replicaset_name = new_resource.replicaset_name
    elsif new_resource.is_shard && new_resource.shard_name
      # for replicated shards we autogenerate
      # the replicaset name for each shard
      replicaset_name = "rs_#{new_resource.shard_name}"
    else
      # Well shoot, we don't have a predefined name and we aren't
      # really sharded. If we want backwards compatibity, this should be:
      #   replicaset_name = "rs_#{new_resource.shard_name}"
      # which with default values defaults to:
      #   replicaset_name = 'rs_default'
      # But using a non-default shard name when we're creating a default
      # replicaset name seems surprising to me and needlessly arbitrary.
      # So let's use the *default* default in this case:
      replicaset_name = 'rs_default'
    end<commit_msg>allow the user to set it to whatever<commit_after>#
# Cookbook Name:: mongodb
# Definition:: mongodb
#
# Copyright 2011, edelight GmbH
# Authors:
#       <NAME> <<EMAIL>>
#
# 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.
#

define :mongodb_instance,
    :mongodb_type  => "mongod",
    :action        => [:enable, :start],
    :logpath       => "/var/log/mongodb",
    :dbpath        => "/data",
    :configserver  => [],
    :replicaset    => nil,
    :notifies      => [] do

  if !["mongod", "shard", "configserver", "mongos"].include?(params[:mongodb_type])
    raise ArgumentError, ":mongodb_type must be 'mongod', 'shard', 'configserver' or 'mongos'; was #{params[:mongodb_type].inspect}"
  end

  require 'ostruct'

  new_resource = OpenStruct.new

  new_resource.name                       = params[:name]
  new_resource.configserver_nodes         = params[:configserver]
  new_resource.dbpath                     = params[:dbpath]
  new_resource.logpath                    = params[:logpath]
  new_resource.replicaset                 = params[:replicaset]
  new_resource.service_action             = params[:action]
  new_resource.service_notifies           = params[:notifies]
  new_resource.type                       = params[:mongodb_type]

  # TODO(jh): parameterize so we can make a resource provider
  new_resource.auto_configure_replicaset  = node['mongodb']['auto_configure']['replicaset']
  new_resource.auto_configure_sharding    = node['mongodb']['auto_configure']['sharding']
  new_resource.bind_ip                    = node['mongodb']['config']['bind_ip']
  new_resource.cluster_name               = node['mongodb']['cluster_name']
  new_resource.config                     = node['mongodb']['config']
  new_resource.dbconfig_file              = node['mongodb']['dbconfig_file']
  new_resource.dbconfig_file_template     = node['mongodb']['dbconfig_file_template']
  new_resource.init_dir                   = node['mongodb']['init_dir']
  new_resource.init_script_template       = node['mongodb']['init_script_template']
  new_resource.is_replicaset              = node['mongodb']['is_replicaset']
  new_resource.is_shard                   = node['mongodb']['is_shard']
  new_resource.mongodb_group              = node['mongodb']['group']
  new_resource.mongodb_user               = node['mongodb']['user']
  new_resource.replicaset_name            = node['mongodb']['replicaset_name']
  new_resource.port                       = node['mongodb']['config']['port']
  new_resource.root_group                 = node['mongodb']['root_group']
  new_resource.shard_name                 = node['mongodb']['shard_name']
  new_resource.sharded_collections        = node['mongodb']['sharded_collections']
  new_resource.sysconfig_file             = node['mongodb']['sysconfig_file']
  new_resource.sysconfig_file_template    = node['mongodb']['sysconfig_file_template']
  new_resource.sysconfig_vars             = node['mongodb']['sysconfig']
  new_resource.template_cookbook          = node['mongodb']['template_cookbook']
  new_resource.ulimit                     = node['mongodb']['ulimit']
  new_resource.reload_action              = node['mongodb']['reload_action']

  if node['mongodb']['apt_repo'] == "ubuntu-upstart"
    new_resource.init_file = File.join(node['mongodb']['init_dir'], "#{new_resource.name}.conf")
    mode = "0644"
  else
    new_resource.init_file = File.join(node['mongodb']['init_dir'], new_resource.name)
    mode = "0755"
  end

  # TODO(jh): reimplement using polymorphism
  if new_resource.is_replicaset
    if new_resource.replicaset_name
      # trust a predefined replicaset name
      replicaset_name = new_resource.replicaset_name
    elsif new_resource.is_shard && new_resource.shard_name
      # for replicated shards we autogenerate
      # the replicaset name for each shard
      replicaset_name = "rs_#{new_resource.shard_name}"
    else
      # Well shoot, we don't have a predefined name and we aren't
      # really sharded. If we want backwards compatibity, this should be:
      #   replicaset_name = "rs_#{new_resource.shard_name}"
      # which with default values defaults to:
      #   replicaset_name = 'rs_default'
      # But using a non-default shard name when we're creating a default
      # replicaset name seems surprising to me and needlessly arbitrary.
      # So let's use the *default* default in this case:
      replicaset_name = 'rs_default'
    end
{'fraction_non_alphanumeric': 0.11520554730064388, 'fraction_numerical': 0.0031698860822189203, 'mean_word_length': 3.2154488517745303, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2448659', 'n_tokens_mistral': 3081, 'n_tokens_neox': 2916, 'n_words': 652}