Monday, January 5, 2015

Checking WebSphere Commerce Search Server Configuration

Sometimes there is a need to retrieve the search server configuration information from a live server to validate the search configurations, here is a class could be used to do that:

The information displayed is retrieved from the following configuration files:

In Search project:
xml/config/com.ibm.commerce.catalog.ext/wc-search.xml
xml/config/com.ibm.commerce.catalog/wc-search.xml

public class SearchServerConfigInfo {

    public static String getAllSearchServerConfigsInfo() {
        final SolrSearchConfigurationRegistry catalogReg = SolrSearchConfigurationRegistry
                .getInstance("com.ibm.commerce.catalog");
        final Field f;
        final StringBuilder result = new StringBuilder();
        try {
            f = SolrSearchConfigurationRegistry.class.getDeclaredField("imapSolrSearchServerConfigByCoreName");
            f.setAccessible(true);
            final Map<String, SolrSearchServerConfig> coreSearchServerConfigMap = (Map<String, SolrSearchServerConfig>) f
                    .get(catalogReg);
            final Set<String> coreNames = coreSearchServerConfigMap.keySet();
            SolrSearchServerConfig searchConf;
            result.append("\n=== === ===\nSearch Configuration:\n--- --- ---\n");
            for (String coreName : coreNames) {
                searchConf = catalogReg.getSolrSearchServerConfiguration(coreName);

                if (searchConf != null) {
                    result.append("coreName:").append(coreName).append('\n');
                    String corePath = catalogReg.getCorePath(coreName);
                    result.append("corePath:").append(corePath).append('\n');
                    String masterCatalog = catalogReg.getMasterCatalog(coreName);
                    result.append("masterCatalog:").append(masterCatalog).append('\n');
                    String languageId = catalogReg.getLanguageId(coreName);
                    result.append("languageId:").append(languageId).append('\n');
                    String name = searchConf.getName();
                    result.append("name:").append(name).append('\n');

                    Map<String, String> searchServerConfMap = searchConf.getConfigParameters();
                    Set keys = searchServerConfMap.keySet();
                    result.append("parameters:[");
                    for (Object keyObject : keys) {
                        String key = (String) keyObject;
                        result.append("key=").append(key).append(',');
                        String val = searchServerConfMap.get(key);
                        result.append("value=").append(val).append(';');
                    }
                    result.append("]\n");

                    boolean isEmbeddedServer = searchConf.isEmbeddedServer();
                    result.append("isEmbeddedServer:").append(isEmbeddedServer).append('\n');

                    SolrSearchServerConfig.CommonHttpServerConfig httpServerConf = searchConf
                            .getCommonHttpServerConfig();
                    String url = httpServerConf.getURL();
                    result.append("url:").append(url).append('\n');

                    String reference = httpServerConf.getReference();
                    result.append("reference").append(reference).append('\n');
                }
                result.append("--- --- ---\n");
            }
        } catch (Exception e) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            result.append("\nSearch configuration was not able to be retrieved. Exception stack trace:\n");
            result.append(sw.toString());
        }
        return result.toString();
    }
}



The result:

=== === ===
Search Configuration:
--- --- ---
coreName:MC_11101_CatalogEntry_Unstructured_en_US
corePath:/MC_11101/en_US/CatalogEntry/unstructured
masterCatalog:11101
languageId:-1
name:AdvancedConfiguration
parameters:[]
isEmbeddedServer:false
url:http://localhost:10080/solr
referencecom.ibm.commerce.foundation.server.services.search.url
--- --- ---
coreName:MC_11101_CatalogGroup_en_US
corePath:/MC_11101/en_US/CatalogGroup
masterCatalog:11101
languageId:-1
name:AdvancedConfiguration
parameters:[]
isEmbeddedServer:false
url:http://localhost:10080/solr
referencecom.ibm.commerce.foundation.server.services.search.url
--- --- ---
coreName:MC_11101_CatalogEntry_Inventory_generic
corePath:/MC_11101/generic/CatalogEntry/Inventory
masterCatalog:10751
languageId:-1
name:AdvancedConfiguration
parameters:[]
isEmbeddedServer:false
url:http://localhost:10080/solr
referencecom.ibm.commerce.foundation.server.services.search.url
--- --- ---
coreName:MC_11101_CatalogEntry_en_US
corePath:/MC_11101/en_US/CatalogEntry
masterCatalog:11101
languageId:-1
name:AdvancedConfiguration
parameters:[]
isEmbeddedServer:false
url:http://localhost:10080/solr
referencecom.ibm.commerce.foundation.server.services.search.url
--- --- ---

No comments:

Post a Comment