-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into consumer-e2e
- Loading branch information
Showing
150 changed files
with
2,767 additions
and
1,578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.run/Dev, start pulsar and zk.run.xml → .run/Start pulsar and zk (dev mode).run.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
plugins { | ||
id "com.flipkart.varadhi.java-common-conventions" | ||
} | ||
|
||
tasks.register('version') { | ||
doLast { | ||
println("Version: ${version}") | ||
} | ||
} | ||
|
||
tasks.register("copyConfigForE2E", Copy, copyConfigToDir("setup/docker/config.overrides", "setup/docker/configs/varadhi-auto-generated")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
common/src/main/java/com/flipkart/varadhi/reflect/RecursiveFieldUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.flipkart.varadhi.reflect; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Field; | ||
import java.util.Objects; | ||
import java.util.function.BiFunction; | ||
|
||
public class RecursiveFieldUpdater { | ||
|
||
public static <T, V> void visit(T object, Class<? extends Annotation> annotationClass, BiFunction<String, V, V> updateFunction) { | ||
Objects.requireNonNull(object, "Object cannot be null"); | ||
traverseObject(object, annotationClass, updateFunction, ""); | ||
} | ||
|
||
private static <T, V> void traverseObject(T obj, Class<? extends Annotation> annotationClass, BiFunction<String, V, V> updateFunction, String path) { | ||
if (obj == null) return; | ||
|
||
Class<?> clazz = obj.getClass(); | ||
for (Field field : clazz.getDeclaredFields()) { | ||
field.setAccessible(true); | ||
String fieldPath = path.isEmpty() ? field.getName() : path + "." + field.getName(); | ||
|
||
try { | ||
Object fieldValue = field.get(obj); | ||
|
||
// If the field is annotated with the specified annotation, process it | ||
if (field.isAnnotationPresent(annotationClass)) { | ||
// Apply the update function to get the new value | ||
V newValue = updateFunction.apply(fieldPath, (V)fieldValue); | ||
setFieldValue(obj, field, newValue); | ||
} else if (!field.getType().isPrimitive() && field.getType().getName().startsWith("com.flipkart.varadhi.")) { | ||
// Recursively visit nested POJOs | ||
traverseObject(fieldValue, annotationClass, updateFunction, fieldPath); | ||
} | ||
} catch (IllegalAccessException e) { | ||
throw new RuntimeException("Failed to access field: " + field.getName(), e); | ||
} | ||
} | ||
} | ||
|
||
private static void setFieldValue(Object obj, Field field, Object newValue) { | ||
try { | ||
field.set(obj, newValue); | ||
} catch (IllegalAccessException e) { | ||
throw new RuntimeException("Failed to set field value for: " + field.getName(), e); | ||
} | ||
} | ||
} |
18 changes: 12 additions & 6 deletions
18
common/src/main/java/com/flipkart/varadhi/utils/HostUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
package com.flipkart.varadhi.utils; | ||
|
||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
|
||
@Slf4j | ||
public class HostUtils { | ||
@Getter | ||
private static String hostName; | ||
@Getter | ||
private static String hostAddress; | ||
|
||
public static String getHostName() throws UnknownHostException { | ||
// debug to see how much time it takes, in case DNS resolution is taking time. | ||
log.debug("getHostName: started"); | ||
String host = InetAddress.getLocalHost().getHostName(); | ||
log.debug("getHostName: completed"); | ||
return host; | ||
public static void initHostUtils() throws UnknownHostException { | ||
if(hostName == null) { | ||
hostName = InetAddress.getLocalHost().getHostName(); | ||
} | ||
if(hostAddress == null) { | ||
hostAddress = InetAddress.getLocalHost().getHostAddress(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ | |
|
||
exports com.flipkart.varadhi; | ||
exports com.flipkart.varadhi.exceptions; | ||
exports com.flipkart.varadhi.reflect; | ||
} |
15 changes: 15 additions & 0 deletions
15
common/src/test/java/com/flipkart/varadhi/utils/HostUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,33 @@ | ||
package com.flipkart.varadhi.utils; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
|
||
public class HostUtilsTest { | ||
|
||
@BeforeAll | ||
public static void init() throws UnknownHostException { | ||
HostUtils.initHostUtils(); | ||
} | ||
|
||
@Test | ||
public void TestGetHostName() throws UnknownHostException { | ||
// dummy test.. no validations here. | ||
String host = HostUtils.getHostName(); | ||
Assertions.assertNotNull(host); | ||
Assertions.assertEquals(InetAddress.getLocalHost().getHostName(), host); | ||
} | ||
|
||
@Test | ||
public void TestGetHostAddress() throws UnknownHostException { | ||
// dummy test.. no validations here. | ||
String address = HostUtils.getHostAddress(); | ||
Assertions.assertNotNull(address); | ||
Assertions.assertEquals(InetAddress.getLocalHost().getHostAddress(), address); | ||
} | ||
|
||
} |
Oops, something went wrong.