Sun Open Telecommunications Platform 2.0 Developer's Guide

Calling N1 SPS Plans From Java

You can invoke the N1 SPS plans through the Java API by using the sps-api.jar library. This library is located in the /var/js/spsotp/N1_Service_Provisioning_System_5.2/cli/lib/ directory. For more information about the API documentation, see Sun N1 Service Provisioning System JavaDoc.

A sample code indicating the running of the InstallSecurity plan from Sun OTP 2.0 plug-in and waiting for running plan of given ID is as follows:


Note –

This example does not handle all plan execution scenarios. Consider a case where there are 20 tasks that should be completed after the task that you specify completes. Before you check the status of task, the array that the pe.p.la command generates does not contain any information regarding the task. However, in case the array does not contain any information corresponding to your task, you can rerun the pe.p.la command specifying a higher result array size or by specifying a plan name for the tasks to match.


For more information about the pe.p.la and pe.p.lo commands, see Sun N1 Service Provisioning System 5.2 Command-Line Interface Reference Manual.

package spsapitest;

import com.sun.n1.sps.client.*;
import com.sun.n1.sps.model.executor.RunningPlanBean;
import com.sun.n1.sps.model.executor.TaskID;
import com.sun.n1.sps.model.util.ClientException;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

public class SPSTest {

    public static void main(String[] args) {
        try {
            CommandManagerBuilder cmb = new com.sun.n1.sps.client.CommandManagerBuilder();            
            cmb.setCLIInstallationDir(new File("/var/js/spsotp/N1_Service_Provisioning_System_5.2/cli"));
            CommandManager cm = cmb.build();
            
            //running the plan
            Map<String, String> arguments = new HashMap<String, String>();
            arguments.put("u", "otpadmin");     //user
            arguments.put("p", "adminadmin");   //password         
            arguments.put("PID", "NM:/com/sun/OTP/security/plans/InstallSecurity"); 		//plan name
            arguments.put("tar", "H:NM:otp-eng-x11;H:NM:otp-eng-x11;H:NM:otp-eng-x11");	//target
            arguments.put("vs", "+;+;+,+,+,+,+,+,+,+");   	//variable settings
            arguments.put("comp", "+;+;+,+,+,+,+,+,+,+"); 	//components versions
            arguments.put("pto", "9000");       //plan timeout
            arguments.put("nto", "9000");       //native call timeout
            TaskID taskID = (TaskID)cm.execute("pe.p.run", arguments);  //see pe.p.run in N1SPS CLI doc
            
            //waiting for plan to complete
            arguments.clear();
            arguments.put("u", "otpadmin");
            arguments.put("p", "adminadmin"); 
            arguments.put("ID", taskID.toString());                                     
            cm.execute("pe.p.lo", arguments);
                                    
            //checking plan status
            arguments.clear();
            arguments.put("u", "otpadmin");
            arguments.put("p", "adminadmin");   
            arguments.put("max", "20");         //maximum numbers of tasks to get info
            RunningPlanBean[] rpba = (RunningPlanBean[]) cm.execute("pe.p.la", arguments);
            for (RunningPlanBean rpb : rpba) {                
                if (taskID.equals(rpb.getTaskID())) {
                    System.out.println("Task ID: "+rpb.getTaskID().toString()+"\n"+
                            "Plan name: "+rpb.getName()+"\n"+
                            "Status: "+rpb.getTaskStatus().toString()+"\n"+
                            "Start date: "+rpb.getStartDate().toString()+"\n"+
                            "Complete date: "+rpb.getCompleteDate());
                }                
            }                        
        } catch (ConfigurationException ex) {
            Logger.getLogger(SPSTest.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClientException ex) {
            Logger.getLogger(SPSTest.class.getName()).log(Level.SEVERE, null, ex);

        }
    }    
}