Skip to content

Commit 8445424

Browse files
committed
updating debug logging
fixing tests for returning {} for [] in headers
1 parent e15a6fb commit 8445424

File tree

16 files changed

+264
-202
lines changed

16 files changed

+264
-202
lines changed

marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/debug-lib.xqy

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ declare option xdmp:mapping "false";
2121

2222
declare function debug:enable($enable as xs:boolean)
2323
{
24-
xdmp:set-server-field("HUB_DEBUG", $enable)
24+
xdmp:set-server-field("HUB_DEBUG", $enable),
25+
xdmp:set-server-field("MarkLogic.DEBUG", $enable)
2526
};
2627

2728
(:~
@@ -51,6 +52,11 @@ declare function debug:log($items)
5152
: Dumps the request environment. Useful for debugging
5253
:)
5354
declare function debug:dump-env()
55+
{
56+
debug:dump-env(())
57+
};
58+
59+
declare function debug:dump-env($name as xs:string?)
5460
{
5561
let $request-path := xdmp:get-request-path()
5662
let $request-path :=
@@ -67,7 +73,16 @@ declare function debug:dump-env()
6773
return
6874
debug:log((
6975
"",
76+
"",
77+
"################################################################",
7078
"REQUEST DETAILS:",
79+
"",
80+
if ($name) then
81+
(
82+
" **" || $name || "**",
83+
""
84+
)
85+
else (),
7186
" [" || xdmp:get-request-method() || "] " || $request-path,
7287
"",
7388
" [Headers]",
@@ -85,10 +100,25 @@ declare function debug:dump-env()
85100
(
86101
"",
87102
" [Body]",
88-
$body
103+
" " || xdmp:describe($body, (), ())
89104
)
90105
else (),
91106
"",
107+
"################################################################",
108+
"",
109+
"",
92110
""
93111
))
94112
};
113+
114+
declare function debug:dump-map($m as map:map)
115+
{
116+
debug:dump-map($m, ())
117+
};
118+
119+
declare function debug:dump-map($m as map:map, $prefix)
120+
{
121+
for $key in map:keys($m)
122+
return
123+
$prefix || $key || " => " || map:get($m, $key)
124+
};

marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/flow-lib.xqy

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import module namespace debug = "http://marklogic.com/data-hub/debug-lib"
2626
import module namespace hul = "http://marklogic.com/data-hub/hub-utils-lib"
2727
at "/com.marklogic.hub/lib/hub-utils-lib.xqy";
2828

29+
import module namespace json="http://marklogic.com/xdmp/json"
30+
at "/MarkLogic/json/json.xqy";
31+
2932
import module namespace functx = "http://www.functx.com"
3033
at "/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy";
3134

