Skip to content

Commit

Permalink
Add generic AddBlob command (IntelLabs#79)
Browse files Browse the repository at this point in the history
* Add generic AddBlob command

* Format CMakeLists.txt

* Fix the AddBlob test and include all other tests

* Fix run_test.sh

* Add the add_blob test and fix the blob reading functions for the client examples

* Fix the run_Test to include all the tests

* Aff FindBlob Test code

* Fix the FindBLob test

* ADD UPDATE BLOB TEST and FINDBLOB TEST

* Update dockerfiles (IntelLabs#81) (IntelLabs#83)

* Update dockerfiles; Checkin dockerfiles now only copy vdms folders; remove maven; centralize dependencies in /dependencies folder

* Correct zlib and tiledb paths

* Remove coverage file check

* Change coverage script path

* Change coverage script path

* cd before coverage script

* Add maven build arg to avoid target failure

* Add blob: Update coverage (IntelLabs#84)

* Modify python port and run coverage w/ same cmd

* move large1.jpg to test_images folder, updated paths to image, remove unused image and video in  images folder

---------

Co-authored-by: Chaunte W. Lacewell <[email protected]>
  • Loading branch information
Ragaad and cwlacewe authored Mar 6, 2023
1 parent 726b642 commit fccb2eb
Show file tree
Hide file tree
Showing 23 changed files with 725 additions and 108 deletions.
19 changes: 2 additions & 17 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,11 @@ jobs:
mkdir -p coverage
echo "${{ matrix.container_name }}"
# Make sure CPP coverage script is available
# if [ ! -f docker/check-in/run_coverage_cpp.sh ]; then
# docker exec ${{ matrix.container_name }} bash -c "touch /run_coverage_cpp.sh && echo 'cd /vdms/tests && chmod +x run_tests.sh && ./run_tests.sh' >> /run_coverage_cpp.sh && chmod +x /run_coverage_cpp.sh && mkdir -p /vdms/tests/coverage_report"
# docker exec ${{ matrix.container_name }} bash -c "echo 'gcovr -k --root /vdms -e /vdms/src/pmgd -e /vdms/build/CMakeFiles -f "/vdms/client/.*\.cc" -f "/vdms/ext/.*\.cc" -f "/vdms/src/.*\.cc" -f src/SearchExpression.cc --exclude-unreachable-branches --xml-pretty --xml=/vdms/tests/coverage_report/c_coverage_report.xml --txt=/vdms/tests/coverage_report/c_coverage_report.txt' >> /run_coverage_cpp.sh && echo "echo 'DONE'" >> /run_coverage_cpp.sh"
# docker exec ${{ matrix.container_name }} bash -c "echo 'cat /vdms/tests/coverage_report/c_coverage_report.txt' >> /run_coverage_cpp.sh"
# fi
# # Make sure Python coverage script is available
# if [ ! -f docker/check-in/run_coverage_py.sh ]; then
# docker exec ${{ matrix.container_name }} bash -c "touch /run_coverage_py.sh && echo 'cd /vdms/tests/python && ./run_python_tests.sh' >> /run_coverage_py.sh && chmod +x /run_coverage_py.sh && mkdir -p /vdms/tests/coverage_report"
# docker exec ${{ matrix.container_name }} bash -c "echo 'python -m coverage report > /vdms/tests/coverage_report/py_coverage_report.txt' >> /run_coverage_py.sh && echo "echo 'DONE'" >> /run_coverage_py.sh"
# docker exec ${{ matrix.container_name }} bash -c "echo 'cat /vdms/tests/coverage_report/py_coverage_report.txt' >> /run_coverage_py.sh"
# fi
docker exec ${{ matrix.container_name }} bash -c "cd / && ./run_coverage_cpp.sh"
docker exec ${{ matrix.container_name }} bash -c "cd / && ./run_coverage_cpp.sh && cd / && ./run_coverage_py.sh"
docker cp $(docker ps -a | grep ${{ matrix.container_name }} | awk '{print $1}'):/vdms/tests/coverage_report/c_coverage_report.txt coverage/c_coverage_report_target.txt
docker cp $(docker ps -a | grep ${{ matrix.container_name }} | awk '{print $1}'):/vdms/tests/coverage_report/c_coverage_report.xml coverage/c_coverage_report_target.xml
echo "coverage_value_cpp=$(cat coverage/c_coverage_report_target.xml | grep -oP 'coverage line-rate="([-+]?\d*\.\d+|\d+)"' | grep -oP "[-+]?\d*\.\d+|\d+" | awk '{print $1*100}')" >> $GITHUB_ENV
docker exec ${{ matrix.container_name }} bash -c "cd / && ./run_coverage_py.sh"
docker cp $(docker ps -a | grep ${{ matrix.container_name }} | awk '{print $1}'):/vdms/tests/coverage_report/py_coverage_report.txt coverage/py_coverage_report_target.txt || true
docker cp $(docker ps -a | grep ${{ matrix.container_name }} | awk '{print $1}'):/vdms/tests/coverage_report/py_coverage_report.xml coverage/py_coverage_report_target.xml || true
if [ ! -f coverage/py_coverage_report_target.xml ] && [ "${{ matrix.coverage_type }}" == "Target" ]; then
Expand Down Expand Up @@ -175,7 +160,7 @@ jobs:
echo "Source Python Coverage: ${{needs.coverage_job.outputs.source_coverage_py}}"
echo "Target Python Coverage: ${{needs.coverage_job.outputs.target_coverage_py}}"
if ${{needs.coverage_job.outputs.target_coverage_py}} != 0 && ${{ needs.coverage_job.outputs.target_coverage_py > needs.coverage_job.outputs.source_coverage_py }}
if ${{ needs.coverage_job.outputs.target_coverage_py > needs.coverage_job.outputs.source_coverage_py }}
then
echo 'Python coverage below target'
exit 1
Expand Down
22 changes: 21 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,27 @@ else()

link_directories(/usr/local/lib /usr/lib/x86_64-linux-gnu/)
include_directories(/usr/include/jsoncpp utils/include/ src/pmgd/include src/pmgd/util include/ src/vcl /usr/include ${CMAKE_CURRENT_BINARY_DIR}/utils/src/protobuf)
add_library(dms SHARED src/BoundingBoxCommand.cc src/CommunicationManager.cc src/DescriptorsCommand.cc src/DescriptorsManager.cc src/ExceptionsCommand.cc src/ImageCommand.cc src/PMGDIterators.cc src/PMGDQuery.cc src/PMGDQueryHandler.cc src/QueryHandler.cc src/QueryMessage.cc src/RSCommand.cc src/SearchExpression.cc src/Server.cc src/VDMSConfig.cc src/VideoCommand.cc src/AutoDeleteNode.cc ${PROTO_SRCS} ${PROTO_HDRS})
add_library(dms SHARED
src/BoundingBoxCommand.cc
src/BlobCommand.cc
src/CommunicationManager.cc
src/DescriptorsCommand.cc
src/DescriptorsManager.cc
src/ExceptionsCommand.cc
src/ImageCommand.cc
src/PMGDIterators.cc
src/PMGDQuery.cc
src/PMGDQueryHandler.cc
src/QueryHandler.cc
src/QueryMessage.cc
src/RSCommand.cc
src/SearchExpression.cc
src/Server.cc
src/VDMSConfig.cc
src/VideoCommand.cc
src/AutoDeleteNode.cc
${PROTO_SRCS} ${PROTO_HDRS}
)
target_link_libraries(dms vcl pmgd pmgd-util protobuf vdms-utils pthread)


Expand Down
2 changes: 1 addition & 1 deletion client/cpp/VDMSClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace VDMS {

// Blocking call
VDMS::Response query(const std::string &json_query,
const std::vector<std::string *> blobs = {});
const std::vector<std::string*> blobs = {});

};
};
243 changes: 243 additions & 0 deletions src/BlobCommand.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
/**
* @file BlobCommand.cc
*
* @section LICENSE
*
* The MIT License
*
* @copyright Copyright (c) 2017 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

#include <iostream>

#include "BlobCommand.h"
#include "VDMSConfig.h"
#include "defines.h"

using namespace VDMS;

//========= AddBlob definitions =========

BlobCommand::BlobCommand(const std::string &cmd_name):
RSCommand(cmd_name)
{
}

AddBlob::AddBlob() : BlobCommand("AddBlob")
{

_storage_bin = VDMSConfig::instance()->get_path_bin();
}

int AddBlob::construct_protobuf(PMGDQuery& query,
const Json::Value& jsoncmd,
const std::string& blob,
int grp_id,
Json::Value& error)
{
const Json::Value& cmd = jsoncmd[_cmd_name];

std::cout << " inside ADDBLOB" <<std::endl;
int node_ref = get_value<int>(cmd, "_ref",
query.get_available_reference());


std::string format = "bin";
char binary_img_flag = 1;
VCL::Image img((void*)blob.data(), blob.size(), binary_img_flag);


std::string blob_root = _storage_bin;
VCL::Image::Format blob_format = VCL::Image::Format::BIN;
std::string file_name = VCL::create_unique(blob_root, format);
std::cout << "Blob was added in " <<_storage_bin << "\t"<< file_name << std::endl;
Json::Value props = get_value<Json::Value>(cmd, "properties");
props[VDMS_EN_BLOB_PATH_PROP] = file_name;


query.AddNode(node_ref, VDMS_BLOB_TAG, props, Json::Value());

img.store(file_name, blob_format);


error["Blob_added"] = file_name;

if (cmd.isMember("link")) {
add_link(query, cmd["link"], node_ref, VDMS_BLOB_EDGE_TAG);
}

return 0;
}

//========= UpdateBLOB definitions =========

UpdateBlob::UpdateBlob() : BlobCommand("UpdateBlob")
{
}

int UpdateBlob::construct_protobuf(PMGDQuery& query,
const Json::Value& jsoncmd,
const std::string& blob,
int grp_id,
Json::Value& error)
{
const Json::Value& cmd = jsoncmd[_cmd_name];

// Update Image node
query.UpdateNode(get_value<int>(cmd, "_ref", -1),
VDMS_BLOB_TAG,
cmd["properties"],
cmd["remove_props"],
cmd["constraints"],
get_value<bool>(cmd, "unique", false));

return 0;
}

//========= FindBLOB definitions =========

FindBlob::FindBlob() : BlobCommand("FindBlob")
{
}

int FindBlob::construct_protobuf(
PMGDQuery& query,
const Json::Value& jsoncmd,
const std::string& blob,
int grp_id,
Json::Value& error)
{
const Json::Value& cmd = jsoncmd[_cmd_name];

Json::Value results = get_value<Json::Value>(cmd, "results");

// Unless otherwhis specified, we return the blob.
if (get_value<bool>(results, "blob", true)){
results["list"].append(VDMS_EN_BLOB_PATH_PROP);
}

query.QueryNode(
get_value<int>(cmd, "_ref", -1),
VDMS_BLOB_TAG,
cmd["link"],
cmd["constraints"],
results,
get_value<bool>(cmd, "unique", false)
);

return 0;
}

Json::Value FindBlob::construct_responses(
Json::Value& responses,
const Json::Value& json,
protobufs::queryMessage &query_res,
const std::string &blob)
{
const Json::Value& cmd = json[_cmd_name];

Json::Value ret;

auto error = [&](Json::Value& res)
{
ret[_cmd_name] = res;
return ret;
};

if (responses.size() != 1) {
Json::Value return_error;
return_error["status"] = RSCommand::Error;
return_error["info"] = "PMGD Response Bad Size";
return error(return_error);
}

Json::Value& findBlob = responses[0];

if (findBlob["status"] != 0) {
findBlob["status"] = RSCommand::Error;
// Uses PMGD info error.
return error(findBlob);
}

Json::Value results = get_value<Json::Value>(cmd, "results");

bool flag_empty = false;

// Check if blob (image) must be returned
if (get_value<bool>(results, "blob", true)) {

for (auto& ent : findBlob["entities"]) {

assert(ent.isMember(VDMS_EN_BLOB_PATH_PROP));

std::string blob_path = ent[VDMS_EN_BLOB_PATH_PROP].asString();
ent.removeMember(VDMS_EN_BLOB_PATH_PROP);

if (ent.getMemberNames().size() == 0) {
flag_empty = true;
}

try {
VCL::Image blob_im(blob_path);


// We will return the image in the format the user
// request, or on its format in disk, except for the case
// of .tdb, where we will encode as png.
VCL::Image::Format format =VCL::Image::Format::BIN;

std::vector<unsigned char> blob_buffer;
blob_buffer = blob_im.get_encoded_image(format);

if (!blob_buffer.empty()) {

std::string* blob_str = query_res.add_blobs();
blob_str->resize(blob_buffer.size());
std::memcpy((void*)blob_str->data(),
(void*)blob_buffer.data(),
blob_buffer.size());
}
else {
Json::Value return_error;
return_error["status"] = RSCommand::Error;
return_error["info"] = "Blob Data not found";
return error(return_error);
}
} catch (VCL::Exception e) {
print_exception(e);
Json::Value return_error;
return_error["status"] = RSCommand::Error;
return_error["info"] = "VCL Exception";
return error(return_error);
}
}
}

if (flag_empty) {
findBlob.removeMember("entities");
}

ret[_cmd_name].swap(findBlob);
return ret;
}
Loading

0 comments on commit fccb2eb

Please sign in to comment.