-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
2,030 additions
and
607 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2014 Confluent Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
kafkastore.connection.url=localhost:2181 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/io/confluent/kafka/schemaregistry/rest/RegisterSchemaForwardingAgent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Copyright 2014 Confluent Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.confluent.kafka.schemaregistry.rest; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import io.confluent.kafka.schemaregistry.rest.entities.requests.RegisterSchemaRequest; | ||
import io.confluent.kafka.schemaregistry.storage.exceptions.SchemaRegistryException; | ||
import io.confluent.kafka.schemaregistry.utils.RestUtils; | ||
|
||
/** | ||
* An agent responsible for forwarding an incoming registering schema request to another HTTP server | ||
*/ | ||
public class RegisterSchemaForwardingAgent { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(RegisterSchemaForwardingAgent.class); | ||
private final Map<String, String> requestProperties; | ||
private final String topic; | ||
private final boolean isKey; | ||
private final RegisterSchemaRequest registerSchemaRequest; | ||
|
||
public RegisterSchemaForwardingAgent(Map<String, String> requestProperties, String topic, | ||
boolean isKey, RegisterSchemaRequest registerSchemaRequest) { | ||
this.requestProperties = requestProperties; | ||
this.topic = topic; | ||
this.isKey = isKey; | ||
this.registerSchemaRequest = registerSchemaRequest; | ||
} | ||
|
||
/** | ||
* Forward the request | ||
* | ||
* @param host host to forward the request to | ||
* @param port port to forward the request to | ||
* @return The version id of the schema if registration is successful. Otherwise, throw a | ||
* WebApplicationException. | ||
*/ | ||
public int forward(String host, int port) throws SchemaRegistryException { | ||
String baseUrl = String.format("http://%s:%d", host, port); | ||
log.debug(String.format("Forwarding registering schema request %s to %s", | ||
registerSchemaRequest, baseUrl)); | ||
try { | ||
int version = RestUtils.registerSchema(baseUrl, requestProperties, registerSchemaRequest, | ||
topic, isKey); | ||
return version; | ||
} catch (IOException e) { | ||
throw new SchemaRegistryException( | ||
String.format("Unexpected error while forwarding the registering schema request %s to %s", | ||
registerSchemaRequest, baseUrl), | ||
e); | ||
} | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
src/main/java/io/confluent/kafka/schemaregistry/rest/SchemaRegistryConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/** | ||
* Copyright 2014 Confluent Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.confluent.kafka.schemaregistry.rest; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.Map; | ||
|
||
import io.confluent.common.config.ConfigDef; | ||
import io.confluent.common.config.ConfigException; | ||
import io.confluent.rest.RestConfig; | ||
import io.confluent.rest.RestConfigException; | ||
|
||
import static io.confluent.common.config.ConfigDef.Range.atLeast; | ||
|
||
public class SchemaRegistryConfig extends RestConfig { | ||
|
||
public static final String KAFKASTORE_CONNECTION_URL_CONFIG = "kafkastore.connection.url"; | ||
protected static final String KAFKASTORE_CONNECTION_URL_DOC = | ||
"Zookeeper url for the Kafka cluster"; | ||
|
||
/** | ||
* <code>kafkastore.zk.session.timeout.ms</code> | ||
*/ | ||
public static final String KAFKASTORE_ZK_SESSION_TIMEOUT_MS_CONFIG | ||
= "kafkastore.zk.session.timeout.ms"; | ||
protected static final String KAFKASTORE_ZK_SESSION_TIMEOUT_MS_DOC = | ||
"Zookeeper session timeout"; | ||
|
||
/** | ||
* <code>kafkastore.topic</code> | ||
*/ | ||
public static final String KAFKASTORE_TOPIC_CONFIG = "kafkastore.topic"; | ||
public static final String DEFAULT_KAFKASTORE_TOPIC = "_schemas"; | ||
protected static final String KAFKASTORE_TOPIC_DOC = | ||
"The durable single partition topic that acts" + | ||
"as the durable log for the data"; | ||
|
||
/** | ||
* <code>kafkastore.timeout.ms</code> | ||
*/ | ||
public static final String KAFKASTORE_TIMEOUT_CONFIG = "kafkastore.timeout.ms"; | ||
protected static final String KAFKASTORE_TIMEOUT_DOC = | ||
"The timeout for an operation on the Kafka store"; | ||
|
||
/** | ||
* <code>kafkastore.commit.interval.ms</code> | ||
*/ | ||
public static final String KAFKASTORE_COMMIT_INTERVAL_MS_CONFIG = "kafkastore.commit.interval.ms"; | ||
protected static final String KAFKASTORE_COMMIT_INTERVAL_MS_DOC = | ||
"The interval to commit offsets while consuming the Kafka topic"; | ||
public static final int OFFSET_COMMIT_OFF = -1; | ||
// TODO: turn off offset commit by default for now since we only have an in-memory store | ||
private static final int KAFKASTORE_COMMIT_INTERVAL_MS_DEFAULT = OFFSET_COMMIT_OFF; | ||
|
||
/** | ||
* <code>advertised.host</code> | ||
*/ | ||
public static final String ADVERTISED_HOST_CONFIG = "advertised.host"; | ||
protected static final String ADVERTISED_HOST_DOC = "The host name advertised in Zookeeper"; | ||
|
||
static { | ||
config | ||
.defineOverride(RESPONSE_MEDIATYPE_PREFERRED_CONFIG, ConfigDef.Type.LIST, | ||
Versions.PREFERRED_RESPONSE_TYPES, ConfigDef.Importance.HIGH, | ||
RESPONSE_MEDIATYPE_PREFERRED_CONFIG_DOC) | ||
.defineOverride(RESPONSE_MEDIATYPE_DEFAULT_CONFIG, ConfigDef.Type.STRING, | ||
Versions.SCHEMA_REGISTRY_MOST_SPECIFIC_DEFAULT, ConfigDef.Importance.HIGH, | ||
RESPONSE_MEDIATYPE_DEFAULT_CONFIG_DOC) | ||
.define(KAFKASTORE_CONNECTION_URL_CONFIG, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, | ||
KAFKASTORE_CONNECTION_URL_DOC) | ||
.define(KAFKASTORE_ZK_SESSION_TIMEOUT_MS_CONFIG, ConfigDef.Type.INT, 10000, atLeast(0), | ||
ConfigDef.Importance.LOW, KAFKASTORE_ZK_SESSION_TIMEOUT_MS_DOC) | ||
.define(KAFKASTORE_TOPIC_CONFIG, ConfigDef.Type.STRING, DEFAULT_KAFKASTORE_TOPIC, | ||
ConfigDef.Importance.HIGH, KAFKASTORE_TOPIC_DOC) | ||
.define(KAFKASTORE_TIMEOUT_CONFIG, ConfigDef.Type.INT, 500, atLeast(0), | ||
ConfigDef.Importance.MEDIUM, KAFKASTORE_TIMEOUT_DOC) | ||
.define(KAFKASTORE_COMMIT_INTERVAL_MS_CONFIG, ConfigDef.Type.INT, | ||
KAFKASTORE_COMMIT_INTERVAL_MS_DEFAULT, ConfigDef.Importance.MEDIUM, | ||
KAFKASTORE_COMMIT_INTERVAL_MS_DOC) | ||
.define(ADVERTISED_HOST_CONFIG, ConfigDef.Type.STRING, getDefaultHost(), | ||
ConfigDef.Importance.LOW, ADVERTISED_HOST_DOC); | ||
} | ||
|
||
private static String getDefaultHost() { | ||
try { | ||
return InetAddress.getLocalHost().getCanonicalHostName(); | ||
} catch (UnknownHostException e) { | ||
throw new ConfigException("Unknown local hostname", e); | ||
} | ||
} | ||
|
||
public SchemaRegistryConfig(Map<? extends Object, ? extends Object> props) { | ||
super(props); | ||
} | ||
|
||
public SchemaRegistryConfig(String propsFile) throws RestConfigException { | ||
this(getPropsFromFile(propsFile)); | ||
} | ||
|
||
public static void main(String[] args) { | ||
System.out.println(config.toHtmlTable()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.