Skip to content

Commit

Permalink
#92 Provide task metadata to event consumer. Expose in debug script. (#…
Browse files Browse the repository at this point in the history
…104)

#92 Provide task metadata to event consumer. Expose in debug script.

Co-authored-by: marcin.szymura <marcin.szymura@cognifide.com>
Co-authored-by: Tomasz Michalak <tomek.michalak@gmail.com>
Co-authored-by: Voycawojka <filip.artur.kowalski@gmail.com>
  • Loading branch information
4 people authored Mar 10, 2020
1 parent 444b0a9 commit ffa6866
Show file tree
Hide file tree
Showing 48 changed files with 3,318 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.knotx.fragments.handler.action.cb;

import static io.knotx.fragments.engine.api.node.single.FragmentResult.ERROR_TRANSITION;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -70,6 +71,6 @@ void expectErrorTransitionConfigured() {
CircuitBreakerActionFactoryOptions tested = new CircuitBreakerActionFactoryOptions(json);

// then
assertTrue(tested.getErrorTransitions().contains("_error"));
assertTrue(tested.getErrorTransitions().contains(ERROR_TRANSITION));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.knotx.fragments.handler.action.cb;

import static io.knotx.fragments.engine.api.node.single.FragmentResult.ERROR_TRANSITION;
import static io.knotx.fragments.handler.action.cb.CircuitBreakerAction.ERROR_LOG_KEY;
import static io.knotx.fragments.handler.action.cb.CircuitBreakerAction.INVOCATION_COUNT_LOG_KEY;
import static io.knotx.fragments.handler.action.cb.CircuitBreakerActionFactory.FALLBACK_TRANSITION;
Expand Down Expand Up @@ -679,7 +680,7 @@ private void validateScenario(Action firstInvocationBehaviour, Action secondInvo
CircuitBreakerAction tested = new CircuitBreakerAction(circuitBreaker,
CircuitBreakerDoActions
.applyOneAfterAnother(firstInvocationBehaviour, secondInvocationBehaviour), "tested",
INFO, Collections.singleton("_error"));
INFO, Collections.singleton(ERROR_TRANSITION));

// when
tested.apply(new FragmentContext(FRAGMENT, new ClientRequest()), handler);
Expand Down
57 changes: 57 additions & 0 deletions handler/core/docs/asciidoc/dataobjects.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ The factory name.
+++
|===

[[FragmentExecutionLog]]
== FragmentExecutionLog


[cols=">25%,25%,50%"]
[frame="topbot"]
|===
^|Name | Type ^| Description
|[[finishTime]]`@finishTime`|`Number (long)`|-
|[[fragment]]`@fragment`|`link:dataobjects.html#Fragment[Fragment]`|-
|[[graph]]`@graph`|`link:dataobjects.html#GraphNodeExecutionLog[GraphNodeExecutionLog]`|-
|[[startTime]]`@startTime`|`Number (long)`|-
|[[status]]`@status`|`link:enums.html#Status[Status]`|-
|===

[[FragmentsHandlerOptions]]
== FragmentsHandlerOptions

Expand All @@ -127,6 +142,36 @@ The array/list of task factory options defines factories taking part in the crea
+++
|===

[[GraphNodeExecutionLog]]
== GraphNodeExecutionLog


[cols=">25%,25%,50%"]
[frame="topbot"]
|===
^|Name | Type ^| Description
|[[id]]`@id`|`String`|-
|[[label]]`@label`|`String`|-
|[[on]]`@on`|`link:dataobjects.html#GraphNodeExecutionLog[GraphNodeExecutionLog]`|-
|[[operation]]`@operation`|`link:dataobjects.html#GraphNodeOperationLog[GraphNodeOperationLog]`|-
|[[response]]`@response`|`link:dataobjects.html#GraphNodeResponseLog[GraphNodeResponseLog]`|-
|[[status]]`@status`|`link:enums.html#LoggedNodeStatus[LoggedNodeStatus]`|-
|[[subtasks]]`@subtasks`|`Array of link:dataobjects.html#GraphNodeExecutionLog[GraphNodeExecutionLog]`|-
|[[type]]`@type`|`link:enums.html#NodeType[NodeType]`|-
|===

[[GraphNodeOperationLog]]
== GraphNodeOperationLog


[cols=">25%,25%,50%"]
[frame="topbot"]
|===
^|Name | Type ^| Description
|[[data]]`@data`|`Json object`|-
|[[factory]]`@factory`|`String`|-
|===

[[GraphNodeOptions]]
== GraphNodeOptions

Expand Down Expand Up @@ -157,6 +202,18 @@ Sets a node factory name to <code>SubtasksNodeFactory.NAME</code> and configures
+++
|===

[[GraphNodeResponseLog]]
== GraphNodeResponseLog


[cols=">25%,25%,50%"]
[frame="topbot"]
|===
^|Name | Type ^| Description
|[[invocations]]`@invocations`|`Json array`|-
|[[transition]]`@transition`|`String`|-
|===

[[LogLevelConfig]]
== LogLevelConfig

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (C) 2019 Knot.x Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.knotx.fragments.engine;

import io.knotx.fragments.engine.api.node.NodeType;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class NodeMetadata {

private String nodeId;
private String label;
private NodeType type;
private Map<String, String> transitions;
private List<String> nestedNodes;
private OperationMetadata operation;

public static NodeMetadata single(String nodeId, String label, Map<String, String> transitions, OperationMetadata operation) {
return new NodeMetadata(nodeId, label, NodeType.SINGLE, transitions, Collections.emptyList(), operation);
}

public static NodeMetadata composite(String nodeId, String label, Map<String, String> transitions,
List<String> nestedNodes, OperationMetadata operation) {
return new NodeMetadata(nodeId, label, NodeType.COMPOSITE, transitions, nestedNodes, operation);
}

private NodeMetadata(String nodeId, String label, NodeType type, Map<String, String> transitions,
List<String> nestedNodes, OperationMetadata operation) {
this.nodeId = nodeId;
this.label = label;
this.type = type;
this.transitions = transitions;
this.nestedNodes = nestedNodes;
this.operation = operation;
}

public String getNodeId() {
return nodeId;
}

public String getLabel() {
return label;
}

public NodeType getType() {
return type;
}

/**
* @return transition name to node id map
*/
public Map<String, String> getTransitions() {
return transitions;
}

/**
* @return list of composite nodes identifiers
*/
public List<String> getNestedNodes() {
return nestedNodes;
}

public OperationMetadata getOperation() {
return operation;
}

@Override
public String toString() {
return "NodeMetadata{" +
"nodeId='" + nodeId + '\'' +
", label='" + label + '\'' +
", type=" + type +
", transitions=" + transitions +
", nestedNodes=" + nestedNodes +
", operation=" + operation +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2019 Knot.x Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.knotx.fragments.engine;

import io.vertx.core.json.JsonObject;

public class OperationMetadata {

private final String factory;

private final JsonObject data;

public OperationMetadata(String factory) {
this(factory, new JsonObject());
}

public OperationMetadata(String factory, JsonObject data) {
this.factory = factory;
this.data = data;
}

public String getFactory() {
return factory;
}

public JsonObject getData() {
return data;
}

@Override
public String toString() {
return "OperationMetadata{" +
"factory='" + factory + '\'' +
", data=" + data +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2019 Knot.x Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.knotx.fragments.engine;

import io.knotx.fragments.handler.ExecutionPlan;
import java.util.HashMap;
import java.util.Map;

public class TaskMetadata {

private final String taskName;
private final String rootNodeId;
private final Map<String, NodeMetadata> nodesMetadata;

private TaskMetadata(String taskName, String rootNodeId, Map<String, NodeMetadata> nodesMetadata) {
this.taskName = taskName;
this.rootNodeId = rootNodeId;
this.nodesMetadata = nodesMetadata;
}

public static TaskMetadata create(String taskName, String rootNodeId, Map<String, NodeMetadata> nodesMetadata) {
return new TaskMetadata(taskName, rootNodeId, nodesMetadata);
}

public static TaskMetadata noMetadata(String taskName, String rootNodeId) {
return new TaskMetadata(taskName, rootNodeId, new HashMap<>());
}

public static TaskMetadata notDefined() {
return noMetadata(ExecutionPlan.UNDEFINED_TASK, "");
}

public String getTaskName() {
return taskName;
}

public String getRootNodeId() {
return rootNodeId;
}

public Map<String, NodeMetadata> getNodesMetadata() {
return nodesMetadata;
}

@Override
public String toString() {
return "TaskMetadata{" +
"taskName='" + taskName + '\'' +
", rootNodeId='" + rootNodeId + '\'' +
", nodesMetadata=" + nodesMetadata +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2019 Knot.x Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.knotx.fragments.engine;

import io.knotx.fragments.engine.api.Task;

public class TaskWithMetadata {

private final Task task;
private final TaskMetadata metadata;

public TaskWithMetadata(Task task, TaskMetadata taskMetadata) {
this.task = task;
this.metadata = taskMetadata;
}

public Task getTask() {
return task;
}

public TaskMetadata getMetadata() {
return metadata;
}

@Override
public String toString() {
return "TaskWithMetadata{" +
"task=" + task +
", taskMetadata=" + metadata +
'}';
}
}
Loading

0 comments on commit ffa6866

Please sign in to comment.