private void checkDeltaConnection() { if ( ! valid ) throw new DeltaConfigException(format("[%s] DeltaConnection not valid", datasourceId)); }
public static void main(String...args) { FmtLog.info(Delta.DELTA_LOG, "%s %s %s", SystemInfo.systemName(), SystemInfo.version(), SystemInfo.buildDate()); try { DeltaServer deltaServer = server(args); if ( deltaServer == null ) { System.err.println("Failed to run the server"); System.exit(1); } // And away we go. try { deltaServer.start(); deltaServer.join(); System.exit(0); } catch(BindException ex) { cmdLineError("Port in use: port=%d", deltaServer.getPort()); } } catch (DeltaConfigException ex) { cmdLineError(ex.getMessage()); } }
public PropertiesBuilder set(String propertyName, String propertyValue) { Objects.requireNonNull(propertyName, "propertyName"); if ( propertyValue == null ) throw new DeltaConfigException("Null value for '"+propertyName+"'"); properties.setProperty(propertyName, propertyValue); return this; }
/** Return a {@link LocalServerConfig} for zookeeper usage */ private static LocalServerConfig serverConfigZookeeper(DeltaServerConfig config) { // Allocate zookeeper if ( config.zkConnectionString == null ) throw new DeltaConfigException("No connection string for Zookeeper"); // Set connection string when the test server starts. // if ( config.zkMode == ZkMode.MEM ) { // if ( config.zkPort == null ) // config.zkPort = WebLib.choosePort(); // config.zkConnectionString = "localhost:"+config.zkPort; // } if ( config.zkConnectionString == null ) throw new DeltaConfigException("No connection string for ZooKeeper"); // If zk+S3, there isn't a provider name set yet. LocalServerConfig localServerConfig = LocalServers.configZk(config.zkConnectionString); return localServerConfig; }
/** Supply a dataset for matching to an attached external data source */ public void externalStorage(Id datasourceId, DatasetGraph dsg) { if ( datasets.containsKey(datasourceId) ) throw new DeltaConfigException("Data source already regsitered as zone-managed: "+datasourceId); if ( external.containsKey(datasourceId) ) { DatasetGraph dsg1 = external.get(datasourceId); if ( dsg1 == dsg ) { LOG.warn("Data source already setup as external; same dataset: "+datasourceId); return; } else { LOG.warn("Data source already setup as external; replacing dataset: "+datasourceId); } } external.put(datasourceId, dsg); }
/** Connect to a {@code DataSorce} that is already in this zone. */ public DataState connect(Id datasourceId) { if ( ! exists(datasourceId) ) throw new DeltaConfigException("Not found: "+datasourceId); return states.get(datasourceId); }
public PatchStorageS3(AmazonS3 client, String bucketName, String prefix) { this.client = client; this.bucketName = bucketName; if ( ! prefix.endsWith("/") ) prefix = prefix+"/"; this.prefix = prefix; if ( ! S3.bucketExists(client, bucketName) ) throw new DeltaConfigException("Bucket does not exist or is not accessible"); }
/** Put state file name into DataState then only have here */ private DataState readDataState(Path p) { Path versionFile = p.resolve(FN.STATE); if ( ! Files.exists(versionFile) ) throw new DeltaConfigException("No state file: "+versionFile); PersistentState state = new PersistentState(versionFile); if ( state.getString().isEmpty() ) throw new DeltaConfigException("Error reading state: version file exist but is empty"); DataState dataState = new DataState(this, state) ; return dataState; }
private static PatchStore createPatchStore(LocalServerConfig config) { String providerName = config.getLogProvider(); if ( providerName == null ) throw new DeltaConfigException("LocalServer.selectPatchStore: Provider name is null"); PatchStoreProvider psp = PatchStoreMgr.getPatchStoreProvider(providerName); if ( psp == null ) throw new DeltaConfigException("No patch store provider: "+config.getLogProvider()); PatchStore ps = psp.create(config); if ( ps == null ) throw new DeltaConfigException("Patch store not created and configured: "+config.getLogProvider()); return ps; }
/** Supply a dataset for matching to an attached external data source */ public void externalStorage(Id datasourceId, DatasetGraph dsg) { if ( ! zone.exists(datasourceId) ) throw new DeltaConfigException("Can't add external storage: data source not attached to this zone: "+datasourceId); DataState dataState = zone.get(datasourceId); if ( ! LocalStorageType.EXTERNAL.equals(dataState.getStorageType()) ) { throw new DeltaConfigException("Can't add external storage: data source is not 'external': "+datasourceId); } zone.externalStorage(datasourceId, dsg); }
/** Parse a configuration file. */ public Builder parse(String configFile) { Path path = Paths.get(configFile); if ( ! Files.exists(path) ) throw new DeltaConfigException("File not found: "+configFile); // -- version JsonObject obj = JSON.read(configFile); int version = JSONX.getInt(obj, F_VERSION, -99); if ( version == -99 ) { LOG.warn("No version number for the configuration file : assuming 'current'"); version = DeltaConst.SYSTEM_VERSION; } if ( version != SYSTEM_VERSION ) throw new DeltaConfigException("Version number for LocalServer must be "+DeltaConst.SYSTEM_VERSION+"."); this.configFile = configFile; // -- log provider logProvider = DPS.PatchStoreFileProvider; String logTypeName = JSONX.getStrOrNull(obj, F_LOG_TYPE); if ( logTypeName != null ) { String providerName = PatchStoreMgr.canonical(logTypeName); if ( providerName == null ) providerName = DeltaConst.LOG_FILE; logProvider = providerName; } setProperty(DeltaConst.pDeltaFile, path.getParent().toString()); return this; }
/** * 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 DatasetGraph build() { if ( zone == null ) throw new DeltaConfigException("zone not set"); if ( deltaLink == null ) throw new DeltaConfigException("deltaLink not set"); if ( logName == null ) throw new DeltaConfigException("logName not set"); if ( syncPolicy == null ) throw new DeltaConfigException("syncPolicy not set"); throw new DeltaConfigException("storageType not set");
private void setupState$(DataSourceDescription dsd, LocalStorageType storageType) { Id datasourceId = dsd.getId(); if ( zone.exists(datasourceId) ) { DataState dataState = zone.get(datasourceId); throw new DeltaConfigException("Local data source management already exists: "+dataState.getDatasourceName()); } DataState dataState = zone.create(datasourceId, dsd.getName(), dsd.getUri(), storageType); }
/** * Connect to an existing {@code DataSource} with existing local state. * This operation does not fail if it can not contact the patch log server. * @param datasourceId * @param syncPolicy */ public void connect(Id datasourceId, SyncPolicy syncPolicy) { syncPolicy = applyDefault(syncPolicy); if ( ! zone.exists(datasourceId) ) throw new DeltaConfigException("Data source '"+datasourceId.toString()+"' not found for this DeltaClient"); DataState dataState = zone.connect(datasourceId); DatasetGraph dsg = zone.getDataset(dataState); DeltaConnection dConn = DeltaConnection.create(dataState, dsg, dLink, syncPolicy); putCache(datasourceId, dConn); }
private void setupExternal(DataSourceDescription dsd, DatasetGraph dsg) { Id datasourceId = dsd.getId(); if ( zone.exists(datasourceId) ) { DataState dataState = zone.get(datasourceId); throw new DeltaConfigException("Can't attach: data source already exists locally: "+dataState.getDatasourceName()); } DataState dataState = zone.create(datasourceId, dsd.getName(), dsd.getUri(), LocalStorageType.EXTERNAL); externalStorage(datasourceId, dsg); }
break; default : throw new DeltaConfigException("Unrecognized provider: "+deltaServerConfig.provider);