/** * Gets the list of hosts. * * @return the list of hosts */ public List<String> getHosts() { return proxied.getHosts(); }
private static Cluster createCluster(final MongoClientURI mongoURI, @Nullable final MongoDriverInformation mongoDriverInformation) { List<MongoCredential> credentialList = mongoURI.getCredentials() != null ? singletonList(mongoURI.getCredentials()) : Collections.<MongoCredential>emptyList(); if (mongoURI.getHosts().size() == 1) { return createCluster(createServerAddress(mongoURI.getHosts().get(0)), credentialList, mongoURI.getOptions(), null); } else { List<ServerAddress> seedList = new ArrayList<ServerAddress>(mongoURI.getHosts().size()); for (final String host : mongoURI.getHosts()) { seedList.add(createServerAddress(host)); } return createCluster(seedList, credentialList, mongoURI.getOptions(), mongoDriverInformation); } }
@Override public int hashCode() { int result = getOptions().hashCode(); result = 31 * result + getHosts().hashCode(); MongoCredential credentials = getCredentials(); result = 31 * result + (credentials != null ? credentials.hashCode() : 0); String database = getDatabase(); result = 31 * result + (database != null ? database.hashCode() : 0); String collection = getCollection(); result = 31 * result + (collection != null ? collection.hashCode() : 0); return result; }
@Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } MongoClientURI that = (MongoClientURI) o; if (!getHosts().equals(that.getHosts())) { return false; } String database = getDatabase(); if (database != null ? !database.equals(that.getDatabase()) : that.getDatabase() != null) { return false; } String collection = getCollection(); if (collection != null ? !collection.equals(that.getCollection()) : that.getCollection() != null) { return false; } MongoCredential credentials = getCredentials(); if (credentials != null ? !credentials.equals(that.getCredentials()) : that.getCredentials() != null) { return false; } if (!getOptions().equals(that.getOptions())) { return false; } return true; }
/** * Gets the list of hosts. * * @return the list of hosts */ public List<String> getHosts() { return proxied.getHosts(); }
@Override public String[] getLocations() throws IOException { List<String> hosts = inputURI.getHosts(); return hosts.toArray(new String[hosts.size()]); }
@Override public String toString() { StringBuilder sb = new StringBuilder("GridFSSplit{"); if (inputURI != null) { sb.append("inputURI hosts=") .append(inputURI.getHosts()) .append(", "); } if (fileId != null) { sb.append("fileId=").append(fileId).append(", "); } return sb .append("chunkSize=").append(chunkSize) .append(", fileLength=").append(fileLength) .append(", chunkId=").append(chunkId).append("}").toString(); }
@SuppressWarnings("ReplaceAllDot") private String createLogUri(MongoClientURI clientURI) { StringBuilder sb = new StringBuilder(); String password = clientURI.getPassword() == null ? null : new String(clientURI.getPassword()).replaceAll(".", "x"); String username = clientURI.getUsername(); for (String host : clientURI.getHosts()) { sb.append("mongodb://"); if (username != null) { sb.append(username); if (password != null) { sb.append(':').append(password); } sb.append('@'); } sb.append(host).append(" "); } return sb.toString(); }
@Override public String toString() { String result = "MongoInputSplit{inputURI hosts=" + this.inputURI.getHosts() + ", inputURI namespace=" + this.inputURI.getDatabase() + "." + this.inputURI.getCollection(); if (authURI != null) { result += "authURI hosts=" + authURI.getHosts() + ", authURI database=" + authURI.getDatabase(); } return result + ", min=" + this.min + ", max=" + this.max + ", query=" + this.query + ", sort=" + this.sort + ", fields=" + this.fields + ", limit=" + this.limit + ", skip=" + this.skip + ", notimeout=" + this.notimeout + '}'; }
private static Cluster createCluster(final MongoClientURI mongoURI, @Nullable final MongoDriverInformation mongoDriverInformation) { List<MongoCredential> credentialList = mongoURI.getCredentials() != null ? singletonList(mongoURI.getCredentials()) : Collections.<MongoCredential>emptyList(); if (mongoURI.getHosts().size() == 1) { return createCluster(createServerAddress(mongoURI.getHosts().get(0)), credentialList, mongoURI.getOptions(), null); } else { List<ServerAddress> seedList = new ArrayList<ServerAddress>(mongoURI.getHosts().size()); for (final String host : mongoURI.getHosts()) { seedList.add(createServerAddress(host)); } return createCluster(seedList, credentialList, mongoURI.getOptions(), mongoDriverInformation); } }
public DB create() { try { mongoClient = new MongoClient(uri); mongoClient.setWriteConcern(WriteConcern.ACKNOWLEDGED); return mongoClient.getDB(uri.getDatabase()); } catch (Exception e) { LOGGER.error(format("Cannot connect to MongoDB on hosts %s using username: '%s'", uri.getHosts(), uri.getUsername()), e); throw new CouldNotProvideMongoException(e); } }
@Override public List<InputSplit> calculateSplits() { if (LOG.isDebugEnabled()) { MongoClientURI inputURI = MongoConfigUtil.getInputURI(getConfiguration()); LOG.debug(format("SingleMongoSplitter calculating splits for namespace: %s.%s; hosts: %s", inputURI.getDatabase(), inputURI.getCollection(), inputURI.getHosts())); } return Collections.singletonList( (InputSplit) new MongoInputSplit(getConfiguration())); }
@Override public int hashCode() { int result = getOptions().hashCode(); result = 31 * result + getHosts().hashCode(); MongoCredential credentials = getCredentials(); result = 31 * result + (credentials != null ? credentials.hashCode() : 0); String database = getDatabase(); result = 31 * result + (database != null ? database.hashCode() : 0); String collection = getCollection(); result = 31 * result + (collection != null ? collection.hashCode() : 0); return result; }
public MongoClientURIBuilder(final MongoClientURI mongoClientURI) { List<String> hosts = mongoClientURI.getHosts(); if (!hosts.isEmpty()) { String first = hosts.get(0);
public MongoClientURIBuilder(final MongoClientURI mongoClientURI) { List<String> list = mongoClientURI.getHosts(); for (String s : list) { host(s); } database = mongoClientURI.getDatabase(); collection = mongoClientURI.getCollection(); userName = mongoClientURI.getUsername(); if (mongoClientURI.getPassword() != null) { password = new String(mongoClientURI.getPassword()); } options = mongoClientURI.getOptions(); String uri = mongoClientURI.getURI(); if (uri.contains("?")) { String query = uri.substring(uri.indexOf('?') + 1); String[] pairs = query.split("&"); for (String pair : pairs) { String[] split = pair.split("="); param(split[0], split[1]); } } }
/** * Get a connection if available. If not available, null is returned. * * @param dbName the database name * @return the connection or null */ public static MongoConnection getConnection(String dbName) { MongoClientURI clientURI; try { clientURI = new MongoClientURI(URL); } catch (IllegalArgumentException e) { // configured URL is invalid return null; } StringBuilder uri = new StringBuilder("mongodb://"); String separator = ""; for (String host : clientURI.getHosts()) { uri.append(separator); separator = ","; uri.append(host); } uri.append("/").append(dbName).append("?").append(OPTIONS); return getConnectionByURL(uri.toString()); }
@Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } MongoClientURI that = (MongoClientURI) o; if (!getHosts().equals(that.getHosts())) { return false; } String database = getDatabase(); if (database != null ? !database.equals(that.getDatabase()) : that.getDatabase() != null) { return false; } String collection = getCollection(); if (collection != null ? !collection.equals(that.getCollection()) : that.getCollection() != null) { return false; } MongoCredential credentials = getCredentials(); if (credentials != null ? !credentials.equals(that.getCredentials()) : that.getCredentials() != null) { return false; } if (!getOptions().equals(that.getOptions())) { return false; } return true; }
public RealMongoDBExtendedStoreConnection(MongoURI mongoURI) { MongoClientURI mongoClientUri = null; try { mongoClientUri = new MongoClientURI(mongoURI.getValue()); } catch (Exception e) { throw new BaseException("can not parse:\"" + mongoURI.getValue() + "\" " + MongoParamParser.EXPECTED_PARAMS, e); } Frame frame = new Frame(); frame.add("USE MONGO DB"); frame.add("mongo db has be up and running"); frame.add("uri: " + mongoURI.getValue()); frame.add(" -> database:" + mongoClientUri.getDatabase()); frame.add(" -> user:" + mongoClientUri.getUsername()); mongoClientUri.getHosts().forEach(host -> { frame.add(" -> host:" + host); } ); frame.add(" -> ssl:" + mongoClientUri.getOptions().isSslEnabled()); LOGGER.info(frame.toString()); MongoClient mongoClient = new MongoClient(mongoClientUri); database = mongoClient.getDatabase(mongoClientUri.getDatabase()); databaseDeprecated = mongoClient.getDB(mongoClientUri.getDatabase()); }