Search in sources :

Example 36 with Debug

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);
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) ShutdownManager(com.sun.identity.common.ShutdownManager) DirectoryEnvironmentConfig(org.opends.server.types.DirectoryEnvironmentConfig) ZipFile(java.util.zip.ZipFile) File(java.io.File) Debug(com.sun.identity.shared.debug.Debug) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) LdapException(org.forgerock.opendj.ldap.LdapException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IOException(java.io.IOException)

Example 37 with Debug

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;
}
Also used : ByteString(org.forgerock.opendj.ldap.ByteString) ZipFile(java.util.zip.ZipFile) File(java.io.File) Debug(com.sun.identity.shared.debug.Debug) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) LdapException(org.forgerock.opendj.ldap.LdapException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IOException(java.io.IOException)

Example 38 with Debug

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.");
    }
}
Also used : Debug(com.sun.identity.shared.debug.Debug)

Example 39 with Debug

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;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ByteString(org.forgerock.opendj.ldap.ByteString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Debug(com.sun.identity.shared.debug.Debug)

Example 40 with Debug

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Attribute(org.forgerock.opendj.ldap.Attribute) ByteString(org.forgerock.opendj.ldap.ByteString) ByteString(org.forgerock.opendj.ldap.ByteString) Debug(com.sun.identity.shared.debug.Debug) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) LdapException(org.forgerock.opendj.ldap.LdapException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IOException(java.io.IOException) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry) HashSet(java.util.HashSet)

Aggregations

Debug (com.sun.identity.shared.debug.Debug)50 BeforeMethod (org.testng.annotations.BeforeMethod)15 IOException (java.io.IOException)14 ByteString (org.forgerock.opendj.ldap.ByteString)10 FileNotFoundException (java.io.FileNotFoundException)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)7 HashSet (java.util.HashSet)6 LdapException (org.forgerock.opendj.ldap.LdapException)6 BufferedReader (java.io.BufferedReader)5 File (java.io.File)5 Subject (javax.security.auth.Subject)5 CoreWrapper (org.forgerock.openam.core.CoreWrapper)5 Test (org.testng.annotations.Test)5 StringReader (java.io.StringReader)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 SSOToken (com.iplanet.sso.SSOToken)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ArrayList (java.util.ArrayList)3 ZipFile (java.util.zip.ZipFile)3