use of co.cask.cdap.api.workflow.NodeValue in project cdap by caskdata.
the class WorkflowHttpHandler method getWorkflowToken.
@GET
@Path("/apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/token")
public void getWorkflowToken(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("workflow-id") String workflowId, @PathParam("run-id") String runId, @QueryParam("scope") @DefaultValue("user") String scope, @QueryParam("key") @DefaultValue("") String key) throws NotFoundException {
WorkflowToken workflowToken = getWorkflowToken(namespaceId, appId, workflowId, runId);
WorkflowToken.Scope tokenScope = WorkflowToken.Scope.valueOf(scope.toUpperCase());
WorkflowTokenDetail workflowTokenDetail = WorkflowTokenDetail.of(workflowToken.getAll(tokenScope));
Type workflowTokenDetailType = new TypeToken<WorkflowTokenDetail>() {
}.getType();
if (key.isEmpty()) {
responder.sendJson(HttpResponseStatus.OK, workflowTokenDetail, workflowTokenDetailType, GSON);
return;
}
List<NodeValue> nodeValueEntries = workflowToken.getAll(key, tokenScope);
if (nodeValueEntries.isEmpty()) {
throw new NotFoundException(key);
}
responder.sendJson(HttpResponseStatus.OK, WorkflowTokenDetail.of(ImmutableMap.of(key, nodeValueEntries)), workflowTokenDetailType, GSON);
}
use of co.cask.cdap.api.workflow.NodeValue in project cdap by caskdata.
the class BasicWorkflowToken method put.
private void put(String key, Value value, Scope scope) {
if (!putAllowed) {
String msg = String.format("Failed to put key '%s' from node '%s' in the WorkflowToken. Put operation is not " + "allowed from the Mapper and Reducer classes and from Spark executor.", key, nodeName);
throw new UnsupportedOperationException(msg);
}
Preconditions.checkNotNull(key, "Null key cannot be added in the WorkflowToken.");
Preconditions.checkNotNull(value, String.format("Null value provided for the key '%s'.", key));
Preconditions.checkNotNull(value.toString(), String.format("Null value provided for the key '%s'.", key));
Preconditions.checkState(nodeName != null, "nodeName cannot be null.");
List<NodeValue> nodeValueList = tokenValueMap.get(scope).get(key);
if (nodeValueList == null) {
nodeValueList = Lists.newArrayList();
tokenValueMap.get(scope).put(key, nodeValueList);
}
NodeValue nodeValueToAddUpdate = new NodeValue(nodeName, value);
// In that case replace that entry with the new one
for (int i = 0; i < nodeValueList.size(); i++) {
NodeValue existingNodeValue = nodeValueList.get(i);
if (existingNodeValue.getNodeName().equals(nodeName)) {
addOrUpdate(key, nodeValueToAddUpdate, nodeValueList, i);
return;
}
}
addOrUpdate(key, nodeValueToAddUpdate, nodeValueList, -1);
}
use of co.cask.cdap.api.workflow.NodeValue in project cdap by caskdata.
the class WorkflowTokenDetail method of.
/**
* Constructs a {@link WorkflowTokenDetail} by flattening the {@link Value} from the output of
* {@link WorkflowToken#getAll(WorkflowToken.Scope)}.
*
* @param data the workflow token data to flatten
* @return {@link WorkflowTokenDetail} from the specified workflow token data
*/
public static WorkflowTokenDetail of(Map<String, List<NodeValue>> data) {
Map<String, List<NodeValueDetail>> converted = new HashMap<>();
for (Map.Entry<String, List<NodeValue>> entry : data.entrySet()) {
List<NodeValueDetail> convertedList = new ArrayList<>();
for (NodeValue nodeValue : entry.getValue()) {
convertedList.add(new NodeValueDetail(nodeValue.getNodeName(), nodeValue.getValue().toString()));
}
converted.put(entry.getKey(), convertedList);
}
return new WorkflowTokenDetail(converted);
}
Aggregations