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/08/23 08:57:05 UTC
[1/5] ambari git commit: AMBARI-18227. Add unit tests for Log Search
components and refactor them as needed - Vol 1. (Miklos Gergely via oleewere)
Repository: ambari
Updated Branches:
refs/heads/branch-dev-logsearch a565ead6f -> ffcf5328e
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
deleted file mode 100644
index de83e7e..0000000
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/StringUtil.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.stereotype.Component;
-
-@Component
-public class StringUtil {
-
- private static Logger logger = Logger.getLogger(StringUtil.class);
-
- public boolean isEmpty(String str) {
- return str == null || str.trim().length() == 0;
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/filters/LogsearchSecurityContextFormationFilter.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/filters/LogsearchSecurityContextFormationFilter.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/filters/LogsearchSecurityContextFormationFilter.java
index 69132e8..9fb285e 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/filters/LogsearchSecurityContextFormationFilter.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/filters/LogsearchSecurityContextFormationFilter.java
@@ -29,12 +29,10 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
-import org.apache.ambari.logsearch.common.RequestContext;
-import org.apache.ambari.logsearch.common.UserSessionInfo;
+import org.apache.ambari.logsearch.common.LogSearchContext;
import org.apache.ambari.logsearch.manager.SessionMgr;
-import org.apache.ambari.logsearch.security.context.LogsearchContextHolder;
-import org.apache.ambari.logsearch.security.context.LogsearchSecurityContext;
import org.apache.ambari.logsearch.util.CommonUtil;
+import org.apache.ambari.logsearch.web.model.User;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
@@ -89,31 +87,21 @@ public class LogsearchSecurityContextFormationFilter extends GenericFilterBean {
httpResponse.addCookie(cookie);
}
// [1]get the context from session
- LogsearchSecurityContext context = (LogsearchSecurityContext) httpSession
+ LogSearchContext context = (LogSearchContext) httpSession
.getAttribute(LOGSEARCH_SC_SESSION_KEY);
if (context == null) {
- context = new LogsearchSecurityContext();
+ context = new LogSearchContext();
httpSession.setAttribute(LOGSEARCH_SC_SESSION_KEY, context);
}
- String userAgent = httpRequest.getHeader(USER_AGENT);
- // Get the request specific info
- RequestContext requestContext = new RequestContext();
- String reqIP = httpRequest.getRemoteAddr();
- requestContext.setIpAddress(reqIP);
- requestContext.setMsaCookie(msaCookie);
- requestContext.setUserAgent(userAgent);
- requestContext.setServerRequestId(CommonUtil.genGUI());
- requestContext.setRequestURL(httpRequest.getRequestURI());
- context.setRequestContext(requestContext);
- LogsearchContextHolder.setSecurityContext(context);
- UserSessionInfo userSession = sessionMgr.processSuccessLogin(0, userAgent);
- context.setUserSession(userSession);
+ LogSearchContext.setContext(context);
+ User user = sessionMgr.processSuccessLogin();
+ context.setUser(user);
}
chain.doFilter(request, response);
} finally {
// [4]remove context from thread-local
- LogsearchContextHolder.resetSecurityContext();
+ LogSearchContext.resetContext();
}
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchExternalServerAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchExternalServerAuthenticationProvider.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchExternalServerAuthenticationProvider.java
index f1f2e31..72ee60f 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchExternalServerAuthenticationProvider.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchExternalServerAuthenticationProvider.java
@@ -26,8 +26,8 @@ import javax.annotation.PostConstruct;
import org.apache.ambari.logsearch.util.ExternalServerClient;
import org.apache.ambari.logsearch.util.JSONUtil;
import org.apache.ambari.logsearch.util.PropertiesUtil;
-import org.apache.ambari.logsearch.util.StringUtil;
import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
@@ -99,9 +99,6 @@ public class LogsearchExternalServerAuthenticationProvider extends
ExternalServerClient externalServerClient;
@Autowired
- StringUtil stringUtil;
-
- @Autowired
JSONUtil jsonUtil;
private String loginAPIURL = "/api/v1/users/$USERNAME/privileges?fields=*";// default
@@ -130,10 +127,10 @@ public class LogsearchExternalServerAuthenticationProvider extends
}
String username = authentication.getName();
String password = (String) authentication.getCredentials();
- if (stringUtil.isEmpty(username)) {
+ if (StringUtils.isBlank(username)) {
throw new BadCredentialsException("Username can't be null or empty.");
}
- if (stringUtil.isEmpty(password)) {
+ if (StringUtils.isBlank(password)) {
throw new BadCredentialsException("Password can't be null or empty.");
}
// html unescape
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchFileAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchFileAuthenticationProvider.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchFileAuthenticationProvider.java
index a5ff295..44c31c5 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchFileAuthenticationProvider.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchFileAuthenticationProvider.java
@@ -20,9 +20,9 @@ package org.apache.ambari.logsearch.web.security;
import java.util.Collection;
-import org.apache.ambari.logsearch.dao.UserDao;
-import org.apache.ambari.logsearch.util.StringUtil;
+import org.apache.ambari.logsearch.util.CommonUtil;
import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
@@ -40,12 +40,6 @@ public class LogsearchFileAuthenticationProvider extends LogsearchAbstractAuthen
private static Logger logger = Logger.getLogger(LogsearchFileAuthenticationProvider.class);
@Autowired
- UserDao userDao;
-
- @Autowired
- StringUtil stringUtil;
-
- @Autowired
private UserDetailsService userDetailsService;
@Override
@@ -56,10 +50,10 @@ public class LogsearchFileAuthenticationProvider extends LogsearchAbstractAuthen
}
String username = authentication.getName();
String password = (String) authentication.getCredentials();
- if (stringUtil.isEmpty(username)) {
+ if (StringUtils.isBlank(username)) {
throw new BadCredentialsException("Username can't be null or empty.");
}
- if (stringUtil.isEmpty(password)) {
+ if (StringUtils.isBlank(password)) {
throw new BadCredentialsException("Password can't be null or empty.");
}
// html unescape
@@ -76,7 +70,7 @@ public class LogsearchFileAuthenticationProvider extends LogsearchAbstractAuthen
throw new BadCredentialsException("Password can't be null or empty.");
}
- String encPassword = userDao.encryptPassword(username, password);
+ String encPassword = CommonUtil.encryptPassword(username, password);
if (!encPassword.equals(user.getPassword())) {
logger.error("Wrong password for user=" + username);
throw new BadCredentialsException("Wrong password");
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchSimpleAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchSimpleAuthenticationProvider.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchSimpleAuthenticationProvider.java
index 7e0546e..ec2516c 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchSimpleAuthenticationProvider.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchSimpleAuthenticationProvider.java
@@ -18,11 +18,10 @@
*/
package org.apache.ambari.logsearch.web.security;
-import org.apache.ambari.logsearch.util.StringUtil;
import org.apache.ambari.logsearch.web.model.User;
import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
@@ -34,9 +33,6 @@ public class LogsearchSimpleAuthenticationProvider extends LogsearchAbstractAuth
private static Logger logger = Logger.getLogger(LogsearchSimpleAuthenticationProvider.class);
- @Autowired
- StringUtil stringUtil;
-
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
if (!this.isEnable()) {
@@ -46,7 +42,7 @@ public class LogsearchSimpleAuthenticationProvider extends LogsearchAbstractAuth
String username = authentication.getName();
String password = (String) authentication.getCredentials();
username = StringEscapeUtils.unescapeHtml(username);
- if (stringUtil.isEmpty(username)) {
+ if (StringUtils.isBlank(username)) {
throw new BadCredentialsException("Username can't be null or empty.");
}
User user = new User();
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/common/LogSearchContextUtilTest.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/common/LogSearchContextUtilTest.java b/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/common/LogSearchContextUtilTest.java
new file mode 100644
index 0000000..cd33741
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/common/LogSearchContextUtilTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.web.model.User;
+import org.junit.Before;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class LogSearchContextUtilTest {
+
+ @Before
+ public void resetContext() {
+ LogSearchContext.resetContext();
+ }
+
+ @Test
+ public void testNoContext() {
+ Assert.assertNull(LogSearchContext.getCurrentUsername());
+ }
+
+ @Test
+ public void testUserSession() {
+ User user = new User("UserName", "Password", null);
+
+ LogSearchContext context = new LogSearchContext();
+ context.setUser(user);
+
+ LogSearchContext.setContext(context);
+
+ Assert.assertEquals(LogSearchContext.getCurrentUsername(), "UserName");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/common/ManageStartEndTimeTest.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/common/ManageStartEndTimeTest.java b/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/common/ManageStartEndTimeTest.java
new file mode 100644
index 0000000..6b75d87
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/common/ManageStartEndTimeTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.junit.Assert;
+import org.junit.Test;
+
+public class ManageStartEndTimeTest {
+
+ @Test
+ public void testManageStartEndTime() {
+ ManageStartEndTime.manage();
+ Date[] range = ManageStartEndTime.getStartEndTime();
+ Assert.assertEquals(range[1].getTime() - range[0].getTime(), 60*60*1000);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/AuditSolrDaoTest.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/AuditSolrDaoTest.java b/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/AuditSolrDaoTest.java
new file mode 100644
index 0000000..0b94b60
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/AuditSolrDaoTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.util.ArrayList;
+
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.common.util.NamedList;
+import org.easymock.Capture;
+import org.easymock.CaptureType;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class AuditSolrDaoTest {
+
+ @Test
+ public void testAuditSolrDaoPostConstructor() throws Exception {
+ SolrClient mockSolrClient = EasyMock.strictMock(SolrClient.class);
+
+ NamedList<Object> response = new NamedList<Object>();
+ NamedList<Object> header = new NamedList<Object>();
+ header.add("status", 0);
+ response.add("responseHeader", header);
+ response.add("collections", new ArrayList<String>());
+
+ Capture<CollectionAdminRequest.Create> captureCreateRequest = EasyMock.newCapture(CaptureType.LAST);
+
+ EasyMock.expect(mockSolrClient.request(EasyMock.anyObject(CollectionAdminRequest.List.class), EasyMock.anyString())).andReturn(response);
+
+ mockSolrClient.request(EasyMock.capture(captureCreateRequest), EasyMock.anyString());
+ EasyMock.expectLastCall().andReturn(response);
+
+ EasyMock.replay(mockSolrClient);
+
+ AuditSolrDao dao = new AuditSolrDao();
+ dao.solrClient = mockSolrClient;
+ dao.isZkConnectString = true;
+
+ dao.postConstructor();
+ EasyMock.verify(mockSolrClient);
+
+ CollectionAdminRequest.Create createRequest = captureCreateRequest.getValue();
+ Assert.assertEquals(createRequest.getConfigName(), "test_audit_logs_config_name");
+ Assert.assertEquals(createRequest.getNumShards().intValue(), 123);
+ Assert.assertEquals(createRequest.getReplicationFactor().intValue(), 456);
+ Assert.assertEquals(createRequest.getCollectionName(), "test_audit_logs_collection");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/ServiceLogsSolrDaoTest.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/ServiceLogsSolrDaoTest.java b/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/ServiceLogsSolrDaoTest.java
new file mode 100644
index 0000000..2985a62
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/ServiceLogsSolrDaoTest.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.dao;
+
+import java.util.ArrayList;
+
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.common.util.NamedList;
+import org.easymock.Capture;
+import org.easymock.CaptureType;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class ServiceLogsSolrDaoTest {
+
+ @Test
+ public void testServiceLogsSolrDaoPostConstructor() throws Exception {
+ SolrClient mockSolrClient = EasyMock.strictMock(SolrClient.class);
+
+ NamedList<Object> response = new NamedList<Object>();
+ NamedList<Object> header = new NamedList<Object>();
+ header.add("status", 0);
+ response.add("responseHeader", header);
+ response.add("collections", new ArrayList<String>());
+
+ Capture<CollectionAdminRequest.Create> captureCreateRequest = EasyMock.newCapture(CaptureType.LAST);
+
+ EasyMock.expect(mockSolrClient.request(EasyMock.anyObject(CollectionAdminRequest.List.class), EasyMock.anyString())).andReturn(response);
+ mockSolrClient.request(EasyMock.capture(captureCreateRequest), EasyMock.anyString()); EasyMock.expectLastCall().andReturn(response);
+
+ EasyMock.replay(mockSolrClient);
+
+ ServiceLogsSolrDao dao = new ServiceLogsSolrDao();
+ dao.solrClient = mockSolrClient;
+ dao.isZkConnectString = true;
+
+ dao.postConstructor();
+ EasyMock.verify(mockSolrClient);
+
+ CollectionAdminRequest.Create createRequest = captureCreateRequest.getValue();
+ Assert.assertEquals(createRequest.getConfigName(), "test_service_logs_config_name");
+ Assert.assertEquals(createRequest.getNumShards().intValue(), 789);
+ Assert.assertEquals(createRequest.getReplicationFactor().intValue(), 987);
+ Assert.assertEquals(createRequest.getCollectionName(), "test_service_logs_collection");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/SolrDaoBaseTest.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/SolrDaoBaseTest.java b/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/SolrDaoBaseTest.java
new file mode 100644
index 0000000..0ded95d
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/SolrDaoBaseTest.java
@@ -0,0 +1,286 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Arrays;
+
+import javax.ws.rs.WebApplicationException;
+
+import org.apache.ambari.logsearch.manager.MgrBase.LogType;
+import org.apache.ambari.logsearch.util.RESTErrorUtil;
+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.impl.CloudSolrClient;
+import org.apache.solr.client.solrj.impl.HttpSolrClient;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.client.solrj.response.UpdateResponse;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.util.NamedList;
+import org.easymock.EasyMock;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import junit.framework.Assert;
+
+public class SolrDaoBaseTest {
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ // ----------------------------------------------------------- connectToSolr -----------------------------------------------------------
+
+ @Test
+ public void testConnectToSolrWithConnectString() throws Exception {
+ SolrDaoBase dao = new SolrDaoBase(null) {};
+ SolrClient solrClient = dao.connectToSolr(null, "zk_connect_string", "collection");
+
+ Assert.assertEquals(solrClient.getClass(), CloudSolrClient.class);
+ }
+
+ @Test
+ public void testConnectToSolrWithUrl() throws Exception {
+ SolrDaoBase dao = new SolrDaoBase(null) {};
+ SolrClient solrClient = dao.connectToSolr("url", null, "collection");
+
+ Assert.assertEquals(solrClient.getClass(), HttpSolrClient.class);
+ }
+
+ @Test
+ public void testConnectToSolrWithBoth() throws Exception {
+ SolrDaoBase dao = new SolrDaoBase(null) {};
+ SolrClient solrClient = dao.connectToSolr("url", "zk_connect_string", "collection");
+
+ Assert.assertEquals(solrClient.getClass(), CloudSolrClient.class);
+ }
+
+ @Test
+ public void testConnectToSolrWithNeither() throws Exception {
+ expectedException.expect(Exception.class);
+ expectedException.expectMessage("Both zkConnectString and URL are empty. zkConnectString=null, collection=collection, url=null");
+
+ SolrDaoBase dao = new SolrDaoBase(null) {};
+ dao.connectToSolr(null, null, "collection");
+ }
+
+ @Test
+ public void testConnectToSolrWithoutCollection() throws Exception {
+ expectedException.expect(Exception.class);
+ expectedException.expectMessage("For solr, collection name is mandatory. zkConnectString=zk_connect_string, collection=null, url=url");
+
+ SolrDaoBase dao = new SolrDaoBase(null) {};
+ dao.connectToSolr("url", "zk_connect_string", null);
+ }
+
+ // ---------------------------------------------------------- checkSolrStatus ----------------------------------------------------------
+
+ @Test
+ public void testCheckSolrStatus() throws Exception {
+ SolrClient mockSolrClient = EasyMock.strictMock(SolrClient.class);
+
+ NamedList<Object> response = new NamedList<Object>();
+ NamedList<Object> header = new NamedList<Object>();
+ header.add("status", 0);
+ response.add("responseHeader", header);
+ response.add("collections", new ArrayList<String>());
+
+ EasyMock.expect(mockSolrClient.request(EasyMock.anyObject(CollectionAdminRequest.List.class), EasyMock.anyString())).andReturn(response);
+ EasyMock.replay(mockSolrClient);
+
+ SolrDaoBase dao = new SolrDaoBase(null) {};
+ dao.solrClient = mockSolrClient;
+
+ boolean status = dao.checkSolrStatus(10000);
+ Assert.assertTrue(status);
+
+ EasyMock.verify(mockSolrClient);
+ }
+
+ @Test
+ public void testCheckSolrStatusNotSuccessful() throws Exception {
+ SolrClient mockSolrClient = EasyMock.strictMock(SolrClient.class);
+ EasyMock.replay(mockSolrClient);
+
+ SolrDaoBase dao = new SolrDaoBase(null) {};
+ dao.solrClient = mockSolrClient;
+
+ boolean status = dao.checkSolrStatus(10000);
+ Assert.assertFalse(status);
+
+ EasyMock.verify(mockSolrClient);
+ }
+
+ // ------------------------------------------------------------- setupAlias ------------------------------------------------------------
+
+ @Test
+ public void testSetupAlias() throws Exception {
+ SolrClient mockSolrClient = EasyMock.strictMock(SolrClient.class);
+ CloudSolrClient mockSolrClouldClient = EasyMock.strictMock(CloudSolrClient.class);
+
+ NamedList<Object> response = new NamedList<Object>();
+ NamedList<Object> header = new NamedList<Object>();
+ header.add("status", 0);
+ response.add("responseHeader", header);
+ response.add("collections", Arrays.asList("collection1", "collection2"));
+
+ EasyMock.expect(mockSolrClient.request(EasyMock.anyObject(CollectionAdminRequest.List.class), EasyMock.anyString())).andReturn(response);
+ EasyMock.expect(mockSolrClouldClient.request(EasyMock.anyObject(CollectionAdminRequest.CreateAlias.class), EasyMock.anyString())).andReturn(response);
+ mockSolrClouldClient.setDefaultCollection("alias_name"); EasyMock.expectLastCall();
+
+ EasyMock.replay(mockSolrClient, mockSolrClouldClient);
+
+ SolrDaoBase dao = new SolrDaoBase(null) {};
+ dao.isZkConnectString = true;
+ dao.solrClient = mockSolrClient;
+ dao.solrClouldClient = mockSolrClouldClient;
+ dao.collectionName = "test_collection";
+
+ dao.setupAlias("alias_name", Arrays.asList("collection1", "collection2"));
+
+ Thread.sleep(1000);
+
+ EasyMock.verify(mockSolrClient, mockSolrClouldClient);
+ }
+
+ // ---------------------------------------------------------- setupCollections ---------------------------------------------------------
+
+ @Test
+ public void testCreateCollectionsDontSplitPopulate() throws Exception {
+ SolrClient mockSolrClient = EasyMock.strictMock(SolrClient.class);
+
+ NamedList<Object> response = new NamedList<Object>();
+ NamedList<Object> header = new NamedList<Object>();
+ header.add("status", 0);
+ response.add("responseHeader", header);
+ response.add("collections", new ArrayList<String>());
+
+ EasyMock.expect(mockSolrClient.request(EasyMock.anyObject(CollectionAdminRequest.List.class), EasyMock.anyString())).andReturn(response);
+ EasyMock.expect(mockSolrClient.request(EasyMock.anyObject(CollectionAdminRequest.Create.class), EasyMock.anyString())).andReturn(response);
+ EasyMock.replay(mockSolrClient);
+
+ SolrDaoBase dao = new SolrDaoBase(null) {};
+ dao.isZkConnectString = true;
+ dao.solrClient = mockSolrClient;
+ dao.collectionName = "test_collection";
+
+ dao.setupCollections("none", "configName", 1, 1, true);
+
+ EasyMock.verify(mockSolrClient);
+ }
+
+ @Test
+ public void testCreateCollectionsSplitDontPopulate() throws Exception {
+ SolrClient mockSolrClient = EasyMock.strictMock(SolrClient.class);
+
+ NamedList<Object> response = new NamedList<Object>();
+ NamedList<Object> header = new NamedList<Object>();
+ header.add("status", 0);
+ response.add("responseHeader", header);
+ response.add("collections", new ArrayList<String>());
+
+ EasyMock.expect(mockSolrClient.request(EasyMock.anyObject(CollectionAdminRequest.List.class), EasyMock.anyString())).andReturn(response);
+ EasyMock.expect(mockSolrClient.request(EasyMock.anyObject(CollectionAdminRequest.Create.class), EasyMock.anyString())).andReturn(response);
+ EasyMock.replay(mockSolrClient);
+
+ SolrDaoBase dao = new SolrDaoBase(null) {};
+ dao.isZkConnectString = true;
+ dao.solrClient = mockSolrClient;
+
+ dao.setupCollections("1", "configName", 3, 1, false);
+
+ EasyMock.verify(mockSolrClient);
+ }
+
+ // -------------------------------------------------------------- process --------------------------------------------------------------
+
+ @Test
+ public void testProcess() throws Exception {
+ SolrClient mockSolrClient = EasyMock.strictMock(SolrClient.class);
+ EasyMock.expect(mockSolrClient.query(EasyMock.anyObject(SolrQuery.class), EasyMock.eq(METHOD.POST))).andReturn(new QueryResponse());
+ EasyMock.replay(mockSolrClient);
+
+ SolrDaoBase dao = new SolrDaoBase(null) {};
+ dao.solrClient = mockSolrClient;
+
+ dao.process(new SolrQuery());
+
+ EasyMock.verify(mockSolrClient);
+ }
+
+ @Test
+ public void testProcessNoConnection() throws Exception {
+ expectedException.expect(WebApplicationException.class);
+
+ SolrDaoBase dao = new SolrDaoBase(LogType.SERVICE) {};
+ dao.restErrorUtil = new RESTErrorUtil();
+ dao.process(new SolrQuery());
+ }
+
+ // ----------------------------------------------------------- add/removeDoc -----------------------------------------------------------
+
+ @Test
+ public void testAddDoc() throws Exception {
+ SolrClient mockSolrClient = EasyMock.strictMock(SolrClient.class);
+
+ UpdateResponse updateResponse = new UpdateResponse();
+ NamedList<Object> response = new NamedList<Object>();
+ NamedList<Object> header = new NamedList<Object>();
+ header.add("QTime", 1);
+ response.add("responseHeader", header);
+ updateResponse.setResponse(response);
+
+ EasyMock.expect(mockSolrClient.add(EasyMock.anyObject(SolrInputDocument.class))).andReturn(updateResponse);
+ EasyMock.expect(mockSolrClient.commit()).andReturn(updateResponse);
+ EasyMock.replay(mockSolrClient);
+
+ SolrDaoBase dao = new SolrDaoBase(null) {};
+ dao.solrClient = mockSolrClient;
+
+ dao.addDocs(new SolrInputDocument());
+
+ EasyMock.verify(mockSolrClient);
+ }
+
+ @Test
+ public void testRemoveDoc() throws Exception {
+ SolrClient mockSolrClient = EasyMock.strictMock(SolrClient.class);
+
+ UpdateResponse updateResponse = new UpdateResponse();
+ NamedList<Object> response = new NamedList<Object>();
+ NamedList<Object> header = new NamedList<Object>();
+ header.add("QTime", 1);
+ response.add("responseHeader", header);
+ updateResponse.setResponse(response);
+
+ EasyMock.expect(mockSolrClient.deleteByQuery(EasyMock.anyString())).andReturn(updateResponse);
+ EasyMock.expect(mockSolrClient.commit()).andReturn(updateResponse);
+ EasyMock.replay(mockSolrClient);
+
+ SolrDaoBase dao = new SolrDaoBase(null) {};
+ dao.solrClient = mockSolrClient;
+
+ dao.removeDoc("query");
+
+ EasyMock.verify(mockSolrClient);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/UserConfigSolrDaoTest.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/UserConfigSolrDaoTest.java b/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/UserConfigSolrDaoTest.java
new file mode 100644
index 0000000..5ef286f
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/UserConfigSolrDaoTest.java
@@ -0,0 +1,129 @@
+/*
+ * 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.util.ArrayList;
+
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrRequest.METHOD;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.client.solrj.response.UpdateResponse;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.easymock.Capture;
+import org.easymock.CaptureType;
+import org.easymock.EasyMock;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import junit.framework.Assert;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "/applicationContext.xml" })
+public class UserConfigSolrDaoTest {
+
+ @Autowired
+ private UserConfigSolrDao dao;
+
+ @Test
+ public void testUserConfigDaoPostConstructor() throws Exception {
+ SolrClient mockSolrClient = EasyMock.strictMock(SolrClient.class);
+
+ NamedList<Object> requestResponse = new NamedList<Object>();
+ NamedList<Object> requestResponseHeader = new NamedList<Object>();
+ requestResponseHeader.add("status", 0);
+ requestResponse.add("responseHeader", requestResponseHeader);
+ requestResponse.add("collections", new ArrayList<String>());
+
+ QueryResponse queryResponse = new QueryResponse();
+
+ UpdateResponse updateResponse = new UpdateResponse();
+ NamedList<Object> updateResponseContent = new NamedList<Object>();
+ NamedList<Object> updateResponseHeader = new NamedList<Object>();
+ updateResponseHeader.add("QTime", 1);
+ updateResponseContent.add("responseHeader", updateResponseHeader);
+ updateResponse.setResponse(updateResponseContent);
+
+ Capture<CollectionAdminRequest.Create> captureCreateRequest = EasyMock.newCapture(CaptureType.LAST);
+ Capture<SolrParams> captureSolrParams = EasyMock.newCapture(CaptureType.LAST);
+ Capture<METHOD> captureMethod = EasyMock.newCapture(CaptureType.LAST);
+ Capture<SolrInputDocument> captureSolrInputDocument = EasyMock.newCapture(CaptureType.LAST);
+
+ EasyMock.expect(mockSolrClient.request(EasyMock.anyObject(CollectionAdminRequest.List.class), EasyMock.anyString())).andReturn(requestResponse);
+ mockSolrClient.request(EasyMock.capture(captureCreateRequest), EasyMock.anyString()); EasyMock.expectLastCall().andReturn(requestResponse);
+ mockSolrClient.query(EasyMock.capture(captureSolrParams), EasyMock.capture(captureMethod)); EasyMock.expectLastCall().andReturn(queryResponse);
+ mockSolrClient.add(EasyMock.capture(captureSolrInputDocument)); EasyMock.expectLastCall().andReturn(updateResponse);
+ EasyMock.expect(mockSolrClient.commit()).andReturn(updateResponse);
+ EasyMock.replay(mockSolrClient);
+
+ dao.solrClient = mockSolrClient;
+ dao.isZkConnectString = true;
+
+ dao.postConstructor();
+ EasyMock.verify(mockSolrClient);
+
+ CollectionAdminRequest.Create createRequest = captureCreateRequest.getValue();
+ Assert.assertEquals(createRequest.getConfigName(), "test_history_logs_config_name");
+ Assert.assertEquals(createRequest.getReplicationFactor().intValue(), 234);
+ Assert.assertEquals(createRequest.getCollectionName(), "test_history_logs_collection");
+
+ SolrParams solrParams = captureSolrParams.getValue();
+ Assert.assertEquals(solrParams.get("q"), "*:*");
+ Assert.assertEquals(solrParams.get("fq"), "rowtype:log_feeder_config");
+
+ METHOD method = captureMethod.getValue();
+ Assert.assertEquals(method, METHOD.POST);
+
+ SolrInputDocument solrInputDocument = captureSolrInputDocument.getValue();
+ Assert.assertNotNull(solrInputDocument.getFieldValue("id"));
+ Assert.assertEquals(solrInputDocument.getFieldValue("rowtype"), "log_feeder_config");
+ Assert.assertEquals(solrInputDocument.getFieldValue("jsons"), "{\"filter\":{\"test_component2\":{\"label\":\"test_component2\",\"hosts\":[],\"defaultLevels\":[\"FATAL\",\"ERROR\",\"WARN\",\"INFO\",\"DEBUG\",\"TRACE\"],\"overrideLevels\":[]},\"test_component1\":{\"label\":\"test_component1\",\"hosts\":[],\"defaultLevels\":[\"FATAL\",\"ERROR\",\"WARN\",\"INFO\",\"DEBUG\",\"TRACE\"],\"overrideLevels\":[]}},\"id\":\"" + solrInputDocument.getFieldValue("id") + "\"}");
+ Assert.assertEquals(solrInputDocument.getFieldValue("username"), "log_feeder_config");
+ Assert.assertEquals(solrInputDocument.getFieldValue("filtername"), "log_feeder_config");
+ }
+
+ @Test
+ public void testDeleteUserConfig() throws Exception {
+ SolrClient mockSolrClient = EasyMock.strictMock(SolrClient.class);
+
+ UpdateResponse updateResponse = new UpdateResponse();
+ NamedList<Object> response = new NamedList<Object>();
+ NamedList<Object> header = new NamedList<Object>();
+ header.add("QTime", 1);
+ response.add("responseHeader", header);
+ updateResponse.setResponse(response);
+
+ EasyMock.expect(mockSolrClient.deleteByQuery("id:test_id")).andReturn(updateResponse);
+ EasyMock.expect(mockSolrClient.commit()).andReturn(updateResponse);
+ EasyMock.replay(mockSolrClient);
+
+ dao.solrClient = mockSolrClient;
+ dao.isZkConnectString = true;
+
+ dao.deleteUserConfig("test_id");
+
+ EasyMock.verify(mockSolrClient);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/UserDaoTest.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/UserDaoTest.java b/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/UserDaoTest.java
new file mode 100644
index 0000000..703d877
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/UserDaoTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.util.Collection;
+
+import org.apache.ambari.logsearch.web.model.Role;
+import org.apache.ambari.logsearch.web.model.User;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "/applicationContext.xml" })
+public class UserDaoTest {
+
+ @Autowired
+ private UserDao dao;
+
+ @Test
+ public void testUserDaoInitAndFindUser() throws Exception {
+ User user = dao.loadUserByUsername("testUserName");
+ assertEquals(user.getUsername(), "testUserName");
+ assertEquals(user.getFirstName(), "Test User Name");
+ assertEquals(user.getLastName(), "Test User Name");
+
+ Collection<? extends GrantedAuthority> authorities = user.getAuthorities();
+ assertTrue(authorities.size() == 1);
+
+ Role authority = (Role)authorities.iterator().next();
+ assertEquals(authority.getName(), "ROLE_USER");
+ assertTrue(authority.getPrivileges().size() == 1);
+ assertEquals(authority.getPrivileges().get(0).getName(), "READ_PRIVILEGE");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/test/resources/HadoopServiceConfig.json
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/test/resources/HadoopServiceConfig.json b/ambari-logsearch/ambari-logsearch-portal/src/test/resources/HadoopServiceConfig.json
new file mode 100644
index 0000000..344dc3d
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/test/resources/HadoopServiceConfig.json
@@ -0,0 +1,17 @@
+{
+ "service": {
+ "accumulo": {
+ "label": "TestService",
+ "components": [
+ {
+ "name": "test_component1"
+ },
+ {
+ "name": "test_component2"
+ }
+ ],
+ "dependencies": [
+ ]
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/test/resources/applicationContext.xml
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/test/resources/applicationContext.xml b/ambari-logsearch/ambari-logsearch-portal/src/test/resources/applicationContext.xml
new file mode 100644
index 0000000..5e24d88
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/test/resources/applicationContext.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee"
+xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
+xmlns:task="http://www.springframework.org/schema/task" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+xmlns:util="http://www.springframework.org/schema/util"
+xsi:schemaLocation="http://www.springframework.org/schema/aop
+http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
+http://www.springframework.org/schema/beans
+http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
+http://www.springframework.org/schema/context
+http://www.springframework.org/schema/context/spring-context-4.2.xsd
+http://www.springframework.org/schema/jee
+http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
+http://www.springframework.org/schema/tx
+http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
+http://www.springframework.org/schema/task
+http://www.springframework.org/schema/task/spring-task-4.2.xsd
+http://www.springframework.org/schema/util
+http://www.springframework.org/schema/util/spring-util.xsd">
+
+ <context:component-scan base-package="org.apache.ambari.logsearch" />
+ <task:annotation-driven />
+ <bean id="xmlPropertyConfigurer" class="org.apache.ambari.logsearch.util.XMLPropertiesUtil" />
+
+ <bean id="propertyConfigurer" class="org.apache.ambari.logsearch.util.PropertiesUtil">
+ <property name="locations">
+ <list>
+ <value>classpath:default.properties</value>
+ <value>classpath:logsearch.properties</value>
+ <value>classpath:logsearch-admin-site.xml</value>
+ </list>
+ </property>
+ <property name="propertiesPersister" ref="xmlPropertyConfigurer" />
+ </bean>
+
+</beans>
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/test/resources/applicationContext_testManagers.xml
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/test/resources/applicationContext_testManagers.xml b/ambari-logsearch/ambari-logsearch-portal/src/test/resources/applicationContext_testManagers.xml
new file mode 100644
index 0000000..f1d1dbe
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/test/resources/applicationContext_testManagers.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee"
+xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
+xmlns:task="http://www.springframework.org/schema/task" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+xmlns:util="http://www.springframework.org/schema/util"
+xsi:schemaLocation="http://www.springframework.org/schema/aop
+http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
+http://www.springframework.org/schema/beans
+http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
+http://www.springframework.org/schema/context
+http://www.springframework.org/schema/context/spring-context-4.2.xsd
+http://www.springframework.org/schema/jee
+http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
+http://www.springframework.org/schema/tx
+http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
+http://www.springframework.org/schema/task
+http://www.springframework.org/schema/task/spring-task-4.2.xsd
+http://www.springframework.org/schema/util
+http://www.springframework.org/schema/util/spring-util.xsd">
+
+ <context:component-scan base-package="org.apache.ambari.logsearch.manager.dao, org.apache.ambari.logsearch.util" />
+ <task:annotation-driven />
+ <bean id="xmlPropertyConfigurer" class="org.apache.ambari.logsearch.util.XMLPropertiesUtil" />
+
+ <bean id="propertyConfigurer" class="org.apache.ambari.logsearch.util.PropertiesUtil">
+ <property name="locations">
+ <list>
+ <value>classpath:default.properties</value>
+ <value>classpath:logsearch.properties</value>
+ <value>classpath:logsearch-admin-site.xml</value>
+ </list>
+ </property>
+ <property name="propertiesPersister" ref="xmlPropertyConfigurer" />
+ </bean>
+
+</beans>
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/test/resources/logsearch.properties
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/test/resources/logsearch.properties b/ambari-logsearch/ambari-logsearch-portal/src/test/resources/logsearch.properties
new file mode 100755
index 0000000..fa3efb8
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/test/resources/logsearch.properties
@@ -0,0 +1,32 @@
+# 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.
+
+logsearch.solr.audit.logs.config.name=test_audit_logs_config_name
+logsearch.collection.audit.logs.numshards=123
+logsearch.collection.audit.logs.replication.factor=456
+logsearch.solr.collection.audit.logs=test_audit_logs_collection
+
+logsearch.solr.service.logs.config.name=test_service_logs_config_name
+logsearch.collection.service.logs.numshards=789
+logsearch.collection.service.logs.replication.factor=987
+logsearch.solr.collection.service.logs=test_service_logs_collection
+logsearch.service.logs.split.interval.mins=1
+
+logsearch.solr.history.config.name=test_history_logs_config_name
+logsearch.collection.history.replication.factor=234
+logsearch.solr.collection.history=test_history_logs_collection
+
+logsearch.auth.file.enable=true
+logsearch.login.credentials.file=user_pass.json
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/test/resources/user_pass.json
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/test/resources/user_pass.json b/ambari-logsearch/ambari-logsearch-portal/src/test/resources/user_pass.json
new file mode 100644
index 0000000..0a04afe
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/test/resources/user_pass.json
@@ -0,0 +1,8 @@
+{
+ "users": [{
+ "name": "Test User Name",
+ "username": "testUserName",
+ "password": "testUserPassword",
+ "en_password": ""
+ }]
+}
\ No newline at end of file
[3/5] ambari git commit: AMBARI-18227. Add unit tests for Log Search
components and refactor them as needed - Vol 1. (Miklos Gergely via oleewere)
Posted by ol...@apache.org.
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogsMgr.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogsMgr.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogsMgr.java
index 257f04d..9baccce 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogsMgr.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogsMgr.java
@@ -36,7 +36,6 @@ import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
-import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response;
import org.apache.ambari.logsearch.common.LogSearchConstants;
@@ -62,6 +61,8 @@ import org.apache.ambari.logsearch.view.VNode;
import org.apache.ambari.logsearch.view.VNodeList;
import org.apache.ambari.logsearch.view.VSolrLogList;
import org.apache.ambari.logsearch.view.VSummary;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.time.DateUtils;
import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
@@ -83,29 +84,24 @@ import com.google.common.collect.Lists;
@Component
public class LogsMgr extends MgrBase {
- private static Logger logger = Logger.getLogger(LogsMgr.class);
+ private static final Logger logger = Logger.getLogger(LogsMgr.class);
- public static List<String> cancelByDate = new CopyOnWriteArrayList<String>();
+ private static List<String> cancelByDate = new CopyOnWriteArrayList<String>();
- public static Map<String, String> mapUniqueId = new ConcurrentHashMap<String, String>();
-
- public static enum CONDITION {
+ private static Map<String, String> mapUniqueId = new ConcurrentHashMap<String, String>();
+
+ private static enum CONDITION {
OR, AND
}
@Autowired
- ServiceLogsSolrDao serviceLogsSolrDao;
-
+ private ServiceLogsSolrDao serviceLogsSolrDao;
@Autowired
- BizUtil bizUtil;
-
+ private BizUtil bizUtil;
@Autowired
- FileUtil fileUtil;
-
-
+ private FileUtil fileUtil;
@Autowired
- GraphDataGenerator graphDataGenerator;
-
+ private GraphDataGenerator graphDataGenerator;
public String searchLogs(SearchCriteria searchCriteria) {
String keyword = (String) searchCriteria.getParamValue("keyword");
@@ -113,7 +109,7 @@ public class LogsMgr extends MgrBase {
String lastPage = (String) searchCriteria.getParamValue("isLastPage");
Boolean isLastPage = Boolean.parseBoolean(lastPage);
- if (!stringUtil.isEmpty(keyword)) {
+ if (!StringUtils.isBlank(keyword)) {
try {
return getPageByKeyword(searchCriteria);
} catch (SolrException | SolrServerException e) {
@@ -121,7 +117,7 @@ public class LogsMgr extends MgrBase {
throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
- } else if (!stringUtil.isEmpty(logId)) {
+ } else if (!StringUtils.isBlank(logId)) {
try {
return getPageByLogId(searchCriteria);
} catch (SolrException e) {
@@ -148,11 +144,11 @@ public class LogsMgr extends MgrBase {
}
}
- public String getHosts(SearchCriteria searchCriteria) {
- return getFields(searchCriteria, LogSearchConstants.SOLR_HOST);
+ public String getHosts() {
+ return getFields(LogSearchConstants.SOLR_HOST);
}
-
- public String getFields(SearchCriteria searchCriteria,String field){
+
+ private String getFields(String field){
SolrQuery solrQuery = new SolrQuery();
VGroupList collection = new VGroupList();
@@ -200,8 +196,8 @@ public class LogsMgr extends MgrBase {
}
- public String getComponents(SearchCriteria searchCriteria) {
- return getFields(searchCriteria, LogSearchConstants.SOLR_COMPONENT);
+ public String getComponents() {
+ return getFields(LogSearchConstants.SOLR_COMPONENT);
}
public String getAggregatedInfo(SearchCriteria searchCriteria) {
@@ -255,7 +251,7 @@ public class LogsMgr extends MgrBase {
return logList;
}
- public VCountList getFieldCount(SearchCriteria searchCriteria, String field){
+ public VCountList getFieldCount(String field){
VCountList collection = new VCountList();
List<VCount> vCounts = new ArrayList<VCount>();
SolrQuery solrQuery = new SolrQuery();
@@ -297,17 +293,17 @@ public class LogsMgr extends MgrBase {
collection.setCounts(vCounts);
return collection;
}
-
- public VCountList getLogLevelCount(SearchCriteria searchCriteria) {
- return getFieldCount(searchCriteria, LogSearchConstants.SOLR_LEVEL);
+
+ public VCountList getLogLevelCount() {
+ return getFieldCount(LogSearchConstants.SOLR_LEVEL);
}
- public VCountList getComponentsCount(SearchCriteria searchCriteria) {
- return getFieldCount(searchCriteria, LogSearchConstants.SOLR_COMPONENT);
+ public VCountList getComponentsCount() {
+ return getFieldCount(LogSearchConstants.SOLR_COMPONENT);
}
- public VCountList getHostsCount(SearchCriteria searchCriteria) {
- return getFieldCount(searchCriteria, LogSearchConstants.SOLR_HOST);
+ public VCountList getHostsCount() {
+ return getFieldCount(LogSearchConstants.SOLR_HOST);
}
public List<VNode> buidTreeData(List<PivotField> pivotFields,
@@ -322,13 +318,13 @@ public class LogsMgr extends MgrBase {
VNode hostNode = new VNode();
String name = (pivotHost.getValue() == null ? "" : ""+ pivotHost.getValue());
String value = "" + pivotHost.getCount();
- if(!stringUtil.isEmpty(name)){
+ if(!StringUtils.isBlank(name)){
hostNode.setName(name);
}
- if(!stringUtil.isEmpty(value)){
+ if(!StringUtils.isBlank(value)){
hostNode.setValue(value);
}
- if(!stringUtil.isEmpty(firstPriority)){
+ if(!StringUtils.isBlank(firstPriority)){
hostNode.setType(firstPriority);
}
@@ -336,7 +332,7 @@ public class LogsMgr extends MgrBase {
hostNode.setRoot(true);
PivotField hostPivot = null;
for (PivotField searchHost : pivotFieldHost) {
- if (!stringUtil.isEmpty(hostNode.getName())
+ if (!StringUtils.isBlank(hostNode.getName())
&& hostNode.getName().equals(searchHost.getValue())) {
hostPivot = searchHost;
break;
@@ -369,7 +365,7 @@ public class LogsMgr extends MgrBase {
String compName = (pivotComp.getValue() == null ? "" : ""
+ pivotComp.getValue());
compNode.setName(compName);
- if (!stringUtil.isEmpty(secondPriority)) {
+ if (!StringUtils.isBlank(secondPriority)) {
compNode.setType(secondPriority);
}
compNode.setValue("" + pivotComp.getCount());
@@ -414,7 +410,7 @@ public class LogsMgr extends MgrBase {
String hostName = ""
+ ((searchCriteria.getParamValue("hostName") == null) ? ""
: searchCriteria.getParamValue("hostName"));
- if (!stringUtil.isEmpty(hostName)){
+ if (!StringUtils.isBlank(hostName)){
solrQuery.addFilterQuery(LogSearchConstants.SOLR_HOST + ":*"
+ hostName + "*");
}
@@ -478,7 +474,7 @@ public class LogsMgr extends MgrBase {
String componentName = ""
+ ((searchCriteria.getParamValue("componentName") == null) ? ""
: searchCriteria.getParamValue("componentName"));
- if (!stringUtil.isEmpty(componentName)){
+ if (!StringUtils.isBlank(componentName)){
solrQuery.addFilterQuery(LogSearchConstants.SOLR_COMPONENT + ":"
+ componentName);
} else {
@@ -552,7 +548,7 @@ public class LogsMgr extends MgrBase {
for (String level : LogSearchConstants.SUPPORTED_LOG_LEVEL) {
VNameValue nameValue = new VNameValue();
String value = map.get(level);
- if (stringUtil.isEmpty(value)) {
+ if (StringUtils.isBlank(value)) {
value = defalutValue;
}
nameValue.setName(level);
@@ -590,7 +586,7 @@ public class LogsMgr extends MgrBase {
String defaultChoice = "0";
String key = (String) searchCriteria.getParamValue("keyword");
- if(stringUtil.isEmpty(key)){
+ if(StringUtils.isBlank(key)){
throw restErrorUtil.createRESTException("Keyword was not given",
MessageEnums.DATA_NOT_FOUND);
}
@@ -651,7 +647,7 @@ public class LogsMgr extends MgrBase {
nextPageLogID = ""
+ solrDoc.get(LogSearchConstants.ID);
- if (stringUtil.isEmpty(nextPageLogID)){
+ if (StringUtils.isBlank(nextPageLogID)){
nextPageLogID = "0";
}
@@ -698,13 +694,13 @@ public class LogsMgr extends MgrBase {
logTimeThroughRangeQuery.remove("start");
logTimeThroughRangeQuery.remove("rows");
logTimeThroughRangeQuery.setRows(1);
- if (!stringUtil.isEmpty(filterQueryListIds)){
+ if (!StringUtils.isBlank(filterQueryListIds)){
logTimeThroughRangeQuery.setFilterQueries(filterQueryListIds);
}
String sortByType = searchCriteria.getSortType();
- if (!stringUtil.isEmpty(sortByType) && sortByType
+ if (!StringUtils.isBlank(sortByType) && sortByType
.equalsIgnoreCase(LogSearchConstants.ASCENDING_ORDER)) {
queryGenerator.setSingleRangeFilter(logTimeThroughRangeQuery,
@@ -759,16 +755,16 @@ public class LogsMgr extends MgrBase {
rangeLogQuery.remove("start");
rangeLogQuery.remove("rows");
- if (!stringUtil.isEmpty(sortByType) && sortByType
+ if (!StringUtils.isBlank(sortByType) && sortByType
.equalsIgnoreCase(LogSearchConstants.ASCENDING_ORDER)) {
- keywordLogDate = dateUtil.addMilliSecondsToDate(keywordLogDate, 1);
+ keywordLogDate = DateUtils.addMilliseconds(keywordLogDate, 1);
String keywordDateTime = dateUtil
.convertDateWithMillisecondsToSolrDate(keywordLogDate);
queryGenerator.setSingleRangeFilter(rangeLogQuery,
LogSearchConstants.LOGTIME, startTime,
keywordDateTime);
} else {
- keywordLogDate = dateUtil.addMilliSecondsToDate(keywordLogDate, -1);
+ keywordLogDate = DateUtils.addMilliseconds(keywordLogDate, -1);
String keywordDateTime = dateUtil
.convertDateWithMillisecondsToSolrDate(keywordLogDate);
queryGenerator.setSingleRangeFilter(rangeLogQuery,
@@ -795,8 +791,8 @@ public class LogsMgr extends MgrBase {
String id = (String) solrDocumenent
.getFieldValue(LogSearchConstants.ID);
countNumberLogs++;
-
- if (stringUtil.isEmpty(id) && id.equals(keywordId)){
+
+ if (StringUtils.isBlank(id) && id.equals(keywordId)){
break;
}
}
@@ -910,11 +906,11 @@ public class LogsMgr extends MgrBase {
logTimeThroughRangeQuery.setRows(1);
queryGenerator.setSingleExcludeFilter(logTimeThroughRangeQuery,
LogSearchConstants.ID, lastLogsLogId);
- if (!stringUtil.isEmpty(filterQueryListIds)){
+ if (!StringUtils.isBlank(filterQueryListIds)){
logTimeThroughRangeQuery.setFilterQueries(filterQueryListIds);
}
- if (!stringUtil.isEmpty(sortByType) && sortByType
+ if (!StringUtils.isBlank(sortByType) && sortByType
.equalsIgnoreCase(LogSearchConstants.ASCENDING_ORDER)) {
logTimeThroughRangeQuery.remove(LogSearchConstants.SORT);
@@ -974,7 +970,7 @@ public class LogsMgr extends MgrBase {
rangeLogQuery.remove("start");
rangeLogQuery.remove("rows");
- if (!stringUtil.isEmpty(sortByType) && sortByType
+ if (!StringUtils.isBlank(sortByType) && sortByType
.equalsIgnoreCase(LogSearchConstants.ASCENDING_ORDER)) {
// keywordLogDate = dateUtil.addMilliSecondsToDate(keywordLogDate, 1);
String keywordDateTime = dateUtil
@@ -1010,7 +1006,7 @@ public class LogsMgr extends MgrBase {
String id = (String) solrDocumenent
.getFieldValue(LogSearchConstants.ID);
countNumberLogs++;
- if ( stringUtil.isEmpty(id) && id.equals(keywordId)) {
+ if ( StringUtils.isBlank(id) && id.equals(keywordId)) {
break;
}
}
@@ -1039,13 +1035,13 @@ public class LogsMgr extends MgrBase {
private String getPageByLogId(SearchCriteria searchCriteria) {
VSolrLogList vSolrLogList = new VSolrLogList();
String endLogTime = (String) searchCriteria.getParamValue("to");
- if(stringUtil.isEmpty(endLogTime)){
+ if(StringUtils.isBlank(endLogTime)){
return convertObjToString(vSolrLogList);
}
long startIndex = 0l;
String logId = (String) searchCriteria.getParamValue("sourceLogId");
- if(stringUtil.isEmpty(logId)){
+ if(StringUtils.isBlank(logId)){
return convertObjToString(vSolrLogList);
}
SolrQuery solrQuery = queryGenerator.commonServiceFilterQuery(searchCriteria);
@@ -1078,7 +1074,7 @@ public class LogsMgr extends MgrBase {
if (dateOfLogId != null) {
logTime = dateUtil.convertDateWithMillisecondsToSolrDate(dateOfLogId);
- Date endDate = dateUtil.addMilliSecondsToDate(dateOfLogId, 1);
+ Date endDate = DateUtils.addMilliseconds(dateOfLogId, 1);
endTimeMinusOneMilli = (String) dateUtil
.convertDateWithMillisecondsToSolrDate(endDate);
}
@@ -1111,7 +1107,7 @@ public class LogsMgr extends MgrBase {
String id = (String) solrDocumenent
.getFieldValue(LogSearchConstants.ID);
startIndex++;
- if (!stringUtil.isEmpty(id)) {
+ if (!StringUtils.isBlank(id)) {
if (id.equals(logId)) {
break;
}
@@ -1280,7 +1276,7 @@ public class LogsMgr extends MgrBase {
}
public String cancelFindRequestByDate(String uniqueId) {
- if (stringUtil.isEmpty(uniqueId)) {
+ if (StringUtils.isEmpty(uniqueId)) {
logger.error("Unique id is Empty");
throw restErrorUtil.createRESTException("Unique id is Empty",
MessageEnums.DATA_NOT_FOUND);
@@ -1294,7 +1290,7 @@ public class LogsMgr extends MgrBase {
}
public boolean cancelRequest(String uniqueId) {
- if (stringUtil.isEmpty(uniqueId)) {
+ if (StringUtils.isBlank(uniqueId)) {
logger.error("Unique id is Empty");
throw restErrorUtil.createRESTException("Unique id is Empty",
MessageEnums.DATA_NOT_FOUND);
@@ -1317,8 +1313,8 @@ public class LogsMgr extends MgrBase {
format = defaultFormat.equalsIgnoreCase(format) && format != null ? ".txt"
: ".json";
-
- if(stringUtil.isEmpty(utcOffset)){
+
+ if(StringUtils.isBlank(utcOffset)){
utcOffset = "0";
}
@@ -1368,7 +1364,7 @@ public class LogsMgr extends MgrBase {
vsummary.setTo(to);
String includeString = (String) searchCriteria.getParamValue("iMessage");
- if (stringUtil.isEmpty(includeString)) {
+ if (StringUtils.isBlank(includeString)) {
includeString = "";
}
@@ -1378,7 +1374,7 @@ public class LogsMgr extends MgrBase {
includeString = includeString + ",\"" + inc + "\"";
}
includeString = includeString.replaceFirst(",", "");
- if (!stringUtil.isEmpty(includeString)) {
+ if (!StringUtils.isBlank(includeString)) {
vsummary.setIncludeString(includeString);
}
@@ -1386,7 +1382,7 @@ public class LogsMgr extends MgrBase {
boolean isNormalExcluded = false;
excludeString = (String) searchCriteria.getParamValue("eMessage");
- if (stringUtil.isEmpty(excludeString)) {
+ if (StringUtils.isBlank(excludeString)) {
excludeString = "";
}
@@ -1396,14 +1392,14 @@ public class LogsMgr extends MgrBase {
}
excludeString = excludeString.replaceFirst(",", "");
- if (!stringUtil.isEmpty(excludeString)) {
+ if (!StringUtils.isBlank(excludeString)) {
vsummary.setExcludeString(excludeString);
isNormalExcluded = true;
}
String globalExcludeString = (String) searchCriteria
.getParamValue("gEMessage");
- if (stringUtil.isEmpty(globalExcludeString)) {
+ if (StringUtils.isBlank(globalExcludeString)) {
globalExcludeString = "";
}
@@ -1414,7 +1410,7 @@ public class LogsMgr extends MgrBase {
excludeString = excludeString + ",\"" + exc + "\"";
}
- if (!stringUtil.isEmpty(excludeString)) {
+ if (!StringUtils.isBlank(excludeString)) {
if (!isNormalExcluded) {
excludeString = excludeString.replaceFirst(",", "");
}
@@ -1513,7 +1509,7 @@ public class LogsMgr extends MgrBase {
try {
String bundelId = (String) searchCriteria
.getParamValue(LogSearchConstants.BUNDLE_ID);
- if(stringUtil.isEmpty(bundelId)){
+ if(StringUtils.isBlank(bundelId)){
bundelId = "";
}
@@ -1709,18 +1705,18 @@ public class LogsMgr extends MgrBase {
SolrDocumentList docList = null;
String id = (String) searchCriteria
.getParamValue(LogSearchConstants.ID);
- if (stringUtil.isEmpty(id)) {
+ if (StringUtils.isBlank(id)) {
return convertObjToString(vSolrLogList);
}
String maxRows = "";
maxRows = (String) searchCriteria.getParamValue("numberRows");
- if (stringUtil.isEmpty(maxRows)){
+ if (StringUtils.isBlank(maxRows)){
maxRows = ""+maxRows;
}
String scrollType = (String) searchCriteria.getParamValue("scrollType");
- if(stringUtil.isEmpty(scrollType)){
+ if(StringUtils.isBlank(scrollType)){
scrollType = "";
}
@@ -1744,7 +1740,7 @@ public class LogsMgr extends MgrBase {
+ docList.get(0).getFieldValue(
LogSearchConstants.SEQUNCE_ID);
}
- if (stringUtil.isEmpty(logTime)) {
+ if (StringUtils.isBlank(logTime)) {
return convertObjToString(vSolrLogList);
}
} catch (SolrServerException | SolrException | IOException e) {
@@ -1874,10 +1870,10 @@ public class LogsMgr extends MgrBase {
TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT");
GregorianCalendar utc = new GregorianCalendar(gmtTimeZone);
utc.setTimeInMillis(new Date().getTime());
- utc.set(GregorianCalendar.HOUR, 0);
- utc.set(GregorianCalendar.MINUTE, 0);
- utc.set(GregorianCalendar.MILLISECOND, 001);
- utc.set(GregorianCalendar.SECOND, 0);
+ utc.set(Calendar.HOUR, 0);
+ utc.set(Calendar.MINUTE, 0);
+ utc.set(Calendar.MILLISECOND, 001);
+ utc.set(Calendar.SECOND, 0);
dateUtil.convertDateWithMillisecondsToSolrDate(utc.getTime());
String from = dateUtil.convertDateWithMillisecondsToSolrDate(utc.getTime());
utc.set(Calendar.MILLISECOND, 999);
@@ -1889,7 +1885,7 @@ public class LogsMgr extends MgrBase {
LogSearchConstants.LOGTIME, from,to);
String level = LogSearchConstants.FATAL+","+LogSearchConstants.ERROR+","+LogSearchConstants.WARN;
queryGenerator.setFilterClauseWithFieldName(solrQuery, level,
- LogSearchConstants.SOLR_LEVEL, "", QueryGenerationBase.CONDITION.OR);
+ LogSearchConstants.SOLR_LEVEL, "", QueryGenerationBase.Condition.OR);
try {
serviceLogsSolrDao.process(solrQuery);
} catch (SolrServerException | IOException e) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/MgrBase.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/MgrBase.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/MgrBase.java
index 99eb9f2..02e2e69 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/MgrBase.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/MgrBase.java
@@ -35,8 +35,8 @@ import org.apache.ambari.logsearch.util.DateUtil;
import org.apache.ambari.logsearch.util.JSONUtil;
import org.apache.ambari.logsearch.util.RESTErrorUtil;
import org.apache.ambari.logsearch.util.SolrUtil;
-import org.apache.ambari.logsearch.util.StringUtil;
import org.apache.ambari.logsearch.view.VSolrLogList;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
@@ -57,53 +57,46 @@ import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
public class MgrBase {
- static private Logger logger = Logger.getLogger(MgrBase.class);
+ private static final Logger logger = Logger.getLogger(MgrBase.class);
@Autowired
- SolrUtil solrUtil;
+ protected SolrUtil solrUtil;
@Autowired
- JSONUtil jsonUtil;
+ protected JSONUtil jsonUtil;
@Autowired
- QueryGeneration queryGenerator;
+ protected QueryGeneration queryGenerator;
@Autowired
- StringUtil stringUtil;
+ protected RESTErrorUtil restErrorUtil;
@Autowired
- RESTErrorUtil restErrorUtil;
+ protected DateUtil dateUtil;
- @Autowired
- DateUtil dateUtil;
-
- JsonSerializer<Date> jsonDateSerialiazer = null;
- JsonDeserializer<Date> jsonDateDeserialiazer = null;
+ private JsonSerializer<Date> jsonDateSerialiazer = null;
+ private JsonDeserializer<Date> jsonDateDeserialiazer = null;
- public enum LOG_TYPE {
- SERVICE {
- @Override
- public String getLabel() {
- return "Service";
- }
- },
- AUDIT {
- @Override
- public String getLabel() {
- return "Audit";
- }
- };
- public abstract String getLabel();
+ public enum LogType {
+ SERVICE("Service"),
+ AUDIT("Audit");
+
+ private String label;
+
+ private LogType(String label) {
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
}
public MgrBase() {
jsonDateSerialiazer = new JsonSerializer<Date>() {
@Override
- public JsonElement serialize(Date paramT,
- java.lang.reflect.Type paramType,
- JsonSerializationContext paramJsonSerializationContext) {
-
+ public JsonElement serialize(Date paramT, java.lang.reflect.Type paramType, JsonSerializationContext paramJsonSerializationContext) {
return paramT == null ? null : new JsonPrimitive(paramT.getTime());
}
};
@@ -111,15 +104,15 @@ public class MgrBase {
jsonDateDeserialiazer = new JsonDeserializer<Date>() {
@Override
- public Date deserialize(JsonElement json, java.lang.reflect.Type typeOfT,
- JsonDeserializationContext context) throws JsonParseException {
+ public Date deserialize(JsonElement json, java.lang.reflect.Type typeOfT, JsonDeserializationContext context)
+ throws JsonParseException {
return json == null ? null : new Date(json.getAsLong());
}
};
}
- public String convertObjToString(Object obj) {
+ protected String convertObjToString(Object obj) {
if (obj == null) {
return "";
}
@@ -136,8 +129,7 @@ public class MgrBase {
// Get file from resources folder
ClassLoader classLoader = getClass().getClassLoader();
- File file = new File(classLoader.getResource("HadoopServiceConfig.json")
- .getFile());
+ File file = new File(classLoader.getResource("HadoopServiceConfig.json").getFile());
try (Scanner scanner = new Scanner(file)) {
@@ -150,26 +142,25 @@ public class MgrBase {
} catch (IOException e) {
logger.error("Unable to read HadoopServiceConfig.json", e);
- throw restErrorUtil.createRESTException(e.getMessage(),
- MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(e.getMessage(), MessageEnums.ERROR_SYSTEM);
}
String hadoopServiceConfig = result.toString();
if (jsonUtil.isJSONValid(hadoopServiceConfig)) {
return hadoopServiceConfig;
}
- throw restErrorUtil.createRESTException("Improper JSON",
- MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException("Improper JSON", MessageEnums.ERROR_SYSTEM);
}
- protected VSolrLogList getLastPage(SearchCriteria searchCriteria,String logTimeField,SolrDaoBase solrDoaBase,SolrQuery lastPageQuery){
+ protected VSolrLogList getLastPage(SearchCriteria searchCriteria, String logTimeField, SolrDaoBase solrDoaBase,
+ SolrQuery lastPageQuery) {
Integer maxRows = searchCriteria.getMaxRows();
String givenSortType = searchCriteria.getSortType();
searchCriteria = new SearchCriteria();
searchCriteria.setSortBy(logTimeField);
- if(givenSortType == null || givenSortType.equals(LogSearchConstants.DESCENDING_ORDER)){
+ if (givenSortType == null || givenSortType.equals(LogSearchConstants.DESCENDING_ORDER)) {
lastPageQuery.removeSort(LogSearchConstants.LOGTIME);
searchCriteria.setSortType(LogSearchConstants.ASCENDING_ORDER);
} else {
@@ -185,8 +176,7 @@ public class MgrBase {
try {
queryGenerator.setStart(lastPageQuery, 0);
queryGenerator.setRowCount(lastPageQuery, maxRows);
- collection = getLogAsPaginationProvided(lastPageQuery,
- solrDoaBase);
+ collection = getLogAsPaginationProvided(lastPageQuery, solrDoaBase);
totalLogs = countQuery(lastPageQuery,solrDoaBase);
if(maxRows != null){
startIndex = Integer.parseInt("" + ((totalLogs/maxRows) * maxRows));
@@ -209,14 +199,12 @@ public class MgrBase {
} catch (SolrException | SolrServerException | IOException | NumberFormatException e) {
logger.error("Count Query was not executed successfully",e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
return collection;
}
- public VSolrLogList getLogAsPaginationProvided(SolrQuery solrQuery,
- SolrDaoBase solrDaoBase) {
+ protected VSolrLogList getLogAsPaginationProvided(SolrQuery solrQuery, SolrDaoBase solrDaoBase) {
try {
QueryResponse response = solrDaoBase.process(solrQuery);
VSolrLogList collection = new VSolrLogList();
@@ -235,14 +223,11 @@ public class MgrBase {
return collection;
} catch (SolrException | SolrServerException | IOException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
-
}
- public Long countQuery(SolrQuery query,SolrDaoBase solrDaoBase) throws SolrException,
- SolrServerException, IOException {
+ protected Long countQuery(SolrQuery query,SolrDaoBase solrDaoBase) throws SolrException, SolrServerException, IOException {
query.setRows(0);
QueryResponse response = solrDaoBase.process(query);
if (response == null) {
@@ -256,14 +241,14 @@ public class MgrBase {
}
protected String getUnit(String unit) {
- if (stringUtil.isEmpty(unit)) {
+ if (StringUtils.isBlank(unit)) {
unit = "+1HOUR";
}
return unit;
}
protected String getFrom(String from) {
- if (stringUtil.isEmpty(from)) {
+ if (StringUtils.isBlank(from)) {
Date date = dateUtil.getTodayFromDate();
try {
from = dateUtil.convertGivenDateFormatToSolrDateFormat(date);
@@ -275,7 +260,7 @@ public class MgrBase {
}
protected String getTo(String to) {
- if (stringUtil.isEmpty(to)) {
+ if (StringUtils.isBlank(to)) {
to = "NOW";
}
return to;
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/PublicMgr.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/PublicMgr.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/PublicMgr.java
index 0dccb74..398d270 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/PublicMgr.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/PublicMgr.java
@@ -31,7 +31,7 @@ import org.springframework.stereotype.Component;
@Component
public class PublicMgr extends MgrBase {
@Autowired
- LogsearchSimpleAuthenticationProvider simpleAuthenticationProvider;
+ private LogsearchSimpleAuthenticationProvider simpleAuthenticationProvider;
public String getGeneralConfig() {
VNameValueList nameValueList = new VNameValueList();
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/SessionMgr.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/SessionMgr.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/SessionMgr.java
index dbc14e1..c6f7dc5 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/SessionMgr.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/SessionMgr.java
@@ -18,11 +18,7 @@
*/
package org.apache.ambari.logsearch.manager;
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.ambari.logsearch.common.UserSessionInfo;
-import org.apache.ambari.logsearch.security.context.LogsearchContextHolder;
-import org.apache.ambari.logsearch.security.context.LogsearchSecurityContext;
+import org.apache.ambari.logsearch.common.LogSearchContext;
import org.apache.ambari.logsearch.web.model.User;
import org.apache.log4j.Logger;
import org.springframework.security.core.Authentication;
@@ -33,38 +29,28 @@ import org.springframework.stereotype.Component;
@Component
public class SessionMgr {
- static final Logger logger = Logger.getLogger(SessionMgr.class);
+ private static final Logger logger = Logger.getLogger(SessionMgr.class);
public SessionMgr() {
logger.debug("SessionManager created");
}
- public UserSessionInfo processSuccessLogin(int authType, String userAgent) {
- return processSuccessLogin(authType, userAgent, null);
- }
-
- public UserSessionInfo processSuccessLogin(int authType, String userAgent, HttpServletRequest httpRequest) {
+ public User processSuccessLogin() {
boolean newSessionCreation = true;
- UserSessionInfo userSession = null;
- LogsearchSecurityContext context = LogsearchContextHolder.getSecurityContext();
- if (context != null) {
- userSession = context.getUserSession();
- }
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
WebAuthenticationDetails details = (WebAuthenticationDetails) authentication.getDetails();
String currentLoginId = authentication.getName();
- if (userSession != null) {
- if (validateUserSession(userSession, currentLoginId)) {
+ LogSearchContext context = LogSearchContext.getContext();
+ User user = context.getUser();
+ if (user != null) {
+ if (validateUser(user, currentLoginId)) {
newSessionCreation = false;
}
}
//
if (newSessionCreation) {
- // // Need to build the UserSession
- userSession = new UserSessionInfo();
- User user = new User();
+ user = new User();
user.setUsername(currentLoginId);
- userSession.setUser(user);
if (details != null) {
logger.info("Login Success: loginId=" + currentLoginId + ", sessionId=" + details.getSessionId()
+ ", requestId=" + details.getRemoteAddress());
@@ -74,15 +60,15 @@ public class SessionMgr {
}
- return userSession;
+ return user;
}
- protected boolean validateUserSession(UserSessionInfo userSession, String currentUsername) {
- if (currentUsername.equalsIgnoreCase(userSession.getUser().getUsername())) {
+ private boolean validateUser(User user, String currentUsername) {
+ if (currentUsername.equalsIgnoreCase(user.getUsername())) {
return true;
} else {
logger.info("loginId doesn't match loginId from HTTPSession. Will create new session. loginId="
- + currentUsername + ", userSession=" + userSession, new Exception());
+ + currentUsername + ", user=" + user, new Exception());
return false;
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/UserConfigMgr.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/UserConfigMgr.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/UserConfigMgr.java
index c4fbd9f..28f806c 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/UserConfigMgr.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/UserConfigMgr.java
@@ -31,10 +31,10 @@ import org.apache.ambari.logsearch.dao.UserConfigSolrDao;
import org.apache.ambari.logsearch.query.QueryGeneration;
import org.apache.ambari.logsearch.util.RESTErrorUtil;
import org.apache.ambari.logsearch.util.SolrUtil;
-import org.apache.ambari.logsearch.util.StringUtil;
import org.apache.ambari.logsearch.view.VLogfeederFilterWrapper;
import org.apache.ambari.logsearch.view.VUserConfig;
import org.apache.ambari.logsearch.view.VUserConfigList;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
@@ -50,35 +50,26 @@ import org.springframework.stereotype.Component;
@Component
public class UserConfigMgr extends MgrBase {
- static Logger logger = Logger.getLogger(UserConfigMgr.class);
+ private static final Logger logger = Logger.getLogger(UserConfigMgr.class);
@Autowired
- UserConfigSolrDao userConfigSolrDao;
-
- @Autowired
- SolrUtil solrUtil;
-
+ private UserConfigSolrDao userConfigSolrDao;
@Autowired
- RESTErrorUtil restErrorUtil;
-
+ private SolrUtil solrUtil;
@Autowired
- QueryGeneration queryGenerator;
-
+ private RESTErrorUtil restErrorUtil;
@Autowired
- StringUtil stringUtil;
+ private QueryGeneration queryGenerator;
public String saveUserConfig(VUserConfig vHistory) {
SolrInputDocument solrInputDoc = new SolrInputDocument();
if (!isValid(vHistory)) {
- throw restErrorUtil.createRESTException("No FilterName Specified",
- MessageEnums.INVALID_INPUT_DATA);
+ throw restErrorUtil.createRESTException("No FilterName Specified", MessageEnums.INVALID_INPUT_DATA);
}
if (isNotUnique(vHistory) && !vHistory.isOverwrite()) {
- throw restErrorUtil.createRESTException(
- "Name '" + vHistory.getFiltername() + "' already exists",
- MessageEnums.INVALID_INPUT_DATA);
+ throw restErrorUtil.createRESTException( "Name '" + vHistory.getFiltername() + "' already exists", MessageEnums.INVALID_INPUT_DATA);
}
String loggedInUserName = vHistory.getUserName();
String filterName = vHistory.getFiltername();
@@ -95,25 +86,20 @@ public class UserConfigMgr extends MgrBase {
// Check whether the Filter Name exists in solr
SolrQuery solrQuery = new SolrQuery();
queryGenerator.setMainQuery(solrQuery, null);
- queryGenerator.setSingleIncludeFilter(solrQuery,
- LogSearchConstants.FILTER_NAME, solrUtil.makeSearcableString(filterName));
- queryGenerator.setSingleIncludeFilter(solrQuery,
- LogSearchConstants.USER_NAME, loggedInUserName);
+ queryGenerator.setSingleIncludeFilter(solrQuery, LogSearchConstants.FILTER_NAME, solrUtil.makeSearcableString(filterName));
+ queryGenerator.setSingleIncludeFilter(solrQuery, LogSearchConstants.USER_NAME, loggedInUserName);
try {
QueryResponse queryResponse = userConfigSolrDao.process(solrQuery);
if (queryResponse != null) {
SolrDocumentList documentList = queryResponse.getResults();
- if (documentList != null && !documentList.isEmpty()
- && !vHistory.isOverwrite()) {
+ if (documentList != null && !documentList.isEmpty() && !vHistory.isOverwrite()) {
logger.error("Filtername is already present");
- throw restErrorUtil.createRESTException(
- "Filtername is already present", MessageEnums.INVALID_INPUT_DATA);
+ throw restErrorUtil.createRESTException("Filtername is already present", MessageEnums.INVALID_INPUT_DATA);
}
}
} catch (SolrException | SolrServerException | IOException e) {
logger.error("Error in checking same filtername config", e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
try {
@@ -121,8 +107,7 @@ public class UserConfigMgr extends MgrBase {
return convertObjToString(solrInputDoc);
} catch (SolrException | SolrServerException | IOException e) {
logger.error("Error saving user config. solrDoc=" + solrInputDoc, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -133,12 +118,10 @@ public class UserConfigMgr extends MgrBase {
if (filterName != null && rowType != null) {
SolrQuery solrQuery = new SolrQuery();
filterName = solrUtil.makeSearcableString(filterName);
- solrQuery.setQuery(LogSearchConstants.COMPOSITE_KEY + ":" + filterName
- + "-" + rowType);
+ solrQuery.setQuery(LogSearchConstants.COMPOSITE_KEY + ":" + filterName + "-" + rowType);
queryGenerator.setRowCount(solrQuery, 0);
try {
- Long numFound = userConfigSolrDao.process(solrQuery).getResults()
- .getNumFound();
+ Long numFound = userConfigSolrDao.process(solrQuery).getResults().getNumFound();
if (numFound > 0) {
return true;
}
@@ -150,18 +133,17 @@ public class UserConfigMgr extends MgrBase {
}
private boolean isValid(VUserConfig vHistory) {
- return !stringUtil.isEmpty(vHistory.getFiltername())
- && !stringUtil.isEmpty(vHistory.getRowType())
- && !stringUtil.isEmpty(vHistory.getUserName())
- && !stringUtil.isEmpty(vHistory.getValues());
+ return !StringUtils.isBlank(vHistory.getFiltername())
+ && !StringUtils.isBlank(vHistory.getRowType())
+ && !StringUtils.isBlank(vHistory.getUserName())
+ && !StringUtils.isBlank(vHistory.getValues());
}
public void deleteUserConfig(String id) {
try {
userConfigSolrDao.deleteUserConfig(id);
} catch (SolrException | SolrServerException | IOException e) {
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -171,40 +153,31 @@ public class UserConfigMgr extends MgrBase {
SolrDocumentList solrList = new SolrDocumentList();
VUserConfigList userConfigList = new VUserConfigList();
- String rowType = (String) searchCriteria
- .getParamValue(LogSearchConstants.ROW_TYPE);
- if (stringUtil.isEmpty(rowType)) {
- throw restErrorUtil.createRESTException("row type was not specified",
- MessageEnums.INVALID_INPUT_DATA);
+ String rowType = (String) searchCriteria.getParamValue(LogSearchConstants.ROW_TYPE);
+ if (StringUtils.isBlank(rowType)) {
+ throw restErrorUtil.createRESTException("row type was not specified", MessageEnums.INVALID_INPUT_DATA);
}
- String userName = (String) searchCriteria
- .getParamValue(LogSearchConstants.USER_NAME);
- if (stringUtil.isEmpty(userName)) {
- throw restErrorUtil.createRESTException("user name was not specified",
- MessageEnums.INVALID_INPUT_DATA);
+ String userName = (String) searchCriteria.getParamValue(LogSearchConstants.USER_NAME);
+ if (StringUtils.isBlank(userName)) {
+ throw restErrorUtil.createRESTException("user name was not specified", MessageEnums.INVALID_INPUT_DATA);
}
- String filterName = (String) searchCriteria
- .getParamValue(LogSearchConstants.FILTER_NAME);
- filterName = stringUtil.isEmpty(filterName) ? "*" : "*" + filterName + "*";
+ String filterName = (String) searchCriteria.getParamValue(LogSearchConstants.FILTER_NAME);
+ filterName = StringUtils.isBlank(filterName) ? "*" : "*" + filterName + "*";
try {
SolrQuery userConfigQuery = new SolrQuery();
queryGenerator.setMainQuery(userConfigQuery, null);
queryGenerator.setPagination(userConfigQuery, searchCriteria);
- queryGenerator.setSingleIncludeFilter(userConfigQuery,
- LogSearchConstants.ROW_TYPE, rowType);
- queryGenerator.setSingleORFilter(userConfigQuery,
- LogSearchConstants.USER_NAME, userName,
- LogSearchConstants.SHARE_NAME_LIST, userName);
- queryGenerator.setSingleIncludeFilter(userConfigQuery,
- LogSearchConstants.FILTER_NAME, solrUtil.makeSearcableString(filterName));
-
- if (stringUtil.isEmpty(searchCriteria.getSortBy())) {
+ queryGenerator.setSingleIncludeFilter(userConfigQuery, LogSearchConstants.ROW_TYPE, rowType);
+ queryGenerator.setSingleORFilter(userConfigQuery, LogSearchConstants.USER_NAME, userName, LogSearchConstants.SHARE_NAME_LIST, userName);
+ queryGenerator.setSingleIncludeFilter(userConfigQuery, LogSearchConstants.FILTER_NAME, solrUtil.makeSearcableString(filterName));
+
+ if (StringUtils.isBlank(searchCriteria.getSortBy())) {
searchCriteria.setSortBy(LogSearchConstants.FILTER_NAME);
}
- if (stringUtil.isEmpty(searchCriteria.getSortType())) {
+ if (StringUtils.isBlank(searchCriteria.getSortType())) {
searchCriteria.setSortType("" + SolrQuery.ORDER.asc);
}
@@ -215,14 +188,12 @@ public class UserConfigMgr extends MgrBase {
for (SolrDocument solrDoc : solrList) {
VUserConfig userConfig = new VUserConfig();
- userConfig.setFiltername(""
- + solrDoc.get(LogSearchConstants.FILTER_NAME));
+ userConfig.setFiltername("" + solrDoc.get(LogSearchConstants.FILTER_NAME));
userConfig.setId("" + solrDoc.get(LogSearchConstants.ID));
userConfig.setValues("" + solrDoc.get(LogSearchConstants.VALUES));
userConfig.setRowType("" + solrDoc.get(LogSearchConstants.ROW_TYPE));
try {
- List<String> shareNameList = (List<String>) solrDoc
- .get(LogSearchConstants.SHARE_NAME_LIST);
+ List<String> shareNameList = (List<String>) solrDoc.get(LogSearchConstants.SHARE_NAME_LIST);
userConfig.setShareNameList(shareNameList);
} catch (Exception e) {
// do nothing
@@ -243,8 +214,7 @@ public class UserConfigMgr extends MgrBase {
} catch (SolrException | SolrServerException | IOException e) {
// do nothing
logger.error(e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
return convertObjToString(userConfigList);
@@ -255,43 +225,30 @@ public class UserConfigMgr extends MgrBase {
return saveUserConfig(vuserConfig);
}
- // ////////////////////////////LEVEL
- // FILTER/////////////////////////////////////
+ // ////////////////////////////LEVEL FILTER/////////////////////////////////////
- /**
- * @return
- */
public String getUserFilter() {
VLogfeederFilterWrapper userFilter;
try {
userFilter = userConfigSolrDao.getUserFilter();
} catch (SolrServerException | IOException e) {
logger.error(e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
return convertObjToString(userFilter);
}
- /**
- * Creating filter for logfeeder
- *
- * @param String
- * @return
- */
public String saveUserFiter(String json) {
- if (!stringUtil.isEmpty(json)) {
- VLogfeederFilterWrapper logfeederFilterWrapper = (VLogfeederFilterWrapper) jsonUtil
- .jsonToObj(json, VLogfeederFilterWrapper.class);
+ if (!StringUtils.isBlank(json)) {
+ VLogfeederFilterWrapper logfeederFilterWrapper = (VLogfeederFilterWrapper) jsonUtil.jsonToObj(json, VLogfeederFilterWrapper.class);
try {
if (logfeederFilterWrapper == null) {
logger.error(json + " is a invalid json");
}
- userConfigSolrDao.saveUserFiter(logfeederFilterWrapper);
+ userConfigSolrDao.saveUserFilter(logfeederFilterWrapper);
} catch (SolrException | SolrServerException | IOException e) {
logger.error("user config not able to save", e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
return getUserFilter();
@@ -307,20 +264,16 @@ public class UserConfigMgr extends MgrBase {
if (queryResponse == null) {
return convertObjToString(userList);
}
- List<Count> counList = queryResponse.getFacetField(
- LogSearchConstants.USER_NAME).getValues();
+ List<Count> counList = queryResponse.getFacetField(LogSearchConstants.USER_NAME).getValues();
for (Count cnt : counList) {
String userName = cnt.getName();
userList.add(userName);
}
} catch (SolrException | SolrServerException | IOException e) {
logger.warn("Error getting all users.", e);
- // do nothing
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
return convertObjToString(userList);
-
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGeneration.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGeneration.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGeneration.java
index d934e84..0c8be45 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGeneration.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGeneration.java
@@ -28,7 +28,7 @@ import java.util.regex.Pattern;
import org.apache.ambari.logsearch.common.LogSearchConstants;
import org.apache.ambari.logsearch.common.SearchCriteria;
import org.apache.ambari.logsearch.dao.SolrDaoBase;
-import org.apache.ambari.logsearch.manager.MgrBase.LOG_TYPE;
+import org.apache.ambari.logsearch.manager.MgrBase.LogType;
import org.apache.ambari.logsearch.util.ConfigUtil;
import org.apache.ambari.logsearch.util.PropertiesUtil;
import org.apache.commons.lang.StringUtils;
@@ -48,7 +48,7 @@ public class QueryGeneration extends QueryGenerationBase {
private static Logger logger = Logger.getLogger(QueryGeneration.class);
public SolrQuery commonServiceFilterQuery(SearchCriteria searchCriteria) {
- LOG_TYPE logType = LOG_TYPE.SERVICE;
+ LogType logType = LogType.SERVICE;
SolrQuery solrQuery = new SolrQuery();
String treeParams = (String) searchCriteria.getParamValue("treeParams");
String givenQuery = (String) searchCriteria.getParamValue("q");
@@ -59,19 +59,15 @@ public class QueryGeneration extends QueryGenerationBase {
String eMessage = (String) searchCriteria.getParamValue("eMessage");
String gEmessage = (String) searchCriteria.getParamValue("gEMessage");
String selectedComp = (String) searchCriteria.getParamValue("selectComp");
- String bundleId = (String) searchCriteria
- .getParamValue(LogSearchConstants.BUNDLE_ID);
- String globalExcludeComp = (String) searchCriteria
- .getParamValue("gMustNot");
- String unselectedComp = (String) searchCriteria
- .getParamValue("unselectComp");
+ String bundleId = (String) searchCriteria.getParamValue(LogSearchConstants.BUNDLE_ID);
+ String globalExcludeComp = (String) searchCriteria.getParamValue("gMustNot");
+ String unselectedComp = (String) searchCriteria.getParamValue("unselectComp");
String urlHostName = (String) searchCriteria.getParamValue("host_name");
- String urlComponentName = (String) searchCriteria
- .getParamValue("component_name");
+ String urlComponentName = (String) searchCriteria.getParamValue("component_name");
String file_name = (String) searchCriteria.getParamValue("file_name");
String advQuery = (String) searchCriteria.getParamValue("advanceSearch");
// build advance query
- if (!stringUtil.isEmpty(advQuery)) {
+ if (!StringUtils.isBlank(advQuery)) {
String advQueryParameters[] = advQuery.split(Pattern.quote("}{"));
SolrQuery advSolrQuery = new SolrQuery();
for (String queryParam : advQueryParameters) {
@@ -79,25 +75,13 @@ public class QueryGeneration extends QueryGenerationBase {
if (params != null && params.length > 1)
advSolrQuery.setParam(params[0], params[1]);
}
- // Building and adding levels to filters
- setFilterClauseWithFieldName(advSolrQuery, level,
- LogSearchConstants.SOLR_LEVEL, "", CONDITION.OR);
+ setFilterClauseWithFieldName(advSolrQuery, level, LogSearchConstants.SOLR_LEVEL, "", Condition.OR);
+ setSingleRangeFilter(advSolrQuery, LogSearchConstants.LOGTIME, startTime, endTime);
+ setFilterClauseWithFieldName(advSolrQuery, unselectedComp, LogSearchConstants.SOLR_COMPONENT, LogSearchConstants.MINUS_OPERATOR,
+ Condition.AND);
+ setFilterClauseWithFieldName(advSolrQuery, selectedComp, LogSearchConstants.SOLR_COMPONENT, LogSearchConstants.NO_OPERATOR,
+ Condition.OR);
- // Adding Logtime to filters
- setSingleRangeFilter(advSolrQuery, LogSearchConstants.LOGTIME, startTime,
- endTime);
-
- // Building and adding exlcude components to filters
- setFilterClauseWithFieldName(advSolrQuery, unselectedComp,
- LogSearchConstants.SOLR_COMPONENT, LogSearchConstants.MINUS_OPERATOR,
- CONDITION.AND);
-
- // Building and adding exlcude components to filters
- setFilterClauseWithFieldName(advSolrQuery, selectedComp,
- LogSearchConstants.SOLR_COMPONENT, LogSearchConstants.NO_OPERATOR,
- CONDITION.OR);
-
- // Set Pagination
setPagination(advSolrQuery, searchCriteria);
return advSolrQuery;
@@ -105,140 +89,71 @@ public class QueryGeneration extends QueryGenerationBase {
setMainQuery(solrQuery, givenQuery);
- // Adding Logtime to filters
- setSingleRangeFilter(solrQuery, LogSearchConstants.LOGTIME, startTime,
- endTime);
-
- // String mainFilterQuery = buildQueryFromJSONCompHost(jsonHCNames,
- // selectedComp);
-
- // if (mainFilterQuery != null && !mainFilterQuery.equals(""))
- // solrQuery.addFilterQuery(mainFilterQuery);
-
- // add component filter
- addFilter(solrQuery, selectedComp, LogSearchConstants.SOLR_COMPONENT,
- CONDITION.OR);
-
- // add treeParams filter
- // hosts comma separated list
- addFilterQueryFromArray(solrQuery, treeParams,
- LogSearchConstants.SOLR_HOST, CONDITION.OR);
-
- // Building and adding levels to filters
- setFilterClauseWithFieldName(solrQuery, level,
- LogSearchConstants.SOLR_LEVEL, LogSearchConstants.NO_OPERATOR,
- CONDITION.OR);
+ setSingleRangeFilter(solrQuery, LogSearchConstants.LOGTIME, startTime, endTime);
+ addFilter(solrQuery, selectedComp, LogSearchConstants.SOLR_COMPONENT, Condition.OR);
+ addFilterQueryFromArray(solrQuery, treeParams, LogSearchConstants.SOLR_HOST, Condition.OR);
- // Building and adding include string to filters
- setFilterClauseForSolrSearchableString(solrQuery, iMessage, CONDITION.OR,
- LogSearchConstants.NO_OPERATOR, LogSearchConstants.SOLR_KEY_LOG_MESSAGE);
+ setFilterClauseWithFieldName(solrQuery, level, LogSearchConstants.SOLR_LEVEL, LogSearchConstants.NO_OPERATOR, Condition.OR);
- // Building and adding global exclude string to filters
- setFilterClauseForSolrSearchableString(solrQuery, gEmessage, CONDITION.AND,
- LogSearchConstants.MINUS_OPERATOR, LogSearchConstants.SOLR_KEY_LOG_MESSAGE);
+ setFilterClauseForSolrSearchableString(solrQuery, iMessage, Condition.OR, LogSearchConstants.NO_OPERATOR, LogSearchConstants.SOLR_KEY_LOG_MESSAGE);
+ setFilterClauseForSolrSearchableString(solrQuery, gEmessage, Condition.AND, LogSearchConstants.MINUS_OPERATOR, LogSearchConstants.SOLR_KEY_LOG_MESSAGE);
+ setFilterClauseForSolrSearchableString(solrQuery, eMessage, Condition.AND, LogSearchConstants.MINUS_OPERATOR, LogSearchConstants.SOLR_KEY_LOG_MESSAGE);
- // Building and adding exclude string to filter
- setFilterClauseForSolrSearchableString(solrQuery, eMessage, CONDITION.AND,
- LogSearchConstants.MINUS_OPERATOR, LogSearchConstants.SOLR_KEY_LOG_MESSAGE);
-
- // Building and adding logfile to filters
applyLogFileFilter(solrQuery, searchCriteria);
- // Building and adding exclude components to filters
- setFilterClauseWithFieldName(solrQuery, globalExcludeComp,
- LogSearchConstants.SOLR_COMPONENT, LogSearchConstants.MINUS_OPERATOR,
- CONDITION.AND);
-
- // Building and adding exlcude components to filters
- setFilterClauseWithFieldName(solrQuery, unselectedComp,
- LogSearchConstants.SOLR_COMPONENT, LogSearchConstants.MINUS_OPERATOR,
- CONDITION.AND);
+ setFilterClauseWithFieldName(solrQuery, globalExcludeComp, LogSearchConstants.SOLR_COMPONENT, LogSearchConstants.MINUS_OPERATOR, Condition.AND);
+ setFilterClauseWithFieldName(solrQuery, unselectedComp, LogSearchConstants.SOLR_COMPONENT, LogSearchConstants.MINUS_OPERATOR, Condition.AND);
- // Building and adding host names given url
- // setFilterClauseWithFieldName(solrQuery, urlHostName,
- // LogSearchConstants.SOLR_HOST,
- // "", "OR");
urlHostName = solrUtil.escapeQueryChars(urlHostName);
setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_HOST, urlHostName);
- //
- // //Building and addding component names given url
- // setFilterClauseWithFieldName(solrQuery, urlComponents,
- // LogSearchConstants.SOLR_COMPONENT,
- // "", "OR");
urlComponentName = solrUtil.escapeQueryChars(urlComponentName);
- setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_COMPONENT,
- urlComponentName);
+ setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_COMPONENT, urlComponentName);
- // Set Pagination
setPagination(solrQuery, searchCriteria);
-
- // SetSort type (by default Descending)
setSortOrderDefaultServiceLog(solrQuery, searchCriteria);
-
- // Set Bundle Id
setSingleIncludeFilter(solrQuery, LogSearchConstants.BUNDLE_ID, bundleId);
-
- // Set filename
file_name = solrUtil.escapeQueryChars(file_name);
setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_PATH, file_name);
- // include query
- this.setUserSpecificFilter(searchCriteria, solrQuery,
- LogSearchConstants.INCLUDE_QUERY, LogSearchConstants.INCLUDE_QUERY,
- logType);
- // exclude query
- this.setUserSpecificFilter(searchCriteria, solrQuery,
- LogSearchConstants.EXCLUDE_QUERY, LogSearchConstants.EXCLUDE_QUERY,
- logType);
+ setUserSpecificFilter(searchCriteria, solrQuery, LogSearchConstants.INCLUDE_QUERY, LogSearchConstants.INCLUDE_QUERY, logType);
+ setUserSpecificFilter(searchCriteria, solrQuery, LogSearchConstants.EXCLUDE_QUERY, LogSearchConstants.EXCLUDE_QUERY, logType);
+
return solrQuery;
}
- public void applyLogFileFilter(SolrQuery solrQuery,
- SearchCriteria searchCriteria) {
+ public void applyLogFileFilter(SolrQuery solrQuery, SearchCriteria searchCriteria) {
String hostLogFile = (String) searchCriteria.getParamValue("hostLogFile");
String compLogFile = (String) searchCriteria.getParamValue("compLogFile");
String givenQuery = (String) searchCriteria.getParamValue("q");
String logfileQuery = "";
- if (!stringUtil.isEmpty(hostLogFile) && !stringUtil.isEmpty(compLogFile)) {
- logfileQuery = LogSearchConstants.SOLR_HOST + ":" + hostLogFile + " "
- + CONDITION.AND + " " + LogSearchConstants.SOLR_COMPONENT + ":"
- + compLogFile;
- if (!stringUtil.isEmpty(givenQuery)) {
- logfileQuery = "(" + givenQuery + ") " + CONDITION.AND + " ("
- + logfileQuery + ")";
+ if (!StringUtils.isBlank(hostLogFile) && !StringUtils.isBlank(compLogFile)) {
+ logfileQuery = LogSearchConstants.SOLR_HOST + ":" + hostLogFile + " " + Condition.AND + " " +
+ LogSearchConstants.SOLR_COMPONENT + ":" + compLogFile;
+ if (!StringUtils.isBlank(givenQuery)) {
+ logfileQuery = "(" + givenQuery + ") " + Condition.AND + " (" + logfileQuery + ")";
}
- if (!stringUtil.isEmpty(logfileQuery)) {
+ if (!StringUtils.isBlank(logfileQuery)) {
solrQuery.addFilterQuery(logfileQuery);
}
}
}
- public void setUserSpecificFilter(SearchCriteria searchCriteria,
- SolrQuery solrQuery, String paramName, String operation, LOG_TYPE logType) {
+ private void setUserSpecificFilter(SearchCriteria searchCriteria, SolrQuery solrQuery, String paramName, String operation,
+ LogType logType) {
String queryString = (String) searchCriteria.getParamValue(paramName);
- String columnQuery = (String) searchCriteria
- .getParamValue(LogSearchConstants.COLUMN_QUERY);
- if (stringUtil.isEmpty(queryString)) {
+ String columnQuery = (String) searchCriteria.getParamValue(LogSearchConstants.COLUMN_QUERY);
+ if (StringUtils.isBlank(queryString)) {
queryString = null;
}
- // if (!stringUtil.isEmpty(queryString) && "[]".equals(queryString)) {
- // queryString = null;
- // }
- if (!stringUtil.isEmpty(columnQuery) && stringUtil.isEmpty(queryString)
- && !paramName.equals(LogSearchConstants.EXCLUDE_QUERY)) {
+ if (!StringUtils.isBlank(columnQuery) && StringUtils.isBlank(queryString) && !paramName.equals(LogSearchConstants.EXCLUDE_QUERY)) {
queryString = columnQuery;
}
List<String> conditionQuries = new ArrayList<String>();
List<String> referalConditionQuries = new ArrayList<String>();
List<String> elments = new ArrayList<String>();
- // convert json to list of hashmap
- List<HashMap<String, Object>> queryList = jsonUtil
- .jsonToMapObjectList(queryString);
- // null and size check
+ List<HashMap<String, Object>> queryList = jsonUtil.jsonToMapObjectList(queryString);
if (queryList != null && queryList.size() > 0) {
- if (!stringUtil.isEmpty(columnQuery) && !columnQuery.equals(queryString)
- && !paramName.equals(LogSearchConstants.EXCLUDE_QUERY)) {
- List<HashMap<String, Object>> columnQueryList = jsonUtil
- .jsonToMapObjectList(columnQuery);
+ if (!StringUtils.isBlank(columnQuery) && !columnQuery.equals(queryString) && !paramName.equals(LogSearchConstants.EXCLUDE_QUERY)) {
+ List<HashMap<String, Object>> columnQueryList = jsonUtil.jsonToMapObjectList(columnQuery);
if (columnQueryList != null && columnQueryList.size() > 0) {
queryList.addAll(columnQueryList);
}
@@ -248,12 +163,11 @@ public class QueryGeneration extends QueryGenerationBase {
StringBuilder field = new StringBuilder();
if (columnListMap != null) {
for (String key : columnListMap.keySet()) {
- if (!stringUtil.isEmpty(key)) {
+ if (!StringUtils.isBlank(key)) {
String originalKey = getOriginalKey(key, logType);
- String value = getOriginalValue(originalKey,
- "" + columnListMap.get(key));
+ String value = getOriginalValue(originalKey, "" + columnListMap.get(key));
orQuery = putWildCardByType(value, originalKey, logType);
- if (stringUtil.isEmpty(orQuery)) {
+ if (StringUtils.isBlank(orQuery)) {
logger.debug("Removing invalid filter for key :"+originalKey +" and value :" +value );
continue;
}
@@ -264,8 +178,7 @@ public class QueryGeneration extends QueryGenerationBase {
if (isSame && !operation.equals(LogSearchConstants.EXCLUDE_QUERY)) {
for (String tempCondition : conditionQuries) {
if (tempCondition.contains(originalKey)) {
- String newCondtion = tempCondition + " "
- + CONDITION.OR.name() + " " + orQuery;
+ String newCondtion = tempCondition + " " + Condition.OR.name() + " " + orQuery;
referalConditionQuries.remove(tempCondition);
referalConditionQuries.add(newCondtion);
}
@@ -283,17 +196,16 @@ public class QueryGeneration extends QueryGenerationBase {
}
}
}
- if (!referalConditionQuries.isEmpty() && !stringUtil.isEmpty(operation)) {
- if (operation.equals(LogSearchConstants.INCLUDE_QUERY)
- || operation.equals(LogSearchConstants.COLUMN_QUERY)) {
+ if (!referalConditionQuries.isEmpty() && !StringUtils.isBlank(operation)) {
+ if (operation.equals(LogSearchConstants.INCLUDE_QUERY) || operation.equals(LogSearchConstants.COLUMN_QUERY)) {
for (String filter : referalConditionQuries) {
- if (!stringUtil.isEmpty(filter)) {
+ if (!StringUtils.isBlank(filter)) {
solrQuery.addFilterQuery(filter);
}
}
} else if (operation.equals(LogSearchConstants.EXCLUDE_QUERY)) {
for (String filter : referalConditionQuries) {
- if (!stringUtil.isEmpty(filter)) {
+ if (!StringUtils.isBlank(filter)) {
filter = LogSearchConstants.MINUS_OPERATOR + filter;
solrQuery.addFilterQuery(filter);
}
@@ -303,40 +215,23 @@ public class QueryGeneration extends QueryGenerationBase {
}
public SolrQuery commonAuditFilterQuery(SearchCriteria searchCriteria) {
- LOG_TYPE logType = LOG_TYPE.AUDIT;
+ LogType logType = LogType.AUDIT;
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery("*:*");
String startTime = (String) searchCriteria.getParamValue("startTime");
String endTime = (String) searchCriteria.getParamValue("endTime");
- String selectedComp = (String) searchCriteria
- .getParamValue("includeString");
- this.setFilterClauseWithFieldName(solrQuery, selectedComp,
- LogSearchConstants.AUDIT_COMPONENT, LogSearchConstants.NO_OPERATOR,
- CONDITION.OR);
- String globalExcludeComp = (String) searchCriteria
- .getParamValue("gMustNot");
- this.setUserSpecificFilter(searchCriteria, solrQuery,
- LogSearchConstants.INCLUDE_QUERY, LogSearchConstants.INCLUDE_QUERY,
- logType);
- this.setUserSpecificFilter(searchCriteria, solrQuery,
- LogSearchConstants.EXCLUDE_QUERY, LogSearchConstants.EXCLUDE_QUERY,
- logType);
- String unselectedComp = (String) searchCriteria
- .getParamValue("unselectComp");
- this.setFilterClauseWithFieldName(solrQuery, globalExcludeComp,
- LogSearchConstants.AUDIT_COMPONENT, LogSearchConstants.MINUS_OPERATOR,
- CONDITION.AND);
- // Building and adding exlcude components to filters
- this.setFilterClauseWithFieldName(solrQuery, unselectedComp,
- LogSearchConstants.AUDIT_COMPONENT, LogSearchConstants.MINUS_OPERATOR,
- CONDITION.AND);
- // Adding Logtime to filters
- this.setSingleRangeFilter(solrQuery, LogSearchConstants.AUDIT_EVTTIME,
- startTime, endTime);
- this.setPagination(solrQuery, searchCriteria);
+ String selectedComp = (String) searchCriteria.getParamValue("includeString");
+ setFilterClauseWithFieldName(solrQuery, selectedComp, LogSearchConstants.AUDIT_COMPONENT, LogSearchConstants.NO_OPERATOR, Condition.OR);
+ String globalExcludeComp = (String) searchCriteria.getParamValue("gMustNot");
+ setUserSpecificFilter(searchCriteria, solrQuery, LogSearchConstants.INCLUDE_QUERY, LogSearchConstants.INCLUDE_QUERY, logType);
+ setUserSpecificFilter(searchCriteria, solrQuery, LogSearchConstants.EXCLUDE_QUERY, LogSearchConstants.EXCLUDE_QUERY, logType);
+ String unselectedComp = (String) searchCriteria.getParamValue("unselectComp");
+ setFilterClauseWithFieldName(solrQuery, globalExcludeComp, LogSearchConstants.AUDIT_COMPONENT, LogSearchConstants.MINUS_OPERATOR, Condition.AND);
+ setFilterClauseWithFieldName(solrQuery, unselectedComp, LogSearchConstants.AUDIT_COMPONENT, LogSearchConstants.MINUS_OPERATOR, Condition.AND);
+ setSingleRangeFilter(solrQuery, LogSearchConstants.AUDIT_EVTTIME, startTime, endTime);
+ setPagination(solrQuery, searchCriteria);
try {
- if (searchCriteria.getSortBy() == null
- || searchCriteria.getSortBy().isEmpty()) {
+ if (searchCriteria.getSortBy() == null || searchCriteria.getSortBy().isEmpty()) {
searchCriteria.setSortBy(LogSearchConstants.AUDIT_EVTTIME);
searchCriteria.setSortType(SolrQuery.ORDER.desc.toString());
}
@@ -344,11 +239,11 @@ public class QueryGeneration extends QueryGenerationBase {
searchCriteria.setSortBy(LogSearchConstants.AUDIT_EVTTIME);
searchCriteria.setSortType(SolrQuery.ORDER.desc.toString());
}
- this.setSortOrderDefaultServiceLog(solrQuery, searchCriteria);
+ setSortOrderDefaultServiceLog(solrQuery, searchCriteria);
return solrQuery;
}
- private String putWildCardByType(String str, String key, LOG_TYPE logType) {
+ private String putWildCardByType(String str, String key, LogType logType) {
String fieldType;
SolrDaoBase solrDaoBase = null;
switch (logType) {
@@ -368,10 +263,10 @@ public class QueryGeneration extends QueryGenerationBase {
logger.error("Invalid logtype :" + logType);
fieldType = null;
}
- if (!stringUtil.isEmpty(fieldType)) {
+ if (!StringUtils.isBlank(fieldType)) {
if (solrUtil.isSolrFieldNumber(fieldType, solrDaoBase)) {
String value = putEscapeCharacterForNumber(str, fieldType,solrDaoBase);
- if (!stringUtil.isEmpty(value)) {
+ if (!StringUtils.isBlank(value)) {
return key + ":" + value;
} else {
return null;
@@ -388,7 +283,7 @@ public class QueryGeneration extends QueryGenerationBase {
}
private String putEscapeCharacterForNumber(String str,String fieldType,SolrDaoBase solrDaoBase) {
- if (!stringUtil.isEmpty(str)) {
+ if (!StringUtils.isBlank(str)) {
str = str.replace("*", "");
}
String escapeCharSting = parseInputValueAsPerFieldType(str,fieldType,solrDaoBase);
@@ -420,28 +315,25 @@ public class QueryGeneration extends QueryGenerationBase {
private String getOriginalValue(String name, String value) {
String solrValue = PropertiesUtil.getProperty(name);
- if (stringUtil.isEmpty(solrValue)) {
+ if (StringUtils.isBlank(solrValue)) {
return value;
}
try {
- String propertyFieldMappings[] = solrValue
- .split(LogSearchConstants.LIST_SEPARATOR);
+ String propertyFieldMappings[] = solrValue.split(LogSearchConstants.LIST_SEPARATOR);
if (propertyFieldMappings != null && propertyFieldMappings.length > 0) {
HashMap<String, String> propertyFieldValue = new HashMap<String, String>();
for (String temp : propertyFieldMappings) {
- if (!stringUtil.isEmpty(temp)) {
+ if (!StringUtils.isBlank(temp)) {
String arrayValue[] = temp.split(":");
if (arrayValue.length > 1) {
- propertyFieldValue.put(arrayValue[0].toLowerCase(Locale.ENGLISH),
- arrayValue[1].toLowerCase(Locale.ENGLISH));
+ propertyFieldValue.put(arrayValue[0].toLowerCase(Locale.ENGLISH), arrayValue[1].toLowerCase(Locale.ENGLISH));
} else {
logger.warn("array length is less than required length 1");
}
}
}
- String originalValue = propertyFieldValue.get(value
- .toLowerCase(Locale.ENGLISH));
- if (!stringUtil.isEmpty(originalValue)) {
+ String originalValue = propertyFieldValue.get(value.toLowerCase(Locale.ENGLISH));
+ if (!StringUtils.isBlank(originalValue)) {
return originalValue;
}
}
@@ -451,35 +343,29 @@ public class QueryGeneration extends QueryGenerationBase {
return value;
}
- private String getOriginalKey(String key, LOG_TYPE logType) {
+ private String getOriginalKey(String key, LogType logType) {
String originalKey;
switch (logType) {
case AUDIT:
- originalKey = ConfigUtil.auditLogsColumnMapping.get(key
- + LogSearchConstants.UI_SUFFIX);
+ originalKey = ConfigUtil.auditLogsColumnMapping.get(key + LogSearchConstants.UI_SUFFIX);
break;
case SERVICE:
- originalKey = ConfigUtil.serviceLogsColumnMapping.get(key
- + LogSearchConstants.UI_SUFFIX);
+ originalKey = ConfigUtil.serviceLogsColumnMapping.get(key + LogSearchConstants.UI_SUFFIX);
break;
default:
originalKey = null;
- // set as null
}
- if (stringUtil.isEmpty(originalKey)) {
- // return default values
+ if (StringUtils.isBlank(originalKey)) {
return key;
}
return originalKey;
}
- public boolean checkTokenizer(String fieldType,Class tokenizerFactoryClass,SolrDaoBase solrDaoBase) {
+ private boolean checkTokenizer(String fieldType, Class tokenizerFactoryClass, SolrDaoBase solrDaoBase) {
HashMap<String, Object> fieldTypeMap = solrUtil.getFieldTypeInfoMap(fieldType,solrDaoBase);
- HashMap<String, Object> analyzer = (HashMap<String, Object>) fieldTypeMap
- .get("analyzer");
+ HashMap<String, Object> analyzer = (HashMap<String, Object>) fieldTypeMap.get("analyzer");
if (analyzer != null) {
- HashMap<String, Object> tokenizerMap = (HashMap<String, Object>) analyzer
- .get("tokenizer");
+ HashMap<String, Object> tokenizerMap = (HashMap<String, Object>) analyzer.get("tokenizer");
if (tokenizerMap != null) {
String tokenizerClass = (String) tokenizerMap.get("class");
if (!StringUtils.isEmpty(tokenizerClass)) {
@@ -493,4 +379,4 @@ public class QueryGeneration extends QueryGenerationBase {
}
return false;
}
-}
\ No newline at end of file
+}
[4/5] ambari git commit: AMBARI-18227. Add unit tests for Log Search
components and refactor them as needed - Vol 1. (Miklos Gergely via oleewere)
Posted by ol...@apache.org.
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
index e612475..a0c1134 100644
--- 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
@@ -21,6 +21,7 @@ package org.apache.ambari.logsearch.dao;
import java.io.File;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
@@ -40,46 +41,40 @@ import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import com.google.gson.JsonParseException;
-import org.apache.ambari.logsearch.manager.MgrBase.LOG_TYPE;
+import org.apache.ambari.logsearch.manager.MgrBase.LogType;
import org.apache.ambari.logsearch.util.PropertiesUtil;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
@Component
public class UserConfigSolrDao extends SolrDaoBase {
- static private Logger logger = Logger.getLogger(UserConfigSolrDao.class);
+ private static final Logger logger = Logger.getLogger(UserConfigSolrDao.class);
private static final String DEFAULT_LEVELS = "FATAL,ERROR,WARN,INFO,DEBUG,TRACE";
public UserConfigSolrDao() {
- super(LOG_TYPE.SERVICE);
+ super(LogType.SERVICE);
}
@PostConstruct
public void postConstructor() {
-
String solrUrl = PropertiesUtil.getProperty("logsearch.solr.url");
String zkConnectString = PropertiesUtil.getProperty("logsearch.solr.zk_connect_string");
- String collection = PropertiesUtil.getProperty("logsearch.solr.collection.history",
- "history");
- String configName = PropertiesUtil.getProperty(
- "logsearch.solr.history.config.name", "history");
- int replicationFactor = PropertiesUtil.getIntProperty(
- "logsearch.collection.history.replication.factor", 2);
+ String collection = PropertiesUtil.getProperty("logsearch.solr.collection.history", "history");
+ String configName = PropertiesUtil.getProperty("logsearch.solr.history.config.name", "history");
+ int replicationFactor = PropertiesUtil.getIntProperty("logsearch.collection.history.replication.factor", 2);
String splitInterval = "none";
int numberOfShards = 1;
try {
connectToSolr(solrUrl, zkConnectString, collection);
- setupCollections(splitInterval, configName, numberOfShards,
- replicationFactor,true);
+ setupCollections(splitInterval, configName, numberOfShards, replicationFactor, true);
intializeLogFeederFilter();
} catch (Exception e) {
- logger.error(
- "error while connecting to Solr for history logs : solrUrl="
- + solrUrl + ", zkConnectString=" + zkConnectString
- + ", collection=" + collection, e);
+ logger.error("error while connecting to Solr for history logs : solrUrl=" + solrUrl + ", zkConnectString=" + zkConnectString +
+ ", collection=" + collection, e);
}
}
@@ -91,8 +86,7 @@ public class UserConfigSolrDao extends SolrDaoBase {
}
}
- public void saveUserFiter(VLogfeederFilterWrapper logfeederFilterWrapper) throws SolrException,
- SolrServerException, IOException {
+ public void saveUserFilter(VLogfeederFilterWrapper logfeederFilterWrapper) throws SolrException, SolrServerException, IOException {
String filterName = LogSearchConstants.LOGFEEDER_FILTER_NAME;
String json = jsonUtil.objToJson(logfeederFilterWrapper);
SolrInputDocument configDocument = new SolrInputDocument();
@@ -104,47 +98,32 @@ public class UserConfigSolrDao extends SolrDaoBase {
addDocs(configDocument);
}
- public void deleteUserConfig(String id) throws SolrException,
- SolrServerException, IOException {
+ public void deleteUserConfig(String id) throws SolrException, SolrServerException, IOException {
removeDoc("id:" + id);
}
@SuppressWarnings("unchecked")
- public VLogfeederFilterWrapper getUserFilter() throws SolrServerException,
- IOException {
+ public VLogfeederFilterWrapper getUserFilter() throws SolrServerException, IOException {
- String filterName = LogSearchConstants.LOGFEEDER_FILTER_NAME;
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery("*:*");
- String fq = LogSearchConstants.ROW_TYPE + ":" + filterName;
+ String fq = LogSearchConstants.ROW_TYPE + ":" + LogSearchConstants.LOGFEEDER_FILTER_NAME;
solrQuery.setFilterQueries(fq);
QueryResponse response = process(solrQuery);
SolrDocumentList documentList = response.getResults();
VLogfeederFilterWrapper logfeederFilterWrapper = null;
- if (documentList != null && documentList.size() > 0) {
+ if (!CollectionUtils.isEmpty(documentList)) {
SolrDocument configDoc = documentList.get(0);
String configJson = jsonUtil.objToJson(configDoc);
- HashMap<String, Object> configMap = (HashMap<String, Object>) jsonUtil
- .jsonToMapObject(configJson);
+ HashMap<String, Object> configMap = (HashMap<String, Object>) jsonUtil.jsonToMapObject(configJson);
String json = (String) configMap.get(LogSearchConstants.VALUES);
- logfeederFilterWrapper = (VLogfeederFilterWrapper) jsonUtil.jsonToObj(
- json, VLogfeederFilterWrapper.class);
+ logfeederFilterWrapper = (VLogfeederFilterWrapper) jsonUtil.jsonToObj(json, VLogfeederFilterWrapper.class);
logfeederFilterWrapper.setId("" + configDoc.get(LogSearchConstants.ID));
} else {
- String logfeederDefaultLevels = PropertiesUtil.getProperty(
- "logsearch.logfeeder.include.default.level", DEFAULT_LEVELS);
- JSONArray levelJsonArray = new JSONArray();
- try {
- String levelArray[] = logfeederDefaultLevels.split(",");
- for (String level : levelArray) {
- levelJsonArray.put(level.toUpperCase());
- }
- } catch (Exception e) {
- logger.error("Error spliting logfeederDefaultLevels="
- + logfeederDefaultLevels, e);
- }
+ String logfeederDefaultLevels = PropertiesUtil.getProperty("logsearch.logfeeder.include.default.level", DEFAULT_LEVELS);
+ JSONArray levelJsonArray = new JSONArray(Arrays.asList(logfeederDefaultLevels.split(",")));
String hadoopServiceString = getHadoopServiceConfigJSON();
String key = null;
@@ -153,13 +132,11 @@ public class UserConfigSolrDao extends SolrDaoBase {
JSONObject componentList = new JSONObject();
JSONObject jsonValue = new JSONObject();
- JSONObject hadoopServiceJsonObject = new JSONObject(hadoopServiceString)
- .getJSONObject("service");
+ JSONObject hadoopServiceJsonObject = new JSONObject(hadoopServiceString).getJSONObject("service");
Iterator<String> hadoopSerivceKeys = hadoopServiceJsonObject.keys();
while (hadoopSerivceKeys.hasNext()) {
key = hadoopSerivceKeys.next();
- componentArray = hadoopServiceJsonObject.getJSONObject(key)
- .getJSONArray("components");
+ componentArray = hadoopServiceJsonObject.getJSONObject(key).getJSONArray("components");
for (int i = 0; i < componentArray.length(); i++) {
JSONObject compJsonObject = (JSONObject) componentArray.get(i);
String componentName = compJsonObject.getString("name");
@@ -171,27 +148,24 @@ public class UserConfigSolrDao extends SolrDaoBase {
}
}
jsonValue.put("filter", componentList);
- logfeederFilterWrapper = (VLogfeederFilterWrapper) jsonUtil
- .jsonToObj(jsonValue.toString(), VLogfeederFilterWrapper.class);
+ logfeederFilterWrapper = (VLogfeederFilterWrapper) jsonUtil.jsonToObj(jsonValue.toString(), VLogfeederFilterWrapper.class);
logfeederFilterWrapper.setId(""+new Date().getTime());
- saveUserFiter(logfeederFilterWrapper);
+ saveUserFilter(logfeederFilterWrapper);
} catch (JsonParseException | JSONException je) {
- logger.error("Error parsing JSON. key=" + key + ", componentArray="
- + componentArray, je);
+ logger.error("Error parsing JSON. key=" + key + ", componentArray=" + componentArray, je);
logfeederFilterWrapper = new VLogfeederFilterWrapper();
}
}
return logfeederFilterWrapper;
}
- public String getHadoopServiceConfigJSON() {
+ private String getHadoopServiceConfigJSON() {
StringBuilder result = new StringBuilder("");
// Get file from resources folder
ClassLoader classLoader = getClass().getClassLoader();
- File file = new File(classLoader.getResource("HadoopServiceConfig.json")
- .getFile());
+ File file = new File(classLoader.getResource("HadoopServiceConfig.json").getFile());
try (Scanner scanner = new Scanner(file)) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
index 6b2f049..b7853df 100644
--- 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
@@ -20,46 +20,43 @@ package org.apache.ambari.logsearch.dao;
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
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.CommonUtil;
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.commons.lang.StringUtils;
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;
+ private static final String USER_NAME = "username";
+ private static final String PASSWORD = "password";
+ private static final String ENC_PASSWORD = "en_password";
+ private static final String NAME = "name";
@Autowired
- StringUtil stringUtil;
-
+ private JSONUtil jsonUtil;
@Autowired
- FileUtil fileUtil;
-
+ private FileUtil fileUtil;
@Autowired
- LogsearchFileAuthenticationProvider fileAuthenticationProvider;
-
- private HashMap<String, Object> userInfos = null;
+ private LogsearchFileAuthenticationProvider fileAuthenticationProvider;
private ArrayList<HashMap<String, String>> userList = null;
@@ -68,23 +65,17 @@ public class UserDao {
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);
+ String userPassJsonFileName = PropertiesUtil.getProperty("logsearch.login.credentials.file");
+ logger.info("USER PASS JSON file NAME:" + userPassJsonFileName);
+ File jsonFile = fileUtil.getFileFromClasspath(userPassJsonFileName);
if (jsonFile == null || !jsonFile.exists()) {
- logger.fatal("user_pass json file not found in classpath :"
- + USER_PASS_JSON_FILE_NAME);
+ logger.fatal("user_pass json file not found in classpath :" + userPassJsonFileName);
System.exit(1);
}
- userInfos = jsonUtil.readJsonFromFile(jsonFile);
- userList = (ArrayList<HashMap<String, String>>) userInfos
- .get("users");
+ HashMap<String, Object> 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);
@@ -95,108 +86,78 @@ public class UserDao {
}
} catch (Exception exception) {
- logger.error("Error while reading user prop file :"
- + exception.getMessage());
- userInfos = new HashMap<String, Object>();
+ logger.error("Error while reading user prop file :" + exception.getMessage());
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);
+ HashMap<String, String> userInfo = 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) : "");
+ user.setFirstName(userInfo.get(NAME) != null ? userInfo.get(NAME) : "Unknown");
+ user.setLastName(userInfo.get(NAME) != null ? userInfo.get(NAME) : "Unknown");
+ user.setUsername(userInfo.get(USER_NAME) != null ? userInfo.get(USER_NAME) : "");
+ user.setPassword(userInfo.get(ENC_PASSWORD) != null ? userInfo.get(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);
+ r.setPrivileges(Arrays.asList(priv));
+ user.setAuthorities(Arrays.asList((GrantedAuthority)r));
+
return user;
}
- /**
- * @param username
- * @return
- */
- public HashMap<String, Object> findByusername(final String username) {
- if (this.userList == null) {
+ private HashMap<String, String> findByusername(final String username) {
+ if (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);
+ HashMap<String, String> userInfo = (HashMap<String, String>) CollectionUtils.find(userList,
+ new Predicate() {
+ @Override
+ public boolean evaluate(Object args) {
+ HashMap<String, String> tmpUserInfo = (HashMap<String, String>) args;
+ String objUsername = tmpUserInfo.get(USER_NAME);
+ return (objUsername != null && username != null && 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);
+ String encPassword = user.get(ENC_PASSWORD);
+ String username = user.get(USER_NAME);
+ String password = user.get(PASSWORD);
+ if (!StringUtils.isBlank(password)) {
+ encPassword = CommonUtil.encryptPassword(username, password);
+ user.put(PASSWORD, "");
+ user.put(ENC_PASSWORD, encPassword);
isUpdated = true;
}
- if (stringUtil.isEmpty(password) && stringUtil.isEmpty(encPassword)) {
- // log error
- logger.error("Password is empty or null for username : "
- + username);
+ if (StringUtils.isBlank(password) && StringUtils.isBlank(encPassword)) {
+ logger.error("Password is empty or null for username : " + username);
}
}
return isUpdated;
}
-
- /**
- * @param username
- * @param password
- * @return
- */
+
public String encryptPassword(String username, String password) {
- if (!stringUtil.isEmpty(username)) {
+ if (!StringUtils.isEmpty(username)) {
username = username.toLowerCase();
}
- String saltEncodedpasswd = md5Encoder
- .encodePassword(password, username);
+ String saltEncodedpasswd = CommonUtil.encryptPassword(password, username);
return saltEncodedpasswd;
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
deleted file mode 100644
index 7bc3555..0000000
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/UserInfoAttributes.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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";
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGenerator.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGenerator.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGenerator.java
index d3975b3..3793f50 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGenerator.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGenerator.java
@@ -29,14 +29,12 @@ import org.apache.ambari.logsearch.common.MessageEnums;
import org.apache.ambari.logsearch.common.SearchCriteria;
import org.apache.ambari.logsearch.dao.SolrDaoBase;
import org.apache.ambari.logsearch.query.QueryGeneration;
-import org.apache.ambari.logsearch.util.ConfigUtil;
-import org.apache.ambari.logsearch.util.DateUtil;
import org.apache.ambari.logsearch.util.RESTErrorUtil;
import org.apache.ambari.logsearch.util.SolrUtil;
-import org.apache.ambari.logsearch.util.StringUtil;
import org.apache.ambari.logsearch.view.VBarDataList;
import org.apache.ambari.logsearch.view.VBarGraphData;
import org.apache.ambari.logsearch.view.VNameValue;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
@@ -46,7 +44,6 @@ import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.RangeFacet;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.SimpleOrderedMap;
-import org.apache.solr.schema.TextField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -55,32 +52,16 @@ import org.springframework.stereotype.Component;
@Component
public class GraphDataGenerator extends GraphDataGeneratorBase {
- @Autowired
- StringUtil stringUtil;
+ private static final Logger logger = Logger.getLogger(GraphDataGenerator.class);
@Autowired
- QueryGeneration queryGenerator;
-
+ private QueryGeneration queryGenerator;
@Autowired
- RESTErrorUtil restErrorUtil;
-
+ private RESTErrorUtil restErrorUtil;
@Autowired
- DateUtil dateUtil;
-
- @Autowired
- SolrUtil solrUtil;
-
- private static Logger logger = Logger.getLogger(GraphDataGenerator.class);
+ private SolrUtil solrUtil;
- /**
- *
- * @param searchCriteria
- * @param solrDaoBase
- * @param solrQuery
- * @return
- */
- public VBarDataList getAnyGraphData(SearchCriteria searchCriteria,
- SolrDaoBase solrDaoBase, SolrQuery solrQuery) {
+ public VBarDataList getAnyGraphData(SearchCriteria searchCriteria, SolrDaoBase solrDaoBase, SolrQuery solrQuery) {
// X axis credentials
String xAxisField = (String) searchCriteria.getParamValue("xAxis");
String stackField = (String) searchCriteria.getParamValue("stackBy");
@@ -88,7 +69,7 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
String to = (String) searchCriteria.getParamValue("to");
String unit = (String) searchCriteria.getParamValue("unit");
String typeXAxis = solrDaoBase.schemaFieldsNameMap.get(xAxisField);
- typeXAxis = (stringUtil.isEmpty(typeXAxis)) ? "string" : typeXAxis;
+ typeXAxis = (StringUtils.isBlank(typeXAxis)) ? "string" : typeXAxis;
// Y axis credentials
String yAxisField = (String) searchCriteria.getParamValue("yAxis");
@@ -96,17 +77,14 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
searchCriteria.addParam("type", typeXAxis);
String fieldTime = (String) searchCriteria.getParamValue("fieldTime");
// decide graph type based on user request parameter
- GRAPH_TYPE garphType = getGraphType(searchCriteria);
+ GraphType garphType = getGraphType(searchCriteria);
switch (garphType) {
case NORMAL_GRAPH:
- return normalGraph(xAxisField, yAxisField, from, to, solrDaoBase,
- typeXAxis, fieldTime, solrQuery);
+ return normalGraph(xAxisField, yAxisField, from, to, solrDaoBase, typeXAxis, fieldTime, solrQuery);
case RANGE_NON_STACK_GRAPH:
- return rangeNonStackGraph(xAxisField, yAxisField, from, to, unit,
- solrDaoBase, typeXAxis, fieldTime, solrQuery);
+ return rangeNonStackGraph(xAxisField, yAxisField, from, to, unit, solrDaoBase, typeXAxis, fieldTime, solrQuery);
case NON_RANGE_STACK_GRAPH:
- return nonRangeStackGraph(xAxisField, yAxisField, stackField, from, to,
- solrDaoBase, typeXAxis, fieldTime, solrQuery);
+ return nonRangeStackGraph(xAxisField, yAxisField, stackField, from, to, solrDaoBase, typeXAxis, fieldTime, solrQuery);
case RANGE_STACK_GRAPH:
return rangeStackGraph(xAxisField, stackField, from, to, unit, solrDaoBase, solrQuery);
default:
@@ -115,9 +93,9 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
}
}
- private GRAPH_TYPE getGraphType(SearchCriteria searchCriteria) {
+ private GraphType getGraphType(SearchCriteria searchCriteria) {
// default graph type is unknown
- GRAPH_TYPE graphType = GRAPH_TYPE.UNKNOWN;
+ GraphType graphType = GraphType.UNKNOWN;
// X axis credentials
String xAxisField = (String) searchCriteria.getParamValue("xAxis");
String stackField = (String) searchCriteria.getParamValue("stackBy");
@@ -127,46 +105,35 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
if (xType != null) {
// Y axis credentials
String yAxisField = (String) searchCriteria.getParamValue("yAxis");
- if (stringUtil.isEmpty(xAxisField) || stringUtil.isEmpty(yAxisField)) {
- graphType = GRAPH_TYPE.UNKNOWN;
- } else if (stringUtil.isEmpty(stackField) && !stringUtil.isEmpty(to)
- && !stringUtil.isEmpty(from)
+ if (StringUtils.isBlank(xAxisField) || StringUtils.isBlank(yAxisField)) {
+ graphType = GraphType.UNKNOWN;
+ } else if (StringUtils.isBlank(stackField) && !StringUtils.isBlank(to) && !StringUtils.isBlank(from)
&& !(xType.contains("date") || xType.contains("time"))) {
- // Normal Graph Type
- graphType = GRAPH_TYPE.NORMAL_GRAPH;
- } else if (stringUtil.isEmpty(stackField) && !stringUtil.isEmpty(to)
- && !stringUtil.isEmpty(from)
+ graphType = GraphType.NORMAL_GRAPH;
+ } else if (StringUtils.isBlank(stackField) && !StringUtils.isBlank(to) && !StringUtils.isBlank(from)
&& (xType.contains("date") || xType.contains("time"))) {
- // Range(Non-Stack) Graph Type
- graphType = GRAPH_TYPE.RANGE_NON_STACK_GRAPH;
- } else if (!stringUtil.isEmpty(stackField) && !stringUtil.isEmpty(to)
- && !stringUtil.isEmpty(from)
+ graphType = GraphType.RANGE_NON_STACK_GRAPH;
+ } else if (!StringUtils.isBlank(stackField) && !StringUtils.isBlank(to) && !StringUtils.isBlank(from)
&& !(xType.contains("date") || xType.contains("time"))) {
- // Non-Range Stack Graph Type
- graphType = GRAPH_TYPE.NON_RANGE_STACK_GRAPH;
- } else if (!stringUtil.isEmpty(stackField) && !stringUtil.isEmpty(to)
- && !stringUtil.isEmpty(from)
+ graphType = GraphType.NON_RANGE_STACK_GRAPH;
+ } else if (!StringUtils.isBlank(stackField) && !StringUtils.isBlank(to) && !StringUtils.isBlank(from)
&& (xType.contains("date") || xType.contains("time"))) {
- // Range Stack GraphType
- graphType = GRAPH_TYPE.RANGE_STACK_GRAPH;
+ graphType = GraphType.RANGE_STACK_GRAPH;
}
}
return graphType;
}
@SuppressWarnings("unchecked")
- private VBarDataList normalGraph(String xAxisField, String yAxisField, String from,
- String to, SolrDaoBase solrDaoBase, String typeXAxis, String fieldTime,
- SolrQuery solrQuery) {
+ private VBarDataList normalGraph(String xAxisField, String yAxisField, String from, String to, SolrDaoBase solrDaoBase,
+ String typeXAxis, String fieldTime, SolrQuery solrQuery) {
VBarDataList dataList = new VBarDataList();
Collection<VBarGraphData> vBarGraphDatas = new ArrayList<VBarGraphData>();
VBarGraphData vBarGraphData = new VBarGraphData();
Collection<VNameValue> vNameValues = new ArrayList<VNameValue>();
queryGenerator.setMainQuery(solrQuery, null);
- queryGenerator.setSingleIncludeFilter(solrQuery, fieldTime, "[" + from
- + " TO " + to + "]");
- if (typeXAxis.contains("string") || typeXAxis.contains("key_lower_case")
- || typeXAxis.contains("text")) {
+ queryGenerator.setSingleIncludeFilter(solrQuery, fieldTime, "[" + from + " TO " + to + "]");
+ if (typeXAxis.contains("string") || typeXAxis.contains("key_lower_case") || typeXAxis.contains("text")) {
queryGenerator.setFacetField(solrQuery, xAxisField);
try {
QueryResponse response = solrDaoBase.process(solrQuery);
@@ -214,20 +181,17 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
return dataList;
} catch (SolrException | SolrServerException | IOException e) {
String query = solrQuery != null ? solrQuery.toQueryString() : "";
- logger.error("Got exception for solr query :" + query,
- e.getCause());
+ logger.error("Got exception for solr query :" + query, e.getCause());
}
} else {
queryGenerator.setRowCount(solrQuery, 0);
String yAxis = yAxisField.contains("count") ? "sum" : yAxisField;
- String jsonQuery = queryGenerator.buildJSONFacetAggregatedFuncitonQuery(
- yAxis, xAxisField);
+ String jsonQuery = queryGenerator.buildJSONFacetAggregatedFuncitonQuery(yAxis, xAxisField);
queryGenerator.setJSONFacet(solrQuery, jsonQuery);
try {
QueryResponse response = solrDaoBase.process(solrQuery);
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
- .getResponse().get("facets");
- if (jsonFacetResponse.toString().equals("{count=0}")){
+ SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response.getResponse().get("facets");
+ if (jsonFacetResponse.toString().equals("{count=0}")) {
return dataList;
}
VNameValue value = new VNameValue();
@@ -242,31 +206,26 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
return dataList;
} catch (SolrException | SolrServerException | IOException e) {
String query = solrQuery != null ? solrQuery.toQueryString() : "";
- logger.error("Got exception for solr query :" + query,
- e.getCause());
+ logger.error("Got exception for solr query :" + query, e.getCause());
}
}
return null;
}
@SuppressWarnings("unchecked")
- private VBarDataList nonRangeStackGraph(String xAxisField, String yAxisField,
- String stackField, String from, String to, SolrDaoBase solrDaoBase,
- String typeXAxis, String fieldTime, SolrQuery solrQuery) {
+ private VBarDataList nonRangeStackGraph(String xAxisField, String yAxisField, String stackField, String from, String to,
+ SolrDaoBase solrDaoBase, String typeXAxis, String fieldTime, SolrQuery solrQuery) {
VBarDataList dataList = new VBarDataList();
Collection<VBarGraphData> vGraphData = new ArrayList<VBarGraphData>();
- String mainQuery = queryGenerator.buildInclusiveRangeFilterQuery(fieldTime,
- from, to);
+ String mainQuery = queryGenerator.buildInclusiveRangeFilterQuery(fieldTime, from, to);
queryGenerator.setMainQuery(solrQuery, mainQuery);
queryGenerator.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
String jsonQuery = "";
if (solrUtil.isSolrFieldNumber(typeXAxis,solrDaoBase)) {
String function = (yAxisField.contains("count")) ? "sum" : yAxisField;
- jsonQuery = queryGenerator.buidlJSONFacetRangeQueryForNumber(stackField,
- xAxisField, function);
+ jsonQuery = queryGenerator.buidlJSONFacetRangeQueryForNumber(stackField, xAxisField, function);
} else {
- jsonQuery = queryGenerator.buildJsonFacetTermsRangeQuery(stackField,
- xAxisField);
+ jsonQuery = queryGenerator.buildJsonFacetTermsRangeQuery(stackField, xAxisField);
}
try {
queryGenerator.setJSONFacet(solrQuery, jsonQuery);
@@ -279,16 +238,12 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
if (count <= 0) {
return dataList;
}
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
- .getResponse().get("facets");
- if (jsonFacetResponse == null
- || jsonFacetResponse.toString().equals("{count=0}")) {
+ SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response.getResponse().get("facets");
+ if (jsonFacetResponse == null || jsonFacetResponse.toString().equals("{count=0}")) {
return dataList;
}
- extractNonRangeStackValuesFromBucket(jsonFacetResponse, stackField,
- vGraphData, typeXAxis);
- if (LogSearchConstants.SOLR_LEVEL.equalsIgnoreCase(stackField)
- && LogSearchConstants.SOLR_LEVEL.equalsIgnoreCase(xAxisField)) {
+ extractNonRangeStackValuesFromBucket(jsonFacetResponse, stackField, vGraphData, typeXAxis);
+ if (LogSearchConstants.SOLR_LEVEL.equalsIgnoreCase(stackField) && LogSearchConstants.SOLR_LEVEL.equalsIgnoreCase(xAxisField)) {
Collection<VBarGraphData> levelVGraphData = dataList.getGraphData();
for (VBarGraphData garphData : levelVGraphData) {
Collection<VNameValue> valueList = garphData.getDataCount();
@@ -312,17 +267,14 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
return dataList;
} catch (SolrException | IOException | SolrServerException e) {
String query = solrQuery != null ? solrQuery.toQueryString() : "";
- logger.error("Got exception for solr query :" + query,
- e.getCause());
- throw restErrorUtil.createRESTException(MessageEnums.DATA_NOT_FOUND
- .getMessage().getMessage(), MessageEnums.DATA_NOT_FOUND);
+ logger.error("Got exception for solr query :" + query, e.getCause());
+ throw restErrorUtil.createRESTException(MessageEnums.DATA_NOT_FOUND.getMessage().getMessage(), MessageEnums.DATA_NOT_FOUND);
}
}
@SuppressWarnings("unchecked")
- private VBarDataList rangeNonStackGraph(String xAxisField, String yAxisField,
- String from, String to, String unit, SolrDaoBase solrDaoBase,
- String typeXAxis, String fieldTime, SolrQuery solrQuery) {
+ private VBarDataList rangeNonStackGraph(String xAxisField, String yAxisField, String from, String to, String unit,
+ SolrDaoBase solrDaoBase, String typeXAxis, String fieldTime, SolrQuery solrQuery) {
VBarDataList dataList = new VBarDataList();
Collection<VBarGraphData> vBarGraphDatas = new ArrayList<VBarGraphData>();
VBarGraphData vBarGraphData = new VBarGraphData();
@@ -330,8 +282,7 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
queryGenerator.setMainQuery(solrQuery, null);
if (solrUtil.isSolrFieldNumber(typeXAxis,solrDaoBase)) {
queryGenerator.setSingleRangeFilter(solrQuery, fieldTime, from, to);
- return normalGraph(xAxisField, yAxisField, from, to, solrDaoBase,
- typeXAxis, fieldTime, solrQuery);
+ return normalGraph(xAxisField, yAxisField, from, to, solrDaoBase, typeXAxis, fieldTime, solrQuery);
} else {
try {
queryGenerator.setFacetRange(solrQuery, xAxisField, from, to, unit);
@@ -360,44 +311,36 @@ public class GraphDataGenerator extends GraphDataGeneratorBase {
}
return dataList;
} catch (SolrException | SolrServerException | IOException e) {
- logger.error("Got exception for solr query :" + solrQuery,
- e.getCause());
+ logger.error("Got exception for solr query :" + solrQuery, e.getCause());
}
}
return null;
}
@SuppressWarnings("unchecked")
- private VBarDataList rangeStackGraph(String xAxisField, String stackField,
- String from, String to, String unit, SolrDaoBase solrDaoBase,
- SolrQuery solrQuery) {
+ private VBarDataList rangeStackGraph(String xAxisField, String stackField, String from, String to, String unit,
+ SolrDaoBase solrDaoBase, SolrQuery solrQuery) {
VBarDataList dataList = new VBarDataList();
List<VBarGraphData> histogramData = new ArrayList<VBarGraphData>();
queryGenerator.setMainQuery(solrQuery, null);
queryGenerator.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
- String jsonHistogramQuery = queryGenerator
- .buildJSONFacetTermTimeRangeQuery(stackField, xAxisField, from, to,
- unit).replace("\\", "");
+ String jsonHistogramQuery =
+ queryGenerator.buildJSONFacetTermTimeRangeQuery(stackField, xAxisField, from, to, unit).replace("\\", "");
try {
solrQuery.set("json.facet", jsonHistogramQuery);
queryGenerator.setRowCount(solrQuery, 0);
QueryResponse response = solrDaoBase.process(solrQuery);
if (response != null) {
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
- .getResponse().get("facets");
- if (jsonFacetResponse == null
- || jsonFacetResponse.toString().equals("{count=0}")) {
- // return
+ SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response.getResponse().get("facets");
+ if (jsonFacetResponse == null || jsonFacetResponse.toString().equals("{count=0}")) {
return dataList;
}
- extractRangeStackValuesFromBucket(jsonFacetResponse, "x", "y",
- histogramData);
+ extractRangeStackValuesFromBucket(jsonFacetResponse, "x", "y", histogramData);
dataList.setGraphData(histogramData);
}
return dataList;
} catch (SolrException | IOException | SolrServerException e) {
- logger.error("Got exception for solr query :" + solrQuery,
- e.getCause());
+ logger.error("Got exception for solr query :" + solrQuery, e.getCause());
}
return null;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGeneratorBase.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGeneratorBase.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGeneratorBase.java
index a813e96..49006e2 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGeneratorBase.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/graph/GraphDataGeneratorBase.java
@@ -25,95 +25,50 @@ import java.util.List;
import org.apache.ambari.logsearch.manager.MgrBase;
import org.apache.ambari.logsearch.util.DateUtil;
-import org.apache.ambari.logsearch.util.StringUtil;
import org.apache.ambari.logsearch.view.VBarGraphData;
import org.apache.ambari.logsearch.view.VNameValue;
-import org.apache.solr.client.solrj.response.RangeFacet;
+import org.apache.commons.lang.StringUtils;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.springframework.beans.factory.annotation.Autowired;
-public class GraphDataGeneratorBase extends MgrBase {
-
-
- @Autowired
- DateUtil dateUtil;
+class GraphDataGeneratorBase extends MgrBase {
@Autowired
- StringUtil stringUtil;
+ private DateUtil dateUtil;
- private static String BUCKETS = "buckets";
+ private static final String BUCKETS = "buckets";
- public static enum DATA_TYPE {
- LONG {
- @Override
- String getType() {
- return "long";
- }
- },
- DOUBLE {
- @Override
- String getType() {
- return "double";
- }
- },
- FLOAT {
- @Override
- String getType() {
- return "long";
- }
- },
- INT {
- @Override
- String getType() {
- return "long";
- }
-
- };
- abstract String getType();
+ private static enum DataType {
+ LONG("long"),
+ DOUBLE("double"),
+ FLOAT("long"),
+ INT("long");
+
+ private String type;
+
+ DataType(String type) {
+ this.type = type;
+ }
+
+ String getType() {
+ return type;
+ }
}
- public static enum GRAPH_TYPE {
- UNKNOWN {
- @Override
- int getType() {
- return 0;
- }
- },
- NORMAL_GRAPH {
- @Override
- int getType() {
- return 1;
- }
- },
- RANGE_NON_STACK_GRAPH {
- @Override
- int getType() {
- return 2;
- }
- },
- NON_RANGE_STACK_GRAPH {
- @Override
- int getType() {
- return 3;
- }
- },
- RANGE_STACK_GRAPH {
- @Override
- int getType() {
- return 4;
- }
- };
- abstract int getType();
+ protected static enum GraphType {
+ UNKNOWN,
+ NORMAL_GRAPH,
+ RANGE_NON_STACK_GRAPH,
+ NON_RANGE_STACK_GRAPH,
+ RANGE_STACK_GRAPH;
}
@SuppressWarnings("unchecked")
- protected void extractRangeStackValuesFromBucket(
- SimpleOrderedMap<Object> jsonFacetResponse, String outerField,
+ protected void extractRangeStackValuesFromBucket(SimpleOrderedMap<Object> jsonFacetResponse, String outerField,
String innerField, List<VBarGraphData> histogramData) {
if (jsonFacetResponse != null) {
- NamedList<Object> stack = (NamedList<Object>) jsonFacetResponse
- .get(outerField);
+ NamedList<Object> stack = (NamedList<Object>) jsonFacetResponse.get(outerField);
if (stack != null) {
ArrayList<Object> stackBuckets = (ArrayList<Object>) stack.get(BUCKETS);
if (stackBuckets != null) {
@@ -121,26 +76,19 @@ public class GraphDataGeneratorBase extends MgrBase {
VBarGraphData vBarGraphData = new VBarGraphData();
SimpleOrderedMap<Object> level = (SimpleOrderedMap<Object>) stackBucket;
if (level != null) {
- String name = level.getVal(0) != null ? level.getVal(0)
- .toString().toUpperCase() : "";
+ String name = level.getVal(0) != null ? level.getVal(0).toString().toUpperCase() : "";
vBarGraphData.setName(name);
Collection<VNameValue> vNameValues = new ArrayList<VNameValue>();
- NamedList<Object> innerFiledValue = (NamedList<Object>) level
- .get(innerField);
+ NamedList<Object> innerFiledValue = (NamedList<Object>) level.get(innerField);
if (innerFiledValue != null) {
- ArrayList<Object> levelBuckets = (ArrayList<Object>) innerFiledValue
- .get(BUCKETS);
+ ArrayList<Object> levelBuckets = (ArrayList<Object>) innerFiledValue.get(BUCKETS);
if (levelBuckets != null) {
for (Object levelBucket : levelBuckets) {
SimpleOrderedMap<Object> countValue = (SimpleOrderedMap<Object>) levelBucket;
if (countValue != null) {
- String innerName = dateUtil
- .convertDateWithMillisecondsToSolrDate((Date) countValue
- .getVal(0));
- String innerValue = countValue.getVal(1) != null ? countValue
- .getVal(1).toString() : "";
- VNameValue vNameValue = new VNameValue(innerName,
- innerValue);
+ String innerName = dateUtil.convertDateWithMillisecondsToSolrDate((Date) countValue.getVal(0));
+ String innerValue = countValue.getVal(1) != null ? countValue.getVal(1).toString() : "";
+ VNameValue vNameValue = new VNameValue(innerName, innerValue);
vNameValues.add(vNameValue);
}
}
@@ -156,27 +104,23 @@ public class GraphDataGeneratorBase extends MgrBase {
}
@SuppressWarnings("unchecked")
- protected boolean extractNonRangeStackValuesFromBucket(
- SimpleOrderedMap<Object> jsonFacetResponse, String level,
+ protected boolean extractNonRangeStackValuesFromBucket(SimpleOrderedMap<Object> jsonFacetResponse, String level,
Collection<VBarGraphData> vGraphDatas, String typeXAxis) {
boolean zeroFlag = true;
if (jsonFacetResponse == null || jsonFacetResponse.get(level) == null
|| jsonFacetResponse.get(level).toString().equals("{count=0}")) {
return false;
}
- NamedList<Object> levelList = (NamedList<Object>) jsonFacetResponse
- .get(level);
+ NamedList<Object> levelList = (NamedList<Object>) jsonFacetResponse.get(level);
if (levelList != null) {
ArrayList<Object> bucketList = (ArrayList<Object>) levelList.get(BUCKETS);
if (bucketList != null) {
for (int index = 0; index < bucketList.size(); index++) {
- SimpleOrderedMap<Object> valueCount = (SimpleOrderedMap<Object>) bucketList
- .get(index);
+ SimpleOrderedMap<Object> valueCount = (SimpleOrderedMap<Object>) bucketList.get(index);
if (valueCount != null && valueCount.size() > 2) {
VBarGraphData vGraphData = new VBarGraphData();
Collection<VNameValue> levelCounts = new ArrayList<VNameValue>();
- String name = valueCount.getVal(0) != null ? valueCount.getVal(0)
- .toString().trim() : "";
+ String name = valueCount.getVal(0) != null ? valueCount.getVal(0).toString().trim() : "";
if (isTypeNumber(typeXAxis)) {
VNameValue nameValue = new VNameValue();
Double sumValue = (Double) valueCount.getVal(2);
@@ -188,24 +132,16 @@ public class GraphDataGeneratorBase extends MgrBase {
nameValue.setValue(value);
levelCounts.add(nameValue);
} else {
- SimpleOrderedMap<Object> valueCountMap = (SimpleOrderedMap<Object>) valueCount
- .getVal(2);
+ SimpleOrderedMap<Object> valueCountMap = (SimpleOrderedMap<Object>) valueCount.getVal(2);
if (valueCountMap != null) {
- ArrayList<Object> buckets = (ArrayList<Object>) valueCountMap
- .get(BUCKETS);
+ ArrayList<Object> buckets = (ArrayList<Object>) valueCountMap.get(BUCKETS);
if (buckets != null) {
for (int innerIndex = 0; innerIndex < buckets.size(); innerIndex++) {
- SimpleOrderedMap<Object> innerValueCount = (SimpleOrderedMap<Object>) buckets
- .get(innerIndex);
+ SimpleOrderedMap<Object> innerValueCount = (SimpleOrderedMap<Object>) buckets.get(innerIndex);
if (innerValueCount != null) {
- String innerName = innerValueCount.getVal(0) != null ? innerValueCount
- .getVal(0).toString().trim()
- : "";
- String innerValue = innerValueCount.getVal(1) != null ? innerValueCount
- .getVal(1).toString().trim()
- : "";
- VNameValue nameValue = new VNameValue(innerName,
- innerValue);
+ String innerName = innerValueCount.getVal(0) != null ? innerValueCount.getVal(0).toString().trim() : "";
+ String innerValue = innerValueCount.getVal(1) != null ? innerValueCount.getVal(1).toString().trim() : "";
+ VNameValue nameValue = new VNameValue(innerName, innerValue);
levelCounts.add(nameValue);
}
}
@@ -222,59 +158,12 @@ public class GraphDataGeneratorBase extends MgrBase {
return zeroFlag;
}
- @SuppressWarnings("unchecked")
- protected boolean extractValuesFromJson(
- SimpleOrderedMap<Object> jsonFacetResponse, String level,
- VBarGraphData histogramData, List<RangeFacet.Count> counts) {
- histogramData.setName(level);
- Collection<VNameValue> levelCounts = new ArrayList<VNameValue>();
- histogramData.setDataCounts(levelCounts);
- boolean zeroFlag = true;
- if (jsonFacetResponse.get(level).toString().equals("{count=0}")) {
- if (counts != null) {
- for (RangeFacet.Count date : counts) {
- VNameValue nameValue = new VNameValue();
- nameValue.setName(date.getValue());
- nameValue.setValue("0");
- levelCounts.add(nameValue);
- }
- }
- return false;
- }
- NamedList<Object> levelList = (NamedList<Object>) jsonFacetResponse
- .get(level);
- if (levelList != null && counts != null && levelList.size() > 1) {
- NamedList<Object> levelValues = (NamedList<Object>) levelList.getVal(1);
- if (levelValues != null) {
- ArrayList<Object> bucketList = (ArrayList<Object>) levelValues
- .get(BUCKETS);
- int i = 0;
- for (RangeFacet.Count date : counts) {
- SimpleOrderedMap<Object> valueCount = (SimpleOrderedMap<Object>) bucketList
- .get(i);
- if (valueCount != null) {
- Double count = (Double) valueCount.getVal(1);
- if (count != null && !count.equals(0D)) {
- zeroFlag = false;
- }
- String name = date.getValue();
- String value = count != null ? "" + count.longValue() : "0";
- VNameValue nameValue = new VNameValue(name, value);
- levelCounts.add(nameValue);
- }
- i++;
- }
- }
- }
- return zeroFlag;
- }
-
protected boolean isTypeNumber(String typeXAxis) {
- if (stringUtil.isEmpty(typeXAxis)) {
+ if (StringUtils.isBlank(typeXAxis)) {
return false;
} else {
- return typeXAxis.contains(DATA_TYPE.LONG.getType()) || typeXAxis.contains(DATA_TYPE.INT.getType())
- || typeXAxis.contains(DATA_TYPE.FLOAT.getType()) || typeXAxis.contains(DATA_TYPE.DOUBLE.getType());
+ return typeXAxis.contains(DataType.LONG.getType()) || typeXAxis.contains(DataType.INT.getType())
+ || typeXAxis.contains(DataType.FLOAT.getType()) || typeXAxis.contains(DataType.DOUBLE.getType());
}
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditMgr.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditMgr.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditMgr.java
index ab287bc..947fdbb 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditMgr.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditMgr.java
@@ -41,10 +41,8 @@ import org.apache.ambari.logsearch.graph.GraphDataGenerator;
import org.apache.ambari.logsearch.util.BizUtil;
import org.apache.ambari.logsearch.util.ConfigUtil;
import org.apache.ambari.logsearch.util.DateUtil;
-import org.apache.ambari.logsearch.util.JSONUtil;
import org.apache.ambari.logsearch.util.PropertiesUtil;
import org.apache.ambari.logsearch.util.RESTErrorUtil;
-import org.apache.ambari.logsearch.util.StringUtil;
import org.apache.ambari.logsearch.view.VBarDataList;
import org.apache.ambari.logsearch.view.VBarGraphData;
import org.apache.ambari.logsearch.view.VGroupList;
@@ -69,54 +67,41 @@ import org.springframework.stereotype.Component;
@Component
public class AuditMgr extends MgrBase {
- static Logger logger = Logger.getLogger(AuditMgr.class);
+ private static final Logger logger = Logger.getLogger(AuditMgr.class);
@Autowired
- AuditSolrDao auditSolrDao;
-
+ private AuditSolrDao auditSolrDao;
@Autowired
- RESTErrorUtil restErrorUtil;
-
+ private RESTErrorUtil restErrorUtil;
@Autowired
- JSONUtil jsonUtil;
-
+ private BizUtil bizUtil;
@Autowired
- StringUtil stringUtil;
-
+ private DateUtil dateUtil;
@Autowired
- BizUtil bizUtil;
-
- @Autowired
- DateUtil dateUtil;
-
- @Autowired
- GraphDataGenerator graphDataGenerator;
+ private GraphDataGenerator graphDataGenerator;
public String getLogs(SearchCriteria searchCriteria) {
String lastPage = (String) searchCriteria.getParamValue("isLastPage");
Boolean isLastPage = Boolean.parseBoolean(lastPage);
if (isLastPage) {
SolrQuery lastPageQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
- VSolrLogList collection = getLastPage(searchCriteria,LogSearchConstants.AUDIT_EVTTIME,auditSolrDao,lastPageQuery);
+ VSolrLogList collection = getLastPage(searchCriteria, LogSearchConstants.AUDIT_EVTTIME, auditSolrDao, lastPageQuery);
if(collection == null){
collection = new VSolrLogList();
}
return convertObjToString(collection);
}
SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
- VSolrLogList collection = getLogAsPaginationProvided(solrQuery,
- auditSolrDao);
+ VSolrLogList collection = getLogAsPaginationProvided(solrQuery, auditSolrDao);
return convertObjToString(collection);
}
- public SolrDocumentList getComponents(SearchCriteria searchCriteria) {
- SolrQuery solrQuery = queryGenerator
- .commonAuditFilterQuery(searchCriteria);
+ private SolrDocumentList getComponents(SearchCriteria searchCriteria) {
+ SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
SolrDocumentList docList = new SolrDocumentList();
try {
- queryGenerator.setFacetField(solrQuery,
- LogSearchConstants.AUDIT_COMPONENT);
+ queryGenerator.setFacetField(solrQuery, LogSearchConstants.AUDIT_COMPONENT);
queryGenerator.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
List<FacetField> facetFields = null;
List<Count> componentsCount = new ArrayList<Count>();
@@ -146,8 +131,7 @@ public class AuditMgr extends MgrBase {
return docList;
} catch (SolrException | SolrServerException | IOException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -167,14 +151,10 @@ public class AuditMgr extends MgrBase {
String from = getFrom((String) searchCriteria.getParamValue("startTime"));
String to = getTo((String) searchCriteria.getParamValue("endTime"));
String unit = getUnit((String) searchCriteria.getParamValue("unit"));
-
-
List<VBarGraphData> histogramData = new ArrayList<VBarGraphData>();
- String jsonHistogramQuery = queryGenerator.buildJSONFacetTermTimeRangeQuery(
- LogSearchConstants.AUDIT_COMPONENT,
- LogSearchConstants.AUDIT_EVTTIME, from, to, unit).replace("\\",
- "");
+ String jsonHistogramQuery = queryGenerator.buildJSONFacetTermTimeRangeQuery(LogSearchConstants.AUDIT_COMPONENT,
+ LogSearchConstants.AUDIT_EVTTIME, from, to, unit).replace("\\", "");
try {
queryGenerator.setJSONFacet(solrQuery, jsonHistogramQuery);
@@ -183,24 +163,20 @@ public class AuditMgr extends MgrBase {
if (response == null){
return convertObjToString(dataList);
}
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
- .getResponse().get("facets");
+ SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response.getResponse().get("facets");
- if (jsonFacetResponse == null
- || jsonFacetResponse.toString().equals("{count=0}")){
+ if (jsonFacetResponse == null || jsonFacetResponse.toString().equals("{count=0}")) {
return convertObjToString(dataList);
}
- extractValuesFromBucket(jsonFacetResponse, "x", "y",
- histogramData);
+ extractValuesFromBucket(jsonFacetResponse, "x", "y", histogramData);
dataList.setGraphData(histogramData);
return convertObjToString(dataList);
} catch (SolrServerException | SolrException | IOException e) {
logger.error(e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -212,8 +188,7 @@ public class AuditMgr extends MgrBase {
if (top == null){
top = new Integer(topCounts);
}
- SolrQuery solrQuery = queryGenerator
- .commonAuditFilterQuery(searchCriteria);
+ SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
try {
List<VNameValue> nameValues = new ArrayList<VNameValue>();
@@ -226,13 +201,12 @@ public class AuditMgr extends MgrBase {
List<Count> countList = new ArrayList<FacetField.Count>();
QueryResponse queryResponse = auditSolrDao.process(solrQuery);
- if(queryResponse == null){
+ if (queryResponse == null) {
return convertObjToString(nameValueList);
}
if (queryResponse.getFacetField(facetField) != null) {
- FacetField queryFacetField = queryResponse
- .getFacetField(facetField);
+ FacetField queryFacetField = queryResponse.getFacetField(facetField);
if (queryFacetField != null) {
countList = queryFacetField.getValues();
}
@@ -249,8 +223,7 @@ public class AuditMgr extends MgrBase {
} catch (SolrException | IOException | SolrServerException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -260,16 +233,12 @@ public class AuditMgr extends MgrBase {
SolrQuery solrQuery = new SolrQuery();
solrQuery.setParam("event", "/audit/logs/live/count");
try {
- String startDate = dateUtil
- .convertGivenDateFormatToSolrDateFormat(ManageStartEndTime.startDate);
-
- String endDate = dateUtil
- .convertGivenDateFormatToSolrDateFormat(ManageStartEndTime.endDate);
+ Date[] timeRange = ManageStartEndTime.getStartEndTime();
+ String startDate = dateUtil.convertGivenDateFormatToSolrDateFormat(timeRange[0]);
+ String endDate = dateUtil.convertGivenDateFormatToSolrDateFormat(timeRange[1]);
queryGenerator.setMainQuery(solrQuery, null);
- queryGenerator.setFacetRange(solrQuery,
- LogSearchConstants.AUDIT_EVTTIME, startDate, endDate,
- "+2MINUTE");
+ queryGenerator.setFacetRange(solrQuery, LogSearchConstants.AUDIT_EVTTIME, startDate, endDate, "+2MINUTE");
List<RangeFacet.Count> listCount;
QueryResponse response = auditSolrDao.process(solrQuery);
@@ -301,22 +270,21 @@ public class AuditMgr extends MgrBase {
} catch (SolrException | SolrServerException | ParseException
| IOException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
public String topTenUsers(SearchCriteria searchCriteria) {
- String jsonUserQuery = "{Users:{type:terms, field:reqUser, facet:{ Repo:{ type:terms, field:repo, facet:{eventCount:\"sum(event_count)\"}}}}}";
- SolrQuery solrQuery = queryGenerator
- .commonAuditFilterQuery(searchCriteria);
+ String jsonUserQuery =
+ "{Users:{type:terms, field:reqUser, facet:{ Repo:{ type:terms, field:repo, facet:{eventCount:\"sum(event_count)\"}}}}}";
+ SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
queryGenerator.setJSONFacet(solrQuery, jsonUserQuery);
queryGenerator.setRowCount(solrQuery, 0);
try {
VBarDataList vBarDataList = new VBarDataList();
QueryResponse queryResponse = auditSolrDao.process(solrQuery);
- if(queryResponse == null){
+ if (queryResponse == null) {
return convertObjToString(vBarDataList);
}
@@ -327,12 +295,11 @@ public class AuditMgr extends MgrBase {
}
@SuppressWarnings("unchecked")
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList
- .get("facets");
- if(jsonFacetResponse == null){
+ SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList.get("facets");
+ if (jsonFacetResponse == null) {
return convertObjToString(vBarDataList);
}
- if(jsonFacetResponse.toString().equals("{count=0}")){
+ if (jsonFacetResponse.toString().equals("{count=0}")) {
return convertObjToString(vBarDataList);
}
vBarDataList = bizUtil.buildSummaryForTopCounts(jsonFacetResponse,"Repo","Users");
@@ -340,16 +307,15 @@ public class AuditMgr extends MgrBase {
} catch (SolrServerException | SolrException | IOException e) {
logger.error("Error during solrQuery=" + e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
public String topTenResources(SearchCriteria searchCriteria) {
- String jsonUserQuery = "{Users:{type:terms,field:resource,facet:{Repo:{type:terms,field:repo,facet:{eventCount:\"sum(event_count)\"}}}}}";
- SolrQuery solrQuery = queryGenerator
- .commonAuditFilterQuery(searchCriteria);
+ String jsonUserQuery =
+ "{Users:{type:terms,field:resource,facet:{Repo:{type:terms,field:repo,facet:{eventCount:\"sum(event_count)\"}}}}}";
+ SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
queryGenerator.setJSONFacet(solrQuery, jsonUserQuery);
queryGenerator.setRowCount(solrQuery, 0);
try {
@@ -365,16 +331,14 @@ public class AuditMgr extends MgrBase {
}
@SuppressWarnings("unchecked")
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList
- .get("facets");
+ SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList.get("facets");
vBarDataList = bizUtil.buildSummaryForTopCounts(jsonFacetResponse,"Repo","Users");
return convertObjToString(vBarDataList);
} catch (SolrServerException | SolrException | IOException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
@@ -385,19 +349,15 @@ public class AuditMgr extends MgrBase {
String to = getTo((String) searchCriteria.getParamValue("endTime"));
String unit = getUnit((String) searchCriteria.getParamValue("unit"));
- SolrQuery solrQuery = queryGenerator
- .commonAuditFilterQuery(searchCriteria);
+ SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
VBarDataList dataList = new VBarDataList();
List<VBarGraphData> histogramData = new ArrayList<VBarGraphData>();
queryGenerator.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
- String jsonHistogramQuery = queryGenerator
- .buildJSONFacetTermTimeRangeQuery(
- LogSearchConstants.AUDIT_REQUEST_USER,
- LogSearchConstants.AUDIT_EVTTIME, from, to, unit)
- .replace("\\", "");
+ String jsonHistogramQuery = queryGenerator.buildJSONFacetTermTimeRangeQuery(LogSearchConstants.AUDIT_REQUEST_USER,
+ LogSearchConstants.AUDIT_EVTTIME, from, to, unit).replace("\\", "");
try {
queryGenerator.setJSONFacet(solrQuery, jsonHistogramQuery);
@@ -406,11 +366,9 @@ public class AuditMgr extends MgrBase {
if (response == null){
return convertObjToString(dataList);
}
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response
- .getResponse().get("facets");
+ SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response.getResponse().get("facets");
- if (jsonFacetResponse == null
- || jsonFacetResponse.toString().equals("{count=0}")){
+ if (jsonFacetResponse == null || jsonFacetResponse.toString().equals("{count=0}")) {
return convertObjToString(dataList);
}
extractValuesFromBucket(jsonFacetResponse, "x", "y", histogramData);
@@ -420,63 +378,19 @@ public class AuditMgr extends MgrBase {
} catch (SolrException | IOException | SolrServerException e) {
logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
}
- public SolrDocumentList getRequestUser(SearchCriteria searchCriteria) {
- SolrDocumentList docList = new SolrDocumentList();
- SolrQuery solrQuery = queryGenerator
- .commonAuditFilterQuery(searchCriteria);
- try {
- queryGenerator.setFacetField(solrQuery,
- LogSearchConstants.AUDIT_REQUEST_USER);
- queryGenerator.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
- List<FacetField> facetFields = null;
- List<Count> componentsCount = new ArrayList<Count>();
- FacetField facetField = null;
-
- QueryResponse queryResponse = auditSolrDao.process(solrQuery);
- if (queryResponse == null) {
- return docList;
- }
-
- facetFields = queryResponse.getFacetFields();
- if (facetFields == null) {
- return docList;
- }
- if (!facetFields.isEmpty()) {
- facetField = facetFields.get(0);
- }
- if (facetField != null) {
- componentsCount = facetField.getValues();
- }
-
- for (Count compnonet : componentsCount) {
- SolrDocument solrDocument = new SolrDocument();
- solrDocument.addField("type", compnonet.getName());
- docList.add(solrDocument);
- }
- return docList;
- } catch (SolrException | SolrServerException | IOException e) {
- logger.error("Error during solrQuery=" + solrQuery, e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
- }
- }
-
public String getAuditLogsSchemaFieldsName() {
- String excludeArray[] = PropertiesUtil
- .getPropertyStringList("logsearch.solr.audit.logs.exclude.columnlist");
+ String excludeArray[] = PropertiesUtil.getPropertyStringList("logsearch.solr.audit.logs.exclude.columnlist");
List<String> fieldNames = new ArrayList<String>();
HashMap<String, String> uiFieldColumnMapping = new HashMap<String, String>();
ConfigUtil.getSchemaFieldsName(excludeArray, fieldNames,auditSolrDao);
for (String fieldName : fieldNames) {
- String uiField = ConfigUtil.auditLogsColumnMapping.get(fieldName
- + LogSearchConstants.SOLR_SUFFIX);
+ String uiField = ConfigUtil.auditLogsColumnMapping.get(fieldName + LogSearchConstants.SOLR_SUFFIX);
if (uiField == null) {
uiFieldColumnMapping.put(fieldName, fieldName);
} else {
@@ -492,8 +406,7 @@ public class AuditMgr extends MgrBase {
public String getAnyGraphData(SearchCriteria searchCriteria) {
searchCriteria.addParam("fieldTime", LogSearchConstants.AUDIT_EVTTIME);
SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
- VBarDataList result = graphDataGenerator.getAnyGraphData(searchCriteria,
- auditSolrDao, solrQuery);
+ VBarDataList result = graphDataGenerator.getAnyGraphData(searchCriteria, auditSolrDao, solrQuery);
if (result == null) {
result = new VBarDataList();
}
@@ -502,13 +415,10 @@ public class AuditMgr extends MgrBase {
}
@SuppressWarnings("unchecked")
- public void extractValuesFromBucket(
- SimpleOrderedMap<Object> jsonFacetResponse, String outerField,
- String innerField, List<VBarGraphData> histogramData) {
- NamedList<Object> stack = (NamedList<Object>) jsonFacetResponse
- .get(outerField);
- ArrayList<Object> stackBuckets = (ArrayList<Object>) stack
- .get("buckets");
+ private void extractValuesFromBucket(SimpleOrderedMap<Object> jsonFacetResponse, String outerField, String innerField,
+ List<VBarGraphData> histogramData) {
+ NamedList<Object> stack = (NamedList<Object>) jsonFacetResponse.get(outerField);
+ ArrayList<Object> stackBuckets = (ArrayList<Object>) stack.get("buckets");
for (Object temp : stackBuckets) {
VBarGraphData vBarGraphData = new VBarGraphData();
@@ -518,13 +428,10 @@ public class AuditMgr extends MgrBase {
Collection<VNameValue> vNameValues = new ArrayList<VNameValue>();
vBarGraphData.setDataCounts(vNameValues);
- ArrayList<Object> levelBuckets = (ArrayList<Object>) ((NamedList<Object>) level
- .get(innerField)).get("buckets");
+ ArrayList<Object> levelBuckets = (ArrayList<Object>) ((NamedList<Object>) level.get(innerField)).get("buckets");
for (Object temp1 : levelBuckets) {
SimpleOrderedMap<Object> countValue = (SimpleOrderedMap<Object>) temp1;
- String value = dateUtil
- .convertDateWithMillisecondsToSolrDate((Date) countValue
- .getVal(0));
+ String value = dateUtil.convertDateWithMillisecondsToSolrDate((Date) countValue.getVal(0));
String count = "" + countValue.getVal(1);
VNameValue vNameValue = new VNameValue();
@@ -536,12 +443,12 @@ public class AuditMgr extends MgrBase {
}
}
- @SuppressWarnings({"unchecked", "resource"})
+ @SuppressWarnings({"unchecked"})
public Response exportUserTableToTextFile(SearchCriteria searchCriteria) {
- String jsonUserQuery = "{ Users: { type: terms, field: reqUser, facet: {Repo: { type: terms, field: repo, facet: { eventCount: \"sum(event_count)\"}}}},x:{ type: terms,field: resource, facet: {y: { type: terms, field: repo,facet: { eventCount: \"sum(event_count)\"}}}}}";
+ String jsonUserQuery =
+ "{ Users: { type: terms, field: reqUser, facet: {Repo: { type: terms, field: repo, facet: { eventCount: \"sum(event_count)\"}}}},x:{ type: terms,field: resource, facet: {y: { type: terms, field: repo,facet: { eventCount: \"sum(event_count)\"}}}}}";
- SolrQuery solrQuery = queryGenerator
- .commonAuditFilterQuery(searchCriteria);
+ SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
String startTime = (String) searchCriteria.getParamValue("startTime");
String endTime = (String) searchCriteria.getParamValue("endTime");
@@ -562,7 +469,7 @@ public class AuditMgr extends MgrBase {
}
NamedList<Object> namedList = queryResponse.getResponse();
- if(namedList == null){
+ if (namedList == null) {
VResponse response = new VResponse();
response.setMsgDesc("Query was not able to execute "+solrQuery);
throw restErrorUtil.createRESTException(response);
@@ -570,12 +477,9 @@ public class AuditMgr extends MgrBase {
VBarDataList vBarUserDataList = new VBarDataList();
VBarDataList vBarResourceDataList = new VBarDataList();
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList
- .get("facets");
- vBarUserDataList = bizUtil
- .buildSummaryForTopCounts(jsonFacetResponse,"Repo","Users");
- vBarResourceDataList = bizUtil
- .buildSummaryForTopCounts(jsonFacetResponse,"y","x");
+ SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList.get("facets");
+ vBarUserDataList = bizUtil.buildSummaryForTopCounts(jsonFacetResponse,"Repo","Users");
+ vBarResourceDataList = bizUtil.buildSummaryForTopCounts(jsonFacetResponse,"y","x");
String data = "";
String summary = "";
if ("text".equals(dataFormat)) {
@@ -584,8 +488,7 @@ public class AuditMgr extends MgrBase {
summary += "\n\n\n\n";
data += addBlank("Users") + "Components/Access" + "\n";
data += "--------------------------------------------------------------------------\n";
- Collection<VBarGraphData> tableUserData = vBarUserDataList
- .getGraphData();
+ Collection<VBarGraphData> tableUserData = vBarUserDataList.getGraphData();
for (VBarGraphData graphData : tableUserData) {
String userName = graphData.getName();
String largeUserName = "";
@@ -596,13 +499,11 @@ public class AuditMgr extends MgrBase {
} else
data += addBlank(userName);
- Collection<VNameValue> vnameValueList = graphData
- .getDataCount();
+ Collection<VNameValue> vnameValueList = graphData.getDataCount();
int count = 0;
String blank = "";
for (VNameValue vNameValue : vnameValueList) {
- data += blank + vNameValue.getName() + " "
- + vNameValue.getValue() + "\n";
+ data += blank + vNameValue.getName() + " " + vNameValue.getValue() + "\n";
if (count == 0)
blank = addBlank(blank);
count++;
@@ -617,8 +518,7 @@ public class AuditMgr extends MgrBase {
data += "\n\n\n\n\n\n";
data += addBlank("Resources") + "Components/Access" + "\n";
data += "--------------------------------------------------------------------------\n";
- Collection<VBarGraphData> tableResourceData = vBarResourceDataList
- .getGraphData();
+ Collection<VBarGraphData> tableResourceData = vBarResourceDataList.getGraphData();
for (VBarGraphData graphData : tableResourceData) {
String resourceName = graphData.getName();
String largeResourceName = resourceName;
@@ -631,13 +531,11 @@ public class AuditMgr extends MgrBase {
//resourceName = resourceName.replaceAll("(.{45})", resourceName.substring(0, 45)+"\n");
data += addBlank(resourceName);
- Collection<VNameValue> vnameValueList = graphData
- .getDataCount();
+ Collection<VNameValue> vnameValueList = graphData.getDataCount();
int count = 0;
String blank = "";
for (VNameValue vNameValue : vnameValueList) {
- data += blank + vNameValue.getName() + " "
- + vNameValue.getValue() + "\n";
+ data += blank + vNameValue.getName() + " " + vNameValue.getValue() + "\n";
if (count == 0)
blank = addBlank(blank);
count++;
@@ -660,22 +558,19 @@ public class AuditMgr extends MgrBase {
data = "{" + convertObjToString(vBarUserDataList) + "," + convertObjToString(vBarResourceDataList) + "}";
dataFormat = "json";
}
- String fileName = "Users_Resource" + startTime + endTime
- + ".";
+ String fileName = "Users_Resource" + startTime + endTime + ".";
File file = File.createTempFile(fileName, dataFormat);
fis = new FileOutputStream(file);
fis.write(data.getBytes());
return Response
.ok(file, MediaType.APPLICATION_OCTET_STREAM)
- .header("Content-Disposition",
- "attachment;filename=" + fileName + dataFormat)
+ .header("Content-Disposition", "attachment;filename=" + fileName + dataFormat)
.build();
} catch (SolrServerException | SolrException | IOException e) {
logger.error("Error during solrQuery=" + e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
} finally {
if (fis != null) {
try {
@@ -704,21 +599,18 @@ public class AuditMgr extends MgrBase {
SolrQuery serivceLoadQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
try {
- queryGenerator.setFacetField(serivceLoadQuery,
- LogSearchConstants.AUDIT_COMPONENT);
- QueryResponse serviceLoadResponse = auditSolrDao
- .process(serivceLoadQuery);
+ queryGenerator.setFacetField(serivceLoadQuery, LogSearchConstants.AUDIT_COMPONENT);
+ QueryResponse serviceLoadResponse = auditSolrDao.process(serivceLoadQuery);
if (serviceLoadResponse == null){
return convertObjToString(dataList);
}
- FacetField serviceFacetField =serviceLoadResponse.getFacetField(
- LogSearchConstants.AUDIT_COMPONENT);
- if(serviceFacetField == null){
+ FacetField serviceFacetField =serviceLoadResponse.getFacetField(LogSearchConstants.AUDIT_COMPONENT);
+ if (serviceFacetField == null) {
return convertObjToString(dataList);
}
List<Count> serviceLoadFacets = serviceFacetField.getValues();
- if(serviceLoadFacets == null){
+ if (serviceLoadFacets == null) {
return convertObjToString(dataList);
}
for (Count cnt : serviceLoadFacets) {
@@ -733,70 +625,11 @@ public class AuditMgr extends MgrBase {
vBarGraphData.setDataCounts(valueList);
}
-
return convertObjToString(dataList);
} catch (SolrException | SolrServerException | IOException e) {
logger.error("Error during solrQuery=" + e);
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
-
- /*
- String preDefinedJSON = getHadoopServiceConfigJSON();
- try {
- JSONObject serviceJSON = new JSONObject(preDefinedJSON).getJSONObject("service");
- HashMap<String, Object> serviceMap = jsonUtil.jsonToMapObject(serviceJSON.toString());
- Iterator<Entry<String, Object>> serviceMapIterator= serviceMap.entrySet().iterator();
- List<VNameValue> newValueList = new ArrayList<VNameValue>();
- for (VNameValue vNameValue : valueList) {
- String name=vNameValue.getName();
- while (serviceMapIterator.hasNext()) {
- Map.Entry<String, Object> tempMap = serviceMapIterator
- .next();
-
- String keyName = tempMap.getKey();
-
- JSONObject valueObj = new JSONObject(tempMap.toString().replace(keyName+"=", ""));
- if(name.contains(keyName.toLowerCase())){
- vNameValue.setName(valueObj.getString("label"));
- break;
- }
- JSONArray componentsArray = valueObj.getJSONArray("components");
-
- for(int i =0;i< componentsArray.length();i++){
- JSONObject jObj = componentsArray.getJSONObject(i);
- String jsonName = jObj.getString("name");
- if(name.contains(jsonName.toLowerCase())){
- vNameValue.setName(valueObj.getString("label"));
- break;
- }
- }
-
- }
- if(newValueList.isEmpty()){
- newValueList.add(vNameValue);
- }else{
- boolean isMatch = false;
- for(VNameValue vValue: newValueList){
- if(vValue.getName().equalsIgnoreCase(vNameValue.getName())){
- isMatch =true;
- Integer cnt1 = Integer.parseInt(vValue.getValue());
- Integer cnt2 = Integer.parseInt(vNameValue.getValue());
- vValue.setValue((cnt1+cnt2)+"");
- }
- }
- if(!isMatch)
- newValueList.add(vNameValue);
- }
- }
- vBarGraphData.setDataCounts(newValueList);
- vBarGraphData.setName("ServiceList");
- return convertObjToString(dataList);
-
- } catch (Exception e) {
- throw restErrorUtil.createRESTException(e.getMessage(),
- MessageEnums.ERROR_SYSTEM);
- }*/
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogFileMgr.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogFileMgr.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogFileMgr.java
index 1bd9a78..8badb61 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogFileMgr.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogFileMgr.java
@@ -32,6 +32,7 @@ import org.apache.ambari.logsearch.view.VLogFile;
import org.apache.ambari.logsearch.view.VLogFileList;
import org.apache.ambari.logsearch.view.VSolrLogList;
import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
@@ -46,24 +47,13 @@ import org.springframework.stereotype.Component;
@Component
public class LogFileMgr extends MgrBase {
- private static Logger logger = Logger.getLogger(LogFileMgr.class);
-
+ private static final Logger logger = Logger.getLogger(LogFileMgr.class);
@Autowired
- ServiceLogsSolrDao serviceLogsSolrDao;
-
+ private ServiceLogsSolrDao serviceLogsSolrDao;
@Autowired
- AuditSolrDao auditSolrDao;
+ private AuditSolrDao auditSolrDao;
- @Autowired
- LogsMgr logMgr;
-
- /**
- * Search logFiles
- *
- * @param searchCriteria
- * @return
- */
public String searchLogFiles(SearchCriteria searchCriteria) {
VLogFileList logFileList = new VLogFileList();
List<VLogFile> logFiles = new ArrayList<VLogFile>();
@@ -72,31 +62,26 @@ public class LogFileMgr extends MgrBase {
int minCount = 1;// to remove zero count facet
SolrQuery solrQuery = new SolrQuery();
queryGenerator.setMainQuery(solrQuery, null);
- queryGenerator.setFacetFieldWithMincount(solrQuery, LogSearchConstants.SOLR_PATH,
- minCount);
+ queryGenerator.setFacetFieldWithMincount(solrQuery, LogSearchConstants.SOLR_PATH, minCount);
// adding filter
- queryGenerator.setSingleIncludeFilter(solrQuery,
- LogSearchConstants.SOLR_COMPONENT, componentName);
- queryGenerator.setSingleIncludeFilter(solrQuery,
- LogSearchConstants.SOLR_HOST, host);
+ queryGenerator.setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_COMPONENT, componentName);
+ queryGenerator.setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_HOST, host);
try {
String logType = (String) searchCriteria.getParamValue("logType");
- if (stringUtil.isEmpty(logType)) {
- logType = LOG_TYPE.SERVICE.name();// default is service Log
+ if (StringUtils.isBlank(logType)) {
+ logType = LogType.SERVICE.name();// default is service Log
}
SolrDaoBase daoMgr = null;
- if (logType.equalsIgnoreCase(LOG_TYPE.SERVICE.name())) {
+ if (logType.equalsIgnoreCase(LogType.SERVICE.name())) {
daoMgr = serviceLogsSolrDao;
- } else if (logType.equalsIgnoreCase(LOG_TYPE.AUDIT.name())) {
+ } else if (logType.equalsIgnoreCase(LogType.AUDIT.name())) {
daoMgr = auditSolrDao;
} else {
- throw restErrorUtil.createRESTException(logType
- + " is not a valid logType", MessageEnums.INVALID_INPUT_DATA);
+ throw restErrorUtil.createRESTException(logType + " is not a valid logType", MessageEnums.INVALID_INPUT_DATA);
}
QueryResponse queryResponse = daoMgr.process(solrQuery);
if (queryResponse.getFacetField(LogSearchConstants.SOLR_PATH) != null) {
- FacetField queryFacetField = queryResponse
- .getFacetField(LogSearchConstants.SOLR_PATH);
+ FacetField queryFacetField = queryResponse.getFacetField(LogSearchConstants.SOLR_PATH);
if (queryFacetField != null) {
List<Count> countList = queryFacetField.getValues();
for (Count count : countList) {
@@ -110,10 +95,8 @@ public class LogFileMgr extends MgrBase {
}
}
} catch (SolrException | SolrServerException | IOException e) {
- logger.error("Error in solr query :" + e.getLocalizedMessage()
- + "\n Query :" + solrQuery.toQueryString(), e.getCause());
- throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR
- .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
+ logger.error("Error in solr query :" + e.getLocalizedMessage() + "\n Query :" + solrQuery.toQueryString(), e.getCause());
+ throw restErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
}
logFileList.setLogFiles(logFiles);
String jsonStr = "";
@@ -127,28 +110,22 @@ public class LogFileMgr extends MgrBase {
String logFile = (String) searchCriteria.getParamValue("name");
String component = (String) searchCriteria.getParamValue("component");
String tailSize = (String) searchCriteria.getParamValue("tailSize");
- if (stringUtil.isEmpty(host)) {
- throw restErrorUtil.createRESTException("missing Host Name",
- MessageEnums.ERROR_SYSTEM);
+ if (StringUtils.isBlank(host)) {
+ throw restErrorUtil.createRESTException("missing Host Name", MessageEnums.ERROR_SYSTEM);
}
- tailSize = (stringUtil.isEmpty(tailSize)) ? "10" : tailSize;
+ tailSize = (StringUtils.isBlank(tailSize)) ? "10" : tailSize;
SolrQuery logFileTailQuery = new SolrQuery();
try {
int tail = Integer.parseInt(tailSize);
tail = tail > 100 ? 100 : tail;
queryGenerator.setMainQuery(logFileTailQuery, null);
- queryGenerator.setSingleIncludeFilter(logFileTailQuery,
- LogSearchConstants.SOLR_HOST, host);
- if (!stringUtil.isEmpty(logFile)) {
- queryGenerator.setSingleIncludeFilter(logFileTailQuery,
- LogSearchConstants.SOLR_PATH,
- solrUtil.makeSolrSearchString(logFile));
- } else if (!stringUtil.isEmpty(component)) {
- queryGenerator.setSingleIncludeFilter(logFileTailQuery,
- LogSearchConstants.SOLR_COMPONENT, component);
+ queryGenerator.setSingleIncludeFilter(logFileTailQuery, LogSearchConstants.SOLR_HOST, host);
+ if (!StringUtils.isBlank(logFile)) {
+ queryGenerator.setSingleIncludeFilter(logFileTailQuery, LogSearchConstants.SOLR_PATH, solrUtil.makeSolrSearchString(logFile));
+ } else if (!StringUtils.isBlank(component)) {
+ queryGenerator.setSingleIncludeFilter(logFileTailQuery, LogSearchConstants.SOLR_COMPONENT, component);
} else {
- throw restErrorUtil.createRESTException("component or logfile parameter must be present",
- MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException("component or logfile parameter must be present", MessageEnums.ERROR_SYSTEM);
}
queryGenerator.setRowCount(logFileTailQuery, tail);
[5/5] ambari git commit: AMBARI-18227. Add unit tests for Log Search
components and refactor them as needed - Vol 1. (Miklos Gergely via oleewere)
Posted by ol...@apache.org.
AMBARI-18227. Add unit tests for Log Search components and refactor them as needed - Vol 1. (Miklos Gergely via oleewere)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/ffcf5328
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/ffcf5328
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/ffcf5328
Branch: refs/heads/branch-dev-logsearch
Commit: ffcf5328eb177f76dfe3b78d6d236453b6651eec
Parents: a565ead
Author: Miklos Gergely <mg...@hortonworks.com>
Authored: Mon Aug 22 18:32:39 2016 +0200
Committer: oleewere <ol...@gmail.com>
Committed: Mon Aug 22 18:32:39 2016 +0200
----------------------------------------------------------------------
.../ambari-logsearch-portal/pom.xml | 16 +
.../org/apache/ambari/logsearch/LogSearch.java | 9 +-
.../logsearch/common/LogSearchConstants.java | 11 -
.../logsearch/common/LogSearchContext.java | 62 +++
.../logsearch/common/LogsearchContextUtil.java | 60 ---
.../logsearch/common/ManageStartEndTime.java | 60 +--
.../ambari/logsearch/common/MessageEnums.java | 43 +-
.../ambari/logsearch/common/RequestContext.java | 143 ------
.../ambari/logsearch/common/SearchCriteria.java | 76 +--
.../logsearch/common/UserSessionInfo.java | 46 --
.../ambari/logsearch/dao/AuditSolrDao.java | 53 +--
.../logsearch/dao/ServiceLogsSolrDao.java | 31 +-
.../ambari/logsearch/dao/SolrDaoBase.java | 462 +++++++------------
.../ambari/logsearch/dao/UserConfigSolrDao.java | 80 ++--
.../apache/ambari/logsearch/dao/UserDao.java | 137 ++----
.../logsearch/dao/UserInfoAttributes.java | 28 --
.../logsearch/graph/GraphDataGenerator.java | 167 +++----
.../logsearch/graph/GraphDataGeneratorBase.java | 203 ++------
.../ambari/logsearch/manager/AuditMgr.java | 323 ++++---------
.../ambari/logsearch/manager/LogFileMgr.java | 71 +--
.../ambari/logsearch/manager/LogsMgr.java | 148 +++---
.../ambari/logsearch/manager/MgrBase.java | 95 ++--
.../ambari/logsearch/manager/PublicMgr.java | 2 +-
.../ambari/logsearch/manager/SessionMgr.java | 38 +-
.../ambari/logsearch/manager/UserConfigMgr.java | 139 ++----
.../ambari/logsearch/query/QueryGeneration.java | 274 ++++-------
.../logsearch/query/QueryGenerationBase.java | 292 +++---------
.../ambari/logsearch/rest/ServiceLogsREST.java | 10 +-
.../context/LogsearchContextHolder.java | 41 --
.../context/LogsearchSecurityContext.java | 55 ---
.../apache/ambari/logsearch/util/BizUtil.java | 94 ++--
.../ambari/logsearch/util/CommonUtil.java | 49 +-
.../ambari/logsearch/util/ConfigUtil.java | 40 +-
.../apache/ambari/logsearch/util/DateUtil.java | 141 +-----
.../apache/ambari/logsearch/util/FileUtil.java | 56 +--
.../apache/ambari/logsearch/util/JSONUtil.java | 136 +-----
.../util/LogsearchPropertiesConfiguration.java | 89 ----
.../ambari/logsearch/util/PropertiesUtil.java | 16 +-
.../apache/ambari/logsearch/util/QueryBase.java | 16 +-
.../ambari/logsearch/util/RESTErrorUtil.java | 2 +-
.../apache/ambari/logsearch/util/SolrUtil.java | 75 +--
.../ambari/logsearch/util/StringUtil.java | 33 --
...LogsearchSecurityContextFormationFilter.java | 28 +-
...rchExternalServerAuthenticationProvider.java | 9 +-
.../LogsearchFileAuthenticationProvider.java | 16 +-
.../LogsearchSimpleAuthenticationProvider.java | 8 +-
.../common/LogSearchContextUtilTest.java | 51 ++
.../common/ManageStartEndTimeTest.java | 35 ++
.../ambari/logsearch/dao/AuditSolrDaoTest.java | 68 +++
.../logsearch/dao/ServiceLogsSolrDaoTest.java | 66 +++
.../ambari/logsearch/dao/SolrDaoBaseTest.java | 286 ++++++++++++
.../logsearch/dao/UserConfigSolrDaoTest.java | 129 ++++++
.../ambari/logsearch/dao/UserDaoTest.java | 58 +++
.../src/test/resources/HadoopServiceConfig.json | 17 +
.../src/test/resources/applicationContext.xml | 53 +++
.../applicationContext_testManagers.xml | 53 +++
.../src/test/resources/logsearch.properties | 32 ++
.../src/test/resources/user_pass.json | 8 +
58 files changed, 1967 insertions(+), 2872 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/pom.xml b/ambari-logsearch/ambari-logsearch-portal/pom.xml
index a886b37..8d345d9 100755
--- a/ambari-logsearch/ambari-logsearch-portal/pom.xml
+++ b/ambari-logsearch/ambari-logsearch-portal/pom.xml
@@ -466,6 +466,17 @@
</profile>
</profiles>
<dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>3.4</version>
+ <scope>test</scope>
+ </dependency>
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
@@ -477,6 +488,11 @@
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
index d1fbcde..fcebcea 100644
--- 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
@@ -24,7 +24,6 @@ import java.net.ServerSocket;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
-import java.util.Timer;
import org.apache.ambari.logsearch.common.ManageStartEndTime;
import org.apache.ambari.logsearch.solr.metrics.SolrMetricsLoader;
@@ -46,7 +45,6 @@ import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.webapp.WebAppContext;
-
public class LogSearch {
private static final Logger logger = Logger.getLogger(LogSearch.class);
@@ -71,8 +69,7 @@ public class LogSearch {
public static void main(String[] argv) {
LogSearch logSearch = new LogSearch();
- Timer timer = new Timer();
- timer.schedule(new ManageStartEndTime(), 0, 40000);
+ ManageStartEndTime.manage();
try {
logSearch.run(argv);
} catch (Throwable e) {
@@ -149,7 +146,7 @@ public class LogSearch {
}
private WebAppContext createBaseWebappContext() throws MalformedURLException {
- URI webResourceBase = findWebResourceBase(LogSearch.class.getClassLoader());
+ URI webResourceBase = findWebResourceBase();
WebAppContext context = new WebAppContext();
context.setBaseResource(Resource.newResource(webResourceBase));
context.setContextPath(ROOT_CONTEXT);
@@ -168,7 +165,7 @@ public class LogSearch {
return context;
}
- private URI findWebResourceBase(ClassLoader classLoader) {
+ private URI findWebResourceBase() {
URL fileCompleteUrl = Thread.currentThread().getContextClassLoader()
.getResource(WEB_RESOURCE_FOLDER);
if (fileCompleteUrl != null) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
index 5dcdac1..142b29b 100644
--- 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
@@ -33,7 +33,6 @@ public class LogSearchConstants {
// 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";
@@ -44,8 +43,6 @@ public class LogSearchConstants {
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";
@@ -73,17 +70,11 @@ public class LogSearchConstants {
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\\|";
@@ -128,7 +119,5 @@ public class LogSearchConstants {
public static final String FACET_GROUP = "group";
public static final String FACET_GROUP_MAIN = "group.main";
public static final String FACET_GROUP_FIELD = "group.field";
- public static final String FACET_LIMIT = "facet.limit";
-
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/LogSearchContext.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/LogSearchContext.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/LogSearchContext.java
new file mode 100644
index 0000000..b4b52b3
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/LogSearchContext.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.common;
+
+import java.io.Serializable;
+
+import org.apache.ambari.logsearch.web.model.User;
+
+public class LogSearchContext implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private User user;
+
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(User user) {
+ this.user = user;
+ }
+
+ //------------------------------------------------------------------------------------------------------
+
+ private static final ThreadLocal<LogSearchContext> contextThreadLocal = new ThreadLocal<LogSearchContext>();
+
+ public static LogSearchContext getContext() {
+ return contextThreadLocal.get();
+ }
+
+ public static void setContext(LogSearchContext context) {
+ contextThreadLocal.set(context);
+ }
+
+ public static void resetContext() {
+ contextThreadLocal.remove();
+ }
+
+ public static String getCurrentUsername() {
+ LogSearchContext context = LogSearchContext.getContext();
+ if (context != null && context.getUser() != null) {
+ return context.getUser().getUsername();
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
deleted file mode 100644
index 617f2fd..0000000
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/LogsearchContextUtil.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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/ffcf5328/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
index 94b7159..b6aa2d0 100644
--- 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
@@ -20,54 +20,36 @@
package org.apache.ambari.logsearch.common;
import java.util.Date;
-import java.util.GregorianCalendar;
+import java.util.Timer;
import java.util.TimerTask;
-import org.apache.log4j.Logger;
+import org.apache.commons.lang.time.DateUtils;
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();
+ private static final int UPDATE_TIME_IN_SECONDS = 40;
+
+ private static Date startDate;
+ private static Date endDate;
+
+ public static void manage() {
+ Timer timer = new Timer();
+ timer.schedule(new ManageStartEndTime(), 0, UPDATE_TIME_IN_SECONDS * 1000);
+ }
+
+ private ManageStartEndTime() {
+ endDate = new Date();
+ startDate = DateUtils.addHours(endDate, -1);
}
@Override
- public void run() {
- if (startDate == null){
- intailizeStartEndTime();
- }else{
- adjustStartEndTime();
+ public synchronized void run() {
+ synchronized (ManageStartEndTime.class) {
+ startDate = DateUtils.addSeconds(startDate, UPDATE_TIME_IN_SECONDS);
+ endDate = DateUtils.addHours(startDate, 1);
}
}
- 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();
+ public static synchronized Date[] getStartEndTime() {
+ return new Date[] {startDate, endDate};
}
-
- 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/ffcf5328/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
index 59e698f..786cf99 100644
--- 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
@@ -23,33 +23,30 @@ import org.apache.ambari.logsearch.view.VMessage;
public enum MessageEnums {
// Common Errors
- DATA_NOT_FOUND("logsearch.error.data_not_found", "Data not found"), OPER_NOT_ALLOWED_FOR_STATE(
- "logsearch.error.oper_not_allowed_for_state",
- "Operation not allowed in current state"), OPER_NOT_ALLOWED_FOR_ENTITY(
- "logsearch.error.oper_not_allowed_for_state",
- "Operation not allowed for entity"), OPER_NO_PERMISSION(
- "logsearch.error.oper_no_permission",
- "User doesn't have permission to perform this operation"), DATA_NOT_UPDATABLE(
- "logsearch.error.data_not_updatable", "Data not updatable"), ERROR_CREATING_OBJECT(
- "logsearch.error.create_object", "Error creating object"), ERROR_DUPLICATE_OBJECT(
- "logsearch.error.duplicate_object", "Error creating duplicate object"), ERROR_SYSTEM(
- "logsearch.error.system", "System Error. Please try later."),
- SOLR_ERROR("logsearch.solr.error","Something went wrong, For more details check the logs or configuration."),
+ DATA_NOT_FOUND("logsearch.error.data_not_found", "Data not found"),
+ OPER_NOT_ALLOWED_FOR_STATE("logsearch.error.oper_not_allowed_for_state", "Operation not allowed in current state"),
+ OPER_NOT_ALLOWED_FOR_ENTITY("logsearch.error.oper_not_allowed_for_state", "Operation not allowed for entity"),
+ OPER_NO_PERMISSION("logsearch.error.oper_no_permission", "User doesn't have permission to perform this operation"),
+ DATA_NOT_UPDATABLE("logsearch.error.data_not_updatable", "Data not updatable"),
+ ERROR_CREATING_OBJECT("logsearch.error.create_object", "Error creating object"),
+ ERROR_DUPLICATE_OBJECT("logsearch.error.duplicate_object", "Error creating duplicate object"),
+ ERROR_SYSTEM("logsearch.error.system", "System Error. Please try later."),
+ SOLR_ERROR("logsearch.solr.error","Something went wrong, For more details check the logs or configuration."),
// Common Validations
- INVALID_PASSWORD("logsearch.validation.invalid_password", "Invalid password"), INVALID_INPUT_DATA(
- "logsearch.validation.invalid_input_data", "Invalid input data"), NO_INPUT_DATA(
- "logsearch.validation.no_input_data", "Input data is not provided"), INPUT_DATA_OUT_OF_BOUND(
- "logsearch.validation.data_out_of_bound", "Input data if out of bound"), NO_NAME(
- "logsearch.validation.no_name", "Name is not provided"), NO_OR_INVALID_COUNTRY_ID(
- "logsearch.validation.no_country_id", "Valid Country Id was not provided"), NO_OR_INVALID_CITY_ID(
- "logsearch.validation.no_city_id", "Valid City Id was not provided"), NO_OR_INVALID_STATE_ID(
- "logsearch.validation.no_state_id", "Valid State Id was not provided");
+ INVALID_PASSWORD("logsearch.validation.invalid_password", "Invalid password"),
+ INVALID_INPUT_DATA("logsearch.validation.invalid_input_data", "Invalid input data"),
+ NO_INPUT_DATA("logsearch.validation.no_input_data", "Input data is not provided"),
+ INPUT_DATA_OUT_OF_BOUND("logsearch.validation.data_out_of_bound", "Input data if out of bound"),
+ NO_NAME("logsearch.validation.no_name", "Name is not provided"),
+ NO_OR_INVALID_COUNTRY_ID("logsearch.validation.no_country_id", "Valid Country Id was not provided"),
+ NO_OR_INVALID_CITY_ID("logsearch.validation.no_city_id", "Valid City Id was not provided"),
+ NO_OR_INVALID_STATE_ID("logsearch.validation.no_state_id", "Valid State Id was not provided");
- String rbKey;
- String messageDesc;
+ private String rbKey;
+ private String messageDesc;
- MessageEnums(String rbKey, String messageDesc) {
+ private MessageEnums(String rbKey, String messageDesc) {
this.rbKey = rbKey;
this.messageDesc = messageDesc;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
deleted file mode 100644
index 83ed3bd..0000000
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/RequestContext.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * 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/ffcf5328/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
index d0facbc..2cf2139 100644
--- 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
@@ -49,44 +49,35 @@ public class SearchCriteria {
public SearchCriteria(HttpServletRequest request) {
try {
- if (request.getParameter("startIndex") != null
- && (!request.getParameter("startIndex").isEmpty())) {
- this.startIndex = new Integer(
- request.getParameter("startIndex"));
+ 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())) {
+ 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())) {
+ if (request.getParameter("pageSize") != null && (!request.getParameter("pageSize").isEmpty())) {
this.maxRows = new Integer(request.getParameter("pageSize"));
} else {
- this.maxRows = PropertiesUtil.getIntProperty("db.maxResults",
- 50);
+ this.maxRows = PropertiesUtil.getIntProperty("db.maxResults", 50);
}
} catch (NumberFormatException e) {
// do nothing
}
// Sort fields
- if (request.getParameter("sortBy") != null
- && (!request.getParameter("sortBy").isEmpty())) {
+ if (request.getParameter("sortBy") != null && (!request.getParameter("sortBy").isEmpty())) {
this.sortBy = "" + request.getParameter("sortBy");
}
- if (request.getParameter("sortType") != null
- && (!request.getParameter("sortType").isEmpty())) {
+ 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())) {
+ 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())) {
+ 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"));
}
@@ -164,31 +155,24 @@ public class SearchCriteria {
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("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("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("component_name", request.getParameter("component_name"));
this.addParam("file_name", request.getParameter("file_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("excludeQuery", StringEscapeUtils.unescapeXml(request.getParameter("excludeQuery")));
+ this.addParam("includeQuery", StringEscapeUtils.unescapeXml(request.getParameter("includeQuery")));
}
/**
@@ -196,20 +180,14 @@ public class SearchCriteria {
*/
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("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("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"));
}
@@ -220,9 +198,9 @@ public class SearchCriteria {
*/
public void addParam(String name, Object value) {
String solrValue = PropertiesUtil.getProperty(name);
- if (solrValue == null || solrValue.isEmpty()){
+ if (solrValue == null || solrValue.isEmpty()) {
paramList.put(name, value);
- }else {
+ } else {
try {
String propertyFieldMappings[] = solrValue.split(",");
HashMap<String, String> propertyFieldValue = new HashMap<String, String>();
@@ -253,14 +231,6 @@ public class SearchCriteria {
}
/**
- * @param string
- * @param caId
- */
- public Object removeParam(String name) {
- return paramList.remove(name);
- }
-
- /**
* @return the nullParamList
*/
public Set<String> getNullParamList() {
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
deleted file mode 100644
index 78fea31..0000000
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/UserSessionInfo.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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;
-
- private 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/ffcf5328/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
index 5a56ad7..a6f77e9 100644
--- 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
@@ -19,13 +19,14 @@
package org.apache.ambari.logsearch.dao;
-import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import javax.annotation.PostConstruct;
-import org.apache.ambari.logsearch.manager.MgrBase.LOG_TYPE;
+import org.apache.ambari.logsearch.manager.MgrBase.LogType;
import org.apache.ambari.logsearch.util.PropertiesUtil;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -35,50 +36,36 @@ public class AuditSolrDao extends SolrDaoBase {
static private Logger logger = Logger.getLogger(AuditSolrDao.class);
public AuditSolrDao() {
- super(LOG_TYPE.AUDIT);
+ super(LogType.AUDIT);
}
@PostConstruct
public void postConstructor() {
String solrUrl = PropertiesUtil.getProperty("logsearch.solr.audit.logs.url");
String zkConnectString = PropertiesUtil.getProperty("logsearch.solr.audit.logs.zk_connect_string");
- String collection = PropertiesUtil.getProperty(
- "logsearch.solr.collection.audit.logs", "audit_logs");
- String aliasNameIn = PropertiesUtil.getProperty(
- "logsearch.solr.audit.logs.alias.name", "audit_logs_alias");
- String rangerAuditCollection = PropertiesUtil.getProperty(
- "logsearch.ranger.audit.logs.collection.name");
- String splitInterval = PropertiesUtil.getProperty(
- "logsearch.audit.logs.split.interval.mins", "none");
- String configName = PropertiesUtil.getProperty(
- "logsearch.solr.audit.logs.config.name", "audit_logs");
- int numberOfShards = PropertiesUtil.getIntProperty(
- "logsearch.collection.audit.logs.numshards", 1);
- int replicationFactor = PropertiesUtil.getIntProperty(
- "logsearch.collection.audit.logs.replication.factor", 1);
+ String collection = PropertiesUtil.getProperty("logsearch.solr.collection.audit.logs", "audit_logs");
+ String aliasNameIn = PropertiesUtil.getProperty("logsearch.solr.audit.logs.alias.name", "audit_logs_alias");
+ String rangerAuditCollection = PropertiesUtil.getProperty("logsearch.ranger.audit.logs.collection.name");
+ String splitInterval = PropertiesUtil.getProperty("logsearch.audit.logs.split.interval.mins", "none");
+ String configName = PropertiesUtil.getProperty("logsearch.solr.audit.logs.config.name", "audit_logs");
+ int numberOfShards = PropertiesUtil.getIntProperty("logsearch.collection.audit.logs.numshards", 1);
+ int replicationFactor = PropertiesUtil.getIntProperty("logsearch.collection.audit.logs.replication.factor", 1);
try {
connectToSolr(solrUrl, zkConnectString, collection);
- boolean createAlias = false;
- if (aliasNameIn != null && rangerAuditCollection != null
- && rangerAuditCollection.trim().length() > 0) {
- createAlias = true;
- }
+
+ boolean createAlias = (aliasNameIn != null && !StringUtils.isBlank(rangerAuditCollection));
boolean needToPopulateSchemaField = !createAlias;
- setupCollections(splitInterval, configName, numberOfShards,
- replicationFactor, needToPopulateSchemaField);
- if(createAlias) {
- Collection<String> collectionsIn = new ArrayList<String>();
- collectionsIn.add(collection);
- collectionsIn.add(rangerAuditCollection.trim());
+
+ setupCollections(splitInterval, configName, numberOfShards, replicationFactor, needToPopulateSchemaField);
+
+ if (createAlias) {
+ Collection<String> collectionsIn = Arrays.asList(collection, rangerAuditCollection.trim());
setupAlias(aliasNameIn, collectionsIn);
}
} catch (Exception e) {
- logger.error(
- "Error while connecting to Solr for audit logs : solrUrl="
- + solrUrl + ", zkConnectString=" + zkConnectString
- + ", collection=" + collection, e);
+ logger.error("Error while connecting to Solr for audit logs : solrUrl=" + solrUrl + ", zkConnectString=" +
+ zkConnectString + ", collection=" + collection, e);
}
}
-
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
index 5aba6d1..af6d62d 100644
--- 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
@@ -21,7 +21,7 @@ package org.apache.ambari.logsearch.dao;
import javax.annotation.PostConstruct;
-import org.apache.ambari.logsearch.manager.MgrBase.LOG_TYPE;
+import org.apache.ambari.logsearch.manager.MgrBase.LogType;
import org.apache.ambari.logsearch.util.PropertiesUtil;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -29,10 +29,10 @@ import org.springframework.stereotype.Component;
@Component
public class ServiceLogsSolrDao extends SolrDaoBase {
- static private Logger logger = Logger.getLogger(ServiceLogsSolrDao.class);
+ private static final Logger logger = Logger.getLogger(ServiceLogsSolrDao.class);
public ServiceLogsSolrDao() {
- super(LOG_TYPE.SERVICE);
+ super(LogType.SERVICE);
}
@PostConstruct
@@ -40,27 +40,18 @@ public class ServiceLogsSolrDao extends SolrDaoBase {
logger.info("postConstructor() called.");
String solrUrl = PropertiesUtil.getProperty("logsearch.solr.url");
String zkConnectString = PropertiesUtil.getProperty("logsearch.solr.zk_connect_string");
- String collection = PropertiesUtil.getProperty("logsearch.solr.collection.service.logs",
- "hadoop_logs");
- String splitInterval = PropertiesUtil.getProperty(
- "logsearch.service.logs.split.interval.mins", "none");
- String configName = PropertiesUtil.getProperty(
- "logsearch.solr.service.logs.config.name", "hadoop_logs");
- int numberOfShards = PropertiesUtil.getIntProperty(
- "logsearch.collection.service.logs.numshards", 1);
- int replicationFactor = PropertiesUtil.getIntProperty(
- "logsearch.collection.service.logs.replication.factor", 1);
+ String collection = PropertiesUtil.getProperty("logsearch.solr.collection.service.logs", "hadoop_logs");
+ String splitInterval = PropertiesUtil.getProperty("logsearch.service.logs.split.interval.mins", "none");
+ String configName = PropertiesUtil.getProperty("logsearch.solr.service.logs.config.name", "hadoop_logs");
+ int numberOfShards = PropertiesUtil.getIntProperty("logsearch.collection.service.logs.numshards", 1);
+ int replicationFactor = PropertiesUtil.getIntProperty("logsearch.collection.service.logs.replication.factor", 1);
try {
connectToSolr(solrUrl, zkConnectString, collection);
- setupCollections(splitInterval, configName, numberOfShards,
- replicationFactor,true);
+ setupCollections(splitInterval, configName, numberOfShards, replicationFactor, true);
} catch (Exception e) {
- logger.error(
- "error while connecting to Solr for service logs : solrUrl="
- + solrUrl + ", zkConnectString=" + zkConnectString
- + ", collection=" + collection, e);
+ logger.error("error while connecting to Solr for service logs : solrUrl=" + solrUrl + ", zkConnectString=" +
+ zkConnectString + ", collection=" + collection, e);
}
}
-
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
index cda5e26..2129f9e 100644
--- 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
@@ -24,16 +24,16 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
-import org.apache.ambari.logsearch.common.LogsearchContextUtil;
+
+import org.apache.ambari.logsearch.common.LogSearchContext;
import org.apache.ambari.logsearch.common.MessageEnums;
-import org.apache.ambari.logsearch.manager.MgrBase.LOG_TYPE;
+import org.apache.ambari.logsearch.manager.MgrBase.LogType;
import org.apache.ambari.logsearch.util.ConfigUtil;
import org.apache.ambari.logsearch.util.JSONUtil;
import org.apache.ambari.logsearch.util.PropertiesUtil;
import org.apache.ambari.logsearch.util.RESTErrorUtil;
-import org.apache.ambari.logsearch.util.StringUtil;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
@@ -58,104 +58,87 @@ import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.NamedList;
import org.springframework.beans.factory.annotation.Autowired;
+import com.google.common.annotations.VisibleForTesting;
+
public abstract class SolrDaoBase {
- static private Logger logger = Logger.getLogger(SolrDaoBase.class);
+ private static final Logger logger = Logger.getLogger(SolrDaoBase.class);
+ private static final Logger logPerformance = Logger.getLogger("org.apache.ambari.logsearch.performance");
public HashMap<String, String> schemaFieldsNameMap = new HashMap<String, String>();
public HashMap<String, String> schemaFieldTypeMap = new HashMap<String, String>();
-
- private static Logger logPerformance = Logger
- .getLogger("org.apache.ambari.logsearch.performance");
private static final String ROUTER_FIELD = "_router_field_";
-
- protected LOG_TYPE logType;
+
+ private static final int SETUP_RETRY_SECOND = 30;
+ private static final int SETUP_UPDATE_SECOND = 10*60; //10 min
+ private static final int ALIAS_SETUP_RETRY_SECOND = 30*60;
- @Autowired
- StringUtil stringUtil;
+ private LogType logType;
@Autowired
- JSONUtil jsonUtil;
-
+ protected JSONUtil jsonUtil;
@Autowired
- RESTErrorUtil restErrorUtil;
-
- String collectionName = null;
+ protected RESTErrorUtil restErrorUtil;
+
+ @VisibleForTesting
+ protected String collectionName = null;
+ @VisibleForTesting
+ protected SolrClient solrClient = null;
+ @VisibleForTesting
+ protected CloudSolrClient solrClouldClient = null;
+ @VisibleForTesting
+ protected boolean isZkConnectString = false;
- String aliasName = null;
- Collection<String> aliasCollectionList = new ArrayList<String>();
-
- private SolrClient solrClient = null;
- CloudSolrClient solrClouldClient = null;
-
- boolean isSolrCloud = true;
- String solrDetail = "";
-
- boolean isSolrInitialized = false;
-
- private boolean setup_status = false;
+ private String solrDetail = "";
private boolean populateFieldsThreadActive = false;
-
- int SETUP_RETRY_SECOND = 30;
- int SETUP_UPDATE_SECOND = 10*60; //10 min
- int ALIAS_SETUP_RETRY_SECOND = 30*60; //30 minutes
- private boolean isZkConnectString=false;//by default its false
-
- //set logtype
- public SolrDaoBase(LOG_TYPE logType) {
+ protected SolrDaoBase(LogType logType) {
this.logType = logType;
}
- public SolrClient connectToSolr(String url, String zkConnectString,
- String collection) throws Exception {
+ protected SolrClient connectToSolr(String url, String zkConnectString, String collection) throws Exception {
this.collectionName = collection;
- solrDetail = "zkConnectString=" + zkConnectString + ", collection=" + collection
- + ", url=" + url;
+ solrDetail = "zkConnectString=" + zkConnectString + ", collection=" + collection + ", url=" + url;
logger.info("connectToSolr() " + solrDetail);
- if (stringUtil.isEmpty(collection)) {
- throw new Exception("For solr, collection name is mandatory. "
- + solrDetail);
+ if (StringUtils.isBlank(collection)) {
+ throw new Exception("For solr, collection name is mandatory. " + solrDetail);
}
+
setupSecurity();
- if (!stringUtil.isEmpty(zkConnectString)) {
- isZkConnectString=true;
+
+ if (solrClient != null) {
+ return solrClient;
+ }
+
+ if (!StringUtils.isBlank(zkConnectString)) {
+ isZkConnectString = true;
solrDetail = "zkConnectString=" + zkConnectString + ", collection=" + collection;
- logger.info("Using zookeepr. " + solrDetail);
+ logger.info("Using zookeeper. " + solrDetail);
solrClouldClient = new CloudSolrClient(zkConnectString);
solrClouldClient.setDefaultCollection(collection);
solrClient = solrClouldClient;
int waitDurationMS = 3 * 60 * 1000;
checkSolrStatus(waitDurationMS);
} else {
- if (stringUtil.isEmpty(url)) {
- throw new Exception("Both zkConnectString and URL are empty. zkConnectString="
- + zkConnectString + ", collection=" + collection + ", url="
- + url);
+ if (StringUtils.isBlank(url)) {
+ throw new Exception("Both zkConnectString and URL are empty. zkConnectString=" + zkConnectString + ", " +
+ "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) {
+ protected boolean checkSolrStatus(int waitDurationMS) {
boolean status = false;
try {
long beginTimeMS = System.currentTimeMillis();
@@ -166,10 +149,7 @@ public abstract class SolrDaoBase {
try {
List<String> collectionList = getCollections();
if (collectionList != null) {
- logger.info("checkSolrStatus(): Solr getCollections() is success. solr="
- + solrDetail
- + ", collectionList="
- + collectionList);
+ logger.info("checkSolrStatus(): Solr getCollections() is success. solr=" + solrDetail + ", collectionList=" + collectionList);
status = true;
break;
}
@@ -177,17 +157,12 @@ public abstract class SolrDaoBase {
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);
+ 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);
+ 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);
@@ -198,37 +173,34 @@ public abstract class SolrDaoBase {
return status;
}
- public void setupAlias(final String aliasNameIn, final Collection<String> collectionListIn ) throws Exception {
- if( aliasNameIn == null || collectionListIn== null || collectionListIn.size() == 0 || solrClouldClient == null) {
- logger.info("Will not create alias " + aliasNameIn + " for "
- + (collectionListIn==null?null: collectionListIn.toString()) + ", solrCloudClient=" + solrClouldClient);
+ protected void setupAlias(final String aliasNameIn, final Collection<String> collectionListIn ) throws Exception {
+ if (aliasNameIn == null || collectionListIn == null || collectionListIn.size() == 0 || solrClouldClient == null) {
+ logger.info("Will not create alias " + aliasNameIn + " for " +
+ (collectionListIn == null ? null: collectionListIn.toString()) + ", solrCloudClient=" + solrClouldClient);
return;
}
- logger.info("setupAlias " + aliasNameIn + " for " + (collectionListIn==null?null: collectionListIn.toString()));
- aliasName = aliasNameIn;
- aliasCollectionList = collectionListIn;
-
+
+ logger.info("setupAlias " + aliasNameIn + " for " + (collectionListIn == null ? null: collectionListIn.toString()));
// Start a background thread to do setup
Thread setupThread = new Thread("setup_alias_" + aliasNameIn) {
@Override
public void run() {
- logger.info("Started monitoring thread to check availability of Solr server. alias="
- + aliasNameIn + ", collections=" + collectionListIn.toString());
+ logger.info("Started monitoring thread to check availability of Solr server. alias=" + aliasNameIn +
+ ", collections=" + collectionListIn.toString());
int retryCount = 0;
while (true) {
try {
- int count = createAlias(aliasNameIn,collectionListIn);
+ int count = createAlias(aliasNameIn, collectionListIn);
if (count > 0) {
solrClouldClient.setDefaultCollection(aliasNameIn);
- if( count == collectionListIn.size()) {
- logger.info("Setup for alias " + aliasNameIn
- + " is successful. Exiting setup retry thread. Collections=" + collectionListIn);
+ if (count == collectionListIn.size()) {
+ logger.info("Setup for alias " + aliasNameIn + " is successful. Exiting setup retry thread. " +
+ "Collections=" + collectionListIn);
populateSchemaFields();
break;
}
} else {
- logger.warn("Not able to create alias="
- + aliasNameIn + ", retryCount=" + retryCount);
+ logger.warn("Not able to create alias=" + aliasNameIn + ", retryCount=" + retryCount);
}
} catch (Exception e) {
logger.error("Error setting up alias=" + aliasNameIn, e);
@@ -236,8 +208,7 @@ public abstract class SolrDaoBase {
try {
Thread.sleep(ALIAS_SETUP_RETRY_SECOND * 1000);
} catch (InterruptedException sleepInterrupted) {
- logger.info("Sleep interrupted while setting up alias "
- + aliasNameIn);
+ logger.info("Sleep interrupted while setting up alias " + aliasNameIn);
break;
}
retryCount++;
@@ -245,93 +216,64 @@ public abstract class SolrDaoBase {
}
};
setupThread.setDaemon(true);
- setupThread.start();
+ setupThread.start();
}
- /**
- * @param aliasNameIn
- * @param collectionListIn
- * @return
- * @throws IOException
- * @throws SolrServerException
- */
- protected int createAlias(String aliasNameIn,
- Collection<String> collectionListIn) throws SolrServerException, IOException {
- List<String> collections = getCollections();
- List<String> collectionToAdd = new ArrayList<String>();
- for (String col : collections) {
- if( collectionListIn.contains(col)) {
- collectionToAdd.add(col);
- }
- }
+ private int createAlias(String aliasNameIn, Collection<String> collectionListIn) throws SolrServerException, IOException {
+ List<String> collectionToAdd = getCollections();
+ collectionToAdd.retainAll(collectionListIn);
+
String collectionsCSV = null;
- if( collectionToAdd.size() > 0 ) {
- for (String col : collectionToAdd) {
- if(collectionsCSV == null) {
- collectionsCSV = col;
- } else {
- collectionsCSV = collectionsCSV + "," + col;
- }
- }
+ if (!collectionToAdd.isEmpty()) {
+ collectionsCSV = StringUtils.join(collectionToAdd, ',');
CollectionAdminRequest.CreateAlias aliasCreateRequest = new CollectionAdminRequest.CreateAlias();
aliasCreateRequest.setAliasName(aliasNameIn);
aliasCreateRequest.setAliasedCollections(collectionsCSV);
CollectionAdminResponse createResponse = aliasCreateRequest.process(solrClouldClient);
if (createResponse.getStatus() != 0) {
- logger.error("Error creating alias. alias="
- + aliasNameIn + ", collectionList=" + collectionsCSV
- + ", solrDetail=" + solrDetail + ", response="
- + createResponse);
+ logger.error("Error creating alias. alias=" + aliasNameIn + ", collectionList=" + collectionsCSV +
+ ", solrDetail=" + solrDetail + ", response=" + createResponse);
return 0;
}
}
- if( collectionToAdd.size() == collectionListIn.size()) {
- logger.info("Created alias for all collections. alias=" + aliasNameIn + ", collectionsCSV="
- + collectionsCSV + ", solrDetail=" + solrDetail);
+ if ( collectionToAdd.size() == collectionListIn.size()) {
+ logger.info("Created alias for all collections. alias=" + aliasNameIn + ", collectionsCSV=" + collectionsCSV +
+ ", solrDetail=" + solrDetail);
} else {
- logger.info("Created alias for " + collectionToAdd.size() + " out of " +
- + collectionListIn.size() + " collections. alias=" + aliasNameIn
- + ", collectionsCSV=" + collectionsCSV + ", solrDetail=" + solrDetail);
+ logger.info("Created alias for " + collectionToAdd.size() + " out of " + collectionListIn.size() + " collections. " +
+ "alias=" + aliasNameIn + ", collectionsCSV=" + collectionsCSV + ", solrDetail=" + solrDetail);
}
return collectionToAdd.size();
}
- public void setupCollections(final String splitMode, final String configName,
- final int numberOfShards, final int replicationFactor,boolean needToPopulateSchemaField) throws Exception {
+ protected void setupCollections(final String splitInterval, final String configName, final int numberOfShards,
+ final int replicationFactor, boolean needToPopulateSchemaField) throws Exception {
if (isZkConnectString) {
- setup_status = createCollectionsIfNeeded(splitMode, configName,
- numberOfShards, replicationFactor);
- logger.info("Setup status for " + collectionName + " is " + setup_status);
- if (!setup_status) {
+ boolean setupStatus = createCollectionsIfNeeded(splitInterval, configName, numberOfShards, replicationFactor);
+ logger.info("Setup status for " + collectionName + " is " + setupStatus);
+ if (!setupStatus) {
// 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);
+ logger.info("Started monitoring thread to check availability of Solr server. collection=" + collectionName);
int retryCount = 0;
while (true) {
try {
Thread.sleep(SETUP_RETRY_SECOND * 1000);
retryCount++;
- setup_status = createCollectionsIfNeeded(splitMode, configName,
- numberOfShards, replicationFactor);
- if (setup_status) {
- logger.info("Setup for collection " + collectionName
- + " is successful. Exiting setup retry thread");
+ boolean setupStatus = createCollectionsIfNeeded(splitInterval, configName, numberOfShards, replicationFactor);
+ if (setupStatus) {
+ 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);
+ 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 up collection=" + collectionName, e);
}
- logger.error("Error setting collection. collection="
- + collectionName + ", retryCount=" + retryCount);
+ logger.error("Error setting collection. collection=" + collectionName + ", retryCount=" + retryCount);
}
}
};
@@ -339,46 +281,39 @@ public abstract class SolrDaoBase {
setupThread.start();
}
}
- if(needToPopulateSchemaField){
+
+ if (needToPopulateSchemaField){
populateSchemaFields();
}
}
- public boolean createCollectionsIfNeeded(final String splitMode,
- final String configName, final int numberOfShards,
- final int replicationFactor) {
+ private boolean createCollectionsIfNeeded(String splitInterval, String configName, int numberOfShards, 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);
+ if (splitInterval.equalsIgnoreCase("none")) {
+ result = createCollection(configName, numberOfShards, replicationFactor, allCollectionList);
} else {
- result = setupCollectionsWithImplicitRouting(splitMode,
- configName, numberOfShards, replicationFactor, allCollectionList);
+ result = setupCollectionsWithImplicitRouting(configName, numberOfShards, replicationFactor, allCollectionList);
}
} catch (Exception ex) {
- logger.error("Error creating collection. collectionName="
- + collectionName, ex);
+ logger.error("Error creating collection. collectionName=" + collectionName, ex);
}
return result;
}
- public List<String> getCollections() throws SolrServerException,
+ private 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);
+ logger.error("Error getting collection list from solr. response=" + response);
return null;
}
@SuppressWarnings("unchecked")
- List<String> allCollectionList = (List<String>) response
- .getResponse().get("collections");
+ List<String> allCollectionList = (List<String>) response.getResponse().get("collections");
return allCollectionList;
} catch (SolrException e) {
logger.error(e);
@@ -386,91 +321,61 @@ public abstract class SolrDaoBase {
}
}
- public boolean setupCollectionsWithImplicitRouting(String splitMode,
- String configName, int numberOfShards, int replicationFactor,
+ private boolean setupCollectionsWithImplicitRouting(String configName, int numberOfShards, int replicationFactor,
List<String> allCollectionList) throws Exception {
- logger.info("setupCollectionsWithImplicitRouting(). collectionName="
- + collectionName + ", numberOfShards=" + numberOfShards);
- return createCollectionWithImplicitRoute(collectionName, configName,
- numberOfShards, replicationFactor, allCollectionList);
- }
-
- public boolean createCollectionWithImplicitRoute(String colName,
- String configName, int numberOfShards, int replicationFactor,
- List<String> allCollectionList) throws SolrServerException,
- IOException {
+ logger.info("setupCollectionsWithImplicitRouting(). collectionName=" + collectionName + ", numberOfShards=" + numberOfShards);
- // Default is true, because if the collection and shard is already
- // there, then it will return true
+ // 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);
+ shardsList.add("shard" + i);
}
+ String shardsListStr = StringUtils.join(shardsList, ',');
// Check if collection is already in zookeeper
- if (!allCollectionList.contains(colName)) {
- logger.info("Creating collection " + colName + ", shardsList="
- + shardsList + ", solrDetail=" + solrDetail);
+ if (!allCollectionList.contains(collectionName)) {
+ logger.info("Creating collection " + collectionName + ", shardsList=" + shardsList + ", solrDetail=" + solrDetail);
CollectionAdminRequest.Create collectionCreateRequest = new CollectionAdminRequest.Create();
- collectionCreateRequest.setCollectionName(colName);
+ collectionCreateRequest.setCollectionName(collectionName);
collectionCreateRequest.setRouterName("implicit");
collectionCreateRequest.setShards(shardsListStr);
- collectionCreateRequest.setMaxShardsPerNode(numberOfShards);
+ collectionCreateRequest.setNumShards(numberOfShards);
collectionCreateRequest.setReplicationFactor(replicationFactor);
collectionCreateRequest.setConfigName(configName);
collectionCreateRequest.setRouterField(ROUTER_FIELD);
- collectionCreateRequest.setMaxShardsPerNode(replicationFactor
- * numberOfShards);
+ collectionCreateRequest.setMaxShardsPerNode(replicationFactor * numberOfShards);
- CollectionAdminResponse createResponse = collectionCreateRequest
- .process(solrClient);
+ CollectionAdminResponse createResponse = collectionCreateRequest.process(solrClient);
if (createResponse.getStatus() != 0) {
returnValue = false;
- logger.error("Error creating collection. collectionName="
- + colName + ", shardsList=" + shardsList
- + ", solrDetail=" + solrDetail + ", response="
- + createResponse);
+ logger.error("Error creating collection. collectionName=" + collectionName + ", shardsList=" + shardsList +
+ ", solrDetail=" + solrDetail + ", response=" + createResponse);
} else {
- logger.info("Created collection " + colName + ", shardsList="
- + shardsList + ", solrDetail=" + solrDetail);
+ logger.info("Created collection " + collectionName + ", shardsList=" + shardsList + ", solrDetail=" + solrDetail);
}
} else {
- logger.info("Collection "
- + colName
- + " is already there. Will check whether it has the required shards");
+ logger.info("Collection " + collectionName + " 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);
+ 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);
+ CollectionAdminResponse response = createShardRequest.process(solrClient);
if (response.getStatus() != 0) {
- logger.error("Error creating shard " + shard
- + " in collection " + collectionName
- + ", response=" + response
- + ", solrDetail=" + solrDetail);
+ 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);
+ logger.info("Successfully created shard " + shard + " in collection " + collectionName);
}
} catch (Throwable t) {
- logger.error("Error creating shard " + shard
- + " in collection " + collectionName
- + ", solrDetail=" + solrDetail, t);
+ logger.error("Error creating shard " + shard + " in collection " + collectionName + ", solrDetail=" + solrDetail, t);
returnValue = false;
break;
}
@@ -480,7 +385,7 @@ public abstract class SolrDaoBase {
return returnValue;
}
- public Collection<String> getShards() {
+ private Collection<String> getShards() {
Collection<String> list = new HashSet<String>();
if (solrClouldClient == null) {
@@ -489,106 +394,76 @@ public abstract class SolrDaoBase {
}
ZkStateReader reader = solrClouldClient.getZkStateReader();
- Collection<Slice> slices = reader.getClusterState().getSlices(
- collectionName);
- Iterator<Slice> iter = slices.iterator();
-
- while (iter.hasNext()) {
- Slice slice = iter.next();
+ Collection<Slice> slices = reader.getClusterState().getSlices(collectionName);
+ for (Slice slice : slices) {
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"));
+ 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");
+ private boolean createCollection(String configName, int numberOfShards, int replicationFactor,
+ List<String> allCollectionList) throws SolrServerException, IOException {
+ if (allCollectionList.contains(collectionName)) {
+ logger.info("Collection " + collectionName + " is already there. Won't create it");
return true;
}
- logger.info("Creating collection " + colName + ", numberOfShards="
- + numberOfShards + ", replicationFactor=" + replicationFactor
- + ", solrDetail=" + solrDetail);
+ logger.info("Creating collection " + collectionName + ", numberOfShards=" + numberOfShards +
+ ", replicationFactor=" + replicationFactor + ", solrDetail=" + solrDetail);
CollectionAdminRequest.Create collectionCreateRequest = new CollectionAdminRequest.Create();
- collectionCreateRequest.setCollectionName(colName);
+ collectionCreateRequest.setCollectionName(collectionName);
collectionCreateRequest.setNumShards(numberOfShards);
collectionCreateRequest.setReplicationFactor(replicationFactor);
collectionCreateRequest.setConfigName(configName);
- collectionCreateRequest.setMaxShardsPerNode(replicationFactor
- * numberOfShards);
- CollectionAdminResponse createResponse = collectionCreateRequest
- .process(solrClient);
+ collectionCreateRequest.setMaxShardsPerNode(replicationFactor * numberOfShards);
+ CollectionAdminResponse createResponse = collectionCreateRequest.process(solrClient);
if (createResponse.getStatus() != 0) {
- logger.error("Error creating collection. collectionName=" + colName
- + ", solrDetail=" + solrDetail + ", response="
- + createResponse);
+ logger.error("Error creating collection. collectionName=" + collectionName + ", solrDetail=" + solrDetail + ", response=" +
+ createResponse);
return false;
} else {
- logger.info("Created collection " + colName + ", numberOfShards="
- + numberOfShards + ", replicationFactor="
- + replicationFactor + ", solrDetail=" + solrDetail);
+ logger.info("Created collection " + collectionName + ", numberOfShards=" + numberOfShards +
+ ", replicationFactor=" + replicationFactor + ", solrDetail=" + solrDetail);
return true;
}
}
- public QueryResponse process(SolrQuery solrQuery)
- throws SolrServerException, IOException {
+ public QueryResponse process(SolrQuery solrQuery) throws SolrServerException, IOException {
if (solrClient != null) {
String event = solrQuery.get("event");
solrQuery.remove("event");
- QueryResponse queryResponse = solrClient.query(solrQuery,
- METHOD.POST);
+ QueryResponse queryResponse = solrClient.query(solrQuery, METHOD.POST);
if (event != null && !"/audit/logs/live/count".equalsIgnoreCase(event)) {
- logPerformance.info("\n Username :- "
- + LogsearchContextUtil.getCurrentUsername()
- + " Event :- " + event + " SolrQuery :- " + solrQuery
- + "\nQuery Time Execution :- "
- + queryResponse.getQTime()
- + " Total Time Elapsed is :- "
- + queryResponse.getElapsedTime());
+ logPerformance.info("\n Username :- " + LogSearchContext.getCurrentUsername() + " Event :- " + event + " SolrQuery :- " +
+ solrQuery + "\nQuery Time Execution :- " + queryResponse.getQTime() + " Total Time Elapsed is :- " +
+ queryResponse.getElapsedTime());
}
return queryResponse;
} else {
- throw restErrorUtil.createRESTException(
- "Solr configuration improper for " + logType.getLabel() +" logs",
+ throw restErrorUtil.createRESTException("Solr configuration improper for " + logType.getLabel() +" logs",
MessageEnums.ERROR_SYSTEM);
}
}
- public UpdateResponse addDocs(SolrInputDocument doc)
- throws SolrServerException, IOException, SolrException {
+ public UpdateResponse addDocs(SolrInputDocument doc) throws SolrServerException, IOException, SolrException {
UpdateResponse updateResoponse = solrClient.add(doc);
- logPerformance.info("\n Username :- "
- + LogsearchContextUtil.getCurrentUsername()
- + " Update Time Execution :- " + updateResoponse.getQTime()
- + " Total Time Elapsed is :- "
- + updateResoponse.getElapsedTime());
+ logPerformance.info("\n Username :- " + LogSearchContext.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 {
+ public UpdateResponse removeDoc(String query) throws SolrServerException, IOException, SolrException {
UpdateResponse updateResoponse = solrClient.deleteByQuery(query);
solrClient.commit();
- logPerformance.info("\n Username :- "
- + LogsearchContextUtil.getCurrentUsername()
- + " Remove Time Execution :- " + updateResoponse.getQTime()
- + " Total Time Elapsed is :- "
- + updateResoponse.getElapsedTime());
+ logPerformance.info("\n Username :- " + LogSearchContext.getCurrentUsername() +
+ " Remove Time Execution :- " + updateResoponse.getQTime() + " Total Time Elapsed is :- " + updateResoponse.getElapsedTime());
return updateResoponse;
}
@@ -605,14 +480,11 @@ public abstract class SolrDaoBase {
private void populateSchemaFields() {
if (!populateFieldsThreadActive) {
populateFieldsThreadActive = true;
- logger.info("Creating thread to populated fields for collection="
- + collectionName);
- Thread fieldPopulationThread = new Thread("populated_fields_"
- + collectionName) {
+ 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);
+ logger.info("Started thread to get fields for collection=" + collectionName);
int retryCount = 0;
while (true) {
try {
@@ -620,24 +492,19 @@ public abstract class SolrDaoBase {
retryCount++;
boolean _result = _populateSchemaFields();
if (_result) {
- logger.info("Populate fields for collection " + collectionName
- + " is success, Update it after " + SETUP_UPDATE_SECOND
- + " sec");
+ logger.info("Populate fields for collection " + collectionName + " is success, Update it after " +
+ SETUP_UPDATE_SECOND + " sec");
Thread.sleep(SETUP_UPDATE_SECOND * 1000);
}
} catch (InterruptedException sleepInterrupted) {
- logger
- .info("Sleep interrupted while populating fields for collection "
- + collectionName);
+ 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);
+ logger.error("Error while populating fields for collection " + collectionName + ", retryCount=" + retryCount);
}
}
populateFieldsThreadActive = false;
- logger.info("Exiting thread for populating fields. collection="
- + collectionName);
+ logger.info("Exiting thread for populating fields. collection=" + collectionName);
}
};
fieldPopulationThread.setDaemon(true);
@@ -657,16 +524,13 @@ public abstract class SolrDaoBase {
NamedList<Object> namedList = null;
try {
namedList = solrClient.request(request);
- logger.info("populateSchemaFields() collection="
- + collectionName + ", fields=" + namedList);
+ logger.info("populateSchemaFields() collection=" + collectionName + ", fields=" + namedList);
} catch (SolrException | SolrServerException | IOException e) {
- logger.error(
- "Error occured while popuplating field. collection="
- + collectionName, e);
+ logger.error("Error occured while popuplating field. collection=" + collectionName, e);
}
+
if (namedList != null) {
- ConfigUtil.extractSchemaFieldsName(namedList.toString(),
- schemaFieldsNameMap,schemaFieldTypeMap);
+ ConfigUtil.extractSchemaFieldsName(namedList.toString(), schemaFieldsNameMap,schemaFieldTypeMap);
return true;
}
}
[2/5] ambari git commit: AMBARI-18227. Add unit tests for Log Search
components and refactor them as needed - Vol 1. (Miklos Gergely via oleewere)
Posted by ol...@apache.org.
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGenerationBase.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGenerationBase.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGenerationBase.java
index a128098..ca6df65 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGenerationBase.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/query/QueryGenerationBase.java
@@ -29,56 +29,47 @@ import org.apache.ambari.logsearch.dao.ServiceLogsSolrDao;
import org.apache.ambari.logsearch.util.JSONUtil;
import org.apache.ambari.logsearch.util.QueryBase;
import org.apache.ambari.logsearch.util.SolrUtil;
-import org.apache.ambari.logsearch.util.StringUtil;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrQuery.ORDER;
import org.springframework.beans.factory.annotation.Autowired;
import com.google.gson.Gson;
-import com.sun.jersey.api.spring.Autowire;
public abstract class QueryGenerationBase extends QueryBase {
- static Logger logger = Logger.getLogger(QueryGenerationBase.class);
+ private static final Logger logger = Logger.getLogger(QueryGenerationBase.class);
@Autowired
- SolrUtil solrUtil;
-
- @Autowired
- StringUtil stringUtil;
-
- @Autowired
- JSONUtil jsonUtil;
+ protected SolrUtil solrUtil;
@Autowired
- AuditSolrDao auditSolrDao;
+ protected AuditSolrDao auditSolrDao;
@Autowired
- ServiceLogsSolrDao serviceLogsSolrDao;
-
+ protected ServiceLogsSolrDao serviceLogsSolrDao;
+ @Autowired
+ protected JSONUtil jsonUtil;
- public static enum CONDITION {
+ public static enum Condition {
OR, AND
}
// SetMethods to apply to the query
- public void setFilterClauseForSolrSearchableString(SolrQuery solrQuery,
- String commaSepratedString, CONDITION condition, String operator,
- String messageField) {
+ protected void setFilterClauseForSolrSearchableString(SolrQuery solrQuery, String commaSepratedString, Condition condition,
+ String operator, String messageField) {
String filterQuery = "";
- if (!stringUtil.isEmpty(commaSepratedString)) {
+ if (!StringUtils.isBlank(commaSepratedString)) {
StringBuilder queryMsg = new StringBuilder();
operator = (operator == null ? LogSearchConstants.NO_OPERATOR : operator);
- String[] msgList = commaSepratedString
- .split(LogSearchConstants.I_E_SEPRATOR);
+ String[] msgList = commaSepratedString.split(LogSearchConstants.I_E_SEPRATOR);
int count = 0;
for (String temp : msgList) {
count += 1;
if (LogSearchConstants.SOLR_LOG_MESSAGE.equalsIgnoreCase(messageField)) {
- queryMsg.append(" " + operator
- + solrUtil.escapeForLogMessage(messageField, temp));
+ queryMsg.append(" " + operator + solrUtil.escapeForLogMessage(messageField, temp));
} else {
temp = solrUtil.escapeForStandardTokenizer(temp);
if(temp.startsWith("\"") && temp.endsWith("\"")){
@@ -86,8 +77,7 @@ public abstract class QueryGenerationBase extends QueryBase {
temp = temp.substring(0, temp.length()-1);
}
temp = "*" + temp + "*";
- queryMsg.append(" " + operator + messageField + ":"
- + temp);
+ queryMsg.append(" " + operator + messageField + ":" + temp);
}
if (msgList.length > count){
queryMsg.append(" " + condition.name() + " ");
@@ -99,21 +89,20 @@ public abstract class QueryGenerationBase extends QueryBase {
}
}
- public void setFilterClauseWithFieldName(SolrQuery solrQuery,
- String commaSepratedString, String field, String operator,
- CONDITION condition) {
- if (!stringUtil.isEmpty(commaSepratedString)) {
+ public void setFilterClauseWithFieldName(SolrQuery solrQuery, String commaSepratedString, String field, String operator,
+ Condition condition) {
+ if (!StringUtils.isBlank(commaSepratedString)) {
String[] arrayOfSepratedString = commaSepratedString.split(LogSearchConstants.LIST_SEPARATOR);
String filterQuery = null;
- if (CONDITION.OR.equals(condition)) {
+ if (Condition.OR.equals(condition)) {
filterQuery = solrUtil.orList(operator + field, arrayOfSepratedString,"");
- } else if (CONDITION.AND.equals(condition)) {
+ } else if (Condition.AND.equals(condition)) {
filterQuery = solrUtil.andList(operator + field, arrayOfSepratedString,"");
}else{
logger.warn("Not a valid condition :" + condition.name());
}
//add
- if(!stringUtil.isEmpty(filterQuery)){
+ if (!StringUtils.isBlank(filterQuery)){
solrQuery.addFilterQuery(filterQuery);
logger.debug("Filter added :- " + filterQuery);
}
@@ -121,58 +110,42 @@ public abstract class QueryGenerationBase extends QueryBase {
}
}
- public void setSortOrderDefaultServiceLog(SolrQuery solrQuery,
- SearchCriteria searchCriteria) {
+ public void setSortOrderDefaultServiceLog(SolrQuery solrQuery, SearchCriteria searchCriteria) {
List<SolrQuery.SortClause> defaultSort = new ArrayList<SolrQuery.SortClause>();
- if (searchCriteria.getSortBy() != null
- && (!searchCriteria.getSortBy().isEmpty())) {
+ if (!StringUtils.isBlank(searchCriteria.getSortBy())) {
ORDER order = SolrQuery.ORDER.asc;
- if (searchCriteria.getSortType() != null
- && (!searchCriteria.getSortType().isEmpty())
- && !searchCriteria.getSortType().equalsIgnoreCase(order.toString())) {
+ if (!order.toString().equalsIgnoreCase(searchCriteria.getSortType())) {
order = SolrQuery.ORDER.desc;
}
- SolrQuery.SortClause logtimeSortClause = SolrQuery.SortClause.create(
- searchCriteria.getSortBy(), order);
+ SolrQuery.SortClause logtimeSortClause = SolrQuery.SortClause.create(searchCriteria.getSortBy(), order);
defaultSort.add(logtimeSortClause);
} else {
- // by default sorting by logtime and sequence number in
- // Descending order
- SolrQuery.SortClause logtimeSortClause = SolrQuery.SortClause.create(
- LogSearchConstants.LOGTIME, SolrQuery.ORDER.desc);
+ // by default sorting by logtime and sequence number in Descending order
+ SolrQuery.SortClause logtimeSortClause = SolrQuery.SortClause.create(LogSearchConstants.LOGTIME, SolrQuery.ORDER.desc);
defaultSort.add(logtimeSortClause);
}
- SolrQuery.SortClause sequenceNumberSortClause = SolrQuery.SortClause
- .create(LogSearchConstants.SEQUNCE_ID, SolrQuery.ORDER.desc);
+ SolrQuery.SortClause sequenceNumberSortClause = SolrQuery.SortClause.create(LogSearchConstants.SEQUNCE_ID, SolrQuery.ORDER.desc);
defaultSort.add(sequenceNumberSortClause);
solrQuery.setSorts(defaultSort);
logger.debug("Sort Order :-" + defaultSort);
}
- public void setFilterFacetSort(SolrQuery solrQuery,
- SearchCriteria searchCriteria) {
- if (searchCriteria.getSortBy() != null
- && (!searchCriteria.getSortBy().isEmpty())) {
+ public void setFilterFacetSort(SolrQuery solrQuery, SearchCriteria searchCriteria) {
+ if (!StringUtils.isBlank(searchCriteria.getSortBy())) {
solrQuery.setFacetSort(searchCriteria.getSortBy());
logger.info("Sorted By :- " + searchCriteria.getSortBy());
}
}
- public void setSingleSortOrder(SolrQuery solrQuery,
- SearchCriteria searchCriteria) {
+ public void setSingleSortOrder(SolrQuery solrQuery, SearchCriteria searchCriteria) {
List<SolrQuery.SortClause> sort = new ArrayList<SolrQuery.SortClause>();
- if (searchCriteria.getSortBy() != null
- && (!searchCriteria.getSortBy().isEmpty())) {
+ if (!StringUtils.isBlank(searchCriteria.getSortBy())) {
ORDER order = SolrQuery.ORDER.asc;
- if (searchCriteria.getSortType() != null
- && (!searchCriteria.getSortType().isEmpty())
- && !searchCriteria.getSortType().equalsIgnoreCase(
- order.toString())) {
+ if (!order.toString().equalsIgnoreCase(searchCriteria.getSortType())) {
order = SolrQuery.ORDER.desc;
}
- SolrQuery.SortClause sortOrder = SolrQuery.SortClause.create(
- searchCriteria.getSortBy(), order);
+ SolrQuery.SortClause sortOrder = SolrQuery.SortClause.create(searchCriteria.getSortBy(), order);
sort.add(sortOrder);
solrQuery.setSorts(sort);
logger.debug("Sort Order :-" + sort);
@@ -182,23 +155,19 @@ public abstract class QueryGenerationBase extends QueryBase {
// Search Criteria has parameter "sort" from it can get list of Sort Order
// Example of list can be [logtime desc,seq_num desc]
@SuppressWarnings("unchecked")
- public void setMultipleSortOrder(SolrQuery solrQuery,
- SearchCriteria searchCriteria) {
+ public void setMultipleSortOrder(SolrQuery solrQuery, SearchCriteria searchCriteria) {
List<SolrQuery.SortClause> sort = new ArrayList<SolrQuery.SortClause>();
List<String> sortList = (List<String>) searchCriteria.getParamValue("sort");
if (sortList != null) {
for (String sortOrder : sortList) {
- if (!stringUtil.isEmpty(sortOrder)) {
+ if (!StringUtils.isBlank(sortOrder)) {
String sortByAndOrder[] = sortOrder.split(" ");
if (sortByAndOrder.length > 1) {
- ORDER order = sortByAndOrder[1].contains("asc") ? SolrQuery.ORDER.asc
- : SolrQuery.ORDER.desc;
- SolrQuery.SortClause solrSortClause = SolrQuery.SortClause.create(
- sortByAndOrder[0], order);
+ ORDER order = sortByAndOrder[1].contains("asc") ? SolrQuery.ORDER.asc : SolrQuery.ORDER.desc;
+ SolrQuery.SortClause solrSortClause = SolrQuery.SortClause.create(sortByAndOrder[0], order);
sort.add(solrSortClause);
logger.debug("Sort Order :-" + sort);
} else {
- // log warn
logger.warn("Not a valid sort Clause " + sortOrder);
}
}
@@ -207,34 +176,26 @@ public abstract class QueryGenerationBase extends QueryBase {
}
}
- public void setSingleIncludeFilter(SolrQuery solrQuery, String filterType,
- String filterValue) {
- if (filterType != null && !filterType.isEmpty() && filterValue != null
- && !filterValue.isEmpty()) {
+ public void setSingleIncludeFilter(SolrQuery solrQuery, String filterType, String filterValue) {
+ if (!StringUtils.isBlank(filterType) && !StringUtils.isBlank(filterValue)) {
String filterQuery = buildFilterQuery(filterType, filterValue);
solrQuery.addFilterQuery(filterQuery);
logger.debug("Filter added :- " + filterQuery);
}
}
- public void setSingleExcludeFilter(SolrQuery solrQuery, String filterType,
- String filterValue) {
- if (!stringUtil.isEmpty(filterValue) && !stringUtil.isEmpty(filterType)) {
- String filterQuery = LogSearchConstants.MINUS_OPERATOR
- + buildFilterQuery(filterType, filterValue);
+ public void setSingleExcludeFilter(SolrQuery solrQuery, String filterType, String filterValue) {
+ if (!StringUtils.isBlank(filterValue) && !StringUtils.isBlank(filterType)) {
+ String filterQuery = LogSearchConstants.MINUS_OPERATOR + buildFilterQuery(filterType, filterValue);
solrQuery.addFilterQuery(filterQuery);
logger.debug("Filter added :- " + filterQuery);
}
}
- public void setSingleRangeFilter(SolrQuery solrQuery, String filterType,
- String filterFromValue, String filterToValue) {
- if (!stringUtil.isEmpty(filterToValue)
- && !stringUtil.isEmpty(filterType)
- && !stringUtil.isEmpty(filterFromValue)) {
- String filterQuery = buildInclusiveRangeFilterQuery(filterType,
- filterFromValue, filterToValue);
- if (!stringUtil.isEmpty(filterQuery)) {
+ public void setSingleRangeFilter(SolrQuery solrQuery, String filterType, String filterFromValue, String filterToValue) {
+ if (!StringUtils.isBlank(filterToValue) && !StringUtils.isBlank(filterType) && !StringUtils.isBlank(filterFromValue)) {
+ String filterQuery = buildInclusiveRangeFilterQuery(filterType, filterFromValue, filterToValue);
+ if (!StringUtils.isBlank(filterQuery)) {
solrQuery.addFilterQuery(filterQuery);
logger.debug("Filter added :- " + filterQuery);
}
@@ -258,30 +219,17 @@ public abstract class QueryGenerationBase extends QueryBase {
}
if (startIndex != null && maxRows != null)
- logger.info("Pagination was set from " + startIndex.intValue()
- + " to " + maxRows.intValue());
+ logger.info("Pagination was set from " + startIndex.intValue() + " to " + maxRows.intValue());
}
- public void setSingleORFilter(SolrQuery solrQuery, String filterName1,
- String value1, String filterName2, String value2) {
- String filterQuery = filterName1 + ":" + value1 + " " + CONDITION.OR.name()
- + " " + filterName2 + ":" + value2;
+ public void setSingleORFilter(SolrQuery solrQuery, String filterName1, String value1, String filterName2, String value2) {
+ String filterQuery = filterName1 + ":" + value1 + " " + Condition.OR.name() + " " + filterName2 + ":" + value2;
solrQuery.setFilterQueries(filterQuery);
}
// BuildMethods to prepare a particular format as required for solr
- public String buildInclusiveRangeFilterQuery(String filterType,
- String filterFromValue, String filterToValue) {
- String filterQuery = filterType + ":[" + filterFromValue + " TO "
- + filterToValue + "]";
- logger.info("Build Filter was :- " + filterQuery);
- return filterQuery;
- }
-
- public String buildExclusiveRangeFilterQuery(String filterType,
- String filterFromValue, String filterToValue) {
- String filterQuery = filterType + ":{" + filterFromValue + " TO "
- + filterToValue + "}";
+ public String buildInclusiveRangeFilterQuery(String filterType, String filterFromValue, String filterToValue) {
+ String filterQuery = filterType + ":[" + filterFromValue + " TO " + filterToValue + "]";
logger.info("Build Filter was :- " + filterQuery);
return filterQuery;
}
@@ -292,139 +240,32 @@ public abstract class QueryGenerationBase extends QueryBase {
return filterQuery;
}
-// public String buildQueryFromJSONCompHost(String jsonHCNames,
-// String selectedComponent) {
-// String queryHostComponent = "";
-// // Building and adding exclude string to filters
-// String selectedCompQuery = "";
-// if (!stringUtil.isEmpty(selectedComponent)) {
-// String[] selectedComponents = selectedComponent
-// .split(LogSearchConstants.LIST_SEPARATOR);
-// selectedCompQuery = solrUtil.orList(LogSearchConstants.SOLR_COMPONENT,
-// selectedComponents);
-// }
-//
-// // Building Query of Host and Components from given json
-// if (jsonHCNames != null && !jsonHCNames.equals("")
-// && !jsonHCNames.equals("[]")) {
-//
-// try {
-// JSONArray jarray = new JSONArray(jsonHCNames);
-// int flagHost = 0;
-// int flagComp;
-// int count;
-// for (int i = 0; i < jarray.length(); i++) {
-// if (flagHost == 1)
-// queryHostComponent = queryHostComponent + " OR ";
-// JSONObject jsonObject = jarray.getJSONObject(i);
-// String host = jsonObject.getString("h");
-// queryHostComponent = queryHostComponent + "( host:" + host;
-// List<String> components = JSONUtil.JSONToList(jsonObject
-// .getJSONArray("c"));
-// if (!components.isEmpty())
-// queryHostComponent = queryHostComponent + " AND ";
-//
-// flagComp = 0;
-// count = 0;
-// for (String comp : components) {
-// if (flagComp == 0)
-// queryHostComponent = queryHostComponent + " ( ";
-// count += 1;
-// queryHostComponent = queryHostComponent + " " + " type:" + comp;
-// if (components.size() <= count)
-// queryHostComponent = queryHostComponent + " ) ";
-// else
-// queryHostComponent = queryHostComponent + " OR ";
-// flagComp = 1;
-// }
-// queryHostComponent = queryHostComponent + " ) ";
-// flagHost = 1;
-// }
-// } catch (JSONException e) {
-// logger.error(e);
-// }
-// }
-// if (selectedCompQuery != null && !selectedCompQuery.equals("")) {
-// if (queryHostComponent == null || queryHostComponent.equals(""))
-// queryHostComponent = selectedCompQuery;
-// else
-// queryHostComponent = queryHostComponent + " OR " + selectedCompQuery;
-// }
-// return queryHostComponent;
-// }
-
- // JSON BuildMethods
-
- /**
- * @param function , xAxisField
- * @return jsonString
- */
- public String buildJSONFacetAggregatedFuncitonQuery(String function,
- String xAxisField) {
+ public String buildJSONFacetAggregatedFuncitonQuery(String function, String xAxisField) {
return "{x:'" + function + "(" + xAxisField + ")'}";
}
- /**
- * @param fieldName , fieldTime, from, to, unit
- * @return jsonString
- * @hierarchy Term, Time Range
- */
- public String buildJSONFacetTermTimeRangeQuery(String fieldName,
- String fieldTime, String from, String to, String unit) {
+ public String buildJSONFacetTermTimeRangeQuery(String fieldName, String fieldTime, String from, String to, String unit) {
String query = "{";
- query += "x" + ":{type:terms,field:" + fieldName
- + ",facet:{y:{type:range,field:" + fieldTime + ",start:\""
- + from + "\",end:\"" + to + "\",gap:\"" + unit + "\"}}}";
+ query += "x" + ":{type:terms,field:" + fieldName + ",facet:{y:{type:range,field:" + fieldTime + ",start:\"" + from + "\",end:\"" + to + "\",gap:\"" + unit + "\"}}}";
query += "}";
logger.info("Build JSONQuery is :- " + query);
return query;
}
- /**
- * @param stackField , xAxisField
- * @return jsonString
- * @hierarchy Term, Range
- */
- public String buildJsonFacetTermsRangeQuery(String stackField,
- String xAxisField) {
- String jsonQuery = "{ " + stackField + ": { type: terms,field:"
- + stackField + "," + "facet: { x: { type: terms, field:"
- + xAxisField + ",mincount:0,sort:{index:asc}}}}}";
- logger.info("Build JSONQuery is :- " + jsonQuery);
- return jsonQuery;
- }
-
- /**
- * @param stackField , xAxisField, function
- * @return
- * @hierarchy Term, Range
- */
- public String buidlJSONFacetRangeQueryForNumber(String stackField,
- String xAxisField, String function) {
- String jsonQuery = "{ " + stackField + ": { type: terms,field:"
- + stackField + "," + "facet: { x:'" + function + "("
- + xAxisField + ")'}}}}";
+ public String buildJsonFacetTermsRangeQuery(String stackField, String xAxisField) {
+ String jsonQuery = "{ " + stackField + ": { type: terms,field:" + stackField + "," + "facet: { x: { type: terms, field:" + xAxisField + ",mincount:0,sort:{index:asc}}}}}";
logger.info("Build JSONQuery is :- " + jsonQuery);
return jsonQuery;
}
- /**
- * @param stackField , xAxisField, function
- * @return
- * @hierarchy Query, T
- */
- public String buidlJSONFacetRangeQueryForSuggestion(
- String originalFieldName, String valueToSuggest) {
- String jsonQuery = "{y:{type:query,query:\"" + originalFieldName + ":"
- + valueToSuggest + "\",facet:{x:{type:terms,field:"
- + originalFieldName + "}}}}";
+ public String buidlJSONFacetRangeQueryForNumber(String stackField, String xAxisField, String function) {
+ String jsonQuery = "{ " + stackField + ": { type: terms,field:" + stackField + "," + "facet: { x:'" + function + "(" + xAxisField + ")'}}}}";
logger.info("Build JSONQuery is :- " + jsonQuery);
return jsonQuery;
}
- public String buildListQuery(String paramValue, String solrFieldName,
- CONDITION condition) {
- if (!stringUtil.isEmpty(paramValue)) {
+ private String buildListQuery(String paramValue, String solrFieldName, Condition condition) {
+ if (!StringUtils.isBlank(paramValue)) {
String[] values = paramValue.split(LogSearchConstants.LIST_SEPARATOR);
switch (condition) {
case OR:
@@ -438,10 +279,8 @@ public abstract class QueryGenerationBase extends QueryBase {
return "";
}
-
- public void addFilterQueryFromArray(SolrQuery solrQuery, String jsonArrStr,
- String solrFieldName, CONDITION condition) {
- if (!stringUtil.isEmpty(jsonArrStr) && condition != null && solrQuery!=null) {
+ protected void addFilterQueryFromArray(SolrQuery solrQuery, String jsonArrStr, String solrFieldName, Condition condition) {
+ if (!StringUtils.isBlank(jsonArrStr) && condition != null && solrQuery != null) {
Gson gson = new Gson();
String[] arr = null;
try {
@@ -462,16 +301,15 @@ public abstract class QueryGenerationBase extends QueryBase {
query=null;
logger.error("Invalid condition :" + condition.name());
}
- if (!stringUtil.isEmpty(query)) {
+ if (!StringUtils.isBlank(query)) {
solrQuery.addFilterQuery(query);
}
}
}
- public void addFilter(SolrQuery solrQuery, String paramValue,
- String solrFieldName, CONDITION condition) {
+ protected void addFilter(SolrQuery solrQuery, String paramValue, String solrFieldName, Condition condition) {
String filterQuery = buildListQuery(paramValue, solrFieldName, condition);
- if (!stringUtil.isEmpty(filterQuery)) {
+ if (!StringUtils.isBlank(filterQuery)) {
if (solrQuery != null) {
solrQuery.addFilterQuery(filterQuery);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/ServiceLogsREST.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/ServiceLogsREST.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/ServiceLogsREST.java
index 373f7ff..a906ceb 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/ServiceLogsREST.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/ServiceLogsREST.java
@@ -113,7 +113,7 @@ public class ServiceLogsREST {
public String getHosts(@Context HttpServletRequest request) {
SearchCriteria searchCriteria = new SearchCriteria(request);
searchCriteria.addParam("q", request.getParameter("q"));
- return logMgr.getHosts(searchCriteria);
+ return logMgr.getHosts();
}
@GET
@@ -126,7 +126,7 @@ public class ServiceLogsREST {
public String getComponents(@Context HttpServletRequest request) {
SearchCriteria searchCriteria = new SearchCriteria(request);
searchCriteria.addParam("q", request.getParameter("q"));
- return logMgr.getComponents(searchCriteria);
+ return logMgr.getComponents();
}
@GET
@@ -174,7 +174,7 @@ public class ServiceLogsREST {
searchCriteria
.addParam("startDate", request.getParameter("start_time"));
searchCriteria.addParam("endDate", request.getParameter("end_time"));
- return logMgr.getLogLevelCount(searchCriteria);
+ return logMgr.getLogLevelCount();
}
@GET
@@ -192,7 +192,7 @@ public class ServiceLogsREST {
searchCriteria
.addParam("startDate", request.getParameter("start_time"));
searchCriteria.addParam("endDate", request.getParameter("end_time"));
- return logMgr.getComponentsCount(searchCriteria);
+ return logMgr.getComponentsCount();
}
@GET
@@ -216,7 +216,7 @@ public class ServiceLogsREST {
.unescapeXml(request.getParameter("excludeQuery")));
searchCriteria.addParam("includeQuery", StringEscapeUtils
.unescapeXml(request.getParameter("includeQuery")));
- return logMgr.getHostsCount(searchCriteria);
+ return logMgr.getHostsCount();
}
@GET
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/security/context/LogsearchContextHolder.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/security/context/LogsearchContextHolder.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/security/context/LogsearchContextHolder.java
deleted file mode 100644
index fb23cde..0000000
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/security/context/LogsearchContextHolder.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.security.context;
-
-public class LogsearchContextHolder {
-
- private static final ThreadLocal<LogsearchSecurityContext> securityContextThreadLocal = new ThreadLocal<LogsearchSecurityContext>();
-
- private LogsearchContextHolder() {
-
- }
-
- public static LogsearchSecurityContext getSecurityContext() {
- return securityContextThreadLocal.get();
- }
-
- public static void setSecurityContext(LogsearchSecurityContext context) {
- securityContextThreadLocal.set(context);
- }
-
- public static void resetSecurityContext() {
- securityContextThreadLocal.remove();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/security/context/LogsearchSecurityContext.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/security/context/LogsearchSecurityContext.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/security/context/LogsearchSecurityContext.java
deleted file mode 100644
index 4a79525..0000000
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/security/context/LogsearchSecurityContext.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.security.context;
-
-import java.io.Serializable;
-
-import org.apache.ambari.logsearch.common.RequestContext;
-import org.apache.ambari.logsearch.common.UserSessionInfo;
-
-
-public class LogsearchSecurityContext implements Serializable{
- private static final long serialVersionUID = 1L;
- private UserSessionInfo userSession;
- private RequestContext requestContext;
-
- public UserSessionInfo getUserSession() {
- return userSession;
- }
-
- public void setUserSession(UserSessionInfo userSession) {
- this.userSession = userSession;
- }
-
- /**
- * @return the requestContext
- */
- public RequestContext getRequestContext() {
- return requestContext;
- }
-
- /**
- * @param requestContext the requestContext to set
- */
- public void setRequestContext(RequestContext requestContext) {
- this.requestContext = requestContext;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
index 8dd0fb9..814b8ee 100644
--- 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
@@ -37,27 +37,22 @@ 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.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
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;
-
- @Autowired
- StringUtil stringUtil;
+ private static final Logger logger = Logger.getLogger(BizUtil.class);
public String convertObjectToNormalText(SolrDocumentList docList) {
String textToSave = "";
HashMap<String, String> blankFieldsMap = new HashMap<String, String>();
- if(docList == null){
+ if (docList == null){
return "no data";
}
if (docList.isEmpty()) {
@@ -67,66 +62,50 @@ public class BizUtil {
if(docForBlankCaculation == null){
return "no data";
}
- Collection<String> fieldsForBlankCaculation = docForBlankCaculation
- .getFieldNames();
+ Collection<String> fieldsForBlankCaculation = docForBlankCaculation.getFieldNames();
int maxLengthOfField = 0;
- if(fieldsForBlankCaculation == null){
+ if (fieldsForBlankCaculation == null) {
return "no data";
}
- for (String field : fieldsForBlankCaculation) {
- if (!stringUtil.isEmpty(field) && field.length() > maxLengthOfField){
+ for (String field : fieldsForBlankCaculation) {
+ if (!StringUtils.isBlank(field) && field.length() > maxLengthOfField) {
maxLengthOfField = field.length();
}
}
for (String field : fieldsForBlankCaculation) {
- if(!stringUtil.isEmpty(field)){
- blankFieldsMap
- .put(field,
- addBlanksToString(
- maxLengthOfField - field.length(), field));
+ if (!StringUtils.isBlank(field)) {
+ blankFieldsMap.put(field, addBlanksToString(maxLengthOfField - field.length(), field));
}
- }
+ }
for (SolrDocument doc : docList) {
if (doc != null) {
StringBuffer textTowrite = new StringBuffer();
if (doc.getFieldValue(LogSearchConstants.LOGTIME) != null) {
- textTowrite.append(doc.getFieldValue(LogSearchConstants.LOGTIME)
- .toString() + " ");
+ textTowrite.append(doc.getFieldValue(LogSearchConstants.LOGTIME).toString() + " ");
}
if (doc.getFieldValue(LogSearchConstants.SOLR_LEVEL) != null) {
- textTowrite.append(
- doc.getFieldValue(LogSearchConstants.SOLR_LEVEL).toString())
- .append(" ");
+ 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(" ");
+ 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(" ");
+ 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) {
+ if (doc.getFieldValue(LogSearchConstants.SOLR_FILE) != null && doc.getFieldValue(LogSearchConstants.SOLR_LINE_NUMBER) != null) {
textTowrite
- .append(
- doc.getFieldValue(LogSearchConstants.SOLR_FILE).toString())
+ .append(doc.getFieldValue(LogSearchConstants.SOLR_FILE).toString())
.append(":")
- .append(
- doc.getFieldValue(LogSearchConstants.SOLR_LINE_NUMBER)
- .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());
+ .append(doc.getFieldValue(LogSearchConstants.SOLR_LOG_MESSAGE).toString());
}
textTowrite.append("\n");
textToSave += textTowrite.toString();
@@ -137,7 +116,7 @@ public class BizUtil {
public VSummary buildSummaryForLogFile(SolrDocumentList docList) {
VSummary vsummary = new VSummary();
- if(docList == null || docList.isEmpty()){
+ if (CollectionUtils.isEmpty(docList)) {
return vsummary;
}
int numLogs = 0;
@@ -150,14 +129,14 @@ public class BizUtil {
String hostname = (String) doc.getFieldValue("host");
String comp = (String) doc.getFieldValue("type");
String level = (String) doc.getFieldValue("level");
- if (stringUtil.isEmpty(level)) {
+ if (StringUtils.isBlank(level)) {
level = "";
}
boolean newHost = true;
for (VHost host : vHosts) {
if (host != null && host.getName().equals(hostname)) {
newHost = false;
- if (stringUtil.isEmpty(comp)) {
+ if (StringUtils.isBlank(comp)) {
Set<String> compList = host.getComponents();
if (compList != null) {
compList.add(comp);
@@ -168,11 +147,11 @@ public class BizUtil {
}
if (newHost) {
VHost vHost = new VHost();
- if (!stringUtil.isEmpty(hostname)) {
+ if (!StringUtils.isBlank(hostname)) {
vHost.setName(hostname);
}
Set<String> component = new LinkedHashSet<String>();
- if (stringUtil.isEmpty(comp)) {
+ if (StringUtils.isBlank(comp)) {
component.add(comp);
}
vHost.setComponents(component);
@@ -191,8 +170,8 @@ public class BizUtil {
return vsummary;
}
- public String addBlanksToString(int count, String field) {
- if (stringUtil.isEmpty(field)) {
+ private String addBlanksToString(int count, String field) {
+ if (StringUtils.isBlank(field)) {
return field;
}
if (count > 0) {
@@ -203,8 +182,7 @@ public class BizUtil {
}
@SuppressWarnings({"unchecked", "rawtypes"})
- public VBarDataList buildSummaryForTopCounts(
- SimpleOrderedMap<Object> jsonFacetResponse,String innerJsonKey,String outerJsonKey) {
+ public VBarDataList buildSummaryForTopCounts(SimpleOrderedMap<Object> jsonFacetResponse,String innerJsonKey,String outerJsonKey) {
VBarDataList vBarDataList = new VBarDataList();
@@ -217,14 +195,12 @@ public class BizUtil {
if (userList.isEmpty()) {
return vBarDataList;
}
- SimpleOrderedMap<Map<String, Object>> userMap = (SimpleOrderedMap<Map<String, Object>>) userList
- .get(0);
+ 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");
+ List<SimpleOrderedMap> userUsageList = (List<SimpleOrderedMap>) userMap.get("buckets");
if(userUsageList == null){
return vBarDataList;
}
@@ -232,13 +208,12 @@ public class BizUtil {
if (usageMap != null) {
VBarGraphData vBarGraphData = new VBarGraphData();
String userName = (String) usageMap.get("val");
- if (!stringUtil.isEmpty(userName)) {
+ if (!StringUtils.isBlank(userName)) {
vBarGraphData.setName(userName);
}
SimpleOrderedMap repoMap = (SimpleOrderedMap) usageMap.get(innerJsonKey);
List<VNameValue> componetCountList = new ArrayList<VNameValue>();
- List<SimpleOrderedMap> repoUsageList = (List<SimpleOrderedMap>) repoMap
- .get("buckets");
+ List<SimpleOrderedMap> repoUsageList = (List<SimpleOrderedMap>) repoMap.get("buckets");
if (repoMap != null) {
for (SimpleOrderedMap repoUsageMap : repoUsageList) {
VNameValue componetCount = new VNameValue();
@@ -265,9 +240,8 @@ public class BizUtil {
return vBarDataList;
}
- public HashMap<String, String> sortHashMapByValues(
- HashMap<String, String> passedMap) {
- if(passedMap == null ){
+ public HashMap<String, String> sortHashMapByValues(HashMap<String, String> passedMap) {
+ if (passedMap == null ) {
return passedMap;
}
HashMap<String, String> sortedMap = new LinkedHashMap<String, String>();
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
index 320e589..8ec04f8 100644
--- 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
@@ -18,49 +18,20 @@
*/
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;
+import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
- static SecureRandom secureRandom = new SecureRandom();
- static int counter = 0;
+public class CommonUtil {
+ private static SecureRandom secureRandom = new SecureRandom();
+ private static int counter = 0;
- static public String genGUI() {
- return System.currentTimeMillis() + "_" + secureRandom.nextInt(1000)
- + "_" + counter++;
+ public static 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();
+
+ private static final Md5PasswordEncoder md5Encoder = new Md5PasswordEncoder();
+ public static String encryptPassword(String username, String password) {
+ return md5Encoder.encodePassword(password, username);
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
index 2661150..88f92a2 100644
--- 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
@@ -27,12 +27,13 @@ import org.apache.ambari.logsearch.common.LogSearchConstants;
import org.apache.ambari.logsearch.common.MessageEnums;
import org.apache.ambari.logsearch.dao.SolrDaoBase;
import org.apache.ambari.logsearch.manager.MgrBase;
+import org.apache.commons.lang.ArrayUtils;
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);
+ private static final Logger logger = Logger.getLogger(MgrBase.class);
public static HashMap<String, String> serviceLogsColumnMapping = new HashMap<String, String>();
@@ -43,9 +44,7 @@ public class ConfigUtil {
initializeColumnMapping();
}
- private static void intializeUISolrColumnMapping(
- String columnMappingArray[],
- HashMap<String, String> columnMappingMap) {
+ private static void intializeUISolrColumnMapping(String columnMappingArray[], HashMap<String, String> columnMappingMap) {
if (columnMappingArray != null && columnMappingArray.length > 0) {
for (String columnMapping : columnMappingArray) {
@@ -54,32 +53,24 @@ public class ConfigUtil {
String solrField = mapping[0];
String uiField = mapping[1];
- columnMappingMap.put(solrField + LogSearchConstants.SOLR_SUFFIX,
- uiField);
- columnMappingMap.put(uiField + LogSearchConstants.UI_SUFFIX,
- solrField);
+ columnMappingMap.put(solrField + LogSearchConstants.SOLR_SUFFIX, uiField);
+ columnMappingMap.put(uiField + LogSearchConstants.UI_SUFFIX, solrField);
}
}
}
}
private static void initializeColumnMapping() {
- String serviceLogsColumnMappingArray[] = PropertiesUtil
- .getPropertyStringList("logsearch.solr.service.logs.column.mapping");
- String auditLogsColumnMappingArray[] = PropertiesUtil
- .getPropertyStringList("logsearch.solr.audit.logs.column.mapping");
+ String serviceLogsColumnMappingArray[] = PropertiesUtil.getPropertyStringList("logsearch.solr.service.logs.column.mapping");
+ String auditLogsColumnMappingArray[] = PropertiesUtil.getPropertyStringList("logsearch.solr.audit.logs.column.mapping");
// Initializing column mapping for Service Logs
- intializeUISolrColumnMapping(serviceLogsColumnMappingArray,
- serviceLogsColumnMapping);
+ intializeUISolrColumnMapping(serviceLogsColumnMappingArray, serviceLogsColumnMapping);
// Initializing column mapping for Audit Logs
- intializeUISolrColumnMapping(auditLogsColumnMappingArray,
- auditLogsColumnMapping);
+ intializeUISolrColumnMapping(auditLogsColumnMappingArray, auditLogsColumnMapping);
}
-
- public static void extractSchemaFieldsName(String responseString,
- HashMap<String, String> schemaFieldsNameMap,
+ public static void extractSchemaFieldsName(String responseString, HashMap<String, String> schemaFieldsNameMap,
HashMap<String, String> schemaFieldTypeMap) {
try {
JSONObject jsonObject = new JSONObject(responseString);
@@ -118,17 +109,14 @@ public class ConfigUtil {
schemaFieldsNameMap.putAll(_schemaFieldsNameMap);
schemaFieldTypeMap.putAll(_schemaFieldTypeMap);
} catch (Exception e) {
- logger.error(e + "Credentials not specified in logsearch.properties "
- + MessageEnums.ERROR_SYSTEM);
+ logger.error(e + "Credentials not specified in logsearch.properties " + MessageEnums.ERROR_SYSTEM);
}
}
@SuppressWarnings("rawtypes")
- public static void getSchemaFieldsName(String excludeArray[],
- List<String> fieldNames, SolrDaoBase solrDaoBase) {
+ public static void getSchemaFieldsName(String excludeArray[], List<String> fieldNames, SolrDaoBase solrDaoBase) {
if (!solrDaoBase.schemaFieldsNameMap.isEmpty()) {
- Iterator iteratorSechmaFieldsName = solrDaoBase.schemaFieldsNameMap
- .entrySet().iterator();
+ Iterator iteratorSechmaFieldsName = solrDaoBase.schemaFieldsNameMap.entrySet().iterator();
while (iteratorSechmaFieldsName.hasNext()) {
Map.Entry fieldName = (Map.Entry) iteratorSechmaFieldsName.next();
String field = "" + fieldName.getKey();
@@ -140,7 +128,7 @@ public class ConfigUtil {
}
private static boolean isExclude(String name, String excludeArray[]) {
- if (excludeArray != null && excludeArray.length > 0) {
+ if (!ArrayUtils.isEmpty(excludeArray)) {
for (String exclude : excludeArray) {
if (name.equals(exclude)){
return true;
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
index 7425aaa..516d828 100644
--- 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
@@ -30,35 +30,30 @@ import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import org.apache.ambari.logsearch.common.LogSearchConstants;
+import org.apache.commons.lang.StringUtils;
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 static final Logger logger = Logger.getLogger(DateUtil.class);
private DateUtil() {
}
public String addOffsetToDate(String date, Long utcOffset, String dateFormat) {
- if (stringUtil.isEmpty(date)) {
+ if (StringUtils.isBlank(date)) {
logger.debug("input date is empty or null.");
return null;
}
if (utcOffset == null) {
- logger
- .debug("Utc offset is null, Return input date without adding offset.");
+ logger.debug("Utc offset is null, Return input date without adding offset.");
return date;
}
- if (stringUtil.isEmpty(dateFormat)) {
- logger
- .debug("dateFormat is null or empty, Return input date without adding offset.");
+ if (StringUtils.isBlank(dateFormat)) {
+ logger.debug("dateFormat is null or empty, Return input date without adding offset.");
return date;
}
String retDate = "";
@@ -67,10 +62,9 @@ public class DateUtil {
if (date.contains(".")) {
modifiedDate = date.replace(".", ",");
}
- SimpleDateFormat formatter = new SimpleDateFormat(dateFormat,
- Locale.ENGLISH);
+ SimpleDateFormat formatter = new SimpleDateFormat(dateFormat, Locale.ENGLISH);
Date startDate = formatter.parse(modifiedDate);
- long toWithOffset = getTimeWithOffset(startDate, utcOffset, dateFormat);
+ long toWithOffset = getTimeWithOffset(startDate, utcOffset);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(toWithOffset);
retDate = formatter.format(calendar.getTime());
@@ -80,98 +74,28 @@ public class DateUtil {
return retDate;
}
- public long getTimeWithOffset(Date date, Long utcOffset, String dateFormate) {
+ private long getTimeWithOffset(Date date, Long utcOffset) {
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 getTodayFromDate() {
Calendar c = new GregorianCalendar();
- c.set(Calendar.HOUR_OF_DAY, 0);
+ c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
return c.getTime();
}
- 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 {
+ 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);
+ 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);
@@ -183,53 +107,36 @@ public class DateUtil {
if (date == null) {
return "";
}
- SimpleDateFormat formatter = new SimpleDateFormat(
- LogSearchConstants.SOLR_DATE_FORMAT_PREFIX_Z, Locale.ENGLISH);
+ 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 {
+ public String convertSolrDateToNormalDateFormat(long d, long utcOffset) throws ParseException {
Date date = new Date(d);
- SimpleDateFormat formatter = new SimpleDateFormat(
- LogSearchConstants.SOLR_DATE_FORMAT, Locale.ENGLISH);
+ 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);
+ 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;
- }
-
public boolean isDateValid(String value) {
- if(stringUtil.isEmpty(value)){
+ if (StringUtils.isBlank(value)) {
return false;
}
Date date = null;
try {
- SimpleDateFormat sdf = new SimpleDateFormat(LogSearchConstants.SOLR_DATE_FORMAT_PREFIX_Z);
- date = sdf.parse(value);
- if (!value.equals(sdf.format(date))) {
- date = null;
- }
+ SimpleDateFormat sdf = new SimpleDateFormat(LogSearchConstants.SOLR_DATE_FORMAT_PREFIX_Z);
+ date = sdf.parse(value);
+ if (!value.equals(sdf.format(date))) {
+ date = null;
+ }
} catch (Exception ex) {
- //do nothing
+ // do nothing
}
return date != null;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
index 658635c..e3c2063 100644
--- 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
@@ -39,24 +39,19 @@ import org.springframework.stereotype.Component;
@Component
public class FileUtil {
- static Logger logger = Logger.getLogger(FileUtil.class);
+ private static final Logger logger = Logger.getLogger(FileUtil.class);
@Autowired
- RESTErrorUtil restErrorUtil;
+ private RESTErrorUtil restErrorUtil;
- @SuppressWarnings("resource")
public Response saveToFile(String text, String fileName, VSummary vsummary) {
String mainExportedFile = "";
FileOutputStream fis = null;
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";
+ 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 = String.format("%-8s", "");
@@ -89,42 +84,30 @@ public class FileUtil {
blankCharacterForHost = String.format("%-3s", blankCharacterForHost);
}
if (numberHost == 1) {
- mainExportedFile = mainExportedFile + "Host"
- + blankCharacterForHost + " : " + h + " [" + c
- + "] " + "\n";
+ mainExportedFile = mainExportedFile + "Host" + blankCharacterForHost + " : " + h + " [" + c + "] " + "\n";
} else if (numberHost > 1) {
- mainExportedFile = mainExportedFile + "Host_" + numberHost
- + blankCharacterForHost + " : " + h + " [" + c
- + "] " + "\n";
+ mainExportedFile = mainExportedFile + "Host_" + numberHost + blankCharacterForHost + " : " + h + " [" + c + "] " + "\n";
}
}
- mainExportedFile = mainExportedFile + "Levels"+String.format("%-9s", blankCharacterForHost)+": "
- + vsummary.getLevels() + "\n";
- mainExportedFile = mainExportedFile + "Format"+String.format("%-9s", blankCharacterForHost)+": "
- + vsummary.getFormat() + "\n";
+ mainExportedFile = mainExportedFile + "Levels"+String.format("%-9s", blankCharacterForHost)+": " + vsummary.getLevels() + "\n";
+ mainExportedFile = mainExportedFile + "Format"+String.format("%-9s", blankCharacterForHost)+": " + 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 + "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());
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();
+ .header("Content-Disposition", "attachment;filename=" + fileName + vsummary.getFormat())
+ .build();
} catch (Exception e) {
logger.error(e.getMessage());
- throw restErrorUtil.createRESTException(e.getMessage(),
- MessageEnums.ERROR_SYSTEM);
+ throw restErrorUtil.createRESTException(e.getMessage(), MessageEnums.ERROR_SYSTEM);
} finally {
if (fis != null) {
try {
@@ -135,13 +118,8 @@ public class FileUtil {
}
}
- /**
- * @param filename
- * @return
- */
public File getFileFromClasspath(String filename) {
- URL fileCompleteUrl = Thread.currentThread().getContextClassLoader()
- .getResource(filename);
+ URL fileCompleteUrl = Thread.currentThread().getContextClassLoader().getResource(filename);
logger.debug("File Complete URI :" + fileCompleteUrl);
File file = null;
try {
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
index 4703c58..5332d18 100644
--- 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
@@ -22,15 +22,14 @@ 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.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.ambari.logsearch.common.MessageEnums;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
-import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
@@ -47,112 +46,51 @@ import com.google.gson.GsonBuilder;
@Component
public class JSONUtil {
- static Logger logger = Logger.getLogger(JSONUtil.class);
+ private static final Logger logger = Logger.getLogger(JSONUtil.class);
@Autowired
- RESTErrorUtil restErrorUtil;
+ private 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);
- }
-
- }
+ private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
+ private Gson gson = new GsonBuilder().setDateFormat(DATE_FORMAT).create();
@SuppressWarnings("unchecked")
public HashMap<String, Object> jsonToMapObject(String jsonStr) {
- if (stringUtil.isEmpty(jsonStr)) {
+ if (StringUtils.isBlank(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>>() {
- });
+ 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);
+ 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);
+ 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);
+ throw restErrorUtil.createRESTException("Invalid input data: " + e.getMessage(), MessageEnums.INVALID_INPUT_DATA);
}
}
@SuppressWarnings("unchecked")
public List<HashMap<String, Object>> jsonToMapObjectList(String jsonStr) {
- if (stringUtil.isEmpty(jsonStr)) {
+ if (StringUtils.isBlank(jsonStr)) {
return null;
}
ObjectMapper mapper = new ObjectMapper();
try {
- Object tempObject = mapper.readValue(jsonStr,
- new TypeReference<List<HashMap<String, Object>>>() {
- });
+ 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);
+ 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);
+ 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);
+ throw restErrorUtil.createRESTException("Invalid input data: " + e.getMessage(), MessageEnums.INVALID_INPUT_DATA);
}
}
@@ -170,21 +108,11 @@ public class JSONUtil {
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>>() {
- });
+ 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());
}
@@ -197,10 +125,6 @@ public class JSONUtil {
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());
}
@@ -209,13 +133,8 @@ public class JSONUtil {
/**
* WRITE JOSN IN FILE ( Delete existing file and create new file)
- *
- * @param jsonStr
- * @param outputFile
- * @param beautify
*/
- public synchronized void writeJSONInFile(String jsonStr, File outputFile,
- boolean beautify) {
+ public synchronized void writeJSONInFile(String jsonStr, File outputFile, boolean beautify) {
FileWriter fileWriter = null;
if (outputFile == null) {
logger.error("user_pass json file can't be null.");
@@ -231,14 +150,11 @@ public class JSONUtil {
if (beautify) {
ObjectMapper mapper = new ObjectMapper();
Object json = mapper.readValue(jsonStr, Object.class);
- jsonStr = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(
- json);
+ 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());
+ 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());
@@ -248,7 +164,6 @@ public class JSONUtil {
fileWriter.flush();
fileWriter.close();
} catch (Exception exception) {
- // ignore
logger.error(exception);
}
}
@@ -265,14 +180,9 @@ public class JSONUtil {
/**
* GET VALUES FROM JSON BY GIVING KEY RECURSIVELY
- *
- * @param jsonStr
- * @param keyName
- * @return
*/
@SuppressWarnings("rawtypes")
- public static String getValuesOfKey(String jsonStr, String keyName,
- List<String> values) {
+ public static String getValuesOfKey(String jsonStr, String keyName, List<String> values) {
if (values == null) {
return null;
}
@@ -318,13 +228,11 @@ public class JSONUtil {
// ignore
}
- } else if ((((JSONObject) jsonObj).optJSONArray(key) != null)
- || (((JSONObject) jsonObj).optJSONObject(key) != null)) {
+ } else if ((((JSONObject) jsonObj).optJSONArray(key) != null) || (((JSONObject) jsonObj).optJSONObject(key) != null)) {
String str = null;
try {
- str = getValuesOfKey("" + ((JSONObject) jsonObj).getString(key),
- keyName, values);
+ str = getValuesOfKey("" + ((JSONObject) jsonObj).getString(key), keyName, values);
} catch (Exception e) {
// ignore
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
deleted file mode 100644
index c3ef20f..0000000
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/LogsearchPropertiesConfiguration.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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/ffcf5328/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
index 16ebae2..59f0296 100644
--- 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
@@ -34,9 +34,11 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
public class PropertiesUtil extends PropertyPlaceholderConfigurer {
- static Logger logger = Logger.getLogger(PropertiesUtil.class);
- private static Map<String, String> propertiesMap;
+ private static final Logger logger = Logger.getLogger(PropertiesUtil.class);
+
private static final String LOGSEARCH_PROP_FILE="logsearch.properties";
+
+ private static Map<String, String> propertiesMap;
private PropertiesUtil() {
@@ -45,8 +47,7 @@ public class PropertiesUtil extends PropertyPlaceholderConfigurer {
static {
propertiesMap = new HashMap<String, String>();
Properties properties = new Properties();
- URL fileCompleteUrl = Thread.currentThread()
- .getContextClassLoader().getResource(LOGSEARCH_PROP_FILE);
+ URL fileCompleteUrl = Thread.currentThread().getContextClassLoader().getResource(LOGSEARCH_PROP_FILE);
FileInputStream fileInputStream = null;
try {
File file = new File(fileCompleteUrl.toURI());
@@ -69,9 +70,7 @@ public class PropertiesUtil extends PropertyPlaceholderConfigurer {
}
@Override
- protected void processProperties(
- ConfigurableListableBeanFactory beanFactory, Properties props)
- throws BeansException {
+ protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) throws BeansException {
super.processProperties(beanFactory, props);
propertiesMap = new HashMap<String, String>();
@@ -80,8 +79,7 @@ public class PropertiesUtil extends PropertyPlaceholderConfigurer {
Set<Object> keySet = System.getProperties().keySet();
for (Object key : keySet) {
String keyStr = key.toString();
- propertiesMap.put(keyStr, System.getProperties()
- .getProperty(keyStr).trim());
+ propertiesMap.put(keyStr, System.getProperties().getProperty(keyStr).trim());
}
// add our properties now
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
index d1e0a86..5961cff 100644
--- 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
@@ -20,13 +20,10 @@
package org.apache.ambari.logsearch.util;
import org.apache.ambari.logsearch.common.LogSearchConstants;
+import org.apache.commons.lang.StringUtils;
import org.apache.solr.client.solrj.SolrQuery;
-import org.springframework.beans.factory.annotation.Autowired;
public class QueryBase {
-
- @Autowired
- StringUtil stringUtil;
//Solr Facet Methods
public void setFacetField(SolrQuery solrQuery, String facetField) {
@@ -48,8 +45,7 @@ public class QueryBase {
solrQuery.setFacetSort(sortType);
}
- public void setFacetPivot(SolrQuery solrQuery, int mincount,
- String... hirarchy) {
+ public void setFacetPivot(SolrQuery solrQuery, int mincount, String... hirarchy) {
solrQuery.setFacet(true);
setRowCount(solrQuery, 0);
solrQuery.set(LogSearchConstants.FACET_PIVOT, hirarchy);
@@ -57,8 +53,7 @@ public class QueryBase {
setFacetLimit(solrQuery, -1);
}
- public void setFacetDate(SolrQuery solrQuery, String facetField,
- String from, String to, String unit) {
+ public void setFacetDate(SolrQuery solrQuery, String facetField, String from, String to, String unit) {
solrQuery.setFacet(true);
setRowCount(solrQuery, 0);
solrQuery.set(LogSearchConstants.FACET_DATE, facetField);
@@ -69,8 +64,7 @@ public class QueryBase {
setFacetLimit(solrQuery, -1);
}
- public void setFacetRange(SolrQuery solrQuery, String facetField,
- String from, String to, String unit) {
+ public void setFacetRange(SolrQuery solrQuery, String facetField, String from, String to, String unit) {
solrQuery.setFacet(true);
setRowCount(solrQuery, 0);
solrQuery.set(LogSearchConstants.FACET_RANGE, facetField);
@@ -96,7 +90,7 @@ public class QueryBase {
//Main Query
public void setMainQuery(SolrQuery solrQuery, String query) {
String defalultQuery = "*:*";
- if (stringUtil.isEmpty(query)){
+ if (StringUtils.isBlank(query)){
solrQuery.setQuery(defalultQuery);
}else{
solrQuery.setQuery(query);
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
index e64f742..6df5b05 100644
--- 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
@@ -54,7 +54,7 @@ public class RESTErrorUtil {
return webAppEx;
}
- public WebApplicationException createRESTException(VResponse response, int sc) {
+ private WebApplicationException createRESTException(VResponse response, int sc) {
Response errorResponse = Response.status(sc).entity(response).build();
WebApplicationException restException = new WebApplicationException(errorResponse);
restException.fillInStackTrace();
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffcf5328/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
index ee706bf..bcf9605 100644
--- 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
@@ -25,23 +25,21 @@ import java.util.Locale;
import org.apache.ambari.logsearch.common.LogSearchConstants;
import org.apache.ambari.logsearch.dao.SolrDaoBase;
-import org.apache.log4j.Logger;
import org.apache.solr.schema.TrieDoubleField;
import org.apache.solr.schema.TrieFloatField;
import org.apache.solr.schema.TrieIntField;
import org.apache.solr.schema.TrieLongField;
import org.springframework.beans.factory.annotation.Autowired;
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
@Component
public class SolrUtil {
- static final Logger logger = Logger.getLogger("org.apache.ambari.logsearch");
-
- @Autowired
- StringUtil stringUtil;
@Autowired
- JSONUtil jsonUtil;
+ private JSONUtil jsonUtil;
public String setField(String fieldName, String value) {
if (value == null || value.trim().length() == 0) {
@@ -50,13 +48,8 @@ public class SolrUtil {
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) {
+ if (ArrayUtils.isEmpty(values)) {
return "";
}
String expr = "";
@@ -71,12 +64,8 @@ public class SolrUtil {
}
}
- /**
- * @param familyUserIdSet
- * @return
- */
public String inList(Collection<Long> values) {
- if (values == null || values.isEmpty()) {
+ if (CollectionUtils.isEmpty(values)) {
return "";
}
String expr = "";
@@ -92,18 +81,12 @@ public class SolrUtil {
}
- /**
- * @param wildCard
- * @param string
- * @param searchList
- * @return
- */
public String orList(String fieldName, String[] valueList, String wildCard) {
- if (valueList == null || valueList.length == 0) {
+ if (ArrayUtils.isEmpty(valueList)) {
return "";
}
- if(stringUtil.isEmpty(wildCard)){
+ if (StringUtils.isBlank(wildCard)) {
wildCard = "";
}
@@ -126,18 +109,12 @@ public class SolrUtil {
}
- /**
- * @param wildCard
- * @param string
- * @param searchList
- * @return
- */
public String andList(String fieldName, String[] valueList, String wildCard) {
- if (valueList == null || valueList.length == 0) {
+ if (ArrayUtils.isEmpty(valueList)) {
return "";
}
- if(stringUtil.isEmpty(wildCard)){
+ if (StringUtils.isBlank(wildCard)) {
wildCard = "";
}
@@ -162,9 +139,6 @@ public class SolrUtil {
/**
* Copied from Solr ClientUtils.escapeQueryChars and removed escaping *
- *
- * @param s
- * @return
*/
public String escapeQueryChars(String s) {
StringBuilder sb = new StringBuilder();
@@ -195,7 +169,7 @@ public class SolrUtil {
return sb.toString();
}
- public String escapeForWhiteSpaceTokenizer(String search) {
+ private String escapeForWhiteSpaceTokenizer(String search) {
if (search == null) {
return null;
}
@@ -233,30 +207,24 @@ public class SolrUtil {
return newSearch;
}
- public String escapeForKeyTokenizer(String search) {
- if (search.startsWith("*") && search.endsWith("*")
- && !stringUtil.isEmpty(search)) {
+ private String escapeForKeyTokenizer(String search) {
+ if (search.startsWith("*") && search.endsWith("*") && !StringUtils.isBlank(search)) {
// Remove the * from both the sides
if (search.length() > 1) {
search = search.substring(1, search.length() - 1);
- }else{
+ } else {
//search string have only *
search="";
}
}
- // Escape the string
search = escapeQueryChars(search);
- // Add the *
return "*" + search + "*";
}
/**
* This is a special case scenario to handle log_message for wild card
* scenarios
- *
- * @param search
- * @return
*/
public String escapeForLogMessage(String field, String search) {
if (search.startsWith("*") && search.endsWith("*")) {
@@ -272,8 +240,7 @@ public class SolrUtil {
public String makeSolrSearchString(String search) {
String newString = search.trim();
- String newSearch = newString.replaceAll(
- "(?=[]\\[+&|!(){},:\"^~/=$@%?:.\\\\])", "\\\\");
+ String newSearch = newString.replaceAll("(?=[]\\[+&|!(){},:\"^~/=$@%?:.\\\\])", "\\\\");
newSearch = newSearch.replace("\n", "*");
newSearch = newSearch.replace("\t", "*");
newSearch = newSearch.replace("\r", "*");
@@ -284,8 +251,7 @@ public class SolrUtil {
public String makeSolrSearchStringWithoutAsterisk(String search) {
String newString = search.trim();
- String newSearch = newString.replaceAll(
- "(?=[]\\[+&|!(){}^\"~=/$@%?:.\\\\])", "\\\\");
+ String newSearch = newString.replaceAll("(?=[]\\[+&|!(){}^\"~=/$@%?:.\\\\])", "\\\\");
newSearch = newSearch.replace("\n", "*");
newSearch = newSearch.replace("\t", "*");
newSearch = newSearch.replace("\r", "*");
@@ -296,19 +262,18 @@ public class SolrUtil {
}
public String makeSearcableString(String search) {
- if (search == null || search.isEmpty()){
+ if (StringUtils.isBlank(search)) {
return "";
}
String newSearch = search.replaceAll("[\\t\\n\\r]", " ");
- newSearch = newSearch.replaceAll("(?=[]\\[+&|!(){}^~=$/@%?:.\\\\-])",
- "\\\\");
+ newSearch = newSearch.replaceAll("(?=[]\\[+&|!(){}^~=$/@%?:.\\\\-])", "\\\\");
return newSearch.replace(" ", "\\ ");
}
public boolean isSolrFieldNumber(String fieldType,SolrDaoBase solrDaoBase) {
- if (stringUtil.isEmpty(fieldType)) {
+ if (StringUtils.isBlank(fieldType)) {
return false;
} else {
HashMap<String, Object> typeInfoMap = getFieldTypeInfoMap(fieldType,solrDaoBase);
@@ -344,7 +309,7 @@ public class SolrUtil {
return new HashMap<String, Object>();
}
String classname = (String) fieldTypeMap.get("class");
- if (!stringUtil.isEmpty(classname)) {
+ if (!StringUtils.isBlank(classname)) {
classname = classname.replace("solr.", "");
fieldTypeMap.put("class", classname);
}