def save_simulation_json(data, do_validate=True): """Prepare data and save to json db Args: data (dict): what to write (contains simulationId) """ try: # Never save this #TODO(robnagler) have "_private" fields that don't get saved del data['simulationStatus'] except Exception: pass data = fixup_old_data(data)[0] s = data.models.simulation sim_type = data.simulationType fn = sim_data_file(sim_type, s.simulationId) with _global_lock: need_validate = True try: # OPTIMIZATION: If folder/name same, avoid reading entire folder on_disk = read_json(fn).models.simulation need_validate = not ( on_disk.folder == s.folder and on_disk.name == s.name ) except Exception: pass if need_validate and do_validate: srschema.validate_name( data, iterate_simulation_datafiles( sim_type, lambda res, _, d: res.append(d), {'simulation.folder': s.folder}, ), SCHEMA_COMMON.common.constants.maxSimCopies ) srschema.validate_fields(data, get_schema(data.simulationType)) s.simulationSerial = _serial_new() write_json(fn, data) return data
def save_simulation_json(data, do_validate=True): """Prepare data and save to json db Args: data (dict): what to write (contains simulationId) """ data = fixup_old_data(data)[0] # old implementation value data.pkdel('computeJobHash') s = data.models.simulation sim_type = data.simulationType fn = sim_data_file(sim_type, s.simulationId) with _global_lock: need_validate = True try: # OPTIMIZATION: If folder/name same, avoid reading entire folder on_disk = read_json(fn).models.simulation need_validate = not ( on_disk.folder == s.folder and on_disk.name == s.name ) except Exception: pass if need_validate and do_validate: srschema.validate_name( data, iterate_simulation_datafiles( sim_type, lambda res, _, d: res.append(d), PKDict({'simulation.folder': s.folder}), ), SCHEMA_COMMON.common.constants.maxSimCopies ) srschema.validate_fields(data, get_schema(data.simulationType)) s.simulationSerial = _serial_new() # Do not write simulationStatus or computeJobCacheKey d = copy.deepcopy(data) pkcollections.unchecked_del(d.models, 'simulationStatus', 'computeJobCacheKey') write_json(fn, d) return data