This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Add a workflow task that sends a message to topic in TIBCO #123
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,10 @@ | ||
#!/bin/bash | ||
if [ -f "tibjms.jar" ]; then exit 0; fi | ||
rm -rf /tmp/tibco | ||
mkdir /tmp/tibco | ||
curl -s -o /tmp/tibco/tibco.zip "https://edownloads.tibco.com/Installers/tap/EMS-CE/10.2.1/TIB_ems-ce_10.2.1_linux_x86_64.zip?SJCDPTPG=1681227113_1e3fe1f60cbbe9ee810af68e0b4256bb&ext=.zip" | ||
cd /tmp/tibco | ||
unzip tibco.zip TIB_ems-ce_10.2.1/tar/TIB_ems-ce_10.2.1_linux_x86_64-java_client.tar.gz | ||
tar -zxf TIB_ems-ce_10.2.1/tar/TIB_ems-ce_10.2.1_linux_x86_64-java_client.tar.gz opt/tibco/ems/10.2/lib/tibjms.jar | ||
cd - | ||
cp /tmp/tibco/opt/tibco/ems/10.2/lib/tibjms.jar . |
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,60 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>dev.parodos</groupId> | ||
<artifactId>parados-parent</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>external-dependencies</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>3.1.0</version> | ||
<executions> | ||
<execution> | ||
<id>download-tibco</id> | ||
<goals><goal>exec</goal></goals> | ||
<phase>clean</phase> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<executable>${project.basedir}/download-tibco.sh</executable> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.4</version> | ||
<configuration> | ||
<groupId>com.tibco</groupId> | ||
<artifactId>tibjms</artifactId> | ||
<version>10.2</version> | ||
<file>${project.basedir}/tibjms.jar</file> | ||
<packaging>jar</packaging> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>install_tibco</id> | ||
<goals> | ||
<goal>install-file</goal> | ||
</goals> | ||
<phase>clean</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>dev.parodos</groupId> | ||
<artifactId>parados-parent</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>prebuilt-tasks</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>dev.parodos</groupId> | ||
<artifactId>external-dependencies</artifactId> | ||
<version>${revision}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.24</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>dev.parodos</groupId> | ||
<artifactId>parodos-model-api</artifactId> | ||
<version>${revision}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.jms</groupId> | ||
<artifactId>jakarta.jms-api</artifactId> | ||
<version>2.0.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.tibco</groupId> | ||
<artifactId>tibjms</artifactId> | ||
<version>10.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.13.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<version>3.9.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
74 changes: 74 additions & 0 deletions
74
prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/tibco/TibcoWorkFlowTask.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,74 @@ | ||
package com.redhat.parodos.tasks.tibco; | ||
|
||
import com.redhat.parodos.workflow.task.BaseWorkFlowTask; | ||
import com.redhat.parodos.workflow.task.WorkFlowTaskOutput; | ||
import com.redhat.parodos.workflow.task.parameter.WorkFlowTaskParameter; | ||
import com.redhat.parodos.workflow.task.parameter.WorkFlowTaskParameterType; | ||
import com.redhat.parodos.workflows.work.DefaultWorkReport; | ||
import com.redhat.parodos.workflows.work.WorkContext; | ||
import com.redhat.parodos.workflows.work.WorkReport; | ||
import com.redhat.parodos.workflows.work.WorkStatus; | ||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
@Slf4j | ||
public class TibcoWorkFlowTask extends BaseWorkFlowTask { | ||
|
||
private final Tibjms service; | ||
|
||
private final String url; | ||
|
||
private final String caFile; | ||
|
||
private final String username; | ||
|
||
private final String password; | ||
|
||
public TibcoWorkFlowTask(String url, String caFile, String username, String password) { | ||
this(new TibjmsImpl(), url, username, password, caFile); | ||
} | ||
|
||
TibcoWorkFlowTask(Tibjms service, String url, String caFile, String username, String password) { | ||
this.service = service; | ||
this.url = url; | ||
this.caFile = caFile; | ||
this.username = username; | ||
this.password = password; | ||
} | ||
|
||
@Override | ||
public @NonNull List<WorkFlowTaskParameter> getWorkFlowTaskParameters() { | ||
LinkedList<WorkFlowTaskParameter> params = new LinkedList<WorkFlowTaskParameter>(); | ||
params.add(WorkFlowTaskParameter.builder().key("topic").type(WorkFlowTaskParameterType.TEXT).optional(false) | ||
.description("Topic to send to").build()); | ||
params.add(WorkFlowTaskParameter.builder().key("message").type(WorkFlowTaskParameterType.TEXT).optional(false) | ||
.description("Message to send to topic").build()); | ||
return params; | ||
} | ||
|
||
@Override | ||
public @NonNull List<WorkFlowTaskOutput> getWorkFlowTaskOutputs() { | ||
return List.of(WorkFlowTaskOutput.OTHER); | ||
} | ||
|
||
@Override | ||
public WorkReport execute(WorkContext workContext) { | ||
try { | ||
String topic = getParameterValue(workContext, "topic"); | ||
String message = getParameterValue(workContext, "message"); | ||
|
||
service.sendMessage(url, caFile, username, password, topic, message); | ||
|
||
} | ||
catch (Exception e) { | ||
log.error("TIBCO task failed", e); | ||
return new DefaultWorkReport(WorkStatus.FAILED, workContext, e); | ||
} | ||
|
||
return new DefaultWorkReport(WorkStatus.COMPLETED, workContext); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/tibco/Tibjms.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,8 @@ | ||
package com.redhat.parodos.tasks.tibco; | ||
|
||
public interface Tibjms { | ||
masayag marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public void sendMessage(String url, String caFile, String username, String password, String topic, String message) | ||
throws javax.jms.JMSException; | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/tibco/TibjmsImpl.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,30 @@ | ||
package com.redhat.parodos.tasks.tibco; | ||
|
||
import com.tibco.tibjms.TibjmsConnectionFactory; | ||
|
||
import javax.jms.JMSException; | ||
import javax.jms.Connection; | ||
import javax.jms.Destination; | ||
import javax.jms.Session; | ||
import javax.jms.MessageProducer; | ||
import javax.jms.TextMessage; | ||
|
||
public class TibjmsImpl implements Tibjms { | ||
|
||
@Override | ||
public void sendMessage(String url, String caFile, String username, String password, String topic, String message) | ||
throws JMSException { | ||
TibjmsConnectionFactory factory = new TibjmsConnectionFactory(url); | ||
if (!caFile.isEmpty()) { | ||
factory.setSSLTrustedCertificate(caFile); | ||
} | ||
try (Connection connection = factory.createConnection(username, password); | ||
Session session = connection.createSession(javax.jms.Session.AUTO_ACKNOWLEDGE);) { | ||
Destination destination = session.createTopic(topic); | ||
MessageProducer producer = session.createProducer(destination); | ||
TextMessage textMessage = session.createTextMessage(message); | ||
producer.send(textMessage); | ||
} | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/tibco/TibcoWorkFlowTaskTest.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,81 @@ | ||
package com.redhat.parodos.tasks.tibco; | ||
|
||
import com.redhat.parodos.workflow.context.WorkContextDelegate; | ||
import com.redhat.parodos.workflow.exception.MissingParameterException; | ||
import com.redhat.parodos.workflows.work.WorkContext; | ||
import com.redhat.parodos.workflows.work.WorkReport; | ||
import com.redhat.parodos.workflows.work.WorkStatus; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import javax.jms.JMSException; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class TibcoWorkFlowTaskTest { | ||
|
||
private final static String caFile = "/cafile"; | ||
|
||
private final static String url = "ssl://localhost:7222"; | ||
|
||
private final static String username = "username"; | ||
|
||
private final static String passowrd = "password"; | ||
|
||
private final static String topic = "topic"; | ||
|
||
private final static String message = "test message"; | ||
|
||
private final static Tibjms tibjms = Mockito.mock(Tibjms.class); | ||
|
||
private final static TibcoWorkFlowTask task = new TibcoWorkFlowTask(tibjms, url, caFile, username, passowrd); | ||
|
||
@Before | ||
public void setUp() { | ||
task.setBeanName("Test"); | ||
} | ||
|
||
@Test | ||
public void executeMissingParameter() { | ||
WorkContext ctx = getWorkContext(false); | ||
WorkReport result = task.execute(ctx); | ||
assertEquals(WorkStatus.FAILED, result.getStatus()); | ||
assertEquals(MissingParameterException.class, result.getError().getClass()); | ||
} | ||
|
||
@Test | ||
public void executeErrorInTibco() throws JMSException { | ||
WorkContext ctx = getWorkContext(true); | ||
doThrow(JMSException.class).when(tibjms).sendMessage(any(), any(), any(), any(), any(), any()); | ||
WorkReport result = task.execute(ctx); | ||
assertEquals(WorkStatus.FAILED, result.getStatus()); | ||
assertEquals(JMSException.class, result.getError().getClass()); | ||
} | ||
|
||
@Test | ||
public void executeSuccess() throws JMSException { | ||
WorkContext ctx = getWorkContext(true); | ||
WorkReport result = task.execute(ctx); | ||
assertEquals(WorkStatus.COMPLETED, result.getStatus()); | ||
verify(tibjms, times(1)).sendMessage(url, caFile, username, passowrd, topic, message); | ||
} | ||
|
||
private WorkContext getWorkContext(boolean withParams) { | ||
WorkContext ctx = new WorkContext(); | ||
HashMap<String, String> map = new HashMap<>(); | ||
if (withParams) { | ||
map.put("topic", topic); | ||
map.put("message", message); | ||
} | ||
|
||
WorkContextDelegate.write(ctx, WorkContextDelegate.ProcessType.WORKFLOW_TASK_EXECUTION, task.getName(), | ||
WorkContextDelegate.Resource.ARGUMENTS, map); | ||
return ctx; | ||
} | ||
|
||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe
mktemp -d tibco-XXX
?(just in case there are few build processes running on the same machine)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really? isn't each build in its own container?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. maybe @eloycoto knows?