Name
global.ApplicationsFingerprintOperations
Description
AFP operations class for operating AFP functionalities.
Script
var ApplicationsFingerprintOperations = Class.create();
ApplicationsFingerprintOperations.DELETE = 'Delete';
ApplicationsFingerprintOperations.UPDATE = 'Update';
ApplicationsFingerprintOperations.INSERT = 'Insert';
ApplicationsFingerprintOperations.prototype = {
initialize: function() {
this.smMLTableUtils = new SMMLTableUtils();
this.afpLogger = new ApplicationsFingerprintLogger('ApplicationsFingerprintOperations');
},
deleteActiveSolution: function() {
var solutionNameGr = this.smMLTableUtils.getSaHashGR('app_fingerprint_solution_name');
if (solutionNameGr) {
var activeSolutionName = solutionNameGr.getValue("hash");
var solutionSysID;
try {
var solution = sn_ml.ClusteringSolutionStore.get(activeSolutionName);
if (solution) {
var activeSolution = solution.getActiveVersion();
solutionSysID = this.smMLTableUtils.getSolutionProperty(activeSolution, activeSolutionName, "sys_id");
//use te ML API to delete the solution form Glide.
var store = sn_ml.ClusteringSolutionStore;
store.deleteObject(activeSolutionName);
}
} catch (ex) {
var log = this.afpLogger.buildLog(activeSolutionName, solutionSysID, ApplicationsFingerprintOperations.DELETE, ex + '');
this.afpLogger.error(log);
}
}
//delete all applicative hashes
this.deleteHashes();
//delete all clustered data
this.deleteTable('cmdb_process_groups');
this.deleteTable('cmdb_process_to_group');
var deleteLog = this.afpLogger.buildLog(activeSolutionName, solutionSysID, ApplicationsFingerprintOperations.DELETE, 'AFP Solution Deleted Completely');
this.afpLogger.info(deleteLog);
},
deleteTable: function(tableName) {
var gr = new GlideRecord(tableName);
gr.setWorkflow(false); //Don't fire Business rule,notifications
gr.deleteMultiple();
},
deleteHashes: function() {
var gr = new GlideRecord('sa_hash');
gr.addQuery("name", "CONTAINS", "fingerprint").addOrCondition('name', 'process_grouping_last_update_sequence').addOrCondition('name', 'process_grouping_last_member_update_sequence').addOrCondition('name', "STARTWITH", 'cancel_retry_stuck_').addOrCondition('name', 'ENDSWITH', '_retry_checksum').addOrCondition('name', 'STARTWITH', 'force_retry_');
gr.query();
gr.deleteMultiple();
if (gs.tableExists('sa_ml_solution_failure_stats')) {
var failureStatsGr = new GlideRecord("sa_ml_solution_failure_stats");
failureStatsGr.query();
failureStatsGr.deleteMultiple();
}
},
deleteStuckHash: function(solutionName, solutionSysID, solutionHashKey) {
if (gs.tableExists('sa_ml_solution_failure_stats')) {
var failureStatsGr = new GlideRecord("sa_ml_solution_failure_stats");
failureStatsGr.addQuery("solution", solutionSysID);
failureStatsGr.query();
failureStatsGr.deleteMultiple();
}
this.smMLTableUtils.deleteSaHash("cancel_retry_stuck_" + solutionHashKey);
this.smMLTableUtils.deleteSaHash(solutionHashKey + "_retry_checksum");
this.smMLTableUtils.deleteSaHash("first_error_time_" + solutionHashKey);
var deleteLog = this.afpLogger.buildLog(solutionName, solutionSysID, ApplicationsFingerprintOperations.DELETE, 'Solution Deleted because stuck AFP');
this.afpLogger.info(deleteLog);
},
deleteHashOfStuckSolution: function(solutionHashKey, solutionStore) {
var solutionNameGr = this.smMLTableUtils.getSaHashGR(solutionHashKey);
if (solutionNameGr) {
var activeSolution = this.smMLTableUtils.getActiveSolution(solutionNameGr.getValue("hash"), solutionStore);
if (activeSolution) {
var solutionName = solutionNameGr.getValue("hash");
var solutionSysID = this.smMLTableUtils.getSolutionProperty(activeSolution, solutionName, "sys_id");
this.deleteStuckHash(solutionName, solutionSysID, solutionHashKey);
}
}
},
triggerTraining: function(forceRetry) {
if (GlideProperties.get("process.clustering.appfingerprint.enabled", "true") == "true") {
if (GlidePluginManager.isActive("com.glide.platform_ml")) {
var cancelMLSolutionUpdate = new CancelMLSolution();
if (cancelMLSolutionUpdate.checkUpdateStateAndCancelOnError("app_fingerprint_solution_name", sn_ml.ClusteringSolutionStore, forceRetry)) {
gs.info("runProcessSuggest has started");
var groupSVC = new SNC.ProcessGroupJS();
groupSVC.processGrouping();
gs.info("runProcessSuggest has finished");
} else {
gs.info("runProcessSuggest scheduler: skipped, As the Update State of ML Solution is in error state and canceling Update Job Failed");
}
} else {
gs.info("runProcessSuggest scheduler: Predictive intelligence is not installed");
}
} else {
gs.info("runProcessSuggest scheduler: skipped, feature is disabled, set process.clustering.appfingerprint.enabled to \"true\" ");
}
},
type: 'ApplicationsFingerprintOperations'
};
Sys ID
35bc4eb0ebb111101a443e82b85228de