Upversion for Casablanca
[aai/router-core.git] / src / main / java / org / onap / aai / event / DMaaPEventBusEndpoint.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 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
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 package org.onap.aai.event;
22
23
24 import org.apache.camel.Consumer;
25 import org.apache.camel.Processor;
26 import org.apache.camel.Producer;
27 import org.apache.camel.spi.Metadata;
28 import org.apache.camel.spi.UriEndpoint;
29 import org.apache.camel.spi.UriParam;
30 import org.apache.camel.spi.UriPath;
31 import org.eclipse.jetty.util.security.Password;
32 import org.onap.aai.event.client.DMaaPEventConsumer;
33
34 /**
35  * Represents a EventBus endpoint.
36  */
37 @UriEndpoint(scheme = "dmaap-event-bus", syntax = "dmaap-event-bus:name",
38     consumerClass = EventBusConsumer.class, title = "dmaap-event-bus")
39 public class DMaaPEventBusEndpoint extends AbstractEventBusEndpoint {
40   @UriPath
41   @Metadata(required = "true")
42   private String name;
43
44   @UriParam(label = "eventTopic")
45   @Metadata(required = "true")
46   private String eventTopic;
47   @UriParam(label = "consumerGroup")
48   @Metadata(required = "true")
49   private String consumerGroup;
50   @UriParam(label = "consumerId")
51   @Metadata(required = "true")
52   private String consumerId;
53   @UriParam(label = "username")
54   private String username;
55   @UriParam(label = "password")
56   private String password;
57   @UriParam(label = "url")
58   @Metadata(required = "true")
59   private String url;
60   @UriParam(label = "poolSize")
61   @Metadata(required = "true", defaultValue="20")
62   private int poolSize = 20;
63   @UriParam(label = "pollingDelay")
64   @Metadata(required = "true", defaultValue="30000")
65   private int pollingDelay = 30000;
66   @UriParam(label = "transportType")
67   @Metadata(required = "true", defaultValue="HTTPAUTH")
68   private String transportType;
69
70   private DMaaPEventConsumer dmaapConsumer;
71   
72   public DMaaPEventBusEndpoint() {}
73
74   public DMaaPEventBusEndpoint(String uri, DMaaPEventBusComponent component) {
75     super(uri, component);
76   }
77
78   public DMaaPEventBusEndpoint(String endpointUri) {
79     super(endpointUri);
80   }
81
82   @Override
83   void close() {
84     // Don't have to do anything for DMaaP
85   }
86
87   @Override
88   public Producer createProducer() throws Exception {
89     return new EventBusProducer(this);
90   }
91   @Override
92   public Consumer createConsumer(Processor processor) throws Exception {
93     // TODO: other overloads based on filled-in properties
94     dmaapConsumer = new DMaaPEventConsumer(url, eventTopic, Password.deobfuscate(username), Password.deobfuscate(password), consumerGroup, consumerId, 15000, 1000, transportType);
95     return new EventBusConsumer(this, processor, dmaapConsumer);
96   }
97   @Override
98   public boolean isSingleton() {
99     return false;
100   }
101
102   public void setName(String name) {
103     this.name = name;
104   }
105
106   public String getName() {
107     return name;
108   }
109
110   public String getEventTopic() {
111     return eventTopic;
112   }
113
114   public void setEventTopic(String eventTopic) {
115     this.eventTopic = eventTopic;
116   }
117
118   public String getConsumerGroup() {
119     return consumerGroup;
120   }
121
122   public void setConsumerGroup(String consumerGroup) {
123     this.consumerGroup = consumerGroup;
124   }
125
126   public String getConsumerId() {
127     return consumerId;
128   }
129
130   public void setConsumerId(String consumerId) {
131     this.consumerId = consumerId;
132   }
133
134   public String getUsername() {
135     return username == null ? null : Password.deobfuscate(username);
136     //return username;
137   }
138
139   public void setUsername(String username) {
140     this.username = username;
141   }
142
143   public String getPassword() {
144     return password == null ? null : Password.deobfuscate(password);
145     //return password;
146   }
147
148   public void setPassword(String password) {
149     this.password = password;
150   }
151   
152   public int getPoolSize() {
153         return poolSize;
154   }
155
156   public void setPoolSize(int poolsize) {
157         this.poolSize = poolsize;
158   }
159
160   public int getPollingDelay() {
161           return pollingDelay;
162   }
163
164   public void setPollingDelay(int pollingDelay) {
165           this.pollingDelay = pollingDelay;
166   }
167
168   public String getUrl() {
169           return url;
170   }
171
172   public void setUrl(String url) {
173     this.url = url;
174   }
175
176   public String getTransportType() {
177     return transportType;
178   }
179
180   public void setTransportType(String transportType) {
181     this.transportType = transportType;
182   }
183 }
184