Skip to content

Commit 198e832

Browse files
committed
Refactor MoSAPI models to records and address review nits
- Convert model classes to Java records for conciseness and immutability. - Update unit tests to use Java text blocks for improved JSON readability. - Simplify service and action layers by removing redundant logic and logging. - Fix configuration nits regarding primitive types and comment formatting.
1 parent f083a1e commit 198e832

18 files changed

+309
-322
lines changed

core/src/main/java/google/registry/config/RegistryConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ public static ImmutableSet<String> provideMosapiServices(RegistryConfigSettings
14641464

14651465
@Provides
14661466
@Config("mosapiTldThreadCnt")
1467-
public static Integer provideMosapiTldThreads(RegistryConfigSettings config) {
1467+
public static int provideMosapiTldThreads(RegistryConfigSettings config) {
14681468
return config.mosapi.tldThreadCnt;
14691469
}
14701470

core/src/main/java/google/registry/config/RegistryConfigSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,6 @@ public static class MosApi {
272272
public String entityType;
273273
public List<String> tlds;
274274
public List<String> services;
275-
public Integer tldThreadCnt;
275+
public int tldThreadCnt;
276276
}
277277
}

core/src/main/java/google/registry/config/files/default-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ mosapi:
642642
- "epp"
643643
- "dnssec"
644644

645-
#Provides a fixed thread pool for parallel TLD processing.
645+
# Provides a fixed thread pool for parallel TLD processing.
646646
# @see <a href="https://www.icann.org/mosapi-specification.pdf">
647647
# ICANN MoSAPI Specification, Section 12.3</a>
648648
tldThreadCnt: 4

core/src/main/java/google/registry/mosapi/GetServiceStateAction.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package google.registry.mosapi;
1616

17-
import com.google.common.flogger.FluentLogger;
1817
import com.google.common.net.MediaType;
1918
import com.google.gson.Gson;
2019
import google.registry.request.Action;
@@ -32,7 +31,6 @@
3231
method = Action.Method.GET,
3332
auth = Auth.AUTH_ADMIN)
3433
public class GetServiceStateAction implements Runnable {
35-
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
3634

3735
public static final String PATH = "/_dr/mosapi/getServiceState";
3836
public static final String TLD_PARAM = "tld";
@@ -64,8 +62,6 @@ public void run() {
6462
response.setPayload(gson.toJson(stateService.getAllServiceStateSummaries()));
6563
}
6664
} catch (MosApiException e) {
67-
logger.atWarning().withCause(e).log(
68-
"MoSAPI client failed to get Service state for %s TLD", tld.orElse("all"));
6965
throw new ServiceUnavailableException("Error fetching MoSAPI service state.");
7066
}
7167
}

core/src/main/java/google/registry/mosapi/MosApiStateService.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
/** A service that provides business logic for interacting with MoSAPI Service State. */
3434
public class MosApiStateService {
35+
3536
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
3637
private final ServiceMonitoringClient serviceMonitoringClient;
3738
private final ExecutorService tldExecutor;
@@ -91,24 +92,24 @@ public AllServicesStateResponse getAllServiceStateSummaries() {
9192

9293
private ServiceStateSummary transformToSummary(TldServiceState rawState) {
9394
List<ServiceStatus> activeIncidents = null;
94-
if (DOWN_STATUS.equalsIgnoreCase(rawState.getStatus())) {
95+
if (DOWN_STATUS.equalsIgnoreCase(rawState.status())) {
9596
activeIncidents =
96-
rawState.getServiceStatuses().entrySet().stream()
97+
rawState.serviceStatuses().entrySet().stream()
9798
.filter(
9899
entry -> {
99100
ServiceStatus serviceStatus = entry.getValue();
100-
return serviceStatus.getIncidents() != null
101-
&& !serviceStatus.getIncidents().isEmpty();
101+
return serviceStatus.incidents() != null
102+
&& !serviceStatus.incidents().isEmpty();
102103
})
103104
.map(
104105
entry ->
105106
new ServiceStatus(
106107
// key is the service name
107108
entry.getKey(),
108-
entry.getValue().getEmergencyThreshold(),
109-
entry.getValue().getIncidents()))
109+
entry.getValue().emergencyThreshold(),
110+
entry.getValue().incidents()))
110111
.collect(toImmutableList());
111112
}
112-
return new ServiceStateSummary(rawState.getTld(), rawState.getStatus(), activeIncidents);
113+
return new ServiceStateSummary(rawState.tld(), rawState.status(), activeIncidents);
113114
}
114115
}

