ahgittin commented on a change in pull request #196:
URL: https://github.com/apache/brooklyn-ui/pull/196#discussion_r613241409
##########
File path: ui-modules/app-inspector/app/components/stream/stream.directive.js
##########
@@ -67,28 +99,170 @@ export function streamDirective() {
});
$scope.$on('$destroy', cancelUpdate);
+ /**
+ * Updates the stream data.
+ */
function updateStream() {
activityApi.activityStream($scope.activityId,
$scope.streamType).then((response)=> {
+
+ // 1. Try to identify CLI XML output.
+ const CLI_XML_HEADER_SIZE = 100; // estimated headers size in
WinRM that can contain indication of CLI XML output
+ if ($scope.cliXmlVerificationRequired && typeof response.data
=== 'string' && response.data.length >= CLI_XML_HEADER_SIZE) {
+ let header = response.data.slice(0, CLI_XML_HEADER_SIZE);
+ if (header.includes('#< CLIXML') ||
header.includes('xmlns="http://schemas.microsoft.com/powershell')) {
+ $scope.cliXmlIdentified = true;
+ }
+ $scope.cliXmlVerificationRequired = false; // perform
verification once, if conditions match
+ }
+
+ // 2. Update the stream data holder in this directive.
$scope.stream = response.data;
+
+ // 3. Filter the content where relevant and display it.
+ updateFilteredContent();
+
}).catch((error)=> {
if (error.data) {
$scope.error = error.data.message;
}
}).finally(() => {
if ($scope.tail) {
$scope.$applyAsync(() => {
- pre[0].scrollTop = pre[0].scrollHeight;
+ autoScrollableElement.forEach(item => item.scrollTop =
item.scrollHeight);
});
}
})
}
+ /**
+ * Cancels the auto-update of the streamed content.
+ */
function cancelUpdate() {
if (refreshFunction) {
$interval.cancel(refreshFunction);
}
}
+ /**
+ * @returns {boolean} True if CLI XML is supported, and false
otherwise. CLI XML is expected in WinRM stream only.
+ */
+ function isCliXmlSupported() {
+ return isWinRmStream() && $scope.cliXmlIdentified === true;
+ }
+
+ /**
+ * @returns {boolean} True if stream type is WinRM, and false
otherwise.
+ */
+ function isWinRmStream() {
+ return $scope.streamType === 'winrm';
+ }
+
+ /**
+ * Switches content format to CLI XML and back.
+ */
+ function toggleCliXml() {
+ $scope.cliXml = !$scope.cliXml;
+ updateFilteredContent();
+ }
+
+ /**
+ * @returns {boolean} True if logging filter should be displayed, and
false otherwise.
+ */
+ function isFilterContent() {
+ return isCliXmlSupported() && $scope.cliXml !== true;
+ }
+
+ /**
+ * @returns {string} Returns class name of the formatted item log
level.
+ */
+ function getFormattedItemLogLevel(formattedItem) {
+ if (formattedItem.isWarning) {
+ return 'log-warning';
+ } else if (formattedItem.isError) {
+ return 'log-error';
+ } if (formattedItem.isDebug) {
+ return 'log-debug';
+ }
+ return 'log-trace';
+ }
+
+ /**
+ * @returns {boolean} True if formatted item should be displayed, and
false otherwise.
+ */
+ function isDisplayFormattedItem(formattedItem) {
+ return formattedItem.isWarning && $scope.isDisplayWarning
+ || formattedItem.isDebug && $scope.isDisplayDebug
+ || formattedItem.isError && $scope.isDisplayError
+ || formattedItem.isTrace && $scope.isDisplayTrace
+ || formattedItem.isOther && $scope.isDisplayOther;
+ }
+
+ /**
+ * Formats CLI XML output and displays it in 'filtered-stream-content'
field.
+ */
+ function formatCliXmlContent() {
+
+ // Slice at index of last closing tag ending wth the new line
+ let streamTags = $scope.stream.match(/<\/(.*?)>\n/g);
+ let lastClosingTagIndex =
$scope.stream.lastIndexOf(streamTags[streamTags.length-1]);
+ let newCliXmlData =
$scope.stream.slice($scope.streamProcessedUpTo, lastClosingTagIndex);
+ if (!newCliXmlData) {
+ return;
+ }
+
+ $scope.streamProcessedUpTo += newCliXmlData.length;
+
+ newCliXmlData.split(/\n/g).forEach(item => {
+ let formattedItem = {
+ id: ($scope.filteredStream.length), // ng-repeat requires
unique items, array length fits the bill
+ text: item,
+ isOther: false,
+ isError: false,
+ isDebug: false,
+ isTrace: false,
+ isWarning: false
+ };
+
+ if (/<s s="warning">/i.test(item)) {
+ formattedItem.isWarning = true;
+ } else if (/<s s="debug">/i.test(item)) {
+ formattedItem.isDebug = true;
+ } else if (/<s s="verbose">/i.test(item)) {
+ formattedItem.isTrace = true;
+ } else if (/<s s="error">/i.test(item)) {
+ formattedItem.isError = true;
+ } else {
+ formattedItem.isOther = true;
+ }
+
+ // Remove CLI XML string tags for know log levels
+ if (!formattedItem.isOther) {
+ formattedItem.text = item.replace(/<s s="(.*?)">|\t/gi,
'');
+ }
+
+ // Remove CLI XML markers, newlines and replace tabs with
spaces
+ formattedItem.text =
formattedItem.text.replace(/<\/s>|_x000[a-z0-9]_|\n/gi, '').replace(/\t/g,' ');
Review comment:
will this work for collapsing new lines, or if a new line is in the
output? we split on `\n` to create this loop so feels like if the input is
```
<s s="error">line 1
line 2
</s>
```
then here `text` would just be `<s s="error">line1` ... the next lines `line
2` and `</s>` will be other iterations of this loop and so would be classed as
`other` ? what am i missing?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]