Skip to content

Commit

Permalink
Set browser as default web (#608)
Browse files Browse the repository at this point in the history
* update

* update

* update

* update

* update

* update

* fix bug

* update browser commit

* update

* fix datatime

* update

* update

* update

* update

* update

* fix cpplint

* fix

* fix test case error

* fix it error
  • Loading branch information
ljcui authored Jul 25, 2024
1 parent b72df60 commit 4cab5e7
Show file tree
Hide file tree
Showing 26 changed files with 116 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ build
*.ttl
release/doc/*.html
src/restful/server/resource/
src/restful/server/browser-resource/
src/server/restful/server/resource/
.idea
.code-workspace
Expand Down
3 changes: 1 addition & 2 deletions ci/images/tugraph-compile-centos7-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ RUN yum -x filesystem update -y && yum install -y \
automake \
libtoolize \
texinfo \
java-1.8.0-openjdk* \
perl-Digest-MD5 \
libcurl-devel.x86_64 \
kde-l10n-Chinese \
glibc-common \
which \
java-11-openjdk-devel
java-11-openjdk-devel && yum clean all

# install g++ 8.4.0
# if it is not accessible, replace it with the link below
Expand Down
3 changes: 1 addition & 2 deletions ci/images/tugraph-compile-centos8-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ RUN yum update -y && yum install -y \
automake \
perl-Digest-MD5 \
perl.x86_64 \
java-1.8.0-openjdk* \
libcurl-devel.x86_64 \
glibc-common \
langpacks-zh_CN \
which \
java-11-openjdk-devel \
openssh-server
openssh-server && yum clean all

RUN rm /run/nologin && rm /usr/sbin/nologin

Expand Down
1 change: 0 additions & 1 deletion ci/images/tugraph-compile-ubuntu18.04-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ RUN apt-get update && apt-get install -y \
libjson-perl \
libperlio-gzip-perl \
libdigest-perl-md5-perl \
openjdk-8-jdk \
language-pack-zh* \
openjdk-11-jdk

Expand Down
5 changes: 1 addition & 4 deletions ci/images/tugraph-mini-runtime-centos7-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,4 @@ RUN rpm -ivh ${FILENAME} && rm /${FILENAME}

ENV LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib:$LD_LIBRARY_PATH

# set locale
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LANG zh_CN.utf8
ENV LC_ALL zh_CN.utf8
CMD ["lgraph_server -d start"]
4 changes: 1 addition & 3 deletions ci/images/tugraph-mini-runtime-centos8-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ RUN rpm -ivh ${FILENAME} && rm /${FILENAME}

ENV LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib:$LD_LIBRARY_PATH

# set locale
ENV LANG zh_CN.utf8
ENV LC_ALL zh_CN.utf8
CMD ["lgraph_server -d start"]
3 changes: 0 additions & 3 deletions ci/images/tugraph-mini-runtime-ubuntu18.04-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,3 @@ RUN wget ${FILEPATH}/${FILENAME}
RUN dpkg -i ${FILENAME} && rm /${FILENAME}

ENV LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib:$LD_LIBRARY_PATH

ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8
4 changes: 0 additions & 4 deletions ci/images/tugraph-runtime-arm64v8-centos7-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,3 @@ ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk/jre/ \
PYTHONPATH=/usr/local/lib64:$PYTHONPATH \
PATH=/opt/apache-maven-3.8.7/bin:$PATH

# set locale
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LANG zh_CN.utf8
ENV LC_ALL zh_CN.utf8
7 changes: 4 additions & 3 deletions ci/images/tugraph-runtime-centos7-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN yum -x filesystem update -y && yum install -y \
bzip2 \
unzip \
openssl-static \
libcurl-devel.x86_64
libcurl-devel.x86_64 && yum clean all

# install g++ 8.4.0
# if it is not accessible, replace it with the link below
Expand Down Expand Up @@ -66,8 +66,9 @@ RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/boost_1_68
ARG FILEPATH
# specifies installation package name for tugraph
ARG FILENAME
RUN wget ${FILEPATH}/${FILENAME}
RUN rpm -ivh ${FILENAME} && rm /${FILENAME}
RUN wget ${FILEPATH}/${FILENAME} && rpm -ivh ${FILENAME} && rm -f /${FILENAME}

ENV LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH \
PYTHONPATH=/usr/local/lib64:$PYTHONPATH

CMD ["lgraph_server -d start"]
7 changes: 4 additions & 3 deletions ci/images/tugraph-runtime-centos8-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN yum update -y && yum install -y \
bzip2 \
unzip \
openssl-devel.x86_64 \
libcurl-devel.x86_64
libcurl-devel.x86_64 && yum clean all

# install g++ 8.4.0
# if it is not accessible, replace it with the link below
Expand Down Expand Up @@ -64,8 +64,9 @@ RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/boost_1_68
ARG FILEPATH
# specifies installation package name for tugraph
ARG FILENAME
RUN wget ${FILEPATH}/${FILENAME}
RUN rpm -ivh ${FILENAME} && rm /${FILENAME}
RUN wget ${FILEPATH}/${FILENAME} && rpm -ivh ${FILENAME} && rm -f /${FILENAME}

ENV LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib:$LD_LIBRARY_PATH \
PYTHONPATH=/usr/local/lib64:$PYTHONPATH

CMD ["lgraph_server -d start"]
2 changes: 0 additions & 2 deletions ci/images/tugraph-runtime-ubuntu18.04-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,3 @@ ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre \
PYTHONPATH=/usr/local/lib64:$PYTHONPATH \
PATH=/opt/apache-maven-3.8.7/bin:/usr/lib/jvm/java-8-openjdk-amd64/jre/bin:$PATH

ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8
16 changes: 15 additions & 1 deletion deps/build_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,19 @@ npm run lint -- --fix
npm run build
RESOURCE_DIR=${SCRIPT_DIR}/../src/restful/server/resource/
rm -rf ${RESOURCE_DIR}
rm -rf dist/scene_data
cp -r dist ${RESOURCE_DIR}
cd -
cd ..

echo "======================================"
echo "Building tugraph-db-browser"
echo "======================================"

cd tugraph-db-browser
yarn bootstrap
rm -rf client/dist
yarn build
BROWSER_RESOURCE_DIR=${SCRIPT_DIR}/../src/restful/server/browser-resource
rm -rf ${BROWSER_RESOURCE_DIR}
cp -r client/dist/resource ${BROWSER_RESOURCE_DIR}
cp -r client/src/constants/demo_data ${BROWSER_RESOURCE_DIR}/
2 changes: 1 addition & 1 deletion deps/tugraph-db-browser
2 changes: 1 addition & 1 deletion release/local/etc/lgraph.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"ssl_auth" : false,
"server_key" : "/usr/local/etc/lgraph/server-key.pem",
"server_cert" : "/usr/local/etc/lgraph/server-cert.pem",
"web" : "/usr/local/share/lgraph/resource"
"web" : "/usr/local/share/lgraph/browser-resource"
}
23 changes: 15 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ include(BuildClients.cmake)
include(BuildCythonExtension.cmake)
include(BuildBoltLib.cmake)

install(TARGETS lgraph lgraph_python_api lgraph_server lgraph_client_python lgraph_db_python
install(TARGETS lgraph lgraph_python_api lgraph_server lgraph_db_python
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib64)
install(DIRECTORY
${CMAKE_CURRENT_LIST_DIR}/restful/server/resource
DESTINATION share/lgraph)
install(DIRECTORY
${CMAKE_CURRENT_LIST_DIR}/../deps/tugraph-db-browser
${CMAKE_CURRENT_LIST_DIR}/restful/server/browser-resource
DESTINATION share/lgraph)
# install procedure demos
install(DIRECTORY
Expand All @@ -31,6 +31,13 @@ install(FILES
${CMAKE_CURRENT_LIST_DIR}/../procedures/demo/v2_pagerank.cpp
${CMAKE_CURRENT_LIST_DIR}/../procedures/demo/scan_graph.py
DESTINATION share/lgraph/resource/procedure_demo/)
install(DIRECTORY
DESTINATION share/lgraph/browser-resource/procedure_demo/)
install(FILES
${CMAKE_CURRENT_LIST_DIR}/../procedures/demo/v1_scan_graph.cpp
${CMAKE_CURRENT_LIST_DIR}/../procedures/demo/v2_pagerank.cpp
${CMAKE_CURRENT_LIST_DIR}/../procedures/demo/scan_graph.py
DESTINATION share/lgraph/browser-resource/procedure_demo/)
install(FILES
${CMAKE_CURRENT_LIST_DIR}/python/lgraph_task_runner.py
DESTINATION bin)
Expand All @@ -54,13 +61,13 @@ add_custom_command(TARGET lgraph_server
add_custom_command(TARGET lgraph_server
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_CURRENT_LIST_DIR}/restful/server/resource
${CMAKE_CURRENT_LIST_DIR}/restful/server/browser-resource
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resource)
add_custom_command(TARGET lgraph_server
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/../procedures/demo/
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resource/procedure_demo/)
#add_custom_command(TARGET lgraph_server
# POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_directory
# ${CMAKE_CURRENT_LIST_DIR}/../procedures/demo/
# ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resource/procedure_demo/)
add_custom_command(TARGET lgraph_server
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
Expand Down
9 changes: 6 additions & 3 deletions src/bolt/pack_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ class PackStream {
}

void PackDate(const bolt::Date& m) {
packer_.StructHeader('D', 1);
packer_.Int64(m.days);
}
void PackLocalTime(const bolt::LocalTime& m) {
void PackLocalDateTime(const bolt::LocalDateTime& m) {
packer_.StructHeader('d', 2);
packer_.Int64(m.seconds);
packer_.Int64(m.nanoseconds);
}

Expand Down Expand Up @@ -123,8 +126,8 @@ class PackStream {
PackList(std::any_cast<const std::vector<std::any>&>(x));
} else if (type == typeid(bolt::Date)) {
PackDate(std::any_cast<const bolt::Date&>(x));
} else if (type == typeid(bolt::LocalTime)) {
PackLocalTime(std::any_cast<const bolt::LocalTime&>(x));
} else if (type == typeid(bolt::LocalDateTime)) {
PackLocalDateTime(std::any_cast<const bolt::LocalDateTime&>(x));
} else {
LOG_FATAL() << FMA_FMT("PackX meet unexpected type {}", type.name());
}
Expand Down
12 changes: 8 additions & 4 deletions src/bolt/to_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "tools/lgraph_log.h"
#include "bolt/record.h"
#include "bolt/graph.h"
#include "lgraph/lgraph_date_time.h"
#pragma once

namespace bolt {
Expand Down Expand Up @@ -53,10 +54,13 @@ nlohmann::json ToJsonObj(const std::any& item) {
return ToJsonObj(path);
} else if (item.type() == typeid(bolt::Date)) {
const auto& date = std::any_cast<const bolt::Date&>(item);
return ToJsonObj(date.days);
} else if (item.type() == typeid(bolt::LocalTime)) {
const auto& localTime = std::any_cast<const bolt::LocalTime&>(item);
return ToJsonObj(localTime.nanoseconds);
lgraph_api::Date d(date.days);
return ToJsonObj(d.ToString());
} else if (item.type() == typeid(bolt::LocalDateTime)) {
const auto& localDateTime = std::any_cast<const bolt::LocalDateTime&>(item);
lgraph_api::DateTime dateTime(
localDateTime.seconds * 1000000 + localDateTime.nanoseconds/1000);
return ToJsonObj(dateTime.ToString());
} else if (item.type() == typeid(std::vector<std::any>)) {
const auto& vector = std::any_cast<const std::vector<std::any>&>(item);
nlohmann::json ret = nlohmann::json::array();
Expand Down
20 changes: 20 additions & 0 deletions src/cypher/procedure/procedure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "cypher/monitor/memory_monitor_allocator.h"
#include "fma-common/encrypt.h"
#include "import/import_v3.h"
#include "server/bolt_session.h"

namespace cypher {

Expand Down Expand Up @@ -1646,6 +1647,25 @@ void BuiltinProcedure::DbmsMetaRefreshCount(RTContext *ctx, const Record *record
ac_db.RefreshCount();
}

void BuiltinProcedure::DbmsSecurityIsDefaultUserPassword(RTContext *ctx,
const cypher::Record *record,
const cypher::VEC_EXPR &args,
const cypher::VEC_STR &yield_items,
std::vector<Record> *records) {
CYPHER_ARG_CHECK(
args.size() == 0,
"need 0 parameters, e.g. dbms.security.isDefaultUserPassword()")
if (ctx->txn_) ctx->txn_->Abort();
bool is_default_user_password = false;
if (ctx->bolt_conn_) {
auto session = (bolt::BoltSession*)(ctx->bolt_conn_->GetContext());
is_default_user_password = session->using_default_user_password;
}
Record r;
r.AddConstant(lgraph::FieldData(is_default_user_password));
records->emplace_back(r.Snapshot());
}

void BuiltinProcedure::DbmsSecurityChangePassword(RTContext *ctx, const cypher::Record *record,
const cypher::VEC_EXPR &args,
const cypher::VEC_STR &yield_items,
Expand Down
10 changes: 10 additions & 0 deletions src/cypher/procedure/procedure.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ class BuiltinProcedure {
static void DbmsMetaRefreshCount(RTContext *ctx, const Record *record, const VEC_EXPR &args,
const VEC_STR &yield_items, std::vector<Record> *records);

static void DbmsSecurityIsDefaultUserPassword(RTContext *ctx, const Record *record,
const VEC_EXPR &args, const VEC_STR &yield_items,
std::vector<Record> *records);

static void DbmsSecurityChangePassword(RTContext *ctx, const Record *record,
const VEC_EXPR &args, const VEC_STR &yield_items,
std::vector<Record> *records);
Expand Down Expand Up @@ -728,6 +732,12 @@ static std::vector<Procedure> global_procedures = {
Procedure("dbms.meta.refreshCount", BuiltinProcedure::DbmsMetaRefreshCount,
Procedure::SIG_SPEC{}, Procedure::SIG_SPEC{{"", {0, lgraph_api::LGraphType::NUL}}},
false, true),
Procedure("dbms.security.isDefaultUserPassword",
BuiltinProcedure::DbmsSecurityIsDefaultUserPassword,
Procedure::SIG_SPEC{},
Procedure::SIG_SPEC{
{"isDefaultUserPassword", {0, lgraph_api::LGraphType::BOOLEAN}}
}, true, false),
Procedure("dbms.security.changePassword", BuiltinProcedure::DbmsSecurityChangePassword,
Procedure::SIG_SPEC{
{"current_password", {0, lgraph_api::LGraphType::STRING}},
Expand Down
7 changes: 5 additions & 2 deletions src/lgraph_api/lgraph_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ std::any FieldData::ToBolt() const {
return *data.buf;
case FieldType::DATE:
return bolt::Date{data.int32};
case FieldType::DATETIME:
return bolt::LocalTime({data.int64 * 1000});
case FieldType::DATETIME: {
int64_t sec = data.int64 / 1000000;
int64_t micro = data.int64 % 1000000;
return bolt::LocalDateTime{sec, micro*1000};
}
default:
throw std::runtime_error("ToBolt meet unsupported data type.");
}
Expand Down
4 changes: 4 additions & 0 deletions src/server/bolt_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ std::function<void(bolt::BoltConnection &conn, bolt::BoltMsg msg,
session->python_driver = true;
}
}
if (principal == lgraph::_detail::DEFAULT_ADMIN_NAME &&
credentials == lgraph::_detail::DEFAULT_ADMIN_PASS) {
session->using_default_user_password = true;
}
session->state = SessionState::READY;
session->user = principal;
session->fsm_thread = std::thread(BoltFSM, conn.shared_from_this());
Expand Down
1 change: 1 addition & 0 deletions src/server/bolt_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct BoltSession {
BlockingQueue<BoltMsgDetail> msgs;
std::thread fsm_thread;
bool python_driver = false;
bool using_default_user_password = false;
};

} // namespace bolt
2 changes: 1 addition & 1 deletion test/integration/test_ha_procedure.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def test_procedure(self):
procedures = json.loads(ret[1])
#TODO when this assert failed , you should add the additional procedure test code or remove the deleted procedure test code
log.info("procedures count : %s", len(procedures))
assert len(procedures) == 103
assert len(procedures) == 104
ha_client.logout()

def test_graph(self):
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_procedure.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def test_procedure(self, server, client):
procedures = json.loads(ret[1])
#TODO when this assert failed , you should add the additional procedure test code or remove the deleted procedure test code
log.info("procedures count : %s", len(procedures))
assert len(procedures) == 103
assert len(procedures) == 104


@pytest.mark.parametrize("server", [SERVEROPT], indirect=True)
Expand Down
Loading

0 comments on commit 4cab5e7

Please sign in to comment.