use of gov.cms.bfd.sharedutils.config.ConfigLoader in project beneficiary-fhir-data by CMSgov.
the class RDABridge method main.
/**
* Handles translation of a CLI execution, validating and pulling arguments to then invoke the
* underlying application code with.
*
* @param args Array of the command line arguments.
*/
public static void main(String[] args) {
try {
Options options = new Options().addOption(OUTPUT_FLAG, true, "The directory where the output files will be written to.").addOption(MBI_FLAG, true, "Benefit History file to read from").addOption(FISS_FLAG, true, "FISS file to read from").addOption(MCS_FLAG, true, "MCS file to read from").addOption(FISS_OUTPUT_FLAG, true, "FISS RDA output file").addOption(MCS_OUTPUT_FLAG, true, "MCS RDA output file").addOption(EXTERNAL_CONFIG_FLAG, true, "Path to yaml file containing run configs").addOption(FISS_SEQ_START, true, "Starting point for FISS sequence values").addOption(MCS_SEQ_START, true, "Starting point for MCS sequence values").addOption(BUILD_ATTRIBUTION_FILE, true, "Indicates if the attribution sql script should be generated").addOption(ATTRIBUTION_SIZE, true, "The number of MBIs to pull for building the attribution file").addOption(ATTRIBUTION_TEMPLATE_FILE, true, "The template file to use for building the attribution script").addOption(ATTRIBUTION_SCRIPT_FILE, true, "The attribution script file to write to").addOption(ATTRIBUTION_FISS_RATIO, true, "Ratio of fiss to mcs MBIs to use in attribution");
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
ConfigLoader config;
if (cmd.hasOption(EXTERNAL_CONFIG_FLAG)) {
config = createYamlConfig(cmd.getOptionValue(EXTERNAL_CONFIG_FLAG));
} else if (!cmd.getArgList().isEmpty()) {
config = createCliConfig(cmd);
} else {
printUsage(options);
System.exit(1);
throw new IllegalStateException("This will never happen");
}
new RDABridge().run(config);
} catch (IOException | ParseException e) {
log.error("Failed to execute", e);
System.exit(1);
}
}
use of gov.cms.bfd.sharedutils.config.ConfigLoader in project beneficiary-fhir-data by CMSgov.
the class DirectRdaLoadApp method main.
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.err.printf("usage: %s configfile claimType%n", DirectRdaLoadApp.class.getSimpleName());
System.exit(1);
}
final ConfigLoader options = ConfigLoader.builder().addPropertiesFile(new File(args[0])).addSystemProperties().build();
final String claimType = Strings.nullToEmpty(args[1]);
final MetricRegistry metrics = new MetricRegistry();
final Slf4jReporter reporter = Slf4jReporter.forRegistry(metrics).outputTo(LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
reporter.start(5, TimeUnit.SECONDS);
final RdaLoadOptions jobConfig = readRdaLoadOptionsFromProperties(options);
final DatabaseOptions databaseConfig = readDatabaseOptions(options, jobConfig.getJobConfig().getWriteThreads());
HikariDataSource pooledDataSource = PipelineApplicationState.createPooledDataSource(databaseConfig, metrics);
System.out.printf("thread count is %d%n", jobConfig.getJobConfig().getWriteThreads());
System.out.printf("database pool size %d%n", pooledDataSource.getMaximumPoolSize());
DatabaseSchemaManager.createOrUpdateSchema(pooledDataSource);
try (PipelineApplicationState appState = new PipelineApplicationState(metrics, pooledDataSource, PipelineApplicationState.RDA_PERSISTENCE_UNIT_NAME, Clock.systemUTC())) {
final Optional<PipelineJob<?>> job = createPipelineJob(jobConfig, appState, claimType);
if (!job.isPresent()) {
System.err.printf("error: invalid claim type: '%s' expected 'fiss' or 'mcs'%n", claimType);
System.exit(1);
}
try {
job.get().call();
} finally {
reporter.report();
}
}
}
use of gov.cms.bfd.sharedutils.config.ConfigLoader in project beneficiary-fhir-data by CMSgov.
the class StoreRdaJsonApp method main.
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.err.println("usage: StoreRdaJsonApp config");
System.exit(1);
}
final ConfigLoader loader = ConfigLoader.builder().addPropertiesFile(new File(args[0])).addSystemProperties().build();
final Config config = new Config(loader);
final ManagedChannel channel = createChannel(config);
try {
final GrpcResponseStream<? extends MessageOrBuilder> results = callService(config, channel);
int received = 0;
try (PrintWriter output = new PrintWriter(new FileWriter(config.outputFile))) {
while (received < config.maxToReceive && results.hasNext()) {
final MessageOrBuilder change = results.next();
final String json = convertToJson(change);
output.println(json);
output.flush();
received += 1;
if (received < 100 || received % 100 == 0) {
System.out.printf("%d: %s%n", received, json);
}
}
}
System.out.printf("received %d claims%n", received);
System.out.println("cancelling stream...");
results.cancelStream("finished reading");
} finally {
channel.shutdown();
channel.awaitTermination(60, TimeUnit.SECONDS);
}
}
use of gov.cms.bfd.sharedutils.config.ConfigLoader in project beneficiary-fhir-data by CMSgov.
the class RDABridge method createYamlConfig.
/**
* Creates a {@link ConfigLoader} from a given yaml configuration file.
*
* @param yamlFilePath Path to the yaml configuration file.
* @return The {@link ConfigLoader} generated from the yaml configuration file.
* @throws FileNotFoundException If the yaml configuration file was not found.
*/
@VisibleForTesting
static ConfigLoader createYamlConfig(String yamlFilePath) throws IOException {
try (FileReader reader = new FileReader(yamlFilePath)) {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
AppConfig appConfig = mapper.readValue(reader, AppConfig.class);
Map<String, Collection<String>> mapConfig = ImmutableMap.<String, Collection<String>>builder().put(AppConfig.Fields.inputDirPath, Collections.singleton(appConfig.getInputDirPath())).put(AppConfig.Fields.outputDirPath, Collections.singleton(appConfig.getOutputDirPath())).put(AppConfig.Fields.fissOutputFile, Collections.singleton(appConfig.getFissOutputFile())).put(AppConfig.Fields.mcsOutputFile, Collections.singleton(appConfig.getMcsOutputFile())).put(AppConfig.Fields.fissSeqStart, Collections.singleton(appConfig.getFissSeqStart())).put(AppConfig.Fields.mcsSeqStart, Collections.singleton(appConfig.getMcsSeqStart())).put(AppConfig.Fields.buildAttributionSet, Collections.singleton(appConfig.getBuildAttributionSet())).put(AppConfig.Fields.attributionSetSize, Collections.singleton(appConfig.getAttributionSetSize())).put(AppConfig.Fields.attributionTemplateFile, Collections.singleton(appConfig.getAttributionTemplateFile())).put(AppConfig.Fields.attributionScriptFile, Collections.singleton(appConfig.getAttributionScriptFile())).put(AppConfig.Fields.attributionFissRatio, Collections.singleton(appConfig.getAttributionFissRatio())).put(AppConfig.Fields.fissSources, appConfig.getFissSources()).put(AppConfig.Fields.mcsSources, appConfig.getMcsSources()).put(AppConfig.Fields.mbiSource, Collections.singleton(appConfig.getMbiSource())).build();
return new ConfigLoader(mapConfig::get);
}
}
Aggregations