Resources Validations

The resources validations, is a set of beans used to validate resources used by a batch. This can be used, when an administrator, changes the batch parameters, or deploys a new release.

Creating a validator

To create a validator, you just need to create a spring managed bean, that implements BatchResourceValidation class. The public boolean exectue(StringBuffer buffer,String mimeType) method is called by SBAL, with:

  • A buffer that will store informations to be displayed on the console
  • A mime type, to decide how to fill the buffer (text or html are possible values).

The method must return a boolean indicating if the validation ended successfully (true) or in error (false).

Dummy validator sample that checks for a value passed through spring configuration:

public class SimpleResourceValidation implements BatchResourceValidation {

        protected String value;
        protected String name;
        public boolean exectue(StringBuffer buffer,String mimeType) {
                buffer.append("Simple dummy validation");
                return value.equals("ok");
        }
        /**
         * @param value the value to set
         */
        public void setValue(String value) {
                this.value = value;
        }
        /**
         * @return the name
         */
        public String getName() {
                return name;
        }
        /**
         * @param name the name to set
         */
        public void setName(String name) {
                this.name = name;
        }

}

Adding validator to configuration

This validator is configured in spring like this:

        <bean id="diag" class="com.pf.ast.batch.SimpleResourceValidation">
                <property name="name">
                        <value>${validation.name}</value>
                </property>
                <property name="value">
                        <value>${validation.ok}</value>
                </property>
        </bean>

${validation.name} and ${validation.ok} are taken from the configuration properties.

Once the validation is defined, it can be added to the list:

        <bean id="resourceValidationRunner"
                class="net.sf.spring.batch.impl.DefaultResourceValidationRunner">
                <property name="resourceValidations">
                        <list value-type="com.pf.ast.batch.BatchResourceValidation">
                                <ref bean="diag" />
                        </list>
                </property>
        </bean>

Validation result

The output of SBAL launched with '-d' option gives:

    ----------------------------------------\
    dummy validation    ok                   |      <- Validation name and result status
    ----------------------------------------  > Repeated block for each validation
    Simple dummy validation                  |      <- Buffer content
    ----------------------------------------/
    Summary:2/2                                     <- Result summary
    ----------------------------------------