Skip to content

Commit 5cac1d2

Browse files
author
EvgeniiMunin
committed
refacto
1 parent e934a4b commit 5cac1d2

File tree

22 files changed

+295
-422
lines changed

22 files changed

+295
-422
lines changed

extra/modules/confiant-ad-quality/src/main/java/org/prebid/server/hooks/modules/com/confiant/adquality/v1/ConfiantAdQualityBidResponsesScanHook.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ private InvocationResult<AllProcessedBidResponsesPayload> toInvocationResult(
119119
.payloadUpdate(payload -> AllProcessedBidResponsesPayloadImpl.of(
120120
Stream.concat(bidderResponsesWithoutIssues.stream(), notScannedBidderResponses.stream()).toList()));
121121

122-
System.out.println("ConfiantAdQualityBidResponsesScanHook/ InvocationResult: " + resultBuilder.build());
123-
124122
return resultBuilder.build();
125123
}
126124

extra/modules/greenbids-real-time-data/pom.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,40 @@
3434
</dependency>
3535
</dependencies>
3636

37+
<build>
38+
<plugins>
39+
<plugin>
40+
<groupId>org.apache.maven.plugins</groupId>
41+
<artifactId>maven-checkstyle-plugin</artifactId>
42+
<version>3.4.0</version>
43+
<executions>
44+
<execution>
45+
<id>checkstyle</id>
46+
<phase>compile</phase> <!-- Run during the compile phase -->
47+
<goals>
48+
<goal>check</goal>
49+
</goals>
50+
</execution>
51+
</executions>
52+
<configuration>
53+
<!-- Project rooted path to CheckStyle configuration file. -->
54+
<configLocation>checkstyle.xml</configLocation>
55+
<encoding>UTF-8</encoding>
56+
<consoleOutput>true</consoleOutput>
57+
<!-- true if project build should fails on any style violation. -->
58+
<failsOnError>true</failsOnError>
59+
<linkXRef>false</linkXRef>
60+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
61+
</configuration>
62+
<dependencies>
63+
<dependency>
64+
<groupId>com.puppycrawl.tools</groupId>
65+
<artifactId>checkstyle</artifactId>
66+
<version>10.17.0</version>
67+
</dependency>
68+
</dependencies>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
3773
</project>

extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/config/GreenbidsRealTimeDataConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public class GreenbidsRealTimeDataConfiguration {
2323

2424
@Bean
2525
GreenbidsRealTimeDataModule greenbidsRealTimeDataModule(
26-
@Value("${hooks.modules.greenbids-real-time-data.google-cloud-greenbids-project}") String googleCloudGreenbidsProject,
26+
@Value("${hooks.modules.greenbids-real-time-data.google-cloud-greenbids-project}")
27+
String googleCloudGreenbidsProject,
2728
@Value("${hooks.modules.greenbids-real-time-data.gcs-bucket-name}") String gcsBucketName,
2829
@Value("${hooks.modules.greenbids-real-time-data.cache-expiration-minutes}") Integer cacheExpirationMinutes,
2930
@Value("${hooks.modules.greenbids-real-time-data.geo-lite-country-path}") String geoLiteCountryPath) {

extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/core/Partner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public Partner(
3232
}
3333

3434
public Double getThresholdForPartner(ThrottlingThresholds throttlingThresholds) {
35-
List<Double> truePositiveRates = throttlingThresholds.getTpr();
36-
List<Double> thresholds = throttlingThresholds.getThresholds();
35+
final List<Double> truePositiveRates = throttlingThresholds.getTpr();
36+
final List<Double> thresholds = throttlingThresholds.getThresholds();
3737

3838
return truePositiveRates.stream()
3939
.filter(truePositiveRate -> truePositiveRate >= targetTpr)

extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/model/GreenbidsRealTimeDataProperties.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
@Value(staticConstructor = "of")
99
public class GreenbidsRealTimeDataProperties {
10+
1011
@JsonProperty(value = "modelCacheWithExpiration", required = true)
1112
Cache<String, OnnxModelRunner> modelCacheWithExpiration;
1213

extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/model/GreenbidsUserAgent.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@
88
import java.util.Set;
99

1010
public class GreenbidsUserAgent {
11+
1112
public static final Set<String> PC_OS_FAMILIES = Set.of(
1213
"Windows 95", "Windows 98", "Solaris");
1314

15+
private static final Parser UA_PARSER = new Parser();
16+
1417
private final String userAgentString;
18+
1519
private final UserAgent userAgent;
20+
1621
private final ua_parser.Device device;
17-
private final ua_parser.OS os;
1822

19-
private static final Parser uaParser = new Parser();
23+
private final ua_parser.OS os;
2024

2125
public GreenbidsUserAgent(String userAgentString) {
2226
this.userAgentString = userAgentString;
23-
Client client = uaParser.parse(userAgentString);
27+
final Client client = UA_PARSER.parse(userAgentString);
2428
this.userAgent = client.userAgent;
2529
this.device = client.device;
2630
this.os = client.os;
@@ -43,10 +47,10 @@ public String getBrowser() {
4347
}
4448

4549
public boolean isPC() {
46-
return userAgentString.contains("Windows NT") ||
47-
PC_OS_FAMILIES.contains(os.family) ||
48-
("Windows".equals(os.family) && "ME".equals(os.major)) ||
49-
("Mac OS X".equals(os.family) && !userAgentString.contains("Silk")) ||
50-
userAgentString.contains("Linux") && userAgentString.contains("X11");
50+
return userAgentString.contains("Windows NT")
51+
|| PC_OS_FAMILIES.contains(os.family)
52+
|| ("Windows".equals(os.family) && "ME".equals(os.major))
53+
|| ("Mac OS X".equals(os.family) && !userAgentString.contains("Silk"))
54+
|| userAgentString.contains("Linux") && userAgentString.contains("X11");
5155
}
5256
}

extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/model/ModelCache.java

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@
99
import lombok.Getter;
1010
import org.prebid.server.exception.PreBidException;
1111

12-
import java.util.Map;
1312
import java.util.concurrent.locks.ReentrantLock;
1413

1514
public class ModelCache {
1615

1716
String gcsBucketName;
17+
1818
String modelPath;
19+
1920
@Getter
2021
Cache<String, OnnxModelRunner> cache;
22+
2123
Storage storage;
24+
2225
ReentrantLock lock;
2326

2427
public ModelCache(
@@ -34,39 +37,19 @@ public ModelCache(
3437
}
3538

3639
public OnnxModelRunner getModelRunner(String pbuid) {
37-
String cacheKey = "onnxModelRunner_" + pbuid;
38-
39-
OnnxModelRunner cachedOnnxModelRunner = cache.getIfPresent(cacheKey);
40-
System.out.println(
41-
"getModelRunner: \n" +
42-
" cacheKey: " + cacheKey + "\n" +
43-
" cachedOnnxModelRunner: " + cachedOnnxModelRunner + "\n" +
44-
" cache: " + cache
45-
);
46-
47-
for (Map.Entry<String, OnnxModelRunner> entry: cache.asMap().entrySet()) {
48-
System.out.println("\nKey: " + entry.getKey() + ", Value: " + entry.getValue() + "\n");
49-
}
40+
final String cacheKey = "onnxModelRunner_" + pbuid;
41+
final OnnxModelRunner cachedOnnxModelRunner = cache.getIfPresent(cacheKey);
5042

5143
if (cachedOnnxModelRunner != null) {
52-
System.out.println("cachedOnnxModelRunner available");
5344
return cachedOnnxModelRunner;
54-
};
45+
}
5546

56-
boolean locked = lock.tryLock();
47+
final boolean locked = lock.tryLock();
5748
try {
5849
if (locked) {
59-
Blob blob = getBlob();
60-
61-
System.out.println(
62-
"getModelRunner: \n" +
63-
" blob: " + blob + "\n" +
64-
" cache: " + cache
65-
);
66-
50+
final Blob blob = getBlob();
6751
cache.put(cacheKey, loadModelRunner(blob));
6852
} else {
69-
System.out.println("Another thread is updating the cache. Skipping fetching predictor.");
7053
return null;
7154
}
7255
} finally {
@@ -80,23 +63,16 @@ public OnnxModelRunner getModelRunner(String pbuid) {
8063

8164
private Blob getBlob() {
8265
try {
83-
System.out.println(
84-
"getBlob: \n" +
85-
" storage: " + storage + "\n" +
86-
" gcsBucketName: " + gcsBucketName + "\n" +
87-
" modelPath: " + modelPath + "\n"
88-
);
89-
Bucket bucket = storage.get(gcsBucketName);
66+
final Bucket bucket = storage.get(gcsBucketName);
9067
return bucket.get(modelPath);
9168
} catch (StorageException e) {
92-
System.out.println("Error accessing GCS artefact for model: " + e);
9369
throw new PreBidException("Error accessing GCS artefact for model: ", e);
9470
}
9571
}
9672

9773
private OnnxModelRunner loadModelRunner(Blob blob) {
9874
try {
99-
byte[] onnxModelBytes = blob.getContent();
75+
final byte[] onnxModelBytes = blob.getContent();
10076
return new OnnxModelRunner(onnxModelBytes);
10177
} catch (OrtException e) {
10278
throw new RuntimeException("Failed to load ONNX model", e);

extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/model/OnnxModelRunner.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
import java.util.Collections;
99

1010
public class OnnxModelRunner {
11+
1112
private OrtSession session;
13+
1214
private OrtEnvironment environment;
1315

1416
public OnnxModelRunner(byte[] onnxModelBytes) throws OrtException {
1517
environment = OrtEnvironment.getEnvironment();
16-
OrtSession.SessionOptions options = new OrtSession.SessionOptions();
18+
final OrtSession.SessionOptions options = new OrtSession.SessionOptions();
1719
session = environment.createSession(onnxModelBytes, options);
1820
}
1921

2022
public OrtSession.Result runModel(String[][] throttlingInferenceRow) throws OrtException {
21-
OnnxTensor inputTensor = OnnxTensor.createTensor(OrtEnvironment.getEnvironment(), throttlingInferenceRow);
23+
final OnnxTensor inputTensor = OnnxTensor.createTensor(OrtEnvironment.getEnvironment(), throttlingInferenceRow);
2224
return session.run(Collections.singletonMap("input", inputTensor));
2325
}
2426
}

extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/model/ThresholdCache.java

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.prebid.server.hooks.modules.greenbids.real.time.data.core.ThrottlingThresholds;
1212

1313
import java.io.IOException;
14-
import java.util.Map;
1514
import java.util.concurrent.locks.ReentrantLock;
1615

1716
public class ThresholdCache {
@@ -39,39 +38,19 @@ public ThresholdCache(
3938
}
4039

4140
public ThrottlingThresholds getThrottlingThresholds(String pbuid) {
42-
String cacheKey = "throttlingThresholds_" + pbuid;
43-
44-
ThrottlingThresholds cachedThrottlingThresholds = cache.getIfPresent(cacheKey);
45-
System.out.println(
46-
"getThrottlingThresholds: \n" +
47-
" cacheKey: " + cacheKey + "\n" +
48-
" cachedThrottlingThresholds: " + cachedThrottlingThresholds + "\n" +
49-
" cache: " + cache
50-
);
51-
52-
for (Map.Entry<String, ThrottlingThresholds> entry: cache.asMap().entrySet()) {
53-
System.out.println("\nKey: " + entry.getKey() + ", Value: " + entry.getValue() + "\n");
54-
}
41+
final String cacheKey = "throttlingThresholds_" + pbuid;
42+
final ThrottlingThresholds cachedThrottlingThresholds = cache.getIfPresent(cacheKey);
5543

5644
if (cachedThrottlingThresholds != null) {
57-
System.out.println("cachedThrottlingThresholds available");
5845
return cachedThrottlingThresholds;
59-
};
46+
}
6047

61-
boolean locked = lock.tryLock();
48+
final boolean locked = lock.tryLock();
6249
try {
6350
if (locked) {
64-
Blob blob = getBlob();
65-
66-
System.out.println(
67-
"getThrottlingThresholds: \n" +
68-
"read blob: " + blob + "\n" +
69-
"put in cache: " + cache
70-
);
71-
51+
final Blob blob = getBlob();
7252
cache.put(cacheKey, loadThrottlingThresholds(blob));
7353
} else {
74-
System.out.println("Another thread is updating the cache. Skipping fetching predictor.");
7554
return null;
7655
}
7756
} finally {
@@ -85,26 +64,18 @@ public ThrottlingThresholds getThrottlingThresholds(String pbuid) {
8564

8665
private Blob getBlob() {
8766
try {
88-
System.out.println(
89-
"getBlob: \n" +
90-
"storage: " + storage + "\n" +
91-
"gcsBucketName: " + gcsBucketName + "\n" +
92-
"thresholdPath: " + thresholdPath + "\n"
93-
);
9467
return storage.get(gcsBucketName).get(thresholdPath);
9568
} catch (StorageException e) {
96-
System.out.println("Error accessing GCS artefact for threshold: " + e);
9769
throw new PreBidException("Error accessing GCS artefact for threshold: ", e);
9870
}
9971
}
10072

10173
private ThrottlingThresholds loadThrottlingThresholds(Blob blob) {
102-
JsonNode thresholdsJsonNode;
74+
final JsonNode thresholdsJsonNode;
10375
try {
104-
byte[] jsonBytes = blob.getContent();
76+
final byte[] jsonBytes = blob.getContent();
10577
thresholdsJsonNode = mapper.readTree(jsonBytes);
106-
ThrottlingThresholds throttlingThresholds = mapper.treeToValue(thresholdsJsonNode, ThrottlingThresholds.class);
107-
return throttlingThresholds;
78+
return mapper.treeToValue(thresholdsJsonNode, ThrottlingThresholds.class);
10879
} catch (IOException e) {
10980
throw new RuntimeException(e);
11081
}

extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/v1/GreenbidsRealTimeDataModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.List;
99

1010
public class GreenbidsRealTimeDataModule implements Module {
11+
1112
public static final String CODE = "greenbids-real-time-data";
1213

1314
private final List<? extends Hook<?, ? extends InvocationContext>> hooks;

0 commit comments

Comments
 (0)