Skip to content

Commit 57aa03e

Browse files
authored
closes #80 prepare demo for mule to boot migration (#81)
1 parent 943e64b commit 57aa03e

File tree

21 files changed

+346
-4
lines changed

21 files changed

+346
-4
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Adds
44
- Unmarshalling ejb-jar.xml for EJB 2.1 (#62)
5+
- Demo for Mule to Boot migration (#80)
56

67
### Fixes
78
- Paths and CLI rendering under Windows (#58)

components/sbm-core/src/main/java/org/springframework/sbm/engine/precondition/PreconditionCheck.java

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
public abstract class PreconditionCheck {
2626

27-
private ResultState resultState;
28-
2927
public abstract PreconditionCheckResult verify(Path projectRoot, List<Resource> projectResources);
3028

3129
public enum ResultState {

components/sbm-core/src/main/java/org/springframework/sbm/engine/recipe/AbstractAction.java

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.sbm.engine.recipe;
1717

18+
import com.fasterxml.jackson.annotation.JsonIgnore;
1819
import lombok.AllArgsConstructor;
1920
import lombok.Getter;
2021
import lombok.NoArgsConstructor;
@@ -38,6 +39,7 @@ public abstract class AbstractAction implements Action {
3839
private Condition condition = Condition.TRUE;
3940

4041
@Autowired
42+
@JsonIgnore
4143
@Getter
4244
private ApplicationEventPublisher eventPublisher;
4345

components/sbm-support-weblogic/src/test/java/org/springframework/sbm/jee/wls/actions/MigrateWlsEjbDeploymentDescriptorTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.springframework.sbm.jee.wls.actions;
1717

1818
import org.junit.jupiter.api.Test;
19+
import org.springframework.context.ApplicationEventPublisher;
1920
import org.springframework.sbm.GitHubIssue;
2021
import org.springframework.sbm.engine.context.ProjectContext;
2122
import org.springframework.sbm.jee.wls.JeeWlsEjbJarProjectResourceRegistrar;
@@ -24,6 +25,7 @@
2425
import java.nio.file.Path;
2526

2627
import static org.assertj.core.api.Assertions.assertThat;
28+
import static org.mockito.Mockito.mock;
2729

2830
class MigrateWlsEjbDeploymentDescriptorTest {
2931
@Test
@@ -93,6 +95,7 @@ void shouldAddTransactionalAnnotationAndTimeoutIfAnnotationDoesNotExist() {
9395

9496

9597
MigrateWlsEjbDeploymentDescriptor sut = new MigrateWlsEjbDeploymentDescriptor();
98+
sut.setEventPublisher(mock(ApplicationEventPublisher.class));
9699
sut.apply(projectContext);
97100

98101
String resultingJavaSource = projectContext.getProjectJavaSources().list().get(0).getResource().print();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
testcode/result/*
2+
/**/.git
3+
/.rewrite-cache/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
= Migrate Mule 3.9 to Spring Integration
2+
3+
== Introduction
4+
5+
This demo shows how SBM can be used to migrate a https://docs.mulesoft.com/release-notes/mule-runtime/mule-3.9.0-release-notes[Mule 3.9]
6+
application to Spring Integration by applying recipe `migrate-mule-to-boot`.
7+
8+
=== Requirements
9+
10+
The demo was created on Mac OS but should run under Windows with a shell too.
11+
12+
- JDK 11
13+
- Maven
14+
- Docker
15+
- IntelliJ (can be changed)
16+
17+
== The Demo
18+
19+
A Mulesoft application with one flow using `http:listener` and `amqp:outbound-endpoint` gets migrated to Spring Integration.
20+
The migrated application provides a REST endpoint that sends a message received as POST request to a RabbitMQ queue.
21+
22+
=== Run the demo
23+
24+
* Call the `run-demo.sh` shell script to ru the full demo +
25+
`./run-demo.sh`
26+
27+
The script
28+
29+
* Moves all resources from `testcode/given`
30+
* Initializes Git repository in the project to migrate
31+
* Uses `docker-compose` to start a RabbitMQ instance with `sales_queue` configured
32+
* Waits, and proceeds on `enter`
33+
* Runs the migration by applying the commands in `commands.txt` (`initalize-spring-boot-migration`, `migrate-mule-to-boot`)
34+
* Opens IntelliJ IDEA +
35+
Under `Git/Log` in IntelliJ you should be able to find the commits for the applied recipes and compare the applied changes.
36+
37+
image::media/intellij-git-perspective.png[]
38+
39+
You can select the commits to compare
40+
41+
image::media/intellij-git-compare-commit.png[]
42+
43+
image::media/intellij-git-compare-commit-2.png[]
44+
45+
image::media/intellij-git-compare-commit-3.png[]
46+
47+
* Builds the migrated application +
48+
You'll need to exit the application manually using `Ctrl + c` as the `exit` is currently broken (v0.10.0)
49+
* Waits, and proceeds on `enter`
50+
* Starts the migrated application +
51+
The application is started in the background and console output can be found in `./application.log`
52+
* Find the URL for the RabbitMQ console in console output, verify no message exists
53+
* Waits, and proceeds on `enter`
54+
* Sends a message to the REST endpoint +
55+
`curl --location --request POST 'http://localhost:8081/' --header 'Content-Type: text/plain' --data-raw '{"hello": "from mule spring world"}'`
56+
* Waits, and proceeds on `enter`, this lets you verify one message was sent
57+
* The message can be checked in the http://localhost:15672/#/queues/%2F/sales_queue[RabbiMQ console] +
58+
**You might have to refresh the browser few times (or wait few seconds)**
59+
* Waits, and proceeds on `enter`
60+
* shuts down the application
61+
* performs clean up
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
s ./testcode/result/spring-amqp-mule
2+
a initialize-spring-boot-migration
3+
a migrate-mule-to-boot
4+
exit
Loading
Loading
Loading
Loading
+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/bin/sh
2+
3+
#
4+
# Copyright 2021 - 2022 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
scriptDir=$(dirname "${BASH_SOURCE[0]}")
19+
resultDir="$scriptDir/testcode/result"
20+
resultAppDir="$resultDir/spring-amqp-mule"
21+
sbmRootDir="$scriptDir/../.."
22+
23+
24+
function pause(){
25+
echo "=============================================================================================="
26+
echo " -> $*"
27+
echo " Press Enter to continue..."
28+
read -p "=============================================================================================="
29+
}
30+
31+
function stopApplication() {
32+
PID=$(ps -ef | grep .jar | grep -v grep | awk '{ print $2 }')
33+
if [ -z "$PID" ]
34+
then
35+
echo Application is already stopped
36+
else
37+
echo kill $PID
38+
kill $PID
39+
fi
40+
}
41+
42+
function cleanup() {
43+
rm -rf $resultDir
44+
mkdir $resultDir
45+
}
46+
47+
echo "clean up..."
48+
cleanup
49+
50+
echo "prepare demo..."
51+
cp -R ./testcode/given/* $resultDir
52+
53+
echo "start infrastructure..."
54+
docker-compose -f $resultDir/docker-compose.yaml stop && docker-compose -f $resultDir/docker-compose.yaml rm -f
55+
docker-compose -f $resultDir/docker-compose.yaml rm -v
56+
docker-compose -f $resultDir/docker-compose.yaml up -d --no-recreate
57+
58+
echo "init git..."
59+
pushd $resultAppDir
60+
git init .
61+
git add .
62+
git commit -am "initial commit"
63+
popd
64+
65+
echo "build SBM..."
66+
pushd $sbmRootDir
67+
mvn clean package -DskipTests
68+
popd
69+
70+
pause "start migration"
71+
72+
echo "start migration..."
73+
java -jar $sbmRootDir/applications/spring-shell/target/spring-boot-migrator.jar @commands.txt
74+
75+
echo "build migrated application..."
76+
pushd $resultAppDir
77+
mvn clean package
78+
mvn package spring-boot:repackage
79+
idea .
80+
popd
81+
82+
pause "start migrated application"
83+
84+
echo "start migrated spring boot application..."
85+
nohup java -jar $resultAppDir/target/hellomule-migrated-1.0-SNAPSHOT.jar >./application.log &
86+
87+
echo "Open RabbitMQ console and verify no messages exist: http://localhost:15672/#/queues/%2F/sales_queue"
88+
89+
pause "send message to REST endpoint"
90+
91+
# call migrated application
92+
curl --location --request POST 'http://localhost:8081/' --header 'Content-Type: text/plain' --data-raw '{"hello": "from mule spring world"}'
93+
94+
pause "Verify the messages was sent: http://localhost:15672/#/queues/%2F/sales_queue"
95+
96+
pause "shutdown"
97+
98+
echo "shutdown and cleanup..."
99+
100+
stopApplication
101+
102+
# shutdown infrastructure
103+
docker-compose -f $resultDir/docker-compose.yaml stop && docker-compose -f $resultDir/docker-compose.yaml rm -f
104+
docker-compose -f $resultDir/docker-compose.yaml rm -vs
105+
106+
cleanup
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3.3'
2+
3+
services:
4+
rabbitmq:
5+
image: rabbitmq:3-management
6+
container_name: rabbitmq
7+
restart: always
8+
ports:
9+
- "15672:15672"
10+
- "5672:5672"
11+
volumes:
12+
- ./init/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
13+
- ./init/definitions.json:/etc/rabbitmq/definitions.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"queues": [
3+
{
4+
"name": "sales_queue",
5+
"vhost": "/",
6+
"durable": true,
7+
"auto_delete": false,
8+
"arguments": {
9+
"x-queue-type": "classic"
10+
}
11+
}
12+
],
13+
"exchanges": [
14+
{
15+
"name": "sales_exchange",
16+
"vhost": "/",
17+
"type": "direct",
18+
"durable": true,
19+
"auto_delete": false,
20+
"internal": false,
21+
"arguments": {}
22+
}
23+
],
24+
"bindings": [
25+
{
26+
"source": "sales_exchange",
27+
"vhost": "/",
28+
"destination": "sales_queue",
29+
"destination_type": "queue",
30+
"routing_key": "sales_queue",
31+
"arguments": {}
32+
}
33+
]
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
management.load_definitions = /etc/rabbitmq/definitions.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
!**/src/main/**/build/
30+
!**/src/test/**/build/
31+
32+
### VS Code ###
33+
.vscode/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2021 - 2022 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>org.example</groupId>
24+
<artifactId>hellomule-migrated</artifactId>
25+
<version>1.0-SNAPSHOT</version>
26+
27+
<properties>
28+
<maven.compiler.source>11</maven.compiler.source>
29+
<maven.compiler.target>11</maven.compiler.target>
30+
</properties>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.junit.jupiter</groupId>
35+
<artifactId>junit-jupiter-api</artifactId>
36+
<version>5.8.2</version>
37+
</dependency>
38+
</dependencies>
39+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.example.javadsl;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
5+
@Configuration
6+
public class Foo {
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<mule xmlns:amqp="http://www.mulesoft.org/schema/mule/amqp" xmlns:http="http://www.mulesoft.org/schema/mule/http"
4+
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
7+
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
8+
http://www.mulesoft.org/schema/mule/amqp http://www.mulesoft.org/schema/mule/amqp/current/mule-amqp.xsd">
9+
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
10+
<amqp:connector name="AMQP_0_9_Connector" validateConnections="true" doc:name="AMQP-0-9 Connector"/>
11+
<flow name="json-to-rabbitmqFlow">
12+
<http:listener config-ref="HTTP_Listener_Configuration" path="/" allowedMethods="POST" doc:name="Recieve HTTP request"/>
13+
<logger message="payload to be sent: #[new String(payload)]" level="INFO" doc:name="Log the message content to be sent"/>
14+
<amqp:outbound-endpoint exchangeName="sales_exchange" queueName="sales_queue" responseTimeout="10000" doc:name="Send to AMQP queue"/>
15+
</flow>
16+
</mule>

0 commit comments

Comments
 (0)