diff --git a/CHANGELOG.md b/CHANGELOG.md index c18648e5..d62a8420 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog ## [Unreleased] +### Added +- `ReportPortalClient.updateLaunch` method, by @matt-richardson +### Changed +- `SecondaryLaunchFinishCondition` class was separated to resolve fat jar issues, by @HardNorth +- `rxjava` was forcibly excluded from `retrofit2:adapter-rxjava2` transitive dependencies to resolve fat jar issues, by @HardNorth ## [5.1.23] ### Changed diff --git a/build.gradle b/build.gradle index d6281fb0..9c423dd5 100644 --- a/build.gradle +++ b/build.gradle @@ -52,7 +52,9 @@ dependencies { implementation ("com.squareup.retrofit2:converter-jackson:${project.retrofit_version}") { exclude module: 'jackson-databind' } - implementation "com.squareup.retrofit2:adapter-rxjava2:${project.retrofit_version}" + implementation ("com.squareup.retrofit2:adapter-rxjava2:${project.retrofit_version}") { + exclude module: 'rxjava' + } implementation 'com.squareup.okhttp3:logging-interceptor:3.14.9' api "org.aspectj:aspectjrt:${project.aspectj_version}" diff --git a/src/main/java/com/epam/reportportal/service/ReportPortalClient.java b/src/main/java/com/epam/reportportal/service/ReportPortalClient.java index 7b867573..90d8aa91 100644 --- a/src/main/java/com/epam/reportportal/service/ReportPortalClient.java +++ b/src/main/java/com/epam/reportportal/service/ReportPortalClient.java @@ -17,10 +17,7 @@ import com.epam.ta.reportportal.ws.model.*; import com.epam.ta.reportportal.ws.model.item.ItemCreatedRS; -import com.epam.ta.reportportal.ws.model.launch.LaunchResource; -import com.epam.ta.reportportal.ws.model.launch.MergeLaunchesRQ; -import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; -import com.epam.ta.reportportal.ws.model.launch.StartLaunchRS; +import com.epam.ta.reportportal.ws.model.launch.*; import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; import io.reactivex.Maybe; import okhttp3.MultipartBody; @@ -36,6 +33,9 @@ public interface ReportPortalClient { @POST("v1/{projectName}/launch/merge") Maybe mergeLaunches(@Body MergeLaunchesRQ rq); + @PUT("v1/{projectName}/launch/{launchId}/update") + Maybe updateLaunch(@Path("launchId") String launchId, @Body UpdateLaunchRQ rq); + @PUT("v1/{projectName}/launch/{launchId}/finish") Maybe finishLaunch(@Path("launchId") String launch, @Body FinishExecutionRQ rq); diff --git a/src/main/java/com/epam/reportportal/service/launch/PrimaryLaunch.java b/src/main/java/com/epam/reportportal/service/launch/PrimaryLaunch.java index 4e7fa171..b6f535b1 100644 --- a/src/main/java/com/epam/reportportal/service/launch/PrimaryLaunch.java +++ b/src/main/java/com/epam/reportportal/service/launch/PrimaryLaunch.java @@ -25,13 +25,11 @@ import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; import java.util.Calendar; -import java.util.Collection; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import static com.epam.reportportal.utils.ObjectUtils.clonePojo; -import static java.util.Optional.ofNullable; /** * An implementation of a {@link Launch} object which managed to obtain main lock with {@link LaunchIdLock} object. @@ -44,37 +42,19 @@ public PrimaryLaunch(ReportPortalClient rpClient, ListenerParameters parameters, super(rpClient, parameters, launch, executorService, launchIdLock, instanceUuid); } + /** + * Wait for all secondary launches finish and then close the Primary Launch. If there was running secondary launch + * number change then the timeout will reset. + * + * @param request Finish Launch Request to use (end time will be updated after wait). + */ @Override public void finish(final FinishExecutionRQ request) { stopRunning(); - - // Secondary launch wait finish condition - Callable finishCondition = new Callable() { - private volatile Collection launches; - - @Override - public Boolean call() { - // Get current live secondary launches, locks `.sync` file - Collection current = lock.getLiveInstanceUuids(); - - // If there is no live launches, or the only live launch is the primary launch we are done - if (current.isEmpty() || (current.size() == 1 && uuid.equals(current.iterator().next()))) { - return true; - } - - // Determine whether there were any updates in secondary launches: new launches started or old one finished - Boolean changed = ofNullable(launches).map(l -> !l.equals(current)).orElse(Boolean.TRUE); - launches = current; - if (changed) { - // If there were changes in secondary launches than the execution is live, and we are going wait more - return false; - } - // No changes from last time - return null; - } - }; - + Callable finishCondition = new SecondaryLaunchFinishCondition(lock, uuid); Boolean finished = Boolean.FALSE; + // If there was launch number change (finished == false) we will wait more. + // Only if while (finished != Boolean.TRUE && finished != null) { Waiter waiter = new Waiter("Wait for all launches end").duration( getParameters().getClientJoinTimeout(), diff --git a/src/main/java/com/epam/reportportal/service/launch/SecondaryLaunchFinishCondition.java b/src/main/java/com/epam/reportportal/service/launch/SecondaryLaunchFinishCondition.java new file mode 100644 index 00000000..15301e49 --- /dev/null +++ b/src/main/java/com/epam/reportportal/service/launch/SecondaryLaunchFinishCondition.java @@ -0,0 +1,59 @@ +/* + * Copyright 2023 EPAM Systems + * + * 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 com.epam.reportportal.service.launch; + +import com.epam.reportportal.service.LaunchIdLock; + +import java.util.Collection; +import java.util.concurrent.Callable; + +import static java.util.Optional.ofNullable; + +/** + * Condition which designed to wait for all secondary launches finished (true), or at least one launch finished (false). + */ +public class SecondaryLaunchFinishCondition implements Callable { + private volatile Collection launches; + private final LaunchIdLock lock; + private final String uuid; + + public SecondaryLaunchFinishCondition(LaunchIdLock launchIdLock, String selfUuid) { + lock = launchIdLock; + uuid = selfUuid; + } + + @Override + public Boolean call() { + // Get current live secondary launches, locks `.sync` file + Collection current = lock.getLiveInstanceUuids(); + + // If there is no live launches, or the only live launch is the primary launch we are done + if (current.isEmpty() || (current.size() == 1 && uuid.equals(current.iterator().next()))) { + return true; + } + + // Determine whether there were any updates in secondary launches: new launches started or old one finished + Boolean changed = ofNullable(launches).map(l -> !l.equals(current)).orElse(Boolean.TRUE); + launches = current; + if (changed) { + // If there were changes in secondary launches than the execution is live, and we are going wait more + return false; + } + // No changes from last time + return null; + } +}