use of org.apache.kafka.common.requests.ApiVersionsResponse.ApiVersion in project kafka by apache.
the class NodeApiVersionsTest method testUsableVersionLatestVersions.
@Test
public void testUsableVersionLatestVersions() {
List<ApiVersion> versionList = new LinkedList<>();
for (ApiVersion apiVersion : ApiVersionsResponse.API_VERSIONS_RESPONSE.apiVersions()) {
versionList.add(apiVersion);
}
// Add an API key that we don't know about.
versionList.add(new ApiVersion((short) 100, (short) 0, (short) 1));
NodeApiVersions versions = new NodeApiVersions(versionList);
for (ApiKeys apiKey : ApiKeys.values()) {
assertEquals(apiKey.latestVersion(), versions.usableVersion(apiKey));
}
}
use of org.apache.kafka.common.requests.ApiVersionsResponse.ApiVersion in project kafka by apache.
the class NodeApiVersionsTest method testUnknownApiVersionsToString.
@Test
public void testUnknownApiVersionsToString() {
ApiVersion unknownApiVersion = new ApiVersion((short) 337, (short) 0, (short) 1);
NodeApiVersions versions = new NodeApiVersions(Collections.singleton(unknownApiVersion));
assertTrue(versions.toString().endsWith("UNKNOWN(337): 0 to 1)"));
}
use of org.apache.kafka.common.requests.ApiVersionsResponse.ApiVersion in project apache-kafka-on-k8s by banzaicloud.
the class SaslAuthenticatorTest method startServerWithoutSaslAuthenticateHeader.
private NioEchoServer startServerWithoutSaslAuthenticateHeader(final SecurityProtocol securityProtocol, String saslMechanism) throws Exception {
final ListenerName listenerName = ListenerName.forSecurityProtocol(securityProtocol);
final Map<String, ?> configs = Collections.emptyMap();
final JaasContext jaasContext = JaasContext.loadServerContext(listenerName, saslMechanism, configs);
final Map<String, JaasContext> jaasContexts = Collections.singletonMap(saslMechanism, jaasContext);
boolean isScram = ScramMechanism.isScram(saslMechanism);
if (isScram)
ScramCredentialUtils.createCache(credentialCache, Arrays.asList(saslMechanism));
SaslChannelBuilder serverChannelBuilder = new SaslChannelBuilder(Mode.SERVER, jaasContexts, securityProtocol, listenerName, false, saslMechanism, true, credentialCache, null) {
@Override
protected SaslServerAuthenticator buildServerAuthenticator(Map<String, ?> configs, String id, TransportLayer transportLayer, Map<String, Subject> subjects) throws IOException {
return new SaslServerAuthenticator(configs, id, jaasContexts, subjects, null, credentialCache, listenerName, securityProtocol, transportLayer, null) {
@Override
protected ApiVersionsResponse apiVersionsResponse() {
List<ApiVersion> apiVersions = new ArrayList<>(ApiVersionsResponse.defaultApiVersionsResponse().apiVersions());
for (Iterator<ApiVersion> it = apiVersions.iterator(); it.hasNext(); ) {
ApiVersion apiVersion = it.next();
if (apiVersion.apiKey == ApiKeys.SASL_AUTHENTICATE.id) {
it.remove();
break;
}
}
return new ApiVersionsResponse(0, Errors.NONE, apiVersions);
}
@Override
protected void enableKafkaSaslAuthenticateHeaders(boolean flag) {
// Don't enable Kafka SASL_AUTHENTICATE headers
}
};
}
};
serverChannelBuilder.configure(saslServerConfigs);
server = new NioEchoServer(listenerName, securityProtocol, new TestSecurityConfig(saslServerConfigs), "localhost", serverChannelBuilder, credentialCache);
server.start();
return server;
}
use of org.apache.kafka.common.requests.ApiVersionsResponse.ApiVersion in project apache-kafka-on-k8s by banzaicloud.
the class NodeApiVersions method toString.
/**
* Convert the object to a string.
*
* @param lineBreaks True if we should add a linebreak after each api.
*/
public String toString(boolean lineBreaks) {
// The apiVersion collection may not be in sorted order. We put it into
// a TreeMap before printing it out to ensure that we always print in
// ascending order.
TreeMap<Short, String> apiKeysText = new TreeMap<>();
for (ApiVersion supportedVersion : this.supportedVersions.values()) apiKeysText.put(supportedVersion.apiKey, apiVersionToText(supportedVersion));
for (ApiVersion apiVersion : unknownApis) apiKeysText.put(apiVersion.apiKey, apiVersionToText(apiVersion));
// which may happen when the remote is too old.
for (ApiKeys apiKey : ApiKeys.values()) {
if (!apiKeysText.containsKey(apiKey.id)) {
StringBuilder bld = new StringBuilder();
bld.append(apiKey.name).append("(").append(apiKey.id).append("): ").append("UNSUPPORTED");
apiKeysText.put(apiKey.id, bld.toString());
}
}
String separator = lineBreaks ? ",\n\t" : ", ";
StringBuilder bld = new StringBuilder();
bld.append("(");
if (lineBreaks)
bld.append("\n\t");
bld.append(Utils.join(apiKeysText.values(), separator));
if (lineBreaks)
bld.append("\n");
bld.append(")");
return bld.toString();
}
use of org.apache.kafka.common.requests.ApiVersionsResponse.ApiVersion in project apache-kafka-on-k8s by banzaicloud.
the class NodeApiVersions method apiVersionToText.
private String apiVersionToText(ApiVersion apiVersion) {
StringBuilder bld = new StringBuilder();
ApiKeys apiKey = null;
if (ApiKeys.hasId(apiVersion.apiKey)) {
apiKey = ApiKeys.forId(apiVersion.apiKey);
bld.append(apiKey.name).append("(").append(apiKey.id).append("): ");
} else {
bld.append("UNKNOWN(").append(apiVersion.apiKey).append("): ");
}
if (apiVersion.minVersion == apiVersion.maxVersion) {
bld.append(apiVersion.minVersion);
} else {
bld.append(apiVersion.minVersion).append(" to ").append(apiVersion.maxVersion);
}
if (apiKey != null) {
ApiVersion supportedVersion = supportedVersions.get(apiKey);
if (apiKey.latestVersion() < supportedVersion.minVersion) {
bld.append(" [unusable: node too new]");
} else if (supportedVersion.maxVersion < apiKey.oldestVersion()) {
bld.append(" [unusable: node too old]");
} else {
short latestUsableVersion = Utils.min(apiKey.latestVersion(), supportedVersion.maxVersion);
bld.append(" [usable: ").append(latestUsableVersion).append("]");
}
}
return bld.toString();
}
Aggregations