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