Tutorial: Create a program APX

This tutorial demonstrates how to create, publish, and run a simple program APX named myshellapp that runs a simple shell script. Later the tutorial shows you how to modify the shell script to call the apxprogress command and provide progress information. Because the tutorial provides the source code, prior knowledge of shell programming is not required.

Complete the following tasks in order.

Tutorial prerequisites

To complete this tutorial, you must have the following capabilities and environment:

  • The ability to log on to SA as admin or as another member of the Super Administrators group. Logging on as admin enables you to set permissions.
  • The ability to log on to SA as a user who belongs to the Advanced Users group.
  • Advanced users have permission to create and run the web application. In the example commands shown in this tutorial, the name of this user is jdoe.
  • An understanding of how to set client feature permissions in the SA Client.
  • For more information about permissions, see the "User and Group Setup section" in the SA Administer section.
  • An understanding of how to create folders in the SA Client
  • For details on folders, see the SA Use section.
  • An understanding of how to open a Global Shell (OGSH) session and use the Global Shell.
  • An understanding of basic Unix commands such as ls and cd.

Setting permissions and creating the tutorial folder

  1. Log on to the SA Client as admin and open the Folder Properties of the MyApp folder.
  2. On the Permissions tab of Folder Properties, make sure that the Advanced Users group has the following permissions:
    • List Contents of Folder

    • Read Objects Within Folder

    • Write Objects Within Folder

    • Execute Objects Within Folder

  3. Exit the SA Client.

Creating a new program APX

  1. Open a Global Shell session as an SA user who belongs to the Advanced Users group.
  2. In your core’s OGFS home directory, create a directory named myshellapp and then change to that directory:

    $ mkdir myshellapp
    $ cd myshellapp


    The program APX files will be stored in the myshellapp directory.
  3. Using the apxtool new command, create the directory structure and default files for the program APX as shown below.

    $ pwd
    /home/jdoe/myshellapp
    $ ls
    $
    $ apxtool new -ts -d "This is my first program APX." \
    -u com.hpe.sa.jdoe.myshellapp

    Create source directory under ‘/home/jdoe/myshellapp/com.hpe.sa.jdoe.myshellapp’ for APX ‘myshellapp’? Y/N y
    Info: Successfully created source directory ‘/home/jdoe/myshellapp/com.hpe.sa.jdoe.myshellapp for APX ‘myshellapp’.

    The -ts option indicates that the APX type is a program APX (also called a script APX), -d specifies a description, and -u specifies a unique name for the application.

    For more information about the apxtool new command options, see the online help:
    $ apxtool new -h
  4. List the files created by the apxtool new command:

    $ pwd
    /home/jdoe/mywebapp
    $ ls
    com.hpe.sa.jdoe.myshellapp
    $ cd com.hpe.sa.jdoe.myshellapp
    $ pwd
    /home/jdoe/myshellapp/com.hpe.sa.jdoe.myshellapp
    $ ls -R
    .:
    APX-INF run.sh
    ./APX-INF:
    apx.cfg apx.perm description.txt interfaces usage.txt
  5. Display the contents of the default run.sh file:

    $ cat run.sh
    #!/bin/sh

    ######################################################################
    # APX myshellapp
    #
    # Created by: jdoe
    #
    ######################################################################
    echo "This is APX myshellapp"
  6. Examine some of the files in the APX-INF directory. For more information on these files see APX files.

    The APX-INF directory contains information that is specific to APXs. As shown by the following cat command, the description.txt file holds the text you specified with the -d option of apxtool new.
    $ ls APX-INF/
    apx.cfg apx.perm  description.txt  interfaces  usage.txt
    $ cat APX-INF/description.txt
    This is my first program APX.$


    The following grep command shows some of the properties in apx.cfg, the APX configuration file. The values for type and uniquename result from the -t and -u options of the apxtool new command. For details on the APX configuration file, see APX configuration file - apx.cfg.

    $ grep "=" APX-INF/apx.cfg
    type=script
    name=myshellapp
    unique_name=com.hpe.sa.jdoe.myshellapp
    command=run.sh

Importing the new APX into SA

Importing the APX performs the following actions:

  • Copies the APX to a folder that appears in the SA Library.
  • Assigns a version number to the APX.

Enter the apxtool import command and respond to the prompts with y, as shown below. The -f option specifies the folder in the SA Library where the web application will be stored. The -c option sets the current version of the web application.

