N1 Grid Service Provisioning System 5.0 Plug-in Development Guide

Appendix A Example Plug-In

This appendix contains example code for a simple plug-in. This sample is based on the Linux plug-in, which is provided with the N1 Grid Service Provisioning System 5.0 software.

Description of the Sample Plug-In

The sample plug-in includes the following files and directories in the com.sun.linux_1.1.jar file:

META-INF/
META-INF/MANIFEST.MF
plugin-descriptor.xml
1.1/
1.1/components/
1.1/components/com/
1.1/components/com/sun/
1.1/components/com/sun/linux/
1.1/components/com/sun/linux/RPM CT.xml
1.1/resources/
1.1/resources/com/
1.1/resources/com/sun/
1.1/resources/com/sun/linux/
1.1/resources/com/sun/linux/plugin-linux.jar
1.1/plans/

The sample plug-in does not include a pluginUI.xml because the Linux plug-in does not provide a customized interface page. For an example of a plug-in interface file, see Example 2–16.

Plug-In Descriptor File

The plugin-descriptor.xml defines the sample plug-in. Look at the following items in the example below:

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.sun.com/schema/SPS"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.sun.com/schema/SPS ../plugin.xsd"
  name="com.sun.linux"
  vendor="Sun Microsystems"
  version="1.1"
  schemaVersion="5.0">

  <dependencyList> 
    <pluginRef name="system" version="1.0"/>
  </dependencyList>

  <memberList>
    <!-- Folders -->
    
    <folder name="/com/sun/linux" 
        description="contains linux plugin objects"/>

    <!-- Components -->
    
    <component jarPath="1.0/components/com/sun/linux/RPM CT.xml">
      <componentType name="rpm file" 
         description="the active component type for rpm files"
         group="any UNIX"
         order="000700-000100-000200"
         indentLevel="1"/>
    </component>

  </memberList>
</plugin>

Components

The sample plug-in contains the RPM CT.xml file in the components directory. This file defines the backing component for the rpm component type, and is not expected to be used directly as a component itself. Look at the following items in the example below:

<?xml version="1.0" encoding="UTF-8"?>
<component xmlns="http://www.sun.com/schema/SPS"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    version="5.0"
    xsi:schemaLocation="http://www.sun.com/schema/SPS
                    component.xsd"
    modifier="ABSTRACT"
    path="/com/sun/linux"
    name="RPM CT"
    description="RPM Installer"
    platform="system#Red Hat Linux - any version">

    <extends>
        <type name="system#CR Simple Base"/>
    </extends>

    <varList>
        <var name="filterName" default="rpmOnly" access="PRIVATE"/>
        <var name="filterDescription" 
            default="show RPM file types only (.rpm)" 
            access="PRIVATE"/>
        <var name="filterExtensions" default=".rpm" access="PRIVATE"/>
        <var name="rpmCmd" default="rpm"/>
        <var modifier="FINAL" name="installDeployMode" default="REPLACE"/>
        <var name="installDiffDeploy" default="TRUE"/>
        <var access="PRIVATE" name="exporterClassName" 
             default="com.sun.n1.sps.pluginimpl.system.export.FilesystemExporter"/>
        <var access="PRIVATE" name="canBeConfigTemplate" default="FALSE"/>
    </varList>

    <installList>
        <installSteps name="default">
            <deployResource/>
            <execNative userToRunAs="root">
                <exec cmd=":[rpmCmd]">
                    <arg value="-i"></arg>
                    <arg value=":[sys.rsrcInstallPath]"></arg>
                </exec>
            </execNative>
        </installSteps>
    </installList>

    <uninstallList>
        <uninstallSteps name="default">
            <execNative userToRunAs="root">
                <shell cmd="sh -c">
                     <![CDATA[:[rpmCmd] -e `:[rpmCmd] 
                        -qp :[sys.rsrcInstallPath] 
                        -qf '%{NAME}' 2> /dev/null`]]>
                </shell>
            </execNative>
            <call blockName="deleteFile">
                <argList absPath=":[sys.rsrcInstallPath]"/>
                <systemService name="system#core services"/>
            </call>
        </uninstallSteps>
    </uninstallList>

</component>