This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #905 from ZupIT/wf-listener-publish-implementation
add customized WorkflowStatusListener
- Loading branch information
Showing
6 changed files
with
332 additions
and
17 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
contribs/src/main/java/com/netflix/conductor/contribs/DynoQueueStatusPublisherModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.netflix.conductor.contribs; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.netflix.conductor.contribs.listener.DynoQueueStatusPublisher; | ||
import com.netflix.conductor.core.execution.WorkflowStatusListener; | ||
|
||
public class DynoQueueStatusPublisherModule extends AbstractModule { | ||
@Override | ||
protected void configure() { | ||
bind(WorkflowStatusListener.class).to(DynoQueueStatusPublisher.class); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
contribs/src/main/java/com/netflix/conductor/contribs/listener/DynoQueueStatusPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* Copyright 2016 Netflix, Inc. | ||
* | ||
* 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 com.netflix.conductor.contribs.listener; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.netflix.conductor.common.run.Workflow; | ||
import com.netflix.conductor.common.run.WorkflowSummary; | ||
import com.netflix.conductor.core.config.Configuration; | ||
import com.netflix.conductor.core.events.queue.Message; | ||
import com.netflix.conductor.core.execution.WorkflowStatusListener; | ||
import com.netflix.conductor.dao.QueueDAO; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.inject.Inject; | ||
import java.util.Collections; | ||
|
||
/** | ||
* Publishes a @see Message containing a @see WorkflowSummary to a DynoQueue on a workflow completion or termination event. | ||
*/ | ||
public class DynoQueueStatusPublisher implements WorkflowStatusListener { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(DynoQueueStatusPublisher.class); | ||
private final QueueDAO queueDAO; | ||
private final ObjectMapper objectMapper; | ||
private final Configuration config; | ||
private final String successStatusQueue; | ||
private final String failureStatusQueue; | ||
|
||
@Inject | ||
public DynoQueueStatusPublisher(QueueDAO queueDAO, ObjectMapper objectMapper, Configuration config) { | ||
this.queueDAO = queueDAO; | ||
this.objectMapper = objectMapper; | ||
this.config = config; | ||
this.successStatusQueue = config.getProperty("workflowstatuslistener.publisher.success.queue", "_callbackSuccessQueue"); | ||
this.failureStatusQueue = config.getProperty("workflowstatuslistener.publisher.failure.queue", "_callbackFailureQueue"); | ||
} | ||
|
||
@Override | ||
public void onWorkflowCompleted(Workflow workflow) { | ||
LOGGER.info("Publishing callback of workflow {} on completion ", workflow.getWorkflowId()); | ||
queueDAO.push(successStatusQueue, Collections.singletonList(workflowToMessage(workflow))); | ||
} | ||
|
||
@Override | ||
public void onWorkflowTerminated(Workflow workflow) { | ||
LOGGER.info("Publishing callback of workflow {} on termination", workflow.getWorkflowId()); | ||
queueDAO.push(failureStatusQueue, Collections.singletonList(workflowToMessage(workflow))); | ||
} | ||
|
||
private Message workflowToMessage(Workflow workflow) { | ||
String jsonWfSummary; | ||
WorkflowSummary summary = new WorkflowSummary(workflow); | ||
try { | ||
jsonWfSummary = objectMapper.writeValueAsString(summary); | ||
} catch (JsonProcessingException e) { | ||
LOGGER.error("Failed to convert WorkflowSummary: {} to String. Exception: {}", summary, e); | ||
throw new RuntimeException(e); | ||
} | ||
return new Message(workflow.getWorkflowId(), jsonWfSummary, null); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...harness/src/test/java/com/netflix/conductor/tests/listener/StatusPublisherTestRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright 2016 Netflix, Inc. | ||
* | ||
* 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 com.netflix.conductor.tests.listener; | ||
|
||
import com.google.inject.Guice; | ||
import com.google.inject.Injector; | ||
import com.google.inject.util.Modules; | ||
import com.netflix.conductor.contribs.DynoQueueStatusPublisherModule; | ||
import com.netflix.conductor.tests.utils.TestModule; | ||
import org.junit.runners.BlockJUnit4ClassRunner; | ||
|
||
public class StatusPublisherTestRunner extends BlockJUnit4ClassRunner { | ||
|
||
private Injector dependenciesInjector; | ||
|
||
static { | ||
System.setProperty("EC2_REGION", "us-east-1"); | ||
System.setProperty("EC2_AVAILABILITY_ZONE", "us-east-1c"); | ||
} | ||
|
||
|
||
public StatusPublisherTestRunner(Class<?> klass) throws Exception { | ||
super(klass); | ||
System.setProperty("workflow.namespace.prefix", "conductor" + System.getProperty("user.name")); | ||
dependenciesInjector = Guice.createInjector(Modules.override(new TestModule()).with(new DynoQueueStatusPublisherModule())); | ||
} | ||
|
||
@Override | ||
protected Object createTest() throws Exception { | ||
Object test = super.createTest(); | ||
dependenciesInjector.injectMembers(test); | ||
return test; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.