Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noise model triton changes #74

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 69 additions & 81 deletions src/main/java/in/handyman/raven/lib/IntegratedNoiseModelApiAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,10 @@
import in.handyman.raven.lambda.action.ActionExecution;
import in.handyman.raven.lambda.action.IActionExecution;
import in.handyman.raven.lambda.doa.audit.ActionExecutionAudit;

import java.sql.Types;
import java.util.concurrent.LinkedBlockingQueue;


import java.lang.Exception;
import java.lang.Object;
import java.lang.Override;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import in.handyman.raven.lib.model.IntegratedNoiseModelApi;
import in.handyman.raven.lib.model.NoiseModel.NoiseModelConsumerProcess;
import in.handyman.raven.lib.model.NoiseModel.NoiseModelInputEntity;
import in.handyman.raven.lib.model.NoiseModel.NoiseModelOutputEnitity;
//import in.handyman.raven.lib.model.qrExtraction.QrConsumerProcess;
//import in.handyman.raven.lib.model.qrExtraction.QrInputEntity;
//import in.handyman.raven.lib.model.qrExtraction.QrOutputEntity;
import in.handyman.raven.lib.model.NoiseModel.NoiseModelOutputEntity;
import in.handyman.raven.util.ExceptionUtil;
import org.jdbi.v3.core.Jdbi;
import org.jdbi.v3.core.argument.Arguments;
Expand All @@ -36,85 +17,92 @@
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Types;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.stream.Collectors;

