KAFKA-17314 Fix the typo: `maxlifeTimeMs` (#17749)

Reviewers: TengYao Chi <kitingiao@gmail.com>, Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
Ken Huang 2024-11-12 16:26:29 +08:00 committed by GitHub
parent a951b73fa5
commit 207b35901c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 32 additions and 15 deletions

View File

@ -31,7 +31,7 @@ import java.util.Optional;
*/ */
@InterfaceStability.Evolving @InterfaceStability.Evolving
public class CreateDelegationTokenOptions extends AbstractOptions<CreateDelegationTokenOptions> { public class CreateDelegationTokenOptions extends AbstractOptions<CreateDelegationTokenOptions> {
private long maxLifeTimeMs = -1; private long maxLifetimeMs = -1;
private List<KafkaPrincipal> renewers = new LinkedList<>(); private List<KafkaPrincipal> renewers = new LinkedList<>();
private KafkaPrincipal owner = null; private KafkaPrincipal owner = null;
@ -53,12 +53,29 @@ public class CreateDelegationTokenOptions extends AbstractOptions<CreateDelegati
return Optional.ofNullable(owner); return Optional.ofNullable(owner);
} }
public CreateDelegationTokenOptions maxlifeTimeMs(long maxLifeTimeMs) { /**
this.maxLifeTimeMs = maxLifeTimeMs; * @deprecated since 4.0 and should not be used any longer.
*/
@Deprecated
public CreateDelegationTokenOptions maxlifeTimeMs(long maxLifetimeMs) {
this.maxLifetimeMs = maxLifetimeMs;
return this; return this;
} }
public CreateDelegationTokenOptions maxLifetimeMs(long maxLifetimeMs) {
this.maxLifetimeMs = maxLifetimeMs;
return this;
}
/**
* @deprecated since 4.0 and should not be used any longer.
*/
@Deprecated
public long maxlifeTimeMs() { public long maxlifeTimeMs() {
return maxLifeTimeMs; return maxLifetimeMs;
}
public long maxLifetimeMs() {
return maxLifetimeMs;
} }
} }

View File

