summaryrefslogtreecommitdiffstats
path: root/huawei/vnfmadapter/VnfmadapterService/service
diff options
context:
space:
mode:
authorluxin <luxin7@huawei.com>2017-09-19 10:28:55 +0800
committerluxin <luxin7@huawei.com>2017-09-19 10:46:15 +0800
commit2ff33c87830f6f98bbb3842d6a3df9fb77d091e1 (patch)
tree2ca476148177dd4ec1606e07eaa12fd9c01d4c35 /huawei/vnfmadapter/VnfmadapterService/service
parentfa7789059a8abb39ae7125f186c4a95f3e236594 (diff)
Remove unused import
Remove unused import and define a constant instead duplicating literal Change-Id: I9edc7751344490b0a7e3e78ff78cdba72ecb784b Issue-Id:VFC-375 Signed-off-by: luxin <luxin7@huawei.com>
Diffstat (limited to 'huawei/vnfmadapter/VnfmadapterService/service')
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManager.java85
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManager.java3
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/Constant.java14
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfResourceMgr.java8
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoa.java6
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java8
6 files changed, 62 insertions, 62 deletions
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManager.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManager.java
index d0d84d4b..b2157ed9 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManager.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Huawei Technologies Co., Ltd.
+ * Copyright 2016-2017 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,10 +19,7 @@ package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
@@ -41,15 +38,11 @@ import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
-
/**
* Utility class to download CSAR
*
* @author
- * @version VFC 1.0 Sep 5, 2016
- *
+ * @version VFC 1.0 Sep 5, 2016
*/
public class DownloadCsarManager {
@@ -57,12 +50,13 @@ public class DownloadCsarManager {
public static final int CACHE = 100 * 1024;
- private DownloadCsarManager(){
- //private constructor
+ private DownloadCsarManager() {
+ // private constructor
}
/**
* Download from given URL.
+ *
* @param url String
* @return
*/
@@ -72,6 +66,7 @@ public class DownloadCsarManager {
/**
* Download from given URL to given file location.
+ *
* @param url String
* @param filepath String
* @return
@@ -85,8 +80,8 @@ public class DownloadCsarManager {
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
- if (filepath == null){
- filepath = getFilePath(response); //NOSONAR
+ if(filepath == null) {
+ filepath = getFilePath(response); // NOSONAR
}
File file = new File(filepath);
@@ -95,23 +90,24 @@ public class DownloadCsarManager {
byte[] buffer = new byte[CACHE];
int ch;
- while ((ch = is.read(buffer)) != -1) {
- fileout.write(buffer,0,ch);
+ while((ch = is.read(buffer)) != -1) {
+ fileout.write(buffer, 0, ch);
}
is.close();
fileout.flush();
fileout.close();
status = Constant.DOWNLOADCSAR_SUCCESS;
- } catch (Exception e) {
+ } catch(Exception e) {
status = Constant.DOWNLOADCSAR_FAIL;
- LOG.error("Download csar file failed! "+ e.getMessage(), e);
+ LOG.error("Download csar file failed! " + e.getMessage(), e);
}
return status;
}
/**
* Retrieve file path from given response.
+ *
* @param response HttpResponse
* @return
*/
@@ -119,7 +115,7 @@ public class DownloadCsarManager {
String filepath = System.getProperty("java.home");
String filename = getFileName(response);
- if (filename != null) {
+ if(filename != null) {
filepath += filename;
} else {
filepath += getRandomFileName();
@@ -129,21 +125,22 @@ public class DownloadCsarManager {
/**
* Retrieve file name from given response.
+ *
* @param response HttpResponse
* @return
*/
public static String getFileName(HttpResponse response) {
Header contentHeader = response.getFirstHeader("Content-Disposition");
String filename = null;
- if (contentHeader != null) {
+ if(contentHeader != null) {
HeaderElement[] values = contentHeader.getElements();
- if (values.length == 1) {
+ if(values.length == 1) {
NameValuePair param = values[0].getParameterByName("filename");
- if (param != null) {
+ if(param != null) {
try {
filename = param.getValue();
- } catch (Exception e) {
- LOG.error("getting filename failed! "+ e.getMessage(), e);
+ } catch(Exception e) {
+ LOG.error("getting filename failed! " + e.getMessage(), e);
}
}
}
@@ -153,60 +150,60 @@ public class DownloadCsarManager {
/**
* Provides random file name.
+ *
* @return
*/
public static String getRandomFileName() {
return String.valueOf(System.currentTimeMillis());
}
-
+
/**
* unzip CSAR packge
+ *
* @param fileName filePath
* @return
*/
- public static int unzipCSAR(String fileName,String filePath){
- final int BUFFER = 2048;
- int status=0;
-
+ public static int unzipCSAR(String fileName, String filePath) {
+ final int BUFFER = 2048;
+ int status = 0;
+
try {
ZipFile zipFile = new ZipFile(fileName);
Enumeration emu = zipFile.entries();
- int i=0;
- while(emu.hasMoreElements()){
+ int i = 0;
+ while(emu.hasMoreElements()) {
ZipEntry entry = (ZipEntry)emu.nextElement();
- //read directory as file first,so only need to create directory
- if (entry.isDirectory())
- {
+ // read directory as file first,so only need to create directory
+ if(entry.isDirectory()) {
new File(filePath + entry.getName()).mkdirs();
continue;
}
BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));
File file = new File(filePath + entry.getName());
- //Because that is random to read zipfile,maybe the file is read first
- //before the directory is read,so we need to create directory first.
+ // Because that is random to read zipfile,maybe the file is read first
+ // before the directory is read,so we need to create directory first.
File parent = file.getParentFile();
- if(parent != null && (!parent.exists())){
+ if(parent != null && (!parent.exists())) {
parent.mkdirs();
}
FileOutputStream fos = new FileOutputStream(file);
- BufferedOutputStream bos = new BufferedOutputStream(fos,BUFFER);
-
+ BufferedOutputStream bos = new BufferedOutputStream(fos, BUFFER);
+
int count;
byte data[] = new byte[BUFFER];
- while ((count = bis.read(data, 0, BUFFER)) != -1)
- {
+ while((count = bis.read(data, 0, BUFFER)) != -1) {
bos.write(data, 0, count);
}
bos.flush();
bos.close();
bis.close();
}
- status=Constant.UNZIP_SUCCESS;
+ status = Constant.UNZIP_SUCCESS;
zipFile.close();
- } catch (Exception e) {
- status=Constant.UNZIP_FAIL;
+ } catch(Exception e) {
+ status = Constant.UNZIP_FAIL;
e.printStackTrace();
}
return status;
}
-} \ No newline at end of file
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManager.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManager.java
index 42b9b27c..f9fe98f5 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManager.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/adapter/impl/AdapterResourceManager.java
@@ -180,8 +180,9 @@ public class AdapterResourceManager implements IResourceManager {
}
// upload VNF package
- csarTempObj.put("vim_id", vimId);
+ csarTempObj.getJSONArray("vim_list").getJSONObject(0).put("vim_id", vimId);
vnfpkg.put("template", csarTempObj);
+ LOG.info("vnfpkg: " + vnfpkg);
JSONObject uploadPkgObject = upload(vnfpkg, vnfmUrl, connToken);
LOG.info("uploadPkgObject:" + uploadPkgObject);
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/Constant.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/Constant.java
index 77367d53..bd2ad3fa 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/Constant.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/Constant.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant;
import java.util.Arrays;
@@ -90,7 +91,8 @@ public class Constant {
public static final int HTTP_INNERERROR = 500;
- public static final List<String> AUTHLIST = Collections.unmodifiableList(Arrays.asList(Constant.ANONYMOUS, Constant.CERTIFICATE));
+ public static final List<String> AUTHLIST =
+ Collections.unmodifiableList(Arrays.asList(Constant.ANONYMOUS, Constant.CERTIFICATE));
public static final int INTERNAL_EXCEPTION = 600;
@@ -124,13 +126,15 @@ public class Constant {
public static final String STATUS = "status";
- public static final String VNFPKGINFO="vnfpkginfo.json";
+ public static final String VNFPKGINFO = "vnfpkginfo.json";
public static final int ERROR_STATUS_CODE = -1;
-
- public static final String COLON=":";
+
+ public static final String COLON = ":";
+
+ public static final String ERRORMSG = "errorMsg";
private Constant() {
- //private constructor
+ // private constructor
}
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfResourceMgr.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfResourceMgr.java
index b15f9a1e..29141588 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfResourceMgr.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/process/VnfResourceMgr.java
@@ -20,10 +20,10 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
+import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.RestfulResponse;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VnfmRestfulUtil;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.ParamConstants;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.RestfulResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -66,7 +66,7 @@ public class VnfResourceMgr {
if(StringUtils.isEmpty(type) || StringUtils.isEmpty(requestType) || StringUtils.isEmpty(vnfName)
|| StringUtils.isEmpty(vnfId)) {
LOG.error("function=grantVnfResource, msg=grant basic params error");
- resultJson.put("errorMsg", "basic params error");
+ resultJson.put(Constant.ERRORMSG, "basic params error");
return resultJson;
}
@@ -76,7 +76,7 @@ public class VnfResourceMgr {
if(null == resMap) {
LOG.error("function=grantVnfResource, msg=grant resource params error");
- resultJson.put("errorMsg", "resource params error");
+ resultJson.put(Constant.ERRORMSG, "resource params error");
return resultJson;
}
@@ -93,7 +93,7 @@ public class VnfResourceMgr {
LOG.error("function=grantVnfResource, resultJson={}.", resultJson);
} catch(JSONException e) {
LOG.error("function=grantVnfResource, msg=parse params occoured JSONException e={}.", e);
- resultJson.put("errorMsg", "params parse exception");
+ resultJson.put(Constant.ERRORMSG, "params parse exception");
}
return resultJson;
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 b7ad0b03..de8686cd 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
@@ -111,9 +111,8 @@ public class VnfRoa {
JSONObject jsonObject = VnfmJsonUtil.getJsonFromContexts(context);
LOG.info("function=scaleVNF, msg=enter to scale a vnf. request body:" + jsonObject);
JSONObject result = new JSONObject();
- String msg = "";
if(null == jsonObject) {
- msg = "the parameters do not meet the requirements,please check it!";
+ String msg = "the parameters do not meet the requirements,please check it!";
LOG.error("function=scalVnf," + msg);
resp.setStatus(Constant.HTTP_NOT_ACCEPTABLE);
result.put("msg", msg);
@@ -217,8 +216,7 @@ public class VnfRoa {
@GET
@Path("/{vnfmId}/vnfs/{vnfInstanceId}")
public String getVnf(@PathParam("vnfmId") String vnfmId, @Context HttpServletResponse resp,
- @PathParam("vnfInstanceId") String vnfInstanceId, @Context HttpServletRequest context)
- throws ServiceException {
+ @PathParam("vnfInstanceId") String vnfInstanceId) throws ServiceException {
LOG.warn("function=getVnf, msg=enter to get a vnf: vnfInstanceId: {}, vnfmId: {}", vnfInstanceId, vnfmId);
JSONObject restJson = new JSONObject();
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java
index 9b87f2ef..b82c26af 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java
@@ -300,7 +300,7 @@ public class VnfRoaTest {
}
};
- String result = vnfRoa.getVnf("vnfmId", mockResInstance, "", mockInstance);
+ String result = vnfRoa.getVnf("vnfmId", mockResInstance, "");
assertEquals(restJson.toString(), result);
}
@@ -323,7 +323,7 @@ public class VnfRoaTest {
}
};
- String result = vnfRoa.getVnf("", mockResInstance, "vnfId", mockInstance);
+ String result = vnfRoa.getVnf("", mockResInstance, "vnfId");
assertEquals(restJson.toString(), result);
}
@@ -355,7 +355,7 @@ public class VnfRoaTest {
}
};
- String result = vnfRoa.getVnf("vnfmId", mockResInstance, "vnfId", mockInstance);
+ String result = vnfRoa.getVnf("vnfmId", mockResInstance, "vnfId");
assertEquals(restJson.toString(), result);
}
@@ -399,7 +399,7 @@ public class VnfRoaTest {
}
};
- String result = vnfRoa.getVnf("vnfmId", mockResInstance, "vnfId", mockInstance);
+ String result = vnfRoa.getVnf("vnfmId", mockResInstance, "vnfId");
JSONObject basicInfoJson = new JSONObject();
JSONObject retJson = new JSONObject();
basicInfoJson.put("vnfInstanceId", "123");