e8009a5d8227a8258835c3d3f4d32599013acc53
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.plugins.event.carrier.websocket;
22
23 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
24
25 /**
26  * Apex parameters for Kafka as an event carrier technology.
27  *
28  * @author Liam Fallon (liam.fallon@ericsson.com)
29  */
30 public class WEBSOCKETCarrierTechnologyParameters extends CarrierTechnologyParameters {
31     // @formatter:off
32     private static final int MIN_USER_PORT =  1024;
33     private static final int MAX_USER_PORT = 65535;
34
35     /** The label of this carrier technology. */
36     public static final String WEB_SCOKET_CARRIER_TECHNOLOGY_LABEL = "WEBSOCKET";
37
38     /** The producer plugin class for the web socket carrier technology. */
39     public static final String WEB_SCOKET_EVENT_PRODUCER_PLUGIN_CLASS = ApexWebSocketProducer.class.getCanonicalName();
40
41     /** The consumer plugin class for the web socket carrier technology. */
42     public static final String KWEB_SCOKET_EVENT_CONSUMER_PLUGIN_CLASS = ApexWebSocketConsumer.class.getCanonicalName();
43
44     // Default parameter values
45     private static final String DEFAULT_HOST = "localhost";
46     private static final int    DEFAULT_PORT = -1;
47
48     // Web socket parameters
49     private boolean wsClient = true;
50     private String  host     = DEFAULT_HOST;
51     private int     port     = DEFAULT_PORT;
52     // @formatter:on
53
54     /**
55      * Constructor to create a web socket carrier technology parameters instance and register the instance with the
56      * parameter service.
57      */
58     public WEBSOCKETCarrierTechnologyParameters() {
59         super(WEBSOCKETCarrierTechnologyParameters.class.getCanonicalName());
60
61         // Set the carrier technology properties for the web socket carrier technology
62         this.setLabel(WEB_SCOKET_CARRIER_TECHNOLOGY_LABEL);
63         this.setEventProducerPluginClass(WEB_SCOKET_EVENT_PRODUCER_PLUGIN_CLASS);
64         this.setEventConsumerPluginClass(KWEB_SCOKET_EVENT_CONSUMER_PLUGIN_CLASS);
65     }
66
67     /**
68      * Gets the host.
69      *
70      * @return the host
71      */
72     public String getHost() {
73         return host;
74     }
75
76     /**
77      * Gets the port.
78      *
79      * @return the port
80      */
81     public int getPort() {
82         return port;
83     }
84
85     /**
86      * Checks if is ws client.
87      *
88      * @return true, if checks if is ws client
89      */
90     public boolean isWsClient() {
91         return wsClient;
92     }
93
94     /*
95      * (non-Javadoc)
96      *
97      * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate()
98      */
99     @Override
100     public String validate() {
101         final StringBuilder errorMessageBuilder = new StringBuilder();
102
103         errorMessageBuilder.append(super.validate());
104
105         if (wsClient && (host == null || host.trim().length() == 0)) {
106             errorMessageBuilder.append("  host not specified, must be host as a string\n");
107         }
108
109         if (port < MIN_USER_PORT || port > MAX_USER_PORT) {
110             errorMessageBuilder.append("  port [" + port + "] invalid, must be specified as 1024 <= port <= 6535\n");
111         }
112
113         return errorMessageBuilder.toString();
114     }
115 }