diff --git a/client/src/main/java/com/netflix/conductor/client/http/ClientBase.java b/client/src/main/java/com/netflix/conductor/client/http/ClientBase.java index 88a6f6c02b..848c8aa308 100644 --- a/client/src/main/java/com/netflix/conductor/client/http/ClientBase.java +++ b/client/src/main/java/com/netflix/conductor/client/http/ClientBase.java @@ -294,7 +294,7 @@ private void handleUniformInterfaceException(UniformInterfaceException exception return; } String errorMessage = clientResponse.getEntity(String.class); - LOGGER.error( + LOGGER.warn( "Unable to invoke Conductor API with uri: {}, unexpected response from server: statusCode={}, responseBody='{}'.", uri, clientResponse.getStatus(), errorMessage); ErrorResponse errorResponse; diff --git a/client/src/main/java/com/netflix/conductor/client/http/EventClient.java b/client/src/main/java/com/netflix/conductor/client/http/EventClient.java new file mode 100644 index 0000000000..aa8d9210bd --- /dev/null +++ b/client/src/main/java/com/netflix/conductor/client/http/EventClient.java @@ -0,0 +1,108 @@ +package com.netflix.conductor.client.http; + +import com.google.common.base.Preconditions; +import com.netflix.conductor.client.config.ConductorClientConfiguration; +import com.netflix.conductor.client.config.DefaultConductorClientConfiguration; +import com.netflix.conductor.common.metadata.events.EventHandler; +import com.sun.jersey.api.client.ClientHandler; +import com.sun.jersey.api.client.GenericType; +import com.sun.jersey.api.client.config.ClientConfig; +import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.api.client.filter.ClientFilter; +import org.apache.commons.lang.StringUtils; + +import java.util.List; + +// Client class for all Event Handler operations +public class EventClient extends ClientBase { + private static final GenericType> eventHandlerList = new GenericType>() { + }; + /** + * Creates a default metadata client + */ + public EventClient() { + this(new DefaultClientConfig(), new DefaultConductorClientConfiguration(), null); + } + + /** + * @param clientConfig REST Client configuration + */ + public EventClient(ClientConfig clientConfig) { + this(clientConfig, new DefaultConductorClientConfiguration(), null); + } + + /** + * @param clientConfig REST Client configuration + * @param clientHandler Jersey client handler. Useful when plugging in various http client interaction modules (e.g. + * ribbon) + */ + public EventClient(ClientConfig clientConfig, ClientHandler clientHandler) { + this(clientConfig, new DefaultConductorClientConfiguration(), clientHandler); + } + + /** + * @param config config REST Client configuration + * @param handler handler Jersey client handler. Useful when plugging in various http client interaction modules + * (e.g. ribbon) + * @param filters Chain of client side filters to be applied per request + */ + public EventClient(ClientConfig config, ClientHandler handler, ClientFilter... filters) { + this(config, new DefaultConductorClientConfiguration(), handler, filters); + } + + /** + * @param config REST Client configuration + * @param clientConfiguration Specific properties configured for the client, see {@link ConductorClientConfiguration} + * @param handler Jersey client handler. Useful when plugging in various http client interaction modules + * (e.g. ribbon) + * @param filters Chain of client side filters to be applied per request + */ + public EventClient(ClientConfig config, ConductorClientConfiguration clientConfiguration, ClientHandler handler, + ClientFilter... filters) { + super(config, clientConfiguration, handler); + for (ClientFilter filter : filters) { + super.client.addFilter(filter); + } + } + + /** + * Register an event handler with the server + * + * @param eventHandler the eventHandler definition + */ + public void registerEventHandler(EventHandler eventHandler) { + Preconditions.checkNotNull(eventHandler, "Event Handler definition cannot be null"); + postForEntityWithRequestOnly("event", eventHandler); + } + + /** + * Updates an event handler with the server + * + * @param eventHandler the eventHandler definition + */ + public void updateEventHandler(EventHandler eventHandler) { + Preconditions.checkNotNull(eventHandler, "Event Handler definition cannot be null"); + put("event", null, eventHandler); + } + + /** + * @param event name of the event + * @param activeOnly if true, returns only the active handlers + * @return Returns the list of all the event handlers for a given event + */ + public List getEventHandlers(String event, boolean activeOnly) { + Preconditions.checkArgument(org.apache.commons.lang3.StringUtils.isNotBlank(event), "Event cannot be blank"); + + return getForEntity("event/{event}", new Object[]{"activeOnly", activeOnly}, eventHandlerList, event); + } + + /** + * Removes the event handler definition from the conductor server + * + * @param name the name of the event handler to be unregistered + */ + public void unregisterEventHandler(String name) { + Preconditions.checkArgument(StringUtils.isNotBlank(name), "Event handler name cannot be blank"); + delete("event/{name}", name); + } +} diff --git a/client/src/test/java/com/netflix/conductor/client/http/EventClientTest.java b/client/src/test/java/com/netflix/conductor/client/http/EventClientTest.java new file mode 100644 index 0000000000..b93c321c19 --- /dev/null +++ b/client/src/test/java/com/netflix/conductor/client/http/EventClientTest.java @@ -0,0 +1,76 @@ +package com.netflix.conductor.client.http; + +import com.netflix.conductor.common.metadata.events.EventHandler; +import com.sun.jersey.api.client.ClientHandler; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.config.ClientConfig; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.springframework.test.context.junit4.SpringRunner; + +import java.net.URI; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +@RunWith(SpringRunner.class) +public class EventClientTest { + + @Mock + private ClientHandler clientHandler; + + @Mock + private ClientConfig clientConfig; + + private EventClient eventClient; + + @Before + public void before() { + this.eventClient = new EventClient(clientConfig, clientHandler); + this.eventClient.setRootURI("http://myuri:8080/"); + } + + @Test + public void testRegisterEventHandler() { + EventHandler eventHandler = mock(EventHandler.class); + when(clientHandler.handle(argThat(argument -> + argument.getURI().equals(URI.create("http://myuri:8080/event"))))) + .thenReturn(mock(ClientResponse.class)); + eventClient.registerEventHandler(eventHandler); + verify(clientHandler).handle(any()); + } + + @Test + public void testUpdateEventHandler() { + EventHandler eventHandler = mock(EventHandler.class); + when(clientHandler.handle(argThat(argument -> + argument.getURI().equals(URI.create("http://myuri:8080/event"))))) + .thenReturn(mock(ClientResponse.class)); + eventClient.updateEventHandler(eventHandler); + verify(clientHandler).handle(any()); + } + + @Test + public void testGetEventHandlers() { + when(clientHandler.handle(argThat(argument -> + argument.getURI().equals(URI.create("http://myuri:8080/event/test?activeOnly=true"))))) + .thenReturn(mock(ClientResponse.class)); + eventClient.getEventHandlers("test", true); + verify(clientHandler).handle(any()); + } + + @Test + public void testUnregisterEventHandler() { + when(clientHandler.handle(argThat(argument -> + argument.getURI().equals(URI.create("http://myuri:8080/event/test"))))) + .thenReturn(mock(ClientResponse.class)); + eventClient.unregisterEventHandler("test"); + verify(clientHandler).handle(any()); + } +} diff --git a/grpc-client/src/main/java/com/netflix/conductor/client/grpc/EventClient.java b/grpc-client/src/main/java/com/netflix/conductor/client/grpc/EventClient.java new file mode 100644 index 0000000000..615b66efe2 --- /dev/null +++ b/grpc-client/src/main/java/com/netflix/conductor/client/grpc/EventClient.java @@ -0,0 +1,78 @@ +package com.netflix.conductor.client.grpc; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Iterators; +import com.netflix.conductor.common.metadata.events.EventHandler; +import com.netflix.conductor.grpc.EventServiceGrpc; +import com.netflix.conductor.grpc.EventServicePb; +import com.netflix.conductor.proto.EventHandlerPb; +import org.apache.commons.lang3.StringUtils; + +import java.util.Iterator; + +public class EventClient extends ClientBase { + + private final EventServiceGrpc.EventServiceBlockingStub stub; + + public EventClient(String address, int port) { + super(address, port); + this.stub = EventServiceGrpc.newBlockingStub(this.channel); + } + + /** + * Register an event handler with the server + * + * @param eventHandler the event handler definition + */ + public void registerEventHandler(EventHandler eventHandler) { + Preconditions.checkNotNull(eventHandler, "Event handler definition cannot be null"); + stub.addEventHandler( + EventServicePb.AddEventHandlerRequest.newBuilder() + .setHandler(protoMapper.toProto(eventHandler)) + .build() + ); + } + + /** + * Updates an existing event handler + * + * @param eventHandler the event handler to be updated + */ + public void updateEventHandler(EventHandler eventHandler) { + Preconditions.checkNotNull(eventHandler, "Event handler definition cannot be null"); + stub.updateEventHandler( + EventServicePb.UpdateEventHandlerRequest.newBuilder() + .setHandler(protoMapper.toProto(eventHandler)) + .build() + ); + } + + /** + * @param event name of the event + * @param activeOnly if true, returns only the active handlers + * @return Returns the list of all the event handlers for a given event + */ + public Iterator getEventHandlers(String event, boolean activeOnly) { + Preconditions.checkArgument(StringUtils.isNotBlank(event), "Event cannot be blank"); + + EventServicePb.GetEventHandlersForEventRequest.Builder request = + EventServicePb.GetEventHandlersForEventRequest.newBuilder() + .setEvent(event) + .setActiveOnly(activeOnly); + Iterator it = stub.getEventHandlersForEvent(request.build()); + return Iterators.transform(it, protoMapper::fromProto); + } + + /** + * Removes the event handler from the conductor server + * + * @param name the name of the event handler + */ + public void unregisterEventHandler(String name) { + Preconditions.checkArgument(StringUtils.isNotBlank(name), "Name cannot be blank"); + stub.removeEventHandler(EventServicePb.RemoveEventHandlerRequest.newBuilder() + .setName(name) + .build() + ); + } +} diff --git a/grpc-client/src/test/java/com/netflix/conductor/client/grpc/EventClientTest.java b/grpc-client/src/test/java/com/netflix/conductor/client/grpc/EventClientTest.java new file mode 100644 index 0000000000..41d919a576 --- /dev/null +++ b/grpc-client/src/test/java/com/netflix/conductor/client/grpc/EventClientTest.java @@ -0,0 +1,94 @@ +package com.netflix.conductor.client.grpc; + +import com.netflix.conductor.common.metadata.events.EventHandler; +import com.netflix.conductor.grpc.EventServiceGrpc; +import com.netflix.conductor.grpc.EventServicePb; +import com.netflix.conductor.grpc.ProtoMapper; +import com.netflix.conductor.proto.EventHandlerPb; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import static junit.framework.TestCase.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(SpringRunner.class) +public class EventClientTest { + + @Mock + ProtoMapper mockedProtoMapper; + + @Mock + EventServiceGrpc.EventServiceBlockingStub mockedStub; + + EventClient eventClient; + + @Before + public void init() { + eventClient = new EventClient("test", 0); + ReflectionTestUtils.setField(eventClient, "stub", mockedStub); + ReflectionTestUtils.setField(eventClient, "protoMapper", mockedProtoMapper); + } + + @Test + public void testRegisterEventHandler() { + EventHandler eventHandler = mock(EventHandler.class); + EventHandlerPb.EventHandler eventHandlerPB = mock(EventHandlerPb.EventHandler.class); + when(mockedProtoMapper.toProto(eventHandler)).thenReturn(eventHandlerPB); + + EventServicePb.AddEventHandlerRequest request = EventServicePb.AddEventHandlerRequest.newBuilder() + .setHandler(eventHandlerPB) + .build(); + eventClient.registerEventHandler(eventHandler); + verify(mockedStub, times(1)).addEventHandler(request); + } + + @Test + public void testUpdateEventHandler() { + EventHandler eventHandler = mock(EventHandler.class); + EventHandlerPb.EventHandler eventHandlerPB = mock(EventHandlerPb.EventHandler.class); + when(mockedProtoMapper.toProto(eventHandler)).thenReturn(eventHandlerPB); + + EventServicePb.UpdateEventHandlerRequest request = EventServicePb.UpdateEventHandlerRequest.newBuilder() + .setHandler(eventHandlerPB) + .build(); + eventClient.updateEventHandler(eventHandler); + verify(mockedStub, times(1)).updateEventHandler(request); + } + + @Test + public void testGetEventHandlers() { + EventHandler eventHandler = mock(EventHandler.class); + EventHandlerPb.EventHandler eventHandlerPB = mock(EventHandlerPb.EventHandler.class); + when(mockedProtoMapper.fromProto(eventHandlerPB)).thenReturn(eventHandler); + EventServicePb.GetEventHandlersForEventRequest request = EventServicePb.GetEventHandlersForEventRequest.newBuilder() + .setEvent("test") + .setActiveOnly(true) + .build(); + List result = new ArrayList<>(); + result.add(eventHandlerPB); + when(mockedStub.getEventHandlersForEvent(request)).thenReturn(result.iterator()); + Iterator response = eventClient.getEventHandlers("test", true); + verify(mockedStub, times(1)).getEventHandlersForEvent(request); + assertEquals(response.next(), eventHandler); + } + + @Test + public void testUnregisterEventHandler() { + EventServicePb.RemoveEventHandlerRequest request = EventServicePb.RemoveEventHandlerRequest.newBuilder() + .setName("test") + .build(); + eventClient.unregisterEventHandler("test"); + verify(mockedStub, times(1)).removeEventHandler(request); + } +} diff --git a/test-harness/src/test/java/com/netflix/conductor/test/integration/AbstractEndToEndTest.java b/test-harness/src/test/java/com/netflix/conductor/test/integration/AbstractEndToEndTest.java index affc626862..96a6eb772c 100644 --- a/test-harness/src/test/java/com/netflix/conductor/test/integration/AbstractEndToEndTest.java +++ b/test-harness/src/test/java/com/netflix/conductor/test/integration/AbstractEndToEndTest.java @@ -12,6 +12,7 @@ */ package com.netflix.conductor.test.integration; +import com.netflix.conductor.common.metadata.events.EventHandler; import com.netflix.conductor.common.metadata.tasks.TaskDef; import com.netflix.conductor.common.metadata.tasks.TaskType; import com.netflix.conductor.common.metadata.workflow.WorkflowDef; @@ -24,6 +25,7 @@ import org.elasticsearch.client.RestClientBuilder; import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,12 +37,15 @@ import java.io.InputStreamReader; import java.io.Reader; import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Optional; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertFalse; @TestPropertySource(properties = {"conductor.indexing.enabled=true", "conductor.elasticsearch.version=6"}) public abstract class AbstractEndToEndTest { @@ -183,6 +188,28 @@ public void testEphemeralWorkflowsWithEphemeralAndStoredTasks() { } + @Test + public void testEventHandler() { + String eventName = "conductor:test_workflow:complete_task_with_event"; + EventHandler eventHandler = new EventHandler(); + eventHandler.setName("test_complete_task_event"); + EventHandler.Action completeTaskAction = new EventHandler.Action(); + completeTaskAction.setAction(EventHandler.Action.Type.complete_task); + completeTaskAction.setComplete_task(new EventHandler.TaskDetails()); + completeTaskAction.getComplete_task().setTaskRefName("test_task"); + completeTaskAction.getComplete_task().setWorkflowId("test_id"); + completeTaskAction.getComplete_task().setOutput(new HashMap<>()); + eventHandler.getActions().add(completeTaskAction); + eventHandler.setEvent(eventName); + eventHandler.setActive(true); + registerEventHandler(eventHandler); + + Iterator it = getEventHandlers(eventName, true); + EventHandler result = it.next(); + assertFalse(it.hasNext()); + assertEquals(eventHandler.getName(), result.getName()); + } + protected WorkflowTask createWorkflowTask(String name) { WorkflowTask workflowTask = new WorkflowTask(); workflowTask.setName(name); @@ -238,4 +265,10 @@ private String getDefaultDescription(String nameResource) { protected abstract TaskDef getTaskDefinition(String taskName); protected abstract void registerTaskDefinitions(List taskDefinitionList); + + protected abstract void registerWorkflowDefinition(WorkflowDef workflowDefinition); + + protected abstract void registerEventHandler(EventHandler eventHandler); + + protected abstract Iterator getEventHandlers(String event, boolean activeOnly); } diff --git a/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/AbstractGrpcEndToEndTest.java b/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/AbstractGrpcEndToEndTest.java index a4169a414a..140373b511 100644 --- a/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/AbstractGrpcEndToEndTest.java +++ b/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/AbstractGrpcEndToEndTest.java @@ -16,9 +16,11 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import com.netflix.conductor.client.grpc.EventClient; import com.netflix.conductor.client.grpc.MetadataClient; import com.netflix.conductor.client.grpc.TaskClient; import com.netflix.conductor.client.grpc.WorkflowClient; +import com.netflix.conductor.common.metadata.events.EventHandler; import com.netflix.conductor.common.metadata.tasks.Task; import com.netflix.conductor.common.metadata.tasks.Task.Status; import com.netflix.conductor.common.metadata.tasks.TaskDef; @@ -33,6 +35,8 @@ import com.netflix.conductor.common.run.Workflow.WorkflowStatus; import com.netflix.conductor.common.run.WorkflowSummary; import com.netflix.conductor.test.integration.AbstractEndToEndTest; + +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import org.junit.Test; @@ -52,6 +56,7 @@ public abstract class AbstractGrpcEndToEndTest extends AbstractEndToEndTest { protected static TaskClient taskClient; protected static WorkflowClient workflowClient; protected static MetadataClient metadataClient; + protected static EventClient eventClient; @Override protected String startWorkflow(String workflowExecutionName, WorkflowDef workflowDefinition) { @@ -76,6 +81,21 @@ protected void registerTaskDefinitions(List taskDefinitionList) { metadataClient.registerTaskDefs(taskDefinitionList); } + @Override + protected void registerWorkflowDefinition(WorkflowDef workflowDefinition) { + metadataClient.registerWorkflowDef(workflowDefinition); + } + + @Override + protected void registerEventHandler(EventHandler eventHandler) { + eventClient.registerEventHandler(eventHandler); + } + + @Override + protected Iterator getEventHandlers(String event, boolean activeOnly) { + return eventClient.getEventHandlers(event, activeOnly); + } + @Test public void testAll() throws Exception { assertNotNull(taskClient); diff --git a/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/GrpcEndToEndTest.java b/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/GrpcEndToEndTest.java index 8917d9394b..7bd1e52b33 100644 --- a/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/GrpcEndToEndTest.java +++ b/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/GrpcEndToEndTest.java @@ -12,6 +12,7 @@ */ package com.netflix.conductor.test.integration.grpc; +import com.netflix.conductor.client.grpc.EventClient; import com.netflix.conductor.client.grpc.MetadataClient; import com.netflix.conductor.client.grpc.TaskClient; import com.netflix.conductor.client.grpc.WorkflowClient; @@ -24,5 +25,6 @@ public void init() { taskClient = new TaskClient("localhost", 8092); workflowClient = new WorkflowClient("localhost", 8092); metadataClient = new MetadataClient("localhost", 8092); + eventClient = new EventClient("localhost", 8092); } } diff --git a/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/mysql/MySQLGrpcEndToEndTest.java b/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/mysql/MySQLGrpcEndToEndTest.java index 5af65fa177..45b879a40f 100644 --- a/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/mysql/MySQLGrpcEndToEndTest.java +++ b/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/mysql/MySQLGrpcEndToEndTest.java @@ -12,6 +12,7 @@ */ package com.netflix.conductor.test.integration.grpc.mysql; +import com.netflix.conductor.client.grpc.EventClient; import com.netflix.conductor.client.grpc.MetadataClient; import com.netflix.conductor.client.grpc.TaskClient; import com.netflix.conductor.client.grpc.WorkflowClient; @@ -38,5 +39,6 @@ public void init() { taskClient = new TaskClient("localhost", 8094); workflowClient = new WorkflowClient("localhost", 8094); metadataClient = new MetadataClient("localhost", 8094); + eventClient = new EventClient("localhost", 8094); } } diff --git a/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/postgres/PostgresGrpcEndToEndTest.java b/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/postgres/PostgresGrpcEndToEndTest.java index d5e365531b..e820e71e33 100644 --- a/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/postgres/PostgresGrpcEndToEndTest.java +++ b/test-harness/src/test/java/com/netflix/conductor/test/integration/grpc/postgres/PostgresGrpcEndToEndTest.java @@ -12,6 +12,7 @@ */ package com.netflix.conductor.test.integration.grpc.postgres; +import com.netflix.conductor.client.grpc.EventClient; import com.netflix.conductor.client.grpc.MetadataClient; import com.netflix.conductor.client.grpc.TaskClient; import com.netflix.conductor.client.grpc.WorkflowClient; @@ -38,5 +39,6 @@ public void init() { taskClient = new TaskClient("localhost", 8098); workflowClient = new WorkflowClient("localhost", 8098); metadataClient = new MetadataClient("localhost", 8098); + eventClient = new EventClient("localhost", 8098); } } diff --git a/test-harness/src/test/java/com/netflix/conductor/test/integration/http/AbstractHttpEndToEndTest.java b/test-harness/src/test/java/com/netflix/conductor/test/integration/http/AbstractHttpEndToEndTest.java index a2b622aaab..18cafc6c73 100644 --- a/test-harness/src/test/java/com/netflix/conductor/test/integration/http/AbstractHttpEndToEndTest.java +++ b/test-harness/src/test/java/com/netflix/conductor/test/integration/http/AbstractHttpEndToEndTest.java @@ -18,9 +18,11 @@ import static org.junit.Assert.assertTrue; import com.netflix.conductor.client.exception.ConductorClientException; +import com.netflix.conductor.client.http.EventClient; import com.netflix.conductor.client.http.MetadataClient; import com.netflix.conductor.client.http.TaskClient; import com.netflix.conductor.client.http.WorkflowClient; +import com.netflix.conductor.common.metadata.events.EventHandler; import com.netflix.conductor.common.metadata.tasks.Task; import com.netflix.conductor.common.metadata.tasks.Task.Status; import com.netflix.conductor.common.metadata.tasks.TaskDef; @@ -38,6 +40,7 @@ import com.netflix.conductor.test.integration.AbstractEndToEndTest; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; import org.junit.Test; @@ -61,6 +64,7 @@ public abstract class AbstractHttpEndToEndTest extends AbstractEndToEndTest { protected static TaskClient taskClient; protected static WorkflowClient workflowClient; protected static MetadataClient metadataClient; + protected static EventClient eventClient; @Override protected String startWorkflow(String workflowExecutionName, WorkflowDef workflowDefinition) { @@ -86,6 +90,21 @@ protected void registerTaskDefinitions(List taskDefinitionList) { metadataClient.registerTaskDefs(taskDefinitionList); } + @Override + protected void registerWorkflowDefinition(WorkflowDef workflowDefinition) { + metadataClient.registerWorkflowDef(workflowDefinition); + } + + @Override + protected void registerEventHandler(EventHandler eventHandler) { + eventClient.registerEventHandler(eventHandler); + } + + @Override + protected Iterator getEventHandlers(String event, boolean activeOnly) { + return eventClient.getEventHandlers(event, activeOnly).iterator(); + } + @Test public void testAll() throws Exception { createAndRegisterTaskDefinitions("t", 5); diff --git a/test-harness/src/test/java/com/netflix/conductor/test/integration/http/HttpEndToEndTest.java b/test-harness/src/test/java/com/netflix/conductor/test/integration/http/HttpEndToEndTest.java index 5c4a3e4ab3..4c6d5b3e6c 100644 --- a/test-harness/src/test/java/com/netflix/conductor/test/integration/http/HttpEndToEndTest.java +++ b/test-harness/src/test/java/com/netflix/conductor/test/integration/http/HttpEndToEndTest.java @@ -12,11 +12,15 @@ */ package com.netflix.conductor.test.integration.http; +import com.netflix.conductor.client.http.EventClient; import com.netflix.conductor.client.http.MetadataClient; import com.netflix.conductor.client.http.TaskClient; import com.netflix.conductor.client.http.WorkflowClient; +import com.netflix.conductor.common.metadata.events.EventHandler; import org.junit.Before; +import java.util.Iterator; + public class HttpEndToEndTest extends AbstractHttpEndToEndTest { @Before @@ -31,5 +35,8 @@ public void init() { metadataClient = new MetadataClient(); metadataClient.setRootURI(apiRoot); + + eventClient = new EventClient(); + eventClient.setRootURI(apiRoot); } }