public Representation post()

in uReplicator-Controller/src/main/java/com/uber/stream/kafka/mirrormaker/controller/rest/resources/TopicPartitionBlacklistRestletResource.java [61:93]


  public Representation post() {
    Form params = getRequest().getResourceRef().getQueryAsForm();
    String topicName = params.getFirstValue("topic");
    String partitionName = params.getFirstValue("partition");
    String opt = params.getFirstValue("opt");
    if (StringUtils.isEmpty(topicName) || StringUtils.isEmpty(partitionName) || StringUtils.isEmpty(opt)) {
      getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
      return new StringRepresentation("Parameter topic, partition and opt are required.");
    }

    try {
      int partition = Integer.parseInt(partitionName);

      if ("blacklist".equalsIgnoreCase(opt)) {
        _helixMirrorMakerManager.updateTopicPartitionStateInMirrorMaker(topicName, partition, Constants.HELIX_OFFLINE_STATE);
      } else if ("whitelist".equalsIgnoreCase(opt)) {
        _helixMirrorMakerManager.updateTopicPartitionStateInMirrorMaker(topicName, partition, Constants.HELIX_ONLINE_STATE);
      } else {
        getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
        return new StringRepresentation("Invalid parameter opt");
      }
    } catch (NumberFormatException e) {
      getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
      return new StringRepresentation("Parameter partition should be Integer");
    } catch (IllegalArgumentException e) {
      getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
      return new StringRepresentation(e.getMessage());
    } catch (Exception e) {
      getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
      return new StringRepresentation(e.getMessage());
    }
    return new StringRepresentation("OK");
  }