http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/configsets/solr.xml ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/configsets/solr.xml b/ambari-logsearch/ambari-logsearch-portal/src/main/configsets/solr.xml new file mode 100644 index 0000000..e0d93df --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/configsets/solr.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<solr> +</solr>
http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/README.md ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/README.md b/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/README.md new file mode 100644 index 0000000..3cc4915 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/README.md @@ -0,0 +1,35 @@ +<!-- +{% comment %} +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to you under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +{% endcomment %} +--> + +This folder contains scripts to configure and run SolrCloud for development. + +This helps in seting up SolrCloud using embedded zookeeper. + +##Setup Solr Collections +```./update_config.sh <path to solr install folder> +``` + + +##Run Solr +```./restart_solr.sh +``` + +##Delete collections +```./reset_collections.sh +``` \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/reset_collections.sh ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/reset_collections.sh b/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/reset_collections.sh new file mode 100755 index 0000000..7c742c0 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/reset_collections.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This script is used to delete all the documents in Solr +host_port=localhost:8983 +if [ $# -eq 1 ]; then + host_port=$1 +fi +set -x +curl http://${host_port}/solr/hadoop_logs/update --data '<delete><query>*:*</query></delete>' -H 'Content-type:text/xml; charset=utf-8' +curl http://${host_port}/solr/hadoop_logs/update --data '<commit/>' -H 'Content-type:text/xml; charset=utf-8' + +curl http://${host_port}/solr/audit_logs/update --data '<delete><query>*:*</query></delete>' -H 'Content-type:text/xml; charset=utf-8' +curl http://${host_port}/solr/audit_logs/update --data '<commit/>' -H 'Content-type:text/xml; charset=utf-8' + http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/restart_solr.sh ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/restart_solr.sh b/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/restart_solr.sh new file mode 100755 index 0000000..bd436bb --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/restart_solr.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +function usage { + echo "Usage: $0 <Solr Install Folder>" +} + +if [ $# -ne 1 ]; then + usage + exit 1 +fi + +SOLR_INSTALL=$1 +if [ -x $SOLR_INSTALL/bin/solr ]; then + SOLR_BIN=$SOLR_INSTALL/bin/solr +else + echo "ERROR: Invalid Solr install folder $SOLR_INSTALL" + usage + exit 1 +fi + +set -x +$SOLR_BIN restart -c http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/update_config.sh ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/update_config.sh b/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/update_config.sh new file mode 100755 index 0000000..93e3496 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/dev/solrcloud/update_config.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +function usage { + echo "Usage: $0 <Solr Install Folder> [zk_hosts]" +} + +if [ $# -lt 1 ]; then + usage + exit 1 +fi + +curr_dir=`pwd` +cd `dirname $0`; script_dir=`pwd`; cd $curr_dir + +SOLR_INSTALL=$1 +if [ -x $SOLR_INSTALL/server/scripts/cloud-scripts/zkcli.sh ]; then + ZK_CLI=$SOLR_INSTALL/server/scripts/cloud-scripts/zkcli.sh +else + echo "ERROR: Invalid Solr install folder $SOLR_INSTALL" + usage + exit 1 +fi + +zk_hosts="localhost:9983" +if [ $# -eq 2 ]; then + zk_hosts=$2 +fi + + +CONFIGSET_FOLDER=$script_dir/../../configsets + +set -x +$ZK_CLI -zkhost $zk_hosts -cmd upconfig -confdir $CONFIGSET_FOLDER/audit_logs/conf -confname audit_logs +$ZK_CLI -zkhost $zk_hosts -cmd upconfig -confdir $CONFIGSET_FOLDER/hadoop_logs/conf -confname hadoop_logs +$ZK_CLI -zkhost $zk_hosts -cmd upconfig -confdir $CONFIGSET_FOLDER/history/conf -confname history http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/LogSearch.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/LogSearch.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/LogSearch.java new file mode 100644 index 0000000..14c0c1e --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/LogSearch.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Timer; + +import org.apache.ambari.logsearch.common.ManageStartEndTime; +import org.apache.ambari.logsearch.util.ConfigUtil; +import org.apache.hadoop.http.HttpServer2; +import org.apache.log4j.Logger; + +public class LogSearch { + static Logger logger = Logger.getLogger(LogSearch.class); + + public static void main(String argv[]) { + String port = (argv.length > 0) ? argv[0] : "61888"; + HttpServer2.Builder builder = new HttpServer2.Builder(); + builder.setName("app"); + builder.addEndpoint(URI.create("http://0.0.0.0:" + port)); + builder.setFindPort(false); + List<String> pathList = new ArrayList<String>(); + pathList.add("/*"); + builder.setPathSpec(pathList.toArray(new String[0])); + builder.needsClientAuth(false); + Timer timer = new Timer(); + timer.schedule(new ManageStartEndTime(), 0, 40000); + try { + logger.info("Starting logsearch server..."); + HttpServer2 server = builder.build(); + server.start(); + ConfigUtil.initializeApplicationConfig(); + logger.info(server.toString()); + } catch (Throwable e) { + logger.error("Error running logsearch server", e); + } + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java new file mode 100644 index 0000000..7398098 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.ambari.logsearch.common; + +public class LogSearchConstants { + // Log Levels + public static final String INFO = "INFO"; + public static final String WARN = "WARN"; + public static final String DEBUG = "DEBUG"; + public static final String ERROR = "ERROR"; + public static final String TRACE = "TRACE"; + public static final String FATAL = "FATAL"; + + // Application Constants + public static final String HOST = "H"; + public static final String SERVICE = "S"; + public static final String COMPONENT = "C"; + public static final String SCROLL_TYPE_AFTER = "after"; + public static final String SCROLL_TYPE_BEFORE = "before"; + + // UserConfig Constants + public static final String ID = "id"; + public static final String USER_NAME = "username"; + public static final String VALUES = "jsons"; + public static final String FILTER_NAME = "filtername"; + public static final String ROW_TYPE = "rowtype"; + public static final String USER_CONFIG_DASHBOARD = "dashboard"; + public static final String USER_CONFIG_HISTORY = "history"; + public static final String COMPOSITE_KEY = "composite_filtername-username"; + public static final String SHARE_NAME_LIST = "share_username_list"; + + // SOLR Document Constants for ServiceLogs + public static final String BUNDLE_ID = "bundle_id"; + public static final String LOGTIME = "logtime"; + public static final String SEQUNCE_ID = "seq_num"; + public static final String SOLR_COMPONENT = "type"; + public static final String SOLR_LOG_MESSAGE = "log_message"; + public static final String SOLR_HOST = "host"; + public static final String SOLR_LEVEL = "level"; + public static final String SOLR_THREAD_NAME = "thread_name"; + public static final String SOLR_LOGGER_NAME = "logger_name"; + public static final String SOLR_FILE = "file"; + public static final String SOLR_LINE_NUMBER = "line_number"; + public static final String SOLR_PATH = "path"; + + //SOLR Document Constant for audit log + public static final String AUDIT_COMPONENT = "repo"; + public static final String AUDIT_EVTTIME = "evtTime"; + public static final String AUDIT_REQUEST_USER = "reqUser"; + + // Operator's + public static final String MINUS_OPERATOR = "-"; + public static final String NO_OPERATOR = ""; + + + //operation + public static final String EXCLUDE_QUERY = "excludeQuery"; + public static final String INCLUDE_QUERY = "includeQuery"; + public static final String COLUMN_QUERY = "columnQuery"; + + //URL PARAMS + public static final String GLOBAL_START_TIME = "globalStartTime"; + public static final String GLOBAL_END_TIME = "globalEndTime"; + + + // Seprator's + public static final String I_E_SEPRATOR = "\\|i\\:\\:e\\|"; + + //SUFFIX + public static final String UI_SUFFIX = "@UI@"; + public static final String SOLR_SUFFIX = "@Solr@"; + public static final String NGRAM_SUFFIX = "ngram_"; + + //Date Format for SOLR + public static final String SOLR_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss,SSS"; + public static final String SOLR_DATE_FORMAT_PREFIX_Z = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; + + //Solr Order By + public static final String ASCENDING_ORDER = "asc"; + public static final String DESCENDING_ORDER = "desc"; + + //Solr Facet Sort By + public static final String FACET_INDEX = "index"; + public static final String FACET_COUNT = "count"; + + // logfeeder + public static final String LOGFEEDER_FILTER_NAME = "log_feeder_config"; + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/LogsearchContextUtil.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/LogsearchContextUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/LogsearchContextUtil.java new file mode 100644 index 0000000..617f2fd --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/LogsearchContextUtil.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.common; + +import org.apache.ambari.logsearch.security.context.LogsearchContextHolder; +import org.apache.ambari.logsearch.security.context.LogsearchSecurityContext; + +public class LogsearchContextUtil { + + /** + * Singleton class + */ + private LogsearchContextUtil() { + } + + public static String getCurrentUsername() { + LogsearchSecurityContext context = LogsearchContextHolder.getSecurityContext(); + if (context != null) { + UserSessionInfo userSession = context.getUserSession(); + if (userSession != null) { + return userSession.getUsername(); + } + } + return null; + } + + public static UserSessionInfo getCurrentUserSession() { + UserSessionInfo userSession = null; + LogsearchSecurityContext context = LogsearchContextHolder.getSecurityContext(); + if (context != null) { + userSession = context.getUserSession(); + } + return userSession; + } + + public static RequestContext getCurrentRequestContext() { + LogsearchSecurityContext context = LogsearchContextHolder.getSecurityContext(); + if (context != null) { + return context.getRequestContext(); + } + return null; + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/ManageStartEndTime.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/ManageStartEndTime.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/ManageStartEndTime.java new file mode 100644 index 0000000..2525e61 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/ManageStartEndTime.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.ambari.logsearch.common; + +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.TimerTask; + +import org.apache.ambari.logsearch.util.ConfigUtil; +import org.apache.log4j.Logger; + +public class ManageStartEndTime extends TimerTask { + static Logger logger = Logger.getLogger(ManageStartEndTime.class); + + public static Date startDate = new Date(); + + public static Date endDate = new Date(); + + public ManageStartEndTime() { + intailizeStartEndTime(); + } + + @Override + public void run() { + if (startDate == null) + intailizeStartEndTime(); + else + adjustStartEndTime(); + } + + private void adjustStartEndTime() { + startDate = addSecondsToDate(startDate, 40); + endDate = addHoursToDate(startDate, 1); + } + + private Date addSecondsToDate(Date date, int i) { + GregorianCalendar greorianCalendar = new GregorianCalendar(); + greorianCalendar.setTime(date); + greorianCalendar.add(GregorianCalendar.SECOND, i); + return greorianCalendar.getTime(); + } + + private Date addHoursToDate(Date date, int i) { + GregorianCalendar greorianCalendar = new GregorianCalendar(); + greorianCalendar.setTime(date); + greorianCalendar.add(GregorianCalendar.HOUR_OF_DAY, i); + return greorianCalendar.getTime(); + } + + private void intailizeStartEndTime() { + + endDate = new Date(); + startDate = addHoursToDate(endDate, -1); + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/MessageEnums.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/MessageEnums.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/MessageEnums.java new file mode 100644 index 0000000..77ee854 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/MessageEnums.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.common; + +import org.apache.ambari.logsearch.view.VMessage; + +public enum MessageEnums { + + // Common Errors + DATA_NOT_FOUND("fs.error.data_not_found", "Data not found"), OPER_NOT_ALLOWED_FOR_STATE( + "fs.error.oper_not_allowed_for_state", + "Operation not allowed in current state"), OPER_NOT_ALLOWED_FOR_ENTITY( + "fs.error.oper_not_allowed_for_state", + "Operation not allowed for entity"), OPER_NO_PERMISSION( + "fs.error.oper_no_permission", + "User doesn't have permission to perform this operation"), DATA_NOT_UPDATABLE( + "fs.error.data_not_updatable", "Data not updatable"), ERROR_CREATING_OBJECT( + "fs.error.create_object", "Error creating object"), ERROR_DUPLICATE_OBJECT( + "fs.error.duplicate_object", "Error creating duplicate object"), ERROR_SYSTEM( + "fs.error.system", "System Error. Please try later."), + + // Common Validations + INVALID_PASSWORD("fs.validation.invalid_password", "Invalid password"), INVALID_INPUT_DATA( + "fs.validation.invalid_input_data", "Invalid input data"), NO_INPUT_DATA( + "fs.validation.no_input_data", "Input data is not provided"), INPUT_DATA_OUT_OF_BOUND( + "fs.validation.data_out_of_bound", "Input data if out of bound"), NO_NAME( + "fs.validation.no_name", "Name is not provided"), NO_OR_INVALID_COUNTRY_ID( + "fs.validation.no_country_id", "Valid Country Id was not provided"), NO_OR_INVALID_CITY_ID( + "fs.validation.no_city_id", "Valid City Id was not provided"), NO_OR_INVALID_STATE_ID( + "fs.validation.no_state_id", "Valid State Id was not provided"); + + String rbKey; + String messageDesc; + + MessageEnums(String rbKey, String messageDesc) { + this.rbKey = rbKey; + this.messageDesc = messageDesc; + } + + public VMessage getMessage() { + VMessage msg = new VMessage(); + msg.setName(this.toString()); + msg.setRbKey(rbKey); + msg.setMessage(messageDesc); + return msg; + } + + public VMessage getMessage(Long objectId, String fieldName) { + VMessage msg = new VMessage(); + msg.setName(this.toString()); + msg.setRbKey(rbKey); + msg.setMessage(messageDesc); + msg.setObjectId(objectId); + msg.setFieldName(fieldName); + return msg; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/RequestContext.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/RequestContext.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/RequestContext.java new file mode 100644 index 0000000..83ed3bd --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/RequestContext.java @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.common; + +import java.io.Serializable; + +public class RequestContext implements Serializable { + private static final long serialVersionUID = -7083383106845193385L; + String ipAddress = null; + String msaCookie = null; + String userAgent = null; + String requestURL = null; + String serverRequestId = null; + String clientTimeOffset; + boolean isSync = true; + long startTime = System.currentTimeMillis(); + + /** + * @return the ipAddress + */ + public String getIpAddress() { + return ipAddress; + } + + /** + * @param ipAddress the ipAddress to set + */ + public void setIpAddress(String ipAddress) { + this.ipAddress = ipAddress; + } + + /** + * @return the msaCookie + */ + public String getMsaCookie() { + return msaCookie; + } + + /** + * @param msaCookie the msaCookie to set + */ + public void setMsaCookie(String msaCookie) { + this.msaCookie = msaCookie; + } + + /** + * @return the userAgent + */ + public String getUserAgent() { + return userAgent; + } + + /** + * @param userAgent the userAgent to set + */ + public void setUserAgent(String userAgent) { + this.userAgent = userAgent; + } + + /** + * @return the serverRequestId + */ + public String getServerRequestId() { + return serverRequestId; + } + + /** + * @param serverRequestId the serverRequestId to set + */ + public void setServerRequestId(String serverRequestId) { + this.serverRequestId = serverRequestId; + } + + /** + * @return the isSync + */ + public boolean isSync() { + return isSync; + } + + /** + * @param isSync the isSync to set + */ + public void setSync(boolean isSync) { + this.isSync = isSync; + } + + /** + * @return the requestURL + */ + public String getRequestURL() { + return requestURL; + } + + /** + * @param requestURL the requestURL to set + */ + public void setRequestURL(String requestURL) { + this.requestURL = requestURL; + } + + /** + * @return the startTime + */ + public long getStartTime() { + return startTime; + } + + /** + * @param startTime the startTime to set + */ + public void setStartTime(long startTime) { + this.startTime = startTime; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "RequestContext [ipAddress=" + ipAddress + ", msaCookie=" + msaCookie + ", userAgent=" + userAgent + + ", requestURL=" + requestURL + ",serverRequestId=" + serverRequestId + ", isSync=" + isSync + + ", startTime=" + startTime + "]"; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/SearchCriteria.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/SearchCriteria.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/SearchCriteria.java new file mode 100644 index 0000000..a5c9770 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/SearchCriteria.java @@ -0,0 +1,336 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.common; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.ambari.logsearch.util.PropertiesUtil; +import org.apache.commons.lang.StringEscapeUtils; + +public class SearchCriteria { + private int startIndex = 0; + private int maxRows = Integer.MAX_VALUE; + private String sortBy = null; + private String sortType = null; + private int page = 0; + + private String globalStartTime = null; + private String globalEndTime = null; + + private boolean getCount = true; + private boolean isDistinct = false; + private HashMap<String, Object> paramList = new HashMap<String, Object>(); + final private Set<String> nullParamList = new HashSet<String>(); + final private Set<String> notNullParamList = new HashSet<String>(); + + private Map<String, Object> urlParamMap = new HashMap<String, Object>(); + + public SearchCriteria(HttpServletRequest request) { + try { + if (request.getParameter("startIndex") != null + && (!request.getParameter("startIndex").isEmpty())) { + this.startIndex = new Integer( + request.getParameter("startIndex")); + } + if (request.getParameter("page") != null + && (!request.getParameter("page").isEmpty())) { + this.page = new Integer(request.getParameter("page")); + } + if (request.getParameter("pageSize") != null + && (!request.getParameter("pageSize").isEmpty())) { + this.maxRows = new Integer(request.getParameter("pageSize")); + } else { + this.maxRows = PropertiesUtil.getIntProperty("db.maxResults", + 50); + } + } catch (NumberFormatException e) { + // do nothing + } + + // Sort fields + if (request.getParameter("sortBy") != null + && (!request.getParameter("sortBy").isEmpty())) { + this.sortBy = "" + request.getParameter("sortBy"); + } + if (request.getParameter("sortType") != null + && (!request.getParameter("sortType").isEmpty())) { + this.sortType = "" + request.getParameter("sortType"); + } + + // url params + if (request.getParameter("start_time") != null + && (!request.getParameter("start_time").isEmpty())) { + this.globalStartTime = "" + request.getParameter("start_time"); + this.urlParamMap.put("globalStartTime", request.getParameter("start_time")); + } + if (request.getParameter("end_time") != null + && (!request.getParameter("end_time").isEmpty())) { + this.globalEndTime = "" + request.getParameter("end_time"); + this.urlParamMap.put("globalEndTime", request.getParameter("end_time")); + } + } + + public SearchCriteria() { + // Auto-generated constructor stub + } + + /** + * @return the startIndex + */ + public int getStartIndex() { + return startIndex; + } + + /** + * @param startIndex the startIndex to set + */ + public void setStartIndex(int startIndex) { + this.startIndex = startIndex; + } + + /** + * @return the maxRows + */ + public int getMaxRows() { + return maxRows; + } + + /** + * @param maxRows the maxRows to set + */ + public void setMaxRows(int maxRows) { + this.maxRows = maxRows; + } + + /** + * @return the sortType + */ + + public String getSortType() { + return sortType; + } + + /** + * @param sortType the sortType to set + */ + + public boolean isGetCount() { + return getCount; + } + + public void setGetCount(boolean getCount) { + this.getCount = getCount; + } + + /** + * @return the paramList + */ + public HashMap<String, Object> getParamList() { + return paramList; + } + + /** + * @param paramList the paramList to set + */ + public void setParamList(HashMap<String, Object> paramList) { + this.paramList = paramList; + } + + /** + * @param request + */ + public void addRequiredServiceLogsParams(HttpServletRequest request) { + this.addParam("advanceSearch", StringEscapeUtils.unescapeXml(request.getParameter("advanceSearch"))); + this.addParam("q", request.getParameter("q")); + this.addParam("treeParams", StringEscapeUtils + .unescapeHtml(request.getParameter("treeParams"))); + this.addParam("level", request.getParameter("level")); + this.addParam("gMustNot", request.getParameter("gMustNot")); + this.addParam("from", request.getParameter("from")); + this.addParam("to", request.getParameter("to")); + this.addParam("selectComp", request.getParameter("mustBe")); + this.addParam("unselectComp", request.getParameter("mustNot")); + this.addParam("iMessage", StringEscapeUtils.unescapeXml(request + .getParameter("iMessage"))); + this.addParam("gEMessage", StringEscapeUtils + .unescapeXml(request.getParameter("gEMessage"))); + this + .addParam("eMessage", StringEscapeUtils.unescapeXml(request + .getParameter("eMessage"))); + this.addParam(LogSearchConstants.BUNDLE_ID, request.getParameter(LogSearchConstants.BUNDLE_ID)); + this.addParam("host_name", request.getParameter("host_name")); + this.addParam("components_name", request.getParameter("components_name")); + this.addParam("startDate", request.getParameter("start_time")); + this.addParam("endDate", request.getParameter("end_time")); + this.addParam("excludeQuery", StringEscapeUtils.unescapeXml( + request.getParameter("excludeQuery"))); + this.addParam("includeQuery", StringEscapeUtils.unescapeXml( + request.getParameter("includeQuery"))); + this.addParam("includeQuery", StringEscapeUtils.unescapeXml( + request.getParameter("includeQuery"))); + } + + /** + * @param request + */ + public void addRequiredAuditLogsParams(HttpServletRequest request) { + this.addParam("q", request.getParameter("q")); + this.addParam("columnQuery", StringEscapeUtils + .unescapeXml(request.getParameter("columnQuery"))); + this.addParam("iMessage", StringEscapeUtils.unescapeXml(request + .getParameter("iMessage"))); + this.addParam("gEMessage", StringEscapeUtils + .unescapeXml(request.getParameter("gEMessage"))); + this.addParam("eMessage", StringEscapeUtils.unescapeXml(request + .getParameter("eMessage"))); + this.addParam("includeString", request.getParameter("mustBe")); + this.addParam("unselectComp", request.getParameter("mustNot")); + this.addParam("excludeQuery", StringEscapeUtils.unescapeXml( + request.getParameter("excludeQuery"))); + this.addParam("includeQuery", StringEscapeUtils.unescapeXml( + request.getParameter("includeQuery"))); + this.addParam("startTime", request.getParameter("from")); + this.addParam("endTime", request.getParameter("to")); + } + + /** + * @param string + * @param caId + */ + public void addParam(String name, Object value) { + String solrValue = PropertiesUtil.getProperty(name); + if (solrValue == null || solrValue.isEmpty()) + paramList.put(name, value); + else { + try { + String propertyFieldMappings[] = solrValue.split(","); + HashMap<String, String> propertyFieldValue = new HashMap<String, String>(); + for (String temp : propertyFieldMappings) { + String arrayValue[] = temp.split(":"); + propertyFieldValue.put(arrayValue[0].toLowerCase(Locale.ENGLISH), arrayValue[1].toLowerCase(Locale.ENGLISH)); + } + String originalValue = propertyFieldValue.get(value.toString().toLowerCase(Locale.ENGLISH)); + if (originalValue != null && !originalValue.isEmpty()) + paramList.put(name, originalValue); + + } catch (Exception e) { + //do nothing + } + } + } + + public void setNullParam(String name) { + nullParamList.add(name); + } + + public void setNotNullParam(String name) { + notNullParamList.add(name); + } + + public Object getParamValue(String name) { + return paramList.get(name); + } + + /** + * @param string + * @param caId + */ + public Object removeParam(String name) { + return paramList.remove(name); + } + + /** + * @return the nullParamList + */ + public Set<String> getNullParamList() { + return nullParamList; + } + + /** + * @return the notNullParamList + */ + public Set<String> getNotNullParamList() { + return notNullParamList; + } + + /** + * @return the isDistinct + */ + public boolean isDistinct() { + return isDistinct; + } + + public String getSortBy() { + return sortBy; + } + + public void setSortBy(String sortBy) { + this.sortBy = sortBy; + } + + public void setSortType(String sortType) { + this.sortType = sortType; + } + + /** + * @param isDistinct the isDistinct to set + */ + public void setDistinct(boolean isDistinct) { + this.isDistinct = isDistinct; + } + + public int getPage() { + return page; + } + + public void setPage(int page) { + this.page = page; + } + + public String getGlobalStartTime() { + return globalStartTime; + } + + public void setGlobalStartTime(String globalStartTime) { + this.globalStartTime = globalStartTime; + } + + public String getGlobalEndTime() { + return globalEndTime; + } + + public void setGlobalEndTime(String globalEndTime) { + this.globalEndTime = globalEndTime; + } + + public Map<String, Object> getUrlParamMap() { + return urlParamMap; + } + + public void setUrlParamMap(Map<String, Object> urlParamMap) { + this.urlParamMap = urlParamMap; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/UserSessionInfo.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/UserSessionInfo.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/UserSessionInfo.java new file mode 100644 index 0000000..e8db862 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/UserSessionInfo.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.common; + +import java.io.Serializable; + +import org.apache.ambari.logsearch.web.model.User; + +public class UserSessionInfo implements Serializable { + + private static final long serialVersionUID = 1L; + + User user; + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public String getUsername() { + if (user != null) { + return user.getUsername(); + } + return null; + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/AuditSolrDao.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/AuditSolrDao.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/AuditSolrDao.java new file mode 100644 index 0000000..990ad00 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/AuditSolrDao.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.ambari.logsearch.dao; + +import javax.annotation.PostConstruct; + +import org.apache.ambari.logsearch.util.PropertiesUtil; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + +@Component +public class AuditSolrDao extends SolrDaoBase { + + static private Logger logger = Logger.getLogger(AuditSolrDao.class); + + @PostConstruct + public void postConstructor() { + String solrUrl = PropertiesUtil.getProperty("auditlog.solr.url"); + String zkHosts = PropertiesUtil.getProperty("auditlog.solr.zkhosts"); + String collection = PropertiesUtil.getProperty( + "auditlog.solr.core.logs", "audit_logs"); + String splitInterval = PropertiesUtil.getProperty( + "solr.audit_logs.split_interval_mins", "none"); + String configName = PropertiesUtil.getProperty( + "solr.audit_logs.config_name", "audit_logs"); + int numberOfShards = PropertiesUtil.getIntProperty( + "solr.audit_logs.shards", 1); + int replicationFactor = PropertiesUtil.getIntProperty( + "solr.audit_logs.replication_factor", 1); + + try { + connectToSolr(solrUrl, zkHosts, collection); + setupCollections(splitInterval, configName, numberOfShards, + replicationFactor); + } catch (Exception e) { + logger.error( + "Error while connecting to Solr for audit logs : solrUrl=" + + solrUrl + ", zkHosts=" + zkHosts + + ", collection=" + collection, e); + } + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/ServiceLogsSolrDao.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/ServiceLogsSolrDao.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/ServiceLogsSolrDao.java new file mode 100644 index 0000000..9703273 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/ServiceLogsSolrDao.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.ambari.logsearch.dao; + +import javax.annotation.PostConstruct; + +import org.apache.ambari.logsearch.util.PropertiesUtil; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + +@Component +public class ServiceLogsSolrDao extends SolrDaoBase { + static private Logger logger = Logger.getLogger(ServiceLogsSolrDao.class); + + @PostConstruct + public void postConstructor() { + logger.info("postConstructor() called."); + String solrUrl = PropertiesUtil.getProperty("solr.url"); + String zkHosts = PropertiesUtil.getProperty("solr.zkhosts"); + String collection = PropertiesUtil.getProperty("solr.core.logs", + "hadoop_logs"); + String splitInterval = PropertiesUtil.getProperty( + "solr.service_logs.split_interval_mins", "none"); + String configName = PropertiesUtil.getProperty( + "solr.service_logs.config_name", "hadoop_logs"); + int numberOfShards = PropertiesUtil.getIntProperty( + "solr.service_logs.shards", 1); + int replicationFactor = PropertiesUtil.getIntProperty( + "solr.service_logs.replication_factor", 1); + + try { + connectToSolr(solrUrl, zkHosts, collection); + setupCollections(splitInterval, configName, numberOfShards, + replicationFactor); + } catch (Exception e) { + logger.error( + "error while connecting to Solr for service logs : solrUrl=" + + solrUrl + ", zkHosts=" + zkHosts + + ", collection=" + collection, e); + } + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java new file mode 100644 index 0000000..228ddd1 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java @@ -0,0 +1,541 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.ambari.logsearch.dao; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; + +import org.apache.ambari.logsearch.common.LogsearchContextUtil; +import org.apache.ambari.logsearch.util.ConfigUtil; +import org.apache.ambari.logsearch.util.JSONUtil; +import org.apache.ambari.logsearch.util.StringUtil; +import org.apache.log4j.Logger; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.SolrQuery; +import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.SolrRequest.METHOD; +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.impl.HttpSolrClient; +import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.schema.SchemaRequest; +import org.apache.solr.client.solrj.response.CollectionAdminResponse; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.client.solrj.response.UpdateResponse; +import org.apache.solr.client.solrj.response.schema.SchemaResponse; +import org.apache.solr.common.SolrException; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.cloud.Replica; +import org.apache.solr.common.cloud.Slice; +import org.apache.solr.common.cloud.ZkStateReader; +import org.apache.solr.common.util.NamedList; +import org.springframework.beans.factory.annotation.Autowired; + +public abstract class SolrDaoBase { + static private Logger logger = Logger.getLogger(SolrDaoBase.class); + + static Logger logPerfomance = Logger + .getLogger("org.apache.ambari.logsearch.performance"); + + private static final String ROUTER_FIELD = "_router_field_"; + + @Autowired + StringUtil stringUtil; + + @Autowired + JSONUtil jsonUtil; + + String collectionName = null; + // List<String> collectionList = new ArrayList<String>(); + + private SolrClient solrClient = null; + CloudSolrClient solrClouldClient = null; + + boolean isSolrCloud = true; + String solrDetail = ""; + + boolean isSolrInitialized = false; + + private boolean setup_status = false; + private boolean populateFieldsThreadActive = false; + + int SETUP_RETRY_SECOND = 30; + + public SolrClient connectToSolr(String url, String zkHosts, + String collection) throws Exception { + this.collectionName = collection; + solrDetail = "zkHosts=" + zkHosts + ", collection=" + collection + + ", url=" + url; + + logger.info("connectToSolr() " + solrDetail); + if (stringUtil.isEmpty(collection)) { + throw new Exception("For solr, collection name is mandatory. " + + solrDetail); + } + if (!stringUtil.isEmpty(zkHosts)) { + solrDetail = "zkHosts=" + zkHosts + ", collection=" + collection; + logger.info("Using zookeepr. " + solrDetail); + solrClouldClient = new CloudSolrClient(zkHosts); + solrClouldClient.setDefaultCollection(collection); + solrClient = solrClouldClient; + int waitDurationMS = 3 * 60 * 1000; + checkSolrStatus(waitDurationMS); + } else { + if (stringUtil.isEmpty(url)) { + throw new Exception("Both zkHosts and URL are empty. zkHosts=" + + zkHosts + ", collection=" + collection + ", url=" + + url); + } + solrDetail = "collection=" + collection + ", url=" + url; + String collectionURL = url + "/" + collection; + logger.info("Connecting to solr : " + collectionURL); + solrClient = new HttpSolrClient(collectionURL); + + } + // populateSchemaFields(collection); + return solrClient; + } + + public SolrClient getSolrClient() { + return solrClient; + } + + /** + * This will try to get the collections from the Solr. Ping doesn't work if + * collection is not given + * + * @param waitDurationMS + */ + public boolean checkSolrStatus(int waitDurationMS) { + boolean status = false; + try { + long beginTimeMS = System.currentTimeMillis(); + long waitIntervalMS = 2000; + int pingCount = 0; + while (true) { + pingCount++; + try { + List<String> collectionList = getCollections(); + if (collectionList != null) { + logger.info("checkSolrStatus(): Solr getCollections() is success. solr=" + + solrDetail + + ", collectionList=" + + collectionList); + status = true; + break; + } + } catch (Exception ex) { + logger.error("Error while doing Solr check", ex); + } + if (System.currentTimeMillis() - beginTimeMS > waitDurationMS) { + logger.error("Solr is not reachable even after " + + (System.currentTimeMillis() - beginTimeMS) + + " ms. If you are using alias, then you might have to restart LogSearch after Solr is up and running. solr=" + + solrDetail); + break; + } else { + logger.warn("Solr is not not reachable yet. getCollections() attempt count=" + + pingCount + + ". Will sleep for " + + waitIntervalMS + + " ms and try again." + " solr=" + solrDetail); + } + Thread.sleep(waitIntervalMS); + + } + } catch (Throwable t) { + logger.error("Seems Solr is not up. solrDetail=" + solrDetail); + } + return status; + } + + public void setupCollections(final String splitMode, + final String configName, final int numberOfShards, + final int replicationFactor) throws Exception { + setup_status = createCollectionsIfNeeded(splitMode, configName, + numberOfShards, replicationFactor); + logger.info("Setup status for " + collectionName + " is " + + setup_status); + if (!setup_status) { + // Start a background thread to do setup + Thread setupThread = new Thread("setup_collection_" + + collectionName) { + @Override + public void run() { + logger.info("Started monitoring thread to check availability of Solr server. collection=" + + collectionName); + int retryCount = 0; + while (true) { + try { + Thread.sleep(SETUP_RETRY_SECOND); + retryCount++; + setup_status = createCollectionsIfNeeded(splitMode, + configName, numberOfShards, + replicationFactor); + if (setup_status) { + logger.info("Setup for collection " + + collectionName + + " is successful. Exiting setup retry thread"); + break; + } + } catch (InterruptedException sleepInterrupted) { + logger.info("Sleep interrupted while setting up collection " + + collectionName); + break; + } catch (Exception e) { + logger.error("Error setting up collection=" + + collectionName, e); + } + logger.error("Error setting collection. collection=" + + collectionName + ", retryCount=" + retryCount); + } + } + + }; + setupThread.setDaemon(true); + setupThread.start(); + } + populateSchemaFields(); + } + + public boolean createCollectionsIfNeeded(final String splitMode, + final String configName, final int numberOfShards, + final int replicationFactor) { + boolean result = false; + try { + List<String> allCollectionList = getCollections(); + if (splitMode.equalsIgnoreCase("none")) { + // Just create regular collection + result = createCollection(collectionName, configName, + numberOfShards, replicationFactor, allCollectionList); + } else { + result = setupCollectionsWithImplicitRouting(splitMode, + configName, numberOfShards, allCollectionList); + } + } catch (Exception ex) { + logger.error("Error creating collection. collectionName=" + + collectionName, ex); + } + return result; + } + + public List<String> getCollections() throws SolrServerException, + IOException { + try { + CollectionAdminRequest.List colListReq = new CollectionAdminRequest.List(); + CollectionAdminResponse response = colListReq.process(solrClient); + if (response.getStatus() != 0) { + logger.error("Error getting collection list from solr. response=" + + response); + return null; + } + + @SuppressWarnings("unchecked") + List<String> allCollectionList = (List<String>) response + .getResponse().get("collections"); + return allCollectionList; + } catch (SolrException e) { + logger.error(e); + return null; + } + } + + public boolean setupCollectionsWithImplicitRouting(String splitMode, + String configName, int numberOfShards, + List<String> allCollectionList) throws Exception { + logger.info("setupCollectionsWithImplicitRouting(). collectionName=" + + collectionName + ", numberOfShards=" + numberOfShards); + return createCollectionWithImplicitRoute(collectionName, configName, + numberOfShards, allCollectionList); + } + + public boolean createCollectionWithImplicitRoute(String colName, + String configName, int numberOfShards, + List<String> allCollectionList) throws SolrServerException, + IOException { + + // Default is true, because if the collection and shard is already + // there, then it will return true + boolean returnValue = true; + String shardsListStr = ""; + List<String> shardsList = new ArrayList<String>(); + for (int i = 0; i < numberOfShards; i++) { + if (i != 0) { + shardsListStr += ","; + } + String shard = "shard" + i; + shardsListStr += shard; + shardsList.add(shard); + } + + // Check if collection is already in zookeeper + if (!allCollectionList.contains(colName)) { + logger.info("Creating collection " + colName + ", shardsList=" + + shardsList + ", solrDetail=" + solrDetail); + int replicationFactor = 1; + CollectionAdminRequest.Create collectionCreateRequest = new CollectionAdminRequest.Create(); + collectionCreateRequest.setCollectionName(colName); + collectionCreateRequest.setRouterName("implicit"); + collectionCreateRequest.setShards(shardsListStr); + collectionCreateRequest.setMaxShardsPerNode(numberOfShards); + collectionCreateRequest.setReplicationFactor(replicationFactor); + collectionCreateRequest.setConfigName(configName); + collectionCreateRequest.setRouterField(ROUTER_FIELD); + collectionCreateRequest.setMaxShardsPerNode(replicationFactor + * numberOfShards); + + CollectionAdminResponse createResponse = collectionCreateRequest + .process(solrClient); + if (createResponse.getStatus() != 0) { + returnValue = false; + logger.error("Error creating collection. collectionName=" + + colName + ", shardsList=" + shardsList + + ", solrDetail=" + solrDetail + ", response=" + + createResponse); + } else { + logger.info("Created collection " + colName + ", shardsList=" + + shardsList + ", solrDetail=" + solrDetail); + } + } else { + logger.info("Collection " + + colName + + " is already there. Will check whether it has the required shards"); + Collection<String> existingShards = getShards(); + for (String shard : shardsList) { + if (!existingShards.contains(shard)) { + try { + logger.info("Going to add Shard " + shard + + " to collection " + collectionName); + CollectionAdminRequest.CreateShard createShardRequest = new CollectionAdminRequest.CreateShard(); + createShardRequest.setCollectionName(collectionName); + createShardRequest.setShardName(shard); + CollectionAdminResponse response = createShardRequest + .process(solrClient); + if (response.getStatus() != 0) { + logger.error("Error creating shard " + shard + + " in collection " + collectionName + + ", response=" + response + + ", solrDetail=" + solrDetail); + returnValue = false; + break; + } else { + logger.info("Successfully created shard " + shard + + " in collection " + collectionName); + } + } catch (Throwable t) { + logger.error("Error creating shard " + shard + + " in collection " + collectionName + + ", solrDetail=" + solrDetail, t); + returnValue = false; + break; + } + } + } + } + return returnValue; + } + + public Collection<String> getShards() { + Collection<String> list = new HashSet<String>(); + + if (solrClouldClient == null) { + logger.error("getShards(). Only supporting in SolrCloud mode"); + return list; + } + + ZkStateReader reader = solrClouldClient.getZkStateReader(); + Collection<Slice> slices = reader.getClusterState().getSlices( + collectionName); + Iterator<Slice> iter = slices.iterator(); + + while (iter.hasNext()) { + Slice slice = iter.next(); + for (Replica replica : slice.getReplicas()) { + logger.info("colName=" + collectionName + ", slice.name=" + + slice.getName() + ", slice.state=" + slice.getState() + + ", replica.core=" + replica.getStr("core") + + ", replica.state=" + replica.getStr("state")); + list.add(slice.getName()); + } + } + return list; + } + + public boolean createCollection(String colName, String configName, + int numberOfShards, int replicationFactor, + List<String> allCollectionList) throws SolrServerException, + IOException { + // Check if collection is already in zookeeper + if (allCollectionList.contains(colName)) { + logger.info("Collection " + colName + + " is already there. Won't create it"); + return true; + } + + logger.info("Creating collection " + colName + ", numberOfShards=" + + numberOfShards + ", replicationFactor=" + replicationFactor + + ", solrDetail=" + solrDetail); + + CollectionAdminRequest.Create collectionCreateRequest = new CollectionAdminRequest.Create(); + collectionCreateRequest.setCollectionName(colName); + collectionCreateRequest.setNumShards(numberOfShards); + collectionCreateRequest.setReplicationFactor(replicationFactor); + collectionCreateRequest.setConfigName(configName); + collectionCreateRequest.setMaxShardsPerNode(replicationFactor + * numberOfShards); + CollectionAdminResponse createResponse = collectionCreateRequest + .process(solrClient); + if (createResponse.getStatus() != 0) { + logger.error("Error creating collection. collectionName=" + colName + + ", solrDetail=" + solrDetail + ", response=" + + createResponse); + return false; + } else { + logger.info("Created collection " + colName + ", numberOfShards=" + + numberOfShards + ", replicationFactor=" + + replicationFactor + ", solrDetail=" + solrDetail); + return true; + } + } + + public QueryResponse process(SolrQuery solrQuery) + throws SolrServerException, IOException, SolrException { + if (solrClient != null) { + String event = solrQuery.get("event"); + solrQuery.remove("event"); + QueryResponse queryResponse = solrClient.query(solrQuery, + METHOD.POST); + + if (event != null && !"/getLiveLogsCount".equalsIgnoreCase(event)) { + logPerfomance.info("\n Username :- " + + LogsearchContextUtil.getCurrentUsername() + + " Event :- " + event + " SolrQuery :- " + solrQuery + + "\nQuery Time Execution :- " + + queryResponse.getQTime() + + " Total Time Elapsed is :- " + + queryResponse.getElapsedTime()); + } + return queryResponse; + } else { + return null; + } + } + + public UpdateResponse addDocs(SolrInputDocument doc) + throws SolrServerException, IOException, SolrException { + UpdateResponse updateResoponse = solrClient.add(doc); + logPerfomance.info("\n Username :- " + + LogsearchContextUtil.getCurrentUsername() + + " Update Time Execution :- " + updateResoponse.getQTime() + + " Total Time Elapsed is :- " + + updateResoponse.getElapsedTime()); + solrClient.commit(); + return updateResoponse; + } + + public UpdateResponse removeDoc(String query) throws SolrServerException, + IOException, SolrException { + UpdateResponse updateResoponse = solrClient.deleteByQuery(query); + solrClient.commit(); + logPerfomance.info("\n Username :- " + + LogsearchContextUtil.getCurrentUsername() + + " Remove Time Execution :- " + updateResoponse.getQTime() + + " Total Time Elapsed is :- " + + updateResoponse.getElapsedTime()); + return updateResoponse; + } + + private void populateSchemaFields() { + boolean result = _populateSchemaFields(); + if (!result && !populateFieldsThreadActive) { + populateFieldsThreadActive = true; + logger.info("Creating thread to populated fields for collection=" + + collectionName); + Thread fieldPopulationThread = new Thread("populated_fields_" + + collectionName) { + @Override + public void run() { + logger.info("Started thread to get fields for collection=" + + collectionName); + int retryCount = 0; + while (true) { + try { + Thread.sleep(SETUP_RETRY_SECOND); + retryCount++; + boolean _result = _populateSchemaFields(); + if (_result) { + logger.info("Populate fields for collection " + + collectionName + " is success"); + break; + } + } catch (InterruptedException sleepInterrupted) { + logger.info("Sleep interrupted while populating fields for collection " + + collectionName); + break; + } catch (Exception ex) { + logger.error("Error while populating fields for collection " + + collectionName + + ", retryCount=" + + retryCount); + } finally { + populateFieldsThreadActive = false; + } + } + logger.info("Exiting thread for populating fields. collection=" + + collectionName); + } + + }; + fieldPopulationThread.setDaemon(true); + fieldPopulationThread.start(); + } + } + + /** + * Called from the thread. Don't call this directly + */ + private boolean _populateSchemaFields() { + SolrRequest<SchemaResponse> request = new SchemaRequest(); + request.setMethod(METHOD.GET); + request.setPath("/schema/fields"); + if (solrClient != null) { + NamedList<Object> namedList = null; + try { + namedList = solrClient.request(request); + logger.info("populateSchemaFields() collection=" + + collectionName + ", fields=" + namedList); + } catch (SolrException | SolrServerException | IOException e) { + logger.error( + "Error occured while popuplating field. collection=" + + collectionName, e); + } + if (namedList != null) { + ConfigUtil.extractSchemaFieldsName(namedList.toString(), + collectionName); + return true; + } + } + return false; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserConfigSolrDao.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserConfigSolrDao.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserConfigSolrDao.java new file mode 100644 index 0000000..750cf07 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserConfigSolrDao.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.ambari.logsearch.dao; + +import javax.annotation.PostConstruct; + +import org.apache.ambari.logsearch.util.PropertiesUtil; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + +@Component +public class UserConfigSolrDao extends SolrDaoBase { + + static private Logger logger = Logger.getLogger(UserConfigSolrDao.class); + + @PostConstruct + public void postConstructor() { + + String solrUrl = PropertiesUtil.getProperty("solr.url"); + String zkHosts = PropertiesUtil.getProperty("solr.zkhosts"); + String collection = PropertiesUtil.getProperty("solr.core.history", + "history"); + String configName = PropertiesUtil.getProperty( + "solr.history.config_name", "history"); + int replicationFactor = PropertiesUtil.getIntProperty( + "solr.history.replication_factor", 2); + String splitInterval = "none"; + int numberOfShards = 1; + + try { + connectToSolr(solrUrl, zkHosts, collection); + setupCollections(splitInterval, configName, numberOfShards, + replicationFactor); + + } catch (Exception e) { + logger.error( + "error while connecting to Solr for history logs : solrUrl=" + + solrUrl + ", zkHosts=" + zkHosts + + ", collection=" + collection, e); + } + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserDao.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserDao.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserDao.java new file mode 100644 index 0000000..091c40b --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserDao.java @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.dao; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import javax.annotation.PostConstruct; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.encoding.Md5PasswordEncoder; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.stereotype.Repository; +import org.apache.ambari.logsearch.util.FileUtil; +import org.apache.ambari.logsearch.util.JSONUtil; +import org.apache.ambari.logsearch.util.PropertiesUtil; +import org.apache.ambari.logsearch.util.StringUtil; +import org.apache.ambari.logsearch.web.model.Privilege; +import org.apache.ambari.logsearch.web.model.Role; +import org.apache.ambari.logsearch.web.model.User; +import org.apache.ambari.logsearch.web.security.LogsearchFileAuthenticationProvider; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.Predicate; +import org.apache.log4j.Logger; + +@Repository +public class UserDao { + + private static final Logger logger = Logger.getLogger(UserDao.class); + private static final Md5PasswordEncoder md5Encoder = new Md5PasswordEncoder(); + + @Autowired + JSONUtil jsonUtil; + + @Autowired + StringUtil stringUtil; + + @Autowired + FileUtil fileUtil; + + @Autowired + LogsearchFileAuthenticationProvider fileAuthenticationProvider; + + private HashMap<String, Object> userInfos = null; + + private ArrayList<HashMap<String, String>> userList = null; + + @SuppressWarnings("unchecked") + @PostConstruct + public void initialization() { + if (fileAuthenticationProvider.isEnable()) { + try { + String USER_PASS_JSON_FILE_NAME = PropertiesUtil + .getProperty("logsearch.login.credentials.file"); + logger.info("USER PASS JSON file NAME:" + USER_PASS_JSON_FILE_NAME); + File jsonFile = fileUtil + .getFileFromClasspath(USER_PASS_JSON_FILE_NAME); + if (jsonFile == null || !jsonFile.exists()) { + logger.fatal("user_pass json file not found in classpath :" + + USER_PASS_JSON_FILE_NAME); + System.exit(1); + } + userInfos = jsonUtil.readJsonFromFile(jsonFile); + userList = (ArrayList<HashMap<String, String>>) userInfos + .get("users"); + if (userList != null) { + // encrypting password using MD5 algo with salt username + boolean isUpdated = this.encryptAllPassword(); + // updating json + userInfos.put("users", userList); + if (isUpdated) { + String jsonStr = jsonUtil.mapToJSON(userInfos); + jsonUtil.writeJSONInFile(jsonStr, jsonFile, true); + } + } else { + userList = new ArrayList<HashMap<String, String>>(); + } + + } catch (Exception exception) { + logger.error("Error while reading user prop file :" + + exception.getMessage()); + userInfos = new HashMap<String, Object>(); + userList = new ArrayList<HashMap<String, String>>(); + } + } else { + logger.info("File auth is disabled."); + } + + } + + /** + * @param username + * @return + */ + public User loadUserByUsername(final String username) { + logger.debug(" loadUserByUsername username" + username); + HashMap<String, Object> userInfo = this.findByusername(username); + User user = new User(); + + if (userInfo != null) { + user.setFirstName(userInfo.get(UserInfoAttributes.NAME) != null ? (String) userInfo + .get(UserInfoAttributes.NAME) : "Unknown"); + user.setLastName(userInfo.get(UserInfoAttributes.NAME) != null ? (String) userInfo + .get(UserInfoAttributes.NAME) : "Unknown"); + user.setUsername(userInfo.get(UserInfoAttributes.USER_NAME) != null ? (String) userInfo + .get(UserInfoAttributes.USER_NAME) : ""); + user.setPassword(userInfo.get(UserInfoAttributes.ENC_PASSWORD) != null ? (String) userInfo + .get(UserInfoAttributes.ENC_PASSWORD) : ""); + } + + Role r = new Role(); + r.setName("ROLE_USER"); + Privilege priv = new Privilege(); + priv.setName("READ_PRIVILEGE"); + ArrayList<Privilege> plist = new ArrayList<Privilege>(); + plist.add(priv); + r.setPrivileges(plist); + List<GrantedAuthority> roles = new ArrayList<GrantedAuthority>(); + roles.add(r); + user.setAuthorities(roles); + return user; + } + + /** + * @param username + * @return + */ + public HashMap<String, Object> findByusername(final String username) { + if (this.userList == null) { + return null; + } + @SuppressWarnings("unchecked") + HashMap<String, Object> userInfo = (HashMap<String, Object>) CollectionUtils + .find(this.userList, new Predicate() { + @Override + public boolean evaluate(Object args) { + HashMap<String, Object> tmpuserInfo = (HashMap<String, Object>) args; + String objUsername = (String) tmpuserInfo + .get(UserInfoAttributes.USER_NAME); + if (objUsername != null && username != null) { + return username.equalsIgnoreCase(objUsername); + } + return false; + } + }); + return userInfo; + } + + private boolean encryptAllPassword() { + boolean isUpdated = false; + for (HashMap<String, String> user : userList) { + // user + String encPassword = user.get(UserInfoAttributes.ENC_PASSWORD); + String username = user.get(UserInfoAttributes.USER_NAME); + String password = user.get(UserInfoAttributes.PASSWORD); + if (!stringUtil.isEmpty(password)) { + encPassword = encryptPassword(username, password); + user.put(UserInfoAttributes.PASSWORD, ""); + user.put(UserInfoAttributes.ENC_PASSWORD, encPassword); + isUpdated = true; + } + if (stringUtil.isEmpty(password) && stringUtil.isEmpty(encPassword)) { + // log error + logger.error("Password is empty or null for username : " + + username); + } + } + return isUpdated; + } + + /** + * @param username + * @param password + * @return + */ + public String encryptPassword(String username, String password) { + String saltEncodedpasswd = md5Encoder + .encodePassword(password, username); + return saltEncodedpasswd; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserInfoAttributes.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserInfoAttributes.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserInfoAttributes.java new file mode 100644 index 0000000..7bc3555 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserInfoAttributes.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.dao; + +public interface UserInfoAttributes { + + public static final String USER_NAME = "username"; + public static final String PASSWORD = "password"; + public static final String ENC_PASSWORD = "en_password"; + public static final String NAME = "name"; + +}
