http://git-wip-us.apache.org/repos/asf/ambari/blob/c15ed8b7/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/templates/dashboard/MainLayoutView_tmpl.html ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/templates/dashboard/MainLayoutView_tmpl.html b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/templates/dashboard/MainLayoutView_tmpl.html index c79ed1d..bc59f76 100644 --- a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/templates/dashboard/MainLayoutView_tmpl.html +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/templates/dashboard/MainLayoutView_tmpl.html @@ -43,12 +43,6 @@ <a class="collapse-link"> <i class="fa fa-chevron-up"></i> </a> - <!-- <a class=""> - <i class="fa fa-gear"></i> - </a> - <a class="close-link"> - <i class="fa fa-close"></i> - </a> --> </div> <div class="no-move"></div> </div> @@ -62,71 +56,6 @@ </div> </div> </div> - <!-- div class="col-md-3"> - <div class="box"> - <div class="box-header"> - <div class="box-name"> - <span>Time Range</span> - </div> - <div class="box-icons"> - <a class="collapse-link"> - <i class="fa fa-chevron-up"></i> - </a> - <a class=""> - <i class="fa fa-gear"></i> - </a> - <a class="close-link"> - <i class="fa fa-close"></i> - </a> - </div> - <div class="no-move"></div> - </div> - <div class="box-content"> - <div class="btn-group btn-group-sm"> - <button class="btn btn-primary">15m</button> - <button class="btn btn-primary">1h</button> - <button class="btn btn-primary">24h</button> - </div> - </div> - </div> - </div> - <div class="col-md-6"> - <div class="box"> - <div class="box-header"> - <div class="box-name"> - <span>Filtering</span> - </div> - <div class="box-icons"> - <a class="collapse-link"> - <i class="fa fa-chevron-up"></i> - </a> - <a class=""> - <i class="fa fa-gear"></i> - </a> - <a class="close-link"> - <i class="fa fa-close"></i> - </a> - </div> - <div class="no-move"></div> - </div> - <div class="box-content"> - <table class="table-bordered table-condensed"> - <tr> - <th>Time</th> - <td colspan="5">must</td> - </tr> - <tr> - <th>field</th> - <td>logtime</td> - <th>from</th> - <td>2014-12-17T04:59:00.362Z</td> - <th>to</th> - <td>2015-06-15T04:59:00.363Z</td> - </tr> - </table> - </div> - </div> - </div--> </div> <div class="row"> <div class="col-md-3"> @@ -143,56 +72,6 @@ </div> <div class="col-md-9"> <div id="r_BubbleTable"></div> - <!-- <div class="box no-drop"> - <div class="box-header"> - <div class="box-name"> - <span>Log Data</span> - </div> - <div class="box-icons"> - <span id="loaderGraph"> - <i class="fa fa-spinner fa-spin"></i> - </span> - <a class=""> - <i class="fa fa-save"></i> - </a> - <a class=""> - <i class="fa fa-info"></i> - </a> - <a class=""> - <i class="fa fa-gear"></i> - </a> - <a class="collapse-link"> - <i class="fa fa-chevron-up"></i> - </a> - <a class="close-link"> - <i class="fa fa-close"></i> - </a> - </div> - <div class="no-move"></div> - </div> - <div class="box-content"> - <div class=""> - <div class="radio-inline"> - <label> - <input type="radio" name="viewType" value="G" checked=""> Graph - <i class="fa fa-circle-o small"></i> - </label> - </div> - <div class="radio-inline"> - <label> - <input type="radio" name="viewType" value="T"> Table - <i class="fa fa-circle-o small"></i> - </label> - </div> - </div> - <div data-id="table" style="display:none;"> - <div id=control></div> - <div id="rLogTable" ></div> - </div> - - <div id="graphAgg"></div> - </div> - </div> --> </div> </div> </div>
http://git-wip-us.apache.org/repos/asf/ambari/blob/c15ed8b7/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/templates/helpers/Helpers.js ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/templates/helpers/Helpers.js b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/templates/helpers/Helpers.js index f4f1d32..151335d 100644 --- a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/templates/helpers/Helpers.js +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/templates/helpers/Helpers.js @@ -22,7 +22,6 @@ var Handlebars = require('handlebars'); var Util = require('utils/Utils'); var localization = require('utils/LangSupport'); - var SessionMgr = require('mgrs/SessionMgr'); require('moment'); /* * General guidelines while writing helpers: @@ -274,18 +273,12 @@ return 'styles/images/avatar' + parseInt(((Math.random()*10)%4) + 1,10) + '.png'; }); Handlebars.registerHelper('isSystemAdmin', function(context, options) { - if(SessionMgr.isSystemAdmin()) - return options.fn(this); return options.inverse(this); }); Handlebars.registerHelper('isSchoolAdmin', function(context, options) { - if(SessionMgr.isSchoolAdmin() || SessionMgr.isSystemAdmin()) - return options.fn(this); return options.inverse(this); }); Handlebars.registerHelper('isTeacher', function(context, options) { - if(SessionMgr.isTeacher()) - return options.fn(this); return options.inverse(this); }); Handlebars.registerHelper('getAvatar', function(options,size) { @@ -510,41 +503,9 @@ } return new Handlebars.SafeString(html); }); - // Handlebars.registerHelper('getServices', function(services, serviceDef) { - // var XAEnums = require('utils/XAEnums'); - // var tr = '', serviceOperationDiv = ''; - // var serviceType = serviceDef.get('name'); - // if(!_.isUndefined(services[serviceType])){ - // _.each(services[serviceType],function(serv){ - // serviceName = serv.get('name'); - // if(SessionMgr.isSystemAdmin()){ - // serviceOperationDiv = '<div class="pull-right">\ - // <a data-id="'+serv.id+'" class="btn btn-mini" href="#!/service/'+serviceDef.id+'/edit/'+serv.id+'" title="Edit"><i class="icon-edit"></i></a>\ - // <a data-id="'+serv.id+'" class="deleteRepo btn btn-mini btn-danger" href="javascript:void(0);" title="Delete">\ - // <i class="icon-trash"></i></a>\ - // </div>' - // } - // tr += '<tr><td><div>\ - // <a data-id="'+serv.id+'" href="#!/service/'+serv.id+'/policies">'+_.escape(serv.attributes.name)+'</a>'+serviceOperationDiv+'\ - // </div></td></tr>'; - // }); - // } - // return tr; - // }); Handlebars.registerHelper('capitaliseLetter', function(str) { return str.toUpperCase(); }); - // Handlebars.registerHelper('hasAccessToTab', function(tabName,options) { - // var vxPortalUser = SessionMgr.getUserProfile(); - // var userModules = _.pluck(vxPortalUser.get('userPermList'), 'moduleName'); - // var groupModules = _.pluck(vxPortalUser.get('groupPermissions'), 'moduleName'); - // var moduleNames = _.union(userModules,groupModules); - // var returnFlag = _.contains(moduleNames, tabName); - // if (returnFlag) - // return options.fn(this); - // else - // return options.inverse(this); - // }); /*logserach*/ Handlebars.registerHelper ("setChecked", function (value, currentValue) { http://git-wip-us.apache.org/repos/asf/ambari/blob/c15ed8b7/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 deleted file mode 100644 index 017d7a8..0000000 --- a/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/AuditSolrDaoTest.java +++ /dev/null @@ -1,99 +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; - -import java.util.ArrayList; - -import org.apache.ambari.logsearch.conf.SolrAuditLogConfig; -import org.apache.ambari.logsearch.conf.SolrKerberosConfig; -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.easymock.EasyMockSupport; -import org.easymock.Mock; -import org.easymock.TestSubject; -import org.junit.Before; -import org.junit.Test; - -import junit.framework.Assert; - -public class AuditSolrDaoTest { - - @TestSubject - private AuditSolrDao dao = new AuditSolrDao(); - - @Mock - private SolrAuditLogConfig configMock; - - @Mock - private SolrKerberosConfig kerbConfigMock; - - @Before - public void setUp() { - EasyMockSupport.injectMocks(this); - } - - @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>()); - - EasyMock.expect(configMock.getSolrUrl()).andReturn(null); - EasyMock.expect(configMock.getZkConnectString()).andReturn("dummyHost1:2181,dummyHost2:2181"); - EasyMock.expect(configMock.getConfigName()).andReturn("test_audit_logs_config_name"); - EasyMock.expect(configMock.getCollection()).andReturn("test_audit_logs_collection"); - EasyMock.expect(configMock.getSplitInterval()).andReturn("none"); - EasyMock.expect(configMock.getNumberOfShards()).andReturn(123); - EasyMock.expect(configMock.getReplicationFactor()).andReturn(456); - EasyMock.expect(configMock.getAliasNameIn()).andReturn("alias"); - EasyMock.expect(configMock.getRangerCollection()).andReturn("ranger_audit"); - EasyMock.expect(kerbConfigMock.isEnabled()).andReturn(false); - EasyMock.expect(kerbConfigMock.getJaasFile()).andReturn("jaas_file"); - - 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, configMock, kerbConfigMock); - - 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/c15ed8b7/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 deleted file mode 100644 index bdee8a8..0000000 --- a/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/ServiceLogsSolrDaoTest.java +++ /dev/null @@ -1,95 +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; - -import java.util.ArrayList; - -import org.apache.ambari.logsearch.conf.SolrKerberosConfig; -import org.apache.ambari.logsearch.conf.SolrServiceLogConfig; -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.easymock.EasyMockSupport; -import org.easymock.Mock; -import org.easymock.TestSubject; -import org.junit.Before; -import org.junit.Test; - -import junit.framework.Assert; - -public class ServiceLogsSolrDaoTest { - - @TestSubject - private ServiceLogsSolrDao dao = new ServiceLogsSolrDao(); - - @Mock - private SolrKerberosConfig kerbConfigMock; - - @Mock - private SolrServiceLogConfig configMock; - - @Before - public void setUp() { - EasyMockSupport.injectMocks(this); - } - - @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>()); - - EasyMock.expect(configMock.getSolrUrl()).andReturn(null); - EasyMock.expect(configMock.getZkConnectString()).andReturn("dummyHost1:2181,dummyHost2:2181"); - EasyMock.expect(configMock.getConfigName()).andReturn("test_service_logs_config_name"); - EasyMock.expect(configMock.getCollection()).andReturn("test_service_logs_collection"); - EasyMock.expect(configMock.getSplitInterval()).andReturn("none"); - EasyMock.expect(configMock.getNumberOfShards()).andReturn(789); - EasyMock.expect(configMock.getReplicationFactor()).andReturn(987); - EasyMock.expect(kerbConfigMock.isEnabled()).andReturn(false); - EasyMock.expect(kerbConfigMock.getJaasFile()).andReturn("jaas_file"); - - 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, configMock, kerbConfigMock); - - dao.solrClient = mockSolrClient; - dao.isZkConnectString = true; - - dao.postConstructor(); - EasyMock.verify(mockSolrClient, configMock, kerbConfigMock); - - 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/c15ed8b7/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 deleted file mode 100644 index 22b10c3..0000000 --- a/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/SolrDaoBaseTest.java +++ /dev/null @@ -1,306 +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; - -import java.util.ArrayList; -import java.util.Arrays; - -import javax.ws.rs.WebApplicationException; - -import org.apache.ambari.logsearch.conf.SolrKerberosConfig; -import org.apache.ambari.logsearch.manager.ManagerBase.LogType; -import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.SolrQuery; -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.easymock.EasyMockSupport; -import org.easymock.Mock; -import org.easymock.TestSubject; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import junit.framework.Assert; - -public class SolrDaoBaseTest { - - @TestSubject - private SolrDaoBase dao = new SolrDaoBase(LogType.SERVICE) {}; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Mock - private SolrKerberosConfig kerbConfigMock; - - @Before - public void setUp() { - EasyMockSupport.injectMocks(this); - } - - // ----------------------------------------------------------- connectToSolr ----------------------------------------------------------- - - @Test - public void testConnectToSolrWithConnectString() throws Exception { - EasyMock.expect(kerbConfigMock.isEnabled()).andReturn(false); - EasyMock.expect(kerbConfigMock.getJaasFile()).andReturn("jaas_file"); - - EasyMock.replay(kerbConfigMock); - - SolrClient solrClient = dao.connectToSolr(null, "zk_connect_string", "collection"); - - Assert.assertEquals(solrClient.getClass(), CloudSolrClient.class); - } - - @Test - public void testConnectToSolrWithUrl() throws Exception { - EasyMock.expect(kerbConfigMock.isEnabled()).andReturn(false); - EasyMock.expect(kerbConfigMock.getJaasFile()).andReturn("jaas_file"); - - EasyMock.replay(kerbConfigMock); - - SolrClient solrClient = dao.connectToSolr("url", null, "collection"); - - Assert.assertEquals(solrClient.getClass(), HttpSolrClient.class); - } - - @Test - public void testConnectToSolrWithBoth() throws Exception { - EasyMock.expect(kerbConfigMock.isEnabled()).andReturn(false); - EasyMock.expect(kerbConfigMock.getJaasFile()).andReturn("jaas_file"); - - EasyMock.replay(kerbConfigMock); - - SolrClient solrClient = dao.connectToSolr("url", "zk_connect_string", "collection"); - - Assert.assertEquals(solrClient.getClass(), CloudSolrClient.class); - } - - @Test - public void testConnectToSolrWithNeither() throws Exception { - EasyMock.expect(kerbConfigMock.isEnabled()).andReturn(false); - EasyMock.expect(kerbConfigMock.getJaasFile()).andReturn("jaas_file"); - - EasyMock.replay(kerbConfigMock); - - expectedException.expect(Exception.class); - expectedException.expectMessage("Both zkConnectString and URL are empty. zkConnectString=null, collection=collection, url=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"); - - 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); - - 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); - - 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); - - 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); - - 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); - - 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); - - dao.solrClient = mockSolrClient; - - dao.process(new SolrQuery()); - - EasyMock.verify(mockSolrClient); - } - - @Test - public void testProcessNoConnection() throws Exception { - expectedException.expect(WebApplicationException.class); - - 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); - - 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); - - dao.solrClient = mockSolrClient; - - dao.removeDoc("query"); - - EasyMock.verify(mockSolrClient); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c15ed8b7/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 deleted file mode 100644 index 3b01a19..0000000 --- a/ambari-logsearch/ambari-logsearch-portal/src/test/java/org/apache/ambari/logsearch/dao/UserConfigSolrDaoTest.java +++ /dev/null @@ -1,164 +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; - -import java.util.ArrayList; -import java.util.Arrays; - -import org.apache.ambari.logsearch.conf.SolrKerberosConfig; -import org.apache.ambari.logsearch.conf.SolrUserConfig; -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.easymock.EasyMockSupport; -import org.easymock.Mock; -import org.easymock.TestSubject; -import org.junit.Before; -import org.junit.Test; - -import junit.framework.Assert; - -public class UserConfigSolrDaoTest { - - @TestSubject - private UserConfigSolrDao dao = new UserConfigSolrDao(); - - @Mock - private SolrUserConfig configMock; - - @Mock - private SolrKerberosConfig kerbConfigMock; - - @Before - public void setUp() { - EasyMockSupport.injectMocks(this); - } - - @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); - - EasyMock.expect(configMock.getSolrUrl()).andReturn(null).times(2); - EasyMock.expect(configMock.getZkConnectString()).andReturn("dummyHost1:2181,dummyHost2:2181").times(2); - EasyMock.expect(configMock.getConfigName()).andReturn("test_history_logs_config_name").times(2); - EasyMock.expect(configMock.getCollection()).andReturn("test_history_logs_collection").times(2); - EasyMock.expect(configMock.getSplitInterval()).andReturn("none").times(2); - EasyMock.expect(configMock.getNumberOfShards()).andReturn(123).times(2); - EasyMock.expect(configMock.getReplicationFactor()).andReturn(234).times(2); - EasyMock.expect(configMock.getLogLevels()).andReturn(Arrays.asList("TRACE")).times(2); - EasyMock.expect(kerbConfigMock.isEnabled()).andReturn(false).times(2); - EasyMock.expect(kerbConfigMock.getJaasFile()).andReturn("jaas_file").times(2); - - 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, configMock, kerbConfigMock); - - dao.postConstructor(); - 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\":[\"TRACE\"],\"overrideLevels\":[]},\"test_component1\":{\"label\":\"test_component1\",\"hosts\":[],\"defaultLevels\":[\"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(configMock.getSolrUrl()).andReturn(null); - EasyMock.expect(configMock.getZkConnectString()).andReturn("dummyHost1:2181,dummyHost2:2181"); - EasyMock.expect(configMock.getConfigName()).andReturn("test_history_logs_config_name"); - EasyMock.expect(configMock.getCollection()).andReturn("test_history_logs_collection"); - EasyMock.expect(configMock.getSplitInterval()).andReturn("none"); - EasyMock.expect(configMock.getNumberOfShards()).andReturn(123); - EasyMock.expect(configMock.getReplicationFactor()).andReturn(234); - EasyMock.expect(kerbConfigMock.isEnabled()).andReturn(false); - EasyMock.expect(kerbConfigMock.getJaasFile()).andReturn("jaas_file"); - - EasyMock.expect(mockSolrClient.deleteByQuery("id:test_id")).andReturn(updateResponse); - EasyMock.expect(mockSolrClient.commit()).andReturn(updateResponse); - EasyMock.replay(mockSolrClient, configMock, kerbConfigMock); - - dao.postConstructor(); - dao.solrClient = mockSolrClient; - dao.isZkConnectString = true; - - dao.deleteUserConfig("test_id"); - - EasyMock.verify(mockSolrClient, configMock, kerbConfigMock); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c15ed8b7/ambari-logsearch/docker/test-config/logsearch/logsearch.properties ---------------------------------------------------------------------- diff --git a/ambari-logsearch/docker/test-config/logsearch/logsearch.properties b/ambari-logsearch/docker/test-config/logsearch/logsearch.properties index 2c83581..71c1a1c 100644 --- a/ambari-logsearch/docker/test-config/logsearch/logsearch.properties +++ b/ambari-logsearch/docker/test-config/logsearch/logsearch.properties @@ -22,8 +22,6 @@ logsearch.service.logs.split.interval.mins=15 logsearch.collection.service.logs.numshards=3 logsearch.collection.service.logs.replication.factor=2 -logsearch.service.logs.fields=logtime,level,event_count,ip,type,seq_num,path,file,line_number,host,log_message,id - # Audit logs logsearch.solr.audit.logs.zk_connect_string=localhost:9983 logsearch.solr.collection.audit.logs=audit_logs