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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations