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

pull updates from v3 #875

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions clientlibs/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
at the same time that happen to rev to the same new version will be caught
by a merge conflict. -->

<!-- 2.0.0 -> 3.0.0: changes groupMembership, workingGroup, userAliases to PATCH, updated response objects -->
<!-- 4.1.0 -> 4.1.1: use apachec connector provider -->

<version>4.1.0</version>
<version>4.1.1</version>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -50,7 +50,11 @@
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.30.1</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-apache-connector</artifactId>
<version>2.30.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
Expand Down
139 changes: 65 additions & 74 deletions clientlibs/java/src/main/java/org/upgradeplatform/client/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,110 +11,101 @@

import org.eclipse.jdt.annotation.NonNull;
import org.upgradeplatform.interfaces.ResponseCallback;
import org.upgradeplatform.requestbeans.MarkExperimentRequestData;
import org.upgradeplatform.responsebeans.UserAliasResponse;
import org.upgradeplatform.responsebeans.Condition;
import org.upgradeplatform.responsebeans.ErrorResponse;
import org.upgradeplatform.responsebeans.ExperimentUser;
import org.upgradeplatform.responsebeans.ExperimentsResponse;
import org.upgradeplatform.responsebeans.InitializeUser;
import org.upgradeplatform.responsebeans.MarkExperimentPoint;
import org.upgradeplatform.responsebeans.UserAliasResponse;
import org.upgradeplatform.utils.Utils.MarkedDecisionPointStatus;

