org.rhq.enterprise.server.plugins.url
Class UrlProvider

java.lang.Object
  extended by org.rhq.enterprise.server.plugins.url.UrlProvider
All Implemented Interfaces:
ContentProvider, PackageSource
Direct Known Subclasses:
HttpProvider

public class UrlProvider
extends java.lang.Object
implements ContentProvider, PackageSource

This is a basic implementation of a content source that provides primative package synchronization with a URL-based content source, such as an HTTP server. In order for this URL content source to properly scan and find content in the remote server, an index file must exist that provides metadata about each file. There are two forms of the index metadata file. The simple form is a list of each file relative to the root URL location. This index file can include paths to subdirectories under the root URL. The index file must be named "content-index.txt" unless overridden by the content source's configuration setting. The metadata stored in this simple index file describes the packages. Each line in the simple index file must be a single filename, followed by the MD5 of the files:

 release-v1.0.zip|abe347586edbc6723461253457687bef
 release-v2.0.zip|456834fed6edb3452346125345768723d
 patches/patch-123.jar|56bc47586e5456edfb6a2534e7687345
 patches/patch-4567.jar|dcb567886eabc6723461253457687bef
 
Note that this is a very inefficient type of content source because of the lack of metadata. Because the only thing we know is the URL to a piece of content and nothing else, the only way to determine things like version number is to possible download the content to scan it. The other index file supported is an XML file that contains the full set of metadata needed to fully define a package. Its XML file has a schema - look at the schema for the full syntax. Subclasses can override this class if they want to support more full-featured metadata (for example, an RSS feed found at the index URL). The index file can be specified as a full URL - if it is not, it will be assumed relative to the root URL.

Author:
John Mazzitelli

Constructor Summary
UrlProvider()
           
 
Method Summary
protected  ContentProviderPackageDetails createPackage(RemotePackageInfo rpi)
          Created the package details given the remote package information.
protected  RemotePackageInfo.SupportedPackageType determinePackageType(RemotePackageInfo rpi)
           
protected  ContentProviderPackageDetails findPackage(java.util.List<ContentProviderPackageDetails> packages, ContentProviderPackageDetails pkg)
           
protected  java.io.InputStream getIndexInputStream()
          Returns the stream that contains the index file content.
protected  java.net.URL getIndexUrl()
           
 java.io.InputStream getInputStream(java.lang.String location)
           
protected  java.util.Map<java.lang.String,RemotePackageInfo> getRemotePackageInfosFromIndex()
          Returns info on all the files listed in the index file.
protected  java.net.URL getRootUrl()
           
protected  java.lang.String getRootUrlString()
          Returns a stringified version of root URL that is used to build a full URL to content.
protected  java.util.Map<java.lang.String,RemotePackageInfo.SupportedPackageType> getSupportedPackageTypes()
           
 void initialize(Configuration configuration)
           
protected  void initializePackageTypes(Configuration config)
           
protected  void setIndexUrl(java.net.URL indexURL)
           
protected  void setRootUrl(java.net.URL url)
           
protected  void setSupportedPackageTypes(java.util.Map<java.lang.String,RemotePackageInfo.SupportedPackageType> supportedPackageTypes)
           
 void shutdown()
           
 void synchronizePackages(java.lang.String repoName, PackageSyncReport report, java.util.Collection<ContentProviderPackageDetails> existingPackages)
           
protected  void syncPackage(PackageSyncReport report, java.util.List<ContentProviderPackageDetails> packages, RemotePackageInfo rpi)
          Builds up the report of packages by adding to it the content that is being processed.
 void testConnection()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UrlProvider

public UrlProvider()
Method Detail

getRootUrlString

protected java.lang.String getRootUrlString()
Returns a stringified version of root URL that is used to build a full URL to content. This will be ensured to end with a "/".

Returns:
root URL string that ends with a trailing "/".

getRootUrl

protected java.net.URL getRootUrl()

setRootUrl

protected void setRootUrl(java.net.URL url)

getIndexUrl

protected java.net.URL getIndexUrl()

setIndexUrl

protected void setIndexUrl(java.net.URL indexURL)

getSupportedPackageTypes

protected java.util.Map<java.lang.String,RemotePackageInfo.SupportedPackageType> getSupportedPackageTypes()

setSupportedPackageTypes

protected void setSupportedPackageTypes(java.util.Map<java.lang.String,RemotePackageInfo.SupportedPackageType> supportedPackageTypes)

initialize

public void initialize(Configuration configuration)
                throws java.lang.Exception
Specified by:
initialize in interface ContentProvider
Throws:
java.lang.Exception

shutdown

public void shutdown()
Specified by:
shutdown in interface ContentProvider

synchronizePackages

public void synchronizePackages(java.lang.String repoName,
                                PackageSyncReport report,
                                java.util.Collection<ContentProviderPackageDetails> existingPackages)
                         throws java.lang.Exception
Specified by:
synchronizePackages in interface PackageSource
Throws:
java.lang.Exception

testConnection

public void testConnection()
                    throws java.lang.Exception
Specified by:
testConnection in interface ContentProvider
Throws:
java.lang.Exception

getInputStream

public java.io.InputStream getInputStream(java.lang.String location)
                                   throws java.lang.Exception
Specified by:
getInputStream in interface PackageSource
Throws:
java.lang.Exception

getIndexInputStream

protected java.io.InputStream getIndexInputStream()
                                           throws java.lang.Exception
Returns the stream that contains the index file content.

Returns:
index file content stream
Throws:
java.lang.Exception

getRemotePackageInfosFromIndex

protected java.util.Map<java.lang.String,RemotePackageInfo> getRemotePackageInfosFromIndex()
                                                                                    throws java.lang.Exception
Returns info on all the files listed in the index file.

Returns:
map of Strings/Infos, where each string is the location relative to the root URL. Each string in the map keys is guaranteed not to have a leading slash.
Throws:
java.lang.Exception - if the index file is missing or cannot be processed

syncPackage

protected void syncPackage(PackageSyncReport report,
                           java.util.List<ContentProviderPackageDetails> packages,
                           RemotePackageInfo rpi)
                    throws java.lang.Exception
Builds up the report of packages by adding to it the content that is being processed. As content is found, their associated packages are removed from packages if they exist leaving only packages remaining that do not exist on the remote system.

Parameters:
report - the report that we are building up
packages - existing packages not yet found on the remote system but exist in server inventory
rpi - information about the package that needs to be synced
Throws:
java.lang.Exception - if the sync fails

createPackage

protected ContentProviderPackageDetails createPackage(RemotePackageInfo rpi)
                                               throws java.lang.Exception
Created the package details given the remote package information.

Parameters:
rpi - information about the remote package
Returns:
the full details about the package
Throws:
java.lang.Exception

findPackage

protected ContentProviderPackageDetails findPackage(java.util.List<ContentProviderPackageDetails> packages,
                                                    ContentProviderPackageDetails pkg)

initializePackageTypes

protected void initializePackageTypes(Configuration config)

determinePackageType

protected RemotePackageInfo.SupportedPackageType determinePackageType(RemotePackageInfo rpi)


Copyright © 2008-2009 Red Hat, Inc.. All Rights Reserved.