private List<com.homeaway.streamplatform.streamregistry.model.Consumer> getAllConsumers(String streamName) { List<com.homeaway.streamplatform.streamregistry.model.Consumer> consumers = new ArrayList<>(); // pull data from state store of this instance. log.info("Pulling stream information from local instance's state-store for stream={} ; consumers=all", streamName); Optional<AvroStream> streamValue = kStreams.getAvroStreamForKey(AvroStreamKey.newBuilder().setStreamName(streamName).build()); if (streamValue.isPresent() && streamValue.get().getConsumers() != null) { streamValue.get().setOperationType(OperationType.GET); for (com.homeaway.digitalplatform.streamregistry.Consumer consumer : streamValue.get().getConsumers()) { consumers.add(AvroToJsonDTO.getJsonConsumer(consumer)); } } return consumers; }
private void deleteConsumer(String streamName, String consumerName) { Optional<AvroStream> avroStream = getAvroStreamKeyValue(streamName).getValue(); if (avroStream.isPresent()) { final List<com.homeaway.digitalplatform.streamregistry.Consumer> withConsumer = avroStream.get().getConsumers(); // Obtains consumer list size before remove consumer final int consumerInitialSize = withConsumer.size(); // Obtains filtered consumer list not containing the consumer we want to remove List<com.homeaway.digitalplatform.streamregistry.Consumer> withoutConsumer = withConsumer .stream() .filter(consumer -> !StreamRegistryUtils.hasActorNamed(consumerName, consumer::getActor)) .collect(Collectors.toList()); // Update stream's consumer list avroStream.get().setConsumers(withoutConsumer); // If filtered consumer list size is less than initial size stream will be updated if (avroStream.get().getConsumers().size() < consumerInitialSize) updateAvroStream(avroStream.get()); else throw new ConsumerNotFoundException(consumerName); } else { throw new StreamNotFoundException(streamName); } } }
private Optional<com.homeaway.streamplatform.streamregistry.model.Consumer> getConsumer(String streamName, String consumerName) { // pull data from state store of this instance. log.info("Pulling stream information from local instance's state-store for streamName={} ; consumerName={}", streamName, consumerName); Optional<AvroStream> streamValue = kStreams.getAvroStreamForKey( AvroStreamKey.newBuilder().setStreamName(streamName).build()); if (streamValue.isPresent()) { streamValue.get().setOperationType(OperationType.GET); for (com.homeaway.digitalplatform.streamregistry.Consumer consumer : streamValue.get().getConsumers()) { if (consumer.getActor().getName().equals(consumerName)) return Optional.of(AvroToJsonDTO.getJsonConsumer(consumer)); } } return Optional.empty(); }
List<Consumer> consumers = avroStream.get().getConsumers(); if (consumers != null) { for (com.homeaway.digitalplatform.streamregistry.Consumer consumer : consumers) {
private Optional<com.homeaway.streamplatform.streamregistry.model.Consumer> createConsumer(AvroStream avroStream, String consumerName, String region) { log.info("==>>> getting into creating consumer. Initial Stream: {}", avroStream.toString()); if (!regionDao.getSupportedRegions(avroStream.getTags().getHint()).contains(region)) throw new UnknownRegionException(region); List<com.homeaway.digitalplatform.streamregistry.Consumer> listConsumers = avroStream.getConsumers(); if (listConsumers == null) { listConsumers = new ArrayList<>(); } com.homeaway.digitalplatform.streamregistry.Consumer consumer = com.homeaway.digitalplatform.streamregistry.Consumer .newBuilder() .setActor(Actor.newBuilder() .setName(consumerName) .build()) .build(); String streamHint = avroStream.getTags().getHint(); String hint = (streamHint == null || streamHint.trim().matches("(?i:string)?")) ? AbstractDao.PRIMARY_HINT : streamHint.trim().toLowerCase(); Actor actor = populateActorStreamConfig(avroStream.getName(), region, consumer.getActor(), OPERATION.CREATE.name(), TOPIC_POST_FIXES, hint, ACTOR_TYPE, avroStream.getTopicConfig()); consumer = Consumer.newBuilder() .setActor(actor) .build(); listConsumers.add(consumer); avroStream.setConsumers(listConsumers); updateAvroStream(avroStream); return Optional.of(AvroToJsonDTO.getJsonConsumer(consumer)); }
avroStream.setConsumers(value.get().getConsumers()); avroStream.setRegionReplicatorList(value.get().getRegionReplicatorList()); avroStream.setS3ConnectorList(value.get().getS3ConnectorList());