896cb3bb43a0fca425f37251c5623ee55f6e2c13
[policy/common.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
6  * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.common.endpoints.event.comm.bus.internal;
23
24 import org.onap.policy.common.endpoints.event.comm.Topic;
25 import org.onap.policy.common.endpoints.event.comm.bus.UebTopicSink;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 /**
30  * This implementation publishes events for the associated UEB topic, inline with the calling
31  * thread.
32  */
33 public class InlineUebTopicSink extends InlineBusTopicSink implements UebTopicSink {
34
35     /**
36      * Logger.
37      */
38     private static Logger logger = LoggerFactory.getLogger(InlineUebTopicSink.class);
39
40     /**
41      * Argument-based UEB Topic Writer instantiation. BusTopicParams contains below mentioned
42      * attributes.
43      *
44      * <p>servers              list of UEB servers available for publishing
45      * topic                the topic to publish to
46      * apiKey               the api key (optional)
47      * apiSecret            the api secret (optional)
48      * partitionId          the partition key (optional, autogenerated if not provided)
49      * useHttps             does connection use HTTPS?
50      * allowTracing         is tracing allowed?
51      * allowSelfSignedCerts are self-signed certificates allow
52      * @param busTopicParams contains attributes needed
53      * @throws IllegalArgumentException if invalid arguments are detected
54      */
55     public InlineUebTopicSink(BusTopicParams busTopicParams) {
56         super(busTopicParams);
57     }
58
59     /**
60      * Instantiation of internal resources.
61      */
62     @Override
63     public void init() {
64
65         this.publisher = new BusPublisher.CambriaPublisherWrapper(BusTopicParams.builder()
66                 .servers(this.servers)
67                 .topic(this.effectiveTopic)
68                 .apiKey(this.apiKey)
69                 .apiSecret(this.apiSecret)
70                 .useHttps(this.useHttps)
71                 .allowTracing(this.allowTracing)
72                 .allowSelfSignedCerts(this.allowSelfSignedCerts)
73                 .build());
74         logger.info("{}: UEB SINK created", this);
75     }
76
77     @Override
78     public String toString() {
79         return "InlineUebTopicSink [getTopicCommInfrastructure()=" + getTopicCommInfrastructure() + ", toString()="
80                         + super.toString() + "]";
81     }
82
83     @Override
84     public CommInfrastructure getTopicCommInfrastructure() {
85         return Topic.CommInfrastructure.UEB;
86     }
87 }