Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Cline.cpp 9.85 KB
Newer Older
GUYOT DOMINIQUE's avatar
GUYOT DOMINIQUE committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
/*

Copyright or © or Copr. Dominique GUYOT 2016

dominique.guyot@univ-lyon1.fr

This software is a computer program whose purpose is to make load balancing
for very large data parallel computing.

This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software.  You can  use, 
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info". 

As a counterpart to the access to the source code and  rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty  and the software's author,  the holder of the
economic rights,  and the successive licensors  have only  limited
liability. 

In this respect, the user's attention is drawn to the risks associated
with loading,  using,  modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean  that it is complicated to manipulate,  and  that  also
therefore means  that it is reserved for developers  and  experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or 
data to be ensured and,  more generally, to use and operate it in the 
same conditions as regards security. 

The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.

*/




#include "Cline.hpp"
#include <getopt.h>
#include <iostream>
#include <fstream>

using namespace::std;

Cline::Cline(int argc,char **argv)
{
	int c;
	int option_index = 0;
 	struct option opt[21] =
    	{
		{"input", 1, 0, (int)('i')},
		{"output", 1, 0, (int)('o')},
		{"conf", 1, 0, (int)('C')},
		{"host", 1, 0, (int)('h')},
		{"port", 1, 0, (int)('p')},
		{"log", 1, 0, (int)('l')},
		{"shm", 1, 0, (int)('S')},
		{"server", 0, 0, (int)('s')},
		{"client", 0, 0, (int)('c')},
		{"watch", 0, 0, (int)('w')},
		{"verbose", 0, 0, (int)('v')},
		{"help", 0, 0, (int)('?')},
		{"version", 0, 0, (int)('V')},
		{"ping", 0, 0, (int)('P')},
		{"info", 0, 0, (int)('I')},
		{"bg", 0, 0, (int)('b')},
		{"report", 1, 0, (int)('r')},
		{"fails", 1, 0, (int)('f')},
		{"tool", 1, 0, (int)('t')},
		{"outsort", 1, 0, (int)('O')},
		{0, 0, 0, 0},
	};

	input = "";
	output = "";
	conf = "paraload.conf";
	log = "";
	host = "localhost";
	port = "";
	server = "no";
	client = "no";
	watch = "no";
	verbose = "no";
	shm = "/dev/shm";
	help = "no";
	version = "no";
	ping = "no";
	info = "no";
	bg = "no";
	report = "";
	fails = "-1";
	voidstring = "";
	tool = "";
	outsort = "";


	while( (c = getopt_long(argc,argv,"i:o:C:h:p:l:S:scwv?VPIbr:f:t:O:",opt,&option_index)) != -1)
    	{
		switch(c)
		{
			case 'i':
				input = optarg;
				break;
			case 'o':
				output = optarg;
				break;
			case 'C':
				conf = optarg;
				break;
			case 'h':
				host = optarg;
				break;
			case 'p':
				port = optarg;
				break;
			case 'l':
				log = optarg;
				break;
			case 'S':
				shm = optarg;
				break;
			case 's':
				server = "yes";
				break;
			case 'c':
				client = "yes";
				break;
			case 'w':
				watch = "yes";
				break;
			case 'v':
				verbose = "yes";
				break;
			case '?' :
				help = "yes";
				break;
			case 'V' :
				version = "yes";
				break;
			case 'P' :
				ping = "yes";
				break;
			case 'I' :
				info = "yes";
				break;
			case 'b' :
				bg = "yes";
				break;
			case 'r' :
				report = optarg;
				break;
			case 'f' :
				fails = optarg;
				break;
			case 't' :
				tool = optarg;
				break;
			case 'O' :
				outsort = optarg;
				break;
		}
	}
}


const string& Cline::getcmd(string what)
{
	if (what == "input")
	return input;
	else if (what == "output")
	return output;
	else if (what == "conf")
	return conf;
	else if (what == "host")
	return host;
	else if (what == "port")
	return port;
	else if (what == "log")
	return log;
	else if (what == "shm")
	return shm;
	else if (what == "server")
	return server;
	else if (what == "client")
	return client;
	else if (what == "watch")
	return watch;
	else if (what == "verbose")
	return verbose;
	else if (what == "help")
	return help;
	else if (what == "version")
	return version;
	else if (what == "ping")
	return ping;
	else if (what == "info")
	return info;
	else if (what == "bg")
	return bg;
	else if (what == "report")
	return report;
	else if (what == "fails")
	return fails;
	else if (what == "tool")
	return tool;
	else if (what == "outsort")
	return outsort;
	else
	return voidstring;
}

