use of co.cask.cdap.api.messaging.TopicNotFoundException in project cdap by caskdata.
the class LevelDBMetadataTable method updateTopic.
@Override
public void updateTopic(TopicMetadata topicMetadata) throws TopicNotFoundException, IOException {
try {
TopicId topicId = topicMetadata.getTopicId();
byte[] key = MessagingUtils.toMetadataRowKey(topicId);
synchronized (this) {
byte[] tableValue = levelDB.get(key);
if (tableValue == null) {
throw new TopicNotFoundException(topicId.getNamespace(), topicId.getTopic());
}
Map<String, String> oldProperties = GSON.fromJson(Bytes.toString(tableValue), MAP_TYPE);
TopicMetadata oldMetadata = new TopicMetadata(topicId, oldProperties);
if (!oldMetadata.exists()) {
throw new TopicNotFoundException(topicId.getNamespace(), topicId.getTopic());
}
TreeMap<String, String> newProperties = new TreeMap<>(topicMetadata.getProperties());
newProperties.put(TopicMetadata.GENERATION_KEY, Integer.toString(oldMetadata.getGeneration()));
levelDB.put(key, Bytes.toBytes(GSON.toJson(newProperties, MAP_TYPE)), WRITE_OPTIONS);
}
} catch (DBException e) {
throw new IOException(e);
}
}
use of co.cask.cdap.api.messaging.TopicNotFoundException in project cdap by caskdata.
the class ClientMessagingService method getTopic.
@Override
public TopicMetadata getTopic(TopicId topicId) throws TopicNotFoundException, IOException {
HttpRequest request = remoteClient.requestBuilder(HttpMethod.GET, createTopicPath(topicId)).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);
Map<String, String> properties = GSON.fromJson(response.getResponseBodyAsString(), TOPIC_PROPERTY_TYPE);
return new TopicMetadata(topicId, properties);
}
use of co.cask.cdap.api.messaging.TopicNotFoundException in project cdap by caskdata.
the class ClientMessagingService method rollback.
@Override
public void rollback(TopicId topicId, RollbackDetail rollbackDetail) throws TopicNotFoundException, IOException {
ByteBuffer requestBody = (rollbackDetail instanceof ClientRollbackDetail) ? ByteBuffer.wrap(((ClientRollbackDetail) rollbackDetail).getEncoded()) : encodeRollbackDetail(rollbackDetail);
HttpRequest httpRequest = remoteClient.requestBuilder(HttpMethod.POST, createTopicPath(topicId) + "/rollback").addHeader(HttpHeaders.CONTENT_TYPE, "avro/binary").withBody(requestBody).build();
HttpResponse response = remoteClient.execute(httpRequest);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new TopicNotFoundException(topicId.getNamespace(), topicId.getTopic());
}
handleError(response, "Failed to rollback message in topic " + topicId + " with rollback detail " + rollbackDetail);
}
use of co.cask.cdap.api.messaging.TopicNotFoundException 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.api.messaging.TopicNotFoundException in project cdap by caskdata.
the class CoreMessagingService method rollback.
@Override
public void rollback(TopicId topicId, RollbackDetail rollbackDetail) throws TopicNotFoundException, IOException {
TopicMetadata metadata = getTopic(topicId);
Exception failure = null;
try (MessageTable messageTable = createMessageTable(metadata)) {
messageTable.rollback(metadata, rollbackDetail);
} catch (Exception e) {
failure = e;
}
// Throw if there is any failure in rollback.
if (failure != null) {
Throwables.propagateIfPossible(failure, TopicNotFoundException.class, IOException.class);
throw Throwables.propagate(failure);
}
}
Aggregations