package example; import org.restlet.data.MediaType; import org.restlet.representation.EmptyRepresentation; import org.restlet.representation.Representation; import org.restlet.representation.StringRepresentation; import org.restlet.resource.ServerResource; public class UserResource extends ServerResource { @Override public Representation get() { ExampleApp app = (ExampleApp) getApplication(); if (!app.authenticate(getRequest(), getResponse())) { // Not authenticated return new EmptyRepresentation(); } // Generate list of users // ... } @Override public Representation post(Representation entity) { // Handle post // ... } }
@Override @Get public Representation get() { return new StringRepresentation("OK"); }
@Override @Put("json") public Representation put(Representation entity) { try { String jsonRequest = entity.getText(); TopicPartition topicPartitionInfo = TopicPartition.init(jsonRequest); if (_autoTopicWhitelistingManager != null) { _autoTopicWhitelistingManager.removeFromBlacklist(topicPartitionInfo.getTopic()); } if (_helixMirrorMakerManager.isTopicExisted(topicPartitionInfo.getTopic())) { _helixMirrorMakerManager.expandTopicInMirrorMaker(topicPartitionInfo); return new StringRepresentation( String.format("Successfully expand topic: %s", topicPartitionInfo)); } else { getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND); return new StringRepresentation(String.format( "Failed to expand topic, topic: %s is not existed!", topicPartitionInfo.getTopic())); } } catch (IOException e) { LOGGER.error("Got error during processing Put request", e); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation( String.format("Failed to expand topic, with exception: %s", e)); } }
public ValidationRestletResource() { getVariants().add(new Variant(MediaType.TEXT_PLAIN)); getVariants().add(new Variant(MediaType.APPLICATION_JSON)); setNegotiated(false); _validationManager = (ValidationManager) getApplication().getContext() .getAttributes().get(ValidationManager.class.toString()); if (getApplication().getContext().getAttributes() .containsKey(SourceKafkaClusterValidationManager.class.toString())) { _srcKafkaValidationManager = (SourceKafkaClusterValidationManager) getApplication().getContext() .getAttributes().get(SourceKafkaClusterValidationManager.class.toString()); } else { _srcKafkaValidationManager = null; } }
@Override public void setCharacterSet(CharacterSet characterSet) { super.setCharacterSet(characterSet); updateSize(); }
@Override public InputStream getStream() throws IOException { if (Edition.CURRENT != Edition.GWT) { final InputStream result = this.stream; setStream(null); return result; } return this.stream; }
@Override @Get public Representation get() { final String opt = (String) getRequest().getAttributes().get("opt"); if ("disable_autobalancing".equalsIgnoreCase(opt)) { _helixMirrorMakerManager.disableAutoBalancing(); LOGGER.info("Disabled autobalancing!"); return new StringRepresentation("Disabled autobalancing!\n"); } else if ("enable_autobalancing".equalsIgnoreCase(opt)) { _helixMirrorMakerManager.enableAutoBalancing(); LOGGER.info("Enabled autobalancing!"); return new StringRepresentation("Enabled autobalancing!\n"); } LOGGER.info("No valid input!"); return new StringRepresentation("No valid input!\n"); }
try { final String topicName = (String) getRequest().getAttributes().get("topicName"); String jsonRequest = entity.getText(); TopicPartition topicPartitionInfo = null; if ((jsonRequest == null || jsonRequest.isEmpty()) && topicName != null return new StringRepresentation(String.format( "Failed to add new topic: %s, it's not exsited in source kafka cluster!", topicName)); return new StringRepresentation(String.format( "Failed to add new topic: %s, it is already existed!", topicPartitionInfo.getTopic())); } else { _helixMirrorMakerManager.addTopicToMirrorMaker(topicPartitionInfo); return new StringRepresentation( String.format("Successfully add new topic: %s", topicPartitionInfo)); LOGGER.error("Got error during processing Post request", e); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation( String.format("Failed to add new topic, with exception: %s", e));
public TopicManagementRestletResource() { getVariants().add(new Variant(MediaType.TEXT_PLAIN)); getVariants().add(new Variant(MediaType.APPLICATION_JSON)); setNegotiated(false); _helixMirrorMakerManager = (HelixMirrorMakerManager) getApplication().getContext() .getAttributes().get(HelixMirrorMakerManager.class.toString()); _autoTopicWhitelistingManager = (AutoTopicWhitelistingManager) getApplication().getContext() .getAttributes().get(AutoTopicWhitelistingManager.class.toString()); if (getApplication().getContext().getAttributes() .containsKey(KafkaBrokerTopicObserver.class.toString())) { _srcKafkaBrokerTopicObserver = (KafkaBrokerTopicObserver) getApplication().getContext() .getAttributes().get(KafkaBrokerTopicObserver.class.toString()); } else { _srcKafkaBrokerTopicObserver = null; } }
@Override public void setCharacterSet(CharacterSet characterSet) { super.setCharacterSet(characterSet); updateSize(); }
@Override @Get public Representation get() { final String option = (String) getRequest().getAttributes().get("option"); if ("srcKafka".equals(option)) { if (_srcKafkaValidationManager == null) { LOGGER.warn("SourceKafkaClusterValidationManager is null!"); return new StringRepresentation("SrcKafkaValidationManager is not been initialized!"); } LOGGER.info("Trying to call validation on source kafka cluster!"); return new StringRepresentation(_srcKafkaValidationManager.validateSourceKafkaCluster()); } else { LOGGER.info("Trying to call validation on current cluster!"); return new StringRepresentation(_validationManager.validateExternalView()); } }
@Override @Delete public Representation delete() { final String topicName = (String) getRequest().getAttributes().get("topicName"); 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)); } }
List<String> topicLists = _helixMirrorMakerManager.getTopicLists(); if (topicLists == null || topicLists.isEmpty()) { return new StringRepresentation("No topic is added in MirrorMaker Controller!"); } else { return new StringRepresentation(String .format("Current serving topics: %s", Arrays.toString(topicLists.toArray()))); return new StringRepresentation(responseJson.toJSONString()); } else { getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND); return new StringRepresentation(String .format("Failed to get ExternalView for topic: %s, it is not existed!", topicName)); LOGGER.error("Got error during processing Get request", e); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation(String .format("Failed to get ExternalView for topic: %s, with exception: %s", topicName, e));
idealState.append(new StringRepresentation(resultList.toJSONString())); partitionAssignment.append(new StringRepresentation(resultList.toJSONString()));