Class BaseSolarPkgPlatformPackageService

java.lang.Object
net.solarnetwork.node.service.support.BasePlatformPackageService
net.solarnetwork.node.service.support.BaseSolarPkgPlatformPackageService
All Implemented Interfaces:
PlatformPackageService

public abstract class BaseSolarPkgPlatformPackageService extends BasePlatformPackageService
Base implementation of PlatformPackageService, with support for using an OS-level helper program that adheres to a solarpkg API.

The solarpkg program API follows this simple pattern:

 solarpkg <action> [arguments...]
 

All invocations are expected to return a status code 0 on success. All "return" values are printed to STDOUT. The action values include:

clean
Remove any cached download packages or temporary files. Remove any packages no longer required by other packages.
install name [version]
Install package name. If name appears to be the path to a package file, then install the specific package file. Otherwise, download and install name from some OS-configured package repository; if version specified then install the specific version.
is-installed name
Test if a particular package is installed. Returns true or false.
list [name]
List packages. If name is provided, only packages matching this name (including wildcards) will be listed. The output is a CSV table of columns: name, version, installed. The installed column contains (true if the package is currently installed, or false otherwise.
list-available [name]
List packages available to be installesd. If name is provided, only packages matching this name (including wildcards) will be listed. The output is a CSV table of columns: name, version, installed. The installed column contains (false in all cases.
list-installed [name]
List installed packages. If name is provided, only packages matching this name (including wildcards) will be listed. The output is a CSV table of columns: name, version, installed. The installed column contains (true in all cases.
list-upgradable
List upgradable packages. The output is a CSV table of columns: name, version, installed. The installed column contains (false in all cases.
refresh
Refresh the available packages from remote repositories.
remove name
Remove the installed package name.
upgrade [major]
Upgrade all packages. If major defined, then perform a "major" upgrade, allowing for more aggressive upgrading.
Since:
2.0
Version:
1.1
Author:
matt
  • Field Details

    • DEFAULT_COMMAND

      public static final String DEFAULT_COMMAND
      The default value for the command property.
    • DEFAULT_PACKAGE_ACTION_TIMEOUT_SECS

      public static final long DEFAULT_PACKAGE_ACTION_TIMEOUT_SECS
      The default package timeout value.
  • Constructor Details

    • BaseSolarPkgPlatformPackageService

      public BaseSolarPkgPlatformPackageService()
      Default constructor.
  • Method Details

    • pkgCommand

      protected List<String> pkgCommand(BaseSolarPkgPlatformPackageService.Action action, String... args)
      Get an OS command to run, based on the configured command program, an action verb, and optional arguments.
      Parameters:
      action - the action verb
      args - the arguments
      Returns:
      the command as a list
    • executePackageCommand

      protected <T> PlatformPackageService.PlatformPackageResult<T> executePackageCommand(List<String> cmd, T context) throws Exception
      Execute an OS command that prints out file paths.
      Type Parameters:
      T - the context type
      Parameters:
      cmd - the command to execute
      context - the context
      Returns:
      the result
      Throws:
      Exception - if an error occurs
    • executeCommand

      protected List<String> executeCommand(List<String> cmd) throws Exception
      Execute an OS command.
      Parameters:
      cmd - the command to execute
      Returns:
      the STDOUT result
      Throws:
      Exception - if an error occurs
    • installPackage

      public <T> Future<PlatformPackageService.PlatformPackageResult<T>> installPackage(Path archive, Path baseDirectory, net.solarnetwork.service.ProgressListener<T> progressListener, T context)
      Description copied from interface: PlatformPackageService
      Install a package from an archive file.
      Type Parameters:
      T - the context object type
      Parameters:
      archive - the package to extract and install
      baseDirectory - a "base" directory to resolve relative file paths against
      progressListener - an optional listener of the progress of extracting the package
      context - a context object to pass to progressListener and provide in the result; may be null
      Returns:
      a future for the package installation results
    • listNamedPackages

      public Future<Iterable<PlatformPackageService.PlatformPackage>> listNamedPackages(String nameFilter, Boolean installedFilter)
      Description copied from interface: PlatformPackageService
      List named packages, optionally filtering by name and installed status.
      Parameters:
      nameFilter - a regular expression to filter packages by, or null to include everything
      installedFilter - true to include only installed packages, false to exclude installed packages, or null to include everything
      Returns:
      the matching packages, never null
    • listUpgradableNamedPackages

      public Future<Iterable<PlatformPackageService.PlatformPackage>> listUpgradableNamedPackages()
      Description copied from interface: PlatformPackageService
      List upgradable named packages.
      Returns:
      the upgradable packages, never null
    • installNamedPackage

      public <T> Future<PlatformPackageService.PlatformPackageResult<T>> installNamedPackage(String name, String version, Path baseDirectory, net.solarnetwork.service.ProgressListener<T> progressListener, T context)
      Description copied from interface: PlatformPackageService
      Install a package.

      This method is used to install named packages that are "available" to be installed, i.e. one that is returned from the PlatformPackageService.listNamedPackages(String, Boolean) method when false is passed. The package might have to be downloaded from a remote package repository and then installed.

      Type Parameters:
      T - the context object type
      Parameters:
      name - the package name to install
      version - the package version to install, or null for the highest available version
      baseDirectory - a "base" directory to resolve relative file paths against
      progressListener - an optional listener of the progress of extracting the package
      context - a context object to pass to progressListener and provide in the result; may be null
      Returns:
      a future for the package installation results
    • removeNamedPackage

      public <T> Future<PlatformPackageService.PlatformPackageResult<T>> removeNamedPackage(String name, net.solarnetwork.service.ProgressListener<T> progressListener, T context)
      Description copied from interface: PlatformPackageService
      Remove a named package.

      This method is used to remove named packages that are currently installed.

      Type Parameters:
      T - the context object type
      Parameters:
      name - the package name to install
      progressListener - an optional listener of the progress of extracting the package
      context - a context object to pass to progressListener and provide in the result; may be null
      Returns:
      a future for the package installation results
    • upgradeNamedPackages

      public <T> Future<PlatformPackageService.PlatformPackageResult<T>> upgradeNamedPackages(net.solarnetwork.service.ProgressListener<T> progressListener, T context)
      Description copied from interface: PlatformPackageService
      Upgrade all installed packages.

      This method is used to upgrade named packages to the highest available versions.

      Type Parameters:
      T - the context object type
      Parameters:
      progressListener - an optional listener of the progress of extracting the package
      context - a context object to pass to progressListener and provide in the result; may be null
      Returns:
      a future for the package installation results
    • refreshNamedPackages

      public Future<Boolean> refreshNamedPackages()
      Description copied from interface: PlatformPackageService
      Refresh named packages.
      Returns:
      the task completion status
    • cleanup

      public Future<Boolean> cleanup()
      Description copied from interface: PlatformPackageService
      Cleanup any temporary or cached data.
      Returns:
      the task completion status
    • getCommand

      public String getCommand()
      Get the OS command for the package helper program to use.
      Returns:
      the OS command; defaults to DEFAULT_COMMAND
    • setCommand

      public void setCommand(String command)
      Set the OS command for the package helper program to use.
      Parameters:
      command - the OS command
    • getPackageActionTimeoutSecs

      public long getPackageActionTimeoutSecs()
      Get the timeout, in seconds, to use for package actions.
      Returns:
      the seconds; defaults to DEFAULT_PACKAGE_ACTION_TIMEOUT_SECS
    • setPackageActionTimeoutSecs

      public void setPackageActionTimeoutSecs(long packageActionTimeoutSecs)
      Set a timeout, in seconds, to use for package actions.
      Parameters:
      packageActionTimeoutSecs - the timeout to use