You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ol...@apache.org on 2016/04/11 18:14:48 UTC
[34/51] [partial] ambari git commit: AMBARI-15679. Initial commit for
LogSearch module (oleewre)
http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/BizUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/BizUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/BizUtil.java
new file mode 100644
index 0000000..348ca4a
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/BizUtil.java
@@ -0,0 +1,304 @@
+/*
+ * 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.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.ambari.logsearch.common.LogSearchConstants;
+import org.apache.ambari.logsearch.view.VBarDataList;
+import org.apache.ambari.logsearch.view.VBarGraphData;
+import org.apache.ambari.logsearch.view.VHost;
+import org.apache.ambari.logsearch.view.VNameValue;
+import org.apache.ambari.logsearch.view.VSummary;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.solr.common.SolrDocument;
+import org.apache.solr.common.SolrDocumentList;
+import org.apache.solr.common.util.SimpleOrderedMap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class BizUtil {
+ static Logger logger = Logger.getLogger(BizUtil.class);
+
+ @Autowired
+ RESTErrorUtil restErrorUtil;
+
+ public String convertObjectToNormalText(SolrDocumentList docList) {
+ String textToSave = "";
+ HashMap<String, String> blankFieldsMap = new HashMap<String, String>();
+ if (docList.isEmpty()) {
+ return "no data";
+ }
+ SolrDocument docForBlankCaculation = docList.get(0);
+ Collection<String> fieldsForBlankCaculation = docForBlankCaculation
+ .getFieldNames();
+
+ int maxLengthOfField = 0;
+ for (String field : fieldsForBlankCaculation) {
+ if (field.length() > maxLengthOfField)
+ maxLengthOfField = field.length();
+ }
+
+ for (String field : fieldsForBlankCaculation) {
+ blankFieldsMap
+ .put(field,
+ addBlanksToString(
+ maxLengthOfField - field.length(), field));
+ }
+
+ for (SolrDocument doc : docList) {
+
+ StringBuffer textTowrite = new StringBuffer();
+
+ if (doc.getFieldValue(LogSearchConstants.LOGTIME) != null) {
+ textTowrite.append(doc
+ .getFieldValue(LogSearchConstants.LOGTIME).toString()
+ + " ");
+ }
+ if (doc.getFieldValue(LogSearchConstants.SOLR_LEVEL) != null) {
+ textTowrite.append(
+ doc.getFieldValue(LogSearchConstants.SOLR_LEVEL)
+ .toString()).append(" ");
+ }
+ if (doc.getFieldValue(LogSearchConstants.SOLR_THREAD_NAME) != null) {
+ textTowrite.append(
+ doc.getFieldValue(LogSearchConstants.SOLR_THREAD_NAME)
+ .toString().trim()).append(" ");
+ }
+ if (doc.getFieldValue(LogSearchConstants.SOLR_LOGGER_NAME) != null) {
+ textTowrite.append(
+ doc.getFieldValue(LogSearchConstants.SOLR_LOGGER_NAME)
+ .toString().trim()).append(" ");
+ }
+ if (doc.getFieldValue(LogSearchConstants.SOLR_FILE) != null
+ && doc.getFieldValue(LogSearchConstants.SOLR_LINE_NUMBER) != null) {
+ textTowrite
+ .append(doc.getFieldValue(LogSearchConstants.SOLR_FILE)
+ .toString())
+ .append(":")
+ .append(doc.getFieldValue(
+ LogSearchConstants.SOLR_LINE_NUMBER).toString())
+ .append(" ");
+ }
+ if (doc.getFieldValue(LogSearchConstants.SOLR_LOG_MESSAGE) != null) {
+ textTowrite.append("- ").append(
+ doc.getFieldValue(LogSearchConstants.SOLR_LOG_MESSAGE)
+ .toString());
+ }
+ textTowrite.append("\n");
+ if (textTowrite != null)
+ textToSave += textTowrite.toString();
+ }
+ return textToSave;
+ }
+
+ public VSummary buildSummaryForLogFile(SolrDocumentList docList) {
+ VSummary vsummary = new VSummary();
+ int numLogs = 0;
+ List<VHost> vHosts = new ArrayList<VHost>();
+ vsummary.setHosts(vHosts);
+ String levels = "";
+ for (SolrDocument doc : docList) {
+ // adding Host and Component appropriately
+ String hostname = (String) doc.getFieldValue("host");
+ String comp = (String) doc.getFieldValue("type");
+ String level = (String) doc.getFieldValue("level");
+ boolean newHost = true;
+ for (VHost host : vHosts) {
+ if (host.getName().equals(hostname)) {
+ newHost = false;
+ host.getComponents().add(comp);
+ break;
+ }
+ }
+ if (newHost) {
+ VHost vHost = new VHost();
+ vHost.setName(hostname);
+ Set<String> component = new LinkedHashSet<String>();
+ component.add(comp);
+ vHost.setComponents(component);
+ vHosts.add(vHost);
+ }
+ // getting levels
+ if (!levels.contains(level))
+ levels = levels + ", " + level;
+ numLogs += 1;
+ }
+ levels = levels.replaceFirst(", ", "");
+ vsummary.setLevels(levels);
+ vsummary.setNumberLogs("" + numLogs);
+ return vsummary;
+ }
+
+ public String addBlanksToString(int count, String field) {
+ String temp = field;
+ for (int i = 0; i < count; i++) {
+ temp = temp + " ";
+ }
+ return temp;
+ }
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public VBarDataList buildSummaryForTopCounts(
+ SimpleOrderedMap<Object> jsonFacetResponse) {
+
+ VBarDataList vBarDataList = new VBarDataList();
+
+ Collection<VBarGraphData> dataList = new ArrayList<VBarGraphData>();
+ if (jsonFacetResponse == null) {
+ logger.info("Solr document list in null");
+ return vBarDataList;
+ }
+ List<Object> userList = jsonFacetResponse.getAll("Users");
+ if (userList.isEmpty()) {
+ return vBarDataList;
+ }
+ SimpleOrderedMap<Map<String, Object>> userMap = (SimpleOrderedMap<Map<String, Object>>) userList
+ .get(0);
+ if (userMap == null) {
+ logger.info("No top user details found");
+ return vBarDataList;
+ }
+ List<SimpleOrderedMap> userUsageList = (List<SimpleOrderedMap>) userMap
+ .get("buckets");
+ for (SimpleOrderedMap usageMap : userUsageList) {
+ VBarGraphData vBarGraphData = new VBarGraphData();
+ String userName = (String) usageMap.get("val");
+ vBarGraphData.setName(userName);
+ SimpleOrderedMap repoMap = (SimpleOrderedMap) usageMap.get("Repo");
+ List<VNameValue> componetCountList = new ArrayList<VNameValue>();
+ List<SimpleOrderedMap> repoUsageList = (List<SimpleOrderedMap>) repoMap
+ .get("buckets");
+ for (SimpleOrderedMap repoUsageMap : repoUsageList) {
+ VNameValue componetCount = new VNameValue();
+ if (repoUsageMap.get("val") != null)
+ componetCount.setName(repoUsageMap.get("val").toString());
+ String eventCount = "";
+ if (repoUsageMap.get("eventCount") != null)
+ eventCount = repoUsageMap.get("eventCount").toString();
+ eventCount = eventCount.replace(".0", "");
+ eventCount = eventCount.replace(".00", "");
+
+ componetCount.setValue(eventCount);
+ componetCountList.add(componetCount);
+ }
+ vBarGraphData.setDataCounts(componetCountList);
+ dataList.add(vBarGraphData);
+
+ }
+ vBarDataList.setGraphData(dataList);
+ logger.info("getting graph data");
+
+ return vBarDataList;
+ }
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public VBarDataList buildSummaryForResourceCounts(
+ SimpleOrderedMap<Object> jsonFacetResponse) {
+
+ VBarDataList vBarDataList = new VBarDataList();
+
+ Collection<VBarGraphData> dataList = new ArrayList<VBarGraphData>();
+ if (jsonFacetResponse == null) {
+ logger.info("Solr document list in null");
+ return vBarDataList;
+ }
+ List<Object> userList = jsonFacetResponse.getAll("x");
+ if (userList.isEmpty()) {
+ return vBarDataList;
+ }
+ SimpleOrderedMap<Map<String, Object>> userMap = (SimpleOrderedMap<Map<String, Object>>) userList
+ .get(0);
+ if (userMap == null) {
+ logger.info("No top user details found");
+ return vBarDataList;
+ }
+ List<SimpleOrderedMap> userUsageList = (List<SimpleOrderedMap>) userMap
+ .get("buckets");
+ for (SimpleOrderedMap usageMap : userUsageList) {
+ VBarGraphData vBarGraphData = new VBarGraphData();
+ String userName = (String) usageMap.get("val");
+ vBarGraphData.setName(userName);
+ SimpleOrderedMap repoMap = (SimpleOrderedMap) usageMap.get("y");
+ List<VNameValue> componetCountList = new ArrayList<VNameValue>();
+ List<SimpleOrderedMap> repoUsageList = (List<SimpleOrderedMap>) repoMap
+ .get("buckets");
+ for (SimpleOrderedMap repoUsageMap : repoUsageList) {
+ VNameValue componetCount = new VNameValue();
+ if (repoUsageMap.get("val") != null)
+ componetCount.setName(repoUsageMap.get("val").toString());
+ String eventCount = "";
+ if (repoUsageMap.get("eventCount") != null)
+ eventCount = repoUsageMap.get("eventCount").toString();
+ eventCount = eventCount.replace(".0", "");
+ eventCount = eventCount.replace(".00", "");
+
+ componetCount.setValue(eventCount);
+ componetCountList.add(componetCount);
+ }
+ vBarGraphData.setDataCounts(componetCountList);
+ dataList.add(vBarGraphData);
+
+ }
+ vBarDataList.setGraphData(dataList);
+ logger.info("getting graph data");
+
+ return vBarDataList;
+ }
+
+ public HashMap<String, String> sortHashMapByValuesD(
+ HashMap<String, String> passedMap) {
+ HashMap<String, String> sortedMap = new LinkedHashMap<String, String>();
+ List<String> mapValues = new ArrayList<String>(passedMap.values());
+ HashMap<String, String> invertedKeyValue = new HashMap<String, String>();
+ Collections.sort(mapValues, new Comparator<String>() {
+ @Override
+ public int compare(String s1, String s2) {
+ return s1.compareToIgnoreCase(s2);
+ }
+ });
+ Iterator<Entry<String, String>> it = passedMap.entrySet().iterator();
+ while (it.hasNext()) {
+ @SuppressWarnings("rawtypes")
+ Map.Entry pair = (Map.Entry) it.next();
+ invertedKeyValue.put("" + pair.getValue(), "" + pair.getKey());
+ it.remove();
+ }
+
+ for (String valueOfKey : mapValues) {
+ sortedMap.put(invertedKeyValue.get(valueOfKey), valueOfKey);
+ }
+
+ return sortedMap;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/CommonUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/CommonUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/CommonUtil.java
new file mode 100644
index 0000000..320e589
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/CommonUtil.java
@@ -0,0 +1,66 @@
+/*
+ * 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.util;
+
+import java.io.Serializable;
+import java.security.SecureRandom;
+
+public class CommonUtil implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7284237762948427019L;
+
+ static SecureRandom secureRandom = new SecureRandom();
+ static int counter = 0;
+
+ static public String genGUI() {
+ return System.currentTimeMillis() + "_" + secureRandom.nextInt(1000)
+ + "_" + counter++;
+ }
+
+ static public String genGUI(int length) {
+ String str = "";
+ for (int i = 0; i < length; i++) {
+ int ascii = genInteger(65, 90);
+ str += (char) ascii;
+ }
+ return str;
+ }
+
+ static public int genInteger() {
+ return secureRandom.nextInt();
+ }
+
+ static public int genInteger(int min, int max) {
+ int value = secureRandom.nextInt(max - min);
+ return value + min;
+ }
+
+ /**
+ * @return
+ */
+ public static long genLong() {
+ return secureRandom.nextLong();
+ }
+
+ static public int genInteger(int n) {
+ return secureRandom.nextInt();
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/ConfigUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/ConfigUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/ConfigUtil.java
new file mode 100644
index 0000000..036d5d1
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/ConfigUtil.java
@@ -0,0 +1,177 @@
+/*
+ * 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.util;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ambari.logsearch.common.LogSearchConstants;
+import org.apache.ambari.logsearch.common.MessageEnums;
+import org.apache.ambari.logsearch.manager.MgrBase;
+import org.apache.log4j.Logger;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONObject;
+
+public class ConfigUtil {
+ static Logger logger = Logger.getLogger(MgrBase.class);
+
+ public static List<String> logLevels = new ArrayList<String>();
+
+ public static HashMap<String, String> serviceLogsColumnMapping = new HashMap<String, String>();
+
+ public static HashMap<String, String> auditLogsColumnMapping = new HashMap<String, String>();
+
+ public static HashMap<String, String> schemaFieldsName = new HashMap<String, String>();
+
+ public static void initializeApplicationConfig() {
+ intializeLogLevels();
+ initializeColumnMapping();
+ }
+
+ private static void intializeUISolrColumnMapping(
+ String columnMappingArray[],
+ HashMap<String, String> columnMappingMap) {
+
+ if (columnMappingArray != null && columnMappingArray.length > 0) {
+ for (String columnMapping : columnMappingArray) {
+ String mapping[] = columnMapping.split(":");
+ String solrField = mapping[0];
+ String uiField = mapping[1];
+ String modifiedUIField = getModifiedUIField(uiField);
+ columnMappingMap.put(
+ solrField + LogSearchConstants.SOLR_SUFFIX,
+ modifiedUIField);
+ columnMappingMap.put(modifiedUIField
+ + LogSearchConstants.UI_SUFFIX, solrField);
+ }
+ }
+ }
+
+ private static String getModifiedUIField(String uiField) {
+ String modifiedUIField = "";
+ String temp = serviceLogsColumnMapping.get(uiField
+ + LogSearchConstants.UI_SUFFIX);
+ if (temp == null)
+ return uiField;
+ else {
+ String lastChar = uiField.substring(uiField.length() - 1,
+ uiField.length());
+ int k = 1;
+ try {
+ k = Integer.parseInt(lastChar);
+ k = k + 1;
+ modifiedUIField = uiField.substring(0, uiField.length() - 2);
+ } catch (Exception e) {
+
+ }
+ modifiedUIField = uiField + "_" + k;
+ }
+ return getModifiedUIField(modifiedUIField);
+ }
+
+ private static void intializeLogLevels() {
+ logLevels.add(LogSearchConstants.TRACE);
+ logLevels.add(LogSearchConstants.DEBUG);
+ logLevels.add(LogSearchConstants.INFO);
+ logLevels.add(LogSearchConstants.WARN);
+ logLevels.add(LogSearchConstants.ERROR);
+ logLevels.add(LogSearchConstants.FATAL);
+ }
+
+ private static void initializeColumnMapping() {
+ String serviceLogsColumnMappingArray[] = PropertiesUtil
+ .getPropertyStringList("servicelog.column.mapping");
+ String auditLogsColumnMappingArray[] = PropertiesUtil
+ .getPropertyStringList("auditlog.column.mapping");
+
+ // Initializing column mapping for Service Logs
+ intializeUISolrColumnMapping(serviceLogsColumnMappingArray,
+ serviceLogsColumnMapping);
+
+ // Initializing column mapping for Audit Logs
+ intializeUISolrColumnMapping(auditLogsColumnMappingArray,
+ auditLogsColumnMapping);
+ }
+
+ public static void extractSchemaFieldsName(String responseString,
+ String suffix) {
+ try {
+ JSONObject jsonObject = new JSONObject(responseString);
+ JSONArray jsonArrayList = jsonObject.getJSONArray("fields");
+
+ for (int i = 0; i < jsonArrayList.length(); i++) {
+ JSONObject explrObject = jsonArrayList.getJSONObject(i);
+ String name = explrObject.getString("name");
+ String type = explrObject.getString("type");
+
+ if (!name.contains("@") && !name.startsWith("_")
+ && !name.contains("_md5") && !name.contains("_ms")
+ && !name.contains(LogSearchConstants.NGRAM_SUFFIX)) {
+ schemaFieldsName.put(name + suffix, type);
+ }
+ }
+
+ } catch (Exception e) {
+
+ logger.error(e + "Credentials not specified in logsearch.properties "
+ + MessageEnums.ERROR_SYSTEM);
+
+ }
+
+ }
+
+ @SuppressWarnings("rawtypes")
+ public static void getSchemaFieldsName(String suffix, String excludeArray[],
+ List<String> fieldNames) {
+ if (!schemaFieldsName.isEmpty()) {
+ Iterator iteratorSechmaFieldsName = schemaFieldsName.entrySet()
+ .iterator();
+
+ while (iteratorSechmaFieldsName.hasNext()) {
+
+ Map.Entry fieldName = (Map.Entry) iteratorSechmaFieldsName
+ .next();
+ String field = "" + fieldName.getKey();
+
+ if (field.contains(suffix)) {
+ field = field.replace(suffix, "");
+ if (!isExclude(field, excludeArray)) {
+ fieldNames.add(field);
+ }
+
+ }
+ }
+ }
+ }
+
+ private static boolean isExclude(String name, String excludeArray[]) {
+ if (excludeArray != null && excludeArray.length > 0) {
+ for (String exclude : excludeArray) {
+ if (name.equals(exclude))
+ 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/util/DateUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/DateUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/DateUtil.java
new file mode 100644
index 0000000..77dd536
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/DateUtil.java
@@ -0,0 +1,206 @@
+/*
+ * 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.util;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.ambari.logsearch.common.LogSearchConstants;
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class DateUtil {
+
+ static Logger logger = Logger.getLogger(DateUtil.class);
+
+ @Autowired
+ StringUtil stringUtil;
+
+ private DateUtil() {
+
+ }
+
+ public String addOffsetToDate(String date, Long utcOffset,
+ String dateFormate) {
+ if (date == null || date.equals("")) {
+ return null;
+ }
+ if (utcOffset == null) {
+ return date;
+ }
+ String retDate = "";
+
+ try {
+ String modifiedDate = date;
+ if (date.contains(".")) {
+ modifiedDate = date.replace(".", ",");
+ }
+ SimpleDateFormat formatter = new SimpleDateFormat(dateFormate, Locale.ENGLISH);
+ Date startDate = (Date) formatter.parse(modifiedDate);
+ long toWithOffset = getTimeWithOffset(startDate, utcOffset,
+ dateFormate);
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(toWithOffset);
+ retDate = formatter.format(calendar.getTime());
+
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ return retDate;
+ }
+
+ public long getTimeWithOffset(Date date, Long utcOffset, String dateFormate) {
+ return date.getTime() + TimeUnit.MINUTES.toMillis(utcOffset);
+ }
+
+ public Date getUTCDate(long epoh) {
+ if (epoh == 0) {
+ return null;
+ }
+ try {
+ TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT+0");
+ Calendar local = Calendar.getInstance();
+ int offset = local.getTimeZone().getOffset(epoh);
+ GregorianCalendar utc = new GregorianCalendar(gmtTimeZone);
+ utc.setTimeInMillis(epoh);
+ utc.add(Calendar.MILLISECOND, -offset);
+
+ return utc.getTime();
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+
+ public String dateToString(Date date, String dateFormat) {
+ if (date == null || dateFormat == null || dateFormat.isEmpty()) {
+ return "";
+ }
+ SimpleDateFormat formatter = new SimpleDateFormat(dateFormat, Locale.ENGLISH);
+ TimeZone timeZone = TimeZone.getTimeZone("GMT");
+ formatter.setTimeZone(timeZone);
+ return formatter.format(date);
+ }
+
+ public String getCurrentDateInString() {
+ DateFormat df = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss", Locale.ENGLISH);
+ Date today = Calendar.getInstance().getTime();
+ return df.format(today);
+ }
+
+ public String getTimeInSolrFormat(String timeString) {
+ String time;
+ if (stringUtil.isEmpty(timeString)) {
+ return null;
+ }
+ time = timeString.replace(" ", "T");
+ time = time.replace(",", ".");
+ time = time + "Z";
+
+ return time;
+ }
+
+ public Date addHoursToDate(Date date, int hours) {
+ GregorianCalendar greorianCalendar = new GregorianCalendar();
+ greorianCalendar.setTime(date);
+ greorianCalendar.add(GregorianCalendar.HOUR_OF_DAY, hours);
+ return greorianCalendar.getTime();
+ }
+
+ public Date addMinsToDate(Date date, int mins) {
+ GregorianCalendar greorianCalendar = new GregorianCalendar();
+ greorianCalendar.setTime(date);
+ greorianCalendar.add(GregorianCalendar.MINUTE, mins);
+ return greorianCalendar.getTime();
+ }
+
+ public Date addSecondsToDate(Date date, int secs) {
+ GregorianCalendar greorianCalendar = new GregorianCalendar();
+ greorianCalendar.setTime(date);
+ greorianCalendar.add(GregorianCalendar.SECOND, secs);
+ return greorianCalendar.getTime();
+ }
+
+ public Date addMilliSecondsToDate(Date date, int secs) {
+ GregorianCalendar greorianCalendar = new GregorianCalendar();
+ greorianCalendar.setTime(date);
+ greorianCalendar.add(GregorianCalendar.MILLISECOND, secs);
+ return greorianCalendar.getTime();
+ }
+
+ public String convertGivenDateFormatToSolrDateFormat(Date date)
+ throws ParseException {
+ String time = date.toString();
+ SimpleDateFormat input = new SimpleDateFormat(
+ "EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
+ SimpleDateFormat output = new SimpleDateFormat(
+ LogSearchConstants.SOLR_DATE_FORMAT_PREFIX_Z, Locale.ENGLISH);
+ Date d = input.parse(time);
+ TimeZone timeZone = TimeZone.getTimeZone("UTC");
+ output.setTimeZone(timeZone);
+
+ return output.format(d);
+ }
+
+ public String convertDateWithMillisecondsToSolrDate(Date date) {
+ SimpleDateFormat formatter = new SimpleDateFormat(
+ LogSearchConstants.SOLR_DATE_FORMAT_PREFIX_Z, Locale.ENGLISH);
+ TimeZone timeZone = TimeZone.getTimeZone("GMT");
+ formatter.setTimeZone(timeZone);
+
+ return formatter.format(date);
+ }
+
+ public String convertSolrDateToNormalDateFormat(long d, long utcOffset)
+ throws ParseException {
+ Date date = new Date(d);
+ SimpleDateFormat formatter = new SimpleDateFormat(
+ LogSearchConstants.SOLR_DATE_FORMAT, Locale.ENGLISH);
+ TimeZone timeZone = TimeZone.getTimeZone("GMT");
+ formatter.setTimeZone(timeZone);
+ String stringDate = formatter.format(date);
+ return addOffsetToDate(stringDate, Long.parseLong("" + utcOffset),
+ LogSearchConstants.SOLR_DATE_FORMAT);
+
+ }
+
+ public Date convertStringToDate(String dateString) {
+
+ SimpleDateFormat formatter = new SimpleDateFormat(
+ LogSearchConstants.SOLR_DATE_FORMAT_PREFIX_Z, Locale.ENGLISH);
+ TimeZone timeZone = TimeZone.getTimeZone("GMT");
+ formatter.setTimeZone(timeZone);
+
+ try {
+ return formatter.parse(dateString);
+ } catch (ParseException e) {
+ //do nothing
+ }
+ 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/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/FileUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/FileUtil.java
new file mode 100644
index 0000000..7981cb1
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/FileUtil.java
@@ -0,0 +1,144 @@
+/*
+ * 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.util;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.net.URL;
+import java.util.List;
+import java.util.Set;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.ambari.logsearch.common.MessageEnums;
+import org.apache.ambari.logsearch.manager.UserConfigMgr;
+import org.apache.ambari.logsearch.view.VHost;
+import org.apache.ambari.logsearch.view.VSummary;
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class FileUtil {
+
+ static Logger logger = Logger.getLogger(FileUtil.class);
+
+ @Autowired
+ RESTErrorUtil restErrorUtil;
+
+ @SuppressWarnings("resource")
+ public Response saveToFile(String text, String fileName, VSummary vsummary) {
+ String mainExportedFile = "";
+ try {
+ mainExportedFile = mainExportedFile
+ + "**********************Summary**********************\n";
+ mainExportedFile = mainExportedFile + "Number of Logs : "
+ + vsummary.getNumberLogs() + "\n";
+ mainExportedFile = mainExportedFile + "From : "
+ + vsummary.getFrom() + "\n";
+ mainExportedFile = mainExportedFile + "To : "
+ + vsummary.getTo() + "\n";
+
+ List<VHost> hosts = vsummary.getHosts();
+ String blankCharacterForHost = " ";
+ int numberHost = 0;
+ for (VHost host : hosts) {
+ numberHost += 1;
+ String h = host.getName();
+ String c = "";
+ Set<String> comp = host.getComponents();
+ boolean zonetar = true;
+ for (String component : comp) {
+ if (zonetar) {
+ c = component;
+ zonetar = false;
+ } else {
+ c = c + ", " + component;
+ }
+ }
+ if (numberHost > 9)
+ blankCharacterForHost = " ";
+ else if (numberHost > 99)
+ blankCharacterForHost = " ";
+ else if (numberHost > 999)
+ blankCharacterForHost = " ";
+ else if (numberHost > 9999)
+ blankCharacterForHost = " ";
+ else if (numberHost > 99999)
+ blankCharacterForHost = " ";
+ if (numberHost == 1) {
+ mainExportedFile = mainExportedFile + "Host"
+ + blankCharacterForHost + " : " + h + " [" + c
+ + "] " + "\n";
+ } else if (numberHost > 1) {
+ mainExportedFile = mainExportedFile + "Host_" + numberHost
+ + blankCharacterForHost + " : " + h + " [" + c
+ + "] " + "\n";
+ }
+
+ }
+ mainExportedFile = mainExportedFile + "Levels : "
+ + vsummary.getLevels() + "\n";
+ mainExportedFile = mainExportedFile + "Format : "
+ + vsummary.getFormat() + "\n";
+ mainExportedFile = mainExportedFile + "\n";
+
+ mainExportedFile = mainExportedFile + "Included String: ["
+ + vsummary.getIncludeString() + "]\n\n";
+ mainExportedFile = mainExportedFile + "Excluded String: ["
+ + vsummary.getExcludeString() + "]\n\n";
+ mainExportedFile = mainExportedFile
+ + "************************Logs***********************"
+ + "\n";
+ mainExportedFile = mainExportedFile + text + "\n";
+ File file = File.createTempFile(fileName, vsummary.getFormat());
+ FileOutputStream fis = new FileOutputStream(file);
+ fis.write(mainExportedFile.getBytes());
+ return Response
+ .ok(file, MediaType.APPLICATION_OCTET_STREAM)
+ .header("Content-Disposition",
+ "attachment;filename=" + fileName
+ + vsummary.getFormat()).build();
+ } catch (Exception e) {
+ logger.error(e.getMessage());
+ throw restErrorUtil.createRESTException(e.getMessage(),
+ MessageEnums.ERROR_SYSTEM);
+ }
+ }
+
+ /**
+ * @param filename
+ * @return
+ */
+ public File getFileFromClasspath(String filename) {
+ URL fileCompleteUrl = Thread.currentThread().getContextClassLoader()
+ .getResource(filename);
+ logger.debug("File Complete URI :" + fileCompleteUrl);
+ File file = null;
+ try {
+ file = new File(fileCompleteUrl.toURI());
+ } catch (Exception exception) {
+ logger.debug(exception.getMessage(), exception.getCause());
+ }
+ return file;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/JSONUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/JSONUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/JSONUtil.java
new file mode 100644
index 0000000..417a0b1
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/JSONUtil.java
@@ -0,0 +1,261 @@
+/*
+ * 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.util;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ambari.logsearch.common.MessageEnums;
+import org.apache.log4j.Logger;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.codehaus.jackson.type.TypeReference;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+@Component
+public class JSONUtil {
+
+ static Logger logger = Logger.getLogger(JSONUtil.class);
+
+ @Autowired
+ RESTErrorUtil restErrorUtil;
+
+ @Autowired
+ StringUtil stringUtil;
+
+ public final static String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
+ Gson gson = new GsonBuilder().setDateFormat(DATE_FORMAT).create();
+
+ // Conversion from JSONArray to List<String>
+ public static List<String> JSONToList(JSONArray jarray)
+ throws JSONException {
+ ArrayList<String> list = new ArrayList<String>();
+ JSONArray jsonArray = jarray;
+ if (jsonArray != null) {
+ int len = jsonArray.length();
+ for (int i = 0; i < len; i++) {
+ list.add(jsonArray.get(i).toString());
+ }
+ }
+ return list;
+ }
+
+ @SuppressWarnings("unchecked")
+ public HashMap<String, String> jsonToMap(String jsonStr) {
+ if (stringUtil.isEmpty(jsonStr)) {
+ logger.info("jsonString is empty, cannot conver to map");
+ return null;
+ }
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ Object tempObject = mapper.readValue(jsonStr,
+ new TypeReference<HashMap<String, String>>() {
+ });
+ return (HashMap<String, String>) tempObject;
+
+ } catch (JsonParseException e) {
+ throw restErrorUtil.createRESTException(
+ "Invalid input data: " + e.getMessage(),
+ MessageEnums.INVALID_INPUT_DATA);
+ } catch (JsonMappingException e) {
+ throw restErrorUtil.createRESTException(
+ "Invalid input data: " + e.getMessage(),
+ MessageEnums.INVALID_INPUT_DATA);
+ } catch (IOException e) {
+ throw restErrorUtil.createRESTException(
+ "Invalid input data: " + e.getMessage(),
+ MessageEnums.INVALID_INPUT_DATA);
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public HashMap<String, Object> jsonToMapObject(String jsonStr) {
+ if (stringUtil.isEmpty(jsonStr)) {
+ logger.info("jsonString is empty, cannot conver to map");
+ return null;
+ }
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ Object tempObject = mapper.readValue(jsonStr,
+ new TypeReference<HashMap<String, Object>>() {
+ });
+ return (HashMap<String, Object>) tempObject;
+
+ } catch (JsonParseException e) {
+ throw restErrorUtil.createRESTException(
+ "Invalid input data: " + e.getMessage(),
+ MessageEnums.INVALID_INPUT_DATA);
+ } catch (JsonMappingException e) {
+ throw restErrorUtil.createRESTException(
+ "Invalid input data: " + e.getMessage(),
+ MessageEnums.INVALID_INPUT_DATA);
+ } catch (IOException e) {
+ throw restErrorUtil.createRESTException(
+ "Invalid input data: " + e.getMessage(),
+ MessageEnums.INVALID_INPUT_DATA);
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<HashMap<String, Object>> jsonToMapObjectList(String jsonStr) {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ Object tempObject = mapper.readValue(jsonStr,
+ new TypeReference<List<HashMap<String, Object>>>() {
+ });
+ return (List<HashMap<String, Object>>) tempObject;
+
+ } catch (JsonParseException e) {
+ throw restErrorUtil.createRESTException(
+ "Invalid input data: " + e.getMessage(),
+ MessageEnums.INVALID_INPUT_DATA);
+ } catch (JsonMappingException e) {
+ throw restErrorUtil.createRESTException(
+ "Invalid input data: " + e.getMessage(),
+ MessageEnums.INVALID_INPUT_DATA);
+ } catch (IOException e) {
+ throw restErrorUtil.createRESTException(
+ "Invalid input data: " + e.getMessage(),
+ MessageEnums.INVALID_INPUT_DATA);
+ }
+
+ }
+
+ public boolean isJSONValid(String jsonString) {
+ try {
+ new JSONObject(jsonString);
+ } catch (JSONException ex) {
+ try {
+ new JSONArray(jsonString);
+ } catch (JSONException ex1) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * @param fileName
+ * @return
+ */
+ public HashMap<String, Object> readJsonFromFile(File jsonFile) {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ HashMap<String, Object> jsonmap = mapper.readValue(jsonFile,
+ new TypeReference<HashMap<String, Object>>() {
+ });
+ return jsonmap;
+ } catch (JsonParseException e) {
+ logger.error(e, e.getCause());
+ } catch (JsonMappingException e) {
+ logger.error(e, e.getCause());
+ } catch (IOException e) {
+ logger.error(e, e.getCause());
+ }
+ return new HashMap<String, Object>();
+ }
+
+ public String mapToJSON(Map<String, Object> map) {
+ ObjectMapper om = new ObjectMapper();
+ try {
+ String json = om.writeValueAsString(map);
+
+ return json;
+ } catch (JsonGenerationException e) {
+ logger.error(e, e.getCause());
+ } catch (JsonMappingException e) {
+ logger.error(e, e.getCause());
+ } catch (IOException e) {
+ logger.error(e, e.getCause());
+ }
+ return "";
+ }
+
+ /**
+ * WRITE JOSN IN FILE ( Delete existing file and create new file)
+ *
+ * @param jsonStr
+ * @param outputFile
+ * @param beautify
+ */
+ public void writeJSONInFile(String jsonStr, File outputFile,
+ boolean beautify) {
+ FileWriter fileWriter = null;
+ if (outputFile == null) {
+ logger.error("user_pass json file can't be null.");
+ return;
+ }
+ try {
+ boolean writePermission = false;
+ if (outputFile.exists() && outputFile.canWrite()) {
+ writePermission = true;
+ }
+ if (writePermission) {
+ fileWriter = new FileWriter(outputFile);
+ if (beautify) {
+ ObjectMapper mapper = new ObjectMapper();
+ Object json = mapper.readValue(jsonStr, Object.class);
+ jsonStr = mapper.writerWithDefaultPrettyPrinter()
+ .writeValueAsString(json);
+ }
+ fileWriter.write(jsonStr);
+ } else {
+ logger.error("Applcation does not have permission to update file to write enc_password. file="
+ + outputFile.getAbsolutePath());
+ }
+ } catch (IOException e) {
+ logger.error("Error writing to password file.", e.getCause());
+ } finally {
+ if (fileWriter != null) {
+ try {
+ fileWriter.flush();
+ fileWriter.close();
+ } catch (Exception exception) {
+ // ignore
+ logger.error(exception);
+ }
+ }
+ }
+ }
+
+ public String objToJson(Object obj) {
+ return gson.toJson(obj);
+ }
+
+ public Object jsonToObj(String json, Class<?> klass) {
+ return gson.fromJson(json, klass);
+ }
+}
\ 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/util/LogsearchPropertiesConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/LogsearchPropertiesConfiguration.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/LogsearchPropertiesConfiguration.java
new file mode 100644
index 0000000..c3ef20f
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/LogsearchPropertiesConfiguration.java
@@ -0,0 +1,89 @@
+/*
+ * 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.util;
+
+import java.io.File;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.log4j.Logger;
+
+public class LogsearchPropertiesConfiguration extends PropertiesConfiguration {
+
+ Logger logger = Logger.getLogger(LogsearchPropertiesConfiguration.class);
+
+ public LogsearchPropertiesConfiguration() {
+ super();
+ }
+
+
+ public static LogsearchPropertiesConfiguration getInstance() {
+ return new LogsearchPropertiesConfiguration();
+ }
+
+ public void load(File file) {
+ if (!file.exists()) {
+ logger.error("File :" + file.getAbsolutePath() + " not exists");
+ return;
+ }
+ try {
+ super.load(file);
+ } catch (ConfigurationException e) {
+ logger.error(e);
+ }
+ }
+
+ public void load(String fileAbsolutePath) {
+ File file = new File(fileAbsolutePath);
+ load(file);
+ }
+
+ /**
+ * Load from classPath
+ *
+ * @param fileName
+ */
+ public void loadFromClasspath(String fileName) {
+ logger.debug("loading config properties : " + fileName);
+ // load file from classpath
+ try {
+ URL fileCompleteUrl = Thread.currentThread()
+ .getContextClassLoader().getResource(fileName);
+ logger.debug("File Complete URI :" + fileCompleteUrl);
+ File file = new File(fileCompleteUrl.toURI());
+ load(file);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ public HashMap<String, Object> getPropertyMap() {
+ HashMap<String, Object> propertyMap = new HashMap<String, Object>();
+ Iterator<String> keys = this.getKeys();
+ while (keys.hasNext()) {
+ String key = keys.next();
+ propertyMap.put(key, this.getProperty(key));
+ }
+ return propertyMap;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/PropertiesUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/PropertiesUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/PropertiesUtil.java
new file mode 100644
index 0000000..f31e8f8
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/PropertiesUtil.java
@@ -0,0 +1,150 @@
+/*
+ * 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.util;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
+
+public class PropertiesUtil extends PropertyPlaceholderConfigurer {
+ private static Map<String, String> propertiesMap;
+
+ private PropertiesUtil() {
+
+ }
+
+ @Override
+ protected void processProperties(
+ ConfigurableListableBeanFactory beanFactory, Properties props)
+ throws BeansException {
+ super.processProperties(beanFactory, props);
+
+ propertiesMap = new HashMap<String, String>();
+
+ // First add the system properties
+ Set<Object> keySet = System.getProperties().keySet();
+ for (Object key : keySet) {
+ String keyStr = key.toString();
+ propertiesMap.put(keyStr, System.getProperties()
+ .getProperty(keyStr).trim());
+ }
+
+ // add our properties now
+ keySet = props.keySet();
+ for (Object key : keySet) {
+ String keyStr = key.toString();
+ propertiesMap.put(keyStr, props.getProperty(keyStr).trim());
+ }
+ }
+
+ public static String getProperty(String key, String defaultValue) {
+ if (key == null) {
+ return null;
+ }
+ String rtrnVal = propertiesMap.get(key);
+ if (rtrnVal == null) {
+ rtrnVal = defaultValue;
+ }
+ return rtrnVal;
+ }
+
+ public static String getProperty(String key) {
+ if (key == null) {
+ return null;
+ }
+ return propertiesMap.get(key);
+ }
+
+ public static String[] getPropertyStringList(String key) {
+ if (key == null) {
+ return null;
+ }
+ String value = propertiesMap.get(key);
+ if (value == null || value.trim().equals("")) {
+ return new String[0];
+ } else {
+ String[] splitValues = value.split(",");
+ String[] returnValues = new String[splitValues.length];
+ for (int i = 0; i < splitValues.length; i++) {
+ returnValues[i] = splitValues[i].trim();
+ }
+ return returnValues;
+ }
+ }
+
+ public static Integer getIntProperty(String key, int defaultValue) {
+ if (key == null) {
+ return null;
+ }
+ String rtrnVal = propertiesMap.get(key);
+ if (rtrnVal == null) {
+ return defaultValue;
+ }
+ return Integer.valueOf(rtrnVal);
+ }
+
+ public static Integer getIntProperty(String key) {
+ if (key == null) {
+ return null;
+ }
+ String rtrnVal = propertiesMap.get(key);
+ if (rtrnVal == null) {
+ return null;
+ }
+ return Integer.valueOf(rtrnVal);
+ }
+
+ public static Long getLongProperty(String key, long defaultValue) {
+ if (key == null) {
+ return null;
+ }
+ String rtrnVal = propertiesMap.get(key);
+ if (rtrnVal == null) {
+ return defaultValue;
+ }
+ return Long.valueOf(rtrnVal);
+ }
+
+ public static Long getLongProperty(String key) {
+ if (key == null) {
+ return null;
+ }
+ String rtrnVal = propertiesMap.get(key);
+ if (rtrnVal == null) {
+ return null;
+ }
+ return Long.valueOf(rtrnVal);
+ }
+
+ public static boolean getBooleanProperty(String key, boolean defaultValue) {
+ if (key == null) {
+ return defaultValue;
+ }
+ String value = getProperty(key);
+ if (value == null) {
+ return defaultValue;
+ }
+ return Boolean.parseBoolean(value);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/QueryBase.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/QueryBase.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/QueryBase.java
new file mode 100644
index 0000000..4f65cf6
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/QueryBase.java
@@ -0,0 +1,127 @@
+/*
+ * 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.util;
+
+import org.apache.solr.client.solrj.SolrQuery;
+
+public class QueryBase {
+
+ //Solr Facet Methods
+ public void setFacetField(SolrQuery solrQuery, String facetField) {
+ solrQuery.setFacet(true);
+ setRowCount(solrQuery, 0);
+ solrQuery.set("facet.field", facetField);
+ setFacetLimit(solrQuery, -1);
+ }
+
+ public void setJSONFacet(SolrQuery solrQuery, String jsonQuery) {
+ solrQuery.setFacet(true);
+ setRowCount(solrQuery, 0);
+ solrQuery.set("json.facet", jsonQuery);
+ setFacetLimit(solrQuery, -1);
+ }
+
+ public void setFacetSort(SolrQuery solrQuery, String sortType) {
+ solrQuery.setFacet(true);
+ solrQuery.setFacetSort(sortType);
+ }
+
+ public void setFacetPivot(SolrQuery solrQuery, int mincount,
+ String... hirarchy) {
+ solrQuery.setFacet(true);
+ setRowCount(solrQuery, 0);
+ solrQuery.set("facet.pivot", hirarchy);
+ solrQuery.set("facet.pivot.mincount", mincount);
+ setFacetLimit(solrQuery, -1);
+ }
+
+ public void setFacetDate(SolrQuery solrQuery, String facetField,
+ String from, String to, String unit) {
+ solrQuery.setFacet(true);
+ setRowCount(solrQuery, 0);
+ solrQuery.set("facet.date", facetField);
+ solrQuery.set("facet.date.start", from);
+ solrQuery.set("facet.date.end", to);
+ solrQuery.set("facet.date.gap", unit);
+ solrQuery.set("facet.mincount", 0);
+ setFacetLimit(solrQuery, -1);
+ }
+
+ public void setFacetRange(SolrQuery solrQuery, String facetField,
+ String from, String to, String unit) {
+ solrQuery.setFacet(true);
+ setRowCount(solrQuery, 0);
+ solrQuery.set("facet.range", facetField);
+ solrQuery.set("facet.range.start", from);
+ solrQuery.set("facet.range.end", to);
+ solrQuery.set("facet.range.gap", unit);
+ solrQuery.set("facet.mincount", 0);
+ setFacetLimit(solrQuery, -1);
+ }
+
+ public void setFacetLimit(SolrQuery solrQuery, int limit) {
+ solrQuery.set("facet.limit", limit);
+ }
+
+ //Solr Group Mehtods
+ public void setGroupField(SolrQuery solrQuery, String groupField, int rows) {
+ solrQuery.set("group", true);
+ solrQuery.set("group.field", groupField);
+ solrQuery.set("group.main", true);
+ setRowCount(solrQuery, rows);
+ }
+
+ //Main Query
+ public void setMainQuery(SolrQuery solrQuery, String query) {
+ String defalultQuery = "*:*";
+ if (query == null || query.isEmpty())
+ solrQuery.setQuery(defalultQuery);
+ else
+ solrQuery.setQuery(query);
+ }
+
+ public void setStart(SolrQuery solrQuery, int start) {
+ if (start > 0) {
+ solrQuery.setStart(start);
+ } else {
+ solrQuery.setStart(0);
+ }
+ }
+
+ //Set Number of Rows
+ public void setRowCount(SolrQuery solrQuery, int rows) {
+ if (rows > 0) {
+ solrQuery.setRows(rows);
+ } else {
+ solrQuery.setRows(0);
+ solrQuery.remove("sort");
+ }
+ }
+
+ //Solr Facet Methods
+ public void setFacetField(SolrQuery solrQuery, String facetField, int minCount) {
+ solrQuery.setFacet(true);
+ setRowCount(solrQuery, 0);
+ solrQuery.set("facet.field", facetField);
+ solrQuery.set("facet.mincount", minCount);
+ setFacetLimit(solrQuery, -1);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/RESTErrorUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/RESTErrorUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/RESTErrorUtil.java
new file mode 100644
index 0000000..a3cb855
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/RESTErrorUtil.java
@@ -0,0 +1,66 @@
+/*
+ * 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.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+import org.apache.ambari.logsearch.common.MessageEnums;
+import org.apache.ambari.logsearch.view.VMessage;
+import org.apache.ambari.logsearch.view.VResponse;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+@Component
+public class RESTErrorUtil {
+
+ static final Logger logger = Logger.getLogger("org.apache.ambari.logsearch");
+
+ public static final String TRUE = "true";
+
+ public WebApplicationException createRESTException(VResponse response) {
+ return createRESTException(response, HttpServletResponse.SC_BAD_REQUEST);
+ }
+
+ public WebApplicationException createRESTException(String errorMessage,
+ MessageEnums messageEnum) {
+ List<VMessage> messageList = new ArrayList<VMessage>();
+ messageList.add(messageEnum.getMessage());
+
+ VResponse response = new VResponse();
+ response.setStatusCode(VResponse.STATUS_ERROR);
+ response.setMsgDesc(errorMessage);
+ response.setMessageList(messageList);
+ WebApplicationException webAppEx = createRESTException(response);
+ logger.error("Operation error. response=" + response, webAppEx);
+ return webAppEx;
+ }
+
+ public WebApplicationException createRESTException(VResponse response, int sc) {
+ Response errorResponse = Response.status(sc).entity(response).build();
+ WebApplicationException restException = new WebApplicationException(errorResponse);
+ restException.fillInStackTrace();
+ return restException;
+ }
+
+}
\ 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/util/SolrUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/SolrUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/SolrUtil.java
new file mode 100644
index 0000000..6fa513d
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/SolrUtil.java
@@ -0,0 +1,202 @@
+/*
+ * 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.util;
+
+import java.util.Collection;
+import java.util.Locale;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SolrUtil {
+ static final Logger logger = Logger.getLogger("org.apache.ambari.logsearch");
+
+ public String setField(String fieldName, String value) {
+ if (value == null || value.trim().length() == 0) {
+ return "";
+ }
+ return fieldName + ":" + value.trim().toLowerCase(Locale.ENGLISH);
+ }
+
+ /**
+ * @param string
+ * @param myClassTypes
+ * @return
+ */
+ public String inList(String fieldName, int[] values) {
+ if (values == null || values.length == 0) {
+ return "";
+ }
+ String expr = "";
+ // Add the filter queries
+ for (int i : values) {
+ expr += i + " ";
+ }
+ if (values.length == 0) {
+ return fieldName + ":" + expr;
+ } else {
+ return fieldName + ":(" + expr + ")";
+ }
+ }
+
+ /**
+ * @param familyUserIdSet
+ * @return
+ */
+ public String inList(Collection<Long> values) {
+ if (values == null || values.isEmpty()) {
+ return "";
+ }
+ String expr = "";
+ for (Long value : values) {
+ expr += value.toString() + " ";
+ }
+
+ if (values.isEmpty()) {
+ return expr.trim();
+ } else {
+ return "(" + expr.trim() + ")";
+ }
+
+ }
+
+ /**
+ * @param fuzzyStr
+ * @param string
+ * @param searchList
+ * @return
+ */
+ public String orList(String fieldName, String[] valueList, String fuzzyStr) {
+ if (valueList == null || valueList.length == 0) {
+ return "";
+ }
+ String expr = "";
+ int count = -1;
+ for (String value : valueList) {
+ count++;
+ if (count > 0) {
+ expr += " OR ";
+ }
+ expr += fieldName + ":*" + value + "*";
+
+ }
+ if (valueList.length == 0) {
+ return expr;
+ } else {
+ return "(" + expr + ")";
+ }
+
+ }
+
+ /**
+ * @param fuzzyStr
+ * @param string
+ * @param searchList
+ * @return
+ */
+ public String orList(String fieldName, String[] valueList) {
+ if (valueList == null || valueList.length == 0) {
+ return "";
+ }
+ String expr = "";
+ int count = -1;
+ for (String value : valueList) {
+ count++;
+ if (count > 0) {
+ expr += " OR ";
+ }
+ expr += fieldName + ":" + value;
+
+ }
+ if (valueList.length == 0) {
+ return expr;
+ } else {
+ return "(" + expr + ")";
+ }
+
+ }
+
+
+
+ /**
+ * @param fuzzyStr
+ * @param string
+ * @param searchList
+ * @return
+ */
+ public String andList(String fieldName, String[] valueList, String fuzzyStr) {
+ if (valueList == null || valueList.length == 0) {
+ return "";
+ }
+ String expr = "";
+ int count = -1;
+ for (String value : valueList) {
+ count++;
+ if (count > 0) {
+ expr += " AND ";
+ }
+ expr += fieldName + ":*" + value + "*";
+ }
+ if (valueList.length == 0) {
+ return expr;
+ } else {
+ return "(" + expr + ")";
+ }
+
+ }
+
+ public String makeSolrSearchString(String search) {
+ String newString = search.trim();
+ String newSearch = newString.replaceAll(
+ "(?=[]\\[+&|!(){}^~*=$@%?:.\\\\])", "\\\\");
+ newSearch = newSearch.replace("\n", "*");
+ newSearch = newSearch.replace("\t", "*");
+ newSearch = newSearch.replace("\r", "*");
+ newSearch = newSearch.replace(" ", "\\ ");
+ newSearch = newSearch.replace("**", "*");
+ newSearch = newSearch.replace("***", "*");
+ return "*" + newSearch + "*";
+ }
+
+ public String makeSolrSearchStringWithoutAsterisk(String search) {
+ String newString = search.trim();
+ String newSearch = newString.replaceAll(
+ "(?=[]\\[+&|!(){}^\"~=$@%?:.\\\\])", "\\\\");
+ newSearch = newSearch.replace("\n", "*");
+ newSearch = newSearch.replace("\t", "*");
+ newSearch = newSearch.replace("\r", "*");
+ newSearch = newSearch.replace(" ", "\\ ");
+ newSearch = newSearch.replace("**", "*");
+ newSearch = newSearch.replace("***", "*");
+ return newSearch;
+ }
+
+ public String makeSearcableString(String search) {
+ if(search == null || search.isEmpty())
+ return "";
+ String newSearch = search.replaceAll("[\\t\\n\\r]", " ");
+ newSearch = newSearch.replaceAll(
+ "(?=[]\\[+&|!(){}^~*=$/@%?:.\\\\-])", "\\\\");
+
+ return newSearch.replace(" ", "\\ ");
+ }
+
+}
\ 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/util/StringUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/StringUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/StringUtil.java
new file mode 100644
index 0000000..9a21e6a
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/StringUtil.java
@@ -0,0 +1,37 @@
+/*
+ * 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.util;
+
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class StringUtil {
+
+ static Logger logger = Logger.getLogger(StringUtil.class);
+
+ @Autowired
+ RESTErrorUtil restErrorUtil;
+
+ public boolean isEmpty(String str) {
+ return str == null || str.trim().length() == 0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/XMLPropertiesUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/XMLPropertiesUtil.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/XMLPropertiesUtil.java
new file mode 100644
index 0000000..ea041dc
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/XMLPropertiesUtil.java
@@ -0,0 +1,86 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.log4j.Logger;
+import org.springframework.util.DefaultPropertiesPersister;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class XMLPropertiesUtil extends DefaultPropertiesPersister {
+ private static Logger logger = Logger.getLogger(XMLPropertiesUtil.class);
+
+ public XMLPropertiesUtil() {
+ }
+
+ @Override
+ public void loadFromXml(Properties properties, InputStream inputStream)
+ throws IOException {
+ try {
+ DocumentBuilderFactory xmlDocumentBuilderFactory = DocumentBuilderFactory
+ .newInstance();
+ xmlDocumentBuilderFactory.setIgnoringComments(true);
+ xmlDocumentBuilderFactory.setNamespaceAware(true);
+ DocumentBuilder xmlDocumentBuilder = xmlDocumentBuilderFactory
+ .newDocumentBuilder();
+ Document xmlDocument = xmlDocumentBuilder.parse(inputStream);
+ xmlDocument.getDocumentElement().normalize();
+
+ NodeList nList = xmlDocument.getElementsByTagName("property");
+
+ for (int temp = 0; temp < nList.getLength(); temp++) {
+
+ Node nNode = nList.item(temp);
+
+ if (nNode.getNodeType() == Node.ELEMENT_NODE) {
+
+ Element eElement = (Element) nNode;
+
+ String propertyName = "";
+ String propertyValue = "";
+ if (eElement.getElementsByTagName("name").item(0) != null) {
+ propertyName = eElement.getElementsByTagName("name")
+ .item(0).getTextContent().trim();
+ }
+ if (eElement.getElementsByTagName("value").item(0) != null) {
+ propertyValue = eElement.getElementsByTagName("value")
+ .item(0).getTextContent().trim();
+ }
+
+ properties.put(propertyName, propertyValue);
+
+ }
+ // logger.info("ranger site properties loaded successfully.");
+ }
+ } catch (Exception e) {
+ logger.error("Error loading : ", e);
+ }
+ }
+
+}
\ 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/view/VBarDataList.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VBarDataList.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VBarDataList.java
new file mode 100644
index 0000000..9e88bd5
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VBarDataList.java
@@ -0,0 +1,42 @@
+/*
+ * 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.view;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class VBarDataList {
+ Collection<VBarGraphData> graphData = new ArrayList<VBarGraphData>();
+
+ public Collection<VBarGraphData> getGraphData() {
+ return graphData;
+ }
+
+ public void setGraphData(Collection<VBarGraphData> histogramData) {
+ this.graphData = histogramData;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VBarGraphData.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VBarGraphData.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VBarGraphData.java
new file mode 100644
index 0000000..50fe47e
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VBarGraphData.java
@@ -0,0 +1,50 @@
+/*
+ * 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.view;
+
+import java.util.Collection;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class VBarGraphData {
+ protected Collection<VNameValue> dataCount = null;
+ protected String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String level) {
+ this.name = level;
+ }
+
+ public Collection<VNameValue> getDataCount() {
+ return dataCount;
+ }
+
+ public void setDataCounts(Collection<VNameValue> dateValueCounts) {
+ this.dataCount = dateValueCounts;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VCount.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VCount.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VCount.java
new file mode 100644
index 0000000..7832fcc
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VCount.java
@@ -0,0 +1,62 @@
+/*
+ * 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.view;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class VCount implements java.io.Serializable {
+ private static final long serialVersionUID = 1L;
+
+ protected String name;
+
+ protected Long count;
+
+ /**
+ * Default constructor. This will set all the attributes to default value.
+ */
+ public VCount() {
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Long getCount() {
+ return count;
+ }
+
+ public void setCount(Long count) {
+ this.count = count;
+ }
+
+ public String toString() {
+ String str = "VLogLevel={";
+ str += super.toString();
+ str += "name={" + name + "} ";
+ str += "count={" + count + "} ";
+ str += "}";
+ return str;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VCountList.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VCountList.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VCountList.java
new file mode 100644
index 0000000..ed04db7
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VCountList.java
@@ -0,0 +1,67 @@
+/*
+ * 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.view;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.codehaus.jackson.annotate.JsonAutoDetect;
+import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+@JsonAutoDetect(getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, fieldVisibility = Visibility.ANY)
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class VCountList extends VList {
+ private static final long serialVersionUID = 1L;
+
+ List<VCount> vCounts = new ArrayList<VCount>();
+
+ public VCountList() {
+ super();
+ }
+
+ public VCountList(List<VCount> logList) {
+ super(logList);
+ this.vCounts = logList;
+ }
+
+ public void setCounts(List<VCount> list) {
+ this.vCounts = list;
+ }
+
+ @Override
+ public int getListSize() {
+ if (vCounts != null)
+ return vCounts.size();
+ return 0;
+ }
+
+ @Override
+ public List<VCount> getList() {
+ return vCounts;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VGraphData.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VGraphData.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VGraphData.java
new file mode 100644
index 0000000..1eebfac
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VGraphData.java
@@ -0,0 +1,79 @@
+/*
+ * 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.view;
+
+import java.io.Serializable;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.codehaus.jackson.annotate.JsonAutoDetect;
+import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+@JsonAutoDetect(getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, fieldVisibility = Visibility.ANY)
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class VGraphData implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String name;
+
+ protected Long count;
+
+ protected List<VGraphData> dataList;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Long getCount() {
+ return count;
+ }
+
+ public void setCount(Long info) {
+ this.count = info;
+ }
+
+ public List<VGraphData> getDataList() {
+ return dataList;
+ }
+
+ public void setDataList(List<VGraphData> dataList) {
+ this.dataList = dataList;
+ }
+
+ @Override
+ public String toString() {
+ String str = "VGraphData={";
+ str += super.toString();
+ str += "info={ " + count + " } ";
+ str += "dataList={ " + dataList + " } ";
+ return str;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VGraphInfo.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VGraphInfo.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VGraphInfo.java
new file mode 100644
index 0000000..2bf75b5
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VGraphInfo.java
@@ -0,0 +1,62 @@
+/*
+ * 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.view;
+
+import java.io.Serializable;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.codehaus.jackson.annotate.JsonAutoDetect;
+import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+@JsonAutoDetect(getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, fieldVisibility = Visibility.ANY)
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class VGraphInfo implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ protected List<VGraphData> graphData;
+
+ public List<VGraphData> getGraphData() {
+ return graphData;
+ }
+
+ public void setGraphData(List<VGraphData> graphData) {
+ this.graphData = graphData;
+ }
+
+ @Override
+ public String toString() {
+ String str = "VGraphInfo={";
+ str += super.toString();
+ str += "graphData={ " + graphData + " }";
+ return str;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VGroupList.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VGroupList.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VGroupList.java
new file mode 100644
index 0000000..25f44fc
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/view/VGroupList.java
@@ -0,0 +1,65 @@
+/*
+ * 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.view;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.solr.common.SolrDocumentList;
+import org.codehaus.jackson.annotate.JsonAutoDetect;
+import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+@JsonAutoDetect(getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, fieldVisibility = Visibility.ANY)
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class VGroupList extends VList {
+ private static final long serialVersionUID = 1L;
+
+ SolrDocumentList groupList = new SolrDocumentList();
+
+ public VGroupList() {
+ super();
+ }
+
+ public VGroupList(SolrDocumentList logList) {
+ super(logList);
+ this.groupList = logList;
+ }
+
+ public void setGroupDocuments(SolrDocumentList list) {
+ this.groupList = list;
+ }
+
+ @Override
+ public int getListSize() {
+ if (groupList != null)
+ return groupList.size();
+ return 0;
+ }
+
+ @Override
+ public SolrDocumentList getList() {
+ return groupList;
+ }
+
+}