source: ThirdParty/JobMarket/src/JobMarket/server_main.cpp@ ab2e834

Candidate_v1.7.0 stable
Last change on this file since ab2e834 was ab2e834, checked in by Frederik Heber <frederik.heber@…>, 3 months ago

Reduces JobMarket features for use in kubernetes clusters.

  • removes all functionality where we can enumerate the workers, enroll or remove them.
  • removes PoolGuard and CheckAlive functionality.
  • removes the shutdown thread: not needed as we don't wait for busy workers anymore.
  • removes WorkerPool. This is now handled by the kubernetes deployment.
  • TESTS: Removed respective unit and regression tests.
  • TESTS: Adapted regression tests as worker now needs to be present when first job is sent. Moreover, server needs to be equipped with worker host and port.
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Project: JobMarket
3 * Description: asynchronous Server/Controller/Client-approach to parallel computing, based on boost::asio
4 * Copyright (C) 2011-2012 Frederik Heber. All rights reserved.
5 *
6 */
7
8/*
9 * \file server_main.cpp
10 *
11 * This file strongly follows the Serialization example from the boost::asio
12 * library (see server.cpp)
13 *
14 * Created on: Oct 21, 2011
15 * Author: heber
16 */
17
18// include config.h
19#ifdef HAVE_CONFIG_H
20#include <config.h>
21#endif
22
23// boost asio needs specific operator new
24#include <boost/asio.hpp>
25// program_options must have some strange static stuff, causes double free or
26// corruption if included after MemDebug
27#include <boost/program_options.hpp>
28
29//#include "CodePatterns/MemDebug.hpp"
30
31#include <cstdlib>
32#include <iostream>
33#include <vector>
34
35#include "CodePatterns/Info.hpp"
36#include "CodePatterns/Log.hpp"
37#include "JobMarket/atexit.hpp"
38#include "JobMarket/FragmentScheduler.hpp"
39#include "JobMarket/Jobs/SystemCommandJob.hpp"
40#include "JobMarket/ServerOptions.hpp"
41#include "JobMarket/SignalHandler.hpp"
42
43int server_main(int argc, char* argv[])
44{
45 // from this moment on, we need to be sure to deinitialize in the correct order
46 // this is handled by the cleanup function
47 atexit(cleanUp);
48
49 ServerOptions ServerOpts;
50
51 // Declare the supported options.
52 boost::program_options::options_description desc("Allowed options");
53 desc.add_options()
54 ("help,h", "produce help message")
55 ("verbosity,v", boost::program_options::value<size_t>(), "set verbosity level")
56 ("signal", boost::program_options::value< std::vector<size_t> >(), "set signal to catch (can be given multiple times)")
57 ("workeraddress", boost::program_options::value< std::string>(), "connect to all workers at this address (host:port)")
58 ("workerport", boost::program_options::value< unsigned short >(), "listen on this port for connecting workers")
59 ("controllerport", boost::program_options::value< unsigned short >(), "listen on this port for connecting controller")
60 ("timeout", boost::program_options::value< size_t >(), "timeout in seconds for alive status of workers")
61 ;
62
63 boost::program_options::variables_map vm;
64 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
65 boost::program_options::notify(vm);
66
67 int status = 0;
68 status = ServerOpts.parseHelp(vm, desc);
69 if (status) return status;
70 status = ServerOpts.parseVerbosity(vm);
71 if (status) return status;
72 status = ServerOpts.parseWorkerPort(vm);
73 if (status) return status;
74 status = ServerOpts.parseControllerPort(vm);
75 if (status) return status;
76 status = ServerOpts.parseTimeout(vm);
77 if (status) return status;
78 status = ServerOpts.parseSignals(vm);
79 if (status) return status;
80 status = ServerOpts.parseWorkerAddress(vm);
81 if (status) return status;
82
83 size_t Exitflag = 0;
84 try
85 {
86 boost::asio::io_service io_service;
87 FragmentScheduler Server(
88 io_service,
89 ServerOpts.workerport,
90 ServerOpts.controllerport,
91 WorkerAddress(ServerOpts.workeraddresshost, ServerOpts.workeraddressport),
92 ServerOpts.timeout);
93
94 // catch ctrl-c and shutdown worker properly
95 boost::function<void (int)> shutdownfunction = boost::bind(&FragmentScheduler::shutdown, boost::ref(Server), _1);
96 SignalHandler signalhandler(shutdownfunction, ServerOpts.signals);
97
98 {
99 Info info("io_service");
100 io_service.run();
101 }
102 Exitflag = Server.getExitflag();
103 }
104 catch (std::exception& e)
105 {
106 std::cerr << e.what() << std::endl;
107 }
108
109 return Exitflag;
110}
Note: See TracBrowser for help on using the repository browser.