310 likes | 554 Views
Build Forge API. Yang Qian (Eric) qianyang@cn.ibm.com. Agenda. BuildForge API Overall Java API Overall Java API Example Connect to RBF ServerAuth/Server/Selector operation—Create demo Run build operation---Run/Rerun demo System setting operation—Update demo
E N D
Build Forge API Yang Qian (Eric) qianyang@cn.ibm.com
Agenda • BuildForge API Overall • Java API Overall • Java API Example • Connect to RBF • ServerAuth/Server/Selector operation—Create demo • Run build operation---Run/Rerun demo • System setting operation—Update demo • User/schedule etc operation—Delete/Search demo • FQA
BuildForge two API:Java API and Perl API • Most of the java and perl API have the same function. • Java API is the recommended API • The following example will focus on java API
Agenda • API Overall • Java API Overall • Java API Example • Connect to RBF • ServerAuth/Server/Selector operation—Create demo • Run build operation---Run/Rerun demo • System setting operation—Update demo • User/schedule etc operation—Delete/Search demo • FQA
Java API Overall • Client_Classes • For client side use • Can be divided into 3 kinds • com.buildforge.services.client.api for communication with service layer server • com.buildforge.services.client.cli for access to command line utility that are part of the RBF service layer • com.buildforge.services.client.dbo client-side implement of the database objects that are created and managed by BuildForge • Common Classes • Implement the actual DB operation/text/config • Some common utility,such as text security function,io operation
Agenda • API Overall • Java API Overall • Java API Example • Connect to RBF • ServerAuth/Server/Selector operation—Create demo • Run build operation---Run/Rerun demo • System setting operation—Update demo • User/schedule etc operation—Delete/Search demo • FQA
Java API – connect to BuildForge 1 • Prepare Env • IBMJDK 1.5 or 1.6. • Set the JAVA_HOME, PATH, CLASSPATH properly • Copy the rbf-services-client-java.jar to the proper location, such as your program location and reference it in your java project • APIClientConnection This class implements the basic interaction of an API client with the underlying connection. • SecureAPIClientConnection • is a secured subclass of the APIClientConnection class that utilizes SSL to encrypt communications between an API client and the server. • BF Console needs to enable SSL setting firstly • Bfclient.conf and keystore folder need to be copied into your program location from BF console installation location
Java API – connect to BuildForge 2 • APIClientConnection • The APIClientConnection class has three constructors: • APIClientConnection () – localhost, default port (port 3966). • APIClientConnection (java.lang.String hostname) – hostname specified, default port. • APIClientConnection (java.lang.String hostname, int port) – hostname and port specified. • code section • APIClientConnection conn = new APIClientConnection (" www.bf.com", 3967 ); • conn.authUser ("root", "passwordOfroot"); • /*conn.authUser(“zyx@www.xxx.com", "password“, “domainName" ); */
Java API – connect to BuildForge 3(Secure Conn) • SecureAPIClientConnection • The SecureAPIClientConnection class has three constructors: • SecureAPIClientConnection() – localhost, default port (port 49150). • SecureAPIClientConnection(java.lang.String hostname) – hostname specified, default port. • SecureAPIClientConnection(java.lang.String hostname, int port) – hostname and port specified. • code seciton • SecureAPIClientConnection conn = new SecureAPIClientConnection (" www.bf.com", 49150 ); • conn.authUser ("root", "passwordOfroot"); • or conn.authUser(“zyx@www.xxx.com", "password“, “domainName" ); • use the SecureAPIClientConnection demo (24712)
ServerAuth/Server/Selector operation—Create demo 1 • You can create serverAuth/server/selector dynamically, then use them, after the job is passed, delete them. This is very useful when you run jobs on VM, which is created dynamically • ServerAuth • setUsername(java.lang.String username) • setPasswordAsClearText(java.lang.String clearText) • Server setPath(java.lang.String path) setName(java.lang.String name) setAuthUuid(java.lang.String authUuid) • Selector/SelectorProperty SelectorProperty (APIClientConnection conn, Selector newParent)
ServerAuth/Server/Selector operation—Create demo 2(ServerAuth) • import com.buildforge.services.client.dbo.ServerAuth; • ServerAuth sa = new ServerAuth(conn); • sa.setLevel(6); //6 is the build engireer access group • sa.setName(name); • sa.setUsername("TEST_USER"); • sa. setPasswordAsClearText( "password"); • sa.setAuthId(name);
ServerAuth/Server/Selector operation—Create demo 3(Server) • import com.buildforge.services.client.dbo.Server; • String saUuid = sa.getUuid(); • Server s = new Server(conn); • s.setName(SERVER_NAME_1); • s.setHost("localhost"); • s.setLevel(TestConstants.DEFAULT_LEVEL); • s.setMaxJobs(1); • s.setPath("C:\\builds"); • s.setPublish(Publish.NONE); • s.setRefreshTime(30000); • s.setCollectorUuid(null); • s.setEnvironmentUuid(null); • s.setAuthUuid(saUuid); • s.create();
ServerAuth/Server/Selector operation—Create demo 4(Selector) import com.buildforge.services.client.dbo.Selector; import com.buildforge.services.client.dbo.SelectorProperty; import com.buildforge.services.common.dbo.SelectorPropertyDBO.Operator; Selector selector = new Selector(conn); selector.setName(“TEST_SELECTOR_1); selector.setLevel(6); //6 stands for build engineer group SelectorProperty selectorProperty = new SelectorProperty(conn, selector); selectorProperty.setPropertyName("BF_NAME"); selectorProperty.setPropertyValue (“ServerName"); selectorProperty.setOperator(Operator.EQ); selectorProperty.setRequired(true); selector.addProperty(selectorProperty); selector = selector.create();
Run build operation---Run/Rerun demo 1 • Project class • You can start a build by project.fire(), which likes UI quick start function • fire() Creates a new build of this project. • Build.Request • This is recommended class to fire build. You can update the buildclass, Selector,Tag,runLink,buildEnv • Need to relate with build for complete the build fire • Build • fire(APIClientConnection conn, java.lang.String projectUuid) • fire(Build.Request req) • fire(Build.Request req, int timeout) • fire(Build.Request req, int timeout, int interval) • reprepareBuild(Build.Request req)
Run build operation---Run/Rerun demo 2 (Project Class) • Project class to fire a build Project project = Project.findByName(conn, name); • if( project == null){ • System.out.println(" can't find project:"+name); • System.exit(-1); • } • Build build = project.fire();
Run build operation---Run/Rerun demo 3(Build.Request) • Build.Request • privatestaticfinal String NEW_TAG = • "TESTING REP TAG"; • Project project = Project.findByName(conn, name); • if( project == null){ • System.out.println(" can't find project:"+name); • System.exit(-1); • } • Build.Request buildRequest = • new Build.Request(project); • buildRequest.setRunLink(false); • BuildClass buildClass = • BuildClass.findByName(conn, "Scratch"); • buildRequest.setBuildClassUuid(buildClass.getUuid()); • buildRequest.setTag(NEW_TAG); • Build build = Build.fire(buildRequest, • 60000);
Run build operation---Run/Rerun demo 3(rerun job) • privatestaticfinal String NEW_TAG = • "TESTING REP TAG"; • Project project = Project.findByName(conn, name); • if( project == null){ • System.out.println(" can't find project:"+name); • System.exit(-1); • } • List<Build> builds = Build.findByProjectUuid(conn,project.getUuid()); • Build build = builds.get(0);//make sure that build is complete • Build.Request buildRequest = • new Build.Request(project); • build = build.reprepareBuild(buildRequest);
System setting operation—Update demo 1 • SysConfig SysConfig objects represent system-wide configuration parameters that determine the global behaviour of the Build Forge system. Metadata such as the address of the license server and the port on which the management console is attached are stored in this configuration store. • findByName(APIClientConnection conn, java.lang.String parameterName) • getName() • getDescription() • setValue(java.lang.String value) • setDefaultValue(java.lang.String defaultValue) • update() • findAll(APIClientConnection conn) • If you don’t know the system parameter name, you can call findAll, then print all the system parameter name
System setting operation—Update demo 2 import com.buildforge.services.client.dbo.SysConfig; privatestaticfinal String SYS_CONFIG = "max_inline_depth"; SysConfig sysConfig = SysConfig.findByName(conn, SYS_CONFIG); originalValue = sysConfig.getValue(); sysConfig.setValue("2"); sysConfig = sysConfig.update();
User/schedule etc operation—Delete/Search demo 1 User UserfindByLogin(APIClientConnection conn, java.lang.String login) findAll(APIClientConnection conn) Schedule(Cron class) findAll(APIClientConnection conn) getNextRun() delete()
User/schedule etc operation—Delete/Search demo 2(User Class) import com.buildforge.services.client.dbo.User;; privatestaticfinal String TEST_USER_NAME = “user001"; User user = User.findByLogin(conn, TEST_USER_NAME); if(user ! = null ) { user.setTimeZone("US/Eastern"); user = user.update(); System.out.println(" Find user:"+ TEST_USER_NAME); user.delete(); System.out.println(" Delete user:"+ TEST_USER_NAME); }
User/schedule etc operation—Delete/Search demo 3(Cron Class) import com.buildforge.services.client.dbo.Cron; privatestaticfinal String CRON_NAME= “MyInstall_test_sche"; List<Cron> crons = Cron.findAll(conn); for (Cron cron : crons) { if ( cron.getDescription(). equals(CRON_NAME) ) { System.out.println(" find schedule: "+ CRON_NAME); break; } }
Notes BuildForge has 3 type users 7.1.3.x Normal API only (this type cannot access the console using a web client. However, users of that type can have more than one login session. Session information is shared automatically between sessions) Read-Only