Developer's manual V2.0

From OneCMDB

Contents

OneCMDB Source Code

Niklas editerar

When installing OneCMDB the source code is placed in the installation directory in the directory /src.
The source code will soon be available from CVS at Sourceforge.

Building

OneCMDB is built using Ant.
Building scripts will be available from CVS at Sourceforge.

Programming OneCMDB

The Java API available to program against OneCMDB Core is described in the following document: Core Java API V2

The Webservices interface is described in this document: Web Services V2. Please note that this document is currently being updated.

SQL Database

OneCMDB Single user edition uses HSQLDB. Currently the connection to the database is locked by the thread doing a query, limiting multi-usage. This limitation will be removed in the forthcoming OneCMDB Team Edition.

Database Schema

See Database Schema.

Supported Databases

Besides HSQLDB, OneCMDB runs with MYSQL, MS SQL Server and PostgreSQL.

Configuring the Database to use

You configure what database to use in the following configuration file:

<onecmdb_install_dir>/tomcat-5.5.17/webapps/ROOT/WEB-INF/classes/datasource.xml

HSQLDB

HSQLDB is used default, so the HSQLDB driver is included in the distribution.
For HSQLDB the datasource.xml should contain the following:

<bean id="dataSource"
		class="org.onecmdb.core.internal.storage.DataSourceWrapper"
		destroy-method="close" >
		<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
		<property name="url" value="jdbc:hsqldb:hsql://localhost" />
		<property name="username" value="sa" />
		<property name="password" value="" />
		
		<property name="initialSize" value="0" />
		<property name="maxActive" value="8" />
		<property name="minIdle" value="0" />
		<property name="maxIdle" value="8" />

		<property name="connectionProperties">
			<props>
				<prop key="shutdown">false</prop>
			</props>
		</property>
</bean>
<bean id="hibernateProperties" class="org.onecmdb.core.internal.storage.HibernateProperty">
		<property name="properties">
			<props>
				<prop key="hibernate.dialect">org.onecmdb.core.internal.storage.hibernate.hsql.HypersonicSQL18Dialect</prop>
				<prop key="show_sql">true</prop>
				<prop key="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
				<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
			</props>
		</property>
	</bean>

MySQL

For MySQL a jar containing the driver needs to be uploded to

<onecmdb_install_dir>/tomcat-5.5.17/webapps/ROOT/WEB-INF/lib

The MySQL driver can be found here:
http://dev.mysql.com/downloads/connector/j/5.1.html

The datasource.xml should contain the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE 
	beans PUBLIC "-//SPRING//DTD BEAN//EN" 
	"http://www.springframework.org/dtd/spring-beans.dtd">

<!-- 
	Definition of the datasource.
	Need to specify the folowing beans:
		dataSource - defines driver/url/user/pwd
		hibernateProperties - defines the db dialect
		shutdownDb - true if hsql in process else false.

 -->
 
<beans default-dependency-check="none">
	<bean id="dataSource"
		class="org.onecmdb.core.internal.storage.DataSourceWrapper"
		destroy-method="close" >
		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
		<property name="url" value="jdbc:mysql://localhost/onecmdb" />
		<property name="username" value="root" />
		<property name="password" value="" />
		
		<property name="initialSize" value="0" />
		<property name="maxActive" value="8" />
		<property name="minIdle" value="0" />
		<property name="maxIdle" value="8" />

		<property name="connectionProperties">
			<props>
				<prop key="shutdown">false</prop>
			</props>
		</property>
	</bean>
	<bean id="hibernateProperties" class="org.onecmdb.core.internal.storage.HibernateProperty">
		<property name="properties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
				<prop key="show_sql">true</prop>
				<prop key="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
				<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
			</props>
		</property>
	</bean>
</beans>

This assumes that MySQL database is running on the same machine (localhost) with a created database called onecmdb.

MS SQL

For MS SQL a jar containing the driver needs to be uploded to

<onecmdb_install_dir>/tomcat-5.5.17/webapps/ROOT/WEB-INF/lib

The datasource.xml should contain the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE 
	beans PUBLIC "-//SPRING//DTD BEAN//EN" 
	"http://www.springframework.org/dtd/spring-beans.dtd">

