Skip to content

Commit ecd91db

Browse files
committed
enable disable tracing
1 parent ca80475 commit ecd91db

File tree

13 files changed

+178
-47
lines changed

13 files changed

+178
-47
lines changed

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -221,26 +221,15 @@ declare function trace:trace-to-json($trace)
221221

222222
declare function trace:trace-to-json-slim($trace)
223223
{
224-
if ($trace instance of element()) then
225-
let $o := json:object()
226-
let $_ := (
227-
map:put($o, "traceId", $trace/trace-id/string()),
228-
map:put($o, "created", $trace/created/string()),
229-
map:put($o, "identifier", $trace/identifier/string()),
230-
map:put($o, "flowType", $trace/flow-type/string())
231-
)
232-
return
233-
$o
234-
else
235-
let $o := json:object()
236-
let $_ := (
237-
map:put($o, "traceId", $trace/traceId),
238-
map:put($o, "created", $trace/created),
239-
map:put($o, "identifier", $trace/identifier),
240-
map:put($o, "flowType", $trace/flowType)
241-
)
242-
return
243-
$o
224+
let $o := json:object()
225+
let $_ := (
226+
map:put($o, "traceId", $trace/trace-id/string()),
227+
map:put($o, "created", $trace/created/string()),
228+
map:put($o, "identifier", $trace/identifier/string()),
229+
map:put($o, "flowType", $trace/flow-type/string())
230+
)
231+
return
232+
$o
244233
};
245234

