Class BaseSolarPkgPlatformPackageService
java.lang.Object
net.solarnetwork.node.service.support.BasePlatformPackageService
net.solarnetwork.node.service.support.BaseSolarPkgPlatformPackageService
- All Implemented Interfaces:
PlatformPackageService
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.
installname [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-installedname- 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. Theinstalledcolumn 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. Theinstalledcolumn 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. Theinstalledcolumn contains (true in all cases. list-upgradable- List upgradable packages. The output is a CSV table of columns:
name, version, installed. Theinstalledcolumn contains (false in all cases. refresh- Refresh the available packages from remote repositories.
removename- 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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe "solarpkg" actions.Nested classes/interfaces inherited from interface net.solarnetwork.node.service.PlatformPackageService
PlatformPackageService.PlatformPackage, PlatformPackageService.PlatformPackageResult<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default value for thecommandproperty.static final longThe default package timeout value.Fields inherited from class net.solarnetwork.node.service.support.BasePlatformPackageService
log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncleanup()Cleanup any temporary or cached data.executeCommand(List<String> cmd) Execute an OS command.protected <T> PlatformPackageService.PlatformPackageResult<T> executePackageCommand(List<String> cmd, T context) Execute an OS command that prints out file paths.Get the OS command for the package helper program to use.longGet the timeout, in seconds, to use for package actions.installNamedPackage(String name, String version, Path baseDirectory, net.solarnetwork.service.ProgressListener<T> progressListener, T context) Install a package.installPackage(Path archive, Path baseDirectory, net.solarnetwork.service.ProgressListener<T> progressListener, T context) Install a package from an archive file.listNamedPackages(String nameFilter, Boolean installedFilter) List named packages, optionally filtering by name and installed status.List upgradable named packages.pkgCommand(BaseSolarPkgPlatformPackageService.Action action, String... args) Get an OS command to run, based on the configuredcommandprogram, an action verb, and optional arguments.Refresh named packages.removeNamedPackage(String name, net.solarnetwork.service.ProgressListener<T> progressListener, T context) Remove a named package.voidsetCommand(String command) Set the OS command for the package helper program to use.voidsetPackageActionTimeoutSecs(long packageActionTimeoutSecs) Set a timeout, in seconds, to use for package actions.upgradeNamedPackages(net.solarnetwork.service.ProgressListener<T> progressListener, T context) Upgrade all installed packages.Methods inherited from class net.solarnetwork.node.service.support.BasePlatformPackageService
getTaskExecutor, performPackageResultTask, performTask, setTaskExecutor, taskExecutorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.solarnetwork.node.service.PlatformPackageService
handlesPackage
-
Field Details
-
DEFAULT_COMMAND
The default value for thecommandproperty. -
DEFAULT_PACKAGE_ACTION_TIMEOUT_SECS
public static final long DEFAULT_PACKAGE_ACTION_TIMEOUT_SECSThe default package timeout value.
-
-
Constructor Details
-
BaseSolarPkgPlatformPackageService
public BaseSolarPkgPlatformPackageService()Default constructor.
-
-
Method Details
-
pkgCommand
Get an OS command to run, based on the configuredcommandprogram, an action verb, and optional arguments.- Parameters:
action- the action verbargs- 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 executecontext- the context- Returns:
- the result
- Throws:
Exception- if an error occurs
-
executeCommand
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:PlatformPackageServiceInstall a package from an archive file.- Type Parameters:
T- the context object type- Parameters:
archive- the package to extract and installbaseDirectory- a "base" directory to resolve relative file paths againstprogressListener- an optional listener of the progress of extracting the packagecontext- a context object to pass toprogressListenerand 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:PlatformPackageServiceList named packages, optionally filtering by name and installed status.- Parameters:
nameFilter- a regular expression to filter packages by, or null to include everythinginstalledFilter- true to include only installed packages, false to exclude installed packages, or null to include everything- Returns:
- the matching packages, never null
-
listUpgradableNamedPackages
Description copied from interface:PlatformPackageServiceList 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:PlatformPackageServiceInstall 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 installversion- the package version to install, or null for the highest available versionbaseDirectory- a "base" directory to resolve relative file paths againstprogressListener- an optional listener of the progress of extracting the packagecontext- a context object to pass toprogressListenerand 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:PlatformPackageServiceRemove 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 installprogressListener- an optional listener of the progress of extracting the packagecontext- a context object to pass toprogressListenerand 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:PlatformPackageServiceUpgrade 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 packagecontext- a context object to pass toprogressListenerand provide in the result; may be null- Returns:
- a future for the package installation results
-
refreshNamedPackages
Description copied from interface:PlatformPackageServiceRefresh named packages.- Returns:
- the task completion status
-
cleanup
Description copied from interface:PlatformPackageServiceCleanup any temporary or cached data.- Returns:
- the task completion status
-
getCommand
Get the OS command for the package helper program to use.- Returns:
- the OS command; defaults to
DEFAULT_COMMAND
-
setCommand
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
-