2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.plugins.event.carrier.grpc;
25 import org.apache.commons.lang3.StringUtils;
26 import org.onap.policy.apex.service.engine.event.ApexEventException;
27 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
31 * Apex parameters for gRPC as an event carrier technology.
33 * <p>The parameters for this plugin are:
35 * <li>host: The host on which CDS is running. This parameter is mandatory
36 * <li>port: The port on the CDS host to connect to for CDS. This parameter is mandatory.
37 * <li>username: The username for basic authentication to connect to CDS. This parameter is mandatory.
38 * <li>password: The password for basic authentication to connect to CDS. This parameter is mandatory.
39 * <li>timeout: The timeout in seconds for CDS requests. This parameter is mandatory.
42 * @author Ajith Sreekumar(ajith.sreekumar@est.tech)
47 public class GrpcCarrierTechnologyParameters extends CarrierTechnologyParameters {
49 private static final int MIN_USER_PORT = 1024;
50 private static final int MAX_USER_PORT = 65535;
52 /** The label of this carrier technology. */
53 public static final String GRPC_CARRIER_TECHNOLOGY_LABEL = "GRPC";
55 /** The producer plugin class for the grpc carrier technology. */
56 public static final String GRPC_EVENT_PRODUCER_PLUGIN_CLASS = ApexGrpcProducer.class.getName();
58 /** The consumer plugin class for the gRPC carrier technology. */
59 public static final String GRPC_EVENT_CONSUMER_PLUGIN_CLASS = ApexGrpcConsumer.class.getName();
64 private String username;
65 private String password;
69 * Constructor to create a gRPC carrier technology parameters instance and register the instance with the
72 public GrpcCarrierTechnologyParameters() {
74 // Set the carrier technology properties for the gRPC carrier technology
75 this.setLabel(GRPC_CARRIER_TECHNOLOGY_LABEL);
76 this.setEventProducerPluginClass(GRPC_EVENT_PRODUCER_PLUGIN_CLASS);
77 this.setEventConsumerPluginClass(GRPC_EVENT_CONSUMER_PLUGIN_CLASS);
81 * The method validates the gRPC parameters. Host details are specified as parameters only for a gRPC producer.
83 * @param isProducer if the parameters specified are for the gRPC producer or consumer
84 * @throws ApexEventException exception thrown when invalid parameters are provided
86 public void validateGrpcParameters(boolean isProducer) throws ApexEventException {
87 StringBuilder errorMessage = new StringBuilder();
90 errorMessage.append("timeout should have a positive value.\n");
92 if (MIN_USER_PORT > port || MAX_USER_PORT < port) {
93 errorMessage.append("port range should be between ").append(MIN_USER_PORT).append(" and ")
94 .append(MAX_USER_PORT).append("\n");
96 if (StringUtils.isEmpty(host)) {
97 errorMessage.append("host should be specified.\n");
99 if (StringUtils.isEmpty(username)) {
100 errorMessage.append("username should be specified.\n");
102 if (StringUtils.isEmpty(password)) {
103 errorMessage.append("password should be specified.\n");
106 if (errorMessage.length() > 0) {
107 errorMessage.insert(0, "Issues in specifying gRPC Producer parameters:\n");
108 throw new ApexEventException(errorMessage.toString());