Skip to content
Snippets Groups Projects
Commit 8320cb39 authored by Jason Hiser's avatar Jason Hiser :tractor:
Browse files

Added SeedList functionality.

parent d83a1d74
No related branches found
No related tags found
1 merge request!10Add seed list
Pipeline #20210 passed
// std c/c++ includes
#include <iostream>
#include <fstream>
......@@ -50,7 +48,7 @@ int Usage(int argc, char* argv[], OptionVector_t& upper_opts)
cerr << "todo log delete prep <ver id> Delete the prep logs for a version id" << endl;
cerr << "todo log delete fuzz <ver id> Delete the fuzzing logs for a version id" << endl;
cerr << " seed add <boost id> <seed.yaml> Add a seed file to a boost" << endl;
cerr << "clc seed list <boost id> List all seed files for a boost " << endl;
cerr << " seed list <boost id> List all seed files for a boost " << endl;
cerr << " input import-raw-file <input-name> <on-disk-name> <input.yaml> " << endl;
cerr << " Edit input.yaml to add raw data from a file." << endl;
cerr << " input extract-raw-file <input filename> <input.yaml> " << endl;
......@@ -219,32 +217,32 @@ int VersionList(int argc, char *argv[], OptionVector_t& upper_opts)
request.set_boost_id(atoi(argv[1]));
auto reader = move(unique_ptr<ClientReader<VersionInfo_t> >( backend->VersionList(&context, request)));
auto reader = move(unique_ptr<ClientReader<VersionInfo_t> >( backend->VersionList(&context, request)));
cout << "id\t"
<< setw(16) << left << "orig bin sha"
<< setw(16) << left << "zafl bin sha"
<< setw(25) << left << "submit time"
<< setw(25) << left << "processing start time"
<< setw(25) << left << "processing end time"
<< "error"
<< endl;
while(reader->Read(&reply))
{
cout << dec
<< reply.ver_id ()<< "\t"
<< setw(16) << left << reply.orig_bin_sha ()
<< setw(16) << left << reply.zafl_bin_sha ()
<< setw(25) << left << reply.submit_time ()
<< setw(25) << left << reply.start_time ()
<< setw(25) << left << reply.end_time ()
<< boolalpha << reply.err()
<< endl;
cout << "id\t"
<< setw(16) << left << "orig bin sha"
<< setw(16) << left << "zafl bin sha"
<< setw(25) << left << "submit time"
<< setw(25) << left << "processing start time"
<< setw(25) << left << "processing end time"
<< "error"
<< endl;
while(reader->Read(&reply))
{
cout << dec
<< reply.ver_id ()<< "\t"
<< setw(16) << left << reply.orig_bin_sha ()
<< setw(16) << left << reply.zafl_bin_sha ()
<< setw(25) << left << reply.submit_time ()
<< setw(25) << left << reply.start_time ()
<< setw(25) << left << reply.end_time ()
<< boolalpha << reply.err()
<< endl;
}
}
const auto status = reader->Finish();
const auto status = reader->Finish();
// Act upon its status.
if (!status.ok())
......@@ -920,6 +918,51 @@ int SeedAdd(int argc, char *argv[], OptionVector_t& upper_opts)
}
/*
* List all seeds in a boost.
*/
int SeedList(int argc, char *argv[], OptionVector_t& upper_opts)
{
if(argc<2)
{
cerr << "Error, seed list must specify a boost id" << endl;
Usage(argc,argv, upper_opts);
return 1;
}
if(argc>2)
{
cerr << "Error, junk at end of seed list " << endl;
Usage(argc,argv, upper_opts);
return 1;
}
SETUP_CONN(SeedListRequest_t, SeedInfo_t, upper_opts);
request.set_boost_id(atoi(argv[1]));
auto reader = move(unique_ptr<ClientReader<SeedInfo_t> >(backend->SeedList(&context, request)));
cout << "BID\tSeed ID\tInput ID" << endl;
while(reader->Read(&reply))
{
cout << dec
<< (reply.boost_id()) << "\t"
<< (reply.seed_id()) << "\t"
<< (reply.input_id())
<< endl;
}
const auto status = reader->Finish();
// Act upon its status.
if (!status.ok())
{
print_error(status);
return 1;
}
cout << "Server returned OK" << endl;
return 0;
}
//
// process the boost subcommand
//
......@@ -928,6 +971,7 @@ int Seed(int argc, char *argv[], OptionVector_t& upper_opts)
const auto subcommands = SubCommandVector_t
{
{"add", SeedAdd },
{"list", SeedList },
};
return subcommandDispatch("seed", subcommands, argc, argv, upper_opts);
......
......@@ -29,6 +29,7 @@ service TurboService
rpc GetZaflLog (GetZaflLogRequest_t) returns (LogFile_t) {}
rpc GetFuzzLog (GetFuzzLogRequest_t) returns (LogFile_t) {}
rpc SeedAdd (SeedAddRequest_t) returns (SeedAddReply_t) {}
rpc SeedList (SeedListRequest_t) returns (stream SeedInfo_t) {}
rpc InputAdd (InputAddRequest_t) returns (InputAddReply_t) {}
rpc DownloadInputs (DownloadInputsRequest_t) returns (stream DownloadInputsReply_t) {}
rpc DownloadCrashes (DownloadInputsRequest_t) returns (stream DownloadInputsReply_t) {}
......@@ -114,7 +115,6 @@ message LogFile_t
bytes log = 1;
}
message SeedAddRequest_t
{
uint32 boost_id = 1;
......@@ -127,6 +127,17 @@ message SeedAddReply_t
uint32 input_id = 2;
}
message SeedListRequest_t
{
uint32 boost_id = 1;
}
message SeedInfo_t
{
uint32 boost_id = 1;
uint32 seed_id = 2;
uint32 input_id = 3;
}
message InputAddRequest_t
{
......
......@@ -346,6 +346,41 @@ class TurboServiceImpl final : public TurboService::Service
}
}
Status SeedList(ServerContext *context, const SeedListRequest_t *request, ServerWriter<SeedInfo_t> *writer) override final
{
try
{
pqxx::connection conn{db_connect_options.c_str()};
pqxx::work txn(conn);
cout << "Requested seed list " << endl;
conn.prepare("seedlist", "select S.seed_id as sid ,S.input_id as iid, I.boost_id as bid from seeds S inner join inputs I on I.boost_id = $1 and S.input_id = I.input_id");
const auto res_table = txn.exec_prepared("seedlist", request->boost_id());
if(res_table.size() == 0)
{
return Status(ABORTED, "No boost " + to_string(request->boost_id()) + " or no seeds found for boost");
}
for(const auto &res : res_table)
{
auto reply = SeedInfo_t();
reply.set_boost_id(res["bid"].as<int>());
reply.set_input_id(res["iid"].as<int>());
reply.set_seed_id (res["sid"].as<int>());
writer->Write(reply);
}
return Status::OK;
}
catch(const std::exception& e)
{
return Status(ABORTED, e.what());
}
}
Status InputAdd(ServerContext *context, const InputAddRequest_t *request, InputAddReply_t *reply) override final
{
try
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment