File: dmucs_host.h

package info (click to toggle)
dmucs 0.6.1-3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 3,220 kB
  • sloc: ansic: 5,053; sh: 3,557; cpp: 2,472; makefile: 63; perl: 26
file content (119 lines) | stat: -rw-r--r-- 3,368 bytes parent folder | download | duplicates (3)
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
#ifndef _DMUCS_HOST_H_
#define _DMUCS_HOST_H_ 1

/*
 * dmucs_host.h: the DMUCS host definition.
 *
 * Copyright (C) 2005, 2006  Victor T. Norman
 *
 * This program 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 2 of the License, or (at your
 * option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include <sys/types.h>
#include <time.h>
#include <exception>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string>
#include "dmucs_dprop.h"


enum host_status_t {
    STATUS_UNKNOWN = 0,
    STATUS_AVAILABLE = 1,
    STATUS_UNAVAILABLE,
    STATUS_OVERLOADED,
    STATUS_SILENT
};

class DmucsHostState;


#define DMUCS_HOST_SILENT_TIME	60	/* if we don't hear from a host for
					   60 seconds, we consider it to be
					   silent, and we remove it from the
					   list of available hosts. */

class DmucsHost
{
private:
    /* dProp_: indicates which kind of host this is.  Users can use
       Dmucs to maintain collections of multiple types of hosts -- e.g.,
       hosts that will only compile solaris binaries vs. those that will only
       compile linux binaries.  Or, hosts that are reserved for certain
       segments of users vs. hosts that are available to everyone.  We call
       this user-defined distinction a "distinguishing property" or "dprop"
       of a host. */
    DmucsHostState *	state_;
    struct in_addr 	ipAddr_;
    DmucsDprop		dprop_;
    std::string		resolvedName_;
    int 		ncpus_;
    int			pindex_;
    float		ldavg1_, ldavg5_, ldavg10_;
    time_t		lastUpdate_;

    friend class DmucsHostState;
    void changeState(DmucsHostState *state);

public:
    DmucsHost(const struct in_addr &ipAddr, DmucsDprop dprop,
	      const int numCpus, const int powerIndex);

    void updateTier(float ldAvg1, float ldAvg5, float ldAvg10);

    void avail();
    void unavail();
    void silent();
    void overloaded();

    static DmucsHost *createHost(const struct in_addr &ipAddr,
				  const DmucsDprop dprop,
				  const std::string &hostsInfoFile);

    const int getStateAsInt() const;
    int getTier() const;
    int calcTier(float ldavg1, float ldavg5, float ldavg10, int pindex) const;
    const std::string &getName();
    const DmucsDprop getDprop() const { return dprop_; }

    unsigned int getIpAddrInt() const { return ipAddr_.s_addr; }
    int getNumCpus() const { return ncpus_; }
    bool seemsDown() const;
    bool isUnavailable() const;
    bool isSilent() const;
    bool isOverloaded() const;

    static std::string resolveIp2Name(unsigned int ipAddr, DmucsDprop dprop);
    static const std::string &getName(std::string &resolvedName,
				      const struct in_addr &ipAddr);

    void dump();
};



class DmucsNoMoreHosts : public std::exception
{
    // TODO
};

class DmucsHostNotFound : public std::exception
{
    // TODO
};


#endif