f09170ff904362c3e561d40287e2d180de398408
[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.lifecycle;\r
18 \r
19 import com.google.gson.Gson;\r
20 import com.google.gson.reflect.TypeToken;\r
21 \r
22 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;\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.lifecycle.InstanceEntity;\r
26 import org.slf4j.Logger;\r
27 import org.slf4j.LoggerFactory;\r
28 \r
29 import java.lang.reflect.Type;\r
30 import java.util.ArrayList;\r
31 \r
32 \r
33 \r
34 /**\r
35  * The lifecycle service.\r
36  * \r
37  * @author 10189609\r
38  * \r
39  */\r
40 public class LifeCycleServiceConsumer {\r
41   private static final Logger LOG = LoggerFactory.getLogger(LifeCycleServiceConsumer.class);\r
42 \r
43   /**\r
44    * get lifecycle application instances.\r
45    * \r
46    * @return instance entity\r
47    */\r
48   public static ArrayList<InstanceEntity> getInstances() {\r
49     ILifeCycleServiceRest resourceserviceproxy =\r
50         ConsumerFactory.createConsumer(MsbUtil.getNsocLifecycleBaseUrl(),\r
51             ILifeCycleServiceRest.class);\r
52     String result = "";\r
53     try {\r
54       result = resourceserviceproxy.getVnfInstances();\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       return null;\r
61     }\r
62 \r
63     Gson gson = new Gson();\r
64     Type listType = new TypeToken<ArrayList<InstanceEntity>>() {}.getType();\r
65     return gson.fromJson(result, listType);\r
66   }\r
67 }\r