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