Classes | |
interface | OtaUpdater |
OtaUpdater. More... | |
class | OtaUpdaterChannel |
OtaUpdaterChannel channel information. More... | |
interface | OtaUpdaterEvent |
OtaUpdater event. More... | |
class | OtaUpdaterLowLevelException |
OtaUpdater low level exception. More... | |
interface | OtaUpdaterManager |
OtaUpdater Manager. More... | |
class | OtaUpdaterNotAvailableException |
OtaUpdater not available exception. More... | |
class | OtaUpdaterObserver |
OtaUpdater observer. More... | |
class | OtaUpdaterPackage |
OtaUpdaterPackage ota updater class defining a package. More... | |
class | OtaUpdaterStatus |
interface | OtaUpdaterStatusEvent |
Detailed Description
;
To work with Deepsy ota updater service it is necessary to use DeepsyOtaUpdaterManager located in com.gmv.its.deepsy.otaupdater to obtain the initial OtaUpdater object.
OtaUpdaterManager.getInstance has an optional parameter indicating the ip address of remote service. For instance:
OtaUpdaterManager is an AutoCloseable interface. An object that may hold resources (such as file or socket handles) until it is closed. The close() method of an AutoCloseable object is called automatically when exiting a try-with-resources block for which the object has been declared in the resource specification header. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur. To obtain an OTA object:
If this object is not inside a try with resources block, it is recommended to call to OtaUpdaterManager.close() in order to finalize properly;
Service availability
To detect service availability the DeepsyOtaUpdaterManager implements Manager interface which provides methods for getting availability and subscribing to availability events.
Examples
-
Retrieve version from existing packages in the system , both in current and alternative RFS /B>
package com.gmv.its.dpyjavaexamples.otaupdater;import java.util.List;public class GetVersionsApp {public static void main(String[] args) {DeepsyOtaUpdaterManager otaManager = DeepsyOtaUpdaterManager.getInstance();try {OtaUpdater ota = otaManager.getOtaUpdater();System.out.println("Retrieving packages ...");List<OtaUpdaterPackage> packages = ota.getPackagesVersion();System.out.println("Package Current RFS version Alternative RFS version");for (OtaUpdaterPackage otapackage : packages) {System.out.println(otapackage.getName() + " " + otapackage.getVersionCurrentRfs() + " " + otapackage.getVersionAlternativeRfs());}} catch (Exception e) {System.out.println(e.getMessage());}}}
-
Add a custom channel to perform updates and retrieve the channel list /B>
package com.gmv.its.dpyjavaexamples.otaupdater;import java.util.List;public class AddChannelApp {public static void main(String[] args) {DeepsyOtaUpdaterManager otaManager = DeepsyOtaUpdaterManager.getInstance();try {OtaUpdater ota = otaManager.getOtaUpdater();ota.addChannel(new OtaUpdaterChannel("mychannel", "rpm-md","http://myrepochannelurl"));System.out.println("List of channels");List<OtaUpdaterChannel> channelList = ota.getChannels();for (OtaUpdaterChannel channel : channelList) {System.out.println(channel.toString());}} catch (Exception e) {System.out.println(e.getMessage());}// If manager object is not inside a try with resources block, it is necessary to call to .close() in order to finalize properly;otaManager.close();}}
-
Retrieve available updates for the existing channels /B>
In order to obtain the available updates it is needed to add at least channel to synchronize with. After this, get the current status of the system and check available updates on the existing channels.package com.gmv.its.dpyjavaexamples.otaupdater;import java.util.Map;class MyOtaUpdaterApp extends OtaUpdaterObserver {public MyOtaUpdaterApp() {this.currentStatus = new OtaUpdaterStatus(OtaUpdaterStatus.ServiceStatus.IDLE,OtaUpdaterStatus.AltRfsStatus.OK);try {otaManager = DeepsyOtaUpdaterManager.getInstance("192.168.0.144");ota = otaManager.getOtaUpdater();ota.subscribe(this);ota.addChannel(new OtaUpdaterChannel("deepsy", "rpm-md","http://172.22.196.105/download/yocto/sumo/builds/ep100/tmp/deploy/rpm/"));} catch (Exception e) {System.out.println(e.getMessage());}}private OtaUpdaterStatus currentStatus;private DeepsyOtaUpdaterManager otaManager;private OtaUpdater ota;public OtaUpdaterStatus getCurrentStatus() {return currentStatus;}public void updateStatus() throws OtaUpdaterNotAvailableException, OtaUpdaterLowLevelException {this.currentStatus = ota.getStatus();}@Overridepublic void notifyNewStatus(OtaUpdaterStatusEvent event) {this.currentStatus = event.getStatus();System.out.println(this.currentStatus.toString());}public void sync() throws OtaUpdaterNotAvailableException, OtaUpdaterLowLevelException {ota.repoSync();}public Map<String, String> getUpdates() throws OtaUpdaterNotAvailableException, OtaUpdaterLowLevelException {return ota.getUpdates();}}public class GetAvailableUpdatesApp {public static void main(String[] args) {try {MyOtaUpdaterApp app = new MyOtaUpdaterApp();app.updateStatus();System.out.println(app.getCurrentStatus().toString());// Execute sync, status should change to SYNCHRONIZINGapp.sync();app.updateStatus();System.out.println(app.getCurrentStatus().toString());// Wait for synchronization to finishwhile (app.getCurrentStatus().getServiceStatus() == OtaUpdaterStatus.ServiceStatus.SYNCHRONIZING) {System.out.println("Waiting for synchronization with package repo...");Thread.sleep(5000);}// Retrieve available updates after syncMap<String, String> updatesList = app.getUpdates();if(updatesList.size() > 0) {System.out.println("Packages available to update");System.out.println("Package Name Version");for (Map.Entry<String, String> entry : updatesList.entrySet()) {System.out.println(entry.getKey() + " " + entry.getValue());}}else {System.out.println("No updates available");}} catch (Exception e) {System.out.println(e.getMessage());}}}
-
Retrieve available remote updates for the existing package/s /B>
In order to obtain the available remote updates it is needed to add at least channel to synchronize with. After this, get the current status of the system and check available updates on the existing channels. This example retrieves the current remote updates of mcu firmware of uc100 equipment.package com.gmv.its.dpyjavaexamples.otaupdater;import java.util.List;import java.util.Arrays;import java.util.Map;import java.util.AbstractMap;class RemoteUpdatesApp extends OtaUpdaterObserver {public RemoteUpdatesApp() {this.currentStatus = new OtaUpdaterStatus(OtaUpdaterStatus.ServiceStatus.IDLE,OtaUpdaterStatus.AltRfsStatus.OK);try {otaManager = DeepsyOtaUpdaterManager.getInstance("192.168.0.125");ota = otaManager.getOtaUpdater();ota.subscribe(this);} catch (Exception e) {System.out.println(e.getMessage());}}private OtaUpdaterStatus currentStatus;private DeepsyOtaUpdaterManager otaManager;private OtaUpdater ota;public OtaUpdaterStatus getCurrentStatus() {return currentStatus;}public void updateStatus() throws OtaUpdaterNotAvailableException, OtaUpdaterLowLevelException {this.currentStatus = ota.getStatus();}@Overridepublic void notifyNewStatus(OtaUpdaterStatusEvent event) {this.currentStatus = event.getStatus();System.out.println(this.currentStatus.toString());}public void sync() throws OtaUpdaterNotAvailableException, OtaUpdaterLowLevelException {ota.repoSync();}public List<AbstractMap.SimpleEntry<String, String>> getRemoteVersions(List<String> packageList) throws OtaUpdaterNotAvailableException, OtaUpdaterLowLevelException {return ota.getRemoteVersions(packageList);}}public class GetRemoteUpdatesApp {public static void main(String[] args) {try {RemoteUpdatesApp app = new RemoteUpdatesApp();app.updateStatus();System.out.println(app.getCurrentStatus().toString());// Execute sync, status should change to SYNCHRONIZINGapp.sync();app.updateStatus();System.out.println(app.getCurrentStatus().toString());// Wait for synchronization to finishwhile (app.getCurrentStatus().getServiceStatus() == OtaUpdaterStatus.ServiceStatus.SYNCHRONIZING) {System.out.println("Waiting for synchronization with package repo...");Thread.sleep(5000);}List<String> packageList = Arrays.asList("deepsy-19.10");// Retrieve available updates after syncList<AbstractMap.SimpleEntry<String, String>> remotePackagesList = app.getRemoteVersions(packageList);if(remotePackagesList.size() > 0) {System.out.println("Packages available to update");System.out.println("Package Name Version");for (AbstractMap.SimpleEntry<String, String> entry : remotePackagesList) {System.out.println(entry.getKey() + " " + entry.getValue());}}else {System.out.println("No remote updates available");}} catch (Exception e) {System.out.println(e.getMessage());}}}