@Override public void removeOutputFromAllStreams(Output output) { ObjectId outputId = new ObjectId(output.getId()); DBObject match = new BasicDBObject(StreamImpl.FIELD_OUTPUTS, outputId); DBObject modify = new BasicDBObject("$pull", new BasicDBObject(StreamImpl.FIELD_OUTPUTS, outputId)); // Collect streams that will change before updating them because we don't get the list of changed streams // from the upsert call. final ImmutableSet<String> updatedStreams; try (final DBCursor cursor = collection(StreamImpl.class).find(match)) { updatedStreams = StreamSupport.stream(cursor.spliterator(), false) .map(stream -> stream.get("_id")) .filter(Objects::nonNull) .map(id -> ((ObjectId) id).toHexString()) .collect(ImmutableSet.toImmutableSet()); } collection(StreamImpl.class).update( match, modify, false, true ); clusterEventBus.post(StreamsChangedEvent.create(updatedStreams)); }
@Override public List<MessageTrace> getMessageStatus(String qualifiedTopicName, String subscriptionName, String messageId) { DBCursor publishedCursor = database.getCollection(COLLECTION_PUBLISHED_NAME) .find(new BasicDBObject(LogSchemaAware.MESSAGE_ID, messageId)) .sort(new BasicDBObject(TIMESTAMP, 1)); DBCursor sentCursor = database.getCollection(COLLECTION_SENT_NAME) .find(new BasicDBObject(LogSchemaAware.MESSAGE_ID, messageId).append(SUBSCRIPTION, subscriptionName)) .sort(new BasicDBObject(TIMESTAMP, 1)); return Stream.concat( StreamSupport.stream(publishedCursor.spliterator(), false).map(this::convertToPublishedMessage), StreamSupport.stream(sentCursor.spliterator(), false).map(this::convertToSentMessage)) .collect(Collectors.toList()); }
@Override public void onBeforeDelete(BeforeDeleteEvent<Launch> event) { DBObject dboq = queryMapper.getMappedObject(event.getDBObject(), mappingContext.getPersistentEntity(Launch.class)); List<String> ids = stream(mongoTemplate.getCollection(event.getCollectionName()).find(dboq).spliterator(), false) .map(dbObject -> dbObject.get("_id").toString()).distinct().collect(toList()); final BasicDBObject itemsQuery = new BasicDBObject("parent", new BasicDBObject("$exists", false)); itemsQuery.put("launchRef", new BasicDBObject("$in", ids)); final List<String> itemIds = stream(mongoTemplate.getCollection("testItem").find(itemsQuery).spliterator(), false) .map(dbObject -> dbObject.get("_id").toString()).collect(toList()); testItemRepository.delete(itemIds); } }
@ChangeSet(order = "001", id = "001", author = "bhliva") public void migrateSchedulerFields(DB db) { log.info("Replacing field days_repeat with start_days_repeat and stop_days_repeat"); final DBCollection userInstances = db.getCollection("userInstances"); StreamSupport.stream(userInstances.find().spliterator(), false) .forEach(dbObject -> updateSchedulerFieldsForExploratory(userInstances, dbObject)); log.info("Replacing scheduler field days_repeat finished successfully"); }
@Override public List<SentMessageTrace> getLastUndeliveredMessages(String topicName, String subscriptionName, int limit) { try ( DBCursor cursor = database.getCollection(COLLECTION_SENT_NAME).find( new BasicDBObject(TOPIC_NAME, topicName) .append(SUBSCRIPTION, subscriptionName) .append(STATUS, SentMessageTraceStatus.DISCARDED.toString()) ).sort(new BasicDBObject(TIMESTAMP, -1)) .limit(limit) ) { return StreamSupport.stream(cursor.spliterator(), false) .map(this::convertToSentMessage) .collect(Collectors.toList()); } }
@Override public void removeOutputFromAllStreams(Output output) { ObjectId outputId = new ObjectId(output.getId()); DBObject match = new BasicDBObject(StreamImpl.FIELD_OUTPUTS, outputId); DBObject modify = new BasicDBObject("$pull", new BasicDBObject(StreamImpl.FIELD_OUTPUTS, outputId)); // Collect streams that will change before updating them because we don't get the list of changed streams // from the upsert call. final ImmutableSet<String> updatedStreams; try (final DBCursor cursor = collection(StreamImpl.class).find(match)) { updatedStreams = StreamSupport.stream(cursor.spliterator(), false) .map(stream -> stream.get("_id")) .filter(Objects::nonNull) .map(id -> ((ObjectId) id).toHexString()) .collect(ImmutableSet.toImmutableSet()); } collection(StreamImpl.class).update( match, modify, false, true ); clusterEventBus.post(StreamsChangedEvent.create(updatedStreams)); }
private List<SentMessageTrace> getLastUndeliveredMessages(String topicName, String subscriptionName, SentMessageTraceStatus status) { try ( DBCursor cursor = database.getCollection(COLLECTION_SENT_NAME) .find(new BasicDBObject(TOPIC_NAME, topicName) .append(LogSchemaAware.SUBSCRIPTION, subscriptionName).append(STATUS, status.toString())) .sort(new BasicDBObject(TIMESTAMP, -1)).limit(1) ) { return StreamSupport.stream(cursor.spliterator(), false) .map(this::convert) .collect(Collectors.toList()); } }