List of usage examples for com.mongodb MongoCredential getMechanism
@Nullable
public String getMechanism()
From source file:com.redhat.lightblue.mongo.config.MongoConfiguration.java
License:Open Source License
public static String toString(MongoCredential cr) { StringBuilder bld = new StringBuilder(); bld.append("{mechanism:").append(cr.getMechanism()); if (cr.getUserName() != null) { bld.append(" userName:").append(cr.getUserName()); }//from w w w.j av a 2 s.c o m if (cr.getPassword() != null) { bld.append(" password:").append(cr.getPassword()); } if (cr.getSource() != null) { bld.append(" source:").append(cr.getSource()); } bld.append('}'); return bld.toString(); }
From source file:org.pentaho.mongo.MongoUtils.java
License:Open Source License
/** * Return a list of custom "lastErrorModes" (if any) defined in the replica * set configuration object on the server. These can be used as the "w" * setting for the write concern in addition to the standard "w" values of * <number> or "majority"./*w w w . j ava 2s .com*/ * * @param hostsPorts the hosts to use * @param singlePort the default port to use if no ports are given in the * hostsPorts spec * @param username the username for authentication * @param password the password for authentication * @param vars the environment variables to use * @param log for logging * @return a list of the names of any custom "lastErrorModes" * @throws KettleException if a problem occurs */ public static List<String> getLastErrorModes(String hostsPorts, String singlePort, MongoCredential cred, VariableSpace vars, LogChannelInterface log) throws KettleException { List<String> customLastErrorModes = new ArrayList<String>(); MongoClient mongo = null; try { if (cred != null && cred.getMechanism().equals(MongoCredential.MONGODB_CR_MECHANISM)) { // need to make a new credential that specifies the local database cred = MongoCredential.createMongoCRCredential(cred.getUserName(), LOCAL_DB, cred.getPassword()); } mongo = initConnection(hostsPorts, singlePort, cred, false, null, null, null, null, null, false, null, vars, log); DB local = mongo.getDB(LOCAL_DB); if (local != null) { DBCollection replset = local.getCollection(REPL_SET_COLLECTION); if (replset != null) { DBObject config = replset.findOne(); extractLastErrorModes(config, customLastErrorModes); } } } finally { if (mongo != null) { mongo.close(); } } return customLastErrorModes; }
From source file:org.pentaho.mongo.MongoUtils.java
License:Open Source License
protected static BasicDBList getRepSetMemberRecords(String hostsPorts, String singlePort, MongoCredential cred, VariableSpace vars, LogChannelInterface log) throws KettleException { MongoClient mongo = null;//w w w .j a v a 2s .c om BasicDBList setMembers = null; try { if (cred != null && cred.getMechanism().equals(MongoCredential.MONGODB_CR_MECHANISM)) { // need to make a new credential that specifies the local database cred = MongoCredential.createMongoCRCredential(cred.getUserName(), LOCAL_DB, cred.getPassword()); } mongo = initConnection(hostsPorts, singlePort, cred, false, null, null, null, null, null, false, null, vars, log); DB local = mongo.getDB(LOCAL_DB); if (local != null) { DBCollection replset = local.getCollection(REPL_SET_COLLECTION); if (replset != null) { DBObject config = replset.findOne(); if (config != null) { Object members = config.get(REPL_SET_MEMBERS); if (members instanceof BasicDBList) { if (((BasicDBList) members).size() == 0) { // log that there are no replica set members defined if (log != null) { log.logBasic(BaseMessages.getString(PKG, "MongoUtils.Message.Warning.NoReplicaSetMembersDefined")); //$NON-NLS-1$ } } else { setMembers = (BasicDBList) members; } } else { // log that there are no replica set members defined if (log != null) { log.logBasic(BaseMessages.getString(PKG, "MongoUtils.Message.Warning.NoReplicaSetMembersDefined")); //$NON-NLS-1$ } } } else { // log that there are no replica set members defined if (log != null) { log.logBasic(BaseMessages.getString(PKG, "MongoUtils.Message.Warning.NoReplicaSetMembersDefined")); //$NON-NLS-1$ } } } else { // log that the replica set collection is not available if (log != null) { log.logBasic(BaseMessages.getString(PKG, "MongoUtils.Message.Warning.ReplicaSetCollectionUnavailable")); //$NON-NLS-1$ } } } else { // log that the local database is not available!! if (log != null) { log.logBasic(BaseMessages.getString(PKG, "MongoUtils.Message.Warning.LocalDBNotAvailable")); //$NON-NLS-1$ } } } catch (Exception ex) { throw new KettleException(ex); } finally { if (mongo != null) { mongo.close(); } } return setMembers; }