<commit_before>/**
 * \file dcs/testbed/ycsb/workload_driver.hpp
 *
 * \brief Workload driver based on the YCSB workload toolkit.
 *
 * \author <NAME> (<EMAIL>)
 *
 * <hr/>
 *
 * Copyright (C) 2014       <NAME> (<EMAIL>)
 *
 * This file is part of dcsxx-testbed.
 *
 * dcsxx-testbed is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * dcsxx-testbed is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with dcsxx-testbed. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef DCS_TESTBED_YCSB_WORKLOAD_DRIVER_HPP
#define DCS_TESTBED_YCSB_WORKLOAD_DRIVER_HPP


#include <boost/smart_ptr.hpp>
#include <boost/thread.hpp>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <dcs/debug.hpp>
#include <dcs/exception.hpp>
#include <dcs/logging.hpp>
#include <dcs/system/posix_process.hpp>
#include <dcs/system/process_status_category.hpp>
#include <dcs/testbed/application_performance_category.hpp>
#include <dcs/testbed/base_sensor.hpp>
#include <dcs/testbed/base_workload_driver.hpp>
#include <dcs/testbed/ycsb/sensors.hpp>
#include <dcs/testbed/workload_category.hpp>
#include <dcs/testbed/workload_generator_category.hpp>
#include <exception>
#include <fstream>
#include <istream>
#include <list>
#include <sstream>
#include <string>
#include <vector>


namespace dcs { namespace testbed { namespace ycsb {

namespace detail {

namespace /*<unnamed>*/ {

inline
::std::string make_java_command(::std::string const& java_home)
{
	return java_home + "/bin/java";
}

inline
::std::string make_java_command()
{
	char* java_path = ::std::getenv("JAVA_HOME");
	if (java_path)
	{
		return make_java_command(::std::string(java_path));
	}

	java_path = ::std::getenv("JRE_HOME");
	if (java_path)
	{
		return make_java_command(::std::string(java_path));
	}

	return ::std::string("java");
}

/**
 * \brief Build arguments to pass to YCSB workload toolkit.
 *
 * The basic structure of the YCSB command is:
 * <pre>
 *  ycsb <command> <database> [options]
 * </pre>
 */
template <typename WklIterT, typename ArgIterT>
::std::vector< ::std::string > make_ycsb_args(workload_category wkl_cat,
											  ::std::string const& ycsb_home,
											  bool load_phase,
											  WklIterT first_wkl,
											  WklIterT last_wkl,
											  ArgIterT first_arg,
											  ArgIterT last_arg)
{
	::std::vector< ::std::string > args(first_arg, last_arg);

	::std::string workload;
	::std::string workload_cls;
	switch (wkl_cat)
	{
		case cassandra_workload: //TODO: handle different version of the same workload
			workload = "cassandra";
			workload_cls = "CassandraClient7";
//java -cp build/ycsb.jar:db/cassandra-0.7/lib/* com.yahoo.ycsb.Client -load -s -db com.yahoo.ycsb.db.CassandraClient7 -P workloads/workloada -P settings_load.dat 
			break;
		default:
		{
			::std::ostringstream oss;
			oss << "Workload '" << to_string(wkl_cat) << "' not handled";
			DCS_EXCEPTION_THROW(::std::invalid_argument, oss.str());
		}
	}

	args.push_back("-cp");
	args.push_back(ycsb_home + "/core/target/classes:" + ycsb_home + "/" + workload + "/target/classes");
	args.push_back("com.yahoo.ycsb.Client");
	if (load_phase)
	{
		args.push_back("-load");
	}
	else
	{
		args.push_back("-t");
	}
	args.push_back("-db");
	args.push_back("com.yahoo.ycsb.db." + workload_cls);
	args.push_back("-s");
	while (first_wkl != last_wkl)
	{
		args.push_back("-P");
		args.push_back(*first_wkl);
		++first_wkl;
	}

	return args;
}

template <typename WklIterT>
::std::vector< ::std::string > make_ycsb_args(workload_category wkl_cat,
											  ::std::string const& ycsb_home,<commit_msg>(bug-fix:minor) Fixed java classpath for YCSB<commit_after>/**
 * \file dcs/testbed/ycsb/workload_driver.hpp
 *
 * \brief Workload driver based on the YCSB workload toolkit.
 *
 * \author <NAME> (<EMAIL>)
 *
 * <hr/>
 *
 * Copyright (C) 2014       <NAME> (<EMAIL>)
 *
 * This file is part of dcsxx-testbed.
 *
 * dcsxx-testbed is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * dcsxx-testbed is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with dcsxx-testbed. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef DCS_TESTBED_YCSB_WORKLOAD_DRIVER_HPP
#define DCS_TESTBED_YCSB_WORKLOAD_DRIVER_HPP


#include <boost/smart_ptr.hpp>
#include <boost/thread.hpp>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <dcs/debug.hpp>
#include <dcs/exception.hpp>
#include <dcs/logging.hpp>
#include <dcs/system/posix_process.hpp>
#include <dcs/system/process_status_category.hpp>
#include <dcs/testbed/application_performance_category.hpp>
#include <dcs/testbed/base_sensor.hpp>
#include <dcs/testbed/base_workload_driver.hpp>
#include <dcs/testbed/ycsb/sensors.hpp>
#include <dcs/testbed/workload_category.hpp>
#include <dcs/testbed/workload_generator_category.hpp>
#include <exception>
#include <fstream>
#include <istream>
#include <list>
#include <sstream>
#include <string>
#include <vector>


namespace dcs { namespace testbed { namespace ycsb {

namespace detail {

namespace /*<unnamed>*/ {

inline
::std::string make_java_command(::std::string const& java_home)
{
	return java_home + "/bin/java";
}

inline
::std::string make_java_command()
{
	char* java_path = ::std::getenv("JAVA_HOME");
	if (java_path)
	{
		return make_java_command(::std::string(java_path));
	}

	java_path = ::std::getenv("JRE_HOME");
	if (java_path)
	{
		return make_java_command(::std::string(java_path));
	}

	return ::std::string("java");
}

/**
 * \brief Build arguments to pass to YCSB workload toolkit.
 *
 * The basic structure of the YCSB command is:
 * <pre>
 *  ycsb <command> <database> [options]
 * </pre>
 */
template <typename WklIterT, typename ArgIterT>
::std::vector< ::std::string > make_ycsb_args(workload_category wkl_cat,
											  ::std::string const& ycsb_home,
											  bool load_phase,
											  WklIterT first_wkl,
											  WklIterT last_wkl,
											  ArgIterT first_arg,
											  ArgIterT last_arg)
{
	::std::vector< ::std::string > args(first_arg, last_arg);

	::std::string workload;
	::std::string workload_cls;
	switch (wkl_cat)
	{
		case cassandra_workload: //TODO: handle different version of the same workload
			workload = "cassandra";
			workload_cls = "CassandraClient7";
//java -cp build/ycsb.jar:db/cassandra-0.7/lib/* com.yahoo.ycsb.Client -load -s -db com.yahoo.ycsb.db.CassandraClient7 -P workloads/workloada -P settings_load.dat 
			break;
		default:
		{
			::std::ostringstream oss;
			oss << "Workload '" << to_string(wkl_cat) << "' not handled";
			DCS_EXCEPTION_THROW(::std::invalid_argument, oss.str());
		}
	}

	args.push_back("-cp");
	args.push_back(ycsb_home + "/core/target/core-0.1.4.jar:" + ycsb_home + "/" + workload + "/target/cassandra-binding-0.1.4.jar"); //FIXME: add a parameter for this stuff
	args.push_back("com.yahoo.ycsb.Client");
	if (load_phase)
	{
		args.push_back("-load");
	}
	else
	{
		args.push_back("-t");
	}
	args.push_back("-db");
	args.push_back("com.yahoo.ycsb.db." + workload_cls);
	args.push_back("-s");
	while (first_wkl != last_wkl)
	{
		args.push_back("-P");
		args.push_back(*first_wkl);
		++first_wkl;
	}

	return args;
}

template <typename WklIterT>
::std::vector< ::std::string > make_ycsb_args(workload_category wkl_cat,
											  ::std::string const& ycsb_home,
{'fraction_non_alphanumeric': 0.1407416472891935, 'fraction_numerical': 0.0029372169869049075, 'mean_word_length': 4.268858800773694, 'pattern_counts': {'":': 0, '<': 95, '<?xml version=': 0, '>': 83, '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': '3211660', 'n_tokens_mistral': 3206, 'n_tokens_neox': 2949, 'n_words': 685}