<!-- 
	Definition of the datasource.
	Need to specify the folowing beans:
		dataSource - defines driver/url/user/pwd
		hibernateProperties - defines the db dialect
		shutdownDb - true if hsql in process else false.

 -->
 
<beans default-dependency-check="none">


	<bean id="dataSource"
	class="org.apache.commons.dbcp.BasicDataSource"
	destroy-method="close">
		<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
		<property name="url" value="jdbc:sqlserver://localhost:1340;databaseName=onecmdb" />
		<property name="username" value="sa" />
		<property name="password" value="1qaz1qaz" />
		
		<property name="initialSize">
			<value>5</value>
		</property>
	</bean>
	
	<bean id="hibernateProperties" class="org.onecmdb.core.internal.storage.HibernateProperty">
		<property name="properties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.SQLServerDialect
				</prop>
				<prop key="show_sql">false</prop>
					
				<prop key="transaction.factory_class">
					org.hibernate.transaction.JDBCTransactionFactory
				</prop>
					
				<prop key="hibernate.cache.provider_class">
					org.hibernate.cache.HashtableCacheProvider
				</prop>
					
				<prop key="hibernate.hbm2ddl.auto">
					update
				</prop>
			</props>
		</property>
	</bean>
</beans>

This assumes that MS SQL database is running on the same machine (localhost) with a created database called onecmdb.

PostgreSQL

For PostgreSQL a jar containing the driver needs to be uploded to

<onecmdb_install_dir>/tomcat-5.5.17/webapps/ROOT/WEB-INF/lib

The datasource.xml should contain the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE 
	beans PUBLIC "-//SPRING//DTD BEAN//EN" 
	"http://www.springframework.org/dtd/spring-beans.dtd">

<!-- ==================== datasource.xml =========================  -->
<!--	                                                            -->
<!--	Definition of the data source to be used by OneCMDB         -->
<!--	                                                            -->
<!--	The following beans are used:                               -->
<!--	                                                            -->
<!--	  dataSource            defines driver/url/user/pwd         -->
<!--	  hibernateProperties   defines the database dialect        -->
<!--	                                                            -->
<beans default-dependency-check="none">

	<bean id="dataSource" 
		class="org.onecmdb.core.internal.storage.DataSourceWrapper"
		destroy-method="close" >
		<property name="driverClassName" value="org.postgresql.Driver" />
		<property name="url"
			value="jdbc:postgresql://localhost/onecmdb" />
		<property name="username" value="postgres" />
		<property name="password" value="xxxxxx" />
		<property name="initialSize">
			<value>5</value>
		</property>
	
		<property name="connectionProperties">
			<props>
				<prop key="shutdown">false</prop>
			</props>
		</property>
	</bean>

	<!--  Hibernate configuration taking the 'dataSoure' defintion  -->
	<!--  in account, specifically the dialect to use.              -->
	<!--                                                            -->
	<bean id="hibernateProperties" class="org.onecmdb.core.internal.storage.HibernateProperty">
		<property name="properties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
				<prop key="show_sql">true</prop>
				<prop key="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
				<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
				<prop key="hibernate.jdbc.batch_size">20</prop>
			</props>
		</property>
	</bean>
</beans>

This assumes that PostgreSQL database is running on the same machine (localhost) with a created database called onecmdb.

Oracle

For Oracle a jar containing the jdbc driver needs to be uploded to

<onecmdb_install_dir>/tomcat-5.5.17/webapps/ROOT/WEB-INF/lib

The datasource.xml should contain the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE 
	beans PUBLIC "-//SPRING//DTD BEAN//EN" 
	"http://www.springframework.org/dtd/spring-beans.dtd">

<!-- 
	Definition of the datasource.
	Need to specify the folowing beans:
		dataSource - defines driver/url/user/pwd
		hibernateProperties - defines the db dialect
		

 -->
 
