<commit_before>package com.netflix.elasticcar.defaultimpl;

import com.google.inject.Inject;
import com.netflix.elasticcar.configuration.IConfiguration;
import com.netflix.elasticcar.utils.IElasticsearchTuner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;

public class StandardTuner implements IElasticsearchTuner
{
    private static final Logger logger = LoggerFactory.getLogger(StandardTuner.class);
    private static final String CL_BACKUP_PROPS_FILE = "/conf/commitlog_archiving.properties";
    protected final IConfiguration config;

    @Inject
    public StandardTuner(IConfiguration config)
    {
        this.config = config;
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
	public void writeAllProperties(String yamlLocation, String hostname) throws IOException
    {
        DumperOptions options = new DumperOptions();
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
        Yaml yaml = new Yaml(options);
        File yamlFile = new File(yamlLocation);
        Map map = (Map) yaml.load(new FileInputStream(yamlFile));
        map.put("cluster.name", config.getAppName());
        map.put("transport.tcp.port", config.getTransportTcpPort());
        map.put("http.port", config.getHttpPort());       
        map.put("path.data", config.getDataFileLocation());
        map.put("path.logs", config.getLogFileLocation());
        map.put("discovery.type", config.getElasticsearchDiscoveryType());
        map.put("discovery.zen.minimum_master_nodes",config.getMinimumMasterNodes());
        map.put("index.number_of_shards", config.getNumOfShards());
        map.put("index.number_of_replicas", config.getNumOfReplicas());
        map.put("index.refresh_interval", config.getIndexRefreshInterval());
        //NOTE: When using awareness attributes, shards will not be allocated to nodes
        //that do not have values set for those attributes.
        //*** Important in dedicated master nodes deployment
        map.put("cluster.routing.allocation.awareness.attributes", config.getClusterRoutingAttributes());
		if (config.isMultiDC()) 
		{
			map.put("node.name", config.getRac() + "." + config.getInstanceId());
			map.put("node.rack_id", config.getDC());
			map.put("network.publish_host", config.getHostIP());
		}        
		else
        {
			map.put("node.name", config.getRac() + "." + config.getInstanceId());
			map.put("node.rack_id", config.getRac());
        }
		
		//TODO: Create New Tuner for ASG Based Deployment
		if(config.isAsgBasedDedicatedDeployment())
		{
			if(config.getASGName().toLowerCase().contains("master"))<commit_msg>Updating Tuner according to Total Shards per node<commit_after>package com.netflix.elasticcar.defaultimpl;

import com.google.inject.Inject;
import com.netflix.elasticcar.configuration.IConfiguration;
import com.netflix.elasticcar.utils.IElasticsearchTuner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;

public class StandardTuner implements IElasticsearchTuner
{
    private static final Logger logger = LoggerFactory.getLogger(StandardTuner.class);
    private static final String CL_BACKUP_PROPS_FILE = "/conf/commitlog_archiving.properties";
    protected final IConfiguration config;

    @Inject
    public StandardTuner(IConfiguration config)
    {
        this.config = config;
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
	public void writeAllProperties(String yamlLocation, String hostname) throws IOException
    {
        DumperOptions options = new DumperOptions();
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
        Yaml yaml = new Yaml(options);
        File yamlFile = new File(yamlLocation);
        Map map = (Map) yaml.load(new FileInputStream(yamlFile));
        map.put("cluster.name", config.getAppName());
        map.put("transport.tcp.port", config.getTransportTcpPort());
        map.put("http.port", config.getHttpPort());       
        map.put("path.data", config.getDataFileLocation());
        map.put("path.logs", config.getLogFileLocation());
        map.put("discovery.type", config.getElasticsearchDiscoveryType());
        map.put("discovery.zen.minimum_master_nodes",config.getMinimumMasterNodes());
        map.put("index.number_of_shards", config.getNumOfShards());
        map.put("index.number_of_replicas", config.getNumOfReplicas());
        map.put("index.refresh_interval", config.getIndexRefreshInterval());
        //NOTE: When using awareness attributes, shards will not be allocated to nodes
        //that do not have values set for those attributes.
        //*** Important in dedicated master nodes deployment
        map.put("cluster.routing.allocation.awareness.attributes", config.getClusterRoutingAttributes());

        if(config.isShardPerNodeEnabled())
            map.put("index.routing.allocation.total_shards_per_node",config.getTotalShardsPerNode());

		if (config.isMultiDC()) 
		{
			map.put("node.name", config.getRac() + "." + config.getInstanceId());
			map.put("node.rack_id", config.getDC());
			map.put("network.publish_host", config.getHostIP());
		}        
		else
        {
			map.put("node.name", config.getRac() + "." + config.getInstanceId());
			map.put("node.rack_id", config.getRac());
        }
		
		//TODO: Create New Tuner for ASG Based Deployment
		if(config.isAsgBasedDedicatedDeployment())
		{
			if(config.getASGName().toLowerCase().contains("master"))
{'fraction_non_alphanumeric': 0.12510770291228676, 'fraction_numerical': 0.0006892986386351886, 'mean_word_length': 3.9948364888123926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '6816741', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1699, 'n_words': 318}