Thursday, 30 October 2014

Automatic graph layout with javascript (JsPlumb, jQuery and Dagre)

This post solves the limitation of JsPlumb graph layout by integrating with Dagre.

First, I assume that you assign an ID (which is supposed to be unique) to each node in your JsPlumb graph and a class "node" and JsPlumb graph are already created and you want to add automatic layout to that graph.

Now you can get all the nodes with jQuery as follows:
var nodes = $(".node");
And you can get all edges using your JsPlum instance using:
var edges = inst.getAllConnections();
With nodes and edges, you have everything you need to use dagre. Here's the simple code to layout your graph:
// construct dagre graph from JsPlumb graph
var g = new dagre.graphlib.Graph();
g.setGraph({});
g.setDefaultEdgeLabel(function() { return {}; });

var nodes = $(".node");
for (var i = 0; i < nodes.length; i++) {
    var n = nodes[i];
    g.setNode(n.id, {width: n.width(), height: n.height()});
}
var edges = inst.getAllConnections();
for (var i = 0; i < edges.length; i++) {
    var c = edges[i];
    g.setEdge(c.source.id,c.target.id );
}
// calculate the layout (i.e. node positions)
dagre.layout(g);

// Applying the calculated layoutg.nodes().forEach(function(v) {
    $("#" + v).css("left", g.node(v).x + "px");
    $("#" + v).css("top", g.node(v).y + "px");
})
You can put the above code in a function (i.e. layout(nodes, jsPlumbInst)) to apply to any jsPlumb graph.

Thanks to Yuri Gor for creating a live demo at https://codepen.io/yurigor/pen/vXYomB

Monday, 1 September 2014

DB2 10 certification prepration guides (Fundamentals[610] and DBA[611])

There are multiple sources to prepare for DB2 certification. The most comprehensive guides will the IBM official guides. Both -the Fundamentals and DBA are publicly available.

The quick and fast developer works tutorials are also good for your preparations though they don't all the details for the beginners. The starters should seek the comprehensive guides to get all the details. The full series for exam 610 and 611 can be found at IBM developer works site for Fundamentals and DBA certifications.


Reset DB2 Automatic client Reroute (alternate server)

Although automatic client reroute is good at solving some problems it can become an evil with some of the limitations is has. In case you faced that evil face and want to reset it back, you may use the following command:


db2 update alternate server for db using hostname NULL port NULL

Configuring DB2 HADR with Zero downtime

A few weeks ago I setup DB2 HADR for a large bank and they wanted the setup to be in the minimal downtime.Traditionally, I have been implementing this using offline backups. Using offline backups will make the system offline for a certain period that vary based on you database size. The new challenge was to make it with the minimal or no downtime. I thought online backup would require certain workarounds or tweaks and might not work. However, it worked like a charm and very straightforward.

Here are the steps I followed to make the implementation in zero down time:
  1. Take full online backup from the primary DB.
  2. Restore the backup on the standby server.
  3. Change HADR configuration parameters for the standby machine.
  4. [OPTIONAL -for 9.7.1 or higher] enable read on standby on the standby machine.
  5. Configure HADR parameters on the primary database.
  6. Start HADR on the standby machine as standby.
  7. Start HADR on the primary database as primary.
You need not to do any roll-forward commands on the standby database. HADR will take case of transferring all the delta logs from the primary to the standby.

A common pitfall would be the HADR ports are not open or blocked by the firewall. So, please make sure you communicate these ports to your network administrator.