OGEMA Console Command Implementation

Last modified by David Nestle on 2019/03/02 10:36

Introduction

Besides GUI implementations via the OGEMA widget framework console commands are another standard way for administration access to applications. For systems with a weak communication / internet connection or other restrictions regarding web GUI access console commands are the core tool for administration.

Console Access Implementation

There are two usual ways to implement console commands. The first and simpler options provides a class that declares to register the required service via annotations. This requires a constructor without arguments - references to the application accessed via console usually have to be provided via static variables if not available as OSGi service itself. The second and more flexible/recommended way is to register the service explicitly. This needs some more support from the app providing the console access.

Example for simple service definition:

@Component(specVersion = "1.2")
@Properties( {
@Property(name = "osgi.command.scope", value = "logtransfer"),
@Property(name = "osgi.command.function", value = { "sendlogs", "setlastupdatetime" })
})
@Service(ShellCommandsLTS.class)
@Descriptor("Log transfer commands")
public class ShellCommandsLTS {

public static SPLogTransfer app;

   @Descriptor("send new log data now (for testing purposes, blocks while searching for files)")
   public void sendlogs() throws IOException {
        app.logTransfer.transferNewLogs();
    }
   
   @Descriptor("set the last update time for all series")
   public void setlastupdatetime(@Descriptor("full ISO8601 format") String iso8601datetime) {
        ZonedDateTime time = ZonedDateTime.parse(iso8601datetime);
        app.logTransfer.getLogs().forEach(s -> s.setLastTransferTime(time.toInstant().toEpochMilli()));
   }
}

Example for recommended implementation:

See activate-logmodus/ShellCommandsLTS .

 

Tags:
Created by David Nestle on 2019/03/01 19:38