private DataSourceDescription getDataSourceDescription(JsonObject arg) { JsonObject obj = rpc(DeltaConst.OP_DESCR_DS, arg); if ( obj.isEmpty() ) return null; return DataSourceDescription.fromJson(obj); }
private List<DataSourceDescription> listDataSourcesZkPath(String logsPath) { List<DataSourceDescription> descriptions = new ArrayList<>(); List<String> logNames = Zk.zkSubNodes(client, logsPath); if ( logNames == null ) return Collections.emptyList(); for ( String name: logNames) { String logDsd = zkPath(ZkConst.pLogs, name, ZkConst.nDsd); JsonObject obj = zkFetchJson(client, logDsd); if ( obj == null ) { FmtLog.info(LOGZK, "[%d] listDataSourcesZkPath: %s: no DSD", instance, name); continue; } DataSourceDescription dsd = DataSourceDescription.fromJson(obj); descriptions.add(dsd); }; return descriptions; }
/** * Look for {@link DataSource DataSources} in a disk area given by {@code location}. * <p> * Scan the given area for directories (must have a config file), check they are enabled, * and deal with {@code log_type}. */ public static List<DataSourceDescription> scanForLogs(Path location, PatchStore ps) { // PatchStore's that rely on the scan of local directories and checking the "log_type" field. Pair<List<Path>, List<Path>> pair = scanDirectory(location); List<Path> dataSourcePaths = pair.getLeft(); List<Path> disabledDataSources = pair.getRight(); //dataSourcePaths.forEach(p->LOG.info("Data source paths: "+p)); disabledDataSources.forEach(p->LOG.info("Data source: "+p+" : Disabled")); List<DataSourceDescription> descriptions = ListUtils.toList (dataSourcePaths.stream() .map(p->{ // Extract name from disk name. String dsName = p.getFileName().toString(); // read config file. JsonObject sourceObj = JSON.read(p.resolve(FileNames.DS_CONFIG).toString()); DataSourceDescription dsd = DataSourceDescription.fromJson(sourceObj); if ( ! Objects.equals(dsName, dsd.getName()) ) throw new DeltaConfigException("Names do not match: directory="+dsName+", dsd="+dsd); return dsd; }) .filter(Objects::nonNull) ); return descriptions; }
public static PatchLogInfo fromJson(JsonObject obj) { DataSourceDescription dsd = DataSourceDescription.fromJson(obj); Version minVer = Version.fromJson(obj, F_MINVER, Version.UNSET) ; Version maxVer = Version.fromJson(obj, F_MAXVER, Version.UNSET) ; String latestPatchStr = JSONX.getStrOrNull(obj, F_LATEST); Id latestPatch = null; if ( latestPatchStr != null && !latestPatchStr.isEmpty() ) latestPatch = Id.fromString(latestPatchStr); return new PatchLogInfo(dsd, minVer, maxVer, latestPatch); }
private List<DataSourceDescription> listDataSourcesZkPath_alt(String logsPath) { List<String> logNames = Zk.zkSubNodes(client, logsPath); Stream<DataSourceDescription> descriptions = logNames.stream() .map(name->{ FmtLog.info(LOGZK, "[%d] listDataSources: %s", instance, name); String logDsd = ZKPaths.makePath(ZkConst.pLogs, name, ZkConst.nDsd); JsonObject obj = zkFetchJson(client, logDsd); if ( obj == null ) { FmtLog.info(LOGZK, "[%d] listDataSourcesZkPath: %s: no DSD", instance, name); return null; } DataSourceDescription dsd = DataSourceDescription.fromJson(obj); return dsd; }) .filter(Objects::nonNull) ; return ListUtils.toList(descriptions); }
DataSourceDescription dsd = DataSourceDescription.fromJson(obj); createPatchLog(dsd); });