Create seed code of svnfm vnfmdriver
[vfc/nfvo/driver/vnfm/svnfm.git] / nokia / vnfmdriver / vfcadaptorservice / vfcadaptor / src / main / java / com / nokia / vfcadaptor / catalog / impl / CatalogMgmrImpl.java
1 /*
2  * Copyright 2016-2017, Nokia 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
17 package com.nokia.vfcadaptor.catalog.impl;
18
19 import java.io.IOException;
20
21 import org.apache.http.client.ClientProtocolException;
22 import org.apache.http.impl.client.HttpClientBuilder;
23 import org.apache.log4j.Logger;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.stereotype.Component;
26 import org.springframework.web.bind.annotation.RequestMethod;
27
28 import com.google.gson.Gson;
29 import com.nokia.vfcadaptor.catalog.bo.CatalogQueryVnfResponse;
30 import com.nokia.vfcadaptor.catalog.inf.CatalogMgmrInf;
31 import com.nokia.vfcadaptor.common.bo.AdaptorEnv;
32 import com.nokia.vfcadaptor.constant.CommonConstants;
33 import com.nokia.vfcadaptor.http.client.HttpRequestProcessor;
34 import com.nokia.vfcadaptor.nslcm.bo.entity.VnfPackageInfo;
35
36 @Component
37 public class CatalogMgmrImpl implements CatalogMgmrInf{
38         private Logger logger = Logger.getLogger(CatalogMgmrImpl.class);
39         
40         private Gson gson = new Gson();
41         
42         @Autowired 
43         private AdaptorEnv adaptorEnv;
44         
45         @Autowired
46         private HttpClientBuilder httpClientBuilder;
47         
48         public VnfPackageInfo queryVnfPackage(String vnfPackageId) throws ClientProtocolException, IOException {
49                 String url="http://" + adaptorEnv.getCatalogIp() + ":" + adaptorEnv.getCatalogPort() + String.format(CommonConstants.RetrieveVnfPackagePath, vnfPackageId);
50                 HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
51                 
52                 String responseStr = processor.process(url);
53                 
54                 logger.info("CbamMgmrImpl -> queryVnfPackage, responseStr is " + responseStr);
55                 
56                 CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
57                 
58                 return resp.getPackageInfo();
59         }
60
61         
62 }