Skip to content

Commit

Permalink
Merge pull request #2763 from mattcasters/master
Browse files Browse the repository at this point in the history
Issue #2544 : Execution state doesn't contain an end date
  • Loading branch information
hansva committed Mar 23, 2023
2 parents d72d1ba + fd706f5 commit df3b804
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 31 deletions.
Expand Up @@ -67,9 +67,12 @@ public class ExecutionState {
/** Extra details that a plugin might want to save in the state */
private Map<String, String> details;

/** Indicates whether or not the execution failed */
/** Indicates whether the execution failed */
private boolean failed;

/** If the execution finished, what was the end date? */
private Date executionEndDate;

/**
* The ID of the container where we are executing in. Usually this is the Object ID found on the
* Hop server.
Expand Down Expand Up @@ -334,4 +337,22 @@ public String getContainerId() {
public void setContainerId(String containerId) {
this.containerId = containerId;
}

/**
* Gets executionEndDate
*
* @return value of executionEndDate
*/
public Date getExecutionEndDate() {
return executionEndDate;
}

/**
* Sets executionEndDate
*
* @param executionEndDate value of executionEndDate
*/
public void setExecutionEndDate(Date executionEndDate) {
this.executionEndDate = executionEndDate;
}
}
Expand Up @@ -18,6 +18,12 @@

package org.apache.hop.execution;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.hop.core.Result;
import org.apache.hop.core.logging.HopLogStore;
import org.apache.hop.core.logging.LoggingRegistry;
Expand All @@ -30,13 +36,6 @@
import org.apache.hop.workflow.WorkflowMeta;
import org.apache.hop.workflow.engine.IWorkflowEngine;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class ExecutionStateBuilder {
private ExecutionType executionType;
private Date updateTime;
Expand All @@ -52,6 +51,7 @@ public final class ExecutionStateBuilder {
private boolean failed;
private Map<String, String> details;
private String containerId;
private Date executionEndDate;

private ExecutionStateBuilder() {
this.updateTime = new Date();
Expand Down Expand Up @@ -95,7 +95,8 @@ public static ExecutionStateBuilder fromExecutor(
.withStatusDescription(pipeline.getStatusDescription())
.withChildIds(
LoggingRegistry.getInstance().getChildrenMap().get(pipeline.getLogChannelId()))
.withContainerId(pipeline.getContainerId());
.withContainerId(pipeline.getContainerId())
.withExecutionEndDate(pipeline.getExecutionEndDate());

EngineMetrics engineMetrics = pipeline.getEngineMetrics();

Expand Down Expand Up @@ -134,7 +135,8 @@ public static ExecutionStateBuilder fromTransform(
.withName(component.getName())
.withCopyNr(Integer.toString(component.getCopyNr()))
.withParentId(pipeline.getLogChannelId())
.withContainerId(pipeline.getContainerId());
.withContainerId(pipeline.getContainerId())
.withExecutionEndDate(component.getExecutionEndDate());
}

private static void addMetric(
Expand Down Expand Up @@ -169,7 +171,8 @@ public static ExecutionStateBuilder fromExecutor(
.withStatusDescription(workflow.getStatusDescription())
.withChildIds(
LoggingRegistry.getInstance().getChildrenMap().get(workflow.getLogChannelId()))
.withContainerId(workflow.getContainerId());
.withContainerId(workflow.getContainerId())
.withExecutionEndDate(workflow.getExecutionEndDate());
}

public ExecutionStateBuilder withExecutionType(ExecutionType executionType) {
Expand Down Expand Up @@ -248,6 +251,11 @@ public ExecutionStateBuilder withContainerId(String containerId) {
return this;
}

public ExecutionStateBuilder withExecutionEndDate(Date executionEndDate) {
this.executionEndDate = executionEndDate;
return this;
}

public ExecutionState build() {
ExecutionState state = new ExecutionState();
state.setExecutionType(executionType);
Expand All @@ -264,6 +272,7 @@ public ExecutionState build() {
state.setFailed(failed);
state.setDetails(details);
state.setContainerId(containerId);
state.setExecutionEndDate(executionEndDate);
return state;
}
}
Expand Up @@ -21,6 +21,14 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.hop.core.Const;
import org.apache.hop.core.exception.HopException;
Expand Down Expand Up @@ -77,15 +85,6 @@
import org.neo4j.driver.Transaction;
import org.neo4j.driver.Value;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@GuiPlugin(description = "Neo4j execution information location GUI elements")
@ExecutionInfoLocationPlugin(
id = "neo4j-location",
Expand Down Expand Up @@ -114,6 +113,7 @@ public class NeoExecutionInfoLocation implements IExecutionInfoLocation {
public static final String EP_FAILED = "failed";
public static final String EP_DETAILS = "details";
public static final String EP_CONTAINER_ID = "containerId";
public static final String EP_EXECUTION_END_DATE = "executionEndDate";

public static final String CL_EXECUTION_METRIC = "ExecutionMetric";
public static final String CP_ID = "id";
Expand Down Expand Up @@ -639,7 +639,8 @@ private boolean updateNeo4jExecutionState(Transaction transaction, ExecutionStat
.withValue(EP_CHILD_IDS, state.getChildIds())
.withValue(EP_FAILED, state.isFailed())
.withValue(EP_DETAILS, state.getDetails())
.withValue(EP_CONTAINER_ID, state.getContainerId());
.withValue(EP_CONTAINER_ID, state.getContainerId())
.withValue(EP_EXECUTION_END_DATE, state.getExecutionEndDate());

transaction.run(stateCypherBuilder.cypher(), stateCypherBuilder.parameters());

Expand Down Expand Up @@ -701,7 +702,8 @@ private ExecutionState getNeo4jExecutionState(Transaction transaction, String ex
EP_CHILD_IDS,
EP_FAILED,
EP_DETAILS,
EP_CONTAINER_ID);
EP_CONTAINER_ID,
EP_EXECUTION_END_DATE);
Result result = transaction.run(executionBuilder.cypher(), executionBuilder.parameters());

// We expect exactly one result
Expand All @@ -724,7 +726,8 @@ private ExecutionState getNeo4jExecutionState(Transaction transaction, String ex
.withChildIds(getList(record, EP_CHILD_IDS))
.withFailed(getBoolean(record, EP_FAILED))
.withDetails(getMap(record, EP_DETAILS))
.withContainerId(getString(record, EP_CONTAINER_ID));
.withContainerId(getString(record, EP_CONTAINER_ID))
.withExecutionEndDate(getDate(record, EP_EXECUTION_END_DATE));

// Add the metrics to the state...
//
Expand Down
Expand Up @@ -18,6 +18,9 @@

package org.apache.hop.pipeline.transforms.execinfo;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import org.apache.commons.lang.StringUtils;
import org.apache.hop.core.ICheckResult;
import org.apache.hop.core.exception.HopException;
Expand All @@ -39,10 +42,6 @@
import org.apache.hop.pipeline.transform.TransformMeta;
import org.json.simple.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

/** Execute a process * */
public class ExecInfo extends BaseTransform<ExecInfoMeta, ExecInfoData> {

Expand Down Expand Up @@ -279,12 +278,13 @@ private void outputExecutionAndState(IRowMeta rowMeta, Object[] row, Execution e
outputRow[index++] = execution.getRegistrationDate();
outputRow[index++] = execution.getExecutionStartDate();
outputRow[index++] = execution.getRunConfigurationName();
outputRow[index++] = execution.getLogLevel();
outputRow[index++] = execution.getLogLevel() == null ? null : execution.getLogLevel().getCode();
if (executionState != null) {
outputRow[index++] = executionState.getUpdateTime();
outputRow[index++] = executionState.getLoggingText();
outputRow[index++] = executionState.isFailed();
outputRow[index] = executionState.getStatusDescription();
outputRow[index++] = executionState.getStatusDescription();
outputRow[index] = executionState.getExecutionEndDate();
}
putRow(data.outputRowMeta, outputRow);
}
Expand Down
Expand Up @@ -18,6 +18,7 @@

package org.apache.hop.pipeline.transforms.execinfo;

import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.hop.core.CheckResult;
import org.apache.hop.core.ICheckResult;
Expand All @@ -33,8 +34,6 @@
import org.apache.hop.pipeline.transform.BaseTransformMeta;
import org.apache.hop.pipeline.transform.TransformMeta;

import java.util.List;

@Transform(
id = "ExecInfo",
image = "ui/images/location.svg",
Expand Down Expand Up @@ -130,6 +129,7 @@ public void getFields(
.addString("loggingText")
.addBoolean("failed")
.addString("statusDescription")
.addDate("executionEndDate")
.build());
return;
case DeleteExecution:
Expand Down
Expand Up @@ -24,7 +24,9 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.plugins.IPlugin;
import org.apache.hop.core.plugins.IPluginType;
Expand Down Expand Up @@ -62,6 +64,18 @@ public Response getTypes() {
public Response listPlugins(@PathParam("typeClassName") String typeClassName) {
try {
PluginRegistry registry = PluginRegistry.getInstance();

// Make sure that the requested type class is actually available in the plugin registry.
// If we don't do this any class in the classpath can be constructed which is not secure.
//
List<Class<? extends IPluginType>> pluginTypes = registry.getPluginTypes();
Set<String> typeClassesSet = new HashSet<>();
pluginTypes.forEach(c -> typeClassesSet.add(c.getName()));
if (!typeClassesSet.contains(typeClassName)) {
throw new HopException(
"Type class name is not available in the plugin registry: " + typeClassName);
}

Class<IPluginType<?>> typeClass = (Class<IPluginType<?>>) Class.forName(typeClassName);
List<IPlugin> plugins = registry.getPlugins(typeClass);
return Response.ok(plugins).build();
Expand Down

0 comments on commit df3b804

Please sign in to comment.