package com.gbs.tools;
import java.net.Inet4Address;
import com.crystaldecisions.sdk.exception.SDKException;
import com.crystaldecisions.sdk.framework.IEnterpriseSession;
import com.crystaldecisions.sdk.occa.infostore.IInfoObject;
import com.crystaldecisions.sdk.occa.infostore.IInfoStore;
import com.crystaldecisions.sdk.plugin.desktop.program.IProgramBaseEx;
import com.crystaldecisions.sdk.properties.IProperty;
public class BobjIpManager implements IProgramBaseEx {
@Override
public void run(IEnterpriseSession enterpriseSession, IInfoStore infoStore, IInfoObject programInfoObject, String programInstanceID, String[] args)
throws SDKException {
try {
// Indicate that if there is an error when running the java program object, then the status of
// the program object can be set to failure.
programInfoObject.getProcessingInfo().properties().add("SI_PROGRAM_CAN_FAIL_JOB", Boolean.TRUE, IProperty.DIRTY);
programInfoObject.save();
String host = Inet4Address.getLocalHost().getHostAddress();
System.out.println("Current host ip: " + host);
Tools.setLocalIpOnBobjServer(infoStore, host);
Tools.setLocalIpOnRestfulWebService(infoStore, host);
Tools.setLocalIpWebService(infoStore, host);
} catch (Exception e) {
// We catch an exception here. When there is an exception, we are going to
// treat that as a program error. When there is a program error, we want
// the program object instance to have a Status of "Failed". In order to do
// that, we write "PROCPROGRAM:PROGRAM_ERROR" and "62009" to the System.out
// and then we can write up to 3 lines to the System.out.
// At the end, we do a System.exit(1) and the Status of this program
// object will now be "Failed".
System.out.println("PROCPROGRAM:PROGRAM_ERROR");
System.out.println("62009");
// On the first line, print out the error to the System.out:
// The first line appears as the error message when the "FAILED" status
// of the instance is clicked on the History page.
System.out.println(e);
// We will print out up to two extra lines of information. These two
// extra lines are not seen when clicking on the "FAILED" status on the
// instance History page
// All three lines of information can be seen in the SI_STATUSINFO property
// for the program instance object.
// System.out.println("Optional line 1.");
//System.out.println("Optional line 2.");
// Exit the system so that the Status is set to "Failed".
System.exit(1);
}
}
}
package com.gbs.tools;
import java.net.UnknownHostException;
import com.businessobjects.sdk.plugin.desktop.common.IConfiguredContainer;
import com.businessobjects.sdk.plugin.desktop.common.IExecProps;
import com.businessobjects.sdk.plugin.desktop.restwebservice.IRestWebService;
import com.businessobjects.sdk.plugin.desktop.webservice.IWebService;
import com.crystaldecisions.sdk.exception.SDKException;
import com.crystaldecisions.sdk.occa.infostore.IInfoObjects;
import com.crystaldecisions.sdk.occa.infostore.IInfoStore;
import com.crystaldecisions.sdk.plugin.desktop.server.ExpectedRunState;
import com.crystaldecisions.sdk.plugin.desktop.server.IServer;
public class Tools {
public static void setLocalIpOnBobjServer(IInfoStore infostore, String host) throws SDKException, UnknownHostException {
String serverQuery = "SELECT * FROM CI_SYSTEMOBJECTS WHERE SI_KIND='Server' AND SI_SERVER_KIND in ('aps', 'fileserver')";
IInfoObjects servers = infostore.query(serverQuery);
for(int i = 0; i < servers.size(); i++) {
IServer server = (IServer) servers.get(i);
System.out.println("Working on: " + server.getName());
// Get the server command parameter
IConfiguredContainer cfgContainer = server.getContainer();
IExecProps execProps = cfgContainer.getExecProps();
// Check if the current arguments contains correct host
if (containCorrectHost(server.getServerKind(), execProps.getArgs(), host)) {
System.out.println("Host is already set: " + execProps.getArgs());
} else {
// we need to replace/add
execProps.setArgs(replaceHost(server.getServerKind(), execProps.getArgs(), host));
server.setExpectedRunState(ExpectedRunState.RESTART);
server.save();
System.out.println("Change is done! New command line after change: " + execProps.getArgs());
}
}
}
/**
* Fix the Web Service API
*
* @param infoStore
* @throws UnknownHostException
* @throws SDKException
*/
public static void setLocalIpWebService(IInfoStore infoStore, String host) throws SDKException {
String applicationsQuery = "SELECT * FROM CI_APPOBJECTS WHERE SI_KIND='WebService'";
IInfoObjects applications = infoStore.query(applicationsQuery);
for(int i = 0; i < applications.size(); i++) {
IWebService webService = (IWebService) applications.get(i);
String url = "http://" + host + ":8080/dswsbobje";
if(host.equals("")) {
url = "http://localhost:8080/dswsbobje";
}
System.out.println("Set WebService URL: " + url);
webService.setURL(url);
webService.save();
}
}
/**
* Fix the RESTful API
*
* @param infoStore
* @throws UnknownHostException
* @throws SDKException
*/
public static void setLocalIpOnRestfulWebService(IInfoStore infoStore, String host) throws SDKException {
String applicationsQuery = "SELECT * FROM CI_APPOBJECTS WHERE SI_KIND='RestWebService'";
IInfoObjects applications = infoStore.query(applicationsQuery);
for(int i = 0; i < applications.size(); i++) {
IRestWebService restWebService = (IRestWebService) applications.get(i);
String url = "http://" + host + ":6405/biprws";
if(host.equals("")) {
url = "http://localhost:6405/biprws";
}
System.out.println("Set RESTful URL: " + url);
restWebService.setURL(url);
restWebService.save();
}
}
/**
*
* @param serverKind
* @param args
* @return true if args contains a valid hostname
*/
public static boolean containCorrectHost(String serverkind, String args, String host) {
if(serverkind.equals("aps") && host.equals("")) {
return args.contains("-port 6400");
}
else if(serverkind.equals("aps")) {
return args.contains("-port " + host + ":6400");
}
if(serverkind.equals("fileserver") && host.equals("")) {
return !args.contains("-port");
}
else {
return args.contains("-port " + host);
}
}
/**
*
* @param serverKind
* @param args
* @param host
* @return the args with hostname
*/
public static String replaceHost(String serverKind, String args, String host) {
if(serverKind.equals("aps") && host.equals("")) {
return args.replaceAll("-port (.*)6400", "-port 6400");
}
else if(serverKind.equals("aps")) {
return args.replaceAll("-port (.*)6400", "-port " + host + ":6400");
}
else {
if(host.equals("")) {
return args.replaceAll("-port (.*)", "");
}
else {
if(args.contains("-port")) {
// if existing value
return args.replaceAll("-port (.*)", "-port " + host);
}
else {
//if no existing value
return args + " -port " + host;
}
}
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |