bump the version
[dmaap/messagerouter/msgrtr.git] / src / main / java / org / onap / dmaap / dmf / mr / listener / DME2EndPointLoader.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
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
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  *  ============LICENSE_END=========================================================
18  *  
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  *  
21  *******************************************************************************/
22 package org.onap.dmaap.dmf.mr.listener;
23
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.util.Properties;
27
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;
34
35 /**
36  * 
37  * @author anowarul.islam
38  *
39  */
40 public class DME2EndPointLoader {
41
42         private String latitude;
43         private String longitude;
44         private String version;
45         private String serviceName;
46         private String env;
47         private String routeOffer;
48         private String hostName;
49         private String port;
50         private String contextPath;
51         private String protocol;
52         private String serviceURL;
53         private static DME2EndPointLoader loader = new DME2EndPointLoader();
54
55         private static final EELFLogger LOG = EELFManager.getInstance().getLogger(EventsServiceImpl.class);
56         private DME2EndPointLoader() {
57         }
58
59         public static DME2EndPointLoader getInstance() {
60                 return loader;
61         }
62
63         /**
64          * publishing endpoints
65          */
66         public void publishEndPoints() {
67
68                 try {
69                         InputStream input = this.getClass().getResourceAsStream("/endpoint.properties");
70                         Properties props = new Properties();
71                         props.load(input);
72
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");
83
84                         System.setProperty("AFT_LATITUDE", latitude);
85                         System.setProperty("AFT_LONGITUDE", longitude);
86                         System.setProperty("AFT_ENVIRONMENT", "AFTUAT");
87
88                         serviceURL = "service=" + serviceName + "/" + "version=" + version + "/" + "envContext=" + env + "/"
89                                         + "routeOffer=" + routeOffer;
90
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
95                         // protocol as args
96                         svcRegistry.publish(serviceURL, contextPath, hostName, Integer.parseInt(port), protocol);
97
98                 } catch (IOException | DME2Exception e) {
99                         LOG.error("Failed due to :" + e);
100                 }
101
102         }
103 /**
104  * unpublishing endpoints
105  */
106         public void unPublishEndPoints() {
107
108                 DME2Manager manager;
109                 try {
110                         System.setProperty("AFT_LATITUDE", latitude);
111                         System.setProperty("AFT_LONGITUDE", longitude);
112                         System.setProperty("AFT_ENVIRONMENT", "AFTUAT");
113
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);
119                 }
120
121         }
122
123 }