Project

General

Profile

Sample-DB-worker-node » History » Revision 3

Revision 2 (Udo Offermann, 02.04.2013 14:56) → Revision 3/19 (Udo Offermann, 03.04.2013 16:04)

h1. Sample DB Worker DBWorker Node 

 This sample illustrates the usage of the [[DB_Worker_Node_Add-on]] and thereby how easy it is to setup a all-in-one-system comprising the z2 environment and the database. The sample web-application has a very simple database schema containing one table with a primary key and a varchar column while the UI provides just the basic CRUD actions. 

 The sample is provided via the repository "z2-samples-dbworker":http://redmine.z2-environment.net/projects/z2-samples/repository/z2-samples-dbworker. 

 h2. Prerequisites 

 All you need is a JDK 6 distribution as described in [[Step_2_-_Install_and_run_in_5_minutes]].  

 h2. Setting up the sample 

 There This sample is no further pre-requisite to running this sample, and you may proceed as described in run like all samples, that is, following [[How to run a sample]]. Here's 

 Assuming everything (including the really fast version: z2 core and dbworker sample) is under *install* and your workspace is in *install/workspace* please import the following    projects into your workspace: _core_ from z2-base.core, _environemnt_ and _com.zfabrik.samples.dbworker.webapp_ from z2-samples.dbworker.  

 *Note:* if the h2 driver jar is not found, please switch the core to branch _master_. 

 <pre><code class="ruby"> 
 mkdir install 
 cd install  
 git clone -b master http://git.z2-environment.net/z2-base.core 
 git clone -b master http://git.z2-environment.net/z2-samples.dbworker h2. Running the sample 

 # on Linux / Mac OS: 
 cd z2-base.core/run/bin 
 ./gui.sh 

 # on Windows: 
 cd z2-base.core\run\bin 
 gui.bat 
 </code></pre> 

 h3. Starting Z2.  

 Use the Eclipse launcher or start from the command line. The first time you launch the sample this will take a while. short moment. Watch the log output and keep an eye out for the following lines: 
 <pre> 
 4/03 15:50:52 [33]...ment/h2Worker@0.2 04/02 14:43:22 [51]...ment/dbWorker@0.1 [800]: 04/03 15:50:52 [1]...2DatabaseLauncher [800]: H2 TCP Server running Listening for transport dt_socket at tcp://192.168.178.28:9092 (only local connections allowed) address: 5100 
 04/03 15:50:52 [32]...ment/h2Worker@0.1 04/02 14:43:22 [52]...ment/dbWorker@0.2 [800]: SQLState(90028) vendor code(90028) 04/02 14:43:22 [1]...stemStateResource [800]: Attained system state: com.zfabrik.boot.main/bootrepo_up 
 04/03 15:50:52 [33]...ment/h2Worker@0.2 04/02 14:43:22 [52]...ment/dbWorker@0.2 [800]: 04/03 15:50:52 [1]...2DatabaseLauncher 04/02 14:43:22 [1]...stemStateResource [800]: Attained system state: com.zfabrik.boot.main/sysrepo_up 
 04/02 14:43:22 [52]...ment/dbWorker@0.2 [800]: 04/02 14:43:22 [1]...stemStateResource [800]: Attained system state: com.zfabrik.boot.main/process_up 
 04/02 14:43:22 [52]...ment/dbWorker@0.2 [800]: 04/02 14:43:22 [1]...stemStateResource [800]: Attained system state: com.zfabrik.boot.main/worker_up 
 04/02 14:43:22 [52]...ment/dbWorker@0.2 [800]: 04/02 14:43:22 [1]....db.h2.H2Database [800]: Starting H2 server... 
 04/02 14:43:22 [52]...ment/dbWorker@0.2 [800]: 04/02 14:43:22 [1]....db.h2.H2Database [800]: H2 Console Server running at http://192.168.178.28:8082 (only local connections allowed) 
 04/03 15:50:52 [33]...ment/h2Worker@0.2 [800]: 04/03 15:50:52 [1]...stemStateResource [800]: Attained system state: com.zfabrik.db.environment/h2WorkerUp 
 04/03 15:50:52 [33]...ment/h2Worker@0.2 [800]: 04/03 15:50:52 [1]...worker.WorkerSoul [800]: Completed worker process initialization 
 </pre> 

 If you want to inspect the code using Eclipse, please create a workspace in install (i.e. @install/workspace@) and import the Git repositories and the following    projects into your workspace: _core_ from z2-base.core, _environemnt_ and _com.zfabrik.samples.dbworker.webapp_ from z2-samples.dbworker (see also [[Step_3_-_First_steps_with_Z2_on_Git|First steps]]). 

 *Note:* if the h2 driver jar is not found, please switch the core to branch _master_. 

 h3. Run the sample app 

 run http://localhost:8080/dbworker_sample and play around with the UI. You can create new entries, modify and update existing entries by clicking inside the name column and delete entries. The sample application itself is not that tricky. It uses the JDBC API in order to create the schema on demand as well as to implement the CRUD operations. A single jsp file provides the UI.  

 h2. How can I use by myself? 

 The *environment* project module of the sample "dbworker sample":http://redmine.z2-environment.net/projects/z2-samples/repository/z2-samples-dbworker/revisions/master/show/environment contains the important pieces: The z2 repository component @dbWorkerAddon.properties@ makes the DB Worker Node Add-on available pieces. [[DB_Worker_Node_Add-on]] lists all environment components that you have to the z2-Environment. Furthermore the _home layout_ defined change or add in @home.properties@ launches the database worker in addition order to configure the web worker: 

 <pre> 
 com.zfabrik.component.type=com.zfabrik.homeLayout 
 home.workers = com.zfabrik.db.environment/h2Worker, environment/webWorker 
 </pre> 

 Note that @com.zfabrik.db.environment/h2Worker@ precedes @environment/webWorker@ so that the DB is up and running when before the web applications are started. 


 worker node feature.