/**
* Auto Generated By Raven
*/
@ActionExecution(
actionName = "IntegratedNoiseModelApi"
)
public class IntegratedNoiseModelApiAction implements IActionExecution {
private final ActionExecutionAudit action;

private final Logger log;

private final IntegratedNoiseModelApi integratedNoiseModelApi;
private static String httpClientTimeout = new String();
private final Marker aMarker;

public IntegratedNoiseModelApiAction(final ActionExecutionAudit action, final Logger log,
final Object integratedNoiseModelApi) {
this.integratedNoiseModelApi = (IntegratedNoiseModelApi) integratedNoiseModelApi;
this.action = action;
this.log = log;
this.aMarker = MarkerFactory.getMarker(" IntegratedNoiseModelApi:"+this.integratedNoiseModelApi.getName());
}

@Override
public void execute() throws Exception {
try {
log.info(aMarker, "Integrated noise model Action for {} with group by eoc-id has started", integratedNoiseModelApi.getName());
final Jdbi jdbi = ResourceAccess.rdbmsJDBIConn(integratedNoiseModelApi.getResourceConn());
jdbi.getConfig(Arguments.class).setUntypedNullArgument(new NullArgument(Types.NULL)); //for handling null values
//3. initiate Copro processor and Copro urls change the url to integrated noise model
final List<URL> urls = Optional.ofNullable(integratedNoiseModelApi.getEndPoint()).map(s -> Arrays.stream(s.split(",")).map(s1 -> {
try {
return new URL(s1);
} catch (MalformedURLException e) {
log.error("Error in processing the URL {}", s1, e);
throw new HandymanException("Error in processing the URL", e, action);
}
}).collect(Collectors.toList())).orElse(Collections.emptyList());
log.info("Urls for the Integrated noise model : {}", urls);
//5. build insert prepare statement with output table columns
//
final String insertQuery = "INSERT INTO " + integratedNoiseModelApi.getOutputTable() +
" ( origin_id, paper_no, process_id, group_id, tenant_id, input_file_path, " +
"consolidated_confidence_score, consolidated_class, noise_models_result, hw_noise_detection_output, " +
"check_noise_detection_output, checkbox_mark_detection_output, speckle_noise_detection_output," +
" created_on, root_pipeline_id,status,stage,message)" +
"VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
private final ActionExecutionAudit action;

private final Logger log;

private final IntegratedNoiseModelApi integratedNoiseModelApi;
private static String httpClientTimeout = new String();
private final Marker aMarker;

// Class<NoiseModelInputEntity> NoiseModelInputEntity = null;
final CoproProcessor<NoiseModelInputEntity, NoiseModelOutputEnitity> coproProcessor =
new CoproProcessor<>(new LinkedBlockingQueue<>(),
NoiseModelOutputEnitity.class,
NoiseModelInputEntity.class,
jdbi, log,
new NoiseModelInputEntity(), urls, action);
public IntegratedNoiseModelApiAction(final ActionExecutionAudit action, final Logger log,
final Object integratedNoiseModelApi) {
this.integratedNoiseModelApi = (IntegratedNoiseModelApi) integratedNoiseModelApi;
this.action = action;
this.log = log;
this.aMarker = MarkerFactory.getMarker(" IntegratedNoiseModelApi:" + this.integratedNoiseModelApi.getName());
}

@Override
public void execute() throws Exception {
try {
log.info(aMarker, "Integrated noise model Action for {} with group by eoc-id has started", integratedNoiseModelApi.getName());
final Jdbi jdbi = ResourceAccess.rdbmsJDBIConn(integratedNoiseModelApi.getResourceConn());
jdbi.getConfig(Arguments.class).setUntypedNullArgument(new NullArgument(Types.NULL)); //for handling null values
//3. initiate Copro processor and Copro urls change the url to integrated noise model
final List<URL> urls = Optional.ofNullable(integratedNoiseModelApi.getEndPoint()).map(s -> Arrays.stream(s.split(",")).map(s1 -> {
try {
return new URL(s1);
} catch (MalformedURLException e) {
log.error("Error in processing the URL {}", s1, e);
throw new HandymanException("Error in processing the URL", e, action);
}
}).collect(Collectors.toList())).orElse(Collections.emptyList());
log.info("Urls for the Integrated noise model : {}", urls);
//5. build insert prepare statement with output table columns
//
final String insertQuery = "INSERT INTO " + integratedNoiseModelApi.getOutputTable() +
" ( origin_id, paper_no, process_id, group_id, tenant_id, input_file_path, " +
"consolidated_confidence_score, consolidated_class, noise_models_result, hw_noise_detection_output, " +
"check_noise_detection_output, checkbox_mark_detection_output, speckle_noise_detection_output," +
" created_on, root_pipeline_id,status,stage,message,model_name,model_version)" +
"VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

coproProcessor.startProducer(integratedNoiseModelApi.getQuerySet(), Integer.valueOf(action.getContext().get("read.batch.size")));
log.info("start producer method from copro processor ");
Thread.sleep(1000);

//8. call the method start consumer from coproprocessor
coproProcessor.startConsumer(insertQuery, Integer.valueOf(action.getContext().get("noise.consumer.API.count")), Integer.valueOf(action.getContext().get("write.batch.size")), new NoiseModelConsumerProcess(log, aMarker, action));
log.info("start consumer method from copro processor ");
// Class<NoiseModelInputEntity> NoiseModelInputEntity = null;
final CoproProcessor<NoiseModelInputEntity, NoiseModelOutputEntity> coproProcessor =
new CoproProcessor<>(new LinkedBlockingQueue<>(),
NoiseModelOutputEntity.class,
NoiseModelInputEntity.class,
jdbi, log,
new NoiseModelInputEntity(), urls, action);

coproProcessor.startProducer(integratedNoiseModelApi.getQuerySet(), Integer.valueOf(action.getContext().get("read.batch.size")));
log.info("start producer method from copro processor ");
Thread.sleep(1000);

//8. call the method start consumer from coproprocessor
coproProcessor.startConsumer(insertQuery, Integer.valueOf(action.getContext().get("noise.consumer.API.count")), Integer.valueOf(action.getContext().get("write.batch.size")), new NoiseModelConsumerProcess(log, aMarker, action));
log.info("start consumer method from copro processor ");


} catch (Exception e) {
log.error("Error in the Integrated noise model action {}", ExceptionUtil.toString(e));
throw new HandymanException("Integrated noise model action failed ", e, action);

} catch (Exception e) {
log.error("Error in the Integrated noise model action {}", ExceptionUtil.toString(e));
throw new HandymanException("Integrated noise model action failed ", e, action);

}
}

@Override
public boolean executeIf() throws Exception {
return integratedNoiseModelApi.getCondition();
}
}
@Override
public boolean executeIf() throws Exception {
return integratedNoiseModelApi.getCondition();
}
}
Loading