[jboss-as7-dev] Detyped API document feedback

Brian Stansberry brian.stansberry at redhat.com
Wed Jan 5 00:46:00 EST 2011


On 1/4/11 11:02 AM, David M. Lloyd wrote:

> I'd rather do something more dynamic where you can start with a node and
> just build up whatever you want from it:
>
> node = new ModelNode();
> node.get("operation").set("change-bind-port"); // string
> node.get("address").add("base, "domain"); // a list
> node.get("address").add("profile", "web");
> node.get("address").add("subsystem", "web");
> node.get("address").add("connector", "ssl");
> node.get("bind-port").set(8433); // int
> result = connection.execute(node); // goes over remoting
> System.out.println("Result is: " + result);
> // nicely formatted, JSON-style (but with more possible types)
>
> I wipped up a demo of this style of API at:
> https://github.com/dmlloyd/jboss-dmr
>
> Notice there's only one public class and one type enum.  (The Validation
> class isn't anything, just an experiment.)
>

The add(String, String) method isn't there; just set(String, ModelNode). 
That would be ok if there were overloaded ModelNode constructors to 
match the set() methods, allowing you to create a model node, set it's 
value and pass it as a method parameter all in one line:

node.get("address").add().set("base", new ModelNode("domain"));

A whole bunch of overloaded variants (set(String, String), set(String, 
boolean), set(String, int) etc) would accomplish the same thing.

I played at creating a couple "update plans" (pretty much like the 
Alpha1 deployment plans) and it was pretty painless, except for the 
minor nit above:

// We're going to create a composite update for this plan
ModelNode composite = planA.get("operation");
// First, add previously uploaded content to the domain
ModelNode first = composite.get("operations").add();
first.get("operation").set("addDeployment");
// Having to set values of type PROPERTY this way is not so nice
first.get("address").add().set("base", new ModelNode());
first.get("address").get(0).get("base").set("domain");
first.get("uniqueName").set("foo.war");
first.get("hash").set(new byte[20]); // pretend the hash came from elsewhere
// Next, include it with a server group's list of deployments
ModelNode second = composite.get("operations").add();
second.get("operation").set("addDeployment");
second.get("address").add().set("base", new ModelNode());
second.get("address").get(0).get("base").set("domain");
second.get("address").add().set("server-group", new ModelNode());
second.get("address").get(1).get("server-group").set("groupA");
second.get("uniqueName").set("foo.war");
second.get("start").set(true);
// Third operation is to replace previously existing "bar.ear" across
// the domain with new content previously uploaded
ModelNode third = composite.get("operations").add();
third.get("operation").set("fullyReplaceDeployment");
third.get("address").add().set("base", new ModelNode());
third.get("address").get(0).get("base").set("domain");
third.get("uniqueName").set("bar.ear");
third.get("hash").set(new byte[20]);

// Next create lists of lists for how to roll out. Inner lists
// are rolled out concurrently; outer lists are done in series
ModelNode serverGroupPlans = planA.get("serverGroups");
ModelNode groupAPlan = serverGroupPlans.add().add();
groupAPlan.get("server-group").set("groupA");
groupAPlan.get("rollingToServers").set(true);
groupAPlan.get("maxFailurePercentage").set(20);
ModelNode groupBPlan = serverGroupPlans.get(0).add();
groupBPlan.get("server-group").set("groupB");
groupBPlan.get("rollingToServers").set(false);
groupBPlan.get("maxFailedServers").set(1);

ModelNode groupCPlan = serverGroupPlans.add().add();
groupCPlan.get("server-group").set("groupC");
groupBPlan.get("rollbackAcrossServers").set(false);
// We're going to re-use serverGroupPlans, so lock it down
serverGroupPlans.protect();

// If application to groupA, B or C fail, don't rollback the others
planA.get("rollbackAcrossGroups").set(false);


// A simple single update plan
ModelNode planB = new ModelNode();
ModelNode operation = planB.get("operation");
operation.get("operation").set("setCoreThreads");
operation.get("address").add().set("base", new ModelNode());
operation.get("address").get(0).get("base").set("domain");
operation.get("address").add().set("profile", new ModelNode());
operation.get("address").get(1).get("profile").set("production");
operation.get("address").add().set("subsystem", new ModelNode());
operation.get("address").get(2).get("subsystem").set("threads");
operation.get("address").add().set("bounded-queue-thread-pool", new 
ModelNode());
operation.get("address").get(2).get("bounded-queue-thread-pool").set("pool1");
operation.get("count").set(0);
operation.get("per-cpu").set(20);
// We'll reuse the server-group rollout plans from above
planB.get("serverGroups").set(serverGroupPlans);


-- 
Brian Stansberry
Principal Software Engineer
JBoss by Red Hat



More information about the jboss-as7-dev mailing list