示例#1
0
文件: rstat.cpp 项目: ISP-SST/redux
void printPeerList( TcpConnection::Ptr conn, int ns ) {

    uint8_t cmd = CMD_PSTAT;
    boost::asio::write(conn->socket(),boost::asio::buffer(&cmd,1));

    uint64_t blockSize;
    shared_ptr<char> buf = conn->receiveBlock( blockSize );

    if ( !blockSize ) return;

    const char* ptr = buf.get();
    uint64_t count(0);
    try {
        Host peer;
        cout << "    " << peer.printHeader() << endl;
        int hostCount(0);
        while( count < blockSize ) {
            count += peer.unpack(ptr+count,conn->getSwapEndian());
            if ( hostCount == 0 ) cout << "    " << peer.print() << endl;
            else if ( ns==0 || hostCount < ns) cout << alignRight(to_string(hostCount),4) << peer.print() << endl;
            hostCount++;
        }
        if (ns!=0 && hostCount > ns) cout << "   :" << endl << alignRight(to_string(hostCount),4) << peer.print() << endl;
    } catch ( const exception& e) {
        cerr << "printPeerList: Exception caught while parsing block: " << e.what() << endl;
    }
    if( count != blockSize ) {
        cerr << "printPeerList: Parsing of datablock failed, count = " << count << "  blockSize = " << blockSize << "  bytes." << endl;
    }
}
示例#2
0
文件: rstat.cpp 项目: ISP-SST/redux
void printJobList( TcpConnection::Ptr conn, int nj ) {

    uint8_t cmd = CMD_JSTAT;
    boost::asio::write(conn->socket(),boost::asio::buffer(&cmd,1));

    uint64_t blockSize;
    shared_ptr<char> buf = conn->receiveBlock( blockSize );

    if ( !blockSize ) return;

    const char* ptr = buf.get();
    uint64_t count(0);
    try {
        typedef std::shared_ptr<Job::Info> InfoPtr;
        vector<InfoPtr> infos;
        size_t maxLength[2] = {0,0};       // jobName & user
        //cout << Job::Info::printHeader() << endl;
        while( count < blockSize ) {
            InfoPtr info(new Job::Info);
            count += info->unpack(ptr+count,conn->getSwapEndian());
            maxLength[0] = max(maxLength[0],info->name.size());
            maxLength[1] = max(maxLength[1],info->user.size()+info->host.size());
            infos.push_back(info);
        }
        std::sort( infos.begin(), infos.end(), [](const InfoPtr& a, const InfoPtr& b) {
            if(a->step != b->step) return (a->step > b->step);
            if(a->priority != b->priority) return (a->priority > b->priority);
            return (a->id < b->id);
            
        } );
        int nJobs = infos.size();
        bool addComma(false);
        if ( nj != 0 ) {
            if ( nj < nJobs ) addComma = true;
            nJobs = min(nj,nJobs);
        }
        cout << alignRight("#", 4) << alignRight("ID", 5) << alignCenter("type", 10) << alignCenter("started", 20); // + alignCenter("started", 20);
        cout << alignCenter("name", maxLength[0]+4) + alignCenter("user", maxLength[1]+5) + alignCenter("priority", 8) + alignCenter("state", 8);
        cout << endl;
        ptime now = boost::posix_time::second_clock::local_time();
        for( int i=0; i<nJobs; ++i ) {
            if( i == nJobs-1 ) {
                i = infos.size()-1;
                if (addComma) cout << "   :" << endl;
            }
                
            string info = alignRight(std::to_string(infos[i]->id), 5) + alignCenter(infos[i]->typeString, 10);
            string startedString;
            if ( infos[i]->startedTime < now ) startedString = to_iso_extended_string(infos[i]->startedTime);
            else startedString = to_iso_extended_string(infos[i]->submitTime);
            info += alignCenter(startedString, 20);
            info += alignCenter(infos[i]->name, maxLength[0]+4) + alignLeft(infos[i]->user + "@" + infos[i]->host, maxLength[1]+5);
            info += alignCenter(std::to_string(infos[i]->priority), 8);
            info += alignCenter(Job::stateTag(infos[i]->state), 3) + alignLeft(infos[i]->progressString, 15);
            cout << alignRight(to_string(i+1),4) << info << endl;
        }
    } catch ( const exception& e) {
        cerr << "printJobList: Exception caught while parsing block: " << e.what() << endl;
    }
    if( count != blockSize ) {
        cerr << "printJobList: Parsing of datablock failed,  count = " << count << "   blockSize = " << blockSize << "  bytes." << endl;
    }

}