65431a2b3d974db1a8448fc12a27ca7d99b50348
[vfc/nfvo/catalog.git] /
1 /**\r
2  * Copyright 2016 [ZTE] and others.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 package org.openo.commontosca.catalog.model.externalservice.ro;\r
17 \r
18 import org.openo.commontosca.catalog.common.MSBUtil;\r
19 import org.openo.commontosca.catalog.common.ToolUtil;\r
20 import org.openo.commontosca.catalog.model.externalservice.entity.roEntity.ResourceResponseEntity;\r
21 import org.openo.commontosca.catalog.model.externalservice.entity.roEntity.VimEntity;\r
22 import org.slf4j.Logger;\r
23 import org.slf4j.LoggerFactory;\r
24 \r
25 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;\r
26 import com.google.gson.Gson;\r
27 \r
28 /**\r
29  * The roc resource service.\r
30  * @author 10189609\r
31  *\r
32  */\r
33 public class ResourceServiceConsumer {\r
34         private static final Logger LOG = LoggerFactory.getLogger(ResourceServiceConsumer.class);\r
35         \r
36         private static final String RESOURCE_REST_RESULT = "SUCCESS";\r
37         \r
38         /**\r
39          * get vim entity from roc by vimid\r
40          * @param vimId id\r
41          * @return vim entity\r
42          */\r
43         public static VimEntity getResourceVim(String vimId) {\r
44                 LOG.info("begin query vim info from roc,vimId:" + vimId);\r
45                 IResourceServiceRest resourceserviceproxy = ConsumerFactory\r
46                                 .createConsumer(MSBUtil.getRocBaseUrl(), IResourceServiceRest.class);   \r
47                 String result = "";\r
48                 try {\r
49                         result = resourceserviceproxy.getResourceVim(vimId);\r
50                 } catch (Exception e) {\r
51                         LOG.error("query vim info faild.", e);\r
52                         return null;\r
53                 }\r
54                 if (ToolUtil.isEmptyString(result)) {\r
55                         LOG.error("query vim info faild, vim info is null, vimId:" + vimId);\r
56                         return null;\r
57                 }\r
58                 \r
59                 Gson gson = new Gson();\r
60                 ResourceResponseEntity responseEntity = gson.fromJson(result, ResourceResponseEntity.class);\r
61                 if (!RESOURCE_REST_RESULT.equalsIgnoreCase(responseEntity.getOperationResult())) \r
62                 {\r
63                         LOG.error("query vim info faild.vimId:" + vimId);\r
64                         return null;\r
65                 }\r
66                 if (responseEntity.getData().size() <= 0)\r
67         {\r
68                         LOG.error("query vim info faild, vim info is empty, vimId:" + vimId);\r
69             return null;\r
70         }\r
71                 \r
72                 LOG.info("end query vim info from roc.");\r
73                 return responseEntity.getData().get(0);\r
74         }\r
75 }\r