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