aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/ReadyHttpServlet.java37
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java68
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/ODLVersionLUT.java39
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/SystemInfo.java9
-rw-r--r--sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/DataMigrationProviderImpl.java16
-rw-r--r--sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/Program.java98
6 files changed, 179 insertions, 88 deletions
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/ReadyHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/ReadyHttpServlet.java
index e20f453a1..cb74911ff 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/ReadyHttpServlet.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/ReadyHttpServlet.java
@@ -22,19 +22,21 @@
package org.onap.ccsdk.features.sdnr.wt.dataprovider.http;
import java.io.IOException;
-
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.MarkdownTable;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ReadyHttpServlet extends HttpServlet {
/**
- *
+ *
*/
private static final long serialVersionUID = 1L;
private static final Logger LOG = LoggerFactory.getLogger(ReadyHttpServlet.class);
@@ -43,7 +45,7 @@ public class ReadyHttpServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- if (isReady()) {
+ if (isReady() && this.getBundleStatesNotActiveCount()==0) {
resp.setStatus(HttpServletResponse.SC_OK);
} else {
@@ -63,4 +65,31 @@ public class ReadyHttpServlet extends HttpServlet {
status = s;
LOG.info("status is set to ready: {}", status);
}
+
+ private int getBundleStatesNotActiveCount() {
+ Bundle thisbundle = FrameworkUtil.getBundle(this.getClass());
+ BundleContext context = thisbundle ==null?null:thisbundle.getBundleContext();
+ if (context == null) {
+ LOG.debug("no bundle context available");
+ return 0;
+ }
+ Bundle[] bundles = context.getBundles();
+ if (bundles == null || bundles.length <= 0) {
+ LOG.debug("no bundles found");
+ return 0;
+ }
+ LOG.debug("found {} bundles", bundles.length);
+ MarkdownTable table = new MarkdownTable();
+ table.setHeader(new String[] {"Bundle-Id","Version","Symbolic-Name","Status"});
+ int cntNotActive=0;
+ for (Bundle bundle : bundles) {
+
+ if(bundle.getState()!=Bundle.ACTIVE) {
+ cntNotActive++;
+ }
+
+ }
+ return cntNotActive;
+ }
+
}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java
index 9ac0cc0c3..81b9645fe 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java
@@ -38,6 +38,9 @@ import javax.servlet.http.HttpServletResponse;
import org.onap.ccsdk.features.sdnr.wt.common.Resources;
import org.onap.ccsdk.features.sdnr.wt.common.file.PomFile;
import org.onap.ccsdk.features.sdnr.wt.common.file.PomPropertiesFile;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,7 +62,6 @@ public class AboutHttpServlet extends HttpServlet {
private static final String PLACEHOLDER_ONAP_RELEASEVERSION = "{release-version}";
private static final String PLACEHOLDER_ODL_RELEASENAME = "{odl-version}";
private static final String PLACEHOLDER_BUILD_TIMESTAMP = "{build-time}";
- private static final String PLACEHOLDER_ODLUX_REVISION = "{odlux-revision}";
private static final String PLACEHOLDER_PACKAGE_GITHASH = "{package-githash}";
private static final String PLACEHOLDER_PACAKGE_VERSION = "{package-version}";
private static final String PLACEHOLDER_CCSDK_VERSION = "{ccsdk-version}";
@@ -69,10 +71,12 @@ public class AboutHttpServlet extends HttpServlet {
private static final String PLACEHOLDER_KARAF_INFO = "{karaf-info}";
private static final String PLACEHOLDER_DEVICEMANAGER_TABLE = "{devicemanagers}";
private static final String README_FILE = "README.md";
+ private static final String NO_DEVICEMANAGERS_RUNNING_MESSAGE = null;
private final String groupId = "org.onap.ccsdk.features.sdnr.wt";
private final String artifactId = "sdnr-wt-data-provider-provider";
+ private final Map<Integer,String> BUNDLESTATE_LUT;
private final Map<String, String> data;
private final String readmeContent;
// private BundleService bundleService;
@@ -83,7 +87,13 @@ public class AboutHttpServlet extends HttpServlet {
this.data = new HashMap<>();
this.collectStaticData();
this.readmeContent = this.render(this.getResourceFileContent(README_FILE));
- //BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
+ this.BUNDLESTATE_LUT = new HashMap<>();
+ this.BUNDLESTATE_LUT.put(Bundle.UNINSTALLED, "uninstalled");
+ this.BUNDLESTATE_LUT.put(Bundle.INSTALLED, "installed");
+ this.BUNDLESTATE_LUT.put(Bundle.RESOLVED, "resolved");
+ this.BUNDLESTATE_LUT.put(Bundle.STARTING, "starting");
+ this.BUNDLESTATE_LUT.put(Bundle.STOPPING, "stopping");
+ this.BUNDLESTATE_LUT.put(Bundle.ACTIVE, "active");
}
@@ -97,13 +107,14 @@ public class AboutHttpServlet extends HttpServlet {
private void collectStaticData() {
PomPropertiesFile props = this.getPomProperties();
final String ccsdkVersion = this.getPomParentVersion();
+ final String mdsalVersion = SystemInfo.getMdSalVersion(UNKNOWN);
this.data.put(PLACEHOLDER_ONAP_RELEASENAME, ODLVersionLUT.getONAPReleaseName(ccsdkVersion, UNKNOWN));
- this.data.put(PLACEHOLDER_ODL_RELEASENAME, ODLVersionLUT.getOdlVersion(ccsdkVersion, UNKNOWN));
+ this.data.put(PLACEHOLDER_ODL_RELEASENAME, ODLVersionLUT.getOdlVersion(mdsalVersion, UNKNOWN));
this.data.put(PLACEHOLDER_BUILD_TIMESTAMP, props != null ? props.getBuildDate().toString() : "");
this.data.put(PLACEHOLDER_PACAKGE_VERSION, this.getManifestValue("Bundle-Version"));
this.data.put(PLACEHOLDER_CCSDK_VERSION, ccsdkVersion);
- this.data.put(PLACEHOLDER_ONAP_RELEASEVERSION, "2.0.0-SNAPSHOT");
- this.data.put(PLACEHOLDER_MDSAL_VERSION, SystemInfo.getMdSalVersion(UNKNOWN));
+ this.data.put(PLACEHOLDER_ONAP_RELEASEVERSION, SystemInfo.getOnapVersion(UNKNOWN));
+ this.data.put(PLACEHOLDER_MDSAL_VERSION, mdsalVersion);
this.data.put(PLACEHOLDER_YANGTOOLS_VERSION, SystemInfo.getYangToolsVersion(UNKNOWN));
this.data.put(PLACEHOLDER_PACKAGE_GITHASH, this.getGitHash(UNKNOWN));
}
@@ -272,25 +283,34 @@ public class AboutHttpServlet extends HttpServlet {
}
private String getDevicemanagerBundles() {
- // if(this.bundleService==null) {
- // LOG.debug("no bundle service available");
- // return "";
- // }
- //
- // List<String> ids = new ArrayList<String>();
- // List<Bundle> bundles = bundleService.selectBundles("0", ids , true);
- // if(bundles==null || bundles.size()<=0) {
- // LOG.debug("no bundles found");
- // return "";
- // }
- // LOG.debug("found {} bundles",bundles.size());
- // MarkdownTable table = new MarkdownTable();
- // for(Bundle bundle:bundles) {
- // BundleInfo info = this.bundleService.getInfo(bundle);
- // table.addRow(new String[] {String.valueOf(info.getBundleId()),info.getVersion(),info.getName(),info.getState().toString()});
- // }
- // return table.toMarkDown();
- return "";
+ Bundle thisbundle = FrameworkUtil.getBundle(this.getClass());
+ BundleContext context = thisbundle ==null?null:thisbundle.getBundleContext();
+ if (context == null) {
+ LOG.debug("no bundle context available");
+ return "";
+ }
+ Bundle[] bundles = context.getBundles();
+ if (bundles == null || bundles.length <= 0) {
+ LOG.debug("no bundles found");
+ return NO_DEVICEMANAGERS_RUNNING_MESSAGE;
+ }
+ LOG.debug("found {} bundles", bundles.length);
+ MarkdownTable table = new MarkdownTable();
+ table.setHeader(new String[] {"Bundle-Id","Version","Symbolic-Name","Status"});
+ String name;
+ for (Bundle bundle : bundles) {
+ name = bundle.getSymbolicName();
+ if(!(name.contains("devicemanager") && name.contains("provider"))) {
+ continue;
+ }
+ if(name.equals("org.onap.ccsdk.features.sdnr.wt.sdnr-wt-devicemanager-provider")) {
+ continue;
+ }
+ table.addRow(new String[] {String.valueOf(bundle.getBundleId()), bundle.getVersion().toString(), name,
+ BUNDLESTATE_LUT.getOrDefault(bundle.getState(),"unknown")});
+
+ }
+ return table.toMarkDown();
}
/**
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/ODLVersionLUT.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/ODLVersionLUT.java
index bd8fae6a0..991231f87 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/ODLVersionLUT.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/ODLVersionLUT.java
@@ -21,8 +21,13 @@
*/
package org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about;
+import java.util.HashMap;
+import java.util.Map;
+
public class ODLVersionLUT {
+ private static Map<String,String> odlMdsalVersionLUT=null;
+
public static String getONAPReleaseName(String onapCCSDKVersion, String def) {
if (onapCCSDKVersion == null) {
return def;
@@ -45,26 +50,26 @@ public class ODLVersionLUT {
return def;
}
- public static String getOdlVersion(String onapCCSDKVersion, String def) {
+ public static String getOdlVersion(String mdsalVersion, String def) {
- if (onapCCSDKVersion == null) {
+ if (mdsalVersion == null) {
return def;
}
- if (onapCCSDKVersion.startsWith("2.")) {
- return "sodium-SR3 (0.11.3)";
- }
- if (onapCCSDKVersion.startsWith("1.5.")) {
- return "neon-SR1 (0.10.1)";
- }
- if (onapCCSDKVersion.startsWith("1.4.")) {
- return "neon-SR1 (0.10.1)";
+ if(odlMdsalVersionLUT==null) {
+ odlMdsalVersionLUT = new HashMap<>();
+ odlMdsalVersionLUT.put("5.0.14","magnesium-SR2 (0.12.2)");
+ odlMdsalVersionLUT.put("5.0.10","magnesium-SR1 (0.12.1)");
+ odlMdsalVersionLUT.put("5.0.9","magnesium-SR0 (0.12.0)");
+ odlMdsalVersionLUT.put("4.0.14","sodium-SR3 (0.11.3)");
+ odlMdsalVersionLUT.put("4.0.11","sodium-SR2 (0.11.2)");
+ odlMdsalVersionLUT.put("4.0.6","sodium-SR1 (0.11.1)");
+ odlMdsalVersionLUT.put("4.0.4","sodium-SR0 (0.11.0)");
+ odlMdsalVersionLUT.put("3.0.13","neon-SR3 (0.10.3)");
+ odlMdsalVersionLUT.put("3.0.10","neon-SR2 (0.10.2)");
+ odlMdsalVersionLUT.put("3.0.8","neon-SR1 (0.10.1)");
+ odlMdsalVersionLUT.put("3.0.6","neon-SR0 (0.10.0)");
}
- if (onapCCSDKVersion.startsWith("1.3.")) {
- return "fluorine-SR2 (0.9.2)";
- }
- if (onapCCSDKVersion.startsWith("1.2.")) {
- return "sodium-SR3 (0.11.3)";
- }
- return def;
+
+ return odlMdsalVersionLUT.getOrDefault(mdsalVersion, def);
}
}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/SystemInfo.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/SystemInfo.java
index 1497362a6..134e3d37b 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/SystemInfo.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/SystemInfo.java
@@ -42,7 +42,6 @@ import java.util.concurrent.Callable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
-
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
@@ -54,6 +53,10 @@ public class SystemInfo {
private static OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
protected static boolean showMemoryPools = false;
+ public static String getOnapVersion(String def) {
+ return getOnapVersion("", def);
+ }
+
public static String getMdSalVersion(String def) {
return getMdSalVersion("", def);
}
@@ -62,6 +65,10 @@ public class SystemInfo {
return getYangToolsVersion("", def);
}
+ public static String getOnapVersion(String baseOdlDirectory, String def) {
+ return getFeatureVersionByFolder(baseOdlDirectory, "system/org/onap/sdnc/northbound/sdnc-northbound-all/", def);
+ }
+
public static String getMdSalVersion(String baseOdlDirectory, String def) {
return getFeatureVersionByFolder(baseOdlDirectory, "system/org/opendaylight/mdsal/mdsal-binding-api/", def);
}
diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/DataMigrationProviderImpl.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/DataMigrationProviderImpl.java
index 100f52371..7d2adc5ad 100644
--- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/DataMigrationProviderImpl.java
+++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/DataMigrationProviderImpl.java
@@ -344,6 +344,7 @@ public class DataMigrationProviderImpl implements DataMigrationProviderService {
}
//check aliases
AliasesEntryList entries = this.readAliases();
+ IndicesEntryList entries2 = this.readIndices();
if (entries == null) {
return false;
}
@@ -381,9 +382,22 @@ public class DataMigrationProviderImpl implements DataMigrationProviderService {
return false;
}
}
+ else {
+ //try to find malformed typed index with alias name
+ IndicesEntry entry2ToDelete = entries2.findByIndex(aliasToDelete);
+ if (entry2ToDelete != null) {
+ try {
+ LOG.info("deleting index {}", entry2ToDelete.getName());
+ response = this.dbClient.deleteIndex(new DeleteIndexRequest(entry2ToDelete.getName()));
+ LOG.info(response.isResponseSucceeded() ? "succeeded" : "failed");
+ } catch (IOException e) {
+ LOG.error(e.getMessage());
+ return false;
+ }
+ }
+ }
}
}
- IndicesEntryList entries2 = this.readIndices();
if (entries2 == null) {
return false;
}
diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/Program.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/Program.java
index 4b201bccc..54204f170 100644
--- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/Program.java
+++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/Program.java
@@ -23,8 +23,13 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup;
import java.util.Arrays;
import java.util.List;
-
-import org.apache.commons.cli.*;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.ConsoleAppender;
@@ -293,17 +298,13 @@ public class Program {
}
private static void cmd_dbimport(CommandLine cmd) throws Exception {
- String dbUrl = getOptionOrDefault(cmd, OPTION_DATABASE_SHORT, DEFAULT_DBURL);
- String username = getOptionOrDefault(cmd, OPTION_DATABASEUSER_SHORT, null);
- String password = getOptionOrDefault(cmd, OPTION_DATABASEPASSWORD_SHORT, null);
+ DatabaseOptions options = new DatabaseOptions(cmd);
String filename = getOptionOrDefault(cmd, OPTION_OUTPUTFILE_SHORT, null);
- boolean trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, DEFAULT_TRUSTINSECURESSL);
if (filename == null) {
throw new Exception("please add output file parameter");
}
- long timeoutms = getTimeoutOptionMillis(cmd);
- DataMigrationProviderImpl service = new DataMigrationProviderImpl(new HostInfo[] {HostInfo.parse(dbUrl)},
- username, password, trustAll, timeoutms);
+ DataMigrationProviderImpl service = new DataMigrationProviderImpl(new HostInfo[] {HostInfo.parse(options.getUrl())},
+ options.getUsername(), options.getPassword(), options.doTrustAll(), options.getTimeoutMs());
DataMigrationReport report = service.importData(filename, false);
LOG.info(report);
if (!report.completed()) {
@@ -313,17 +314,13 @@ public class Program {
}
private static void cmd_dbexport(CommandLine cmd) throws Exception {
- String dbUrl = getOptionOrDefault(cmd, OPTION_DATABASE_SHORT, DEFAULT_DBURL);
- String username = getOptionOrDefault(cmd, OPTION_DATABASEUSER_SHORT, null);
- String password = getOptionOrDefault(cmd, OPTION_DATABASEPASSWORD_SHORT, null);
+ DatabaseOptions options = new DatabaseOptions(cmd);
String filename = getOptionOrDefault(cmd, OPTION_OUTPUTFILE_SHORT, null);
- boolean trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, DEFAULT_TRUSTINSECURESSL);
if (filename == null) {
throw new Exception("please add output file parameter");
}
- long timeoutms = getTimeoutOptionMillis(cmd);
- DataMigrationProviderImpl service = new DataMigrationProviderImpl(new HostInfo[] {HostInfo.parse(dbUrl)},
- username, password, trustAll, timeoutms);
+ DataMigrationProviderImpl service = new DataMigrationProviderImpl(new HostInfo[] {HostInfo.parse(options.getUrl())},
+ options.getUsername(), options.getPassword(), options.doTrustAll(), options.getTimeoutMs());
DataMigrationReport report = service.exportData(filename);
LOG.info(report);
if (!report.completed()) {
@@ -343,29 +340,21 @@ public class Program {
private static void cmd_clear_db(CommandLine cmd) throws Exception {
Release r = getOptionOrDefault(cmd, OPTION_VERSION_SHORT, (Release) null);
- String dbUrl = getOptionOrDefault(cmd, OPTION_DATABASE_SHORT, DEFAULT_DBURL);
+ DatabaseOptions options = new DatabaseOptions(cmd);
String dbPrefix = getOptionOrDefault(cmd, OPTION_DATABASEPREFIX_SHORT, DEFAULT_DBPREFIX);
- String username = getOptionOrDefault(cmd, OPTION_DATABASEUSER_SHORT, null);
- String password = getOptionOrDefault(cmd, OPTION_DATABASEPASSWORD_SHORT, null);
- boolean trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, DEFAULT_TRUSTINSECURESSL);
- long timeoutms = getTimeoutOptionMillis(cmd);
- DataMigrationProviderImpl service = new DataMigrationProviderImpl(new HostInfo[] {HostInfo.parse(dbUrl)},
- username, password, trustAll, timeoutms);
- if (!service.clearDatabase(r, dbPrefix, timeoutms)) {
+ DataMigrationProviderImpl service = new DataMigrationProviderImpl(new HostInfo[] {HostInfo.parse(options.getUrl())},
+ options.getUsername(), options.getPassword(), options.doTrustAll(), options.getTimeoutMs());
+ if (!service.clearDatabase(r, dbPrefix, options.getTimeoutMs())) {
throw new Exception("failed to init database");
}
LOG.info("database clear completed successfully");
}
private static void cmd_clear_db_complete(CommandLine cmd) throws Exception {
- String dbUrl = getOptionOrDefault(cmd, OPTION_DATABASE_SHORT, DEFAULT_DBURL);
- String username = getOptionOrDefault(cmd, OPTION_DATABASEUSER_SHORT, null);
- String password = getOptionOrDefault(cmd, OPTION_DATABASEPASSWORD_SHORT, null);
- boolean trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, DEFAULT_TRUSTINSECURESSL);
- long timeoutms = getTimeoutOptionMillis(cmd);
- DataMigrationProviderImpl service = new DataMigrationProviderImpl(new HostInfo[] {HostInfo.parse(dbUrl)},
- username, password, trustAll, timeoutms);
- if (!service.clearCompleteDatabase(timeoutms)) {
+ DatabaseOptions options = new DatabaseOptions(cmd);
+ DataMigrationProviderImpl service = new DataMigrationProviderImpl(new HostInfo[] {HostInfo.parse(options.getUrl())},
+ options.getUsername(), options.getPassword(), options.doTrustAll(), options.getTimeoutMs());
+ if (!service.clearCompleteDatabase(options.getTimeoutMs())) {
throw new Exception("failed to init database");
}
LOG.info("database complete clear completed successfully");
@@ -375,16 +364,12 @@ public class Program {
Release r = getOptionOrDefault(cmd, OPTION_VERSION_SHORT, (Release) null);
int numShards = getOptionOrDefault(cmd, OPTION_SHARDS_SHORT, DEFAULT_SHARDS);
int numReplicas = getOptionOrDefault(cmd, OPTION_REPLICAS_SHORT, DEFAULT_REPLICAS);
- String dbUrl = getOptionOrDefault(cmd, OPTION_DATABASE_SHORT, DEFAULT_DBURL);
+ DatabaseOptions options = new DatabaseOptions(cmd);
String dbPrefix = getOptionOrDefault(cmd, OPTION_DATABASEPREFIX_SHORT, DEFAULT_DBPREFIX);
- String username = getOptionOrDefault(cmd, OPTION_DATABASEUSER_SHORT, null);
- String password = getOptionOrDefault(cmd, OPTION_DATABASEPASSWORD_SHORT, null);
- boolean trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, DEFAULT_TRUSTINSECURESSL);
- long timeoutms = getTimeoutOptionMillis(cmd);
- DataMigrationProviderImpl service = new DataMigrationProviderImpl(new HostInfo[] {HostInfo.parse(dbUrl)},
- username, password, trustAll, timeoutms);
+ DataMigrationProviderImpl service = new DataMigrationProviderImpl(new HostInfo[] {HostInfo.parse(options.getUrl())},
+ options.getUsername(), options.getPassword(), options.doTrustAll(), options.getTimeoutMs());
boolean forceRecreate = cmd.hasOption(OPTION_FORCE_RECREATE_SHORT);
- if (!service.initDatabase(r, numShards, numReplicas, dbPrefix, forceRecreate, timeoutms)) {
+ if (!service.initDatabase(r, numShards, numReplicas, dbPrefix, forceRecreate, options.getTimeoutMs())) {
throw new Exception("failed to init database");
}
LOG.info("database init completed successfully");
@@ -425,7 +410,7 @@ public class Program {
/**
* create option for argparse lib
- *
+ *
* @param opt short option string
* @param longOpt long option string
* @param hasArg flag if has a parameter after option tag
@@ -440,4 +425,35 @@ public class Program {
return o;
}
// end of private methods
+
+ private static class DatabaseOptions{
+ private final String url;
+ private final String username;
+ private final String password;
+ private final boolean trustAll;
+ private final long timeoutMs;
+
+ public String getUrl() {
+ return this.url;
+ }
+ public String getUsername() {
+ return this.username;
+ }
+ public String getPassword() {
+ return this.password;
+ }
+ public boolean doTrustAll() {
+ return this.trustAll;
+ }
+ public long getTimeoutMs() {
+ return this.timeoutMs;
+ }
+ public DatabaseOptions(CommandLine cmd) throws ParseException {
+ this.url = getOptionOrDefault(cmd, OPTION_DATABASE_SHORT, DEFAULT_DBURL);
+ this.username = getOptionOrDefault(cmd, OPTION_DATABASEUSER_SHORT, null);
+ this.password = getOptionOrDefault(cmd, OPTION_DATABASEPASSWORD_SHORT, null);
+ this.trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, DEFAULT_TRUSTINSECURESSL);
+ this.timeoutMs = getTimeoutOptionMillis(cmd);
+ }
+ }
}