2 * Copyright 2016 ZTE, Inc. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.msb.apiroute.wrapper;
18 import java.util.List;
20 import org.onap.msb.apiroute.api.IuiRouteInfo;
21 import org.onap.msb.apiroute.api.exception.ExtendedInternalServerErrorException;
22 import org.onap.msb.apiroute.api.exception.ExtendedNotFoundException;
23 import org.onap.msb.apiroute.wrapper.service.IuiRouteService;
24 import org.onap.msb.apiroute.wrapper.util.RouteUtil;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class IuiRouteServiceWrapper {
31 private static final Logger LOGGER = LoggerFactory.getLogger(IuiRouteServiceWrapper.class);
33 private static IuiRouteServiceWrapper instance = new IuiRouteServiceWrapper();
35 private IuiRouteServiceWrapper() {}
37 public static IuiRouteServiceWrapper getInstance() {
44 * @Title: getAllIuiRouteService
45 * @Description: TODO(get All IuiRouteServices)
47 * @return: IuiRouteInfo[]
49 public List<IuiRouteInfo> getAllIuiRouteInstances(String routeWay) {
51 RouteUtil.checkRouteWay(routeWay);
54 String iuiRedisKey = RouteUtil.getMutiRedisKey(RouteUtil.IUIROUTE, routeWay);
56 return IuiRouteService.getInstance().getMultiIuiRouteInstances(iuiRedisKey);
58 } catch (Exception e) {
59 throw new ExtendedInternalServerErrorException(e.getMessage());
68 * @Title: getIuiRouteInstance
69 * @Description: TODO(get one IuiRouteInstance by serviceName)
70 * @param: @param serviceName
72 * @return: IuiRouteInfo
74 public IuiRouteInfo getIuiRouteInstance(String serviceName, String host, String publish_port,
77 RouteUtil.checkRouteWay(routeWay);
79 String iuiRedisPrefixedKey =
81 .getRedisPrefixedKey(RouteUtil.IUIROUTE, serviceName, host, publish_port, routeWay);
83 IuiRouteInfo iuiRouteInfo;
85 iuiRouteInfo = IuiRouteService.getInstance().getIuiRouteInstance(iuiRedisPrefixedKey);
86 } catch (Exception e) {
87 LOGGER.error("get IuiRouteInstance throw exception", e);
88 throw new ExtendedInternalServerErrorException("get IuiRouteInstance throw exception"
94 if (null == iuiRouteInfo) {
95 throw new ExtendedNotFoundException("iui RouteInfo not found");
104 * @Title updateIuiRouteStatus
105 * @Description TODO(update one IuiRoute Status)
109 * @return RouteResult
111 public synchronized IuiRouteInfo updateIuiRouteStatus(String serviceName, String host,
112 String publish_port, String status, String routeWay) {
114 RouteUtil.checkRouteWay(routeWay);
116 RouteUtil.checkServiceStatus(status);
119 String iuiRedisPrefixedKey =
120 RouteUtil.getRedisPrefixedKey(RouteUtil.IUIROUTE, serviceName, host, publish_port,
123 IuiRouteService.getInstance().updateIuiRouteStatus2Redis(iuiRedisPrefixedKey, status);
126 } catch (Exception e) {
127 LOGGER.error("update IuiRoute status throw exception", e);
128 throw new ExtendedInternalServerErrorException(e.getMessage());
131 IuiRouteInfo new_iuiRouteInfo = getIuiRouteInstance(serviceName, host, publish_port, routeWay);
133 return new_iuiRouteInfo;
137 * @Title: saveIuiRouteInstance
138 * @Description: TODO(save one IuiRouteInstance)
139 * @param: @param IuiRouteInfo
141 * @return: IuiRouteInfo
143 public synchronized IuiRouteInfo saveIuiRouteInstance4Rest(IuiRouteInfo iuiRouteInfo,
146 RouteUtil.checkRouteWay(routeWay);
148 RouteUtil.checkRouterInfoFormat(iuiRouteInfo);
152 saveIuiRouteInstance(iuiRouteInfo, routeWay);
153 } catch (Exception e) {
154 throw new ExtendedInternalServerErrorException("save iuiRouteInfo fail: [serviceName]"
155 + iuiRouteInfo.getServiceName() + e.getMessage());
162 public synchronized void saveIuiRouteInstance(IuiRouteInfo iuiRouteInfo, String routeWay)
165 String iuiRedisPrefixedKey =
166 RouteUtil.getRedisPrefixedKey(RouteUtil.IUIROUTE, iuiRouteInfo.getServiceName(),
167 iuiRouteInfo.getHost(), iuiRouteInfo.getPublish_port(), routeWay);
169 IuiRouteService.getInstance().saveIuiRouteService2Redis(iuiRouteInfo, iuiRedisPrefixedKey);
170 LOGGER.info("save iuiRouteInfo [serviceName]" + iuiRouteInfo.getServiceName() + " [host]"
171 + iuiRouteInfo.getHost() + " [publish_port]" + iuiRouteInfo.getPublish_port()
172 + " [routeWay]" + routeWay + " success");
174 } catch (Exception e) {
175 LOGGER.error("save iuiRouteInfo [serviceName]" + iuiRouteInfo.getServiceName() + " [host]"
176 + iuiRouteInfo.getHost() + " [publish_port]" + iuiRouteInfo.getPublish_port()
177 + " [routeWay]" + routeWay + " throw exception", e);
185 * @Title: deleteIuiRoute
186 * @Description: TODO(delete one IuiRoute)
187 * @param: @param type
188 * @param: @param serviceName
189 * @param: @param delKey
193 public synchronized void deleteIuiRoute(String serviceName, String host, String publish_port,
196 RouteUtil.checkRouteWay(routeWay);
198 String iuiRedisPrefixedKey =
200 .getRedisPrefixedKey(RouteUtil.IUIROUTE, serviceName, host, publish_port, routeWay);
203 IuiRouteService.getInstance().deleteIuiRouteService2Redis(iuiRedisPrefixedKey);
204 LOGGER.info("delete iuiRouteInfo [serviceName]" + serviceName + " [host]" + host
205 + " [publish_port]" + publish_port + " [routeWay]" + routeWay + " success");
207 } catch (ExtendedNotFoundException e) {
209 } catch (Exception e) {
210 LOGGER.error("delete iuiRouteInfo [serviceName]" + serviceName + " [host]" + host
211 + " [publish_port]" + publish_port + " [routeWay]" + routeWay + " throw exception", e);
212 throw new ExtendedInternalServerErrorException("delete iuiRouteInfo [serviceName]" + serviceName +e.getMessage());