IBM Support

ITNM: Supporting Custom Properties in Custom Java Collectors

Technical Blog Post


Abstract

ITNM: Supporting Custom Properties in Custom Java Collectors

Body

Overview

This post provides a working example showing how you can load custom properties into a custom Java collector.

In short, you're free to use java.util.Properties to process properties, however the current sample collectors don't provide an example of this. 

This post tries to eliminate any confusion as to how the property support in the Collector base class relates to the property support in the custom collector.

The example presented here will be a simple modification of the SampleCollector shipped with Network Manager which can be found in $NCHOME/precision/collectors/javaCollectors/samples.

 

Collector Base Class Property Support

Property support in the Collector base class is primarily concerned with the loading at startup of the standard framework properties such as port, and logging properties. This is as described in the documentation for that class (Documentation/com/ibm/tivoli/nm/collectors/framework/collector/Collector.html). 

 

On startup a custom collector should call Collector::startup() passing the command-line arguments (e.g. -propsFile) and optionally a default property file name (this defaults to "../framework/collector.properties" if not specified).

startup() will read the standard framework properties from the file DEFAULT_PROPERTIES_FILE_NAME ( "../framework/collector.properties" ) and from the collector specific properties file (i.e. either the -propsFile arg or the supplied default). The collector properties override any clashing properties, e.g. port.

 

The points to note here are that the Collector base class...;

  • ... doesn't process any custom properties
  • ... will allow our custom collectors properties file to hold the definitive standard framework properties (i.e. we can mix custom properties with the standard properties in a single file)
  • ... will make a note of the selected collector specific property file name in Collector::propsFileName

Adding Custom Property Support to SampleCollector

Out of the box $NCHOME/precision/collectors/javaCollectors/samples/SampleCollector.java calls the version of startup() that results in the properties file being "../framework/collector.properties.

We'd rather support a collector specific properties file, allowing standard framework properties and custom properties to be defined in the same file (while still supporting the -propsFile command-line argument).
To do this we should provide a default collector specific property file name and pass it to startup() as follows;
        

public static void main(String[] args) {
    ...
    // Start up the collector framework

    startup(args);
    startup(args, "../samples/SampleCollector.properties");
    ...

 

 

Properties are supported using the standard java.util.Properties class. So all we need to do is load our properties from the file pointed to by Collector::propsFileName (following the call to startup()).

 

Given a properties file such as;

 

# Custom Properties

myCustomUser = user1

# Standard properties 

port = 8082

 

  

The following changes to SampleCollector.java would allow SampleCollector to load the custom properties;

 

...

import java.util.logging.Logger;

import java.util.Properties;

...

public static void main(String[] args) {

    ...

    // Start up the collector framework

    startup(args);

    startup(args, "../samples/SampleCollector.properties");

    ...

    Properties customProps = loadPropertiesFile( propsFileName );

    String user = customProps.getProperty( "myCustomUser" );

 

    System.out.print("myCustomUser is " + user );

    ...

  

You could use the java.util.Properties load() methods directly rather than the Collector::loadPropertiesFile method if preferred. 

The key points are that you tell startup() which properties file you want to use, from which it loads the standard properties, and then you handle the loading of your custom properties yourself.

 

[{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"","label":""},"Component":"","Platform":[{"code":"","label":""}],"Version":"","Edition":"","Line of Business":{"code":"","label":""}}]

UID

ibm11082337