Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Fix: change retry condition for waitProjectStart
Browse files Browse the repository at this point in the history
Signed-off-by: Gloria Ciavarrini <gciavarrini@redhat.com>
  • Loading branch information
gciavarrini committed May 17, 2023
1 parent df18709 commit 04327d6
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions sdk-utils/src/main/java/com/redhat/parodos/sdkutils/SdkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void onFailure(ApiException e, int statusCode, Map<String, List<String>>

@Override
public void onSuccess(T result, int statusCode, Map<String, List<String>> responseHeaders) {
if (f.check(result)) {
if (f.check(result, statusCode)) {
try {
f.execute(this);
}
Expand Down Expand Up @@ -192,8 +192,18 @@ private void signal() {
* @throws InterruptedException If the async call reaches the waiting timeout
* @throws ApiException If the API method invocation fails
*/
public static void waitProjectStart(ProjectApi projectApi) throws InterruptedException, ApiException {
waitAsyncResponse((FuncExecutor<List<ProjectResponseDTO>>) callback -> projectApi.getProjectsAsync(callback));
public static void waitProjectStart(ProjectApi projectApi) throws ApiException, InterruptedException {
waitAsyncResponse(new FuncExecutor<List<ProjectResponseDTO>>() {
@Override
public boolean check(List<ProjectResponseDTO> result, int statusCode) {
return statusCode != 200;
}

@Override
public void execute(@NonNull ApiCallback<List<ProjectResponseDTO>> callback) throws ApiException {
projectApi.getProjectsAsync(callback);
}
});
}

/**
Expand All @@ -208,9 +218,10 @@ public static void waitProjectStart(ProjectApi projectApi) throws InterruptedExc
*/
public static WorkFlowStatusResponseDTO waitWorkflowStatusAsync(WorkflowApi workflowApi, UUID workFlowExecutionId)
throws InterruptedException, ApiException {

WorkFlowStatusResponseDTO workFlowStatusResponseDTO = waitAsyncResponse(new FuncExecutor<>() {
@Override
public boolean check(WorkFlowStatusResponseDTO result) {
public boolean check(WorkFlowStatusResponseDTO result, int statusCode) {
return !result.getStatus().equals(WorkFlowStatusResponseDTO.StatusEnum.COMPLETED);
}

Expand Down Expand Up @@ -264,7 +275,7 @@ public interface FuncExecutor<T> {
* @return {true} if it is necessary to continue monitoring the result, {false}
* when it's possible to stop the monitoring.
*/
default boolean check(T result) {
default boolean check(T result, int statusCode) {
return true;
}

Expand All @@ -284,7 +295,7 @@ default boolean check(T result) {
* @throws ApiException If the API methods invocations fail
*/
public static ProjectResponseDTO getProjectAsync(ApiClient apiClient, String projectName, String projectDescription)
throws InterruptedException, ApiException {
throws ApiException {
ProjectApi projectApi = new ProjectApi(apiClient);

ProjectResponseDTO testProject;
Expand Down Expand Up @@ -321,7 +332,6 @@ public static ProjectResponseDTO getProjectAsync(ApiClient apiClient, String pro

// ASSERT PROJECT "testProject" IS PRESENT
projects = projectApi.getProjects();
log.debug("PROJECTS: {}", projects);

if (projects.isEmpty()) {
throw new ApiException("Project has not been created.");
Expand Down

0 comments on commit 04327d6

Please sign in to comment.