use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.
the class DefaultDebugRecorder method startRecording.
/**
* Start recording an issue
*
* @param jsonProperties
* @throws RecordException throw a RecordException if the issueID doesn't exist
*/
public synchronized void startRecording(JsonValue jsonProperties) throws RecordException {
RecordProperties recordProperties = RecordProperties.fromJson(jsonProperties);
Record record = createRecord(recordProperties);
if (isRecording()) {
debug.message("Issue '{}' was recording, we stop it.", currentRecord);
stopRecording();
}
previousDebugDirectory = SystemPropertiesManager.get(DebugConstants.CONFIG_DEBUG_DIRECTORY);
debug.message("Start recording issue '{}'.", record);
//we switch the OpenAM debug folder with the issue folder
changeOpenAMDebugFolder(record.getFolderPath() + File.separator + RecordConstants.DEBUG_FOLDER_NAME);
currentRecord = record;
currentRecord.startRecord();
//We will switch the debug level with the one required for the issue
previousDebugLevel = new HashMap<Debug, Integer>();
List<Debug> debugInstances = new ArrayList<Debug>(Debug.getInstances());
for (Debug debug : debugInstances) {
previousDebugLevel.put(debug, debug.getState());
debug.setDebug(record.getRecordProperties().getDebugLevel().getName());
}
//Export Config export
exportConfigExport();
//We start the different threads
try {
startThreadDump();
} catch (IOException e) {
debug.error("Thread dump can't be enable", e);
throw new RecordException("Thread dump can't be enable", e);
}
startAutoStopRecording();
}
use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.
the class DebugPropertiesObserver method notifyChanges.
/**
* This method will be call if configuration changed.
*/
public synchronized void notifyChanges() {
String state = SystemProperties.get(Constants.SERVICES_DEBUG_LEVEL);
if (!currentState.equals(state)) {
Collection debugInstances = Debug.getInstances();
for (Object debugInstance : debugInstances) {
Debug d = (Debug) debugInstance;
d.setDebug(state);
}
currentState = state;
}
String mergeflag = SystemProperties.get(Constants.SERVICES_DEBUG_MERGEALL);
if (!currentMergeFlag.equals(mergeflag)) {
Collection debugInstances = Debug.getInstances();
for (Object debugInstance : debugInstances) {
Debug d = (Debug) debugInstance;
d.resetDebug(mergeflag);
}
currentMergeFlag = mergeflag;
}
}
use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.
the class EmbeddedOpenDS method delOpenDSServer.
/**
* Removes host:port from OpenDJ replication
*/
public static void delOpenDSServer(Connection lc, String delServer) {
String replServerDN = "cn=" + delServer + ",cn=Servers,cn=admin data";
final String[] attrs = { "ds-cfg-key-id" };
Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
if (lc == null) {
debug.error("EmbeddedOpenDS:syncOpenDSServer():" + "Could not connect to local OpenDJ instance." + replServerDN);
return;
}
String trustKey = null;
try {
SearchResultEntry le = lc.searchSingleEntry(LDAPRequests.newSingleEntrySearchRequest(replServerDN, attrs));
if (le != null) {
Attribute la = le.getAttribute(attrs[0]);
if (la != null) {
trustKey = la.firstValueAsString();
}
String keyDN = "ds-cfg-key-id=" + trustKey + ",cn=instance keys,cn=admin data";
lc.delete(LDAPRequests.newDeleteRequest(keyDN));
} else {
debug.error("EmbeddedOpenDS:syncOpenDSServer():" + "Could not find trustkey for:" + replServerDN);
}
} catch (Exception ex) {
debug.error("EmbeddedOpenDS.syncOpenDSServer()." + " Error getting replication key:", ex);
}
try {
lc.delete(LDAPRequests.newDeleteRequest(replServerDN));
} catch (Exception ex) {
debug.error("EmbeddedOpenDS.syncOpenDSServer()." + " Error getting deleting server entry:" + replServerDN, ex);
}
try {
ModifyRequest modifyRequest = LDAPRequests.newModifyRequest(replDN).addModification(new Modification(ModificationType.DELETE, Attributes.singletonAttribute("uniqueMember", "cn=" + delServer)));
lc.modify(modifyRequest);
} catch (Exception ex) {
debug.error("EmbeddedOpenDS.syncOpenDSServer()." + " Error getting removing :" + replDN, ex);
}
}
use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.
the class EmbeddedOpenDS method getReplicationStatus.
/**
* Returns Replication Status by invoking OpenDJ <code>dsreplication</code>
* CLI
*
* @param port LDAP port number of embedded OpenDJ
* @param passwd Directory Manager password
* @param oo Standard output
* @param err : Standard error
* @return <code>dsreplication</code> CLI exit code.
*/
public static int getReplicationStatus(String port, String passwd, OutputStream oo, OutputStream err) {
Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
String baseDir = SystemProperties.get(SystemProperties.CONFIG_PATH);
String[] statusCmd = { "status", "--no-prompt", "-h", "localhost", "-p", port, "--adminUID", "admin", "--adminPassword", passwd, "-s", "--configFile", baseDir + "/opends/config/config.ldif", "--noPropertiesFile" };
if (debug.messageEnabled()) {
String dbgcmd = concat(statusCmd).replaceAll(passwd, "****");
debug.message("EmbeddedOpenDS:getReplicationStatus:exec dsreplication :" + dbgcmd);
}
int ret = ReplicationCliMain.mainCLI(statusCmd, false, oo, err);
if (debug.messageEnabled()) {
debug.message("EmbeddedOpenDS:getReplicationStatus:dsreplication ret:" + ret);
}
return ret;
}
use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.
the class EmbeddedOpenDS method syncReplicatedServers.
/**
* Synchronizes replication server info with current list of OpenAM servers.
*/
public static boolean syncReplicatedServers(Set currServerSet, String port, String passwd) {
Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
debug.message("EmbeddedOPenDS:syncReplication:start processing.");
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-server", "--provider-name", "Multimaster Synchronization", "--property", "replication-server", "--property", "replication-port", "--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();
final boolean hasReplicationServers = !stre.contains("Unable to continue since there are no Replication " + "Server currently");
if (!stre.isEmpty() && hasReplicationServers) {
debug.error("EmbeddedOpenDS:syncReplication: stderr is not empty:" + stre);
return false;
} else {
if (debug.messageEnabled()) {
debug.message("EmbeddedOpenDS:syncReplication: stderr is not empty:" + stre);
}
}
/*
v2.6 output example
Replication Server : replication-server : replication-port
-------------------:----------------------------------------------:-----------------
replication-server : dj1.example.com:58989, dj2.example.com:50889 : 50889
*/
BufferedReader brd = new BufferedReader(new StringReader(str));
String line = null;
try {
// 1st line
line = brd.readLine();
// 2nd line
line = brd.readLine();
// 3rd line
line = brd.readLine();
} catch (Exception ex) {
debug.error("EmbeddedOpenDS:syncReplication:Failed:", ex);
}
if (line == null) {
if (hasReplicationServers) {
debug.error("EmbeddedOpenDS:syncReplication:cmd failed" + str);
}
return false;
}
try {
int lastcolon = line.lastIndexOf(':');
int stcolon = line.indexOf(':');
String replservers = line.substring(stcolon + 1, lastcolon);
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-server-prop");
cmdlist.add("--provider-name");
cmdlist.add("Multimaster Synchronization");
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 (debug.messageEnabled()) {
debug.message("EmbeddedOpenDS:syncReplication:Result:" + str);
}
if (stre.length() != 0) {
debug.error("EmbeddedOpenDS:syncReplication:cmd stderr:" + stre);
}
}
} catch (Exception ex) {
debug.error("EmbeddedOpenDS:syncReplication:Failed:", ex);
return false;
}
return true;
}
Aggregations