@Override public String apply(TopicId topicId) { return topicId.getTopic(); } };
@Override public String apply(TopicId topicId) { return topicId.getTopic(); } };
/** * Creates the URL path for making HTTP requests for the given topic. */ private String createTopicPath(TopicId topicId) { return topicId.getNamespace() + "/topics/" + topicId.getTopic(); }
private File getDataDBPath(String tableName, TopicId topicId, int generation, boolean ensureExists) throws IOException { String fileName = String.format("%s.%s.%s.%d", topicId.getNamespace(), tableName, topicId.getTopic(), generation); File file = new File(baseDir, fileName); if (ensureExists) { ensureDirExists(file); } return file; }
/** * Convert {@link TopicId} to byte array to be used a message tables row key prefix. * * @param topicId {@link TopicId} * @return byte array representation for the topic id */ public static byte[] toMetadataRowKey(TopicId topicId) { String topic = topicId.getNamespace() + ":" + topicId.getTopic() + ":"; return Bytes.toBytes(topic); }
@Nullable @Override protected String loadMessageId(DatasetContext datasetContext) { AppMetadataStore appMetadataStore = AppMetadataStore.create(cConf, datasetContext, datasetFramework); return appMetadataStore.retrieveSubscriberState(getTopicId().getTopic(), "metadata.writer"); }
@Nullable @Override protected String loadMessageId(DatasetContext datasetContext) { return getAppMetadataStore(datasetContext).retrieveSubscriberState(getTopicId().getTopic(), ""); }
@Nullable @Override protected String loadMessageId(DatasetContext datasetContext) { return getJobQueue(datasetContext).retrieveSubscriberState(getTopicId().getTopic()); }
/** * Creates a {@link MetricsContext} for {@link MessageCache} to use for the given topic. */ private MetricsContext createMetricsContext(CConfiguration cConf, TopicId topicId, MetricsCollectionService metricsCollectionService) { return metricsCollectionService.getContext(ImmutableMap.of( Constants.Metrics.Tag.COMPONENT, Constants.Service.MESSAGING_SERVICE, Constants.Metrics.Tag.INSTANCE_ID, cConf.get(Constants.MessagingSystem.CONTAINER_INSTANCE_ID, "0"), Constants.Metrics.Tag.NAMESPACE, topicId.getNamespace(), Constants.Metrics.Tag.TOPIC, topicId.getTopic() )); } }
@Override protected void storeMessageId(DatasetContext datasetContext, String messageId) { AppMetadataStore appMetadataStore = AppMetadataStore.create(cConf, datasetContext, datasetFramework); appMetadataStore.persistSubscriberState(getTopicId().getTopic(), "metadata.writer", messageId); }
@Override protected void storeMessageId(DatasetContext datasetContext, String messageId) { getAppMetadataStore(datasetContext).persistSubscriberState(getTopicId().getTopic(), "", messageId); }
@Override protected void storeMessageId(DatasetContext datasetContext, String messageId) { getJobQueue(datasetContext).persistSubscriberState(getTopicId().getTopic(), messageId); }
@Override protected void publish(TopicId topicId, Iterator<byte[]> payloads) throws IOException, TopicNotFoundException { if (NamespaceId.SYSTEM.equals(topicId.getNamespaceId())) { throw new IllegalArgumentException("Publish to '" + topicId.getNamespace() + "' namespace is not allowed"); } delegate.publish(topicId.getNamespace(), topicId.getTopic(), payloads); } }
@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); }
@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); }
@Override public void createTopic(TopicMetadata topicMetadata) throws TopicAlreadyExistsException, IOException { TopicId topicId = topicMetadata.getTopicId(); HttpRequest request = remoteClient.requestBuilder(HttpMethod.PUT, createTopicPath(topicId)) .withBody(GSON.toJson(topicMetadata.getProperties())) .build(); HttpResponse response = remoteClient.execute(request); if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) { throw new TopicAlreadyExistsException(topicId.getNamespace(), topicId.getTopic()); } handleError(response, "Failed to create topic " + topicId); }
@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); }
@Override public void createTopic(TopicMetadata topicMetadata) throws TopicAlreadyExistsException, IOException { TopicId topicId = topicMetadata.getTopicId(); HttpRequest request = remoteClient.requestBuilder(HttpMethod.PUT, createTopicPath(topicId)) .withBody(GSON.toJson(topicMetadata.getProperties())) .build(); HttpResponse response = remoteClient.execute(request); if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) { throw new TopicAlreadyExistsException(topicId.getNamespace(), topicId.getTopic()); } handleError(response, "Failed to create topic " + topicId); }
@Override public void deleteTopic(TopicId topicId) throws TopicNotFoundException, IOException { HttpRequest request = remoteClient.requestBuilder(HttpMethod.DELETE, 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); }
@Override public void deleteTopic(TopicId topicId) throws TopicNotFoundException, IOException { HttpRequest request = remoteClient.requestBuilder(HttpMethod.DELETE, 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); }