1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
/*
* Copyright (C) 2018 CMCC, Inc. and others. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onap.usecaseui.server.service.sotn.impl;
import static org.onap.usecaseui.server.util.RestfulServices.extractBody;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.onap.usecaseui.server.bean.sotn.Pinterface;
import org.onap.usecaseui.server.bean.sotn.PinterfaceRsp;
import org.onap.usecaseui.server.constant.Constant;
import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException;
import org.onap.usecaseui.server.service.lcm.domain.so.exceptions.SOException;
import org.onap.usecaseui.server.service.sotn.SOTNService;
import org.onap.usecaseui.server.util.RestfulServices;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Service;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Response;
@Service("SOTNService")
@org.springframework.context.annotation.Configuration
@EnableAspectJAutoProxy
public class SOTNServiceImpl implements SOTNService{
private static final Logger logger = LoggerFactory.getLogger(SOTNServiceImpl.class);
private AAIService aaiService;
public SOTNServiceImpl() {
this(RestfulServices.create(AAIService.class));
}
public SOTNServiceImpl(AAIService aaiService) {
this.aaiService = aaiService;
}
@Override
public String getNetWorkResources() {
String result="";
try {
logger.info("aai getNetWorkResources is starting!");
Response<ResponseBody> response = this.aaiService.listNetWorkResources().execute();
logger.info("aai getNetWorkResources has finished!");
if (response.isSuccessful()) {
result=new String(response.body().bytes());
} else {
logger.info(String.format("Can not get getNetWorkResources[code=%s, message=%s]", response.code(), response.message()));
result = Constant.CONSTANT_FAILED;
}
} catch (IOException e) {
logger.error("getNetWorkResources occur exception:"+e);
result = Constant.CONSTANT_FAILED;;
}
return result;
}
@Override
public List<Pinterface> getPinterfaceByPnfName(String pnfName) {
try {
logger.info("aai getPinterfaceByPnfName is starting!");
Response<PinterfaceRsp> response = this.aaiService.getPinterfaceByPnfName(pnfName).execute();
logger.info(String.format("excute aai interface:/api/aai-network/v13/pnfs/pnf/%s/p-interfaces",pnfName));
logger.info("aai getPinterfaceByPnfName has finished!");
if (response.isSuccessful()) {
return response.body().getPinterfaces();
} else {
logger.info(String.format("Can not get getPinterfaceByPnfName[code=%s, message=%s]", response.code(), response.message()));
return Collections.emptyList();
}
} catch (IOException e) {
logger.error("getPinterfaceByPnfName occur exception:"+e);
throw new AAIException("AAI is not available.", e);
}
}
@Override
public String getLogicalLinks() {
String result="";
try {
logger.info("aai getLogicalLinks is starting!");
Response<ResponseBody> response = this.aaiService.getLogicalLinks().execute();
logger.info("aai getLogicalLinks has finished!");
if (response.isSuccessful()) {
result=new String(response.body().bytes());
} else {
logger.info(String.format("Can not get getLogicalLinks[code=%s, message=%s]", response.code(), response.message()));
result=Constant.CONSTANT_FAILED;;
}
} catch (IOException e) {
logger.error("getLogicalLinks occur exception:"+e);
result=Constant.CONSTANT_FAILED;;
}
return result;
}
@Override
public String getSpecificLogicalLink(String linkName) {
String result="";
try {
logger.info("aai getSpecificLogicalLink is starting!");
Response<ResponseBody> response = this.aaiService.getSpecificLogicalLink(linkName).execute();
logger.info("aai getSpecificLogicalLink has finished!");
if (response.isSuccessful()) {
result=new String(response.body().bytes());
} else {
logger.info(String.format("Can not get getSpecificLogicalLink[code=%s, message=%s]", response.code(), response.message()));
result=Constant.CONSTANT_FAILED;
}
} catch (IOException e) {
logger.error("getSpecificLogicalLink occur exception:"+e);
result=Constant.CONSTANT_FAILED;
}
return result;
}
@Override
public String getHostUrl(String aaiId) {
String result="";
try {
logger.info("aai getHostUrl is starting!");
Response<ResponseBody> response = this.aaiService.getHostUrl(aaiId).execute();
logger.info("aai getHostUrl has finished!");
if (response.isSuccessful()) {
result=new String(response.body().bytes());
} else {
logger.info(String.format("Can not get getHostUrl[code=%s, message=%s]", response.code(), response.message()));
result=Constant.CONSTANT_FAILED;
}
} catch (IOException e) {
logger.error("getHostUrl occur exception:"+e);
result=Constant.CONSTANT_FAILED;;
}
return result;
}
@Override
public String createHostUrl(HttpServletRequest request,String aaiId) {
String result = "";
try {
logger.info("aai createHostUrl is starting");
RequestBody requestBody = extractBody(request);
Response<ResponseBody> response = aaiService.createHostUrl(requestBody,aaiId).execute();
logger.info("aai createHostUrl has finished");
if (response.isSuccessful()) {
result=Constant.CONSTANT_SUCCESS;
} else {
result=Constant.CONSTANT_FAILED;
logger.error(String.format("Can not createHostUrl[code=%s, message=%s]", response.code(), response.message()));
throw new SOException("aai createHostUrl failed!");
}
} catch (Exception e) {
result=Constant.CONSTANT_FAILED;
logger.error("createHostUrl occur exception:"+e);
throw new SOException("aai createHostUrl is not available!", e);
}
return result;
}
@Override
public String createTopoNetwork(HttpServletRequest request,String networkId) {
String result = "";
try {
logger.info("aai createTopoNetwork is starting");
RequestBody requestBody = extractBody(request);
Response<ResponseBody> response = aaiService.createTopoNetwork(requestBody,networkId).execute();
logger.info("aai createTopoNetwork has finished");
if (response.isSuccessful()) {
result=Constant.CONSTANT_SUCCESS;
} else {
result=Constant.CONSTANT_FAILED;
logger.error(String.format("Can not createTopoNetwork[code=%s, message=%s]", response.code(), response.message()));
throw new SOException("aai createTopoNetwork failed!");
}
} catch (Exception e) {
result=Constant.CONSTANT_FAILED;
logger.error("createTopoNetwork occur exception:"+e);
throw new SOException("aai createTopoNetwork is not available!", e);
}
return result;
}
@Override
public String createTerminationPoint(HttpServletRequest request,String pnfName,String tpId) {
String result = "";
try {
logger.info("aai createTerminationPoint is starting");
RequestBody requestBody = extractBody(request);
Response<ResponseBody> response = aaiService.createTerminationPoint(requestBody,pnfName,tpId).execute();
logger.info("aai createTerminationPoint has finished");
if (response.isSuccessful()) {
result=Constant.CONSTANT_SUCCESS;
} else {
result=Constant.CONSTANT_FAILED;
logger.error(String.format("Can not createTerminationPoint[code=%s, message=%s]", response.code(), response.message()));
throw new SOException("aai createTerminationPoint failed!");
}
} catch (Exception e) {
result=Constant.CONSTANT_FAILED;
logger.error("createTerminationPoint occur exception:"+e);
throw new SOException("aai createTerminationPoint is not available!", e);
}
return result;
}
@Override
public String createLink(HttpServletRequest request,String linkName) {
String result = "";
try {
logger.info("aai createLink is starting");
RequestBody requestBody = extractBody(request);
Response<ResponseBody> response = aaiService.createLink(requestBody,linkName).execute();
logger.info("aai createLink has finished");
if (response.isSuccessful()) {
result=Constant.CONSTANT_SUCCESS;
} else {
result=Constant.CONSTANT_FAILED;
logger.error(String.format("Can not createLink[code=%s, message=%s]", response.code(), response.message()));
throw new SOException("aai createLink failed!");
}
} catch (Exception e) {
result="FAILED";
logger.error("createLink occur exception:"+e);
throw new SOException("aai createLink is not available!", e);
}
return result;
}
@Override
public String createPnf(HttpServletRequest request,String pnfName) {
String result = "";
try {
logger.info("aai createPnf is starting");
RequestBody requestBody = extractBody(request);
Response<ResponseBody> response = aaiService.createPnf(requestBody,pnfName).execute();
logger.info("aai createPnf has finished");
if (response.isSuccessful()) {
result=Constant.CONSTANT_SUCCESS;
} else {
result=Constant.CONSTANT_FAILED;
logger.error(String.format("Can not createPnf[code=%s, message=%s]", response.code(), response.message()));
throw new SOException("aai createPnf failed!");
}
} catch (Exception e) {
result=Constant.CONSTANT_FAILED;
logger.error("createPnf occur exception:"+e);
}
return result;
}
@Override
public String deleteLink(String linkName,String resourceVersion) {
String result = "";
try {
logger.info("aai deleteLink is starting");
Response<ResponseBody> response = aaiService.deleteLink(linkName,resourceVersion).execute();
logger.info("aai deleteLink has finished");
if (response.isSuccessful()) {
result=Constant.CONSTANT_SUCCESS;
} else {
result=Constant.CONSTANT_FAILED;
logger.error(String.format("Can not deleteLink[code=%s, message=%s]", response.code(), response.message()));
throw new SOException("aai deleteLink failed!");
}
} catch (Exception e) {
result=Constant.CONSTANT_FAILED;
logger.error("deleteLink occur exception:"+e);
throw new SOException("aai deleteLink is not available!", e);
}
return result;
}
@Override
public String getServiceInstances(String customerId, String serviceType) {
String result="";
try {
logger.info("aai getServiceInstances is starting");
Response<ResponseBody> response = aaiService.getServiceInstances(customerId, serviceType).execute();
logger.info("aai getServiceInstances has finished");
if (response.isSuccessful()) {
result=new String(response.body().bytes());
} else {
logger.error(String.format("Can not getServiceInstances[code=%s, message=%s]", response.code(), response.message()));
result= Constant.CONSTANT_FAILED;
}
} catch (Exception e) {
logger.error("getServiceInstances occur exception:"+e);
result= Constant.CONSTANT_FAILED;
}
return result;
}
@Override
public String serviceInstanceInfo(String customerId, String serviceType, String serviceInstanceId) {
try {
logger.info("aai serviceInstanceInfo is starting");
Response<ResponseBody> response = aaiService.serviceInstaneInfo(customerId, serviceType, serviceInstanceId).execute();
logger.info("aai serviceInstanceInfo has finished");
if (response.isSuccessful()) {
String result=new String(response.body().bytes());
return result;
} else {
logger.error(String.format("Can not serviceInstanceInfo[code=%s, message=%s]", response.code(), response.message()));
throw new SOException("aai serviceInstanceInfo failed!");
}
} catch (Exception e) {
logger.error("serviceInstanceInfo occur exception:"+e);
throw new SOException("aai serviceInstanceInfo is not available!", e);
}
}
}
|