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(HttpRequest 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.getContent())));
responder.sendStatus(HttpResponseStatus.OK);
}
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(HttpRequest 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.getContent())));
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.proto.id.TopicId in project cdap by caskdata.
the class StoreHandler method store.
@POST
@Path("/store")
public void store(HttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception {
TopicId topicId = new NamespaceId(namespace).topic(topic);
StoreRequest storeRequest = createStoreRequest(topicId, request);
// It must be transactional with payload for store request
if (!storeRequest.isTransactional() || !storeRequest.hasNext()) {
throw new BadRequestException("Store request must be transactional with payload. Topic: " + topicId);
}
messagingService.storePayload(storeRequest);
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.proto.id.TopicId in project cdap by caskdata.
the class HBaseMetadataTable method createTopic.
@Override
public void createTopic(TopicMetadata topicMetadata) throws TopicAlreadyExistsException, IOException {
TopicId topicId = topicMetadata.getTopicId();
byte[] rowKey = MessagingUtils.toMetadataRowKey(topicId);
PutBuilder putBuilder = tableUtil.buildPut(rowKey);
Get get = tableUtil.buildGet(rowKey).addFamily(columnFamily).build();
try {
boolean completed = false;
while (!completed) {
Result result = hTable.get(get);
byte[] value = result.getValue(columnFamily, COL);
if (value == null) {
TreeMap<String, String> properties = new TreeMap<>(topicMetadata.getProperties());
properties.put(TopicMetadata.GENERATION_KEY, MessagingUtils.Constants.DEFAULT_GENERATION);
putBuilder.add(columnFamily, COL, Bytes.toBytes(GSON.toJson(properties, MAP_TYPE)));
completed = hTable.checkAndPut(rowKey, columnFamily, COL, null, putBuilder.build());
} else {
Map<String, String> properties = GSON.fromJson(Bytes.toString(value), MAP_TYPE);
TopicMetadata metadata = new TopicMetadata(topicId, properties);
if (metadata.exists()) {
throw new TopicAlreadyExistsException(topicId.getNamespace(), topicId.getTopic());
}
int newGenerationId = (metadata.getGeneration() * -1) + 1;
TreeMap<String, String> newProperties = new TreeMap<>(properties);
newProperties.put(TopicMetadata.GENERATION_KEY, Integer.toString(newGenerationId));
putBuilder.add(columnFamily, COL, Bytes.toBytes(GSON.toJson(newProperties, MAP_TYPE)));
completed = hTable.checkAndPut(rowKey, columnFamily, COL, value, putBuilder.build());
}
}
} catch (IOException e) {
throw exceptionHandler.handle(e);
}
}
use of co.cask.cdap.proto.id.TopicId in project cdap by caskdata.
the class MessagingUtilsTest method testSystemTopics.
@Test
public void testSystemTopics() {
CConfiguration cConf = CConfiguration.create();
cConf.set(Constants.MessagingSystem.SYSTEM_TOPICS, " topic-1, topic_2 ,prefix:10,invalid.name");
Set<TopicId> topics = MessagingServiceUtils.getSystemTopics(cConf, true);
Set<TopicId> expected = new LinkedHashSet<>();
expected.add(NamespaceId.SYSTEM.topic("topic-1"));
expected.add(NamespaceId.SYSTEM.topic("topic_2"));
for (int i = 0; i < 10; i++) {
expected.add(NamespaceId.SYSTEM.topic("prefix" + i));
}
Assert.assertEquals(expected, topics);
}
Aggregations