core/src/main/java/google/registry/mosapi/ServiceMonitoringClient.java

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

2626
/** Facade for MoSAPI's service monitoring endpoints. */
2727
public class ServiceMonitoringClient {
28+
2829
private final MosApiClient mosApiClient;
2930
private final Gson gson;
3031

core/src/main/java/google/registry/mosapi/model/AllServicesStateResponse.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,11 @@
2626
* @see <a href="https://www.icann.org/mosapi-specification.pdf">ICANN MoSAPI Specification, Section
2727
* 5.1</a>
2828
*/
29-
public final class AllServicesStateResponse {
29+
public record AllServicesStateResponse(
30+
// A list of state summaries for each monitored service (e.g. DNS, RDDS, etc.)
31+
@Expose @SerializedName("serviceStates") List<ServiceStateSummary> serviceStates) {
3032

31-
// A list of state summaries for each monitored service (e.g. DNS, RDDS, etc.)
32-
@Expose
33-
@SerializedName("serviceStates")
34-
private final List<ServiceStateSummary> serviceStates;
35-
36-
public AllServicesStateResponse(List<ServiceStateSummary> serviceStates) {
37-
this.serviceStates = serviceStates;
38-
}
39-
40-
public List<ServiceStateSummary> getServiceStates() {
41-
return serviceStates;
33+
public AllServicesStateResponse {
34+
serviceStates = (serviceStates == null) ? List.of() : List.copyOf(serviceStates);
4235
}
4336
}

core/src/main/java/google/registry/mosapi/model/IncidentSummary.java

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,54 +24,9 @@
2424
* @see <a href="https://www.icann.org/mosapi-specification.pdf">ICANN MoSAPI Specification, Section
2525
* 5.1</a>
2626
*/
27-
public final class IncidentSummary {
28-
@Expose
29-
@SerializedName("incidentID")
30-
private String incidentID;
31-
32-
@Expose
33-
@SerializedName("startTime")
34-
private long startTime;
35-
36-
@Expose
37-
@SerializedName("falsePositive")
38-
private boolean falsePositive;
39-
40-
@Expose
41-
@SerializedName("state")
42-
private String state;
43-
44-
@Expose
45-
@SerializedName("endTime")
46-
@Nullable
47-
private Long endTime;
48-
49-
public IncidentSummary(
50-
String incidentID, long startTime, boolean falsePositive, String state, Long endTime) {
51-
this.incidentID = incidentID;
52-
this.startTime = startTime;
53-
this.falsePositive = falsePositive;
54-
this.state = state;
55-
this.endTime = endTime;
56-
}
57-
58-
public String getIncidentID() {
59-
return incidentID;
60-
}
61-
62-
public long getStartTime() {
63-
return startTime;
64-
}
65-
66-
public boolean isFalsePositive() {
67-
return falsePositive;
68-
}
69-
70-
public String getState() {
71-
return state;
72-
}
73-
74-
public Long getEndTime() {
75-
return endTime;
76-
}
77-
}
27+
public record IncidentSummary(
28+
@Expose @SerializedName("incidentID") String incidentID,
29+
@Expose @SerializedName("startTime") long startTime,
30+
@Expose @SerializedName("falsePositive") boolean falsePositive,
31+
@Expose @SerializedName("state") String state,
32+
@Expose @SerializedName("endTime") @Nullable Long endTime) {}

core/src/main/java/google/registry/mosapi/model/ServiceStateSummary.java

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,12 @@
2828
* @see <a href="https://www.icann.org/mosapi-specification.pdf">ICANN MoSAPI Specification, Section
2929
* 5.1</a>
3030
*/
31-
public final class ServiceStateSummary {
32-
@Expose
33-
@SerializedName("tld")
34-
private final String tld;
31+
public record ServiceStateSummary(
32+
@Expose @SerializedName("tld") String tld,
33+
@Expose @SerializedName("overallStatus") String overallStatus,
34+
@Expose @SerializedName("activeIncidents") @Nullable List<ServiceStatus> activeIncidents) {
3535

36-
// The overall status of the TLD (e.g. "Up", "Down", "UP-inconclusive")
37-
@Expose
38-
@SerializedName("overallStatus")
39-
private final String overallStatus;
40-
41-
/*
42-
A list of summaries for services that currently have active incidents. May be null or empty if
43-
the status is "up"
44-
*/
45-
@Expose
46-
@SerializedName("activeIncidents")
47-
@Nullable
48-
private final List<ServiceStatus> activeIncidents;
49-
50-
public ServiceStateSummary(
51-
String tld, String overallStatus, @Nullable List<ServiceStatus> activeIncidents) {
52-
this.tld = tld;
53-
this.overallStatus = overallStatus;
54-
this.activeIncidents = activeIncidents;
55-
}
56-
57-
public String getTld() {
58-
return tld;
59-
}
60-
61-
public String getOverallStatus() {
62-
return overallStatus;
63-
}
64-
65-
@Nullable
66-
public List<ServiceStatus> getActiveIncidents() {
67-
return activeIncidents;
36+
public ServiceStateSummary {
37+
activeIncidents = activeIncidents == null ? null : List.copyOf(activeIncidents);
6838
}
6939
}

core/src/main/java/google/registry/mosapi/model/ServiceStatus.java

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,20 @@
1919
import java.util.List;
2020

2121
/** Represents the status of a single monitored service. */
22-
public final class ServiceStatus {
23-
/**
24-
* A JSON string that contains the status of the Service as seen from the monitoring system.
25-
* Possible values include "Up", "Down", "Disabled", "UP-inconclusive-no-data", etc.
26-
*
27-
* @see <a href="https://www.icann.org/mosapi-specification.pdf">ICANN MoSAPI Specification,
28-
* Section 5.1</a>
29-
*/
30-
@Expose
31-
@SerializedName("status")
32-
private String status;
33-
34-
// A JSON number that contains the current percentage of the Emergency Threshold
35-
// of the Service. A value of "0" specifies that there are no Incidents
36-
// affecting the threshold.
37-
@Expose
38-
@SerializedName("emergencyThreshold")
39-
private double emergencyThreshold;
40-
41-
@Expose
42-
@SerializedName("incidents")
43-
private List<IncidentSummary> incidents;
44-
45-
public ServiceStatus(String status, double emergencyThreshold, List<IncidentSummary> incidents) {
46-
this.status = status;
47-
this.emergencyThreshold = emergencyThreshold;
48-
this.incidents = incidents;
49-
}
50-
51-
public String getStatus() {
52-
return status;
53-
}
54-
55-
public double getEmergencyThreshold() {
56-
return emergencyThreshold;
57-
}
58-
59-
public List<IncidentSummary> getIncidents() {
60-
return incidents;
22+
public record ServiceStatus(
23+
/**
24+
* A JSON string that contains the status of the Service as seen from the monitoring system.
25+
* Possible values include "Up", "Down", "Disabled", "UP-inconclusive-no-data", etc.
26+
*/
27+
@Expose @SerializedName("status") String status,
28+
29+
// A JSON number that contains the current percentage of the Emergency Threshold
30+
// of the Service. A value of "0" specifies that there are no Incidents
31+
// affecting the threshold.
32+
@Expose @SerializedName("emergencyThreshold") double emergencyThreshold,
33+
@Expose @SerializedName("incidents") List<IncidentSummary> incidents) {
34+
35+
public ServiceStatus {
36+
incidents = incidents == null ? List.of() : List.copyOf(incidents);
6137
}
6238
}

0 commit comments

Comments
 (0)