246235
declare function trace:find-traces(
@@ -254,13 +243,13 @@ declare function trace:find-traces(
254243
<return-facets>true</return-facets>
255244
</options>
256245
let $query := search:parse($q)
257-
let $count := xdmp:estimate(cts:search(/trace, cts:query($query)))
246+
let $count := xdmp:estimate(cts:search(fn:doc(), cts:query($query)))
258247
let $start := ($page - 1) * $page-length + 1
259248
let $end := fn:min(($start + $page-length - 1, $count))
260249
let $results :=
261250
for $result in search:resolve-nodes($query, $options, $start, $page-length)
262251
return
263-
trace:trace-to-json-slim($result/trace)
252+
trace:trace-to-json-slim($result/node())
264253
return
265254
object-node {
266255
"start": $start,

marklogic-data-hub/src/trace-ui/src/components/pagination/pagination.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="container">
1+
<div class="container" ng-if="ctrl.total > 0">
22
Showing Results {{ ctrl.start }} to {{ctrl.end}} of {{ctrl.total}}
33
<div class="pagination">
44
<a ng-click="ctrl.gotoPage(1)">&lt;&lt;</a>
@@ -10,3 +10,6 @@
1010
<a ng-click="ctrl.gotoPage(ctrl.totalPages)">&gt;&gt;</a>
1111
</div>
1212
</div>
13+
<div class="container" ng-if="ctrl.total <= 0">
14+
No Traces Found
15+
</div>

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import com.google.common.base.Charsets;
2222
import com.google.common.io.Files;
23+
import com.marklogic.client.DatabaseClient;
24+
import com.marklogic.client.DatabaseClientFactory;
25+
import com.marklogic.client.DatabaseClientFactory.Authentication;
2326
import com.marklogic.hub.HubConfig;
2427

2528
/***
@@ -262,4 +265,28 @@ public HubConfig getHubConfig() {
262265
return hubConfig;
263266
}
264267

268+
public DatabaseClient getStagingClient() {
269+
Authentication authMethod = Authentication
270+
.valueOf(getMLAuth().toUpperCase());
271+
272+
DatabaseClient client = DatabaseClientFactory.newClient(
273+
getMLHost(),
274+
Integer.parseInt(getMLStagingPort()),
275+
getMLUsername(),
276+
getMLPassword(), authMethod);
277+
return client;
278+
}
279+
280+
public DatabaseClient getFinalClient() {
281+
Authentication authMethod = Authentication
282+
.valueOf(getMLAuth().toUpperCase());
283+
284+
DatabaseClient client = DatabaseClientFactory.newClient(
285+
getMLHost(),
286+
Integer.parseInt(getMLFinalPort()),
287+
getMLUsername(),
288+
getMLPassword(), authMethod);
289+
return client;
290+
}
291+
265292
}

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
@@ -43,7 +43,7 @@ public JsonNode validateUserModules() {
4343
return dataHub.validateUserModules();
4444
}
4545

46-
private DataHub getDataHub() throws DataHubException {
46+
public DataHub getDataHub() throws DataHubException {
4747
try {
4848
LOGGER.info("Connecting to DataHub at host is {}:{} with user={}",
4949
new Object[] {

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
import com.fasterxml.jackson.databind.JsonNode;
1313
import com.fasterxml.jackson.databind.ObjectMapper;
14-
import com.marklogic.client.DatabaseClient;
15-
import com.marklogic.client.DatabaseClientFactory;
16-
import com.marklogic.client.DatabaseClientFactory.Authentication;
1714
import com.marklogic.client.io.Format;
1815
import com.marklogic.contentpump.bean.MlcpBean;
1916
import com.marklogic.hub.FlowManager;
@@ -29,19 +26,10 @@
2926
public class FlowManagerService {
3027

3128
@Autowired
32-
private EnvironmentConfiguration environmentConfiguration;
29+
private EnvironmentConfiguration environmentConfig;
3330

3431
public FlowManager getFlowManager() {
35-
36-
Authentication authMethod = Authentication
37-
.valueOf(environmentConfiguration.getMLAuth().toUpperCase());
38-
DatabaseClient client = DatabaseClientFactory.newClient(
39-
environmentConfiguration.getMLHost(),
40-
Integer.parseInt(environmentConfiguration.getMLStagingPort()),
41-
environmentConfiguration.getMLUsername(),
42-
environmentConfiguration.getMLPassword(), authMethod);
43-
return new FlowManager(client);
44-
32+
return new FlowManager(environmentConfig.getStagingClient());
4533
}
4634

4735
public List<Flow> getFlows(String entityName) {
@@ -87,7 +75,7 @@ public FlowModel createFlow(String entityName, String flowName,
8775
FlowType flowType, PluginFormat pluginFormat, Format dataFormat) {
8876
FlowModelFactory flowModelFactory = new FlowModelFactory(entityName);
8977

90-
File projectDir = new File(environmentConfiguration.getProjectDir());
78+
File projectDir = new File(environmentConfig.getProjectDir());
9179
FlowModel flowModel;
9280
try {
9381
flowModel = flowModelFactory.createNewFlow(projectDir, flowName,
@@ -100,12 +88,12 @@ public FlowModel createFlow(String entityName, String flowName,
10088

10189
public void loadData(JsonNode json) throws IOException {
10290
MlcpBean bean = new ObjectMapper().readerFor(MlcpBean.class).readValue(json);
103-
bean.setHost(environmentConfiguration.getMLHost());
104-
bean.setPort(Integer.parseInt(environmentConfiguration.getMLStagingPort()));
91+
bean.setHost(environmentConfig.getMLHost());
92+
bean.setPort(Integer.parseInt(environmentConfig.getMLStagingPort()));
10593

10694
// Assume that the HTTP credentials will work for mlcp
107-
bean.setUsername(environmentConfiguration.getMLUsername());
108-
bean.setPassword(environmentConfiguration.getMLPassword());
95+
bean.setUsername(environmentConfig.getMLUsername());
96+
bean.setPassword(environmentConfig.getMLPassword());
10997

11098
File file = new File(json.get("input_file_path").asText());
11199
String canonicalPath = file.getCanonicalPath();
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.marklogic.hub.web.controller.api;
2+
3+
import java.io.IOException;
4+
5+
import javax.servlet.http.HttpSession;
6+
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RequestMethod;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
import com.fasterxml.jackson.core.JsonProcessingException;
13+
import com.fasterxml.jackson.databind.JsonNode;
14+
import com.fasterxml.jackson.databind.ObjectMapper;
15+
import com.marklogic.hub.Tracing;
16+
import com.marklogic.hub.config.EnvironmentConfiguration;
17+
18+
@RestController
19+
@RequestMapping("/api/tracing")
20+
public class TracingController {
21+
22+
@Autowired
23+
private EnvironmentConfiguration environmentConfig;
24+
25+
private Tracing getTracing() {
26+
return new Tracing(environmentConfig.getStagingClient());
27+
}
28+
@RequestMapping(value="/enable", method = RequestMethod.POST)
29+
public void enableTracing(HttpSession session) {
30+
Tracing t = getTracing();
31+
t.enable();
32+
}
33+
34+
@RequestMapping(value="/disable", method = RequestMethod.POST)
35+
public void disableTracing(HttpSession session) {
36+
Tracing t = getTracing();
37+
t.disable();
38+
}
39+
40+
@RequestMapping(value="/is-enabled", method = RequestMethod.GET)
41+
public JsonNode isEnabled(HttpSession session) throws JsonProcessingException, IOException {
42+
Tracing t = getTracing();
43+
ObjectMapper om = new ObjectMapper();
44+
return om.readTree("{\"enabled\":" + t.isEnabled() + "}");
45+
}
46+
47+
}

quick-start/src/main/resources/static/app/directives/header.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
</div>
99
<div id="sitemenu" class="col-xs-6 col-sm-6 col-md-6 dropdown" ng-if="status != null">
1010
<button type="submit" name="installUserModules" class="btn btn-primary" ng-if="status.installed" ng-click="installUserModules()" ng-disabled="action.type != null">Deploy to server</button>
11-
<button type="submit" name="uninstall" class="btn btn-primary" ng-if="status.installed" ng-click="uninstall()" confirm-settings="{size: 'sm', animation: false}" confirm="Do you really want to continue uninstalling data hub?" confirm-title="Confirm Uninstall" ng-disabled="action.type != null">Uninstall</button>
1211
<button class="btn btn-default dropdown-toggle" type="button" id="headerDropdownMenu" data-toggle="dropdown" aria-expanded="true">
1312
Welcome {{status.mlUsername}}! <span class="caret"></span>
1413
</button>
1514
<ul class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="headerDropdownMenu">
16-
<li role="presentation"><a href="javascript:void(0)" ng-click="logout()">Logout</a></li>
15+
<li role="presentation"><a href ng-if="status.installed" ng-click="uninstall()" confirm-settings="{size: 'sm', animation: false}" confirm="Do you really want to continue uninstalling data hub?" confirm-title="Confirm Uninstall" ng-disabled="action.type != null">Uninstall</a></li>
16+
<li role="separator" class="divider divider-menu"></li>
17+
<li role="presentation"><a href ng-click="toggleTracing()">{{getTracingButton()}}</a></li>
18+
<li role="presentation"><a ng-href="{{getTracingUri()}}" target="_blank">Trace Viewer</a></li>
19+
<li role="separator" class="divider divider-menu"></li>
20+
<li role="presentation"><a href ng-click="logout()">Logout</a></li>
1721
</ul>
1822
</div>
1923
</div>

quick-start/src/main/resources/static/app/directives/headerDirective.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
angular.module('dhib.quickstart.directives.header', [])
66
.directive('header', HeaderDirective);
77

8-
function HeaderDirective($http, $location, DataHub) {
8+
function HeaderDirective($http, $location, DataHub, tracingService) {
99
return {
1010
restrict: 'E',
1111
templateUrl : function(element, attrs) {
@@ -43,6 +43,37 @@
4343
DataHub.showApiDoc();
4444
};
4545

46+
scope.tracingEnabled = false;
47+
48+
scope.getTracingButton = function() {
49+
var txt = '';
50+
txt += (scope.tracingEnabled) ? 'Disable' : 'Enable';
51+
txt += ' Tracing';
52+
return txt;
53+
}
54+
55+
scope.getTracingUri = function() {
56+
return 'http://' + scope.status.mlHost + ':' +
57+
scope.status.mlTracePort + '/';
58+
}
59+
60+
scope.toggleTracing = function() {
61+
if (scope.tracingEnabled) {
62+
tracingService.disableTracing().then(function() {
63+
scope.tracingEnabled = false;
64+
});
65+
}
66+
else {
67+
tracingService.enableTracing().then(function() {
68+
scope.tracingEnabled = true;
69+
});
70+
}
71+
}
72+
73+
tracingService.isEnabled().then(function(resp) {
74+
scope.tracingEnabled = resp.data.enabled;
75+
});
76+
4677
}
4778
};
4879
}

quick-start/src/main/resources/static/app/quickStartApp.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
'angular-confirm',
1818
'ngSanitize',
1919
'swaggerUi',
20-
'mlcp'
20+
'mlcp',
21+
'tracing'
2122
];
2223
angular.module('quickStartApp', dependencies)
2324
.factory('$exceptionHandler', ExceptionHandler)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(function () {
2+
3+
'use strict';
4+
5+
angular.module('tracing', []);
6+
7+
})();

0 commit comments

Comments
 (0)