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.
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.
The plugin-descriptor.xml defines the sample plug-in. Look at the following items in the example below:
Most attributes to the <plugin> element use standard values. The two exceptions are the name and version attributes.
The <dependencyList> element tells you that the system plug-in, version 1.0 is required for the sample plug-in to work correctly. The system plug-in is a core part of the N1 Grid Service Provisioning System software and should always exist.
The <folder> element creates a folder in which Linux objects can be stored.
The <component> element defines a component type whose backing component is 1.0/components/com/sun/linux/RPM CT.xml.
<?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>
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:
The path, name, description, and platform attributes to the <component> element provide specific information about the component type.
The <extends> element tells you that the RPM component type extends the features available in the system#CR Simple Base component type.
The <varlist> element defines several variables that enable the user to customize components based on this component type.
The <installList> element calls the <exceNative> step to run the Linux command to install the RPM files.
The <uninstallList> element calls the <exceNative> step to run the Linux command to uninstall the RPM files.
<?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>