$ pwd
/home/jdoe/myshellapp/com.hpe.sa.jdoe.myshellapp
$
$ apxtool import -f "/Dev/MyApp" -c
APX source is not specified.
Do you want to publish current directory: /home/jdoe/myshellapp/
com.hpe.sa.jdoe.myshellapp? Y/N y
APX with unique name 'com.hpe.sa.jdoe.myshellapp' does not exist.
Register it into the system? Y/N y
Info: Successfully registered APX 'myshellapp' (20001).
Info: Successfully published a new version '1' for APX 'myshellapp'
Info: Successfully set APX 'myshellapp'(20001) current version as '1'.

Now that you have published the APX, you are ready to run it from the SA Client, just as another SA user would.

Running the new APX

Now that you have published the APX, you are ready to run it from the SA Client.

  1. Log on to the SA Client as a user who belongs to the Advanced Users group.
  2. In the navigation pane, select the Library tab, then the By Type tab.
  3. Open the Extensions node and select the Program node. This displays all the program APXs in the SA Library. You should see your APX there. If you do not see myshellapp, make sure that you have the necessary permissions as described in Setting permissions and creating the tutorial folder.
  4. Select your APX.
  5. Select the Actions > Run menu item. This displays the Run Program Extension wizard.
  6. Select the Next button.
  7. Select the Start Job button.
  8. When your APX finishes, select the status indicator to display details.
  9. Select the Close button.

Modifying the APX

In this section, you modify the run.sh file and add calls to the apxprogress command to provide progress information.

  1. In the Global Shell session, locate the run.sh file of the APX.

    $ cd /home/jdoe/myshellapp/com.hpe.sa.jdoe.myshellapp
    $ ls
    APX-INF run.sh

  2. Open the run.sh file in a text editor such as vi.

  3. Replace the contents of run.sh with the following lines:

    echo "This is a simple APX that uses apxprogress."
     
    totalsteps=100
    apxprogress -i $totalsteps -c 1
    for i in `seq $totalsteps`; do
    	apxprogress -c $i -m "myshellapx is running, working on step $i" #-d
    	sleep 10
    done

    These apxprogress commands specify that the APX has 100 steps and it calls apxprogress 100 times, once for each step, waiting ten seconds between calls. For more information, see Show the progress of an APX.

    For debugging, you can change “#-d” to “-d” and run the shell script manually to display the output from the apxprogress commands on stdout.

  4. Save the run.sh file and exit the text editor.

  5. Publish the modified APX.

    The following apxtool import command loads the new version of the APX and sets the current version to 2. The -F option suppresses the confirmation prompts.

    $ apxtool import -f "/home/jdoe/myshellapp" \
    -c --version=2 -F
    Info: Successfully published a new version '2' for APX 'myshellapp'
    Info: Successfully set APX 'myshellapp'(20001) current version as '2'.


Running the modified APX

Now that you have modified and republished the APX, run it from the SA Client as before.

  1. In the SA Client, use the View >Refresh menu to refresh the view of the program extensions, which should now show version 2 of myshellapp.
  2. Select your APX.
  3. Select the Actions > Run menu item. This displays the Run Program Extension wizard.
  4. Select Next.
  5. Select Start Job.

Viewing the APX progress in the Twister interface

The apxprogress commands report the progress of the running APX. You can obtain this progress information by calling the API method JobService.getProgress(). This section shows you how to run this method from the Twister interface. For more information on the Twister interface to the SA API, see API Documentation and the Twister.

  1. In the SA Client, select the Jobs and Sessions tab.
  2. Locate your APX in the list of jobs.
  3. Note the Job ID number of your APX job. You will use this in a later step.
  4. Run the SA Twist interface by entering the following URL into a web browser:

    https://<core_host>:1032

    where <core_host> is the IP address or host name of your SA core server. This displays the Twist interface to the SA API in the web browser.
  5. Select the “Twister” link. This displays the Twister interface to the SA API where you can get complete information about API interfaces, packages and methods and where you can run methods.
  6. Locate and select the JobService interface, which is in the com.opsware.job package.
  7. Scroll down and locate the getProgress() method.
  8. Select the Try It button just above the getProgress() method.
  9. Enter your SA credentials.
  10. Select Login.
  11. In the “id” field, enter the job number of your running APX, from step 3 above.
  12. Select Go. This calls the getProgress() method and displays the current progress information about your APX from the apxprogress command, as shown below. Notice that the total number of steps is 100 and the number of completed steps is 94 in this snapshot. For more information on the output from the getProgress() method, see the Javadocs documentation by selecting the getProgress() method in the navigation pane of the Twister web browser.