From 7b78f8874ffe96330506b13c4a54fbdb405b3d70 Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski <17914061+ThePrez@users.noreply.github.com> Date: Sat, 30 Dec 2023 18:04:19 -0600 Subject: [PATCH 1/9] add `dir` destination --- .../manzan/configuration/DestinationConfig.java | 5 +++++ .../manzan/routes/dest/DirDestination.java | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 camel/src/main/java/com/github/theprez/manzan/routes/dest/DirDestination.java diff --git a/camel/src/main/java/com/github/theprez/manzan/configuration/DestinationConfig.java b/camel/src/main/java/com/github/theprez/manzan/configuration/DestinationConfig.java index 4155849..d17a09c 100644 --- a/camel/src/main/java/com/github/theprez/manzan/configuration/DestinationConfig.java +++ b/camel/src/main/java/com/github/theprez/manzan/configuration/DestinationConfig.java @@ -14,6 +14,7 @@ import com.github.theprez.jcmdutils.StringUtils; import com.github.theprez.manzan.routes.ManzanRoute; +import com.github.theprez.manzan.routes.dest.DirDestination; import com.github.theprez.manzan.routes.dest.EmailDestination; import com.github.theprez.manzan.routes.dest.FileDestination; import com.github.theprez.manzan.routes.dest.FluentDDestination; @@ -69,6 +70,10 @@ public synchronized Map getRoutes(CamelContext context) { final String file = getRequiredString(name, "file"); ret.put(name, new FileDestination(name, file, format, getUriAndHeaderParameters(name, sectionObj, "file"))); break; + case "dir": + final String dir = getRequiredString(name, "dir"); + ret.put(name, new DirDestination(name, dir, format, getUriAndHeaderParameters(name, sectionObj, "dir"))); + break; case "sentry": final String dsn = getRequiredString(name, "dsn"); ret.put(name, new SentryDestination(name, dsn)); diff --git a/camel/src/main/java/com/github/theprez/manzan/routes/dest/DirDestination.java b/camel/src/main/java/com/github/theprez/manzan/routes/dest/DirDestination.java new file mode 100644 index 0000000..bb542e2 --- /dev/null +++ b/camel/src/main/java/com/github/theprez/manzan/routes/dest/DirDestination.java @@ -0,0 +1,17 @@ +package com.github.theprez.manzan.routes.dest; + +import java.util.Map; + +import org.apache.camel.Exchange; + +import com.github.theprez.manzan.routes.ManzanGenericCamelRoute; + +public class DirDestination extends ManzanGenericCamelRoute { + public DirDestination(final String _name, final String _file, final String _format, final Map _uriParams) { + super(_name, "file", _file, _format, _uriParams, null); + } + + @Override + protected void customPostProcess(Exchange exchange) { + } +} From 310205a87c2c286a06322730eac0dee4e03564f4 Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski <17914061+ThePrez@users.noreply.github.com> Date: Sat, 30 Dec 2023 18:04:42 -0600 Subject: [PATCH 2/9] Fix `file` destination to use Camel Stream endpoint --- .../manzan/routes/dest/FileDestination.java | 9 +++++++- test/{ => msg/snd2q}/sndmsg.java | 21 +++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) rename test/{ => msg/snd2q}/sndmsg.java (58%) diff --git a/camel/src/main/java/com/github/theprez/manzan/routes/dest/FileDestination.java b/camel/src/main/java/com/github/theprez/manzan/routes/dest/FileDestination.java index e64548f..0a5da16 100644 --- a/camel/src/main/java/com/github/theprez/manzan/routes/dest/FileDestination.java +++ b/camel/src/main/java/com/github/theprez/manzan/routes/dest/FileDestination.java @@ -1,5 +1,6 @@ package com.github.theprez.manzan.routes.dest; +import java.util.LinkedHashMap; import java.util.Map; import org.apache.camel.Exchange; @@ -8,7 +9,13 @@ public class FileDestination extends ManzanGenericCamelRoute { public FileDestination(final String _name, final String _file, final String _format, final Map _uriParams) { - super(_name, "file", _file, _format, _uriParams, null); + super(_name, "stream", "file", _format, addToMap(_uriParams, "fileName", _file), null); + } + + private static Map addToMap(Map _uriParams, String _key, String _val) { + Map ret = null == _uriParams ? new LinkedHashMap(): _uriParams; + ret.put(_key, _val); + return ret; } @Override diff --git a/test/sndmsg.java b/test/msg/snd2q/sndmsg.java similarity index 58% rename from test/sndmsg.java rename to test/msg/snd2q/sndmsg.java index 807df09..f44810e 100644 --- a/test/sndmsg.java +++ b/test/msg/snd2q/sndmsg.java @@ -1,10 +1,13 @@ -import com.ibm.as400.access.*; -public class sndmsg -{ - - public static void main(String[] args) throws Exception{ - AS400 as400 = new AS400("localhost", "*CURRENT", "*CURRENT"); - MessageQueue mq = new MessageQueue(as400, "/qsys.lib/jesseg.lib/manzanq.msgq"); - mq.sendInformational("CAE0023", "/qsys.lib/qcpfmsg.msgf", "TABLE1".getBytes("Cp037")); - } +import com.ibm.as400.access.*; +public class sndmsg +{ + + public static void main(String[] args) throws Exception{ + String lib = args[0]; + String q = args[1]; + AS400 as400 = new AS400("localhost", "*CURRENT", "*CURRENT"); + MessageQueue mq = new MessageQueue(as400, "/qsys.lib/"+lib+".lib/"+q+".msgq"); + mq.sendInformational("CAE0023", "/qsys.lib/qcpfmsg.msgf", "TABLE1".getBytes("Cp037")); + System.out.println("msg sent to MSGQ"); + } } \ No newline at end of file From f1cb4e6b94fbfda03d932679a9cb80aa95faa3af Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski <17914061+ThePrez@users.noreply.github.com> Date: Sat, 30 Dec 2023 18:05:18 -0600 Subject: [PATCH 3/9] Fix timing bug in main handling loop --- .../com/github/theprez/manzan/routes/event/WatchMsgEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/camel/src/main/java/com/github/theprez/manzan/routes/event/WatchMsgEvent.java b/camel/src/main/java/com/github/theprez/manzan/routes/event/WatchMsgEvent.java index 2b1d1b0..699e891 100644 --- a/camel/src/main/java/com/github/theprez/manzan/routes/event/WatchMsgEvent.java +++ b/camel/src/main/java/com/github/theprez/manzan/routes/event/WatchMsgEvent.java @@ -29,7 +29,7 @@ public WatchMsgEvent(final String _name, final String _session_id, final String //@formatter:off @Override public void configure() { - from("timer://foo?synchronous=false&period=" + m_interval) + from("timer://foo?synchronous=true&period=" + m_interval) .routeId("manzan_msg:"+m_name) .setHeader(EVENT_TYPE, constant(ManzanEventType.WATCH_MSG)) .setBody(constant("SeLeCt * fRoM " + m_schema + ".mAnZaNmSg wHeRe SESSION_ID = '"+m_sessionId+"' limit " + m_numToProcess )) From 989f3125eaa291b7f3131014cfb5e48295dfce7b Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski <17914061+ThePrez@users.noreply.github.com> Date: Sat, 30 Dec 2023 18:09:59 -0600 Subject: [PATCH 4/9] fix: stop encoding URI params --- .../manzan/routes/ManzanGenericCamelRoute.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/camel/src/main/java/com/github/theprez/manzan/routes/ManzanGenericCamelRoute.java b/camel/src/main/java/com/github/theprez/manzan/routes/ManzanGenericCamelRoute.java index 0bd6b68..2d21bb3 100644 --- a/camel/src/main/java/com/github/theprez/manzan/routes/ManzanGenericCamelRoute.java +++ b/camel/src/main/java/com/github/theprez/manzan/routes/ManzanGenericCamelRoute.java @@ -45,6 +45,7 @@ public void configure() { } }) .setBody(simple("${body}\n")) + .wireTap("stream:out") .process(exchange -> {customPostProcess(exchange);}) .to(getTargetUri()); } @@ -61,14 +62,17 @@ private String getTargetUri() { for (final Entry entry : m_uriParams.entrySet()) { ret += entry.getKey(); ret += "="; - try { - ret += URLEncoder.encode(entry.getValue(), "UTF-8"); - } catch (final UnsupportedEncodingException e) { - ret += URLEncoder.encode(entry.getValue()); - } + ret += entry.getValue(); + //TODO: what's right here? with "file://" targets Camel wants real paths + // try { + // ret += URLEncoder.encode(entry.getValue(), "UTF-8"); + // } catch (final UnsupportedEncodingException e) { + // ret += URLEncoder.encode(entry.getValue()); + // } ret += "&"; } ret = ret.replaceFirst("&$", ""); + System.out.println("target URI: "+ret); return ret; } } From 27aa6f38708476f4338b6904cd907b67ed3bb814 Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski <17914061+ThePrez@users.noreply.github.com> Date: Sat, 30 Dec 2023 18:10:55 -0600 Subject: [PATCH 5/9] bugfix: fix JSON publishing crashes --- ile/src/pub_json.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ile/src/pub_json.cpp b/ile/src/pub_json.cpp index d977c42..4608453 100644 --- a/ile/src/pub_json.cpp +++ b/ile/src/pub_json.cpp @@ -9,6 +9,7 @@ #include #include #include +#include int to_utf8(char *out, size_t out_len, const char *in) { @@ -99,17 +100,24 @@ int json_publish(const char *_session_id, std::string &_json) DEBUG("Publishing JSON\n"); DEBUG("%s\n", _json.c_str()); - char dtaq_key[11]; + __attribute__((aligned(16))) char dtaq_key[11]; memset(dtaq_key, ' ', 11); memcpy(dtaq_key, _session_id, MIN(11, strlen(_session_id))); + _DecimalT<5,0> len2 = __D("0"); + len2 += strlen(utf8); + _DecimalT<3,0> keyLen = __D("10.0"); + + DEBUG("About to call QSNDDTAQ\n"); QSNDDTAQ("MANZANDTAQ", - "*CURLIB ", // TODO: How to properly resolve the library here? - strlen(utf8), + "MANZAN ", // TODO: How to properly resolve the library here? + len2, utf8, - (_Decimal(3,0))10, - dtaq_key); + keyLen, + &dtaq_key); + DEBUG("About to free up stuff\n"); free(utf8); + DEBUG("Done publishing JSON\n"); return 0; } From e6761a5d04898dff1137de6999a43fe9156871d3 Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski <17914061+ThePrez@users.noreply.github.com> Date: Sat, 30 Dec 2023 18:11:16 -0600 Subject: [PATCH 6/9] bugfix: `config` makefile target --- config/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/Makefile b/config/Makefile index c93d9ca..fea954c 100755 --- a/config/Makefile +++ b/config/Makefile @@ -10,7 +10,7 @@ app.ini: app.ini.tpl cat $< | /QOpenSys/usr/bin/sed 's|library=.*|library=${BUILDLIB}|g' > $@ -copyfiles: app.ini data.ini dests.ini +copyfiles: app.ini $(CURDIR)/data.ini dests.ini install -m 555 -o qsys $^ ${INSTALL_ROOT}/QOpenSys/etc/manzan install: mkdirs copyfiles From 4c0f818fc59de9ae4bd4a72c6c910019b7b551cd Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski <17914061+ThePrez@users.noreply.github.com> Date: Sat, 30 Dec 2023 18:11:47 -0600 Subject: [PATCH 7/9] Reworked test function --- Makefile | 5 +++- test/Makefile | 30 +++++++++++++-------- test/msg/snd2q/Makefile | 29 ++++++++++++++++++++ test/msg/snd2q/data.ini | 5 ++++ test/msg/snd2q/dests.ini | 6 +++++ test/runTests.sh | 57 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 120 insertions(+), 12 deletions(-) create mode 100644 test/msg/snd2q/Makefile create mode 100644 test/msg/snd2q/data.ini create mode 100644 test/msg/snd2q/dests.ini create mode 100644 test/runTests.sh diff --git a/Makefile b/Makefile index 7602b50..954b903 100755 --- a/Makefile +++ b/Makefile @@ -10,9 +10,12 @@ ile: camel: gmake -C camel -test: +test: install gmake -C test +testonly: + gmake -C test runtests + all: ile camel install: diff --git a/test/Makefile b/test/Makefile index f91dc11..7e93cc6 100755 --- a/test/Makefile +++ b/test/Makefile @@ -4,22 +4,30 @@ ile: gmake -C ../ile -testing: /qsys.lib/${BUILDLIB}.lib/MANZANQ.msgq watch_start watch_testq watch_end -sndmsg.class: sndmsg.java - javac -cp /QIBM/ProdData/OS400/jt400/lib/jt400.jar sndmsg.java +TESTS:=$(shell find * -type d) +TESTLIB:=MZNTEST + +# run before every test case +pretest: + echo "Doing pre-test setup" + system "crtlib ${TESTLIB}" || system "clrlib ${TESTLIB}" + +# Run after every test case +posttest: + echo "Doing post-test cleanup" + system -kKv "ENDWCH SSNID(TESTING)" || echo "watch not ended" + system "clrlib ${TESTLIB}" -watch_testq: ./tester/sndmsg.class - java -cp ./tester:/QIBM/ProdData/OS400/jt400/lib/jt400.jar sndmsg +runtests: + echo "Running tests" + exec runTests.sh + +testing: /qsys.lib/${BUILDLIB}.lib/MANZANQ.msgq watch_start watch_testq watch_end -watch_start: - # Listens to chosen message queue for all messages - # then calls the handler program - # Check /tmp/manzan_debug.txt for logs - system -kKv "STRWCH SSNID(TESTING) WCHPGM(${BUILDLIB}/HANDLER) CALLWCHPGM(*STRWCH) WCHMSG((*ALL)) WCHMSGQ((${BUILDLIB}/MANZANQ))" watch_end: system -kKv "ENDWCH SSNID(TESTING)" # select rtrim(HANDLED_TIMESTAMP) as TS, rtrim(SESSION_ID) as SESSION, rtrim(MESSAGE_ID) as MSG_ID from ${BUILDLIB}.manzanmsg where SESSION_ID = 'TESTING ' -all: ile testing +all: ile runtests diff --git a/test/msg/snd2q/Makefile b/test/msg/snd2q/Makefile new file mode 100644 index 0000000..9f65da2 --- /dev/null +++ b/test/msg/snd2q/Makefile @@ -0,0 +1,29 @@ +TESTLIB:=MZNTEST + +/qsys.lib/${TESTLIB}.lib/msgs.msgq: + system "CRTMSGQ ${TESTLIB}/MSGS" + + +sndmsg.class: sndmsg.java + /QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit/bin/javac -cp /QIBM/ProdData/OS400/jt400/lib/jt400.jar sndmsg.java + +setup: /qsys.lib/${TESTLIB}.lib/msgs.msgq sndmsg.class + rm -f $(CURDIR)/test.out + touch $(CURDIR)/test.out + echo "strwch=WCHMSG((*ALL)) WCHMSGQ((${TESTLIB}/MSGS))" >> data.ini + echo "file=$(CURDIR)/test.out" >> dests.ini + # echo "[install]" > app.ini + # echo "library=${TESTLIB}" >> app.ini + +cleanup: + rm sndmsg.class + rm -f $(CURDIR)/test.out + +run: + /opt/manzan/bin/manzan --configdir=$(CURDIR) & + sleep 12 + /QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit/bin/java -cp $(CURDIR):/QIBM/ProdData/OS400/jt400/lib/jt400.jar sndmsg ${TESTLIB} msgs + sleep 5 + +checkresult: + grep -i CAE0023 $(CURDIR)/test.out diff --git a/test/msg/snd2q/data.ini b/test/msg/snd2q/data.ini new file mode 100644 index 0000000..6bef716 --- /dev/null +++ b/test/msg/snd2q/data.ini @@ -0,0 +1,5 @@ +[watchout] +type=watch +id=TESTING +destinations=stdout,myfile +format=$MESSAGE_ID$ (severity $SEVERITY$): $MESSAGE$ \ No newline at end of file diff --git a/test/msg/snd2q/dests.ini b/test/msg/snd2q/dests.ini new file mode 100644 index 0000000..bd36ca3 --- /dev/null +++ b/test/msg/snd2q/dests.ini @@ -0,0 +1,6 @@ + +[stdout] +type=stdout + +[myfile] +type=file diff --git a/test/runTests.sh b/test/runTests.sh new file mode 100644 index 0000000..e3180fb --- /dev/null +++ b/test/runTests.sh @@ -0,0 +1,57 @@ +#!/QOpenSys/pkgs/bin/bash + +TESTS=$(/QOpenSys/pkgs/bin/find * -mindepth 1 -type d) + +num_fail=0 +num_pass=0 +num_error=0 + +for test in $TESTS +do + echo "Running test $test..." + gmake pretest + echo "Performing test-specific setup for test $test..." + gmake -C $test setup || exit 1 + echo "Running test $test..." + gmake -C $test run + if [[ "0" != "$?" ]] + then + ((num_error+=1)) + fi + + echo "Done running test $test. Exit code was $?" + + echo "Killing jobs..." + for pid in $(ps | grep jre| awk '{print $1}') + do + echo killing pid $pid + kill -INT $pid + sleep 1 + kill -KILL $pid + done + echo "checking result...." + echo "==================================" + gmake -C $test checkresult + echo "result is $?" + if [[ "0" == "$?" ]] + then + ((num_pass+=1)) + else + ((num_fail+=1)) + fi + echo "==================================" + echo "output" + echo "==================================" + cat $test/test.out + echo "==================================" + + echo "Performing test-specific cleanup for test $test..." + gmake -C $test cleanup || echo "no setup needed" + echo "Performing cleanup..." + gmake posttest + echo "==================================" + echo "Results:" + echo " $num_pass passed" + echo " $num_fail failed" + echo " $num_error errored" +done From 38316e13cbc0b94d7fb8c0e88ab113d011d9109f Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski <17914061+ThePrez@users.noreply.github.com> Date: Sat, 30 Dec 2023 18:12:01 -0600 Subject: [PATCH 8/9] bugfix: build failures --- camel/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/camel/Makefile b/camel/Makefile index 20f296d..5b3d1e1 100755 --- a/camel/Makefile +++ b/camel/Makefile @@ -6,7 +6,7 @@ BUILDVERSION:="Development build \(built with Make\)" JAVA_SRCS := $(shell find src -type f) target/manzan.jar: ${JAVA_SRCS} /QOpenSys/pkgs/bin/mvn - JAVA_HOME=/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit /QOpenSys/pkgs/bin/mvn -Djava.net.preferIPv4Stack=true "-Dmanzan.version=${BUILDVERSION}" package + JAVA_HOME=/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit /QOpenSys/pkgs/bin/mvn -Djava.net.preferIPv4Stack=true -Dmanzan.version=${BUILDVERSION} package cp target/manzan-*-with-dependencies.jar target/manzan.jar mkdirs: From bb5f92782f53325c7b5c7369082909b11e8d5b75 Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski <17914061+ThePrez@users.noreply.github.com> Date: Sat, 30 Dec 2023 18:12:40 -0600 Subject: [PATCH 9/9] Add STRWCH command to output --- .../src/main/java/com/github/theprez/manzan/WatchStarter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/camel/src/main/java/com/github/theprez/manzan/WatchStarter.java b/camel/src/main/java/com/github/theprez/manzan/WatchStarter.java index 42f8bed..8a95a17 100644 --- a/camel/src/main/java/com/github/theprez/manzan/WatchStarter.java +++ b/camel/src/main/java/com/github/theprez/manzan/WatchStarter.java @@ -70,7 +70,7 @@ public void strwch() public boolean isRunning() throws AS400SecurityException, ErrorCompletingRequestException, IOException, InterruptedException, PropertyVetoException, ObjectDoesNotExistException { - AS400 as400 = IBMiDotEnv.getNewSystemConnection(true); + AS400 as400 = new AS400("localhost","*CURRENT","*CURRENT");//IBMiDotEnv.getNewSystemConnection(true); ProgramCall pc = new ProgramCall(as400); final ProgramCall program = new ProgramCall(as400); @@ -106,7 +106,7 @@ public boolean isRunning() private static void runCmd(final String _command) throws AS400SecurityException, ErrorCompletingRequestException, IOException, InterruptedException { - AS400 as400 = IBMiDotEnv.getNewSystemConnection(true); + AS400 as400 = new AS400("localhost","*CURRENT","*CURRENT");// IBMiDotEnv.getNewSystemConnection(true); CommandCall cmd = new CommandCall(as400, _command); boolean isSuccess = cmd.run();