Java Code Examples for com.mongodb.MongoException#getMessage()

The following examples show how to use com.mongodb.MongoException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoCommander.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("boxing")
public static String ensureIndexes(MongoIndex index, DB dbConn, int indexOrder) {
    DBObject options = new BasicDBObject();
    options.put("name", "idx_" + indexOrder);
    options.put("unique", index.isUnique());
    options.put("sparse", index.isSparse());
    options.put("ns", dbConn.getCollection(index.getCollection()).getFullName());

    try {
        dbConn.getCollection(index.getCollection()).createIndex(new BasicDBObject(index.getKeys()), options);
        return null;
    } catch (MongoException e) {
        LOG.error("Failed to ensure index:{}", e.getMessage());
        return "Failed to ensure index:" + e.getMessage();
    }
}
 
Example 2
Source File: MongoSinkTask.java    From mongo-kafka with Apache License 2.0 5 votes vote down vote up
private void checkRetriableException(final MongoSinkTopicConfig config, final MongoException e) {
  if (getRemainingRetriesForTopic(config.getTopic()).decrementAndGet() <= 0) {
    throw new DataException("Failed to write mongodb documents despite retrying", e);
  }
  Integer deferRetryMs = config.getInt(RETRIES_DEFER_TIMEOUT_CONFIG);
  LOGGER.debug("Deferring retry operation for {}ms", deferRetryMs);
  context.timeout(deferRetryMs);
  throw new RetriableException(e.getMessage(), e);
}
 
Example 3
Source File: MongoDbSinkTask.java    From kafka-connect-mongodb with Apache License 2.0 5 votes vote down vote up
private void processSinkRecords(MongoCollection<BsonDocument> collection, List<SinkRecord> batch) {
    String collectionName = collection.getNamespace().getCollectionName();
    List<? extends WriteModel<BsonDocument>> docsToWrite =
            sinkConfig.isUsingCdcHandler(collectionName)
                    ? buildWriteModelCDC(batch,collectionName)
                    : buildWriteModel(batch,collectionName);
    try {
        if (!docsToWrite.isEmpty()) {
            LOGGER.debug("bulk writing {} document(s) into collection [{}]",
                    docsToWrite.size(), collection.getNamespace().getFullName());
            BulkWriteResult result = collection.bulkWrite(
                    docsToWrite, BULK_WRITE_OPTIONS);
            LOGGER.debug("mongodb bulk write result: " + result.toString());
        }
    } catch (MongoException mexc) {
        if (mexc instanceof BulkWriteException) {
            BulkWriteException bwe = (BulkWriteException) mexc;
            LOGGER.error("mongodb bulk write (partially) failed", bwe);
            LOGGER.error(bwe.getWriteResult().toString());
            LOGGER.error(bwe.getWriteErrors().toString());
            LOGGER.error(bwe.getWriteConcernError().toString());
        } else {
            LOGGER.error("error on mongodb operation", mexc);
            LOGGER.error("writing {} document(s) into collection [{}] failed -> remaining retries ({})",
                    docsToWrite.size(), collection.getNamespace().getFullName() ,remainingRetries);
        }
        if (remainingRetries-- <= 0) {
            throw new ConnectException("failed to write mongodb documents"
                    + " despite retrying -> GIVING UP! :( :( :(", mexc);
        }
        LOGGER.debug("deferring retry operation for {}ms", deferRetryMs);
        context.timeout(deferRetryMs);
        throw new RetriableException(mexc.getMessage(), mexc);
    }
}
 
Example 4
Source File: MongoDBArtifactStore.java    From hawkbit-extensions with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void deleteBySha1(final String tenant, final String sha1Hash) {
    try {
        deleteArtifact(gridFs.findOne(new Query()
                .addCriteria(Criteria.where(FILENAME).is(sha1Hash).and(TENANT_QUERY).is(sanitizeTenant(tenant)))));
    } catch (final MongoException e) {
        throw new ArtifactStoreException(e.getMessage(), e);
    }
}
 
Example 5
Source File: MongoDBArtifactStore.java    From hawkbit-extensions with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void deleteTempFile(final String tempFile) {
    try {
        deleteArtifact(loadTempFile(tempFile));
    } catch (final MongoException e) {
        throw new ArtifactStoreException(e.getMessage(), e);
    }

}
 
Example 6
Source File: MongoDb4Connection.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public void insertObject(final NoSqlObject<Document> object) {
    try {
        final Document unwrapped = object.unwrap();
        LOGGER.debug("Inserting BSON Document {}", unwrapped);
        InsertOneResult insertOneResult = this.collection.insertOne(unwrapped);
        LOGGER.debug("Insert MongoDb result {}", insertOneResult);
    } catch (final MongoException e) {
        throw new AppenderLoggingException("Failed to write log event to MongoDB due to error: " + e.getMessage(),
                e);
    }
}
 
Example 7
Source File: MongoDb3Connection.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public void insertObject(final NoSqlObject<Document> object) {
    try {
        final Document unwrapped = object.unwrap();
        LOGGER.debug("Inserting object {}", unwrapped);
        this.collection.insertOne(unwrapped);
    } catch (final MongoException e) {
        throw new AppenderLoggingException("Failed to write log event to MongoDB due to error: " + e.getMessage(),
                e);
    }
}