public class Main {
public static void main(String[] args) throws InterruptedException, ExecutionException
{
final String baseUrl = "http://localhost:3030";
final String userId = UUID.randomUUID().toString();
final String site = "SelectSection";
public static void main(String[] args) throws InterruptedException, ExecutionException
{
final String baseUrl = "https://upgradeapi.qa-cli.net";
final String userId = UUID.randomUUID().toString();
final String site = "SelectSection";

String target = args.length > 0 ? args[0] : "absolute_value_plot_equality";
String target = args.length > 0 ? args[0] : "volume_surface_area_cone_vol";

try(ExperimentClient experimentClient = new ExperimentClient(userId, "BearerToken", baseUrl, Collections.emptyMap())){
CompletableFuture<String> result = new CompletableFuture<>();
try(ExperimentClient experimentClient = new ExperimentClient(userId, "BearerToken", baseUrl, Collections.emptyMap())){
CompletableFuture<String> result = new CompletableFuture<>();

System.out.println(prefix() + "initiating requests");
experimentClient.init(new ResponseCallback<InitializeUser>() {
@Override
public void onSuccess(@NonNull InitializeUser t){
System.out.println("init " + t);
List<String> schools = new ArrayList<String>();

List<String> schools = new ArrayList<>();
schools.add("school1");
Map<String, List<String>> group = new HashMap<String, List<String>>();
Map<String, List<String>> group = new HashMap<>();
group.put("schoolid", schools);

System.out.println(prefix() + "setting group membership");
experimentClient.setGroupMembership(group, new ResponseCallback<ExperimentUser>(){
@Override
public void onSuccess(@NonNull ExperimentUser expResult){
System.out.println("group membership " + expResult);
System.out.println("success updating groups");
}
@Override
public void onError(@NonNull ErrorResponse error){
System.out.println("error updating groups " + error);
}
});


System.out.println(prefix() + "setting working group");
Map<String, String> workingGroup = new HashMap<String, String>();
workingGroup.put("schoolId", "school1");
experimentClient.setWorkingGroup(workingGroup, new ResponseCallback<ExperimentUser>(){
@Override
public void onSuccess(@NonNull ExperimentUser expResult){
System.out.println("working group " + expResult);
System.out.println("success updating working groups");
}
@Override
public void onError(@NonNull ErrorResponse error){
System.out.println("error updating working groups " + error);
}
});
System.out.println(prefix() + "success updating groups; setting working group");


System.out.println(prefix() + "setting user aliases");
List<String> altIds = new ArrayList<String>();
altIds.add(UUID.randomUUID().toString());
experimentClient.setAltUserIds(altIds, new ResponseCallback<UserAliasResponse>(){
@Override
public void onSuccess(@NonNull UserAliasResponse t) {
System.out.println("aliases " + t);
System.out.println("success updating user aliases");
}
@Override
public void onError(@NonNull ErrorResponse error){
System.out.println("error updating user aliases " + error);
}

});

System.out.println(prefix() + "getting conditions");
experimentClient.getExperimentCondition("assign-prog", site, target, new ResponseCallback<ExperimentsResponse>(){
@Override
public void onSuccess(@NonNull ExperimentsResponse expResult){
System.out.println("condition " + expResult);
Condition condition = expResult.getAssignedCondition();
String code = condition == null ? null : condition.getConditionCode();
MarkExperimentRequestData data = new MarkExperimentRequestData(site, target, condition);
experimentClient.markExperimentPoint(MarkedDecisionPointStatus.CONDITION_APPLIED, data, new ResponseCallback<MarkExperimentPoint>(){
Map<String, String> workingGroup = new HashMap<>();
workingGroup.put("schoolId", "school1");
experimentClient.setWorkingGroup(workingGroup, new ResponseCallback<ExperimentUser>(){
@Override
public void onSuccess(@NonNull MarkExperimentPoint markResult){
result.complete("marked " + code + ": " + markResult.toString());
public void onSuccess(@NonNull ExperimentUser expResult){
System.out.println(prefix() + "success updating working groups; setting user aliases");

List<String> altIds = new ArrayList<>();
altIds.add(UUID.randomUUID().toString());
experimentClient.setAltUserIds(altIds, new ResponseCallback<UserAliasResponse>(){
@Override
public void onSuccess(@NonNull UserAliasResponse uar) {
System.out.println(prefix() + "success updating user aliases; getting conditions");

experimentClient.getExperimentCondition("assign-prog", site, target, new ResponseCallback<ExperimentsResponse>(){
@Override
public void onSuccess(@NonNull ExperimentsResponse expResult){
System.out.println(prefix() + "success getting condition; marking");

Condition condition = expResult.getAssignedCondition();
String code = condition == null ? null : condition.getConditionCode();
experimentClient.markExperimentPoint(site, target, code, MarkedDecisionPointStatus.CONDITION_APPLIED, new ResponseCallback<MarkExperimentPoint>(){
@Override
public void onSuccess(@NonNull MarkExperimentPoint markResult){
result.complete("marked " + code + ": " + markResult.toString());
}

@Override
public void onError(@NonNull ErrorResponse error){
result.complete("error marking " + code + ": " + error.toString());
}
});
}

@Override
public void onError(@NonNull ErrorResponse error){
result.complete(error.toString());
}

});
}
@Override
public void onError(@NonNull ErrorResponse error){
result.complete(error.toString());
}

});
}

@Override
public void onError(@NonNull ErrorResponse error){
result.complete("error marking " + code + ": " + error.toString());
result.complete(error.toString());
}
});
}

@Override
public void onError(@NonNull ErrorResponse error){
result.complete(error.toString());
}

});
}

Expand All @@ -127,10 +118,10 @@ public void onError(@NonNull ErrorResponse error){
System.out.println(prefix() + result.getNow("not complete yet"));
String rs = result.get();
System.out.println(prefix() + rs);
}
}
}
}

private static final String prefix() {
return "on thread " + Thread.currentThread().getName() + " at " + System.currentTimeMillis() + ": ";
}
private static final String prefix() {
return "on thread " + Thread.currentThread().getName() + " at " + System.currentTimeMillis() + ": ";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.apache.connector.ApacheConnectorProvider;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.HttpUrlConnectorProvider;


public class APIService implements AutoCloseable{
Expand All @@ -35,7 +36,7 @@ public APIService(String baseUrl, String authToken, String sessionId, Map<String
}

public static Client createClient(Map<String,Object> properties) {
Client client = ClientBuilder.newClient();
Client client = ClientBuilder.newClient(new ClientConfig().connectorProvider(new ApacheConnectorProvider()));
client.property(ClientProperties.CONNECT_TIMEOUT, 3000);
client.property(ClientProperties.READ_TIMEOUT, 3000);
properties.entrySet().stream()
Expand All @@ -57,12 +58,11 @@ public AsyncInvoker prepareRequest(String apiPath) {
.request(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer "+this.authToken)
.header("Session-Id", this.sessionId)
.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true)
.async();
}

@Override
public void close() {
client.close();
}
}
}