Check for existence of provided topics in Kafka.
167202
def check_topics(client, req_topics):
    """"""
    client.update_cluster()
    logger.debug('Found topics: %r', client.topics.keys())

    for req_topic in req_topics:
        if req_topic not in client.topics.keys():
            err_topic_not_found = 'Topic not found: {}'.format(req_topic)
            logger.warning(err_topic_not_found)
            raise TopicNotFound(err_topic_not_found)

        topic = client.topics[req_topic]
        if not topic.partitions:
            err_topic_no_part = 'Topic has no partitions: {}'.format(req_topic)
            logger.warning(err_topic_no_part)
            raise TopicNoPartition(err_topic_no_part)

        logger.info('Topic is ready: %s', req_topic)
765782
def tombstone_topic(self, topic, node):
        """"""
        nsq.assert_valid_topic_name(topic)
        return self._request('POST', '/topic/tombstone',
                             fields={'topic': topic, 'node': node})
1155007
def check_issues(issues, after=None):
    """"""
    issues = closed_issues(issues, after) if after else all_issues(issues)
    issues = sorted(issues, key=ISSUES_SORT_KEY)

    have_warnings = False

    for section, issue_group in groupby(issues, key=ISSUES_BY_SECTION):
        for issue in issue_group:
            have_warnings |= check_issue(issue, after)

    return have_warnings
617337
def parse_args():
    """"""
    parser = argparse.ArgumentParser(
        description='Check kafka current status',
    )
    parser.add_argument(
        "--cluster-type",
        "-t",
        dest='cluster_type',
        required=True,
        help='Type of cluster',
        default=None,
    )
    parser.add_argument(
        "--cluster-name",
        "-c",
        dest='cluster_name',
        help='Name of the cluster',
    )
    parser.add_argument(
        '--discovery-base-path',
        dest='discovery_base_path',
        type=str,
        help='Path of the directory containing the <cluster_type>.yaml config',
    )
    parser.add_argument(
        "--broker-id",
        help='The broker id where the check is running. Set to -1 if you use automatic '
        'broker ids, and it will read the id from data-path instead. This parameter is '
        'required only in case controller-only or first-broker-only are used.',
        type=convert_to_broker_id,
    )
    parser.add_argument(
        "--data-path",
        help='Path to the Kafka data folder.',
    )
    parser.add_argument(
        '--controller-only',
        action="store_true",
        help='If this parameter is specified, it will do nothing and succeed on '
        'non-controller brokers. Default: %(default)s',
    )
    parser.add_argument(
        '--first-broker-only',
        action='store_true',
        help='If specified, the command will only perform the check if '
        'broker_id is the lowest broker id in the cluster. If it is not the lowest, '
        'it will not perform any check and succeed immediately. '
        'Default: %(default)s',
    )
    parser.add_argument(
        '-v',
        '--verbose',
        help='print verbose execution information. Default: %(default)s',
        action="store_true",
        default=False,
    )
    parser.add_argument(
        '-j',
        '--json',
        help='Print output in json format. Default: %(default)s',
        action="store_true",
        default=False,
    )

    subparsers = parser.add_subparsers()
    MinIsrCmd().add_subparser(subparsers)
    ReplicaUnavailabilityCmd().add_subparser(subparsers)
    ReplicationFactorCmd().add_subparser(subparsers)
    OfflineCmd().add_subparser(subparsers)

    return parser.parse_args()
931640
def topics(text):
    """"""
    detectors = [
        detector_50_Cent
    ]
    ts = []
    for detector in detectors:
        ts.append(detector(text))

    return [t[0] for t in ts if t[1] > 0.95]
313825
private static void validateKafkaConfig(List<ImportConfigurationType> configs) {
        if (configs.isEmpty()) {
            return;
        }
        // We associate each group id with the set of topics that belong to it
        HashMap<String, HashSet<String>> groupidToTopics = new HashMap<>();
        for (ImportConfigurationType config : configs) {
            String groupid = "";
            HashSet<String> topics = new HashSet<>();
            // Fetch topics and group id from each configuration
            for (PropertyType pt : config.getProperty()) {
                if (pt.getName().equals("topics")) {
                    topics.addAll(Arrays.asList(pt.getValue().split("\\s*,\\s*")));
                } else if (pt.getName().equals("groupid")) {
                    groupid = pt.getValue();
                }
            }
            if (groupidToTopics.containsKey(groupid)) {
                // Under this group id, we first union the set of already-stored topics with the set of newly-seen topics.
                HashSet<String> union = new HashSet<>(groupidToTopics.get(groupid));
                union.addAll(topics);
                if (union.size() == (topics.size() + groupidToTopics.get(groupid).size())) {
                    groupidToTopics.put(groupid, union);
                } else {
                    // If the size of the union doesn't equal to the sum of sizes of newly-seen topic set and
                    // already-stored topic set, those two sets must overlap with each other, which means that
                    // there must be two configurations having the same group id and overlapping sets of topics.
                    // Thus, we throw the RuntimeException.
                    throw new RuntimeException("Invalid import configuration. Two Kafka entries have the same groupid and topic.");
                }
            } else {
                groupidToTopics.put(groupid, topics);
            }
        }
    }
