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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a workflow task that sends a message to topic in TIBCO
FLPATH-145 https://issues.redhat.com/browse/FLPATH-145 Signed-off-by: Yaron Dayagi <ydayagi@redhat.com>
- Loading branch information
Showing
12 changed files
with
496 additions
and
2 deletions.
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,65 @@ | ||
<?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>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
<version>5.3.14</version> | ||
<scope>compile</scope> | ||
</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> |
73 changes: 73 additions & 0 deletions
73
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,73 @@ | ||
// @formatter:off | ||
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 com.tibco.tibjms.TibjmsConnectionFactory; | ||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
@Slf4j | ||
public class TibcoWorkFlowTask extends BaseWorkFlowTask { | ||
|
||
private Tibjms service; | ||
private String url; | ||
private String caFile; | ||
private String username; | ||
private 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() { | ||
List 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"); | ||
|
||
log.debug("sending to topic " + topic + " message: " + 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 { | ||
|
||
public void sendMessage(String url, String caFile, String username, String password, String topic, String message) | ||
throws javax.jms.JMSException; | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
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,24 @@ | ||
package com.redhat.parodos.tasks.tibco; | ||
|
||
import com.tibco.tibjms.TibjmsConnectionFactory; | ||
|
||
import javax.jms.*; | ||
|
||
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); | ||
} | ||
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); | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
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,75 @@ | ||
// @formatter:off | ||
package com.redhat.parodos.tasks.tibco; | ||
|
||
import com.redhat.parodos.tasks.tibco.TibcoWorkFlowTask; | ||
import com.redhat.parodos.tasks.tibco.Tibjms; | ||
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 { | ||
|
||
String caFile = "/cafile"; | ||
String url = "ssl://localhost:7222"; | ||
String username = "username"; | ||
String passowrd = "password"; | ||
String topic = "topic"; | ||
String message = "test message"; | ||
Tibjms tibjms = Mockito.mock(Tibjms.class); | ||
TibcoWorkFlowTask task = new TibcoWorkFlowTask(tibjms, url, caFile, username, passowrd); | ||
|
||
@Before | ||
public void before() { | ||
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(); | ||
Map map; | ||
if ( withParams == true ) { | ||
map = Map.of("topic",topic,"message",message); | ||
} else { | ||
map = new HashMap(); | ||
} | ||
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
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.