The UMM API allows you to programmatically create and store application configurations in the UMM database. The UMM GUI uses the same API to create users, passwords, applications configurations and configuration templates. See UMM Java API for UMM objects, constructors and methods.
Programs that create application XML configurations store them in the UMM Configuration Database as shown in the diagram, Architecture for Programming Application Configurations. The UMM Daemon serves the XML configuration to UM applications.
The following sample code provides a framework for creating an application configuration, test_application with two templates. template_1 sets the file descriptor type option for a UM context. template_2 sets the resolver multicast address and port. Use of the application configuration is also authenticated with a username and password.
See <templates> and <applications> in the UM Configuration Guide for more information about XML configuration elements. See also Creating Configuration Templates and Creating Application Configurations for information on creating templates and application configurations using the UMM GUI.
package umm.api; import java.io.CharArrayReader; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.xml.sax.InputSource; import umm.api.NameValue; import umm.api.UMMAPI; import umm.api.util.DOMUtil; import umm.api.util.Util; public class Example { String test_application = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<application name=\"test_application\" template=\"\">\n" + " <contexts order=\"deny,allow\">\n" + "<context rule=\"allow\" template=\"\">\n" + "<sources order=\"deny,allow\"/>\n" + " <receivers order=\"deny,allow\"/>\n" + "<wildcard-receivers order=\"deny,allow\"/>\n" + " </context>\n" + " </contexts>\n" + "<event-queues order=\"deny,allow\">\n" + " <event-queue rule=\"allow\"/>\n" + "</event-queues>\n" + "</application>"; String template_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<template name=\"template_1\">\n" + "<options type=\"context\">\n" + "<option default-value=\"epoll\" name=\"fd_management_type\"/>\n" + "</options>\n" + "</template>"; String template_2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<template name=\"template_2\">\n" + "<options type=\"context\">\n" + "<option default-value=\"224.9.10.11\" name=\"resolver_multicast_address\"/>\n" + "<option default-value=\"12965\" name=\"resolver_multicast_port\"/>\n" + "</options>\n" + "</template>"; UMMAPI api; private void init(String machine, int port) throws Exception { //Create the UMMPI object. The constructor takes a machine name and port //which are used to connect to the UMM Daemon. api = new UMMAPI(machine, port); System.out.println("Init Success"); } private void login(String userName, String password) throws Exception { //Logon to the UMM system. The login method must be called with a valid username //and password. The login user must be a UMM administrative user. if (api.login(userName, password)) { System.out.println("login Success"); return; } System.out.println("login Failure"); System.exit(-1); } public Example(String args[]) { try { String machine = args[0]; int port = Integer.parseInt(args[1]); String userName = args[2]; String password = args[3]; init(machine, port); //Connect to the UMM daemon login(userName, password); //Login to the daemon. ArrayList<NameValue> templateList = new ArrayList(); // Need a list of templates to assign to the Application. NameValue nv = api.saveTemplate("template_1", template_1); if (nv == null) { System.out.println("saveTemplate Failure"); System.exit(-1); } templateList.add(nv); nv = api.saveTemplate("template_2", template_2); if (nv == null) { System.out.println("saveTemplate Failure"); System.exit(-1); } templateList.add(nv); String xml = setTemplateXML(templateList, test_application); if (xml == null) { System.out.println("setTemplateXML Failure"); System.exit(-1); } //The template names must be set in the xml. if (api.saveApplication("test_application", xml) == null) { System.out.println("saveApplication Failure"); System.exit(-1); } //The template names must be set in the Database. if (api.setTemplates("test_application", templateList) == false) { System.out.println("setTemplates Failure"); System.exit(-1); } System.out.println("##############################################"); System.out.println(api.getConfig("test_application")); } catch (Exception ex) { Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex); } api.logOff(); } private String setTemplateXML(ArrayList<NameValue> list, String xml) { try { StringBuilder sb = new StringBuilder(); //Build the template name string. for (NameValue nv : list) { sb.append(nv.getName() + ","); } // Remove the last "," if (sb.length() > 0) { sb.delete(sb.length() - 1, sb.length()); } //Create a DOM document. CharArrayReader characterStream = new CharArrayReader(xml.toCharArray()); InputSource is = new InputSource(characterStream); Document document = DOMUtil.createDocument(is); Node node = (Node) document.getDocumentElement(); //Find the correct node to add the templates to. node = DOMUtil.findNode("contexts", node); if (node == null) { System.out.println("No contexts node"); return null; } node = DOMUtil.findNode("context", node); if (node == null) { System.out.println("No context node"); return null; } if (node.getAttributes().getNamedItem("template") != null) { node.getAttributes().getNamedItem("template").setNodeValue(sb.toString()); return DOMUtil.getXML(document); } } catch (Exception ex) { ex.printStackTrace(); } return null; } public static void main(String args[]) { new Example(args); System.exit(0); } }
Copyright (c) 2004 - 2014 Informatica Corporation. All rights reserved.