9febeb45b3536f2151ea7007dad0129f04245b40
[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 import org.onap.policy.common.parameters.GroupValidationResult;
25 import org.onap.policy.common.parameters.ValidationStatus;
26
27 /**
28  * Apex parameters for Kafka as an event carrier technology.
29  *
30  * @author Liam Fallon (liam.fallon@ericsson.com)
31  */
32 public class WebSocketCarrierTechnologyParameters extends CarrierTechnologyParameters {
33     // @formatter:off
34     private static final int MIN_USER_PORT =  1024;
35     private static final int MAX_USER_PORT = 65535;
36
37     /** The label of this carrier technology. */
38     public static final String WEB_SCOKET_CARRIER_TECHNOLOGY_LABEL = "WEBSOCKET";
39
40     /** The producer plugin class for the web socket carrier technology. */
41     public static final String WEB_SCOKET_EVENT_PRODUCER_PLUGIN_CLASS = ApexWebSocketProducer.class.getCanonicalName();
42
43     /** The consumer plugin class for the web socket carrier technology. */
44     public static final String KWEB_SCOKET_EVENT_CONSUMER_PLUGIN_CLASS = ApexWebSocketConsumer.class.getCanonicalName();
45
46     // Default parameter values
47     private static final String DEFAULT_HOST = "localhost";
48     private static final int    DEFAULT_PORT = -1;
49
50     // Web socket parameters
51     private boolean wsClient = true;
52     private String  host     = DEFAULT_HOST;
53     private int     port     = DEFAULT_PORT;
54     // @formatter:on
55
56     /**
57      * Constructor to create a web socket carrier technology parameters instance and register the instance with the
58      * parameter service.
59      */
60     public WebSocketCarrierTechnologyParameters() {
61         super();
62
63         // Set the carrier technology properties for the web socket carrier technology
64         this.setLabel(WEB_SCOKET_CARRIER_TECHNOLOGY_LABEL);
65         this.setEventProducerPluginClass(WEB_SCOKET_EVENT_PRODUCER_PLUGIN_CLASS);
66         this.setEventConsumerPluginClass(KWEB_SCOKET_EVENT_CONSUMER_PLUGIN_CLASS);
67     }
68
69     /**
70      * Gets the host.
71      *
72      * @return the host
73      */
74     public String getHost() {
75         return host;
76     }
77
78     /**
79      * Gets the port.
80      *
81      * @return the port
82      */
83     public int getPort() {
84         return port;
85     }
86
87     /**
88      * Checks if is ws client.
89      *
90      * @return true, if checks if is ws client
91      */
92     public boolean isWsClient() {
93         return wsClient;
94     }
95
96     /*
97      * (non-Javadoc)
98      *
99      * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate()
100      */
101     @Override
102     public GroupValidationResult validate() {
103         final GroupValidationResult result = super.validate();
104
105         if (wsClient && (host == null || host.trim().length() == 0)) {
106             result.setResult("host", ValidationStatus.INVALID, "host not specified, must be host as a string");
107         }
108
109         if (port < MIN_USER_PORT || port > MAX_USER_PORT) {
110             result.setResult("port", ValidationStatus.INVALID,
111                             "[" + port + "] invalid, must be specified as 1024 <= port <= 65535");
112         }
113
114         return result;
115     }
116 }