/** * Updates the stored base list with a new one based on the config. * * @param config */ public void updateStoredBaseList(Config config) { List<String> bucketServers = config.getServers(); if (bucketServers.size() > 0) { List<URI> newList = new ArrayList<URI>(); for (String bucketServer : bucketServers) { String hostname = bucketServer.split(":")[0]; try { newList.add(new URI("http://" + hostname + ":8091/pools")); } catch (URISyntaxException ex) { getLogger() .warn( "Could not add node to updated bucket list because " + "of a parsing exception."); getLogger().debug("Could not parse list because: " + ex); } } if (nodeListsAreDifferent(storedBaseList, newList)) { getLogger() .info("Replacing current streaming node list " + storedBaseList + " with " + newList); potentiallyRandomizeNodeList(newList); storedBaseList = newList; getConfigurationProvider().updateBaseListFromConfig(newList); } } }
@Override public NodeLocator createLocator(List<MemcachedNode> nodes) { Config config = getVBucketConfig(); if (config == null) { throw new IllegalStateException("Couldn't get config"); } if (config.getConfigType() == ConfigType.MEMCACHE) { return new KetamaNodeLocator(nodes, DefaultHashAlgorithm.KETAMA_HASH); } else if (config.getConfigType() == ConfigType.COUCHBASE) { return new VBucketNodeLocator(nodes, getVBucketConfig()); } else { throw new IllegalStateException("Unhandled locator type: " + config.getConfigType()); } }
@Override public MemcachedConnection createConnection(List<InetSocketAddress> addrs) throws IOException { Config config = getVBucketConfig(); if (config.getConfigType() == ConfigType.MEMCACHE) { return new CouchbaseMemcachedConnection( getReadBufSize(), this, addrs, getInitialObservers(), getFailureMode(), getOperationFactory()); } else if (config.getConfigType() == ConfigType.COUCHBASE) { return new CouchbaseConnection( getReadBufSize(), this, addrs, getInitialObservers(), getFailureMode(), getOperationFactory()); } throw new IOException("No ConnectionFactory for bucket type " + config.getConfigType()); }
@Override public List<InputSplit> getSplits(JobContext ctx) throws IOException { final Configuration conf = ctx.getConfiguration(); final URI ClusterURI; try { ClusterURI = new URI(conf.get(CouchbaseConfig.CB_INPUT_CLUSTER)); } catch (URISyntaxException e) { throw new IOException(e); } final List<URI> ClientURIList = new ArrayList<URI>(); ClientURIList.add(ClusterURI.resolve("/pools")); final String bucket = conf.get(CouchbaseConfig.CB_INPUT_BUCKET, "default"); final String password = conf.get(CouchbaseConfig.CB_INPUT_PASSWORD, ""); final CouchbaseConnectionFactory fact = new CouchbaseConnectionFactory(ClientURIList, bucket, password); final com.couchbase.client.vbucket.config.Config vbconfig = fact.getVBucketConfig(); final List<VBucket> allVBuckets = vbconfig.getVbuckets(); @SuppressWarnings("unchecked") final ArrayList<Integer>[] vblists = new ArrayList[vbconfig.getServersCount()]; int vbid = 0; for (VBucket v : allVBuckets) { if (vblists[v.getMaster()] == null) { vblists[v.getMaster()] = new ArrayList<Integer>(); } vblists[v.getMaster()].add(vbid); vbid++; } final ArrayList<InputSplit> splits = new ArrayList<InputSplit>(); for (ArrayList<Integer> vblist : vblists) { splits.add(new CouchbaseSplit(vblist)); } return splits; }