/** * Syncs replication data between two OpenDJ sms and user stores. $ dsreplication initialize * --baseDN "dc=example,dc=com" --adminUID admin --adminPassword pass --hostSource host1 * --portSource 1389 --hostDestination host2 --portDestination 2389 --trustAll * * @param map Map of properties collected by the configurator. * @return status : 0 == success, !0 == failure */ public static int setupReplicationInitialize(Map map) { String[] initializeCmd = { "initialize", // 0 "--no-prompt", // 1 "--baseDN", // 2 Constants.DEFAULT_ROOT_SUFFIX, // 3 Placeholder "--adminUID", // 4 "admin", // 5 "--adminPassword", // 6 "xxxxxxxx", // 7 "--hostSource", // 8 "localhost", // 9 "--portSource", // 10 "50389", // 11 "--hostDestination", // 12 "localhost", // 13 "--portDestination", // 14 "51389", // 15 "--trustAll", // 16 "--configFile", // 17 "path/to/config.ldif" // 18 }; initializeCmd[3] = (String) map.get(SetupConstants.CONFIG_VAR_ROOT_SUFFIX); initializeCmd[9] = (String) map.get(SetupConstants.DS_EMB_REPL_HOST2); initializeCmd[11] = (String) map.get(SetupConstants.DS_EMB_REPL_ADMINPORT2); initializeCmd[13] = getOpenDJHostName(map); initializeCmd[15] = (String) map.get(SetupConstants.CONFIG_VAR_DIRECTORY_ADMIN_SERVER_PORT); initializeCmd[18] = getOpenDJConfigFile(map); Object[] params = {concat(initializeCmd)}; SetupProgress.reportStart("emb.replcommand", params); initializeCmd[7] = (String) map.get(SetupConstants.CONFIG_VAR_DS_MGR_PWD); int ret = ReplicationCliMain.mainCLI( initializeCmd, false, SetupProgress.getOutputStream(), SetupProgress.getOutputStream(), null); if (ret == 0) { SetupProgress.reportEnd("emb.success", null); } else { SetupProgress.reportEnd("emb.failed", null); } return ret; }
/** * Runs the OpenDJ setup command like this: $ ./setup --cli --adminConnectorPort 4444 --baseDN * dc=openam,dc=forgerock,dc=org --rootUserDN "cn=directory manager" --doNotStart --ldapPort 50389 * --skipPortCheck --rootUserPassword xxxxxxx --jmxPort 1689 --no-prompt * * @param map Map of properties collected by the configurator. * @return status : 0 == success, !0 == failure */ public static int runOpenDSSetup(Map map) { String[] setupCmd = { "--cli", // 0 "--adminConnectorPort", // 1 "4444", // 2 "--baseDN", // 3 Constants.DEFAULT_ROOT_SUFFIX, // 4 "--rootUserDN", // 5 "cn=Directory Manager", // 6 "--ldapPort", // 7 "50389", // 8 "--skipPortCheck", // 9 "--rootUserPassword", // 10 "xxxxxxx", // 11 "--jmxPort", // 12 "1689", // 13 "--no-prompt", // 14 "--doNotStart", // 15 "--hostname", // 16 "hostname" // 17 }; setupCmd[2] = (String) map.get(SetupConstants.CONFIG_VAR_DIRECTORY_ADMIN_SERVER_PORT); setupCmd[4] = (String) map.get(SetupConstants.CONFIG_VAR_ROOT_SUFFIX); setupCmd[6] = (String) map.get(SetupConstants.CONFIG_VAR_DS_MGR_DN); setupCmd[8] = (String) map.get(SetupConstants.CONFIG_VAR_DIRECTORY_SERVER_PORT); setupCmd[13] = (String) map.get(SetupConstants.CONFIG_VAR_DIRECTORY_JMX_SERVER_PORT); setupCmd[17] = getOpenDJHostName(map); Object[] params = {concat(setupCmd)}; SetupProgress.reportStart("emb.setupcommand", params); setupCmd[11] = (String) map.get(SetupConstants.CONFIG_VAR_DS_MGR_PWD); int ret = InstallDS.mainCLI( setupCmd, SetupProgress.getOutputStream(), SetupProgress.getOutputStream(), null); if (ret == 0) { SetupProgress.reportEnd("emb.success", null); } else { SetupProgress.reportEnd("emb.failed", null); } return ret; }
/** * Utility function to preload data in the embedded instance. Must be called when the directory * instance is shutdown. * * @param odsRoot Local directory where <code>OpenDJ</code> is installed. * @param ldif Full path of the ldif file to be loaded. */ public static int loadLDIF(Map map, String odsRoot, String ldif) { int ret = 0; Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME); File ldifFile = new File(ldif); if (!ldifFile.exists()) { debug.error("LDIF File:" + ldifFile.getAbsolutePath() + " does not exist, unable to load!"); return -1; } try { if (debug.messageEnabled()) { debug.message("EmbeddedOpenDS:loadLDIF(" + ldif + ")"); } String[] args1 = { "-C", // 0 "org.opends.server.extensions.ConfigFileHandler", // 1 "-f", // 2 odsRoot + "/config/config.ldif", // 3 "-n", // 4 "userRoot", // 5 "-l", // 6 ldif, // 7 "--trustAll", // 8 "-D", // 9 "cn=Directory Manager", // 10 "-w", // 11 "password" // 12 }; args1[10] = (String) map.get(SetupConstants.CONFIG_VAR_DS_MGR_DN); args1[12] = (String) map.get(SetupConstants.CONFIG_VAR_DS_MGR_PWD); ret = org.opends.server.tools.ImportLDIF.mainImportLDIF( args1, false, SetupProgress.getOutputStream(), SetupProgress.getOutputStream()); if (debug.messageEnabled()) { debug.message("EmbeddedOpenDS:loadLDIF Success"); } } catch (Exception ex) { debug.error("EmbeddedOpenDS:loadLDIF:ex=", ex); } return ret; }
/** * Setups replication between two OpenDJ sms and user stores. $ dsreplication enable --no-prompt * --host1 host1 --port1 1389 --bindDN1 "cn=Directory Manager" --bindPassword1 password * --replicationPort1 8989 --host2 host2 --port2 2389 --bindDN2 "cn=Directory Manager" * --bindPassword2 password --replicationPort2 8990 --adminUID admin --adminPassword password * --baseDN "dc=example,dc=com" * * @param map Map of properties collected by the configurator. * @return status : 0 == success, !0 == failure */ public static int setupReplicationEnable(Map map) { String[] enableCmd = { "enable", // 0 "--no-prompt", // 1 "--host1", // 2 "host1val", // 3 "--port1", // 4 "port1ival", // 5 "--bindDN1", // 6 "cn=Directory Manager", // 7 "--bindPassword1", // 8 "xxxxxxxx", // 9 "--replicationPort1", // 10 "8989", // 11 "--host2", // 12 "host2val", // 13 "--port2", // 14 "port2ival", // 15 "--bindDN2", // 16 "cn=Directory Manager", // 17 "--bindPassword2", // 18 "xxxxxxxx", // 19 "--replicationPort2", // 20 "8989", // 21 "--adminUID", // 22 "admin", // 23 "--adminPassword", // 24 "xxxxxxxx", // 25 "--baseDN", // 26 "dc=example,dc=com", // 27 "--trustAll", // 28 "--configFile", // 29 "path/to/config.ldif" // 30 }; enableCmd[3] = (String) map.get(SetupConstants.DS_EMB_REPL_HOST2); enableCmd[5] = (String) map.get(SetupConstants.DS_EMB_REPL_ADMINPORT2); enableCmd[11] = (String) map.get(SetupConstants.DS_EMB_REPL_REPLPORT2); enableCmd[13] = getOpenDJHostName(map); enableCmd[15] = (String) map.get(SetupConstants.CONFIG_VAR_DIRECTORY_ADMIN_SERVER_PORT); enableCmd[21] = (String) map.get(SetupConstants.DS_EMB_REPL_REPLPORT1); enableCmd[27] = (String) map.get(SetupConstants.CONFIG_VAR_ROOT_SUFFIX); enableCmd[30] = getOpenDJConfigFile(map); Object[] params = {concat(enableCmd)}; SetupProgress.reportStart("emb.replcommand", params); enableCmd[9] = (String) map.get(SetupConstants.CONFIG_VAR_DS_MGR_PWD); enableCmd[19] = (String) map.get(SetupConstants.CONFIG_VAR_DS_MGR_PWD); enableCmd[25] = (String) map.get(SetupConstants.CONFIG_VAR_DS_MGR_PWD); Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME); if (debug.messageEnabled()) { debug.message("EmbeddedOpenDS.setupReplicationEnable: " + "Host 1 " + enableCmd[3]); debug.message("EmbeddedOpenDS.setupReplicationEnable: " + "Host 2 " + enableCmd[13]); debug.message("EmbeddedOpenDS.setupReplicationEnable: " + "Port 1 " + enableCmd[5]); debug.message("EmbeddedOpenDS.setupReplicationEnable: " + "Port 2 " + enableCmd[15]); } int ret = ReplicationCliMain.mainCLI( enableCmd, false, SetupProgress.getOutputStream(), SetupProgress.getOutputStream(), null); if (ret == 0) { SetupProgress.reportEnd("emb.success", null); } else { SetupProgress.reportEnd("emb.failed", null); } return ret; }