public enum Mode {
TEST,
PROD;
// Returns true if this mode trusts the specified node:
public boolean trust(Mode mode);
}
KOS operates in one of two distinct modes: production (PROD) or development/testing (TEST).
Production mode is used for deploying and running the system in a live environment, where reliability and performance are critical.
Test mode is used for developing and debugging the system in a simulated environment, where errors and failures can be detected and fixed without affecting the real users.
Depending on the mode, KOS may have different configurations, behaviors and outputs.
KOS always runs in one of the following modes:
PROD (production)
TEST (development and testing)
The mode is encoded in certificates and KAB files, and therefore allows KOS to determine when to trust artifacts and when not to.
The TEST mode trusts both TEST and PROD components
The PROD mode only trusts PROD components
This section gives the API for modes of operation, which is simply a Mode enum.
Here’s the definition of the Mode enum:
Mode
enumpublic enum Mode {
TEST,
PROD;
// Returns true if this mode trusts the specified node:
public boolean trust(Mode mode);
}
Here’s the unit tests that should make it clear:
Mode
unit testsclass UT_Mode {
@Test
void verify_all() {
// There are exactly two possible modes:
assertThat(Mode.values().length, equalTo(2));
// TEST mode trusts TEST and PROD:
assertThat(Mode.TEST.trust(Mode.TEST), equalTo(true));
assertThat(Mode.TEST.trust(Mode.PROD), equalTo(true));
// PROD mode only trusts PROD:
assertThat(Mode.PROD.trust(Mode.TEST), equalTo(false));
assertThat(Mode.PROD.trust(Mode.PROD), equalTo(true));
// Null is never trusted:
assertThat(Mode.PROD.trust(null), equalTo(false));
assertThat(Mode.TEST.trust(null), equalTo(false));
}
}
Here’s a little example code to demonstrate the mode of operation.
Source code for this and most other Java reference pages is available on GitHub. |
The system mode is easily obtained using the built-in global KosCore object:
ModesModule
classpackage com.example.modes;
import com.example.Module;
import com.tccc.kos.commons.core.context.BeanContext;
import com.tccc.kos.core.app.KosCore;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ModesModule implements Module {
@Override
public void init(BeanContext ctx) {
log.info("> ModesModule.init()");
log.info("> Mode = {}", KosCore.getMode());
log.info("> Mode.isProd() = {}", KosCore.isProd());
log.info("> Mode.isTest() = {}", KosCore.isTest());
}
@Override
public void run() {
log.info("> ModesModule.run()");
}
}
Be sure to make the following change to the MyKosApp
class:
MyKosApp
class modificationpublic class MyKosApp extends SystemApplication<BaseAppConfig> {
public void initModule() {
module = new ModesModule();
}
// . . .
}
Running the above code produces the following output logs:
ModesModule
output> ====== BEGIN =========================================
> MyKosApp.load()
> ModesModule.init()
> KosCore.getMode() = TEST
> KosCore.isProd() = false
> KosCore.isTest() = true
> MyKosApp.start()
> ModesModule.run()
> ====== END ===========================================
Note
When running your KOS application in the Studio simulator, it always runs in TEST mode. |