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

Support deprecated bidders #169

Merged
merged 14 commits into from
Oct 30, 2018
1 change: 1 addition & 0 deletions docs/config-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ There are several typical keys:
- `adapters.<BIDDER_NAME>.endpoint` - the url for submitting bids.
- `adapters.<BIDDER_NAME>.usersync-url` - the url for synchronizing UIDs cookie.
- `adapters.<BIDDER_NAME>.pbs-enforces-gdpr` - indicates if pbs server provides gdpr support for bidder or bidder will handle it itself.
- `adapters.<BIDDER_NAME>.deprecated-names` - comma separated deprecated names of bidder.

But feel free to add additional bidder's specific options.

Expand Down
23 changes: 18 additions & 5 deletions src/main/java/org/prebid/server/auction/ExchangeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ private static Map<String, Map<String, BigDecimal>> currencyRates(ExtRequestTarg
* NOTE: the return list will only contain entries for bidders that both have the extension field in at least one
* {@link Imp}, and are known to {@link BidderCatalog} or aliases from {@link BidRequest}.ext.prebid.aliases.
*/
private Future<List<BidderRequest>> extractBidderRequests(BidRequest bidRequest,
UidsCookie uidsCookie,
private Future<List<BidderRequest>> extractBidderRequests(BidRequest bidRequest, UidsCookie uidsCookie,
Map<String, String> aliases,
Timeout timeout) {
// sanity check: discard imps without extension
Expand Down Expand Up @@ -1065,22 +1064,36 @@ private CacheAsset toCacheAsset(String cacheId) {
* Creates {@link ExtBidResponse} populated with response time, errors and debug info (if requested) from all
* bidders
*/
private static ExtBidResponse toExtBidResponse(List<BidderResponse> results, BidRequest bidRequest) {
private ExtBidResponse toExtBidResponse(List<BidderResponse> results, BidRequest bidRequest) {
final Map<String, List<ExtHttpCall>> httpCalls = Objects.equals(bidRequest.getTest(), 1)
? results.stream().collect(
Collectors.toMap(BidderResponse::getBidder, r -> ListUtils.emptyIfNull(r.getSeatBid().getHttpCalls())))
: null;
final ExtResponseDebug extResponseDebug = httpCalls != null ? ExtResponseDebug.of(httpCalls, bidRequest) : null;

final Map<String, List<String>> errors = results.stream()
.collect(Collectors.toMap(BidderResponse::getBidder, r -> messages(r.getSeatBid().getErrors())));
final Map<String, List<String>> errors = new HashMap<>();
for (BidderResponse bidderResponse : results) {
errors.put(bidderResponse.getBidder(), messages(bidderResponse.getSeatBid().getErrors()));
}

errors.putAll(extractDeprecatedBiddersErrors(bidRequest));

final Map<String, Integer> responseTimeMillis = results.stream()
.collect(Collectors.toMap(BidderResponse::getBidder, BidderResponse::getResponseTime));

return ExtBidResponse.of(extResponseDebug, errors, responseTimeMillis, null);
}

private Map<String, List<String>> extractDeprecatedBiddersErrors(BidRequest bidRequest) {
return bidRequest.getImp().stream()
.filter(imp -> imp.getExt() != null)
.flatMap(imp -> asStream(imp.getExt().fieldNames()))
.distinct()
.filter(bidderCatalog::isDeprecatedName)
.collect(Collectors.toMap(Function.identity(),
bidder -> Collections.singletonList(bidderCatalog.errorForDeprecatedName(bidder))));
}

private static List<String> messages(List<BidderError> errors) {
return CollectionUtils.emptyIfNull(errors).stream().map(BidderError::getMessage).collect(Collectors.toList());
}
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/org/prebid/server/bidder/BidderCatalog.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.prebid.server.bidder;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand All @@ -13,11 +14,20 @@
*/
public class BidderCatalog {

private static final String ERROR_MESSAGE_TEMPLATE_FOR_DEPRECATED = "%s has been deprecated and is no "
+ "longer available. Use %s instead.";

private final Map<String, BidderDeps> bidderDepsMap;

private final Map<String, String> deprecatedNameToError = new HashMap<>();

public BidderCatalog(List<BidderDeps> bidderDeps) {
bidderDepsMap = Objects.requireNonNull(bidderDeps).stream()
.collect(Collectors.toMap(BidderDeps::getName, Function.identity()));

bidderDeps.forEach(deps ->
deprecatedNameToError.putAll(createErrorsForDeprecatedNames(deps.getDeprecatedNames(),
deps.getName())));
}

/**
Expand All @@ -34,6 +44,19 @@ public boolean isValidName(String name) {
return bidderDepsMap.containsKey(name);
}

public boolean isDeprecatedName(String name) {
return deprecatedNameToError.containsKey(name);
}

public String errorForDeprecatedName(String name) {
return deprecatedNameToError.get(name);
}

private Map<String, String> createErrorsForDeprecatedNames(List<String> deprecatedNames, String name) {
return deprecatedNames.stream().collect(Collectors.toMap(deprecatedName -> deprecatedName,
deprecatedName -> String.format(ERROR_MESSAGE_TEMPLATE_FOR_DEPRECATED, deprecatedName, name)));
}

/**
* Tells if given bidder is enabled and ready for auction.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/prebid/server/bidder/BidderDeps.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import lombok.AllArgsConstructor;
import lombok.Value;

import java.util.List;

/**
* Gathers all dependencies for bidder.
*/
Expand All @@ -18,6 +20,8 @@ public class BidderDeps {
*/
String name;

List<String> deprecatedNames;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's replace the list with a map like:

private final Map<String, String> deprecatedNameToError;

which will contain error for each deprecated name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is no longer valid suggestion


/**
* Bidder's meta information is used in {@link org.prebid.server.handler.info.BidderDetailsHandler} handler
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class AdformConfiguration extends BidderConfiguration {

Expand All @@ -37,6 +39,9 @@ public class AdformConfiguration extends BidderConfiguration {
@Value("${external-url}")
private String externalUrl;

@Value("${adapters.adform.deprecated-names}")
private List<String> deprecatedNames;

@Bean
BidderDeps adformBidderDeps(HttpClient httpClient, HttpAdapterConnector httpAdapterConnector) {
return bidderDeps(httpClient, httpAdapterConnector);
Expand All @@ -47,6 +52,11 @@ protected String bidderName() {
return BIDDER_NAME;
}

@Override
protected List<String> deprecatedNames() {
return deprecatedNames;
}

@Override
protected MetaInfo createMetaInfo() {
return new AdformMetaInfo(enabled, pbsEnforcesGdpr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class AdkernelAdnConfiguration extends BidderConfiguration {

Expand All @@ -36,6 +38,9 @@ public class AdkernelAdnConfiguration extends BidderConfiguration {
@Value("${external-url}")
private String externalUrl;

@Value("${adapters.adkerneladn.deprecated-names}")
private List<String> deprecatedNames;

@Bean
BidderDeps adkernelAdnBidderDeps(HttpClient httpClient, HttpAdapterConnector httpAdapterConnector) {
return bidderDeps(httpClient, httpAdapterConnector);
Expand All @@ -46,6 +51,11 @@ protected String bidderName() {
return BIDDER_NAME;
}

@Override
protected List<String> deprecatedNames() {
return deprecatedNames;
}

@Override
protected MetaInfo createMetaInfo() {
return new AdkernelAdnMetaInfo(enabled, pbsEnforcesGdpr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class AdtelligentConfiguration extends BidderConfiguration {

Expand All @@ -36,11 +38,19 @@ public class AdtelligentConfiguration extends BidderConfiguration {
@Value("${external-url}")
private String externalUrl;

@Value("${adapters.adtelligent.deprecated-names}")
private List<String> deprecatedNames;

@Override
protected String bidderName() {
return BIDDER_NAME;
}

@Override
protected List<String> deprecatedNames() {
return deprecatedNames;
}

@Bean
BidderDeps adtelligentBidderDeps(HttpClient httpClient, HttpAdapterConnector httpAdapterConnector) {
return bidderDeps(httpClient, httpAdapterConnector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class AppnexusConfiguration extends BidderConfiguration {

Expand All @@ -37,6 +39,9 @@ public class AppnexusConfiguration extends BidderConfiguration {
@Value("${external-url}")
private String externalUrl;

@Value("${adapters.appnexus.deprecated-names}")
private List<String> deprecatedNames;

@Bean
BidderDeps appnexusBidderDeps(HttpClient httpClient, HttpAdapterConnector httpAdapterConnector) {
return bidderDeps(httpClient, httpAdapterConnector);
Expand All @@ -47,6 +52,11 @@ protected String bidderName() {
return BIDDER_NAME;
}

@Override
protected List<String> deprecatedNames() {
return deprecatedNames;
}

@Override
protected MetaInfo createMetaInfo() {
return new AppnexusMetaInfo(enabled, pbsEnforcesGdpr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class BeachfrontConfiguration extends BidderConfiguration {

Expand All @@ -39,6 +41,9 @@ public class BeachfrontConfiguration extends BidderConfiguration {
@Value("${adapters.beachfront.pbs-enforces-gdpr}")
private boolean pbsEnforcesGdpr;

@Value("${adapters.beachfront.deprecated-names}")
private List<String> deprecatedNames;

@Bean
BidderDeps beachfrontBidderDeps(HttpClient httpClient, HttpAdapterConnector httpAdapterConnector) {
return bidderDeps(httpClient, httpAdapterConnector);
Expand All @@ -49,6 +54,11 @@ protected String bidderName() {
return BIDDER_NAME;
}

@Override
protected List<String> deprecatedNames() {
return deprecatedNames;
}

@Override
protected MetaInfo createMetaInfo() {
return new BeachfrontMetaInfo(enabled, pbsEnforcesGdpr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.prebid.server.bidder.Usersyncer;
import org.prebid.server.vertx.http.HttpClient;

import java.util.List;

public abstract class BidderConfiguration {

private static final String ERROR_MESSAGE_TEMPLATE_FOR_DISABLED = "%s is not configured properly on this "
Expand All @@ -33,11 +35,13 @@ protected BidderDeps bidderDeps(HttpClient httpClient, HttpAdapterConnector http
final BidderRequester bidderRequester = createBidderRequester(httpClient, bidder, adapter, usersyncer,
httpAdapterConnector);

return BidderDeps.of(bidderName, metaInfo, usersyncer, bidder, adapter, bidderRequester);
return BidderDeps.of(bidderName, deprecatedNames(), metaInfo, usersyncer, bidder, adapter, bidderRequester);
}

protected abstract String bidderName();

protected abstract List<String> deprecatedNames();

protected abstract MetaInfo createMetaInfo();

protected abstract Usersyncer createUsersyncer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class BrightrollConfiguration extends BidderConfiguration {

Expand All @@ -36,6 +38,9 @@ public class BrightrollConfiguration extends BidderConfiguration {
@Value("${external-url}")
private String externalUrl;

@Value("${adapters.brightroll.deprecated-names}")
private List<String> deprecatedNames;

@Bean
BidderDeps brightrollBidderDeps(HttpClient httpClient, HttpAdapterConnector httpAdapterConnector) {
return bidderDeps(httpClient, httpAdapterConnector);
Expand All @@ -46,6 +51,11 @@ protected String bidderName() {
return BIDDER_NAME;
}

@Override
protected List<String> deprecatedNames() {
return deprecatedNames;
}

@Override
protected MetaInfo createMetaInfo() {
return new BrightrollMetaInfo(enabled, pbsEnforcesGdpr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class ConversantConfiguration extends BidderConfiguration {

Expand All @@ -37,6 +39,9 @@ public class ConversantConfiguration extends BidderConfiguration {
@Value("${external-url}")
private String externalUrl;

@Value("${adapters.conversant.deprecated-names}")
private List<String> deprecatedNames;

@Bean
BidderDeps conversantBidderDeps(HttpClient httpClient, HttpAdapterConnector httpAdapterConnector) {
return bidderDeps(httpClient, httpAdapterConnector);
Expand All @@ -47,6 +52,11 @@ protected String bidderName() {
return BIDDER_NAME;
}

@Override
protected List<String> deprecatedNames() {
return deprecatedNames;
}

@Override
protected MetaInfo createMetaInfo() {
return new ConversantMetaInfo(enabled, pbsEnforcesGdpr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class EplanningConfiguration extends BidderConfiguration {

Expand All @@ -36,11 +38,19 @@ public class EplanningConfiguration extends BidderConfiguration {
@Value("${external-url}")
private String externalUrl;

@Value("${adapters.eplanning.deprecated-names}")
private List<String> deprecatedNames;

@Override
protected String bidderName() {
return BIDDER_NAME;
}

@Override
protected List<String> deprecatedNames() {
return deprecatedNames;
}

@Bean
BidderDeps eplanningBidderDeps(HttpClient httpClient, HttpAdapterConnector httpAdapterConnector) {
return bidderDeps(httpClient, httpAdapterConnector);
Expand Down
Loading