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