89588ec37a154c1d8728807b2a1013b0ae12e346
[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 lombok.Getter;
25 import org.apache.commons.lang3.StringUtils;
26 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
27 import org.onap.policy.common.parameters.BeanValidationResult;
28 import org.onap.policy.common.parameters.ValidationStatus;
29 import org.onap.policy.common.parameters.annotations.Max;
30 import org.onap.policy.common.parameters.annotations.Min;
31 import org.onap.policy.models.base.Validated;
32
33 /**
34  * Apex parameters for Kafka as an event carrier technology.
35  *
36  * @author Liam Fallon (liam.fallon@ericsson.com)
37  */
38 @Getter
39 public class WebSocketCarrierTechnologyParameters extends CarrierTechnologyParameters {
40     // @formatter:off
41     private static final int MIN_USER_PORT =  1024;
42     private static final int MAX_USER_PORT = 65535;
43
44     /** The label of this carrier technology. */
45     public static final String WEB_SCOKET_CARRIER_TECHNOLOGY_LABEL = "WEBSOCKET";
46
47     /** The producer plugin class for the web socket carrier technology. */
48     public static final String WEB_SCOKET_EVENT_PRODUCER_PLUGIN_CLASS = ApexWebSocketProducer.class.getName();
49
50     /** The consumer plugin class for the web socket carrier technology. */
51     public static final String KWEB_SCOKET_EVENT_CONSUMER_PLUGIN_CLASS = ApexWebSocketConsumer.class.getName();
52
53     // Default parameter values
54     private static final String DEFAULT_HOST = "localhost";
55     private static final int    DEFAULT_PORT = -1;
56
57     // Web socket parameters
58     private boolean wsClient = true;
59     private String  host     = DEFAULT_HOST;
60     @Min(MIN_USER_PORT)
61     @Max(MAX_USER_PORT)
62     private int     port     = DEFAULT_PORT;
63     // @formatter:on
64
65     /**
66      * Constructor to create a web socket carrier technology parameters instance and register the instance with the
67      * parameter service.
68      */
69     public WebSocketCarrierTechnologyParameters() {
70         super();
71
72         // Set the carrier technology properties for the web socket carrier technology
73         this.setLabel(WEB_SCOKET_CARRIER_TECHNOLOGY_LABEL);
74         this.setEventProducerPluginClass(WEB_SCOKET_EVENT_PRODUCER_PLUGIN_CLASS);
75         this.setEventConsumerPluginClass(KWEB_SCOKET_EVENT_CONSUMER_PLUGIN_CLASS);
76     }
77
78     /**
79      * {@inheritDoc}.
80      */
81     @Override
82     public BeanValidationResult validate() {
83         final BeanValidationResult result = super.validate();
84
85         if (wsClient && StringUtils.isBlank(host)) {
86             result.addResult("host", host, ValidationStatus.INVALID, Validated.IS_BLANK);
87         }
88
89         return result;
90     }
91 }