// Takes in the whole config JSON file as a JObject and returns a list of Fields public FullConfig Translate(JObject config) { List <Field> fields = new List <Field>(); foreach (JObject fieldConfig in (JArray)config["dimension_attributes"]) { string typeID = (string)fieldConfig["type"]; fields.Add(this.CaseAt(typeID, fieldConfig)); } FullConfig fullConfig = new FullConfig( (string)config["config_name"], (int)config["threads_count"], (int)config["records_count"], (double)config["error_rate"], fields ); return(fullConfig); }
public static void ProduceAndSend(string configUUID, FullConfig producerConfig, string host_addr, CustomLogger log) { Producer producer = new Producer(producerConfig.records_count, producerConfig.fields, producerConfig.error_rate); // Generate and Send Data Records host_addr = host_addr ?? LOCAL_HOST; ProducerToDefaultConsumerAddpt adapter = new ProducerToDefaultConsumerAddpt(); for (int counter = producerConfig.records_count; counter > 0; counter--) { try { producer.SendRecord(adapter, configUUID, host_addr, log); } catch (WebException webExcp) { log.RawLog(LogLevel.ERROR, $"[ERROR] Got WebException {webExcp} while sending {counter}th record!"); } } ; }
public static FullConfig?ParseConfig(JObject jConfig) { List <FieldAttributes> fields = new List <FieldAttributes>(); foreach (JObject fieldConfig in (JArray)jConfig["dimension_attributes"]) { string typeID = (string)fieldConfig["type"]; fields.Add(configToFieldsTranslator.CaseAt(typeID, fieldConfig)); } // TESTING: try { int threads_count = (int)jConfig["threads_count"]; int records_count = (int)jConfig["records_count"] < 2147483647 ? (int)jConfig["records_count"] : 2147483647; ErrorRateConfig error_rate = new ErrorRateConfig { missingField = (double)jConfig["error_rate"]["missing_field"], badValue = (double)jConfig["error_rate"]["bad_value"], additionalField = (double)jConfig["error_rate"]["additional_field"] }; FullConfig fullConfig = new FullConfig( threads_count, records_count, error_rate, fields ); return(fullConfig); } catch (Exception e) { //Console.WriteLine("Type casting error in thread or record or error_rate."); return(null); } }