diff options
14 files changed, 153 insertions, 163 deletions
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoa.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoa.java index 6ed28a81..ad963e75 100644 --- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoa.java +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoa.java @@ -36,7 +36,6 @@ import org.apache.commons.lang3.StringUtils; import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.ResultRequestUtil; import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmJsonUtil; import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmUtil; -import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.ServiceException; import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant; import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.VnfMgr; import org.slf4j.Logger; @@ -103,13 +102,11 @@ public class VnfRoa { * { * "jobId":"1" * } - * @throws ServiceException */ @POST @Path("/{vnfmId}/vnfs/{vnfInstanceId}/scale") public String scaleVnf(@Context HttpServletRequest context, @Context HttpServletResponse resp, - @PathParam("vnfmId") String vnfmId, @PathParam("vnfInstanceId") String vnfInstanceId) - throws ServiceException { + @PathParam("vnfmId") String vnfmId, @PathParam("vnfInstanceId") String vnfInstanceId) { JSONObject jsonObject = VnfmJsonUtil.getJsonFromContexts(context); LOG.info("function=scaleVNF, msg=enter to scale a vnf. request body:" + jsonObject); JSONObject result = new JSONObject(); @@ -139,13 +136,12 @@ public class VnfRoa { * @param resp * @param vnfmId * @return - * @throws ServiceException * @since VFC 1.0 */ @POST @Path("/{vnfmId}/vnfs") public String addVnf(@Context HttpServletRequest context, @Context HttpServletResponse resp, - @PathParam("vnfmId") String vnfmId) throws ServiceException { + @PathParam("vnfmId") String vnfmId) { LOG.warn("function=addVnf, msg=enter to add a vnf"); JSONObject subJsonObject = VnfmJsonUtil.getJsonFromContexts(context); JSONObject restJson = new JSONObject(); @@ -176,14 +172,12 @@ public class VnfRoa { * @param vnfInstanceId * @param context * @return - * @throws ServiceException * @since VFC 1.0 */ @POST @Path("/{vnfmId}/vnfs/{vnfInstanceId}/terminate") public String delVnf(@PathParam("vnfmId") String vnfmId, @Context HttpServletResponse resp, - @PathParam("vnfInstanceId") String vnfInstanceId, @Context HttpServletRequest context) - throws ServiceException { + @PathParam("vnfInstanceId") String vnfInstanceId, @Context HttpServletRequest context) { LOG.warn("function=delVnf, msg=enter to delete a vnf: vnfInstanceId: {}, vnfmId: {}", vnfInstanceId, vnfmId); JSONObject vnfObject = VnfmJsonUtil.getJsonFromContexts(context); JSONObject restJson = new JSONObject(); @@ -212,13 +206,12 @@ public class VnfRoa { * @param vnfInstanceId * @param context * @return - * @throws ServiceException * @since VFC 1.0 */ @GET @Path("/{vnfmId}/vnfs/{vnfInstanceId}") public String getVnf(@PathParam("vnfmId") String vnfmId, @Context HttpServletResponse resp, - @PathParam("vnfInstanceId") String vnfInstanceId) throws ServiceException { + @PathParam("vnfInstanceId") String vnfInstanceId) { LOG.warn("function=getVnf, msg=enter to get a vnf: vnfInstanceId: {}, vnfmId: {}", vnfInstanceId, vnfmId); JSONObject restJson = new JSONObject(); @@ -244,13 +237,11 @@ public class VnfRoa { * @param vnfmId * @param resp * @return - * @throws ServiceException * @since VFC 1.0 */ @GET @Path("/{vnfmId}") - public String getVnfmById(@PathParam("vnfmId") String vnfmId, @Context HttpServletResponse resp) - throws ServiceException { + public String getVnfmById(@PathParam("vnfmId") String vnfmId, @Context HttpServletResponse resp) { LOG.warn("function=getVnfmById, vnfmId: {}", vnfmId); return VnfmUtil.getVnfmById(vnfmId).toString(); } @@ -264,13 +255,12 @@ public class VnfRoa { * @param resp * @param responseId * @return - * @throws ServiceException * @since VFC 1.0 */ @GET @Path("/{vnfmId}/jobs/{jobId}") public String getJob(@PathParam("jobId") String jobId, @PathParam("vnfmId") String vnfmId, - @Context HttpServletResponse resp, @QueryParam("@responseId") String responseId) throws ServiceException { + @Context HttpServletResponse resp, @QueryParam("@responseId") String responseId) { LOG.warn("function=getJob, msg=enter to get a job: jobId: {}, responseId: {}", jobId, responseId); JSONObject restJson = new JSONObject(); @@ -291,28 +281,26 @@ public class VnfRoa { /** * <br> - * + * * @param context * { - * �action�: �vmReset�, - * �affectedvm�: { - * �vmid�: �804cca71 - 9ae9 - 4511 - 8e30 - d1387718caff�, - * �vduid�: �vdu_100�, - * �vmname�: �ZTE_SSS_111_PP_2_L� + * "action": "vmReset", + * "affectedvm": { + * "vmid": "804cca71 - 9ae9 - 4511 - 8e30 - d1387718caff", + * "vduid": "vdu_100", + * "vmname": "ZTE_SSS_111_PP_2_L" * } * } * @param resp * @param vnfmId * @param vnfInstanceId * @return - * @throws ServiceException * @since VFC 1.0 */ @POST @Path("/{vnfmId}/vnfs/{vnfInstanceId}/heal") public String healVnf(@Context HttpServletRequest context, @Context HttpServletResponse resp, - @PathParam("vnfmId") String vnfmId, @PathParam("vnfInstanceId") String vnfInstanceId) - throws ServiceException { + @PathParam("vnfmId") String vnfmId, @PathParam("vnfInstanceId") String vnfInstanceId) { LOG.warn("function=healVnf, msg=enter to heal a vnf: vnfInstanceId: {}, vnfmId: {}", vnfInstanceId, vnfmId); JSONObject restJson = new JSONObject(); JSONObject jsonObject = VnfmJsonUtil.getJsonFromContexts(context); @@ -356,10 +344,17 @@ public class VnfRoa { return jobInfoJson.toString(); } + /** + * <br> + * Query vms info from vnfm + * + * @param vnfmId + * @param resp + * @return + */ @GET @Path("/{vnfmId}/vms") - public String getVms(@PathParam("vnfmId") String vnfmId, @Context HttpServletResponse resp) - throws ServiceException { + public String getVms(@PathParam("vnfmId") String vnfmId, @Context HttpServletResponse resp) { LOG.info("function=getVms, msg=enter to get vms: vnfmId: {}", vnfmId); JSONObject restJson = new JSONObject(); JSONObject vnfmObjcet = VnfmUtil.getVnfmById(vnfmId); @@ -382,11 +377,10 @@ public class VnfRoa { * @param vnfmId * @param responseId * @return - * @throws ServiceException * @since VFC 1.0 */ public String getJobFromVnfm(@PathParam("jobId") String jobId, @PathParam("vnfmId") String vnfmId, - @Context HttpServletResponse resp, @QueryParam("@responseId") String responseId) throws ServiceException { + @Context HttpServletResponse resp, @QueryParam("@responseId") String responseId) { LOG.warn("function=getJobFromVnfm, msg=enter to get a job: jobId: {}, responseId: {}", jobId, responseId); JSONObject restJson = vnfMgr.getJobFromVnfm(jobId, vnfmId); diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/log4j.properties b/huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/log4j.properties index 833c7a77..195e9410 100644 --- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/log4j.properties +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/resources/log4j.properties @@ -15,7 +15,13 @@ ############################################################################### log4j.rootLogger=INFO,root log4j.appender.root.Append=true -log4j.appender.root.File=${catalina.base}/logs/vnfmadapterservice.log + +#Log Directory +logDir=/var/log/onap +componentName=svnfmdriver +subComponentName=huaweivnfmdriver +log4j.appender.root.File=${logDir}/${componentName}/${subComponentName}/vnfmadapterservice.log + log4j.appender.root.layout.ConversionPattern=%d %-5p [%t][%X{moduleID}][%C %L] %m%n log4j.appender.root.layout=org.apache.log4j.PatternLayout log4j.appender.root.MaxBackupIndex=50 diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Cbam2DriverResponseConverter.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Cbam2DriverResponseConverter.java index c153095b..6034b55b 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Cbam2DriverResponseConverter.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Cbam2DriverResponseConverter.java @@ -155,11 +155,11 @@ public class Cbam2DriverResponseConverter { if (OperationType.INSTANTIATE == oper.getOperationType()) { double instantiateProgress = (nowTime - jobInfo.getOperateStartTime()) - / adaptorEnv.getInstantiateTimeInterval(); + / (double)(adaptorEnv.getInstantiateTimeInterval()); initialProgress = (int) (instantiateProgress + initialProgress); } else if (OperationType.TERMINATE == oper.getOperationType()) { double terminateProgress = (nowTime - jobInfo.getOperateStartTime()) - / adaptorEnv.getTerminateTimeInterval(); + / (double)(adaptorEnv.getTerminateTimeInterval()); initialProgress = (int) (terminateProgress + initialProgress); } else { initialProgress = 0; diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Driver2CbamRequestConverter.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Driver2CbamRequestConverter.java index 493033c9..8c60cc67 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Driver2CbamRequestConverter.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Driver2CbamRequestConverter.java @@ -54,11 +54,11 @@ public class Driver2CbamRequestConverter { } public CBAMInstantiateVnfRequest instantiateRequestConvert(InstantiateVnfRequest driverRequest, - NslcmGrantVnfResponse nslc, GrantInfo grant, VimComputeResourceFlavour vimco) throws Exception { - Gson gson = new Gson(); + NslcmGrantVnfResponse nslc, GrantInfo grant, VimComputeResourceFlavour vimco) throws IOException{ + Gson gson = new Gson(); String inputJson = readcbamInputInfoFromJsonFile(); CBAMInstantiateVnfRequest request = gson.fromJson(inputJson, CBAMInstantiateVnfRequest.class); - + return request; } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/OpenstackV2Info.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/OpenstackV2Info.java index 3ffa0fb0..1f1eb1ca 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/OpenstackV2Info.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/OpenstackV2Info.java @@ -14,10 +14,10 @@ * limitations under the License. */ package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity; - +import java.io.Serializable; import com.fasterxml.jackson.annotation.JsonProperty; -public class OpenstackV2Info { +public class OpenstackV2Info implements Serializable { @JsonProperty("vimInfoType") private VimInfoType vimInfoType; @@ -52,7 +52,4 @@ public class OpenstackV2Info { this.accessInfo = accessInfo; } - - - } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/OpenstackV3Info.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/OpenstackV3Info.java index 22de770e..7d4c53e6 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/OpenstackV3Info.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/OpenstackV3Info.java @@ -16,8 +16,9 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; -public class OpenstackV3Info { +public class OpenstackV3Info implements Serializable { @JsonProperty("vimInfoType") private VimInfoType vimInfoType; @@ -52,6 +53,4 @@ public class OpenstackV3Info { this.accessInfo = accessInfo; } - - } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/OtherVimInfo.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/OtherVimInfo.java index 4b7fb072..1cedf98b 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/OtherVimInfo.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/OtherVimInfo.java @@ -15,9 +15,10 @@ */ package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity; +import java.io.Serializable; import com.fasterxml.jackson.annotation.JsonProperty; -public class OtherVimInfo { +public class OtherVimInfo implements Serializable { @JsonProperty("vimInfoType") private VimInfoType vimInfoType; @@ -40,6 +41,4 @@ public class OtherVimInfo { this.id = id; } - - } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/VimInfoType.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/VimInfoType.java index 779e2659..5be96a88 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/VimInfoType.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/VimInfoType.java @@ -14,28 +14,22 @@ * limitations under the License. */ package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity; +import java.io.Serializable; -public enum VimInfoType { - - OPENSTACK_V2_INFO { +public enum VimInfoType implements Serializable{ + + OPENSTACK_V2_INFO { private OpenstackV2Info openstackv2; - - }, - OPENSTACK_V3_INFO{ - private OpenstackV3Info openstackv3; - }, - VMWARE_VCLOUD_INFO{ - private VmwareVcloudInfo vmwareInfo; - }, - OTHER_VIM_INFO{ - private OtherVimInfo other; - } - - - - - - - + + }, + OPENSTACK_V3_INFO{ + private OpenstackV3Info openstackv3; + }, + VMWARE_VCLOUD_INFO{ + private VmwareVcloudInfo vmwareInfo; + }, + OTHER_VIM_INFO{ + private OtherVimInfo other; + } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/VmwareVcloudInfo.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/VmwareVcloudInfo.java index 746cb007..73446461 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/VmwareVcloudInfo.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/entity/VmwareVcloudInfo.java @@ -15,9 +15,10 @@ */ package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity; +import java.io.Serializable; import com.fasterxml.jackson.annotation.JsonProperty; -public class VmwareVcloudInfo { +public class VmwareVcloudInfo implements Serializable{ @JsonProperty("vimInfoType") private VimInfoType vimInfoType; diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/MultipartUtility.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/MultipartUtility.java index f8f0c400..834c2a7b 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/MultipartUtility.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/MultipartUtility.java @@ -32,6 +32,8 @@ import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.List; +import java.security.NoSuchAlgorithmException; +import java.security.KeyManagementException; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; @@ -74,7 +76,7 @@ public class MultipartUtility { * @throws IOException */ public MultipartUtility(String requestURL, String charset) - throws Exception { + throws CertificateException, IOException, NoSuchAlgorithmException, KeyManagementException{ this.charset = charset; // creates a unique boundary based on time stamp @@ -165,10 +167,10 @@ public class MultipartUtility { KEY_STORE_TYPE = sslConf.getKeyStoreType(); } // load jks file - FileInputStream f_certStore = new FileInputStream(CommonUtil.getAppRoot() + CERT_STORE); - KeyStore ks = KeyStore.getInstance(KEY_STORE_TYPE); - ks.load(f_certStore, CERT_STORE_PASSWORD.toCharArray()); - f_certStore.close(); + try(FileInputStream f_certStore = new FileInputStream(CommonUtil.getAppRoot() + CERT_STORE)){ + KeyStore ks = KeyStore.getInstance(KEY_STORE_TYPE); + ks.load(f_certStore, CERT_STORE_PASSWORD.toCharArray()); + // init and create String alg = KeyManagerFactory.getDefaultAlgorithm(); @@ -176,6 +178,7 @@ public class MultipartUtility { kmFact.init(ks, CERT_STORE_PASSWORD.toCharArray()); kms = kmFact.getKeyManagers(); + } } catch(Exception e) { logger.error("create KeyManager fail!", e); } @@ -196,15 +199,16 @@ public class MultipartUtility { } String jksFilePath1 =CommonUtil.getAppRoot() + TRUST_STORE; logger.info("jks path is " + jksFilePath1); - FileInputStream f_trustStore = new FileInputStream(jksFilePath1); - KeyStore ks = KeyStore.getInstance(TRUST_STORE_TYPE); - ks.load(f_trustStore, TRUST_STORE_PASSWORD.toCharArray()); - f_trustStore.close(); + try(FileInputStream f_trustStore = new FileInputStream(jksFilePath1)){ + KeyStore ks = KeyStore.getInstance(TRUST_STORE_TYPE); + ks.load(f_trustStore, TRUST_STORE_PASSWORD.toCharArray()); + String alg = TrustManagerFactory.getDefaultAlgorithm(); TrustManagerFactory tmFact = TrustManagerFactory.getInstance(alg); tmFact.init(ks); tms = tmFact.getTrustManagers(); + } } catch(Exception e) { logger.error("create TrustManager fail!", e); @@ -235,14 +239,14 @@ public class MultipartUtility { writer.append(LINE_FEED); writer.flush(); - FileInputStream inputStream = new FileInputStream(uploadFile); - byte[] buffer = new byte[4096]; - int bytesRead = -1; - while ((bytesRead = inputStream.read(buffer)) != -1) { - outputStream.write(buffer, 0, bytesRead); - } - outputStream.flush(); - inputStream.close(); + try(FileInputStream inputStream = new FileInputStream(uploadFile)){ + byte[] buffer = new byte[4096]; + int bytesRead = -1; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + outputStream.flush(); + } writer.append(LINE_FEED); writer.flush(); @@ -289,4 +293,4 @@ public class MultipartUtility { return response; } -}
\ No newline at end of file +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/common/util/CommonUtil.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/common/util/CommonUtil.java index 47bb55f1..9ae3c940 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/common/util/CommonUtil.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/common/util/CommonUtil.java @@ -38,13 +38,10 @@ public final class CommonUtil { } public static String getJsonStrFromFilePath(String fileName) throws IOException { - InputStream ins = null; - BufferedInputStream bins = null; String fileContent = ""; - 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); @@ -54,14 +51,7 @@ public final class CommonUtil { } } catch(FileNotFoundException e) { logger.error(fileName + " is not found!", e); - } finally { - if(ins != null) { - ins.close(); - } - if(bins != null) { - bins.close(); - } - } + } return fileContent; } @@ -87,25 +77,22 @@ public final class CommonUtil { } public static byte[] getBytes(String filePath){ - byte[] buffer = null; - try { - File file = new File(filePath); - FileInputStream fis = new FileInputStream(file); - ByteArrayOutputStream bos = new ByteArrayOutputStream(1000); - byte[] b = new byte[1000]; - int n; - while ((n = fis.read(b)) != -1) { - bos.write(b, 0, n); - } - fis.close(); - bos.close(); - buffer = bos.toByteArray(); - } catch (FileNotFoundException e) { - logger.error("file " + filePath + " is not found.", e); - } catch (IOException e) { - logger.error("file " + filePath + " IOException.", e); - } - return buffer; + byte[] buffer = null; + File file = new File(filePath); + try(FileInputStream fis = new FileInputStream(file); + ByteArrayOutputStream bos = new ByteArrayOutputStream(1000)){ + byte[] b = new byte[1000]; + int n; + while ((n = fis.read(b)) != -1) { + bos.write(b, 0, n); + } + buffer = bos.toByteArray(); + } catch (FileNotFoundException e) { + logger.error("file " + filePath + " is not found.", e); + } catch (IOException e) { + logger.error("file " + filePath + " IOException.", e); + } + return buffer; } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorImpl.java index 489ab927..7878a00c 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorImpl.java @@ -40,17 +40,22 @@ public class HttpClientProcessorImpl implements HttpClientProcessorInf{ @Autowired private HttpClientBuilder httpClientBuilder; - public HttpResult process(String url, RequestMethod methodType, HashMap<String, String> headerMap, String bodyString) throws ClientProtocolException, IOException + public HttpResult process(String url, RequestMethod methodType, HashMap<String, String> headerMap, String bodyString) throws IOException { HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, methodType); + //Map<String, String> headerMap = new HashMap<String, String>(); if(headerMap != null && !headerMap.isEmpty()) { - for(String key : headerMap.keySet()) + /*for(String key : headerMap.keySet()) { processor.addHdeader(key, headerMap.get(key)); + }*/ + + for (HashMap.Entry<String, String> entry : headerMap.entrySet()) { + processor.addHeader(entry.getKey(), entry.getValue()); } - if(null != bodyString && bodyString.length() > 0 && !bodyString.equalsIgnoreCase("null")) + if(bodyString.length() > 0 && !"null".equalsIgnoreCase(bodyString)) { processor.addPostEntity(bodyString); } @@ -59,15 +64,19 @@ public class HttpClientProcessorImpl implements HttpClientProcessorInf{ return processor.process(url); } - public HttpResult processBytes(String url, RequestMethod methodType, HashMap<String, String> headerMap, byte[] byteArray) throws ClientProtocolException, IOException + public HttpResult processBytes(String url, RequestMethod methodType, HashMap<String, String> headerMap, byte[] byteArray) throws IOException { HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, methodType); if(headerMap != null && !headerMap.isEmpty()) { - for(String key : headerMap.keySet()) + for (HashMap.Entry<String, String> entry : headerMap.entrySet()) { + processor.addHeader(entry.getKey(), entry.getValue()); + } //Iterate over the "entrySet" instead of the "keySet" + + /*for(String key : headerMap.keySet()) { - processor.addHdeader(key, headerMap.get(key)); - } + processor.addHeader(key, headerMap.get(key)); + }*/ if(null != byteArray && byteArray.length > 0) { @@ -96,12 +105,11 @@ public class HttpClientProcessorImpl implements HttpClientProcessorInf{ if(!saveDir.exists()){ saveDir.mkdir(); } - File file = new File(saveDir+File.separator+fileName); - FileOutputStream fos = new FileOutputStream(file); - fos.write(getData); - if(fos!=null){ - fos.close(); - } + File file = new File(saveDir+File.separator+fileName); + try(FileOutputStream fos = new FileOutputStream(file)){ + fos.write(getData); + } + if(inputStream!=null){ inputStream.close(); } @@ -119,11 +127,11 @@ public class HttpClientProcessorImpl implements HttpClientProcessorInf{ public static byte[] readInputStream(InputStream inputStream) throws IOException { byte[] buffer = new byte[1024]; int len = 0; - ByteArrayOutputStream bos = new ByteArrayOutputStream(); + try(ByteArrayOutputStream bos = new ByteArrayOutputStream()){ while((len = inputStream.read(buffer)) != -1) { bos.write(buffer, 0, len); } - bos.close(); return bos.toByteArray(); + } } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpRequestProcessor.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpRequestProcessor.java index 0d472fcb..6c6f27fa 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpRequestProcessor.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpRequestProcessor.java @@ -75,7 +75,7 @@ public class HttpRequestProcessor { return httpResult; } - public void addHdeader(String key, String value) { + public void addHeader(String key, String value) { httpRequest.setHeader(key, value); } 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 74fb4395..cd4c7e31 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 @@ -115,42 +115,43 @@ public class MsbMgmrImpl implements IMsbMgmr { } - 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); - 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); + public String getServiceUrlInMsbBySeriveNameAndVersion(String serviceName, String version) throws IOException { + try{ + 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); + 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); + } + else{ + serviceUrl = serviceInfo.getUrl(); + logger.info("Service Url in MSB for serviceName = {} and version = {} is {}", serviceName, version, serviceUrl); + } } - - serviceUrl = serviceInfo.getUrl(); - logger.info("Service Url in MSB for serviceName = {} and version = {} is {}", serviceName, version, serviceUrl); - } - else - { - logger.error("MsbMgmrImpl -> getServiceUrlInMsbBySeriveNameAndVersion Error, statusCode = " + httpResult.getStatusCode()); - } + else + { + logger.error("MsbMgmrImpl -> getServiceUrlInMsbBySeriveNameAndVersion Error, statusCode = " + httpResult.getStatusCode()); + } + + return serviceUrl; + }catch(Exception e){ + logger.error("MsbMgmrImpl -> getServiceUrlInMsbBySeriveNameAndVersion Error", e); + throw new IOException("getServiceUrlInMsbBySeriveNameAndVersion", e); - return serviceUrl; + } + } public void setAdaptorEnv(AdaptorEnv env) { this.adaptorEnv = env; } -// public static final void main(String[] args) { -//// MsbMgmrImpl impl = new MsbMgmrImpl(); -//// impl.register(); -// System.setProperty("catalina.base", "D:\\Install\\apache-tomcat-9.0.0.M26"); -// System.out.println(System.getProperty("catalina.base")); -// } - } |