use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.
the class EmbeddedOpenDS method syncReplicatedDomains.
/**
* Synchronizes replication domain info with current list of OpenAM servers.
*/
public static boolean syncReplicatedDomains(Set currServerSet, String port, String passwd) {
Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
debug.message("EmbeddedOpenDS:syncReplication:Domains:started");
String[] args = { // 1 : ds port num
"-p", // 1 : ds port num
port, "-h", "localhost", "-D", "cn=directory manager", // 7 : password
"-w", // 7 : password
passwd, "list-replication-domains", "--provider-name", "Multimaster Synchronization", "--property", "replication-server", "--no-prompt", "--trustAll", "--noPropertiesFile" };
if (debug.messageEnabled()) {
String dbgcmd = concat(args).replaceAll(passwd, "****");
debug.message("EmbeddedOpenDS:syncReplication:exec dsconfig:" + dbgcmd);
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ByteArrayOutputStream boe = new ByteArrayOutputStream();
DSConfig.main(args, bos, boe);
String str = bos.toString();
String stre = boe.toString();
if (stre.length() != 0) {
debug.error("EmbeddedOpenDS:syncReplication:stderr:" + stre);
}
/*
v2.6 output example
Replication Domain : replication-server
------------------------------:---------------------------------------------
cn=admin data : dj1.example.com:58989, dj2.example.com:50889
cn=schema : dj1.example.com:58989, dj2.example.com:50889
dc=openam,dc=forgerock,dc=org : dj1.example.com:58989, dj2.example.com:50889
*/
BufferedReader brd = new BufferedReader(new StringReader(str));
String line = null;
try {
// 1st line
line = brd.readLine();
// 2nd line
line = brd.readLine();
while ((line = brd.readLine()) != null) {
try {
int dcolon = line.indexOf(':');
String domainname = line.substring(0, dcolon).trim();
int stcolon = dcolon + 1;
String replservers = line.substring(stcolon + 1);
if (debug.messageEnabled()) {
debug.message("EmbeddedOpenDS:syncRepl:domain=" + domainname + " replservers=" + replservers);
}
StringTokenizer stok = new StringTokenizer(replservers, ",");
// Check if this server is part of server list
List cmdlist = new ArrayList();
cmdlist.add("-p");
cmdlist.add(port);
cmdlist.add("-h");
cmdlist.add("localhost");
cmdlist.add("-D");
cmdlist.add("cn=directory manager");
cmdlist.add("-w");
cmdlist.add(passwd);
cmdlist.add("--no-prompt");
cmdlist.add("--trustAll");
cmdlist.add("set-replication-domain-prop");
cmdlist.add("--provider-name");
cmdlist.add("Multimaster Synchronization");
cmdlist.add("--domain-name");
cmdlist.add(domainname);
cmdlist.add("--noPropertiesFile");
int numremoved = 0;
while (stok.hasMoreTokens()) {
String tok = stok.nextToken().trim();
if (!currServerSet.contains(tok)) {
cmdlist.add("--remove");
cmdlist.add("replication-server:" + tok);
numremoved++;
}
}
if (numremoved > 0) {
String[] args1 = (String[]) cmdlist.toArray(new String[cmdlist.size()]);
if (debug.messageEnabled()) {
String dbgcmd1 = concat(args1).replaceAll(passwd, "****");
debug.message("EmbeddedOpenDS:syncReplication:Execute:" + dbgcmd1);
}
bos = new ByteArrayOutputStream();
boe = new ByteArrayOutputStream();
DSConfig.main(args1, bos, boe);
str = bos.toString();
stre = boe.toString();
if (stre.length() != 0) {
debug.error("EmbeddedOpenDS:syncRepl:stderr=" + stre);
}
if (debug.messageEnabled()) {
debug.message("EmbeddedOpenDS:syncReplication:Result:" + str);
}
}
} catch (Exception ex) {
debug.error("EmbeddedOpenDS:syncReplication:Failed:", ex);
return false;
}
}
} catch (Exception ex) {
debug.error("EmbeddedOpenDS:syncReplication:Failed:", ex);
return false;
}
return true;
}
use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.
the class EmbeddedOpenDS method startServer.
/**
* Starts the embedded <code>OpenDJ</code> instance.
*
* @param odsRoot File system directory where <code>OpenDJ</code>
* is installed.
* @throws Exception upon encountering errors.
*/
public static void startServer(String odsRoot) throws Exception {
if (isStarted()) {
return;
}
Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
debug.message("EmbeddedOpenDS.startServer(" + odsRoot + ")");
DirectoryEnvironmentConfig config = new DirectoryEnvironmentConfig();
config.setServerRoot(new File(odsRoot));
config.setForceDaemonThreads(true);
config.setConfigClass(ConfigFileHandler.class);
config.setConfigFile(new File(odsRoot + "/config", "config.ldif"));
debug.message("EmbeddedOpenDS.startServer:starting DS Server...");
EmbeddedUtils.startServer(config);
debug.message("...EmbeddedOpenDS.startServer:DS Server started.");
int sleepcount = 0;
while (!EmbeddedUtils.isRunning() && (sleepcount < 60)) {
sleepcount++;
SetupProgress.reportStart("emb.waitingforstarted", null);
Thread.sleep(1000);
}
if (EmbeddedUtils.isRunning()) {
SetupProgress.reportEnd("emb.success", null);
} else {
SetupProgress.reportEnd("emb.failed", null);
}
serverStarted = true;
ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
shutdownMan.addShutdownListener(new ShutdownListener() {
public void shutdown() {
try {
shutdownServer("Graceful Shutdown");
} catch (Exception ex) {
Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
debug.error("EmbeddedOpenDS:shutdown hook failed", ex);
}
}
}, ShutdownPriority.LOWEST);
}
use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.
the class EmbeddedOpenDS method loadLDIF.
/**
* 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 = { // 0
"-C", // 1
"org.opends.server.extensions.ConfigFileHandler", // 2
"-f", // 3
odsRoot + "/config/config.ldif", // 4
"-n", // 5
"userRoot", // 6
"-l", // 7
ldif, // 8
"--trustAll", // 9
"-D", // 10
"cn=Directory Manager", // 11
"-w", // 12
"password", // 13
"--noPropertiesFile" };
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;
}
use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.
the class EmbeddedOpenDS method shutdownServer.
/**
* Gracefully shuts down the embedded OpenDJ instance.
*
* @param reason string representing reason why shutdown was called.
* @throws Exception on encountering errors.
*/
public static void shutdownServer(String reason) throws Exception {
Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
if (isStarted()) {
debug.message("EmbeddedOpenDS.shutdown server...");
DirectoryServer.shutDown("com.sun.identity.setup.EmbeddedOpenDS", LocalizableMessage.EMPTY);
int sleepcount = 0;
while (DirectoryServer.isRunning() && (sleepcount < 60)) {
sleepcount++;
Thread.sleep(1000);
}
serverStarted = false;
debug.message("EmbeddedOpenDS.shutdown server success.");
}
}
use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.
the class EmbeddedOpenDS method rebuildIndex.
// Programmatic way of rebuilding indexes in OpenDJ.
// This method simulates the OpenDJ cli command rebuild-index.
// eg., rebuild-index -b dc=example,dc=com -i uid -i mail
public static int rebuildIndex(Map map) throws Exception {
int ret = 0;
shutdownServer("Rebuild index");
Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
String[] args = { "--configClass", "org.opends.server.extensions.ConfigFileHandler", "--configFile", getOpenDJConfigFile(map), "--baseDN", (String) map.get(SetupConstants.CONFIG_VAR_ROOT_SUFFIX), "--rebuildAll", "--noPropertiesFile" };
OutputStream bos = new ByteArrayOutputStream();
OutputStream boe = new ByteArrayOutputStream();
TimeThread.start();
ret = RebuildIndex.mainRebuildIndex(args, true, bos, boe);
TimeThread.stop();
String outStr = bos.toString();
String errStr = boe.toString();
if (errStr.length() != 0) {
debug.error("EmbeddedOpenDS:rebuildIndex:stderr=" + errStr);
}
if (debug.messageEnabled()) {
String msg = "msg=Rebuild complete.";
int idx = outStr.indexOf(msg);
if (idx >= 0) {
debug.message("EmbeddedOpenDS:rebuildIndex: " + "Rebuild Status: " + outStr.substring(idx));
}
debug.message("EmbeddedOpenDS:rebuildIndex:Result:" + outStr);
}
startServer(getOpenDJBaseDir(map));
return ret;
}
Aggregations