[
https://issues.apache.org/jira/browse/KNOX-2023?focusedWorklogId=324957&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-324957
]
ASF GitHub Bot logged work on KNOX-2023:
----------------------------------------
Author: ASF GitHub Bot
Created on: 08/Oct/19 09:08
Start Date: 08/Oct/19 09:08
Worklog Time Spent: 10m
Work Description: smolnar82 commented on pull request #162: KNOX-2023 -
Recording KnoxShellTable builder/filter chain and providing rollback/replay
capabilities using the call history as well as allowing end-users to export
JSON without data (in this case only the call history will be serialized)
URL: https://github.com/apache/knox/pull/162#discussion_r332407621
##########
File path:
gateway-shell/src/main/java/org/apache/knox/gateway/shell/table/KnoxShellTableRowDeserializer.java
##########
@@ -46,6 +57,83 @@ protected KnoxShellTableRowDeserializer(Class<?> vc) {
@Override
public KnoxShellTable deserialize(JsonParser parser, DeserializationContext
context) throws IOException, JsonProcessingException {
final TreeNode jsonContent = parser.readValueAsTree();
+ if (jsonContent.get("callHistoryList") != null) {
+ return parseJsonWithCallHistory(jsonContent);
+ } else {
+ return parseJsonWithData(jsonContent);
+ }
+ }
+
+ private KnoxShellTable parseJsonWithCallHistory(TreeNode jsonContent) throws
IOException {
+ final List<KnoxShellTableCall> calls =
parseCallHistoryListJSONNode(jsonContent.get("callHistoryList"));
+ long tempId = KnoxShellTable.getUniqueTableId();
+ KnoxShellTableCallHistory.getInstance().saveCalls(tempId, calls);
+ final KnoxShellTable table =
KnoxShellTableCallHistory.getInstance().replay(tempId, calls.size());
+ KnoxShellTableCallHistory.getInstance().removeCallsById(tempId);
+ return table;
+ }
+
+ private List<KnoxShellTableCall> parseCallHistoryListJSONNode(TreeNode
callHistoryNode) throws IOException {
+ final List<KnoxShellTableCall> callHistoryList = new
LinkedList<KnoxShellTableCall>();
+ TreeNode callNode;
+ Map<Object, Class<?>> params;
+ String invokerClass, method;
+ Boolean builderMethod;
+ for (int i = 0; i < callHistoryNode.size(); i++) {
+ callNode = callHistoryNode.get(i);
+ invokerClass = trimJSONQuotes(callNode.get("invokerClass").toString());
+ method = trimJSONQuotes(callNode.get("method").toString());
+ builderMethod =
Boolean.valueOf(trimJSONQuotes(callNode.get("builderMethod").toString()));
+ params = fetchParameterMap(callNode.get("params"));
+ callHistoryList.add(new KnoxShellTableCall(invokerClass, method,
builderMethod, params));
+ }
+ return callHistoryList;
+ }
+
+ private Map<Object, Class<?>> fetchParameterMap(TreeNode paramsNode) throws
IOException {
+ try {
+ final Map<Object, Class<?>> parameterMap = new HashMap<>();
+ final Iterator<String> paramsFieldNamesIterator = ((ObjectNode)
paramsNode).fieldNames();
+ String parameterValueAsString;
+ Class<?> parameterType;
+ while (paramsFieldNamesIterator.hasNext()) {
+ parameterValueAsString =
trimJSONQuotes(paramsFieldNamesIterator.next());
+ parameterType =
Class.forName(trimJSONQuotes(paramsNode.get(parameterValueAsString).toString()));
+ parameterMap.put(cast(parameterValueAsString, parameterType),
parameterType);
+ }
+ return parameterMap;
+ } catch (Exception e) {
+ throw new IOException("Error while fetching parameters " + paramsNode,
e);
+ }
+ }
+
+ // This may be done in a different way or using a library; I did not find
any (I
+ // did not do a deep search though)
+ private Object cast(String valueAsString, Class<?> type) throws
ParseException {
+ if (String.class.getCanonicalName().equals(type.getCanonicalName())) {
Review comment:
At best, we can do `XXX.class == type`; please check out my latest patch.
----------------------------------------------------------------
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]
Issue Time Tracking
-------------------
Worklog Id: (was: 324957)
Time Spent: 1h 40m (was: 1.5h)
> KnoxShellTable - Record the Creation Sequence of Tables
> -------------------------------------------------------
>
> Key: KNOX-2023
> URL: https://issues.apache.org/jira/browse/KNOX-2023
> Project: Apache Knox
> Issue Type: Improvement
> Components: KnoxShell
> Reporter: Larry McCay
> Assignee: Sandor Molnar
> Priority: Major
> Fix For: 1.4.0
>
> Time Spent: 1h 40m
> Remaining Estimate: 0h
>
> Each KnoxShellTable instance goes through a number of builders, filters,
> sorts, etc in order to get to their final state.
> Currently, those builder classes just go out of scope as they complete and
> return the resulting table.
> This JIRA represents the thought of recording them in an ArrayList within the
> table so that we could do a number of interesting things:
> * persist JSON representation that doesn't require the actual data
> * materialize tables from that persisted state by replaying the builders in
> order
> * possibly undo or rollback to a previous state
> * possibly providing interesting provenance capabilities with confidence
> factors based on sources
> Interesting challenges here will be when authentication is required for a SQL
> query in the JDBC builder or in accessing data accessed through Knox gateway
> instances.
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)