environment and tags

Environment and Tags

Version: 17.07

Overview

Environment represents the running environment of the project-x runtime. It will be used to determine environment specific details of the deployment. You will see the following Environment bean in the shipped server.xml.

<bean id="env" class="org.adroitlogic.x.core.Environment">
    <constructor-arg name="nodeName" value="UltraESB-X"/>
    <property name="mode" value="IDE"/>
    <property name="projectBaseDir" value="."/>
    <property name="tmpDir" value="."/>
    <property name="productName" value="AdroitLogic IPS"/>
</bean>

Apart from the above shipped configurations, environment can have a list of tags which can be specified as below.

<property name="tags">
    <map>
        <entry key="maxCPUUsage" value="80%"/>
        <entry key="maxMemoryUsage" value="2048"/>
        <entry key="foo1" value="bar1,bar2,bar3"/>
    </map>
</property>

Also, environment has the concept of "Environment Listeners" where these listeners will be notified whenever a tag/tags is/are added to the environment. That is, environment act as the mediator when it comes to notifying runtime changes to the tags to the listeners. This concept allow us to decouple the decision making logic from the monitoring logic.

There’s also a concept called "Environment Evaluators" which we will be discussing later in the documentation. As an overview, evaluators are the classes responsible for evaluating/processing events notified to the environment listeners.

Node Name

Each UltraESB-X instance should have a node name. Since this is a mandatory property required, it is passed in as a constructor argument. In the case of clustering, you have to make sure that no two instances belonging to the same domain have the same node name.

Node name will be further used by the failover strategies when providing failover support to uniquely identify nodes in the cluster.

Properties

projectBaseDir

Gives the base directory for projects as a file. Defaults to "projects".

tmpDir

The directory which will be used as the temporary directory by the UltraESB-X instance. Defaults to "tmp".

productName

The name of the product.

tags

A map of key-value pairs which specifies the initial set of tags to be present in the environment. For a given' key, there can be a list of tags specified as comma separated values. These tags are used for coordination purposes in the runtime. Mostly, these tags are used by the failover strategies as mentioned above.

Environment Listeners

An environment listener should be implementing the interface "org.adroitlogic.x.api.XEnvironmentListener". In order to be notified about the tag changes in the environment, that listener have to be registered as a listener in the environment. After registering, all the tag changes in the environment will be notified to that listener through the listener method, "environmentChanged(XEnvironment environment)".

Currently, Project has implemented this interface and gets registered as an environment listener when a project is being initialized. When a project is notified about the environment. it make use of the "Environment Evaluators" to determine what is the action to be taken.

Environment Evaluators

A project can have multiple environment evaluators. Environment evaluator is any class that is extending the abstract class "org.adroitlogic.x.api.EnvironmentEvaluator". Evaluator’s task is to simply look at the current tags in the environment or look at any other important component’s status and decide whether that evaluator expects the subjected component to be running under current state of the UltraESB-X instance. If yes, evaluator should return true, else false. The evaluation process will consider the an amount equal to positiveWeight if returned true. Else an amount equal to negativeWeight will be added to the sum.

positiveWeight means that this evaluator should return the given amount if the evaluation is in the evaluator’s favor. Therefore, the value of positiveWeight can be either positive or negative depending on the objective of the evaluator. This is similar with negativeWeight. 'negativeWeight' is the amount returned when the evaluation is not in favor.
<x:evaluators>
    <x:evaluator>
        <bean class="org.foo.bar.Evaluator1">
            <constructor-arg name="positiveWeight" value="1"/>
            <constructor-arg name="negativeWeight" value="-1"/>
            ....
        </bean>
    </x:evaluator>
    <x:evaluator>
        <bean class="org.foo.bar.Evaluator2">
            <constructor-arg name="positiveWeight" value="10"/>
            <constructor-arg name="negativeWeight" value="-10"/>
            ....
        </bean>
    </x:evaluator>
    <x:evaluator>
        <bean class="org.foo.bar.Evaluator3">
            <constructor-arg name="weight" value="2"/>
            ....
        </bean>
    </x:evaluator>
    ....
</x:evaluators>

As shown above, you can specify multiple evaluators as you wish. When the environment listener method is being called by the notifier, the evaluators are called and the sum of weights returned by the evaluators is taken. If the sum is,

  • greater than 0, start the project if it is stopped at the moment

  • equal to 0, do nothing

  • smaller than 0, stop the project if it is stopped at the moment.

A Sample Scenario

Similar to the above example, you can set the weights of each evaluator depending on the priority of the evaluators. Suppose there are two evaluators, one for system resource evaluation and one for failover evaluation. In this case, even though the failover strategy wants to start the project, project shouldn’t be started if the system resources are low. In that case, more priority has to be given to system resources.

To accommodate this requirement, we can set the weights of the system resource evaluator to higher values (say 10) and weights of failover evaluator to lower values (say 1). Therefore, whenever an environment tag change occurs, more priority will be given to the system resource evaluator.

Example uses of the environment evaluators can be found in node wise failover strategy and group failover strategy. You can write evaluators on your own to make decisions when tags are changed.
In this topic
In this topic
Contact Us