Skip to content

Commit

Permalink
Merge pull request #223 from reportportal/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
HardNorth committed Nov 15, 2023
2 parents 6e90887 + b707189 commit ab0df32
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 34 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,6 +33,9 @@ public interface ReportPortalClient {
@POST("v1/{projectName}/launch/merge")
Maybe<LaunchResource> mergeLaunches(@Body MergeLaunchesRQ rq);

@PUT("v1/{projectName}/launch/{launchId}/update")
Maybe<LaunchResource> updateLaunch(@Path("launchId") String launchId, @Body UpdateLaunchRQ rq);

@PUT("v1/{projectName}/launch/{launchId}/finish")
Maybe<OperationCompletionRS> finishLaunch(@Path("launchId") String launch, @Body FinishExecutionRQ rq);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<Boolean> finishCondition = new Callable<Boolean>() {
private volatile Collection<String> launches;

@Override
public Boolean call() {
// Get current live secondary launches, locks `.sync` file
Collection<String> 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<Boolean> 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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Boolean> {
private volatile Collection<String> 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<String> 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;
}
}

0 comments on commit ab0df32

Please sign in to comment.