mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-01 03:18:29 +08:00
MS-129 Add more unitest
Former-commit-id: 7e7510967d7d71698475e7868e34a94896c07e71
This commit is contained in:
parent
ec2a868ed5
commit
ad0c4bd688
5
cpp/.gitignore
vendored
5
cpp/.gitignore
vendored
@ -3,3 +3,8 @@ conf/server_config.yaml
|
||||
conf/log_config.conf
|
||||
version.h
|
||||
megasearch/
|
||||
lcov_out/
|
||||
base.info
|
||||
output.info
|
||||
output_new.info
|
||||
server.info
|
@ -135,9 +135,9 @@ if (BUILD_COVERAGE STREQUAL "ON")
|
||||
endif()
|
||||
|
||||
|
||||
if ("${BUILD_UNIT_TEST}" STREQUAL "ON")
|
||||
if (BUILD_UNIT_TEST STREQUAL "ON")
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/unittest)
|
||||
endif(BUILD_UNIT_TEST)
|
||||
endif()
|
||||
|
||||
add_custom_target(Clean-All COMMAND ${CMAKE_BUILD_TOOL} clean)
|
||||
|
||||
|
@ -36,6 +36,11 @@ If you encounter the following error when building:
|
||||
or
|
||||
./build.sh --unittest
|
||||
|
||||
#### To run code coverage
|
||||
|
||||
apt-get install lcov
|
||||
./build.sh -u -c
|
||||
|
||||
### Launch server
|
||||
Set config in cpp/conf/server_config.yaml
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
* GLOBAL:
|
||||
FORMAT = "%datetime | %level | %logger | %msg"
|
||||
FILENAME = "/opt/milvus/logs/milvus-%datetime{%H:%m}-global.log"
|
||||
FILENAME = "/tmp/milvus/logs/milvus-%datetime{%H:%m}-global.log"
|
||||
ENABLED = true
|
||||
TO_FILE = true
|
||||
TO_STANDARD_OUTPUT = false
|
||||
@ -8,12 +8,12 @@
|
||||
PERFORMANCE_TRACKING = false
|
||||
MAX_LOG_FILE_SIZE = 2097152 ## Throw log files away after 2MB
|
||||
* DEBUG:
|
||||
FILENAME = "/opt/milvus/logs/milvus-%datetime{%H:%m}-debug.log"
|
||||
FILENAME = "/tmp/milvus/logs/milvus-%datetime{%H:%m}-debug.log"
|
||||
ENABLED = true
|
||||
* WARNING:
|
||||
FILENAME = "/opt/milvus/logs/milvus-%datetime{%H:%m}-warning.log"
|
||||
FILENAME = "/tmp/milvus/logs/milvus-%datetime{%H:%m}-warning.log"
|
||||
* TRACE:
|
||||
FILENAME = "/opt/milvus/logs/milvus-%datetime{%H:%m}-trace.log"
|
||||
FILENAME = "/tmp/milvus/logs/milvus-%datetime{%H:%m}-trace.log"
|
||||
* VERBOSE:
|
||||
FORMAT = "%datetime{%d/%M/%y} | %level-%vlevel | %msg"
|
||||
TO_FILE = false
|
||||
@ -21,7 +21,7 @@
|
||||
## Error logs
|
||||
* ERROR:
|
||||
ENABLED = true
|
||||
FILENAME = "/opt/milvus/logs/milvus-%datetime{%H:%m}-error.log"
|
||||
FILENAME = "/tmp/milvus/logs/milvus-%datetime{%H:%m}-error.log"
|
||||
* FATAL:
|
||||
ENABLED = true
|
||||
FILENAME = "/opt/milvus/logs/milvus-%datetime{%H:%m}-fatal.log"
|
||||
FILENAME = "/tmp/milvus/logs/milvus-%datetime{%H:%m}-fatal.log"
|
||||
|
@ -5,7 +5,7 @@ server_config:
|
||||
mode: single # milvus deployment type: single, cluster
|
||||
|
||||
db_config:
|
||||
db_path: /opt/milvus # milvus data storage path
|
||||
db_path: /tmp/milvus # milvus data storage path
|
||||
db_backend_url: http://127.0.0.1 # meta database uri
|
||||
index_building_threshold: 1024 # index building trigger threshold, default: 1024, unit: MB
|
||||
archive_disk_threshold: 512 # triger archive action if storage size exceed this value, unit: GB
|
||||
@ -22,7 +22,7 @@ metric_config:
|
||||
|
||||
|
||||
license_config: # license configure
|
||||
license_path: "/opt/milvus/system.license" # license file path
|
||||
license_path: "/tmp/milvus/system.license" # license file path
|
||||
|
||||
cache_config: # cache configure
|
||||
cpu_cache_capacity: 16 # how many memory are used as cache, unit: GB, range: 0 ~ less than total memory
|
||||
|
@ -1,69 +1,69 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
* Proprietary and confidential.
|
||||
******************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <boost/serialization/access.hpp>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
||||
class GPUInfoFile {
|
||||
public:
|
||||
GPUInfoFile() = default;
|
||||
|
||||
GPUInfoFile(const int &device_count, const std::map<int, std::string> &uuid_encryption_map)
|
||||
: device_count_(device_count), uuid_encryption_map_(uuid_encryption_map) {}
|
||||
|
||||
int get_device_count() {
|
||||
return device_count_;
|
||||
}
|
||||
std::map<int, std::string> &get_uuid_encryption_map() {
|
||||
return uuid_encryption_map_;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template<typename Archive>
|
||||
void serialize(Archive &ar, const unsigned int version) {
|
||||
ar & device_count_;
|
||||
ar & uuid_encryption_map_;
|
||||
}
|
||||
|
||||
public:
|
||||
int device_count_ = 0;
|
||||
std::map<int, std::string> uuid_encryption_map_;
|
||||
};
|
||||
|
||||
class SerializedGPUInfoFile {
|
||||
public:
|
||||
~SerializedGPUInfoFile() {
|
||||
if (gpu_info_file_ != nullptr) {
|
||||
delete (gpu_info_file_);
|
||||
gpu_info_file_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
set_gpu_info_file(GPUInfoFile *gpu_info_file) {
|
||||
gpu_info_file_ = gpu_info_file;
|
||||
}
|
||||
|
||||
GPUInfoFile *get_gpu_info_file() {
|
||||
return gpu_info_file_;
|
||||
}
|
||||
private:
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template<typename Archive>
|
||||
void serialize(Archive &ar, const unsigned int version) {
|
||||
ar & gpu_info_file_;
|
||||
}
|
||||
|
||||
private:
|
||||
GPUInfoFile *gpu_info_file_ = nullptr;
|
||||
};
|
||||
///*******************************************************************************
|
||||
// * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// * Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// * Proprietary and confidential.
|
||||
// ******************************************************************************/
|
||||
//#pragma once
|
||||
//
|
||||
//#include <boost/serialization/access.hpp>
|
||||
//#include <string>
|
||||
//#include <map>
|
||||
//
|
||||
//
|
||||
//class GPUInfoFile {
|
||||
// public:
|
||||
// GPUInfoFile() = default;
|
||||
//
|
||||
// GPUInfoFile(const int &device_count, const std::map<int, std::string> &uuid_encryption_map)
|
||||
// : device_count_(device_count), uuid_encryption_map_(uuid_encryption_map) {}
|
||||
//
|
||||
// int get_device_count() {
|
||||
// return device_count_;
|
||||
// }
|
||||
// std::map<int, std::string> &get_uuid_encryption_map() {
|
||||
// return uuid_encryption_map_;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public:
|
||||
// friend class boost::serialization::access;
|
||||
//
|
||||
// template<typename Archive>
|
||||
// void serialize(Archive &ar, const unsigned int version) {
|
||||
// ar & device_count_;
|
||||
// ar & uuid_encryption_map_;
|
||||
// }
|
||||
//
|
||||
// public:
|
||||
// int device_count_ = 0;
|
||||
// std::map<int, std::string> uuid_encryption_map_;
|
||||
//};
|
||||
//
|
||||
//class SerializedGPUInfoFile {
|
||||
// public:
|
||||
// ~SerializedGPUInfoFile() {
|
||||
// if (gpu_info_file_ != nullptr) {
|
||||
// delete (gpu_info_file_);
|
||||
// gpu_info_file_ = nullptr;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// void
|
||||
// set_gpu_info_file(GPUInfoFile *gpu_info_file) {
|
||||
// gpu_info_file_ = gpu_info_file;
|
||||
// }
|
||||
//
|
||||
// GPUInfoFile *get_gpu_info_file() {
|
||||
// return gpu_info_file_;
|
||||
// }
|
||||
// private:
|
||||
// friend class boost::serialization::access;
|
||||
//
|
||||
// template<typename Archive>
|
||||
// void serialize(Archive &ar, const unsigned int version) {
|
||||
// ar & gpu_info_file_;
|
||||
// }
|
||||
//
|
||||
// private:
|
||||
// GPUInfoFile *gpu_info_file_ = nullptr;
|
||||
//};
|
||||
|
@ -1,83 +1,83 @@
|
||||
|
||||
#include "utils/Log.h"
|
||||
#include "LicenseLibrary.h"
|
||||
#include "utils/Error.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <getopt.h>
|
||||
#include <memory.h>
|
||||
// Not provide path: current work path will be used and system.info.
|
||||
using namespace zilliz::milvus;
|
||||
|
||||
void
|
||||
print_usage(const std::string &app_name) {
|
||||
printf("\n Usage: %s [OPTIONS]\n\n", app_name.c_str());
|
||||
printf(" Options:\n");
|
||||
printf(" -h --help Print this help\n");
|
||||
printf(" -s --sysinfo filename Generate system info file as given name\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
std::string app_name = argv[0];
|
||||
if (argc != 1 && argc != 3) {
|
||||
print_usage(app_name);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
static struct option long_options[] = {{"system_info", required_argument, 0, 's'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{NULL, 0, 0, 0}};
|
||||
int value = 0;
|
||||
int option_index = 0;
|
||||
std::string system_info_filename = "./system.info";
|
||||
while ((value = getopt_long(argc, argv, "s:h", long_options, &option_index)) != -1) {
|
||||
switch (value) {
|
||||
case 's': {
|
||||
char *system_info_filename_ptr = strdup(optarg);
|
||||
system_info_filename = system_info_filename_ptr;
|
||||
free(system_info_filename_ptr);
|
||||
// printf("Generate system info file: %s\n", system_info_filename.c_str());
|
||||
break;
|
||||
}
|
||||
case 'h':print_usage(app_name);
|
||||
return EXIT_SUCCESS;
|
||||
case '?':print_usage(app_name);
|
||||
return EXIT_FAILURE;
|
||||
default:print_usage(app_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int device_count = 0;
|
||||
server::ServerError err = server::LicenseLibrary::GetDeviceCount(device_count);
|
||||
if (err != server::SERVER_SUCCESS) return -1;
|
||||
|
||||
// 1. Get All GPU UUID
|
||||
std::vector<std::string> uuid_array;
|
||||
err = server::LicenseLibrary::GetUUID(device_count, uuid_array);
|
||||
if (err != server::SERVER_SUCCESS) return -1;
|
||||
|
||||
// 2. Get UUID SHA256
|
||||
std::vector<std::string> uuid_sha256_array;
|
||||
err = server::LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, uuid_sha256_array);
|
||||
if (err != server::SERVER_SUCCESS) return -1;
|
||||
|
||||
// 3. 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];
|
||||
}
|
||||
|
||||
|
||||
// 4. Generate GPU_info File
|
||||
err = server::LicenseLibrary::GPUinfoFileSerialization(system_info_filename,
|
||||
device_count,
|
||||
uuid_encrption_map);
|
||||
if (err != server::SERVER_SUCCESS) return -1;
|
||||
|
||||
printf("Generate GPU_info File Success\n");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
//#include "utils/Log.h"
|
||||
//#include "LicenseLibrary.h"
|
||||
//#include "utils/Error.h"
|
||||
//
|
||||
//#include <iostream>
|
||||
//#include <getopt.h>
|
||||
//#include <memory.h>
|
||||
//// Not provide path: current work path will be used and system.info.
|
||||
//using namespace zilliz::milvus;
|
||||
//
|
||||
//void
|
||||
//print_usage(const std::string &app_name) {
|
||||
// printf("\n Usage: %s [OPTIONS]\n\n", app_name.c_str());
|
||||
// printf(" Options:\n");
|
||||
// printf(" -h --help Print this help\n");
|
||||
// printf(" -s --sysinfo filename Generate system info file as given name\n");
|
||||
// printf("\n");
|
||||
//}
|
||||
//
|
||||
//int main(int argc, char *argv[]) {
|
||||
// std::string app_name = argv[0];
|
||||
// if (argc != 1 && argc != 3) {
|
||||
// print_usage(app_name);
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
//
|
||||
// static struct option long_options[] = {{"system_info", required_argument, 0, 's'},
|
||||
// {"help", no_argument, 0, 'h'},
|
||||
// {NULL, 0, 0, 0}};
|
||||
// int value = 0;
|
||||
// int option_index = 0;
|
||||
// std::string system_info_filename = "./system.info";
|
||||
// while ((value = getopt_long(argc, argv, "s:h", long_options, &option_index)) != -1) {
|
||||
// switch (value) {
|
||||
// case 's': {
|
||||
// char *system_info_filename_ptr = strdup(optarg);
|
||||
// system_info_filename = system_info_filename_ptr;
|
||||
// free(system_info_filename_ptr);
|
||||
//// printf("Generate system info file: %s\n", system_info_filename.c_str());
|
||||
// break;
|
||||
// }
|
||||
// case 'h':print_usage(app_name);
|
||||
// return EXIT_SUCCESS;
|
||||
// case '?':print_usage(app_name);
|
||||
// return EXIT_FAILURE;
|
||||
// default:print_usage(app_name);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// int device_count = 0;
|
||||
// server::ServerError err = server::LicenseLibrary::GetDeviceCount(device_count);
|
||||
// if (err != server::SERVER_SUCCESS) return -1;
|
||||
//
|
||||
// // 1. Get All GPU UUID
|
||||
// std::vector<std::string> uuid_array;
|
||||
// err = server::LicenseLibrary::GetUUID(device_count, uuid_array);
|
||||
// if (err != server::SERVER_SUCCESS) return -1;
|
||||
//
|
||||
// // 2. Get UUID SHA256
|
||||
// std::vector<std::string> uuid_sha256_array;
|
||||
// err = server::LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, uuid_sha256_array);
|
||||
// if (err != server::SERVER_SUCCESS) return -1;
|
||||
//
|
||||
// // 3. 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];
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // 4. Generate GPU_info File
|
||||
// err = server::LicenseLibrary::GPUinfoFileSerialization(system_info_filename,
|
||||
// device_count,
|
||||
// uuid_encrption_map);
|
||||
// if (err != server::SERVER_SUCCESS) return -1;
|
||||
//
|
||||
// printf("Generate GPU_info File Success\n");
|
||||
//
|
||||
//
|
||||
// return 0;
|
||||
//}
|
@ -1,131 +1,131 @@
|
||||
#include "LicenseCheck.h"
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include <boost/archive/binary_oarchive.hpp>
|
||||
#include <boost/archive/binary_iarchive.hpp>
|
||||
//#include <boost/foreach.hpp>
|
||||
//#include <boost/serialization/vector.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/serialization/map.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace milvus {
|
||||
namespace server {
|
||||
|
||||
LicenseCheck::LicenseCheck() {
|
||||
|
||||
}
|
||||
|
||||
LicenseCheck::~LicenseCheck() {
|
||||
StopCountingDown();
|
||||
}
|
||||
|
||||
ServerError
|
||||
LicenseCheck::LegalityCheck(const std::string &license_file_path) {
|
||||
|
||||
int device_count;
|
||||
LicenseLibrary::GetDeviceCount(device_count);
|
||||
std::vector<std::string> uuid_array;
|
||||
LicenseLibrary::GetUUID(device_count, uuid_array);
|
||||
|
||||
std::vector<std::string> sha_array;
|
||||
LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, sha_array);
|
||||
|
||||
int output_device_count;
|
||||
std::map<int, std::string> uuid_encryption_map;
|
||||
time_t starting_time;
|
||||
time_t end_time;
|
||||
ServerError err = LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||
output_device_count,
|
||||
uuid_encryption_map,
|
||||
starting_time,
|
||||
end_time);
|
||||
if(err !=SERVER_SUCCESS)
|
||||
{
|
||||
std::cout << "License check error: 01" << std::endl;
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
time_t system_time;
|
||||
LicenseLibrary::GetSystemTime(system_time);
|
||||
|
||||
if (device_count != output_device_count) {
|
||||
std::cout << "License check error: 02" << std::endl;
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
if (sha_array[i] != uuid_encryption_map[i]) {
|
||||
std::cout << "License check error: 03" << std::endl;
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
}
|
||||
if (system_time < starting_time || system_time > end_time) {
|
||||
std::cout << "License check error: 04" << std::endl;
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
std::cout << "Legality Check Success" << std::endl;
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
// Part 2: Timing check license
|
||||
|
||||
ServerError
|
||||
LicenseCheck::AlterFile(const std::string &license_file_path,
|
||||
const boost::system::error_code &ec,
|
||||
boost::asio::deadline_timer *pt) {
|
||||
|
||||
ServerError err = LicenseCheck::LegalityCheck(license_file_path);
|
||||
if(err!=SERVER_SUCCESS) {
|
||||
std::cout << "license file check error" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::cout << "---runing---" << std::endl;
|
||||
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));
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
ServerError
|
||||
LicenseCheck::StartCountingDown(const std::string &license_file_path) {
|
||||
|
||||
if (!LicenseLibrary::IsFileExistent(license_file_path)) {
|
||||
std::cout << "license file not exist" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//create a thread to run AlterFile
|
||||
if(counting_thread_ == nullptr) {
|
||||
counting_thread_ = std::make_shared<std::thread>([&]() {
|
||||
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));
|
||||
io_service_.run();//this thread will block here
|
||||
});
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
ServerError
|
||||
LicenseCheck::StopCountingDown() {
|
||||
if(!io_service_.stopped()) {
|
||||
io_service_.stop();
|
||||
}
|
||||
|
||||
if(counting_thread_ != nullptr) {
|
||||
counting_thread_->join();
|
||||
counting_thread_ = nullptr;
|
||||
}
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
//#include "LicenseCheck.h"
|
||||
//#include <iostream>
|
||||
//#include <thread>
|
||||
//
|
||||
//#include <boost/archive/binary_oarchive.hpp>
|
||||
//#include <boost/archive/binary_iarchive.hpp>
|
||||
////#include <boost/foreach.hpp>
|
||||
////#include <boost/serialization/vector.hpp>
|
||||
//#include <boost/filesystem/path.hpp>
|
||||
//#include <boost/serialization/map.hpp>
|
||||
//#include <boost/filesystem/operations.hpp>
|
||||
//#include <boost/thread.hpp>
|
||||
//#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
//
|
||||
//
|
||||
//namespace zilliz {
|
||||
//namespace milvus {
|
||||
//namespace server {
|
||||
//
|
||||
//LicenseCheck::LicenseCheck() {
|
||||
//
|
||||
//}
|
||||
//
|
||||
//LicenseCheck::~LicenseCheck() {
|
||||
// StopCountingDown();
|
||||
//}
|
||||
//
|
||||
//ServerError
|
||||
//LicenseCheck::LegalityCheck(const std::string &license_file_path) {
|
||||
//
|
||||
// int device_count;
|
||||
// LicenseLibrary::GetDeviceCount(device_count);
|
||||
// std::vector<std::string> uuid_array;
|
||||
// LicenseLibrary::GetUUID(device_count, uuid_array);
|
||||
//
|
||||
// std::vector<std::string> sha_array;
|
||||
// LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, sha_array);
|
||||
//
|
||||
// int output_device_count;
|
||||
// std::map<int, std::string> uuid_encryption_map;
|
||||
// time_t starting_time;
|
||||
// time_t end_time;
|
||||
// ServerError err = LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||
// output_device_count,
|
||||
// uuid_encryption_map,
|
||||
// starting_time,
|
||||
// end_time);
|
||||
// if(err !=SERVER_SUCCESS)
|
||||
// {
|
||||
// std::cout << "License check error: 01" << std::endl;
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// time_t system_time;
|
||||
// LicenseLibrary::GetSystemTime(system_time);
|
||||
//
|
||||
// if (device_count != output_device_count) {
|
||||
// std::cout << "License check error: 02" << std::endl;
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// for (int i = 0; i < device_count; ++i) {
|
||||
// if (sha_array[i] != uuid_encryption_map[i]) {
|
||||
// std::cout << "License check error: 03" << std::endl;
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// }
|
||||
// if (system_time < starting_time || system_time > end_time) {
|
||||
// std::cout << "License check error: 04" << std::endl;
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// std::cout << "Legality Check Success" << std::endl;
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
//
|
||||
//// Part 2: Timing check license
|
||||
//
|
||||
//ServerError
|
||||
//LicenseCheck::AlterFile(const std::string &license_file_path,
|
||||
// const boost::system::error_code &ec,
|
||||
// boost::asio::deadline_timer *pt) {
|
||||
//
|
||||
// ServerError err = LicenseCheck::LegalityCheck(license_file_path);
|
||||
// if(err!=SERVER_SUCCESS) {
|
||||
// std::cout << "license file check error" << std::endl;
|
||||
// exit(1);
|
||||
// }
|
||||
//
|
||||
// std::cout << "---runing---" << std::endl;
|
||||
// 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));
|
||||
//
|
||||
// return SERVER_SUCCESS;
|
||||
//
|
||||
//}
|
||||
//
|
||||
//ServerError
|
||||
//LicenseCheck::StartCountingDown(const std::string &license_file_path) {
|
||||
//
|
||||
// if (!LicenseLibrary::IsFileExistent(license_file_path)) {
|
||||
// std::cout << "license file not exist" << std::endl;
|
||||
// exit(1);
|
||||
// }
|
||||
//
|
||||
// //create a thread to run AlterFile
|
||||
// if(counting_thread_ == nullptr) {
|
||||
// counting_thread_ = std::make_shared<std::thread>([&]() {
|
||||
// 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));
|
||||
// io_service_.run();//this thread will block here
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
//
|
||||
//ServerError
|
||||
//LicenseCheck::StopCountingDown() {
|
||||
// if(!io_service_.stopped()) {
|
||||
// io_service_.stop();
|
||||
// }
|
||||
//
|
||||
// if(counting_thread_ != nullptr) {
|
||||
// counting_thread_->join();
|
||||
// counting_thread_ = nullptr;
|
||||
// }
|
||||
//
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
//
|
||||
//}
|
||||
//}
|
||||
//}
|
@ -1,52 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "utils/Error.h"
|
||||
#include "LicenseLibrary.h"
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
#include <thread>
|
||||
#include <memory>
|
||||
|
||||
namespace zilliz {
|
||||
namespace milvus {
|
||||
namespace server {
|
||||
|
||||
class LicenseCheck {
|
||||
private:
|
||||
LicenseCheck();
|
||||
~LicenseCheck();
|
||||
|
||||
public:
|
||||
static LicenseCheck &
|
||||
GetInstance() {
|
||||
static LicenseCheck instance;
|
||||
return instance;
|
||||
};
|
||||
|
||||
static ServerError
|
||||
LegalityCheck(const std::string &license_file_path);
|
||||
|
||||
ServerError
|
||||
StartCountingDown(const std::string &license_file_path);
|
||||
|
||||
ServerError
|
||||
StopCountingDown();
|
||||
|
||||
private:
|
||||
static ServerError
|
||||
AlterFile(const std::string &license_file_path,
|
||||
const boost::system::error_code &ec,
|
||||
boost::asio::deadline_timer *pt);
|
||||
|
||||
private:
|
||||
boost::asio::io_service io_service_;
|
||||
std::shared_ptr<std::thread> counting_thread_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//#pragma once
|
||||
//
|
||||
//#include "utils/Error.h"
|
||||
//#include "LicenseLibrary.h"
|
||||
//
|
||||
//#include <boost/asio.hpp>
|
||||
//
|
||||
//#include <thread>
|
||||
//#include <memory>
|
||||
//
|
||||
//namespace zilliz {
|
||||
//namespace milvus {
|
||||
//namespace server {
|
||||
//
|
||||
//class LicenseCheck {
|
||||
//private:
|
||||
// LicenseCheck();
|
||||
// ~LicenseCheck();
|
||||
//
|
||||
//public:
|
||||
// static LicenseCheck &
|
||||
// GetInstance() {
|
||||
// static LicenseCheck instance;
|
||||
// return instance;
|
||||
// };
|
||||
//
|
||||
// static ServerError
|
||||
// LegalityCheck(const std::string &license_file_path);
|
||||
//
|
||||
// ServerError
|
||||
// StartCountingDown(const std::string &license_file_path);
|
||||
//
|
||||
// ServerError
|
||||
// StopCountingDown();
|
||||
//
|
||||
//private:
|
||||
// static ServerError
|
||||
// AlterFile(const std::string &license_file_path,
|
||||
// const boost::system::error_code &ec,
|
||||
// boost::asio::deadline_timer *pt);
|
||||
//
|
||||
//private:
|
||||
// boost::asio::io_service io_service_;
|
||||
// std::shared_ptr<std::thread> counting_thread_;
|
||||
//
|
||||
//};
|
||||
//
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
//
|
||||
//
|
||||
|
@ -1,86 +1,86 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
* Proprietary and confidential.
|
||||
******************************************************************************/
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <boost/serialization/access.hpp>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
||||
class LicenseFile {
|
||||
public:
|
||||
LicenseFile() = default;
|
||||
|
||||
LicenseFile(const int &device_count,
|
||||
const std::map<int, std::string> &uuid_encryption_map,
|
||||
const time_t &starting_time,
|
||||
const time_t &end_time)
|
||||
: device_count_(device_count),
|
||||
uuid_encryption_map_(uuid_encryption_map),
|
||||
starting_time_(starting_time),
|
||||
end_time_(end_time) {}
|
||||
|
||||
int get_device_count() {
|
||||
return device_count_;
|
||||
}
|
||||
std::map<int, std::string> &get_uuid_encryption_map() {
|
||||
return uuid_encryption_map_;
|
||||
}
|
||||
time_t get_starting_time() {
|
||||
return starting_time_;
|
||||
}
|
||||
time_t get_end_time() {
|
||||
return end_time_;
|
||||
}
|
||||
|
||||
public:
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template<typename Archive>
|
||||
void serialize(Archive &ar, const unsigned int version) {
|
||||
ar & device_count_;
|
||||
ar & uuid_encryption_map_;
|
||||
ar & starting_time_;
|
||||
ar & end_time_;
|
||||
}
|
||||
|
||||
public:
|
||||
int device_count_ = 0;
|
||||
std::map<int, std::string> uuid_encryption_map_;
|
||||
time_t starting_time_ = 0;
|
||||
time_t end_time_ = 0;
|
||||
};
|
||||
|
||||
class SerializedLicenseFile {
|
||||
public:
|
||||
~SerializedLicenseFile() {
|
||||
if (license_file_ != nullptr) {
|
||||
delete (license_file_);
|
||||
license_file_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
set_license_file(LicenseFile *license_file) {
|
||||
license_file_ = license_file;
|
||||
}
|
||||
|
||||
LicenseFile *get_license_file() {
|
||||
return license_file_;
|
||||
}
|
||||
private:
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template<typename Archive>
|
||||
void serialize(Archive &ar, const unsigned int version) {
|
||||
ar & license_file_;
|
||||
}
|
||||
|
||||
private:
|
||||
LicenseFile *license_file_ = nullptr;
|
||||
};
|
||||
|
||||
///*******************************************************************************
|
||||
// * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// * Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// * Proprietary and confidential.
|
||||
// ******************************************************************************/
|
||||
//#pragma once
|
||||
//
|
||||
//
|
||||
//#include <boost/serialization/access.hpp>
|
||||
//#include <string>
|
||||
//#include <map>
|
||||
//
|
||||
//
|
||||
//class LicenseFile {
|
||||
// public:
|
||||
// LicenseFile() = default;
|
||||
//
|
||||
// LicenseFile(const int &device_count,
|
||||
// const std::map<int, std::string> &uuid_encryption_map,
|
||||
// const time_t &starting_time,
|
||||
// const time_t &end_time)
|
||||
// : device_count_(device_count),
|
||||
// uuid_encryption_map_(uuid_encryption_map),
|
||||
// starting_time_(starting_time),
|
||||
// end_time_(end_time) {}
|
||||
//
|
||||
// int get_device_count() {
|
||||
// return device_count_;
|
||||
// }
|
||||
// std::map<int, std::string> &get_uuid_encryption_map() {
|
||||
// return uuid_encryption_map_;
|
||||
// }
|
||||
// time_t get_starting_time() {
|
||||
// return starting_time_;
|
||||
// }
|
||||
// time_t get_end_time() {
|
||||
// return end_time_;
|
||||
// }
|
||||
//
|
||||
// public:
|
||||
// friend class boost::serialization::access;
|
||||
//
|
||||
// template<typename Archive>
|
||||
// void serialize(Archive &ar, const unsigned int version) {
|
||||
// ar & device_count_;
|
||||
// ar & uuid_encryption_map_;
|
||||
// ar & starting_time_;
|
||||
// ar & end_time_;
|
||||
// }
|
||||
//
|
||||
// public:
|
||||
// int device_count_ = 0;
|
||||
// std::map<int, std::string> uuid_encryption_map_;
|
||||
// time_t starting_time_ = 0;
|
||||
// time_t end_time_ = 0;
|
||||
//};
|
||||
//
|
||||
//class SerializedLicenseFile {
|
||||
// public:
|
||||
// ~SerializedLicenseFile() {
|
||||
// if (license_file_ != nullptr) {
|
||||
// delete (license_file_);
|
||||
// license_file_ = nullptr;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// void
|
||||
// set_license_file(LicenseFile *license_file) {
|
||||
// license_file_ = license_file;
|
||||
// }
|
||||
//
|
||||
// LicenseFile *get_license_file() {
|
||||
// return license_file_;
|
||||
// }
|
||||
// private:
|
||||
// friend class boost::serialization::access;
|
||||
//
|
||||
// template<typename Archive>
|
||||
// void serialize(Archive &ar, const unsigned int version) {
|
||||
// ar & license_file_;
|
||||
// }
|
||||
//
|
||||
// private:
|
||||
// LicenseFile *license_file_ = nullptr;
|
||||
//};
|
||||
//
|
||||
|
@ -1,121 +1,121 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <getopt.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "utils/Log.h"
|
||||
#include "license/LicenseLibrary.h"
|
||||
#include "utils/Error.h"
|
||||
|
||||
|
||||
using namespace zilliz::milvus;
|
||||
// Not provide path: current work path will be used and system.info.
|
||||
|
||||
void
|
||||
print_usage(const std::string &app_name) {
|
||||
printf("\n Usage: %s [OPTIONS]\n\n", app_name.c_str());
|
||||
printf(" Options:\n");
|
||||
printf(" -h --help Print this help\n");
|
||||
printf(" -s --sysinfo filename sysinfo file location\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(" -e --end time Set end time (format: YYYY-MM-DD)\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
std::string app_name = argv[0];
|
||||
// if (argc != 1 && argc != 3) {
|
||||
// print_usage(app_name);
|
||||
// return EXIT_FAILURE;
|
||||
//
|
||||
//#include <iostream>
|
||||
//#include <getopt.h>
|
||||
//#include <memory.h>
|
||||
//
|
||||
//#include "utils/Log.h"
|
||||
//#include "license/LicenseLibrary.h"
|
||||
//#include "utils/Error.h"
|
||||
//
|
||||
//
|
||||
//using namespace zilliz::milvus;
|
||||
//// Not provide path: current work path will be used and system.info.
|
||||
//
|
||||
//void
|
||||
//print_usage(const std::string &app_name) {
|
||||
// printf("\n Usage: %s [OPTIONS]\n\n", app_name.c_str());
|
||||
// printf(" Options:\n");
|
||||
// printf(" -h --help Print this help\n");
|
||||
// printf(" -s --sysinfo filename sysinfo file location\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(" -e --end time Set end time (format: YYYY-MM-DD)\n");
|
||||
// printf("\n");
|
||||
//}
|
||||
//
|
||||
//int main(int argc, char *argv[]) {
|
||||
// std::string app_name = argv[0];
|
||||
//// if (argc != 1 && argc != 3) {
|
||||
//// print_usage(app_name);
|
||||
//// 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;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
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;
|
||||
}
|
||||
// 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
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "LicenseLibrary.h"
|
||||
#include "utils/Log.h"
|
||||
#include <cuda_runtime.h>
|
||||
#include <nvml.h>
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include <boost/archive/binary_oarchive.hpp>
|
||||
#include <boost/archive/binary_iarchive.hpp>
|
||||
//#include <boost/foreach.hpp>
|
||||
//#include <boost/serialization/vector.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/serialization/map.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace milvus {
|
||||
namespace server {
|
||||
|
||||
constexpr int LicenseLibrary::sha256_length_;
|
||||
|
||||
// Part 0: File check
|
||||
bool
|
||||
LicenseLibrary::IsFileExistent(const std::string &path) {
|
||||
|
||||
boost::system::error_code error;
|
||||
auto file_status = boost::filesystem::status(path, error);
|
||||
if (error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!boost::filesystem::exists(file_status)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !boost::filesystem::is_directory(file_status);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
//// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
//// Proprietary and confidential.
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//#include "LicenseLibrary.h"
|
||||
//#include "utils/Log.h"
|
||||
//#include <cuda_runtime.h>
|
||||
//#include <nvml.h>
|
||||
//#include <openssl/md5.h>
|
||||
//#include <openssl/sha.h>
|
||||
//
|
||||
//#include <boost/archive/binary_oarchive.hpp>
|
||||
//#include <boost/archive/binary_iarchive.hpp>
|
||||
////#include <boost/foreach.hpp>
|
||||
////#include <boost/serialization/vector.hpp>
|
||||
//#include <boost/filesystem/path.hpp>
|
||||
//#include <boost/serialization/map.hpp>
|
||||
//#include <boost/filesystem/operations.hpp>
|
||||
//
|
||||
//
|
||||
//namespace zilliz {
|
||||
//namespace milvus {
|
||||
//namespace server {
|
||||
//
|
||||
//constexpr int LicenseLibrary::sha256_length_;
|
||||
//
|
||||
//// Part 0: File check
|
||||
//bool
|
||||
//LicenseLibrary::IsFileExistent(const std::string &path) {
|
||||
//
|
||||
// boost::system::error_code error;
|
||||
// auto file_status = boost::filesystem::status(path, error);
|
||||
// if (error) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if (!boost::filesystem::exists(file_status)) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// return !boost::filesystem::is_directory(file_status);
|
||||
//}
|
||||
//
|
||||
//// Part 1: Get GPU Info
|
||||
//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) {
|
||||
//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<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));
|
||||
// oa << serialized_secret_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::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) {
|
||||
//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
|
||||
////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;
|
||||
//
|
||||
// std::ifstream file(path);
|
||||
// boost::archive::binary_iarchive ia(file);
|
||||
// ia.register_type<SecretFile>();
|
||||
// SerializedSecretFile serialized_secret_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();
|
||||
//
|
||||
// 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;
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
//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
|
||||
|
||||
#include "LicenseFile.h"
|
||||
#include "GPUInfoFile.h"
|
||||
|
||||
#include "utils/Error.h"
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace milvus {
|
||||
namespace server {
|
||||
|
||||
class LicenseLibrary {
|
||||
public:
|
||||
// Part 0: File check
|
||||
static bool
|
||||
IsFileExistent(const std::string &path);
|
||||
|
||||
// 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);
|
||||
|
||||
//#pragma once
|
||||
//
|
||||
//#include "LicenseFile.h"
|
||||
//#include "GPUInfoFile.h"
|
||||
//
|
||||
//#include "utils/Error.h"
|
||||
//
|
||||
//#include <boost/asio.hpp>
|
||||
//#include <boost/thread.hpp>
|
||||
//#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
//
|
||||
//#include <vector>
|
||||
//#include <map>
|
||||
//#include <time.h>
|
||||
//
|
||||
//
|
||||
//namespace zilliz {
|
||||
//namespace milvus {
|
||||
//namespace server {
|
||||
//
|
||||
//class LicenseLibrary {
|
||||
// public:
|
||||
// // Part 0: File check
|
||||
// static bool
|
||||
// IsFileExistent(const std::string &path);
|
||||
//
|
||||
// // Part 1: Get GPU Info
|
||||
// static ServerError
|
||||
// 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);
|
||||
// GetDeviceCount(int &device_count);
|
||||
//
|
||||
// static ServerError
|
||||
// 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);
|
||||
|
||||
// Part 3: File attribute: UpdateTime Time/ Size/ MD5
|
||||
static ServerError
|
||||
GetFileUpdateTimeAndSize(const std::string &path, time_t &update_time, off_t &file_size);
|
||||
|
||||
static ServerError
|
||||
GetFileMD5(const std::string &path, std::string &filemd5);
|
||||
|
||||
// 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;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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
|
||||
//// 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);
|
||||
////
|
||||
//// static ServerError
|
||||
//// 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);
|
||||
//
|
||||
// // Part 3: File attribute: UpdateTime Time/ Size/ MD5
|
||||
// static ServerError
|
||||
// GetFileUpdateTimeAndSize(const std::string &path, time_t &update_time, off_t &file_size);
|
||||
//
|
||||
// static ServerError
|
||||
// GetFileMD5(const std::string &path, std::string &filemd5);
|
||||
//
|
||||
// // 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;
|
||||
//};
|
||||
//
|
||||
//
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
|
@ -51,7 +51,7 @@ bool CommonUtil::GetSystemAvailableThreads(unsigned int &threadCnt) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommonUtil::IsDirectoryExit(const std::string &path)
|
||||
bool CommonUtil::IsDirectoryExist(const std::string &path)
|
||||
{
|
||||
DIR *dp = 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));
|
||||
}
|
||||
|
||||
void ConvertTime(tm time_struct, time_t &time_integer) {
|
||||
void CommonUtil::ConvertTime(tm time_struct, time_t &time_integer) {
|
||||
time_integer = mktime(&time_struct);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ class CommonUtil {
|
||||
static bool GetSystemAvailableThreads(unsigned int &threadCnt);
|
||||
|
||||
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 DeleteDirectory(const std::string &path);
|
||||
|
||||
|
@ -46,6 +46,6 @@ set(unittest_libs
|
||||
add_subdirectory(server)
|
||||
add_subdirectory(db)
|
||||
add_subdirectory(faiss_wrapper)
|
||||
add_subdirectory(license)
|
||||
#add_subdirectory(license)
|
||||
add_subdirectory(metrics)
|
||||
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
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
* Proprietary and confidential.
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#include "utils/Log.h"
|
||||
#include "license/LicenseLibrary.h"
|
||||
#include "utils/Error.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace zilliz::milvus;
|
||||
|
||||
TEST(LicenseLibraryTest, FILE_EXISTENT_TEST) {
|
||||
|
||||
std::string hosts_file = "/etc/hosts";
|
||||
ASSERT_EQ(server::LicenseLibrary::IsFileExistent(hosts_file), true);
|
||||
|
||||
std::string no_exist_file = "/temp/asdaasd";
|
||||
ASSERT_EQ(server::LicenseLibrary::IsFileExistent(no_exist_file), false);
|
||||
|
||||
std::string directory = "/tmp";
|
||||
ASSERT_EQ(server::LicenseLibrary::IsFileExistent(directory), false);
|
||||
}
|
||||
|
||||
TEST(LicenseLibraryTest, GPU_INFO_TEST) {
|
||||
|
||||
int device_count = 0;
|
||||
server::ServerError err = server::LicenseLibrary::GetDeviceCount(device_count);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
std::cout << "Device Count: " << device_count << std::endl;
|
||||
|
||||
std::vector<std::string> uuid_array;
|
||||
err = server::LicenseLibrary::GetUUID(device_count, uuid_array);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
for (long i = 0; i < device_count; ++i) {
|
||||
std::cout << "Device Id: " << i << ", UUID: " << uuid_array[i] << std::endl;
|
||||
}
|
||||
|
||||
std::vector<std::string> uuid_md5_array;
|
||||
err = server::LicenseLibrary::GetUUIDMD5(device_count, uuid_array, uuid_md5_array);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
for (long i = 0; i < device_count; ++i) {
|
||||
std::cout << "Device Id: " << i << ", UUID: " << uuid_array[i] << ", UUID_MD5: " << uuid_md5_array[i]
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
std::vector<std::string> uuid_sha256_array;
|
||||
err = server::LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, uuid_sha256_array);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
for (long i = 0; i < device_count; ++i) {
|
||||
std::cout << "Device Id: " << i << ", UUID: " << uuid_array[i] << ", UUID_SHA256: "
|
||||
<< uuid_sha256_array[i] << std::endl;
|
||||
}
|
||||
|
||||
time_t systemtime;
|
||||
err = server::LicenseLibrary::GetSystemTime(systemtime);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
std::cout << "System Time: " << systemtime << std::endl;
|
||||
|
||||
}
|
||||
|
||||
TEST(LicenseLibraryTest, LICENSE_FILE_TEST) {
|
||||
|
||||
// 0. File check
|
||||
std::string test("/tmp/a.test");
|
||||
bool is = server::LicenseLibrary::IsFileExistent(test);
|
||||
ASSERT_EQ(is, false);
|
||||
|
||||
// 1. Get Device Count
|
||||
int device_count = 0;
|
||||
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);
|
||||
///*******************************************************************************
|
||||
// * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// * Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// * Proprietary and confidential.
|
||||
// ******************************************************************************/
|
||||
//
|
||||
//
|
||||
//#include "utils/Log.h"
|
||||
//#include "license/LicenseLibrary.h"
|
||||
//#include "utils/Error.h"
|
||||
//
|
||||
//#include <gtest/gtest.h>
|
||||
//#include <iostream>
|
||||
//
|
||||
//
|
||||
//using namespace zilliz::milvus;
|
||||
//
|
||||
//TEST(LicenseLibraryTest, FILE_EXISTENT_TEST) {
|
||||
//
|
||||
// std::string hosts_file = "/etc/hosts";
|
||||
// ASSERT_EQ(server::LicenseLibrary::IsFileExistent(hosts_file), true);
|
||||
//
|
||||
// std::string no_exist_file = "/temp/asdaasd";
|
||||
// ASSERT_EQ(server::LicenseLibrary::IsFileExistent(no_exist_file), false);
|
||||
//
|
||||
// std::string directory = "/tmp";
|
||||
// ASSERT_EQ(server::LicenseLibrary::IsFileExistent(directory), false);
|
||||
//}
|
||||
//
|
||||
//TEST(LicenseLibraryTest, GPU_INFO_TEST) {
|
||||
//
|
||||
// int device_count = 0;
|
||||
// server::ServerError err = server::LicenseLibrary::GetDeviceCount(device_count);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// std::cout << "Device Count: " << device_count << std::endl;
|
||||
//
|
||||
// std::vector<std::string> uuid_array;
|
||||
// err = server::LicenseLibrary::GetUUID(device_count, uuid_array);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// for (long i = 0; i < device_count; ++i) {
|
||||
// std::cout << "Device Id: " << i << ", UUID: " << uuid_array[i] << std::endl;
|
||||
// }
|
||||
//
|
||||
// std::vector<std::string> uuid_md5_array;
|
||||
// err = server::LicenseLibrary::GetUUIDMD5(device_count, uuid_array, uuid_md5_array);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// for (long i = 0; i < device_count; ++i) {
|
||||
// std::cout << "Device Id: " << i << ", UUID: " << uuid_array[i] << ", UUID_MD5: " << uuid_md5_array[i]
|
||||
// << std::endl;
|
||||
// }
|
||||
//
|
||||
// std::vector<std::string> uuid_sha256_array;
|
||||
// err = server::LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, uuid_sha256_array);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// for (long i = 0; i < device_count; ++i) {
|
||||
// std::cout << "Device Id: " << i << ", UUID: " << uuid_array[i] << ", UUID_SHA256: "
|
||||
// << uuid_sha256_array[i] << std::endl;
|
||||
// }
|
||||
//
|
||||
// time_t systemtime;
|
||||
// err = server::LicenseLibrary::GetSystemTime(systemtime);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// std::cout << "System Time: " << systemtime << std::endl;
|
||||
//
|
||||
//}
|
||||
//
|
||||
//TEST(LicenseLibraryTest, LICENSE_FILE_TEST) {
|
||||
//
|
||||
// // 0. File check
|
||||
// std::string test("/tmp/a.test");
|
||||
// bool is = server::LicenseLibrary::IsFileExistent(test);
|
||||
// ASSERT_EQ(is, false);
|
||||
//
|
||||
// // 1. Get Device Count
|
||||
// int device_count = 0;
|
||||
// server::ServerError err = server::LicenseLibrary::GetDeviceCount(device_count);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// // 16. Get License File MD5
|
||||
// std::string file_md5;
|
||||
// err = server::LicenseLibrary::GetFileMD5(license_file_path, file_md5);
|
||||
// // 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);
|
||||
|
||||
|
||||
|
||||
// // 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);
|
||||
//
|
||||
// // 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);
|
||||
|
||||
// // 18. Define output var
|
||||
// time_t output_update_time;
|
||||
// off_t output_file_size;
|
||||
//
|
||||
// // 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;
|
||||
// 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);
|
||||
//
|
||||
// // 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(update_time, output_update_time);
|
||||
// ASSERT_EQ(file_size, output_file_size);
|
||||
// ASSERT_EQ(device_count, output_device_count);
|
||||
// ASSERT_EQ(starting_time, output_starting_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);
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
@ -18,6 +18,7 @@ set(utils_srcs
|
||||
${MILVUS_ENGINE_SRC}/utils/StringHelpFunctions.cpp
|
||||
${MILVUS_ENGINE_SRC}/utils/TimeRecorder.cpp
|
||||
${MILVUS_ENGINE_SRC}/utils/CommonUtil.cpp
|
||||
${MILVUS_ENGINE_SRC}/utils/LogUtil.cpp
|
||||
)
|
||||
|
||||
cuda_add_executable(server_test
|
||||
@ -54,3 +55,11 @@ target_link_libraries(server_test
|
||||
)
|
||||
|
||||
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)
|
||||
|
27
cpp/unittest/server/appendix/log_config.conf
Normal file
27
cpp/unittest/server/appendix/log_config.conf
Normal file
@ -0,0 +1,27 @@
|
||||
* GLOBAL:
|
||||
FORMAT = "%datetime | %level | %logger | %msg"
|
||||
FILENAME = "/tmp/milvus/logs/milvus-%datetime{%H:%m}-global.log"
|
||||
ENABLED = true
|
||||
TO_FILE = true
|
||||
TO_STANDARD_OUTPUT = false
|
||||
SUBSECOND_PRECISION = 3
|
||||
PERFORMANCE_TRACKING = false
|
||||
MAX_LOG_FILE_SIZE = 2097152 ## Throw log files away after 2MB
|
||||
* DEBUG:
|
||||
FILENAME = "/tmp/milvus/logs/milvus-%datetime{%H:%m}-debug.log"
|
||||
ENABLED = true
|
||||
* WARNING:
|
||||
FILENAME = "/tmp/milvus/logs/milvus-%datetime{%H:%m}-warning.log"
|
||||
* TRACE:
|
||||
FILENAME = "/tmp/milvus/logs/milvus-%datetime{%H:%m}-trace.log"
|
||||
* VERBOSE:
|
||||
FORMAT = "%datetime{%d/%M/%y} | %level-%vlevel | %msg"
|
||||
TO_FILE = false
|
||||
TO_STANDARD_OUTPUT = false
|
||||
## Error logs
|
||||
* ERROR:
|
||||
ENABLED = true
|
||||
FILENAME = "/tmp/milvus/logs/milvus-%datetime{%H:%m}-error.log"
|
||||
* FATAL:
|
||||
ENABLED = true
|
||||
FILENAME = "/tmp/milvus/logs/milvus-%datetime{%H:%m}-fatal.log"
|
28
cpp/unittest/server/appendix/server_config.yaml
Normal file
28
cpp/unittest/server/appendix/server_config.yaml
Normal file
@ -0,0 +1,28 @@
|
||||
server_config:
|
||||
address: 0.0.0.0
|
||||
port: 19530 # the port milvus listen to, default: 19530, range: 1025 ~ 65534
|
||||
gpu_index: 0 # the gpu milvus use, default: 0, range: 0 ~ gpu number - 1
|
||||
mode: single # milvus deployment type: single, cluster
|
||||
|
||||
db_config:
|
||||
db_path: /tmp/milvus # milvus data storage path
|
||||
db_backend_url: http://127.0.0.1 # meta database uri
|
||||
index_building_threshold: 1024 # index building trigger threshold, default: 1024, unit: MB
|
||||
archive_disk_threshold: 512 # triger archive action if storage size exceed this value, unit: GB
|
||||
archive_days_threshold: 30 # files older than x days will be archived, unit: day
|
||||
|
||||
metric_config:
|
||||
is_startup: off # if monitoring start: on, off
|
||||
collector: prometheus # metrics collector: prometheus
|
||||
prometheus_config: # following are prometheus configure
|
||||
collect_type: pull # prometheus collect data method
|
||||
port: 8080 # the port prometheus use to fetch metrics
|
||||
push_gateway_ip_address: 127.0.0.1 # push method configure: push gateway ip address
|
||||
push_gateway_port: 9091 # push method configure: push gateway port
|
||||
|
||||
|
||||
license_config: # license configure
|
||||
license_path: "/tmp/milvus/system.license" # license file path
|
||||
|
||||
cache_config: # cache configure
|
||||
cpu_cache_capacity: 16 # how many memory are used as cache, unit: GB, range: 0 ~ less than total memory
|
@ -11,6 +11,23 @@
|
||||
|
||||
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) {
|
||||
cache::CacheMgr *cpu_mgr = cache::CpuCacheMgr::GetInstance();
|
||||
|
||||
@ -78,4 +95,35 @@ TEST(CacheTest, GPU_CACHE_TEST) {
|
||||
|
||||
gpu_mgr->ClearCache();
|
||||
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;
|
||||
|
||||
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) {
|
||||
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);
|
||||
|
||||
config_mgr->Print();
|
||||
|
||||
server::ConfigNode& root_config = config_mgr->GetRootNode();
|
||||
server::ConfigNode& server_config = root_config.GetChild("server_config");
|
||||
server::ConfigNode& db_config = root_config.GetChild("db_config");
|
||||
@ -43,10 +57,6 @@ TEST(ConfigTest, CONFIG_TEST) {
|
||||
auto children = server_config.GetChildren();
|
||||
ASSERT_TRUE(children.empty());
|
||||
|
||||
root_config.PrintAll();
|
||||
std::string all = root_config.DumpString();
|
||||
ASSERT_TRUE(!all.empty());
|
||||
|
||||
server_config.ClearConfig();
|
||||
auto configs = server_config.GetConfig();
|
||||
ASSERT_TRUE(configs.empty());
|
||||
@ -56,9 +66,20 @@ TEST(ConfigTest, CONFIG_TEST) {
|
||||
auto seq = server_config.GetSequence("seq");
|
||||
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();
|
||||
auto seqs = server_config.GetSequences();
|
||||
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) {
|
||||
@ -73,5 +94,12 @@ TEST(ConfigTest, SERVER_CONFIG_TEST) {
|
||||
int32_t cap = node1.GetInt32Value("cpu_cache_capacity");
|
||||
ASSERT_GT(cap, 0);
|
||||
|
||||
node1.SetValue("bool", "true");
|
||||
bool bt = node1.GetBoolValue("bool");
|
||||
ASSERT_TRUE(bt);
|
||||
|
||||
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/TimeRecorder.h"
|
||||
#include "utils/BlockingQueue.h"
|
||||
#include "utils/LogUtil.h"
|
||||
|
||||
using namespace zilliz::milvus;
|
||||
|
||||
namespace {
|
||||
|
||||
static const std::string LOG_FILE_PATH = "./milvus/conf/log_config.conf";
|
||||
|
||||
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);
|
||||
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");
|
||||
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 path2 = path1 + "common_test_12345/";
|
||||
std::string path3 = path2 + "abcdef";
|
||||
server::ServerError err = server::CommonUtil::CreateDirectory(path3);
|
||||
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);
|
||||
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) {
|
||||
@ -47,29 +95,49 @@ TEST(UtilTest, STRINGFUNCTIONS_TEST) {
|
||||
server::StringHelpFunctions::TrimStringBlank(str);
|
||||
ASSERT_EQ(str, "test zilliz");
|
||||
|
||||
str = "\"test zilliz\"";
|
||||
server::StringHelpFunctions::TrimStringQuote(str, "\"");
|
||||
ASSERT_EQ(str, "test zilliz");
|
||||
|
||||
str = "a,b,c";
|
||||
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);
|
||||
|
||||
str = "55,\"aa,gg,yy\",b";
|
||||
result.clear();
|
||||
server::StringHelpFunctions::SplitStringByQuote(str , ",", "\"", result);
|
||||
err = server::StringHelpFunctions::SplitStringByQuote(str , ",", "\"", result);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
ASSERT_EQ(result.size(), 3UL);
|
||||
|
||||
|
||||
}
|
||||
|
||||
TEST(UtilTest, TIMERECORDER_TEST) {
|
||||
double span = TestTimeRecorder(TimeUnit::eTimeAutoUnit, 0);
|
||||
double span = TestTimeRecorder(TimeUnit::eTimeAutoUnit, 0, 1001);
|
||||
ASSERT_GT(span, 0.0);
|
||||
span = TestTimeRecorder(TimeUnit::eTimeHourUnit, 1);
|
||||
span = TestTimeRecorder(TimeUnit::eTimeAutoUnit, 0, 101);
|
||||
ASSERT_GT(span, 0.0);
|
||||
span = TestTimeRecorder(TimeUnit::eTimeMinuteUnit, 2);
|
||||
span = TestTimeRecorder(TimeUnit::eTimeHourUnit, 1, 10);
|
||||
ASSERT_GT(span, 0.0);
|
||||
span = TestTimeRecorder(TimeUnit::eTimeSecondUnit, 3);
|
||||
span = TestTimeRecorder(TimeUnit::eTimeMinuteUnit, 2, 10);
|
||||
ASSERT_GT(span, 0.0);
|
||||
span = TestTimeRecorder(TimeUnit::eTimeMilliSecUnit, 4);
|
||||
span = TestTimeRecorder(TimeUnit::eTimeSecondUnit, 3, 10);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -98,5 +166,14 @@ TEST(UtilTest, BLOCKINGQUEUE_TEST) {
|
||||
str = bq.Take();
|
||||
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
Block a user