From e4eb41ab8cc133fa34610815442784cd17e51aaa Mon Sep 17 00:00:00 2001 From: ajay priyadarshi Date: Thu, 29 Mar 2018 11:22:53 +0530 Subject: spurious wakeup & Bug fixes common/util/restclient/HttpsRest.java file name: MultivimProxyAdapterMgrService.java Change-Id: Id4b3856f846d449eefae6fae3e841c6cbdfa8554 Issue-ID: VFC-860 Signed-off-by: ajay priyadarshi --- .../common/util/restclient/HttpsRest.java | 26 ++++++++-------- .../impl/MultivimProxyAdapterMgrService.java | 35 ++++++++-------------- 2 files changed, 25 insertions(+), 36 deletions(-) (limited to 'service/src') diff --git a/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/common/util/restclient/HttpsRest.java b/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/common/util/restclient/HttpsRest.java index 7190c56..fa006c1 100644 --- a/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/common/util/restclient/HttpsRest.java +++ b/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/common/util/restclient/HttpsRest.java @@ -43,7 +43,7 @@ public class HttpsRest extends HttpBaseRest { try { client.start(); } catch(Exception e) { - e.printStackTrace(); + LOG.error("Exception: ",e); } } @@ -167,7 +167,7 @@ public class HttpsRest extends HttpBaseRest { try { client.send(exchange); } catch(IOException e) { - e.printStackTrace(); + LOG.error("IOException: ",e); } try { int exchangeState = exchange.waitForDone(); @@ -186,10 +186,10 @@ public class HttpsRest extends HttpBaseRest { throw new ServiceException( "request is expierd: " + RestHttpContentExchange.toState(HttpExchange.STATUS_EXPIRED)); } - } catch(InterruptedException e) { - e.printStackTrace(); } catch(UnsupportedEncodingException e) { - e.printStackTrace(); + LOG.error("UnsupportedEncodingException: ",e); + } catch(Exception e) {//if not specific handling, no use of InterruptedException + LOG.error("InterruptedException: ",e); } return null; } @@ -208,7 +208,7 @@ public class HttpsRest extends HttpBaseRest { try { client.send(exchange); } catch(IOException e) { - e.printStackTrace(); + LOG.error("IOException: ",e); } try { @@ -228,10 +228,10 @@ public class HttpsRest extends HttpBaseRest { throw new ServiceException( "request is expierd: " + RestHttpContentExchange.toState(HttpExchange.STATUS_EXPIRED)); } - } catch(InterruptedException e) { - e.printStackTrace(); } catch(UnsupportedEncodingException e) { - e.printStackTrace(); + LOG.error("UnsupportedEncodingException: ",e); + } catch(Exception e) { + LOG.error("Exception: ",e); } return null; } @@ -258,7 +258,7 @@ public class HttpsRest extends HttpBaseRest { try { client.send(exchange); } catch(IOException e) { - e.printStackTrace(); + LOG.error("IOException: ",e); } try { @@ -278,10 +278,10 @@ public class HttpsRest extends HttpBaseRest { throw new ServiceException( "request is expierd: " + RestHttpContentExchange.toState(HttpExchange.STATUS_EXPIRED)); } - } catch(InterruptedException e) { - e.printStackTrace(); } catch(UnsupportedEncodingException e) { - e.printStackTrace(); + LOG.error("UnsupportedEncodingException: ",e); + } catch(Exception e) { + LOG.error("Exception: ",e); } return null; } diff --git a/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/service/adapter/impl/MultivimProxyAdapterMgrService.java b/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/service/adapter/impl/MultivimProxyAdapterMgrService.java index bb4ec3a..57aafc2 100644 --- a/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/service/adapter/impl/MultivimProxyAdapterMgrService.java +++ b/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/service/adapter/impl/MultivimProxyAdapterMgrService.java @@ -83,17 +83,15 @@ public class MultivimProxyAdapterMgrService implements IMultivimProxyAdapterMgrS * @throws IOException */ public static String readVimAdapterInfoFromJson() throws IOException { - InputStream ins = null; - BufferedInputStream bins = null; String fileContent = ""; String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot() + System.getProperty("file.separator") + "etc" + System.getProperty("file.separator") + "adapterInfo" + System.getProperty("file.separator") + RESMGRADAPTERINFO; - try { - ins = new FileInputStream(fileName); - bins = new BufferedInputStream(ins); + try ( + InputStream ins = new FileInputStream(fileName); + BufferedInputStream bins = new BufferedInputStream(ins)){ byte[] contentByte = new byte[ins.available()]; int num = bins.read(contentByte); @@ -103,14 +101,7 @@ public class MultivimProxyAdapterMgrService implements IMultivimProxyAdapterMgrS } } catch(FileNotFoundException e) { LOG.error(fileName + "is not found!", e); - } finally { - if(ins != null) { - ins.close(); - } - if(bins != null) { - bins.close(); - } - } + } return fileContent; } @@ -145,13 +136,13 @@ public class MultivimProxyAdapterMgrService implements IMultivimProxyAdapterMgrS // catch Runtime Exception try { sendRequest(paramsMap, adapterInfo); - } catch(RuntimeException e) { + } catch(Exception e) { LOG.error(e.getMessage(), e); } } - private void sendRequest(Map paramsMap, JSONObject driverInfo) { + private void sendRequest(Map paramsMap, JSONObject driverInfo)throws InterruptedException { JSONObject resultObj = adapter2MSBMgr.registerProxy(paramsMap, driverInfo); if(Integer.valueOf(resultObj.get("retCode").toString()) == HttpConstant.HTTP_CREATED) { @@ -161,16 +152,14 @@ public class MultivimProxyAdapterMgrService implements IMultivimProxyAdapterMgrS + resultObj.get("reason").toString() + " retCode:" + resultObj.get("retCode").toString()); // if registration fails,wait one minute and try again - try { - synchronized(lockObject) { + synchronized(lockObject) { + while(Integer.valueOf(resultObj.get("retCode").toString()) != Constant.HTTP_CREATED){ lockObject.wait(Constant.REPEAT_REG_TIME); + resultObj = adapter2MSBMgr.registerProxy(this.paramsMap, this.adapterInfo); + } } - } catch(InterruptedException e) { - LOG.error(e.getMessage(), e); - } - - sendRequest(this.paramsMap, this.adapterInfo); - } + LOG.info("Resmgr has now Successfully Registered to the Microservice BUS!"); + } } -- cgit 1.2.3-korg