Skip to content

Commit caab9e0

Browse files
authored
Add support for generating code to send MuleSoft Dataweave Transformations to TriggerMesh (#183)
1 parent 04282f6 commit caab9e0

File tree

15 files changed

+919
-258
lines changed

15 files changed

+919
-258
lines changed

applications/spring-shell/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ spring.profiles.active=default, core
1818
spring.application.name=spring-boot-migrator
1919
# toggle support for git to sync and auto-commit
2020
sbm.gitSupportEnabled=true
21+
sbm.muleTriggerMeshTransformEnabled=true
2122
logging.level.org=ERROR
2223
logging.level.org.springframework.sbm.logging.MethodCallTraceInterceptor=DEBUG
2324
logging.level.org.springframework.sbm.logging.StopWatchTraceInterceptor=DEBUG

applications/spring-shell/src/main/resources/banner.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ Base Package: ${sbm.defaultBasePackage}
3838

3939
Use -Dsbm.defaultBasePackage=com.acme.packagename as VM parameter on startup to set the property.
4040

41+
TriggerMesh transformation support of Dataweave: ${sbm.muleTriggerMeshTransformEnabled}
42+
43+
- When applying the mule-to-boot recipe, use `sbm.muleTriggerMeshTransformEnabled` to
44+
generate the code required to send the Dataweave transformation to TriggerMesh using
45+
the TriggerMesh Dataweave transformation service (https://docs.triggermesh.io/guides/dataweavetransformation/).
46+
- This will require a TriggerMesh transformation exist on your Kubernetes cluster to function. When running the
47+
service, be sure to set the `K_SINK` environment variable to your exposed service URL.
48+
49+
Use -Dsbm.muleTriggerMeshTransformEnabled=true|false as VM parameter on startup to set property.
4150

4251
Get Started:
4352
------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.sbm;
17+
18+
import org.junit.jupiter.api.*;
19+
import org.springframework.http.HttpStatus;
20+
import org.springframework.http.ResponseEntity;
21+
import org.springframework.web.client.RestTemplate;
22+
23+
import java.util.*;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
class MigrateSimpleMuleAppDataweaveIntegrationTest extends IntegrationTestBaseClass {
28+
private final RestTemplate restTemplate = new RestTemplate();
29+
private static RunningNetworkedContainer tmDataweaveContainer;
30+
31+
@Override
32+
protected String getTestSubDir() {
33+
34+
return "mule-app/spring-dw-mule";
35+
36+
}
37+
38+
@BeforeAll
39+
public static void beforeAll() {
40+
IntegrationTestBaseClass.beforeAll();
41+
42+
// Will need to ensure this is set globally for the test
43+
System.setProperty("sbm.muleTriggerMeshTransformEnabled", "true");
44+
45+
// start TriggerMesh Dataweave Translator
46+
HashMap<String, String> envMap = new HashMap<>();
47+
envMap.put("NAMESPACE", "default");
48+
envMap.put("DATAWEAVETRANSFORMATION_ALLOW_SPELL_OVERRIDE", "true");
49+
50+
tmDataweaveContainer = startDockerContainer(
51+
new NetworkedContainer(
52+
"gcr.io/triggermesh/dataweavetransformation-adapter:v1.21.0",
53+
List.of(8080),
54+
"dwhost"),
55+
null,
56+
envMap);
57+
if (!tmDataweaveContainer.getContainer().isRunning()) {
58+
throw new RuntimeException("TriggerMesh Dataweave Transformer container could not be started");
59+
}
60+
}
61+
62+
@AfterAll
63+
public static void afterAll() {
64+
if (tmDataweaveContainer != null && tmDataweaveContainer.getContainer() != null) {
65+
tmDataweaveContainer.getContainer().stop();
66+
}
67+
}
68+
69+
@Test
70+
@Tag("integration")
71+
public void t2_dataweaveIntegrationWorks() {
72+
intializeTestProject();
73+
scanProject();
74+
applyRecipe("initialize-spring-boot-migration");
75+
applyRecipe("migrate-mule-to-triggermesh-boot");
76+
77+
executeMavenGoals(getTestDir(), "clean", "package", "spring-boot:build-image");
78+
79+
int dwPort = tmDataweaveContainer.getContainer().getMappedPort(8080);
80+
HashMap<String, String> runtimeEnv = new HashMap<>();
81+
runtimeEnv.put("K_SINK", "http://dwhost:8080");
82+
83+
RunningNetworkedContainer container = startDockerContainer(
84+
new NetworkedContainer("hellomuledw-migrated:1.0-SNAPSHOT", List.of(9081), "spring"),
85+
tmDataweaveContainer.getNetwork(),
86+
runtimeEnv);
87+
88+
checkSendHttpMessage(container.getContainer().getMappedPort(9081));
89+
checkTranslatedInboundGatewayHttpMessage(container.getContainer().getMappedPort(9081));
90+
}
91+
92+
private void checkTranslatedInboundGatewayHttpMessage(int port) {
93+
ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://localhost:" + port + "/dwtest", String.class);
94+
95+
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
96+
assertThat(responseEntity.getBody()).isEqualTo("\n{\n \"greeting\": \"hello from SBM\"\n}");
97+
}
98+
99+
private void checkSendHttpMessage(int port) {
100+
ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://localhost:" + port + "/test", String.class);
101+
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
102+
}
103+
}
Lines changed: 33 additions & 0 deletions
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/
Lines changed: 39 additions & 0 deletions
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>hellomuledw-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,32 @@
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+
<mule xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core"
18+
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
20+
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
21+
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/ee/dw">
22+
<flow name="get:/dwtest:dwtest-config">
23+
<dw:transform-message doc:name="Transform Message">
24+
<dw:set-payload><![CDATA[%dw 2.0
25+
output application/json
26+
---
27+
greeting: "hello from SBM"
28+
]]>
29+
</dw:set-payload>
30+
</dw:transform-message>
31+
</flow>
32+
</mule>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
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+
19+
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
20+
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
23+
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
24+
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="9081" doc:name="HTTP Listener Configuration"/>
25+
<flow name="http-flow">
26+
<http:listener doc:name="Listener" doc:id="9f602d5c-5386-4fc9-ac8f-024d754c17e5" config-ref="HTTP_Listener_Configuration" path="/test"/>
27+
<logger level="INFO" doc:name="Logger" doc:id="4585ec7f-2d4a-4d86-af24-b678d4a99227" />
28+
</flow>
29+
</mule>

components/sbm-core/src/main/java/org/springframework/sbm/project/resource/SbmApplicationProperties.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
@ConfigurationProperties(prefix = "sbm")
3131
public class SbmApplicationProperties {
3232
private boolean gitSupportEnabled;
33+
private boolean muleTriggerMeshTransformEnabled;
3334
private String defaultBasePackage;
3435
private boolean writeInMavenLocal;
3536
private boolean javaParserLoggingCompilationWarningsAndErrors;

components/sbm-core/src/main/resources/application-core.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
# toggle support for git to sync and auto-commit
2020
sbm.gitSupportEnabled=true
21+
# toggle support to use TriggerMesh for dataweave transformations
22+
sbm.muleTriggerMeshTransformEnabled=false
2123
# default base package when adding classes and no base package can be calculated
2224
sbm.defaultBasePackage=org.springframework.sbm
2325
# default groupId when creating a new build file

components/sbm-recipes-mule-to-boot/src/main/java/org/springframework/sbm/mule/MigrateMuleToBoot.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.sbm.mule;
1717

18+
import lombok.RequiredArgsConstructor;
1819
import org.springframework.beans.factory.annotation.Autowired;
1920
import org.springframework.context.annotation.Bean;
2021
import org.springframework.context.annotation.Configuration;
@@ -30,23 +31,34 @@
3031
import org.springframework.sbm.java.migration.conditions.HasTypeAnnotation;
3132
import org.springframework.sbm.mule.actions.JavaDSLAction2;
3233
import org.springframework.sbm.mule.conditions.MuleConfigFileExist;
34+
import org.springframework.sbm.project.resource.SbmApplicationProperties;
3335

3436
import java.util.List;
3537

38+
@RequiredArgsConstructor
3639
@Configuration
3740
public class MigrateMuleToBoot {
41+
private final SbmApplicationProperties sbmProperties;
3842

3943
@Autowired
4044
private JavaDSLAction2 javaDSLAction2;
4145

42-
4346
@Bean
4447
public Recipe muleRecipe() {
48+
String name = "migrate-mule-to-boot";
49+
String description = "Migrate Mulesoft 3.9 to Spring Boot.";
50+
51+
// Flag to enable TriggerMesh ransformation mode
52+
if (sbmProperties.isMuleTriggerMeshTransformEnabled()) {
53+
name = "migrate-mule-to-triggermesh-boot";
54+
description = "Migrate Mulesoft 3.9 to Spring Boot using TriggerMesh.";
55+
javaDSLAction2.setMuleTriggerMeshTransformEnabled(true);
56+
}
57+
4558
return Recipe.builder()
46-
.name("migrate-mule-to-boot")
47-
.description("Migrate Mulesoft 3.9 to Spring Boot")
59+
.name(name)
60+
.description(description)
4861
.order(60)
49-
.description("Migrate Mulesoft to Spring Boot")
5062
.condition(new MuleConfigFileExist())
5163
.actions(List.of(
5264
/*

0 commit comments

Comments
 (0)