public Representation delete()

in uReplicator-Controller/src/main/java/com/uber/stream/kafka/mirrormaker/controller/rest/resources/TopicManagementRestletResource.java [208:252]


  public Representation delete() {
    final String topicName = (String) getRequest().getAttributes().get("topicName");
    if (_managerControllerHelix != null) {
      // federated mode
      Form params = getRequest().getResourceRef().getQueryAsForm();
      String srcCluster = params.getFirstValue("src");
      String dstCluster = params.getFirstValue("dst");
      String routeId = params.getFirstValue("routeid");
      if (srcCluster == null || dstCluster == null || routeId == null) {
        getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
        return new StringRepresentation("Missing parameters for blacklisting topic " + topicName
            + " in federated uReplicator");
      }
      if (!_managerControllerHelix.handleTopicAssignmentEvent(topicName, srcCluster, dstCluster, routeId, "OFFLINE")) {
        getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
        String resp = String.format("Failed to blacklist topic: %s, src=%s, dst=%s, routeid=%s",
            topicName, srcCluster, dstCluster, routeId);
        LOGGER.info(resp);
        return new StringRepresentation(resp);
      }
      String resp = String.format("Successfully blacklisted topic: %s, src=%s, dst=%s, routeid=%s",
          topicName, srcCluster, dstCluster, routeId);
      LOGGER.info(resp);
      return new StringRepresentation(resp);
    }

    if (_autoTopicWhitelistingManager != null) {
      _autoTopicWhitelistingManager.addIntoBlacklist(topicName);
    }
    if (!_helixMirrorMakerManager.isTopicExisted(topicName)) {
      getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
      return new StringRepresentation(
          String.format("Failed to delete not existed topic: %s", topicName));
    }
    try {
      _helixMirrorMakerManager.deleteTopicInMirrorMaker(topicName);
      return new StringRepresentation(
          String.format("Successfully finished delete topic: %s", topicName));
    } catch (Exception e) {
      getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
      LOGGER.error("Failed to delete topic: {}, with exception: {}", topicName, e);
      return new StringRepresentation(
          String.format("Failed to delete topic: %s, with exception: %s", topicName, e));
    }
  }