@ -3371,7 +3371,7 @@ public class KafkaAdminClient extends AdminClient {
CreateDelegationTokenRequest.Builder createRequest(int timeoutMs) { CreateDelegationTokenRequest.Builder createRequest(int timeoutMs) {
CreateDelegationTokenRequestData data = new CreateDelegationTokenRequestData() CreateDelegationTokenRequestData data = new CreateDelegationTokenRequestData()
.setRenewers(renewers) .setRenewers(renewers)
.setMaxLifetimeMs(options.maxlifeTimeMs()); .setMaxLifetimeMs(options.maxLifetimeMs());
if (options.owner().isPresent()) { if (options.owner().isPresent()) {
data.setOwnerPrincipalName(options.owner().get().getName()); data.setOwnerPrincipalName(options.owner().get().getName());
data.setOwnerPrincipalType(options.owner().get().getPrincipalType()); data.setOwnerPrincipalType(options.owner().get().getPrincipalType());

View File

@ -646,7 +646,7 @@ public class MockAdminClient extends AdminClient {
} }
String tokenId = Uuid.randomUuid().toString(); String tokenId = Uuid.randomUuid().toString();
TokenInformation tokenInfo = new TokenInformation(tokenId, options.renewers().get(0), options.renewers(), System.currentTimeMillis(), options.maxlifeTimeMs(), -1); TokenInformation tokenInfo = new TokenInformation(tokenId, options.renewers().get(0), options.renewers(), System.currentTimeMillis(), options.maxLifetimeMs(), -1);
DelegationToken token = new DelegationToken(tokenInfo, tokenId.getBytes()); DelegationToken token = new DelegationToken(tokenInfo, tokenId.getBytes());
allTokens.add(token); allTokens.add(token);
future.complete(token); future.complete(token);

View File

@ -173,7 +173,7 @@ class SaslSslAdminIntegrationTest extends BaseAdminIntegrationTest with SaslSetu
val renewer = List(SecurityUtils.parseKafkaPrincipal("User:renewer")) val renewer = List(SecurityUtils.parseKafkaPrincipal("User:renewer"))
def generateTokenResult(maxLifeTimeMs: Int, expiryTimePeriodMs: Int, expectedTokenNum: Int): (CreateDelegationTokenResult, ExpireDelegationTokenResult) = { def generateTokenResult(maxLifeTimeMs: Int, expiryTimePeriodMs: Int, expectedTokenNum: Int): (CreateDelegationTokenResult, ExpireDelegationTokenResult) = {
val createResult = client.createDelegationToken(new CreateDelegationTokenOptions().renewers(renewer.asJava).maxlifeTimeMs(maxLifeTimeMs)) val createResult = client.createDelegationToken(new CreateDelegationTokenOptions().renewers(renewer.asJava).maxLifetimeMs(maxLifeTimeMs))
val tokenCreated = createResult.delegationToken.get val tokenCreated = createResult.delegationToken.get
TestUtils.waitUntilTrue(() => brokers.forall(server => server.tokenCache.tokens().size() == expectedTokenNum), TestUtils.waitUntilTrue(() => brokers.forall(server => server.tokenCache.tokens().size() == expectedTokenNum),
"Timed out waiting for token to propagate to all servers") "Timed out waiting for token to propagate to all servers")
@ -413,7 +413,7 @@ class SaslSslAdminIntegrationTest extends BaseAdminIntegrationTest with SaslSetu
client = createAdminClient client = createAdminClient
val timeout = 5000 val timeout = 5000
val options = new CreateDelegationTokenOptions().maxlifeTimeMs(timeout) val options = new CreateDelegationTokenOptions().maxLifetimeMs(timeout)
val tokenInfo = client.createDelegationToken(options).delegationToken.get.tokenInfo val tokenInfo = client.createDelegationToken(options).delegationToken.get.tokenInfo
assertEquals(timeout, tokenInfo.maxTimestamp - tokenInfo.issueTimestamp) assertEquals(timeout, tokenInfo.maxTimestamp - tokenInfo.issueTimestamp)
@ -426,7 +426,7 @@ class SaslSslAdminIntegrationTest extends BaseAdminIntegrationTest with SaslSetu
client = createAdminClient client = createAdminClient
val timeout = 5000 val timeout = 5000
val createOptions = new CreateDelegationTokenOptions().maxlifeTimeMs(timeout) val createOptions = new CreateDelegationTokenOptions().maxLifetimeMs(timeout)
val token = client.createDelegationToken(createOptions).delegationToken.get val token = client.createDelegationToken(createOptions).delegationToken.get
val tokenInfo = token.tokenInfo val tokenInfo = token.tokenInfo
@ -634,7 +634,7 @@ class SaslSslAdminIntegrationTest extends BaseAdminIntegrationTest with SaslSetu
@ValueSource(strings = Array("kraft")) @ValueSource(strings = Array("kraft"))
def testExpireDelegationToken(quorum: String): Unit = { def testExpireDelegationToken(quorum: String): Unit = {
client = createAdminClient client = createAdminClient
val createDelegationTokenOptions = new CreateDelegationTokenOptions().maxlifeTimeMs(5000) val createDelegationTokenOptions = new CreateDelegationTokenOptions().maxLifetimeMs(5000)
// Test expiration for non-exists token // Test expiration for non-exists token
TestUtils.assertFutureExceptionTypeEquals( TestUtils.assertFutureExceptionTypeEquals(
@ -647,7 +647,7 @@ class SaslSslAdminIntegrationTest extends BaseAdminIntegrationTest with SaslSetu
TestUtils.retry(maxWaitMs = 1000) { assertTrue(expireTokenOrFailWithAssert(token1, -1) < System.currentTimeMillis()) } TestUtils.retry(maxWaitMs = 1000) { assertTrue(expireTokenOrFailWithAssert(token1, -1) < System.currentTimeMillis()) }
// Test expiring the expired token // Test expiring the expired token
val token2 = client.createDelegationToken(createDelegationTokenOptions.maxlifeTimeMs(1000)).delegationToken().get() val token2 = client.createDelegationToken(createDelegationTokenOptions.maxLifetimeMs(1000)).delegationToken().get()
// Ensure current time > maxLifeTimeMs of token // Ensure current time > maxLifeTimeMs of token
Thread.sleep(1000) Thread.sleep(1000)
TestUtils.assertFutureExceptionTypeEquals( TestUtils.assertFutureExceptionTypeEquals(
@ -667,7 +667,7 @@ class SaslSslAdminIntegrationTest extends BaseAdminIntegrationTest with SaslSetu
@ValueSource(strings = Array("kraft")) @ValueSource(strings = Array("kraft"))
def testCreateTokenWithOverflowTimestamp(quorum: String): Unit = { def testCreateTokenWithOverflowTimestamp(quorum: String): Unit = {
client = createAdminClient client = createAdminClient
val token = client.createDelegationToken(new CreateDelegationTokenOptions().maxlifeTimeMs(Long.MaxValue)).delegationToken().get() val token = client.createDelegationToken(new CreateDelegationTokenOptions().maxLifetimeMs(Long.MaxValue)).delegationToken().get()
assertEquals(Long.MaxValue, token.tokenInfo().expiryTimestamp()) assertEquals(Long.MaxValue, token.tokenInfo().expiryTimestamp())
} }
@ -675,7 +675,7 @@ class SaslSslAdminIntegrationTest extends BaseAdminIntegrationTest with SaslSetu
@ValueSource(strings = Array("kraft")) @ValueSource(strings = Array("kraft"))
def testExpireTokenWithOverflowTimestamp(quorum: String): Unit = { def testExpireTokenWithOverflowTimestamp(quorum: String): Unit = {
client = createAdminClient client = createAdminClient
val token = client.createDelegationToken(new CreateDelegationTokenOptions().maxlifeTimeMs(Long.MaxValue)).delegationToken().get() val token = client.createDelegationToken(new CreateDelegationTokenOptions().maxLifetimeMs(Long.MaxValue)).delegationToken().get()
TestUtils.retry(1000) { assertTrue(expireTokenOrFailWithAssert(token, Long.MaxValue) == Long.MaxValue) } TestUtils.retry(1000) { assertTrue(expireTokenOrFailWithAssert(token, Long.MaxValue) == Long.MaxValue) }
} }

View File

@ -151,7 +151,7 @@ class DelegationTokenRequestsTest extends IntegrationTestHarness with SaslSetup
// Create a DelegationToken with a short lifetime to validate the expire code // Create a DelegationToken with a short lifetime to validate the expire code
val createResult5 = adminClient.createDelegationToken(new CreateDelegationTokenOptions() val createResult5 = adminClient.createDelegationToken(new CreateDelegationTokenOptions()
.renewers(renewer1) .renewers(renewer1)
.maxlifeTimeMs(1 * 1000)) .maxLifetimeMs(1 * 1000))
val token5 = createResult5.delegationToken().get() val token5 = createResult5.delegationToken().get()
TestUtils.waitUntilTrue(() => brokers.forall(server => server.tokenCache.tokens().size() == 1), TestUtils.waitUntilTrue(() => brokers.forall(server => server.tokenCache.tokens().size() == 1),

View File

@ -97,7 +97,7 @@ public class DelegationTokenCommand {
Long maxLifeTimeMs = opts.maxLifeTime(); Long maxLifeTimeMs = opts.maxLifeTime();
System.out.println("Calling create token operation with renewers :" + renewerPrincipals + " , max-life-time-period :" + maxLifeTimeMs); System.out.println("Calling create token operation with renewers :" + renewerPrincipals + " , max-life-time-period :" + maxLifeTimeMs);
CreateDelegationTokenOptions createDelegationTokenOptions = new CreateDelegationTokenOptions().maxlifeTimeMs(maxLifeTimeMs).renewers(renewerPrincipals); CreateDelegationTokenOptions createDelegationTokenOptions = new CreateDelegationTokenOptions().maxLifetimeMs(maxLifeTimeMs).renewers(renewerPrincipals);
List<KafkaPrincipal> ownerPrincipals = getPrincipals(opts, opts.ownerPrincipalsOpt); List<KafkaPrincipal> ownerPrincipals = getPrincipals(opts, opts.ownerPrincipalsOpt);
if (!ownerPrincipals.isEmpty()) { if (!ownerPrincipals.isEmpty()) {