1 #ifndef _DMUCS_HOST_H_ 2 #define _DMUCS_HOST_H_ 1 3 4 /* 5 * dmucs_host.h: the DMUCS host definition. 6 * 7 * Copyright (C) 2005, 2006 Victor T. Norman 8 * 9 * This program is free software; you can redistribute it and/or modify it 10 * under the terms of the GNU General Public License as published by the 11 * Free Software Foundation; either version 2 of the License, or (at your 12 * option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, but 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 17 * Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License along 20 * with this program; if not, write to the Free Software Foundation, Inc., 21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 */ 23 24 #include <sys/types.h> 25 #include <time.h> 26 #include <exception> 27 #include <netinet/in.h> 28 #include <arpa/inet.h> 29 #include <string> 30 #include "dmucs_dprop.h" 31 32 33 enum host_status_t { 34 STATUS_UNKNOWN = 0, 35 STATUS_AVAILABLE = 1, 36 STATUS_UNAVAILABLE, 37 STATUS_OVERLOADED, 38 STATUS_SILENT 39 }; 40 41 class DmucsHostState; 42 43 44 #define DMUCS_HOST_SILENT_TIME 60 /* if we don't hear from a host for 45 60 seconds, we consider it to be 46 silent, and we remove it from the 47 list of available hosts. */ 48 49 class DmucsHost 50 { 51 private: 52 /* dProp_: indicates which kind of host this is. Users can use 53 Dmucs to maintain collections of multiple types of hosts -- e.g., 54 hosts that will only compile solaris binaries vs. those that will only 55 compile linux binaries. Or, hosts that are reserved for certain 56 segments of users vs. hosts that are available to everyone. We call 57 this user-defined distinction a "distinguishing property" or "dprop" 58 of a host. */ 59 DmucsHostState * state_; 60 struct in_addr ipAddr_; 61 DmucsDprop dprop_; 62 std::string resolvedName_; 63 int ncpus_; 64 int pindex_; 65 float ldavg1_, ldavg5_, ldavg10_; 66 time_t lastUpdate_; 67 68 friend class DmucsHostState; 69 void changeState(DmucsHostState *state); 70 71 public: 72 DmucsHost(const struct in_addr &ipAddr, DmucsDprop dprop, 73 const int numCpus, const int powerIndex); 74 75 void updateTier(float ldAvg1, float ldAvg5, float ldAvg10); 76 77 void avail(); 78 void unavail(); 79 void silent(); 80 void overloaded(); 81 82 static DmucsHost *createHost(const struct in_addr &ipAddr, 83 const DmucsDprop dprop, 84 const std::string &hostsInfoFile); 85 86 const int getStateAsInt() const; 87 int getTier() const; 88 int calcTier(float ldavg1, float ldavg5, float ldavg10, int pindex) const; 89 const std::string &getName(); getDprop()90 const DmucsDprop getDprop() const { return dprop_; } 91 getIpAddrInt()92 unsigned int getIpAddrInt() const { return ipAddr_.s_addr; } getNumCpus()93 int getNumCpus() const { return ncpus_; } 94 bool seemsDown() const; 95 bool isUnavailable() const; 96 bool isSilent() const; 97 bool isOverloaded() const; 98 99 static std::string resolveIp2Name(unsigned int ipAddr, DmucsDprop dprop); 100 static const std::string &getName(std::string &resolvedName, 101 const struct in_addr &ipAddr); 102 103 void dump(); 104 }; 105 106 107 108 class DmucsNoMoreHosts : public std::exception 109 { 110 // TODO 111 }; 112 113 class DmucsHostNotFound : public std::exception 114 { 115 // TODO 116 }; 117 118 119 #endif 120