Search in sources :

Example 1 with AutoMLExecutor

use of com.cognizant.devops.automl.task.util.AutoMLExecutor in project Insights by CognizantOneDevOps.

the class AutoMLSubscriber method handleTaskExecution.

@Override
public void handleTaskExecution(byte[] body) throws IOException {
    List<JsonObject> failedJobs = new ArrayList<>();
    long startTime = System.nanoTime();
    try {
        String message = new String(body, StandardCharsets.UTF_8);
        JsonObject incomingTaskMessage = JsonUtils.parseStringAsJsonObject(message);
        String workflowId = incomingTaskMessage.get("workflowId").getAsString();
        executionId = incomingTaskMessage.get("executionId").getAsLong();
        workflowConfig = workflowDAL.getWorkflowConfigByWorkflowId(workflowId);
        autoMlConfig = autoMlDAL.fetchUseCasesByWorkflowId(workflowId);
        if (autoMlConfig != null) {
            autoMlConfig.setStatus(AutoMLEnum.Status.IN_PROGRESS.name());
            autoMlDAL.updateMLConfig(autoMlConfig);
            List<Callable<JsonObject>> mlTaskToExecute = new ArrayList<>();
            AutoMLExecutor autoMLExecutor = new AutoMLExecutor(autoMlConfig);
            mlTaskToExecute.add(autoMLExecutor);
            /* segregate entire automl execution list into defined chunks */
            List<List<Callable<JsonObject>>> kpiChunkList = WorkflowThreadPool.getChunk(mlTaskToExecute, 1);
            log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, autoMlConfig.getWorkflowConfig().getWorkflowId(), "-", autoMlConfig.getWorkflowConfig().getWorkflowType(), "-", "-", 0, " ModelId :" + autoMlConfig.getModelId() + " UsecaseName :" + autoMlConfig.getUseCaseName() + " PredictionColumn : " + autoMlConfig.getPredictionColumn() + " PredictionType :" + autoMlConfig.getPredictionType() + " TrainingPercentage : " + autoMlConfig.getTrainingPerc() + " status : " + autoMlConfig.getStatus());
            /* submit each chunk to threadpool in a loop */
            executeAutoMLChunks(kpiChunkList, failedJobs);
            if (!failedJobs.isEmpty()) {
                updateFailedTaskStatusLog(failedJobs);
            }
        }
    } catch (InsightsJobFailedException e) {
        log.error("Worlflow Detail ==== InsightsJobFailedException ====  ", e);
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, autoMlConfig.getWorkflowConfig().getWorkflowId(), "-", autoMlConfig.getWorkflowConfig().getWorkflowType(), "-", "-", 0, "ModelId :" + autoMlConfig.getModelId() + " UsecaseName :" + autoMlConfig.getUseCaseName() + " PredictionColumn : " + autoMlConfig.getPredictionColumn() + "predictionType :" + autoMlConfig.getPredictionType() + "trainingPercentage : " + autoMlConfig.getTrainingPerc() + "status : " + autoMlConfig.getStatus() + "Auto ML task failed to execute" + e.getMessage());
        throw new InsightsJobFailedException("Auto ML task failed to execute " + e.getMessage());
    } catch (Exception e) {
        JsonObject response = new JsonObject();
        response.addProperty("Status", "Failure");
        response.addProperty("errorLog", e.getMessage());
        failedJobs.add(response);
        updateFailedTaskStatusLog(failedJobs);
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, autoMlConfig.getWorkflowConfig().getWorkflowId(), "-", autoMlConfig.getWorkflowConfig().getWorkflowType(), "-", "-", 0, "ModelId :" + autoMlConfig.getModelId() + "UsecaseName :" + autoMlConfig.getUseCaseName() + "PredictionColumn : " + autoMlConfig.getPredictionColumn() + "predictionType :" + autoMlConfig.getPredictionType() + "trainingPercentage : " + autoMlConfig.getTrainingPerc() + "status : " + autoMlConfig.getStatus() + e.getMessage());
    }
    long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
    log.debug("Worlflow Detail ==== AutoML task completed successfully.");
    log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, autoMlConfig.getWorkflowConfig().getWorkflowId(), "-", autoMlConfig.getWorkflowConfig().getWorkflowType(), "-", "-", processingTime, "ModelId :" + autoMlConfig.getModelId() + "UsecaseName :" + autoMlConfig.getUseCaseName() + "PredictionColumn : " + autoMlConfig.getPredictionColumn() + "predictionType :" + autoMlConfig.getPredictionType() + "trainingPercentage : " + autoMlConfig.getTrainingPerc() + "status : " + autoMlConfig.getStatus() + " AutoML task completed successfully.");
}
Also used : AutoMLExecutor(com.cognizant.devops.automl.task.util.AutoMLExecutor) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) Callable(java.util.concurrent.Callable) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException)

Aggregations

AutoMLExecutor (com.cognizant.devops.automl.task.util.AutoMLExecutor)1 InsightsJobFailedException (com.cognizant.devops.platformreports.exception.InsightsJobFailedException)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1