2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.common.endpoints.event.comm.bus.internal.impl;
23 import com.att.nsa.mr.test.clients.ProtocolTypeConstants;
25 import java.util.List;
28 import org.onap.policy.common.endpoints.event.comm.bus.DmaapTopicSinkFactory;
29 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
31 public class DmaapDmePublisherWrapper extends DmaapPublisherWrapper {
32 public DmaapDmePublisherWrapper(List<String> servers, String topic, String username, String password,
33 String environment, String aftEnvironment, String dme2Partner, String latitude, String longitude,
34 Map<String, String> additionalProps, boolean useHttps) {
36 super(ProtocolTypeConstants.DME2, servers, topic, username, password, useHttps);
40 String dme2RouteOffer = additionalProps.get(DmaapTopicSinkFactory.DME2_ROUTE_OFFER_PROPERTY);
42 if (environment == null || environment.isEmpty()) {
43 throw parmException(topic, PolicyEndPointProperties.PROPERTY_DMAAP_DME2_ENVIRONMENT_SUFFIX);
45 if (aftEnvironment == null || aftEnvironment.isEmpty()) {
46 throw parmException(topic, PolicyEndPointProperties.PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX);
48 if (latitude == null || latitude.isEmpty()) {
49 throw parmException(topic, PolicyEndPointProperties.PROPERTY_DMAAP_DME2_LATITUDE_SUFFIX);
51 if (longitude == null || longitude.isEmpty()) {
52 throw parmException(topic, PolicyEndPointProperties.PROPERTY_DMAAP_DME2_LONGITUDE_SUFFIX);
55 if ((dme2Partner == null || dme2Partner.isEmpty()) && (dme2RouteOffer == null || dme2RouteOffer.isEmpty())) {
56 throw new IllegalArgumentException(
57 "Must provide at least " + PolicyEndPointProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "." + topic
58 + PolicyEndPointProperties.PROPERTY_DMAAP_DME2_PARTNER_SUFFIX + " or "
59 + PolicyEndPointProperties.PROPERTY_DMAAP_SINK_TOPICS + "." + topic
60 + PolicyEndPointProperties.PROPERTY_DMAAP_DME2_ROUTE_OFFER_SUFFIX + " for DME2");
63 String serviceName = servers.get(0);
65 /* These are required, no defaults */
66 props.setProperty("Environment", environment);
67 props.setProperty("AFT_ENVIRONMENT", aftEnvironment);
69 props.setProperty(DmaapTopicSinkFactory.DME2_SERVICE_NAME_PROPERTY, serviceName);
71 if (dme2Partner != null) {
72 props.setProperty("Partner", dme2Partner);
74 if (dme2RouteOffer != null) {
75 props.setProperty(DmaapTopicSinkFactory.DME2_ROUTE_OFFER_PROPERTY, dme2RouteOffer);
78 props.setProperty("Latitude", latitude);
79 props.setProperty("Longitude", longitude);
81 // ServiceName also a default, found in additionalProps
83 /* These are optional, will default to these values if not set in optionalProps */
84 props.setProperty("AFT_DME2_EP_READ_TIMEOUT_MS", "50000");
85 props.setProperty("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", "240000");
86 props.setProperty("AFT_DME2_EP_CONN_TIMEOUT", "15000");
87 props.setProperty("Version", "1.0");
88 props.setProperty("SubContextPath", "/");
89 props.setProperty("sessionstickinessrequired", "no");
91 /* These should not change */
92 props.setProperty("TransportType", "DME2");
93 props.setProperty("MethodType", "POST");
95 for (Map.Entry<String, String> entry : additionalProps.entrySet()) {
96 String key = entry.getKey();
97 String value = entry.getValue();
100 props.setProperty(key, value);
104 this.publisher.setProps(props);
107 private IllegalArgumentException parmException(String topic, String propnm) {
108 return new IllegalArgumentException("Missing " + PolicyEndPointProperties.PROPERTY_DMAAP_SINK_TOPICS + "."
109 + topic + propnm + " property for DME2 in DMaaP");