コード例 #1
0
  @Test
  public void testModifyPartition() throws Exception {
    int curIdx = 7;
    long curBorder = 800;

    Datasource ds = new Datasource();
    ds.addProperty(new Property("url").setValue("jdbc:mysql://localhost:3306/fxhermesshard01db"));
    ds.addProperty(new Property("user").setValue("root"));
    ds.addProperty(new Property("password").setValue(""));

    Topic t = new Topic().setName("song.test").setId(1L);
    Partition p = new Partition(0);
    MessageTableContext ctx = new MessageTableContext(t, p, 0, 30, 2, 5);
    ctx.setDatasource(ds);

    List<PartitionInfo> addlist = new ArrayList<PartitionInfo>();
    for (int i = 0; i < 5; i++) {
      PartitionInfo info = new PartitionInfo();
      info.setUpperbound(curBorder + (i + 1) * 100);
      info.setName("p" + (curIdx + i + 1));
      addlist.add(info);
    }

    m_service.addPartitions(ctx, addlist);
    m_service.dropPartitions(ctx, addlist);
  }
コード例 #2
0
  private Properties getProducerProperties(String topic) {
    Properties configs = KafkaProperties.getDefaultKafkaProducerProperties();

    try {
      Properties envProperties = m_environment.getProducerConfig(topic);
      configs.putAll(envProperties);
    } catch (IOException e) {
      m_logger.warn("read producer config failed", e);
    }

    List<Partition> partitions = m_metaService.listPartitionsByTopic(topic);
    if (partitions == null || partitions.size() < 1) {
      return configs;
    }

    String producerDatasource = partitions.get(0).getWriteDatasource();
    Storage producerStorage = m_metaService.findStorageByTopic(topic);
    if (producerStorage == null) {
      return configs;
    }

    for (Datasource datasource : producerStorage.getDatasources()) {
      if (producerDatasource.equals(datasource.getId())) {
        Map<String, Property> properties = datasource.getProperties();
        for (Map.Entry<String, Property> prop : properties.entrySet()) {
          configs.put(prop.getValue().getName(), prop.getValue().getValue());
        }
        break;
      }
    }

    return KafkaProperties.overrideByCtripDefaultProducerSetting(configs);
  }