475664
private void _fetch(BlockingQueue<ConsumerRecord<String, byte[]>> buffer, String topic,
            long waitTime, TimeUnit waitTimeUnit) {
        KafkaConsumer<String, byte[]> consumer = _getConsumer(topic);
        synchronized (consumer) {
            _checkAndSubscribe(consumer, topic);
            Set<String> subscription = consumer.subscription();
            ConsumerRecords<String, byte[]> crList = subscription != null
                    && subscription.contains(topic) ? consumer.poll(waitTimeUnit.toMillis(waitTime))
                            : null;
            if (crList != null) {
                for (ConsumerRecord<String, byte[]> cr : crList) {
                    buffer.offer(cr);
                }
            }
        }
    }
49242
def get_msg_info(yaml_info, topics, parse_header=True):
    '''
    
    '''
    topic_info = yaml_info['topics']
    msgs = {}
    classes = {}

    for topic in topics:
        base_key = get_key_name(topic)
        msg_paths = []
        msg_types = {}
        for info in topic_info:
            if info['topic'] == topic:
                msg_class = get_message_class(info['type'])
                if msg_class is None:
                    warnings.warn(
                        'Could not find types for ' + topic + ' skpping ')
                else:
                    (msg_paths, msg_types) = get_base_fields(msg_class(), "",
                                                             parse_header)
                msgs[topic] = msg_paths
                classes[topic] = msg_types
    return (msgs, classes)
1371020
@When("^I send a message '(.+?)' to the kafka topic named '(.+?)'")
    public void sendAMessage(String message, String topic_name) throws Exception {
        commonspec.getKafkaUtils().sendMessage(message, topic_name);
    }
1313787
public List<Subscription> matches(String topic) {
        List<Token> tokens;
        try {
            tokens = splitTopic(topic);
        } catch (ParseException ex) {
            //TODO handle the parse exception
            Log.error(null, ex);
            return Collections.EMPTY_LIST;
        }

        Queue<Token> tokenQueue = new LinkedBlockingDeque<Token>(tokens);
        List<Subscription> matchingSubs = new ArrayList<Subscription>();
        subscriptions.matches(tokenQueue, matchingSubs);
        return matchingSubs;
    }
91502
def check(text):
    """"""
    err = "glaad.offensive_terms"
    msg = "Offensive term. Remove it or consider the context."

    list = [
        "fag",
        "faggot",
        "dyke",
        "sodomite",
        "homosexual agenda",
        "gay agenda",
        "transvestite",
        "homosexual lifestyle",
        "gay lifestyle"
        # homo - may create false positives without additional context
        # FIXME use topic detetor to decide whether "homo" is offensive
    ]

    return existence_check(text, list, err, msg, join=True, ignore_case=False)
523168
function list() {
  var donePromise = mediator.promise(fileSubscribers.getTopic(CONSTANTS.TOPICS.LIST, CONSTANTS.DONE_PREFIX));
  var errorPromise = mediator.promise(fileSubscribers.getTopic(CONSTANTS.TOPICS.LIST, CONSTANTS.ERROR_PREFIX));
  mediator.publish(fileSubscribers.getTopic(CONSTANTS.TOPICS.LIST));

  return getTopicPromises(donePromise, errorPromise);
}
247203
def check_predefined_conditions():
    """"""
    try:
        node_info = current_k8s_corev1_api_client.list_node()
        for node in node_info.items:
            # check based on the predefined conditions about the
            # node status: MemoryPressure, OutOfDisk, KubeletReady
            #              DiskPressure, PIDPressure,
            for condition in node.status.conditions:
                if not condition.status:
                    return False
    except ApiException as e:
        log.error('Something went wrong while getting node information.')
        log.error(e)
        return False
    return True
113097
def lookup(self, topic):
        """"""
        nsq.assert_valid_topic_name(topic)
        return self._request('GET', '/lookup', fields={'topic': topic})
1166863
public static void checkTopicName( String topicName ) throws JMSException
    {
        if (topicName == null)
            throw new FFMQException("Topic name is not set","INVALID_DESTINATION_NAME");      
        if (topicName.length() > FFMQConstants.MAX_TOPIC_NAME_SIZE)
            throw new FFMQException("Topic name '"+topicName+"' is too long ("+topicName.length()+" > "+FFMQConstants.MAX_TOPIC_NAME_SIZE+")","INVALID_DESTINATION_NAME");
        checkDestinationName(topicName);
    }
650120
def has_any? subject, &block
      found = subjects.include? subject
      yield if found && block
      found
    end
26303
def check(self, topic, value):
        
        datatype_key = topic.meta.get('datatype', 'none')
        self._datatypes[datatype_key].check(topic, value)
        validate_dt = topic.meta.get('validate', None)
        if validate_dt:
            self._datatypes[validate_dt].check(topic, value)