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;
}
use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.
the class EmbeddedOpenDS method getServerSet.
/**
* Gets list of replicated servers from local OpenDJ directory.
*/
public static Set getServerSet(Connection lc) {
final String[] attrs = { "uniqueMember" };
Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
try {
if (lc != null) {
SearchResultEntry le = lc.searchSingleEntry(LDAPRequests.newSingleEntrySearchRequest(replDN, attrs));
if (le != null) {
Set hostSet = new HashSet();
Attribute la = le.getAttribute(attrs[0]);
if (la != null) {
for (ByteString value : la) {
hostSet.add(value.toString().substring(3, value.length()));
}
}
return hostSet;
} else {
debug.error("EmbeddedOpenDS:syncOpenDSServer():" + "Could not find trustkey for:" + replDN);
}
} else {
debug.error("EmbeddedOpenDS:syncOpenDSServer():" + "Could not connect to local opends instance.");
}
} catch (Exception ex) {
debug.error("EmbeddedOpenDS.syncOpenDSServer()." + " Error getting replication key:", ex);
}
return null;
}
Aggregations