Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix directories handling #71

Merged
merged 1 commit into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions config-vdms.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
// Sets database paths and other parameters
{
// Network
"port": 55555, // Default is 55555
"max_simultaneous_clients": 20, // Default is 500
"port": 55555,
"max_simultaneous_clients": 100,

// Database paths
"pmgd_path": "db/graph", // This will be an IP address in the future
"png_path": "db/images/pngs/",
"jpg_path": "db/images/jpgs/",
"tdb_path": "db/images/tiledb/tdb/",
"blob_path":"db/blobs/",
"db_root_path": "db",

"support_info": "[email protected]",
"support_phone": "1-800-A-TEAM"
"more-info": "github.com/IntelLabs/vdms"
}
11 changes: 2 additions & 9 deletions run_server.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
rm log.log
rm -r db

mkdir db
mkdir db/images
mkdir db/images/png
mkdir db/images/jpg
mkdir db/images/tiledb
mkdir db/blobs
mkdir db/descriptors

./vdms 2> log.log

# If problems with initialization, try deleting db folder.
3 changes: 1 addition & 2 deletions src/DescriptorsCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ bool DescriptorsCommand::check_blob_size(const std::string& blob, const int dime
AddDescriptorSet::AddDescriptorSet() :
DescriptorsCommand("AddDescriptorSet")
{
_storage_sets = VDMSConfig::instance()
->get_string_value("descriptors", DEFAULT_DESCRIPTORS_PATH);
_storage_sets = VDMSConfig::instance()->get_path_descriptors();
}

int AddDescriptorSet::construct_protobuf(
Expand Down
1 change: 0 additions & 1 deletion src/DescriptorsCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ namespace VDMS{
class AddDescriptorSet: public DescriptorsCommand
{
std::string _storage_sets;
const std::string DEFAULT_DESCRIPTORS_PATH = "db/descriptors";

public:
AddDescriptorSet();
Expand Down
9 changes: 3 additions & 6 deletions src/ImageCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,9 @@ void ImageCommand::enqueue_operations(VCL::Image& img, const Json::Value& ops)

AddImage::AddImage() : ImageCommand("AddImage")
{
_storage_tdb = VDMSConfig::instance()
->get_string_value("tdb_path", DEFAULT_TDB_PATH);
_storage_png = VDMSConfig::instance()
->get_string_value("png_path", DEFAULT_PNG_PATH);
_storage_jpg = VDMSConfig::instance()
->get_string_value("jpg_path", DEFAULT_JPG_PATH);
_storage_tdb = VDMSConfig::instance()->get_path_tdb();
_storage_png = VDMSConfig::instance()->get_path_png();
_storage_jpg = VDMSConfig::instance()->get_path_jpg();
}

int AddImage::construct_protobuf(PMGDQuery& query,
Expand Down
4 changes: 0 additions & 4 deletions src/ImageCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ namespace VDMS {

class AddImage: public ImageCommand
{
const std::string DEFAULT_TDB_PATH = "db/images/tiledb/tdb";
const std::string DEFAULT_PNG_PATH = "db/images/png";
const std::string DEFAULT_JPG_PATH = "db/images/jpg";

std::string _storage_tdb;
std::string _storage_png;
std::string _storage_jpg;
Expand Down
3 changes: 1 addition & 2 deletions src/PMGDQueryHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ PMGD::Graph *PMGDQueryHandler::_db;

void PMGDQueryHandler::init()
{
std::string dbname = VDMSConfig::instance()
->get_string_value("pmgd_path", "db/graph");
std::string dbname = VDMSConfig::instance()->get_path_pmgd();

// Create a db
_db = new PMGD::Graph(dbname.c_str(), PMGD::Graph::Create);
Expand Down
3 changes: 1 addition & 2 deletions src/RSCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ void RSCommand::add_link(PMGDQuery& query, const Json::Value& link,

AddEntity::AddEntity() : RSCommand("AddEntity")
{
_storage_blob = VDMSConfig::instance()
->get_string_value("blob_path", DEFAULT_BLOB_PATH);
_storage_blob = VDMSConfig::instance()->get_path_blobs();
}

bool AddEntity::need_blob(const Json::Value& jsoncmd)
Expand Down
2 changes: 0 additions & 2 deletions src/RSCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ namespace VDMS {
class AddEntity : public RSCommand
{
private:
const std::string DEFAULT_BLOB_PATH = "db/blobs";

std::string _storage_blob;

public:
Expand Down
94 changes: 93 additions & 1 deletion src/VDMSConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,23 @@
#include <fstream>
#include <iostream>

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include <jsoncpp/json/json.h>

#include "VDMSConfig.h"

#define DEFAULT_PATH_ROOT "db"
#define DEFAULT_PATH_PMGD "graph"
#define DEFAULT_PATH_IMAGES "images"
#define DEFAULT_PATH_JPG "jpg"
#define DEFAULT_PATH_PNG "png"
#define DEFAULT_PATH_TDB "tdb"
#define DEFAULT_PATH_BLOBS "blobs"
#define DEFAULT_PATH_DESCRIPTORS "descriptors"

using namespace VDMS;

VDMSConfig* VDMSConfig::cfg;
Expand Down Expand Up @@ -76,8 +89,12 @@ VDMSConfig::VDMSConfig(std::string config_file)
bool parsingSuccessful = reader.parse(file, json_config);

if (!parsingSuccessful){
std::cout << "Error parsing config file" << std::endl;
std::cout << "Error parsing config file." << std::endl;
std::cout << "Exiting..." << std::endl;
exit(0);
}

build_dirs();
}

int VDMSConfig::get_int_value(std::string val, int def)
Expand All @@ -89,3 +106,78 @@ std::string VDMSConfig::get_string_value(std::string val, std::string def)
{
return json_config.get(val, def).asString();
}

// This method will check if the dir exists,
// and create the dir if it does not exist.
int VDMSConfig::create_dir(std::string path)
{
struct stat sb;
while (1)
if (stat(path.c_str(), &sb) == 0)
if (sb.st_mode & S_IFDIR)
return 0;
else
return EEXIST;
else if (errno != ENOENT)
return errno;
else if (mkdir(path.c_str(), 0777) == 0)
return 0;
else if (errno != EEXIST)
return errno;
}

void VDMSConfig::check_or_create(std::string path)
{
if (create_dir(path) == 0){
return;
}
else{
std::cout << "Cannot open/create directories structure." << std::endl;
std::cout << "Failed dir: " << path << std::endl;
std::cout << "Check paths and permissions." << std::endl;
std::cout << "Exiting..." << std::endl;
exit(0);
}
}

void VDMSConfig::build_dirs()
{
// Root
path_root = get_string_value(PARAM_DB_ROOT, DEFAULT_PATH_ROOT);
check_or_create(path_root);

// PMGD
path_pmgd = path_root + "/" + DEFAULT_PATH_PMGD;
path_pmgd = get_string_value(PARAM_DB_PMGD, path_pmgd);
check_or_create(path_pmgd);

// IMAGES
path_images = path_root + "/" + DEFAULT_PATH_IMAGES;
path_images = get_string_value(PARAM_DB_IMAGES, path_images);
check_or_create(path_images);

// IMAGES - PNG
path_png = path_images + "/" + DEFAULT_PATH_PNG;
path_png = get_string_value(PARAM_DB_PNG, path_png);
check_or_create(path_png);

// IMAGES - JPG
path_jpg = path_images + "/" + DEFAULT_PATH_JPG;
path_jpg = get_string_value(PARAM_DB_JPG, path_jpg);
check_or_create(path_jpg);

// IMAGES - TDB
path_tdb = path_images + "/" + DEFAULT_PATH_TDB;
path_tdb = get_string_value(PARAM_DB_TDB, path_tdb);
check_or_create(path_tdb);

// BLOBS
path_blobs = path_root + "/" + DEFAULT_PATH_BLOBS;
path_blobs = get_string_value(PARAM_DB_BLOBS, path_blobs);
check_or_create(path_blobs);

// DESCRIPTORS
path_descriptors = path_root + "/" + DEFAULT_PATH_DESCRIPTORS;
path_descriptors = get_string_value(PARAM_DB_DESCRIPTORS, path_descriptors);
check_or_create(path_descriptors);
}
31 changes: 31 additions & 0 deletions src/VDMSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
#include <string>
#include <jsoncpp/json/value.h>

// Parameters in the JSON config file
#define PARAM_DB_ROOT "db_root_path"
#define PARAM_DB_PMGD "pmgd_path"
#define PARAM_DB_IMAGES "images_path"
#define PARAM_DB_PNG "png_path"
#define PARAM_DB_JPG "jpg_path"
#define PARAM_DB_TDB "tdb_path"
#define PARAM_DB_BLOBS "blobs_path"
#define PARAM_DB_DESCRIPTORS "descriptors_path"

namespace VDMS{

class VDMSConfig
Expand All @@ -48,11 +58,32 @@ namespace VDMS{
static VDMSConfig* cfg;
Json::Value json_config;

// Dirs
std::string path_root;
std::string path_pmgd;
std::string path_images;
std::string path_png;
std::string path_jpg;
std::string path_tdb;
std::string path_blobs;
std::string path_descriptors;

VDMSConfig(std::string config_file);

void build_dirs();
void check_or_create(std::string path);
int create_dir(std::string path);

public:
int get_int_value(std::string val, int def);
std::string get_string_value(std::string val, std::string def);
std::string get_path_root() {return path_root;}
std::string get_path_pmgd() {return path_pmgd;}
std::string get_path_jpg() {return path_jpg;}
std::string get_path_png() {return path_png;}
std::string get_path_tdb() {return path_tdb;}
std::string get_path_blobs() {return path_blobs;}
std::string get_path_descriptors() {return path_descriptors;}
};

}; // vdms namespace
2 changes: 1 addition & 1 deletion tests/config-add10-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Sets database paths and other parameters
{
// Network
"port": 55555, // Default is 55555
"port": 55555,

// Database paths
"pmgd_path": "simpleAddx10_db"
Expand Down
2 changes: 1 addition & 1 deletion tests/config-addfind-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Sets database paths and other parameters
{
// Network
"port": 55555, // Default is 55555
"port": 55555,

// Database paths
"pmgd_path": "jsongraph"
Expand Down
6 changes: 4 additions & 2 deletions tests/config-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// Sets database paths and other parameters
{
// Network
"port": 55555, // Default is 55555
"port": 55555,

// Database paths
"pmgd_path": "simpleAdd_db"
"pmgd_path": "simpleAdd_db",

"more-info": "github.com/IntelLabs/vdms"
}
6 changes: 4 additions & 2 deletions tests/config-update-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// Sets database paths and other parameters
{
// Network
"port": 55555, // Default is 55555
"port": 55555,

// Database paths
"pmgd_path": "simpleUpdate_db"
"pmgd_path": "simpleUpdate_db",

"more-info": "github.com/IntelLabs/vmds"
}
9 changes: 0 additions & 9 deletions tests/python/clean.sh

This file was deleted.

5 changes: 4 additions & 1 deletion tests/python/config-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
// Sets database paths and other parameters
{
// Network
"port": 55557 // Default is 55555
"port": 55557,
"db_root_path": "test_db",

"more-info": "github.com/IntelLabs/vdms"
}
3 changes: 2 additions & 1 deletion tests/python/run_python_tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
sh clean.sh
rm log.log screen.log
rm -r test_db

../../vdms -cfg config-tests.json > screen.log 2> log.log &
python -m unittest discover --pattern=*.py -v
Expand Down