Managing PMML models
The Predictive Analytics Plug-in supports adding, updating, activating, and removing a PMML model at runtime.
To add, update, activate or remove a model in an EPL script
1. The Predictive Analytics Plug-in also supports managing resources at runtime through ModelManager API. ModelManager API can be accessed by calling getModelManager() on the ServiceHandler object received in service initialisation onServiceInitialised callback.
action onServiceInitialised(ServiceHandler servicehandler)
{
ModelManager modelmanager := serviceHandler.getModelManager();
//Add Model1 from PMML_PATH1
modelmanager.addModel("PMML_PATH1");
//Add Model2 from PMML_PATH2
modelmanager.addModel("PMML_PATH2");
...
...
//Update Model1 from another source PMML_PATH3
modelmanager.updateModel("Model1","PMML_PATH3");
...
...
//remove model when done
modelmanager.removeModel("Model1");
modelmanager.removeModel("Model2");
}
Any errors are reported through default callback onServiceError of service handler.
You can add custom callbacks for the above mentioned functions as described below:
action onServiceInitialised(ServiceHandler servicehandler)
{
ModelManager modelmanager := serviceHandler.getModelManager();
//Add Model1 from PMML_PATH1
modelmanager.addModelCb("PMML_PATH1", onStatus);
//Add Model2 from PMML_PATH2
modelmanager.addModelCb("PMML_PATH2", onStatus);
...
...
//Update Model1 from another source PMML_PATH3
modelmanager.updateModelCb("Model1","PMML_PATH3", onStatus);
...
...
//Deactivate Model1
Model model1 := serviceHandler.getModel("Model1")
if(model1.isActive()) {
model1.setActive(false)
}
...
...
//remove model when done
modelmanager.removeModelCb("Model1", onStatus);
modelmanager.removeModelCb("Model2", onStatus);
}
action onStatus(ServiceError serviceError)
{
log "Received status on configured callback:
"+serviceError.getErrorMessage();
}
For more information, refer to the samples at APAMA_HOME/samples/PredictiveAnalytics/EnergyData ModelManager