Source:
<code>public boolean createStream(StreamSpec streamSpec) { LOG.info("Creating Kafka topic: on system: {}", streamSpec.getPhysicalName(), streamSpec.getSystemName()); <START> final String REPL_FACTOR = "replication.factor"; <END> KafkaStreamSpec kSpec = toKafkaSpec(streamSpec); String topicName = kSpec.getPhysicalName(); NewTopic newTopic = new NewTopic(topicName, kSpec.getPartitionCount(), (short) kSpec.getReplicationFactor()); Map<String, String> streamConfig = new HashMap(streamSpec.getConfig()); if (streamConfig.containsKey(REPL_FACTOR)) { String repl = streamConfig.get(REPL_FACTOR); LOG.warn("replication.factor (topic={}, repl={}) is invalid config for AdminClient.createTopics. Removing it. Using kSpec repl factor {}", kSpec.getPhysicalName(), repl, kSpec.getReplicationFactor()); streamConfig.remove(REPL_FACTOR); } newTopic.configs(new MapConfig(streamConfig)); CreateTopicsResult result = adminClient.createTopics(ImmutableSet.of(newTopic)); try { result.all().get(KAFKA_ADMIN_OPS_TIMEOUT_MS, TimeUnit.MILLISECONDS); } catch (Exception e) { if (e instanceof TopicExistsException || e.getCause() instanceof TopicExistsException) { LOG.info("Topic already exists.", topicName); return false; } throw new SamzaException("Create topic failed", e); } LOG.info("Successfully created topic {}", topicName); DescribeTopicsResult desc = adminClient.describeTopics(ImmutableSet.of(topicName)); try { TopicDescription td = desc.all().get(KAFKA_ADMIN_OPS_TIMEOUT_MS, TimeUnit.MILLISECONDS).get(topicName); LOG.info("Topic created with {}", topicName, td); return true; } catch (Exception e) { LOG.error("'Describe after create' failed for topic " + topicName, e); return false; } }</code><technical_language>nit: move static final constants beginning of class</technical_language>

Target:
public boolean createStream(StreamSpec streamSpec) { LOG.info("Creating Kafka topic: on system: {}", streamSpec.getPhysicalName(), streamSpec.getSystemName()); final String REPL_FACTOR = "replication.factor"; KafkaStreamSpec kSpec = toKafkaSpec(streamSpec); String topicName = kSpec.getPhysicalName(); NewTopic newTopic = new NewTopic(topicName, kSpec.getPartitionCount(), (short) kSpec.getReplicationFactor()); Map<String, String> streamConfig = new HashMap(streamSpec.getConfig()); if (streamConfig.containsKey(REPL_FACTOR)) { String repl = streamConfig.get(REPL_FACTOR); LOG.warn("Configuration {}={} for topic={} is invalid. Using kSpec repl factor {}", REPL_FACTOR, repl, kSpec.getPhysicalName(), kSpec.getReplicationFactor()); streamConfig.remove(REPL_FACTOR); } newTopic.configs(new MapConfig(streamConfig)); CreateTopicsResult result = adminClient.createTopics(ImmutableSet.of(newTopic)); try { result.all().get(KAFKA_ADMIN_OPS_TIMEOUT_MS, TimeUnit.MILLISECONDS); } catch (Exception e) { if (e instanceof TopicExistsException || e.getCause() instanceof TopicExistsException) { LOG.info("Topic already exists.", topicName); return false; } throw new SamzaException(String.format("Creation of topic %s failed.", topicName), e); } LOG.info("Successfully created topic {}", topicName); DescribeTopicsResult desc = adminClient.describeTopics(ImmutableSet.of(topicName)); try { TopicDescription td = desc.all().get(KAFKA_ADMIN_OPS_TIMEOUT_MS, TimeUnit.MILLISECONDS).get(topicName); LOG.info("Topic created with {}", topicName, td); return true; } catch (Exception e) { LOG.error("'Describe after create' failed for topic " + topicName, e); return false; } }