Commit 028f1b13 authored by Manuel Wudka-Robles's avatar Manuel Wudka-Robles
Browse files

Add detailed error messages to kineticstat example

parent 56d40650
Loading
Loading
Loading
Loading
+5 −13
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@

#include "kinetic/kinetic.h"
#include "gflags/gflags.h"
#include "util.h"

using kinetic::DriveLog;
using kinetic::Capacity;
@@ -51,28 +52,19 @@ int example_main(
        char** argv) {
    if (FLAGS_type == "all") {
        unique_ptr<DriveLog> drive_log;
        if(!blocking_connection->GetLog(drive_log).ok()) {
            printf("Unable to get log\n");
            return 1;
        }
        PerformKineticOpOrExit(blocking_connection->GetLog(drive_log));

        dump_all_information(*drive_log);
    } else if (FLAGS_type == "log") {
        unique_ptr<DriveLog> drive_log;
        if(!blocking_connection->GetLog(drive_log).ok()) {
            printf("Unable to get log\n");
            return 1;
        }
        PerformKineticOpOrExit(blocking_connection->GetLog(drive_log));

        printf("%s\n", drive_log->messages.c_str());
    } else {
        int report_number = 0;
        while (true) {
            unique_ptr<DriveLog> drive_log;
            if(!blocking_connection->GetLog(drive_log).ok()) {
                printf("Unable to get log\n");
                return 1;
            }
            PerformKineticOpOrExit(blocking_connection->GetLog(drive_log));

            bool print_headers = report_number % 5 == 0;

src/util.h

0 → 100644
+11 −0
Original line number Diff line number Diff line
#ifndef KINETIC_CPP_EXAMPLES_H_
#define KINETIC_CPP_EXAMPLES_H_

void PerformKineticOpOrExit(kinetic::KineticStatus status) {
  if (!status.ok()) {
    fprintf(stderr, "KineticError: %d %s\n", status.statusCode(), status.message().c_str());
    exit(1);
  }
}

#endif  // KINETIC_CPP_EXAMPLES_H_