Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Add a workflow task that sends a message to topic in TIBCO
Browse files Browse the repository at this point in the history
FLPATH-145 https://issues.redhat.com/browse/FLPATH-145

Signed-off-by: Yaron Dayagi <ydayagi@redhat.com>
  • Loading branch information
ydayagi committed Mar 20, 2023
1 parent 48ade40 commit 1b60873
Show file tree
Hide file tree
Showing 12 changed files with 496 additions and 2 deletions.
10 changes: 10 additions & 0 deletions external-dependencies/download-tibco.sh
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 .
60 changes: 60 additions & 0 deletions external-dependencies/pom.xml
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>
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
<module>notification-service</module>
<module>pattern-detection-library</module>
<module>coverage</module>
<module>prebuilt-tasks</module>
<module>external-dependencies</module>
</modules>
<build>
<pluginManagement>
Expand Down
65 changes: 65 additions & 0 deletions prebuilt-tasks/pom.xml
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>
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);
}
}
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;

}
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);
}

}
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;
}
}
18 changes: 16 additions & 2 deletions workflow-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ the 'workflow-service' will explain how to execute the workflow.
In this version of Parodos, Workflow projects are Java project. All configuration is done using the Spring Framework.
These samples are built with Maven, however Gradle could also be used.

The examples in this project can be found in two different packages.
These are the examples in this project:

### Simple

Expand All @@ -23,6 +23,10 @@ Parallel workflows.
This package shows how to work with WorkflowTasks that create a manual process that needs to be monitored before further
WorkFlowTasks can be created. In this project WorkflowCheckers and other related concepts are created and configured.

### TIBCO

A workflow configuration that demonstrates use of TibcoWorkflowTask

## Compiling The Code

To get the Parodos dependencies you will need to run a maven install from the **root** of the project folder. This will
Expand All @@ -42,10 +46,15 @@ Once the Jar has been compiled, ensure it's added to the pom.xml of the workflow
```xml

<dependency>
<groupId>com.redhat.parodos</groupId>
<groupId>dev.parodos</groupId>
<artifactId>workflow-examples</artifactId>
<version>${parodos.version}</version>
</dependency>
<dependency>
<groupId>dev.parodos</groupId>
<artifactId>tasks</artifactId>
<version>${revision}</version>
</dependency>


```
Expand Down Expand Up @@ -353,6 +362,11 @@ hours (or even days). As all state is persisted, when the workflow-service is re

WorkflowCheckers can be used to determine if required manual processes, outside the scope of Parodos, have completed.

### TIBCO workflow

'TibcoWorkFlowConfiguration.java' is the workflow code. You'll find details inside the file.
Use the script 'run_tibco.sh' to execute the workflow.

#### A Note On Defining WorkflowTasks for Usage In A Workflow

***Creating a Single Instance Of The Same Workflow Tasks***
Expand Down
6 changes: 6 additions & 0 deletions workflow-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>dev.parodos</groupId>
<artifactId>prebuilt-tasks</artifactId>
<version>${revision}</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Loading

0 comments on commit 1b60873

Please sign in to comment.