1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 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 * http://www.apache.org/licenses/LICENSE-2.0
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 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package org.onap.dmaap.dmf.mr.listener;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.util.Properties;
28 import com.att.aft.dme2.manager.registry.DME2EndpointRegistry;
29 import com.att.aft.dme2.api.DME2Exception;
30 import com.att.aft.dme2.api.DME2Manager;
31 import org.onap.dmaap.dmf.mr.service.impl.EventsServiceImpl;
32 import com.att.eelf.configuration.EELFLogger;
33 import com.att.eelf.configuration.EELFManager;
37 * @author anowarul.islam
40 public class DME2EndPointLoader {
42 private String latitude;
43 private String longitude;
44 private String version;
45 private String serviceName;
47 private String routeOffer;
48 private String hostName;
50 private String contextPath;
51 private String protocol;
52 private String serviceURL;
53 private static DME2EndPointLoader loader = new DME2EndPointLoader();
55 private static final EELFLogger LOG = EELFManager.getInstance().getLogger(EventsServiceImpl.class);
56 private DME2EndPointLoader() {
59 public static DME2EndPointLoader getInstance() {
64 * publishing endpoints
66 public void publishEndPoints() {
69 InputStream input = this.getClass().getResourceAsStream("/endpoint.properties");
70 Properties props = new Properties();
73 latitude = props.getProperty("Latitude");
74 longitude = props.getProperty("Longitude");
75 version = props.getProperty("Version");
76 serviceName = props.getProperty("ServiceName");
77 env = props.getProperty("Environment");
78 routeOffer = props.getProperty("RouteOffer");
79 hostName = props.getProperty("HostName");
80 port = props.getProperty("Port");
81 contextPath = props.getProperty("ContextPath");
82 protocol = props.getProperty("Protocol");
84 System.setProperty("AFT_LATITUDE", latitude);
85 System.setProperty("AFT_LONGITUDE", longitude);
86 System.setProperty("AFT_ENVIRONMENT", "AFTUAT");
88 serviceURL = "service=" + serviceName + "/" + "version=" + version + "/" + "envContext=" + env + "/"
89 + "routeOffer=" + routeOffer;
91 DME2Manager manager = new DME2Manager("testEndpointPublish", props);
92 manager.setClientCredentials("sh301n", "");
93 DME2EndpointRegistry svcRegistry = manager.getEndpointRegistry();
94 // Publish API takes service name, context path, hostname, port and
96 svcRegistry.publish(serviceURL, contextPath, hostName, Integer.parseInt(port), protocol);
98 } catch (IOException | DME2Exception e) {
99 LOG.error("Failed due to :" + e);
104 * unpublishing endpoints
106 public void unPublishEndPoints() {
110 System.setProperty("AFT_LATITUDE", latitude);
111 System.setProperty("AFT_LONGITUDE", longitude);
112 System.setProperty("AFT_ENVIRONMENT", "AFTUAT");
114 manager = DME2Manager.getDefaultInstance();
115 DME2EndpointRegistry svcRegistry = manager.getEndpointRegistry();
116 svcRegistry.unpublish(serviceURL, hostName, Integer.parseInt(port));
117 } catch (DME2Exception e) {
118 LOG.error("Failed due to DME2Exception" + e);