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 2017/03/29 13:57:20 UTC
[12/67] [abbrv] ambari git commit: AMBARI-20528. Rename Log Search
Portal module to Log Search Server (oleewere)
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ExternalServerClient.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ExternalServerClient.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ExternalServerClient.java
new file mode 100644
index 0000000..df00c15
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ExternalServerClient.java
@@ -0,0 +1,83 @@
+/*
+ * 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 javax.inject.Inject;
+import javax.inject.Named;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.apache.ambari.logsearch.conf.AuthPropsConfig;
+import org.apache.ambari.logsearch.util.SSLUtil;
+import org.apache.commons.httpclient.auth.InvalidCredentialsException;
+import org.apache.log4j.Logger;
+import org.glassfish.jersey.client.JerseyClient;
+import org.glassfish.jersey.client.JerseyClientBuilder;
+import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
+
+/**
+ * Layer to send REST request to External server using jersey client
+ */
+@Named
+public class ExternalServerClient {
+
+ private static Logger LOG = Logger.getLogger(ExternalServerClient.class);
+ private static final ThreadLocal<JerseyClient> localJerseyClient = new ThreadLocal<JerseyClient>() {
+ @Override
+ protected JerseyClient initialValue() {
+ return SSLUtil.isKeyStoreSpecified() ?
+ new JerseyClientBuilder().sslContext(SSLUtil.getSSLContext()).build() :
+ JerseyClientBuilder.createClient();
+ }
+ };
+
+ @Inject
+ private AuthPropsConfig authPropsConfig;
+
+ /**
+ * Send GET request to an external server
+ */
+ public Object sendGETRequest(String loginUrl, Class<?> klass, String username, String password) throws Exception {
+ String url = authPropsConfig.getExternalAuthHostUrl() + loginUrl;
+ JerseyClient client = localJerseyClient.get();
+ HttpAuthenticationFeature authFeature = HttpAuthenticationFeature.basicBuilder()
+ .credentials(username, password)
+ .build();
+ client.register(authFeature);
+
+ WebTarget target = client.target(url);
+ LOG.debug("URL: " + url);
+
+ Invocation.Builder invocationBuilder = target.request();
+ try {
+ Response response = invocationBuilder.get();
+ if (response.getStatus() != Response.Status.OK.getStatusCode()
+ && response.getStatus() != Response.Status.FOUND.getStatusCode()) {
+ throw new InvalidCredentialsException(String.format("External auth failed with status code: %d, response: %s",
+ response.getStatus(), response.readEntity(String.class)));
+ }
+ return response.readEntity(klass);
+ } catch (Exception e) {
+ throw new Exception(e.getCause());
+ } finally {
+ localJerseyClient.remove();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/HadoopServiceConfigHelper.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/HadoopServiceConfigHelper.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/HadoopServiceConfigHelper.java
new file mode 100644
index 0000000..0e2087f
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/HadoopServiceConfigHelper.java
@@ -0,0 +1,80 @@
+/*
+ * 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.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.ambari.logsearch.util.JSONUtil;
+import org.apache.commons.io.FileUtils;
+import org.apache.log4j.Logger;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+
+import com.google.gson.JsonParseException;
+
+public class HadoopServiceConfigHelper {
+ private static final Logger LOG = Logger.getLogger(HadoopServiceConfigHelper.class);
+
+ public static String getHadoopServiceConfigJSON() {
+ String fileContent = null;
+
+ try {
+ ClassLoader classLoader = HadoopServiceConfigHelper.class.getClassLoader();
+ File file = new File(classLoader.getResource("HadoopServiceConfig.json").getFile());
+ fileContent = FileUtils.readFileToString(file);
+ } catch (IOException e) {
+ LOG.error("Unable to read HadoopServiceConfig.json", e);
+ }
+
+ return JSONUtil.isJSONValid(fileContent) ? fileContent : null;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static Set<String> getAllLogIds() {
+ Set<String> logIds = new TreeSet<>();
+
+ String key = null;
+ JSONArray componentArray = null;
+ try {
+ String hadoopServiceConfigJSON = getHadoopServiceConfigJSON();
+ JSONObject hadoopServiceJsonObject = new JSONObject(hadoopServiceConfigJSON).getJSONObject("service");
+ Iterator<String> hadoopSerivceKeys = hadoopServiceJsonObject.keys();
+ while (hadoopSerivceKeys.hasNext()) {
+ key = hadoopSerivceKeys.next();
+ componentArray = hadoopServiceJsonObject.getJSONObject(key).getJSONArray("components");
+ for (int i = 0; i < componentArray.length(); i++) {
+ JSONObject componentJsonObject = (JSONObject) componentArray.get(i);
+ String logId = componentJsonObject.getString("name");
+ logIds.add(logId);
+ }
+ }
+ } catch (JsonParseException | JSONException je) {
+ LOG.error("Error parsing JSON. key=" + key + ", componentArray=" + componentArray, je);
+ return null;
+ }
+
+ return logIds;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java
new file mode 100644
index 0000000..3a74918
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ambari.logsearch.common;
+
+public class LogSearchConstants {
+
+ public static final String LOGSEARCH_SESSION_ID = "LOGSEARCHSESSIONID";
+
+ // Log Levels
+ public static final String INFO = "INFO";
+ public static final String WARN = "WARN";
+ public static final String DEBUG = "DEBUG";
+ public static final String ERROR = "ERROR";
+ public static final String TRACE = "TRACE";
+ public static final String FATAL = "FATAL";
+ public static final String UNKNOWN = "UNKNOWN";
+
+ public static final String[] SUPPORTED_LOG_LEVELS = {FATAL, ERROR, WARN, INFO, DEBUG, TRACE, UNKNOWN};
+
+ // Application Constants
+ public static final String HOST = "H";
+ public static final String COMPONENT = "C";
+ public static final String SCROLL_TYPE_AFTER = "after";
+ public static final String SCROLL_TYPE_BEFORE = "before";
+
+ // Seprator's
+ public static final String I_E_SEPRATOR = "\\|i\\:\\:e\\|";
+
+ //SUFFIX
+ public static final String NGRAM_PREFIX = "ngram_";
+
+ //Date Format for SOLR
+ public static final String SOLR_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss,SSS";
+ public static final String SOLR_DATE_FORMAT_PREFIX_Z = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
+
+ //Solr Order By
+ public static final String ASCENDING_ORDER = "asc";
+ public static final String DESCENDING_ORDER = "desc";
+
+ // logfeeder
+ public static final String LOGFEEDER_FILTER_NAME = "log_feeder_config";
+
+ public static final String SORT = "sort";
+
+ //Facet Constant
+ public static final String FACET_FIELD = "facet.field";
+ public static final String FACET_PIVOT = "facet.pivot";
+ public static final String FACET_PIVOT_MINCOUNT = "facet.pivot.mincount";
+ public static final String FACET_INDEX = "index";
+
+ // Request params
+ public static final String REQUEST_PARAM_XAXIS = "xAxis";
+ public static final String REQUEST_PARAM_YAXIS = "yAxis";
+ public static final String REQUEST_PARAM_STACK_BY = "stackBy";
+ public static final String REQUEST_PARAM_UNIT = "unit";
+ public static final String REQUEST_PARAM_TOP = "top";
+ public static final String REQUEST_PARAM_CLUSTER_NAMES = "clusters";
+ public static final String REQUEST_PARAM_BUNDLE_ID = "bundle_id";
+ public static final String REQUEST_PARAM_START_INDEX = "startIndex";
+ public static final String REQUEST_PARAM_PAGE = "page";
+ public static final String REQUEST_PARAM_PAGE_SIZE = "pageSize";
+ public static final String REQUEST_PARAM_SORT_BY = "sortBy";
+ public static final String REQUEST_PARAM_SORT_TYPE = "sortType";
+ public static final String REQUEST_PARAM_START_TIME = "start_time";
+ public static final String REQUEST_PARAM_END_TIME = "end_time";
+ public static final String REQUEST_PARAM_FROM = "from";
+ public static final String REQUEST_PARAM_TO = "to";
+ public static final String REQUEST_PARAM_FIELD = "field";
+ public static final String REQUEST_PARAM_FORMAT = "format";
+ public static final String REQUEST_PARAM_LAST_PAGE = "lastPage";
+ public static final String REQUEST_PARAM_I_MESSAGE = "iMessage";
+ public static final String REQUEST_PARAM_E_MESSAGE = "eMessage";
+ public static final String REQUEST_PARAM_MUST_BE = "mustBe";
+ public static final String REQUEST_PARAM_MUST_NOT = "mustNot";
+ public static final String REQUEST_PARAM_INCLUDE_QUERY = "includeQuery";
+ public static final String REQUEST_PARAM_EXCLUDE_QUERY = "excludeQuery";
+ public static final String REQUEST_PARAM_ID = "id";
+ public static final String REQUEST_PARAM_SCROLL_TYPE = "scrollType";
+ public static final String REQUEST_PARAM_NUMBER_ROWS = "numberRows";
+ public static final String REQUEST_PARAM_LEVEL = "level";
+ public static final String REQUEST_PARAM_HOST_NAME = "host_name";
+ public static final String REQUEST_PARAM_COMPONENT_NAME = "component_name";
+ public static final String REQUEST_PARAM_FILE_NAME = "file_name";
+ public static final String REQUEST_PARAM_KEYWORD = "find";
+ public static final String REQUEST_PARAM_SOURCE_LOG_ID = "sourceLogId";
+ public static final String REQUEST_PARAM_KEYWORD_TYPE = "keywordType";
+ public static final String REQUEST_PARAM_TOKEN = "token";
+ public static final String REQUEST_PARAM_FILTER_NAME = "filterName";
+ public static final String REQUEST_PARAM_ROW_TYPE = "rowType";
+ public static final String REQUEST_PARAM_UTC_OFFSET = "utcOffset";
+ public static final String REQUEST_PARAM_HOSTS = "hostList";
+
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchContext.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchContext.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchContext.java
new file mode 100644
index 0000000..b4b52b3
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/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/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogType.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogType.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogType.java
new file mode 100644
index 0000000..2e6cddb
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogType.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ambari.logsearch.common;
+
+public enum LogType {
+ SERVICE("Service"),
+ AUDIT("Audit");
+
+ private String label;
+
+ private LogType(String label) {
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ManageStartEndTime.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ManageStartEndTime.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ManageStartEndTime.java
new file mode 100644
index 0000000..b6aa2d0
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ManageStartEndTime.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ambari.logsearch.common;
+
+import java.util.Date;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.apache.commons.lang.time.DateUtils;
+
+public class ManageStartEndTime extends TimerTask {
+ 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 synchronized void run() {
+ synchronized (ManageStartEndTime.class) {
+ startDate = DateUtils.addSeconds(startDate, UPDATE_TIME_IN_SECONDS);
+ endDate = DateUtils.addHours(startDate, 1);
+ }
+ }
+
+ public static synchronized Date[] getStartEndTime() {
+ return new Date[] {startDate, endDate};
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/Marker.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/Marker.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/Marker.java
new file mode 100644
index 0000000..3e088ba
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/Marker.java
@@ -0,0 +1,29 @@
+/*
+ * 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.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Marker {
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/MessageData.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/MessageData.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/MessageData.java
new file mode 100644
index 0000000..34c83ee
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/MessageData.java
@@ -0,0 +1,165 @@
+/*
+* 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 javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class MessageData implements java.io.Serializable {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Message key
+ */
+ protected String name;
+ /**
+ * Resource bundle key
+ */
+ protected String rbKey;
+ /**
+ * Message description. Use rbKey for doing localized lookup
+ */
+ protected String message;
+ /**
+ * Id of the object to which this message is related to
+ */
+ protected Long objectId;
+ /**
+ * Name of the field or attribute to which this message is related to
+ */
+ protected String fieldName;
+
+ /**
+ * This method sets the value to the member attribute <b>name</b>. You
+ * cannot set null to the attribute.
+ *
+ * @param name
+ * Value to set member attribute <b>name</b>
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the value for the member attribute <b>name</b>
+ *
+ * @return String - value of member attribute <b>name</b>.
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * This method sets the value to the member attribute <b>rbKey</b>. You
+ * cannot set null to the attribute.
+ *
+ * @param rbKey
+ * Value to set member attribute <b>rbKey</b>
+ */
+ public void setRbKey(String rbKey) {
+ this.rbKey = rbKey;
+ }
+
+ /**
+ * Returns the value for the member attribute <b>rbKey</b>
+ *
+ * @return String - value of member attribute <b>rbKey</b>.
+ */
+ public String getRbKey() {
+ return this.rbKey;
+ }
+
+ /**
+ * This method sets the value to the member attribute <b>message</b>. You
+ * cannot set null to the attribute.
+ *
+ * @param message
+ * Value to set member attribute <b>message</b>
+ */
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ /**
+ * Returns the value for the member attribute <b>message</b>
+ *
+ * @return String - value of member attribute <b>message</b>.
+ */
+ public String getMessage() {
+ return this.message;
+ }
+
+ /**
+ * This method sets the value to the member attribute <b>objectId</b>. You
+ * cannot set null to the attribute.
+ *
+ * @param objectId
+ * Value to set member attribute <b>objectId</b>
+ */
+ public void setObjectId(Long objectId) {
+ this.objectId = objectId;
+ }
+
+ /**
+ * Returns the value for the member attribute <b>objectId</b>
+ *
+ * @return Long - value of member attribute <b>objectId</b>.
+ */
+ public Long getObjectId() {
+ return this.objectId;
+ }
+
+ /**
+ * This method sets the value to the member attribute <b>fieldName</b>. You
+ * cannot set null to the attribute.
+ *
+ * @param fieldName
+ * Value to set member attribute <b>fieldName</b>
+ */
+ public void setFieldName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ /**
+ * Returns the value for the member attribute <b>fieldName</b>
+ *
+ * @return String - value of member attribute <b>fieldName</b>.
+ */
+ public String getFieldName() {
+ return this.fieldName;
+ }
+
+ /**
+ * This return the bean content in string format
+ *
+ * @return formatedStr
+ */
+ public String toString() {
+ String str = "MessageData={";
+ str += super.toString();
+ str += "name={" + name + "} ";
+ str += "rbKey={" + rbKey + "} ";
+ str += "message={" + message + "} ";
+ str += "objectId={" + objectId + "} ";
+ str += "fieldName={" + fieldName + "} ";
+ str += "}";
+ return str;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/MessageEnums.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/MessageEnums.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/MessageEnums.java
new file mode 100644
index 0000000..4f1725f
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/MessageEnums.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ambari.logsearch.common;
+
+public 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."),
+ ZNODE_NOT_READY("logsearch.zk.znode.error", "ZNode is not available."),
+ ZK_CONFIG_NOT_READY("logsearch.zk.config.error", "Collection configuration has not uploaded yet"),
+ SOLR_COLLECTION_NOT_READY("logsearch.solr.collection.error", "Solr has not accessible yet for collection."),
+
+ // 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");
+
+ private String rbKey;
+ private String messageDesc;
+
+ private MessageEnums(String rbKey, String messageDesc) {
+ this.rbKey = rbKey;
+ this.messageDesc = messageDesc;
+ }
+
+ public MessageData getMessage() {
+ MessageData msg = new MessageData();
+ msg.setName(this.toString());
+ msg.setRbKey(rbKey);
+ msg.setMessage(messageDesc);
+ return msg;
+ }
+
+ public MessageData getMessage(Long objectId, String fieldName) {
+ MessageData msg = new MessageData();
+ msg.setName(this.toString());
+ msg.setRbKey(rbKey);
+ msg.setMessage(messageDesc);
+ msg.setObjectId(objectId);
+ msg.setFieldName(fieldName);
+ return msg;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertiesHelper.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertiesHelper.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertiesHelper.java
new file mode 100644
index 0000000..73a43ad
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertiesHelper.java
@@ -0,0 +1,138 @@
+/*
+ * 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.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
+
+public class PropertiesHelper extends PropertyPlaceholderConfigurer {
+ private static final Logger logger = LoggerFactory.getLogger(PropertiesHelper.class);
+
+ private static final String LOGSEARCH_PROP_FILE="logsearch.properties";
+
+ private static Map<String, String> propertiesMap;
+
+ private PropertiesHelper() {
+ }
+
+ static {
+ propertiesMap = new HashMap<String, String>();
+ Properties properties = new Properties();
+ URL fileCompleteUrl = Thread.currentThread().getContextClassLoader().getResource(LOGSEARCH_PROP_FILE);
+ FileInputStream fileInputStream = null;
+ try {
+ File file = new File(fileCompleteUrl.toURI());
+ fileInputStream = new FileInputStream(file.getAbsoluteFile());
+ properties.load(fileInputStream);
+ } catch (IOException | URISyntaxException e) {
+ logger.error("error loading prop for protocol config",e);
+ } finally {
+ if (fileInputStream != null) {
+ try {
+ fileInputStream.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ for (String key : properties.stringPropertyNames()) {
+ String value = properties.getProperty(key);
+ propertiesMap.put(key, value);
+ }
+ }
+
+ @Override
+ protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) throws BeansException {
+ super.processProperties(beanFactory, props);
+
+ propertiesMap = new HashMap<String, String>();
+
+ // First add the system properties
+ Set<Object> keySet = System.getProperties().keySet();
+ for (Object key : keySet) {
+ String keyStr = key.toString();
+ propertiesMap.put(keyStr, System.getProperties().getProperty(keyStr).trim());
+ }
+
+ // add our properties now
+ keySet = props.keySet();
+ for (Object key : keySet) {
+ String keyStr = key.toString();
+ propertiesMap.put(keyStr, props.getProperty(keyStr).trim());
+ }
+ }
+
+ public static String getProperty(String key, String defaultValue) {
+ if (key == null) {
+ return null;
+ }
+ String rtrnVal = propertiesMap.get(key);
+ if (rtrnVal == null) {
+ rtrnVal = defaultValue;
+ }
+ return rtrnVal;
+ }
+
+ public static String getProperty(String key) {
+ if (key == null) {
+ return null;
+ }
+ return propertiesMap.get(key);
+ }
+
+ public static String[] getPropertyStringList(String key) {
+ if (key == null) {
+ return null;
+ }
+ String value = propertiesMap.get(key);
+ if (value == null || value.trim().equals("")) {
+ return new String[0];
+ } else {
+ String[] splitValues = value.split(",");
+ String[] returnValues = new String[splitValues.length];
+ for (int i = 0; i < splitValues.length; i++) {
+ returnValues[i] = splitValues[i].trim();
+ }
+ return returnValues;
+ }
+ }
+
+ public static boolean getBooleanProperty(String key, boolean defaultValue) {
+ if (key == null) {
+ return defaultValue;
+ }
+ String value = getProperty(key);
+ if (value == null) {
+ return defaultValue;
+ }
+ return Boolean.parseBoolean(value);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/StatusMessage.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/StatusMessage.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/StatusMessage.java
new file mode 100644
index 0000000..d4567de
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/StatusMessage.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ambari.logsearch.common;
+
+public class StatusMessage {
+
+ private String status;
+
+ public StatusMessage(String status) {
+ this.status = status;
+ }
+
+ public StatusMessage(int status) {
+ this.status = String.valueOf(status);
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/VResponse.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/VResponse.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/VResponse.java
new file mode 100644
index 0000000..0c052ab
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/VResponse.java
@@ -0,0 +1,164 @@
+/*
+ * 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.List;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class VResponse implements
+ java.io.Serializable {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Enum values for ResponseStatus
+ */
+ /**
+ * STATUS_SUCCESS is an element of enum ResponseStatus. Its value is
+ * "STATUS_SUCCESS".
+ */
+ public static final int STATUS_SUCCESS = 0;
+ /**
+ * STATUS_ERROR is an element of enum ResponseStatus. Its value is
+ * "STATUS_ERROR".
+ */
+ public static final int STATUS_ERROR = 1;
+ /**
+ * STATUS_VALIDATION is an element of enum ResponseStatus. Its value is
+ * "STATUS_VALIDATION".
+ */
+ public static final int STATUS_VALIDATION = 2;
+ /**
+ * STATUS_WARN is an element of enum ResponseStatus. Its value is
+ * "STATUS_WARN".
+ */
+ public static final int STATUS_WARN = 3;
+ /**
+ * STATUS_INFO is an element of enum ResponseStatus. Its value is
+ * "STATUS_INFO".
+ */
+ public static final int STATUS_INFO = 4;
+ /**
+ * STATUS_PARTIAL_SUCCESS is an element of enum ResponseStatus. Its value is
+ * "STATUS_PARTIAL_SUCCESS".
+ */
+ public static final int STATUS_PARTIAL_SUCCESS = 5;
+
+ /**
+ * Max value for enum ResponseStatus_MAX
+ */
+ public static final int ResponseStatus_MAX = 5;
+
+ /**
+ * Status code This attribute is of type enum Response::ResponseStatus
+ */
+ protected int statusCode;
+ /**
+ * Message description
+ */
+ protected String msgDesc;
+ /**
+ * List of messages
+ */
+ protected List<MessageData> messageList;
+
+ /**
+ * Default constructor. This will set all the attributes to default value.
+ */
+ public VResponse() {
+ statusCode = 0;
+ }
+
+ /**
+ * This method sets the value to the member attribute <b>statusCode</b>. You
+ * cannot set null to the attribute.
+ *
+ * @param statusCode
+ * Value to set member attribute <b>statusCode</b>
+ */
+ public void setStatusCode(int statusCode) {
+ this.statusCode = statusCode;
+ }
+
+ /**
+ * Returns the value for the member attribute <b>statusCode</b>
+ *
+ * @return int - value of member attribute <b>statusCode</b>.
+ */
+ public int getStatusCode() {
+ return this.statusCode;
+ }
+
+ /**
+ * This method sets the value to the member attribute <b>msgDesc</b>. You
+ * cannot set null to the attribute.
+ *
+ * @param msgDesc
+ * Value to set member attribute <b>msgDesc</b>
+ */
+ public void setMsgDesc(String msgDesc) {
+ this.msgDesc = msgDesc;
+ }
+
+ /**
+ * Returns the value for the member attribute <b>msgDesc</b>
+ *
+ * @return String - value of member attribute <b>msgDesc</b>.
+ */
+ public String getMsgDesc() {
+ return this.msgDesc;
+ }
+
+ /**
+ * This method sets the value to the member attribute <b>messageList</b>.
+ * You cannot set null to the attribute.
+ *
+ * @param messageList
+ * Value to set member attribute <b>messageList</b>
+ */
+ public void setMessageList(List<MessageData> messageList) {
+ this.messageList = messageList;
+ }
+
+ /**
+ * Returns the value for the member attribute <b>messageList</b>
+ *
+ * @return List<MessageData> - value of member attribute <b>messageList</b>.
+ */
+ public List<MessageData> getMessageList() {
+ return this.messageList;
+ }
+
+ /**
+ * This return the bean content in string format
+ *
+ * @return formatedStr
+ */
+ public String toString() {
+ String str = "VResponse={";
+ str += super.toString();
+ str += "statusCode={" + statusCode + "} ";
+ str += "msgDesc={" + msgDesc + "} ";
+ str += "messageList={" + messageList + "} ";
+ str += "}";
+ return str;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/XMLPropertiesHelper.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/XMLPropertiesHelper.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/XMLPropertiesHelper.java
new file mode 100644
index 0000000..690a60f
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/XMLPropertiesHelper.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ambari.logsearch.common;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.log4j.Logger;
+import org.springframework.util.DefaultPropertiesPersister;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class XMLPropertiesHelper extends DefaultPropertiesPersister {
+ private static Logger logger = Logger.getLogger(XMLPropertiesHelper.class);
+
+ public XMLPropertiesHelper() {
+ }
+
+ @Override
+ public void loadFromXml(Properties properties, InputStream inputStream)
+ throws IOException {
+ try {
+ DocumentBuilderFactory xmlDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
+ xmlDocumentBuilderFactory.setIgnoringComments(true);
+ xmlDocumentBuilderFactory.setNamespaceAware(true);
+ DocumentBuilder xmlDocumentBuilder = xmlDocumentBuilderFactory.newDocumentBuilder();
+ Document xmlDocument = xmlDocumentBuilder.parse(inputStream);
+ if (xmlDocument != null) {
+ xmlDocument.getDocumentElement().normalize();
+ NodeList nList = xmlDocument.getElementsByTagName("property");
+ if (nList != null) {
+ for (int temp = 0; temp < nList.getLength(); temp++) {
+ Node nNode = nList.item(temp);
+ if (nNode.getNodeType() == Node.ELEMENT_NODE) {
+ Element eElement = (Element) nNode;
+ String propertyName = "";
+ String propertyValue = "";
+ if (eElement.getElementsByTagName("name") != null && eElement.getElementsByTagName("name").item(0) != null) {
+ propertyName = eElement.getElementsByTagName("name").item(0).getTextContent().trim();
+ }
+ if (eElement.getElementsByTagName("value") != null && eElement.getElementsByTagName("value").item(0) != null) {
+ propertyValue = eElement.getElementsByTagName("value").item(0).getTextContent().trim();
+ }
+ if (propertyName != null && !propertyName.isEmpty()) {
+ properties.put(propertyName, propertyValue);
+ }
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ logger.error("Error loading xml properties ", e);
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
new file mode 100644
index 0000000..630e73a
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
@@ -0,0 +1,55 @@
+/*
+ * 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.conf;
+
+import io.swagger.jaxrs.config.BeanConfig;
+import io.swagger.jaxrs.listing.ApiListingResource;
+import io.swagger.jaxrs.listing.SwaggerSerializers;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class ApiDocConfig {
+
+ @Bean
+ public ApiListingResource apiListingResource() {
+ return new ApiListingResource();
+ }
+
+ @Bean
+ public SwaggerSerializers swaggerSerializers() {
+ return new SwaggerSerializers();
+ }
+
+ @Bean
+ public BeanConfig swaggerConfig() {
+ BeanConfig beanConfig = new BeanConfig();
+ beanConfig.setSchemes(new String[]{"http", "https"});
+ beanConfig.setBasePath("/api/v1");
+ beanConfig.setTitle("Log Search REST API");
+ beanConfig.setDescription("Log aggregation, analysis, and visualization.");
+ beanConfig.setLicense("Apache 2.0");
+ beanConfig.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html");
+ beanConfig.setScan(true);
+ beanConfig.setVersion("1.0.0");
+ beanConfig.setResourcePackage("org.apache.ambari.logsearch.rest");
+ return beanConfig;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApplicationConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApplicationConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApplicationConfig.java
new file mode 100644
index 0000000..82a09b2
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApplicationConfig.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.conf;
+
+import freemarker.template.TemplateException;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.context.support.ConversionServiceFactoryBean;
+import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
+import org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean;
+
+import java.io.IOException;
+
+@Configuration
+@ComponentScan("org.apache.ambari.logsearch")
+@PropertySource(value = {"classpath:default.properties", "classpath:logsearch.properties"})
+public class ApplicationConfig {
+
+ @Bean
+ public static PropertySourcesPlaceholderConfigurer propertyConfigurer() {
+ return new PropertySourcesPlaceholderConfigurer();
+ }
+
+ @Bean(name="conversionService")
+ public ConversionServiceFactoryBean conversionServiceFactoryBean() {
+ ConversionServiceFactoryBean conversionServiceFactoryBean = new ConversionServiceFactoryBean();
+ conversionServiceFactoryBean.afterPropertiesSet();
+ return conversionServiceFactoryBean;
+ }
+
+ @Bean
+ public freemarker.template.Configuration freemarkerConfiguration() throws IOException, TemplateException {
+ FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean();
+ factoryBean.setPreferFileSystemAccess(false);
+ factoryBean.setTemplateLoaderPath("classpath:/templates");
+ factoryBean.afterPropertiesSet();
+ return factoryBean.getObject();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/AuthPropsConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/AuthPropsConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/AuthPropsConfig.java
new file mode 100644
index 0000000..54cc10c
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/AuthPropsConfig.java
@@ -0,0 +1,159 @@
+/*
+ * 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.conf;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.List;
+
+@Configuration
+public class AuthPropsConfig {
+
+ @Value("${logsearch.auth.file.enabled:true}")
+ boolean authFileEnabled;
+ @Value("${logsearch.auth.ldap.enabled:false}")
+ boolean authLdapEnabled;
+ @Value("${logsearch.auth.simple.enabled:false}")
+ boolean authSimpleEnabled;
+ @Value("${logsearch.auth.external_auth.enabled:false}")
+ boolean authExternalEnabled;
+ @Value("${logsearch.auth.external_auth.host_url:'http://ip:port'}")
+ private String externalAuthHostUrl;
+ @Value("${logsearch.auth.external_auth.login_url:/api/v1/users/$USERNAME/privileges?fields=*}")
+ private String externalAuthLoginUrl;
+ @Value("${logsearch.login.credentials.file:user_pass.json}")
+ private String credentialsFile;
+ @Value("${logsearch.auth.jwt.enabled:false}")
+ private boolean authJwtEnabled;
+ @Value("${logsearch.auth.jwt.provider_url:}")
+ private String providedUrl;
+ @Value("${logsearch.auth.jwt.public_key:}")
+ private String publicKey;
+ @Value("${logsearch.auth.jwt.cookie.name:hadoop-jwt}")
+ private String cookieName;
+ @Value("${logsearch.auth.jwt.query.param.original_url:originalUrl=}")
+ private String originalUrlQueryParam;
+ @Value("#{'${logsearch.auth.jwt.audiances:}'.split(',')}")
+ private List<String> audiences;
+
+ public boolean isAuthFileEnabled() {
+ return authFileEnabled;
+ }
+
+ public void setAuthFileEnabled(boolean authFileEnabled) {
+ this.authFileEnabled = authFileEnabled;
+ }
+
+ public boolean isAuthLdapEnabled() {
+ return authLdapEnabled;
+ }
+
+ public void setAuthLdapEnabled(boolean authLdapEnabled) {
+ this.authLdapEnabled = authLdapEnabled;
+ }
+
+ public boolean isAuthSimpleEnabled() {
+ return authSimpleEnabled;
+ }
+
+ public void setAuthSimpleEnabled(boolean authSimpleEnabled) {
+ this.authSimpleEnabled = authSimpleEnabled;
+ }
+
+ public String getCredentialsFile() {
+ return credentialsFile;
+ }
+
+ public void setCredentialsFile(String credentialsFile) {
+ this.credentialsFile = credentialsFile;
+ }
+
+ public String getExternalAuthHostUrl() {
+ return externalAuthHostUrl;
+ }
+
+ public void setExternalAuthHostUrl(String externalAuthHostUrl) {
+ this.externalAuthHostUrl = externalAuthHostUrl;
+ }
+
+ public String getExternalAuthLoginUrl() {
+ return externalAuthLoginUrl;
+ }
+
+ public void setExternalAuthLoginUrl(String externalAuthLoginUrl) {
+ this.externalAuthLoginUrl = externalAuthLoginUrl;
+ }
+
+ public boolean isAuthExternalEnabled() {
+ return authExternalEnabled;
+ }
+
+ public void setAuthExternalEnabled(boolean authExternalEnabled) {
+ this.authExternalEnabled = authExternalEnabled;
+ }
+
+ public boolean isAuthJwtEnabled() {
+ return authJwtEnabled;
+ }
+
+ public void setAuthJwtEnabled(boolean authJwtEnabled) {
+ this.authJwtEnabled = authJwtEnabled;
+ }
+
+ public String getProvidedUrl() {
+ return providedUrl;
+ }
+
+ public void setProvidedUrl(String providedUrl) {
+ this.providedUrl = providedUrl;
+ }
+
+ public String getPublicKey() {
+ return publicKey;
+ }
+
+ public void setPublicKey(String publicKey) {
+ this.publicKey = publicKey;
+ }
+
+ public String getCookieName() {
+ return cookieName;
+ }
+
+ public void setCookieName(String cookieName) {
+ this.cookieName = cookieName;
+ }
+
+ public String getOriginalUrlQueryParam() {
+ return originalUrlQueryParam;
+ }
+
+ public void setOriginalUrlQueryParam(String originalUrlQueryParam) {
+ this.originalUrlQueryParam = originalUrlQueryParam;
+ }
+
+ public List<String> getAudiences() {
+ return audiences;
+ }
+
+ public void setAudiences(List<String> audiences) {
+ this.audiences = audiences;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpHeaderConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpHeaderConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpHeaderConfig.java
new file mode 100644
index 0000000..cb8c097
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpHeaderConfig.java
@@ -0,0 +1,70 @@
+/*
+ * 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.conf;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class LogSearchHttpHeaderConfig {
+
+ @Value("${logsearch.http.header.access-control-allow-origin:*}")
+ private String accessControlAllowOrigin;
+
+ @Value("${logsearch.http.header.access-control-allow-headers:origin, content-type, accept, authorization}")
+ private String accessControlAllowHeaders;
+
+ @Value("${logsearch.http.header.access-control-allow-credentials:true}")
+ private String accessControlAllowCredentials;
+
+ @Value("${logsearch.http.header.access-control-allow-methods:GET, POST, PUT, DELETE, OPTIONS, HEAD}")
+ private String accessControlAllowMethods;
+
+ public String getAccessControlAllowOrigin() {
+ return accessControlAllowOrigin;
+ }
+
+ public void setAccessControlAllowOrigin(String accessControlAllowOrigin) {
+ this.accessControlAllowOrigin = accessControlAllowOrigin;
+ }
+
+ public String getAccessControlAllowHeaders() {
+ return accessControlAllowHeaders;
+ }
+
+ public void setAccessControlAllowHeaders(String accessControlAllowHeaders) {
+ this.accessControlAllowHeaders = accessControlAllowHeaders;
+ }
+
+ public String getAccessControlAllowCredentials() {
+ return accessControlAllowCredentials;
+ }
+
+ public void setAccessControlAllowCredentials(String accessControlAllowCredentials) {
+ this.accessControlAllowCredentials = accessControlAllowCredentials;
+ }
+
+ public String getAccessControlAllowMethods() {
+ return accessControlAllowMethods;
+ }
+
+ public void setAccessControlAllowMethods(String accessControlAllowMethods) {
+ this.accessControlAllowMethods = accessControlAllowMethods;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java
new file mode 100644
index 0000000..2f9cba4
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java
@@ -0,0 +1,209 @@
+/*
+ * 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.conf;
+
+import com.google.common.collect.Lists;
+import org.apache.ambari.logsearch.conf.global.SolrCollectionState;
+import org.apache.ambari.logsearch.web.authenticate.LogsearchAuthFailureHandler;
+import org.apache.ambari.logsearch.web.authenticate.LogsearchAuthSuccessHandler;
+import org.apache.ambari.logsearch.web.authenticate.LogsearchLogoutSuccessHandler;
+import org.apache.ambari.logsearch.web.filters.LogsearchAuditLogsStateFilter;
+import org.apache.ambari.logsearch.web.filters.LogsearchAuthenticationEntryPoint;
+import org.apache.ambari.logsearch.web.filters.LogsearchCorsFilter;
+import org.apache.ambari.logsearch.web.filters.LogsearchKRBAuthenticationFilter;
+import org.apache.ambari.logsearch.web.filters.LogsearchJWTFilter;
+import org.apache.ambari.logsearch.web.filters.LogsearchSecurityContextFormationFilter;
+import org.apache.ambari.logsearch.web.filters.LogsearchServiceLogsStateFilter;
+import org.apache.ambari.logsearch.web.filters.LogsearchUserConfigStateFilter;
+import org.apache.ambari.logsearch.web.filters.LogsearchUsernamePasswordAuthenticationFilter;
+import org.apache.ambari.logsearch.web.security.LogsearchAuthenticationProvider;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.config.http.SessionCreationPolicy;
+import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
+import org.springframework.security.web.util.matcher.OrRequestMatcher;
+import org.springframework.security.web.util.matcher.RequestMatcher;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.List;
+
+import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_SESSION_ID;
+
+@Configuration
+@EnableWebSecurity
+public class SecurityConfig extends WebSecurityConfigurerAdapter {
+
+ @Inject
+ private AuthPropsConfig authPropsConfig;
+
+ @Inject
+ private LogSearchHttpHeaderConfig logSearchHttpHeaderConfig;
+
+ @Inject
+ private SolrServiceLogPropsConfig solrServiceLogPropsConfig;
+
+ @Inject
+ private SolrAuditLogPropsConfig solrAuditLogPropsConfig;
+
+ @Inject
+ private SolrUserPropsConfig solrUserPropsConfig;
+
+ @Inject
+ @Named("solrServiceLogsState")
+ private SolrCollectionState solrServiceLogsState;
+
+ @Inject
+ @Named("solrAuditLogsState")
+ private SolrCollectionState solrAuditLogsState;
+
+ @Inject
+ @Named("solrUserConfigState")
+ private SolrCollectionState solrUserConfigState;
+
+ @Override
+ protected void configure(HttpSecurity http) throws Exception {
+ http
+ .csrf().disable()
+ .sessionManagement()
+ .sessionFixation()
+ .newSession()
+ .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
+ .and()
+ .authorizeRequests()
+ .requestMatchers(requestMatcher()).permitAll()
+ .antMatchers("/**").authenticated()
+ .and()
+ .authenticationProvider(logsearchAuthenticationProvider())
+ .formLogin()
+ .loginPage("/login.html")
+ .and()
+ .httpBasic()
+ .authenticationEntryPoint(logsearchAuthenticationEntryPoint())
+ .and()
+ .addFilterBefore(logsearchUsernamePasswordAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
+ .addFilterBefore(logsearchKRBAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
+ .addFilterAfter(securityContextFormationFilter(), FilterSecurityInterceptor.class)
+ .addFilterAfter(logsearchUserConfigFilter(), LogsearchSecurityContextFormationFilter.class)
+ .addFilterAfter(logsearchAuditLogFilter(), LogsearchSecurityContextFormationFilter.class)
+ .addFilterAfter(logsearchServiceLogFilter(), LogsearchSecurityContextFormationFilter.class)
+ .addFilterBefore(corsFilter(), LogsearchSecurityContextFormationFilter.class)
+ .addFilterBefore(logsearchJwtFilter(), LogsearchSecurityContextFormationFilter.class)
+ .logout()
+ .logoutUrl("/logout.html")
+ .deleteCookies(LOGSEARCH_SESSION_ID)
+ .logoutSuccessHandler(new LogsearchLogoutSuccessHandler());
+ }
+
+ @Bean
+ public LogsearchCorsFilter corsFilter() {
+ return new LogsearchCorsFilter(logSearchHttpHeaderConfig);
+ }
+
+ @Bean
+ public LogsearchSecurityContextFormationFilter securityContextFormationFilter() {
+ return new LogsearchSecurityContextFormationFilter();
+ }
+
+ @Bean
+ public LogsearchKRBAuthenticationFilter logsearchKRBAuthenticationFilter() {
+ return new LogsearchKRBAuthenticationFilter();
+ }
+
+ @Bean
+ public LogsearchAuthenticationProvider logsearchAuthenticationProvider() {
+ return new LogsearchAuthenticationProvider();
+ }
+
+ @Bean
+ public LogsearchJWTFilter logsearchJwtFilter() throws Exception {
+ LogsearchJWTFilter filter = new LogsearchJWTFilter(requestMatcher(), authPropsConfig);
+ filter.setAuthenticationManager(authenticationManagerBean());
+ filter.setAuthenticationSuccessHandler(new LogsearchAuthSuccessHandler());
+ filter.setAuthenticationFailureHandler(new LogsearchAuthFailureHandler());
+ return filter;
+ }
+
+ @Bean
+ public LogsearchAuthenticationEntryPoint logsearchAuthenticationEntryPoint() {
+ LogsearchAuthenticationEntryPoint entryPoint = new LogsearchAuthenticationEntryPoint("/login.html");
+ entryPoint.setForceHttps(false);
+ return entryPoint;
+ }
+
+ @Bean
+ public LogsearchUsernamePasswordAuthenticationFilter logsearchUsernamePasswordAuthenticationFilter() throws Exception {
+ LogsearchUsernamePasswordAuthenticationFilter filter = new LogsearchUsernamePasswordAuthenticationFilter();
+ filter.setAuthenticationSuccessHandler(new LogsearchAuthSuccessHandler());
+ filter.setAuthenticationFailureHandler(new LogsearchAuthFailureHandler());
+ filter.setAuthenticationManager(authenticationManagerBean());
+ return filter;
+ }
+
+ @Bean
+ public LogsearchServiceLogsStateFilter logsearchServiceLogFilter() {
+ return new LogsearchServiceLogsStateFilter(serviceLogsRequestMatcher(), solrServiceLogsState, solrServiceLogPropsConfig);
+ }
+
+ @Bean
+ public LogsearchAuditLogsStateFilter logsearchAuditLogFilter() {
+ return new LogsearchAuditLogsStateFilter(auditLogsRequestMatcher(), solrAuditLogsState, solrAuditLogPropsConfig);
+ }
+
+ @Bean
+ public LogsearchUserConfigStateFilter logsearchUserConfigFilter() {
+ return new LogsearchUserConfigStateFilter(userConfigRequestMatcher(), solrUserConfigState, solrUserPropsConfig);
+ }
+
+ @Bean
+ public RequestMatcher requestMatcher() {
+ List<RequestMatcher> matchers = Lists.newArrayList();
+ matchers.add(new AntPathRequestMatcher("/login.html"));
+ matchers.add(new AntPathRequestMatcher("/logout.html"));
+ matchers.add(new AntPathRequestMatcher("/styles/**"));
+ matchers.add(new AntPathRequestMatcher("/fonts/**"));
+ matchers.add(new AntPathRequestMatcher("/scripts/**"));
+ matchers.add(new AntPathRequestMatcher("/libs/**"));
+ matchers.add(new AntPathRequestMatcher("/templates/**"));
+ matchers.add(new AntPathRequestMatcher("/images/**"));
+ matchers.add(new AntPathRequestMatcher("/favicon.ico"));
+ matchers.add(new AntPathRequestMatcher("/api/v1/public/**"));
+ matchers.add(new AntPathRequestMatcher("/api/v1/swagger.json"));
+ matchers.add(new AntPathRequestMatcher("/api/v1/swagger.yaml"));
+ return new OrRequestMatcher(matchers);
+ }
+
+ public RequestMatcher serviceLogsRequestMatcher() {
+ return new AntPathRequestMatcher("/api/v1/service/logs/**");
+ }
+
+ public RequestMatcher auditLogsRequestMatcher() {
+ return new AntPathRequestMatcher("/api/v1/audit/logs/**");
+ }
+
+ public RequestMatcher userConfigRequestMatcher() {
+ return new AntPathRequestMatcher("/api/v1/userconfig/**");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrAuditLogPropsConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrAuditLogPropsConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrAuditLogPropsConfig.java
new file mode 100644
index 0000000..5981bcc
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrAuditLogPropsConfig.java
@@ -0,0 +1,168 @@
+/*
+ * 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.conf;
+
+import org.apache.zookeeper.data.ACL;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.List;
+
+@Configuration
+public class SolrAuditLogPropsConfig implements SolrPropsConfig {
+
+ @Value("${logsearch.solr.audit.logs.url:}")
+ private String solrUrl;
+
+ @Value("${logsearch.solr.audit.logs.zk_connect_string:}")
+ private String zkConnectString;
+
+ @Value("${logsearch.solr.collection.audit.logs:audit_logs}")
+ private String collection;
+
+ @Value("${logsearch.ranger.audit.logs.collection.name:}")
+ private String rangerCollection;
+
+ @Value("${logsearch.solr.audit.logs.config.name:audit_logs}")
+ private String configName;
+
+ @Value("${logsearch.solr.audit.logs.alias.name:audit_logs_alias}")
+ private String aliasNameIn;
+
+ @Value("${logsearch.audit.logs.split.interval.mins:none}")
+ private String splitInterval;
+
+ @Value("${logsearch.collection.audit.logs.numshards:1}")
+ private Integer numberOfShards;
+
+ @Value("${logsearch.collection.audit.logs.replication.factor:1}")
+ private Integer replicationFactor;
+
+ @Value("#{ACLPropertiesSplitter.parseAcls('${logsearch.solr.audit.logs.zk.acls:}')}")
+ private List<ACL> zkAcls;
+
+ @Value("${logsearch.solr.audit.logs.config_set.folder:/etc/ambari-logsearch-portal/conf/solr_configsets}")
+ private String configSetFolder;
+
+ @Override
+ public String getSolrUrl() {
+ return solrUrl;
+ }
+
+ @Override
+ public void setSolrUrl(String solrUrl) {
+ this.solrUrl = solrUrl;
+ }
+
+ @Override
+ public String getCollection() {
+ return collection;
+ }
+
+ @Override
+ public void setCollection(String collection) {
+ this.collection = collection;
+ }
+
+ @Override
+ public String getZkConnectString() {
+ return zkConnectString;
+ }
+
+ @Override
+ public void setZkConnectString(String zkConnectString) {
+ this.zkConnectString = zkConnectString;
+ }
+
+ @Override
+ public String getConfigName() {
+ return configName;
+ }
+
+ @Override
+ public void setConfigName(String configName) {
+ this.configName = configName;
+ }
+
+ @Override
+ public Integer getNumberOfShards() {
+ return numberOfShards;
+ }
+
+ @Override
+ public void setNumberOfShards(Integer numberOfShards) {
+ this.numberOfShards = numberOfShards;
+ }
+
+ @Override
+ public Integer getReplicationFactor() {
+ return replicationFactor;
+ }
+
+ @Override
+ public void setReplicationFactor(Integer replicationFactor) {
+ this.replicationFactor = replicationFactor;
+ }
+
+ @Override
+ public String getSplitInterval() {
+ return splitInterval;
+ }
+
+ @Override
+ public void setSplitInterval(String splitInterval) {
+ this.splitInterval = splitInterval;
+ }
+
+ @Override
+ public List<ACL> getZkAcls() {
+ return zkAcls;
+ }
+
+ @Override
+ public void setZkAcls(List<ACL> zkAcls) {
+ this.zkAcls = zkAcls;
+ }
+
+ @Override
+ public String getConfigSetFolder() {
+ return configSetFolder;
+ }
+
+ @Override
+ public void setConfigSetFolder(String configSetFolder) {
+ this.configSetFolder = configSetFolder;
+ }
+
+ public String getRangerCollection() {
+ return rangerCollection;
+ }
+
+ public void setRangerCollection(String rangerCollection) {
+ this.rangerCollection = rangerCollection;
+ }
+
+ public String getAliasNameIn() {
+ return aliasNameIn;
+ }
+
+ public void setAliasNameIn(String aliasNameIn) {
+ this.aliasNameIn = aliasNameIn;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrConfig.java
new file mode 100644
index 0000000..f00e8c5
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrConfig.java
@@ -0,0 +1,76 @@
+/*
+ * 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.conf;
+
+import org.apache.ambari.logsearch.conf.global.SolrAuditLogsState;
+import org.apache.ambari.logsearch.conf.global.SolrCollectionState;
+import org.apache.ambari.logsearch.conf.global.SolrServiceLogsState;
+import org.apache.ambari.logsearch.conf.global.SolrUserConfigState;
+import org.apache.ambari.logsearch.dao.SolrSchemaFieldDao;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.DependsOn;
+import org.springframework.data.solr.core.SolrTemplate;
+import org.springframework.data.solr.repository.config.EnableSolrRepositories;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+@Configuration
+@EnableSolrRepositories
+@EnableScheduling
+public class SolrConfig {
+
+ @Bean(name = "serviceSolrTemplate")
+ public SolrTemplate serviceSolrTemplate() {
+ return null;
+ }
+
+ @Bean(name = "auditSolrTemplate")
+ @DependsOn("serviceSolrTemplate")
+ public SolrTemplate auditSolrTemplate() {
+ return null;
+ }
+
+ @Bean(name = "userConfigSolrTemplate")
+ @DependsOn("serviceSolrTemplate")
+ public SolrTemplate userConfigSolrTemplate() {
+ return null;
+ }
+
+ @Bean
+ @DependsOn({"serviceSolrTemplate", "auditSolrTemplate"})
+ public SolrSchemaFieldDao solrSchemaFieldDao() {
+ return new SolrSchemaFieldDao();
+ }
+
+ @Bean(name = "solrServiceLogsState")
+ public SolrCollectionState solrServiceLogsState() {
+ return new SolrServiceLogsState();
+ }
+
+ @Bean(name = "solrAuditLogsState")
+ public SolrCollectionState solrAuditLogsState() {
+ return new SolrAuditLogsState();
+ }
+
+ @Bean(name = "solrUserConfigState")
+ public SolrCollectionState solrUserConfigState() {
+ return new SolrUserConfigState();
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrConnectionPropsConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrConnectionPropsConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrConnectionPropsConfig.java
new file mode 100644
index 0000000..7d37efd
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrConnectionPropsConfig.java
@@ -0,0 +1,78 @@
+/*
+ * 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.conf;
+
+import org.apache.zookeeper.data.ACL;
+import org.springframework.beans.factory.annotation.Value;
+
+import java.util.List;
+
+public abstract class SolrConnectionPropsConfig implements SolrPropsConfig {
+ @Value("${logsearch.solr.url:}")
+ private String solrUrl;
+
+ @Value("${logsearch.solr.zk_connect_string:}")
+ private String zkConnectString;
+
+ @Value("#{ACLPropertiesSplitter.parseAcls('${logsearch.solr.zk.acls:}')}")
+ private List<ACL> zkAcls;
+
+ @Value("${logsearch.solr.config_set.folder:/etc/ambari-logsearch-portal/conf/solr_configsets}")
+ private String configSetFolder;
+
+ @Override
+ public String getSolrUrl() {
+ return solrUrl;
+ }
+
+ @Override
+ public void setSolrUrl(String solrUrl) {
+ this.solrUrl = solrUrl;
+ }
+
+ @Override
+ public String getZkConnectString() {
+ return zkConnectString;
+ }
+
+ @Override
+ public void setZkConnectString(String zkConnectString) {
+ this.zkConnectString = zkConnectString;
+ }
+
+ @Override
+ public List<ACL> getZkAcls() {
+ return zkAcls;
+ }
+
+ @Override
+ public void setZkAcls(List<ACL> zkAcls) {
+ this.zkAcls = zkAcls;
+ }
+
+ @Override
+ public String getConfigSetFolder() {
+ return configSetFolder;
+ }
+
+ @Override
+ public void setConfigSetFolder(String configSetFolder) {
+ this.configSetFolder = configSetFolder;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrKerberosConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrKerberosConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrKerberosConfig.java
new file mode 100644
index 0000000..7cf79b0
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrKerberosConfig.java
@@ -0,0 +1,48 @@
+/*
+ * 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.conf;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class SolrKerberosConfig {
+
+ @Value("${logsearch.solr.jaas.file:/usr/lib/ambari-logsearch-portal/logsearch_solr_jaas.conf}")
+ private String jaasFile;
+
+ @Value("${logsearch.solr.kerberos.enable:false}")
+ private boolean enabled;
+
+ public String getJaasFile() {
+ return jaasFile;
+ }
+
+ public void setJaasFile(String jaasFile) {
+ this.jaasFile = jaasFile;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/b0f1e340/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrPropsConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrPropsConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrPropsConfig.java
new file mode 100644
index 0000000..ceddf7e
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SolrPropsConfig.java
@@ -0,0 +1,61 @@
+/*
+ * 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.conf;
+
+import org.apache.zookeeper.data.ACL;
+
+import java.util.List;
+
+public interface SolrPropsConfig {
+ String getSolrUrl();
+
+ void setSolrUrl(String solrUrl);
+
+ String getZkConnectString();
+
+ void setZkConnectString(String zkConnectString);
+
+ String getCollection();
+
+ void setCollection(String collection);
+
+ String getConfigName();
+
+ void setConfigName(String configName);
+
+ Integer getNumberOfShards();
+
+ void setNumberOfShards(Integer numberOfShards);
+
+ Integer getReplicationFactor();
+
+ void setReplicationFactor(Integer replicationFactor);
+
+ String getSplitInterval();
+
+ void setSplitInterval(String splitInterval);
+
+ List<ACL> getZkAcls();
+
+ void setZkAcls(List<ACL> zkAcls);
+
+ String getConfigSetFolder();
+
+ void setConfigSetFolder(String configSetFolder);
+}