f3bed0a0bc813396f7bd96dc031d328175fa8ac8
[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.lifecycle;\r
17 \r
18 import java.lang.reflect.Type;\r
19 import java.util.ArrayList;\r
20 \r
21 import org.openo.commontosca.catalog.common.MSBUtil;\r
22 import org.openo.commontosca.catalog.common.ToolUtil;\r
23 import org.openo.commontosca.catalog.model.externalservice.entity.lifecycleEnity.InstanceEntity;\r
24 import org.slf4j.Logger;\r
25 import org.slf4j.LoggerFactory;\r
26 \r
27 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;\r
28 import com.google.gson.Gson;\r
29 import com.google.gson.reflect.TypeToken;\r
30 \r
31 /**\r
32  * The lifecycle service.\r
33  * @author 10189609\r
34  *\r
35  */\r
36 public class LifeCycleServiceConsumer {\r
37         private static final Logger LOG = LoggerFactory.getLogger(LifeCycleServiceConsumer.class);\r
38         \r
39         /**\r
40          * get lifecycle application instances.\r
41          * @return instance entity\r
42          */\r
43         public static ArrayList<InstanceEntity> getInstances() {\r
44                 ILifeCycleServiceRest resourceserviceproxy = ConsumerFactory\r
45                                 .createConsumer(MSBUtil.getNsocLifecycleBaseUrl(), ILifeCycleServiceRest.class);        \r
46                 String result = "";\r
47                 try {\r
48                         result = resourceserviceproxy.getVNFInstances();\r
49                 } catch (Exception e) {\r
50                         LOG.error("query vim info faild.", e);\r
51                         return null;\r
52                 }\r
53                 if (ToolUtil.isEmptyString(result)) {\r
54                         return null;\r
55                 }\r
56                 \r
57                 Gson gson = new Gson();\r
58                 Type listType = new TypeToken<ArrayList<InstanceEntity>>() {}.getType();\r
59                 return gson.fromJson(result, listType);\r
60         }\r
61 }\r