beautypg.com

Sample program code, Nsasjversionclient.java sample program – HP Integrity NonStop H-Series User Manual

Page 100

background image

Table 26 Sample program details (continued)

Description

Program

application demonstrates how to execute a command
on any individual instance of the NSASJ serverclass
and also on host-controller.

Sample program code

NSASJVersionClient.java

sample program

/*Copyright 2013 Hewlett-Packard Development Company, L.P. */
/**
* NSASJVersionClient is a sample nsasj management client program that demonstrates the usage
* of NSASJClient to get information about the NSASJ Server
*/

package com.hp.nsk.nsasj.client.demo;
import org.jboss.dmr.ModelNode;
import org.jboss.logging.Logger;
import com.hp.nsk.nsasj.client.NSASJClient;

public class NSASJVersionClient extends NSASJClient {
public NSASJVersionClient(String propFile) {
super(propFile);
}

/**
* method - getNSASJVersion(). A method to get the Release version and Release-CodeName of NSASJ.
*
*/
private void getNSASJVersion() {
// Checking whether Client is actually connected to Controller or not by
ModelNode op = new ModelNode();
op.get("operation").set("read-resource");
ModelNode returnVal = null;
try {
returnVal = this.client.execute(op);
} catch (Exception e) {
this.logger.error(e.getMessage());
if (this.client != null)
this.disconnectFromHC();
System.exit(0);

}
System.out.println("Release-Version: " + returnVal.get("result").get("release-version").asString());
System.out.println("Release-Codename: " + returnVal.get("result").get("release-codename").asString());

}

/**
* executeCommand() - the abstract method of NSASJClient is overridden here to provide the NSASJ

*version functionality
*/
@Override
public void executeCommand() {
getNSASJVersion();

}

public static void main(String[] args) {
NSASJVersionClient obj = null;
// Initialize the logger
System.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
System.setProperty("logging.configuration", "file:logging.properties");
Logger logger1 = Logger.getLogger("NSASJClient", "com.hp.nonstop.nsasj.client.demo");
// Get the arguments
if (args.length > 1) {
System.out
.println("Usage : java com.hp.nonstop.nsasj.client.demo.NSASJVersionClient
");
System.exit(0);
} else if (args.length == 1)
obj = new NSASJVersionClient(args[0]);
else
obj = new NSASJVersionClient(null);
obj.logger = logger1;
// Connect to Host Controller
obj.connectToHC();
// Create and execute the command
obj.executeCommand();
// Disconnect and exit
obj.disconnectFromHC();

100 Programmatic Management of NSASJ using API

This manual is related to the following products: