Remove GroupValidationResult
[policy/apex-pdp.git] / plugins / plugins-event / plugins-event-carrier / plugins-event-carrier-jms / src / main / java / org / onap / policy / apex / plugins / event / carrier / jms / JmsCarrierTechnologyParameters.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019,2021 Nordix Foundation.
5  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.apex.plugins.event.carrier.jms;
24
25 import java.util.Properties;
26 import javax.naming.Context;
27 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
28 import org.onap.policy.common.parameters.annotations.Min;
29 import org.onap.policy.common.parameters.annotations.NotBlank;
30 import org.onap.policy.common.parameters.annotations.NotNull;
31
32 /**
33  * Apex parameters for JMS as an event carrier technology.
34  *
35  * <p>The parameters for this plugin are:
36  * <ol>
37  * <li>initialContextFactory: JMS uses a naming {@link Context} object to look up the locations of JMS servers and JMS
38  * topics. An Initial Context Factory is used to when creating a {@link Context} object that can be used for JMS
39  * lookups. The value of this parameter is passed to the {@link Context} with the label
40  * {@link Context#INITIAL_CONTEXT_FACTORY}. Its value must be the full canonical path to a class that implements the
41  * {@code javax.naming.spi.InitialContextFactory} interface. The parameter defaults to the string value
42  * {@code org.jboss.naming.remote.client.InitialContextFactory}.
43  * <li>providerURL: The location of the server to use for naming context lookups. The value of this parameter is passed
44  * to the {@link Context} with the label {@link Context#PROVIDER_URL}. Its value must be a URL that identifies the JMS
45  * naming server. The parameter defaults to the string value {@code remote://localhost:4447}.
46  * <li>securityPrincipal: The user name to use for JMS access. The value of this parameter is passed to the
47  * {@link Context} with the label {@link Context#SECURITY_PRINCIPAL}. Its value must be the user name of a user defined
48  * on the JMS server. The parameter defaults to the string value {@code userid}.
49  * <li>securityCredentials:The password to use for JMS access. The value of this parameter is passed to the
50  * {@link Context} with the label {@link Context#SECURITY_CREDENTIALS}. Its value must be the password of a suer defined
51  * on the JMS server. The parameter defaults to the string value {@code password}.
52  * <li>connectionFactory: JMS uses a {@link javax.jms.ConnectionFactory} instance to create connections towards a JMS
53  * server. The connection factory to use is held in the JMS {@link Context} object. This parameter specifies the label
54  * to use to look up the {@link javax.jms.ConnectionFactory} instance from the JMS {@link Context}.
55  * <li>producerTopic: JMS uses a {@link javax.jms.Topic} instance to for sending and receiving messages. The topic to
56  * use for sending events to JMS from an Apex producer is held in the JMS {@link Context} object. This parameter
57  * specifies the label to use to look up the {@link javax.jms.Topic} instance in the JMS {@link Context} for the JMS
58  * server. The topic must, of course, also be defined on the JMS server. The parameter defaults to the string value
59  * {@code apex-out}.
60  * <li>consumerTopic: The topic to use for receiving events from JMS in an Apex consumer is held in the JMS
61  * {@link Context} object. This parameter specifies the label to use to look up the {@link javax.jms.Topic} instance in
62  * the JMS {@link Context} for the JMS server. The topic must, of course, also be defined on the JMS server. The
63  * parameter defaults to the string value {@code apex-in}.
64  * <li>consumerWaitTime: The amount of milliseconds a JMS consumer should wait between checks of its thread execution
65  * status. The parameter defaults to the long value {@code 100}.
66  * <li>objectMessageSending: A flag that indicates whether Apex producers should send JMS messages as
67  * {@link javax.jms.ObjectMessage} instances for java objects (value {@code true}) or as {@link javax.jms.TextMessage}
68  * instances for strings (value {@code false}) . The parameter defaults to the boolean value {@code true}.
69  * </ol>
70  *
71  * @author Liam Fallon (liam.fallon@ericsson.com)
72  */
73 public class JmsCarrierTechnologyParameters extends CarrierTechnologyParameters {
74     /** The label of this carrier technology. */
75     public static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS";
76
77     /** The producer plugin class for the JMS carrier technology. */
78     public static final String JMS_EVENT_PRODUCER_PLUGIN_CLASS = ApexJmsProducer.class.getName();
79
80     /** The consumer plugin class for the JMS carrier technology. */
81     public static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS = ApexJmsConsumer.class.getName();
82
83     // @formatter:off
84
85     // Default parameter values
86     private static final String  DEFAULT_CONNECTION_FACTORY    = "jms/RemoteConnectionFactory";
87     private static final String  DEFAULT_INITIAL_CTXT_FACTORY  = "org.jboss.naming.remote.client.InitialContextFactory";
88     private static final String  DEFAULT_PROVIDER_URL          = null;
89     private static final String  DEFAULT_SECURITY_PRINCIPAL    = null;
90     private static final String  DEFAULT_SECURITY_CREDENTIALS  = null;
91     private static final String  DEFAULT_CONSUMER_TOPIC        = "apex-in";
92     private static final String  DEFAULT_PRODUCER_TOPIC        = "apex-out";
93     private static final int     DEFAULT_CONSUMER_WAIT_TIME    = 100;
94     private static final boolean DEFAULT_TO_OBJECT_MSG_SENDING = true;
95
96     // Parameter property map tokens
97     private static final String PROPERTY_INITIAL_CONTEXT_FACTORY  = Context.INITIAL_CONTEXT_FACTORY;
98     private static final String PROPERTY_PROVIDER_URL             = Context.PROVIDER_URL;
99     private static final String PROPERTY_SECURITY_PRINCIPAL       = Context.SECURITY_PRINCIPAL;
100     private static final String PROPERTY_SECURITY_CREDENTIALS     = Context.SECURITY_CREDENTIALS;
101
102     // JMS carrier parameters
103     private String  connectionFactory     = DEFAULT_CONNECTION_FACTORY;
104     @NotNull @NotBlank
105     private String  initialContextFactory = DEFAULT_INITIAL_CTXT_FACTORY;
106     @NotNull @NotBlank
107     private String  providerUrl           = DEFAULT_PROVIDER_URL;
108     @NotNull @NotBlank
109     private String  securityPrincipal     = DEFAULT_SECURITY_PRINCIPAL;
110     @NotNull @NotBlank
111     private String  securityCredentials   = DEFAULT_SECURITY_CREDENTIALS;
112     @NotNull @NotBlank
113     private String  producerTopic         = DEFAULT_PRODUCER_TOPIC;
114     @NotNull @NotBlank
115     private String  consumerTopic         = DEFAULT_CONSUMER_TOPIC;
116     @Min(0)
117     private int     consumerWaitTime      = DEFAULT_CONSUMER_WAIT_TIME;
118     private boolean objectMessageSending  = DEFAULT_TO_OBJECT_MSG_SENDING;
119     // @formatter:on
120
121     /**
122      * Constructor to create a jms carrier technology parameters instance and register the instance with the parameter
123      * service.
124      */
125     public JmsCarrierTechnologyParameters() {
126         super();
127
128         // Set the carrier technology properties for the JMS carrier technology
129         this.setLabel(JMS_CARRIER_TECHNOLOGY_LABEL);
130         this.setEventProducerPluginClass(JMS_EVENT_PRODUCER_PLUGIN_CLASS);
131         this.setEventConsumerPluginClass(JMS_EVENT_CONSUMER_PLUGIN_CLASS);
132     }
133
134     /**
135      * Gets the JMS producer properties.
136      *
137      * @return the JMS producer properties
138      */
139     public Properties getJmsProducerProperties() {
140         return getJmsProperties();
141     }
142
143     /**
144      * Gets the jms consumer properties.
145      *
146      * @return the jms consumer properties
147      */
148     public Properties getJmsConsumerProperties() {
149         return getJmsProperties();
150     }
151
152     /**
153      * Gets the JMS consumer properties.
154      *
155      * @return the jms consumer properties
156      */
157     private Properties getJmsProperties() {
158         final Properties jmsProperties = new Properties();
159
160         jmsProperties.put(PROPERTY_INITIAL_CONTEXT_FACTORY, initialContextFactory);
161
162         if (providerUrl != null) {
163             jmsProperties.put(PROPERTY_PROVIDER_URL, providerUrl);
164         }
165
166         if (securityPrincipal != null) {
167             jmsProperties.put(PROPERTY_SECURITY_PRINCIPAL, securityPrincipal);
168         }
169
170         if (securityCredentials != null) {
171             jmsProperties.put(PROPERTY_SECURITY_CREDENTIALS, securityCredentials);
172         }
173
174         return jmsProperties;
175     }
176
177     /**
178      * Gets the connection factory.
179      *
180      * @return the connection factory
181      */
182     public String getConnectionFactory() {
183         return connectionFactory;
184     }
185
186     /**
187      * Gets the initial context factory.
188      *
189      * @return the initial context factory
190      */
191     public String getInitialContextFactory() {
192         return initialContextFactory;
193     }
194
195     /**
196      * Gets the provider URL.
197      *
198      * @return the provider URL
199      */
200     public String getProviderUrl() {
201         return providerUrl;
202     }
203
204     /**
205      * Gets the security principal.
206      *
207      * @return the security principal
208      */
209     public String getSecurityPrincipal() {
210         return securityPrincipal;
211     }
212
213     /**
214      * Gets the security credentials.
215      *
216      * @return the security credentials
217      */
218     public String getSecurityCredentials() {
219         return securityCredentials;
220     }
221
222     /**
223      * Gets the producer topic.
224      *
225      * @return the producer topic
226      */
227     public String getProducerTopic() {
228         return producerTopic;
229     }
230
231     /**
232      * Gets the consumer topic.
233      *
234      * @return the consumer topic
235      */
236     public String getConsumerTopic() {
237         return consumerTopic;
238     }
239
240     /**
241      * Gets the consumer wait time.
242      *
243      * @return the consumer wait time
244      */
245     public long getConsumerWaitTime() {
246         return consumerWaitTime;
247     }
248
249     /**
250      * Sets the connection factory.
251      *
252      * @param connectionFactory the connection factory
253      */
254     public void setConnectionFactory(final String connectionFactory) {
255         this.connectionFactory = connectionFactory;
256     }
257
258     /**
259      * Sets the initial context factory.
260      *
261      * @param initialContextFactory the initial context factory
262      */
263     public void setInitialContextFactory(final String initialContextFactory) {
264         this.initialContextFactory = initialContextFactory;
265     }
266
267     /**
268      * Sets the provider URL.
269      *
270      * @param providerUrl the provider URL
271      */
272     public void setProviderUrl(final String providerUrl) {
273         this.providerUrl = providerUrl;
274     }
275
276     /**
277      * Sets the security principal.
278      *
279      * @param securityPrincipal the security principal
280      */
281     public void setSecurityPrincipal(final String securityPrincipal) {
282         this.securityPrincipal = securityPrincipal;
283     }
284
285     /**
286      * Sets the security credentials.
287      *
288      * @param securityCredentials the security credentials
289      */
290     public void setSecurityCredentials(final String securityCredentials) {
291         this.securityCredentials = securityCredentials;
292     }
293
294     /**
295      * Sets the producer topic.
296      *
297      * @param producerTopic the producer topic
298      */
299     public void setProducerTopic(final String producerTopic) {
300         this.producerTopic = producerTopic;
301     }
302
303     /**
304      * Sets the consumer topic.
305      *
306      * @param consumerTopic the consumer topic
307      */
308     public void setConsumerTopic(final String consumerTopic) {
309         this.consumerTopic = consumerTopic;
310     }
311
312     /**
313      * Sets the consumer wait time.
314      *
315      * @param consumerWaitTime the consumer wait time
316      */
317     public void setConsumerWaitTime(final int consumerWaitTime) {
318         this.consumerWaitTime = consumerWaitTime;
319     }
320
321     /**
322      * Checks if is object message sending.
323      *
324      * @return true, if checks if is object message sending
325      */
326     public boolean isObjectMessageSending() {
327         return objectMessageSending;
328     }
329
330     /**
331      * Sets the object message sending.
332      *
333      * @param objectMessageSending the object message sending
334      */
335     public void setObjectMessageSending(final boolean objectMessageSending) {
336         this.objectMessageSending = objectMessageSending;
337     }
338 }