@@ -195,15 +198,6 @@ declare %private function flow:get-writer(
195198
for $uri in $uris
196199
let $filename as xs:string := hul:get-file-from-uri($uri)
197200
let $type := flow:get-type($filename)
198-
let $_ :=
199-
if (debug:on()) then
200-
debug:log((
201-
"$flow-name: " || $flow-name,
202-
"$uri: " || $uri,
203-
"$filename: " || $filename,
204-
"$type: " || $type
205-
))
206-
else ()
207201
return
208202
element hub:writer {
209203
attribute type { $type },
@@ -253,10 +247,6 @@ declare %private function flow:get-flow(
253247
$flow-type as xs:string?,
254248
$uris as xs:string*) as element(hub:flow)
255249
{
256-
let $_ :=
257-
if (debug:on()) then
258-
debug:log(("entity: " || $entity-name, "flow: " || $flow-name, "flow-type: " || $flow-type, "uris:", $uris))
259-
else ()
260250
let $real-flow-type := fn:replace($uris[1], $ENTITIES-DIR || $entity-name || "/([^/]+)/" || $flow-name || ".*$", "$1")
261251
let $map := map:map()
262252
let $_ :=
@@ -482,7 +472,6 @@ declare function flow:run-plugins(
482472
else ()
483473
))
484474
let $data-format := $flow/hub:data-format
485-
let $_ := xdmp:log($flow)
486475
let $flow-type := $flow/hub:type
487476
let $flow-complexity := $flow/hub:complexity
488477
let $_ :=
@@ -681,6 +670,16 @@ declare function flow:run-plugin(
681670
fn:error("Too Many Nodes!. Return just 1 node")
682671
else
683672
$resp/node()
673+
default return
674+
$resp
675+
676+
let $resp :=
677+
typeswitch($resp)
678+
case object-node() | json:object return
679+
if ($data-format = 'application/xml') then
680+
json:transform-from-json($resp, json:config("custom"))
681+
else
682+
$resp
684683
case json:array return
685684
if ($data-format = 'application/xml') then
686685
json:array-values($resp)

marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/mlcp-flow-transform.xqy

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ xquery version "1.0-ml";
22

33
module namespace mlcpFlow = "http://marklogic.com/data-hub/mlcp-flow-transform";
44

5+
import module namespace debug = "http://marklogic.com/data-hub/debug-lib"
6+
at "/com.marklogic.hub/lib/debug-lib.xqy";
7+
58
import module namespace flow = "http://marklogic.com/data-hub/flow-lib"
69
at "/com.marklogic.hub/lib/flow-lib.xqy";
710

@@ -10,11 +13,32 @@ import module namespace trace = "http://marklogic.com/data-hub/trace"
1013

1114
declare namespace hub = "http://marklogic.com/data-hub";
1215

16+
declare option xdmp:mapping "false";
17+
1318
declare function mlcpFlow:transform(
1419
$content as map:map,
1520
$context as map:map
1621
) as map:map*
1722
{
23+
if (debug:on()) then
24+
debug:log((
25+
"",
26+
"",
27+
"################################################################",
28+
" MLCP INPUT TRANSFORM",
29+
"",
30+
"",
31+
"$content:",
32+
debug:dump-map($content, " "),
33+
"",
34+
"$context: ",
35+
debug:dump-map($context, " "),
36+
"",
37+
"################################################################",
38+
"",
39+
""
40+
))
41+
else (),
1842
let $uri := map:get($content, "uri")
1943

2044
let $paramNodes := xdmp:unquote(map:get($context, 'transform_param'))/node()/*
@@ -26,7 +50,13 @@ declare function mlcpFlow:transform(
2650
map:get($paramMap, 'flow-name'),
2751
map:get($paramMap, 'flow-type'))
2852

29-
let $envelope := flow:run-plugins($flow, $uri, map:get($content, "value"), $paramMap)
53+
let $envelope := try {
54+
flow:run-plugins($flow, $uri, map:get($content, "value"), $paramMap)
55+
}
56+
catch($ex) {
57+
xdmp:log($ex),
58+
xdmp:rethrow()
59+
}
3060
let $_ := map:put($content, "value", $envelope)
3161
let $_ :=
3262
if (trace:enabled()) then

marklogic-data-hub/src/main/resources/ml-modules/services/entity.xqy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ declare function get(
4141
$params as map:map
4242
) as document-node()*
4343
{
44-
debug:dump-env(),
44+
debug:dump-env("GET ENTITY(s)"),
4545

4646
document {
4747
let $entity-name := map:get($params, "entity-name")
@@ -50,7 +50,6 @@ declare function get(
5050
flow:get-entity($entity-name)
5151
else
5252
flow:get-entities()
53-
let $_ := debug:log($resp)
5453
return
5554
$resp
5655
}

marklogic-data-hub/src/main/resources/ml-modules/services/flow.xqy

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ declare function get(
4141
$params as map:map
4242
) as document-node()*
4343
{
44-
debug:dump-env(),
44+
debug:dump-env("GET FLOW"),
4545

4646
document {
4747
let $entity-name := map:get($params, "entity-name")
@@ -52,7 +52,6 @@ declare function get(
5252
flow:get-flow($entity-name, $flow-name, $flow-type)
5353
else
5454
flow:get-flows($entity-name)
55-
let $_ := debug:log($resp)
5655
return
5756
$resp
5857
}
@@ -69,7 +68,7 @@ declare %rapi:transaction-mode("update") function post(
6968
$input as document-node()*
7069
) as document-node()*
7170
{
72-
debug:dump-env(),
71+
debug:dump-env("RUN FLOW"),
7372

7473
let $flow as element(hub:flow) := $input/hub:flow
7574
let $identifier := map:get($params, "identifier")

marklogic-data-hub/src/test/java/com/marklogic/hub/EndToEndTestSjsXml.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static void setup() throws IOException {
3535
installHub();
3636

3737
enableDebugging();
38+
enableTracing();
3839

3940
Scaffolding.createEntity(ENTITY, pluginsDir);
4041
Scaffolding.createFlow(ENTITY, "testinput", FlowType.INPUT,

marklogic-data-hub/src/test/java/com/marklogic/hub/HubTestBase.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ private static void init() {
115115
}
116116

117117
host = properties.getProperty("mlHost");
118-
stagingPort = Integer.parseInt(properties.getProperty("mlStagingRestPort"));
119-
finalPort = Integer.parseInt(properties.getProperty("mlFinalRestPort"));
120-
tracePort = Integer.parseInt(properties.getProperty("mlTraceRestPort"));
118+
stagingPort = Integer.parseInt(properties.getProperty("mlStagingPort"));
119+
finalPort = Integer.parseInt(properties.getProperty("mlFinalPort"));
120+
tracePort = Integer.parseInt(properties.getProperty("mlTracePort"));
121121
user = properties.getProperty("mlUsername");
122122
password = properties.getProperty("mlPassword");
123123
authMethod = Authentication.valueOf(properties.getProperty("auth").toUpperCase());
@@ -136,7 +136,11 @@ public HubTestBase() {
136136
}
137137

138138
protected static void enableDebugging() {
139-
stagingDocMgr.write("/debug", new StringHandle("<debug>true</debug>"));
139+
new Debugging(stagingClient).enable();
140+
}
141+
142+
protected static void enableTracing() {
143+
new Tracing(stagingClient).enable();
140144
}
141145

142146
protected static HubConfig getHubConfig() {

quick-start/src/main/java/com/marklogic/hub/config/EnvironmentConfiguration.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public class EnvironmentConfiguration {
3737
private static final String ML_HOST = "mlHost";
3838
private static final String ML_USERNAME = "mlUsername";
3939
private static final String ML_PASSWORD = "mlPassword";
40-
private static final String ML_STAGING_REST_PORT = "mlStagingRestPort";
41-
private static final String ML_FINAL_REST_PORT = "mlFinalRestPort";
42-
private static final String ML_TRACE_REST_PORT = "mlTraceRestPort";
40+
private static final String ML_STAGING_REST_PORT = "mlStagingPort";
41+
private static final String ML_FINAL_REST_PORT = "mlFinalPort";
42+
private static final String ML_TRACE_REST_PORT = "mlTracePort";
4343
private static final String ML_AUTH = "mlAuth";
4444
private static final String USER_PLUGIN_DIR = "userPluginDir";
4545
private static final String ASSET_INSTALL_TIME_FILE = "assetInstallTimeFile";
@@ -93,7 +93,7 @@ public String getMLPassword() {
9393
return this.environment.getProperty(ML_PASSWORD + DEFAULT_SUFFIX);
9494
}
9595

96-
public String getMLStagingRestPort() {
96+
public String getMLStagingPort() {
9797
String value = this.environmentProperties.getProperty(ML_STAGING_REST_PORT);
9898
if (value != null) {
9999
return value;
@@ -106,7 +106,7 @@ public String getMLStagingRestPort() {
106106
return this.environment.getProperty(ML_STAGING_REST_PORT + DEFAULT_SUFFIX);
107107
}
108108

109-
public String getMLFinalRestPort() {
109+
public String getMLFinalPort() {
110110
String value = this.environmentProperties.getProperty(ML_FINAL_REST_PORT);
111111
if (value != null) {
112112
return value;
@@ -119,7 +119,7 @@ public String getMLFinalRestPort() {
119119
return this.environment.getProperty(ML_FINAL_REST_PORT + DEFAULT_SUFFIX);
120120
}
121121

122-
public String getMLTraceRestPort() {
122+
public String getMLTracePort() {
123123
String value = this.environmentProperties.getProperty(ML_TRACE_REST_PORT);
124124
if (value != null) {
125125
return value;
@@ -175,16 +175,16 @@ public void setMLHost(String mlHost) {
175175
this.environmentProperties.setProperty(ML_HOST, mlHost);
176176
}
177177

178-
public void setMLStagingRestPort(String mlStagingRestPort) {
179-
this.environmentProperties.setProperty(ML_STAGING_REST_PORT, mlStagingRestPort);
178+
public void setMLStagingPort(String mlStagingPort) {
179+
this.environmentProperties.setProperty(ML_STAGING_REST_PORT, mlStagingPort);
180180
}
181181

182-
public void setMLFinalRestPort(String mlFinalRestPort) {
183-
this.environmentProperties.setProperty(ML_FINAL_REST_PORT, mlFinalRestPort);
182+
public void setMLFinalPort(String mlFinalPort) {
183+
this.environmentProperties.setProperty(ML_FINAL_REST_PORT, mlFinalPort);
184184
}
185185

186-
public void setMlTraceRestPort(String mlTraceRestPort) {
187-
this.environmentProperties.setProperty(ML_TRACE_REST_PORT, mlTraceRestPort);
186+
public void setMlTracePort(String mlTracePort) {
187+
this.environmentProperties.setProperty(ML_TRACE_REST_PORT, mlTracePort);
188188
}
189189

190190
public void setMLUsername(String mlUsername) {
@@ -257,9 +257,9 @@ public String getFlowInputPath(String entityName, String flowName) {
257257
public HubConfig getHubConfig() {
258258
HubConfig hubConfig = new HubConfig();
259259
hubConfig.host = getMLHost();
260-
hubConfig.stagingPort = Integer.parseInt(getMLStagingRestPort());
261-
hubConfig.finalPort = Integer.parseInt(getMLFinalRestPort());
262-
hubConfig.tracePort = Integer.parseInt(getMLTraceRestPort());
260+
hubConfig.stagingPort = Integer.parseInt(getMLStagingPort());
261+
hubConfig.finalPort = Integer.parseInt(getMLFinalPort());
262+
hubConfig.tracePort = Integer.parseInt(getMLTracePort());
263263
hubConfig.adminUsername = getMLUsername();
264264
hubConfig.adminPassword = getMLPassword();
265265
return hubConfig;

quick-start/src/main/java/com/marklogic/hub/service/DataHubService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private DataHub getDataHub() throws DataHubException {
4949
LOGGER.info("Connecting to DataHub at host is {}:{} with user={}",
5050
new Object[] {
5151
environmentConfiguration.getMLHost()
52-
,environmentConfiguration.getMLStagingRestPort()
52+
,environmentConfiguration.getMLStagingPort()
5353
,environmentConfiguration.getMLUsername()
5454
});
5555
DataHub dataHub = new DataHub(environmentConfiguration.getHubConfig());

quick-start/src/main/java/com/marklogic/hub/service/EntityManagerService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public EntityManager getEntityManager() {
4343
.valueOf(environmentConfiguration.getMLAuth().toUpperCase());
4444
DatabaseClient client = DatabaseClientFactory.newClient(
4545
environmentConfiguration.getMLHost(),
46-
Integer.parseInt(environmentConfiguration.getMLStagingRestPort()),
46+
Integer.parseInt(environmentConfiguration.getMLStagingPort()),
4747
environmentConfiguration.getMLUsername(),
4848
environmentConfiguration.getMLPassword(), authMethod);
4949
return new EntityManager(client);

0 commit comments

Comments
 (0)