Skip to content
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

[Client] Java client #198

Merged
merged 11 commits into from
Sep 4, 2024
Merged

[Client] Java client #198

merged 11 commits into from
Sep 4, 2024

Conversation

mahatoankitkumar
Copy link
Collaborator

Problem

Java CAC Client

@mahatoankitkumar mahatoankitkumar requested a review from a team as a code owner August 5, 2024 11:29
@mahatoankitkumar mahatoankitkumar force-pushed the feat/java-client branch 3 times, most recently from 448fb73 to 58b53c5 Compare August 7, 2024 11:07
@mahatoankitkumar mahatoankitkumar changed the title feat: java client [Client]: java client Aug 7, 2024
@mahatoankitkumar mahatoankitkumar changed the title [Client]: java client [Client] Java client Aug 7, 2024
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we keep the two clients separately in different projects

# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format

[versions]
guava = "33.1.0-jre"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we import guava? Do we need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, let me check.

Comment on lines +1 to +14
# JAVA Client

## Prerequisites

- Java JDK
- Gradle 7.0 or later

## Building the Project

To build the project, run:
```
./gradlew build
```

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add documentation on how to add this to a separate project?

Comment on lines 5 to 10
guava = "33.1.0-jre"
junit-jupiter = "5.10.2"

[libraries]
guava = { module = "com.google.guava:guava", version.ref = "guava" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need these libraries?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will check

public static RustLib rustLib;

public CacClient(String libraryPath, String libraryName) {
System.setProperty("jnr.ffi.library.path", libraryPath);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read library path from ENV
SUPERPOSITION_LIB_PATH

int result = rustLib.cac_new_client(tenant, updateFrequency, hostName);
if (result > 0) {
String errorMessage = rustLib.cac_last_error_message();
throw new IOException("Failed to create new CAC client: " + errorMessage);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an IOException right? Can we create a special Exception object for this?

Comment on lines 118 to 126
if (ptr == null) {
return null;
}
try {
return ptr.getString(0);
} finally {
freeString(ptr);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write this better?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it looks fine?

private static void callCacClient() {
String dylib = "cac_client";
File currentDir = new File(System.getProperty("user.dir"));
String libraryPath = currentDir.getParentFile().getParentFile().getParentFile() + "/target/debug";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No hardcoding the path please, use env SUPERPOSITION_LIB_PATH


int newClient;
try {
newClient = wrapper.cacNewClient(tenant, 1, "http://localhost:8080");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL should not be hardcoded, is this an example file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is an example file.


import jnr.ffi.Pointer;

public class Client {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name this class better? It seems like a Client implementation

@@ -0,0 +1,116 @@
package CAC;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package should be different

@Datron
Copy link
Collaborator

Datron commented Aug 26, 2024

Can you add java and gradle versions in flakes.nix as well?

@Datron Datron force-pushed the main branch 8 times, most recently from 6ca353c to 41073fc Compare September 2, 2024 10:08
@mahatoankitkumar mahatoankitkumar force-pushed the feat/java-client branch 9 times, most recently from fb9f0ad to 7c87aa6 Compare September 3, 2024 12:59
@mahatoankitkumar mahatoankitkumar force-pushed the feat/java-client branch 4 times, most recently from 35e61af to fd5c309 Compare September 3, 2024 13:47
@Datron Datron force-pushed the feat/java-client branch 4 times, most recently from 1355e99 to a8c218d Compare September 4, 2024 06:12
@mahatoankitkumar mahatoankitkumar force-pushed the feat/java-client branch 2 times, most recently from 469448f to f24abe8 Compare September 4, 2024 06:39
@mahatoankitkumar mahatoankitkumar force-pushed the feat/java-client branch 2 times, most recently from 4ac0f1a to 2599c16 Compare September 4, 2024 08:36
@mahatoankitkumar mahatoankitkumar merged commit 8735883 into main Sep 4, 2024
4 checks passed
@mahatoankitkumar mahatoankitkumar deleted the feat/java-client branch September 4, 2024 09:52
Datron pushed a commit that referenced this pull request Sep 6, 2024
* feat: java client

* fix: Removed unnecessary files

* fix: more cleanups

* feat: Add expt client wrapper

* fix: add experiment client implementation

* fix: Added README.md

* fix: separated cac-client and exp-client

* fix: separated cac-client and exp-client

* fix: make it a lib

* fix: Added Readme.md to use the clients

* fix: yaml file

---------

Co-authored-by: Ankit Mahato <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants