From 8f61e18ef0457745719f05bd5c186992a7155416 Mon Sep 17 00:00:00 2001 From: Jorge Hernandez Date: Thu, 22 Jun 2017 17:17:28 -0500 Subject: [POLICY-30] remove problematic layers add configurability through telemetry API Change-Id: I77ebde12a417d421b98646c32dc74824f4494c2e Signed-off-by: Jorge Hernandez --- .../openecomp/policy/drools/event/comm/Topic.java | 2 +- .../policy/drools/event/comm/TopicEndpoint.java | 23 +++---- .../event/comm/bus/DmaapTopicSinkFactory.java | 21 +++++-- .../event/comm/bus/DmaapTopicSourceFactory.java | 29 ++++++--- .../drools/event/comm/bus/UebTopicSinkFactory.java | 23 +++++-- .../event/comm/bus/UebTopicSourceFactory.java | 28 ++++++--- .../event/comm/bus/internal/BusConsumer.java | 47 +++++++++++---- .../event/comm/bus/internal/BusPublisher.java | 62 +++++++------------ .../comm/bus/internal/InlineBusTopicSink.java | 49 +++++---------- .../comm/bus/internal/InlineDmaapTopicSink.java | 10 ++-- .../comm/bus/internal/InlineUebTopicSink.java | 9 ++- .../bus/internal/SingleThreadedBusTopicSource.java | 70 +++++++++------------- .../internal/SingleThreadedDmaapTopicSource.java | 57 +++++++++--------- .../drools/http/client/HttpClientFactory.java | 13 +++- .../drools/http/client/internal/JerseyClient.java | 10 +++- .../http/server/HttpServletServerFactory.java | 12 ++-- .../http/server/internal/JettyJerseyServer.java | 18 +++--- .../http/server/internal/JettyServletServer.java | 45 ++++++-------- 18 files changed, 278 insertions(+), 250 deletions(-) (limited to 'policy-endpoints/src/main/java/org') diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/Topic.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/Topic.java index d38bab5a..54f49fdc 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/Topic.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/Topic.java @@ -27,7 +27,7 @@ import java.util.List; */ public interface Topic { - public static final String NETWORK_LOGGER = "networkLogger"; + public static final String NETWORK_LOGGER = "network"; /** * Underlying Communication infrastructure Types diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicEndpoint.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicEndpoint.java index b3f236f7..fa73ecb7 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicEndpoint.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicEndpoint.java @@ -28,9 +28,8 @@ import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSink; import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSource; import org.openecomp.policy.drools.event.comm.bus.UebTopicSink; import org.openecomp.policy.drools.event.comm.bus.UebTopicSource; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; -import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; import org.openecomp.policy.drools.properties.Lockable; import org.openecomp.policy.drools.properties.Startable; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -239,8 +238,10 @@ public interface TopicEndpoint extends Startable, Lockable { * implementations according to the communication infrastructure that are supported */ class ProxyTopicEndpointManager implements TopicEndpoint { - // get an instance of logger - private static Logger logger = FlexLogger.getLogger(ProxyTopicEndpointManager.class); + /** + * Logger + */ + private static Logger logger = LoggerFactory.getLogger(ProxyTopicEndpointManager.class); /** * Is this element locked? */ @@ -386,7 +387,7 @@ class ProxyTopicEndpointManager implements TopicEndpoint { success = endpoint.start() && success; } catch (Exception e) { success = false; - logger.error(MessageCodes.EXCEPTION_ERROR, e, endpoint.toString(), this.toString()); + logger.error("Problem starting endpoint: {}", endpoint, e); } } @@ -417,7 +418,7 @@ class ProxyTopicEndpointManager implements TopicEndpoint { success = endpoint.stop() && success; } catch (Exception e) { success = false; - logger.error(MessageCodes.EXCEPTION_ERROR, e, endpoint.toString(), this.toString()); + logger.error("Problem stopping endpoint: {}", endpoint, e); } } @@ -532,7 +533,7 @@ class ProxyTopicEndpointManager implements TopicEndpoint { if (uebSource != null) sources.add(uebSource); } catch (Exception e) { - logger.info("No UEB source for topic: " + topic); + logger.info("No UEB source for topic: {}", topic); } try { @@ -540,7 +541,7 @@ class ProxyTopicEndpointManager implements TopicEndpoint { if (dmaapSource != null) sources.add(dmaapSource); } catch (Exception e) { - logger.info("No DMAAP source for topic: " + topic); + logger.info("No DMAAP source for topic: {}", topic); } } return sources; @@ -564,7 +565,7 @@ class ProxyTopicEndpointManager implements TopicEndpoint { if (uebSink != null) sinks.add(uebSink); } catch (Exception e) { - logger.info("No UEB sink for topic: " + topic); + logger.info("No UEB sink for topic: {}", topic); } try { @@ -572,7 +573,7 @@ class ProxyTopicEndpointManager implements TopicEndpoint { if (dmaapSink != null) sinks.add(dmaapSink); } catch (Exception e) { - logger.info("No DMAAP sink for topic: " + topic); + logger.info("No DMAAP sink for topic: {}", topic); } } return sinks; diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java index 4c96f9be..8b8ca530 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java @@ -27,8 +27,8 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; import org.openecomp.policy.drools.event.comm.bus.internal.InlineDmaapTopicSink; import org.openecomp.policy.drools.properties.PolicyProperties; @@ -171,8 +171,10 @@ public interface DmaapTopicSinkFactory { * Factory of DMAAP Reader Topics indexed by topic name */ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { - // get an instance of logger - private static Logger logger = FlexLogger.getLogger(IndexedDmaapTopicSinkFactory.class); + /** + * Logger + */ + private static Logger logger = LoggerFactory.getLogger(IndexedDmaapTopicSinkFactory.class); /** * DMAAP Topic Name Index @@ -279,7 +281,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { String writeTopics = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS); if (writeTopics == null || writeTopics.isEmpty()) { - logger.warn("No topic for DMAAP Sink " + properties); + logger.info("{}: no topic for DMaaP Sink", this); return new ArrayList(); } @@ -377,7 +379,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { dme2AdditionalProps.put(DME2_SESSION_STICKINESS_REQUIRED_PROPERTY, dme2SessionStickinessRequired); if (servers == null || servers.isEmpty()) { - logger.error("No DMaaP servers or DME2 ServiceName provided"); + logger.error("{}: no DMaaP servers or DME2 ServiceName provided", this); continue; } @@ -486,5 +488,12 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { new ArrayList(this.dmaapTopicWriters.values()); return writers; } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("IndexedDmaapTopicSinkFactory []"); + return builder.toString(); + } } \ No newline at end of file diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java index a54cb6f4..89793d28 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java @@ -28,8 +28,8 @@ import java.util.Map; import java.util.Properties; import org.openecomp.policy.drools.event.comm.bus.internal.SingleThreadedDmaapTopicSource; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; import org.openecomp.policy.drools.properties.PolicyProperties; /** @@ -208,10 +208,13 @@ public interface DmaapTopicSourceFactory { */ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { - // get an instance of logger - private static Logger logger = FlexLogger.getLogger(IndexedDmaapTopicSourceFactory.class); /** - * UEB Topic Name Index + * Logger + */ + private static Logger logger = LoggerFactory.getLogger(IndexedDmaapTopicSourceFactory.class); + + /** + * DMaaP Topic Name Index */ protected HashMap dmaapTopicSources = new HashMap(); @@ -318,7 +321,7 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { String readTopics = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS); if (readTopics == null || readTopics.isEmpty()) { - logger.warn("No topic for UEB Source " + properties); + logger.info("{}: no topic for DMaaP Source", this); return new ArrayList(); } List readTopicList = new ArrayList(Arrays.asList(readTopics.split("\\s*,\\s*"))); @@ -426,7 +429,7 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { if (servers == null || servers.isEmpty()) { - logger.error("No DMaaP servers or DME2 ServiceName provided"); + logger.error("{}: no DMaaP servers or DME2 ServiceName provided", this); continue; } @@ -435,7 +438,8 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { try { fetchTimeout = Integer.parseInt(fetchTimeoutString); } catch (NumberFormatException nfe) { - logger.warn("Fetch Timeout in invalid format for topic " + topic + ": " + fetchTimeoutString); + logger.warn("{}: fetch timeout {} is in invalid format for topic {} ", + this, fetchTimeoutString, topic); } } @@ -447,7 +451,8 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { try { fetchLimit = Integer.parseInt(fetchLimitString); } catch (NumberFormatException nfe) { - logger.warn("Fetch Limit in invalid format for topic " + topic + ": " + fetchLimitString); + logger.warn("{}: fetch limit {} is in invalid format for topic {} ", + this, fetchLimitString, topic); } } @@ -582,6 +587,12 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { this.dmaapTopicSources.clear(); } } + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("IndexedDmaapTopicSourceFactory []"); + return builder.toString(); + } } diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSinkFactory.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSinkFactory.java index 4dc38f18..0469c4a3 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSinkFactory.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSinkFactory.java @@ -27,8 +27,8 @@ import java.util.List; import java.util.Properties; import org.openecomp.policy.drools.event.comm.bus.internal.InlineUebTopicSink; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; import org.openecomp.policy.drools.properties.PolicyProperties; /** @@ -120,8 +120,11 @@ public interface UebTopicSinkFactory { * Factory of UEB Reader Topics indexed by topic name */ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { - // get an instance of logger - private static Logger logger = FlexLogger.getLogger(IndexedUebTopicSinkFactory.class); + /** + * Logger + */ + private static Logger logger = LoggerFactory.getLogger(IndexedUebTopicSinkFactory.class); + /** * UEB Topic Name Index */ @@ -184,7 +187,7 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { String writeTopics = properties.getProperty(PolicyProperties.PROPERTY_UEB_SINK_TOPICS); if (writeTopics == null || writeTopics.isEmpty()) { - logger.warn("No topic for UEB Sink " + properties); + logger.info("{}: no topic for UEB Sink", this); return new ArrayList(); } @@ -201,7 +204,7 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { topic + PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX); if (servers == null || servers.isEmpty()) { - logger.error("No UEB servers provided in " + properties); + logger.error("{}: no UEB servers configured for sink {}", this, topic); continue; } @@ -319,5 +322,13 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { new ArrayList(this.uebTopicSinks.values()); return writers; } + + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("IndexedUebTopicSinkFactory []"); + return builder.toString(); + } } diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSourceFactory.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSourceFactory.java index 474d4a80..77b894db 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSourceFactory.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSourceFactory.java @@ -27,8 +27,8 @@ import java.util.List; import java.util.Properties; import org.openecomp.policy.drools.event.comm.bus.internal.SingleThreadedUebTopicSource; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; import org.openecomp.policy.drools.properties.PolicyProperties; /** @@ -144,8 +144,11 @@ public interface UebTopicSourceFactory { * Factory of UEB Source Topics indexed by topic name */ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory { - // get an instance of logger - private static Logger logger = FlexLogger.getLogger(IndexedUebTopicSourceFactory.class); + /** + * Logger + */ + private static Logger logger = LoggerFactory.getLogger(IndexedUebTopicSourceFactory.class); + /** * UEB Topic Name Index */ @@ -203,7 +206,7 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory { String readTopics = properties.getProperty(PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS); if (readTopics == null || readTopics.isEmpty()) { - logger.warn("No topic for UEB Source " + properties); + logger.info("{}: no topic for UEB Source", this); return new ArrayList(); } List readTopicList = new ArrayList(Arrays.asList(readTopics.split("\\s*,\\s*"))); @@ -221,7 +224,7 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory { PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX); if (servers == null || servers.isEmpty()) { - logger.error("No UEB servers provided in " + properties); + logger.error("{}: no UEB servers configured for sink {}", this, topic); continue; } @@ -251,7 +254,8 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory { try { fetchTimeout = Integer.parseInt(fetchTimeoutString); } catch (NumberFormatException nfe) { - logger.warn("Fetch Timeout in invalid format for topic " + topic + ": " + fetchTimeoutString); + logger.warn("{}: fetch timeout {} is in invalid format for topic {} ", + this, fetchTimeoutString, topic); } } @@ -263,7 +267,8 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory { try { fetchLimit = Integer.parseInt(fetchLimitString); } catch (NumberFormatException nfe) { - logger.warn("Fetch Limit in invalid format for topic " + topic + ": " + fetchLimitString); + logger.warn("{}: fetch limit {} is in invalid format for topic {} ", + this, fetchLimitString, topic); } } @@ -388,5 +393,12 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory { this.uebTopicSources.clear(); } } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("IndexedUebTopicSourceFactory []"); + return builder.toString(); + } } diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusConsumer.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusConsumer.java index 6ea21575..d8eb80b8 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusConsumer.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusConsumer.java @@ -27,9 +27,10 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import org.openecomp.policy.common.logging.eelf.PolicyLogger; import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSinkFactory; import org.openecomp.policy.drools.properties.PolicyProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.nsa.cambria.client.CambriaClientBuilders; import com.att.nsa.cambria.client.CambriaConsumer; @@ -62,6 +63,7 @@ public interface BusConsumer { * Cambria based consumer */ public static class CambriaConsumerWrapper implements BusConsumer { + /** * Cambria client */ @@ -154,7 +156,9 @@ public interface BusConsumer { /** * MR based consumer */ - public abstract class DmaapConsumerWrapper implements BusConsumer { + public abstract class DmaapConsumerWrapper implements BusConsumer { + + private static Logger logger = LoggerFactory.getLogger(DmaapConsumerWrapper.class); protected int fetchTimeout; protected Object closeCondition = new Object(); @@ -206,19 +210,30 @@ public interface BusConsumer { */ public Iterable fetch() throws Exception { MRConsumerResponse response = this.consumer.fetchWithReturnConsumerResponse(); - - if (PolicyLogger.isDebugEnabled() && response != null) - PolicyLogger.debug(DmaapConsumerWrapper.class.getName(), "DMaaP consumer received " + response.getResponseCode() + ": " + response.getResponseMessage()); - - if (response.getResponseCode() == null || !response.getResponseCode().equals("200")) { - if (response.getResponseCode() == null) - PolicyLogger.error(DmaapConsumerWrapper.class.getName(), "DMaaP consumer received response code null"); - else - PolicyLogger.error(DmaapConsumerWrapper.class.getName(), "DMaaP consumer received " + response.getResponseCode() + ": " + response.getResponseMessage()); + if (response == null) { + logger.warn("{}: DMaaP NULL response received", this); synchronized (closeCondition) { closeCondition.wait(fetchTimeout); } + return new ArrayList(); + } else { + logger.debug("DMaaP consumer received {} : {}" + + response.getResponseCode(), + response.getResponseMessage()); + + if (response.getResponseCode() == null || + !response.getResponseCode().equals("200")) { + + logger.error("DMaaP consumer received: {} : {}", + response.getResponseCode(), + response.getResponseMessage()); + + synchronized (closeCondition) { + closeCondition.wait(fetchTimeout); + } + /* fall through */ + } } if (response.getActualMessages() == null) @@ -257,6 +272,9 @@ public interface BusConsumer { * MR based consumer */ public static class DmaapAafConsumerWrapper extends DmaapConsumerWrapper { + + private static Logger logger = LoggerFactory.getLogger(DmaapAafConsumerWrapper.class); + private Properties props; /** @@ -306,7 +324,7 @@ public interface BusConsumer { } this.consumer.setProps(props); - PolicyLogger.info(DmaapConsumerWrapper.class.getName(), "CREATION: " + this); + logger.info("{}: CREATION", this); } @Override @@ -327,6 +345,9 @@ public interface BusConsumer { } public static class DmaapDmeConsumerWrapper extends DmaapConsumerWrapper { + + private static Logger logger = LoggerFactory.getLogger(DmaapDmeConsumerWrapper.class); + private Properties props; public DmaapDmeConsumerWrapper(List servers, String topic, @@ -425,7 +446,7 @@ public interface BusConsumer { MRClientFactory.prop = props; this.consumer.setProps(props); - PolicyLogger.info(DmaapConsumerWrapper.class.getName(), "CREATION: " + this); + logger.info("{}: CREATION", this); } } } diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusPublisher.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusPublisher.java index b5595b2d..54e0bcb2 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusPublisher.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusPublisher.java @@ -28,9 +28,9 @@ import java.util.Map; import java.util.Properties; import java.util.concurrent.TimeUnit; -import org.openecomp.policy.common.logging.eelf.PolicyLogger; import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSinkFactory; import org.openecomp.policy.drools.properties.PolicyProperties; +import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.att.nsa.cambria.client.CambriaBatchingPublisher; @@ -62,6 +62,8 @@ public interface BusPublisher { * Cambria based library publisher */ public static class CambriaPublisherWrapper implements BusPublisher { + + private static Logger logger = LoggerFactory.getLogger(CambriaPublisherWrapper.class); /** * The actual Cambria publisher @@ -111,10 +113,8 @@ public interface BusPublisher { try { this.publisher.send(partitionId, message); } catch (Exception e) { - PolicyLogger.warn(CambriaPublisherWrapper.class.getName(), - "SEND of " + message + " IN " + - this + " cannot be performed because of " + - e.getMessage()); + logger.warn("{}: SEND of {} cannot be performed because of {}", + this, message, e.getMessage(), e); return false; } return true; @@ -125,16 +125,13 @@ public interface BusPublisher { */ @Override public void close() { - if (PolicyLogger.isInfoEnabled()) - PolicyLogger.info(CambriaPublisherWrapper.class.getName(), - "CREATION: " + this); + logger.info("{}: CLOSE", this); try { this.publisher.close(); } catch (Exception e) { - PolicyLogger.warn(CambriaPublisherWrapper.class.getName(), - "CLOSE on " + this + " FAILED because of " + - e.getMessage()); + logger.warn("{}: CLOSE FAILED because of {}", + this, e.getMessage(),e); } } @@ -155,6 +152,9 @@ public interface BusPublisher { * DmaapClient library wrapper */ public abstract class DmaapPublisherWrapper implements BusPublisher { + + private static Logger logger = LoggerFactory.getLogger(DmaapPublisherWrapper.class); + /** * MR based Publisher */ @@ -175,9 +175,9 @@ public interface BusPublisher { String password, boolean useHttps) throws IllegalArgumentException { - if (topic == null || topic.isEmpty()) { + if (topic == null || topic.isEmpty()) throw new IllegalArgumentException("No topic for DMaaP"); - } + if (protocol == ProtocolTypeConstants.AAF_AUTH) { if (servers == null || servers.isEmpty()) @@ -215,7 +215,6 @@ public interface BusPublisher { build(); this.publisher.setProtocolFlag(ProtocolTypeConstants.DME2.getValue()); - } this.publisher.logTo(LoggerFactory.getLogger(MRSimplerBatchPublisher.class.getName())); @@ -225,14 +224,10 @@ public interface BusPublisher { props = new Properties(); - if(useHttps){ - + if (useHttps) { props.setProperty("Protocol", "https"); - } - else{ - + } else { props.setProperty("Protocol", "http"); - } props.setProperty("contenttype", "application/json"); @@ -246,13 +241,7 @@ public interface BusPublisher { if (protocol == ProtocolTypeConstants.AAF_AUTH) this.publisher.setHost(servers.get(0)); - if (PolicyLogger.isInfoEnabled()) { - PolicyLogger.info(DmaapPublisherWrapper.class.getName(), - "CREATION: " + this); - PolicyLogger.info(DmaapPublisherWrapper.class.getName(), - "BusPublisher.DmaapPublisherWrapper using Protocol: " + protocol.getValue()); - } - + logger.info("{}: CREATION: using protocol {}", this, protocol.getValue()); } /** @@ -260,16 +249,13 @@ public interface BusPublisher { */ @Override public void close() { - if (PolicyLogger.isInfoEnabled()) - PolicyLogger.info(DmaapPublisherWrapper.class.getName(), - "CREATION: " + this); + logger.info("{}: CLOSE", this); try { this.publisher.close(1, TimeUnit.SECONDS); } catch (Exception e) { - PolicyLogger.warn(DmaapPublisherWrapper.class.getName(), - "CLOSE: " + this + " because of " + - e.getMessage()); + logger.warn("{}: CLOSE FAILED because of {}", + this, e.getMessage(), e); } } @@ -285,15 +271,13 @@ public interface BusPublisher { this.publisher.setPubResponse(new MRPublisherResponse()); this.publisher.send(partitionId, message); MRPublisherResponse response = this.publisher.sendBatchWithResponse(); - if (PolicyLogger.isDebugEnabled() && response != null) { - PolicyLogger.debug(DmaapPublisherWrapper.class.getName(), - "DMaaP publisher received " + response.getResponseCode() + ": " - + response.getResponseMessage()); - + if (response != null) { + logger.debug("DMaaP publisher received {} : {}", + response.getResponseCode(), + response.getResponseMessage()); } return true; - } @Override diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineBusTopicSink.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineBusTopicSink.java index a78de716..64037749 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineBusTopicSink.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineBusTopicSink.java @@ -23,11 +23,9 @@ package org.openecomp.policy.drools.event.comm.bus.internal; import java.util.List; import java.util.UUID; -import org.apache.log4j.Logger; - import org.openecomp.policy.drools.event.comm.bus.BusTopicSink; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; /** * Transport Agnostic Bus Topic Sink to carry out the core functionality @@ -37,16 +35,10 @@ import org.openecomp.policy.common.logging.eelf.MessageCodes; public abstract class InlineBusTopicSink extends BusTopicBase implements BusTopicSink { /** - * logger + * loggers */ - private static org.openecomp.policy.common.logging.flexlogger.Logger logger = - FlexLogger.getLogger(InlineBusTopicSink.class); - - /** - * Not to be converted to PolicyLogger. - * This will contain all in/out traffic and only that in a single file in a concise format. - */ - protected static final Logger networkLogger = Logger.getLogger(NETWORK_LOGGER); + private static Logger logger = LoggerFactory.getLogger(InlineBusTopicSink.class); + private static final Logger netLogger = LoggerFactory.getLogger(NETWORK_LOGGER); /** * The partition key to publish to @@ -109,8 +101,7 @@ public abstract class InlineBusTopicSink extends BusTopicBase implements BusTopi @Override public boolean start() throws IllegalStateException { - if (logger.isInfoEnabled()) - logger.info("START: " + this); + logger.info("{}: starting", this); synchronized(this) { @@ -144,11 +135,11 @@ public abstract class InlineBusTopicSink extends BusTopicBase implements BusTopi try { publisherCopy.close(); } catch (Exception e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, "PUBLISHER.CLOSE", this.toString()); - e.printStackTrace(); + logger.warn("{}: cannot stop publisher because of {}", + this, e.getMessage(), e); } } else { - logger.warn("No publisher to close: " + this); + logger.warn("{}: there is no publisher", this); return false; } @@ -161,8 +152,7 @@ public abstract class InlineBusTopicSink extends BusTopicBase implements BusTopi @Override public boolean lock() { - if (logger.isInfoEnabled()) - logger.info("LOCK: " + this); + logger.info("{}: locking", this); synchronized (this) { if (this.locked) @@ -180,8 +170,7 @@ public abstract class InlineBusTopicSink extends BusTopicBase implements BusTopi @Override public boolean unlock() { - if (logger.isInfoEnabled()) - logger.info("UNLOCK: " + this); + logger.info("{}: unlocking", this); synchronized(this) { if (!this.locked) @@ -193,9 +182,8 @@ public abstract class InlineBusTopicSink extends BusTopicBase implements BusTopi try { return this.start(); } catch (Exception e) { - logger.warn("can't start after unlocking " + this + - " because of " + e.getMessage()); - e.printStackTrace(); + logger.warn("{}: cannot start after unlocking because of {}", + this, e.getMessage(), e); return false; } } @@ -235,17 +223,12 @@ public abstract class InlineBusTopicSink extends BusTopicBase implements BusTopi this.recentEvents.add(message); } - if (networkLogger.isInfoEnabled()) { - networkLogger.info("[OUT|" + this.getTopicCommInfrastructure() + "|" + - this.topic + "]:" + - message); - } + netLogger.info("[OUT|{}|{}]{}{}", this.getTopicCommInfrastructure(), + this.topic, System.lineSeparator(), message); publisher.send(this.partitionId, message); } catch (Exception e) { - logger.error("can't start after unlocking " + this + - " because of " + e.getMessage()); - e.printStackTrace(); + logger.warn("{}: cannot send because of {}", this, e.getMessage(), e); return false; } diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java index f5a3dc11..a78dd0fc 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java @@ -23,8 +23,8 @@ package org.openecomp.policy.drools.event.comm.bus.internal; import java.util.List; import java.util.Map; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; import org.openecomp.policy.drools.event.comm.Topic; import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSink; @@ -35,7 +35,7 @@ import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSink; public class InlineDmaapTopicSink extends InlineBusTopicSink implements DmaapTopicSink { protected static Logger logger = - FlexLogger.getLogger(InlineDmaapTopicSink.class); + LoggerFactory.getLogger(InlineDmaapTopicSink.class); protected final String userName; protected final String password; @@ -128,8 +128,8 @@ public class InlineDmaapTopicSink extends InlineBusTopicSink implements DmaapTop this.partner, this.latitude, this.longitude, this.additionalProps, this.useHttps); } - if (logger.isInfoEnabled()) - logger.info("DMAAP SINK TOPIC created " + this); + + logger.info("{}: DMAAP SINK created", this); } /** diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineUebTopicSink.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineUebTopicSink.java index c93e0f2b..3b091f5a 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineUebTopicSink.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineUebTopicSink.java @@ -24,7 +24,7 @@ import java.util.List; import org.openecomp.policy.drools.event.comm.Topic; import org.openecomp.policy.drools.event.comm.bus.UebTopicSink; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.slf4j.LoggerFactory; /** * This implementation publishes events for the associated UEB topic, @@ -35,8 +35,8 @@ public class InlineUebTopicSink extends InlineBusTopicSink implements UebTopicSi /** * logger */ - private static org.openecomp.policy.common.logging.flexlogger.Logger logger = - FlexLogger.getLogger(InlineUebTopicSink.class); + private static org.slf4j.Logger logger = + LoggerFactory.getLogger(InlineUebTopicSink.class); /** * Argument-based UEB Topic Writer instantiation @@ -74,8 +74,7 @@ public class InlineUebTopicSink extends InlineBusTopicSink implements UebTopicSi this.apiKey, this.apiSecret, this.useHttps); - if (logger.isInfoEnabled()) - logger.info("UEB SINK TOPIC created " + this); + logger.info("{}: UEB SINK created", this); } @Override diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java index d3be9163..85da3f01 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java @@ -24,12 +24,11 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.openecomp.policy.drools.event.comm.TopicListener; import org.openecomp.policy.drools.event.comm.bus.BusTopicSource; -import org.openecomp.policy.common.logging.eelf.MessageCodes; -import org.openecomp.policy.common.logging.eelf.PolicyLogger; /** * This topic source implementation specializes in reading messages @@ -39,12 +38,12 @@ public abstract class SingleThreadedBusTopicSource extends BusTopicBase implements Runnable, BusTopicSource { - private String className = SingleThreadedBusTopicSource.class.getName(); /** * Not to be converted to PolicyLogger. * This will contain all instract /out traffic and only that in a single file in a concise format. */ - protected static final Logger networkLogger = Logger.getLogger(NETWORK_LOGGER); + private static Logger logger = LoggerFactory.getLogger(InlineBusTopicSink.class); + private static final Logger netLogger = LoggerFactory.getLogger(NETWORK_LOGGER); /** * Bus consumer group @@ -165,7 +164,7 @@ public abstract class SingleThreadedBusTopicSource public void register(TopicListener topicListener) throws IllegalArgumentException { - PolicyLogger.info(className,"REGISTER: " + topicListener + " INTO " + this); + logger.info("{}: registering {}", this, topicListener); synchronized(this) { if (topicListener == null) @@ -185,8 +184,8 @@ public abstract class SingleThreadedBusTopicSource try { this.start(); } catch (Exception e) { - PolicyLogger.info(className, "new registration of " + topicListener + - ",but can't start source because of " + e.getMessage()); + logger.warn("{}: cannot start after registration of because of: {}", + this, topicListener, e.getMessage(), e); } } @@ -196,7 +195,7 @@ public abstract class SingleThreadedBusTopicSource @Override public void unregister(TopicListener topicListener) { - PolicyLogger.info(className, "UNREGISTER: " + topicListener + " FROM " + this); + logger.info("{}: unregistering {}", this, topicListener); boolean stop = false; synchronized (this) { @@ -217,7 +216,8 @@ public abstract class SingleThreadedBusTopicSource */ @Override public boolean lock() { - PolicyLogger.info(className, "LOCK: " + this); + + logger.info("{}: locking", this); synchronized (this) { if (this.locked) @@ -233,8 +233,8 @@ public abstract class SingleThreadedBusTopicSource * {@inheritDoc} */ @Override - public boolean unlock() { - PolicyLogger.info(className, "UNLOCK: " + this); + public boolean unlock() { + logger.info("{}: unlocking", this); synchronized(this) { if (!this.locked) @@ -246,8 +246,7 @@ public abstract class SingleThreadedBusTopicSource try { return this.start(); } catch (Exception e) { - PolicyLogger.warn("can't start after unlocking " + this + - " because of " + e.getMessage()); + logger.warn("{}: cannot after unlocking because of {}", this, e.getMessage(), e); return false; } } @@ -256,19 +255,16 @@ public abstract class SingleThreadedBusTopicSource * {@inheritDoc} */ @Override - public boolean start() throws IllegalStateException { - - PolicyLogger.info(className, "START: " + this); + public boolean start() throws IllegalStateException { + logger.info("{}: starting", this); synchronized(this) { - if (alive) { + if (alive) return true; - } - if (locked) { + if (locked) throw new IllegalStateException(this + " is locked."); - } if (this.busPollerThread == null || !this.busPollerThread.isAlive() || @@ -281,7 +277,7 @@ public abstract class SingleThreadedBusTopicSource this.busPollerThread.setName(this.getTopicCommInfrastructure() + "-source-" + this.getTopic()); busPollerThread.start(); } catch (Exception e) { - e.printStackTrace(); + logger.warn("{}: cannot start because of {}", this, e.getMessage(), e); throw new IllegalStateException(e); } } @@ -295,7 +291,7 @@ public abstract class SingleThreadedBusTopicSource */ @Override public boolean stop() { - PolicyLogger.info(className, "STOP: " + this); + logger.info("{}: stopping", this); synchronized(this) { BusConsumer consumerCopy = this.consumer; @@ -307,7 +303,7 @@ public abstract class SingleThreadedBusTopicSource try { consumerCopy.close(); } catch (Exception e) { - PolicyLogger.warn(MessageCodes.EXCEPTION_ERROR, e, "CONSUMER.CLOSE", this.toString()); + logger.warn("{}: stop failed because of {}", this, e.getMessage(), e); } } } @@ -341,8 +337,8 @@ public abstract class SingleThreadedBusTopicSource try { topicListener.onTopicEvent(this.getTopicCommInfrastructure(), this.topic, message); } catch (Exception e) { - PolicyLogger.warn(this.className, "ERROR notifying " + topicListener.toString() + - " because of " + e.getMessage() + " @ " + this.toString()); + logger.warn("{}: notification error @ {} because of {}", + this, topicListener, e.getMessage(), e); success = false; } } @@ -372,24 +368,21 @@ public abstract class SingleThreadedBusTopicSource this.recentEvents.add(event); } - if (networkLogger.isInfoEnabled()) { - networkLogger.info("IN[" + this.getTopicCommInfrastructure() + "|" + - this.topic + "]:" + - event); - } + netLogger.info("[IN|{}|{}]{}{}", + this.getTopicCommInfrastructure(), this.topic, + System.lineSeparator(), event); - PolicyLogger.info(className, this.topic + " <-- " + event); broadcast(event); if (!this.alive) break; } } catch (Exception e) { - PolicyLogger.error( MessageCodes.EXCEPTION_ERROR, className, e, "CONSUMER.FETCH", this.toString()); + logger.error("{}: cannot fetch because of ", this, e.getMessage(), e); } } - PolicyLogger.warn(this.className, "Exiting: " + this); + logger.info("{}: exiting thread", this); } /** @@ -397,8 +390,6 @@ public abstract class SingleThreadedBusTopicSource */ @Override public boolean offer(String event) { - PolicyLogger.info(className, "OFFER: " + event + " TO " + this); - if (!this.alive) { throw new IllegalStateException(this + " is not alive."); } @@ -407,11 +398,8 @@ public abstract class SingleThreadedBusTopicSource this.recentEvents.add(event); } - if (networkLogger.isInfoEnabled()) { - networkLogger.info("IN[" + this.getTopicCommInfrastructure() + "|" + - this.topic + "]:" + - event); - } + netLogger.info("[IN|{}|{}]{}{}",this.getTopicCommInfrastructure(),this.topic, + System.lineSeparator(), event); return broadcast(event); diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java index 2ced5bcb..7e3e3153 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java @@ -23,22 +23,23 @@ package org.openecomp.policy.drools.event.comm.bus.internal; import java.util.List; import java.util.Map; -import org.openecomp.policy.common.logging.eelf.PolicyLogger; import org.openecomp.policy.drools.event.comm.Topic; import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This topic reader implementation specializes in reading messages * over DMAAP topic and notifying its listeners */ public class SingleThreadedDmaapTopicSource extends SingleThreadedBusTopicSource - implements DmaapTopicSource, Runnable { - + implements DmaapTopicSource, Runnable { + private static Logger logger = LoggerFactory.getLogger(SingleThreadedDmaapTopicSource.class); + protected boolean allowSelfSignedCerts; protected final String userName; protected final String password; - private String className = SingleThreadedDmaapTopicSource.class.getName(); protected String environment = null; protected String aftEnvironment = null; @@ -98,7 +99,7 @@ public class SingleThreadedDmaapTopicSource extends SingleThreadedBusTopicSource try { this.init(); } catch (Exception e) { - e.printStackTrace(); + logger.error("ERROR during init of topic {}", this.topic); throw new IllegalArgumentException(e); } } @@ -135,7 +136,7 @@ public class SingleThreadedDmaapTopicSource extends SingleThreadedBusTopicSource try { this.init(); } catch (Exception e) { - e.printStackTrace(); + logger.warn("dmaap-source: cannot create topic {} because of {}", topic, e.getMessage(), e); throw new IllegalArgumentException(e); } } @@ -154,29 +155,29 @@ public class SingleThreadedDmaapTopicSource extends SingleThreadedBusTopicSource this.consumerGroup, this.consumerInstance, this.fetchTimeout, this.fetchLimit, this.useHttps, this.allowSelfSignedCerts); - } else if ((this.environment == null || this.environment.isEmpty()) && - (this.aftEnvironment == null || this.aftEnvironment.isEmpty()) && - (this.latitude == null || this.latitude.isEmpty()) && - (this.longitude == null || this.longitude.isEmpty()) && - (this.partner == null || this.partner.isEmpty())) { - this.consumer = - new BusConsumer.DmaapAafConsumerWrapper(this.servers, this.topic, - this.apiKey, this.apiSecret, - this.userName, this.password, - this.consumerGroup, this.consumerInstance, - this.fetchTimeout, this.fetchLimit, this.useHttps); - } else { - this.consumer = - new BusConsumer.DmaapDmeConsumerWrapper(this.servers, this.topic, - this.apiKey, this.apiSecret, - this.userName, this.password, - this.consumerGroup, this.consumerInstance, - this.fetchTimeout, this.fetchLimit, - this.environment, this.aftEnvironment, this.partner, - this.latitude, this.longitude, this.additionalProps, this.useHttps); - } + } else if ((this.environment == null || this.environment.isEmpty()) && + (this.aftEnvironment == null || this.aftEnvironment.isEmpty()) && + (this.latitude == null || this.latitude.isEmpty()) && + (this.longitude == null || this.longitude.isEmpty()) && + (this.partner == null || this.partner.isEmpty())) { + this.consumer = + new BusConsumer.DmaapAafConsumerWrapper(this.servers, this.topic, + this.apiKey, this.apiSecret, + this.userName, this.password, + this.consumerGroup, this.consumerInstance, + this.fetchTimeout, this.fetchLimit, this.useHttps); + } else { + this.consumer = + new BusConsumer.DmaapDmeConsumerWrapper(this.servers, this.topic, + this.apiKey, this.apiSecret, + this.userName, this.password, + this.consumerGroup, this.consumerInstance, + this.fetchTimeout, this.fetchLimit, + this.environment, this.aftEnvironment, this.partner, + this.latitude, this.longitude, this.additionalProps, this.useHttps); + } - PolicyLogger.info(className, "CREATION: " + this); + logger.info("{}: INITTED", this); } /** diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/HttpClientFactory.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/HttpClientFactory.java index 53a8c2b2..15586b66 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/HttpClientFactory.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/HttpClientFactory.java @@ -27,6 +27,8 @@ import java.util.Properties; import org.openecomp.policy.drools.http.client.internal.JerseyClient; import org.openecomp.policy.drools.properties.PolicyProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public interface HttpClientFactory { @@ -50,6 +52,11 @@ public interface HttpClientFactory { class IndexedHttpClientFactory implements HttpClientFactory { + /** + * Logger + */ + private static Logger logger = LoggerFactory.getLogger(IndexedHttpClientFactory.class); + protected HashMap clients = new HashMap(); @Override @@ -105,7 +112,7 @@ class IndexedHttpClientFactory implements HttpClientFactory { } port = Integer.parseInt(servicePortString); } catch (NumberFormatException nfe) { - nfe.printStackTrace(); + logger.error("http-client-factory: cannot parse port {}", servicePortString, nfe); continue; } @@ -135,7 +142,7 @@ class IndexedHttpClientFactory implements HttpClientFactory { userName, password, managed); clientList.add(client); } catch (Exception e) { - e.printStackTrace(); + logger.error("http-client-factory: cannot build client {}", clientName, e); } } @@ -166,7 +173,7 @@ class IndexedHttpClientFactory implements HttpClientFactory { try { client.shutdown(); } catch (IllegalStateException e) { - e.printStackTrace(); + logger.error("http-client-factory: cannot shutdown client {}", client, e); } } diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/internal/JerseyClient.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/internal/JerseyClient.java index 4fa59dc8..f041b079 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/internal/JerseyClient.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/internal/JerseyClient.java @@ -35,11 +35,18 @@ import javax.ws.rs.core.Response; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.openecomp.policy.drools.http.client.HttpClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.fasterxml.jackson.annotation.JsonIgnore; public class JerseyClient implements HttpClient { + /** + * Logger + */ + private static Logger logger = LoggerFactory.getLogger(JerseyClient.class); + protected final String name; protected final boolean https; protected final boolean selfSignedCerts; @@ -156,7 +163,8 @@ public class JerseyClient implements HttpClient { try { this.client.close(); } catch (Exception e) { - e.printStackTrace(); + logger.warn("{}: cannot close because of {}", this, + e.getMessage(), e); } } diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/HttpServletServerFactory.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/HttpServletServerFactory.java index 40f5c9ad..83f4b3d7 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/HttpServletServerFactory.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/HttpServletServerFactory.java @@ -25,8 +25,8 @@ import java.util.HashMap; import java.util.List; import java.util.Properties; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; import org.openecomp.policy.drools.http.server.internal.JettyJerseyServer; import org.openecomp.policy.drools.properties.PolicyProperties; @@ -95,7 +95,7 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory { /** * logger */ - protected static Logger logger = FlexLogger.getLogger(IndexedHttpServletServerFactory.class); + protected static Logger logger = LoggerFactory.getLogger(IndexedHttpServletServerFactory.class); /** * servers index @@ -126,7 +126,7 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory { String serviceNames = properties.getProperty(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES); if (serviceNames == null || serviceNames.isEmpty()) { - logger.warn("No topic for HTTP Service " + properties); + logger.warn("No topic for HTTP Service: {}", properties); return serviceList; } @@ -142,13 +142,13 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory { try { if (servicePortString == null || servicePortString.isEmpty()) { if (logger.isWarnEnabled()) - logger.warn("No HTTP port for service in " + serviceName); + logger.warn("No HTTP port for service in {}", serviceName); continue; } servicePort = Integer.parseInt(servicePortString); } catch (NumberFormatException nfe) { if (logger.isWarnEnabled()) - logger.warn("No HTTP port for service in " + serviceName); + logger.warn("No HTTP port for service in {}", serviceName); continue; } diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyJerseyServer.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyJerseyServer.java index 5bc320e5..c60a62ca 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyJerseyServer.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyJerseyServer.java @@ -24,8 +24,8 @@ import java.net.UnknownHostException; import java.util.HashMap; import org.eclipse.jetty.servlet.ServletHolder; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; import io.swagger.jersey.config.JerseyJaxrsConfig; @@ -67,7 +67,7 @@ public class JettyJerseyServer extends JettyServletServer { /** * Logger */ - protected static Logger logger = FlexLogger.getLogger(JettyJerseyServer.class); + protected static Logger logger = LoggerFactory.getLogger(JettyJerseyServer.class); /** * Container for servlets @@ -112,7 +112,7 @@ public class JettyJerseyServer extends JettyServletServer { try { hostname = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { - logger.warn("can't resolve connector's hostname: " + this); + logger.warn("{}: can't resolve connector's hostname: ", this); hostname = "localhost"; } } @@ -125,7 +125,7 @@ public class JettyJerseyServer extends JettyServletServer { swaggerServlet.setInitOrder(2); if (logger.isDebugEnabled()) - logger.debug(this + "Swagger Servlet has been attached: " + swaggerServlet.dump()); + logger.debug("{}: Swagger Servlet has been attached: {}", this, swaggerServlet.dump()); } /** @@ -165,7 +165,7 @@ public class JettyJerseyServer extends JettyServletServer { String initClasses = jerseyServlet.getInitParameter(JERSEY_INIT_CLASSNAMES_PARAM_NAME); if (initClasses != null && !initClasses.isEmpty()) - logger.warn("Both packages and classes are used in Jetty+Jersey Configuration: " + restPackage); + logger.warn("Both packages and classes are used in Jetty+Jersey Configuration: {}", restPackage); String initPackages = jerseyServlet.getInitParameter(JERSEY_INIT_PACKAGES_PARAM_NAME); @@ -188,7 +188,7 @@ public class JettyJerseyServer extends JettyServletServer { jerseyServlet.setInitParameter(JERSEY_INIT_PACKAGES_PARAM_NAME, initPackages); if (logger.isDebugEnabled()) - logger.debug(this + "Added REST Package: " + jerseyServlet.dump()); + logger.debug("{}: added REST package: {}", this, jerseyServlet.dump()); } @Override @@ -206,7 +206,7 @@ public class JettyJerseyServer extends JettyServletServer { String initPackages = jerseyServlet.getInitParameter(JERSEY_INIT_PACKAGES_PARAM_NAME); if (initPackages != null && !initPackages.isEmpty()) - logger.warn("Both classes and packages are used in Jetty+Jersey Configuration: " + restClass); + logger.warn("Both classes and packages are used in Jetty+Jersey Configuration: {}", restClass); String initClasses = jerseyServlet.getInitParameter(JERSEY_INIT_CLASSNAMES_PARAM_NAME); @@ -228,7 +228,7 @@ public class JettyJerseyServer extends JettyServletServer { jerseyServlet.setInitParameter(JERSEY_INIT_CLASSNAMES_PARAM_NAME, initClasses); if (logger.isDebugEnabled()) - logger.debug(this + "Added REST Class: " + jerseyServlet.dump()); + logger.debug("{}: added REST class: {}", this, jerseyServlet.dump()); } @Override diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyServletServer.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyServletServer.java index 74360e80..009ad303 100644 --- a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyServletServer.java +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyServletServer.java @@ -28,11 +28,9 @@ import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.util.security.Constraint; import org.eclipse.jetty.util.security.Credential; - -import org.openecomp.policy.common.logging.eelf.MessageCodes; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; import org.openecomp.policy.drools.http.server.HttpServletServer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -41,7 +39,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; */ public abstract class JettyServletServer implements HttpServletServer, Runnable { - private static Logger logger = FlexLogger.getLogger(JettyServletServer.class); + private static Logger logger = LoggerFactory.getLogger(JettyServletServer.class); protected final String name; @@ -141,25 +139,27 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable */ @Override public void run() { - try { - if (logger.isInfoEnabled()) - logger.info(this + " STARTING " + this.jettyServer.dump()); + try { + logger.info("{}: STARTING", this); this.jettyServer.start(); + if (logger.isInfoEnabled()) + logger.info("{}: STARTED: {}", this, this.jettyServer.dump()); + synchronized(this.startCondition) { this.startCondition.notifyAll(); } this.jettyServer.join(); } catch (Exception e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - "Error found while running management server", this.toString()); + logger.error("{}: error found while bringing up server", this, e); } } @Override public boolean waitedStart(long maxWaitTime) throws IllegalArgumentException { + logger.info("{}: WAITED-START", this); if (maxWaitTime < 0) throw new IllegalArgumentException("max-wait-time cannot be negative"); @@ -184,15 +184,13 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable long endTs = System.currentTimeMillis(); pendingWaitTime = pendingWaitTime - (endTs - startTs); - if (logger.isInfoEnabled()) - logger.info(this + "Pending time is " + pendingWaitTime + - " ms."); + logger.info("{}: pending time is {} ms.", this, pendingWaitTime); if (pendingWaitTime <= 0) return false; } catch (InterruptedException e) { - logger.warn("waited-start has been interrupted"); + logger.warn("{}: waited-start has been interrupted", this); return false; } } @@ -206,8 +204,7 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable */ @Override public boolean start() throws IllegalStateException { - if (logger.isDebugEnabled()) - logger.debug(this + "START"); + logger.info("{}: STARTING", this); synchronized(this) { if (jettyThread == null || @@ -227,7 +224,7 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable */ @Override public boolean stop() throws IllegalStateException { - logger.info(this + "STOP"); + logger.info("{}: STOPPING", this); synchronized(this) { if (jettyThread == null) { @@ -241,16 +238,13 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable try { this.connector.stop(); } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, - "Error while stopping management server", this.toString()); - e.printStackTrace(); + logger.error("{}: error while stopping management server", this, e); } try { this.jettyServer.stop(); } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, - "Error while stopping management server", this.toString()); + logger.error("{}: error while stopping management server", this, e); return false; } @@ -265,7 +259,7 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable */ @Override public void shutdown() throws IllegalStateException { - logger.info(this + "SHUTDOWN"); + logger.info("{}: SHUTTING DOWN", this); this.stop(); @@ -278,15 +272,14 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable try { jettyThreadCopy.join(1000L); } catch (InterruptedException e) { - logger.warn(MessageCodes.EXCEPTION_ERROR, e, - "Error while shutting down management server", this.toString()); + logger.warn("{}: error while shutting down management server", this); } if (!jettyThreadCopy.isInterrupted()) { try { jettyThreadCopy.interrupt(); } catch(Exception e) { // do nothing - logger.warn("exception while shutting down (OK)"); + logger.warn("{}: exception while shutting down (OK)", this); } } } -- cgit 1.2.3-korg