Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package com.redhat.lightblue.common.ldap;

import java.util.Map;

import com.redhat.lightblue.metadata.DataStore;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;
Expand All @@ -36,5 +38,13 @@ public interface DBResolver {
* to the same database.
*/
LDAPConnection get(DataStore store) throws LDAPException;



/**
* @return A {@link Map} of LDAP Database name and corresponding connection
* status as true/false. The status may be an object of
* {@link LDAPException} if no connection is available, or a problem
* occurs while creating a new connection to return
*/
Map<String, Object> getLDAPConnectionsStatus();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package com.redhat.lightblue.config.ldap;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.redhat.lightblue.common.ldap.DBResolver;
Expand Down Expand Up @@ -68,4 +70,27 @@ private LdapDataSourceConfiguration findByDatabase(String database){
return null;
}

@Override
public Map<String, Object> getLDAPConnectionsStatus() {

Map<String, Object> connectionsStatus = new HashMap<>();
LDAPConnection connection = null;

for (LdapDataSourceConfiguration ldapDS : ldapDataSources) {
try {
connection = ldapDS.getLdapConnection();

// If a problem is detected that suggests that the provided
// connection is not suitable for use, LDAPException would be
// thrown.
ldapDS.getLdapConnectionPool().getHealthCheck().ensureConnectionValidForContinuedUse(connection);

connectionsStatus.put(ldapDS.getDatabaseName(), connection.isConnected());
} catch (LDAPException e) {
connectionsStatus.put(ldapDS.getDatabaseName(), e);
}
}

return connectionsStatus;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ public LDAPConnection getLdapConnection() throws LDAPException{
}
return connectionPool.getConnection();
}

public LDAPConnectionPool getLdapConnectionPool() throws LDAPException{
if(connectionPool == null){
throw new IllegalStateException("Class has not yet been initialized");
}
return connectionPool;
}

@Override
public void initializeFromJson(JsonNode node) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
/*
Copyright 2014 Red Hat, Inc. and/or its affiliates.

This file is part of lightblue.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -43,6 +39,7 @@
import com.redhat.lightblue.crud.CRUDUpdateResponse;
import com.redhat.lightblue.crud.CrudConstants;
import com.redhat.lightblue.crud.DocCtx;
import com.redhat.lightblue.crud.CRUDHealth;
import com.redhat.lightblue.crud.ListDocumentStream;
import com.redhat.lightblue.crud.ldap.translator.EntryTranslatorFromJson;
import com.redhat.lightblue.crud.ldap.translator.ModificationTranslatorFromJson;
Expand Down Expand Up @@ -533,5 +530,26 @@ private abstract class ExecutionHandler {
abstract void onSuccess(LDAPResult result);

}

@Override
public CRUDHealth checkHealth() {
boolean isHealthy = true;
Map<String, Object> ldapConnnectionsStatus = dbResolver.getLDAPConnectionsStatus();
List<String> details = new ArrayList<>(ldapConnnectionsStatus.size());

for (Map.Entry<String, Object> connectionStatus : ldapConnnectionsStatus.entrySet()) {

if (connectionStatus.getValue() instanceof LDAPException) {
isHealthy = false;
details.add(new StringBuilder("LDAPConnection [DatabaseName: ").append(connectionStatus.getKey())
.append(", Status: ").append(connectionStatus.getValue()).toString());
} else {
isHealthy = (Boolean) connectionStatus.getValue();

details.add(new StringBuilder("LDAPConnection [DatabaseName: ").append(connectionStatus.getKey())
.append(", Status: ").append(connectionStatus.getValue()).toString());
}
}
return new CRUDHealth(isHealthy, details.toString());
}
}