Jump to: navigation, search

Difference between revisions of "Gyrex/Developer Guide/Roles"

m (Example)
Line 14: Line 14:
 
The following Example defines a role "My Server Role".
 
The following Example defines a role "My Server Role".
 
<source lang="xml">
 
<source lang="xml">
<role id="com.abc.my.role" name="My Server Role">
+
<extension point="org.eclipse.gyrex.server.roles">
 +
  <role id="com.abc.my.role" name="My Server Role">
 
     <requireBundle symbolicName="com.abc.thridparty" />
 
     <requireBundle symbolicName="com.abc.thridparty" />
 
     <requireApplication applicationId="com.abc.my.application" />
 
     <requireApplication applicationId="com.abc.my.application" />
</role>
+
  </role>
 +
</extension>
 
</source>
 
</source>
  
 
The role requires the bundle <code>com.abc.thridparty</code> to be started as well as the application <code>com.abc.my.application</code>.
 
The role requires the bundle <code>com.abc.thridparty</code> to be started as well as the application <code>com.abc.my.application</code>.
 +
 +
 +
== Define Activation Triggers ==
 +
Once roles are defined you also need to define an activation trigger. You can create different triggers depending on the [[Gyrex/Administrator_Guide#Operation_Mode|operation mode]] and the [[Gyrex/Development_Space/ZooKeeper_Interaction#ONLINE|cloud online state]]. An addition start level can be set to apply some level of ordering to roles activation.
 +
 +
=== Example Development Trigger ===
 +
In development mode it's usually very comfortable to automatically start a role. For example, Gyrex itself uses the following trigger to automatically start an embedded ZooKeeper server in development mode.
 +
<source lang="xml">
 +
<extension point="org.eclipse.gyrex.server.roles">
 +
  <defaultStart
 +
      mode="development"
 +
      roleId="org.eclipse.gyrex.cloud.roles.leader"
 +
      startLevel="-10"
 +
      trigger="onBoot">
 +
  </defaultStart>
 +
</extension>
 +
</source>
 +
 +
=== Example Production Trigger ===
 +
In production environment one usually does not want a particular role to start automatically but only when a specific configuration is done. For example, Gyrex itself uses the following trigger to start the Jetty server in production mode when a node is tagged with the tag ''webserver'' and successfully connected with the cloud.
 +
<source lang="xml">
 +
<extension point="org.eclipse.gyrex.server.roles">
 +
  <defaultStart
 +
      mode="production"
 +
      nodeFilter="(tag=webserver)"
 +
      roleId="org.eclipse.gyrex.http.jetty.roles.engine"
 +
      startLevel="10"
 +
      trigger="onCloudConnect">
 +
  </defaultStart>
 +
</extension>
 +
</source>
  
 
[[Category:Gyrex]]
 
[[Category:Gyrex]]

Revision as of 15:17, 28 November 2012

In Gyrex roles are used to control what bundles and what OSGi applications (OSGi application admin) will be started on a particular node.

Dependencies

  • Bundle org.eclipse.gyrex.boot (Gyrex 1.0 or higher)
  • Equinox Extension Registry


Define Roles

Roles are implemented using the Equinox Extension Registry. This decision was made in order to allow a declaritive approach for devining roles without writing any line of Java as well as to support lazy activation. It may be possible to use DS in the future (bug 395332).

In order to define a role you need to create an extension to the org.eclipse.gyrex.server.roles extension point. Each role consists of an identifier, a name and references a set of bundles and/or applications to start. Applications must be defined using the Equinox org.eclipse.core.runtime.applications extension point.

Example

The following Example defines a role "My Server Role".

<extension point="org.eclipse.gyrex.server.roles">
  <role id="com.abc.my.role" name="My Server Role">
    <requireBundle symbolicName="com.abc.thridparty" />
    <requireApplication applicationId="com.abc.my.application" />
  </role>
</extension>

The role requires the bundle com.abc.thridparty to be started as well as the application com.abc.my.application.


Define Activation Triggers

Once roles are defined you also need to define an activation trigger. You can create different triggers depending on the operation mode and the cloud online state. An addition start level can be set to apply some level of ordering to roles activation.

Example Development Trigger

In development mode it's usually very comfortable to automatically start a role. For example, Gyrex itself uses the following trigger to automatically start an embedded ZooKeeper server in development mode.

<extension point="org.eclipse.gyrex.server.roles">
  <defaultStart
      mode="development"
      roleId="org.eclipse.gyrex.cloud.roles.leader"
      startLevel="-10"
      trigger="onBoot">
  </defaultStart>
</extension>

Example Production Trigger

In production environment one usually does not want a particular role to start automatically but only when a specific configuration is done. For example, Gyrex itself uses the following trigger to start the Jetty server in production mode when a node is tagged with the tag webserver and successfully connected with the cloud.

<extension point="org.eclipse.gyrex.server.roles">
  <defaultStart
      mode="production"
      nodeFilter="(tag=webserver)"
      roleId="org.eclipse.gyrex.http.jetty.roles.engine"
      startLevel="10"
      trigger="onCloudConnect">
  </defaultStart>
</extension>