mirror of https://github.com/milvus-io/milvus.git
commit
ecb69a2d41
|
@ -3,3 +3,8 @@ conf/server_config.yaml
|
||||||
conf/log_config.conf
|
conf/log_config.conf
|
||||||
version.h
|
version.h
|
||||||
megasearch/
|
megasearch/
|
||||||
|
lcov_out/
|
||||||
|
base.info
|
||||||
|
output.info
|
||||||
|
output_new.info
|
||||||
|
server.info
|
|
@ -47,6 +47,7 @@ Please mark all change in change log and use the ticket from JIRA.
|
||||||
- MS-96 - add new query interface for specified files
|
- MS-96 - add new query interface for specified files
|
||||||
- MS-97 - Add S3 SDK for MinIO Storage
|
- MS-97 - Add S3 SDK for MinIO Storage
|
||||||
- MS-105 - Add MySQL
|
- MS-105 - Add MySQL
|
||||||
|
- MS-130 - Add prometheus_test
|
||||||
|
|
||||||
## Task
|
## Task
|
||||||
- MS-74 - Change README.md in cpp
|
- MS-74 - Change README.md in cpp
|
||||||
|
|
|
@ -136,9 +136,9 @@ if (BUILD_COVERAGE STREQUAL "ON")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
if ("${BUILD_UNIT_TEST}" STREQUAL "ON")
|
if (BUILD_UNIT_TEST STREQUAL "ON")
|
||||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/unittest)
|
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/unittest)
|
||||||
endif(BUILD_UNIT_TEST)
|
endif()
|
||||||
|
|
||||||
add_custom_target(Clean-All COMMAND ${CMAKE_BUILD_TOOL} clean)
|
add_custom_target(Clean-All COMMAND ${CMAKE_BUILD_TOOL} clean)
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,11 @@ If you encounter the following error when building:
|
||||||
or
|
or
|
||||||
./build.sh --unittest
|
./build.sh --unittest
|
||||||
|
|
||||||
|
#### To run code coverage
|
||||||
|
|
||||||
|
apt-get install lcov
|
||||||
|
./build.sh -u -c
|
||||||
|
|
||||||
### Launch server
|
### Launch server
|
||||||
Set config in cpp/conf/server_config.yaml
|
Set config in cpp/conf/server_config.yaml
|
||||||
|
|
||||||
|
|
|
@ -1,69 +1,69 @@
|
||||||
/*******************************************************************************
|
///*******************************************************************************
|
||||||
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
// * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||||
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
// * Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||||
* Proprietary and confidential.
|
// * Proprietary and confidential.
|
||||||
******************************************************************************/
|
// ******************************************************************************/
|
||||||
#pragma once
|
//#pragma once
|
||||||
|
//
|
||||||
#include <boost/serialization/access.hpp>
|
//#include <boost/serialization/access.hpp>
|
||||||
#include <string>
|
//#include <string>
|
||||||
#include <map>
|
//#include <map>
|
||||||
|
//
|
||||||
|
//
|
||||||
class GPUInfoFile {
|
//class GPUInfoFile {
|
||||||
public:
|
// public:
|
||||||
GPUInfoFile() = default;
|
// GPUInfoFile() = default;
|
||||||
|
//
|
||||||
GPUInfoFile(const int &device_count, const std::map<int, std::string> &uuid_encryption_map)
|
// GPUInfoFile(const int &device_count, const std::map<int, std::string> &uuid_encryption_map)
|
||||||
: device_count_(device_count), uuid_encryption_map_(uuid_encryption_map) {}
|
// : device_count_(device_count), uuid_encryption_map_(uuid_encryption_map) {}
|
||||||
|
//
|
||||||
int get_device_count() {
|
// int get_device_count() {
|
||||||
return device_count_;
|
// return device_count_;
|
||||||
}
|
// }
|
||||||
std::map<int, std::string> &get_uuid_encryption_map() {
|
// std::map<int, std::string> &get_uuid_encryption_map() {
|
||||||
return uuid_encryption_map_;
|
// return uuid_encryption_map_;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
public:
|
// public:
|
||||||
friend class boost::serialization::access;
|
// friend class boost::serialization::access;
|
||||||
|
//
|
||||||
template<typename Archive>
|
// template<typename Archive>
|
||||||
void serialize(Archive &ar, const unsigned int version) {
|
// void serialize(Archive &ar, const unsigned int version) {
|
||||||
ar & device_count_;
|
// ar & device_count_;
|
||||||
ar & uuid_encryption_map_;
|
// ar & uuid_encryption_map_;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public:
|
// public:
|
||||||
int device_count_ = 0;
|
// int device_count_ = 0;
|
||||||
std::map<int, std::string> uuid_encryption_map_;
|
// std::map<int, std::string> uuid_encryption_map_;
|
||||||
};
|
//};
|
||||||
|
//
|
||||||
class SerializedGPUInfoFile {
|
//class SerializedGPUInfoFile {
|
||||||
public:
|
// public:
|
||||||
~SerializedGPUInfoFile() {
|
// ~SerializedGPUInfoFile() {
|
||||||
if (gpu_info_file_ != nullptr) {
|
// if (gpu_info_file_ != nullptr) {
|
||||||
delete (gpu_info_file_);
|
// delete (gpu_info_file_);
|
||||||
gpu_info_file_ = nullptr;
|
// gpu_info_file_ = nullptr;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
void
|
// void
|
||||||
set_gpu_info_file(GPUInfoFile *gpu_info_file) {
|
// set_gpu_info_file(GPUInfoFile *gpu_info_file) {
|
||||||
gpu_info_file_ = gpu_info_file;
|
// gpu_info_file_ = gpu_info_file;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
GPUInfoFile *get_gpu_info_file() {
|
// GPUInfoFile *get_gpu_info_file() {
|
||||||
return gpu_info_file_;
|
// return gpu_info_file_;
|
||||||
}
|
// }
|
||||||
private:
|
// private:
|
||||||
friend class boost::serialization::access;
|
// friend class boost::serialization::access;
|
||||||
|
//
|
||||||
template<typename Archive>
|
// template<typename Archive>
|
||||||
void serialize(Archive &ar, const unsigned int version) {
|
// void serialize(Archive &ar, const unsigned int version) {
|
||||||
ar & gpu_info_file_;
|
// ar & gpu_info_file_;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private:
|
// private:
|
||||||
GPUInfoFile *gpu_info_file_ = nullptr;
|
// GPUInfoFile *gpu_info_file_ = nullptr;
|
||||||
};
|
//};
|
||||||
|
|
|
@ -1,83 +1,83 @@
|
||||||
|
//
|
||||||
#include "utils/Log.h"
|
//#include "utils/Log.h"
|
||||||
#include "LicenseLibrary.h"
|
//#include "LicenseLibrary.h"
|
||||||
#include "utils/Error.h"
|
//#include "utils/Error.h"
|
||||||
|
//
|
||||||
#include <iostream>
|
//#include <iostream>
|
||||||
#include <getopt.h>
|
//#include <getopt.h>
|
||||||
#include <memory.h>
|
//#include <memory.h>
|
||||||
// Not provide path: current work path will be used and system.info.
|
//// Not provide path: current work path will be used and system.info.
|
||||||
using namespace zilliz::milvus;
|
//using namespace zilliz::milvus;
|
||||||
|
//
|
||||||
void
|
//void
|
||||||
print_usage(const std::string &app_name) {
|
//print_usage(const std::string &app_name) {
|
||||||
printf("\n Usage: %s [OPTIONS]\n\n", app_name.c_str());
|
// printf("\n Usage: %s [OPTIONS]\n\n", app_name.c_str());
|
||||||
printf(" Options:\n");
|
// printf(" Options:\n");
|
||||||
printf(" -h --help Print this help\n");
|
// printf(" -h --help Print this help\n");
|
||||||
printf(" -s --sysinfo filename Generate system info file as given name\n");
|
// printf(" -s --sysinfo filename Generate system info file as given name\n");
|
||||||
printf("\n");
|
// printf("\n");
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
int main(int argc, char *argv[]) {
|
//int main(int argc, char *argv[]) {
|
||||||
std::string app_name = argv[0];
|
// std::string app_name = argv[0];
|
||||||
if (argc != 1 && argc != 3) {
|
// if (argc != 1 && argc != 3) {
|
||||||
print_usage(app_name);
|
// print_usage(app_name);
|
||||||
return EXIT_FAILURE;
|
// return EXIT_FAILURE;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
static struct option long_options[] = {{"system_info", required_argument, 0, 's'},
|
// static struct option long_options[] = {{"system_info", required_argument, 0, 's'},
|
||||||
{"help", no_argument, 0, 'h'},
|
// {"help", no_argument, 0, 'h'},
|
||||||
{NULL, 0, 0, 0}};
|
// {NULL, 0, 0, 0}};
|
||||||
int value = 0;
|
// int value = 0;
|
||||||
int option_index = 0;
|
// int option_index = 0;
|
||||||
std::string system_info_filename = "./system.info";
|
// std::string system_info_filename = "./system.info";
|
||||||
while ((value = getopt_long(argc, argv, "s:h", long_options, &option_index)) != -1) {
|
// while ((value = getopt_long(argc, argv, "s:h", long_options, &option_index)) != -1) {
|
||||||
switch (value) {
|
// switch (value) {
|
||||||
case 's': {
|
// case 's': {
|
||||||
char *system_info_filename_ptr = strdup(optarg);
|
// char *system_info_filename_ptr = strdup(optarg);
|
||||||
system_info_filename = system_info_filename_ptr;
|
// system_info_filename = system_info_filename_ptr;
|
||||||
free(system_info_filename_ptr);
|
// free(system_info_filename_ptr);
|
||||||
// printf("Generate system info file: %s\n", system_info_filename.c_str());
|
//// printf("Generate system info file: %s\n", system_info_filename.c_str());
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
case 'h':print_usage(app_name);
|
// case 'h':print_usage(app_name);
|
||||||
return EXIT_SUCCESS;
|
// return EXIT_SUCCESS;
|
||||||
case '?':print_usage(app_name);
|
// case '?':print_usage(app_name);
|
||||||
return EXIT_FAILURE;
|
// return EXIT_FAILURE;
|
||||||
default:print_usage(app_name);
|
// default:print_usage(app_name);
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
int device_count = 0;
|
// int device_count = 0;
|
||||||
server::ServerError err = server::LicenseLibrary::GetDeviceCount(device_count);
|
// server::ServerError err = server::LicenseLibrary::GetDeviceCount(device_count);
|
||||||
if (err != server::SERVER_SUCCESS) return -1;
|
// if (err != server::SERVER_SUCCESS) return -1;
|
||||||
|
//
|
||||||
// 1. Get All GPU UUID
|
// // 1. Get All GPU UUID
|
||||||
std::vector<std::string> uuid_array;
|
// std::vector<std::string> uuid_array;
|
||||||
err = server::LicenseLibrary::GetUUID(device_count, uuid_array);
|
// err = server::LicenseLibrary::GetUUID(device_count, uuid_array);
|
||||||
if (err != server::SERVER_SUCCESS) return -1;
|
// if (err != server::SERVER_SUCCESS) return -1;
|
||||||
|
//
|
||||||
// 2. Get UUID SHA256
|
// // 2. Get UUID SHA256
|
||||||
std::vector<std::string> uuid_sha256_array;
|
// std::vector<std::string> uuid_sha256_array;
|
||||||
err = server::LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, uuid_sha256_array);
|
// err = server::LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, uuid_sha256_array);
|
||||||
if (err != server::SERVER_SUCCESS) return -1;
|
// if (err != server::SERVER_SUCCESS) return -1;
|
||||||
|
//
|
||||||
// 3. Generate GPU ID map with GPU UUID
|
// // 3. Generate GPU ID map with GPU UUID
|
||||||
std::map<int, std::string> uuid_encrption_map;
|
// std::map<int, std::string> uuid_encrption_map;
|
||||||
for (int i = 0; i < device_count; ++i) {
|
// for (int i = 0; i < device_count; ++i) {
|
||||||
uuid_encrption_map[i] = uuid_sha256_array[i];
|
// uuid_encrption_map[i] = uuid_sha256_array[i];
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
// 4. Generate GPU_info File
|
// // 4. Generate GPU_info File
|
||||||
err = server::LicenseLibrary::GPUinfoFileSerialization(system_info_filename,
|
// err = server::LicenseLibrary::GPUinfoFileSerialization(system_info_filename,
|
||||||
device_count,
|
// device_count,
|
||||||
uuid_encrption_map);
|
// uuid_encrption_map);
|
||||||
if (err != server::SERVER_SUCCESS) return -1;
|
// if (err != server::SERVER_SUCCESS) return -1;
|
||||||
|
//
|
||||||
printf("Generate GPU_info File Success\n");
|
// printf("Generate GPU_info File Success\n");
|
||||||
|
//
|
||||||
|
//
|
||||||
return 0;
|
// return 0;
|
||||||
}
|
//}
|
|
@ -1,131 +1,131 @@
|
||||||
#include "LicenseCheck.h"
|
//#include "LicenseCheck.h"
|
||||||
#include <iostream>
|
//#include <iostream>
|
||||||
#include <thread>
|
//#include <thread>
|
||||||
|
//
|
||||||
#include <boost/archive/binary_oarchive.hpp>
|
//#include <boost/archive/binary_oarchive.hpp>
|
||||||
#include <boost/archive/binary_iarchive.hpp>
|
//#include <boost/archive/binary_iarchive.hpp>
|
||||||
//#include <boost/foreach.hpp>
|
////#include <boost/foreach.hpp>
|
||||||
//#include <boost/serialization/vector.hpp>
|
////#include <boost/serialization/vector.hpp>
|
||||||
#include <boost/filesystem/path.hpp>
|
//#include <boost/filesystem/path.hpp>
|
||||||
#include <boost/serialization/map.hpp>
|
//#include <boost/serialization/map.hpp>
|
||||||
#include <boost/filesystem/operations.hpp>
|
//#include <boost/filesystem/operations.hpp>
|
||||||
#include <boost/thread.hpp>
|
//#include <boost/thread.hpp>
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
//#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
//
|
||||||
|
//
|
||||||
namespace zilliz {
|
//namespace zilliz {
|
||||||
namespace milvus {
|
//namespace milvus {
|
||||||
namespace server {
|
//namespace server {
|
||||||
|
//
|
||||||
LicenseCheck::LicenseCheck() {
|
//LicenseCheck::LicenseCheck() {
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
LicenseCheck::~LicenseCheck() {
|
//LicenseCheck::~LicenseCheck() {
|
||||||
StopCountingDown();
|
// StopCountingDown();
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
ServerError
|
//ServerError
|
||||||
LicenseCheck::LegalityCheck(const std::string &license_file_path) {
|
//LicenseCheck::LegalityCheck(const std::string &license_file_path) {
|
||||||
|
//
|
||||||
int device_count;
|
// int device_count;
|
||||||
LicenseLibrary::GetDeviceCount(device_count);
|
// LicenseLibrary::GetDeviceCount(device_count);
|
||||||
std::vector<std::string> uuid_array;
|
// std::vector<std::string> uuid_array;
|
||||||
LicenseLibrary::GetUUID(device_count, uuid_array);
|
// LicenseLibrary::GetUUID(device_count, uuid_array);
|
||||||
|
//
|
||||||
std::vector<std::string> sha_array;
|
// std::vector<std::string> sha_array;
|
||||||
LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, sha_array);
|
// LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, sha_array);
|
||||||
|
//
|
||||||
int output_device_count;
|
// int output_device_count;
|
||||||
std::map<int, std::string> uuid_encryption_map;
|
// std::map<int, std::string> uuid_encryption_map;
|
||||||
time_t starting_time;
|
// time_t starting_time;
|
||||||
time_t end_time;
|
// time_t end_time;
|
||||||
ServerError err = LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
// ServerError err = LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||||
output_device_count,
|
// output_device_count,
|
||||||
uuid_encryption_map,
|
// uuid_encryption_map,
|
||||||
starting_time,
|
// starting_time,
|
||||||
end_time);
|
// end_time);
|
||||||
if(err !=SERVER_SUCCESS)
|
// if(err !=SERVER_SUCCESS)
|
||||||
{
|
// {
|
||||||
std::cout << "License check error: 01" << std::endl;
|
// std::cout << "License check error: 01" << std::endl;
|
||||||
return SERVER_UNEXPECTED_ERROR;
|
// return SERVER_UNEXPECTED_ERROR;
|
||||||
}
|
// }
|
||||||
time_t system_time;
|
// time_t system_time;
|
||||||
LicenseLibrary::GetSystemTime(system_time);
|
// LicenseLibrary::GetSystemTime(system_time);
|
||||||
|
//
|
||||||
if (device_count != output_device_count) {
|
// if (device_count != output_device_count) {
|
||||||
std::cout << "License check error: 02" << std::endl;
|
// std::cout << "License check error: 02" << std::endl;
|
||||||
return SERVER_UNEXPECTED_ERROR;
|
// return SERVER_UNEXPECTED_ERROR;
|
||||||
}
|
// }
|
||||||
for (int i = 0; i < device_count; ++i) {
|
// for (int i = 0; i < device_count; ++i) {
|
||||||
if (sha_array[i] != uuid_encryption_map[i]) {
|
// if (sha_array[i] != uuid_encryption_map[i]) {
|
||||||
std::cout << "License check error: 03" << std::endl;
|
// std::cout << "License check error: 03" << std::endl;
|
||||||
return SERVER_UNEXPECTED_ERROR;
|
// return SERVER_UNEXPECTED_ERROR;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (system_time < starting_time || system_time > end_time) {
|
// if (system_time < starting_time || system_time > end_time) {
|
||||||
std::cout << "License check error: 04" << std::endl;
|
// std::cout << "License check error: 04" << std::endl;
|
||||||
return SERVER_UNEXPECTED_ERROR;
|
// return SERVER_UNEXPECTED_ERROR;
|
||||||
}
|
// }
|
||||||
std::cout << "Legality Check Success" << std::endl;
|
// std::cout << "Legality Check Success" << std::endl;
|
||||||
return SERVER_SUCCESS;
|
// return SERVER_SUCCESS;
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
// Part 2: Timing check license
|
//// Part 2: Timing check license
|
||||||
|
//
|
||||||
ServerError
|
//ServerError
|
||||||
LicenseCheck::AlterFile(const std::string &license_file_path,
|
//LicenseCheck::AlterFile(const std::string &license_file_path,
|
||||||
const boost::system::error_code &ec,
|
// const boost::system::error_code &ec,
|
||||||
boost::asio::deadline_timer *pt) {
|
// boost::asio::deadline_timer *pt) {
|
||||||
|
//
|
||||||
ServerError err = LicenseCheck::LegalityCheck(license_file_path);
|
// ServerError err = LicenseCheck::LegalityCheck(license_file_path);
|
||||||
if(err!=SERVER_SUCCESS) {
|
// if(err!=SERVER_SUCCESS) {
|
||||||
std::cout << "license file check error" << std::endl;
|
// std::cout << "license file check error" << std::endl;
|
||||||
exit(1);
|
// exit(1);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
std::cout << "---runing---" << std::endl;
|
// std::cout << "---runing---" << std::endl;
|
||||||
pt->expires_at(pt->expires_at() + boost::posix_time::hours(1));
|
// pt->expires_at(pt->expires_at() + boost::posix_time::hours(1));
|
||||||
pt->async_wait(boost::bind(LicenseCheck::AlterFile, license_file_path, boost::asio::placeholders::error, pt));
|
// pt->async_wait(boost::bind(LicenseCheck::AlterFile, license_file_path, boost::asio::placeholders::error, pt));
|
||||||
|
//
|
||||||
return SERVER_SUCCESS;
|
// return SERVER_SUCCESS;
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
ServerError
|
//ServerError
|
||||||
LicenseCheck::StartCountingDown(const std::string &license_file_path) {
|
//LicenseCheck::StartCountingDown(const std::string &license_file_path) {
|
||||||
|
//
|
||||||
if (!LicenseLibrary::IsFileExistent(license_file_path)) {
|
// if (!LicenseLibrary::IsFileExistent(license_file_path)) {
|
||||||
std::cout << "license file not exist" << std::endl;
|
// std::cout << "license file not exist" << std::endl;
|
||||||
exit(1);
|
// exit(1);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//create a thread to run AlterFile
|
// //create a thread to run AlterFile
|
||||||
if(counting_thread_ == nullptr) {
|
// if(counting_thread_ == nullptr) {
|
||||||
counting_thread_ = std::make_shared<std::thread>([&]() {
|
// counting_thread_ = std::make_shared<std::thread>([&]() {
|
||||||
boost::asio::deadline_timer t(io_service_, boost::posix_time::hours(1));
|
// boost::asio::deadline_timer t(io_service_, boost::posix_time::hours(1));
|
||||||
t.async_wait(boost::bind(LicenseCheck::AlterFile, license_file_path, boost::asio::placeholders::error, &t));
|
// t.async_wait(boost::bind(LicenseCheck::AlterFile, license_file_path, boost::asio::placeholders::error, &t));
|
||||||
io_service_.run();//this thread will block here
|
// io_service_.run();//this thread will block here
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return SERVER_SUCCESS;
|
// return SERVER_SUCCESS;
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
ServerError
|
//ServerError
|
||||||
LicenseCheck::StopCountingDown() {
|
//LicenseCheck::StopCountingDown() {
|
||||||
if(!io_service_.stopped()) {
|
// if(!io_service_.stopped()) {
|
||||||
io_service_.stop();
|
// io_service_.stop();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if(counting_thread_ != nullptr) {
|
// if(counting_thread_ != nullptr) {
|
||||||
counting_thread_->join();
|
// counting_thread_->join();
|
||||||
counting_thread_ = nullptr;
|
// counting_thread_ = nullptr;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return SERVER_SUCCESS;
|
// return SERVER_SUCCESS;
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
}
|
//}
|
||||||
}
|
//}
|
|
@ -1,52 +1,52 @@
|
||||||
#pragma once
|
//#pragma once
|
||||||
|
//
|
||||||
#include "utils/Error.h"
|
//#include "utils/Error.h"
|
||||||
#include "LicenseLibrary.h"
|
//#include "LicenseLibrary.h"
|
||||||
|
//
|
||||||
#include <boost/asio.hpp>
|
//#include <boost/asio.hpp>
|
||||||
|
//
|
||||||
#include <thread>
|
//#include <thread>
|
||||||
#include <memory>
|
//#include <memory>
|
||||||
|
//
|
||||||
namespace zilliz {
|
//namespace zilliz {
|
||||||
namespace milvus {
|
//namespace milvus {
|
||||||
namespace server {
|
//namespace server {
|
||||||
|
//
|
||||||
class LicenseCheck {
|
//class LicenseCheck {
|
||||||
private:
|
//private:
|
||||||
LicenseCheck();
|
// LicenseCheck();
|
||||||
~LicenseCheck();
|
// ~LicenseCheck();
|
||||||
|
//
|
||||||
public:
|
//public:
|
||||||
static LicenseCheck &
|
// static LicenseCheck &
|
||||||
GetInstance() {
|
// GetInstance() {
|
||||||
static LicenseCheck instance;
|
// static LicenseCheck instance;
|
||||||
return instance;
|
// return instance;
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
static ServerError
|
// static ServerError
|
||||||
LegalityCheck(const std::string &license_file_path);
|
// LegalityCheck(const std::string &license_file_path);
|
||||||
|
//
|
||||||
ServerError
|
// ServerError
|
||||||
StartCountingDown(const std::string &license_file_path);
|
// StartCountingDown(const std::string &license_file_path);
|
||||||
|
//
|
||||||
ServerError
|
// ServerError
|
||||||
StopCountingDown();
|
// StopCountingDown();
|
||||||
|
//
|
||||||
private:
|
//private:
|
||||||
static ServerError
|
// static ServerError
|
||||||
AlterFile(const std::string &license_file_path,
|
// AlterFile(const std::string &license_file_path,
|
||||||
const boost::system::error_code &ec,
|
// const boost::system::error_code &ec,
|
||||||
boost::asio::deadline_timer *pt);
|
// boost::asio::deadline_timer *pt);
|
||||||
|
//
|
||||||
private:
|
//private:
|
||||||
boost::asio::io_service io_service_;
|
// boost::asio::io_service io_service_;
|
||||||
std::shared_ptr<std::thread> counting_thread_;
|
// std::shared_ptr<std::thread> counting_thread_;
|
||||||
|
//
|
||||||
};
|
//};
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
}
|
//}
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
|
@ -1,86 +1,86 @@
|
||||||
/*******************************************************************************
|
///*******************************************************************************
|
||||||
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
// * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||||
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
// * Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||||
* Proprietary and confidential.
|
// * Proprietary and confidential.
|
||||||
******************************************************************************/
|
// ******************************************************************************/
|
||||||
#pragma once
|
//#pragma once
|
||||||
|
//
|
||||||
|
//
|
||||||
#include <boost/serialization/access.hpp>
|
//#include <boost/serialization/access.hpp>
|
||||||
#include <string>
|
//#include <string>
|
||||||
#include <map>
|
//#include <map>
|
||||||
|
//
|
||||||
|
//
|
||||||
class LicenseFile {
|
//class LicenseFile {
|
||||||
public:
|
// public:
|
||||||
LicenseFile() = default;
|
// LicenseFile() = default;
|
||||||
|
//
|
||||||
LicenseFile(const int &device_count,
|
// LicenseFile(const int &device_count,
|
||||||
const std::map<int, std::string> &uuid_encryption_map,
|
// const std::map<int, std::string> &uuid_encryption_map,
|
||||||
const time_t &starting_time,
|
// const time_t &starting_time,
|
||||||
const time_t &end_time)
|
// const time_t &end_time)
|
||||||
: device_count_(device_count),
|
// : device_count_(device_count),
|
||||||
uuid_encryption_map_(uuid_encryption_map),
|
// uuid_encryption_map_(uuid_encryption_map),
|
||||||
starting_time_(starting_time),
|
// starting_time_(starting_time),
|
||||||
end_time_(end_time) {}
|
// end_time_(end_time) {}
|
||||||
|
//
|
||||||
int get_device_count() {
|
// int get_device_count() {
|
||||||
return device_count_;
|
// return device_count_;
|
||||||
}
|
// }
|
||||||
std::map<int, std::string> &get_uuid_encryption_map() {
|
// std::map<int, std::string> &get_uuid_encryption_map() {
|
||||||
return uuid_encryption_map_;
|
// return uuid_encryption_map_;
|
||||||
}
|
// }
|
||||||
time_t get_starting_time() {
|
// time_t get_starting_time() {
|
||||||
return starting_time_;
|
// return starting_time_;
|
||||||
}
|
// }
|
||||||
time_t get_end_time() {
|
// time_t get_end_time() {
|
||||||
return end_time_;
|
// return end_time_;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public:
|
// public:
|
||||||
friend class boost::serialization::access;
|
// friend class boost::serialization::access;
|
||||||
|
//
|
||||||
template<typename Archive>
|
// template<typename Archive>
|
||||||
void serialize(Archive &ar, const unsigned int version) {
|
// void serialize(Archive &ar, const unsigned int version) {
|
||||||
ar & device_count_;
|
// ar & device_count_;
|
||||||
ar & uuid_encryption_map_;
|
// ar & uuid_encryption_map_;
|
||||||
ar & starting_time_;
|
// ar & starting_time_;
|
||||||
ar & end_time_;
|
// ar & end_time_;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public:
|
// public:
|
||||||
int device_count_ = 0;
|
// int device_count_ = 0;
|
||||||
std::map<int, std::string> uuid_encryption_map_;
|
// std::map<int, std::string> uuid_encryption_map_;
|
||||||
time_t starting_time_ = 0;
|
// time_t starting_time_ = 0;
|
||||||
time_t end_time_ = 0;
|
// time_t end_time_ = 0;
|
||||||
};
|
//};
|
||||||
|
//
|
||||||
class SerializedLicenseFile {
|
//class SerializedLicenseFile {
|
||||||
public:
|
// public:
|
||||||
~SerializedLicenseFile() {
|
// ~SerializedLicenseFile() {
|
||||||
if (license_file_ != nullptr) {
|
// if (license_file_ != nullptr) {
|
||||||
delete (license_file_);
|
// delete (license_file_);
|
||||||
license_file_ = nullptr;
|
// license_file_ = nullptr;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
void
|
// void
|
||||||
set_license_file(LicenseFile *license_file) {
|
// set_license_file(LicenseFile *license_file) {
|
||||||
license_file_ = license_file;
|
// license_file_ = license_file;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
LicenseFile *get_license_file() {
|
// LicenseFile *get_license_file() {
|
||||||
return license_file_;
|
// return license_file_;
|
||||||
}
|
// }
|
||||||
private:
|
// private:
|
||||||
friend class boost::serialization::access;
|
// friend class boost::serialization::access;
|
||||||
|
//
|
||||||
template<typename Archive>
|
// template<typename Archive>
|
||||||
void serialize(Archive &ar, const unsigned int version) {
|
// void serialize(Archive &ar, const unsigned int version) {
|
||||||
ar & license_file_;
|
// ar & license_file_;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private:
|
// private:
|
||||||
LicenseFile *license_file_ = nullptr;
|
// LicenseFile *license_file_ = nullptr;
|
||||||
};
|
//};
|
||||||
|
//
|
||||||
|
|
|
@ -1,121 +1,121 @@
|
||||||
|
//
|
||||||
#include <iostream>
|
//#include <iostream>
|
||||||
#include <getopt.h>
|
//#include <getopt.h>
|
||||||
#include <memory.h>
|
//#include <memory.h>
|
||||||
|
//
|
||||||
#include "utils/Log.h"
|
//#include "utils/Log.h"
|
||||||
#include "license/LicenseLibrary.h"
|
//#include "license/LicenseLibrary.h"
|
||||||
#include "utils/Error.h"
|
//#include "utils/Error.h"
|
||||||
|
//
|
||||||
|
//
|
||||||
using namespace zilliz::milvus;
|
//using namespace zilliz::milvus;
|
||||||
// Not provide path: current work path will be used and system.info.
|
//// Not provide path: current work path will be used and system.info.
|
||||||
|
//
|
||||||
void
|
//void
|
||||||
print_usage(const std::string &app_name) {
|
//print_usage(const std::string &app_name) {
|
||||||
printf("\n Usage: %s [OPTIONS]\n\n", app_name.c_str());
|
// printf("\n Usage: %s [OPTIONS]\n\n", app_name.c_str());
|
||||||
printf(" Options:\n");
|
// printf(" Options:\n");
|
||||||
printf(" -h --help Print this help\n");
|
// printf(" -h --help Print this help\n");
|
||||||
printf(" -s --sysinfo filename sysinfo file location\n");
|
// printf(" -s --sysinfo filename sysinfo file location\n");
|
||||||
printf(" -l --license filename Generate license file as given name\n");
|
// printf(" -l --license filename Generate license file as given name\n");
|
||||||
printf(" -b --starting time Set start time (format: YYYY-MM-DD)\n");
|
// printf(" -b --starting time Set start time (format: YYYY-MM-DD)\n");
|
||||||
printf(" -e --end time Set end time (format: YYYY-MM-DD)\n");
|
// printf(" -e --end time Set end time (format: YYYY-MM-DD)\n");
|
||||||
printf("\n");
|
// printf("\n");
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
int main(int argc, char *argv[]) {
|
//int main(int argc, char *argv[]) {
|
||||||
std::string app_name = argv[0];
|
// std::string app_name = argv[0];
|
||||||
// if (argc != 1 && argc != 3) {
|
//// if (argc != 1 && argc != 3) {
|
||||||
// print_usage(app_name);
|
//// print_usage(app_name);
|
||||||
// return EXIT_FAILURE;
|
//// return EXIT_FAILURE;
|
||||||
|
//// }
|
||||||
|
// static struct option long_options[] = {{"system_info", required_argument, 0, 's'},
|
||||||
|
// {"license", optional_argument, 0, 'l'},
|
||||||
|
// {"help", no_argument, 0, 'h'},
|
||||||
|
// {"starting_time", required_argument, 0, 'b'},
|
||||||
|
// {"end_time", required_argument, 0, 'e'},
|
||||||
|
// {NULL, 0, 0, 0}};
|
||||||
|
// server::ServerError err;
|
||||||
|
// int value = 0;
|
||||||
|
// int option_index = 0;
|
||||||
|
// std::string system_info_filename = "./system.info";
|
||||||
|
// std::string license_filename = "./system.license";
|
||||||
|
// char *string_starting_time = NULL;
|
||||||
|
// char *string_end_time = NULL;
|
||||||
|
// time_t starting_time = 0;
|
||||||
|
// time_t end_time = 0;
|
||||||
|
// int flag_s = 1;
|
||||||
|
// int flag_b = 1;
|
||||||
|
// int flag_e = 1;
|
||||||
|
// while ((value = getopt_long(argc, argv, "hl:s:b:e:", long_options, NULL)) != -1) {
|
||||||
|
// switch (value) {
|
||||||
|
// case 's': {
|
||||||
|
// flag_s = 0;
|
||||||
|
// system_info_filename = (std::string) (optarg);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case 'b': {
|
||||||
|
// flag_b = 0;
|
||||||
|
// string_starting_time = optarg;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case 'e': {
|
||||||
|
// flag_e = 0;
|
||||||
|
// string_end_time = optarg;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case 'l': {
|
||||||
|
// license_filename = (std::string) (optarg);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case 'h':print_usage(app_name);
|
||||||
|
// return EXIT_SUCCESS;
|
||||||
|
// case '?':print_usage(app_name);
|
||||||
|
// return EXIT_FAILURE;
|
||||||
|
// default:print_usage(app_name);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// if (flag_s) {
|
||||||
|
// printf("Error: sysinfo file location must be entered\n");
|
||||||
|
// return 1;
|
||||||
|
// }
|
||||||
|
// if (flag_b) {
|
||||||
|
// printf("Error: start time must be entered\n");
|
||||||
|
// return 1;
|
||||||
|
// }
|
||||||
|
// if (flag_e) {
|
||||||
|
// printf("Error: end time must be entered\n");
|
||||||
|
// return 1;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// err = server::LicenseLibrary::GetDateTime(string_starting_time, starting_time);
|
||||||
|
// if (err != server::SERVER_SUCCESS) return -1;
|
||||||
|
//
|
||||||
|
// err = server::LicenseLibrary::GetDateTime(string_end_time, end_time);
|
||||||
|
// if (err != server::SERVER_SUCCESS) return -1;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// int output_info_device_count = 0;
|
||||||
|
// std::map<int, std::string> output_info_uuid_encrption_map;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// err = server::LicenseLibrary::GPUinfoFileDeserialization(system_info_filename,
|
||||||
|
// output_info_device_count,
|
||||||
|
// output_info_uuid_encrption_map);
|
||||||
|
// if (err != server::SERVER_SUCCESS) return -1;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// err = server::LicenseLibrary::LicenseFileSerialization(license_filename,
|
||||||
|
// output_info_device_count,
|
||||||
|
// output_info_uuid_encrption_map,
|
||||||
|
// starting_time,
|
||||||
|
// end_time);
|
||||||
|
// if (err != server::SERVER_SUCCESS) return -1;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// printf("Generate License File Success\n");
|
||||||
|
//
|
||||||
|
// return 0;
|
||||||
//}
|
//}
|
||||||
static struct option long_options[] = {{"system_info", required_argument, 0, 's'},
|
|
||||||
{"license", optional_argument, 0, 'l'},
|
|
||||||
{"help", no_argument, 0, 'h'},
|
|
||||||
{"starting_time", required_argument, 0, 'b'},
|
|
||||||
{"end_time", required_argument, 0, 'e'},
|
|
||||||
{NULL, 0, 0, 0}};
|
|
||||||
server::ServerError err;
|
|
||||||
int value = 0;
|
|
||||||
int option_index = 0;
|
|
||||||
std::string system_info_filename = "./system.info";
|
|
||||||
std::string license_filename = "./system.license";
|
|
||||||
char *string_starting_time = NULL;
|
|
||||||
char *string_end_time = NULL;
|
|
||||||
time_t starting_time = 0;
|
|
||||||
time_t end_time = 0;
|
|
||||||
int flag_s = 1;
|
|
||||||
int flag_b = 1;
|
|
||||||
int flag_e = 1;
|
|
||||||
while ((value = getopt_long(argc, argv, "hl:s:b:e:", long_options, NULL)) != -1) {
|
|
||||||
switch (value) {
|
|
||||||
case 's': {
|
|
||||||
flag_s = 0;
|
|
||||||
system_info_filename = (std::string) (optarg);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'b': {
|
|
||||||
flag_b = 0;
|
|
||||||
string_starting_time = optarg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'e': {
|
|
||||||
flag_e = 0;
|
|
||||||
string_end_time = optarg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'l': {
|
|
||||||
license_filename = (std::string) (optarg);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'h':print_usage(app_name);
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
case '?':print_usage(app_name);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
default:print_usage(app_name);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (flag_s) {
|
|
||||||
printf("Error: sysinfo file location must be entered\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (flag_b) {
|
|
||||||
printf("Error: start time must be entered\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (flag_e) {
|
|
||||||
printf("Error: end time must be entered\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = server::LicenseLibrary::GetDateTime(string_starting_time, starting_time);
|
|
||||||
if (err != server::SERVER_SUCCESS) return -1;
|
|
||||||
|
|
||||||
err = server::LicenseLibrary::GetDateTime(string_end_time, end_time);
|
|
||||||
if (err != server::SERVER_SUCCESS) return -1;
|
|
||||||
|
|
||||||
|
|
||||||
int output_info_device_count = 0;
|
|
||||||
std::map<int, std::string> output_info_uuid_encrption_map;
|
|
||||||
|
|
||||||
|
|
||||||
err = server::LicenseLibrary::GPUinfoFileDeserialization(system_info_filename,
|
|
||||||
output_info_device_count,
|
|
||||||
output_info_uuid_encrption_map);
|
|
||||||
if (err != server::SERVER_SUCCESS) return -1;
|
|
||||||
|
|
||||||
|
|
||||||
err = server::LicenseLibrary::LicenseFileSerialization(license_filename,
|
|
||||||
output_info_device_count,
|
|
||||||
output_info_uuid_encrption_map,
|
|
||||||
starting_time,
|
|
||||||
end_time);
|
|
||||||
if (err != server::SERVER_SUCCESS) return -1;
|
|
||||||
|
|
||||||
|
|
||||||
printf("Generate License File Success\n");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,345 +1,345 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
//// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
//// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||||
// Proprietary and confidential.
|
//// Proprietary and confidential.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
#include "LicenseLibrary.h"
|
//#include "LicenseLibrary.h"
|
||||||
#include "utils/Log.h"
|
//#include "utils/Log.h"
|
||||||
#include <cuda_runtime.h>
|
//#include <cuda_runtime.h>
|
||||||
#include <nvml.h>
|
//#include <nvml.h>
|
||||||
#include <openssl/md5.h>
|
//#include <openssl/md5.h>
|
||||||
#include <openssl/sha.h>
|
//#include <openssl/sha.h>
|
||||||
|
//
|
||||||
#include <boost/archive/binary_oarchive.hpp>
|
//#include <boost/archive/binary_oarchive.hpp>
|
||||||
#include <boost/archive/binary_iarchive.hpp>
|
//#include <boost/archive/binary_iarchive.hpp>
|
||||||
//#include <boost/foreach.hpp>
|
////#include <boost/foreach.hpp>
|
||||||
//#include <boost/serialization/vector.hpp>
|
////#include <boost/serialization/vector.hpp>
|
||||||
#include <boost/filesystem/path.hpp>
|
//#include <boost/filesystem/path.hpp>
|
||||||
#include <boost/serialization/map.hpp>
|
//#include <boost/serialization/map.hpp>
|
||||||
#include <boost/filesystem/operations.hpp>
|
//#include <boost/filesystem/operations.hpp>
|
||||||
|
//
|
||||||
|
//
|
||||||
namespace zilliz {
|
//namespace zilliz {
|
||||||
namespace milvus {
|
//namespace milvus {
|
||||||
namespace server {
|
//namespace server {
|
||||||
|
//
|
||||||
constexpr int LicenseLibrary::sha256_length_;
|
//constexpr int LicenseLibrary::sha256_length_;
|
||||||
|
//
|
||||||
// Part 0: File check
|
//// Part 0: File check
|
||||||
bool
|
//bool
|
||||||
LicenseLibrary::IsFileExistent(const std::string &path) {
|
//LicenseLibrary::IsFileExistent(const std::string &path) {
|
||||||
|
//
|
||||||
boost::system::error_code error;
|
// boost::system::error_code error;
|
||||||
auto file_status = boost::filesystem::status(path, error);
|
// auto file_status = boost::filesystem::status(path, error);
|
||||||
if (error) {
|
// if (error) {
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (!boost::filesystem::exists(file_status)) {
|
// if (!boost::filesystem::exists(file_status)) {
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return !boost::filesystem::is_directory(file_status);
|
// return !boost::filesystem::is_directory(file_status);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
// Part 1: Get GPU Info
|
//// Part 1: Get GPU Info
|
||||||
ServerError
|
|
||||||
LicenseLibrary::GetDeviceCount(int &device_count) {
|
|
||||||
nvmlReturn_t result = nvmlInit();
|
|
||||||
if (NVML_SUCCESS != result) {
|
|
||||||
printf("Failed to initialize NVML: %s\n", nvmlErrorString(result));
|
|
||||||
return SERVER_UNEXPECTED_ERROR;
|
|
||||||
}
|
|
||||||
cudaError_t error_id = cudaGetDeviceCount(&device_count);
|
|
||||||
if (error_id != cudaSuccess) {
|
|
||||||
printf("cudaGetDeviceCount returned %d\n-> %s\n", (int) error_id, cudaGetErrorString(error_id));
|
|
||||||
printf("Result = FAIL\n");
|
|
||||||
return SERVER_UNEXPECTED_ERROR;
|
|
||||||
}
|
|
||||||
return SERVER_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerError
|
|
||||||
LicenseLibrary::GetUUID(int device_count, std::vector<std::string> &uuid_array) {
|
|
||||||
if (device_count == 0) {
|
|
||||||
printf("There are no available device(s) that support CUDA\n");
|
|
||||||
return SERVER_UNEXPECTED_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int dev = 0; dev < device_count; ++dev) {
|
|
||||||
nvmlDevice_t device;
|
|
||||||
nvmlReturn_t result = nvmlDeviceGetHandleByIndex(dev, &device);
|
|
||||||
if (NVML_SUCCESS != result) {
|
|
||||||
printf("Failed to get handle for device %i: %s\n", dev, nvmlErrorString(result));
|
|
||||||
return SERVER_UNEXPECTED_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
char uuid[80];
|
|
||||||
unsigned int length = 80;
|
|
||||||
nvmlReturn_t err = nvmlDeviceGetUUID(device, uuid, length);
|
|
||||||
if (err != NVML_SUCCESS) {
|
|
||||||
printf("nvmlDeviceGetUUID error: %d\n", err);
|
|
||||||
return SERVER_UNEXPECTED_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
uuid_array.emplace_back(uuid);
|
|
||||||
}
|
|
||||||
return SERVER_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerError
|
|
||||||
LicenseLibrary::GetUUIDMD5(int device_count,
|
|
||||||
std::vector<std::string> &uuid_array,
|
|
||||||
std::vector<std::string> &md5_array) {
|
|
||||||
MD5_CTX ctx;
|
|
||||||
unsigned char outmd[16];
|
|
||||||
char temp[2];
|
|
||||||
std::string md5;
|
|
||||||
for (int dev = 0; dev < device_count; ++dev) {
|
|
||||||
md5.clear();
|
|
||||||
memset(outmd, 0, sizeof(outmd));
|
|
||||||
MD5_Init(&ctx);
|
|
||||||
MD5_Update(&ctx, uuid_array[dev].c_str(), uuid_array[dev].size());
|
|
||||||
MD5_Final(outmd, &ctx);
|
|
||||||
for (int i = 0; i < 16; ++i) {
|
|
||||||
std::snprintf(temp, 2, "%02X", outmd[i]);
|
|
||||||
md5 += temp;
|
|
||||||
}
|
|
||||||
md5_array.push_back(md5);
|
|
||||||
}
|
|
||||||
return SERVER_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerError
|
|
||||||
LicenseLibrary::GetUUIDSHA256(const int &device_count,
|
|
||||||
std::vector<std::string> &uuid_array,
|
|
||||||
std::vector<std::string> &sha_array) {
|
|
||||||
SHA256_CTX ctx;
|
|
||||||
unsigned char outmd[sha256_length_];
|
|
||||||
char temp[2];
|
|
||||||
std::string sha;
|
|
||||||
for (int dev = 0; dev < device_count; ++dev) {
|
|
||||||
sha.clear();
|
|
||||||
memset(outmd, 0, sizeof(outmd));
|
|
||||||
SHA256_Init(&ctx);
|
|
||||||
SHA256_Update(&ctx, uuid_array[dev].c_str(), uuid_array[dev].size());
|
|
||||||
SHA256_Final(outmd, &ctx);
|
|
||||||
for (int i = 0; i < sha256_length_; ++i) {
|
|
||||||
std::snprintf(temp, 2, "%02X", outmd[i]);
|
|
||||||
sha += temp;
|
|
||||||
}
|
|
||||||
sha_array.push_back(sha);
|
|
||||||
}
|
|
||||||
return SERVER_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerError
|
|
||||||
LicenseLibrary::GetSystemTime(time_t &system_time) {
|
|
||||||
system_time = time(NULL);
|
|
||||||
return SERVER_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Part 2: Handle License File
|
|
||||||
ServerError
|
|
||||||
LicenseLibrary::LicenseFileSerialization(const std::string &path,
|
|
||||||
int device_count,
|
|
||||||
const std::map<int, std::string> &uuid_encrption_map,
|
|
||||||
time_t starting_time,
|
|
||||||
time_t end_time) {
|
|
||||||
|
|
||||||
std::ofstream file(path);
|
|
||||||
boost::archive::binary_oarchive oa(file);
|
|
||||||
oa.register_type<LicenseFile>();
|
|
||||||
|
|
||||||
SerializedLicenseFile serialized_license_file;
|
|
||||||
|
|
||||||
serialized_license_file.set_license_file(new LicenseFile(device_count,
|
|
||||||
uuid_encrption_map,
|
|
||||||
starting_time,
|
|
||||||
end_time));
|
|
||||||
oa << serialized_license_file;
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
return SERVER_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerError
|
|
||||||
LicenseLibrary::LicenseFileDeserialization(const std::string &path,
|
|
||||||
int &device_count,
|
|
||||||
std::map<int, std::string> &uuid_encrption_map,
|
|
||||||
time_t &starting_time,
|
|
||||||
time_t &end_time) {
|
|
||||||
if (!IsFileExistent(path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
|
||||||
std::ifstream file(path);
|
|
||||||
boost::archive::binary_iarchive ia(file);
|
|
||||||
ia.register_type<LicenseFile>();
|
|
||||||
|
|
||||||
SerializedLicenseFile serialized_license_file;
|
|
||||||
ia >> serialized_license_file;
|
|
||||||
|
|
||||||
device_count = serialized_license_file.get_license_file()->get_device_count();
|
|
||||||
uuid_encrption_map = serialized_license_file.get_license_file()->get_uuid_encryption_map();
|
|
||||||
starting_time = serialized_license_file.get_license_file()->get_starting_time();
|
|
||||||
end_time = serialized_license_file.get_license_file()->get_end_time();
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
return SERVER_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
//ServerError
|
//ServerError
|
||||||
//LicenseLibrary::SecretFileSerialization(const std::string &path,
|
//LicenseLibrary::GetDeviceCount(int &device_count) {
|
||||||
// const time_t &update_time,
|
// nvmlReturn_t result = nvmlInit();
|
||||||
// const off_t &file_size,
|
// if (NVML_SUCCESS != result) {
|
||||||
// const time_t &starting_time,
|
// printf("Failed to initialize NVML: %s\n", nvmlErrorString(result));
|
||||||
// const time_t &end_time,
|
// return SERVER_UNEXPECTED_ERROR;
|
||||||
// const std::string &file_md5) {
|
// }
|
||||||
|
// cudaError_t error_id = cudaGetDeviceCount(&device_count);
|
||||||
|
// if (error_id != cudaSuccess) {
|
||||||
|
// printf("cudaGetDeviceCount returned %d\n-> %s\n", (int) error_id, cudaGetErrorString(error_id));
|
||||||
|
// printf("Result = FAIL\n");
|
||||||
|
// return SERVER_UNEXPECTED_ERROR;
|
||||||
|
// }
|
||||||
|
// return SERVER_SUCCESS;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//ServerError
|
||||||
|
//LicenseLibrary::GetUUID(int device_count, std::vector<std::string> &uuid_array) {
|
||||||
|
// if (device_count == 0) {
|
||||||
|
// printf("There are no available device(s) that support CUDA\n");
|
||||||
|
// return SERVER_UNEXPECTED_ERROR;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for (int dev = 0; dev < device_count; ++dev) {
|
||||||
|
// nvmlDevice_t device;
|
||||||
|
// nvmlReturn_t result = nvmlDeviceGetHandleByIndex(dev, &device);
|
||||||
|
// if (NVML_SUCCESS != result) {
|
||||||
|
// printf("Failed to get handle for device %i: %s\n", dev, nvmlErrorString(result));
|
||||||
|
// return SERVER_UNEXPECTED_ERROR;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// char uuid[80];
|
||||||
|
// unsigned int length = 80;
|
||||||
|
// nvmlReturn_t err = nvmlDeviceGetUUID(device, uuid, length);
|
||||||
|
// if (err != NVML_SUCCESS) {
|
||||||
|
// printf("nvmlDeviceGetUUID error: %d\n", err);
|
||||||
|
// return SERVER_UNEXPECTED_ERROR;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// uuid_array.emplace_back(uuid);
|
||||||
|
// }
|
||||||
|
// return SERVER_SUCCESS;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//ServerError
|
||||||
|
//LicenseLibrary::GetUUIDMD5(int device_count,
|
||||||
|
// std::vector<std::string> &uuid_array,
|
||||||
|
// std::vector<std::string> &md5_array) {
|
||||||
|
// MD5_CTX ctx;
|
||||||
|
// unsigned char outmd[16];
|
||||||
|
// char temp[2];
|
||||||
|
// std::string md5;
|
||||||
|
// for (int dev = 0; dev < device_count; ++dev) {
|
||||||
|
// md5.clear();
|
||||||
|
// memset(outmd, 0, sizeof(outmd));
|
||||||
|
// MD5_Init(&ctx);
|
||||||
|
// MD5_Update(&ctx, uuid_array[dev].c_str(), uuid_array[dev].size());
|
||||||
|
// MD5_Final(outmd, &ctx);
|
||||||
|
// for (int i = 0; i < 16; ++i) {
|
||||||
|
// std::snprintf(temp, 2, "%02X", outmd[i]);
|
||||||
|
// md5 += temp;
|
||||||
|
// }
|
||||||
|
// md5_array.push_back(md5);
|
||||||
|
// }
|
||||||
|
// return SERVER_SUCCESS;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//ServerError
|
||||||
|
//LicenseLibrary::GetUUIDSHA256(const int &device_count,
|
||||||
|
// std::vector<std::string> &uuid_array,
|
||||||
|
// std::vector<std::string> &sha_array) {
|
||||||
|
// SHA256_CTX ctx;
|
||||||
|
// unsigned char outmd[sha256_length_];
|
||||||
|
// char temp[2];
|
||||||
|
// std::string sha;
|
||||||
|
// for (int dev = 0; dev < device_count; ++dev) {
|
||||||
|
// sha.clear();
|
||||||
|
// memset(outmd, 0, sizeof(outmd));
|
||||||
|
// SHA256_Init(&ctx);
|
||||||
|
// SHA256_Update(&ctx, uuid_array[dev].c_str(), uuid_array[dev].size());
|
||||||
|
// SHA256_Final(outmd, &ctx);
|
||||||
|
// for (int i = 0; i < sha256_length_; ++i) {
|
||||||
|
// std::snprintf(temp, 2, "%02X", outmd[i]);
|
||||||
|
// sha += temp;
|
||||||
|
// }
|
||||||
|
// sha_array.push_back(sha);
|
||||||
|
// }
|
||||||
|
// return SERVER_SUCCESS;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//ServerError
|
||||||
|
//LicenseLibrary::GetSystemTime(time_t &system_time) {
|
||||||
|
// system_time = time(NULL);
|
||||||
|
// return SERVER_SUCCESS;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//// Part 2: Handle License File
|
||||||
|
//ServerError
|
||||||
|
//LicenseLibrary::LicenseFileSerialization(const std::string &path,
|
||||||
|
// int device_count,
|
||||||
|
// const std::map<int, std::string> &uuid_encrption_map,
|
||||||
|
// time_t starting_time,
|
||||||
|
// time_t end_time) {
|
||||||
|
//
|
||||||
// std::ofstream file(path);
|
// std::ofstream file(path);
|
||||||
// boost::archive::binary_oarchive oa(file);
|
// boost::archive::binary_oarchive oa(file);
|
||||||
// oa.register_type<SecretFile>();
|
// oa.register_type<LicenseFile>();
|
||||||
//
|
//
|
||||||
// SerializedSecretFile serialized_secret_file;
|
// SerializedLicenseFile serialized_license_file;
|
||||||
//
|
//
|
||||||
// serialized_secret_file.set_secret_file(new SecretFile(update_time, file_size, starting_time, end_time, file_md5));
|
// serialized_license_file.set_license_file(new LicenseFile(device_count,
|
||||||
// oa << serialized_secret_file;
|
// uuid_encrption_map,
|
||||||
|
// starting_time,
|
||||||
|
// end_time));
|
||||||
|
// oa << serialized_license_file;
|
||||||
//
|
//
|
||||||
// file.close();
|
// file.close();
|
||||||
// return SERVER_SUCCESS;
|
// return SERVER_SUCCESS;
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//ServerError
|
//ServerError
|
||||||
//LicenseLibrary::SecretFileDeserialization(const std::string &path,
|
//LicenseLibrary::LicenseFileDeserialization(const std::string &path,
|
||||||
// time_t &update_time,
|
// int &device_count,
|
||||||
// off_t &file_size,
|
// std::map<int, std::string> &uuid_encrption_map,
|
||||||
// time_t &starting_time,
|
// time_t &starting_time,
|
||||||
// time_t &end_time,
|
// time_t &end_time) {
|
||||||
// std::string &file_md5) {
|
// if (!IsFileExistent(path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
||||||
|
// std::ifstream file(path);
|
||||||
|
// boost::archive::binary_iarchive ia(file);
|
||||||
|
// ia.register_type<LicenseFile>();
|
||||||
|
//
|
||||||
|
// SerializedLicenseFile serialized_license_file;
|
||||||
|
// ia >> serialized_license_file;
|
||||||
|
//
|
||||||
|
// device_count = serialized_license_file.get_license_file()->get_device_count();
|
||||||
|
// uuid_encrption_map = serialized_license_file.get_license_file()->get_uuid_encryption_map();
|
||||||
|
// starting_time = serialized_license_file.get_license_file()->get_starting_time();
|
||||||
|
// end_time = serialized_license_file.get_license_file()->get_end_time();
|
||||||
|
//
|
||||||
|
// file.close();
|
||||||
|
// return SERVER_SUCCESS;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
////ServerError
|
||||||
|
////LicenseLibrary::SecretFileSerialization(const std::string &path,
|
||||||
|
//// const time_t &update_time,
|
||||||
|
//// const off_t &file_size,
|
||||||
|
//// const time_t &starting_time,
|
||||||
|
//// const time_t &end_time,
|
||||||
|
//// const std::string &file_md5) {
|
||||||
|
//// std::ofstream file(path);
|
||||||
|
//// boost::archive::binary_oarchive oa(file);
|
||||||
|
//// oa.register_type<SecretFile>();
|
||||||
|
////
|
||||||
|
//// SerializedSecretFile serialized_secret_file;
|
||||||
|
////
|
||||||
|
//// serialized_secret_file.set_secret_file(new SecretFile(update_time, file_size, starting_time, end_time, file_md5));
|
||||||
|
//// oa << serialized_secret_file;
|
||||||
|
////
|
||||||
|
//// file.close();
|
||||||
|
//// return SERVER_SUCCESS;
|
||||||
|
////}
|
||||||
|
////
|
||||||
|
////ServerError
|
||||||
|
////LicenseLibrary::SecretFileDeserialization(const std::string &path,
|
||||||
|
//// time_t &update_time,
|
||||||
|
//// off_t &file_size,
|
||||||
|
//// time_t &starting_time,
|
||||||
|
//// time_t &end_time,
|
||||||
|
//// std::string &file_md5) {
|
||||||
|
//// if (!IsFileExistent(path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
||||||
|
////
|
||||||
|
//// std::ifstream file(path);
|
||||||
|
//// boost::archive::binary_iarchive ia(file);
|
||||||
|
//// ia.register_type<SecretFile>();
|
||||||
|
//// SerializedSecretFile serialized_secret_file;
|
||||||
|
////
|
||||||
|
//// ia >> serialized_secret_file;
|
||||||
|
//// update_time = serialized_secret_file.get_secret_file()->get_update_time();
|
||||||
|
//// file_size = serialized_secret_file.get_secret_file()->get_file_size();
|
||||||
|
//// starting_time = serialized_secret_file.get_secret_file()->get_starting_time();
|
||||||
|
//// end_time = serialized_secret_file.get_secret_file()->get_end_time();
|
||||||
|
//// file_md5 = serialized_secret_file.get_secret_file()->get_file_md5();
|
||||||
|
//// file.close();
|
||||||
|
//// return SERVER_SUCCESS;
|
||||||
|
////}
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//// Part 3: File attribute: UpdateTime Time/ Size/ MD5
|
||||||
|
//ServerError
|
||||||
|
//LicenseLibrary::GetFileUpdateTimeAndSize(const std::string &path, time_t &update_time, off_t &file_size) {
|
||||||
|
//
|
||||||
|
// if (!IsFileExistent(path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
||||||
|
//
|
||||||
|
// struct stat buf;
|
||||||
|
// int err_no = stat(path.c_str(), &buf);
|
||||||
|
// if (err_no != 0) {
|
||||||
|
// std::cout << strerror(err_no) << std::endl;
|
||||||
|
// return SERVER_UNEXPECTED_ERROR;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// update_time = buf.st_mtime;
|
||||||
|
// file_size = buf.st_size;
|
||||||
|
//
|
||||||
|
// return SERVER_SUCCESS;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//ServerError
|
||||||
|
//LicenseLibrary::GetFileMD5(const std::string &path, std::string &filemd5) {
|
||||||
|
//
|
||||||
|
// if (!IsFileExistent(path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
||||||
|
//
|
||||||
|
// filemd5.clear();
|
||||||
|
//
|
||||||
|
// std::ifstream file(path.c_str(), std::ifstream::binary);
|
||||||
|
// if (!file) {
|
||||||
|
// return -1;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// MD5_CTX md5Context;
|
||||||
|
// MD5_Init(&md5Context);
|
||||||
|
//
|
||||||
|
// char buf[1024 * 16];
|
||||||
|
// while (file.good()) {
|
||||||
|
// file.read(buf, sizeof(buf));
|
||||||
|
// MD5_Update(&md5Context, buf, file.gcount());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// unsigned char result[MD5_DIGEST_LENGTH];
|
||||||
|
// MD5_Final(result, &md5Context);
|
||||||
|
//
|
||||||
|
// char hex[35];
|
||||||
|
// memset(hex, 0, sizeof(hex));
|
||||||
|
// for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
|
||||||
|
// sprintf(hex + i * 2, "%02X", result[i]);
|
||||||
|
// }
|
||||||
|
// hex[32] = '\0';
|
||||||
|
// filemd5 = std::string(hex);
|
||||||
|
//
|
||||||
|
// return SERVER_SUCCESS;
|
||||||
|
//}
|
||||||
|
//// Part 4: GPU Info File Serialization/Deserialization
|
||||||
|
//ServerError
|
||||||
|
//LicenseLibrary::GPUinfoFileSerialization(const std::string &path,
|
||||||
|
// int device_count,
|
||||||
|
// const std::map<int, std::string> &uuid_encrption_map) {
|
||||||
|
// std::ofstream file(path);
|
||||||
|
// boost::archive::binary_oarchive oa(file);
|
||||||
|
// oa.register_type<GPUInfoFile>();
|
||||||
|
//
|
||||||
|
// SerializedGPUInfoFile serialized_gpu_info_file;
|
||||||
|
//
|
||||||
|
// serialized_gpu_info_file.set_gpu_info_file(new GPUInfoFile(device_count, uuid_encrption_map));
|
||||||
|
// oa << serialized_gpu_info_file;
|
||||||
|
//
|
||||||
|
// file.close();
|
||||||
|
// return SERVER_SUCCESS;
|
||||||
|
//}
|
||||||
|
//ServerError
|
||||||
|
//LicenseLibrary::GPUinfoFileDeserialization(const std::string &path,
|
||||||
|
// int &device_count,
|
||||||
|
// std::map<int, std::string> &uuid_encrption_map) {
|
||||||
// if (!IsFileExistent(path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
// if (!IsFileExistent(path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
||||||
//
|
//
|
||||||
// std::ifstream file(path);
|
// std::ifstream file(path);
|
||||||
// boost::archive::binary_iarchive ia(file);
|
// boost::archive::binary_iarchive ia(file);
|
||||||
// ia.register_type<SecretFile>();
|
// ia.register_type<GPUInfoFile>();
|
||||||
// SerializedSecretFile serialized_secret_file;
|
//
|
||||||
|
// SerializedGPUInfoFile serialized_gpu_info_file;
|
||||||
|
// ia >> serialized_gpu_info_file;
|
||||||
|
//
|
||||||
|
// device_count = serialized_gpu_info_file.get_gpu_info_file()->get_device_count();
|
||||||
|
// uuid_encrption_map = serialized_gpu_info_file.get_gpu_info_file()->get_uuid_encryption_map();
|
||||||
//
|
//
|
||||||
// ia >> serialized_secret_file;
|
|
||||||
// update_time = serialized_secret_file.get_secret_file()->get_update_time();
|
|
||||||
// file_size = serialized_secret_file.get_secret_file()->get_file_size();
|
|
||||||
// starting_time = serialized_secret_file.get_secret_file()->get_starting_time();
|
|
||||||
// end_time = serialized_secret_file.get_secret_file()->get_end_time();
|
|
||||||
// file_md5 = serialized_secret_file.get_secret_file()->get_file_md5();
|
|
||||||
// file.close();
|
// file.close();
|
||||||
// return SERVER_SUCCESS;
|
// return SERVER_SUCCESS;
|
||||||
//}
|
//}
|
||||||
|
//
|
||||||
|
//ServerError
|
||||||
|
//LicenseLibrary::GetDateTime(const char *cha, time_t &data_time) {
|
||||||
// Part 3: File attribute: UpdateTime Time/ Size/ MD5
|
// tm tm_;
|
||||||
ServerError
|
// int year, month, day;
|
||||||
LicenseLibrary::GetFileUpdateTimeAndSize(const std::string &path, time_t &update_time, off_t &file_size) {
|
// sscanf(cha, "%d-%d-%d", &year, &month, &day);
|
||||||
|
// tm_.tm_year = year - 1900;
|
||||||
if (!IsFileExistent(path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
// tm_.tm_mon = month - 1;
|
||||||
|
// tm_.tm_mday = day;
|
||||||
struct stat buf;
|
// tm_.tm_hour = 0;
|
||||||
int err_no = stat(path.c_str(), &buf);
|
// tm_.tm_min = 0;
|
||||||
if (err_no != 0) {
|
// tm_.tm_sec = 0;
|
||||||
std::cout << strerror(err_no) << std::endl;
|
// tm_.tm_isdst = 0;
|
||||||
return SERVER_UNEXPECTED_ERROR;
|
// data_time = mktime(&tm_);
|
||||||
}
|
// return SERVER_SUCCESS;
|
||||||
|
//
|
||||||
update_time = buf.st_mtime;
|
//}
|
||||||
file_size = buf.st_size;
|
//
|
||||||
|
//}
|
||||||
return SERVER_SUCCESS;
|
//}
|
||||||
}
|
//}
|
||||||
|
|
||||||
ServerError
|
|
||||||
LicenseLibrary::GetFileMD5(const std::string &path, std::string &filemd5) {
|
|
||||||
|
|
||||||
if (!IsFileExistent(path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
|
||||||
|
|
||||||
filemd5.clear();
|
|
||||||
|
|
||||||
std::ifstream file(path.c_str(), std::ifstream::binary);
|
|
||||||
if (!file) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
MD5_CTX md5Context;
|
|
||||||
MD5_Init(&md5Context);
|
|
||||||
|
|
||||||
char buf[1024 * 16];
|
|
||||||
while (file.good()) {
|
|
||||||
file.read(buf, sizeof(buf));
|
|
||||||
MD5_Update(&md5Context, buf, file.gcount());
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char result[MD5_DIGEST_LENGTH];
|
|
||||||
MD5_Final(result, &md5Context);
|
|
||||||
|
|
||||||
char hex[35];
|
|
||||||
memset(hex, 0, sizeof(hex));
|
|
||||||
for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
|
|
||||||
sprintf(hex + i * 2, "%02X", result[i]);
|
|
||||||
}
|
|
||||||
hex[32] = '\0';
|
|
||||||
filemd5 = std::string(hex);
|
|
||||||
|
|
||||||
return SERVER_SUCCESS;
|
|
||||||
}
|
|
||||||
// Part 4: GPU Info File Serialization/Deserialization
|
|
||||||
ServerError
|
|
||||||
LicenseLibrary::GPUinfoFileSerialization(const std::string &path,
|
|
||||||
int device_count,
|
|
||||||
const std::map<int, std::string> &uuid_encrption_map) {
|
|
||||||
std::ofstream file(path);
|
|
||||||
boost::archive::binary_oarchive oa(file);
|
|
||||||
oa.register_type<GPUInfoFile>();
|
|
||||||
|
|
||||||
SerializedGPUInfoFile serialized_gpu_info_file;
|
|
||||||
|
|
||||||
serialized_gpu_info_file.set_gpu_info_file(new GPUInfoFile(device_count, uuid_encrption_map));
|
|
||||||
oa << serialized_gpu_info_file;
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
return SERVER_SUCCESS;
|
|
||||||
}
|
|
||||||
ServerError
|
|
||||||
LicenseLibrary::GPUinfoFileDeserialization(const std::string &path,
|
|
||||||
int &device_count,
|
|
||||||
std::map<int, std::string> &uuid_encrption_map) {
|
|
||||||
if (!IsFileExistent(path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
|
||||||
|
|
||||||
std::ifstream file(path);
|
|
||||||
boost::archive::binary_iarchive ia(file);
|
|
||||||
ia.register_type<GPUInfoFile>();
|
|
||||||
|
|
||||||
SerializedGPUInfoFile serialized_gpu_info_file;
|
|
||||||
ia >> serialized_gpu_info_file;
|
|
||||||
|
|
||||||
device_count = serialized_gpu_info_file.get_gpu_info_file()->get_device_count();
|
|
||||||
uuid_encrption_map = serialized_gpu_info_file.get_gpu_info_file()->get_uuid_encryption_map();
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
return SERVER_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerError
|
|
||||||
LicenseLibrary::GetDateTime(const char *cha, time_t &data_time) {
|
|
||||||
tm tm_;
|
|
||||||
int year, month, day;
|
|
||||||
sscanf(cha, "%d-%d-%d", &year, &month, &day);
|
|
||||||
tm_.tm_year = year - 1900;
|
|
||||||
tm_.tm_mon = month - 1;
|
|
||||||
tm_.tm_mday = day;
|
|
||||||
tm_.tm_hour = 0;
|
|
||||||
tm_.tm_min = 0;
|
|
||||||
tm_.tm_sec = 0;
|
|
||||||
tm_.tm_isdst = 0;
|
|
||||||
data_time = mktime(&tm_);
|
|
||||||
return SERVER_SUCCESS;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,105 +1,105 @@
|
||||||
#pragma once
|
//#pragma once
|
||||||
|
//
|
||||||
#include "LicenseFile.h"
|
//#include "LicenseFile.h"
|
||||||
#include "GPUInfoFile.h"
|
//#include "GPUInfoFile.h"
|
||||||
|
//
|
||||||
#include "utils/Error.h"
|
//#include "utils/Error.h"
|
||||||
|
//
|
||||||
#include <boost/asio.hpp>
|
//#include <boost/asio.hpp>
|
||||||
#include <boost/thread.hpp>
|
//#include <boost/thread.hpp>
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
//#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
//
|
||||||
#include <vector>
|
//#include <vector>
|
||||||
#include <map>
|
//#include <map>
|
||||||
#include <time.h>
|
//#include <time.h>
|
||||||
|
//
|
||||||
|
//
|
||||||
namespace zilliz {
|
//namespace zilliz {
|
||||||
namespace milvus {
|
//namespace milvus {
|
||||||
namespace server {
|
//namespace server {
|
||||||
|
//
|
||||||
class LicenseLibrary {
|
//class LicenseLibrary {
|
||||||
public:
|
// public:
|
||||||
// Part 0: File check
|
// // Part 0: File check
|
||||||
static bool
|
// static bool
|
||||||
IsFileExistent(const std::string &path);
|
// IsFileExistent(const std::string &path);
|
||||||
|
//
|
||||||
// Part 1: Get GPU Info
|
// // Part 1: Get GPU Info
|
||||||
static ServerError
|
|
||||||
GetDeviceCount(int &device_count);
|
|
||||||
|
|
||||||
static ServerError
|
|
||||||
GetUUID(int device_count, std::vector<std::string> &uuid_array);
|
|
||||||
|
|
||||||
static ServerError
|
|
||||||
GetUUIDMD5(int device_count, std::vector<std::string> &uuid_array, std::vector<std::string> &md5_array);
|
|
||||||
|
|
||||||
|
|
||||||
static ServerError
|
|
||||||
GetUUIDSHA256(const int &device_count,
|
|
||||||
std::vector<std::string> &uuid_array,
|
|
||||||
std::vector<std::string> &sha_array);
|
|
||||||
|
|
||||||
static ServerError
|
|
||||||
GetSystemTime(time_t &system_time);
|
|
||||||
|
|
||||||
// Part 2: Handle License File
|
|
||||||
static ServerError
|
|
||||||
LicenseFileSerialization(const std::string &path,
|
|
||||||
int device_count,
|
|
||||||
const std::map<int, std::string> &uuid_encrption_map,
|
|
||||||
time_t starting_time,
|
|
||||||
time_t end_time);
|
|
||||||
|
|
||||||
static ServerError
|
|
||||||
LicenseFileDeserialization(const std::string &path,
|
|
||||||
int &device_count,
|
|
||||||
std::map<int, std::string> &uuid_encrption_map,
|
|
||||||
time_t &starting_time,
|
|
||||||
time_t &end_time);
|
|
||||||
|
|
||||||
// static ServerError
|
// static ServerError
|
||||||
// SecretFileSerialization(const std::string &path,
|
// GetDeviceCount(int &device_count);
|
||||||
// const time_t &update_time,
|
|
||||||
// const off_t &file_size,
|
|
||||||
// const time_t &starting_time,
|
|
||||||
// const time_t &end_time,
|
|
||||||
// const std::string &file_md5);
|
|
||||||
//
|
//
|
||||||
// static ServerError
|
// static ServerError
|
||||||
// SecretFileDeserialization(const std::string &path,
|
// GetUUID(int device_count, std::vector<std::string> &uuid_array);
|
||||||
// time_t &update_time,
|
//
|
||||||
// off_t &file_size,
|
// static ServerError
|
||||||
|
// GetUUIDMD5(int device_count, std::vector<std::string> &uuid_array, std::vector<std::string> &md5_array);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// static ServerError
|
||||||
|
// GetUUIDSHA256(const int &device_count,
|
||||||
|
// std::vector<std::string> &uuid_array,
|
||||||
|
// std::vector<std::string> &sha_array);
|
||||||
|
//
|
||||||
|
// static ServerError
|
||||||
|
// GetSystemTime(time_t &system_time);
|
||||||
|
//
|
||||||
|
// // Part 2: Handle License File
|
||||||
|
// static ServerError
|
||||||
|
// LicenseFileSerialization(const std::string &path,
|
||||||
|
// int device_count,
|
||||||
|
// const std::map<int, std::string> &uuid_encrption_map,
|
||||||
|
// time_t starting_time,
|
||||||
|
// time_t end_time);
|
||||||
|
//
|
||||||
|
// static ServerError
|
||||||
|
// LicenseFileDeserialization(const std::string &path,
|
||||||
|
// int &device_count,
|
||||||
|
// std::map<int, std::string> &uuid_encrption_map,
|
||||||
// time_t &starting_time,
|
// time_t &starting_time,
|
||||||
// time_t &end_time,
|
// time_t &end_time);
|
||||||
// std::string &file_md5);
|
//
|
||||||
|
//// static ServerError
|
||||||
// Part 3: File attribute: UpdateTime Time/ Size/ MD5
|
//// SecretFileSerialization(const std::string &path,
|
||||||
static ServerError
|
//// const time_t &update_time,
|
||||||
GetFileUpdateTimeAndSize(const std::string &path, time_t &update_time, off_t &file_size);
|
//// const off_t &file_size,
|
||||||
|
//// const time_t &starting_time,
|
||||||
static ServerError
|
//// const time_t &end_time,
|
||||||
GetFileMD5(const std::string &path, std::string &filemd5);
|
//// const std::string &file_md5);
|
||||||
|
////
|
||||||
// Part 4: GPU Info File Serialization/Deserialization
|
//// static ServerError
|
||||||
static ServerError
|
//// SecretFileDeserialization(const std::string &path,
|
||||||
GPUinfoFileSerialization(const std::string &path,
|
//// time_t &update_time,
|
||||||
int device_count,
|
//// off_t &file_size,
|
||||||
const std::map<int, std::string> &uuid_encrption_map);
|
//// time_t &starting_time,
|
||||||
static ServerError
|
//// time_t &end_time,
|
||||||
GPUinfoFileDeserialization(const std::string &path,
|
//// std::string &file_md5);
|
||||||
int &device_count,
|
//
|
||||||
std::map<int, std::string> &uuid_encrption_map);
|
// // Part 3: File attribute: UpdateTime Time/ Size/ MD5
|
||||||
|
// static ServerError
|
||||||
static ServerError
|
// GetFileUpdateTimeAndSize(const std::string &path, time_t &update_time, off_t &file_size);
|
||||||
GetDateTime(const char *cha, time_t &data_time);
|
//
|
||||||
|
// static ServerError
|
||||||
|
// GetFileMD5(const std::string &path, std::string &filemd5);
|
||||||
private:
|
//
|
||||||
static constexpr int sha256_length_ = 32;
|
// // Part 4: GPU Info File Serialization/Deserialization
|
||||||
};
|
// static ServerError
|
||||||
|
// GPUinfoFileSerialization(const std::string &path,
|
||||||
|
// int device_count,
|
||||||
}
|
// const std::map<int, std::string> &uuid_encrption_map);
|
||||||
}
|
// static ServerError
|
||||||
}
|
// GPUinfoFileDeserialization(const std::string &path,
|
||||||
|
// int &device_count,
|
||||||
|
// std::map<int, std::string> &uuid_encrption_map);
|
||||||
|
//
|
||||||
|
// static ServerError
|
||||||
|
// GetDateTime(const char *cha, time_t &data_time);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// private:
|
||||||
|
// static constexpr int sha256_length_ = 32;
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
//}
|
||||||
|
//}
|
||||||
|
|
|
@ -22,40 +22,21 @@ class MetricsBase{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ServerError Init() {};
|
virtual ServerError Init() {};
|
||||||
virtual void AddGroupSuccessTotalIncrement(double value = 1) {};
|
|
||||||
virtual void AddGroupFailTotalIncrement(double value = 1) {};
|
|
||||||
virtual void HasGroupSuccessTotalIncrement(double value = 1) {};
|
|
||||||
virtual void HasGroupFailTotalIncrement(double value = 1) {};
|
|
||||||
virtual void GetGroupSuccessTotalIncrement(double value = 1) {};
|
|
||||||
virtual void GetGroupFailTotalIncrement(double value = 1) {};
|
|
||||||
virtual void GetGroupFilesSuccessTotalIncrement(double value = 1) {};
|
|
||||||
virtual void GetGroupFilesFailTotalIncrement(double value = 1) {};
|
|
||||||
virtual void AddVectorsSuccessTotalIncrement(double value = 1) {};
|
virtual void AddVectorsSuccessTotalIncrement(double value = 1) {};
|
||||||
virtual void AddVectorsFailTotalIncrement(double value = 1) {};
|
virtual void AddVectorsFailTotalIncrement(double value = 1) {};
|
||||||
virtual void AddVectorsDurationHistogramOberve(double value) {};
|
virtual void AddVectorsDurationHistogramOberve(double value) {};
|
||||||
virtual void SearchSuccessTotalIncrement(double value = 1) {};
|
|
||||||
virtual void SearchFailTotalIncrement(double value = 1) {};
|
|
||||||
virtual void SearchDurationHistogramObserve(double value) {};
|
|
||||||
virtual void RawFileSizeHistogramObserve(double value) {};
|
virtual void RawFileSizeHistogramObserve(double value) {};
|
||||||
virtual void IndexFileSizeHistogramObserve(double value) {};
|
virtual void IndexFileSizeHistogramObserve(double value) {};
|
||||||
virtual void BuildIndexDurationSecondsHistogramObserve(double value) {};
|
virtual void BuildIndexDurationSecondsHistogramObserve(double value) {};
|
||||||
virtual void AllBuildIndexDurationSecondsHistogramObserve(double value) {};
|
|
||||||
virtual void CacheUsageGaugeIncrement(double value = 1) {};
|
|
||||||
virtual void CacheUsageGaugeDecrement(double value = 1) {};
|
|
||||||
virtual void CacheUsageGaugeSet(double value) {};
|
virtual void CacheUsageGaugeSet(double value) {};
|
||||||
virtual void MetaVisitTotalIncrement(double value = 1) {};
|
|
||||||
virtual void MetaVisitDurationSecondsHistogramObserve(double value) {};
|
|
||||||
virtual void MemUsagePercentGaugeSet(double value) {};
|
|
||||||
virtual void MemUsagePercentGaugeIncrement(double value = 1) {};
|
|
||||||
virtual void MemUsagePercentGaugeDecrement(double value = 1) {};
|
|
||||||
virtual void MemUsageTotalGaugeSet(double value) {};
|
|
||||||
virtual void MemUsageTotalGaugeIncrement(double value = 1) {};
|
|
||||||
virtual void MemUsageTotalGaugeDecrement(double value = 1) {};
|
|
||||||
virtual void MetaAccessTotalIncrement(double value = 1) {};
|
virtual void MetaAccessTotalIncrement(double value = 1) {};
|
||||||
virtual void MetaAccessDurationSecondsHistogramObserve(double value) {};
|
virtual void MetaAccessDurationSecondsHistogramObserve(double value) {};
|
||||||
virtual void FaissDiskLoadDurationSecondsHistogramObserve(double value) {};
|
virtual void FaissDiskLoadDurationSecondsHistogramObserve(double value) {};
|
||||||
virtual void FaissDiskLoadSizeBytesHistogramObserve(double value) {};
|
virtual void FaissDiskLoadSizeBytesHistogramObserve(double value) {};
|
||||||
virtual void FaissDiskLoadIOSpeedHistogramObserve(double value) {};
|
|
||||||
virtual void CacheAccessTotalIncrement(double value = 1) {};
|
virtual void CacheAccessTotalIncrement(double value = 1) {};
|
||||||
virtual void MemTableMergeDurationSecondsHistogramObserve(double value) {};
|
virtual void MemTableMergeDurationSecondsHistogramObserve(double value) {};
|
||||||
virtual void SearchIndexDataDurationSecondsHistogramObserve(double value) {};
|
virtual void SearchIndexDataDurationSecondsHistogramObserve(double value) {};
|
||||||
|
|
|
@ -60,9 +60,6 @@ PrometheusMetrics::GPUPercentGaugeSet() {
|
||||||
if(!startup_) return;
|
if(!startup_) return;
|
||||||
int numDevide = server::SystemInfo::GetInstance().num_device();
|
int numDevide = server::SystemInfo::GetInstance().num_device();
|
||||||
std::vector<unsigned int> values = server::SystemInfo::GetInstance().GPUPercent();
|
std::vector<unsigned int> values = server::SystemInfo::GetInstance().GPUPercent();
|
||||||
// for (int i = 0; i < numDevide; ++i) {
|
|
||||||
// GPU_percent_gauges_[i].Set(static_cast<double>(values[i]));
|
|
||||||
// }
|
|
||||||
if(numDevide >= 1) GPU0_percent_gauge_.Set(static_cast<double>(values[0]));
|
if(numDevide >= 1) GPU0_percent_gauge_.Set(static_cast<double>(values[0]));
|
||||||
if(numDevide >= 2) GPU1_percent_gauge_.Set(static_cast<double>(values[1]));
|
if(numDevide >= 2) GPU1_percent_gauge_.Set(static_cast<double>(values[1]));
|
||||||
if(numDevide >= 3) GPU2_percent_gauge_.Set(static_cast<double>(values[2]));
|
if(numDevide >= 3) GPU2_percent_gauge_.Set(static_cast<double>(values[2]));
|
||||||
|
@ -77,13 +74,10 @@ PrometheusMetrics::GPUPercentGaugeSet() {
|
||||||
|
|
||||||
void PrometheusMetrics::GPUMemoryUsageGaugeSet() {
|
void PrometheusMetrics::GPUMemoryUsageGaugeSet() {
|
||||||
if(!startup_) return;
|
if(!startup_) return;
|
||||||
int numDevide = server::SystemInfo::GetInstance().num_device();
|
|
||||||
std::vector<unsigned long long> values = server::SystemInfo::GetInstance().GPUMemoryUsed();
|
std::vector<unsigned long long> values = server::SystemInfo::GetInstance().GPUMemoryUsed();
|
||||||
constexpr unsigned long long MtoB = 1024*1024;
|
constexpr unsigned long long MtoB = 1024*1024;
|
||||||
int numDevice = values.size();
|
int numDevice = values.size();
|
||||||
// for (int i = 0; i < numDevice; ++i) {
|
|
||||||
// GPU_memory_usage_gauges_[i].Set(values[i]/MtoB);
|
|
||||||
// }
|
|
||||||
if(numDevice >=1) GPU0_memory_usage_gauge_.Set(values[0]/MtoB);
|
if(numDevice >=1) GPU0_memory_usage_gauge_.Set(values[0]/MtoB);
|
||||||
if(numDevice >=2) GPU1_memory_usage_gauge_.Set(values[1]/MtoB);
|
if(numDevice >=2) GPU1_memory_usage_gauge_.Set(values[1]/MtoB);
|
||||||
if(numDevice >=3) GPU2_memory_usage_gauge_.Set(values[2]/MtoB);
|
if(numDevice >=3) GPU2_memory_usage_gauge_.Set(values[2]/MtoB);
|
||||||
|
@ -146,21 +140,6 @@ void PrometheusMetrics::OctetsSet() {
|
||||||
outoctets_gauge_.Set((in_and_out_octets.second-old_outoctets)/total_second);
|
outoctets_gauge_.Set((in_and_out_octets.second-old_outoctets)/total_second);
|
||||||
}
|
}
|
||||||
|
|
||||||
//void PrometheusMetrics::GpuPercentInit() {
|
|
||||||
// int num_device = SystemInfo::GetInstance().num_device();
|
|
||||||
// constexpr char device_number[] = "DeviceNum";
|
|
||||||
// for(int i = 0; i < num_device; ++ i) {
|
|
||||||
// GPU_percent_gauges_.emplace_back(GPU_percent_.Add({{device_number,std::to_string(i)}}));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
//void PrometheusMetrics::GpuMemoryInit() {
|
|
||||||
// int num_device = SystemInfo::GetInstance().num_device();
|
|
||||||
// constexpr char device_number[] = "DeviceNum";
|
|
||||||
// for(int i = 0; i < num_device; ++ i) {
|
|
||||||
// GPU_memory_usage_gauges_.emplace_back(GPU_memory_usage_.Add({{device_number,std::to_string(i)}}));
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,10 +34,6 @@ class PrometheusMetrics: public MetricsBase {
|
||||||
public:
|
public:
|
||||||
static PrometheusMetrics &
|
static PrometheusMetrics &
|
||||||
GetInstance() {
|
GetInstance() {
|
||||||
// switch(MetricCollectorType) {
|
|
||||||
// case: prometheus::
|
|
||||||
// static
|
|
||||||
// }
|
|
||||||
static PrometheusMetrics instance;
|
static PrometheusMetrics instance;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
@ -49,46 +45,21 @@ class PrometheusMetrics: public MetricsBase {
|
||||||
std::shared_ptr<prometheus::Exposer> exposer_ptr_;
|
std::shared_ptr<prometheus::Exposer> exposer_ptr_;
|
||||||
std::shared_ptr<prometheus::Registry> registry_ = std::make_shared<prometheus::Registry>();
|
std::shared_ptr<prometheus::Registry> registry_ = std::make_shared<prometheus::Registry>();
|
||||||
bool startup_ = false;
|
bool startup_ = false;
|
||||||
// void GpuPercentInit();
|
|
||||||
// void GpuMemoryInit();
|
|
||||||
public:
|
public:
|
||||||
|
void SetStartup(bool startup) {startup_ = startup;};
|
||||||
void AddGroupSuccessTotalIncrement(double value = 1.0) override { if(startup_) add_group_success_total_.Increment(value);};
|
|
||||||
void AddGroupFailTotalIncrement(double value = 1.0) override { if(startup_) add_group_fail_total_.Increment(value);};
|
|
||||||
void HasGroupSuccessTotalIncrement(double value = 1.0) override { if(startup_) has_group_success_total_.Increment(value);};
|
|
||||||
void HasGroupFailTotalIncrement(double value = 1.0) override { if(startup_) has_group_fail_total_.Increment(value);};
|
|
||||||
void GetGroupSuccessTotalIncrement(double value = 1.0) override { if(startup_) get_group_success_total_.Increment(value);};
|
|
||||||
void GetGroupFailTotalIncrement(double value = 1.0) override { if(startup_) get_group_fail_total_.Increment(value);};
|
|
||||||
void GetGroupFilesSuccessTotalIncrement(double value = 1.0) override { if(startup_) get_group_files_success_total_.Increment(value);};
|
|
||||||
void GetGroupFilesFailTotalIncrement(double value = 1.0) override { if(startup_) get_group_files_fail_total_.Increment(value);};
|
|
||||||
void AddVectorsSuccessTotalIncrement(double value = 1.0) override { if(startup_) add_vectors_success_total_.Increment(value);};
|
void AddVectorsSuccessTotalIncrement(double value = 1.0) override { if(startup_) add_vectors_success_total_.Increment(value);};
|
||||||
void AddVectorsFailTotalIncrement(double value = 1.0) override { if(startup_) add_vectors_fail_total_.Increment(value);};
|
void AddVectorsFailTotalIncrement(double value = 1.0) override { if(startup_) add_vectors_fail_total_.Increment(value);};
|
||||||
void AddVectorsDurationHistogramOberve(double value) override { if(startup_) add_vectors_duration_histogram_.Observe(value);};
|
void AddVectorsDurationHistogramOberve(double value) override { if(startup_) add_vectors_duration_histogram_.Observe(value);};
|
||||||
void SearchSuccessTotalIncrement(double value = 1.0) override { if(startup_) search_success_total_.Increment(value);};
|
|
||||||
void SearchFailTotalIncrement(double value = 1.0) override { if(startup_) search_fail_total_.Increment(value); };
|
|
||||||
void SearchDurationHistogramObserve(double value) override { if(startup_) search_duration_histogram_.Observe(value);};
|
|
||||||
void RawFileSizeHistogramObserve(double value) override { if(startup_) raw_files_size_histogram_.Observe(value);};
|
void RawFileSizeHistogramObserve(double value) override { if(startup_) raw_files_size_histogram_.Observe(value);};
|
||||||
void IndexFileSizeHistogramObserve(double value) override { if(startup_) index_files_size_histogram_.Observe(value);};
|
void IndexFileSizeHistogramObserve(double value) override { if(startup_) index_files_size_histogram_.Observe(value);};
|
||||||
void BuildIndexDurationSecondsHistogramObserve(double value) override { if(startup_) build_index_duration_seconds_histogram_.Observe(value);};
|
void BuildIndexDurationSecondsHistogramObserve(double value) override { if(startup_) build_index_duration_seconds_histogram_.Observe(value);};
|
||||||
void AllBuildIndexDurationSecondsHistogramObserve(double value) override { if(startup_) all_build_index_duration_seconds_histogram_.Observe(value);};
|
|
||||||
void CacheUsageGaugeIncrement(double value = 1.0) override { if(startup_) cache_usage_gauge_.Increment(value);};
|
|
||||||
void CacheUsageGaugeDecrement(double value = 1.0) override { if(startup_) cache_usage_gauge_.Decrement(value);};
|
|
||||||
void CacheUsageGaugeSet(double value) override { if(startup_) cache_usage_gauge_.Set(value);};
|
void CacheUsageGaugeSet(double value) override { if(startup_) cache_usage_gauge_.Set(value);};
|
||||||
// void MetaVisitTotalIncrement(double value = 1.0) override { meta_visit_total_.Increment(value);};
|
|
||||||
// void MetaVisitDurationSecondsHistogramObserve(double value) override { meta_visit_duration_seconds_histogram_.Observe(value);};
|
|
||||||
void MemUsagePercentGaugeSet(double value) override { if(startup_) mem_usage_percent_gauge_.Set(value);};
|
|
||||||
void MemUsagePercentGaugeIncrement(double value = 1.0) override { if(startup_) mem_usage_percent_gauge_.Increment(value);};
|
|
||||||
void MemUsagePercentGaugeDecrement(double value = 1.0) override { if(startup_) mem_usage_percent_gauge_.Decrement(value);};
|
|
||||||
void MemUsageTotalGaugeSet(double value) override { if(startup_) mem_usage_total_gauge_.Set(value);};
|
|
||||||
void MemUsageTotalGaugeIncrement(double value = 1.0) override { if(startup_) mem_usage_total_gauge_.Increment(value);};
|
|
||||||
void MemUsageTotalGaugeDecrement(double value = 1.0) override { if(startup_) mem_usage_total_gauge_.Decrement(value);};
|
|
||||||
|
|
||||||
void MetaAccessTotalIncrement(double value = 1) override { if(startup_) meta_access_total_.Increment(value);};
|
void MetaAccessTotalIncrement(double value = 1) override { if(startup_) meta_access_total_.Increment(value);};
|
||||||
void MetaAccessDurationSecondsHistogramObserve(double value) override { if(startup_) meta_access_duration_seconds_histogram_.Observe(value);};
|
void MetaAccessDurationSecondsHistogramObserve(double value) override { if(startup_) meta_access_duration_seconds_histogram_.Observe(value);};
|
||||||
|
|
||||||
void FaissDiskLoadDurationSecondsHistogramObserve(double value) override { if(startup_) faiss_disk_load_duration_seconds_histogram_.Observe(value);};
|
void FaissDiskLoadDurationSecondsHistogramObserve(double value) override { if(startup_) faiss_disk_load_duration_seconds_histogram_.Observe(value);};
|
||||||
void FaissDiskLoadSizeBytesHistogramObserve(double value) override { if(startup_) faiss_disk_load_size_bytes_histogram_.Observe(value);};
|
void FaissDiskLoadSizeBytesHistogramObserve(double value) override { if(startup_) faiss_disk_load_size_bytes_histogram_.Observe(value);};
|
||||||
// void FaissDiskLoadIOSpeedHistogramObserve(double value) { if(startup_) faiss_disk_load_IO_speed_histogram_.Observe(value);};
|
|
||||||
void FaissDiskLoadIOSpeedGaugeSet(double value) override { if(startup_) faiss_disk_load_IO_speed_gauge_.Set(value);};
|
void FaissDiskLoadIOSpeedGaugeSet(double value) override { if(startup_) faiss_disk_load_IO_speed_gauge_.Set(value);};
|
||||||
|
|
||||||
void CacheAccessTotalIncrement(double value = 1) override { if(startup_) cache_access_total_.Increment(value);};
|
void CacheAccessTotalIncrement(double value = 1) override { if(startup_) cache_access_total_.Increment(value);};
|
||||||
|
|
|
@ -135,46 +135,6 @@ SystemInfo::CPUPercent() {
|
||||||
return percent;
|
return percent;
|
||||||
}
|
}
|
||||||
|
|
||||||
//std::unordered_map<int,std::vector<double>>
|
|
||||||
//SystemInfo::GetGPUMemPercent(){
|
|
||||||
// // return GPUID: MEM%
|
|
||||||
//
|
|
||||||
// //write GPU info to a file
|
|
||||||
// system("nvidia-smi pmon -c 1 > GPUInfo.txt");
|
|
||||||
// int pid = (int)getpid();
|
|
||||||
//
|
|
||||||
// //parse line
|
|
||||||
// std::ifstream read_file;
|
|
||||||
// read_file.open("GPUInfo.txt");
|
|
||||||
// std::string line;
|
|
||||||
// while(getline(read_file, line)){
|
|
||||||
// std::vector<std::string> words = split(line);
|
|
||||||
// // 0 1 2 3 4 5 6 7
|
|
||||||
// //words stand for gpuindex, pid, type, sm, mem, enc, dec, command respectively
|
|
||||||
// if(std::stoi(words[1]) != pid) continue;
|
|
||||||
// int GPUindex = std::stoi(words[0]);
|
|
||||||
// double sm_percent = std::stod(words[3]);
|
|
||||||
// double mem_percent = std::stod(words[4]);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
|
|
||||||
//std::vector<std::string>
|
|
||||||
//SystemInfo::split(std::string input) {
|
|
||||||
// std::vector<std::string> words;
|
|
||||||
// input += " ";
|
|
||||||
// int word_start = 0;
|
|
||||||
// for (int i = 0; i < input.size(); ++i) {
|
|
||||||
// if(input[i] != ' ') continue;
|
|
||||||
// if(input[i] == ' ') {
|
|
||||||
// word_start = i + 1;
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// words.push_back(input.substr(word_start,i-word_start));
|
|
||||||
// }
|
|
||||||
// return words;
|
|
||||||
//}
|
|
||||||
|
|
||||||
std::vector<unsigned int>
|
std::vector<unsigned int>
|
||||||
SystemInfo::GPUPercent() {
|
SystemInfo::GPUPercent() {
|
||||||
|
|
|
@ -59,8 +59,6 @@ class SystemInfo {
|
||||||
double MemoryPercent();
|
double MemoryPercent();
|
||||||
double CPUPercent();
|
double CPUPercent();
|
||||||
std::pair<unsigned long long , unsigned long long > Octets();
|
std::pair<unsigned long long , unsigned long long > Octets();
|
||||||
// std::unordered_map<int,std::vector<double>> GetGPUMemPercent() {};
|
|
||||||
// std::vector<std::string> split(std::string input) {};
|
|
||||||
std::vector<unsigned int> GPUPercent();
|
std::vector<unsigned int> GPUPercent();
|
||||||
std::vector<unsigned long long> GPUMemoryUsed();
|
std::vector<unsigned long long> GPUMemoryUsed();
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ bool CommonUtil::GetSystemAvailableThreads(unsigned int &threadCnt) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CommonUtil::IsDirectoryExit(const std::string &path)
|
bool CommonUtil::IsDirectoryExist(const std::string &path)
|
||||||
{
|
{
|
||||||
DIR *dp = nullptr;
|
DIR *dp = nullptr;
|
||||||
if ((dp = opendir(path.c_str())) == nullptr) {
|
if ((dp = opendir(path.c_str())) == nullptr) {
|
||||||
|
@ -182,7 +182,7 @@ void CommonUtil::ConvertTime(time_t time_integer, tm &time_struct) {
|
||||||
memcpy(&time_struct, t_m, sizeof(tm));
|
memcpy(&time_struct, t_m, sizeof(tm));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConvertTime(tm time_struct, time_t &time_integer) {
|
void CommonUtil::ConvertTime(tm time_struct, time_t &time_integer) {
|
||||||
time_integer = mktime(&time_struct);
|
time_integer = mktime(&time_struct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ class CommonUtil {
|
||||||
static bool GetSystemAvailableThreads(unsigned int &threadCnt);
|
static bool GetSystemAvailableThreads(unsigned int &threadCnt);
|
||||||
|
|
||||||
static bool IsFileExist(const std::string &path);
|
static bool IsFileExist(const std::string &path);
|
||||||
static bool IsDirectoryExit(const std::string &path);
|
static bool IsDirectoryExist(const std::string &path);
|
||||||
static ServerError CreateDirectory(const std::string &path);
|
static ServerError CreateDirectory(const std::string &path);
|
||||||
static ServerError DeleteDirectory(const std::string &path);
|
static ServerError DeleteDirectory(const std::string &path);
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,6 @@ set(unittest_libs
|
||||||
add_subdirectory(server)
|
add_subdirectory(server)
|
||||||
add_subdirectory(db)
|
add_subdirectory(db)
|
||||||
add_subdirectory(faiss_wrapper)
|
add_subdirectory(faiss_wrapper)
|
||||||
add_subdirectory(license)
|
#add_subdirectory(license)
|
||||||
add_subdirectory(metrics)
|
add_subdirectory(metrics)
|
||||||
add_subdirectory(storage)
|
add_subdirectory(storage)
|
|
@ -1,184 +1,184 @@
|
||||||
|
////
|
||||||
|
//// Created by zilliz on 19-5-13.
|
||||||
|
////
|
||||||
//
|
//
|
||||||
// Created by zilliz on 19-5-13.
|
//#include "utils/Log.h"
|
||||||
|
//#include "license/LicenseCheck.h"
|
||||||
|
//#include "utils/Error.h"
|
||||||
|
//
|
||||||
|
//#include <gtest/gtest.h>
|
||||||
|
//#include <iostream>
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//using namespace zilliz::milvus;
|
||||||
|
//
|
||||||
|
//TEST(LicenseLibraryTest, CHECK_TEST) {
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// server::ServerError err;
|
||||||
|
// // 1. Set license file name
|
||||||
|
// std::string license_file_path("/tmp/milvus/abc.license");
|
||||||
|
//
|
||||||
|
// // 2. Legality check
|
||||||
|
// err = server::LicenseCheck::LegalityCheck(license_file_path);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//TEST(LicenseLibraryTest, CHECK_ERROR1_TEST){
|
||||||
|
//
|
||||||
|
// server::ServerError err;
|
||||||
|
// // 1. Set license file name
|
||||||
|
// std::string license_file_path("/tmp/milvus/abc");
|
||||||
|
//
|
||||||
|
// // 2. Legality check
|
||||||
|
// err = server::LicenseCheck::LegalityCheck(license_file_path);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//TEST(LicenseLibraryTest, CHECK_ERROR2_TEST){
|
||||||
|
//
|
||||||
|
// server::ServerError err;
|
||||||
|
// // 1. Set license file name
|
||||||
|
// std::string license_file_path("/tmp/milvus/abc.license");
|
||||||
|
//
|
||||||
|
// // 2. Define output var
|
||||||
|
// int device_count;
|
||||||
|
// std::map<int, std::string> uuid_encryption_map;
|
||||||
|
// time_t starting_time;
|
||||||
|
// time_t end_time;
|
||||||
|
//
|
||||||
|
// // 3. Read License File
|
||||||
|
// err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||||
|
// device_count,
|
||||||
|
// uuid_encryption_map,
|
||||||
|
// starting_time,
|
||||||
|
// end_time);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
// // 4. Change device count
|
||||||
|
// ++device_count;
|
||||||
|
// err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
||||||
|
// device_count,
|
||||||
|
// uuid_encryption_map,
|
||||||
|
// starting_time,
|
||||||
|
// end_time);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
// // 5. Legality check
|
||||||
|
// err = server::LicenseCheck::LegalityCheck(license_file_path);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//TEST(LicenseLibraryTest, CHECK_ERROR3_TEST){
|
||||||
|
//
|
||||||
|
// server::ServerError err;
|
||||||
|
// // 1. Set license file name
|
||||||
|
// std::string license_file_path("/tmp/milvus/abc.license");
|
||||||
|
//
|
||||||
|
// // 2. Define output var
|
||||||
|
// int device_count;
|
||||||
|
// std::map<int, std::string> uuid_encryption_map;
|
||||||
|
// time_t starting_time;
|
||||||
|
// time_t end_time;
|
||||||
|
//
|
||||||
|
// // 3. Read License File
|
||||||
|
// err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||||
|
// device_count,
|
||||||
|
// uuid_encryption_map,
|
||||||
|
// starting_time,
|
||||||
|
// end_time);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
// // 4. Change device count
|
||||||
|
// if(device_count) uuid_encryption_map[0]+="u";
|
||||||
|
// err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
||||||
|
// device_count,
|
||||||
|
// uuid_encryption_map,
|
||||||
|
// starting_time,
|
||||||
|
// end_time);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
// // 5. Legality check
|
||||||
|
// err = server::LicenseCheck::LegalityCheck(license_file_path);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//TEST(LicenseLibraryTest, CHECK_ERROR4_1_TEST){
|
||||||
|
//
|
||||||
|
// server::ServerError err;
|
||||||
|
// // 1. Set license file name
|
||||||
|
// std::string license_file_path("/tmp/milvus/abc.license");
|
||||||
|
//
|
||||||
|
// // 2. Define output var
|
||||||
|
// int device_count;
|
||||||
|
// std::map<int, std::string> uuid_encryption_map;
|
||||||
|
// time_t starting_time;
|
||||||
|
// time_t end_time;
|
||||||
|
//
|
||||||
|
// // 3. Read License File
|
||||||
|
// err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||||
|
// device_count,
|
||||||
|
// uuid_encryption_map,
|
||||||
|
// starting_time,
|
||||||
|
// end_time);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
// // 4. Change starting time
|
||||||
|
// time_t system_time;
|
||||||
|
// err = server::LicenseLibrary::GetSystemTime(system_time);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
// system_time+=60*60*24;
|
||||||
|
//
|
||||||
|
// err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
||||||
|
// device_count,
|
||||||
|
// uuid_encryption_map,
|
||||||
|
// system_time,
|
||||||
|
// end_time);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
// // 5. Legality check
|
||||||
|
// err = server::LicenseCheck::LegalityCheck(license_file_path);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//TEST(LicenseLibraryTest, CHECK_ERROR4_2_TEST){
|
||||||
|
//
|
||||||
|
// server::ServerError err;
|
||||||
|
// // 1. Set license file name
|
||||||
|
// std::string license_file_path("/tmp/milvus/abc.license");
|
||||||
|
//
|
||||||
|
// // 2. Define output var
|
||||||
|
// int device_count;
|
||||||
|
// std::map<int, std::string> uuid_encryption_map;
|
||||||
|
// time_t starting_time;
|
||||||
|
// time_t end_time;
|
||||||
|
//
|
||||||
|
// // 3. Read License File
|
||||||
|
// err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||||
|
// device_count,
|
||||||
|
// uuid_encryption_map,
|
||||||
|
// starting_time,
|
||||||
|
// end_time);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
// // 4. Change end time
|
||||||
|
// time_t system_time;
|
||||||
|
// err = server::LicenseLibrary::GetSystemTime(system_time);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
// system_time-=100;
|
||||||
|
//
|
||||||
|
// err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
||||||
|
// device_count,
|
||||||
|
// uuid_encryption_map,
|
||||||
|
// starting_time,
|
||||||
|
// system_time);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
// // 5. Legality check
|
||||||
|
// err = server::LicenseCheck::LegalityCheck(license_file_path);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//}
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "utils/Log.h"
|
|
||||||
#include "license/LicenseCheck.h"
|
|
||||||
#include "utils/Error.h"
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace zilliz::milvus;
|
|
||||||
|
|
||||||
TEST(LicenseLibraryTest, CHECK_TEST) {
|
|
||||||
|
|
||||||
|
|
||||||
server::ServerError err;
|
|
||||||
// 1. Set license file name
|
|
||||||
std::string license_file_path("/tmp/milvus/abc.license");
|
|
||||||
|
|
||||||
// 2. Legality check
|
|
||||||
err = server::LicenseCheck::LegalityCheck(license_file_path);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(LicenseLibraryTest, CHECK_ERROR1_TEST){
|
|
||||||
|
|
||||||
server::ServerError err;
|
|
||||||
// 1. Set license file name
|
|
||||||
std::string license_file_path("/tmp/milvus/abc");
|
|
||||||
|
|
||||||
// 2. Legality check
|
|
||||||
err = server::LicenseCheck::LegalityCheck(license_file_path);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(LicenseLibraryTest, CHECK_ERROR2_TEST){
|
|
||||||
|
|
||||||
server::ServerError err;
|
|
||||||
// 1. Set license file name
|
|
||||||
std::string license_file_path("/tmp/milvus/abc.license");
|
|
||||||
|
|
||||||
// 2. Define output var
|
|
||||||
int device_count;
|
|
||||||
std::map<int, std::string> uuid_encryption_map;
|
|
||||||
time_t starting_time;
|
|
||||||
time_t end_time;
|
|
||||||
|
|
||||||
// 3. Read License File
|
|
||||||
err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
|
||||||
device_count,
|
|
||||||
uuid_encryption_map,
|
|
||||||
starting_time,
|
|
||||||
end_time);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
// 4. Change device count
|
|
||||||
++device_count;
|
|
||||||
err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
|
||||||
device_count,
|
|
||||||
uuid_encryption_map,
|
|
||||||
starting_time,
|
|
||||||
end_time);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
// 5. Legality check
|
|
||||||
err = server::LicenseCheck::LegalityCheck(license_file_path);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(LicenseLibraryTest, CHECK_ERROR3_TEST){
|
|
||||||
|
|
||||||
server::ServerError err;
|
|
||||||
// 1. Set license file name
|
|
||||||
std::string license_file_path("/tmp/milvus/abc.license");
|
|
||||||
|
|
||||||
// 2. Define output var
|
|
||||||
int device_count;
|
|
||||||
std::map<int, std::string> uuid_encryption_map;
|
|
||||||
time_t starting_time;
|
|
||||||
time_t end_time;
|
|
||||||
|
|
||||||
// 3. Read License File
|
|
||||||
err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
|
||||||
device_count,
|
|
||||||
uuid_encryption_map,
|
|
||||||
starting_time,
|
|
||||||
end_time);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
// 4. Change device count
|
|
||||||
if(device_count) uuid_encryption_map[0]+="u";
|
|
||||||
err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
|
||||||
device_count,
|
|
||||||
uuid_encryption_map,
|
|
||||||
starting_time,
|
|
||||||
end_time);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
// 5. Legality check
|
|
||||||
err = server::LicenseCheck::LegalityCheck(license_file_path);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(LicenseLibraryTest, CHECK_ERROR4_1_TEST){
|
|
||||||
|
|
||||||
server::ServerError err;
|
|
||||||
// 1. Set license file name
|
|
||||||
std::string license_file_path("/tmp/milvus/abc.license");
|
|
||||||
|
|
||||||
// 2. Define output var
|
|
||||||
int device_count;
|
|
||||||
std::map<int, std::string> uuid_encryption_map;
|
|
||||||
time_t starting_time;
|
|
||||||
time_t end_time;
|
|
||||||
|
|
||||||
// 3. Read License File
|
|
||||||
err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
|
||||||
device_count,
|
|
||||||
uuid_encryption_map,
|
|
||||||
starting_time,
|
|
||||||
end_time);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
// 4. Change starting time
|
|
||||||
time_t system_time;
|
|
||||||
err = server::LicenseLibrary::GetSystemTime(system_time);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
system_time+=60*60*24;
|
|
||||||
|
|
||||||
err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
|
||||||
device_count,
|
|
||||||
uuid_encryption_map,
|
|
||||||
system_time,
|
|
||||||
end_time);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
// 5. Legality check
|
|
||||||
err = server::LicenseCheck::LegalityCheck(license_file_path);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(LicenseLibraryTest, CHECK_ERROR4_2_TEST){
|
|
||||||
|
|
||||||
server::ServerError err;
|
|
||||||
// 1. Set license file name
|
|
||||||
std::string license_file_path("/tmp/milvus/abc.license");
|
|
||||||
|
|
||||||
// 2. Define output var
|
|
||||||
int device_count;
|
|
||||||
std::map<int, std::string> uuid_encryption_map;
|
|
||||||
time_t starting_time;
|
|
||||||
time_t end_time;
|
|
||||||
|
|
||||||
// 3. Read License File
|
|
||||||
err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
|
||||||
device_count,
|
|
||||||
uuid_encryption_map,
|
|
||||||
starting_time,
|
|
||||||
end_time);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
// 4. Change end time
|
|
||||||
time_t system_time;
|
|
||||||
err = server::LicenseLibrary::GetSystemTime(system_time);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
system_time-=100;
|
|
||||||
|
|
||||||
err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
|
||||||
device_count,
|
|
||||||
uuid_encryption_map,
|
|
||||||
starting_time,
|
|
||||||
system_time);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
// 5. Legality check
|
|
||||||
err = server::LicenseCheck::LegalityCheck(license_file_path);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,214 +1,214 @@
|
||||||
/*******************************************************************************
|
///*******************************************************************************
|
||||||
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
// * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||||
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
// * Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||||
* Proprietary and confidential.
|
// * Proprietary and confidential.
|
||||||
******************************************************************************/
|
// ******************************************************************************/
|
||||||
|
//
|
||||||
|
//
|
||||||
#include "utils/Log.h"
|
//#include "utils/Log.h"
|
||||||
#include "license/LicenseLibrary.h"
|
//#include "license/LicenseLibrary.h"
|
||||||
#include "utils/Error.h"
|
//#include "utils/Error.h"
|
||||||
|
//
|
||||||
#include <gtest/gtest.h>
|
//#include <gtest/gtest.h>
|
||||||
#include <iostream>
|
//#include <iostream>
|
||||||
|
//
|
||||||
|
//
|
||||||
using namespace zilliz::milvus;
|
//using namespace zilliz::milvus;
|
||||||
|
//
|
||||||
TEST(LicenseLibraryTest, FILE_EXISTENT_TEST) {
|
//TEST(LicenseLibraryTest, FILE_EXISTENT_TEST) {
|
||||||
|
//
|
||||||
std::string hosts_file = "/etc/hosts";
|
// std::string hosts_file = "/etc/hosts";
|
||||||
ASSERT_EQ(server::LicenseLibrary::IsFileExistent(hosts_file), true);
|
// ASSERT_EQ(server::LicenseLibrary::IsFileExistent(hosts_file), true);
|
||||||
|
//
|
||||||
std::string no_exist_file = "/temp/asdaasd";
|
// std::string no_exist_file = "/temp/asdaasd";
|
||||||
ASSERT_EQ(server::LicenseLibrary::IsFileExistent(no_exist_file), false);
|
// ASSERT_EQ(server::LicenseLibrary::IsFileExistent(no_exist_file), false);
|
||||||
|
//
|
||||||
std::string directory = "/tmp";
|
// std::string directory = "/tmp";
|
||||||
ASSERT_EQ(server::LicenseLibrary::IsFileExistent(directory), false);
|
// ASSERT_EQ(server::LicenseLibrary::IsFileExistent(directory), false);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
TEST(LicenseLibraryTest, GPU_INFO_TEST) {
|
//TEST(LicenseLibraryTest, GPU_INFO_TEST) {
|
||||||
|
//
|
||||||
int device_count = 0;
|
// int device_count = 0;
|
||||||
server::ServerError err = server::LicenseLibrary::GetDeviceCount(device_count);
|
// server::ServerError err = server::LicenseLibrary::GetDeviceCount(device_count);
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
std::cout << "Device Count: " << device_count << std::endl;
|
// std::cout << "Device Count: " << device_count << std::endl;
|
||||||
|
//
|
||||||
std::vector<std::string> uuid_array;
|
// std::vector<std::string> uuid_array;
|
||||||
err = server::LicenseLibrary::GetUUID(device_count, uuid_array);
|
// err = server::LicenseLibrary::GetUUID(device_count, uuid_array);
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
for (long i = 0; i < device_count; ++i) {
|
// for (long i = 0; i < device_count; ++i) {
|
||||||
std::cout << "Device Id: " << i << ", UUID: " << uuid_array[i] << std::endl;
|
// std::cout << "Device Id: " << i << ", UUID: " << uuid_array[i] << std::endl;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
std::vector<std::string> uuid_md5_array;
|
// std::vector<std::string> uuid_md5_array;
|
||||||
err = server::LicenseLibrary::GetUUIDMD5(device_count, uuid_array, uuid_md5_array);
|
// err = server::LicenseLibrary::GetUUIDMD5(device_count, uuid_array, uuid_md5_array);
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
for (long i = 0; i < device_count; ++i) {
|
// for (long i = 0; i < device_count; ++i) {
|
||||||
std::cout << "Device Id: " << i << ", UUID: " << uuid_array[i] << ", UUID_MD5: " << uuid_md5_array[i]
|
// std::cout << "Device Id: " << i << ", UUID: " << uuid_array[i] << ", UUID_MD5: " << uuid_md5_array[i]
|
||||||
<< std::endl;
|
// << std::endl;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
std::vector<std::string> uuid_sha256_array;
|
// std::vector<std::string> uuid_sha256_array;
|
||||||
err = server::LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, uuid_sha256_array);
|
// err = server::LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, uuid_sha256_array);
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
for (long i = 0; i < device_count; ++i) {
|
// for (long i = 0; i < device_count; ++i) {
|
||||||
std::cout << "Device Id: " << i << ", UUID: " << uuid_array[i] << ", UUID_SHA256: "
|
// std::cout << "Device Id: " << i << ", UUID: " << uuid_array[i] << ", UUID_SHA256: "
|
||||||
<< uuid_sha256_array[i] << std::endl;
|
// << uuid_sha256_array[i] << std::endl;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
time_t systemtime;
|
// time_t systemtime;
|
||||||
err = server::LicenseLibrary::GetSystemTime(systemtime);
|
// err = server::LicenseLibrary::GetSystemTime(systemtime);
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
std::cout << "System Time: " << systemtime << std::endl;
|
// std::cout << "System Time: " << systemtime << std::endl;
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
TEST(LicenseLibraryTest, LICENSE_FILE_TEST) {
|
//TEST(LicenseLibraryTest, LICENSE_FILE_TEST) {
|
||||||
|
//
|
||||||
// 0. File check
|
// // 0. File check
|
||||||
std::string test("/tmp/a.test");
|
// std::string test("/tmp/a.test");
|
||||||
bool is = server::LicenseLibrary::IsFileExistent(test);
|
// bool is = server::LicenseLibrary::IsFileExistent(test);
|
||||||
ASSERT_EQ(is, false);
|
// ASSERT_EQ(is, false);
|
||||||
|
//
|
||||||
// 1. Get Device Count
|
// // 1. Get Device Count
|
||||||
int device_count = 0;
|
// int device_count = 0;
|
||||||
server::ServerError err = server::LicenseLibrary::GetDeviceCount(device_count);
|
// server::ServerError err = server::LicenseLibrary::GetDeviceCount(device_count);
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
// 2. Get All GPU UUID
|
|
||||||
std::vector<std::string> uuid_array;
|
|
||||||
err = server::LicenseLibrary::GetUUID(device_count, uuid_array);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
// 3. Get UUID SHA256
|
|
||||||
std::vector<std::string> uuid_sha256_array;
|
|
||||||
err = server::LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, uuid_sha256_array);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
// 4. Generate GPU ID map with GPU UUID
|
|
||||||
std::map<int, std::string> uuid_encrption_map;
|
|
||||||
for (int i = 0; i < device_count; ++i) {
|
|
||||||
uuid_encrption_map[i] = uuid_sha256_array[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5.GPU_info File
|
|
||||||
std::string GPU_info_file_path("/tmp/milvus.info");
|
|
||||||
|
|
||||||
|
|
||||||
// 6. Generate GPU_info File
|
|
||||||
err = server::LicenseLibrary::GPUinfoFileSerialization(GPU_info_file_path,
|
|
||||||
device_count,
|
|
||||||
uuid_encrption_map);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
// 7. Define output var
|
|
||||||
int output_info_device_count = 0;
|
|
||||||
std::map<int, std::string> output_info_uuid_encrption_map;
|
|
||||||
|
|
||||||
// 8. Read GPU_info File
|
|
||||||
err = server::LicenseLibrary::GPUinfoFileDeserialization(GPU_info_file_path,
|
|
||||||
output_info_device_count,
|
|
||||||
output_info_uuid_encrption_map);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
ASSERT_EQ(device_count, output_info_device_count);
|
|
||||||
for (int i = 0; i < device_count; ++i) {
|
|
||||||
ASSERT_EQ(uuid_encrption_map[i], output_info_uuid_encrption_map[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 9. Set license file name
|
|
||||||
std::string license_file_path("/tmp/milvus.license");
|
|
||||||
|
|
||||||
// 10. Get System Time/starting_time ans End Time
|
|
||||||
time_t sysyem_time;
|
|
||||||
err = server::LicenseLibrary::GetSystemTime(sysyem_time);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
// 11.GetDateTime
|
|
||||||
time_t starting_time;
|
|
||||||
time_t end_time;
|
|
||||||
const char *string_starting_time = "2019-05-10";
|
|
||||||
const char *string_end_time = "2022-05-10";
|
|
||||||
err = server::LicenseLibrary::GetDateTime(string_starting_time, starting_time);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
err = server::LicenseLibrary::GetDateTime(string_end_time, end_time);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
// 12. Generate License File
|
|
||||||
err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
|
||||||
device_count,
|
|
||||||
uuid_encrption_map,
|
|
||||||
starting_time,
|
|
||||||
end_time);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
// 13. Define output var
|
|
||||||
int output_device_count = 0;
|
|
||||||
std::map<int, std::string> output_uuid_encrption_map;
|
|
||||||
time_t output_starting_time;
|
|
||||||
time_t output_end_time;
|
|
||||||
|
|
||||||
// 14. Read License File
|
|
||||||
err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
|
||||||
output_device_count,
|
|
||||||
output_uuid_encrption_map,
|
|
||||||
output_starting_time,
|
|
||||||
output_end_time);
|
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
|
||||||
|
|
||||||
ASSERT_EQ(device_count, output_device_count);
|
|
||||||
ASSERT_EQ(starting_time, output_starting_time);
|
|
||||||
ASSERT_EQ(end_time, output_end_time);
|
|
||||||
|
|
||||||
for (int i = 0; i < device_count; ++i) {
|
|
||||||
ASSERT_EQ(uuid_encrption_map[i], output_uuid_encrption_map[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// // 15. Get License File Attribute
|
|
||||||
// time_t update_time;
|
|
||||||
// off_t file_size;
|
|
||||||
// err = server::LicenseLibrary::GetFileUpdateTimeAndSize(license_file_path, update_time, file_size);
|
|
||||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
//
|
//
|
||||||
// // 16. Get License File MD5
|
// // 2. Get All GPU UUID
|
||||||
// std::string file_md5;
|
// std::vector<std::string> uuid_array;
|
||||||
// err = server::LicenseLibrary::GetFileMD5(license_file_path, file_md5);
|
// err = server::LicenseLibrary::GetUUID(device_count, uuid_array);
|
||||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
// // 3. Get UUID SHA256
|
||||||
|
// std::vector<std::string> uuid_sha256_array;
|
||||||
// // 17. Generate Secret File
|
// err = server::LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, uuid_sha256_array);
|
||||||
// std::string secret_file_path("/tmp/milvus.secret");
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
// err = server::LicenseLibrary::SecretFileSerialization(secret_file_path,
|
//
|
||||||
// update_time,
|
// // 4. Generate GPU ID map with GPU UUID
|
||||||
// file_size,
|
// std::map<int, std::string> uuid_encrption_map;
|
||||||
|
// for (int i = 0; i < device_count; ++i) {
|
||||||
|
// uuid_encrption_map[i] = uuid_sha256_array[i];
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 5.GPU_info File
|
||||||
|
// std::string GPU_info_file_path("/tmp/milvus.info");
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // 6. Generate GPU_info File
|
||||||
|
// err = server::LicenseLibrary::GPUinfoFileSerialization(GPU_info_file_path,
|
||||||
|
// device_count,
|
||||||
|
// uuid_encrption_map);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
// // 7. Define output var
|
||||||
|
// int output_info_device_count = 0;
|
||||||
|
// std::map<int, std::string> output_info_uuid_encrption_map;
|
||||||
|
//
|
||||||
|
// // 8. Read GPU_info File
|
||||||
|
// err = server::LicenseLibrary::GPUinfoFileDeserialization(GPU_info_file_path,
|
||||||
|
// output_info_device_count,
|
||||||
|
// output_info_uuid_encrption_map);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
// ASSERT_EQ(device_count, output_info_device_count);
|
||||||
|
// for (int i = 0; i < device_count; ++i) {
|
||||||
|
// ASSERT_EQ(uuid_encrption_map[i], output_info_uuid_encrption_map[i]);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 9. Set license file name
|
||||||
|
// std::string license_file_path("/tmp/milvus.license");
|
||||||
|
//
|
||||||
|
// // 10. Get System Time/starting_time ans End Time
|
||||||
|
// time_t sysyem_time;
|
||||||
|
// err = server::LicenseLibrary::GetSystemTime(sysyem_time);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
// // 11.GetDateTime
|
||||||
|
// time_t starting_time;
|
||||||
|
// time_t end_time;
|
||||||
|
// const char *string_starting_time = "2019-05-10";
|
||||||
|
// const char *string_end_time = "2022-05-10";
|
||||||
|
// err = server::LicenseLibrary::GetDateTime(string_starting_time, starting_time);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
// err = server::LicenseLibrary::GetDateTime(string_end_time, end_time);
|
||||||
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
// // 12. Generate License File
|
||||||
|
// err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
||||||
|
// device_count,
|
||||||
|
// uuid_encrption_map,
|
||||||
// starting_time,
|
// starting_time,
|
||||||
// end_time,
|
// end_time);
|
||||||
// file_md5);
|
|
||||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
// // 18. Define output var
|
// // 13. Define output var
|
||||||
// time_t output_update_time;
|
// int output_device_count = 0;
|
||||||
// off_t output_file_size;
|
// std::map<int, std::string> output_uuid_encrption_map;
|
||||||
// time_t output_starting_time;
|
// time_t output_starting_time;
|
||||||
// time_t output_end_time;
|
// time_t output_end_time;
|
||||||
// std::string output_file_md5;
|
//
|
||||||
|
// // 14. Read License File
|
||||||
// // 19. Read License File
|
// err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||||
// err = server::LicenseLibrary::SecretFileDeserialization(secret_file_path,
|
// output_device_count,
|
||||||
// output_update_time,
|
// output_uuid_encrption_map,
|
||||||
// output_file_size,
|
|
||||||
// output_starting_time,
|
// output_starting_time,
|
||||||
// output_end_time,
|
// output_end_time);
|
||||||
// output_file_md5);
|
|
||||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
//
|
//
|
||||||
// ASSERT_EQ(update_time, output_update_time);
|
// ASSERT_EQ(device_count, output_device_count);
|
||||||
// ASSERT_EQ(file_size, output_file_size);
|
|
||||||
// ASSERT_EQ(starting_time, output_starting_time);
|
// ASSERT_EQ(starting_time, output_starting_time);
|
||||||
// ASSERT_EQ(end_time, output_end_time);
|
// ASSERT_EQ(end_time, output_end_time);
|
||||||
// ASSERT_EQ(file_md5, output_file_md5);
|
//
|
||||||
|
// for (int i = 0; i < device_count; ++i) {
|
||||||
|
// ASSERT_EQ(uuid_encrption_map[i], output_uuid_encrption_map[i]);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//// // 15. Get License File Attribute
|
||||||
|
//// time_t update_time;
|
||||||
|
//// off_t file_size;
|
||||||
|
//// err = server::LicenseLibrary::GetFileUpdateTimeAndSize(license_file_path, update_time, file_size);
|
||||||
|
//// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
////
|
||||||
|
//// // 16. Get License File MD5
|
||||||
|
//// std::string file_md5;
|
||||||
|
//// err = server::LicenseLibrary::GetFileMD5(license_file_path, file_md5);
|
||||||
|
//// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//// // 17. Generate Secret File
|
||||||
|
//// std::string secret_file_path("/tmp/milvus.secret");
|
||||||
|
//// err = server::LicenseLibrary::SecretFileSerialization(secret_file_path,
|
||||||
|
//// update_time,
|
||||||
|
//// file_size,
|
||||||
|
//// starting_time,
|
||||||
|
//// end_time,
|
||||||
|
//// file_md5);
|
||||||
|
//// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//
|
||||||
|
//// // 18. Define output var
|
||||||
|
//// time_t output_update_time;
|
||||||
|
//// off_t output_file_size;
|
||||||
|
//// time_t output_starting_time;
|
||||||
|
//// time_t output_end_time;
|
||||||
|
//// std::string output_file_md5;
|
||||||
|
//
|
||||||
|
//// // 19. Read License File
|
||||||
|
//// err = server::LicenseLibrary::SecretFileDeserialization(secret_file_path,
|
||||||
|
//// output_update_time,
|
||||||
|
//// output_file_size,
|
||||||
|
//// output_starting_time,
|
||||||
|
//// output_end_time,
|
||||||
|
//// output_file_md5);
|
||||||
|
//// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
////
|
||||||
|
//// ASSERT_EQ(update_time, output_update_time);
|
||||||
|
//// ASSERT_EQ(file_size, output_file_size);
|
||||||
|
//// ASSERT_EQ(starting_time, output_starting_time);
|
||||||
|
//// ASSERT_EQ(end_time, output_end_time);
|
||||||
|
//// ASSERT_EQ(file_md5, output_file_md5);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|
|
@ -55,8 +55,9 @@ set(count_test_src
|
||||||
${wrapper_src}
|
${wrapper_src}
|
||||||
${metrics_src}
|
${metrics_src}
|
||||||
metrics_test.cpp
|
metrics_test.cpp
|
||||||
|
prometheus_test.cpp
|
||||||
../db/utils.cpp
|
../db/utils.cpp
|
||||||
)
|
metricbase_test.cpp)
|
||||||
|
|
||||||
|
|
||||||
add_executable(metrics_test ${count_test_src} ${require_files} )
|
add_executable(metrics_test ${count_test_src} ${require_files} )
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||||
|
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||||
|
* Proprietary and confidential.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "metrics/Metrics.h"
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace zilliz::milvus;
|
||||||
|
|
||||||
|
TEST(MetricbaseTest, Metricbase_Test){
|
||||||
|
server::MetricsBase instance = server::MetricsBase::GetInstance();
|
||||||
|
instance.Init();
|
||||||
|
server::SystemInfo::GetInstance().Init();
|
||||||
|
instance.AddVectorsSuccessTotalIncrement();
|
||||||
|
instance.AddVectorsFailTotalIncrement();
|
||||||
|
instance.AddVectorsDurationHistogramOberve(1.0);
|
||||||
|
instance.RawFileSizeHistogramObserve(1.0);
|
||||||
|
instance.IndexFileSizeHistogramObserve(1.0);
|
||||||
|
instance.BuildIndexDurationSecondsHistogramObserve(1.0);
|
||||||
|
instance.CacheUsageGaugeSet(1.0);
|
||||||
|
instance.MetaAccessTotalIncrement();
|
||||||
|
instance.MetaAccessDurationSecondsHistogramObserve(1.0);
|
||||||
|
instance.FaissDiskLoadDurationSecondsHistogramObserve(1.0);
|
||||||
|
instance.FaissDiskLoadSizeBytesHistogramObserve(1.0);
|
||||||
|
instance.FaissDiskLoadIOSpeedGaugeSet(1.0);
|
||||||
|
instance.CacheAccessTotalIncrement();
|
||||||
|
instance.MemTableMergeDurationSecondsHistogramObserve(1.0);
|
||||||
|
instance.SearchIndexDataDurationSecondsHistogramObserve(1.0);
|
||||||
|
instance.SearchRawDataDurationSecondsHistogramObserve(1.0);
|
||||||
|
instance.IndexFileSizeTotalIncrement();
|
||||||
|
instance.RawFileSizeTotalIncrement();
|
||||||
|
instance.IndexFileSizeGaugeSet(1.0);
|
||||||
|
instance.RawFileSizeGaugeSet(1.0);
|
||||||
|
instance.QueryResponseSummaryObserve(1.0);
|
||||||
|
instance.DiskStoreIOSpeedGaugeSet(1.0);
|
||||||
|
instance.DataFileSizeGaugeSet(1.0);
|
||||||
|
instance.AddVectorsSuccessGaugeSet(1.0);
|
||||||
|
instance.AddVectorsFailGaugeSet(1.0);
|
||||||
|
instance.QueryVectorResponseSummaryObserve(1.0, 1);
|
||||||
|
instance.QueryVectorResponsePerSecondGaugeSet(1.0);
|
||||||
|
instance.CPUUsagePercentSet();
|
||||||
|
instance.RAMUsagePercentSet();
|
||||||
|
instance.QueryResponsePerSecondGaugeSet(1.0);
|
||||||
|
instance.GPUPercentGaugeSet();
|
||||||
|
instance.GPUMemoryUsageGaugeSet();
|
||||||
|
instance.AddVectorsPerSecondGaugeSet(1,1,1);
|
||||||
|
instance.QueryIndexTypePerSecondSet("IVF", 1.0);
|
||||||
|
instance.ConnectionGaugeIncrement();
|
||||||
|
instance.ConnectionGaugeDecrement();
|
||||||
|
instance.KeepingAliveCounterIncrement();
|
||||||
|
instance.OctetsSet();
|
||||||
|
}
|
|
@ -24,7 +24,6 @@
|
||||||
using namespace zilliz::milvus;
|
using namespace zilliz::milvus;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_F(DBTest, Metric_Tes) {
|
TEST_F(DBTest, Metric_Tes) {
|
||||||
|
|
||||||
server::SystemInfo::GetInstance().Init();
|
server::SystemInfo::GetInstance().Init();
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||||
|
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||||
|
* Proprietary and confidential.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "metrics/PrometheusMetrics.h"
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace zilliz::milvus;
|
||||||
|
|
||||||
|
TEST(PrometheusTest, Prometheus_Test){
|
||||||
|
server::PrometheusMetrics instance = server::PrometheusMetrics::GetInstance();
|
||||||
|
instance.Init();
|
||||||
|
instance.SetStartup(true);
|
||||||
|
server::SystemInfo::GetInstance().Init();
|
||||||
|
instance.AddVectorsSuccessTotalIncrement();
|
||||||
|
instance.AddVectorsFailTotalIncrement();
|
||||||
|
instance.AddVectorsDurationHistogramOberve(1.0);
|
||||||
|
instance.RawFileSizeHistogramObserve(1.0);
|
||||||
|
instance.IndexFileSizeHistogramObserve(1.0);
|
||||||
|
instance.BuildIndexDurationSecondsHistogramObserve(1.0);
|
||||||
|
instance.CacheUsageGaugeSet(1.0);
|
||||||
|
instance.MetaAccessTotalIncrement();
|
||||||
|
instance.MetaAccessDurationSecondsHistogramObserve(1.0);
|
||||||
|
instance.FaissDiskLoadDurationSecondsHistogramObserve(1.0);
|
||||||
|
instance.FaissDiskLoadSizeBytesHistogramObserve(1.0);
|
||||||
|
instance.FaissDiskLoadIOSpeedGaugeSet(1.0);
|
||||||
|
instance.CacheAccessTotalIncrement();
|
||||||
|
instance.MemTableMergeDurationSecondsHistogramObserve(1.0);
|
||||||
|
instance.SearchIndexDataDurationSecondsHistogramObserve(1.0);
|
||||||
|
instance.SearchRawDataDurationSecondsHistogramObserve(1.0);
|
||||||
|
instance.IndexFileSizeTotalIncrement();
|
||||||
|
instance.RawFileSizeTotalIncrement();
|
||||||
|
instance.IndexFileSizeGaugeSet(1.0);
|
||||||
|
instance.RawFileSizeGaugeSet(1.0);
|
||||||
|
instance.QueryResponseSummaryObserve(1.0);
|
||||||
|
instance.DiskStoreIOSpeedGaugeSet(1.0);
|
||||||
|
instance.DataFileSizeGaugeSet(1.0);
|
||||||
|
instance.AddVectorsSuccessGaugeSet(1.0);
|
||||||
|
instance.AddVectorsFailGaugeSet(1.0);
|
||||||
|
instance.QueryVectorResponseSummaryObserve(1.0, 1);
|
||||||
|
instance.QueryVectorResponsePerSecondGaugeSet(1.0);
|
||||||
|
instance.CPUUsagePercentSet();
|
||||||
|
instance.RAMUsagePercentSet();
|
||||||
|
instance.QueryResponsePerSecondGaugeSet(1.0);
|
||||||
|
instance.GPUPercentGaugeSet();
|
||||||
|
instance.GPUMemoryUsageGaugeSet();
|
||||||
|
instance.AddVectorsPerSecondGaugeSet(1,1,1);
|
||||||
|
instance.QueryIndexTypePerSecondSet("IVF", 1.0);
|
||||||
|
instance.ConnectionGaugeIncrement();
|
||||||
|
instance.ConnectionGaugeDecrement();
|
||||||
|
instance.KeepingAliveCounterIncrement();
|
||||||
|
instance.OctetsSet();
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ set(utils_srcs
|
||||||
${MILVUS_ENGINE_SRC}/utils/StringHelpFunctions.cpp
|
${MILVUS_ENGINE_SRC}/utils/StringHelpFunctions.cpp
|
||||||
${MILVUS_ENGINE_SRC}/utils/TimeRecorder.cpp
|
${MILVUS_ENGINE_SRC}/utils/TimeRecorder.cpp
|
||||||
${MILVUS_ENGINE_SRC}/utils/CommonUtil.cpp
|
${MILVUS_ENGINE_SRC}/utils/CommonUtil.cpp
|
||||||
|
${MILVUS_ENGINE_SRC}/utils/LogUtil.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
cuda_add_executable(server_test
|
cuda_add_executable(server_test
|
||||||
|
@ -54,3 +55,11 @@ target_link_libraries(server_test
|
||||||
)
|
)
|
||||||
|
|
||||||
install(TARGETS server_test DESTINATION bin)
|
install(TARGETS server_test DESTINATION bin)
|
||||||
|
|
||||||
|
configure_file(appendix/server_config.yaml
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/milvus/conf/server_config.yaml"
|
||||||
|
COPYONLY)
|
||||||
|
|
||||||
|
configure_file(appendix/log_config.conf
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/milvus/conf/log_config.conf"
|
||||||
|
COPYONLY)
|
||||||
|
|
|
@ -11,6 +11,23 @@
|
||||||
|
|
||||||
using namespace zilliz::milvus;
|
using namespace zilliz::milvus;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class InvalidCacheMgr : public cache::CacheMgr {
|
||||||
|
public:
|
||||||
|
InvalidCacheMgr() {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class LessItemCacheMgr : public cache::CacheMgr {
|
||||||
|
public:
|
||||||
|
LessItemCacheMgr() {
|
||||||
|
cache_ = std::make_shared<cache::Cache>(1UL << 12, 10);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
TEST(CacheTest, CPU_CACHE_TEST) {
|
TEST(CacheTest, CPU_CACHE_TEST) {
|
||||||
cache::CacheMgr *cpu_mgr = cache::CpuCacheMgr::GetInstance();
|
cache::CacheMgr *cpu_mgr = cache::CpuCacheMgr::GetInstance();
|
||||||
|
|
||||||
|
@ -79,3 +96,34 @@ TEST(CacheTest, GPU_CACHE_TEST) {
|
||||||
gpu_mgr->ClearCache();
|
gpu_mgr->ClearCache();
|
||||||
ASSERT_EQ(gpu_mgr->ItemCount(), 0);
|
ASSERT_EQ(gpu_mgr->ItemCount(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(CacheTest, INVALID_TEST) {
|
||||||
|
{
|
||||||
|
InvalidCacheMgr mgr;
|
||||||
|
ASSERT_EQ(mgr.ItemCount(), 0);
|
||||||
|
ASSERT_FALSE(mgr.ItemExists("test"));
|
||||||
|
ASSERT_EQ(mgr.GetItem("test"), nullptr);
|
||||||
|
|
||||||
|
mgr.InsertItem("test", cache::DataObjPtr());
|
||||||
|
mgr.InsertItem("test", engine::Index_ptr(nullptr));
|
||||||
|
mgr.EraseItem("test");
|
||||||
|
mgr.PrintInfo();
|
||||||
|
mgr.ClearCache();
|
||||||
|
mgr.SetCapacity(100);
|
||||||
|
ASSERT_EQ(mgr.CacheCapacity(), 0);
|
||||||
|
ASSERT_EQ(mgr.CacheUsage(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
LessItemCacheMgr mgr;
|
||||||
|
for(int i = 0; i < 20; i++) {
|
||||||
|
std::shared_ptr<faiss::Index> raw_index(faiss::index_factory(2, "IDMap,Flat"));
|
||||||
|
engine::Index_ptr index = std::make_shared<engine::Index>(raw_index);
|
||||||
|
index->ntotal = 2;
|
||||||
|
|
||||||
|
cache::DataObjPtr obj = std::make_shared<cache::DataObj>(index);
|
||||||
|
mgr.InsertItem("index_" + std::to_string(i), obj);
|
||||||
|
}
|
||||||
|
ASSERT_EQ(mgr.GetItem("index_0"), nullptr);
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,13 +10,27 @@
|
||||||
|
|
||||||
using namespace zilliz::milvus;
|
using namespace zilliz::milvus;
|
||||||
|
|
||||||
static const std::string CONFIG_FILE_PATH = "../../../conf/server_config.yaml";
|
namespace {
|
||||||
|
|
||||||
|
static const std::string CONFIG_FILE_PATH = "./milvus/conf/server_config.yaml";
|
||||||
|
static const std::string LOG_FILE_PATH = "./milvus/conf/log_config.conf";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
TEST(ConfigTest, CONFIG_TEST) {
|
TEST(ConfigTest, CONFIG_TEST) {
|
||||||
server::IConfigMgr* config_mgr = server::IConfigMgr::GetInstance();
|
server::IConfigMgr* config_mgr = server::IConfigMgr::GetInstance();
|
||||||
server::ServerError err = config_mgr->LoadConfigFile(CONFIG_FILE_PATH);
|
|
||||||
|
server::ServerError err = config_mgr->LoadConfigFile("");
|
||||||
|
ASSERT_EQ(err, server::SERVER_UNEXPECTED_ERROR);
|
||||||
|
|
||||||
|
err = config_mgr->LoadConfigFile(LOG_FILE_PATH);
|
||||||
|
ASSERT_EQ(err, server::SERVER_UNEXPECTED_ERROR);
|
||||||
|
|
||||||
|
err = config_mgr->LoadConfigFile(CONFIG_FILE_PATH);
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
|
||||||
|
config_mgr->Print();
|
||||||
|
|
||||||
server::ConfigNode& root_config = config_mgr->GetRootNode();
|
server::ConfigNode& root_config = config_mgr->GetRootNode();
|
||||||
server::ConfigNode& server_config = root_config.GetChild("server_config");
|
server::ConfigNode& server_config = root_config.GetChild("server_config");
|
||||||
server::ConfigNode& db_config = root_config.GetChild("db_config");
|
server::ConfigNode& db_config = root_config.GetChild("db_config");
|
||||||
|
@ -43,10 +57,6 @@ TEST(ConfigTest, CONFIG_TEST) {
|
||||||
auto children = server_config.GetChildren();
|
auto children = server_config.GetChildren();
|
||||||
ASSERT_TRUE(children.empty());
|
ASSERT_TRUE(children.empty());
|
||||||
|
|
||||||
root_config.PrintAll();
|
|
||||||
std::string all = root_config.DumpString();
|
|
||||||
ASSERT_TRUE(!all.empty());
|
|
||||||
|
|
||||||
server_config.ClearConfig();
|
server_config.ClearConfig();
|
||||||
auto configs = server_config.GetConfig();
|
auto configs = server_config.GetConfig();
|
||||||
ASSERT_TRUE(configs.empty());
|
ASSERT_TRUE(configs.empty());
|
||||||
|
@ -56,9 +66,20 @@ TEST(ConfigTest, CONFIG_TEST) {
|
||||||
auto seq = server_config.GetSequence("seq");
|
auto seq = server_config.GetSequence("seq");
|
||||||
ASSERT_EQ(seq.size(), 2UL);
|
ASSERT_EQ(seq.size(), 2UL);
|
||||||
|
|
||||||
|
server::ConfigNode combine;
|
||||||
|
combine.Combine(server_config);
|
||||||
|
|
||||||
|
combine.PrintAll();
|
||||||
|
std::string all = combine.DumpString();
|
||||||
|
ASSERT_TRUE(!all.empty());
|
||||||
|
|
||||||
server_config.ClearSequences();
|
server_config.ClearSequences();
|
||||||
auto seqs = server_config.GetSequences();
|
auto seqs = server_config.GetSequences();
|
||||||
ASSERT_TRUE(seqs.empty());
|
ASSERT_TRUE(seqs.empty());
|
||||||
|
|
||||||
|
const server::ConfigNode const_node = root_config.GetChild("cache_config");
|
||||||
|
float flt = const_node.GetFloatValue("cpu_cache_capacity");
|
||||||
|
ASSERT_GT(flt, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ConfigTest, SERVER_CONFIG_TEST) {
|
TEST(ConfigTest, SERVER_CONFIG_TEST) {
|
||||||
|
@ -73,5 +94,12 @@ TEST(ConfigTest, SERVER_CONFIG_TEST) {
|
||||||
int32_t cap = node1.GetInt32Value("cpu_cache_capacity");
|
int32_t cap = node1.GetInt32Value("cpu_cache_capacity");
|
||||||
ASSERT_GT(cap, 0);
|
ASSERT_GT(cap, 0);
|
||||||
|
|
||||||
|
node1.SetValue("bool", "true");
|
||||||
|
bool bt = node1.GetBoolValue("bool");
|
||||||
|
ASSERT_TRUE(bt);
|
||||||
|
|
||||||
config.PrintAll();
|
config.PrintAll();
|
||||||
|
|
||||||
|
const server::ServerConfig const_config = config;
|
||||||
|
server::ConfigNode node = const_config.GetConfig("aaa");
|
||||||
}
|
}
|
|
@ -11,35 +11,83 @@
|
||||||
#include "utils/StringHelpFunctions.h"
|
#include "utils/StringHelpFunctions.h"
|
||||||
#include "utils/TimeRecorder.h"
|
#include "utils/TimeRecorder.h"
|
||||||
#include "utils/BlockingQueue.h"
|
#include "utils/BlockingQueue.h"
|
||||||
|
#include "utils/LogUtil.h"
|
||||||
|
|
||||||
using namespace zilliz::milvus;
|
using namespace zilliz::milvus;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
static const std::string LOG_FILE_PATH = "./milvus/conf/log_config.conf";
|
||||||
|
|
||||||
using TimeUnit = server::TimeRecorder::TimeDisplayUnit;
|
using TimeUnit = server::TimeRecorder::TimeDisplayUnit;
|
||||||
double TestTimeRecorder(TimeUnit unit, int64_t log_level) {
|
double TestTimeRecorder(TimeUnit unit, int64_t log_level, int64_t sleep_ms) {
|
||||||
server::TimeRecorder rc("test rc", unit, log_level);
|
server::TimeRecorder rc("test rc", unit, log_level);
|
||||||
rc.Record("begin");
|
rc.Record("begin");
|
||||||
std::this_thread::sleep_for(std::chrono::microseconds(10));
|
std::this_thread::sleep_for(std::chrono::milliseconds(sleep_ms));
|
||||||
rc.Elapse("end");
|
rc.Elapse("end");
|
||||||
return rc.Span();
|
return rc.Span();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CommonTest, COMMON_TEST) {
|
TEST(UtilTest, EXCEPTION_TEST) {
|
||||||
|
std::string err_msg = "failed";
|
||||||
|
server::ServerException ex(server::SERVER_UNEXPECTED_ERROR, err_msg);
|
||||||
|
ASSERT_EQ(ex.error_code(), server::SERVER_UNEXPECTED_ERROR);
|
||||||
|
std::string msg = ex.what();
|
||||||
|
ASSERT_EQ(msg, err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UtilTest, COMMON_TEST) {
|
||||||
|
unsigned long total_mem = 0, free_mem = 0;
|
||||||
|
server::CommonUtil::GetSystemMemInfo(total_mem, free_mem);
|
||||||
|
ASSERT_GT(total_mem, 0);
|
||||||
|
ASSERT_GT(free_mem, 0);
|
||||||
|
|
||||||
|
unsigned int thread_cnt = 0;
|
||||||
|
server::CommonUtil::GetSystemAvailableThreads(thread_cnt);
|
||||||
|
ASSERT_GT(thread_cnt, 0);
|
||||||
|
|
||||||
std::string path1 = "/tmp/milvus_test/";
|
std::string path1 = "/tmp/milvus_test/";
|
||||||
std::string path2 = path1 + "common_test_12345/";
|
std::string path2 = path1 + "common_test_12345/";
|
||||||
std::string path3 = path2 + "abcdef";
|
std::string path3 = path2 + "abcdef";
|
||||||
server::ServerError err = server::CommonUtil::CreateDirectory(path3);
|
server::ServerError err = server::CommonUtil::CreateDirectory(path3);
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//test again
|
||||||
|
err = server::CommonUtil::CreateDirectory(path3);
|
||||||
|
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
|
||||||
ASSERT_TRUE(server::CommonUtil::IsDirectoryExit(path3));
|
ASSERT_TRUE(server::CommonUtil::IsDirectoryExist(path3));
|
||||||
|
|
||||||
|
err = server::CommonUtil::DeleteDirectory(path1);
|
||||||
|
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
//test again
|
||||||
err = server::CommonUtil::DeleteDirectory(path1);
|
err = server::CommonUtil::DeleteDirectory(path1);
|
||||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
|
||||||
ASSERT_FALSE(server::CommonUtil::IsDirectoryExit(path1));
|
ASSERT_FALSE(server::CommonUtil::IsDirectoryExist(path1));
|
||||||
|
ASSERT_FALSE(server::CommonUtil::IsFileExist(path1));
|
||||||
|
|
||||||
|
std::string exe_path = server::CommonUtil::GetExePath();
|
||||||
|
ASSERT_FALSE(exe_path.empty());
|
||||||
|
|
||||||
|
time_t tt;
|
||||||
|
time( &tt );
|
||||||
|
tm time_struct;
|
||||||
|
memset(&time_struct, 0, sizeof(tm));
|
||||||
|
server::CommonUtil::ConvertTime(tt, time_struct);
|
||||||
|
ASSERT_GT(time_struct.tm_year, 0);
|
||||||
|
ASSERT_GT(time_struct.tm_mon, 0);
|
||||||
|
ASSERT_GT(time_struct.tm_mday, 0);
|
||||||
|
server::CommonUtil::ConvertTime(time_struct, tt);
|
||||||
|
ASSERT_GT(tt, 0);
|
||||||
|
|
||||||
|
bool res = server::CommonUtil::TimeStrToTime("2019-03-23", tt, time_struct);
|
||||||
|
ASSERT_EQ(time_struct.tm_year, 119);
|
||||||
|
ASSERT_EQ(time_struct.tm_mon, 2);
|
||||||
|
ASSERT_EQ(time_struct.tm_mday, 23);
|
||||||
|
ASSERT_GT(tt, 0);
|
||||||
|
ASSERT_TRUE(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(UtilTest, STRINGFUNCTIONS_TEST) {
|
TEST(UtilTest, STRINGFUNCTIONS_TEST) {
|
||||||
|
@ -47,29 +95,49 @@ TEST(UtilTest, STRINGFUNCTIONS_TEST) {
|
||||||
server::StringHelpFunctions::TrimStringBlank(str);
|
server::StringHelpFunctions::TrimStringBlank(str);
|
||||||
ASSERT_EQ(str, "test zilliz");
|
ASSERT_EQ(str, "test zilliz");
|
||||||
|
|
||||||
|
str = "\"test zilliz\"";
|
||||||
|
server::StringHelpFunctions::TrimStringQuote(str, "\"");
|
||||||
|
ASSERT_EQ(str, "test zilliz");
|
||||||
|
|
||||||
str = "a,b,c";
|
str = "a,b,c";
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
server::StringHelpFunctions::SplitStringByDelimeter(str , ",", result);
|
server::ServerError err = server::StringHelpFunctions::SplitStringByDelimeter(str , ",", result);
|
||||||
|
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
ASSERT_EQ(result.size(), 3UL);
|
||||||
|
|
||||||
|
result.clear();
|
||||||
|
err = server::StringHelpFunctions::SplitStringByQuote(str , ",", "\"", result);
|
||||||
|
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
|
ASSERT_EQ(result.size(), 3UL);
|
||||||
|
|
||||||
|
result.clear();
|
||||||
|
err = server::StringHelpFunctions::SplitStringByQuote(str , ",", "", result);
|
||||||
|
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
ASSERT_EQ(result.size(), 3UL);
|
ASSERT_EQ(result.size(), 3UL);
|
||||||
|
|
||||||
str = "55,\"aa,gg,yy\",b";
|
str = "55,\"aa,gg,yy\",b";
|
||||||
result.clear();
|
result.clear();
|
||||||
server::StringHelpFunctions::SplitStringByQuote(str , ",", "\"", result);
|
err = server::StringHelpFunctions::SplitStringByQuote(str , ",", "\"", result);
|
||||||
|
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||||
ASSERT_EQ(result.size(), 3UL);
|
ASSERT_EQ(result.size(), 3UL);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(UtilTest, TIMERECORDER_TEST) {
|
TEST(UtilTest, TIMERECORDER_TEST) {
|
||||||
double span = TestTimeRecorder(TimeUnit::eTimeAutoUnit, 0);
|
double span = TestTimeRecorder(TimeUnit::eTimeAutoUnit, 0, 1001);
|
||||||
ASSERT_GT(span, 0.0);
|
ASSERT_GT(span, 0.0);
|
||||||
span = TestTimeRecorder(TimeUnit::eTimeHourUnit, 1);
|
span = TestTimeRecorder(TimeUnit::eTimeAutoUnit, 0, 101);
|
||||||
ASSERT_GT(span, 0.0);
|
ASSERT_GT(span, 0.0);
|
||||||
span = TestTimeRecorder(TimeUnit::eTimeMinuteUnit, 2);
|
span = TestTimeRecorder(TimeUnit::eTimeHourUnit, 1, 10);
|
||||||
ASSERT_GT(span, 0.0);
|
ASSERT_GT(span, 0.0);
|
||||||
span = TestTimeRecorder(TimeUnit::eTimeSecondUnit, 3);
|
span = TestTimeRecorder(TimeUnit::eTimeMinuteUnit, 2, 10);
|
||||||
ASSERT_GT(span, 0.0);
|
ASSERT_GT(span, 0.0);
|
||||||
span = TestTimeRecorder(TimeUnit::eTimeMilliSecUnit, 4);
|
span = TestTimeRecorder(TimeUnit::eTimeSecondUnit, 3, 10);
|
||||||
ASSERT_GT(span, 0.0);
|
ASSERT_GT(span, 0.0);
|
||||||
span = TestTimeRecorder(TimeUnit::eTimeMicroSecUnit, -1);
|
span = TestTimeRecorder(TimeUnit::eTimeMilliSecUnit, 4, 10);
|
||||||
|
ASSERT_GT(span, 0.0);
|
||||||
|
span = TestTimeRecorder(TimeUnit::eTimeMicroSecUnit, -1, 10);
|
||||||
ASSERT_GT(span, 0.0);
|
ASSERT_GT(span, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,5 +166,14 @@ TEST(UtilTest, BLOCKINGQUEUE_TEST) {
|
||||||
str = bq.Take();
|
str = bq.Take();
|
||||||
ASSERT_EQ(id, str);
|
ASSERT_EQ(id, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASSERT_EQ(bq.Size(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(UtilTest, LOG_TEST) {
|
||||||
|
int32_t res = server::InitLog(LOG_FILE_PATH);
|
||||||
|
ASSERT_EQ(res, 0);
|
||||||
|
|
||||||
|
std::string fname = server::GetFileName(LOG_FILE_PATH);
|
||||||
|
ASSERT_EQ(fname, "log_config.conf");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue