in modules/command/src/main/java/org/apache/fluo/command/FluoInit.java [100:176]
public void execute() throws FluoCommandException {
var applicationPropsFile = Path.of(getAppPropsPath()).toFile();
Preconditions.checkArgument(applicationPropsFile.exists(),
getAppPropsPath() + " does not exist");
FluoConfiguration config = getConfig();
config.load(applicationPropsFile);
String propKey = getRetrieveProperty();
if (propKey != null && !propKey.isEmpty()) {
if (config.containsKey(propKey)) {
System.out.println(config.getString(propKey));
}
return;
}
if (!config.hasRequiredAdminProps()) {
throw new FluoCommandException(
"Error - Required properties are not set in " + getAppPropsPath());
}
try {
config.validate();
} catch (Exception e) {
throw new FluoCommandException("Error - Invalid configuration due to " + e.getMessage(), e);
}
try (FluoAdminImpl admin = new FluoAdminImpl(config)) {
FluoAdmin.InitializationOptions initOpts = new FluoAdmin.InitializationOptions();
if (getUpdate()) {
System.out.println("Updating configuration for the Fluo '" + config.getApplicationName()
+ "' application in Zookeeper using " + getAppPropsPath());
admin.updateSharedConfig();
System.out.println("Update is complete.");
return;
}
if (getForce()) {
initOpts.setClearZookeeper(true).setClearTable(true);
} else {
if (getClearZookeeper()) {
initOpts.setClearZookeeper(true);
} else if (admin.zookeeperInitialized()) {
System.out.print("A Fluo '" + config.getApplicationName()
+ "' application is already initialized in Zookeeper at " + config.getAppZookeepers()
+ " - Would you like to clear and reinitialize Zookeeper"
+ " for this application (y/n)? ");
if (readYes()) {
initOpts.setClearZookeeper(true);
} else {
throw new FluoCommandException("Aborted initialization.");
}
}
if (getClearTable()) {
initOpts.setClearTable(true);
} else if (admin.accumuloTableExists()) {
System.out.print("The Accumulo table '" + config.getAccumuloTable()
+ "' already exists - Would you like to drop and recreate this table (y/n)? ");
if (readYes()) {
initOpts.setClearTable(true);
} else {
throw new FluoCommandException("Aborted initialization.");
}
}
}
System.out.println("Initializing Fluo '" + config.getApplicationName()
+ "' application using " + getAppPropsPath());
admin.initialize(initOpts);
System.out.println("Initialization is complete.");
} catch (FluoAdmin.AlreadyInitializedException | FluoAdmin.TableExistsException e) {
throw new FluoCommandException(e.getMessage(), e);
}
}