diff options
Diffstat (limited to 'nokia')
-rw-r--r-- | nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImpl.java | 107 |
1 files changed, 67 insertions, 40 deletions
diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImpl.java index f2b1a32e..78dcf413 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImpl.java @@ -16,7 +16,6 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.msb.impl; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; @@ -25,6 +24,7 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.util.CommonUtil; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants; import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpResult; import org.onap.vfc.nfvo.driver.vnfm.svnfm.msb.bo.MsbServiceInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.msb.inf.IMsbMgmr; import org.slf4j.Logger; @@ -39,80 +39,107 @@ import com.google.gson.Gson; @Component public class MsbMgmrImpl implements IMsbMgmr { private static final Logger logger = LoggerFactory.getLogger(MsbMgmrImpl.class); - + @Autowired AdaptorEnv adaptorEnv; - + @Autowired HttpClientProcessorInf httpClientProcessor; - + private Gson gson = new Gson(); - + @Override public void register() { - + try { String url = adaptorEnv.getMsbApiUriFront() + CommonConstants.MSB_REGISTER_SERVICE_PATH; HashMap<String, String> map = new HashMap<>(); map.put(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); - - String bodyPostStr = readVfcAdaptorInfoFromJsonFile();; - - String responseStr = httpClientProcessor.process(url, RequestMethod.POST, map, bodyPostStr).getContent(); - + + String bodyPostStr = readVfcAdaptorInfoFromJsonFile(); + + HttpResult httpResult = httpClientProcessor.process(url, RequestMethod.POST, map, bodyPostStr); + String responseStr = httpResult.getContent(); + logger.info("MsbMgmrImpl -> register, responseStr is " + responseStr); - } catch (IOException e) { + if(httpResult.getStatusCode() == 201) + { + logger.info("MsbMgmrImpl -> register, Successfully "); + } + else + { + logger.error("MsbMgmrImpl -> register Error, statusCode = " + httpResult.getStatusCode()); + } + + } catch (IOException e) { logger.error("IOException Failed to register nokia vnfm driver! ", e); - } - + } + } - + private String readVfcAdaptorInfoFromJsonFile() throws IOException { - String filePath = "/etc/adapterInfo/vnfmadapterinfo.json"; + String filePath = "/etc/adapterInfo/vnfmadapterinfo.json"; String fileContent = CommonUtil.getJsonStrFromFile(filePath); - return fileContent; - } + return fileContent; + } @Override public void unregister() { try { String url = adaptorEnv.getMsbApiUriFront() + String.format(CommonConstants.MSB_UNREGISTER_SERVICE_PATH); - - String responseStr = httpClientProcessor.process(url, RequestMethod.DELETE, null, null).getContent(); - + + HttpResult httpResult = httpClientProcessor.process(url, RequestMethod.DELETE, null, null); + String responseStr = httpResult.getContent(); + logger.info("MsbMgmrImpl -> unregister, responseStr is " + responseStr); - - } catch (Exception e) { + if(httpResult.getStatusCode() == 204) + { + logger.info("MsbMgmrImpl -> register, Successfully "); + } + else + { + logger.error("MsbMgmrImpl -> register Error, statusCode = " + httpResult.getStatusCode()); + } + + } catch (Exception e) { logger.error("IOException Failed to unregister nokia vnfm driver! ", e); } - + } - - public String getServiceUrlInMsbBySeriveNameAndVersion(String serviceName, String version) throws ClientProtocolException, IOException - { - String url=adaptorEnv.getMsbApiUriFront() + String.format(CommonConstants.MSB_QUERY_SERVICE_PATH, serviceName, version); - - String responseStr = httpClientProcessor.process(url, RequestMethod.GET, null, null).getContent(); + + public String getServiceUrlInMsbBySeriveNameAndVersion(String serviceName, String version) throws ClientProtocolException, IOException { + String url = adaptorEnv.getMsbApiUriFront() + String.format(CommonConstants.MSB_QUERY_SERVICE_PATH, serviceName, version); + + HttpResult httpResult = httpClientProcessor.process(url, RequestMethod.GET, null, null); + + String responseStr = httpResult.getContent(); logger.info("MsbMgmrImpl -> getServiceUrlInMsbBySeriveNameAndVersion, responseStr is " + responseStr); - - MsbServiceInfo serviceInfo = gson.fromJson(responseStr, MsbServiceInfo.class); - if(null == serviceInfo) + String serviceUrl = ""; + if(httpResult.getStatusCode() == 200) + { + MsbServiceInfo serviceInfo = gson.fromJson(responseStr, MsbServiceInfo.class); + if (null == serviceInfo) { + logger.error("There is no service in MSB for serviceName = {} and version = {}", serviceName, version); + } + + serviceUrl = serviceInfo.getUrl(); + logger.info("Service Url in MSB for serviceName = {} and version = {} is {}", serviceName, version, serviceUrl); + } + else { - logger.error("There is no service in MSB for serviceName = {} and version = {}", serviceName, version); + logger.error("MsbMgmrImpl -> getServiceUrlInMsbBySeriveNameAndVersion Error, statusCode = " + httpResult.getStatusCode()); } - - String serviceUrl = serviceInfo.getUrl(); - logger.info("Service Url in MSB for serviceName = {} and version = {} is {}", serviceName, version, serviceUrl); - + + return serviceUrl; - } + } public void setAdaptorEnv(AdaptorEnv env) { this.adaptorEnv = env; } - + public static final void main(String[] args) { MsbMgmrImpl impl = new MsbMgmrImpl(); impl.register(); |