forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI commands for schema registry (apache#1944)
* Add CLI commands for schema registry * Rename commandline args * Fix License Headers Issue * - all schema structures used in rest apis should have default constructors - change version to long in rest apis - fix schema cli issues * Add integration tests for Schema CLI * Exclude schema example file from license check * Exclude schema_example.conf from apache-rat:check
- Loading branch information
Showing
17 changed files
with
385 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "STRING", | ||
"schema": "", | ||
"properties": { | ||
"key1" : "value1" | ||
} | ||
} |
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
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
65 changes: 65 additions & 0 deletions
65
pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/Schemas.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,65 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.pulsar.client.admin; | ||
|
||
import org.apache.pulsar.common.schema.PostSchemaPayload; | ||
import org.apache.pulsar.common.schema.SchemaInfo; | ||
|
||
/** | ||
* Admin interface on interacting with schemas. | ||
*/ | ||
public interface Schemas { | ||
|
||
/** | ||
* Retrieve the latest schema of a topic. | ||
* | ||
* @param topic topic name, in fully qualified format | ||
* @return latest schema | ||
* @throws PulsarAdminException | ||
*/ | ||
SchemaInfo getSchemaInfo(String topic) throws PulsarAdminException; | ||
|
||
/** | ||
* Retrieve the schema of a topic at a given <tt>version</tt>. | ||
* | ||
* @param topic topic name, in fully qualified format | ||
* @param version schema version | ||
* @return the schema info at a given <tt>version</tt> | ||
* @throws PulsarAdminException | ||
*/ | ||
SchemaInfo getSchemaInfo(String topic, long version) throws PulsarAdminException; | ||
|
||
/** | ||
* Delete the schema associated with a given <tt>topic</tt>. | ||
* | ||
* @param topic topic name, in fully qualified format | ||
* @throws PulsarAdminException | ||
*/ | ||
void deleteSchema(String topic) throws PulsarAdminException; | ||
|
||
/** | ||
* Create a schema for a given <tt>topic</tt>. | ||
* | ||
* @param topic topic name, in fully qualified format | ||
* @param schemaPayload schema payload | ||
* @throws PulsarAdminException | ||
*/ | ||
void createSchema(String topic, PostSchemaPayload schemaPayload) throws PulsarAdminException; | ||
|
||
} |
102 changes: 102 additions & 0 deletions
102
pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/SchemasImpl.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,102 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.pulsar.client.admin.internal; | ||
|
||
import javax.ws.rs.client.Entity; | ||
import javax.ws.rs.client.WebTarget; | ||
import org.apache.pulsar.client.admin.PulsarAdminException; | ||
import org.apache.pulsar.client.admin.Schemas; | ||
import org.apache.pulsar.client.api.Authentication; | ||
import org.apache.pulsar.common.naming.TopicName; | ||
import org.apache.pulsar.common.policies.data.ErrorData; | ||
import org.apache.pulsar.common.schema.DeleteSchemaResponse; | ||
import org.apache.pulsar.common.schema.GetSchemaResponse; | ||
import org.apache.pulsar.common.schema.PostSchemaPayload; | ||
import org.apache.pulsar.common.schema.SchemaInfo; | ||
|
||
public class SchemasImpl extends BaseResource implements Schemas { | ||
|
||
private final WebTarget target; | ||
|
||
public SchemasImpl(WebTarget web, Authentication auth) { | ||
super(auth); | ||
this.target = web.path("/admin/v2/schemas"); | ||
} | ||
|
||
@Override | ||
public SchemaInfo getSchemaInfo(String topic) throws PulsarAdminException { | ||
try { | ||
TopicName tn = TopicName.get(topic); | ||
GetSchemaResponse response = request(schemaPath(tn)).get(GetSchemaResponse.class); | ||
SchemaInfo info = new SchemaInfo(); | ||
info.setSchema(response.getData().getBytes()); | ||
info.setType(response.getType()); | ||
info.setProperties(response.getProperties()); | ||
info.setName(tn.getLocalName()); | ||
return info; | ||
} catch (Exception e) { | ||
throw getApiException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public SchemaInfo getSchemaInfo(String topic, long version) throws PulsarAdminException { | ||
try { | ||
TopicName tn = TopicName.get(topic); | ||
GetSchemaResponse response = request(schemaPath(tn).path(Long.toString(version))).get(GetSchemaResponse.class); | ||
SchemaInfo info = new SchemaInfo(); | ||
info.setSchema(response.getData().getBytes()); | ||
info.setType(response.getType()); | ||
info.setProperties(response.getProperties()); | ||
info.setName(tn.getLocalName()); | ||
return info; | ||
} catch (Exception e) { | ||
throw getApiException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void deleteSchema(String topic) throws PulsarAdminException { | ||
try { | ||
TopicName tn = TopicName.get(topic); | ||
request(schemaPath(tn)).delete(DeleteSchemaResponse.class); | ||
} catch (Exception e) { | ||
throw getApiException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void createSchema(String topic, PostSchemaPayload payload) throws PulsarAdminException { | ||
try { | ||
TopicName tn = TopicName.get(topic); | ||
request(schemaPath(tn)) | ||
.post(Entity.json(payload), ErrorData.class); | ||
} catch (Exception e) { | ||
throw getApiException(e); | ||
} | ||
} | ||
|
||
private WebTarget schemaPath(TopicName topicName) { | ||
return target | ||
.path(topicName.getTenant()) | ||
.path(topicName.getNamespacePortion()) | ||
.path(topicName.getEncodedLocalName()) | ||
.path("schema"); | ||
} | ||
} |
Oops, something went wrong.