Host Host::autoRegister() { Host newHost = Host(); newHost.setName(Host::currentHostName()); newHost.setOnline(1); newHost.commit(); newHost.updateHardwareInfo(); Service ab = Service::recordByName("Assburner"); if( ab.isRecord() ) { HostService hs = HostService(); hs.setHost(newHost); hs.setService(ab); hs.commit(); } HostGroup hg = HostGroup::recordByName("All"); if( hg.isRecord() ) { HostGroupItem hgi = HostGroupItem(); hgi.setHost(newHost); hgi.setHostGroup(hg); hgi.commit(); } return newHost; }
QVariant serviceData( int column ) const { HostService hs = hostServiceByColumn( column ); if( hs.isRecord() ) return hs.enabled() ? "Enabled" : "Disabled"; return "No Service"; }
QVariant ServiceItem::modelData( const QModelIndex & i, int role ) { int col = i.column(); if( col == 0 && role == Qt::CheckStateRole ) return toggle ? Qt::Checked : Qt::Unchecked; if( col == 0 && role == Qt::DisplayRole ) return name; if( col == 1 && role == Qt::CheckStateRole ) return (hs.isRecord() && hs.enabled()) ? Qt::Checked : Qt::Unchecked; return QVariant(); }
void ServiceDialog::refresh() { HostServiceList hsl = HostService::recordsByHost( mHost ); QMap<Service,HostService> hsm; foreach( HostService hs, hsl ) hsm[hs.service()]=hs; foreach( Service s, mServices ) { if( !hsm.contains(s) ) { HostService hs; hs.setHost(mHost); hs.setService(s); hsl += hs; } } mServiceModel->setRootList( hsl ); }
Qt::ItemFlags ServiceItem::modelFlags( const QModelIndex & i ) { if( i.column() == 0 ) return Qt::ItemFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled ); if( i.column() == 1 ) { return hs.isRecord() ? Qt::ItemFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled ) : Qt::ItemFlags( Qt::ItemIsUserCheckable ); } return Qt::ItemFlags( Qt::ItemIsEnabled ); }
bool ServiceItem::setModelData( const QModelIndex & i, const QVariant & v, int role ) { int col = i.column(); if( col == 0 && role == Qt::CheckStateRole ) { toggle = v.toBool(); if( toggle ) { hs.setEnabled( true ); hs.commit(); } else hs.remove(); return true; } if( col == 1 && role == Qt::CheckStateRole ) { hs.setEnabled( v.toInt() == Qt::Checked ); hs.commit(); return true; } return false; }
void Slave::startup() { registerBuiltinBurners(); loadEmbeddedPython(); LOG_5( "Slave::startup()" ); mHost = Host::currentHost(); mSpooler = new Spooler( this ); if( !mHost.isRecord() ) { if( mAutoRegister ) { LOG_3( "Slave::startup: no host record, auto-registering" ); mHost = Host::autoRegister(); } else { LOG_3( "Slave::startup: no host record, uh oh!" ); exit(-1); } } else mHost.updateHardwareInfo(); mHostStatus = mHost.hostStatus(); if( !mHostStatus.isRecord() ) { if( mAutoRegister ) { LOG_3( "Slave::startup: No host status record(are all your triggers installed?), creating one" ); mHostStatus.setHost( mHost ); mHostStatus.setOnline( 1 ); } else { LOG_3( "Slave::startup: no host status record, uh oh!" ); exit(-1); } } mHostStatus.setAvailableMemory( mHost.memory() ); mHostStatus.commit(); connect( Database::current()->connection(), SIGNAL( connectionLost() ), SLOT( slotConnectionLost() ) ); connect( Database::current()->connection(), SIGNAL( connected() ), SLOT( slotConnected() ) ); // The rest of the initialization is only for normal mode where we moniter and manipulate // the hosts status. In burn only mode we simply execute a job and exit if( mBurnOnlyJobAssignmentKey ) { burn( JobAssignment(mBurnOnlyJobAssignmentKey) ); return; } mService = Service::ensureServiceExists("Assburner"); // Start remote log server and set port in our Assburner HostService record RemoteLogServer * rls = new RemoteLogServer(); HostService hs = HostService::recordByHostAndService( mHost, mService ); if( hs.isRecord() && rls->tcpServer()->isListening() ) { hs.setRemoteLogPort( rls->tcpServer()->serverPort() ); hs.commit(); } // Set host version string. mHost.setAbVersion( "v" + QString(VERSION)); mHost.commit(); // Reset any frame assignments and set our host status // to ready. Do we need this anymore? The reaper // should now detect and re-assign frames if we are // offline, and this prevents a client-update from // happening when assburner starts. // // Nope, this doesn't f**k with the status, so it is // safe. It just clears fkeyJob to slaveFrames. And // returns any frames that have fkeyHost=this mHostStatus.returnSlaveFrames(); loadForbiddenProcesses(); mTimer = new QTimer( this ); connect( mTimer, SIGNAL( timeout() ), SLOT( loop() ) ); // Default 5000ms, min 200ms, max 600,000ms - 10 minutes mLoopTime = qMax( 200, qMin( 1000 * 60 * 10, Config::getInt( "assburnerLoopTime", 5000 ) ) ); // Default mLoopTime / 2, min 100ms, max mLoopTime mQuickLoopTime = qMax( 100, qMin( mLoopTime, Config::getInt( "assburnerQuickLoopTime", mLoopTime / 2 ) ) ); // Default 60 seconds, min 10 seconds. mPulsePeriod = qMax( 10, Config::getInt( "arsenalPulsePeriod", 600 ) ); // Default 60 seconds, min 10 seconds. mMemCheckPeriod = qMax( 10, Config::getInt( "abMemCheckPeriod", 60 ) ); IniConfig & c = config(); c.pushSection( "BackgroundMode" ); mBackgroundModeEnabled = c.readBool( "Enabled", true ); c.popSection(); // Pulse right away. pulse(); // We need to set our host status to offline when assburner quits connect( qApp, SIGNAL( aboutToQuit() ), SLOT( offlineFromAboutToQuit() ) ); if( mUseGui ) { mIdle = new Idle(); connect( mIdle, SIGNAL( secondsIdle( int ) ), SLOT( slotSecondsIdle( int ) ) ); mIdle->start(); } if( mHostStatus.slaveStatus() == "client-update-offline" ) offline(); else if( mHostStatus.slaveStatus() == "client-update" ) clientUpdate(); else { // Store the current status QString currentStatus = mHostStatus.slaveStatus(); // We run the host through the online method first online(); // Check if the old host status wasn't empty if( !currentStatus.isEmpty() ) { // Resume the state the host was in. LOG_3("Slave::startup() Resuming previous status of " + currentStatus); handleStatusChange(currentStatus, ""); } } // Create a timer for logged in user checks mUserTimer = new QTimer( this ); connect( mUserTimer, SIGNAL( timeout() ), SLOT( updateLoggedUsers() ) ); // Set it to trigger every 5 mins mUserTimer->start(300000); LOG_5( "Slave::startup() done" ); }
void ServiceItem::setup( const Record & r, const QModelIndex & ) { hs = r; name = hs.service().service(); toggle = hs.isRecord(); }