public AdminRestletResource() { _helixMirrorMakerManager = (HelixMirrorMakerManager) getApplication().getContext() .getAttributes().get(HelixMirrorMakerManager.class.toString()); }
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; } }
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 @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)); } }
@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"); }
@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 @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)); } }
@Override @Delete public Representation delete() { final String instanceName = (String) getRequest().getAttributes().get("instanceName"); if (instanceName == null) { return new StringRepresentation("Instance name is required to blacklist"); } // blacklist a worker try { _helixMirrorMakerManager.blacklistInstance(instanceName); return new StringRepresentation(String.format("Instance %s is blacklisted", instanceName)); } catch (Exception e) { LOGGER.error("Got error during processing Delete request", e); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation(String .format("Failed to blacklist instance %s, with exception: %s", instanceName, e)); } }
@Override @Get public Representation get() { OffsetMonitor offsetMonitor = _helixMirrorMakerManager.getOffsetMonitor(); final String topicName = (String) getRequest().getAttributes().get("topic"); if (topicName == null) { try { return new StringRepresentation(offsetMonitor.getTopicToOffsetMap().toString()); } catch (Exception e) { LOGGER.error("Got error during processing Get request", e); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation(String .format("Failed to get lag for offset map for all partitions with exception: %s", e)); } } final int partition = Integer.parseInt((String) getRequest().getAttributes().get("partition")); try { return new StringRepresentation(offsetMonitor.getTopicPartitionOffset(new TopicPartition(topicName, partition)).toString()); } catch (Exception e) { LOGGER.error("Got error during processing Get request", e); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation(String .format("Failed to get offset for topic partition: %s:%d, with exception: %s", topicName, partition, e)); } }
public TopicParitionOffsetRestletResource() { _helixMirrorMakerManager = (HelixMirrorMakerManager) getApplication().getContext() .getAttributes().get(HelixMirrorMakerManager.class.toString()); }
public MirrorMakerManagerRestletResource() { _helixMirrorMakerManager = (HelixMirrorMakerManager) getApplication().getContext() .getAttributes().get(HelixMirrorMakerManager.class.toString()); }
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; } }
public TopicManagementRestletResource() { getVariants().add(new Variant(MediaType.TEXT_PLAIN)); getVariants().add(new Variant(MediaType.APPLICATION_JSON)); setNegotiated(false); _managerControllerHelix = (ManagerControllerHelix) getApplication().getContext() .getAttributes().get(ManagerControllerHelix.class.toString()); _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; } }
public Representation post(Representation entity) { try { final String topicName = (String) getRequest().getAttributes().get("topicName"); String jsonRequest = entity.getText(); TopicPartition topicPartitionInfo = null; getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND); return new StringRepresentation(String.format( "Failed to add new topic: %s, it is already existed!", topicPartitionInfo.getTopic())); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation( String.format("Failed to add new topic, with exception: %s", e));
public AdminRestletResource() { _helixMirrorMakerManager = (HelixMirrorMakerManager) getApplication().getContext() .getAttributes().get(HelixMirrorMakerManager.class.toString()); }
@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"); } else if ("autobalancing_status".equalsIgnoreCase(opt)) { if (_helixMirrorMakerManager.isAutoBalancingEnabled()) { return new StringRepresentation("enabled"); } else { return new StringRepresentation("disabled"); } } LOGGER.info("No valid input!"); return new StringRepresentation("No valid input!\n"); }
@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 @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 (Exception 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)); } }
@Override @Post public Representation post(Representation entity) { final String instanceName = (String) getRequest().getAttributes().get("instanceName"); if (instanceName != null) { // whitelist a worker try { _helixMirrorMakerManager.whitelistInstance(instanceName); return new StringRepresentation(String.format("Instance %s is whitelisted", instanceName)); } catch (Exception e) { LOGGER.error("Got error during processing Post request", e); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation(String .format("Failed to whitelist instance %s, with exception: %s", instanceName, e)); } } else { // rebalance the whole cluster try { AutoRebalanceLiveInstanceChangeListener rebalancer = _helixMirrorMakerManager.getRebalancer(); if (rebalancer.triggerRebalanceCluster()) { return new StringRepresentation("Cluster is rebalanced\n"); } return new StringRepresentation("Skipped rebalancing cluster\n"); } catch (Exception e) { LOGGER.error("Got error during processing POST request", e); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation(String.format("Failed to rebalance cluster with exception: %s", e)); } } }
@Override @Get public Representation get() { final String topicName = (String) getRequest().getAttributes().get("topicName"); if (topicName == null) { List<String> topicLists = _helixMirrorMakerManager.getTopicLists(); 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)); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation(String .format("Failed to get ExternalView for topic: %s, with exception: %s", topicName, e));