From c8ef1d3751ec0893a4e7a138b653693abf2045d1 Mon Sep 17 00:00:00 2001 From: yufei_zhou Date: Mon, 30 Oct 2017 11:10:58 +0800 Subject: Modify vnf package extract part Change-Id: I85f94687262107337dc4894d3e29ead4380e4aba Issue-ID: VFC-544 Signed-off-by: yufei_zhou --- .../vfcadaptorservice/docker/instance-init.sh | 2 +- .../svnfm/adaptor/Driver2CbamRequestConverter.java | 1 - .../adaptor/InstantiateVnfContinueRunnable.java | 23 +++++++++++++--------- .../driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java | 23 ++++++++++++++++++---- .../vnfm/svnfm/constant/CommonConstants.java | 2 +- .../svnfm/http/client/HttpClientProcessorImpl.java | 2 +- .../vnfm/svnfm/http/client/HttpClientUtils.java | 3 ++- .../svnfm/http/client/HttpRequestProcessor.java | 3 +-- 8 files changed, 39 insertions(+), 20 deletions(-) (limited to 'nokia/vnfmdriver') diff --git a/nokia/vnfmdriver/vfcadaptorservice/docker/instance-init.sh b/nokia/vnfmdriver/vfcadaptorservice/docker/instance-init.sh index da32e842..cfb9c16b 100755 --- a/nokia/vnfmdriver/vfcadaptorservice/docker/instance-init.sh +++ b/nokia/vnfmdriver/vfcadaptorservice/docker/instance-init.sh @@ -17,6 +17,6 @@ # Config mysql credentials # Initialize MySQL schema -/usr/bin/mysqld_safe & +# /usr/bin/mysqld_safe & cd bin ./init_db.sh root rootpass 127.0.0.1 3306 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 f351925b..2e05e1aa 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 @@ -35,7 +35,6 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.AccessInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.GrantInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.NslcmVimInfo; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.VimAssets; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.VimComputeResourceFlavour; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest; diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/InstantiateVnfContinueRunnable.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/InstantiateVnfContinueRunnable.java index e6e060c0..6fbb028a 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/InstantiateVnfContinueRunnable.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/InstantiateVnfContinueRunnable.java @@ -79,8 +79,6 @@ public class InstantiateVnfContinueRunnable implements Runnable { NslcmGrantVnfRequest grantRequest = buildNslcmGrantVnfRequest(); NslcmGrantVnfResponse grantResponse = nslcmMgmr.grantVnf(grantRequest); - handleNslcmGrantResponse(grantResponse); - //step 5: instantiate vnf CBAMInstantiateVnfRequest instantiateReq = requestConverter.InstantiateReqConvert(driverRequest, grantResponse, null, null); @@ -108,15 +106,15 @@ public class InstantiateVnfContinueRunnable implements Runnable { String packageUrl = vnfPackageInfo.getDownloadUri(); String saveDir = "/service/vnfPackage"; String packageFileName = packageUrl.substring(packageUrl.lastIndexOf("/")); - Process process = Runtime.getRuntime().exec("mkdir " + saveDir); + Process process = Runtime.getRuntime().exec("mkdir -p " + saveDir); process.waitFor(); if (HttpClientProcessorImpl.downLoadFromUrl(packageUrl, packageFileName, saveDir)) { + File csarFile = new File(saveDir + "/" + packageFileName); //extract package - ZipUtil.unpack(new File(saveDir + "/" + packageFileName), new File(saveDir)); - //upload package - String cbamPackageDirName = saveDir + "/" - + packageFileName.substring(0, packageFileName.length() - 4) + "/Artifacts"; + ZipUtil.explode(csarFile); + csarFile.delete(); + String cbamPackageDirName = saveDir + "/" + packageFileName + "/Artifacts"; String cbamPackageName = new File(cbamPackageDirName).list()[0]; cbamMgmr.uploadVnfPackage(cbamPackageName); } @@ -180,8 +178,15 @@ public class InstantiateVnfContinueRunnable implements Runnable { jobDbMgmr.save(jobInfo); } - private void handleNslcmGrantResponse(NslcmGrantVnfResponse grantResponse) { - // TODO Auto-generated method stub + public static void main(String[] argv) { + String saveDir = "D:/tmp/20170926/data"; + String packageFileName = "vCSCF_v3.0.csar"; + File csarFile = new File(saveDir + "/" + packageFileName); + ZipUtil.explode(csarFile); + csarFile.delete(); + String cbamPackageDirName = saveDir + "/" + packageFileName + "/Artifacts"; + String cbamPackageName = new File(cbamPackageDirName).list()[0]; + System.out.println(cbamPackageName); } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java index 6afa6c8d..dc6a6189 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java @@ -59,14 +59,17 @@ public class CbamMgmrImpl implements CbamMgmrInf { @Autowired HttpClientProcessorInf httpClientProcessor; - private String retrieveToken() throws ClientProtocolException, IOException, JSONException { + public String retrieveToken() throws ClientProtocolException, IOException, JSONException { String result = null; String url= adaptorEnv.getCbamApiUriFront() + CommonConstants.CbamRetrieveTokenPath; HashMap map = new HashMap<>(); map.put(CommonConstants.ACCEPT, "*/*"); map.put(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); - String bodyPostStr = String.format(CommonConstants.CbamRetrieveTokenPostStr, adaptorEnv.getGrantType(), adaptorEnv.getClientId(), adaptorEnv.getClientSecret(), adaptorEnv.getCbamUserName(), adaptorEnv.getCbamPassword()); + String bodyPostStr = String.format(CommonConstants.CbamRetrieveTokenPostStr, adaptorEnv.getClientId(), adaptorEnv.getClientSecret(), adaptorEnv.getCbamUserName(), adaptorEnv.getCbamPassword()); + + logger.debug("CbamMgmrImpl -> retrieveToken, url is " + url); + logger.debug("CbamMgmrImpl -> retrieveToken, bodyPostStr is " + bodyPostStr); String responseStr = httpClientProcessor.process(url, RequestMethod.POST, map, bodyPostStr).getContent(); @@ -262,7 +265,7 @@ public class CbamMgmrImpl implements CbamMgmrInf { HttpResult httpResult = operateCbamHttpUploadTask(cbamPackageFilePath, httpPath, method); String responseStr = httpResult.getContent(); - logger.info("CbamMgmrImpl -> uploadVnfPackage, responseStr is " + responseStr); + logger.info("CbamMgmrImpl -> uploadVnfPackage, statusCode is " + httpResult.getStatusCode() + ", cause is " + httpResult.getStatusCause() + ". responseStr is " + responseStr); int code = httpResult.getStatusCode(); if(code == 200) { @@ -273,7 +276,7 @@ public class CbamMgmrImpl implements CbamMgmrInf { } } - private HttpResult operateCbamHttpUploadTask(String filePath, String httpPath, RequestMethod method) throws ClientProtocolException, IOException { + public HttpResult operateCbamHttpUploadTask(String filePath, String httpPath, RequestMethod method) throws ClientProtocolException, IOException { String token = null; try { token = retrieveToken(); @@ -287,6 +290,18 @@ public class CbamMgmrImpl implements CbamMgmrInf { map.put(CommonConstants.AUTHORIZATION, "bearer " + token); map.put(CommonConstants.CONTENT_TYPE, "multipart/form-data, boundary=--fsgdsfgjgjdsgdfjgjgj"); byte[] fileBytes = CommonUtil.getBytes(filePath); + logger.info("CbamMgmrImpl -> operateCbamHttpUploadTask, url is " + url); + logger.info("CbamMgmrImpl -> operateCbamHttpUploadTask, token is " + token); + logger.info("CbamMgmrImpl -> operateCbamHttpUploadTask, bodyPostStr byte lenth is " + fileBytes.length); + return httpClientProcessor.processBytes(url, method, map, fileBytes); } + + public HttpClientProcessorInf getHttpClientProcessor() { + return httpClientProcessor; + } + + public void setHttpClientProcessor(HttpClientProcessorInf httpClientProcessor) { + this.httpClientProcessor = httpClientProcessor; + } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/constant/CommonConstants.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/constant/CommonConstants.java index b1059118..a2be9f12 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/constant/CommonConstants.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/constant/CommonConstants.java @@ -53,7 +53,7 @@ public class CommonConstants { public static final String CbamScaleVnfPath = "/vnfs/%s/scale"; public static final String CbamHealVnfPath="/vnfs/%s/heal"; - public static final String CbamUploadVnfPackagePath="/api/catalog/vnfpackages"; + public static final String CbamUploadVnfPackagePath="/api/catalog/adapter/vnfpackages"; public static final String NSLCM_OPERATION_INSTANTIATE = "Instantiate"; 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 114dea63..489ab927 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 @@ -88,7 +88,7 @@ public class HttpClientProcessorImpl implements HttpClientProcessorInf{ { URL url = new URL(urlStr); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); - conn.setConnectTimeout(10*1000); + conn.setConnectTimeout(20*1000); conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); InputStream inputStream = conn.getInputStream(); byte[] getData = readInputStream(inputStream); diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientUtils.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientUtils.java index 7f6a0006..e5a77f7b 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientUtils.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientUtils.java @@ -72,10 +72,11 @@ public class HttpClientUtils { .register("https", sslSocketFactory) .build(); - PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager( socketFactoryRegistry); + PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry); connMgr.setMaxTotal(200); connMgr.setDefaultMaxPerRoute(50); httpClientBuilder.setConnectionManager(connMgr); + return httpClientBuilder; } 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 363b5a92..8963dd49 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 @@ -24,8 +24,8 @@ import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpRequestBase; -import org.apache.http.entity.StringEntity; import org.apache.http.entity.ByteArrayEntity; +import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; @@ -47,7 +47,6 @@ public class HttpRequestProcessor { httpRequest.setURI(URI.create(url)); HttpResponse response = httpClient.execute(httpRequest); - HttpResult httpResult = buildHttpResult(response); return httpResult; -- cgit 1.2.3-korg