Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Branor committed Feb 22, 2017
1 parent 6f7afa9 commit a87fddc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
Expand Up @@ -210,23 +210,21 @@ public Map<String, Object> revsDiff(String database,
logger.debug("client was null");
}
if(response != null) {
Iterator<MultiGetItemResponse> iterator = response.iterator();
while(iterator.hasNext()) {
MultiGetItemResponse item = iterator.next();
if(item.isFailed()) {
for (MultiGetItemResponse item : response) {
if (item.isFailed()) {
logger.warn("_revs_diff get failure on index: {} id: {} message: {}", item.getIndex(), item.getId(), item.getFailure().getMessage());
} else {
if(item.getResponse().isExists()) {
if (item.getResponse().isExists()) {
String itemId = item.getId();
Map<String, Object> source = item.getResponse().getSourceAsMap();
if(source != null) {
Map<String, Object> meta = (Map<String, Object>)source.get("meta");
if(meta != null) {
String rev = (String)meta.get("rev");
if (source != null) {
Map<String, Object> meta = (Map<String, Object>) source.get("meta");
if (meta != null) {
String rev = (String) meta.get("rev");
//retrieve the revision passed in from Couchbase
Map<String, String> sourceRevMap = (Map<String, String>)responseMap.get(itemId);
Map<String, String> sourceRevMap = (Map<String, String>) responseMap.get(itemId);
String sourceRev = sourceRevMap.get("missing");
if(rev.equals(sourceRev)) {
if (rev.equals(sourceRev)) {
// if our revision is the same as the source rev
// remove it from the response map
responseMap.remove(itemId);
Expand Down
Expand Up @@ -77,10 +77,10 @@ public String getPoolUUID(String pool) {
@Override
public Map<String, Object> getPoolDetails(String pool) {
if("default".equals(pool)) {
Map<String, Object> bucket = new HashMap<String, Object>();
Map<String, Object> bucket = new HashMap<>();
bucket.put("uri", "/pools/" + pool + "/buckets?uuid=" + getPoolUUID(pool));

Map<String, Object> responseMap = new HashMap<String, Object>();
Map<String, Object> responseMap = new HashMap<>();
responseMap.put("buckets", bucket);

List<Object> nodes = getNodesServingPool(pool);
Expand All @@ -94,7 +94,7 @@ public Map<String, Object> getPoolDetails(String pool) {
@Override
public List<String> getBucketsInPool(String pool) {
if("default".equals(pool)) {
List<String> bucketNameList = new ArrayList<String>();
List<String> bucketNameList = new ArrayList<>();

ClusterStateRequestBuilder stateBuilder = client.admin().cluster().prepareState();
ClusterStateResponse response = stateBuilder.execute().actionGet();
Expand Down Expand Up @@ -165,9 +165,9 @@ protected void storeUUID(String bucket, String id, String uuid) {
if(shouldIgnoreBucket(bucket)) // Don't touch buckets on the ignore list
return;

Map<String,Object> doc = new HashMap<String, Object>();
Map<String,Object> doc = new HashMap<>();
doc.put("uuid", uuid);
Map<String, Object> toBeIndexed = new HashMap<String, Object>();
Map<String, Object> toBeIndexed = new HashMap<>();
toBeIndexed.put("doc", doc);

IndexRequestBuilder builder = client.prepareIndex();
Expand Down Expand Up @@ -238,20 +238,20 @@ public List<Object> getNodesServingPool(String pool) {
String host = nodeInfo.getHostname();

if (plugins != null) {
for (PluginInfo plugin : plugins) {
if (plugin.getName().contains("transport-couchbase")) {
Map<String, Object> nodePorts = new HashMap<>();
nodePorts.put("direct", port);

Map<String, Object> node = new HashMap<>();
node.put("couchApiBase", String.format("http://%s:%s/", host, port));
node.put("hostname", String.format("%s:%s", host, port));
node.put("ports", nodePorts);

nodes.add(node);
logger.debug(String.format("Found transport-couchbase running on: %s:%s", host, port));
}
}
plugins.stream()
.filter(plugin -> plugin.getName().contains("transport-couchbase"))
.forEach(plugin -> {
Map<String, Object> nodePorts = new HashMap<>();
nodePorts.put("direct", port);

Map<String, Object> node = new HashMap<>();
node.put("couchApiBase", String.format("http://%s:%s/", host, port));
node.put("hostname", String.format("%s:%s", host, port));
node.put("ports", nodePorts);

nodes.add(node);
logger.debug(String.format("Found transport-couchbase running on: %s:%s", host, port));
});
}
}
return nodes;
Expand All @@ -261,8 +261,7 @@ public List<Object> getNodesServingPool(String pool) {

@Override
public Map<String, Object> getStats() {
Map<String, Object> result = new HashMap<String, Object>();
return result;
return new HashMap<>();
}

}

0 comments on commit a87fddc

Please sign in to comment.