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

Add a workflow task that sends a message to topic in TIBCO #123

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

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)

Copy link
Contributor Author

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?

Copy link
Collaborator

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?

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>external-dependencies</module>
masayag marked this conversation as resolved.
Show resolved Hide resolved
<module>prebuilt-tasks</module>
</modules>
<build>
<pluginManagement>
Expand Down
59 changes: 59 additions & 0 deletions prebuilt-tasks/pom.xml
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>
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);
}

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

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

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

}
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>prebuilt-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
Loading