<beans default-dependency-check="none">


	<bean id="dataSource"
		class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
		<property name="url"
			value="jdbc:oracle:thin:@localhost:1521:XE" />
		<property name="username" value="system" />
		<property name="password" value="xxxxxx" />
		<property name="initialSize">
			<value>5</value>
		</property>
	</bean>
	
	<bean id="hibernateProperties" class="org.onecmdb.core.internal.storage.HibernateProperty">
		<property name="properties">
				<props>
					<prop key="hibernate.dialect">
						 org.hibernate.dialect.OracleDialect
					</prop>
					<prop key="show_sql">false</prop>
					
					<prop key="transaction.factory_class">
						org.hibernate.transaction.JDBCTransactionFactory
					</prop>
					
					<prop key="hibernate.cache.provider_class">						
						org.hibernate.cache.HashtableCacheProvider
					</prop>
					
					<prop key="hibernate.hbm2ddl.auto">
						update
					</prop>
					<prop key="hibernate.jdbc.batch_size">20</prop>

					
				</props>
		</property>
	</bean>
</beans>
<pre>

===Performance Enhancements: Creating database indexes===

 
Follow this procedure to improve <b>HSQLDB</b> performance:<br><br>
For Windows:
#Move to HSQL installation directory: ''<onecmdb_install_dir>/hsqldb-1.8.0.4/demo''
#Run ''runManagerSwing.bat''
#Select Type: HSQL Database Engine Server
#Press OK
#Open Script <onecmdb_install_dir>/etc/create-index-hsql.sql
#Press Execute.
For Linux:
#Move to <onecmdb_install_dir> 
#Run ''jre/bin/java -jar hsqldb/lib/hsqldb.jar --rcFile etc/sqltool.rc onecmdb etc/create-index-hsql.sql''
<br>
Follow this procedure to improve <b>MySQL</b> performance (Assume that the mysql is running on the same host):<br>
# Move to <onecmdb_install_dir>
# Run ''mysql -u root -p -h localhost --database "onecmdb_dbname" <etc/create-index.sql''

==The CMDB Model==
The CMDB model to use is specified by one or several files containing the definition of the datamodel in XML.

===Configuring the model to use at startup===
OneCMDB will check whether model file(s) are previously read or not when it starts. If not, it loads the model file(s and inject entries into the database. The configuration file pointing out the model file is:<br>
<pre>
<onecmdb_install_dir>/tomcat-5.5.17/webapps/ROOT/WEB-INF/classes/provider.xml

In the file you find the following setting:

<beans default-dependency-check="none">
	<bean id="defaultProvider" class="org.onecmdb.core.utils.xml.XmlParser">
		<property name="URLs">
			<list>
				<!-- The datacenter schema -->
				<value>res:Model.xml</value>
			</list>
		</property>
	</bean>
</beans>

The Model Replacy Utility writes new content in the Model.xml file.

The default model we currently provide includes both templates and instances. If you prefer you may split it into two or more files in your production environment. Then you need two list entries in provider.xml, one for the template file and one for the instance file. Note however that this will cause the Model Replace Utility to malfunction.

Path to the model file is:

<onecmdb_install_dir>/tomcat-5.5.17/webapps/ROOT/WEB-INF/classes/Model.xml

The XML description

To be added.

Available models

The Models sections contains descriptions of the different CMDB models available.

OneCMDB GUI Configuration

Setting browsing start point for GUI User mode

The OneCMDB GUI web application needs a instance define as "start point" for browsing in user mode. Else the GUI get the ROOT template as start point. You set the start point in following file:

<onecmdb_install_dir>/tomcat-5.5.17/webapps/ROOT/WEB-INF/classes/onecmdb-servlet.xml<br><br>

See following section in the file:

<bean name="/index.mvc" class="org.onecmdb.web.SiteController"
		init-method="init">
		<property name="commandClass"><value>org.onecmdb.web.SiteCommand</value></property>
		<property name="commandName"><value>site</value></property>
		<property name="bindOnNewForm" value="true" />
		<property name="siteView" value="site" />
		<property name="sessionForm" value="true" />
		<property name="oneCmdb"><ref parent="onecmdb"/></property>
		<-- initial objects -->
		<property name="dataCenter" value="Root/Ci/Folder/DataCenterFolder/DataCenter" />
		<property name="refsBase"  value="Root/Reference/MyDataCenterRef" />
		<property name="templateBase"  value="Root/Ci" />
</bean>
Community and support