198c002542e21bb9c95c1bef46d272cd909dc72f
[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 \r
17 package org.openo.commontosca.catalog.model.externalservice.ro;\r
18 \r
19 import com.google.gson.Gson;\r
20 \r
21 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;\r
22 \r
23 import org.openo.commontosca.catalog.common.MsbUtil;\r
24 import org.openo.commontosca.catalog.common.ToolUtil;\r
25 import org.openo.commontosca.catalog.model.externalservice.entity.ro.ResourceResponseEntity;\r
26 import org.openo.commontosca.catalog.model.externalservice.entity.ro.VimEntity;\r
27 import org.slf4j.Logger;\r
28 import org.slf4j.LoggerFactory;\r
29 \r
30 \r
31 /**\r
32  * The roc resource service.\r
33  * \r
34  * @author 10189609\r
35  * \r
36  */\r
37 public class ResourceServiceConsumer {\r
38   private static final Logger LOG = LoggerFactory.getLogger(ResourceServiceConsumer.class);\r
39 \r
40   private static final String RESOURCE_REST_RESULT = "SUCCESS";\r
41 \r
42   /**\r
43    * get vim entity from roc by vimid.\r
44    * \r
45    * @param vimId id\r
46    * @return vim entity\r
47    */\r
48   public static VimEntity getResourceVim(String vimId) {\r
49     LOG.info("begin query vim info from roc,vimId:" + vimId);\r
50     IResourceServiceRest resourceserviceproxy =\r
51         ConsumerFactory.createConsumer(MsbUtil.getRocBaseUrl(), IResourceServiceRest.class);\r
52     String result = "";\r
53     try {\r
54       result = resourceserviceproxy.getResourceVim(vimId);\r
55     } catch (Exception e1) {\r
56       LOG.error("query vim info faild.", e1);\r
57       return null;\r
58     }\r
59     if (ToolUtil.isEmptyString(result)) {\r
60       LOG.error("query vim info faild, vim info is null, vimId:" + vimId);\r
61       return null;\r
62     }\r
63 \r
64     Gson gson = new Gson();\r
65     ResourceResponseEntity responseEntity = gson.fromJson(result, ResourceResponseEntity.class);\r
66     if (!RESOURCE_REST_RESULT.equalsIgnoreCase(responseEntity.getOperationResult())) {\r
67       LOG.error("query vim info faild.vimId:" + vimId);\r
68       return null;\r
69     }\r
70     if (responseEntity.getData().size() <= 0) {\r
71       LOG.error("query vim info faild, vim info is empty, vimId:" + vimId);\r
72       return null;\r
73     }\r
74 \r
75     LOG.info("end query vim info from roc.");\r
76     return responseEntity.getData().get(0);\r
77   }\r
78 }\r