Skip to content
Merged
238 changes: 169 additions & 69 deletions src/main/java/org/prebid/server/auction/ExchangeService.java
Comment thread
Lightwood13 marked this conversation as resolved.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ private List<SeatBid> resolveSeatBids(StoredResponse storedResponse,
Map<String, String> idToStoredResponses,
String impId) {

if (storedResponse instanceof StoredResponse.StoredResponseObject storedResponseObject) {
return Collections.singletonList(storedResponseObject.seatBid());
if (storedResponse instanceof StoredResponse.StoredResponseObject(SeatBid seatBid)) {
return Collections.singletonList(seatBid);
}

final String storedResponseId = ((StoredResponse.StoredResponseId) storedResponse).id();
Expand Down Expand Up @@ -313,7 +313,7 @@ private static AuctionParticipation updateStoredBidResponse(AuctionParticipation
final BidRequest bidRequest = bidderRequest.getBidRequest();

final List<Imp> imps = bidRequest.getImp();
// Аor now, Stored Bid Response works only for bid requests with single imp
// For now, Stored Bid Response works only for bid requests with single imp
if (imps.size() > 1 || StringUtils.isEmpty(bidderRequest.getStoredResponse())) {
return auctionParticipation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public AuctionContext with(BidResponse bidResponse) {
return this.toBuilder().bidResponse(bidResponse).build();
}

public AuctionContext with(Map<String, BidRejectionTracker> bidRejectionTrackers) {
return this.toBuilder().bidRejectionTrackers(bidRejectionTrackers).build();
}

public AuctionContext with(List<AuctionParticipation> auctionParticipations) {
return this.toBuilder().auctionParticipations(auctionParticipations).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,48 @@ public BidRejectionTracker(String bidder, Set<String> involvedImpIds, double log
rejections = new HashMap<>();
}

public BidRejectionTracker(BidRejectionTracker anotherTracker, Set<String> additionalImpIds) {
this.bidder = anotherTracker.bidder;
this.logSamplingRate = anotherTracker.logSamplingRate;
this.involvedImpIds = new HashSet<>(anotherTracker.involvedImpIds);
this.involvedImpIds.addAll(additionalImpIds);

this.succeededBidsIds = new HashMap<>(anotherTracker.succeededBidsIds);
this.rejections = new HashMap<>(anotherTracker.rejections);
private BidRejectionTracker(
String bidder,
Set<String> involvedImpIds,
Map<String, Set<String>> succeededBidsIds,
Map<String, List<Rejection>> rejections,
double logSamplingRate) {

this.bidder = bidder;
this.involvedImpIds = new HashSet<>(involvedImpIds);
this.logSamplingRate = logSamplingRate;

this.succeededBidsIds = MapUtil.mapValues(succeededBidsIds, v -> new HashSet<>(v));
this.rejections = MapUtil.mapValues(rejections, ArrayList::new);
}

public void succeed(Collection<BidderBid> bids) {
public static BidRejectionTracker copyOf(BidRejectionTracker anotherTracker) {
return new BidRejectionTracker(
anotherTracker.bidder,
anotherTracker.involvedImpIds,
anotherTracker.succeededBidsIds,
anotherTracker.rejections,
anotherTracker.logSamplingRate);
}

public static BidRejectionTracker withAdditionalImpIds(
BidRejectionTracker anotherTracker,
Set<String> additionalImpIds) {

final BidRejectionTracker newTracker = copyOf(anotherTracker);
newTracker.involvedImpIds.addAll(additionalImpIds);
return newTracker;
}

public BidRejectionTracker succeed(Collection<BidderBid> bids) {
bids.stream()
.map(BidderBid::getBid)
.filter(Objects::nonNull)
.forEach(this::succeed);
return this;
}

private void succeed(Bid bid) {
private BidRejectionTracker succeed(Bid bid) {
final String bidId = bid.getId();
final String impId = bid.getImpid();
if (involvedImpIds.contains(impId)) {
Expand All @@ -73,21 +97,23 @@ private void succeed(Bid bid) {
logSamplingRate);
}
}
return this;
}

public void restoreFromRejection(Collection<BidderBid> bids) {
succeed(bids);
}

public void reject(Collection<Rejection> rejections) {
public BidRejectionTracker reject(Collection<Rejection> rejections) {
rejections.forEach(this::reject);
return this;
}

public void reject(Rejection rejection) {
public BidRejectionTracker reject(Rejection rejection) {
if (rejection instanceof ImpRejection && rejection.reason().getValue() >= 300) {
logger.warn("The rejected imp {} with the code {} equal to or higher than 300 assumes "
+ "that there is a rejected bid that shouldn't be lost");
return;
return this;
}

final String impId = rejection.impId();
Expand All @@ -113,14 +139,18 @@ public void reject(Rejection rejection) {
}
}
}

return this;
}

public void rejectImps(Collection<String> impIds, BidRejectionReason reason) {
public BidRejectionTracker rejectImps(Collection<String> impIds, BidRejectionReason reason) {
impIds.forEach(impId -> reject(ImpRejection.of(impId, reason)));
return this;
}

public void rejectAll(BidRejectionReason reason) {
public BidRejectionTracker rejectAll(BidRejectionReason reason) {
involvedImpIds.forEach(impId -> reject(ImpRejection.of(impId, reason)));
return this;
}

public Set<Rejection> getRejected() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Defines the contract for bidrequest.ext.prebid
Expand Down Expand Up @@ -200,4 +201,7 @@ public class ExtRequestPrebid {
ExtRequestPrebidAlternateBidderCodes alternateBidderCodes;

ObjectNode kvps;

@JsonProperty("secondarybidders")
Set<String> secondaryBidders;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.prebid.server.spring.config.bidder.model.MediaType;

import java.util.Map;
import java.util.Set;

@Builder(toBuilder = true)
@Value
Expand Down Expand Up @@ -65,4 +66,7 @@ public class AccountAuctionConfig {
Integer impressionLimit;

AccountProfilesConfig profiles;

@JsonAlias("secondary-bidders")
Set<String> secondaryBidders;
}
22 changes: 22 additions & 0 deletions src/main/java/org/prebid/server/util/MapUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;

public class MapUtil {

Expand All @@ -15,4 +18,23 @@ public static <T, U> Map<T, U> merge(Map<T, U> left, Map<T, U> right) {

return Collections.unmodifiableMap(merged);
}

public static <K, V1, V2> Map<K, V2> mapValues(Map<K, V1> map, Function<V1, V2> transform) {
return mapValues(map, (ignored, value) -> transform.apply(value));
}

public static <K, V1, V2> Map<K, V2> mapValues(Map<K, V1> map, BiFunction<K, V1, V2> transform) {
return map.entrySet().stream().collect(
Collectors.toMap(Map.Entry::getKey, entry -> transform.apply(entry.getKey(), entry.getValue())));
}

public static <K, V1, V2> Function<Map.Entry<K, V1>, Map.Entry<K, V2>> mapEntryValueMapper(
BiFunction<K, V1, V2> transform) {

return mapEntryMapper((key, value) -> Map.entry(key, transform.apply(key, value)));
}

public static <K, V, T> Function<Map.Entry<K, V>, T> mapEntryMapper(BiFunction<K, V, T> transform) {
return entry -> transform.apply(entry.getKey(), entry.getValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class AccountAuctionConfig {
BidAdjustment bidAdjustments
BidRounding bidRounding
Integer impressionLimit
List<BidderName> secondaryBidders

@JsonProperty("price_granularity")
PriceGranularityType priceGranularitySnakeCase
Expand All @@ -58,5 +59,7 @@ class AccountAuctionConfig {
BidRounding bidRoundingSnakeCase
@JsonProperty("impression_limit")
Integer impressionLimitSnakeCase
@JsonProperty("secondary_bidders")
List<BidderName> secondaryBiddersSnakeCase

}
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,16 @@ class BidRequest {
ext.prebid.events = new Events()
}
}

void enabledReturnAllBidStatus() {
if (!ext) {
ext = new BidRequestExt()
}
if (!ext.prebid) {
ext.prebid = new Prebid()
}
if (!ext.prebid.returnAllBidStatus) {
ext.prebid.returnAllBidStatus = true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Prebid {
List<String> profileNames
@JsonProperty("kvps")
Map<String, String> keyValuePairs
List<BidderName> secondaryBidders

static class Channel {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import org.prebid.server.functional.model.request.auction.Imp
import org.prebid.server.functional.model.response.auction.BidResponse
import org.testcontainers.containers.MockServerContainer

import static java.util.concurrent.TimeUnit.MILLISECONDS
import static java.util.concurrent.TimeUnit.SECONDS
import static org.mockserver.model.HttpRequest.request
import static org.mockserver.model.HttpResponse.response
import static org.mockserver.model.HttpStatusCode.OK_200
Expand Down Expand Up @@ -48,6 +50,13 @@ class Bidder extends NetworkScaffolding {
}
}

void setResponseWithDelay(Long dilayTimeoutMillisecond = 5000) {
mockServerClient.when(request().withPath(endpoint), Times.unlimited(), TimeToLive.unlimited(), -10)
.respond {request -> request.withPath(endpoint)
? response().withDelay(MILLISECONDS, dilayTimeoutMillisecond).withStatusCode(OK_200.code()).withBody(getBodyByRequest(request))
: HttpResponse.notFoundResponse()}
}

List<BidRequest> getBidderRequests(String bidRequestId) {
getRecordedRequestsBody(bidRequestId).collect { decode(it, BidRequest) }
}
Expand Down
Loading
Loading