2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.sparky.synchronizer.filter;
25 import java.io.IOException;
26 import java.net.InetAddress;
27 import java.net.UnknownHostException;
29 import javax.servlet.Filter;
30 import javax.servlet.FilterChain;
31 import javax.servlet.FilterConfig;
32 import javax.servlet.ServletException;
33 import javax.servlet.ServletRequest;
34 import javax.servlet.ServletResponse;
36 import org.openecomp.cl.api.Logger;
37 import org.openecomp.cl.eelf.LoggerFactory;
38 import org.openecomp.sparky.config.oxm.OxmModelLoader;
39 import org.openecomp.sparky.logging.AaiUiMsgs;
40 import org.openecomp.sparky.synchronizer.SyncHelper;
41 import org.openecomp.sparky.util.NodeUtils;
43 import org.openecomp.cl.mdc.MdcContext;
46 * This is a wire-frame for an experiment to get the jetty filter-lifecyle initialization method to
47 * setup a scheduled thread executor with an ElasticSearchSynchronization task, which (I'm hoping)
48 * will allow us to do periodic ES <=> AAI synchronization.
50 * Alternatively, if the embedded java approach doesn't work we could try instead to do a
51 * System.exec( "perl refreshElasticSearchInstance.pl"). We have two options, I'm hoping the
52 * embedded options will work for us.
56 * The Class ElasticSearchSynchronizerFilter.
58 public class ElasticSearchSynchronizerFilter implements Filter {
60 private static final Logger LOG = LoggerFactory.getInstance().getLogger(ElasticSearchSynchronizerFilter.class);
62 private SyncHelper syncHelper;
65 * @see javax.servlet.Filter#destroy()
68 public void destroy() {
70 if (syncHelper != null) {
71 syncHelper.shutdown();
76 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
79 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
80 throws IOException, ServletException {
83 * However, we will setup the filtermap with a url that should never get it, so we shouldn't
87 chain.doFilter(request, response);
91 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
94 public void init(FilterConfig filterConfig) throws ServletException {
95 String txnID = NodeUtils.getRandomTxnId();
96 MdcContext.initialize(txnID, "ElasticSearchSynchronizerFilter", "", "Init", "");
98 LOG.debug(AaiUiMsgs.DEBUG_GENERIC, "init()");
101 new SyncHelper(OxmModelLoader.getInstance());
102 } catch (Exception exc) {
103 throw new ServletException("Caught an exception while initializing filter", exc);