Want to create a new Mathematical Function/Action?
It's simple! Learn to create customized Mathematical Function/Action in InSights Inference on this page.
In order to run create a new Mathematical Function/Action in InSights Inference, there are changes that should be made in list of files shown on this page. Please adhere the following instructions, and make respective changes -
On this page:
%WORKSPACE% is the directory which contains InSights - Development Platform.
Changes in ConfigAttributes.java
Browse the directory - "%WORKSPACE%\Insights\PlatformInsights\src\main\java\com\cognizant\devops\platforminsights\core\enums\ConfigAttributes.java"
Add the changes in ConfigAttributes.java as highlighted in Red in the below panel.
package com.cognizant.devops.platformcommons.core.enums;
public enum ExecutionActions {
AVERAGE, COUNT, MINMAX, (Add your new Mathematical Function/Action Name here)
}
Writing Java code for Custom Mathematical Function/Action
- Create a new package under "%WORKSPACE%\Insights\PlatformInsights\src\main\java". Use "com.cognizant.devops.platforminsights.core" as base, then append your custom package structure.
- Import "ConfigConstants.java" from the package, and use the constants specified there to code the Mathematical Function/Action such as SPARK_ES_HOST, SPARK_ES_PORT, SPARK_ES_CONFIGINDEX, SPARK_ES_RESULTINDEX etc,.
- Also, please refer to existing Mathematical Function/Action classes such as "CountActionImpl" , "MinMaxActionImpl" etc,. for coding strategies.
- Your new ActionClass must extend BaseActionImp.java, and override execute() method.
ConfigConstants.java class reads/contains the "sparkConfigurations" from server-config.json. To check the changes in server-config, click here.
Changes in SparkJobExecutor.java
Browse the directory - "%WORKSPACE%\Insights\PlatformInsights\src\main\java\com\cognizant\devops\platforminsights\core\SparkJobExecutor.java"
Add the changes in ConfigAttributes.java as highlighted in Red in the below panel.
package com.cognizant.devops.platforminsights.core;
public enum SparkJobExecutor implements Job,Serializable{
...
...
...
private void executeJob(SparkJobConfiguration job) throws InsightsSparkJobFailedException{
KPIDefinition kpiDefinition = job.getKpiDefinition(job.getKpiDefinition());
if(ExecutionActions.AVERAGE == kpiDefinition.getAction()){
log.debug("KPI action found as AVERAGE");
BaseActionImpl impl = new AverageActionImpl(kpiDefinition);
impl.execute();
} else if(ExecutionActions.COUNT == kpiDefinition.getAction()){
log.debug("KPI action found as COUNT");
BaseActionImpl impl = new CountActionImpl(kpiDefinition);
impl.execute();
}
else if(ExecutionActions.MINMAX == kpiDefinition.getAction()){
log.debug("KPI action found as MINMAX");
BaseActionImpl impl = new MinMaxActionImpl(kpiDefinition);
impl.execute();
}
//(Instance of a Custom Mathematical Function/Action)
else if(ExecutionActions.YourCustomActionName == kpiDefinition.getAction()){
log.debug("KPI action found as Your Custom Action name");
BaseActionImpl impl = new YourCustomActionImplementationClassName(kpiDefinition);
impl.execute();
}
}
...
...
...
}