Search in sources :

Example 21 with TopicId

use of co.cask.cdap.proto.id.TopicId in project cdap by caskdata.

the class ClientMessagingService method updateTopic.

@Override
public void updateTopic(TopicMetadata topicMetadata) throws TopicNotFoundException, IOException {
    TopicId topicId = topicMetadata.getTopicId();
    HttpRequest request = remoteClient.requestBuilder(HttpMethod.PUT, createTopicPath(topicId) + "/properties").withBody(GSON.toJson(topicMetadata.getProperties())).build();
    HttpResponse response = remoteClient.execute(request);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new TopicNotFoundException(topicId.getNamespace(), topicId.getTopic());
    }
    handleError(response, "Failed to update topic " + topicId);
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) TopicNotFoundException(co.cask.cdap.api.messaging.TopicNotFoundException) HttpResponse(co.cask.common.http.HttpResponse) TopicId(co.cask.cdap.proto.id.TopicId)

Example 22 with TopicId

use of co.cask.cdap.proto.id.TopicId in project cdap by caskdata.

the class MetadataHandler method createTopic.

@PUT
@Path("/topics/{topic}")
public void createTopic(FullHttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception {
    TopicId topicId = new NamespaceId(namespace).topic(topic);
    messagingService.createTopic(new TopicMetadata(topicId, decodeTopicProperties(request.content())));
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : TopicId(co.cask.cdap.proto.id.TopicId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) TopicMetadata(co.cask.cdap.messaging.TopicMetadata) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 23 with TopicId

use of co.cask.cdap.proto.id.TopicId in project cdap by caskdata.

the class MetadataHandler method deleteTopic.

@DELETE
@Path("/topics/{topic}")
public void deleteTopic(HttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception {
    TopicId topicId = new NamespaceId(namespace).topic(topic);
    messagingService.deleteTopic(topicId);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : TopicId(co.cask.cdap.proto.id.TopicId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 24 with TopicId

use of co.cask.cdap.proto.id.TopicId in project cdap by caskdata.

the class MetadataHandler method updateTopic.

@PUT
@Path("/topics/{topic}/properties")
public void updateTopic(FullHttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception {
    TopicId topicId = new NamespaceId(namespace).topic(topic);
    messagingService.updateTopic(new TopicMetadata(topicId, decodeTopicProperties(request.content())));
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : TopicId(co.cask.cdap.proto.id.TopicId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) TopicMetadata(co.cask.cdap.messaging.TopicMetadata) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 25 with TopicId

use of co.cask.cdap.proto.id.TopicId in project cdap by caskdata.

the class CoreMessagingService method startAsyncTopicCreation.

/**
 * Starts a thread to create the give list of topics. The thread will keep trying the creation until
 * all of the given topics are created.
 */
private void startAsyncTopicCreation(final Queue<TopicId> topics, final long delay, final TimeUnit unit) {
    final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(Threads.createDaemonThreadFactory("async-topic-creation"));
    executor.schedule(new Runnable() {

        @Override
        public void run() {
            Iterator<TopicId> iterator = topics.iterator();
            while (iterator.hasNext()) {
                TopicId topicId = iterator.next();
                try {
                    createTopicIfNotExists(topicId);
                    // Successfully created, remove it from the async list
                    iterator.remove();
                } catch (Exception e) {
                    LOG.warn("Topic {} creation failed with exception {}. Will retry.", topicId, e.getMessage());
                    LOG.debug("Topic {} creation failure stacktrace", topicId, e);
                }
            }
            if (!topics.isEmpty()) {
                executor.schedule(this, delay, unit);
            }
        }
    }, delay, unit);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Iterator(java.util.Iterator) TopicId(co.cask.cdap.proto.id.TopicId) TopicAlreadyExistsException(co.cask.cdap.api.messaging.TopicAlreadyExistsException) TopicNotFoundException(co.cask.cdap.api.messaging.TopicNotFoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

TopicId (co.cask.cdap.proto.id.TopicId)60 TopicMetadata (co.cask.cdap.messaging.TopicMetadata)33 Test (org.junit.Test)28 NamespaceId (co.cask.cdap.proto.id.NamespaceId)25 ArrayList (java.util.ArrayList)20 Path (javax.ws.rs.Path)14 RawMessage (co.cask.cdap.messaging.data.RawMessage)13 IOException (java.io.IOException)12 MessageId (co.cask.cdap.messaging.data.MessageId)10 TopicNotFoundException (co.cask.cdap.api.messaging.TopicNotFoundException)9 POST (javax.ws.rs.POST)7 TopicAlreadyExistsException (co.cask.cdap.api.messaging.TopicAlreadyExistsException)6 BadRequestException (co.cask.cdap.common.BadRequestException)6 RollbackDetail (co.cask.cdap.messaging.RollbackDetail)5 StoreRequest (co.cask.cdap.messaging.StoreRequest)5 GenericRecord (org.apache.avro.generic.GenericRecord)5 TimeProvider (co.cask.cdap.common.utils.TimeProvider)4 PUT (javax.ws.rs.PUT)4 GenericDatumReader (org.apache.avro.generic.GenericDatumReader)4 Decoder (org.apache.avro.io.Decoder)4