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