diff --git a/CMakeLists.txt b/CMakeLists.txt index aa54458d9..fea1ae623 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ option(SKIP_PYTHON "Skip building Gravity Python wrapper") set(JAVA_HOME "" CACHE PATH "Path to JDK to use") set(Protobuf_SRC_ROOT_FOLDER "" CACHE PATH "Path to Protobuf source build") set(ZMQ_HOME "" CACHE PATH "Path to your local ZeroMQ installation") +set(JAVA_PROTOBUF_JAR "/usr/share/java/protobuf.jar" CACHE PATH "Location of protobuf jar file") get_filename_component(ABS_CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" ABSOLUTE BASE_DIR "${CMAKE_BINARY_DIR}") string(REPLACE "\"" "" ABS_CMAKE_INSTALL_PREFIX "${ABS_CMAKE_INSTALL_PREFIX}") @@ -156,6 +157,7 @@ set(GRAVITY_USING_EXTERNAL_PROTOBUF) if (Protobuf_FOUND AND NOT GRAVITY_USE_EXTERNAL_PROTOBUF) message(STATUS "Using local protobuf libraries") + else() message(STATUS "Using external protobuf build") set(GRAVITY_USING_EXTERNAL_PROTOBUF ON) @@ -312,7 +314,9 @@ else() LIST_SEPARATOR | CMAKE_ARGS -DGRAVITY_ROOT=${PUBLIC_STAGING_DIR} - -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/test/examples + -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/test/examples + -DTOPLEVEL_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} + -DEXTERNAL_JAVA_JAR=${protobufs-java_BINARY_DIR} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_MODULE_PATH=${CMAKE_MODULE_PATH} -DSKIP_JAVA=${SKIP_JAVA} diff --git a/cmake/FindZeroMQ.cmake b/cmake/FindZeroMQ.cmake index 4537aaa67..c0bc33bfa 100644 --- a/cmake/FindZeroMQ.cmake +++ b/cmake/FindZeroMQ.cmake @@ -139,6 +139,8 @@ if(ZeroMQ_LIBRARY) IMPORTED_CONFIGURATIONS RELEASE) set_target_properties(libzmq PROPERTIES IMPORTED_LOCATION_RELEASE "${ZeroMQ_LIBRARY_RELEASE}") + cmake_path(GET ZeroMQ_LIBRARY_RELEASE PARENT_PATH ZeroMQ_LIBRARY_DIRECTORY) + set(ZeroMQ_LIBRARY_DIRECTORY "${ZeroMQ_LIBRARY_DIRECTORY}" CACHE ON FILEPATH) endif() if(EXISTS "${ZeroMQ_LIBRARY_DEBUG}") set_property(TARGET libzmq APPEND PROPERTY diff --git a/src/api/java/CMakeLists.txt b/src/api/java/CMakeLists.txt index e14d8c69e..3607d729c 100644 --- a/src/api/java/CMakeLists.txt +++ b/src/api/java/CMakeLists.txt @@ -8,9 +8,11 @@ include(UseJava) gravity_find_protobuf(ON) # TODO check GRAVITY_USING_EXTERNAL_PROTOBUF -set(PUBLIC_JAR "/usr/share/java/protobuf.jar" "${Protobuf_SRC_ROOT_FOLDER}/java/target/protobuf-java-${Protobuf_VERSION}.jar") +#set(PUBLIC_JAR "/usr/share/java/protobuf.jar" "${Protobuf_SRC_ROOT_FOLDER}/java/target/protobuf-java-${Protobuf_VERSION}.jar") +set(PUBLIC_JAR "${JAVA_PROTOBUF_JAR}" "${Protobuf_SRC_ROOT_FOLDER}/java/target/protobuf-java-${Protobuf_VERSION}.jar") set(CMAKE_JAVA_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/protobuf-java.jar" ${PUBLIC_JAR}) + set(CMAKE_JAVA_COMPILE_FLAGS -sourcepath "${CMAKE_CURRENT_LIST_DIR}/src/java") set(JAVA_SRCS @@ -72,8 +74,6 @@ gravity_add_jar_debug_release(${PROJECT_NAME} SOURCES ${JAVA_SRCS} ${JAVA_PROTO_ "${CMAKE_BINARY_DIR}/java/com/aphysci/gravity/swig/gravityJNI.java" "${CMAKE_BINARY_DIR}/java/com/aphysci/gravity/swig/gravity.java" "${CMAKE_BINARY_DIR}/java/com/aphysci/gravity/swig/gravityConstants.java" - OUTPUT_NAME gravity) - - -gravity_install_jar(${PROJECT_NAME} DESTINATION "${CMAKE_INSTALL_LIBDIR}") -gravity_add_dependency(${PROJECT_NAME}) + OUTPUT_NAME gravity + OUTPUT_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") + gravity_add_dependency(${PROJECT_NAME}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 42c30aaea..81998a0f9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -35,4 +35,4 @@ endif() if (NOT SKIP_PYTHON) add_subdirectory(api/python) endif() -add_subdirectory(examples) \ No newline at end of file +add_subdirectory(examples) diff --git a/test/examples/.gitignore b/test/examples/.gitignore index ee49dfbbc..c75dbb4c4 100644 --- a/test/examples/.gitignore +++ b/test/examples/.gitignore @@ -1,3 +1,5 @@ run.sh cmake_build bin +*Debug.bat +*Release.bat diff --git a/test/examples/1-BasicDataProduct/CMakeLists.txt b/test/examples/1-BasicDataProduct/CMakeLists.txt index 5de1fb5bc..f143a432c 100644 --- a/test/examples/1-BasicDataProduct/CMakeLists.txt +++ b/test/examples/1-BasicDataProduct/CMakeLists.txt @@ -1,11 +1,11 @@ cmake_minimum_required(VERSION 3.17) project(BasicDataProduct) # -# see CMakeLists.txt one level up on how to set up CMAKE_PREFIX_PATH and CMAKE_MODULE_PATH +# see CMakeLists.txt one level up on how to set up CMAKE_PREFIX_PATH and CMAKE_MODULE_PATH # -find_package(Gravity QUIET) +find_package(Gravity QUIET) # since we use spdlog directly find_package(spdlog REQUIRED) @@ -19,3 +19,7 @@ target_link_libraries(BasicDataProductPublisher PRIVATE gravity spdlog::spdlog_h add_executable(BasicDataProductSubscriber BasicDataProductSubscriber.cpp) set_target_properties(BasicDataProductSubscriber PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) target_link_libraries(BasicDataProductSubscriber PRIVATE gravity spdlog::spdlog_header_only) + +configure_file(run.sh.in ${BasicDataProduct_SOURCE_DIR}/run.sh) +configure_file(RunBasicDataProductDebug.bat.in ${BasicDataProduct_SOURCE_DIR}/RunBasicDataProductDebug.bat) +configure_file(RunBasicDataProductRelease.bat.in ${BasicDataProduct_SOURCE_DIR}/RunBasicDataProductRelease.bat) diff --git a/test/examples/1-BasicDataProduct/Gravity.ini b/test/examples/1-BasicDataProduct/Gravity.ini new file mode 100644 index 000000000..1ab230fde --- /dev/null +++ b/test/examples/1-BasicDataProduct/Gravity.ini @@ -0,0 +1,19 @@ +# +# This section is common to all components +# +[general] +# Set the log level for logs written to the log file +GravityFileLogLevel=debug + +# Set the log level for logs written to the console that started the component +#Can make output look funky, so uncomment at your own risk +#GravityConsoleLogLevel=debug + +# Without this, Gravity will spend a few seconds trying to retrieve +# parameters from a remote ConfigServer. +NoConfigServer=true + +# The URL where the ServiceDirectory will be found. This value is the same as the default. +ServiceDirectoryURL="tcp://localhost:5555" + + diff --git a/test/examples/1-BasicDataProduct/RunBasicDataProductDebug.bat.in b/test/examples/1-BasicDataProduct/RunBasicDataProductDebug.bat.in new file mode 100644 index 000000000..3a9e0c10d --- /dev/null +++ b/test/examples/1-BasicDataProduct/RunBasicDataProductDebug.bat.in @@ -0,0 +1,16 @@ +setlocal + +cd @CMAKE_INSTALL_PREFIX@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/libzmq/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/protobuf/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@LOCAL_ZEROMQ_RUNTIME_DIR@ +set path=%Path%;@LOCAL_PROTOBUF_RUNTIME_DIR@ +set path=%Path%;@BasicDataProduct_BINARY_DIR@/Debug + +start ServiceDirectory@CMAKE_DEBUG_POSTFIX@.exe +sleep 3 +start BasicDataProductPublisher@CMAKE_DEBUG_POSTFIX@.exe +sleep 3 +start BasicDataProductSubscriber@CMAKE_DEBUG_POSTFIX@.exe \ No newline at end of file diff --git a/test/examples/1-BasicDataProduct/RunBasicDataProductRelease.bat.in b/test/examples/1-BasicDataProduct/RunBasicDataProductRelease.bat.in new file mode 100644 index 000000000..ce06aba8d --- /dev/null +++ b/test/examples/1-BasicDataProduct/RunBasicDataProductRelease.bat.in @@ -0,0 +1,16 @@ +setlocal + +cd @CMAKE_INSTALL_PREFIX@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/libzmq/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/protobuf/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@LOCAL_ZEROMQ_RUNTIME_DIR@ +set path=%Path%;@LOCAL_PROTOBUF_RUNTIME_DIR@ +set path=%Path%;@BasicDataProduct_BINARY_DIR@/Release + +start ServiceDirectory.exe +sleep 3 +start BasicDataProductPublisher.exe +sleep 3 +start BasicDataProductSubscriber.exe \ No newline at end of file diff --git a/test/examples/1-BasicDataProduct/run.sh.in b/test/examples/1-BasicDataProduct/run.sh.in index d5b9f3d18..5103fbab5 100755 --- a/test/examples/1-BasicDataProduct/run.sh.in +++ b/test/examples/1-BasicDataProduct/run.sh.in @@ -19,11 +19,17 @@ # @configure_input@ # Tool-related substitution variables -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -ZMQ_LIB_DIR=@ZEROMQ_LIBDIR@ +PROTOBUF_LIB_DIR=@Protobuf_LIBRARY_RELEASE@ +ZMQ_LIB_DIR=@ZeroMQ_LIBRARY_RELEASE@ +ONE_BIN_DIR=@BasicDataProduct_BINARY_DIR@ +SD_BIN_DIR=@ServiceDirectory_BINARY_DIR@ #For internal builds +COMP_BIN_DIR=@TOPLEVEL_INSTALL_PREFIX@/bin #For external builds +CME_LIB_DIR=@TOPLEVEL_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +CMI_LIB_DIR=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ -export PATH=$PATH:../../../src/components/cpp/bin -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR + +export PATH=$PATH:$ONE_BIN_DIR:$SD_BIN_DIR:$COMP_BIN_DIR +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR:$CME_LIB_DIR:$CMI_LIB_DIR control_c() # run if user hits control-c @@ -42,10 +48,10 @@ SDPID=$! # sleep for a second to give the service directory a chance to start up sleep 1 -./BasicDataProductPublisher & +BasicDataProductPublisher & PUBPID=$! # sleep for a second to give the publisher a chance to register its data product sleep 1 -./BasicDataProductSubscriber +BasicDataProductSubscriber diff --git a/test/examples/10-Archiving/ArchiveTest.cpp b/test/examples/10-Archiving/ArchiveTest.cpp index b797570b6..f42dc2e08 100644 --- a/test/examples/10-Archiving/ArchiveTest.cpp +++ b/test/examples/10-Archiving/ArchiveTest.cpp @@ -19,9 +19,10 @@ #include #include #include +#include #include -#include "../protobuf/BasicCounterDataProduct.pb.h" +#include "BasicCounterDataProduct.pb.h" #include "protobuf/FileArchiverControlRequestPB.pb.h" int main() @@ -75,10 +76,12 @@ int main() count++; if (count > 50) count = 1; + //Turns archiving on and off every 5 count (on->off->on....) if (count % 5 == 0) { GravityDataProduct gdp("FileArchiverControlRequest"); FileArchiverControlRequestPB request; + //Suspend flag turns off further input into the archiver request.set_suspend(suspend); suspend = !suspend; gdp.setData(request); diff --git a/test/examples/10-Archiving/CMakeLists.txt b/test/examples/10-Archiving/CMakeLists.txt new file mode 100644 index 000000000..8e6af0f59 --- /dev/null +++ b/test/examples/10-Archiving/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.17) +project(Archiving) +# +# see CMakeLists.txt on how to set up CMAKE_PREFIX_PATH and CMAKE_MODULE_PATH +# + +# for gravity_protobuf_generate +include(GravitySupport) + + +find_package(spdlog REQUIRED) +find_package(Gravity QUIET) + +file(GLOB PROTO_FILES "${CMAKE_CURRENT_LIST_DIR}/../protobuf/*.proto") + +gravity_protobuf_generate(APPEND_PATH PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR} OUT_VAR PROTO_SRCS + PROTOS ${PROTO_FILES}) + +add_custom_target(${PROJECT_NAME}_protos ALL DEPENDS ${PROTO_SRCS}) + +set(CMAKE_DEBUG_POSTFIX _d) +add_executable(ArchiveTest ArchiveTest.cpp ${PROTO_SRCS}) +set_target_properties(ArchiveTest PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +target_link_libraries(ArchiveTest PRIVATE gravity spdlog::spdlog_header_only) +target_include_directories(ArchiveTest PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +add_dependencies(ArchiveTest ${PROJECT_NAME}_protos) + +add_executable(ReplayTest ReplayTest.cpp ${PROTO_SRCS}) +set_target_properties(ReplayTest PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +target_link_libraries(ReplayTest PRIVATE gravity spdlog::spdlog_header_only) +target_include_directories(ReplayTest PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +add_dependencies(ReplayTest ${PROJECT_NAME}_protos) + +configure_file(run.sh.in ${Archiving_SOURCE_DIR}/run.sh) diff --git a/test/examples/10-Archiving/Gravity.ini b/test/examples/10-Archiving/Gravity.ini index 6d0c02d65..8d610541c 100644 --- a/test/examples/10-Archiving/Gravity.ini +++ b/test/examples/10-Archiving/Gravity.ini @@ -2,8 +2,9 @@ [general] ServiceDirectoryURL="tcp://localhost:5555" NoConfigServer=true -LocalLogLevel=debug -ConsoleLogLevel=debug +GravityLocalLogLevel=debug +GravityFileLogLevel=debug +#GravityConsoleLogLevel=debug [FileArchiver] ArchiveFilename="archive.bin" diff --git a/test/examples/10-Archiving/ReplayTest.cpp b/test/examples/10-Archiving/ReplayTest.cpp index 65a5354e1..013dbbb78 100644 --- a/test/examples/10-Archiving/ReplayTest.cpp +++ b/test/examples/10-Archiving/ReplayTest.cpp @@ -20,9 +20,10 @@ #include #include #include +#include #include -#include "../protobuf/BasicCounterDataProduct.pb.h" +#include "BasicCounterDataProduct.pb.h" using namespace gravity; using namespace std; diff --git a/test/examples/10-Archiving/run.sh.in b/test/examples/10-Archiving/run.sh.in index b7040cd92..69603242a 100755 --- a/test/examples/10-Archiving/run.sh.in +++ b/test/examples/10-Archiving/run.sh.in @@ -19,11 +19,18 @@ # @configure_input@ # Tool-related substitution variables -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -ZMQ_LIB_DIR=@ZEROMQ_LIBDIR@ +PROTOBUF_LIB_DIR=@Protobuf_LIBRARY_RELEASE@ +ZMQ_LIB_DIR=@ZeroMQ_LIBRARY_RELEASE@ +TEN_BIN_DIR=@Archiving_BINARY_DIR@ +SD_BIN_DIR=@ServiceDirectory_BINARY_DIR@ +ARCH_BIN_DIR=@Archiver_BINARY_DIR@ +PB_BIN_DIR=@Playback_BINARY_DIR@ +COMP_BIN_DIR=@TOPLEVEL_INSTALL_PREFIX@/bin #For external builds +CME_LIB_DIR=@TOPLEVEL_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +CMI_LIB_DIR=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ -export PATH=$PATH:../../../src/components/cpp/bin -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR +export PATH=$PATH:$TEN_BIN_DIR:$SD_BIN_DIR:$ARCH_BIN_DIR:$PB_BIN_DIR:$COMP_BIN_DIR +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR:$CME_LIB_DIR:$CMI_LIB_DIR cleanup() # run if user hits control-c @@ -58,9 +65,9 @@ SDPID=$! # 5 seconds, ArchiveTest will toggle the suspend flag on the FileArchiver. This means # that only about half of the published counter values will be archived. ## -FileArchiver & +Archiver & FAPID=$! -./ArchiveTest & +ArchiveTest & ATPID=$! sleep 20 @@ -77,9 +84,9 @@ sleep 1 # and that the messages that were archived are still published once a second - just like ArchiveTest did originally. ## echo Starting ReplayTest -./ReplayTest & +ReplayTest & RTPID=$! -FileReplay & +Playback & FRPID=$! sleep 20 diff --git a/test/examples/11-PythonPubSub/CMakeLists.txt b/test/examples/11-PythonPubSub/CMakeLists.txt index da898a112..b592528f2 100644 --- a/test/examples/11-PythonPubSub/CMakeLists.txt +++ b/test/examples/11-PythonPubSub/CMakeLists.txt @@ -23,3 +23,5 @@ set_property(TEST pypubsub PROPERTY ENVIRONMENT_MODIFICATION "PYTHONPATH=path_list_prepend:${ABS_GRAVITY_ROOT}/${CMAKE_INSTALL_LIBDIR}" "PYTHONPATH=path_list_prepend:${CMAKE_CURRENT_BINARY_DIR}" ) + +configure_file(run.sh.in ${PythonPubSub_SOURCE_DIR}/run.sh) diff --git a/test/examples/11-PythonPubSub/Gravity.ini b/test/examples/11-PythonPubSub/Gravity.ini index 5bb74a81a..2d44c4661 100644 --- a/test/examples/11-PythonPubSub/Gravity.ini +++ b/test/examples/11-PythonPubSub/Gravity.ini @@ -1,6 +1,6 @@ [general] ServiceDirectoryURL="tcp://127.0.0.1:5555" NoConfigServer=true -LocalLogLevel=DEBUG -ConsoleLogLevel=DEBUG +GravityFileLogLevel=DEBUG +#GravityConsoleLogLevel=DEBUG diff --git a/test/examples/11-PythonPubSub/pypub.py b/test/examples/11-PythonPubSub/pypub.py index 3a1c23f4f..c44711355 100644 --- a/test/examples/11-PythonPubSub/pypub.py +++ b/test/examples/11-PythonPubSub/pypub.py @@ -1,10 +1,13 @@ import time +import logging -from gravity import GravityNode, GravityDataProduct, gravity, GravitySubscriber, Log +from gravity import GravityNode, GravityDataProduct, gravity, GravitySubscriber, SpdLogHandler from BasicCounterDataProduct_pb2 import BasicCounterDataProductPB + + class MySubscriber(GravitySubscriber): # We're only using GravitySubscriber here, but this is generally the way we # initialize Gravity Python components to ensure that __init__ is called @@ -16,15 +19,18 @@ def subscriptionFilled(self, dataProducts): counterPB = BasicCounterDataProductPB() for gdp in dataProducts: gdp.populateMessage(counterPB) - Log.message("received counter with value = "+str(counterPB.count)) + gravlogger.warning("received counter with value = "+str(counterPB.count)) +gravlogger = logging.getLogger() +gravlogger.setLevel(logging.WARNING) # let all logs pass through to Gravity logger +gravlogger.addHandler(SpdLogHandler(True)) mySub = MySubscriber() - gn = GravityNode() while gn.init("PyPub") != gravity.SUCCESS: - Log.warning("failed to init, retrying...") + gravlogger.warning("failed to init, retrying...") time.sleep(1) + gn.registerDataProduct("PythonGDP", gravity.TCP) gn.subscribe("PythonGDP", mySub) diff --git a/test/examples/11-PythonPubSub/run.sh.in b/test/examples/11-PythonPubSub/run.sh.in index a8dd08378..a4e7f0e10 100755 --- a/test/examples/11-PythonPubSub/run.sh.in +++ b/test/examples/11-PythonPubSub/run.sh.in @@ -19,17 +19,23 @@ # @configure_input@ # Tool-related substitution variables -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -ZMQ_LIB_DIR=@ZEROMQ_LIBDIR@ -WITHOUT_PYTHON=@WITHOUT_PYTHON@ -PYTHON=@PYTHON@ - -if test $WITHOUT_PYTHON = no; +PROTOBUF_LIB_DIR=@Protobuf_LIBRARY_RELEASE@ +ZMQ_LIB_DIR=@ZeroMQ_LIBRARY_RELEASE@ +WITHOUT_PYTHON=@SKIP_PYTHON@ +PYTHON=python3 +SD_BIN_DIR=@ServiceDirectory_BINARY_DIR@ +CME_LIB_DIR=@TOPLEVEL_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +CMI_LIB_DIR=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +COMP_BIN_DIR=@TOPLEVEL_INSTALL_PREFIX@/bin #For external builds +ELEV_BIN_DIR=@PythonPubSub_BINARY_DIR@ + + +if test $WITHOUT_PYTHON = OFF; then - export PATH=$PATH:../../../src/components/cpp/bin - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ZMQ_LIB_DIR:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR - export PYTHONPATH=$PYTHONPATH:../../../lib:../protobuf + export PATH=$PATH:$SD_BIN_DIR:$COMP_BIN_DIR + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ZMQ_LIB_DIR:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR:$CME_LIB_DIR:$CMI_LIB_DIR + export PYTHONPATH=$PYTHONPATH:$CME_LIB_DIR:$CMI_LIB_DIR:$ELEV_BIN_DIR ServiceDirectory & SDPID=$! diff --git a/test/examples/12-PythonBasicService/CMakeLists.txt b/test/examples/12-PythonBasicService/CMakeLists.txt index e4eaadd28..a52af90fd 100644 --- a/test/examples/12-PythonBasicService/CMakeLists.txt +++ b/test/examples/12-PythonBasicService/CMakeLists.txt @@ -10,7 +10,7 @@ file(GLOB PROTO_FILES "${CMAKE_CURRENT_LIST_DIR}/../protobuf/*.proto") -gravity_protobuf_generate(APPEND_PATH LANGUAGE python PROTOC_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}" GENERATE_EXTENSIONS .py OUT_VAR SRCS PROTOS ${PROTO_FILES}) +gravity_protobuf_generate(APPEND_PATH LANGUAGE python PROTOC_OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" GENERATE_EXTENSIONS .py OUT_VAR SRCS PROTOS ${PROTO_FILES}) add_custom_target(${PROJECT_NAME} ALL DEPENDS "${SRCS}") set(PY_EXEC python3) @@ -24,3 +24,5 @@ set_property(TEST pybasicservice PROPERTY ENVIRONMENT_MODIFICATION "PYTHONPATH=path_list_prepend:${CMAKE_CURRENT_BINARY_DIR}" "PYTHONPATH=path_list_prepend:${ABS_GRAVITY_ROOT}/${CMAKE_INSTALL_LIBDIR}" ) + +configure_file(run.sh.in ${PythonBasicService_SOURCE_DIR}/run.sh) diff --git a/test/examples/12-PythonBasicService/Gravity.ini b/test/examples/12-PythonBasicService/Gravity.ini index cd8901b6c..be145dcbb 100644 --- a/test/examples/12-PythonBasicService/Gravity.ini +++ b/test/examples/12-PythonBasicService/Gravity.ini @@ -1,6 +1,6 @@ [general] ServiceDirectoryURL="tcp://localhost:5555" NoConfigServer=true -LocalLogLevel=DEBUG -ConsoleLogLevel=DEBUG +GravityFileLogLevel=DEBUG +#GravityConsoleLogLevel=DEBUG diff --git a/test/examples/12-PythonBasicService/requestor.py b/test/examples/12-PythonBasicService/requestor.py index 19251c268..afcd98d8d 100644 --- a/test/examples/12-PythonBasicService/requestor.py +++ b/test/examples/12-PythonBasicService/requestor.py @@ -1,7 +1,8 @@ import time +import logging import gravity -from gravity import GravityNode, GravityDataProduct, gravity, GravityRequestor, GravityServiceProvider, Log +from gravity import GravityNode, GravityDataProduct, gravity, GravityRequestor, GravityServiceProvider, SpdLogHandler from Multiplication_pb2 import MultiplicationOperandsPB, MultiplicationResultPB done = False @@ -15,28 +16,31 @@ def __init__(self): def requestFilled(self, serviceID, requestID, response): multResponse = MultiplicationResultPB() response.populateMessage(multResponse) - Log.message("made it to request filled with request GDP ID = "+response.dataProductID +" and response = " + str(multResponse.result)) + gravlogger.warning("made it to request filled with request GDP ID = "+response.dataProductID +" and response = " + str(multResponse.result)) global done done = True def request(self, serviceID, dataProduct): - Log.message("made it to my request!") - Log.message("for serviceID = "+serviceID) + gravlogger.warning("made it to my request!") + gravlogger.warning("for serviceID = "+serviceID) operands = MultiplicationOperandsPB() - Log.message(str(type(operands))) + gravlogger.warning(str(type(operands))) dataProduct.populateMessage(operands) - Log.message("have operands = "+str([operands.multiplicand_a, operands.multiplicand_b])) + gravlogger.warning("have operands = "+str([operands.multiplicand_a, operands.multiplicand_b])) multResponse = MultiplicationResultPB() multResponse.result = operands.multiplicand_a * operands.multiplicand_b gdp = GravityDataProduct("MultResponse") gdp.data = multResponse - Log.message("returning response with result = "+str(multResponse.result)) + gravlogger.warning("returning response with result = "+str(multResponse.result)) return gdp +gravlogger = logging.getLogger() +gravlogger.setLevel(logging.WARNING) # let all logs pass through to Gravity logger +gravlogger.addHandler(SpdLogHandler(True)) gn = GravityNode() while gn.init("PyRequest") != gravity.SUCCESS: - Log.warning("failed to init, retrying...") + gravlogger.warning("failed to init, retrying...") time.sleep(1) requestorProvider = MyRequestorProvider() @@ -58,10 +62,10 @@ def request(self, serviceID, dataProduct): operands.multiplicand_b = 6 gdp.data=operands gdpResp = gn.request("Multiplication", gdp) -Log.message("received GDP response") +gravlogger.warning("received GDP response") multResponse = MultiplicationResultPB() gdpResp.populateMessage(multResponse) -Log.message("made it to request filled with request GDP ID = "+gdpResp.dataProductID +" and response = " + str(multResponse.result)) +gravlogger.warning("made it to request filled with request GDP ID = "+gdpResp.dataProductID +" and response = " + str(multResponse.result)) diff --git a/test/examples/12-PythonBasicService/run.sh.in b/test/examples/12-PythonBasicService/run.sh.in index 078150747..28ebeb34b 100755 --- a/test/examples/12-PythonBasicService/run.sh.in +++ b/test/examples/12-PythonBasicService/run.sh.in @@ -19,17 +19,21 @@ # @configure_input@ # Tool-related substitution variables -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -ZMQ_LIB_DIR=@ZEROMQ_LIBDIR@ -WITHOUT_PYTHON=@WITHOUT_PYTHON@ -PYTHON=@PYTHON@ - -if test $WITHOUT_PYTHON = no; +PROTOBUF_LIB_DIR=@Protobuf_LIBRARY_RELEASE@ +ZMQ_LIB_DIR=@ZeroMQ_LIBRARY_RELEASE@ +WITHOUT_PYTHON=@SKIP_PYTHON@ +PYTHON=python3 +SD_BIN_DIR=@ServiceDirectory_BINARY_DIR@ +CME_LIB_DIR=@TOPLEVEL_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +CMI_LIB_DIR=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +COMP_BIN_DIR=@TOPLEVEL_INSTALL_PREFIX@/bin #For external builds +TWEL_BIN_DIR=@PythonBasicService_BINARY_DIR@ +if test $WITHOUT_PYTHON = OFF; then - export PATH=$PATH:../../../src/components/cpp/bin - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ZMQ_LIB_DIR:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR - export PYTHONPATH=$PYTHONPATH:../../../lib:../protobuf + export PATH=$PATH:$SD_BIN_DIR:$COMP_BIN_DIR + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ZMQ_LIB_DIR:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR:$CME_LIB_DIR:$CMI_LIB_DIR + export PYTHONPATH=$CME_LIB_DIR:$CMI_LIB_DIR:$TWEL_BIN_DIR ServiceDirectory & SDPID=$! diff --git a/test/examples/13-Relay/CMakeLists.txt b/test/examples/13-Relay/CMakeLists.txt new file mode 100644 index 000000000..8f4da54c7 --- /dev/null +++ b/test/examples/13-Relay/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.17) +project(RelayExample) +# +# see CMakeLists.txt on how to set up CMAKE_PREFIX_PATH and CMAKE_MODULE_PATH +# + +# for gravity_protobuf_generate +include(GravitySupport) + + +find_package(spdlog REQUIRED) +find_package(Gravity QUIET) + +file(GLOB PROTO_FILES "${CMAKE_CURRENT_LIST_DIR}/../protobuf/*.proto") + +gravity_protobuf_generate(APPEND_PATH PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR} OUT_VAR PROTO_SRCS + PROTOS ${PROTO_FILES}) + +add_custom_target(${PROJECT_NAME}_protos ALL DEPENDS ${PROTO_SRCS}) + +set(CMAKE_DEBUG_POSTFIX _d) +add_executable(ProtobufDataProductPublisher ProtobufDataProductPublisher.cpp ${PROTO_SRCS}) +set_target_properties(ProtobufDataProductPublisher PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +target_link_libraries(ProtobufDataProductPublisher PRIVATE gravity spdlog::spdlog_header_only) +target_include_directories(ProtobufDataProductPublisher PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +add_dependencies(ProtobufDataProductPublisher ${PROJECT_NAME}_protos) + +add_executable(ProtobufDataProductSubscriber ProtobufDataProductSubscriber.cpp ${PROTO_SRCS}) +set_target_properties(ProtobufDataProductSubscriber PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +target_link_libraries(ProtobufDataProductSubscriber PRIVATE gravity spdlog::spdlog_header_only) +target_include_directories(ProtobufDataProductSubscriber PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +add_dependencies(ProtobufDataProductSubscriber ${PROJECT_NAME}_protos) + +configure_file(run.sh.in ${RelayExample_SOURCE_DIR}/run.sh) diff --git a/test/examples/13-Relay/Gravity.ini b/test/examples/13-Relay/Gravity.ini index 484b3cf6a..37b31719a 100644 --- a/test/examples/13-Relay/Gravity.ini +++ b/test/examples/13-Relay/Gravity.ini @@ -1,8 +1,9 @@ [general] ServiceDirectoryURL="tcp://localhost:5555" NoConfigServer=true -LocalLogLevel=DEBUG -ConsoleLogLevel=DEBUG +GravityLocalLogLevel=DEBUG +GravityFileLogLevel=DEBUG +#GravityConsoleLogLevel=DEBUG [Relay] DataProductList="BasicCounterDataProduct" diff --git a/test/examples/13-Relay/ProtobufDataProductPublisher.cpp b/test/examples/13-Relay/ProtobufDataProductPublisher.cpp index ef6ecc013..b97cd053b 100644 --- a/test/examples/13-Relay/ProtobufDataProductPublisher.cpp +++ b/test/examples/13-Relay/ProtobufDataProductPublisher.cpp @@ -21,7 +21,7 @@ #include #include -#include "../protobuf/BasicCounterDataProduct.pb.h" +#include "BasicCounterDataProduct.pb.h" int main() { diff --git a/test/examples/13-Relay/ProtobufDataProductSubscriber.cpp b/test/examples/13-Relay/ProtobufDataProductSubscriber.cpp index 84db61a43..b4a15bb52 100644 --- a/test/examples/13-Relay/ProtobufDataProductSubscriber.cpp +++ b/test/examples/13-Relay/ProtobufDataProductSubscriber.cpp @@ -20,9 +20,10 @@ #include #include #include +#include #include -#include "../protobuf/BasicCounterDataProduct.pb.h" +#include "BasicCounterDataProduct.pb.h" using namespace gravity; using namespace std; diff --git a/test/examples/13-Relay/run.sh.in b/test/examples/13-Relay/run.sh.in index 5c57f8365..a3ea4cb7e 100755 --- a/test/examples/13-Relay/run.sh.in +++ b/test/examples/13-Relay/run.sh.in @@ -19,11 +19,18 @@ # @configure_input@ # Tool-related substitution variables -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -ZMQ_LIB_DIR=@ZEROMQ_LIBDIR@ +PROTOBUF_LIB_DIR=@Protobuf_LIBRARY_RELEASE@ +ZMQ_LIB_DIR=@ZeroMQ_LIBRARY_RELEASE@ +SD_BIN_DIR=@ServiceDirectory_BINARY_DIR@ +REL_BIN_DIR=@Relay_BINARY_DIR@ +RELEX_BIN_DIR=@RelayExample_BINARY_DIR@ +COMP_BIN_DIR=@TOPLEVEL_INSTALL_PREFIX@/bin #For external builds +CME_LIB_DIR=@TOPLEVEL_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +CMI_LIB_DIR=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ -export PATH=$PATH:../../../src/components/cpp/bin -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR + +export PATH=$PATH:$SD_BIN_DIR:$REL_BIN_DIR:$RELEX_BIN_DIR:$COMP_BIN_DIR +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR:$CME_LIB_DIR:$CMI_LIB_DIR cleanup() # run if user hits control-c @@ -46,10 +53,10 @@ SDPID=$! # sleep for a second to give the service directory a chance to start up sleep 1 -./ProtobufDataProductPublisher & +ProtobufDataProductPublisher & PUBPID=$! -./ProtobufDataProductSubscriber & +ProtobufDataProductSubscriber & SUBPID=$! sleep 3 diff --git a/test/examples/14-AnomalyDetection/CMakeLists.txt b/test/examples/14-AnomalyDetection/CMakeLists.txt new file mode 100644 index 000000000..fd15e65c7 --- /dev/null +++ b/test/examples/14-AnomalyDetection/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.17) + +project(AnomalyDetection) +include(GNUInstallDirs) +include(GravitySupport) + +find_package(Gravity QUIET) + +file(GLOB PROTO_FILES "${CMAKE_CURRENT_LIST_DIR}/../protobuf/*.proto") + + + +gravity_protobuf_generate(APPEND_PATH LANGUAGE python PROTOC_OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" GENERATE_EXTENSIONS .py OUT_VAR SRCS PROTOS ${PROTO_FILES}) +add_custom_target(${PROJECT_NAME} ALL DEPENDS "${SRCS}") + +set(PY_EXEC python3) +if (WIN32) + set(PY_EXEC python) +endif() + +configure_file(train.sh.in ${AnomalyDetection_SOURCE_DIR}/train.sh) +configure_file(detect.sh.in ${AnomalyDetection_SOURCE_DIR}/detect.sh) diff --git a/test/examples/14-AnomalyDetection/Gravity.ini b/test/examples/14-AnomalyDetection/Gravity.ini index 5273e8247..49ac9e5b7 100644 --- a/test/examples/14-AnomalyDetection/Gravity.ini +++ b/test/examples/14-AnomalyDetection/Gravity.ini @@ -1,8 +1,8 @@ [general] ServiceDirectoryURL="tcp://localhost:5555" NoConfigServer=true -LocalLogLevel=DEBUG -ConsoleLogLevel=DEBUG +GravityFileLogLevel=DEBUG +#GravityConsoleLogLevel=DEBUG subscription_name = "AutoencoderExample" diff --git a/test/examples/14-AnomalyDetection/detect.py b/test/examples/14-AnomalyDetection/detect.py index 9fe9f2c56..87f1775c5 100755 --- a/test/examples/14-AnomalyDetection/detect.py +++ b/test/examples/14-AnomalyDetection/detect.py @@ -16,11 +16,12 @@ #** If not, see . #** +import logging import warnings warnings.simplefilter(action='ignore', category=FutureWarning) # quiet TensorFlow warnings import time, sys -from gravity import GravityNode, GravityDataProduct, gravity, GravitySubscriber, Log +from gravity import GravityNode, GravityDataProduct, gravity, GravitySubscriber, SpdLogHandler from DataPoint_pb2 import DataPointPB from datetime import datetime from gravity_autoencoder import GravityModel @@ -53,10 +54,12 @@ def subscriptionFilled(self, dataProducts): data.put(self.sample_data) self.sample_data = {} - +gravlogger = logging.getLogger() +gravlogger.setLevel(logging.WARNING) # let all logs pass through to Gravity logger +gravlogger.addHandler(SpdLogHandler(True)) gn = GravityNode() while gn.init("AnomalyDetector") != gravity.SUCCESS: - Log.warning("failed to init, retrying...") + gravlogger.warning("failed to init, retrying...") time.sleep(1) model_filename = gn.getStringParam("model_file", "model.json") @@ -69,7 +72,7 @@ def subscriptionFilled(self, dataProducts): while True: d = data.get() mse = model.ComputeMSE(d) - Log.message("MSE = %f"%(mse)) + gravlogger.warning("MSE = %f"%(mse)) # notreached gn.unsubscribe(channel, mySub) diff --git a/test/examples/14-AnomalyDetection/detect.sh.in b/test/examples/14-AnomalyDetection/detect.sh.in index 45e63e01b..7badc7913 100755 --- a/test/examples/14-AnomalyDetection/detect.sh.in +++ b/test/examples/14-AnomalyDetection/detect.sh.in @@ -20,20 +20,25 @@ # Tool-related substitution variables GRAVITY_ROOT=../../.. -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -ZMQ_LIB_DIR=@ZEROMQ_LIBDIR@ -WITHOUT_PYTHON=@WITHOUT_PYTHON@ -PYTHON=@PYTHON@ +PROTOBUF_LIB_DIR=@Protobuf_LIBRARY_RELEASE@ +ZMQ_LIB_DIR=@ZeroMQ_LIBRARY_RELEASE@ +WITHOUT_PYTHON=@SKIP_PYTHON@ +PYTHON=python3 TERM=gnome-terminal +SD_BIN_DIR=@ServiceDirectory_BINARY_DIR@ +CME_LIB_DIR=@TOPLEVEL_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +CMI_LIB_DIR=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +COMP_BIN_DIR=@TOPLEVEL_INSTALL_PREFIX@/bin #For external builds +FOURT_BIN_DIR=@AnomalyDetection_BINARY_DIR@ -if test $WITHOUT_PYTHON = no; +if test $WITHOUT_PYTHON = OFF; then - export PATH=$PATH:$GRAVITY_ROOT/src/components/cpp/bin - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ZMQ_LIB_DIR:$GRAVITY_ROOT/src/api/cpp:$GRAVITY_ROOT/src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR - export PYTHONPATH=$PYTHONPATH:$GRAVITY_ROOT/lib + export PATH=$PATH:$SD_BIN_DIR:$COMP_BIN_DIR + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ZMQ_LIB_DIR:$GRAVITY_ROOT/src/api/cpp:$GRAVITY_ROOT/src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR:$CME_LIB_DIR:$CMI_LIB_DIR + export PYTHONPATH=$PYTHONPATH:$CME_LIB_DIR:$CMI_LIB_DIR:$FOURT_BIN_DIR - @PROTOC@ --proto_path=. --python_out=. DataPoint.proto || exit + protoc --proto_path=. --python_out=. DataPoint.proto || exit $TERM -- /bin/bash -c "echo -ne '\033]0;Service Directory \007'; ServiceDirectory ; read -p 'Press return to exit'" & $TERM -- /bin/bash -c "echo -ne '\033]0;Publisher \007'; $PYTHON pub.py 500 ; read -p 'Press return to exit'" & diff --git a/test/examples/14-AnomalyDetection/pub.py b/test/examples/14-AnomalyDetection/pub.py index 6fce9a6e0..8f14baeda 100755 --- a/test/examples/14-AnomalyDetection/pub.py +++ b/test/examples/14-AnomalyDetection/pub.py @@ -16,12 +16,17 @@ #** If not, see . #** +import logging import time,sys -from gravity import GravityNode, GravityDataProduct, gravity, GravitySubscriber, Log +from gravity import GravityNode, GravityDataProduct, gravity, GravitySubscriber, SpdLogHandler from DataPoint_pb2 import DataPointPB from datetime import datetime import numpy as np + +gravlogger = logging.getLogger() +gravlogger.setLevel(logging.WARNING) # let all logs pass through to Gravity logger +gravlogger.addHandler(SpdLogHandler(True)) name = 'Pub' anomaly_point = None if len(sys.argv) > 1: @@ -63,7 +68,7 @@ time.sleep(0.1) sample_num += 1 if anomaly_point and sample_num == anomaly_point: - Log.message("Anomaly point reached") + gravlogger.warning("Anomaly point reached") inc2 *= 2 diff --git a/test/examples/14-AnomalyDetection/train.py b/test/examples/14-AnomalyDetection/train.py index 7975b6507..468553729 100755 --- a/test/examples/14-AnomalyDetection/train.py +++ b/test/examples/14-AnomalyDetection/train.py @@ -16,11 +16,12 @@ #** If not, see . #** +import logging import warnings warnings.simplefilter(action='ignore', category=FutureWarning) # quiet TensorFlow warnings import time, sys -from gravity import GravityNode, GravityDataProduct, gravity, GravitySubscriber, Log +from gravity import GravityNode, GravityDataProduct, gravity, GravitySubscriber, SpdLogHandler from DataPoint_pb2 import DataPointPB from datetime import datetime from gravity_autoencoder import TrainModel @@ -57,7 +58,7 @@ def subscriptionFilled(self, dataProducts): self.subs += 1 if self.subs == 100: self.subs = 0 - Log.message("Received %d of %d training samples. "%([len(v) for v in training_data.values()][0], training_size)) + gravlogger.warning("Received %d of %d training samples. "%([len(v) for v in training_data.values()][0], training_size)) #Log.message("Training Subscriptions: " + str([(k,len(v)) for k,v in training_data.items()])) has_enough_data = True @@ -66,17 +67,19 @@ def subscriptionFilled(self, dataProducts): has_enough_data = False break if has_enough_data: - Log.message("Calling trainmodel") + gravlogger.warning("Calling trainmodel") self.train_state = TrainingState.TRAINING TrainModel(training_data, model_file, epochs=epochs) self.train_state = TrainingState.TRAINED - +gravlogger = logging.getLogger() +gravlogger.setLevel(logging.WARNING) # let all logs pass through to Gravity logger +gravlogger.addHandler(SpdLogHandler(True)) mySub = MySubscriber() gn = GravityNode() while gn.init("AnomalyDetector") != gravity.SUCCESS: - Log.warning("failed to init, retrying...") + gravlogger.warning("failed to init, retrying...") time.sleep(1) epochs = gn.getIntParam("training_epochs", epochs) @@ -86,7 +89,7 @@ def subscriptionFilled(self, dataProducts): gn.subscribe(channel, mySub) while mySub.train_state != TrainingState.TRAINED: time.sleep(1) -Log.message("Training Complete " + str(mySub.train_state)) +gravlogger.warning("Training Complete " + str(mySub.train_state)) gn.unsubscribe(channel, mySub) sys.exit(0) diff --git a/test/examples/14-AnomalyDetection/train.sh.in b/test/examples/14-AnomalyDetection/train.sh.in index 7d416ff6d..b37630bd3 100755 --- a/test/examples/14-AnomalyDetection/train.sh.in +++ b/test/examples/14-AnomalyDetection/train.sh.in @@ -20,18 +20,24 @@ # Tool-related substitution variables GRAVITY_ROOT=../../.. -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -ZMQ_LIB_DIR=@ZEROMQ_LIBDIR@ -WITHOUT_PYTHON=@WITHOUT_PYTHON@ -PYTHON=@PYTHON@ +PROTOBUF_LIB_DIR=@Protobuf_LIBRARY_DIRECTORY@ +ZMQ_LIB_DIR=@ZeroMQ_LIBRARY_DIRECTORY@ +WITHOUT_PYTHON=@SKIP_PYTHON@ +PYTHON=python3 TERM=gnome-terminal +SD_BIN_DIR=@ServiceDirectory_BINARY_DIR@ +CME_LIB_DIR=@TOPLEVEL_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +CMI_LIB_DIR=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +COMP_BIN_DIR=@TOPLEVEL_INSTALL_PREFIX@/bin #For external builds +FOURT_BIN_DIR=@AnomalyDetection_BINARY_DIR@ -if test $WITHOUT_PYTHON = no; + +if test $WITHOUT_PYTHON = OFF; then - export PATH=$PATH:$GRAVITY_ROOT/src/components/cpp/bin - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ZMQ_LIB_DIR:$GRAVITY_ROOT/src/api/cpp:$GRAVITY_ROOT/src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR - export PYTHONPATH=$PYTHONPATH:$GRAVITY_ROOT/lib + export PATH=$PATH:$SD_BIN_DIR:$COMP_BIN_DIR + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ZMQ_LIB_DIR:$GRAVITY_ROOT/src/api/cpp:$GRAVITY_ROOT/src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR:$CME_LIB_DIR:$CMI_LIB_DIR + export PYTHONPATH=$PYTHONPATH:$CME_LIB_DIR:$CMI_LIB_DIR:$FOURT_BIN_DIR protoc --proto_path=. --python_out=. DataPoint.proto || exit diff --git a/test/examples/2-ProtobufDataProduct/CMakeLists.txt b/test/examples/2-ProtobufDataProduct/CMakeLists.txt index 53bbf29d5..556ca7e9c 100644 --- a/test/examples/2-ProtobufDataProduct/CMakeLists.txt +++ b/test/examples/2-ProtobufDataProduct/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.17) -project(ProtoBufDataProduct) +project(ProtobufDataProduct) # # see CMakeLists.txt on how to set up CMAKE_PREFIX_PATH and CMAKE_MODULE_PATH # @@ -13,21 +13,24 @@ find_package(Gravity QUIET) file(GLOB PROTO_FILES "${CMAKE_CURRENT_LIST_DIR}/../protobuf/*.proto") -gravity_protobuf_generate(APPEND_PATH PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR} OUT_VAR PROTO_SRCS - PROTOS ${PROTO_FILES}) +gravity_protobuf_generate(APPEND_PATH PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR} OUT_VAR PROTO_SRCS + PROTOS ${PROTO_FILES}) add_custom_target(${PROJECT_NAME}_protos ALL DEPENDS ${PROTO_SRCS}) set(CMAKE_DEBUG_POSTFIX _d) -add_executable(ProtobufDataProductPublisher ProtobufDataProductPublisher.cpp ${PROTO_SRCS}) -set_target_properties(ProtobufDataProductPublisher PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) -target_link_libraries(ProtobufDataProductPublisher PRIVATE gravity spdlog::spdlog_header_only) -target_include_directories(ProtobufDataProductPublisher PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) -add_dependencies(ProtobufDataProductPublisher ${PROJECT_NAME}_protos) - -add_executable(ProtobufDataProductSubscriber ProtobufDataProductSubscriber.cpp ${PROTO_SRCS}) -set_target_properties(ProtobufDataProductSubscriber PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) -target_link_libraries(ProtobufDataProductSubscriber PRIVATE gravity spdlog::spdlog_header_only) -target_include_directories(ProtobufDataProductSubscriber PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) -add_dependencies(ProtobufDataProductSubscriber ${PROJECT_NAME}_protos) - +add_executable(ProtobufDataProductPublisher2 ProtobufDataProductPublisher2.cpp ${PROTO_SRCS}) +set_target_properties(ProtobufDataProductPublisher2 PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +target_link_libraries(ProtobufDataProductPublisher2 PRIVATE gravity spdlog::spdlog_header_only) +target_include_directories(ProtobufDataProductPublisher2 PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +add_dependencies(ProtobufDataProductPublisher2 ${PROJECT_NAME}_protos) + +add_executable(ProtobufDataProductSubscriber2 ProtobufDataProductSubscriber2.cpp ${PROTO_SRCS}) +set_target_properties(ProtobufDataProductSubscriber2 PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +target_link_libraries(ProtobufDataProductSubscriber2 PRIVATE gravity spdlog::spdlog_header_only) +target_include_directories(ProtobufDataProductSubscriber2 PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +add_dependencies(ProtobufDataProductSubscriber2 ${PROJECT_NAME}_protos) + +configure_file(run.sh.in ${ProtobufDataProduct_SOURCE_DIR}/run.sh) +configure_file(RunProtobufDataProductDebug.bat.in ${ProtobufDataProduct_SOURCE_DIR}/RunProtobufDataProductDebug.bat) +configure_file(RunProtobufDataProductRelease.bat.in ${ProtobufDataProduct_SOURCE_DIR}/RunProtobufDataProductRelease.bat) diff --git a/test/examples/2-ProtobufDataProduct/Gravity.ini b/test/examples/2-ProtobufDataProduct/Gravity.ini new file mode 100644 index 000000000..1ab230fde --- /dev/null +++ b/test/examples/2-ProtobufDataProduct/Gravity.ini @@ -0,0 +1,19 @@ +# +# This section is common to all components +# +[general] +# Set the log level for logs written to the log file +GravityFileLogLevel=debug + +# Set the log level for logs written to the console that started the component +#Can make output look funky, so uncomment at your own risk +#GravityConsoleLogLevel=debug + +# Without this, Gravity will spend a few seconds trying to retrieve +# parameters from a remote ConfigServer. +NoConfigServer=true + +# The URL where the ServiceDirectory will be found. This value is the same as the default. +ServiceDirectoryURL="tcp://localhost:5555" + + diff --git a/test/examples/2-ProtobufDataProduct/ProtobufDataProductPublisher.cpp b/test/examples/2-ProtobufDataProduct/ProtobufDataProductPublisher2.cpp similarity index 100% rename from test/examples/2-ProtobufDataProduct/ProtobufDataProductPublisher.cpp rename to test/examples/2-ProtobufDataProduct/ProtobufDataProductPublisher2.cpp diff --git a/test/examples/2-ProtobufDataProduct/ProtobufDataProductSubscriber2.cpp b/test/examples/2-ProtobufDataProduct/ProtobufDataProductSubscriber2.cpp new file mode 100644 index 000000000..40d008ae5 --- /dev/null +++ b/test/examples/2-ProtobufDataProduct/ProtobufDataProductSubscriber2.cpp @@ -0,0 +1,69 @@ +/** (C) Copyright 2013, Applied Physical Sciences Corp., A General Dynamics Company + ** + ** Gravity is free software; you can redistribute it and/or modify + ** it under the terms of the GNU Lesser General Public License as published by + ** the Free Software Foundation; either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU Lesser General Public License for more details. + ** + ** You should have received a copy of the GNU Lesser General Public + ** License along with this program; + ** If not, see . + ** + */ + +#include +#include +#include +#include +#include +#include "spdlog/spdlog.h" +#include "BasicCounterDataProduct.pb.h" + +using namespace gravity; +using namespace std; + +//Declare class for receiving Published messages. +class SimpleGravityCounterSubscriber : public GravitySubscriber +{ +public: + virtual void subscriptionFilled(const std::vector >& dataProducts); +}; + +int main() +{ + GravityNode gn; + //Initialize gravity, giving this node a componentID. + gn.init("SimpleGravityComponentID2"); + + //Declare an object of type SimpleGravityCounterSubscriber (this also initilizes the total count to 0). + SimpleGravityCounterSubscriber counterSubscriber; + //Subscribe a SimpleGravityCounterSubscriber to the counter data product. + gn.subscribe("BasicCounterDataProduct", counterSubscriber); + + //Wait for us to exit (Ctrl-C or being killed). + gn.waitForExit(); + + //Currently this will never be hit because we will have been killed (unfortunately). + //But this shouldn't make a difference because the OS should close the socket and free all resources. + gn.unsubscribe("BasicCounterDataProduct", counterSubscriber); +} + +void SimpleGravityCounterSubscriber::subscriptionFilled( + const std::vector >& dataProducts) +{ + for (std::vector >::const_iterator i = dataProducts.begin(); + i != dataProducts.end(); i++) + { + //Get the protobuf object from the message + BasicCounterDataProductPB counterDataPB; + (*i)->populateMessage(counterDataPB); + + //Process the message + spdlog::warn("Current Count: {}", counterDataPB.count()); + } +} diff --git a/test/examples/2-ProtobufDataProduct/RunProtobufDataProductDebug.bat.in b/test/examples/2-ProtobufDataProduct/RunProtobufDataProductDebug.bat.in new file mode 100755 index 000000000..92dbad363 --- /dev/null +++ b/test/examples/2-ProtobufDataProduct/RunProtobufDataProductDebug.bat.in @@ -0,0 +1,16 @@ +setlocal + +cd @CMAKE_INSTALL_PREFIX@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/libzmq/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/protobuf/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@LOCAL_ZEROMQ_RUNTIME_DIR@ +set path=%Path%;@LOCAL_PROTOBUF_RUNTIME_DIR@ +set path=%Path%;@ProtobufDataProduct_BINARY_DIR@/Debug + +start ServiceDirectory@CMAKE_DEBUG_POSTFIX@.exe +sleep 3 +start ProtobufDataProductPublisher2@CMAKE_DEBUG_POSTFIX@.exe +sleep 3 +start ProtobufDataProductSubscriber2@CMAKE_DEBUG_POSTFIX@.exe diff --git a/test/examples/2-ProtobufDataProduct/RunProtobufDataProductRelease.bat.in b/test/examples/2-ProtobufDataProduct/RunProtobufDataProductRelease.bat.in new file mode 100755 index 000000000..688d1dd77 --- /dev/null +++ b/test/examples/2-ProtobufDataProduct/RunProtobufDataProductRelease.bat.in @@ -0,0 +1,17 @@ +setlocal + + +cd @CMAKE_INSTALL_PREFIX@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/libzmq/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/protobuf/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@LOCAL_ZEROMQ_RUNTIME_DIR@ +set path=%Path%;@LOCAL_PROTOBUF_RUNTIME_DIR@ +set path=%Path%;@ProtobufDataProduct_BINARY_DIR@/Release + +start ServiceDirectory.exe +sleep 3 +start ProtobufDataProductPublisher2.exe +sleep 3 +start ProtobufDataProductSubscriber2.exe diff --git a/test/examples/2-ProtobufDataProduct/run.sh.in b/test/examples/2-ProtobufDataProduct/run.sh.in index 59206238d..1ac5c595f 100755 --- a/test/examples/2-ProtobufDataProduct/run.sh.in +++ b/test/examples/2-ProtobufDataProduct/run.sh.in @@ -19,11 +19,16 @@ # @configure_input@ # Tool-related substitution variables -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -ZMQ_LIB_DIR=@ZEROMQ_LIBDIR@ +PROTOBUF_LIB_DIR=@Protobuf_LIBRARY_RELEASE@ +ZMQ_LIB_DIR=@ZeroMQ_LIBRARY_RELEASE@ +TWO_BIN_DIR=@ProtobufDataProduct_BINARY_DIR@ +SD_BIN_DIR=@ServiceDirectory_BINARY_DIR@ +COMP_BIN_DIR=@TOPLEVEL_INSTALL_PREFIX@/bin #For external builds +CME_LIB_DIR=@TOPLEVEL_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +CMI_LIB_DIR=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ -export PATH=$PATH:../../../src/components/cpp/bin -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR +export PATH=$PATH:$TWO_BIN_DIR:$SD_BIN_DIR:$COMP_BIN_DIR +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR:$CME_LIB_DIR:$CMI_LIB_DIR control_c() # run if user hits control-c @@ -42,10 +47,10 @@ SDPID=$! # sleep for a second to give the service directory a chance to start up sleep 1 -./ProtobufDataProductPublisher & +ProtobufDataProductPublisher2 & PUBPID=$! # sleep for a second to give the publisher a chance to register its data product sleep 1 -./ProtobufDataProductSubscriber +ProtobufDataProductSubscriber2 diff --git a/test/examples/3-MultipleDataProduct/CMakeLists.txt b/test/examples/3-MultipleDataProduct/CMakeLists.txt new file mode 100644 index 000000000..a0138c4bd --- /dev/null +++ b/test/examples/3-MultipleDataProduct/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.17) +project(MultipleDataProduct) +# +# see CMakeLists.txt on how to set up CMAKE_PREFIX_PATH and CMAKE_MODULE_PATH +# + +# for gravity_protobuf_generate +include(GravitySupport) + + +find_package(spdlog REQUIRED) +find_package(Gravity QUIET) + +file(GLOB PROTO_FILES "${CMAKE_CURRENT_LIST_DIR}/../protobuf/*.proto") + +gravity_protobuf_generate(APPEND_PATH PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR} OUT_VAR PROTO_SRCS + PROTOS ${PROTO_FILES}) + +add_custom_target(${PROJECT_NAME}_protos ALL DEPENDS ${PROTO_SRCS}) + +set(CMAKE_DEBUG_POSTFIX _d) +add_executable(MultipleDataProductPublisher MultipleDataProductPublisher.cpp ${PROTO_SRCS}) +set_target_properties(MultipleDataProductPublisher PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +target_link_libraries(MultipleDataProductPublisher PRIVATE gravity spdlog::spdlog_header_only) +target_include_directories(MultipleDataProductPublisher PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +add_dependencies(MultipleDataProductPublisher ${PROJECT_NAME}_protos) + +add_executable(MultipleDataProductSubscriber MultipleDataProductSubscriber.cpp ${PROTO_SRCS}) +set_target_properties(MultipleDataProductSubscriber PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +target_link_libraries(MultipleDataProductSubscriber PRIVATE gravity spdlog::spdlog_header_only) +target_include_directories(MultipleDataProductSubscriber PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +add_dependencies(MultipleDataProductSubscriber ${PROJECT_NAME}_protos) + +configure_file(run.sh.in ${MultipleDataProduct_SOURCE_DIR}/run.sh) +configure_file(RunMultipleDataProductDebug.bat.in ${MultipleDataProduct_SOURCE_DIR}/RunMultipleDataProductDebug.bat) +configure_file(RunMultipleDataProductRelease.bat.in ${MultipleDataProduct_SOURCE_DIR}/RunMultipleDataProductRelease.bat) + diff --git a/test/examples/3-MultipleDataProduct/Gravity.ini b/test/examples/3-MultipleDataProduct/Gravity.ini new file mode 100644 index 000000000..1ab230fde --- /dev/null +++ b/test/examples/3-MultipleDataProduct/Gravity.ini @@ -0,0 +1,19 @@ +# +# This section is common to all components +# +[general] +# Set the log level for logs written to the log file +GravityFileLogLevel=debug + +# Set the log level for logs written to the console that started the component +#Can make output look funky, so uncomment at your own risk +#GravityConsoleLogLevel=debug + +# Without this, Gravity will spend a few seconds trying to retrieve +# parameters from a remote ConfigServer. +NoConfigServer=true + +# The URL where the ServiceDirectory will be found. This value is the same as the default. +ServiceDirectoryURL="tcp://localhost:5555" + + diff --git a/test/examples/3-MultipleDataProduct/MultipleDataProductPublisher.cpp b/test/examples/3-MultipleDataProduct/MultipleDataProductPublisher.cpp index 48d5174b9..ba313f655 100644 --- a/test/examples/3-MultipleDataProduct/MultipleDataProductPublisher.cpp +++ b/test/examples/3-MultipleDataProduct/MultipleDataProductPublisher.cpp @@ -19,9 +19,9 @@ #include #include #include +#include #include - -#include "../protobuf/BasicCounterDataProduct.pb.h" +#include "BasicCounterDataProduct.pb.h" using namespace gravity; diff --git a/test/examples/3-MultipleDataProduct/MultipleDataProductSubscriber.cpp b/test/examples/3-MultipleDataProduct/MultipleDataProductSubscriber.cpp index ea17481bc..5694dafeb 100644 --- a/test/examples/3-MultipleDataProduct/MultipleDataProductSubscriber.cpp +++ b/test/examples/3-MultipleDataProduct/MultipleDataProductSubscriber.cpp @@ -19,9 +19,9 @@ #include #include #include +#include #include - -#include "../protobuf/BasicCounterDataProduct.pb.h" +#include "BasicCounterDataProduct.pb.h" using namespace gravity; using namespace std; diff --git a/test/examples/3-MultipleDataProduct/RunMultipleDataProductDebug.bat.in b/test/examples/3-MultipleDataProduct/RunMultipleDataProductDebug.bat.in new file mode 100644 index 000000000..64efb3ad4 --- /dev/null +++ b/test/examples/3-MultipleDataProduct/RunMultipleDataProductDebug.bat.in @@ -0,0 +1,16 @@ +setlocal + +cd @CMAKE_INSTALL_PREFIX@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/libzmq/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/protobuf/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@LOCAL_ZEROMQ_RUNTIME_DIR@ +set path=%Path%;@LOCAL_PROTOBUF_RUNTIME_DIR@ +set path=%Path%;@MultipleDataProduct_BINARY_DIR@/Debug + +start ServiceDirectory@CMAKE_DEBUG_POSTFIX@.exe +sleep 3 +start MultipleDataProductPublisher@CMAKE_DEBUG_POSTFIX@.exe +sleep 3 +start MultipleDataProductSubscriber@CMAKE_DEBUG_POSTFIX@.exe \ No newline at end of file diff --git a/test/examples/3-MultipleDataProduct/RunMultipleDataProductRelease.bat.in b/test/examples/3-MultipleDataProduct/RunMultipleDataProductRelease.bat.in new file mode 100644 index 000000000..0a4b68e07 --- /dev/null +++ b/test/examples/3-MultipleDataProduct/RunMultipleDataProductRelease.bat.in @@ -0,0 +1,17 @@ +setlocal + + +cd @CMAKE_INSTALL_PREFIX@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/libzmq/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/protobuf/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@LOCAL_ZEROMQ_RUNTIME_DIR@ +set path=%Path%;@LOCAL_PROTOBUF_RUNTIME_DIR@ +set path=%Path%;@MultipleDataProduct_BINARY_DIR@/Release + +start ServiceDirectory.exe +sleep 3 +start MultipleDataProductPublisher.exe +sleep 3 +start MultipleDataProductSubscriber.exe \ No newline at end of file diff --git a/test/examples/3-MultipleDataProduct/run.sh.in b/test/examples/3-MultipleDataProduct/run.sh.in index 4dbecd82a..849a71cb2 100755 --- a/test/examples/3-MultipleDataProduct/run.sh.in +++ b/test/examples/3-MultipleDataProduct/run.sh.in @@ -19,11 +19,16 @@ # @configure_input@ # Tool-related substitution variables -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -ZMQ_LIB_DIR=@ZEROMQ_LIBDIR@ +PROTOBUF_LIB_DIR=@Protobuf_LIBRARY_RELEASE@ +ZMQ_LIB_DIR=@ZeroMQ_LIBRARY_RELEASE@ +THREE_BIN_DIR=@MultipleDataProduct_BINARY_DIR@ +SD_BIN_DIR=@ServiceDirectory_BINARY_DIR@ +COMP_BIN_DIR=@TOPLEVEL_INSTALL_PREFIX@/bin #For external builds +CME_LIB_DIR=@TOPLEVEL_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +CMI_LIB_DIR=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ -export PATH=$PATH:../../../src/components/cpp/bin -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR +export PATH=$PATH:$THREE_BIN_DIR:$SD_BIN_DIR:$COMP_BIN_DIR +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR:$CME_LIB_DIR:$CMI_LIB_DIR control_c() # run if user hits control-c @@ -42,10 +47,10 @@ SDPID=$! # sleep for a second to give the service directory a chance to start up sleep 1 -./MultipleDataProductPublisher & +MultipleDataProductPublisher & PUBPID=$! # sleep for a second to give the publisher a chance to register its data product sleep 1 -./MultipleDataProductSubscriber +MultipleDataProductSubscriber diff --git a/test/examples/4-BasicService/BasicServiceProvider.cpp b/test/examples/4-BasicService/BasicServiceProvider.cpp index e1a32b45c..d094d4b88 100644 --- a/test/examples/4-BasicService/BasicServiceProvider.cpp +++ b/test/examples/4-BasicService/BasicServiceProvider.cpp @@ -19,9 +19,10 @@ #include #include #include +#include #include -#include "../protobuf/Multiplication.pb.h" +#include "Multiplication.pb.h" using namespace gravity; using namespace std; diff --git a/test/examples/4-BasicService/BasicServiceRequestor.cpp b/test/examples/4-BasicService/BasicServiceRequestor.cpp index b785bf0ab..ca5cc2677 100644 --- a/test/examples/4-BasicService/BasicServiceRequestor.cpp +++ b/test/examples/4-BasicService/BasicServiceRequestor.cpp @@ -19,9 +19,9 @@ #include #include #include +#include #include - -#include "../protobuf/Multiplication.pb.h" +#include "Multiplication.pb.h" using namespace gravity; using namespace std; diff --git a/test/examples/4-BasicService/CMakeLists.txt b/test/examples/4-BasicService/CMakeLists.txt new file mode 100644 index 000000000..f9dcc30d4 --- /dev/null +++ b/test/examples/4-BasicService/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.17) +project(BasicService) +# +# see CMakeLists.txt on how to set up CMAKE_PREFIX_PATH and CMAKE_MODULE_PATH +# + +# for gravity_protobuf_generate +include(GravitySupport) + + +find_package(spdlog REQUIRED) +find_package(Gravity QUIET) + +file(GLOB PROTO_FILES "${CMAKE_CURRENT_LIST_DIR}/../protobuf/*.proto") + +gravity_protobuf_generate(APPEND_PATH PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR} OUT_VAR PROTO_SRCS + PROTOS ${PROTO_FILES}) + +add_custom_target(${PROJECT_NAME}_protos ALL DEPENDS ${PROTO_SRCS}) + +set(CMAKE_DEBUG_POSTFIX _d) +add_executable(BasicServiceProvider BasicServiceProvider.cpp ${PROTO_SRCS}) +set_target_properties(BasicServiceProvider PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +target_link_libraries(BasicServiceProvider PRIVATE gravity spdlog::spdlog_header_only) +target_include_directories(BasicServiceProvider PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +add_dependencies(BasicServiceProvider ${PROJECT_NAME}_protos) + +add_executable(BasicServiceRequestor BasicServiceRequestor.cpp ${PROTO_SRCS}) +set_target_properties(BasicServiceRequestor PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +target_link_libraries(BasicServiceRequestor PRIVATE gravity spdlog::spdlog_header_only) +target_include_directories(BasicServiceRequestor PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +add_dependencies(BasicServiceRequestor ${PROJECT_NAME}_protos) + +configure_file(run.sh.in ${BasicService_SOURCE_DIR}/run.sh) +configure_file(RunBasicServiceDebug.bat.in ${BasicService_SOURCE_DIR}/RunBasicServiceDebug.bat) +configure_file(RunBasicServiceRelease.bat.in ${BasicService_SOURCE_DIR}/RunBasicServiceRelease.bat) + diff --git a/test/examples/4-BasicService/Gravity.ini b/test/examples/4-BasicService/Gravity.ini new file mode 100644 index 000000000..1ab230fde --- /dev/null +++ b/test/examples/4-BasicService/Gravity.ini @@ -0,0 +1,19 @@ +# +# This section is common to all components +# +[general] +# Set the log level for logs written to the log file +GravityFileLogLevel=debug + +# Set the log level for logs written to the console that started the component +#Can make output look funky, so uncomment at your own risk +#GravityConsoleLogLevel=debug + +# Without this, Gravity will spend a few seconds trying to retrieve +# parameters from a remote ConfigServer. +NoConfigServer=true + +# The URL where the ServiceDirectory will be found. This value is the same as the default. +ServiceDirectoryURL="tcp://localhost:5555" + + diff --git a/test/examples/4-BasicService/RunBasicServiceDebug.bat.in b/test/examples/4-BasicService/RunBasicServiceDebug.bat.in new file mode 100644 index 000000000..3edcf10b3 --- /dev/null +++ b/test/examples/4-BasicService/RunBasicServiceDebug.bat.in @@ -0,0 +1,16 @@ +setlocal + +cd @CMAKE_INSTALL_PREFIX@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/libzmq/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/protobuf/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@LOCAL_ZEROMQ_RUNTIME_DIR@ +set path=%Path%;@LOCAL_PROTOBUF_RUNTIME_DIR@ +set path=%Path%;@BasicService_BINARY_DIR@/Debug + +start ServiceDirectory@CMAKE_DEBUG_POSTFIX@.exe +sleep 3 +start BasicServiceProvider@CMAKE_DEBUG_POSTFIX@.exe +sleep 3 +start BasicServiceRequestor@CMAKE_DEBUG_POSTFIX@.exe \ No newline at end of file diff --git a/test/examples/4-BasicService/RunBasicServiceRelease.bat.in b/test/examples/4-BasicService/RunBasicServiceRelease.bat.in new file mode 100644 index 000000000..3ab7e9c8d --- /dev/null +++ b/test/examples/4-BasicService/RunBasicServiceRelease.bat.in @@ -0,0 +1,17 @@ +setlocal + + +cd @CMAKE_INSTALL_PREFIX@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/libzmq/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/protobuf/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@LOCAL_ZEROMQ_RUNTIME_DIR@ +set path=%Path%;@LOCAL_PROTOBUF_RUNTIME_DIR@ +set path=%Path%;@BasicService_BINARY_DIR@/Release + +start ServiceDirectory.exe +sleep 3 +start BasicServiceProvider.exe +sleep 3 +start BasicServiceRequestor.exe \ No newline at end of file diff --git a/test/examples/4-BasicService/run.sh.in b/test/examples/4-BasicService/run.sh.in index 2ced2e8af..60f9a7449 100755 --- a/test/examples/4-BasicService/run.sh.in +++ b/test/examples/4-BasicService/run.sh.in @@ -19,11 +19,16 @@ # @configure_input@ # Tool-related substitution variables -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -ZMQ_LIB_DIR=@ZEROMQ_LIBDIR@ +PROTOBUF_LIB_DIR=@Protobuf_LIBRARY_RELEASE@ +ZMQ_LIB_DIR=@ZeroMQ_LIBRARY_RELEASE@ +FOUR_BIN_DIR=@BasicService_BINARY_DIR@ +SD_BIN_DIR=@ServiceDirectory_BINARY_DIR@ +COMP_BIN_DIR=@TOPLEVEL_INSTALL_PREFIX@/bin #For external builds +CME_LIB_DIR=@TOPLEVEL_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +CMI_LIB_DIR=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ -export PATH=$PATH:../../../src/components/cpp/bin -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR +export PATH=$PATH:$SD_BIN_DIR:$FOUR_BIN_DIR:$COMP_BIN_DIR +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR:$CME_LIB_DIR:$CMI_LIB_DIR cleanup() # run if user hits control-c @@ -42,12 +47,12 @@ SDPID=$! # sleep for a second to give the service directory a chance to start up sleep 1 -./BasicServiceProvider & +BasicServiceProvider & BSPPID=$! # sleep for a second to give the publisher a chance to register its data product sleep 1 -./BasicServiceRequestor +BasicServiceRequestor cleanup diff --git a/test/examples/5-MiscFunctionality/CMakeLists.txt b/test/examples/5-MiscFunctionality/CMakeLists.txt new file mode 100644 index 000000000..93b4082cf --- /dev/null +++ b/test/examples/5-MiscFunctionality/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.17) +project(MiscFunctionality) +# +# see CMakeLists.txt one level up on how to set up CMAKE_PREFIX_PATH and CMAKE_MODULE_PATH +# + + +find_package(Gravity QUIET) + +# since we use spdlog directly +find_package(spdlog REQUIRED) + +set(CMAKE_DEBUG_POSTFIX _d) +add_executable(MiscComponent1 MiscComponent1.cpp) +set_target_properties(MiscComponent1 PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +target_link_libraries(MiscComponent1 PRIVATE gravity spdlog::spdlog_header_only) + + +add_executable(MiscComponent2 MiscComponent2.cpp) +set_target_properties(MiscComponent2 PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +target_link_libraries(MiscComponent2 PRIVATE gravity spdlog::spdlog_header_only) + +configure_file(run.sh.in ${MiscFunctionality_SOURCE_DIR}/run.sh) +configure_file(RunMiscFunctionalityDebug.bat.in ${MiscFunctionality_SOURCE_DIR}/RunMiscFunctionalityDebug.bat) +configure_file(RunMiscFunctionalityRelease.bat.in ${MiscFunctionality_SOURCE_DIR}/RunMiscFunctionalityRelease.bat) + diff --git a/test/examples/5-MiscFunctionality/Gravity.ini b/test/examples/5-MiscFunctionality/Gravity.ini new file mode 100644 index 000000000..1ab230fde --- /dev/null +++ b/test/examples/5-MiscFunctionality/Gravity.ini @@ -0,0 +1,19 @@ +# +# This section is common to all components +# +[general] +# Set the log level for logs written to the log file +GravityFileLogLevel=debug + +# Set the log level for logs written to the console that started the component +#Can make output look funky, so uncomment at your own risk +#GravityConsoleLogLevel=debug + +# Without this, Gravity will spend a few seconds trying to retrieve +# parameters from a remote ConfigServer. +NoConfigServer=true + +# The URL where the ServiceDirectory will be found. This value is the same as the default. +ServiceDirectoryURL="tcp://localhost:5555" + + diff --git a/test/examples/5-MiscFunctionality/MiscComponent2.cpp b/test/examples/5-MiscFunctionality/MiscComponent2.cpp index 32431d079..242ffd61b 100644 --- a/test/examples/5-MiscFunctionality/MiscComponent2.cpp +++ b/test/examples/5-MiscFunctionality/MiscComponent2.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include using namespace gravity; diff --git a/test/examples/5-MiscFunctionality/RunMiscFunctionalityDebug.bat.in b/test/examples/5-MiscFunctionality/RunMiscFunctionalityDebug.bat.in new file mode 100644 index 000000000..13438e1f9 --- /dev/null +++ b/test/examples/5-MiscFunctionality/RunMiscFunctionalityDebug.bat.in @@ -0,0 +1,16 @@ +setlocal + +cd @CMAKE_INSTALL_PREFIX@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/libzmq/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/protobuf/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@LOCAL_ZEROMQ_RUNTIME_DIR@ +set path=%Path%;@LOCAL_PROTOBUF_RUNTIME_DIR@ +set path=%Path%;@MiscFunctionality_BINARY_DIR@/Debug + +start ServiceDirectory@CMAKE_DEBUG_POSTFIX@.exe +sleep 3 +start MiscComponent1@CMAKE_DEBUG_POSTFIX@.exe +sleep 3 +start MiscComponent2@CMAKE_DEBUG_POSTFIX@.exe \ No newline at end of file diff --git a/test/examples/5-MiscFunctionality/RunMiscFunctionalityRelease.bat.in b/test/examples/5-MiscFunctionality/RunMiscFunctionalityRelease.bat.in new file mode 100644 index 000000000..d6aef44ae --- /dev/null +++ b/test/examples/5-MiscFunctionality/RunMiscFunctionalityRelease.bat.in @@ -0,0 +1,16 @@ +setlocal + +cd @CMAKE_INSTALL_PREFIX@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/libzmq/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/protobuf/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@LOCAL_ZEROMQ_RUNTIME_DIR@ +set path=%Path%;@LOCAL_PROTOBUF_RUNTIME_DIR@ +set path=%Path%;@MiscFunctionality_BINARY_DIR@/Release + +start ServiceDirectory.exe +sleep 3 +start MiscComponent1.exe +sleep 3 +start MiscComponent2.exe \ No newline at end of file diff --git a/test/examples/5-MiscFunctionality/run.sh.in b/test/examples/5-MiscFunctionality/run.sh.in index d2ab65c75..d8dd6c48b 100755 --- a/test/examples/5-MiscFunctionality/run.sh.in +++ b/test/examples/5-MiscFunctionality/run.sh.in @@ -19,11 +19,16 @@ # @configure_input@ # Tool-related substitution variables -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -ZMQ_LIB_DIR=@ZEROMQ_LIBDIR@ +PROTOBUF_LIB_DIR=@Protobuf_LIBRARY_RELEASE@ +ZMQ_LIB_DIR=@ZeroMQ_LIBRARY_RELEASE@ +FIVE_BIN_DIR=@MiscFunctionality_BINARY_DIR@ +SD_BIN_DIR=@ServiceDirectory_BINARY_DIR@ +COMP_BIN_DIR=@TOPLEVEL_INSTALL_PREFIX@/bin #For external builds +CME_LIB_DIR=@TOPLEVEL_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +CMI_LIB_DIR=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ -export PATH=$PATH:../../../src/components/cpp/bin -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR +export PATH=$PATH:$FIVE_BIN_DIR:$SD_BIN_DIR:$COMP_BIN_DIR +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR:$CME_LIB_DIR:$CMI_LIB_DIR control_c() # run if user hits control-c @@ -42,10 +47,10 @@ SDPID=$! # sleep for a second to give the service directory a chance to start up sleep 1 -./MiscComponent1 & +MiscComponent1 & PUBPID=$! # sleep for a second to give the publisher a chance to register its data product sleep 1 -./MiscComponent2 +MiscComponent2 diff --git a/test/examples/6-JavaProtobufDataProduct/CMakeLists.txt b/test/examples/6-JavaProtobufDataProduct/CMakeLists.txt index a9104bd7c..c7a1da48f 100644 --- a/test/examples/6-JavaProtobufDataProduct/CMakeLists.txt +++ b/test/examples/6-JavaProtobufDataProduct/CMakeLists.txt @@ -1,61 +1,73 @@ -cmake_minimum_required(VERSION 3.17) - -project(JavaProtobufDataProduct) -include(GNUInstallDirs) -include(GravitySupport) - -find_package(Gravity QUIET) - -set(LOCAL_PROTOBUF_JAR) -if (Protobuf_SRC_ROOT_FOLDER) - set(LOCAL_PROTOBUF_JAR "${Protobuf_SRC_ROOT_FOLDER}/java/target/protobuf-java-${Protobuf_VERSION}.jar") -endif() -set(PUBLIC_JAR "/usr/share/java/protobuf.jar" "${LOCAL_PROTOBUF_JAR}") -find_package(GravityJava REQUIRED) -include(UseJava) - -file(GLOB PROTO_FILES "${CMAKE_CURRENT_LIST_DIR}/../protobuf/*.proto") - -gravity_protobuf_generate(APPEND_PATH LANGUAGE java PROTOC_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}" GENERATE_EXTENSIONS .java OUT_VAR PROTO_SRCS PROTOS ${PROTO_FILES}) - -add_custom_target(${PROJECT_NAME}_protos ALL DEPENDS ${PROTO_SRCS}) - -set(CMAKE_JAVA_INCLUDE_PATH "${ABS_GRAVITY_ROOT}/${CMAKE_INSTALL_LIBDIR}/protobuf-java.jar" ${PUBLIC_JAR}) -string(APPEND CMAKE_JAVA_INCLUDE_PATH_FINAL_RELEASE "${_UseJava_PATH_SEP}${ABS_GRAVITY_ROOT}/${CMAKE_INSTALL_LIBDIR}/gravity.jar${_UseJava_PATH_SEP}${CMAKE_BINARY_DIR}/src/api/java/gravity.jar") -string(APPEND CMAKE_JAVA_INCLUDE_PATH_FINAL_DEBUG "${_UseJava_PATH_SEP}${ABS_GRAVITY_ROOT}/${CMAKE_INSTALL_LIBDIR}/gravity${CMAKE_DEBUG_POSTFIX}.jar${_UseJava_PATH_SEP}${CMAKE_BINARY_DIR}/src/api/java/gravity${CMAKE_DEBUG_POSTFIX}.jar") -message(STATUS "CMAKE_JAVA_INCLUDE_PATH_FINAL_DEBUG: ${CMAKE_JAVA_INCLUDE_PATH_FINAL_DEBUG}") - -if (WIN32) - get_target_property(ZeroMQ_LIBRARY_RELEASE libzmq LOCATION_RELEASE) - get_filename_component(LIBZMQ_LIBRARY_DIR "${ZeroMQ_LIBRARY_RELEASE}" DIRECTORY) - set(LOCAL_ZEROMQ_RUNTIME_DIR "${LIBZMQ_LIBRARY_DIR}/../bin") - - get_target_property(Protobuf_LIBRARY_RELEASE protobuf::libprotobuf LOCATION_RELEASE) - get_filename_component(LOCAL_PROTOBUF_RUNTIME_DIR "${Protobuf_LIBRARY_RELEASE}" DIRECTORY) - - configure_file("${CMAKE_CURRENT_LIST_DIR}/RunJavaProtobufDataProductDebug.bat.in" "${CMAKE_BINARY_DIR}/RunJavaProtobufDataProductDebug.bat" @ONLY) - configure_file("${CMAKE_CURRENT_LIST_DIR}/RunJavaProtobufDataProductRelease.bat.in" "${CMAKE_BINARY_DIR}/RunJavaProtobufDataProductRelease.bat" @ONLY) - -endif() - -set(JAVA_SRCS - src/JavaProtobufDataProductPublisher.java - src/JavaProtobufDataProductSubscriber.java - ${PROTO_SRCS}) - -set(ORIG_CMAKE_DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) -set(CMAKE_DEBUG_POSTFIX) -gravity_add_jar_debug_release(${PROJECT_NAME} ${JAVA_SRCS}) -list(APPEND _DEPS ${PROJECT_NAME}_protos) -if (TARGET gravity-java) - list(APPEND _DEPS gravity-java) -endif() -add_dependencies(${PROJECT_NAME} ${_DEPS}) -set(CMAKE_DEBUG_POSTFIX ${ORIG_CMAKE_DEBUG_POSTFIX}) - -#gravity_install_jar(${PROJECT_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") - -if (WIN32) - install(FILES "${CMAKE_BINARY_DIR}/RunJavaProtobufDataProductDebug.bat" DESTINATION bin CONFIGURATIONS Debug) - install(FILES "${CMAKE_BINARY_DIR}/RunJavaProtobufDataProductRelease.bat" DESTINATION bin CONFIGURATIONS Release RelWithDebInfo MinSizeRel) -endif() +cmake_minimum_required(VERSION 3.17) + +project(JavaProtobufDataProduct) +include(GNUInstallDirs) +include(GravitySupport) + +find_package(Gravity QUIET) + +set(LOCAL_PROTOBUF_JAR) +if (Protobuf_SRC_ROOT_FOLDER) + set(LOCAL_PROTOBUF_JAR "${Protobuf_SRC_ROOT_FOLDER}/java/target/protobuf-java-${Protobuf_VERSION}.jar") +endif() +#Need prefix path here because build/install gets created at the end of the build process, and doesn't exist yet when this gets built +set(PUBLIC_JAR "${JAVA_PROTOBUF_JAR}" "${LOCAL_PROTOBUF_JAR}") +list(JOIN PUBLIC_JAR ":" PUBLIC_JAR_CACHE) +set(PUBLIC_JAR_CACHE ${PUBLIC_JAR_CACHE} CACHE ON STRING) +find_package(GravityJava REQUIRED) +include(UseJava) + +file(GLOB PROTO_FILES "${CMAKE_CURRENT_LIST_DIR}/../protobuf/*.proto") + +gravity_protobuf_generate(APPEND_PATH LANGUAGE java PROTOC_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}" GENERATE_EXTENSIONS .java OUT_VAR PROTO_SRCS PROTOS ${PROTO_FILES}) + +add_custom_target(${PROJECT_NAME}_protos ALL DEPENDS ${PROTO_SRCS}) + +#set(CMAKE_JAVA_INCLUDE_PATH "${ABS_GRAVITY_ROOT}/${CMAKE_INSTALL_LIBDIR}/protobuf-java.jar" ${PUBLIC_JAR}) +if(WIN32) +set(CMAKE_JAVA_INCLUDE_PATH "${ABS_GRAVITY_ROOT}/${CMAKE_INSTALL_LIBDIR}/protobuf-java.jar" ${PUBLIC_JAR}) #Takes semicolons as dividers +else() +set(CMAKE_JAVA_INCLUDE_PATH "${ABS_GRAVITY_ROOT}/${CMAKE_INSTALL_LIBDIR}/protobuf-java.jar" ${PUBLIC_JAR_CACHE}) #Linux takes colons as dividers +endif() +string(APPEND CMAKE_JAVA_INCLUDE_PATH_FINAL_RELEASE "${_UseJava_PATH_SEP}${ABS_GRAVITY_ROOT}/${CMAKE_INSTALL_LIBDIR}/gravity.jar${_UseJava_PATH_SEP}${CMAKE_BINARY_DIR}/src/api/java/gravity.jar") +string(APPEND CMAKE_JAVA_INCLUDE_PATH_FINAL_DEBUG "${_UseJava_PATH_SEP}${ABS_GRAVITY_ROOT}/${CMAKE_INSTALL_LIBDIR}/gravity${CMAKE_DEBUG_POSTFIX}.jar${_UseJava_PATH_SEP}${CMAKE_BINARY_DIR}/src/api/java/gravity${CMAKE_DEBUG_POSTFIX}.jar") +message(STATUS "CMAKE_JAVA_INCLUDE_PATH_FINAL_DEBUG: ${CMAKE_JAVA_INCLUDE_PATH_FINAL_DEBUG}") + +if (WIN32) + get_target_property(ZeroMQ_LIBRARY_RELEASE libzmq LOCATION_RELEASE) + get_filename_component(LIBZMQ_LIBRARY_DIR "${ZeroMQ_LIBRARY_RELEASE}" DIRECTORY) + set(LOCAL_ZEROMQ_RUNTIME_DIR "${LIBZMQ_LIBRARY_DIR}/../bin") + + get_target_property(Protobuf_LIBRARY_RELEASE protobuf::libprotobuf LOCATION_RELEASE) + get_filename_component(LOCAL_PROTOBUF_RUNTIME_DIR "${Protobuf_LIBRARY_RELEASE}" DIRECTORY) + + configure_file("${CMAKE_CURRENT_LIST_DIR}/RunJavaProtobufDataProductDebug.bat.in" "${CMAKE_BINARY_DIR}/RunJavaProtobufDataProductDebug.bat" @ONLY) + configure_file("${CMAKE_CURRENT_LIST_DIR}/RunJavaProtobufDataProductRelease.bat.in" "${CMAKE_BINARY_DIR}/RunJavaProtobufDataProductRelease.bat" @ONLY) + +endif() + +set(JAVA_SRCS + src/JavaProtobufDataProductPublisher.java + src/JavaProtobufDataProductSubscriber.java + ${PROTO_SRCS}) + +set(ORIG_CMAKE_DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +set(CMAKE_DEBUG_POSTFIX) +gravity_add_jar_debug_release(${PROJECT_NAME} ${JAVA_SRCS}) +list(APPEND _DEPS ${PROJECT_NAME}_protos) +if (TARGET gravity-java) + list(APPEND _DEPS gravity-java) +endif() +add_dependencies(${PROJECT_NAME} ${_DEPS}) +set(CMAKE_DEBUG_POSTFIX ${ORIG_CMAKE_DEBUG_POSTFIX}) + +gravity_install_jar(${PROJECT_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") + +if (WIN32) + install(FILES "${CMAKE_BINARY_DIR}/RunJavaProtobufDataProductDebug.bat" DESTINATION bin CONFIGURATIONS Debug) + install(FILES "${CMAKE_BINARY_DIR}/RunJavaProtobufDataProductRelease.bat" DESTINATION bin CONFIGURATIONS Release RelWithDebInfo MinSizeRel) +endif() + +configure_file(run.sh.in ${JavaProtobufDataProduct_SOURCE_DIR}/run.sh) +#configure_file(RunJavaProtobufDataProductDebug.bat.in ${JavaProtobufDataProduct_SOURCE_DIR}/RunJavaProtobufDataProductDebug.bat) +#configure_file(RunJavaProtobufDataProductRelease.bat.in ${JavaProtobufDataProduct_SOURCE_DIR}/RunJavaProtobufDataProductRelease.bat) diff --git a/test/examples/6-JavaProtobufDataProduct/Gravity.ini b/test/examples/6-JavaProtobufDataProduct/Gravity.ini new file mode 100644 index 000000000..1ab230fde --- /dev/null +++ b/test/examples/6-JavaProtobufDataProduct/Gravity.ini @@ -0,0 +1,19 @@ +# +# This section is common to all components +# +[general] +# Set the log level for logs written to the log file +GravityFileLogLevel=debug + +# Set the log level for logs written to the console that started the component +#Can make output look funky, so uncomment at your own risk +#GravityConsoleLogLevel=debug + +# Without this, Gravity will spend a few seconds trying to retrieve +# parameters from a remote ConfigServer. +NoConfigServer=true + +# The URL where the ServiceDirectory will be found. This value is the same as the default. +ServiceDirectoryURL="tcp://localhost:5555" + + diff --git a/test/examples/6-JavaProtobufDataProduct/RunJavaProtobufDataProductDebug.bat.in b/test/examples/6-JavaProtobufDataProduct/RunJavaProtobufDataProductDebug.bat.in index e5c19526f..209ae97ef 100644 --- a/test/examples/6-JavaProtobufDataProduct/RunJavaProtobufDataProductDebug.bat.in +++ b/test/examples/6-JavaProtobufDataProduct/RunJavaProtobufDataProductDebug.bat.in @@ -7,9 +7,11 @@ set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/protobuf/bin set Path=%Path%;@ABS_GRAVITY_ROOT@/bin set Path=%Path%;@LOCAL_ZEROMQ_RUNTIME_DIR@ set path=%Path%;@LOCAL_PROTOBUF_RUNTIME_DIR@ +set Path=%Path%;@JavaProtobufDataProduct_BINARY_DIR@ +set Path=%Path%;@protobufs-java_BINARY_DIR@ start ServiceDirectory@CMAKE_DEBUG_POSTFIX@.exe sleep 3 -start "" "@Java_JAVA_EXECUTABLE@" -cp JavaProtobufDataProduct.jar;"@ABS_GRAVITY_ROOT@/deps/protobuf/lib/protobuf-java.jar";"@LOCAL_PROTOBUF_JAR@";"@ABS_GRAVITY_ROOT@/lib/gravity@CMAKE_DEBUG_POSTFIX@.jar" -Djava.library.path="@ABS_GRAVITY_ROOT@/deps/libzmq/bin";"@LOCAL_ZEROMQ_RUNTIME_DIR@";"@ABS_GRAVITY_ROOT@/bin" JavaProtobufDataProductPublisher +start "@Java_JAVA_EXECUTABLE@" -cp JavaProtobufDataProduct.jar;"protobuf-java.jar";"@LOCAL_PROTOBUF_JAR@";"@ABS_GRAVITY_ROOT@/lib/gravity@CMAKE_DEBUG_POSTFIX@.jar" -Djava.library.path="@ABS_GRAVITY_ROOT@/deps/libzmq/bin";"@LOCAL_ZEROMQ_RUNTIME_DIR@";"@ABS_GRAVITY_ROOT@/bin" JavaProtobufDataProductPublisher sleep 3 -start "" "@Java_JAVA_EXECUTABLE@" -cp JavaProtobufDataProduct.jar;"@ABS_GRAVITY_ROOT@/deps/protobuf/lib/protobuf-java.jar";"@LOCAL_PROTOBUF_JAR@";"@ABS_GRAVITY_ROOT@/lib/gravity@CMAKE_DEBUG_POSTFIX@.jar" -Djava.library.path="@ABS_GRAVITY_ROOT@/deps/libzmq/bin";"@LOCAL_ZEROMQ_RUNTIME_DIR@";"@ABS_GRAVITY_ROOT@/bin" JavaProtobufDataProductSubscriber +start "" "@Java_JAVA_EXECUTABLE@" -cp JavaProtobufDataProduct.jar;"protobuf-java.jar";"@LOCAL_PROTOBUF_JAR@";"@ABS_GRAVITY_ROOT@/lib/gravity@CMAKE_DEBUG_POSTFIX@.jar" -Djava.library.path="@ABS_GRAVITY_ROOT@/deps/libzmq/bin";"@LOCAL_ZEROMQ_RUNTIME_DIR@";"@ABS_GRAVITY_ROOT@/bin" JavaProtobufDataProductSubscriber diff --git a/test/examples/6-JavaProtobufDataProduct/RunJavaProtobufDataProductRelease.bat.in b/test/examples/6-JavaProtobufDataProduct/RunJavaProtobufDataProductRelease.bat.in index 8104b631d..0352d57b2 100644 --- a/test/examples/6-JavaProtobufDataProduct/RunJavaProtobufDataProductRelease.bat.in +++ b/test/examples/6-JavaProtobufDataProduct/RunJavaProtobufDataProductRelease.bat.in @@ -7,9 +7,10 @@ set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/protobuf/bin set Path=%Path%;@ABS_GRAVITY_ROOT@/bin set Path=%Path%;@LOCAL_ZEROMQ_RUNTIME_DIR@ set path=%Path%;@LOCAL_PROTOBUF_RUNTIME_DIR@ +set Path=%Path%;@protobufs-java_BINARY_DIR@ start ServiceDirectory.exe sleep 3 -start "" "@Java_JAVA_EXECUTABLE@" -cp JavaProtobufDataProduct.jar;"@ABS_GRAVITY_ROOT@/deps/protobuf/lib/protobuf-java.jar";"@LOCAL_PROTOBUF_JAR@";"@ABS_GRAVITY_ROOT@/lib/gravity.jar" -Djava.library.path="@ABS_GRAVITY_ROOT@/deps/libzmq/bin";"@LOCAL_ZEROMQ_RUNTIME_DIR@";"@ABS_GRAVITY_ROOT@/bin" JavaProtobufDataProductPublisher +start "" "@Java_JAVA_EXECUTABLE@" -cp JavaProtobufDataProduct.jar;"protobuf-java.jar";"@LOCAL_PROTOBUF_JAR@";"@ABS_GRAVITY_ROOT@/lib/gravity.jar" -Djava.library.path="@ABS_GRAVITY_ROOT@/deps/libzmq/bin";"@LOCAL_ZEROMQ_RUNTIME_DIR@";"@ABS_GRAVITY_ROOT@/bin" JavaProtobufDataProductPublisher sleep 3 -start "" "@Java_JAVA_EXECUTABLE@" -cp JavaProtobufDataProduct.jar;"@ABS_GRAVITY_ROOT@/deps/protobuf/lib/protobuf-java.jar";"@LOCAL_PROTOBUF_JAR@";"@ABS_GRAVITY_ROOT@/lib/gravity.jar" -Djava.library.path="@ABS_GRAVITY_ROOT@/deps/libzmq/bin";"@LOCAL_ZEROMQ_RUNTIME_DIR@";"@ABS_GRAVITY_ROOT@/bin" JavaProtobufDataProductSubscriber +start "" "@Java_JAVA_EXECUTABLE@" -cp JavaProtobufDataProduct.jar;"protobuf-java.jar";"@LOCAL_PROTOBUF_JAR@";"@ABS_GRAVITY_ROOT@/lib/gravity.jar" -Djava.library.path="@ABS_GRAVITY_ROOT@/deps/libzmq/bin";"@LOCAL_ZEROMQ_RUNTIME_DIR@";"@ABS_GRAVITY_ROOT@/bin" JavaProtobufDataProductSubscriber diff --git a/test/examples/6-JavaProtobufDataProduct/run.sh.in b/test/examples/6-JavaProtobufDataProduct/run.sh.in index 4f68b0d82..2d33314f4 100755 --- a/test/examples/6-JavaProtobufDataProduct/run.sh.in +++ b/test/examples/6-JavaProtobufDataProduct/run.sh.in @@ -19,26 +19,31 @@ # @configure_input@ # Tool-related substitution variables -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -ZMQ_LIB_DIR=@ZEROMQ_LIBDIR@ -JAVAPROTOBUF_DIR=@JAVAPROTOBUF_DIR@ -WITHOUT_JAVA=@WITHOUT_JAVA@ - -if test $WITHOUT_JAVA = no; +PROTOBUF_LIB_DIR=@Protobuf_LIBRARY_RELEASE@ +ZMQ_LIB_DIR=@ZeroMQ_LIBRARY_RELEASE@ +ZMQ_PAR_DIR=@ZeroMQ_LIBRARY_DIRECTORY@ +JAVAPROTOBUF_DIR=@PUBLIC_JAR_CACHE@ +WITHOUT_JAVA=@SKIP_JAVA@ +SD_BIN_DIR=@ServiceDirectory_BINARY_DIR@ +COMP_BIN_DIR=@TOPLEVEL_INSTALL_PREFIX@/bin #For external builds +CME_LIB_DIR=@TOPLEVEL_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +CMI_LIB_DIR=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +SIX_BIN_DIR=@JavaProtobufDataProduct_BINARY_DIR@ + +if test $WITHOUT_JAVA = OFF; then - export PATH=$PATH:../../../src/api/java:../../../src/components/cpp/bin + export PATH=$PATH:$SD_BIN_DIR:$COMP_BIN_DIR export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ZMQ_LIB_DIR:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR ServiceDirectory & SDPID=$! - java -cp build:$JAVAPROTOBUF_DIR:../../../src/api/java/gravity.jar -Djava.library.path=../../../src/api/java:$ZMQ_LIB_DIR JavaProtobufDataProductPublisher & - JDPPID=$! + java -cp $JAVAPROTOBUF_DIR:$CME_LIB_DIR/gravity.jar:$CMI_LIB_DIR/gravity.jar:$SIX_BIN_DIR/JavaProtobufDataProduct.jar: -Djava.library.path=$CME_LIB_DIR:$CMI_LIB_DIR:$ZMQ_PAR_DIR JavaProtobufDataProductPublisher & # sleep for a second to give the publisher a chance to register its data product sleep 1 - java -cp build:$JAVAPROTOBUF_DIR:../../../src/api/java/gravity.jar -Djava.library.path=../../../src/api/java:$ZMQ_LIB_DIR JavaProtobufDataProductSubscriber + java -cp $JAVAPROTOBUF_DIR:$CME_LIB_DIR/gravity.jar:$CMI_LIB_DIR/gravity.jar:$SIX_BIN_DIR/JavaProtobufDataProduct.jar -Djava.library.path=$CME_LIB_DIR:$CMI_LIB_DIR:$ZMQ_PAR_DIR JavaProtobufDataProductSubscriber kill $SDPID kill $JDPPID diff --git a/test/examples/6-JavaProtobufDataProduct/src/JavaProtobufDataProductSubscriber.java b/test/examples/6-JavaProtobufDataProduct/src/JavaProtobufDataProductSubscriber.java index 059120bd2..8b7c2ce72 100755 --- a/test/examples/6-JavaProtobufDataProduct/src/JavaProtobufDataProductSubscriber.java +++ b/test/examples/6-JavaProtobufDataProduct/src/JavaProtobufDataProductSubscriber.java @@ -20,8 +20,8 @@ import com.aphysci.gravity.GravityDataProduct; import com.aphysci.gravity.GravitySubscriber; import com.aphysci.gravity.swig.GravityNode; -import com.aphysci.gravity.swig.Log; -import com.aphysci.gravity.swig.Log.LogLevel; +import com.aphysci.gravity.swig.SpdLog; +import com.aphysci.gravity.swig.SpdLog.LogLevel; class SimpleGravityCounterSubscriber implements GravitySubscriber @@ -33,10 +33,10 @@ public void subscriptionFilled(List dataProducts) //Get the protobuf object from the message BasicCounterDataProduct.BasicCounterDataProductPB.Builder counterDataPB = BasicCounterDataProduct.BasicCounterDataProductPB.newBuilder(); if(!dataProduct.populateMessage(counterDataPB)) - Log.warning("Error Parsing Message"); + SpdLog.warn("Error Parsing Message"); //Process the message - Log.warning(String.format("Current Count: %d", counterDataPB.getCount())); + SpdLog.warn(String.format("Current Count: %d", counterDataPB.getCount())); } } } diff --git a/test/examples/7-JavaBasicService/CMakeLists.txt b/test/examples/7-JavaBasicService/CMakeLists.txt new file mode 100644 index 000000000..6fc08e465 --- /dev/null +++ b/test/examples/7-JavaBasicService/CMakeLists.txt @@ -0,0 +1,70 @@ +cmake_minimum_required(VERSION 3.17) + +project(JavaBasicService) +include(GNUInstallDirs) +include(GravitySupport) + +find_package(Gravity QUIET) + +set(LOCAL_PROTOBUF_JAR) +if (Protobuf_SRC_ROOT_FOLDER) + set(LOCAL_PROTOBUF_JAR "${Protobuf_SRC_ROOT_FOLDER}/java/target/protobuf-java-${Protobuf_VERSION}.jar") +endif() +#Need prefix path here because build/install gets created at the end of the build process, and doesn't exist yet when this gets built +set(PUBLIC_JAR "${JAVA_PROTOBUF_JAR}" "${LOCAL_PROTOBUF_JAR}") +find_package(GravityJava REQUIRED) +include(UseJava) + +file(GLOB PROTO_FILES "${CMAKE_CURRENT_LIST_DIR}/../protobuf/*.proto") + +gravity_protobuf_generate(APPEND_PATH LANGUAGE java PROTOC_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}" GENERATE_EXTENSIONS .java OUT_VAR PROTO_SRCS PROTOS ${PROTO_FILES}) + +add_custom_target(${PROJECT_NAME}_protos ALL DEPENDS ${PROTO_SRCS}) + +if(WIN32) + set(CMAKE_JAVA_INCLUDE_PATH "${ABS_GRAVITY_ROOT}/${CMAKE_INSTALL_LIBDIR}/protobuf-java.jar" ${PUBLIC_JAR}) #Takes semicolons as dividers +else() + set(CMAKE_JAVA_INCLUDE_PATH "${ABS_GRAVITY_ROOT}/${CMAKE_INSTALL_LIBDIR}/protobuf-java.jar" ${PUBLIC_JAR_CACHE}) #Linux takes colons as dividers +endif() +string(APPEND CMAKE_JAVA_INCLUDE_PATH_FINAL_RELEASE "${_UseJava_PATH_SEP}${ABS_GRAVITY_ROOT}/${CMAKE_INSTALL_LIBDIR}/gravity.jar${_UseJava_PATH_SEP}${CMAKE_BINARY_DIR}/src/api/java/gravity.jar") +string(APPEND CMAKE_JAVA_INCLUDE_PATH_FINAL_DEBUG "${_UseJava_PATH_SEP}${ABS_GRAVITY_ROOT}/${CMAKE_INSTALL_LIBDIR}/gravity${CMAKE_DEBUG_POSTFIX}.jar${_UseJava_PATH_SEP}${CMAKE_BINARY_DIR}/src/api/java/gravity${CMAKE_DEBUG_POSTFIX}.jar") +message(STATUS "CMAKE_JAVA_INCLUDE_PATH_FINAL_DEBUG: ${CMAKE_JAVA_INCLUDE_PATH_FINAL_DEBUG}") + +if (WIN32) + get_target_property(ZeroMQ_LIBRARY_RELEASE libzmq LOCATION_RELEASE) + get_filename_component(LIBZMQ_LIBRARY_DIR "${ZeroMQ_LIBRARY_RELEASE}" DIRECTORY) + set(LOCAL_ZEROMQ_RUNTIME_DIR "${LIBZMQ_LIBRARY_DIR}/../bin") + + get_target_property(Protobuf_LIBRARY_RELEASE protobuf::libprotobuf LOCATION_RELEASE) + get_filename_component(LOCAL_PROTOBUF_RUNTIME_DIR "${Protobuf_LIBRARY_RELEASE}" DIRECTORY) + + configure_file("${CMAKE_CURRENT_LIST_DIR}/RunJavaBasicServiceDebug.bat.in" "${CMAKE_BINARY_DIR}/RunJavaBasicServiceDebug.bat" @ONLY) + configure_file("${CMAKE_CURRENT_LIST_DIR}/RunJavaBasicServiceRelease.bat.in" "${CMAKE_BINARY_DIR}/RunJavaBasicServiceRelease.bat" @ONLY) + +endif() + +set(JAVA_SRCS + src/BasicServiceProvider.java + src/BasicServiceRequestor.java + ${PROTO_SRCS}) + +set(ORIG_CMAKE_DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +set(CMAKE_DEBUG_POSTFIX) +gravity_add_jar_debug_release(${PROJECT_NAME} ${JAVA_SRCS}) +list(APPEND _DEPS ${PROJECT_NAME}_protos) +if (TARGET gravity-java) + list(APPEND _DEPS gravity-java) +endif() +add_dependencies(${PROJECT_NAME} ${_DEPS}) +set(CMAKE_DEBUG_POSTFIX ${ORIG_CMAKE_DEBUG_POSTFIX}) + +gravity_install_jar(${PROJECT_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") + +if (WIN32) +install(FILES "${CMAKE_BINARY_DIR}/RunJavaProtobufDataProductDebug.bat" DESTINATION bin CONFIGURATIONS Debug) +install(FILES "${CMAKE_BINARY_DIR}/RunJavaProtobufDataProductRelease.bat" DESTINATION bin CONFIGURATIONS Release RelWithDebInfo MinSizeRel) +endif() + +configure_file(run.sh.in ${JavaBasicService_SOURCE_DIR}/run.sh) +configure_file(RunJavaBasicServiceDebug.bat.in ${JavaBasicService_SOURCE_DIR}/RunJavaBasicServiceDebug.bat) +configure_file(RunJavaBasicServiceRelease.bat.in ${JavaBasicService_SOURCE_DIR}/RunJavaBasicServiceRelease.bat) diff --git a/test/examples/7-JavaBasicService/Gravity.ini b/test/examples/7-JavaBasicService/Gravity.ini new file mode 100644 index 000000000..cee09360b --- /dev/null +++ b/test/examples/7-JavaBasicService/Gravity.ini @@ -0,0 +1,18 @@ +# +# This section is common to all components +# +[general] +# Set the log level for logs written to the log file +GravityFileLogLevel=debug + +# Set the log level for logs written to the console that started the component +#GravityConsoleLogLevel=debug + +# Without this, Gravity will spend a few seconds trying to retrieve +# parameters from a remote ConfigServer. +NoConfigServer=true + +# The URL where the ServiceDirectory will be found. This value is the same as the default. +ServiceDirectoryURL="tcp://localhost:5555" + + diff --git a/test/examples/7-JavaBasicService/RunJavaBasicServiceDebug.bat.in b/test/examples/7-JavaBasicService/RunJavaBasicServiceDebug.bat.in new file mode 100644 index 000000000..1c056edb4 --- /dev/null +++ b/test/examples/7-JavaBasicService/RunJavaBasicServiceDebug.bat.in @@ -0,0 +1,17 @@ +setlocal + +cd @CMAKE_INSTALL_PREFIX@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/libzmq/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/protobuf/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@LOCAL_ZEROMQ_RUNTIME_DIR@ +set path=%Path%;@LOCAL_PROTOBUF_RUNTIME_DIR@ +set Path=%Path%;@JavaBasicService_BINARY_DIR@ +set Path=%Path%;@protobufs-java_BINARY_DIR@ + +start ServiceDirectory@CMAKE_DEBUG_POSTFIX@.exe +sleep 3 +start "" "@Java_JAVA_EXECUTABLE@" -cp JavaBasicService.jar;"protobuf-java.jar";"@ABS_GRAVITY_ROOT@/lib/gravity@CMAKE_DEBUG_POSTFIX@.jar" -Djava.library.path="@ABS_GRAVITY_ROOT@/deps/libzmq/bin";"@LOCAL_ZEROMQ_RUNTIME_DIR@";"@ABS_GRAVITY_ROOT@/bin" JavaBasicServiceProvider +sleep 3 +start "" "@Java_JAVA_EXECUTABLE@" -cp JavaBasicService.jar;"protobuf-java.jar";"@ABS_GRAVITY_ROOT@/lib/gravity@CMAKE_DEBUG_POSTFIX@.jar" -Djava.library.path="@ABS_GRAVITY_ROOT@/deps/libzmq/bin";"@LOCAL_ZEROMQ_RUNTIME_DIR@";"@ABS_GRAVITY_ROOT@/bin" JavaBasicServiceRequestor \ No newline at end of file diff --git a/test/examples/7-JavaBasicService/RunJavaBasicServiceRelease.bat.in b/test/examples/7-JavaBasicService/RunJavaBasicServiceRelease.bat.in new file mode 100644 index 000000000..3b9acf22e --- /dev/null +++ b/test/examples/7-JavaBasicService/RunJavaBasicServiceRelease.bat.in @@ -0,0 +1,17 @@ +setlocal + +cd @CMAKE_INSTALL_PREFIX@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/libzmq/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/deps/protobuf/bin +set Path=%Path%;@ABS_GRAVITY_ROOT@/bin +set Path=%Path%;@LOCAL_ZEROMQ_RUNTIME_DIR@ +set path=%Path%;@LOCAL_PROTOBUF_RUNTIME_DIR@ +set Path=%Path%;@JavaBasicService_BINARY_DIR@ +set Path=%Path%;@protobufs-java_BINARY_DIR@ + +start ServiceDirectory.exe +sleep 3 +start "" "@Java_JAVA_EXECUTABLE@" -cp JavaBasicService.jar;"protobuf-java.jar";"@LOCAL_PROTOBUF_JAR@";"@ABS_GRAVITY_ROOT@/lib/gravity.jar" -Djava.library.path="@ABS_GRAVITY_ROOT@/deps/libzmq/bin";"@LOCAL_ZEROMQ_RUNTIME_DIR@";"@ABS_GRAVITY_ROOT@/bin" JavaBasicServiceProvider +sleep 3 +start "" "@Java_JAVA_EXECUTABLE@" -cp JavaBasicService.jar;"protobuf-java.jar";"@LOCAL_PROTOBUF_JAR@";"@ABS_GRAVITY_ROOT@/lib/gravity.jar" -Djava.library.path="@ABS_GRAVITY_ROOT@/deps/libzmq/bin";"@LOCAL_ZEROMQ_RUNTIME_DIR@";"@ABS_GRAVITY_ROOT@/bin" JavaBasicServiceRequestor \ No newline at end of file diff --git a/test/examples/7-JavaBasicService/run.sh.in b/test/examples/7-JavaBasicService/run.sh.in index 1b248471f..deeea64ff 100755 --- a/test/examples/7-JavaBasicService/run.sh.in +++ b/test/examples/7-JavaBasicService/run.sh.in @@ -19,27 +19,33 @@ # @configure_input@ # Tool-related substitution variables -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -ZMQ_LIB_DIR=@ZEROMQ_LIBDIR@ -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -JAVAPROTOBUF_DIR=@JAVAPROTOBUF_DIR@ -WITHOUT_JAVA=@WITHOUT_JAVA@ - -if test $WITHOUT_JAVA = no; +PROTOBUF_LIB_DIR=@Protobuf_LIBRARY_RELEASE@ +ZMQ_LIB_DIR=@ZeroMQ_LIBRARY_RELEASE@ +ZMQ_PAR_DIR=@ZeroMQ_LIBRARY_DIRECTORY@ +JAVAPROTOBUF_DIR=@PUBLIC_JAR_CACHE@ +WITHOUT_JAVA=@SKIP_JAVA@ +SD_BIN_DIR=@ServiceDirectory_BINARY_DIR@ +CME_LIB_DIR=@TOPLEVEL_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +CMI_LIB_DIR=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +COMP_BIN_DIR=@TOPLEVEL_INSTALL_PREFIX@/bin #For external builds +SEV_BIN_DIR=@JavaBasicService_BINARY_DIR@ + + +if test $WITHOUT_JAVA = OFF; then - export PATH=$PATH:../../../src/api/java:../../../src/components/cpp/bin + export PATH=$PATH:$SD_BIN_DIR:$COMP_BIN_DIR export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR - ServiceDirectory & + ServiceDirectory & SDPID=$! - java -cp build:$JAVAPROTOBUF_DIR:../../../src/api/java/gravity.jar -Djava.library.path=../../../src/api/java:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR BasicServiceProvider & + java -cp build:$JAVAPROTOBUF_DIR:$CME_LIB_DIR/gravity.jar:$CMI_LIB_DIR/gravity.jar:$SEV_BIN_DIR/JavaBasicService.jar -Djava.library.path=$CME_LIB_DIR:$CMI_LIB_DIR:$ZMQ_PAR_DIR BasicServiceProvider & JDPPID=$! # sleep for a second to give the publisher a chance to register its data product sleep 1 - java -cp build:$JAVAPROTOBUF_DIR:../../../src/api/java/gravity.jar -Djava.library.path=../../../src/api/java:$ZMQ_LIB_DIR BasicServiceRequestor + java -cp build:$JAVAPROTOBUF_DIR:$CME_LIB_DIR/gravity.jar:$CMI_LIB_DIR/gravity.jar:$SEV_BIN_DIR/JavaBasicService.jar:$JAVA_PROTOBUF_JAR -Djava.library.path=$CME_LIB_DIR:$CMI_LIB_DIR:$ZMQ_PAR_DIR BasicServiceRequestor kill $SDPID kill $JDPPID diff --git a/test/examples/7-JavaBasicService/src/BasicServiceProvider.java b/test/examples/7-JavaBasicService/src/BasicServiceProvider.java index 72067bcf9..592263adc 100755 --- a/test/examples/7-JavaBasicService/src/BasicServiceProvider.java +++ b/test/examples/7-JavaBasicService/src/BasicServiceProvider.java @@ -19,8 +19,8 @@ import com.aphysci.gravity.GravityDataProduct; import com.aphysci.gravity.GravityServiceProvider; import com.aphysci.gravity.swig.GravityNode; -import com.aphysci.gravity.swig.Log; -import com.aphysci.gravity.swig.Log.LogLevel; +import com.aphysci.gravity.swig.SpdLog; +import com.aphysci.gravity.swig.SpdLog.LogLevel; import com.aphysci.gravity.swig.GravityTransportType; class MultiplicationServiceProvider implements GravityServiceProvider @@ -34,7 +34,7 @@ public GravityDataProduct request(String serviceID, GravityDataProduct dataProdu { //Just to be safe. In theory this can never happen unless this class is registered with more than one serviceID types. if(!dataProduct.getDataProductID().equals("Multiplication")) { - Log.critical(String.format("Request is not for %s, not Multiplication!", dataProduct.getDataProductID())); + SpdLog.critical(String.format("Request is not for %s, not Multiplication!", dataProduct.getDataProductID())); return new GravityDataProduct("BadRequest"); } @@ -42,7 +42,7 @@ public GravityDataProduct request(String serviceID, GravityDataProduct dataProdu Multiplication.MultiplicationOperandsPB.Builder params = Multiplication.MultiplicationOperandsPB.newBuilder(); dataProduct.populateMessage(params); - Log.warning(String.format("%d x %d", params.getMultiplicandA(), params.getMultiplicandB())); + SpdLog.warn(String.format("%d x %d", params.getMultiplicandA(), params.getMultiplicandB())); //Do the calculation int result = params.getMultiplicandA() * params.getMultiplicandB(); diff --git a/test/examples/7-JavaBasicService/src/BasicServiceRequestor.java b/test/examples/7-JavaBasicService/src/BasicServiceRequestor.java index a20fdff80..f2e5d78b9 100755 --- a/test/examples/7-JavaBasicService/src/BasicServiceRequestor.java +++ b/test/examples/7-JavaBasicService/src/BasicServiceRequestor.java @@ -20,7 +20,7 @@ import com.aphysci.gravity.GravityRequestor; import com.aphysci.gravity.swig.GravityNode; import com.aphysci.gravity.swig.GravityReturnCode; -import com.aphysci.gravity.swig.Log; +import com.aphysci.gravity.swig.SpdLog; //After multiplication is requested, this class may be called with the result. @@ -33,7 +33,7 @@ public void requestFilled(String serviceID, String requestID, GravityDataProduct response.populateMessage(result); //Write the answer - Log.warning(String.format("%s: %d", requestID, result.getResult())); + SpdLog.warn(String.format("%s: %d", requestID, result.getResult())); gotAsyncMessage = true; } @@ -56,7 +56,7 @@ public static void main(String[] args) throws InterruptedException { //Initialize gravity, giving this node a componentID. GravityReturnCode ret = gn.init("MultiplicationRequestor"); while (ret != GravityReturnCode.SUCCESS) { - Log.warning("Unable to initialize component, retrying..."); + SpdLog.warn("Unable to initialize component, retrying..."); ret = gn.init("MultiplicationRequestor"); } @@ -79,7 +79,7 @@ public static void main(String[] args) throws InterruptedException { // Service may not be registered yet if (ret != GravityReturnCode.SUCCESS) { - Log.warning("Failed request to Multiplication, retrying..."); + SpdLog.warn("Failed request to Multiplication, retrying..."); Thread.sleep(1000); } } while (ret != GravityReturnCode.SUCCESS); @@ -98,14 +98,14 @@ public static void main(String[] args) throws InterruptedException { 1000); //Timeout in milliseconds if(multSync == null) { - Log.critical("Request Returned NULL!"); + SpdLog.critical("Request Returned NULL!"); } else { Multiplication.MultiplicationResultPB.Builder result = Multiplication.MultiplicationResultPB.newBuilder(); multSync.populateMessage(result); - Log.warning(String.format("5 x 7 = %d", result.getResult())); + SpdLog.warn(String.format("5 x 7 = %d", result.getResult())); } ///////////////////////////////////////// diff --git a/test/examples/8-ConfigFile/CMakeLists.txt b/test/examples/8-ConfigFile/CMakeLists.txt new file mode 100644 index 000000000..916f61170 --- /dev/null +++ b/test/examples/8-ConfigFile/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.17) +project(ConfigFile) +# +# see CMakeLists.txt one level up on how to set up CMAKE_PREFIX_PATH and CMAKE_MODULE_PATH +# + + +find_package(Gravity QUIET) + +# since we use spdlog directly +find_package(spdlog REQUIRED) + +set(CMAKE_DEBUG_POSTFIX _d) +add_executable(ConfigFileExample ConfigFileExample.cpp) +set_target_properties(ConfigFileExample PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +target_link_libraries(ConfigFileExample PRIVATE gravity spdlog::spdlog_header_only) +configure_file(run.sh.in ${ConfigFile_SOURCE_DIR}/run.sh) diff --git a/test/examples/8-ConfigFile/ConfigFileExample.cpp b/test/examples/8-ConfigFile/ConfigFileExample.cpp index c67bed521..30fd34c25 100644 --- a/test/examples/8-ConfigFile/ConfigFileExample.cpp +++ b/test/examples/8-ConfigFile/ConfigFileExample.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include int main() diff --git a/test/examples/8-ConfigFile/Gravity.ini b/test/examples/8-ConfigFile/Gravity.ini index 2ba5b4d9d..32cdb34dd 100644 --- a/test/examples/8-ConfigFile/Gravity.ini +++ b/test/examples/8-ConfigFile/Gravity.ini @@ -3,10 +3,10 @@ # [general] # Set the log level for logs written to the log file -LocalLogLevel=debug +GravityFileLogLevel=debug # Set the log level for logs written to the console that started the component -ConsoleLogLevel=debug +#GravityConsoleLogLevel=debug # Without this, Gravity will spend a few seconds trying to retrieve # parameters from a remote ConfigServer. diff --git a/test/examples/8-ConfigFile/run.sh.in b/test/examples/8-ConfigFile/run.sh.in index 8949d053f..5f6fa4f4c 100755 --- a/test/examples/8-ConfigFile/run.sh.in +++ b/test/examples/8-ConfigFile/run.sh.in @@ -19,11 +19,17 @@ # @configure_input@ # Tool-related substitution variables -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -ZMQ_LIB_DIR=@ZEROMQ_LIBDIR@ - -export PATH=$PATH:../../../src/components/cpp/ConfigServer:../../../src/components/cpp/ServiceDirectory -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR +PROTOBUF_LIB_DIR=@Protobuf_LIBRARY_RELEASE@ +ZMQ_LIB_DIR=@ZeroMQ_LIBRARY_RELEASE@ +EIGHT_BIN_DIR=@ConfigFile_BINARY_DIR@ +SD_BIN_DIR=@ServiceDirectory_BINARY_DIR@ +CS_BIN_DIR=@ConfigServer_BINARY_DIR@ +COMP_BIN_DIR=@TOPLEVEL_INSTALL_PREFIX@/bin #For external builds +CME_LIB_DIR=@TOPLEVEL_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +CMI_LIB_DIR=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ + +export PATH=$PATH:$CS_BIN_DIR:$SD_BIN_DIR:$EIGHT_BIN_DIR:$COMP_BIN_DIR +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR:$CME_LIB_DIR:$CMI_LIB_DIR cleanup() # run if user hits control-c @@ -48,6 +54,6 @@ CSPID=$! # ConfigServer needs to be up and registered before client code calls init sleep 20 -./ConfigFileExample +ConfigFileExample cleanup diff --git a/test/examples/9-Domains/CMakeLists.txt b/test/examples/9-Domains/CMakeLists.txt new file mode 100644 index 000000000..09854027a --- /dev/null +++ b/test/examples/9-Domains/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.17) +project(Domains) +# +# see CMakeLists.txt on how to set up CMAKE_PREFIX_PATH and CMAKE_MODULE_PATH +# + +# for gravity_protobuf_generate +include(GravitySupport) + + +find_package(spdlog REQUIRED) +find_package(Gravity QUIET) + +file(GLOB PROTO_FILES "${CMAKE_CURRENT_LIST_DIR}/../protobuf/*.proto") + +gravity_protobuf_generate(APPEND_PATH PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR} OUT_VAR PROTO_SRCS + PROTOS ${PROTO_FILES}) + +add_custom_target(${PROJECT_NAME}_protos ALL DEPENDS ${PROTO_SRCS}) + +set(CMAKE_DEBUG_POSTFIX _d) +add_executable(ProtobufDataProductPublisher9 ProtobufDataProductPublisher9.cpp ${PROTO_SRCS}) +set_target_properties(ProtobufDataProductPublisher9 PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +target_link_libraries(ProtobufDataProductPublisher9 PRIVATE gravity spdlog::spdlog_header_only) +target_include_directories(ProtobufDataProductPublisher9 PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +add_dependencies(ProtobufDataProductPublisher9 ${PROJECT_NAME}_protos) + +add_executable(ProtobufDataProductSubscriber9 ProtobufDataProductSubscriber9.cpp ${PROTO_SRCS}) +set_target_properties(ProtobufDataProductSubscriber9 PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +target_link_libraries(ProtobufDataProductSubscriber9 PRIVATE gravity spdlog::spdlog_header_only) +target_include_directories(ProtobufDataProductSubscriber9 PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +add_dependencies(ProtobufDataProductSubscriber9 ${PROJECT_NAME}_protos) + +configure_file(run.sh.in ${Domains_SOURCE_DIR}/run.sh) diff --git a/test/examples/9-Domains/Gravity.ini b/test/examples/9-Domains/Gravity.ini index 83759f14d..3d9577488 100755 --- a/test/examples/9-Domains/Gravity.ini +++ b/test/examples/9-Domains/Gravity.ini @@ -2,8 +2,8 @@ [general] Domain="Example9" NoConfigServer=true -LocalLogLevel=debug -ConsoleLogLevel=trace +GravityFileLogLevel=debug +#GravityConsoleLogLevel=debug [ServiceDirectory] ServiceDirectoryURL="tcp://localhost:5555" diff --git a/test/examples/9-Domains/ProtobufDataProductPublisher.cpp b/test/examples/9-Domains/ProtobufDataProductPublisher.cpp index 821ee238c..62468aab4 100644 --- a/test/examples/9-Domains/ProtobufDataProductPublisher.cpp +++ b/test/examples/9-Domains/ProtobufDataProductPublisher.cpp @@ -19,9 +19,10 @@ #include #include #include +#include #include -#include "../protobuf/BasicCounterDataProduct.pb.h" +#include "BasicCounterDataProduct.pb.h" int main() { diff --git a/test/examples/9-Domains/ProtobufDataProductPublisher9.cpp b/test/examples/9-Domains/ProtobufDataProductPublisher9.cpp new file mode 100644 index 000000000..62468aab4 --- /dev/null +++ b/test/examples/9-Domains/ProtobufDataProductPublisher9.cpp @@ -0,0 +1,78 @@ +/** (C) Copyright 2013, Applied Physical Sciences Corp., A General Dynamics Company + ** + ** Gravity is free software; you can redistribute it and/or modify + ** it under the terms of the GNU Lesser General Public License as published by + ** the Free Software Foundation; either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU Lesser General Public License for more details. + ** + ** You should have received a copy of the GNU Lesser General Public + ** License along with this program; + ** If not, see . + ** + */ + +#include +#include +#include +#include +#include + +#include "BasicCounterDataProduct.pb.h" + +int main() +{ + using namespace gravity; + + GravityNode gn; + //Initialize gravity, giving this node a componentID. + GravityReturnCode grc = gn.init("ProtobufGravityComponentID"); + + // It's possible that the GravityNode fails to initialize when using Domains because + // it hasn't heard from the ServiceDirectory. Looping as we've done here ensures that + // the component has connected to the ServiceDirectory before it continues to other tasks. + while (grc != GravityReturnCodes::SUCCESS) + { + spdlog::warn("Unable to connect to ServiceDirectory, will try again in 1 second..."); + gravity::sleep(1000); + grc = gn.init("ProtobufGravityComponentID"); + } + + gn.registerDataProduct( + //This identifies the Data Product to the service directory so that others can + // subscribe to it. (See BasicDataProductSubscriber.cpp). + "BasicCounterDataProduct", + //Assign a transport type to the socket (almost always tcp, unless you are only + //using the gravity data product between two processes on the same computer). + GravityTransportTypes::TCP); + + bool quit = false; //TODO: set this when you want the program to quit if you need to clean up before exiting. + int count = 1; + while (!quit) + { + //Create a data product to send across the network of type "BasicCounterDataProduct". + GravityDataProduct counterDataProduct( + "BasicCounterDataProduct"); //In order to publish, the DataProductID must match one of the registered types. + + //Initialize our message + BasicCounterDataProductPB counterDataPB; + counterDataPB.set_count(count); + + //Put message into data product + counterDataProduct.setData(counterDataPB); + + //Publish the data product. + gn.publish(counterDataProduct); + + //Increment count + count++; + if (count > 50) count = 1; + + //Sleep for 1 second. + gravity::sleep(1000); + } +} diff --git a/test/examples/9-Domains/ProtobufDataProductSubscriber.cpp b/test/examples/9-Domains/ProtobufDataProductSubscriber.cpp index 591a8c79e..602cd2585 100644 --- a/test/examples/9-Domains/ProtobufDataProductSubscriber.cpp +++ b/test/examples/9-Domains/ProtobufDataProductSubscriber.cpp @@ -20,9 +20,10 @@ #include #include #include +#include #include -#include "../protobuf/BasicCounterDataProduct.pb.h" +#include "BasicCounterDataProduct.pb.h" using namespace gravity; using namespace std; diff --git a/test/examples/9-Domains/ProtobufDataProductSubscriber9.cpp b/test/examples/9-Domains/ProtobufDataProductSubscriber9.cpp new file mode 100644 index 000000000..602cd2585 --- /dev/null +++ b/test/examples/9-Domains/ProtobufDataProductSubscriber9.cpp @@ -0,0 +1,80 @@ +/** (C) Copyright 2013, Applied Physical Sciences Corp., A General Dynamics Company + ** + ** Gravity is free software; you can redistribute it and/or modify + ** it under the terms of the GNU Lesser General Public License as published by + ** the Free Software Foundation; either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU Lesser General Public License for more details. + ** + ** You should have received a copy of the GNU Lesser General Public + ** License along with this program; + ** If not, see . + ** + */ + +#include +#include +#include +#include +#include +#include + +#include "BasicCounterDataProduct.pb.h" + +using namespace gravity; +using namespace std; + +//Declare class for receiving Published messages. +class SimpleGravityCounterSubscriber : public GravitySubscriber +{ +public: + virtual void subscriptionFilled(const std::vector >& dataProducts); +}; + +int main() +{ + GravityNode gn; + //Initialize gravity, giving this node a componentID. + GravityReturnCode grc = gn.init("SimpleGravityComponentID2"); + + // It's possible that the GravityNode fails to initialize when using Domains because + // it hasn't heard from the ServiceDirectory. Looping as we've done here ensures that + // the component has connected to the ServiceDirectory before it continues to other tasks. + while (grc != GravityReturnCodes::SUCCESS) + { + spdlog::warn("Unable to connect to ServiceDirectory, will try again in 1 second..."); + gravity::sleep(1000); + grc = gn.init("SimpleGravityComponentID2"); + } + + //Declare an object of type SimpleGravityCounterSubscriber (this also initilizes the total count to 0). + SimpleGravityCounterSubscriber counterSubscriber; + //Subscribe a SimpleGravityCounterSubscriber to the counter data product. + gn.subscribe("BasicCounterDataProduct", counterSubscriber); + + //Wait for us to exit (Ctrl-C or being killed). + gn.waitForExit(); + + //Currently this will never be hit because we will have been killed (unfortunately). + //But this shouldn't make a difference because the OS should close the socket and free all resources. + gn.unsubscribe("BasicCounterDataProduct", counterSubscriber); +} + +void SimpleGravityCounterSubscriber::subscriptionFilled( + const std::vector >& dataProducts) +{ + for (std::vector >::const_iterator i = dataProducts.begin(); + i != dataProducts.end(); i++) + { + //Get the protobuf object from the message + BasicCounterDataProductPB counterDataPB; + (*i)->populateMessage(counterDataPB); + + //Process the message + spdlog::warn("Current Count: {}", counterDataPB.count()); + } +} diff --git a/test/examples/9-Domains/run.sh.in b/test/examples/9-Domains/run.sh.in index 9546e5ef2..a0c9af1fe 100755 --- a/test/examples/9-Domains/run.sh.in +++ b/test/examples/9-Domains/run.sh.in @@ -19,11 +19,16 @@ # @configure_input@ # Tool-related substitution variables -PROTOBUF_LIB_DIR=@PROTOBUF_LIBDIR@ -ZMQ_LIB_DIR=@ZEROMQ_LIBDIR@ +PROTOBUF_LIB_DIR=@Protobuf_LIBRARY_RELEASE@ +ZMQ_LIB_DIR=@ZeroMQ_LIBRARY_RELEASE@ +NINE_BIN_DIR=@Domains_BINARY_DIR@ +SD_BIN_DIR=@ServiceDirectory_BINARY_DIR@ +COMP_BIN_DIR=@TOPLEVEL_INSTALL_PREFIX@/bin #For external builds +CME_LIB_DIR=@TOPLEVEL_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +CMI_LIB_DIR=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ -export PATH=$PATH:../../../src/components/cpp/bin -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR +export PATH=$PATH:$NINE_BIN_DIR:$SD_BIN_DIR:$COMP_BIN_DIR +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyvalue_parser:$ZMQ_LIB_DIR:$PROTOBUF_LIB_DIR:$CME_LIB_DIR:$CMI_LIB_DIR cleanup() # run if user hits control-c @@ -37,30 +42,30 @@ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../../src/api/cpp:../../../src/keyval # trap keyboard interrupt (control-c) trap cleanup SIGINT -./ProtobufDataProductPublisher & +ProtobufDataProductPublisher9 & PUBPID=$! -./ProtobufDataProductSubscriber & +ProtobufDataProductSubscriber9 & SUBPID=$! -sleep 10 +sleep 20 ServiceDirectory & SDPID=$! -sleep 10 +sleep 30 kill $SDPID $PUBPID echo Killed ServiceDirectory and ProtobufDataProductPublisher sleep 10 echo Restarting ServiceDirectory and ProtobufDataProductPublisher -./ProtobufDataProductPublisher & +ProtobufDataProductPublisher & PUBPID=$! ServiceDirectory & SDPID=$! -sleep 30 +sleep 10 cleanup diff --git a/test/examples/CMakeLists.txt b/test/examples/CMakeLists.txt index 6ae5dacff..389d0bf14 100644 --- a/test/examples/CMakeLists.txt +++ b/test/examples/CMakeLists.txt @@ -1,16 +1,26 @@ cmake_minimum_required(VERSION 3.17) project(GravityExamples) - +#Examples 2,9 and 13 all use source files with the same name, so only one can be built at a time add_subdirectory("1-BasicDataProduct") add_subdirectory("2-ProtobufDataProduct") -#add_subdirectory("8-ConfigFile") +add_subdirectory("3-MultipleDataProduct") +add_subdirectory("4-BasicService") +add_subdirectory("5-MiscFunctionality") +add_subdirectory("8-ConfigFile") +add_subdirectory("9-Domains") +add_subdirectory("10-Archiving") +add_subdirectory("13-Relay") if (NOT SKIP_JAVA) add_subdirectory("6-JavaProtobufDataProduct") + add_subdirectory("7-JavaBasicService") + + endif() if (NOT SKIP_PYTHON) add_subdirectory("11-PythonPubSub") add_subdirectory("12-PythonBasicService") + add_subdirectory("14-AnomalyDetection") endif()