Overview
The Software Repository Script Service gives the opportunity to manage the Software Repository via scripts in the RM framework.
Usage
The Software Repository Script Service is related to the RM Software Repository functionality.
The main (entry-point) interface is ScriptSoftwareRepository which is bound in scripts under the alias "softwareRepository" or the short "sr" alias.
Let's say that we have following task: Update bundles on OSGI device if there is a newer version in the Software Repository.
Choose bundle/s to update
Select the Device on that our script will work on. Choose Device Scope. Define a script:
To select all bundles:
// null filter means alltarget.listOSGiBundles(null)To select particular bundle using filter:
target.listOSGiBundles('(\"manifest\"::\"Bundle-SymbolicName\" == \"com.prosyst.mprm.osgidm.message.client\")')In RM scripting there are predefined global variables e.g. "target", "sr", "log" etc. Be careful and do not rebind them.
Find bundle version on the device
Now we can list bundles (filtered or all). Next step is to find its properties – exploring manifest. As first step let us print all information to find needed keys:
def allBundles = target.listOSGiBundles(null)allBundles.each {println(it.manifest)}and to obtain the bundle versions:
def allBundles = target.listOSGiBundles(null)allBundles.each {println(it.manifest.get('Bundle-Version'))}
Finding bundle/s in Service Repository
Now let's look on Service Repository. We can search Service Repository by 'Content-Id'. If nothing is found null will be returned. Alias that refer Software Repository(SR) in RM scripting is
'sr'or'softwareRepository'.We do not care about bundle capabilities so we pass null togetPlatformBundleFor()method.Here is an example:
def allBundles = target.listOSGiBundles(null)allBundles.each {def currentVersion = it.manifest.get('Bundle-Version')def contentId = it.manifest.get('Content-Id')if(contentId) {def srVersion = sr.getPlatformBundleFor(contentId,null)?.getVersion()println("Software Repository version is ${srVersion}")}}Compare versions
Software Repository interface has method that compares two versions but as additional parameter bundle type should be passed. It returns negative if current version is smaller.
def allBundles = target.listOSGiBundles(null)allBundles.each {def currentVersion = it.manifest.get('Bundle-Version')def contentId = it.manifest.get('Content-Id')if(contentId) {def srVersion = sr.getPlatformBundleFor(contentId,null)?.getVersion()def type = sr.getPlatformBundleFor(contentId,null)?.getConcreteTypeName()if(srVersion && type) {print("\n\nType is '${type}' and version in Software Repository is ${srVersion}.")if(sr.compareVersions(type, currentVersion, srVersion) <0) {println('Start updating...')}}}}Be careful – a lot of methods return null.Install Updates
This is the final step. To be accomplished we have to know how to form URL from the location of the bundle to be installed. In our case this is the Software Repository. URL has the following form mprm://contentId=<bundle contentId>. Take the bundle from device and update it using SR URL.
Here is the final version:
def allBundles = target.listOSGiBundles(null)println('\nStart bundle update procedure')allBundles.each {def currentVersion = it.manifest.get('Bundle-Version')def contentId = it.manifest.get('Content-Id')if(contentId) {def srVersion = sr.getPlatformBundleFor(contentId,null)?.getVersion()def type = sr.getPlatformBundleFor(contentId,null)?.getConcreteTypeName()if(srVersion && type) {print("\n\nType is '${type}' and version in Software Repository is ${srVersion}.")if(sr.compareVersions(type, currentVersion, srVersion) <0) {String bundleSRLocation ="mprm://contentId="+ contentIdprintln("\nNew version is available at ${bundleSRLocation}. Start updating from ${currentVersion} to ${srVersion}...")// NOTE: some system bundles e.g. bundles related to transport are not allowed to be upgradeddef bundleToUpgrade = target.getOSGiBundle(it.getId())bundleToUpgrade.update(bundleSRLocation,false)}else{println(" - current ${currentVersion} .... skip update!")}}}}println('\nDone! Target is up to date.')
The Groovy Script is as follows:
def bundleSRLocation = "mprm://contentId=${contentId}"Have in mind that this is a GString and target.installBundle(bundleSRLocation, false, true) will complain.
API Reference
Software Repository Script Service API documentation is available here