|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.pulsar.broker.admin.v3; |
| 20 | + |
| 21 | +import io.swagger.annotations.Api; |
| 22 | +import io.swagger.annotations.ApiOperation; |
| 23 | +import io.swagger.annotations.ApiParam; |
| 24 | +import io.swagger.annotations.ApiResponse; |
| 25 | +import io.swagger.annotations.ApiResponses; |
| 26 | +import javax.ws.rs.DefaultValue; |
| 27 | +import javax.ws.rs.Encoded; |
| 28 | +import javax.ws.rs.PUT; |
| 29 | +import javax.ws.rs.Path; |
| 30 | +import javax.ws.rs.PathParam; |
| 31 | +import javax.ws.rs.Produces; |
| 32 | +import javax.ws.rs.QueryParam; |
| 33 | +import javax.ws.rs.container.AsyncResponse; |
| 34 | +import javax.ws.rs.container.Suspended; |
| 35 | +import javax.ws.rs.core.MediaType; |
| 36 | +import org.apache.pulsar.broker.admin.impl.PersistentTopicsBase; |
| 37 | +import org.apache.pulsar.common.partition.PartitionedTopicMetadata; |
| 38 | +import org.apache.pulsar.common.policies.data.PolicyName; |
| 39 | +import org.apache.pulsar.common.policies.data.PolicyOperation; |
| 40 | +import org.slf4j.Logger; |
| 41 | +import org.slf4j.LoggerFactory; |
| 42 | + |
| 43 | +/** |
| 44 | + */ |
| 45 | +@Path("/persistent") |
| 46 | +@Produces(MediaType.APPLICATION_JSON) |
| 47 | +@Api(value = "/persistent", description = "Persistent topic admin apis", tags = "persistent topic") |
| 48 | +public class PersistentTopics extends PersistentTopicsBase { |
| 49 | + |
| 50 | + @PUT |
| 51 | + @Path("/{tenant}/{namespace}/{topic}/partitions") |
| 52 | + @ApiOperation(value = "Create a partitioned topic.", |
| 53 | + notes = "It needs to be called before creating a producer on a partitioned topic.") |
| 54 | + @ApiResponses(value = { |
| 55 | + @ApiResponse(code = 307, message = "Current broker doesn't serve the namespace of this topic"), |
| 56 | + @ApiResponse(code = 401, message = "Don't have permission to administrate resources on this tenant"), |
| 57 | + @ApiResponse(code = 403, message = "Don't have admin permission"), |
| 58 | + @ApiResponse(code = 404, message = "Tenant does not exist"), |
| 59 | + @ApiResponse(code = 406, message = "The number of partitions should be more than 0 and" |
| 60 | + + " less than or equal to maxNumPartitionsPerPartitionedTopic"), |
| 61 | + @ApiResponse(code = 409, message = "Partitioned topic already exist"), |
| 62 | + @ApiResponse(code = 412, |
| 63 | + message = "Failed Reason : Name is invalid or Namespace does not have any clusters configured"), |
| 64 | + @ApiResponse(code = 500, message = "Internal server error"), |
| 65 | + @ApiResponse(code = 503, message = "Failed to validate global cluster configuration") |
| 66 | + }) |
| 67 | + public void createPartitionedTopic( |
| 68 | + @Suspended final AsyncResponse asyncResponse, |
| 69 | + @ApiParam(value = "Specify the tenant", required = true) |
| 70 | + @PathParam("tenant") String tenant, |
| 71 | + @ApiParam(value = "Specify the namespace", required = true) |
| 72 | + @PathParam("namespace") String namespace, |
| 73 | + @ApiParam(value = "Specify topic name", required = true) |
| 74 | + @PathParam("topic") @Encoded String encodedTopic, |
| 75 | + @ApiParam(value = "The metadata for the topic", |
| 76 | + required = true, type = "PartitionedTopicMetadata") PartitionedTopicMetadata metadata, |
| 77 | + @QueryParam("createLocalTopicOnly") @DefaultValue("false") boolean createLocalTopicOnly) { |
| 78 | + try { |
| 79 | + validateNamespaceName(tenant, namespace); |
| 80 | + validateGlobalNamespaceOwnership(); |
| 81 | + validatePartitionedTopicName(tenant, namespace, encodedTopic); |
| 82 | + validateTopicPolicyOperation(topicName, PolicyName.PARTITION, PolicyOperation.WRITE); |
| 83 | + validateCreateTopic(topicName); |
| 84 | + internalCreatePartitionedTopic(asyncResponse, metadata.partitions, createLocalTopicOnly, |
| 85 | + metadata.properties); |
| 86 | + } catch (Exception e) { |
| 87 | + log.error("[{}] Failed to create partitioned topic {}", clientAppId(), topicName, e); |
| 88 | + resumeAsyncResponseExceptionally(asyncResponse, e); |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + private static final Logger log = LoggerFactory.getLogger(PersistentTopics.class); |
| 93 | +} |
0 commit comments