-
Notifications
You must be signed in to change notification settings - Fork 90
Add support for generating code to send MuleSoft Dataweave Transformations to TriggerMesh #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
37d850d
320e1df
4a48fa2
622a7cc
0f55515
3ffb5b5
7fa4a62
5df5d14
750d3d3
15141be
b1fc898
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright 2021 - 2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.sbm; | ||
|
||
import org.junit.jupiter.api.*; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.*; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@TestMethodOrder(MethodOrderer.MethodName.class) | ||
//@Disabled("Temporary disabled before CI will be fixed with docker in docker issue: #351") | ||
class MigrateSimpleMuleAppDataweaveIntegrationTest extends IntegrationTestBaseClass { | ||
fabapp2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private final RestTemplate restTemplate = new RestTemplate(); | ||
private static RunningNetworkedContainer tmDataweaveContainer; | ||
|
||
@Override | ||
protected String getTestSubDir() { | ||
|
||
return "mule-app/spring-dw-mule"; | ||
|
||
} | ||
|
||
@BeforeAll | ||
public static void beforeAll() { | ||
IntegrationTestBaseClass.beforeAll(); | ||
|
||
// Will need to ensure this is set globally for the test | ||
System.setProperty("sbm.muleTriggerMeshTransformEnabled", "true"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked into overriding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should rework this approach and set the flag in the action of a dedicated recipe, e.g. |
||
|
||
// start TriggerMesh Dataweave Translator | ||
HashMap<String, String> envMap = new HashMap<>(); | ||
envMap.put("NAMESPACE", "default"); | ||
envMap.put("DATAWEAVETRANSFORMATION_ALLOW_SPELL_OVERRIDE", "true"); | ||
|
||
tmDataweaveContainer = startDockerContainer( | ||
new NetworkedContainer( | ||
"gcr.io/triggermesh/dataweavetransformation-adapter:v1.21.0", | ||
List.of(8080), | ||
"dwhost"), | ||
null, | ||
envMap); | ||
if (!tmDataweaveContainer.getContainer().isRunning()) { | ||
throw new RuntimeException("TriggerMesh Dataweave Transformer container could not be started"); | ||
} | ||
} | ||
|
||
@AfterAll | ||
public static void afterAll() { | ||
if (tmDataweaveContainer != null && tmDataweaveContainer.getContainer() != null) { | ||
tmDataweaveContainer.getContainer().stop(); | ||
} | ||
} | ||
|
||
@Test | ||
@Tag("integration") | ||
public void t2_dataweaveIntegrationWorks() { | ||
intializeTestProject(); | ||
scanProject(); | ||
applyRecipe("initialize-spring-boot-migration"); | ||
applyRecipe("migrate-mule-to-triggermesh-boot"); | ||
|
||
executeMavenGoals(getTestDir(), "clean", "package", "spring-boot:build-image"); | ||
|
||
int dwPort = tmDataweaveContainer.getContainer().getMappedPort(8080); | ||
HashMap<String, String> runtimeEnv = new HashMap<>(); | ||
runtimeEnv.put("K_SINK", "http://dwhost:8080"); | ||
|
||
RunningNetworkedContainer container = startDockerContainer( | ||
new NetworkedContainer("hellomuledw-migrated:1.0-SNAPSHOT", List.of(9081), "spring"), | ||
tmDataweaveContainer.getNetwork(), | ||
runtimeEnv); | ||
|
||
checkSendHttpMessage(container.getContainer().getMappedPort(9081)); | ||
checkTranslatedInboundGatewayHttpMessage(container.getContainer().getMappedPort(9081)); | ||
} | ||
|
||
private void checkTranslatedInboundGatewayHttpMessage(int port) { | ||
ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://localhost:" + port + "/dwtest", String.class); | ||
|
||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK); | ||
assertThat(responseEntity.getBody()).isEqualTo("\n{\n \"greeting\": \"hello from SBM\"\n}"); | ||
} | ||
|
||
private void checkSendHttpMessage(int port) { | ||
ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://localhost:" + port + "/test", String.class); | ||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2021 - 2022 the original author or authors. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ https://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<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> | ||
|
||
<groupId>org.example</groupId> | ||
<artifactId>hellomuledw-migrated</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>5.8.2</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.javadsl; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class Foo { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2021 - 2022 the original author or authors. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ https://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
<mule xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" | ||
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" | ||
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd | ||
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"> | ||
<flow name="get:/dwtest:dwtest-config"> | ||
<dw:transform-message doc:name="Transform Message"> | ||
<dw:set-payload><![CDATA[%dw 2.0 | ||
output application/json | ||
--- | ||
greeting: "hello from SBM" | ||
]]> | ||
</dw:set-payload> | ||
</dw:transform-message> | ||
</flow> | ||
</mule> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
~ Copyright 2021 - 2022 the original author or authors. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ https://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" | ||
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd | ||
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd"> | ||
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="9081" doc:name="HTTP Listener Configuration"/> | ||
<flow name="http-flow"> | ||
<http:listener doc:name="Listener" doc:id="9f602d5c-5386-4fc9-ac8f-024d754c17e5" config-ref="HTTP_Listener_Configuration" path="/test"/> | ||
<logger level="INFO" doc:name="Logger" doc:id="4585ec7f-2d4a-4d86-af24-b678d4a99227" /> | ||
</flow> | ||
</mule> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
*/ | ||
package org.springframework.sbm.mule; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
@@ -30,23 +31,34 @@ | |
import org.springframework.sbm.java.migration.conditions.HasTypeAnnotation; | ||
import org.springframework.sbm.mule.actions.JavaDSLAction2; | ||
import org.springframework.sbm.mule.conditions.MuleConfigFileExist; | ||
import org.springframework.sbm.project.resource.SbmApplicationProperties; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration | ||
public class MigrateMuleToBoot { | ||
private final SbmApplicationProperties sbmProperties; | ||
|
||
@Autowired | ||
private JavaDSLAction2 javaDSLAction2; | ||
|
||
|
||
@Bean | ||
public Recipe muleRecipe() { | ||
String name = "migrate-mule-to-boot"; | ||
String description = "Migrate Mulesoft 3.9 to Spring Boot."; | ||
|
||
// Flag to enable TriggerMesh ransformation mode | ||
if (sbmProperties.isMuleTriggerMeshTransformEnabled()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should better create two bean methods here, calling one factory method that creates the recipe twice with the flag true and false. Taht would then finally allow to remove the application property :) |
||
name = "migrate-mule-to-triggermesh-boot"; | ||
description = "Migrate Mulesoft 3.9 to Spring Boot using TriggerMesh."; | ||
javaDSLAction2.setMuleTriggerMeshTransformEnabled(true); | ||
} | ||
|
||
return Recipe.builder() | ||
.name("migrate-mule-to-boot") | ||
.description("Migrate Mulesoft 3.9 to Spring Boot") | ||
.name(name) | ||
.description(description) | ||
.order(60) | ||
.description("Migrate Mulesoft to Spring Boot") | ||
.condition(new MuleConfigFileExist()) | ||
.actions(List.of( | ||
/* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the base test, this annotation is in effect, but left it commented out to facilitate verification for review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I get you here, but the method order is obsolete as there's only one test and no shared state, or?
You can remove the commented
@Disabled
, the test is green 🚀