e39954ed87d54a431174836a452a563401090501
[policy/common.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * policy-endpoints
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.policy.common.endpoints.event.comm.bus.internal.impl;
22
23 import com.att.nsa.mr.test.clients.ProtocolTypeConstants;
24
25 import java.util.List;
26 import java.util.Map;
27
28 import org.onap.policy.common.endpoints.event.comm.bus.DmaapTopicSinkFactory;
29 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
30
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) {
35
36         super(ProtocolTypeConstants.DME2, servers, topic, username, password, useHttps);
37
38
39
40         String dme2RouteOffer = additionalProps.get(DmaapTopicSinkFactory.DME2_ROUTE_OFFER_PROPERTY);
41
42         if (environment == null || environment.isEmpty()) {
43             throw parmException(topic, PolicyEndPointProperties.PROPERTY_DMAAP_DME2_ENVIRONMENT_SUFFIX);
44         }
45         if (aftEnvironment == null || aftEnvironment.isEmpty()) {
46             throw parmException(topic, PolicyEndPointProperties.PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX);
47         }
48         if (latitude == null || latitude.isEmpty()) {
49             throw parmException(topic, PolicyEndPointProperties.PROPERTY_DMAAP_DME2_LATITUDE_SUFFIX);
50         }
51         if (longitude == null || longitude.isEmpty()) {
52             throw parmException(topic, PolicyEndPointProperties.PROPERTY_DMAAP_DME2_LONGITUDE_SUFFIX);
53         }
54
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");
61         }
62
63         String serviceName = servers.get(0);
64
65         /* These are required, no defaults */
66         props.setProperty("Environment", environment);
67         props.setProperty("AFT_ENVIRONMENT", aftEnvironment);
68
69         props.setProperty(DmaapTopicSinkFactory.DME2_SERVICE_NAME_PROPERTY, serviceName);
70
71         if (dme2Partner != null) {
72             props.setProperty("Partner", dme2Partner);
73         }
74         if (dme2RouteOffer != null) {
75             props.setProperty(DmaapTopicSinkFactory.DME2_ROUTE_OFFER_PROPERTY, dme2RouteOffer);
76         }
77
78         props.setProperty("Latitude", latitude);
79         props.setProperty("Longitude", longitude);
80
81         // ServiceName also a default, found in additionalProps
82
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");
90
91         /* These should not change */
92         props.setProperty("TransportType", "DME2");
93         props.setProperty("MethodType", "POST");
94
95         for (Map.Entry<String, String> entry : additionalProps.entrySet()) {
96             String key = entry.getKey();
97             String value = entry.getValue();
98
99             if (value != null) {
100                 props.setProperty(key, value);
101             }
102         }
103
104         this.publisher.setProps(props);
105     }
106
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");
110
111     }
112 }