In this blog, I will be demonstrating a program object to export the list of failed instances in a Business Objects environment.
Prerequisites:
Creation of a Java Program Object:
import com.crystaldecisions.sdk.plugin.desktop.program.*;
import com.crystaldecisions.sdk.framework.*;
import com.crystaldecisions.sdk.occa.infostore.*;
import com.crystaldecisions.sdk.exception.*;
import java.io.FileWriter;
import java.io.IOException;
import com.crystaldecisions.sdk.occa.report.lib.PropertyBag;
import com.crystaldecisions.sdk.properties.IProperties;
import com.crystaldecisions.sdk.properties.IProperty;
import java.util.*;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import java.io.*;
import java.util.Date;
import java.text.*;
import java.util.Calendar;
import org.apache.poi.xssf.usermodel.XSSFPrintSetup;
public class FailedInstances implements IProgramBase
{
public void run(IEnterpriseSession enterprisesession,IInfoStore infostore,String str[]) throws SDKException
{
Calendar cal = Calendar.getInstance();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
cal.add(Calendar.DATE, -15);
System.out.println("Connected to " + enterprisesession.getCMSName() + "CMS");
System.out.println("Using the credentials of " + enterprisesession.getUserInfo().getUserName() );
String starttime=null;
String endtime=null;
String retriesAttempted=null;
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("new sheet");
XSSFRow rowhead = sheet.createRow((short)0);
rowhead.createCell((short) 0).setCellValue("Instance ID");
rowhead.createCell((short) 1).setCellValue("Instance Name");
rowhead.createCell((short) 2).setCellValue("Kind");
rowhead.createCell((short) 3).setCellValue("Start Time");
rowhead.createCell((short) 4).setCellValue("End Time");
rowhead.createCell((short) 5).setCellValue("Instance Type");
rowhead.createCell((short) 6).setCellValue("Retries Attempted");
rowhead.createCell((short) 7).setCellValue("Error Message");
int index = 1;
try
{
String statusCheck=null;
String typeCheck=null;
IInfoStore iStore = (IInfoStore) enterprisesession.getService("", "InfoStore"); System.out.println("Checkpoint1 ");
IInfoObjects infoobjects = iStore .query("SELECT * from CI_INFOOBJECTS WHERE si_instance=1 and si_schedule_status=3 and si_creation_time>'"+ dateFormat.format(cal.getTime())+"'");
System.out.println("Checkpoint2 ");
for(int i=0;i<infoobjects.size();i++)
{
IInfoObject infoobject=(IInfoObject) infoobjects.get(i);
ISchedulingInfo schedInfo=infoobject.getSchedulingInfo();
int instanceID=infoobject.getID();
String instanceName=infoobject.getTitle();
String errorMsg=schedInfo.getErrorMessage();
System.out.println("Instance ID :"+instanceID);
System.out.println("Instance Name :"+instanceName);
int type=schedInfo.getType();
System.out.println(" Type of the report :");
System.out.println("Checkpoin 3 ");
switch(type)
{
case CeScheduleType.ONCE:
typeCheck="ONCE";
System.out.println(typeCheck);
break;
case CeScheduleType.HOURLY: //Job has failed.
typeCheck="HOURLY";
System.out.println(typeCheck);
break;
case CeScheduleType.DAILY: //Job is paused.
typeCheck="DAILY";
System.out.println(typeCheck);
break;
case CeScheduleType.WEEKLY: //Job is pending.
typeCheck="WEEKLY";
System.out.println(typeCheck);
break;
case CeScheduleType.MONTHLY: //Job is running.
typeCheck="MONTHLY";
System.out.println(typeCheck);
break;
case CeScheduleType.NTH_DAY:
typeCheck="NTH_DAY";
System.out.println(typeCheck);
break;
case CeScheduleType.FIRST_MONDAY: //Job has failed.
typeCheck="FIRST_MONDAY";
System.out.println(typeCheck);
break;
case CeScheduleType.LAST_DAY: //Job is paused.
typeCheck="LAST_DAY";
System.out.println(typeCheck);
break;
case CeScheduleType.CALENDAR: //Job is pending.
typeCheck="CALENDAR";
System.out.println(typeCheck);
break;
case CeScheduleType.CALENDAR_TEMPLATE: //Job is running.
typeCheck="CALENDAR_TEMPLATE";
System.out.println(typeCheck);
break;
}
String kind=infoobject.getKind();
System.out.println(kind);
IProperties instanceProperties=(IProperties)infoobject.getSchedulingInfo().properties();
IProperty instanceProperty=instanceProperties.getProperty("SI_STARTTIME");
if(instanceProperty != null)
{
starttime=instanceProperty.getValue().toString();
System.out.println("Instance Start Time :"+starttime);
}
IProperties instanceProperties1=(IProperties)infoobject.getSchedulingInfo().properties();
IProperty instanceProperty1=instanceProperties1.getProperty("SI_ENDTIME");
if(instanceProperty1 != null)
{
endtime=instanceProperty1.getValue().toString();
System.out.println("Instance End Time :"+endtime);
}
IProperties instanceProperties2=(IProperties)infoobject.getSchedulingInfo().properties();
IProperty instanceProperty2=instanceProperties2.getProperty("SI_RETRIES_ATTEMPTED");
if(instanceProperty2 != null)
{
retriesAttempted=instanceProperty2.getValue().toString();
System.out.println("Retries Attemted :"+retriesAttempted);
}
System.out.println("Error Message :"+errorMsg);
System.out.println("====================================================================");
XSSFRow row = sheet.createRow((short)index);
row.createCell((short) 0).setCellValue(instanceID);
row.createCell((short) 1).setCellValue(instanceName);
row.createCell((short) 2).setCellValue(kind);
row.createCell((short) 3).setCellValue(starttime);
row.createCell((short) 4).setCellValue(endtime);
row.createCell((short) 5).setCellValue(typeCheck);
row.createCell((short) 6).setCellValue(retriesAttempted);
row.createCell((short) 7).setCellValue(errorMsg);
index++;
}
System.out.println("Checkpoint4 ");
java.util.Date date=new Date();
System.out.println("Checkpoint5 ");
String date1= date.toString();
String date2=date1.replaceAll("\\W", "_");
FileOutputStream fileOut = new FileOutputStream(str[0]+"_"+date2 +".xlsx");
wb.write(fileOut);
fileOut.close();
System.out.println(" Excel file created successfully");
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
Publishing the Java Program Object to the Enterprise System:
You would then have an excel file generated at the above specified location with the details of failed instances.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |