Skip to content

Commit

Permalink
refactor: move DataCenterInfo and LeaseInfo classes
Browse files Browse the repository at this point in the history
Motivation:

Since it is ensured that the public API does not expose the shaded classes, after moving `com.linecorp.armeria.internal.common.eureka.InstanceInfo` to `com.linecorp.armeria.common.eureka.InstanceInfo`, the same exception occurs with the following jobs:
- build-ubicloud-standard-16-jdk-*
- build-macos-latest-jdk-21
- build-windows-latest-jdk-21

```
Execution failed for task ':javadoc:checkJavadoc'.
> java.lang.Exception: Disallowed class(es) in the public API:
  - InstanceInfo -> com.linecorp.armeria.internal.common.eureka.DataCenterInfo
  - InstanceInfo -> com.linecorp.armeria.internal.common.eureka.LeaseInfo
```

Modifications:

- Move `com.linecorp.armeria.internal.common.eureka.DataCenterInfo` to `com.linecorp.armeria.common.eureka.DataCenterInfo`.
- Move `com.linecorp.armeria.internal.common.eureka.LeaseInfo` to `com.linecorp.armeria.common.eureka.LeaseInfo`.
- Make public `com.linecorp.armeria.internal.common.eureka.DataCenterInfoSerializer`

Result:

DataCenterInfo and LeaseInfo classes are now allowed
  • Loading branch information
Ivan-Montes committed Jan 16, 2025
1 parent 258fd3f commit a945657
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.linecorp.armeria.internal.common.eureka;
package com.linecorp.armeria.common.eureka;

import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;
Expand All @@ -27,6 +27,7 @@
import com.google.common.collect.ImmutableMap;

import com.linecorp.armeria.common.annotation.Nullable;
import com.linecorp.armeria.internal.common.eureka.DataCenterInfoSerializer;

/**
* The data center information.
Expand All @@ -52,10 +53,20 @@ public DataCenterInfo(@JsonProperty("name") String name,
}
}

/**
* Returns the name of the object.
*
* @return the name of the object
*/
public String getName() {
return name;
}

/**
* Returns the metadata associated with the object.
*
* @return a map of key-value pairs representing the metadata
*/
public Map<String, String> getMetadata() {
return metadata;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@

import com.linecorp.armeria.client.Endpoint;
import com.linecorp.armeria.common.annotation.Nullable;
import com.linecorp.armeria.internal.common.eureka.DataCenterInfo;
import com.linecorp.armeria.internal.common.eureka.LeaseInfo;

import io.netty.util.AttributeKey;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.linecorp.armeria.internal.common.eureka;
package com.linecorp.armeria.common.eureka;

import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkArgument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

final class DataCenterInfoSerializer extends StdSerializer<DataCenterInfo> {
import com.linecorp.armeria.common.eureka.DataCenterInfo;

public final class DataCenterInfoSerializer extends StdSerializer<DataCenterInfo> {

private static final long serialVersionUID = -5766818057428683420L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@

import com.linecorp.armeria.common.SessionProtocol;
import com.linecorp.armeria.common.annotation.Nullable;
import com.linecorp.armeria.common.eureka.DataCenterInfo;
import com.linecorp.armeria.common.eureka.InstanceInfo;
import com.linecorp.armeria.common.eureka.InstanceInfo.InstanceStatus;
import com.linecorp.armeria.common.eureka.InstanceInfo.PortWrapper;
import com.linecorp.armeria.internal.common.eureka.DataCenterInfo;
import com.linecorp.armeria.internal.common.eureka.LeaseInfo;
import com.linecorp.armeria.common.eureka.LeaseInfo;

import io.netty.util.NetUtil;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ private static com.linecorp.armeria.common.eureka.InstanceInfo convertInstanceIn
info.getMetadata());
}

private static com.linecorp.armeria.internal.common.eureka.LeaseInfo convertLeaseInfo(
private static com.linecorp.armeria.common.eureka.LeaseInfo convertLeaseInfo(
LeaseInfo leaseInfo) {
return new com.linecorp.armeria.internal.common.eureka.LeaseInfo(
return new com.linecorp.armeria.common.eureka.LeaseInfo(
leaseInfo.getRenewalIntervalInSecs(),
leaseInfo.getDurationInSecs(),
leaseInfo.getRegistrationTimestamp(),
Expand Down Expand Up @@ -312,15 +312,15 @@ private static Map<String, String> headersOf(ResponseHeaders headers) {
return result;
}

private static com.linecorp.armeria.internal.common.eureka.DataCenterInfo convertDataCenterInfo(
private static com.linecorp.armeria.common.eureka.DataCenterInfo convertDataCenterInfo(
DataCenterInfo dataCenterInfo) {
final Map<String, String> metadata;
if (dataCenterInfo.getName() == Name.Amazon) {
metadata = ((AmazonInfo) dataCenterInfo).getMetadata();
} else {
metadata = ImmutableMap.of();
}
return new com.linecorp.armeria.internal.common.eureka.DataCenterInfo(
return new com.linecorp.armeria.common.eureka.DataCenterInfo(
dataCenterInfo.getName().name(), metadata);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import com.linecorp.armeria.client.Endpoint;
import com.linecorp.armeria.common.eureka.InstanceInfo.InstanceStatus;
import com.linecorp.armeria.common.eureka.InstanceInfo.PortWrapper;
import com.linecorp.armeria.internal.common.eureka.DataCenterInfo;
import com.linecorp.armeria.internal.common.eureka.LeaseInfo;

class InstanceInfoTest {

Expand Down Expand Up @@ -90,8 +88,8 @@ void getShouldReturnAssociatedInstanceInfo() {
assertThat(instanceInfoRetrieved.getStatusPageUrl()).isEqualTo(statusPageUrl);
assertThat(instanceInfoRetrieved.getHealthCheckUrl()).isEqualTo(healthCheckUrl);
assertThat(instanceInfoRetrieved.getSecureHealthCheckUrl()).isEqualTo(secureHealthCheckUrl);
//assertThat(instanceInfoRetrieved.getDataCenterInfo()).isEqualTo(dataCenterInfo);
//assertThat(instanceInfoRetrieved.getLeaseInfo()).isEqualTo(leaseInfo);
assertThat(instanceInfoRetrieved.getDataCenterInfo()).isEqualTo(dataCenterInfo);
assertThat(instanceInfoRetrieved.getLeaseInfo()).isEqualTo(leaseInfo);
assertThat(instanceInfoRetrieved.getMetadata()).isEqualTo(metadata);
}
}

0 comments on commit a945657

Please sign in to comment.