diff options
18 files changed, 278 insertions, 106 deletions
diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/pom.xml b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/pom.xml index b12c681e..0a159f91 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/pom.xml +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/pom.xml @@ -120,6 +120,24 @@ <artifactId>dropwizard-core</artifactId> <version>0.8.0</version> </dependency> + + <dependency> + <groupId>com.jcraft</groupId> + <artifactId>jsch</artifactId> + <version>0.1.54</version> + </dependency> + + <dependency> + <groupId>commons-net</groupId> + <artifactId>commons-net</artifactId> + <version>3.6</version> + </dependency> + <dependency> + <groupId>org.zeroturnaround</groupId> + <artifactId>zt-zip</artifactId> + <version>1.12</version> + </dependency> + </dependencies> <build> <!-- diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/bo/AaiVnfmInfo.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/bo/AaiVnfmInfo.java index e405f868..57276747 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/bo/AaiVnfmInfo.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/bo/AaiVnfmInfo.java @@ -40,8 +40,8 @@ public class AaiVnfmInfo { @JsonProperty("resource-version") private String resourceVersion; - @SerializedName("esr-system-info-list") - @JsonProperty("esr-system-info-list") + @SerializedName("esr-system-info") + @JsonProperty("esr-system-info") private List<EsrSystemInfo> esrSystemInfoList; public String getVnfmId() { diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/bo/entity/EsrSystemInfo.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/bo/entity/EsrSystemInfo.java index 9e750ea1..f5a0b8cb 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/bo/entity/EsrSystemInfo.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/bo/entity/EsrSystemInfo.java @@ -16,54 +16,50 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.entity; +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.gson.annotations.SerializedName; public class EsrSystemInfo { + @JsonProperty("esr-system-info-id") @SerializedName("esr-system-info-id") private String esrSystemId; + @JsonProperty("system-name") @SerializedName("system-name") private String esrSystemName; + @JsonProperty("type") @SerializedName("type") private String type; + @JsonProperty("vendor") @SerializedName("vendor") private String vendor; + @JsonProperty("version") @SerializedName("version") private String version; + @JsonProperty("service-url") @SerializedName("service-url") private String serviceUrl; + @JsonProperty("user-name") @SerializedName("user-name") private String userName; + @JsonProperty("password") @SerializedName("password") private String password; - @SerializedName("protocal") - private String protocal; + @JsonProperty("system-type") + @SerializedName("system-type") + private String systemType; - @SerializedName("ssl-cacert") - private String sslCacert; + @JsonProperty("resource-version") + @SerializedName("resource-version") + private String resourceVersion; - @SerializedName("ssl-insecure") - private String sslInsecure; - - @SerializedName("ip-address") - private String ip; - - @SerializedName("port") - private String port; - - @SerializedName("cloud-domain") - private String cloudDomain; - - @SerializedName("default-tenant") - private String defaultTenant; - public String getEsrSystemId() { return esrSystemId; } @@ -128,60 +124,19 @@ public class EsrSystemInfo { this.password = password; } - public String getProtocal() { - return protocal; - } - - public void setProtocal(String protocal) { - this.protocal = protocal; - } - - public String getSslCacert() { - return sslCacert; - } - - public void setSslCacert(String sslCacert) { - this.sslCacert = sslCacert; - } - - public String getSslInsecure() { - return sslInsecure; + public String getSystemType() { + return systemType; } - public void setSslInsecure(String sslInsecure) { - this.sslInsecure = sslInsecure; + public void setSystemType(String systemType) { + this.systemType = systemType; } - public String getIp() { - return ip; + public String getResourceVersion() { + return resourceVersion; } - public void setIp(String ip) { - this.ip = ip; + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; } - - public String getPort() { - return port; - } - - public void setPort(String port) { - this.port = port; - } - - public String getCloudDomain() { - return cloudDomain; - } - - public void setCloudDomain(String cloudDomain) { - this.cloudDomain = cloudDomain; - } - - public String getDefaultTenant() { - return defaultTenant; - } - - public void setDefaultTenant(String defaultTenant) { - this.defaultTenant = defaultTenant; - } - } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImpl.java index a8286f86..ddc78ebe 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImpl.java @@ -19,6 +19,7 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.impl; import java.io.IOException; import java.util.HashMap; +import org.apache.commons.codec.binary.Base64; import org.apache.http.client.ClientProtocolException; import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.AaiVnfmInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.inf.AaiMgmrInf; @@ -28,7 +29,6 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestMethod; @@ -62,10 +62,19 @@ public class AaiMgmrInfImpl implements AaiMgmrInf{ private String operateHttpTask(Object httpBodyObj, String httpPath, RequestMethod method) throws ClientProtocolException, IOException { String url=adaptorEnv.getAaiApiUriFront() + httpPath; - HashMap<String, String> map = new HashMap<>(); - map.put(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); + HashMap<String, String> headerMap = new HashMap<>(); + headerMap.put("Content-Type", "application/json"); + headerMap.put("Accept", "application/json"); + headerMap.put("X-TransactionId", "9999"); + headerMap.put("X-FromAppId", "esr-server"); + + Base64 token = new Base64(); + String authen = new String(token.encode(("AAI:AAI").getBytes())); + headerMap.put("Authorization", "Basic " + authen); + logger.info("getVimById headerMap: {}", headerMap.toString()); + - String responseStr = httpClientProcessor.process(url, method, map, gson.toJson(httpBodyObj)).getContent(); + String responseStr = httpClientProcessor.process(url, method, headerMap, gson.toJson(httpBodyObj)).getContent(); return responseStr; } 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 28400ed0..f351925b 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 @@ -49,7 +49,7 @@ public class Driver2CbamRequestConverter { public CBAMCreateVnfRequest createReqConvert(InstantiateVnfRequest driverRequest) { CBAMCreateVnfRequest request = new CBAMCreateVnfRequest(); - request.setVnfdId("vnfd_001"); + request.setVnfdId(driverRequest.getVnfDescriptorId()); request.setName(driverRequest.getVnfInstanceName()); request.setDescription(driverRequest.getVnfInstanceDescription()); return request; 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 e527b105..e6e060c0 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 @@ -16,9 +16,11 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Executors; import org.apache.http.client.ClientProtocolException; import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.bo.entity.VnfPackageInfo; @@ -31,6 +33,7 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum.LifecycleOperation; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorImpl; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmNotifyLCMEventsRequest; @@ -39,6 +42,7 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.zeroturnaround.zip.ZipUtil; public class InstantiateVnfContinueRunnable implements Runnable { @@ -70,12 +74,13 @@ public class InstantiateVnfContinueRunnable implements Runnable { public void run() { try { + //step 1 handle vnf package + handleVnfPackage(); + NslcmGrantVnfRequest grantRequest = buildNslcmGrantVnfRequest(); NslcmGrantVnfResponse grantResponse = nslcmMgmr.grantVnf(grantRequest); handleNslcmGrantResponse(grantResponse); - //step 2: query vnfPackage uri - VnfPackageInfo vnfPackageInfo = catalogMgmr.queryVnfPackage(driverRequest.getVnfPackageId()); //step 5: instantiate vnf CBAMInstantiateVnfRequest instantiateReq = requestConverter.InstantiateReqConvert(driverRequest, grantResponse, null, null); @@ -92,6 +97,36 @@ public class InstantiateVnfContinueRunnable implements Runnable { } } + + private void handleVnfPackage() { + Executors.newSingleThreadExecutor().execute(new Runnable() { + @Override + public void run() { + try { + //step 1: query vnfPackage uri -- download package -- extract it -- upload CBAM package to CBAM + VnfPackageInfo vnfPackageInfo = catalogMgmr.queryVnfPackage(driverRequest.getVnfPackageId()); + String packageUrl = vnfPackageInfo.getDownloadUri(); + String saveDir = "/service/vnfPackage"; + String packageFileName = packageUrl.substring(packageUrl.lastIndexOf("/")); + Process process = Runtime.getRuntime().exec("mkdir " + saveDir); + process.waitFor(); + + if (HttpClientProcessorImpl.downLoadFromUrl(packageUrl, packageFileName, saveDir)) { + //extract package + ZipUtil.unpack(new File(saveDir + "/" + packageFileName), new File(saveDir)); + //upload package + String cbamPackageDirName = saveDir + "/" + + packageFileName.substring(0, packageFileName.length() - 4) + "/Artifacts"; + String cbamPackageName = new File(cbamPackageDirName).list()[0]; + cbamMgmr.uploadVnfPackage(cbamPackageName); + } + } catch (Exception e) { + logger.error("Error to handleVnfPackage", e); + } + } + + }); + } private NslcmNotifyLCMEventsRequest buildNslcmNotifyLCMEventsRequest(CBAMInstantiateVnfResponse cbamInstantiateResponse) { NslcmNotifyLCMEventsRequest request = new NslcmNotifyLCMEventsRequest(); diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImpl.java index 29d2fc2d..79fb10f7 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImpl.java @@ -229,8 +229,11 @@ public class VnfmDriverMgmrImpl implements VnfmDriverMgmrInf{ EsrSystemInfo systemInfo = vnfmInfo.getEsrSystemInfoList().get(0); - String urlHead = systemInfo.getProtocal() + "://" + systemInfo.getIp() + ":" + systemInfo.getPort(); + String urlHead = systemInfo.getServiceUrl(); adaptorEnv.setCbamApiUriFront(urlHead); + adaptorEnv.setCbamUserName(systemInfo.getUserName()); + adaptorEnv.setCbamPassword(systemInfo.getPassword()); + return urlHead; } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/catalog/impl/CatalogMgmrImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/catalog/impl/CatalogMgmrImpl.java index fd93ee41..4598fa59 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/catalog/impl/CatalogMgmrImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/catalog/impl/CatalogMgmrImpl.java @@ -17,7 +17,6 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.impl; import java.io.IOException; -import java.util.HashMap; import org.apache.http.client.ClientProtocolException; import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.bo.CatalogQueryVnfResponse; @@ -49,11 +48,8 @@ public class CatalogMgmrImpl implements CatalogMgmrInf{ public VnfPackageInfo queryVnfPackage(String vnfPackageId) throws ClientProtocolException, IOException { String url=adaptorEnv.getCatalogApiUriFront() + String.format(CommonConstants.RetrieveVnfPackagePath, vnfPackageId); - HashMap<String, String> map = new HashMap<>(); - String bodyPostStr = String.format(CommonConstants.RetrieveCbamTokenPostStr, adaptorEnv.getGrantType(), adaptorEnv.getClientId(), adaptorEnv.getClientSecret()); - - String responseStr = httpClientProcessor.process(url, RequestMethod.GET, map, bodyPostStr).getContent(); + String responseStr = httpClientProcessor.process(url, RequestMethod.GET, null, null).getContent(); logger.info("CbamMgmrImpl -> queryVnfPackage, responseStr is " + responseStr); 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 bb226db9..6afa6c8d 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 @@ -37,6 +37,7 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; 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; @@ -60,14 +61,14 @@ public class CbamMgmrImpl implements CbamMgmrInf { private String retrieveToken() throws ClientProtocolException, IOException, JSONException { String result = null; - String url= adaptorEnv.getCbamApiUriFront() + CommonConstants.RetrieveCbamTokenPath; + String url= adaptorEnv.getCbamApiUriFront() + CommonConstants.CbamRetrieveTokenPath; HashMap<String, String> map = new HashMap<>(); map.put(CommonConstants.ACCEPT, "*/*"); map.put(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); - String bodyPostStr = String.format(CommonConstants.RetrieveCbamTokenPostStr, adaptorEnv.getGrantType(), adaptorEnv.getClientId(), adaptorEnv.getClientSecret()); + String bodyPostStr = String.format(CommonConstants.CbamRetrieveTokenPostStr, adaptorEnv.getGrantType(), adaptorEnv.getClientId(), adaptorEnv.getClientSecret(), adaptorEnv.getCbamUserName(), adaptorEnv.getCbamPassword()); - String responseStr = httpClientProcessor.process(url, RequestMethod.GET, map, bodyPostStr).getContent(); + String responseStr = httpClientProcessor.process(url, RequestMethod.POST, map, bodyPostStr).getContent(); logger.info("CbamMgmrImpl -> retrieveToken, responseStr is " + responseStr); @@ -252,5 +253,40 @@ public class CbamMgmrImpl implements CbamMgmrInf { public void setAdaptorEnv(AdaptorEnv adaptorEnv) { this.adaptorEnv = adaptorEnv; } + + @Override + public void uploadVnfPackage(String cbamPackageFilePath) throws ClientProtocolException, IOException { + String httpPath = CommonConstants.CbamUploadVnfPackagePath; + RequestMethod method = RequestMethod.POST; + + HttpResult httpResult = operateCbamHttpUploadTask(cbamPackageFilePath, httpPath, method); + String responseStr = httpResult.getContent(); + + logger.info("CbamMgmrImpl -> uploadVnfPackage, responseStr is " + responseStr); + + int code = httpResult.getStatusCode(); + if(code == 200) { + logger.info("CbamMgmrImpl -> uploadVnfPackage, success" ); + logger.info("Upload vnf package " + cbamPackageFilePath + " to CBAM is successful."); + }else { + logger.error("CbamMgmrImpl -> uploadVnfPackage, error" ); + } + } + + private HttpResult operateCbamHttpUploadTask(String filePath, String httpPath, RequestMethod method) throws ClientProtocolException, IOException { + String token = null; + try { + token = retrieveToken(); + } catch (JSONException e) { + logger.error("retrieveTokenError ", e); + } + String url = adaptorEnv.getCbamApiUriFront() + httpPath; + + HashMap<String, String> map = new HashMap<>(); + map.put(CommonConstants.AUTHORIZATION, "bearer " + token); + map.put(CommonConstants.CONTENT_TYPE, "multipart/form-data, boundary=--fsgdsfgjgjdsgdfjgjgj"); + byte[] fileBytes = CommonUtil.getBytes(filePath); + return httpClientProcessor.processBytes(url, method, map, fileBytes); + } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/inf/CbamMgmrInf.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/inf/CbamMgmrInf.java index 9c4bc6cc..d3bb970b 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/inf/CbamMgmrInf.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/inf/CbamMgmrInf.java @@ -53,4 +53,7 @@ public interface CbamMgmrInf { public void deleteVnf(String vnfInstanceId) throws ClientProtocolException, IOException; public CBAMQueryOperExecutionResponse queryOperExecution(String execId) throws ClientProtocolException, IOException; + + public void uploadVnfPackage(String cbamPackageName) throws ClientProtocolException, IOException; + }
\ No newline at end of file diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/common/bo/AdaptorEnv.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/common/bo/AdaptorEnv.java index e9a706c5..1a41765f 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/common/bo/AdaptorEnv.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/common/bo/AdaptorEnv.java @@ -56,6 +56,9 @@ public class AdaptorEnv { //cbamApiFront is from aai query private String cbamApiUriFront; + private String cbamUserName; + private String cbamPassword; + private String msbApiUriFront; @@ -221,5 +224,21 @@ public class AdaptorEnv { this.msbApiUriFront = msbApiUriFront; } + public String getCbamUserName() { + return cbamUserName; + } + + public void setCbamUserName(String cbamUserName) { + this.cbamUserName = cbamUserName; + } + + public String getCbamPassword() { + return cbamPassword; + } + + public void setCbamPassword(String cbamPassword) { + this.cbamPassword = cbamPassword; + } + } 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 34530b51..c49d1f04 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 @@ -17,6 +17,7 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.common.util; import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -78,4 +79,27 @@ public final class CommonUtil { } return path; } + + 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; + } + } 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 052f6ee5..b1059118 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 @@ -30,20 +30,20 @@ public class CommonConstants { public static final String UTF_8 = "utf-8"; //AAI path get vnfm - // /external-system/esr-vnfm-list/esr-vnfm/{vnfm-id} - public static final String RetrieveVnfmListPath = "/external-system/esr-vnfm-list/esr-vnfm/%s"; + // /external-system/esr-vnfm-list/esr-vnfm/{vnfm-id}/esr-system-info-list + public static final String RetrieveVnfmListPath = "/external-system/esr-vnfm-list/esr-vnfm/%s/esr-system-info-list"; //Nslcm path public static final String NslcmGrantPath = "/ns/grantvnf"; public static final String NslcmNotifyPath = "/vnfs/%s/Notify"; //Catalog path - public static final String RetrieveVnfPackagePath = "/vnfpackages/%s"; + public static final String RetrieveVnfPackagePath = "/catalog/v1/vnfpackages/%s"; //CBAM -- Nokia VNFM path public static final String CBAM_TOKEN_KEY = "access_token"; - public static final String RetrieveCbamTokenPath="/auth/realms/cbam/protocol/openid-connect/token"; - public static final String RetrieveCbamTokenPostStr="grant_type=%s&client_id=%s&client_secret=%s"; + public static final String CbamRetrieveTokenPath="/auth/realms/cbam/protocol/openid-connect/token"; + public static final String CbamRetrieveTokenPostStr="grant_type=password&client_id=%s&client_secret=%s&username=%s&password=%s"; public static final String CbamCreateVnfPath="/vnfs"; public static final String CbamInstantiateVnfPath="/vnfs/%s/instantiate"; public static final String CbamQueryVnfPath="/vnfs/%s"; @@ -53,6 +53,9 @@ 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 NSLCM_OPERATION_INSTANTIATE = "Instantiate"; public static final String NSLCM_OPERATION_TERMINATE = "Terminal"; public static final String NSLCM_OPERATION_SCALE_OUT = "Scaleout"; @@ -66,7 +69,6 @@ public class CommonConstants { //MSB public static final String MSB_REGISTER_SERVICE_PATH = "/api/microservices/v1/services"; -// public static final String MSB_REGISTER_SERVICE_PATH = "/api/microservices/v1/services/{serviceName}/version/{version}/nodes/{ip}/{port}"; public static final String MSB_UNREGISTER_SERVICE_PATH = "/api/microservices/v1/services/%s/version/%s/nodes/%s/%s"; public static final String MSB_QUERY_SERVICE_PATH = "/api/microservices/v1/services/%s/version/%s"; } 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 ca8e7e2e..114dea63 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 @@ -16,17 +16,26 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.HashMap; import org.apache.http.client.ClientProtocolException; import org.apache.http.impl.client.HttpClientBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestMethod; @Component public class HttpClientProcessorImpl implements HttpClientProcessorInf{ + private static final Logger logger = LoggerFactory.getLogger(HttpClientProcessorImpl.class); @Autowired private HttpClientBuilder httpClientBuilder; @@ -41,7 +50,7 @@ public class HttpClientProcessorImpl implements HttpClientProcessorInf{ processor.addHdeader(key, headerMap.get(key)); } - if(null != bodyString && bodyString.length() > 0) + if(null != bodyString && bodyString.length() > 0 && !bodyString.equalsIgnoreCase("null")) { processor.addPostEntity(bodyString); } @@ -49,8 +58,72 @@ 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 + { + HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, methodType); + if(headerMap != null && !headerMap.isEmpty()) + { + for(String key : headerMap.keySet()) + { + processor.addHdeader(key, headerMap.get(key)); + } + + if(null != byteArray && byteArray.length > 0) + { + processor.addBytesPostEntity(byteArray); + } + + } + return processor.process(url); + } + public void setHttpClientBuilder(HttpClientBuilder httpClientBuilder) { this.httpClientBuilder = httpClientBuilder; } + + public static boolean downLoadFromUrl(String urlStr, String fileName, String savePath) + { + try + { + URL url = new URL(urlStr); + HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + conn.setConnectTimeout(10*1000); + conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); + InputStream inputStream = conn.getInputStream(); + byte[] getData = readInputStream(inputStream); + File saveDir = new File(savePath); + 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(); + } + if(inputStream!=null){ + inputStream.close(); + } + } + catch ( IOException e ) { + logger.info("write file fail", e); + return false; + } + + logger.info("info: "+ urlStr + " download success"); + return true; + } + + + public static byte[] readInputStream(InputStream inputStream) throws IOException { + byte[] buffer = new byte[1024]; + int len = 0; + 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/HttpClientProcessorInf.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorInf.java index cbb820b8..ffcb68b5 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorInf.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorInf.java @@ -23,6 +23,8 @@ import org.apache.http.client.ClientProtocolException; import org.springframework.web.bind.annotation.RequestMethod; public interface HttpClientProcessorInf { - 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 ClientProtocolException, IOException; + + public HttpResult processBytes(String url, RequestMethod method, HashMap<String, String> map, byte[] fileBytes) throws ClientProtocolException, IOException; } 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 225a228a..363b5a92 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 @@ -25,6 +25,7 @@ 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.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; @@ -76,6 +77,9 @@ public class HttpRequestProcessor { public void addPostEntity(String bodyStr) { ((HttpPost)httpRequest).setEntity(new StringEntity(bodyStr, CommonConstants.UTF_8)); - + } + + public void addBytesPostEntity(byte[] byteArray) { + ((HttpPost)httpRequest).setEntity(new ByteArrayEntity(byteArray)); } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImplTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImplTest.java index 3a2ca761..01c256bd 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImplTest.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImplTest.java @@ -56,7 +56,7 @@ public class AaiMgmrInfImplTest { + "\"vim-id\":\"vim-id_001\"," + "\"certificate-url\":\"certificate-url_001\"," + "\"resource-version\":\"resource-version_001\"," - + "\"esr-system-info-list\":[{\"ip-address\" : \"1.3.5.6\"}]" + + "\"esr-system-info\":[{\"type\" : \"vnfm\"}]" + "}" + ""; HttpResult httpResult = new HttpResult(); @@ -69,6 +69,6 @@ public class AaiMgmrInfImplTest { public void testQueryVnfPackage() throws ClientProtocolException, IOException { AaiVnfmInfo vnfmInfo = aaiMgmr.queryVnfm(vnfmId); - Assert.assertEquals("1.3.5.6", vnfmInfo.getEsrSystemInfoList().get(0).getIp()); + Assert.assertEquals("vnfm", vnfmInfo.getEsrSystemInfoList().get(0).getType()); } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java index 3948638c..d7834465 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java @@ -105,16 +105,9 @@ public class VnfmDriverMgmrImplTest { cbamHttpHead = protocol + "://" + ip + ":" + port; EsrSystemInfo esrSystemInfo = new EsrSystemInfo(); - esrSystemInfo.setProtocal(protocol); - esrSystemInfo.setIp(ip); - esrSystemInfo.setPort(port); - esrSystemInfo.setCloudDomain("cloudDomain"); - esrSystemInfo.setDefaultTenant("defaultTenant"); esrSystemInfo.setEsrSystemId("esrSystemId"); esrSystemInfo.setPassword("password"); - esrSystemInfo.setServiceUrl("serviceUrl"); - esrSystemInfo.setSslCacert("sslCacert"); - esrSystemInfo.setSslInsecure("sslInsecure"); + esrSystemInfo.setServiceUrl(cbamHttpHead); esrSystemInfo.setType("type"); esrSystemInfo.setUserName("userName"); esrSystemInfo.setVendor("vendor"); |