Skip to content

Instantly share code, notes, and snippets.

@ahgittin
Created October 9, 2012 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ahgittin/3858972 to your computer and use it in GitHub Desktop.
Save ahgittin/3858972 to your computer and use it in GitHub Desktop.
BrooklynServerDetails details = BrooklynLauncher.newLauncher().
// to add a custom webapp
webapp("/cdh", "classpath://brooklyn-cdh-frontend.war").
webconsolePort(CommandLineUtil.getCommandLineOption(args, "--port", "8081+")).
launch();
// then things below linked to buttons / etc in app
// get the mgmt context (and also the webconsole URL) from this details container
ManagementContext mgmt;
mgmt = details.getManagementContext();
// or in a webapp access it as:
// javax.servlet.ServletContext ctx = null; // get the javax.servlet.ServletContext
// mgmt = ctx.getAttribute(BrooklynServiceAttributes.BROOKLYN_MANAGEMENT_CONTEXT);
String cloudCode = "aws-ec2"; // jclouds name of cloud (these are available programmatically)
String cloudSpecifier = "us-west-1"; // location, or endpoint in the case of openstack, vcloud, etc
String cloudName = cloudCode+":"+cloudSpecifier;
// to set cloud credentials (needed to roll-out the application)
((BrooklynProperties)mgmt.getConfig()).put("brooklyn.jclouds."+cloudCode+".identity", "IDENTITY");
((BrooklynProperties)mgmt.getConfig()).put("brooklyn.jclouds."+cloudCode+".credential", "CREDENTIAL");
// another way to set cloud credentials:
// for more info (including fixed machines) see:
// https://github.com/brooklyncentral/brooklyn/blob/master/docs/use/guide/defining-applications/common-usage.md#off-the-shelf-locations
String namedLocation = "locationForApp1";
((BrooklynProperties)mgmt.getConfig()).putAll([
("brooklyn.location.named."+namedLocation): "jclouds:"+cloudName,
("brooklyn.location.named."+namedLocation+".identity"): "MyID",
("brooklyn.location.named."+namedLocation+".credential"): "MyCredential",
// can also set advanced properties, e.g. private key file to use, passphrase on private key,
// minRam, or imageId to use a specific VM image
("brooklyn.location.named."+namedLocation+".minRam"): 2048,
// (BTW you may want to generate a private key file to use, in case users don't have one set up)
]);
SampleClouderaManagedCluster app1 = new SampleClouderaManagedCluster(name:'Brooklyn Cloudera Managed Cluster');
details.getManagementContext().manage(app1);
SampleClouderaManagedCluster app2 = new SampleClouderaManagedCluster(name:'Brooklyn Cloudera Managed Cluster');
details.getManagementContext().manage(app2);
List<Location> locations = new LocationRegistry().getLocationsById([
cloudName
// or:
// "named:"+namedLocation
]);
// to start app (NB this call is synchronous, takes about 10m to return)
app1.start(locations);
// meanwhile to track events / give feedback
// - could capture log info (add log4j listener)
// - plug in to BasicExecutionManager API
// - could annotate classes to provide specific info (your own listener)
// to find out the CDH endpoint
System.out.println("CDH Manager running at: "+app1.whirrCM.getAttribute(WhirrClusterManager.CLOUDERA_MANAGER_URL);
// to collect metrics (again, synchronous)
String directory = app1.services.collectMetrics();
System.out.println("Metrics stored in: "+directory);
// to stop:
app1.stop();
// can also start multiple apps...
// app2.start(locations);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment