diff options
Diffstat (limited to 'ResmanagementService/service/src')
6 files changed, 72 insertions, 52 deletions
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/ExceptionArgs.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/ExceptionArgs.java index 89b1b0a..46c3d84 100644 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/ExceptionArgs.java +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/ExceptionArgs.java @@ -16,16 +16,23 @@ package org.onap.vfc.nfvo.resmanagement.common.util.restclient; +import java.io.Serializable; + /** * ROA exception handling parameters. * <br/> * <p> * </p> - * + * * @author * @version 28-May-2016 */ -public class ExceptionArgs { +public class ExceptionArgs implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -6567319637044813966L; /** * Exception descriptions. @@ -51,7 +58,7 @@ public class ExceptionArgs { * Constructor<br/> * <p> * </p> - * + * * @since */ public ExceptionArgs() { @@ -62,7 +69,7 @@ public class ExceptionArgs { * Constructor<br/> * <p> * </p> - * + * * @since * @param descArgs: descriptions. * @param reasonArgs: reasons. diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/HttpBaseRest.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/HttpBaseRest.java index 9cc832f..c962bdc 100644 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/HttpBaseRest.java +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/HttpBaseRest.java @@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory; * <br/> * <p> * </p> - * + * * @author * @version Aug 9, 2016 */ @@ -49,7 +49,7 @@ public abstract class HttpBaseRest implements Restful { protected HttpClient client = null; - private static final String LOCAL_HOST = "127.0.0.1"; + private static final String LOCAL_HOST = "127.0.0.1"; // NOSONAR static final String HTTP_PATCH = "PATCH"; @@ -65,7 +65,7 @@ public abstract class HttpBaseRest implements Restful { * Constructor<br/> * <p> * </p> - * + * * @since */ public HttpBaseRest() { @@ -135,7 +135,7 @@ public abstract class HttpBaseRest implements Restful { /** * <br/> - * + * * @param method * @param servicePath * @param restParametes diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/HttpsRest.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/HttpsRest.java index e8fa42a..4d1ff69 100644 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/HttpsRest.java +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/HttpsRest.java @@ -188,6 +188,8 @@ public class HttpsRest extends HttpBaseRest { } } catch(InterruptedException e) { LOG.error("InterruptedException", e); + // Restore interrupted state... + Thread.currentThread().interrupt(); } catch(UnsupportedEncodingException e) { LOG.error("UnsupportedEncodingException", e); } @@ -230,6 +232,8 @@ public class HttpsRest extends HttpBaseRest { } } catch(InterruptedException e) { LOG.error("InterruptedException", e); + // Restore interrupted state... + Thread.currentThread().interrupt(); } catch(UnsupportedEncodingException e) { LOG.error("UnsupportedEncodingException", e); } @@ -280,6 +284,8 @@ public class HttpsRest extends HttpBaseRest { } } catch(InterruptedException e) { LOG.error("InterruptedException", e); + // Restore interrupted state... + Thread.currentThread().interrupt(); } catch(UnsupportedEncodingException e) { LOG.error("InterruptedException", e); } diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/ServiceException.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/ServiceException.java index 0f6d843..b57c34d 100644 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/ServiceException.java +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/ServiceException.java @@ -22,7 +22,7 @@ import java.text.MessageFormat; * The base class for all common exception.<br/> * <p> * </p> - * + * * @author * @version 28-May-2016 */ @@ -43,7 +43,7 @@ public class ServiceException extends Exception { */ private String id = DEFAULT_ID; - private Object[] args = null; + private Object[] args = null; // NOSONAR private int httpCode = 500; @@ -54,7 +54,7 @@ public class ServiceException extends Exception { * <p> * This method is only used as deserialized, in other cases, use parameterized constructor. * </p> - * + * * @since */ public ServiceException() { @@ -65,7 +65,7 @@ public class ServiceException extends Exception { * Constructor<br/> * <p> * </p> - * + * * @since * @param id: details. * @param cause: reason. @@ -79,7 +79,7 @@ public class ServiceException extends Exception { * Constructor<br/> * <p> * </p> - * + * * @since * @param message: details. */ @@ -91,7 +91,7 @@ public class ServiceException extends Exception { * Constructor<br/> * <p> * </p> - * + * * @since * @param id: exception id. * @param message: details. @@ -105,7 +105,7 @@ public class ServiceException extends Exception { * Constructor<br/> * <p> * </p> - * + * * @since * @param id: exception id. * @param httpCode: http status code. @@ -121,7 +121,7 @@ public class ServiceException extends Exception { * <p> * the exception include the httpcode and message. * </p> - * + * * @since * @param httpCode http code. * @param message details. @@ -135,7 +135,7 @@ public class ServiceException extends Exception { * Constructor<br/> * <p> * </p> - * + * * @since * @param id: exception id. * @param httpCode: http code. @@ -153,7 +153,7 @@ public class ServiceException extends Exception { * <p> * Have a placeholder exception, use args formatted message. * </p> - * + * * @since * @param id: exception id. * @param message: details. @@ -170,7 +170,7 @@ public class ServiceException extends Exception { * <p> * Have a placeholder exception, use args formatted message * </p> - * + * * @since * @param id: exception id. * @param message: details. @@ -187,7 +187,7 @@ public class ServiceException extends Exception { * Constructor<br/> * <p> * </p> - * + * * @since * @param id: exception id. * @param message: details. @@ -202,7 +202,7 @@ public class ServiceException extends Exception { * Constructor<br/> * <p> * </p> - * + * * @since * @param cause: reason. */ @@ -212,7 +212,7 @@ public class ServiceException extends Exception { /** * Get exceptoin id.<br/> - * + * * @return * @since */ @@ -237,7 +237,7 @@ public class ServiceException extends Exception { /** * Obtain the ROA exception handling framework parameters<br/> - * + * * @return exception args. * @since */ @@ -251,7 +251,7 @@ public class ServiceException extends Exception { /** * Gets the parameter information<br/> - * + * * @return parameter list. * @since */ diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java index 2feaba3..606ce50 100644 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java @@ -41,7 +41,7 @@ import net.sf.json.JSONObject; * <br> * <p> * </p> - * + * * @author * @version VFC 1.0 Sep 22, 2016 */ @@ -77,47 +77,40 @@ public class ResmgrAdapterMgrService implements IResmgrAdapterMgrService { /** * Retrieve VIM driver information. - * + * * @return * @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); + return readJson(fileName); + } + + public static String readJson(String fileName) throws IOException { + String fileContent = ""; - byte[] contentByte = new byte[ins.available()]; - int num = bins.read(contentByte); + try (InputStream ins = new FileInputStream(fileName)){ + try(BufferedInputStream bins = new BufferedInputStream(ins)){ - if(num > 0) { - fileContent = new String(contentByte); + byte[] contentByte = new byte[ins.available()]; + int num = bins.read(contentByte); + + if(num > 0) { + fileContent = new String(contentByte); + } } } catch(FileNotFoundException e) { LOG.error(fileName + "is not found!", e); - } finally { - if(ins != null) { - ins.close(); - } - if(bins != null) { - bins.close(); - } } return fileContent; } - private static class RegisterResmgrThread implements Runnable { - // Thread lock Object - private final Object lockObject = new Object(); + private static class RegisterResmgrThread implements Runnable { private IResmgrAdapter2MSBManager adapter2MSBMgr = new ResmgrAdapter2MSBManager(); @@ -161,9 +154,7 @@ public class ResmgrAdapterMgrService implements IResmgrAdapterMgrService { // if registration fails,wait one minute and try again try { - synchronized(lockObject) { - lockObject.wait(Constant.REPEAT_REG_TIME); - } + Thread.sleep(Constant.REPEAT_REG_TIME); } catch(InterruptedException e) { LOG.error(e.getMessage(), e); // Restore interrupted state... diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.java index 3ddaf26..2c49ba3 100644 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.java +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.java @@ -16,11 +16,12 @@ package org.onap.vfc.nfvo.resmanagement.service.adapter.impl; +import java.io.File; import java.io.IOException; import org.junit.Test; -import org.onap.vfc.nfvo.resmanagement.service.adapter.impl.ResmgrAdapterMgrService; +import junit.framework.Assert; import mockit.Mock; import mockit.MockUp; @@ -28,7 +29,7 @@ import mockit.MockUp; * <br> * <p> * </p> - * + * * @author * @version VFC 1.0 Sep 24, 2016 */ @@ -66,4 +67,19 @@ public class ResmgrAdapterMgrServiceTest { ResmgrAdapterMgrService resmgrService = new ResmgrAdapterMgrService(); resmgrService.register(); } + + + @SuppressWarnings("deprecation") + @Test + public void testReadJson() { + File file = new File("./demo.json"); + try { + file.createNewFile(); + String content = ResmgrAdapterMgrService.readJson("./demo.json"); + Assert.assertEquals(content, ""); + file.delete(); + } catch (IOException e) { + e.printStackTrace(); + } + } } |