int Cline::check()
{
	int port_number;
	ifstream config;
	ifstream in;
	ifstream ou;
	ifstream lo;
	
	
	if (help == "yes")
	{
		help_func();
		return(1);
	}
	if (version == "yes")
	{
		version_func();
		return(1);
	}
	
	if ((client == "yes") && (server == "yes"))
	{
		cerr << "Make a choice: run a server with [--server] [-s] or a client with [--client] [-c]" << endl;
		cerr << "More help with --help or -?" << endl;
		return(1);
	}
	if ((client == "no") && (server == "no") && (tool == ""))
	{
		cerr << "Make a choice: run a server with [--server] [-s] or a client with [--client] [-c]" << endl;
		cerr << "More help with --help or -?" << endl;
		return(1);
	}
	if (server == "yes")
	{
		if (port == "")
		{
			cerr << "Please specify	a port [--port] [-p]" << endl;
			return(1);
		}
		if (input == "")
		{
			cerr << "Please specify an input [--input] [-i]" << endl;
			return(1);
		}
		in.open(input.c_str());
		if (in.fail())
		{
			cerr << "Unable to find or read input file [--input] [-i]" << endl;
			return(1);
		}
		if (output == "")
		{
			cerr << "Please specify an output [--output] [-o]" << endl;
			return(1);
		}
		if (log == "")
		{
			cerr << "Please specify a log [--log] [-l]" << endl;
			return(1);
		}
		config.open(conf.c_str());
		if (config.fail())
		{
			cerr << "Unable to find or read configuration file [--conf] [-C] default : paraload.conf" << conf << endl;
			return(1);
		}
		port_number = stoi(port);
		if (port_number > 65535)
		{
			cerr << "Port number must be smaller than 65535" << endl;
			return(1);
		}
		if (port_number < 10000)
		{
			cerr << "Port number must be greater than 10000" << endl;
			return(1);
		}
		
	}
	if (client == "yes")
	{
		if (port == "")
		{
			cerr << "Please specify	a port [--port] [-p]" << endl;
			return(1);
		}
	}
	if (tool == "check")
	{
		if (input == "")
		{
			cerr << "Please specify an input [--input] [-i]" << endl;
			return(1);
		}
		in.open(input.c_str());
		if (in.fail())
		{
			cerr << "Unable to find or read input file [--input] [-i]" << endl;
			return(1);
		}
		if (log == "")
		{
			cerr << "Please specify a log [--log] [-l]" << endl;
			return(1);
		}
		lo.open(log.c_str());
		if (lo.fail())
		{
			cerr << "Unable to find or read log file [--log] [-l]" << endl;
			return(1);
		}
		config.open(conf.c_str());
		if (config.fail())
		{
			cerr << "Unable to find or read configuration file [--conf] [-C] default : paraload.conf" << conf << endl;
			return(1);
		}
	}
	if (tool == "time")
	{
		if (log == "")
		{
			cerr << "Please specify a log [--log] [-l]" << endl;
			return(1);
		}
		lo.open(log.c_str());
		if (lo.fail())
		{
			cerr << "Unable to find or read log file [--log] [-l]" << endl;
			return(1);
		}
	}
	if (tool == "reorder")
	{
		if (log == "")
		{
			cerr << "Please specify a log [--log] [-l]" << endl;
			return(1);
		}
		lo.open(log.c_str());
		if (lo.fail())
		{
			cerr << "Unable to find or read log file [--log] [-l]" << endl;
			return(1);
		}
		if (output ==  "")
		{
			cerr << "Please specify an output [--out] [-o]" << endl;
		}
		ou.open(output.c_str());
		if (ou.fail())
		{
			cerr << "Unable to find or read output file [--output] [-o]" << endl;
			return(1);
		}
	}
	if (tool == "clients")
	{
		if (log == "")
		{
			cerr << "Please specify a log [--log] [-l]" << endl;
			return(1);
		}
		lo.open(log.c_str());
		if (lo.fail())
		{
			cerr << "Unable to find or read log file [--log] [-l]" << endl;
			return(1);
		}
	}
	return(0);
}


void Cline::help_func()
{
	cout << "Run a server: line between {} are optional" << endl;
	cout << "paraload --server(-s) --port(-p) [10000-65535] --input(-i) [input_file] --output(-o) [output_file] --log(-l) [log_file] { --bg(-b) (background) --report(-r) [report_file] } {--conf(-C) [conf_file default:paraload.conf] }" << endl << endl;
	cout << "Run a client:" << endl;
	cout << "paraload --client(-c) --port(-p) [ same as the server ] --host(-h) [ host of the server default:localhost ] --fails(-f) [ max number of command fail allowed default:-1 (infinity)] --shm(-S) [folder for temporary files default:/dev/shm/]" << endl << endl;
	cout << "Check if the server is responding:" << endl;
	cout << "paraload --client(-c) --port(-p) [ same as the server ] --ping(-P)" << endl << endl;
	cout << "Get informations about running clients:" << endl;
	cout << "paraload --client(-c) --port(-p) [ same as the server ] --info(-I)" << endl << endl;
	cout << "Check integrity after a run:" << endl;
	cout << "paraload --tool(-t) check --input(-i) [input_file] --log(-l) [log_file] {--conf(-C) [conf_file default:paraload.conf] }" << endl << endl;
	cout << "Reorder output with the same order as the input:" << endl;
	cout << "paraload --tool(-t) reorder --output(-o) [output_file] --outsort(-O) [output_file sorted]" << endl << endl;
	cout << "Get cumulated time of run (even if the run is not completed):" << endl;
	cout << "paraload --tool(-t) time --log(-l) [log_file]" << endl << endl;
	cout << "Get informations about terminated computations on clients (even if the run is not completed):" << endl;
	cout << "paraload --tool(-t) clients --log(-l) [log_file]" << endl << endl;
	cout << "Print this:" << endl;
	cout << "paraload --help(-?)" << endl << endl;
}



void Cline::version_func()
{
	cout << "\nVersion : " << VERSION << endl;
	cout << "Compiled by " << USER_LOGIN << endl;
	cout << "with " << GCC_VERSION << endl << endl;
}