Browse files

issue69: replica step down should hide connection exception

issue60: Result sets: Overview lines should use full tab window width / Expand all nodes option
issue34: add methods to administer replset: initiate, add, remove
  • Loading branch information...
1 parent 7edab0e commit 9bcd77180b834bc824008974184ffaaf6adac98e @agirbal committed Mar 25, 2012
View
BIN lib/SwingFast.jar
Binary file not shown.
View
58 resource/xml/JMongoBrowser.xml
@@ -316,12 +316,12 @@
<TextArea id="mrMap" label="Map JS Function" toolTipText="map javascript function with signature 'void function map()' which should contain one or more calls to emit(key, obj)" nonEmpty="true" value="function(){ emit(this._id, {count: 1}); }"/>
<TextArea id="mrReduce" label="Reduce JS Function" toolTipText="reduce javascript function with signature 'result reduce(key, values)' where key is the emit key and values is the list of values to reduce.'" nonEmpty="true" value="function(key, values) { total = 0; for (var i = 0; i &lt; values.length; ++i) { total += values[i].count; }; return {count: total}; }"/>
<TextArea id="mrFinalize" label="Finalize JS Function" toolTipText="optional finalize javascript function with signature 'result finalize(key, out)' where out is the result for that key"/>
- <Div id="input">
+ <Div id="input" titled="true">
<com.edgytech.jmongobrowser.DocBuilderField id="mrQuery" label="Query" toolTipText="Query to filter the input, in JSON format"/>
<com.edgytech.jmongobrowser.DocBuilderField id="mrSort" label="Sort" toolTipText="Sort key for the input, in JSON format. Sort by the emit key to optimize performance."/>
<IntSpinner id="mrLimit" label="Limit" toolTipText="Limit of the number of input entries to process" minValue="0"/>
</Div>
- <Div id="output">
+ <Div id="output" titled="true">
<ComboBox id="mrType" label="Output Type" items="replace;merge;reduce;inline" toolTipText="How to process the output"/>
<TextField id="mrOut" label="Output Collection" toolTipText="Name of the output collection" nonEmpty="true"/>
<TextField id="mrOutDB" label="Output Database" toolTipText="Name of the output database, if different from the input database"/>
@@ -524,8 +524,10 @@
</MenuItem>
</Menu>
<Menu id="replica">
- <MenuItem id="replicaSetStatus" call="replicaSetStatus" label="RS Status"/>
- <MenuItem id="oplogInfo" call="oplogInfo" label="Oplog Info"/>
+ <MenuItem id="rsConfig" call="rsConfig" label="Config"/>
+ <MenuItem id="rsStatus" call="rsStatus" label="Status"/>
+ <MenuItem id="rsOplogInfo" call="rsOplogInfo" label="Oplog Info"/>
+ <MenuSeparator/>
<MenuItem id="rsStepDown" call="rsStepDown" label="Step Down" toolTipText="If primary, the server will step down to secondary to let another server be elected."/>
<MenuItem id="rsFreeze" call="rsFreeze" label="Freeze" toolTipText="This server will not attempt to become primary for next N seconds">
<FormDialog>
@@ -540,20 +542,47 @@
<Text id="address" field="true"/>
<Text id="replication" field="true" toolTipText="Replication status" icon="overlay/tick_circle.png" iconGroup="icons"/>
<Text id="maxObjectSize" field="true"/>
- <Text id="durability" field="true" icon="overlay/shield_blue.png" iconGroup="icons"/>
+ <Text id="journaling" field="true" icon="overlay/shield_blue.png" iconGroup="icons"/>
<com.edgytech.jmongobrowser.CmdField id="serverStatus" cmd="serverStatus"/>
</Div>
</Zone>
</com.edgytech.jmongobrowser.ServerPanel>
<com.edgytech.jmongobrowser.ReplSetPanel id="replSetPanel">
<MenuBar id="menu" zone="NORTH" minHeight="50" prefHeight="50">
<Text id="icon" icon="replSet.png" iconGroup="icons" toolTipText="Server"/>
- <Menu id="replSet">
+ <Menu id="replSet" label="ReplicaSet">
<MenuItem id="refresh" label="Refresh" call="refresh" icon="stock_refresh.png" iconGroup="icons" key="r" keyMod="cmd+shift"/>
+ <MenuSeparator/>
+ <MenuItem id="initiate" call="initiate">
+ <com.edgytech.jmongobrowser.DocBuilderField id="initConfig" label="Config" toolTipText="An object representing the configuration. Leave empty to start with a single server."/>
+ </MenuItem>
+ <MenuItem id="reconfigure" call="reconfigure" showDialog="false">
+ <FormDialog>
+ <com.edgytech.jmongobrowser.DocBuilderField id="reconfConfig" label="Config" toolTipText="An object representing the new configuration." nonEmpty="true"/>
+ </FormDialog>
+ </MenuItem>
+ <MenuItem id="addReplica" call="addReplica">
+ <FormDialog>
+ <TextField id="arHost" label="Host" toolTipText="Name of host to add to the replica set" nonEmpty="true"/>
+ <CheckBox id="arArbiterOnly" label="Arbiter only" toolTipText="Whether this replica should be an arbiter only, with no data" value="false"/>
+ <CheckBox id="arHidden" label="Hidden" toolTipText="If true, the replica will not be seen by the client applications (e.g. backup only server)" value="false"/>
+ <DoubleSpinner id="arPriority" label="Priority" toolTipText="Priority of the replica to become primary, between 0 and 1000 (1 is default, 0 means never primary)" minValue="0" maxValue="1000" value="1"/>
+ <com.edgytech.jmongobrowser.DocBuilderField id="arTags" label="Tags" toolTipText="An object representing tags for this server"/>
+ <IntSpinner id="arSlaveDelay" label="Slave delay" minValue="0" value="0" toolTipText="Time in second to remain behind the primary"/>
+ <IntSpinner id="arVotes" label="Votes" minValue="0" value="1" toolTipText="Number of votes for this replica. This option should generally be set to 1."/>
+ <CheckBox id="arIgnoreIndexes" label="Ignore indexes" toolTipText="If true, the replica will not build indexes (e.g. backup only server)" value="false"/>
+ </FormDialog>
+ </MenuItem>
+ <MenuItem id="removeReplica" call="removeReplica" showDialog="false">
+ <FormDialog>
+ <ComboBox id="rrHost" label="Host" items="None" toolTipText="Name of host to remove"/>
+ </FormDialog>
+ </MenuItem>
</Menu>
<Menu id="command">
- <MenuItem id="replicaSetStatus" call="replicaSetStatus" label="RS Status"/>
- <MenuItem id="oplogInfo" call="oplogInfo" label="Oplog Info"/>
+ <MenuItem id="rsConfig" call="rsConfig" label="Config"/>
+ <MenuItem id="rsStatus" call="rsStatus" label="Status"/>
+ <MenuItem id="rsOplogInfo" call="rsOplogInfo" label="Oplog Info"/>
</Menu>
<Menu id="tools">
<MenuItem id="compareReplicas" call="compareReplicas">
@@ -568,6 +597,7 @@
<Div zone="NORTH" gap="true" bgColor="255;255;255">
<Text id="name" field="true"/>
<Text id="maxObjectSize" field="true"/>
+ <Text id="replicas" field="true"/>
</Div>
</Zone>
</com.edgytech.jmongobrowser.ReplSetPanel>
@@ -577,14 +607,15 @@
<Menu id="router" label="MongoS">
<MenuItem id="refresh" label="Refresh" call="refresh" icon="stock_refresh.png" iconGroup="icons" key="r" keyMod="cmd+shift"/>
</Menu>
- <Menu id="Sharding">
+ <Menu id="sharding">
<MenuItem id="listShards" call="listShards"/>
+ <MenuItem id="flushConfiguration" call="flushConfiguration"/>
+ <MenuSeparator/>
<MenuItem id="addShard" call="addShard">
<FormDialog>
- <TextField id="asHost" label="Server Name" toolTipText="Server hostname" nonEmpty="true"/>
- <IntSpinner id="asPort" label="Server Port" minValue="1" value="27017" toolTipText="Server port"/>
- <TextField id="asShardName" label="Shard Name" toolTipText="Optional, a shard name"/>
+ <TextField id="asHost" label="Server Names" toolTipText="Comma-separated list of seed servers for that shard" nonEmpty="true"/>
<TextField id="asReplSetName" label="Replica Set Name" toolTipText="If adding a replica set, the replica set name"/>
+ <TextField id="asShardName" label="Shard Name" toolTipText="Optional, the shard name"/>
<IntSpinner id="asMaxSize" label="Max Size MB" minValue="0" toolTipText="Maximum size in megabytes to store in the shard"/>
</FormDialog>
</MenuItem>
@@ -593,7 +624,8 @@
<ComboBox id="rsShard" label="Shard" items="None" toolTipText="Shard to remove"/>
</FormDialog>
</MenuItem>
- <MenuSeparator/>
+ </Menu>
+ <Menu id="tools">
<CheckBoxMenuItem id="autoBalance" call="autoBalance"/>
<MenuSeparator/>
<MenuItem id="regenConfigDB" label="Regenerate Config DB" call="regenConfigDB">
View
4 resource/xml/docView.xml
@@ -29,6 +29,10 @@
<MenuItem id="getMore" call="getMore" enabled="false"/>
<MenuItem id="getAll" call="getAll" enabled="false"/>
</Menu>
+ <Menu id="view">
+ <MenuItem id="expandAll" call="expandAll"/>
+ <MenuItem id="collapseAll" call="collapseAll"/>
+ </Menu>
<Menu id="document" enabled="false">
<MenuItem id="update" call="update" showDialog="false">
<FormDialog>
View
2 src/com/edgytech/jmongobrowser/CollectionPanel.java
@@ -1024,7 +1024,7 @@ public void shardCollection() {
new InfoDialog(null, "Empty key", null, "You must select a shard key").show();
return;
}
- if (!new ConfirmDialog(null, "Confirm shard key", null, "About to shard collection with key " + key + ", is that correct?").show())
+ if (!new ConfirmDialog(null, "Confirm shard key", null, "About to shard collection with key " + key + ", is it correct? This operation cannot be undone.").show())
return;
boolean unique = getBooleanFieldValue(Item.shardUniqueIndex);
View
23 src/com/edgytech/jmongobrowser/DocView.java
@@ -59,6 +59,8 @@
tools,
startAutoUpdate,
stopAutoUpdate,
+ expandAll,
+ collapseAll
}
DB db;
DBObject cmd;
@@ -90,7 +92,7 @@ public DocView(String id, String label, DBObject doc, Object root, DbJob job) {
setStringFieldValue(Item.tabTitle, label);
getTree().label = root.toString();
if (doc != null) {
- addDocument(doc, job);
+ addDocument(doc, job, true);
}
}
@@ -305,7 +307,8 @@ public void wrapUp(Object res) {
}
addDocument(result, this);
getTree().structureComponent();
- getTree().expandNode(getTree().getTreeNode());
+ // result of command should be fully expanded
+ getTree().expandAll();
// panel info may need to be refreshed
if (panel != null)
@@ -615,15 +618,31 @@ public void wrapUp(Object res) {
}
private void addDocument(DBObject doc, DbJob job) {
+ addDocument(doc, job, false);
+ }
+
+ private void addDocument(DBObject doc, DbJob job, boolean expand) {
TreeNodeLabel node = new TreeNodeDBObject(doc, job);
final PopUpMenu popUp = (PopUpMenu) getBoundUnit(Item.popUp);
node.setPopUpMenu(popUp);
getTree().addChild(node);
+ if (expand)
+ getTree().expandNode(node);
}
// protected void appendDoc(DBObject doc) {
// TreeNodeLabel node = new TreeNodeLabel();
// node.forceTreeNode(MongoUtils.dbObjectToTreeNode(doc));
// getTree().addChild(node);
// }
+
+ public void collapseAll() {
+ getTree().collapseAll();
+ // need to reexpand root
+ getTree().expandNode(getTree().getTreeNode());
+ }
+
+ public void expandAll() {
+ getTree().expandAll();
+ }
}
View
20 src/com/edgytech/jmongobrowser/ReplSetNode.java
@@ -5,9 +5,7 @@
package com.edgytech.jmongobrowser;
-import com.mongodb.Mongo;
-import com.mongodb.MongoOptions;
-import com.mongodb.ServerAddress;
+import com.mongodb.*;
import java.util.List;
import java.util.logging.Level;
import javax.swing.ImageIcon;
@@ -45,10 +43,13 @@ public ReplSetNode(String name, List<ServerAddress> addrs, MongoOptions opts) {
@Override
protected void populateChildren() {
// need to make a query to update server list
- mongo.getDatabaseNames();
+ try {
+ mongo.getDatabaseNames();
+ } catch (Exception e) {}
+
List<ServerAddress> addrs = mongo.getServerAddressList();
for (ServerAddress addr : addrs) {
- addChild(new ServerNode(addr, mongo.getMongoOptions()));
+ addChild(new ServerNode(addr, mongo.getMongoOptions(), null));
}
}
@@ -64,5 +65,14 @@ public String getName() {
protected void updateNode(List<ImageIcon> overlays) {
label = getName();
}
+
+ String[] getReplicaNames() {
+ List<ServerAddress> addrs = mongo.getServerAddressList();
+ String[] names = new String[addrs.size()];
+ int i = 0;
+ for (ServerAddress addr : addrs)
+ names[i++] = addr.toString();
+ return names;
+ }
}
View
191 src/com/edgytech/jmongobrowser/ReplSetPanel.java
@@ -16,6 +16,10 @@
import java.util.ArrayList;
import javax.swing.JPanel;
import com.edgytech.jmongobrowser.ReplSetPanel.Item;
+import com.edgytech.swingfast.*;
+import com.mongodb.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
/**
*
@@ -26,9 +30,26 @@
enum Item {
refresh,
name,
- replicaSetStatus,
- oplogInfo,
maxObjectSize,
+ replicas,
+ initiate,
+ initConfig,
+ reconfigure,
+ reconfConfig,
+ addReplica,
+ arHost,
+ arArbiterOnly,
+ arHidden,
+ arPriority,
+ arVotes,
+ arTags,
+ arSlaveDelay,
+ arIgnoreIndexes,
+ removeReplica,
+ rrHost,
+ rsConfig,
+ rsStatus,
+ rsOplogInfo,
compareReplicas,
crStat
}
@@ -46,6 +67,12 @@ protected void updateComponentCustom(JPanel comp) {
try {
setStringFieldValue(Item.name, getReplSetNode().getName());
setStringFieldValue(Item.maxObjectSize, String.valueOf(getReplSetNode().getMongo().getReplicaSetStatus().getMaxBsonObjectSize()));
+ String replicas = "";
+ for (String replica : getReplSetNode().getReplicaNames()) {
+ replicas += replica + ",";
+ }
+ replicas = replicas.substring(0, replicas.length() - 1);
+ setStringFieldValue(Item.replicas, replicas);
} catch (Exception e) {
JMongoBrowser.instance.showError(this.getClass().getSimpleName() + " update", e);
}
@@ -55,13 +82,169 @@ protected void updateComponentCustom(JPanel comp) {
public void actionPerformed(Item enm, XmlComponentUnit unit, Object src) {
}
- public void replicaSetStatus() {
+ public void rsConfig() {
+ final DBCollection col = getReplSetNode().getMongo().getDB("local").getCollection("system.replset");
+ CollectionPanel.doFind(col, null);
+ }
+
+ public void rsStatus() {
new DocView(null, "RS Status", getReplSetNode().getMongo().getDB("admin"), "replSetGetStatus").addToTabbedDiv();
}
- public void oplogInfo() {
+ public void rsOplogInfo() {
new DocView(null, "Oplog Info", MongoUtils.getReplicaSetInfo(getReplSetNode().getMongo()), "Oplog of " + getReplSetNode().getMongo().toString(), null).addToTabbedDiv();
}
+
+ public void initiate() {
+ DBObject config = ((DocBuilderField)getBoundUnit(Item.initConfig)).getDBObject();
+ DBObject cmd = new BasicDBObject("replSetInitiate", config);
+ DB admin = getReplSetNode().getMongo().getDB("admin");
+ new DocView(null, "RS Initiate", admin, cmd).addToTabbedDiv();
+ }
+
+ public void reconfigure() {
+ final DBCollection col = getReplSetNode().getMongo().getDB("local").getCollection("system.replset");
+ DBObject oldConf = col.findOne();
+ if (oldConf == null) {
+ new InfoDialog(null, "reconfig error", null, "No existing replica set configuration").show();
+ return;
+ }
+ ((DocBuilderField)getBoundUnit(Item.reconfConfig)).setDBObject(oldConf);
+ if (!((MenuItem)getBoundUnit(Item.reconfigure)).getDialog().show())
+ return;
+
+ DBObject config = ((DocBuilderField)getBoundUnit(Item.reconfConfig)).getDBObject();
+ reconfigure(config);
+ }
+
+ public void reconfigure(DBObject config) {
+ final DBCollection col = getReplSetNode().getMongo().getDB("local").getCollection("system.replset");
+ DBObject oldConf = col.findOne();
+ int version = ((Integer) oldConf.get("version")) + 1;
+ config.put("version", version);
+
+ // reconfig usually triggers an error as connections are bounced.. try to absorb it
+ final DBObject cmd = new BasicDBObject("replSetReconfig", config);
+ final DB admin = getReplSetNode().getMongo().getDB("admin");
+ final ReplSetNode node = getReplSetNode();
+
+ new DbJob() {
+
+ @Override
+ public Object doRun() {
+ Object res = null;
+ try {
+ res = admin.command(cmd);
+ } catch (MongoException.Network e) {
+ res = "Operation was likely successful, but connection error: " + e.toString();
+ }
+
+ try {
+ // sleep a bit since it takes time for driver to see change
+ Thread.sleep(6000);
+ } catch (InterruptedException ex) {
+ getLogger().log(Level.WARNING, null, ex);
+ }
+ return res;
+ }
+
+ @Override
+ public String getNS() {
+ return null;
+ }
+
+ @Override
+ public String getShortName() {
+ return "RS Reconfig";
+ }
+
+ @Override
+ public Object getRoot(Object result) {
+ return cmd.toString();
+ }
+
+ @Override
+ public void wrapUp(Object res) {
+ // try to restructure but changes arent seen for a few seconds
+ super.wrapUp(res);
+ node.structureComponent();
+ }
+ }.addJob();
+ }
+
+ public void addReplica() {
+ final DBCollection col = getReplSetNode().getMongo().getDB("local").getCollection("system.replset");
+ DBObject config = col.findOne();
+ if (config == null) {
+ new InfoDialog(null, "reconfig error", null, "No existing replica set configuration").show();
+ return;
+ }
+
+ BasicDBList members = (BasicDBList) config.get("members");
+ int max = 0;
+ for (int i = 0; i < members.size(); ++i) {
+ int id = (Integer)((DBObject)members.get(i)).get("_id");
+ if (id > max)
+ max = id;
+ }
+
+ DBObject member = new BasicDBObject("_id", max + 1);
+ member.put("host", getStringFieldValue(Item.arHost));
+ boolean arb = getBooleanFieldValue(Item.arArbiterOnly);
+ if (arb) member.put("arbiterOnly", true);
+ boolean hidden = getBooleanFieldValue(Item.arHidden);
+ if (hidden) member.put("hidden", true);
+ boolean ignoreIndexes = getBooleanFieldValue(Item.arIgnoreIndexes);
+ if (ignoreIndexes) member.put("buildIndexes", false);
+ double priority = getDoubleFieldValue(Item.arPriority);
+ if (priority != 1.0) member.put("priority", priority);
+ int slaveDelay = getIntFieldValue(Item.arSlaveDelay);
+ if (slaveDelay > 0) member.put("slaveDelay", slaveDelay);
+ int votes = getIntFieldValue(Item.arVotes);
+ if (votes != 1) member.put("votes", votes);
+ DBObject tags = ((DocBuilderField)getBoundUnit(Item.arTags)).getDBObject();
+ if (tags != null) member.put("tags", tags);
+ members.add(member);
+ reconfigure(config);
+ }
+
+ public void removeReplica() {
+ final DBCollection col = getReplSetNode().getMongo().getDB("local").getCollection("system.replset");
+ DBObject config = col.findOne();
+ if (config == null) {
+ new InfoDialog(null, "reconfig error", null, "No existing replica set configuration").show();
+ return;
+ }
+
+ FormDialog dialog = (FormDialog) ((MenuItem) getBoundUnit(Item.removeReplica)).getDialog();
+ ComboBox combo = (ComboBox) getBoundUnit(Item.rrHost);
+ combo.value = 0;
+ combo.items = getReplSetNode().getReplicaNames();
+ combo.structureComponent();
+
+ if (!dialog.show())
+ return;
+
+ String host = getStringFieldValue(Item.rrHost);
+
+ if (!new ConfirmDialog(null, "Remove Replica", null, "Are you sure you want to remove " + host + "? This server should be stopped before removing.").show())
+ return;
+
+ BasicDBList members = (BasicDBList) config.get("members");
+ int i = 0;
+ for (; i < members.size(); ++i) {
+ if (host.equals(((DBObject)members.get(i)).get("host")))
+ break;
+ }
+
+ if (i == members.size()) {
+ new InfoDialog(null, "reconfig error", null, "Cannot remove replica " + host).show();
+ return;
+ }
+
+ members.remove(i);
+ reconfigure(config);
+ }
public void compareReplicas() {
final String stat = getStringFieldValue(Item.crStat);
View
4 src/com/edgytech/jmongobrowser/RouterNode.java
@@ -65,9 +65,9 @@ protected void populateChildren() {
}
if (repl != null || addrs.size() > 1) {
- addChild(new ReplSetNode(repl, addrs, mongo.getMongoOptions()));
+ addChild(new ReplSetNode(id + " (" + repl + ")", addrs, mongo.getMongoOptions()));
} else {
- addChild(new ServerNode(addrs.get(0), mongo.getMongoOptions()));
+ addChild(new ServerNode(addrs.get(0), mongo.getMongoOptions(), id + " (" + addrs.get(0) + ")"));
}
} catch (Exception e) {
getLogger().log(Level.WARNING, null, e);
View
9 src/com/edgytech/jmongobrowser/RouterPanel.java
@@ -46,9 +46,9 @@
address,
shards,
listShards,
+ flushConfiguration,
addShard,
asHost,
- asPort,
asShardName,
asReplSetName,
asMaxSize,
@@ -97,13 +97,10 @@ public void actionPerformed(Item enm, XmlComponentUnit unit, Object src) {
public void addShard() {
final RouterNode router = getRouterNode();
final String host = getStringFieldValue(Item.asHost);
- final int port = getIntFieldValue(Item.asPort);
final String shardName = getStringFieldValue(Item.asShardName);
final String replSetName = getStringFieldValue(Item.asReplSetName);
final int maxsize = getIntFieldValue(Item.asMaxSize);
String server = host;
- if (port > 0)
- server += ":" + port;
if (!replSetName.isEmpty())
server = replSetName + "/" + server;
@@ -135,6 +132,10 @@ public void listShards() {
new DocView(null, "List Shards", getRouterNode().getMongo().getDB("admin"), "listShards").addToTabbedDiv();
}
+ public void flushConfiguration() {
+ new DocView(null, "Flush Config", getRouterNode().getMongo().getDB("admin"), "flushRouterConfig").addToTabbedDiv();
+ }
+
public void autoBalance() {
final Mongo mongo = getRouterNode().getMongo();
final DB config = mongo.getDB("config");
View
11 src/com/edgytech/jmongobrowser/ServerNode.java
@@ -33,10 +33,11 @@ public ServerNode(Mongo mongo) {
} catch (Exception ex) {
getLogger().log(Level.SEVERE, null, ex);
}
+ label = serverAddress.toString();
markStructured();
}
- public ServerNode(ServerAddress serverAddress, MongoOptions opts) {
+ public ServerNode(ServerAddress serverAddress, MongoOptions opts, String name) {
this.serverAddress = serverAddress;
serverMongo = new Mongo(serverAddress, opts);
serverMongo.addOption( Bytes.QUERYOPTION_SLAVEOK );
@@ -46,6 +47,7 @@ public ServerNode(ServerAddress serverAddress, MongoOptions opts) {
} catch (Exception ex) {
getLogger().log(Level.SEVERE, null, ex);
}
+ label = name != null ? name : serverAddress.toString();
markStructured();
}
@@ -67,15 +69,18 @@ protected void populateChildren() {
@Override
protected void updateNode(List<ImageIcon> overlays) {
- label = serverAddress.toString();
CommandResult res = getServerMongo().getDB("local").command("serverStatus");
if (res.containsField("repl")) {
- if (((BasicDBObject) res.get("repl")).getBoolean("ismaster", false)) {
+ BasicDBObject repl = (BasicDBObject) res.get("repl");
+ if (repl.getBoolean("ismaster", false)) {
overlays.add(SwingFast.createIcon("overlay/tick_circle.png", iconGroup));
+ } else if (!repl.getBoolean("secondary", false)) {
+ overlays.add(SwingFast.createIcon("overlay/error.png", iconGroup));
}
}
if (res.containsField("dur")) {
overlays.add(SwingFast.createIcon("overlay/shield_blue.png", iconGroup));
}
+
}
}
View
68 src/com/edgytech/jmongobrowser/ServerPanel.java
@@ -14,6 +14,8 @@
import com.mongodb.ServerAddress;
import javax.swing.JPanel;
import com.edgytech.jmongobrowser.ServerPanel.Item;
+import com.mongodb.*;
+import java.util.logging.Level;
/**
*
@@ -27,16 +29,18 @@
host,
address,
maxObjectSize,
- durability,
+ journaling,
replication,
clientPorts,
serverStatus,
- replicaSetStatus,
- oplogInfo,
+ rsConfig,
+ rsStatus,
+ rsOplogInfo,
refresh,
rsStepDown,
rsFreeze,
rsFreezeTime,
+ rsRemove,
isMaster,
serverStatusCmd,
currentOps,
@@ -79,8 +83,8 @@ protected void updateComponentCustom(JPanel comp) {
DBObject svrStatus = ((DocField) getBoundUnit(Item.serverStatus)).getDoc();
boolean dur = svrStatus.containsField("dur");
- ((Text)getBoundUnit(Item.durability)).setStringValue(dur ? "On" : "Off");
- ((Text)getBoundUnit(Item.durability)).showIcon = dur;
+ ((Text)getBoundUnit(Item.journaling)).setStringValue(dur ? "On" : "Off");
+ ((Text)getBoundUnit(Item.journaling)).showIcon = dur;
} catch (Exception e) {
JMongoBrowser.instance.showError(this.getClass().getSimpleName() + " update", e);
}
@@ -89,17 +93,54 @@ protected void updateComponentCustom(JPanel comp) {
public void actionPerformed(Item enm, XmlComponentUnit unit, Object src) {
}
- public void rsStepDown() {
- DBObject cmd = new BasicDBObject("replSetStepDown", 1);
- new DocView(null, "RS Step Down", getServerNode().getServerMongo().getDB("admin"), cmd).addToTabbedDiv();
+ public void rsStepDown() {
+ final DBObject cmd = new BasicDBObject("replSetStepDown", 1);
+ final DB admin = getServerNode().getServerMongo().getDB("admin");
+
+ new DbJob() {
+
+ @Override
+ public Object doRun() {
+ Object res = null;
+ try {
+ res = admin.command(cmd);
+ } catch (MongoException.Network e) {
+ res = "Operation was likely successful, but connection error: " + e.toString();
+ }
+
+ try {
+ // sleep a bit since it takes time for driver to see change
+ Thread.sleep(6000);
+ } catch (InterruptedException ex) {
+ getLogger().log(Level.WARNING, null, ex);
+ }
+ return res;
+ }
+
+ @Override
+ public String getNS() {
+ return null;
+ }
+
+ @Override
+ public String getShortName() {
+ return "RS Step Down";
+ }
+
+ @Override
+ public Object getRoot(Object result) {
+ return cmd.toString();
+ }
+
+ }.addJob();
}
public void rsFreeze() {
int sec = getIntFieldValue(Item.rsFreezeTime);
DBObject cmd = new BasicDBObject("replSetFreeze", sec);
new DocView(null, "RS Freeze", getServerNode().getServerMongo().getDB("admin"), cmd).addToTabbedDiv();
}
-
+
public void serverStatus() {
new DocView(null, "Server Status", getServerNode().getServerMongo().getDB("admin"), "serverStatus").addToTabbedDiv();
}
@@ -108,11 +149,16 @@ public void isMaster() {
new DocView(null, "Is Master", getServerNode().getServerMongo().getDB("admin"), "isMaster").addToTabbedDiv();
}
- public void replicaSetStatus() {
+ public void rsConfig() {
+ final DBCollection col = getServerNode().getServerMongo().getDB("local").getCollection("system.replset");
+ CollectionPanel.doFind(col, null);
+ }
+
+ public void rsStatus() {
new DocView(null, "RS Status", getServerNode().getServerMongo().getDB("admin"), "replSetGetStatus").addToTabbedDiv();
}
- public void oplogInfo() {
+ public void rsOplogInfo() {
new DocView(null, "Oplog Info", MongoUtils.getReplicaSetInfo(getServerNode().getServerMongo()), "Oplog of " + getServerNode().getServerAddress(), null).addToTabbedDiv();
}

0 comments on commit 9bcd771

Please sign in to comment.