Creating new Mathematical Functions/Actions

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 ExecutionActions.java


Browse the directory - "%WORKSPACE%\Insights\PlatformInsights\src\main\java\com\cognizant\devops\platforminsights\core\enums\ExecutionActions.java"

Add a new enum in ConfigAttributes.java as highlighted in Red in the below panel.

ExecutionActions.java

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_HOSTSPARK_ES_PORT, SPARK_ES_CONFIGINDEX, SPARK_ES_RESULTINDEX etc,.
  • 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.

ConfigAttributes.java

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();

}

}

...

...

...

}


Using new Mathematical Function/Action in Insights Inference - KPI


  • Create KPI jobs based on the new Action. Specify the new Mathematical Function/Action in the KPI's "action".

To know how to use "action" in Insights Inference - KPI, click here.


©2021 Cognizant, all rights reserved. US Patent 10,410,152