summaryrefslogtreecommitdiffstats
path: root/vnf-sdk-function-test/src/main
diff options
context:
space:
mode:
authorKailun Qin <kailun.qin@intel.com>2018-03-27 18:23:01 +0800
committerKailun Qin <kailun.qin@intel.com>2018-03-28 23:34:40 +0800
commitd4a7658f72decfef05d15973d5cee13910eb47ae (patch)
treee9b872d3e58a8fc3c420b0ee020267a22a8c8136 /vnf-sdk-function-test/src/main
parent29078dd84779639f98739d508e947db0662473df (diff)
Port nfvo/vnf_functest for framework merge
Merged VNF onboarding test functions and frameworks locating separately in nfvo/vnf_functest and vnfsdk/vnf-sdk-function-test seed code. 1) Reconstructed by aligning with the original interface and sequence design; 2) Replaced Restful calls with local invokes; 3) Implemented DB support (PostgreSQL) for persistent recording; 4) Added unit tests associated; 5) Unified package names to "onap"; 6) Fixed several inherent issues. Issue-ID: VNFSDK-178 Change-Id: I2147c5df8dd400adef71dafca9073b12d992d2df Signed-off-by: Kailun Qin <kailun.qin@intel.com>
Diffstat (limited to 'vnf-sdk-function-test/src/main')
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/FileUtil.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/FileUtil.java)79
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/TaskExecution.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/TaskExecution.java)90
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/VnfSdkFuncTestApp.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestApp.java)58
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/VnfSdkFuncTestAppConfiguration.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestAppConfiguration.java)28
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/common/Config.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/Config.java)10
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/constants/ApplicationConstants.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/constants/ApplicationConstants.java)8
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/db/TaskMgrCaseTblDAO.java43
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/db/TaskMgrTaskTblDAO.java51
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/Environment.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/Environment.java)134
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/EnvironmentMap.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/EnvironmentMap.java)106
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/OperationStatus.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatus.java)107
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java)147
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceNode.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceNode.java)9
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceRegisterEntity.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceRegisterEntity.java)16
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/models/CaseRecord.java123
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/models/TaskRecord.java202
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/TestResult.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/TestResult.java)108
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/TestResultMap.java51
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/TestResultParser.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/TestResultParser.java)289
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandler.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandler.java)90
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/scriptmgr/ScriptManager.java227
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/taskmgr/TaskManager.java258
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/util/GsonUtil.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/GsonUtil.java)8
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/util/RestResponseUtil.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/RestResponseUtil.java)16
-rw-r--r--vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/util/ZipCompressor.java (renamed from vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/ZipCompressor.java)33
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/ServiceRegistration.java79
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusConsumer.java49
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusRest.java37
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/resource/CommonManager.java341
-rw-r--r--vnf-sdk-function-test/src/main/resources/migrations.xml57
-rw-r--r--vnf-sdk-function-test/src/main/resources/sample.xml8
31 files changed, 1687 insertions, 1175 deletions
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/FileUtil.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/FileUtil.java
index 7a5dbba..fd66362 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/FileUtil.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/FileUtil.java
@@ -14,25 +14,18 @@
* limitations under the License.
*/
-package org.openo.vnfsdk.functest;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+package org.onap.vnfsdk.functest;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
public final class FileUtil {
public static final Logger LOG = LoggerFactory.getLogger(FileUtil.class);
@@ -47,16 +40,16 @@ public final class FileUtil {
/**
* Create directory.
- *
+ *
* @param dir directory to create
* @return boolean
*/
public static boolean createDirectory(String dir) {
File folder = new File(dir);
int tryCount = 0;
- while(tryCount < TRY_COUNT) {
+ while (tryCount < TRY_COUNT) {
tryCount++;
- if(!folder.exists() && !folder.mkdirs()) {
+ if (!folder.exists() && !folder.mkdirs()) {
continue;
} else {
return true;
@@ -68,7 +61,7 @@ public final class FileUtil {
/**
* delete file.
- *
+ *
* @param file the file to delete
* @return boolean
*/
@@ -76,8 +69,8 @@ public final class FileUtil {
String hintInfo = file.isDirectory() ? "dir " : "file ";
boolean isFileDeleted = file.delete();
boolean isFileExist = file.exists();
- if(!isFileExist) {
- if(isFileDeleted) {
+ if (!isFileExist) {
+ if (isFileDeleted) {
LOG.info("delete " + hintInfo + file.getAbsolutePath());
} else {
isFileDeleted = true;
@@ -91,9 +84,9 @@ public final class FileUtil {
/**
* unzip zip file.
- *
+ *
* @param zipFileName file name to zip
- * @param extPlace extPlace
+ * @param extPlace extPlace
* @return unzip file name
* @throws IOException e1
*/
@@ -106,25 +99,25 @@ public final class FileUtil {
Enumeration<?> fileEn = zipFile.entries();
byte[] buffer = new byte[BUFFER_SIZE];
- while(fileEn.hasMoreElements()) {
+ while (fileEn.hasMoreElements()) {
InputStream input = null;
BufferedOutputStream bos = null;
try {
- ZipEntry entry = (ZipEntry)fileEn.nextElement();
- if(entry.isDirectory()) {
+ ZipEntry entry = (ZipEntry) fileEn.nextElement();
+ if (entry.isDirectory()) {
continue;
}
input = zipFile.getInputStream(entry);
File file = new File(extPlace, entry.getName());
- if(!file.getParentFile().exists()) {
+ if (!file.getParentFile().exists()) {
createDirectory(file.getParentFile().getAbsolutePath());
}
bos = new BufferedOutputStream(new FileOutputStream(file));
- while(true) {
+ while (true) {
int length = input.read(buffer);
- if(length == -1) {
+ if (length == -1) {
break;
}
bos.write(buffer, 0, length);
@@ -153,46 +146,46 @@ public final class FileUtil {
/**
* close InputStream.
- *
+ *
* @param inputStream the inputstream to close
*/
private static void closeInputStream(InputStream inputStream) {
try {
- if(inputStream != null) {
+ if (inputStream != null) {
inputStream.close();
}
- } catch(Exception ex) {
+ } catch (Exception ex) {
LOG.error("close InputStream error!: " + ex);
}
}
/**
* close OutputStream.
- *
+ *
* @param outputStream the output stream to close
*/
private static void closeOutputStream(OutputStream outputStream) {
try {
- if(outputStream != null) {
+ if (outputStream != null) {
outputStream.close();
}
- } catch(Exception ex) {
+ } catch (Exception ex) {
LOG.error("close OutputStream error!: " + ex);
}
}
/**
* close zipFile.
- *
+ *
* @param zipFile the zipFile to close
*/
private static void closeZipFile(ZipFile zipFile) {
try {
ZipFile tempZipFile = zipFile;
- if(tempZipFile != null) {
+ if (tempZipFile != null) {
tempZipFile.close();
}
- } catch(IOException ioe) {
+ } catch (IOException ioe) {
LOG.error("close ZipFile error!: " + ioe);
}
}
@@ -204,7 +197,7 @@ public final class FileUtil {
public static Boolean deleteFile(String filePath) {
File file = new File(filePath);
- if(file.exists()) {
+ if (file.exists()) {
return file.delete();
}
return true;
@@ -213,17 +206,17 @@ public final class FileUtil {
public static byte[] convertZipFiletoByteArray(String filename) {
File file = new File(filename);
byte[] emptyArray = new byte[0];
- if(!file.exists()) {
+ if (!file.exists()) {
return emptyArray;
}
- byte[] byteArrayFile = new byte[(int)file.length()];
+ byte[] byteArrayFile = new byte[(int) file.length()];
try {
FileInputStream fileInputStream = new FileInputStream(filename);
int value = fileInputStream.read(byteArrayFile);
fileInputStream.close();
LOG.debug("Number of bytes read from fileInputStream = " + value);
- } catch(Exception e) {
+ } catch (Exception e) {
LOG.error("convertZipFiletoByteArray: " + e);
}
return byteArrayFile;
@@ -238,11 +231,11 @@ public final class FileUtil {
*/
public static void deleteDirectory(String directory) {
File file = new File(directory);
- if(!file.exists()) {
+ if (!file.exists()) {
return;
}
- if(file.isDirectory()) {
- for(File sub : file.listFiles()) {
+ if (file.isDirectory()) {
+ for (File sub : file.listFiles()) {
deleteFile(sub);
}
}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/TaskExecution.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/TaskExecution.java
index d55ec98..51a8799 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/TaskExecution.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/TaskExecution.java
@@ -14,28 +14,28 @@
* limitations under the License.
*/
-package org.openo.vnfsdk.functest;
+package org.onap.vnfsdk.functest;
+
+import com.google.gson.Gson;
+import com.google.gson.stream.JsonReader;
+import org.apache.commons.lang3.SystemUtils;
+import org.onap.vnfsdk.functest.constants.ApplicationConstants;
+import org.onap.vnfsdk.functest.externalservice.entity.Environment;
+import org.onap.vnfsdk.functest.externalservice.entity.EnvironmentMap;
+import org.onap.vnfsdk.functest.externalservice.entity.OperationStatus;
+import org.onap.vnfsdk.functest.externalservice.entity.OperationStatus.operResultCode;
+import org.onap.vnfsdk.functest.externalservice.entity.OperationStatusHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.File;
-import java.io.FileInputStream;
+import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
-import org.apache.commons.lang3.SystemUtils;
-import org.openo.vnfsdk.functest.constants.ApplicationConstants;
-import org.openo.vnfsdk.functest.externalservice.entity.Environment;
-import org.openo.vnfsdk.functest.externalservice.entity.EnvironmentMap;
-import org.openo.vnfsdk.functest.externalservice.entity.OperationStatus;
-import org.openo.vnfsdk.functest.externalservice.entity.OperationStatus.operResultCode;
-import org.openo.vnfsdk.functest.externalservice.entity.OperationStatusHandler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-
public class TaskExecution {
private static final Logger LOGGER = LoggerFactory.getLogger(TaskExecution.class);
@@ -47,13 +47,14 @@ public class TaskExecution {
String confDir = curDir + nl + ApplicationConstants.CONF + nl + ApplicationConstants.ROBOT + nl;
// Read the MetaData from the VNF package
- ObjectMapper mapper = new ObjectMapper();
+// ObjectMapper mapper = new ObjectMapper();
Map<String, String> mapValues = null;
try {
- mapValues =
- mapper.readValue(new FileInputStream(confDir + ApplicationConstants.ROBOTMETADATA_JSON), Map.class);
- } catch(IOException e) {
+// mapValues =
+// mapper.readValue(new FileInputStream(confDir + ApplicationConstants.ROBOTMETADATA_JSON), Map.class);
+ mapValues = new Gson().fromJson(new JsonReader(new FileReader(confDir + ApplicationConstants.ROBOTMETADATA_JSON)), Map.class);
+ } catch (IOException e) {
LOGGER.error(ApplicationConstants.JSON_METADATA_FILE_FAILED, e);
return;
@@ -77,7 +78,7 @@ public class TaskExecution {
mapValues.put("REMOTE_COMMAND", "\"" + remoteCommand + "\"");
String robotvariables = "";
- for(Entry<String, String> values : mapValues.entrySet()) {
+ for (Entry<String, String> values : mapValues.entrySet()) {
robotvariables = robotvariables + " -v " + values.getKey() + ":" + values.getValue() + " ";
}
@@ -92,16 +93,16 @@ public class TaskExecution {
try {
String command = "robot --argumentfile " + argumentFilePath + robotvariables + " " + robotScript;
LOGGER.info("Command execute to execute the script:" + command);
- process = Runtime.getRuntime().exec(new String[] {getShellCommand(), getShellArg(), command});
- if(process != null) {
+ process = Runtime.getRuntime().exec(new String[]{getShellCommand(), getShellArg(), command});
+ if (process != null) {
process.waitFor();
inputStream = process.getInputStream();
}
- while((ch = inputStream.read()) != -1) {
+ while ((ch = inputStream.read()) != -1) {
LOGGER.info(ApplicationConstants.CHARACTER + Integer.toString(ch));
}
- } catch(Exception e) {
+ } catch (Exception e) {
LOGGER.error(ApplicationConstants.TASKEXE_EXESCRIPT_EXCEPTION, e);
}
}
@@ -113,12 +114,13 @@ public class TaskExecution {
String confDir = curDir + nl + ApplicationConstants.CONF + nl + ApplicationConstants.ROBOT + nl;
// Read the MetaData from the VNF package
- ObjectMapper mapper = new ObjectMapper();
+// ObjectMapper mapper = new ObjectMapper();
Map<String, String> mapValues = null;
try {
- mapValues =
- mapper.readValue(new FileInputStream(confDir + ApplicationConstants.ROBOTMETADATA_JSON), Map.class);
- } catch(IOException e) {
+// mapValues =
+// mapper.readValue(new FileInputStream(confDir + ApplicationConstants.ROBOTMETADATA_JSON), Map.class);
+ mapValues = new Gson().fromJson(new JsonReader(new FileReader(confDir + ApplicationConstants.ROBOTMETADATA_JSON)), Map.class);
+ } catch (IOException e) {
LOGGER.error(ApplicationConstants.JSON_METADATA_FILE_FAILED, e);
return;
@@ -126,7 +128,7 @@ public class TaskExecution {
// Get environment of given UUID
Environment functestEnv = EnvironmentMap.getInstance().getEnv(envId);
- if(null == functestEnv) {
+ if (null == functestEnv) {
LOGGER.error("Function Test Environment details are empty,EnvID = " + envId);
} else {
LOGGER.info("Function Test Environment path,Path = " + functestEnv.getPath());
@@ -164,16 +166,16 @@ public class TaskExecution {
try {
String command = ApplicationConstants.ROBOT + remoteArgs + robotScript;
LOGGER.info("Command execute to execute the script:" + command);
- process = Runtime.getRuntime().exec(new String[] {getShellCommand(), getShellArg(), command});
- if(process != null) {
+ process = Runtime.getRuntime().exec(new String[]{getShellCommand(), getShellArg(), command});
+ if (process != null) {
process.waitFor();
inputStream = process.getInputStream();
}
- while((ch = inputStream.read()) != -1) {
+ while ((ch = inputStream.read()) != -1) {
LOGGER.info(ApplicationConstants.CHARACTER + Integer.toString(ch));
}
- } catch(Exception e) {
+ } catch (Exception e) {
LOGGER.error(ApplicationConstants.TASKEXE_EXESCRIPT_EXCEPTION, e);
}
@@ -191,14 +193,14 @@ public class TaskExecution {
String confDir = curDir + nl + ApplicationConstants.CONF + nl + ApplicationConstants.ROBOT + nl;
// Read the MetaData from the VNF package
- ObjectMapper mapper = new ObjectMapper();
+// ObjectMapper mapper = new ObjectMapper();
Map<String, String> mapValues = null;
try {
-
- mapValues =
- mapper.readValue(new FileInputStream(confDir + ApplicationConstants.ROBOTMETADATA_JSON), Map.class);
- } catch(Exception e) {
+// mapValues =
+// mapper.readValue(new FileInputStream(confDir + ApplicationConstants.ROBOTMETADATA_JSON), Map.class);
+ mapValues = new Gson().fromJson(new JsonReader(new FileReader(confDir + ApplicationConstants.ROBOTMETADATA_JSON)), Map.class);
+ } catch (Exception e) {
LOGGER.error(ApplicationConstants.JSON_METADATA_FILE_FAILED, e);
return;
@@ -208,7 +210,7 @@ public class TaskExecution {
mapValues.put("SCRIPT_DIR", dirPath);
String robotvariables = "";
- for(Entry<String, String> values : mapValues.entrySet()) {
+ for (Entry<String, String> values : mapValues.entrySet()) {
robotvariables = robotvariables + " -v " + values.getKey() + ":" + values.getValue() + " ";
}
@@ -229,17 +231,17 @@ public class TaskExecution {
try {
String command = ApplicationConstants.ROBOT_SPACE + robotvariables + robotScript;
LOGGER.info("Command execute to upload the script:" + command);
- process = Runtime.getRuntime().exec(new String[] {getShellCommand(), getShellArg(), command});
- if(process != null) {
+ process = Runtime.getRuntime().exec(new String[]{getShellCommand(), getShellArg(), command});
+ if (process != null) {
process.waitFor();
inputStream = process.getInputStream();
}
- while((ch = inputStream.read()) != -1) {
+ while ((ch = inputStream.read()) != -1) {
LOGGER.info(ApplicationConstants.CHARACTER + Integer.toString(ch));
}
- } catch(Exception e) {
+ } catch (Exception e) {
LOGGER.error(ApplicationConstants.TASKEXE_EXESCRIPT_EXCEPTION, e);
}
@@ -254,7 +256,7 @@ public class TaskExecution {
private String getShellCommand() {
String shellcommand = ApplicationConstants.SHELL_COMMAND;
- if(SystemUtils.IS_OS_LINUX) {
+ if (SystemUtils.IS_OS_LINUX) {
shellcommand = ApplicationConstants.SHELL_COMMAND_BASH;
}
@@ -264,7 +266,7 @@ public class TaskExecution {
private String getShellArg() {
String commandArg = "/c";
- if(SystemUtils.IS_OS_LINUX) {
+ if (SystemUtils.IS_OS_LINUX) {
commandArg = "-c";
}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestApp.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/VnfSdkFuncTestApp.java
index b368f23..abc8aa9 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestApp.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/VnfSdkFuncTestApp.java
@@ -14,27 +14,39 @@
* limitations under the License.
*/
-package org.openo.vnfsdk.functest;
-
-import org.glassfish.jersey.media.multipart.MultiPartFeature;
-import org.openo.vnfsdk.functest.common.Config;
-import org.openo.vnfsdk.functest.common.ServiceRegistration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+package org.onap.vnfsdk.functest;
import com.fasterxml.jackson.annotation.JsonInclude;
-
import io.dropwizard.Application;
import io.dropwizard.assets.AssetsBundle;
+import io.dropwizard.db.DataSourceFactory;
+import io.dropwizard.hibernate.HibernateBundle;
+import io.dropwizard.hibernate.ScanningHibernateBundle;
+import io.dropwizard.migrations.MigrationsBundle;
import io.dropwizard.server.SimpleServerFactory;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.swagger.jaxrs.config.BeanConfig;
import io.swagger.jaxrs.listing.ApiListingResource;
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.onap.vnfsdk.functest.common.Config;
+import org.onap.vnfsdk.functest.db.TaskMgrCaseTblDAO;
+import org.onap.vnfsdk.functest.db.TaskMgrTaskTblDAO;
+import org.onap.vnfsdk.functest.scriptmgr.ScriptManager;
+import org.onap.vnfsdk.functest.taskmgr.TaskManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class VnfSdkFuncTestApp extends Application<VnfSdkFuncTestAppConfiguration> {
private static final Logger LOGGER = LoggerFactory.getLogger(VnfSdkFuncTestApp.class);
+ private final HibernateBundle<VnfSdkFuncTestAppConfiguration> hibernateBundle =
+ new ScanningHibernateBundle<VnfSdkFuncTestAppConfiguration>("org.onap.vnfsdk.functest.models") {
+ @Override
+ public DataSourceFactory getDataSourceFactory(VnfSdkFuncTestAppConfiguration configuration) {
+ return configuration.getDataSourceFactory();
+ }
+ };
public static void main(String[] args) throws Exception {
new VnfSdkFuncTestApp().run(args);
@@ -42,44 +54,46 @@ public class VnfSdkFuncTestApp extends Application<VnfSdkFuncTestAppConfiguratio
@Override
public String getName() {
- return "OPENO-VNFSDK-FunctionTest";
+ return "ONAP-VNFSDK-FunctionTest";
}
@Override
public void initialize(Bootstrap<VnfSdkFuncTestAppConfiguration> bootstrap) {
bootstrap.addBundle(new AssetsBundle("/api-doc", "/api-doc", "index.html", "api-doc"));
-
- }
-
- private void initService() {
- Thread registerExtsysService = new Thread(new ServiceRegistration());
- registerExtsysService.setName("Register vnfsdk-functionTest service to Microservice Bus");
- registerExtsysService.start();
+ bootstrap.addBundle(new MigrationsBundle<VnfSdkFuncTestAppConfiguration>() {
+ @Override
+ public DataSourceFactory getDataSourceFactory(VnfSdkFuncTestAppConfiguration configuration) {
+ return configuration.getDataSourceFactory();
+ }
+ });
+ bootstrap.addBundle(hibernateBundle);
}
@Override
public void run(VnfSdkFuncTestAppConfiguration configuration, Environment environment) {
LOGGER.info("Start to initialize vnfsdk function test.");
- environment.jersey().packages("org.openo.vnfsdk.functest.resource");
+ environment.jersey().packages("org.onap.vnfsdk.functest.taskmgr");
environment.jersey().register(MultiPartFeature.class);
initSwaggerConfig(environment, configuration);
Config.setConfigration(configuration);
- initService();
LOGGER.info("Initialize vnfsdk function test finished.");
}
private void initSwaggerConfig(Environment environment, VnfSdkFuncTestAppConfiguration configuration) {
+ final TaskMgrTaskTblDAO taskDAO = new TaskMgrTaskTblDAO(hibernateBundle.getSessionFactory());
+ final TaskMgrCaseTblDAO caseDAO = new TaskMgrCaseTblDAO(hibernateBundle.getSessionFactory());
environment.jersey().register(new ApiListingResource());
environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ environment.jersey().register(new TaskManager(taskDAO, caseDAO, new ScriptManager(taskDAO, caseDAO)));
BeanConfig config = new BeanConfig();
- config.setTitle("Open-o VnfSdk Functest Service rest API");
+ config.setTitle("ONAP VnfSdk Functest Service rest API");
config.setVersion("1.0.0");
- config.setResourcePackage("org.openo.vnfsdk.functest.resource");
+ config.setResourcePackage("org.onap.vnfsdk.functest.taskmgr");
- SimpleServerFactory simpleServerFactory = (SimpleServerFactory)configuration.getServerFactory();
+ SimpleServerFactory simpleServerFactory = (SimpleServerFactory) configuration.getServerFactory();
String basePath = simpleServerFactory.getApplicationContextPath();
- String rootPath = simpleServerFactory.getJerseyRootPath();
+ String rootPath = simpleServerFactory.getJerseyRootPath().toString();
rootPath = rootPath.substring(0, rootPath.indexOf("/*"));
basePath =
("/").equals(rootPath) ? rootPath : (new StringBuilder()).append(basePath).append(rootPath).toString();
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestAppConfiguration.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/VnfSdkFuncTestAppConfiguration.java
index 574fe0d..f4b7b83 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestAppConfiguration.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/VnfSdkFuncTestAppConfiguration.java
@@ -14,17 +14,15 @@
* limitations under the License.
*/
-package org.openo.vnfsdk.functest;
-
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-
-import org.hibernate.validator.constraints.NotEmpty;
+package org.onap.vnfsdk.functest;
import com.fasterxml.jackson.annotation.JsonProperty;
-
import io.dropwizard.Configuration;
import io.dropwizard.db.DataSourceFactory;
+import org.hibernate.validator.constraints.NotEmpty;
+
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
public class VnfSdkFuncTestAppConfiguration extends Configuration {
@@ -32,16 +30,14 @@ public class VnfSdkFuncTestAppConfiguration extends Configuration {
private String template;
@NotEmpty
- private String defaultName = "OPENO-VnfSdk-FuncTest";
-
- @NotEmpty
- private String msbServerAddr;
+ private String defaultName = "ONAP-VnfSdk-FuncTest";
@Valid
private String serviceIp;
@Valid
@NotNull
+ @JsonProperty
private DataSourceFactory database = new DataSourceFactory();
@JsonProperty("database")
@@ -75,16 +71,6 @@ public class VnfSdkFuncTestAppConfiguration extends Configuration {
}
@JsonProperty
- public String getMsbServerAddr() {
- return msbServerAddr;
- }
-
- @JsonProperty
- public void setMsbServerAddr(String msbServerAddr) {
- this.msbServerAddr = msbServerAddr;
- }
-
- @JsonProperty
public String getServiceIp() {
return serviceIp;
}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/Config.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/common/Config.java
index 23d4158..0be814c 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/Config.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/common/Config.java
@@ -14,23 +14,23 @@
* limitations under the License.
*/
-package org.openo.vnfsdk.functest.common;
+package org.onap.vnfsdk.functest.common;
-import org.openo.vnfsdk.functest.VnfSdkFuncTestAppConfiguration;
+import org.onap.vnfsdk.functest.VnfSdkFuncTestAppConfiguration;
public class Config {
- private static VnfSdkFuncTestAppConfiguration configration;
+ private static VnfSdkFuncTestAppConfiguration configuration;
private Config() {
}
public static VnfSdkFuncTestAppConfiguration getConfigration() {
- return configration;
+ return configuration;
}
public static void setConfigration(VnfSdkFuncTestAppConfiguration config) {
- configration = config;
+ configuration = config;
}
}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/constants/ApplicationConstants.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/constants/ApplicationConstants.java
index d3658a9..630db46 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/constants/ApplicationConstants.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/constants/ApplicationConstants.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.openo.vnfsdk.functest.constants;
+package org.onap.vnfsdk.functest.constants;
public class ApplicationConstants {
@@ -50,6 +50,12 @@ public class ApplicationConstants {
public static final String RUN_SCRIPT_EXECUTE_CMD = "Upload the script and execute the script and run command";
+ public static final String ENVIRONMENT = "environment";
+
+ public static final String ENVIRONMENT_JSON = "environment.json";
+
+ public static final String CATALOG_URI = "file:///C:/RobotScript/RobotScript.zip";
+
private ApplicationConstants() {
}
diff --git a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/db/TaskMgrCaseTblDAO.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/db/TaskMgrCaseTblDAO.java
new file mode 100644
index 0000000..f228ab5
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/db/TaskMgrCaseTblDAO.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2018 Intel Corporation Intellectual Property
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnfsdk.functest.db;
+
+import io.dropwizard.hibernate.AbstractDAO;
+import org.hibernate.SessionFactory;
+import org.onap.vnfsdk.functest.models.CaseRecord;
+
+import java.util.List;
+
+public class TaskMgrCaseTblDAO extends AbstractDAO<CaseRecord> {
+ public TaskMgrCaseTblDAO(SessionFactory factory) {
+ super(factory);
+ }
+
+ public CaseRecord findByTaskID(String taskID) {
+ //return Optional.ofNullable(get(taskID));
+ return get(taskID);
+ }
+
+ public CaseRecord saveOrUpdate(CaseRecord caseRecord) {
+ return persist(caseRecord);
+ }
+
+ public List<CaseRecord> findAll() {
+ return list(namedQuery("org.onap.vnfsdk.functest.models.CaseRecord.findAll"));
+ }
+
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/db/TaskMgrTaskTblDAO.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/db/TaskMgrTaskTblDAO.java
new file mode 100644
index 0000000..2e9fbd2
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/db/TaskMgrTaskTblDAO.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2018 Intel Corporation Intellectual Property
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnfsdk.functest.db;
+
+import io.dropwizard.hibernate.AbstractDAO;
+import org.hibernate.SessionFactory;
+import org.onap.vnfsdk.functest.models.TaskRecord;
+
+import java.util.List;
+import java.util.Optional;
+
+public class TaskMgrTaskTblDAO extends AbstractDAO<TaskRecord> {
+ public TaskMgrTaskTblDAO(SessionFactory factory) {
+ super(factory);
+ }
+
+ public Optional<TaskRecord> findByPackageID(String packageID) {
+ return Optional.ofNullable(get(packageID));
+ }
+
+ public TaskRecord saveOrUpdate(TaskRecord taskRecord) {
+ return persist(taskRecord);
+ }
+
+ public List<TaskRecord> findAll() {
+ return list(namedQuery("org.onap.vnfsdk.functest.models.TaskRecord.findAll"));
+ }
+
+ public List<TaskRecord> findByTaskID(String taskID) {
+ StringBuilder builder = new StringBuilder("%");
+ builder.append(taskID).append("%");
+ return list(
+ namedQuery("org.onap.vnfsdk.functest.models.TaskRecord.findByTaskID")
+ .setParameter("taskID", builder.toString())
+ );
+ }
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/Environment.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/Environment.java
index b63e49b..b22be82 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/Environment.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/Environment.java
@@ -1,67 +1,67 @@
-/*
- * Copyright 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openo.vnfsdk.functest.externalservice.entity;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class Environment {
-
- @JsonProperty("remoteIp")
- private String remoteIp;
-
- @JsonProperty("userName")
- private String userName;
-
- @JsonProperty("password")
- private String password;
-
- @JsonProperty("path")
- private String path;
-
- public String getRemoteIp() {
- return remoteIp;
- }
-
- public void setRemoteIp(String remoteIp) {
- this.remoteIp = remoteIp;
- }
-
- public String getUserName() {
- return userName;
- }
-
- public void setUserName(String userName) {
- this.userName = userName;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public String getPath() {
- return path;
- }
-
- public void setPath(String path) {
- this.path = path;
- }
-
-}
+/*
+ * Copyright 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnfsdk.functest.externalservice.entity;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class Environment {
+
+ @JsonProperty("remoteIp")
+ private String remoteIp;
+
+ @JsonProperty("userName")
+ private String userName;
+
+ @JsonProperty("password")
+ private String password;
+
+ @JsonProperty("path")
+ private String path;
+
+ public String getRemoteIp() {
+ return remoteIp;
+ }
+
+ public void setRemoteIp(String remoteIp) {
+ this.remoteIp = remoteIp;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/EnvironmentMap.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/EnvironmentMap.java
index e2a9ebb..c9584e2 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/EnvironmentMap.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/EnvironmentMap.java
@@ -1,53 +1,53 @@
-/*
- * Copyright 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openo.vnfsdk.functest.externalservice.entity;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-public class EnvironmentMap {
-
- private static Map<UUID, Environment> envmap = new HashMap<UUID, Environment>();
-
- private static EnvironmentMap oInstance = new EnvironmentMap();
-
- private EnvironmentMap() {
- // Empty nothing to do
- }
-
- public static synchronized EnvironmentMap getInstance() {
- return oInstance;
- }
-
- public synchronized Map<UUID, Environment> getEnvmap() {
- return envmap;
- }
-
- public synchronized void addEnv(UUID uuid, Environment envobj) {
- envmap.put(uuid, envobj);
- }
-
- public synchronized void delEnv(UUID uuid) {
- envmap.remove(uuid);
- }
-
- public synchronized Environment getEnv(UUID uuid) {
- return envmap.get(uuid);
- }
-
-}
+/*
+ * Copyright 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnfsdk.functest.externalservice.entity;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+public class EnvironmentMap {
+
+ private static Map<UUID, Environment> envMap = new HashMap<UUID, Environment>();
+
+ private static EnvironmentMap oInstance = new EnvironmentMap();
+
+ private EnvironmentMap() {
+ // Empty nothing to do
+ }
+
+ public static synchronized EnvironmentMap getInstance() {
+ return oInstance;
+ }
+
+ public synchronized Map<UUID, Environment> getEnvmap() {
+ return envMap;
+ }
+
+ public synchronized void addEnv(UUID uuid, Environment envobj) {
+ envMap.put(uuid, envobj);
+ }
+
+ public synchronized void delEnv(UUID uuid) {
+ envMap.remove(uuid);
+ }
+
+ public synchronized Environment getEnv(UUID uuid) {
+ return envMap.get(uuid);
+ }
+
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatus.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/OperationStatus.java
index 7856563..3bab7d0 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatus.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/OperationStatus.java
@@ -1,53 +1,54 @@
-/*
- * Copyright 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openo.vnfsdk.functest.externalservice.entity;
-
-public class OperationStatus {
-
- private boolean operFinished = false;
- private String operResultMessage;
-
- public enum operResultCode {
- SUCCESS, FAILURE, NOTFOUND
- };
-
- operResultCode oResultCode;
-
- public operResultCode getoResultCode() {
- return oResultCode;
- }
-
- public void setoResultCode(operResultCode oResultCode) {
- this.oResultCode = oResultCode;
- }
-
- public String getOperResultMessage() {
- return operResultMessage;
- }
-
- public void setOperResultMessage(String operResultMessage) {
- this.operResultMessage = operResultMessage;
- }
-
- public boolean isOperFinished() {
- return operFinished;
- }
-
- public void setOperFinished(boolean operFinished) {
- this.operFinished = operFinished;
- }
-}
+/*
+ * Copyright 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnfsdk.functest.externalservice.entity;
+
+public class OperationStatus {
+
+ operResultCode oResultCode;
+ private boolean operFinished = false;
+ private String operResultMessage;
+
+ ;
+
+ public operResultCode getoResultCode() {
+ return oResultCode;
+ }
+
+ public void setoResultCode(operResultCode oResultCode) {
+ this.oResultCode = oResultCode;
+ }
+
+ public String getOperResultMessage() {
+ return operResultMessage;
+ }
+
+ public void setOperResultMessage(String operResultMessage) {
+ this.operResultMessage = operResultMessage;
+ }
+
+ public boolean isOperFinished() {
+ return operFinished;
+ }
+
+ public void setOperFinished(boolean operFinished) {
+ this.operFinished = operFinished;
+ }
+
+ public enum operResultCode {
+ SUCCESS, FAILURE, NOTFOUND
+ }
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java
index 7cadec4..7ba71cb 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java
@@ -1,74 +1,73 @@
-/*
- * Copyright 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openo.vnfsdk.functest.externalservice.entity;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ws.rs.core.Response;
-
-import org.openo.vnfsdk.functest.util.RestResponseUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class OperationStatusHandler {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(OperationStatusHandler.class);
-
- private static Map<UUID, OperationStatus> operStatusMap = new HashMap<UUID, OperationStatus>();
-
- private static OperationStatusHandler oInstance = new OperationStatusHandler();
-
- private OperationStatusHandler() {
- // Empty nothing to do
- }
-
- public static synchronized OperationStatusHandler getInstance() {
- return oInstance;
- }
-
- public synchronized Map<UUID, OperationStatus> getOperStatusMap() {
- return operStatusMap;
- }
-
- public synchronized void setOperStatusMap(UUID uuid, OperationStatus inputOperStatusMap) {
- operStatusMap.put(uuid, inputOperStatusMap);
- }
-
- public Response getOperationStatus(UUID uuid) {
-
- if(getOperStatusMap().containsKey(uuid)) {
-
- OperationStatus operstatus = getOperStatusMap().get(uuid);
- LOGGER.info("Operation Finished?" + operstatus.isOperFinished());
- LOGGER.info("Operation Result Message" + operstatus.getOperResultMessage());
-
- return RestResponseUtil.getSuccessResponse(operstatus);
- } else {
- OperationStatus operstatus = new OperationStatus();
- operstatus.setOperFinished(true);
- operstatus.setoResultCode(OperationStatus.operResultCode.NOTFOUND);
- LOGGER.error("uuid not found");
-
- return RestResponseUtil.getSuccessResponse(operstatus);
-
- }
-
- }
-
-}
+/*
+ * Copyright 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnfsdk.functest.externalservice.entity;
+
+import org.onap.vnfsdk.functest.util.RestResponseUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.core.Response;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+public class OperationStatusHandler {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(OperationStatusHandler.class);
+
+ private static Map<UUID, OperationStatus> operStatusMap = new HashMap<UUID, OperationStatus>();
+
+ private static OperationStatusHandler oInstance = new OperationStatusHandler();
+
+ private OperationStatusHandler() {
+ // Empty nothing to do
+ }
+
+ public static synchronized OperationStatusHandler getInstance() {
+ return oInstance;
+ }
+
+ public synchronized Map<UUID, OperationStatus> getOperStatusMap() {
+ return operStatusMap;
+ }
+
+ public synchronized void setOperStatusMap(UUID uuid, OperationStatus inputOperStatusMap) {
+ operStatusMap.put(uuid, inputOperStatusMap);
+ }
+
+ public Response getOperationStatus(UUID uuid) {
+
+ if (getOperStatusMap().containsKey(uuid)) {
+
+ OperationStatus operstatus = getOperStatusMap().get(uuid);
+ LOGGER.info("Operation Finished?" + operstatus.isOperFinished());
+ LOGGER.info("Operation Result Message" + operstatus.getOperResultMessage());
+
+ return RestResponseUtil.getSuccessResponse(operstatus);
+ } else {
+ OperationStatus operstatus = new OperationStatus();
+ operstatus.setOperFinished(true);
+ operstatus.setoResultCode(OperationStatus.operResultCode.NOTFOUND);
+ LOGGER.error("uuid not found");
+
+ return RestResponseUtil.getSuccessResponse(operstatus);
+
+ }
+
+ }
+
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceNode.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceNode.java
index 0d38f06..ca647d5 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceNode.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceNode.java
@@ -14,10 +14,9 @@
* limitations under the License.
*/
-package org.openo.vnfsdk.functest.externalservice.entity;
+package org.onap.vnfsdk.functest.externalservice.entity;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -27,8 +26,8 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class ServiceNode {
-
- private String ip;
+
+ private String ip;
private String port;
@@ -58,5 +57,5 @@ public class ServiceNode {
this.ttl = ttl;
}
-
+
}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceRegisterEntity.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceRegisterEntity.java
index c6d885a..1cf0585 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceRegisterEntity.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/ServiceRegisterEntity.java
@@ -14,24 +14,23 @@
* limitations under the License.
*/
-package org.openo.vnfsdk.functest.externalservice.entity;
-
-import java.util.ArrayList;
-import java.util.List;
+package org.onap.vnfsdk.functest.externalservice.entity;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
+import java.util.ArrayList;
+import java.util.List;
+
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class ServiceRegisterEntity {
-
- private String serviceName;
+
+ private String serviceName;
private String version;
@@ -91,11 +90,10 @@ public class ServiceRegisterEntity {
this.nodes = nodes;
}
-
public void setSingleNode(String ip, String port, int ttl) {
ServiceNode node = new ServiceNode();
- if(ip != null && ip.length() > 0) {
+ if (ip != null && ip.length() > 0) {
node.setIp(ip);
} else {
node.setIp(null);
diff --git a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/models/CaseRecord.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/models/CaseRecord.java
new file mode 100644
index 0000000..683cf2d
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/models/CaseRecord.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2018 Intel Corporation Intellectual Property
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnfsdk.functest.models;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import javax.persistence.*;
+import java.util.Objects;
+
+@Entity
+@Table(name = "CaseRecord")
+@NamedQueries(
+ {
+ @NamedQuery(
+ name = "org.onap.vnfsdk.functest.models.CaseRecord.findAll",
+ query = "SELECT c FROM CaseRecord c"
+ )
+ })
+public class CaseRecord {
+ @Id
+ private String taskID;
+
+ @Column(name = "funcID")
+ private String funcID;
+
+ @Column(name = "testID", nullable = false)
+ private String testID;
+
+ @Column(name = "testResult", nullable = false)
+ private String testResult;
+
+ @Column(name = "testDescription", nullable = false)
+ private String testDescription;
+
+ public CaseRecord() {
+ }
+
+ public CaseRecord(String taskID, String funcID, String testID, String testResult, String testDescription) {
+ this.taskID = taskID;
+ this.funcID = funcID;
+ this.testID = testID;
+ this.testResult = testResult;
+ this.testDescription = testDescription;
+ }
+
+ @JsonProperty
+ public String getTaskID() {
+ return taskID;
+ }
+
+ @JsonProperty
+ public void setTaskID(String taskID) {
+ this.taskID = taskID;
+ }
+
+ @JsonProperty
+ public String getFuncID() {
+ return funcID;
+ }
+
+ @JsonProperty
+ public void setFuncID(String funcID) {
+ this.funcID = funcID;
+ }
+
+ @JsonProperty
+ public String getTestID() {
+ return testID;
+ }
+
+ @JsonProperty
+ public void setTestID(String testID) {
+ this.testID = testID;
+ }
+
+ @JsonProperty
+ public String getTestResult() {
+ return testResult;
+ }
+
+ @JsonProperty
+ public void setTestResult(String testResult) {
+ this.testResult = testResult;
+ }
+
+ @JsonProperty
+ public String getTestDescription() {
+ return testDescription;
+ }
+
+ @JsonProperty
+ public void setTestDescription(String testDescription) {
+ this.testDescription = testDescription;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof CaseRecord)) {
+ return false;
+ }
+
+ final CaseRecord that = (CaseRecord) o;
+
+ return Objects.equals(this.taskID, that.taskID);
+ }
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/models/TaskRecord.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/models/TaskRecord.java
new file mode 100644
index 0000000..7fda025
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/models/TaskRecord.java
@@ -0,0 +1,202 @@
+/*
+ * Copyright (c) 2018 Intel Corporation Intellectual Property
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnfsdk.functest.models;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import javax.persistence.*;
+import java.util.Objects;
+
+@Entity
+@Table(name = "TaskRecord")
+@NamedQueries(
+ {
+ @NamedQuery(
+ name = "org.onap.vnfsdk.functest.models.TaskRecord.findAll",
+ query = "SELECT t FROM TaskRecord t"
+ ),
+ @NamedQuery(name = "org.onap.vnfsdk.functest.models.TaskRecord.findByTaskID",
+ query = "SELECT t FROM TaskRecord t WHERE t.taskID LIKE :taskID"
+ )
+ })
+public class TaskRecord {
+ @Id
+ private String packageID;
+
+ @Column(name = "taskID", nullable = false)
+ private String taskID;
+
+ @Column(name = "envID", nullable = false)
+ private String envID;
+
+ @Column(name = "uploadID", nullable = false)
+ private String uploadID;
+
+ @Column(name = "operID", nullable = false)
+ private String operID;
+
+ @Column(name = "funcID")
+ private String funcID;
+
+ @Column(name = "status", nullable = false)
+ private String status;
+
+ @Column(name = "operFinished", nullable = false)
+ private String operFinished;
+
+ @Column(name = "operResult", nullable = false)
+ private String operResult;
+
+ @Column(name = "operResultMessage")
+ private String operResultMessage;
+
+ public TaskRecord() {
+ }
+
+ public TaskRecord(String packageID, String taskID, String envID, String uploadID, String operID, String funcID, String status, String operFinished, String operResult, String operResultMessage) {
+ this.packageID = packageID;
+ this.taskID = taskID;
+ this.envID = envID;
+ this.uploadID = uploadID;
+ this.operID = operID;
+ this.funcID = funcID;
+ this.status = status;
+ this.operFinished = operFinished;
+ this.operResult = operResult;
+ this.operResultMessage = operResultMessage;
+ }
+
+ @JsonProperty
+ public String getPackageID() {
+ return packageID;
+ }
+
+ @JsonProperty
+ public void setPackageID(String packageID) {
+ this.packageID = packageID;
+ }
+
+ @JsonProperty
+ public String getTaskID() {
+ return taskID;
+ }
+
+ @JsonProperty
+ public void setTaskID(String taskID) {
+ this.taskID = taskID;
+ }
+
+ @JsonProperty
+ public String getEnvID() {
+ return envID;
+ }
+
+ @JsonProperty
+ public void setEnvID(String envID) {
+ this.envID = envID;
+ }
+
+ @JsonProperty
+ public String getUploadID() {
+ return uploadID;
+ }
+
+ @JsonProperty
+ public void setUploadID(String uploadID) {
+ this.uploadID = uploadID;
+ }
+
+ @JsonProperty
+ public String getOperID() {
+ return operID;
+ }
+
+ @JsonProperty
+ public void setOperID(String operID) {
+ this.operID = operID;
+ }
+
+ @JsonProperty
+ public String getFuncID() {
+ return funcID;
+ }
+
+ @JsonProperty
+ public void setFuncID(String funcID) {
+ this.funcID = funcID;
+ }
+
+ @JsonProperty
+ public String getStatus() {
+ return status;
+ }
+
+ @JsonProperty
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ @JsonProperty
+ public String getOperFinished() {
+ return operFinished;
+ }
+
+ @JsonProperty
+ public void setOperFinished(String operFinished) {
+ this.operFinished = operFinished;
+ }
+
+ @JsonProperty
+ public String getOperResult() {
+ return operResult;
+ }
+
+ @JsonProperty
+ public void setOperResult(String operResult) {
+ this.operResult = operResult;
+ }
+
+ @JsonProperty
+ public String getOperResultMessage() {
+ return operResultMessage;
+ }
+
+ @JsonProperty
+ public void setOperResultMessage(String operResultMessage) {
+ this.operResultMessage = operResultMessage;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof TaskRecord)) {
+ return false;
+ }
+
+ final TaskRecord that = (TaskRecord) o;
+
+ return Objects.equals(this.packageID, that.packageID) &&
+ Objects.equals(this.taskID, that.taskID);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(packageID, taskID);
+ }
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/TestResult.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/TestResult.java
index 4704717..10ab2e6 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/TestResult.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/TestResult.java
@@ -1,54 +1,54 @@
-/*
- * Copyright 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openo.vnfsdk.functest.responsehandler;
-
-/**
- * @author Administrator
- */
-public class TestResult {
-
- private String name;
-
- private String description;
-
- private String status;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getStatus() {
- return status;
- }
-
- public void setStatus(String status) {
- this.status = status;
- }
-
-}
+/*
+ * Copyright 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnfsdk.functest.responsehandler;
+
+/**
+ * @author Administrator
+ */
+public class TestResult {
+
+ private String name;
+
+ private String description;
+
+ private String status;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/TestResultMap.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/TestResultMap.java
new file mode 100644
index 0000000..4f73db1
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/TestResultMap.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2018 Intel Corporation Intellectual Property
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnfsdk.functest.responsehandler;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+public class TestResultMap {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(TestResultMap.class);
+
+ private static Map<UUID, List<TestResult>> testResultMap = new HashMap<UUID, List<TestResult>>();
+
+ private static TestResultMap oInstance = new TestResultMap();
+
+ private TestResultMap() {
+ // Empty nothing to do
+ }
+
+ public static synchronized TestResultMap getInstance() {
+ return oInstance;
+ }
+
+ public synchronized Map<UUID, List<TestResult>> getTestResultMap() {
+ return testResultMap;
+ }
+
+ public synchronized void setTestResultMap(UUID uuid, List<TestResult> inputTestResult) {
+ testResultMap.put(uuid, inputTestResult);
+ }
+
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/TestResultParser.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/TestResultParser.java
index 7de2461..d3a6b39 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/TestResultParser.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/TestResultParser.java
@@ -1,143 +1,146 @@
-/*
- * Copyright 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openo.vnfsdk.functest.responsehandler;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.openo.vnfsdk.functest.FileUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-public class TestResultParser {
-
- private static final String STATUSPASS = "PASS";
-
- private static final String RESULTTAG = "test";
-
- private static final String NAMETAG = "name";
-
- private static final String STATUSTAG = "status";
-
- private static final String KWTAG = "kw";
-
- private static final String DOCTAG = "doc";
-
- private static final Logger logger = LoggerFactory.getLogger(TestResultParser.class);
-
- public List<TestResult> populateResultList(String xmlFile) {
- List<TestResult> resultData = new ArrayList<>();
- if(!FileUtil.checkFileExist(xmlFile)) {
- logger.error("File Not Found !!! :" + xmlFile);
- return resultData;
- }
- parseResultData(xmlFile, resultData);
- return resultData;
- }
-
- private void parseResultData(String xmlFile, List<TestResult> resultData) {
- try {
- Document doc = createDocument(xmlFile);
- NodeList list = doc.getElementsByTagName(RESULTTAG);
- for(int i = 0; i < list.getLength(); i++) {
- Node node = list.item(i);
- if(node.getNodeType() != Node.ELEMENT_NODE) {
- continue;
- }
-
- NamedNodeMap attr = node.getAttributes();
- if(null == attr) {
- continue;
- }
-
- String nameAttr = getNodeValue(attr.getNamedItem(NAMETAG));
- if(null == nameAttr) {
- continue;
- }
-
- String descriptionAttr = nameAttr;
- String statusAttr = STATUSPASS;
- NodeList childlist = node.getChildNodes();
- for(int j = 0; j < childlist.getLength(); j++) {
- Node childNode = childlist.item(j);
- if(childNode.getNodeType() != Node.ELEMENT_NODE) {
- continue;
- }
-
- if(KWTAG == childNode.getNodeName()) {
- NodeList kwNodeList = childNode.getChildNodes();
- for(int k = 0; k < kwNodeList.getLength(); k++) {
- Node descNode = kwNodeList.item(k);
- if(descNode.getNodeType() != Node.ELEMENT_NODE) {
- continue;
- }
-
- if(DOCTAG == descNode.getNodeName()) {
- if(null != descNode.getTextContent()) {
- descriptionAttr = descNode.getTextContent();
- break;
- }
- }
- }
- }
-
- if(STATUSTAG == childNode.getNodeName()) {
- NamedNodeMap statusAttrMap = childNode.getAttributes();
- if(null != statusAttrMap) {
- statusAttr = getNodeValue(statusAttrMap.getNamedItem(STATUSTAG));
- }
- }
- }
-
- TestResult testData = new TestResult();
- testData.setName(nameAttr);
- testData.setDescription(descriptionAttr);
- testData.setStatus(statusAttr);
-
- resultData.add(testData);
- }
- } catch(ParserConfigurationException | SAXException | IOException e) {
- logger.error("Exception while parsing file :" + xmlFile);
- logger.error("Exception while parsing file :", e);
- }
- }
-
- private Document createDocument(String fileName) throws ParserConfigurationException, SAXException, IOException {
- InputStream inputStream = new FileInputStream(fileName);
- DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
- Document doc = docBuilder.parse(inputStream);
- doc.getDocumentElement().normalize();
- return doc;
- }
-
- private String getNodeValue(Node namedItem) {
- return (null != namedItem) ? namedItem.getNodeValue() : null;
- }
-}
+/*
+ * Copyright 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnfsdk.functest.responsehandler;
+
+import org.onap.vnfsdk.functest.FileUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+public class TestResultParser {
+
+ private static final String STATUSPASS = "PASS";
+
+ private static final String RESULTTAG = "test";
+
+ private static final String NAMETAG = "name";
+
+ private static final String STATUSTAG = "status";
+
+ private static final String KWTAG = "kw";
+
+ private static final String DOCTAG = "doc";
+
+ private static final Logger logger = LoggerFactory.getLogger(TestResultParser.class);
+
+ public List<TestResult> populateResultList(String taskID, String xmlFile) {
+ List<TestResult> resultData = new ArrayList<>();
+ if (!FileUtil.checkFileExist(xmlFile)) {
+ logger.error("File Not Found !!! :" + xmlFile);
+ return resultData;
+ }
+ parseResultData(taskID, xmlFile, resultData);
+ return resultData;
+ }
+
+ private void parseResultData(String taskID, String xmlFile, List<TestResult> resultData) {
+ try {
+ Document doc = createDocument(xmlFile);
+ NodeList list = doc.getElementsByTagName(RESULTTAG);
+ for (int i = 0; i < list.getLength(); i++) {
+ Node node = list.item(i);
+ if (node.getNodeType() != Node.ELEMENT_NODE) {
+ continue;
+ }
+
+ NamedNodeMap attr = node.getAttributes();
+ if (null == attr) {
+ continue;
+ }
+
+ String nameAttr = getNodeValue(attr.getNamedItem(NAMETAG));
+ if (null == nameAttr) {
+ continue;
+ }
+
+ String descriptionAttr = nameAttr;
+ String statusAttr = STATUSPASS;
+ NodeList childlist = node.getChildNodes();
+ for (int j = 0; j < childlist.getLength(); j++) {
+ Node childNode = childlist.item(j);
+ if (childNode.getNodeType() != Node.ELEMENT_NODE) {
+ continue;
+ }
+
+ if (KWTAG == childNode.getNodeName()) {
+ NodeList kwNodeList = childNode.getChildNodes();
+ for (int k = 0; k < kwNodeList.getLength(); k++) {
+ Node descNode = kwNodeList.item(k);
+ if (descNode.getNodeType() != Node.ELEMENT_NODE) {
+ continue;
+ }
+
+ if (DOCTAG == descNode.getNodeName()) {
+ if (null != descNode.getTextContent()) {
+ descriptionAttr = descNode.getTextContent();
+ break;
+ }
+ }
+ }
+ }
+
+ if (STATUSTAG == childNode.getNodeName()) {
+ NamedNodeMap statusAttrMap = childNode.getAttributes();
+ if (null != statusAttrMap) {
+ statusAttr = getNodeValue(statusAttrMap.getNamedItem(STATUSTAG));
+ }
+ }
+ }
+
+ TestResult testData = new TestResult();
+ testData.setName(nameAttr);
+ testData.setDescription(descriptionAttr);
+ testData.setStatus(statusAttr);
+
+ resultData.add(testData);
+ }
+
+ TestResultMap.getInstance().setTestResultMap(UUID.fromString(taskID), resultData);
+
+ } catch (ParserConfigurationException | SAXException | IOException e) {
+ logger.error("Exception while parsing file :" + xmlFile);
+ logger.error("Exception while parsing file :", e);
+ }
+ }
+
+ private Document createDocument(String fileName) throws ParserConfigurationException, SAXException, IOException {
+ InputStream inputStream = new FileInputStream(fileName);
+ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+ Document doc = docBuilder.parse(inputStream);
+ doc.getDocumentElement().normalize();
+ return doc;
+ }
+
+ private String getNodeValue(Node namedItem) {
+ return (null != namedItem) ? namedItem.getNodeValue() : null;
+ }
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandler.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandler.java
index 7dd47d7..0dce5a0 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandler.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandler.java
@@ -14,45 +14,38 @@
* limitations under the License.
*/
-package org.openo.vnfsdk.functest.responsehandler;
+package org.onap.vnfsdk.functest.responsehandler;
+import com.google.gson.Gson;
+import com.google.gson.stream.JsonReader;
+import org.onap.vnfsdk.functest.FileUtil;
+import org.onap.vnfsdk.functest.util.RestResponseUtil;
+import org.onap.vnfsdk.functest.util.ZipCompressor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.core.Response;
import java.io.File;
-import java.io.FileInputStream;
+import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.Map;
-import javax.ws.rs.core.Response;
-
-import org.openo.vnfsdk.functest.FileUtil;
-import org.openo.vnfsdk.functest.util.RestResponseUtil;
-import org.openo.vnfsdk.functest.util.ZipCompressor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-
public class VnfFuncTestResponseHandler {
+ private static final Logger logger = LoggerFactory.getLogger(VnfFuncTestResponseHandler.class);
private static int actioninProgress = 21;
-
private static int error = 22;
-
private static String resultFileName = "output.xml";
-
- private static String resultpathkey = "DIR_RESULT";
-
+ private static String resultPathKey = "DIR_RESULT";
private static Map<String, String> mapConfigValues;
-
private static VnfFuncTestResponseHandler vnfFuncRspHandler;
- private static final Logger logger = LoggerFactory.getLogger(VnfFuncTestResponseHandler.class);
-
private VnfFuncTestResponseHandler() {
}
public static VnfFuncTestResponseHandler getInstance() {
- if(vnfFuncRspHandler == null) {
+ if (vnfFuncRspHandler == null) {
vnfFuncRspHandler = new VnfFuncTestResponseHandler();
loadConfigurations();
}
@@ -63,29 +56,43 @@ public class VnfFuncTestResponseHandler {
mapConfigValues = inMapConfigValues;
}
+ @SuppressWarnings("unchecked")
+ private static void loadConfigurations() {
+ String curDir = System.getProperty("user.dir");
+ String confDir = curDir + File.separator + "conf" + File.separator + "robot" + File.separator;
+// ObjectMapper mapper = new ObjectMapper();
+
+ try {
+// mapConfigValues = mapper.readValue(new FileInputStream(confDir + "robotMetaData.json"), Map.class);
+ mapConfigValues = new Gson().fromJson(new JsonReader(new FileReader(confDir + "robotMetaData.json")), Map.class);
+ } catch (IOException e) {
+ logger.error("Reading Json Meta data file failed or file do not exist", e);
+ }
+ }
+
public Response getResponseByFuncTestId(String funcTestId) {
- if((null == mapConfigValues) || (null == mapConfigValues.get(resultpathkey))) {
- logger.warn("Result Store path not configfured !!!");
+ if ((null == mapConfigValues) || (null == mapConfigValues.get(resultPathKey))) {
+ logger.warn("Result Store path not configured !!!");
return RestResponseUtil.getErrorResponse(error);
}
- String resultPath = mapConfigValues.get(resultpathkey);
+ String resultPath = mapConfigValues.get(resultPathKey);
/*
* Check whether file Exists for the Request received !!!
* -----------------------------------------------------
*/
String fileName = resultPath + File.separator + funcTestId;
- if(!FileUtil.checkFileExist(fileName)) {
- logger.warn("Resquested function Test result not avaliable/In-Progress !!!");
+ if (!FileUtil.checkFileExist(fileName)) {
+ logger.warn("Requested function Test result not available/In-Progress !!!");
return RestResponseUtil.getErrorResponse(actioninProgress);
}
String zipFileName = fileName + ".zip";
try {
new ZipCompressor(zipFileName).compress(fileName);
- } catch(IOException e) {
+ } catch (IOException e) {
logger.error("getResponseByFuncTestId ", e);
}
@@ -95,7 +102,7 @@ public class VnfFuncTestResponseHandler {
*/
byte[] byteArrayFile = FileUtil.convertZipFiletoByteArray(zipFileName);
- if(null != byteArrayFile) {
+ if (null != byteArrayFile) {
/*
* Delete Result folders present if Success !!!
@@ -105,40 +112,27 @@ public class VnfFuncTestResponseHandler {
/*
* Later will delete this file
*/
- logger.warn("Resquested function Test result Sucess !!!");
+ logger.warn("Requested function Test result Success !!!");
return RestResponseUtil.getSuccessResponse(byteArrayFile);
} else {
- logger.warn("Resquested function Test result Faiuled !!!");
+ logger.warn("Requested function Test result Failed !!!");
return RestResponseUtil.getErrorResponse(error);
}
}
public Response downloadResults(String funcTestId) {
- if((null == mapConfigValues) || (null == mapConfigValues.get(resultpathkey))) {
- logger.warn("Result Store path not configfured !!!");
+ if ((null == mapConfigValues) || (null == mapConfigValues.get(resultPathKey))) {
+ logger.warn("Result Store path not configured !!!");
return RestResponseUtil.getErrorResponse(error);
}
- String resultPath = mapConfigValues.get(resultpathkey);
+ String resultPath = mapConfigValues.get(resultPathKey);
String resultfileName = resultPath + File.separator + funcTestId + File.separator + resultFileName;
-
+ logger.info(resultfileName);
TestResultParser oTestResultParser = new TestResultParser();
- List<TestResult> resultList = oTestResultParser.populateResultList(resultfileName);
+ List<TestResult> resultList = oTestResultParser.populateResultList(funcTestId, resultfileName);
return (!resultList.isEmpty()) ? RestResponseUtil.getSuccessResponse(resultList)
: RestResponseUtil.getErrorResponse(error);
}
-
- @SuppressWarnings("unchecked")
- private static void loadConfigurations() {
- String curDir = System.getProperty("user.dir");
- String confDir = curDir + File.separator + "conf" + File.separator + "robot" + File.separator;
- ObjectMapper mapper = new ObjectMapper();
- try {
- mapConfigValues = mapper.readValue(new FileInputStream(confDir + "robotMetaData.json"), Map.class);
- } catch(IOException e) {
- logger.error("Reading Json Meta data file failed or file do not exist", e);
- return;
- }
- }
}
diff --git a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/scriptmgr/ScriptManager.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/scriptmgr/ScriptManager.java
new file mode 100644
index 0000000..1dae79f
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/scriptmgr/ScriptManager.java
@@ -0,0 +1,227 @@
+/*
+ * Copyright (c) 2018 Intel Corporation Intellectual Property
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnfsdk.functest.scriptmgr;
+
+import com.google.gson.Gson;
+import org.onap.vnfsdk.functest.FileUtil;
+import org.onap.vnfsdk.functest.TaskExecution;
+import org.onap.vnfsdk.functest.constants.ApplicationConstants;
+import org.onap.vnfsdk.functest.db.TaskMgrCaseTblDAO;
+import org.onap.vnfsdk.functest.db.TaskMgrTaskTblDAO;
+import org.onap.vnfsdk.functest.externalservice.entity.Environment;
+import org.onap.vnfsdk.functest.externalservice.entity.EnvironmentMap;
+import org.onap.vnfsdk.functest.externalservice.entity.OperationStatus;
+import org.onap.vnfsdk.functest.externalservice.entity.OperationStatusHandler;
+import org.onap.vnfsdk.functest.models.CaseRecord;
+import org.onap.vnfsdk.functest.models.TaskRecord;
+import org.onap.vnfsdk.functest.responsehandler.TestResult;
+import org.onap.vnfsdk.functest.responsehandler.TestResultMap;
+import org.onap.vnfsdk.functest.responsehandler.VnfFuncTestResponseHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.core.Response;
+import java.io.*;
+import java.net.URL;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.UUID;
+import java.util.concurrent.*;
+
+public class ScriptManager {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ScriptManager.class);
+ private final TaskMgrTaskTblDAO taskMgrTaskTblDAO;
+ private final TaskMgrCaseTblDAO taskMgrCaseTblDAO;
+
+ public ScriptManager(TaskMgrTaskTblDAO taskMgrTaskTblDAO, TaskMgrCaseTblDAO taskMgrCaseTblDAO) {
+ this.taskMgrTaskTblDAO = taskMgrTaskTblDAO;
+ this.taskMgrCaseTblDAO = taskMgrCaseTblDAO;
+ }
+
+ /**
+ * Convert the stream to File Name<br/>
+ *
+ * @param dirName - Directory name
+ * @param fileName - FileName
+ * @param uploadedInputStream - Input Stream
+ * @return - File Path
+ * @throws IOException - Exception while writing file
+ * @since VNFSDK
+ */
+ public static String storeChunkFileInLocal(String dirName, String fileName, InputStream uploadedInputStream)
+ throws IOException {
+ File tmpDir = new File(dirName);
+ LOGGER.info("tmpdir=" + dirName);
+ if (!tmpDir.exists()) {
+ tmpDir.mkdirs();
+ }
+ StringTokenizer st = new StringTokenizer(fileName, "/");
+ String actualFile = null;
+ while (st.hasMoreTokens()) {
+ actualFile = st.nextToken();
+ }
+ File file = new File(tmpDir + File.separator + actualFile);
+ OutputStream os = null;
+ try {
+ int read = 0;
+ byte[] bytes = new byte[1024];
+ os = new FileOutputStream(file, true);
+ while ((read = uploadedInputStream.read(bytes)) != -1) {
+ os.write(bytes, 0, read);
+ }
+ os.flush();
+ return file.getAbsolutePath();
+ } finally {
+ if (os != null) {
+ os.close();
+ }
+ }
+ }
+
+ public UUID setEnvironment(String env) {
+ LOGGER.info("[Scrip Manager] Set Environment.");
+
+ try {
+
+ // Generate UUID for each environment
+ final UUID envID = UUID.randomUUID();
+
+ // Convert input string to Environment class
+// ObjectMapper mapper = new ObjectMapper();
+// Environment envObj = mapper.readValue(env, Environment.class);
+ Environment envObj = new Gson().fromJson(env, Environment.class);
+ if (null == envObj) {
+ // Converting input to Env object failed
+ return null;
+ }
+
+ // Set to the environment map
+ EnvironmentMap.getInstance().addEnv(envID, envObj);
+ LOGGER.info(EnvironmentMap.getInstance().getEnv(envID).getPassword());
+
+ // Send the envID back
+ return envID;
+
+ } catch (Exception e) {
+ LOGGER.error("Setting the Environment Fail", e);
+ }
+
+ return null;
+ }
+
+ public UUID uploadFuncTestPackage(UUID taskID, UUID envID, String url) {
+ LOGGER.info("[Scrip Manager] Upload Function Test Package.");
+
+ try {
+ URL oracle = new URL(url);
+
+ InputStream fis = new BufferedInputStream(oracle.openStream());
+
+ // Convert the stream to script folder
+ String nl = File.separator;
+ String filePath = storeChunkFileInLocal("temp", "TempFile.zip", fis);
+
+ // Unzip the folder
+ String tempDir = System.getProperty("user.dir") + nl + "temp";
+ List<String> list = FileUtil.unzip(filePath, tempDir);
+ LOGGER.info("File path=" + filePath);
+
+ String[] directories = FileUtil.getDirectory(tempDir);
+ LOGGER.info("tempdir=" + tempDir);
+ if (null != directories && 0 != directories.length) {
+ filePath = tempDir + File.separator + directories[0];
+ } else {
+ filePath = tempDir;
+ }
+
+ // generate UUID for the upload
+ final UUID uploadID = UUID.randomUUID();
+ List<TaskRecord> taskRecordList = taskMgrTaskTblDAO.findByTaskID(taskID.toString());
+ TaskRecord taskRecord = taskRecordList.get(0);
+ taskRecord.setUploadID(uploadID.toString());
+ taskRecord.setOperID(uploadID.toString());
+ taskMgrTaskTblDAO.saveOrUpdate(taskRecord);
+
+ final String finalPath = filePath;
+
+ ExecutorService es = Executors.newFixedThreadPool(3);
+ Future<Integer> future = es.submit(new Callable<Integer>() {
+
+ @Override
+ public Integer call() throws Exception {
+
+ new TaskExecution().uploadScript(finalPath, envID, uploadID);
+ return 0;
+ }
+ });
+
+ try {
+ if (0 == future.get(5, TimeUnit.SECONDS)) {
+ LOGGER.info("ExecutorService Done");
+
+ OperationStatus operStatus = OperationStatusHandler.getInstance().getOperStatusMap().get(uploadID);
+ taskRecord.setOperFinished(operStatus.isOperFinished() ? "True" : "False");
+ taskRecord.setOperResult(operStatus.getoResultCode().toString());
+ taskRecord.setOperResultMessage(operStatus.getOperResultMessage());
+ taskMgrTaskTblDAO.saveOrUpdate(taskRecord);
+ }
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ } catch (TimeoutException e) {
+ LOGGER.info("Time out.");
+ e.printStackTrace();
+ }
+
+ return uploadID;
+
+ } catch (IOException e) {
+ LOGGER.error(ApplicationConstants.RUN_SCRIPT_EXECUTE_CMD, e);
+ }
+
+ return null;
+ }
+
+ public Response getOperationResult(UUID operID) {
+ LOGGER.info("[Script Manager] Query functest Status by ID." + operID);
+
+ return OperationStatusHandler.getInstance().getOperationStatus(operID);
+ }
+
+ public Response downloadResults(UUID taskID) {
+ LOGGER.info("[Script Manager] Download functest Result by ID: " + taskID);
+
+ Response resp = VnfFuncTestResponseHandler.getInstance().downloadResults(taskID.toString());
+
+ try {
+ TestResult testResult = TestResultMap.getInstance().getTestResultMap().get(taskID).get(0);
+
+ CaseRecord caseRecord = taskMgrCaseTblDAO.findByTaskID(taskID.toString());
+ caseRecord.setTestID(testResult.getName());
+ caseRecord.setTestResult(testResult.getStatus());
+ caseRecord.setTestDescription(testResult.getDescription());
+ taskMgrCaseTblDAO.saveOrUpdate(caseRecord);
+ } catch (Exception e) {
+ LOGGER.error("Collect Functest Result by ID Failed.", e);
+ }
+ return resp;
+ }
+
+
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/taskmgr/TaskManager.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/taskmgr/TaskManager.java
new file mode 100644
index 0000000..79e611b
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/taskmgr/TaskManager.java
@@ -0,0 +1,258 @@
+/*
+ * Copyright (c) 2018 Intel Corporation Intellectual Property
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnfsdk.functest.taskmgr;
+
+import com.codahale.metrics.annotation.Timed;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.stream.JsonReader;
+import io.dropwizard.hibernate.UnitOfWork;
+import io.swagger.annotations.*;
+import org.eclipse.jetty.http.HttpStatus;
+import org.onap.vnfsdk.functest.constants.ApplicationConstants;
+import org.onap.vnfsdk.functest.db.TaskMgrCaseTblDAO;
+import org.onap.vnfsdk.functest.db.TaskMgrTaskTblDAO;
+import org.onap.vnfsdk.functest.externalservice.entity.OperationStatus;
+import org.onap.vnfsdk.functest.externalservice.entity.OperationStatusHandler;
+import org.onap.vnfsdk.functest.models.CaseRecord;
+import org.onap.vnfsdk.functest.models.TaskRecord;
+import org.onap.vnfsdk.functest.scriptmgr.ScriptManager;
+import org.onap.vnfsdk.functest.util.RestResponseUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+@Path("/functest/taskmanager")
+@Api(tags = {" Function Test Task Manager "})
+public class TaskManager {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(TaskManager.class);
+
+ private final TaskMgrTaskTblDAO taskMgrTaskTblDAO;
+ private final TaskMgrCaseTblDAO taskMgrCaseTblDAO;
+ private final ScriptManager scriptManager;
+
+ public TaskManager(TaskMgrTaskTblDAO taskMgrTaskTblDAO, TaskMgrCaseTblDAO taskMgrCaseTblDAO, ScriptManager scriptManager) {
+ this.taskMgrTaskTblDAO = taskMgrTaskTblDAO;
+ this.taskMgrCaseTblDAO = taskMgrCaseTblDAO;
+ this.scriptManager = scriptManager;
+ }
+
+ @Path("/onboard")
+ @POST
+ @ApiOperation(value = "Start Onboard Testing")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ //@Timed
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
+ @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error", response = String.class)})
+ @UnitOfWork
+ public Response startOnboardTesting(RequestBody requestBody) {
+ LOGGER.info("[Task Manager] Start Onboard Testing");
+ TaskRecord taskRecord = new TaskRecord();
+ CaseRecord caseRecord = new CaseRecord();
+
+ String packageID = requestBody.packageID;
+
+ try {
+ if (taskMgrTaskTblDAO.findByPackageID(packageID).isPresent()) {
+ throw new Exception("Already Onboard.");
+ } else {
+ initOnboardTesting(taskRecord, caseRecord, packageID);
+ scriptManager.uploadFuncTestPackage(UUID.fromString(taskRecord.getTaskID()), UUID.fromString(taskRecord.getEnvID()), ApplicationConstants.CATALOG_URI);
+ }
+ return RestResponseUtil.getCreateSuccessResponse(UUID.fromString(taskRecord.getTaskID()));
+
+ } catch (Exception e) {
+ if ("Already Onboard.".equals(e.getMessage())) {
+ LOGGER.error("The Package " + packageID + " is already the onboarding package.", e);
+ return RestResponseUtil.getErrorResponse(packageID);
+ } else {
+ LOGGER.error("Start Onboard Testing Fail", e);
+ }
+ }
+ return null;
+ }
+
+ @Path("/status/{taskID}")
+ @GET
+ @ApiOperation(value = "Query Function Test Status by ID")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
+ @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error", response = String.class)})
+ @Timed
+ @UnitOfWork
+ public Response queryTestStatus(@ApiParam(value = "taskID") @PathParam("taskID") String taskID) {
+ LOGGER.info("[Task Manager] Query Function Test Status by ID: " + taskID);
+
+ try {
+
+ List<TaskRecord> taskRecordList = taskMgrTaskTblDAO.findByTaskID(taskID);
+ if (taskRecordList.isEmpty()) {
+ throw new Exception("Task Not Exist.");
+ } else {
+
+ TaskRecord taskRecord = taskRecordList.get(0);
+ UUID operID = UUID.fromString(taskRecord.getOperID());
+
+ LOGGER.info(taskRecord.getOperID());
+ OperationStatus operStatus = OperationStatusHandler.getInstance().getOperStatusMap().get(operID);
+ /**
+ * To check whether the operID belongs to a record in memory.
+ * If so, needs refresh db: retrieve the data from the record in memory and update the db accordingly.
+ * If not, means a historical record in db. Obtain the data from db.
+ * */
+ if (null != operStatus) {
+ taskRecord.setOperFinished(operStatus.isOperFinished() ? "True" : "False");
+ taskRecord.setOperResult(operStatus.getoResultCode().toString());
+ taskRecord.setOperResultMessage(operStatus.getOperResultMessage());
+ taskMgrTaskTblDAO.saveOrUpdate(taskRecord);
+ } else {
+ OperationStatus oldOperStatus = new OperationStatus();
+ oldOperStatus.setoResultCode(OperationStatus.operResultCode.valueOf(taskRecord.getOperResult()));
+ oldOperStatus.setOperResultMessage(taskRecord.getOperResultMessage());
+ oldOperStatus.setOperFinished("True".equals(taskRecord.getOperFinished()));
+ OperationStatusHandler.getInstance().setOperStatusMap(operID, oldOperStatus);
+ }
+ return scriptManager.getOperationResult(operID);
+ }
+ } catch (Exception e) {
+ if ("Task Not Exist.".equals(e.getMessage())) {
+ LOGGER.error("The Task " + taskID + " does not exist..!", e);
+ return RestResponseUtil.getNotFoundResponse(taskID);
+ } else {
+ LOGGER.error("Query Function Test Status by ID Failed.", e);
+ }
+ }
+ return null;
+ }
+
+ @Path("/result/{taskID}")
+ @GET
+ @ApiOperation(value = "Get Function Test Result by ID")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
+ @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error", response = String.class)})
+ @Timed
+ @UnitOfWork
+ public Response collectTaskResult(@ApiParam(value = "taskID") @PathParam("taskID") String taskID) {
+ LOGGER.info("[Task Manager] Collect Function Test Result by ID." + taskID);
+
+ try {
+ CaseRecord caseRecord = taskMgrCaseTblDAO.findByTaskID(taskID);
+ if (null == caseRecord) {
+ throw new Exception("Task Not Exist.");
+ } else {
+ /* To check whether we have already collected the result of Task: taskID. */
+ if ("NOT CREATED".equals(caseRecord.getTestID())) {
+ return scriptManager.downloadResults(UUID.fromString(taskID));
+ } else {
+ CaseRecord oldCaseRecord = new CaseRecord();
+ oldCaseRecord.setTestID(caseRecord.getTestID());
+ oldCaseRecord.setTestResult(caseRecord.getTestResult());
+ oldCaseRecord.setTestDescription(caseRecord.getTestDescription());
+ return RestResponseUtil.getSuccessResponse(oldCaseRecord);
+ }
+ }
+ } catch (Exception e) {
+ if ("Task Not Exist.".equals(e.getMessage())) {
+ LOGGER.error("The Task " + taskID + " does not exist..!", e);
+ return RestResponseUtil.getNotFoundResponse(taskID);
+ } else {
+ LOGGER.error("Collect Function Test Result by ID Failed.", e);
+ }
+ }
+ return null;
+ }
+
+ private void initOnboardTesting(TaskRecord taskRecord, CaseRecord caseRecord, String packageID) {
+ /* Create TaskRecord entry in db */
+ taskRecord.setPackageID(packageID);
+ // Generate UUID for each task
+ final UUID taskID = UUID.randomUUID();
+ taskRecord.setTaskID(taskID.toString());
+ // Setup the environment
+ final UUID envID = scriptManager.setEnvironment(loadEnvConfigurations());
+ taskRecord.setEnvID(envID.toString());
+ taskRecord.setUploadID("NOT CREATED");
+ taskRecord.setOperID("NOT CREATED");
+ taskRecord.setFuncID("");
+ taskRecord.setStatus("CREATED");
+ taskRecord.setOperFinished("False");
+ taskRecord.setOperResult("FAILURE");
+ taskRecord.setOperResultMessage("");
+ taskMgrTaskTblDAO.saveOrUpdate(taskRecord);
+
+ /* Create CaseRecord entry in db */
+ caseRecord.setTaskID(taskID.toString());
+ caseRecord.setFuncID("");
+ caseRecord.setTestID("NOT CREATED");
+ caseRecord.setTestResult("NULL");
+ caseRecord.setTestDescription("");
+ taskMgrCaseTblDAO.saveOrUpdate(caseRecord);
+ }
+
+ private String loadEnvConfigurations() {
+ Map<String, String> envConfigurations;
+ String strEnvConfigurations;
+ String curDir = System.getProperty("user.dir");
+ String confDir = curDir + File.separator + ApplicationConstants.CONF + File.separator + ApplicationConstants.ENVIRONMENT + File.separator;
+
+ try {
+
+ envConfigurations = new Gson().fromJson(new JsonReader(new FileReader(confDir + ApplicationConstants.ENVIRONMENT_JSON)), Map.class);
+ Gson gson = new GsonBuilder().create();
+ strEnvConfigurations = gson.toJson(envConfigurations);
+
+ return strEnvConfigurations;
+ } catch (IOException e) {
+ LOGGER.error("Reading Environment Json data file failed or file does not exist", e);
+ }
+ return null;
+ }
+
+ public static class RequestBody {
+
+ @JsonProperty("packageID")
+ private String packageID;
+
+ public String getPackageID() {
+ return packageID;
+ }
+
+ public void setPackageID(String packageID) {
+ this.packageID = packageID;
+ }
+ }
+
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/GsonUtil.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/util/GsonUtil.java
index 78936da..b453d3c 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/GsonUtil.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/util/GsonUtil.java
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package org.openo.vnfsdk.functest.util;
+package org.onap.vnfsdk.functest.util;
+
+import com.google.gson.Gson;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
-import com.google.gson.Gson;
-
public class GsonUtil {
private GsonUtil() {
@@ -41,7 +41,7 @@ public class GsonUtil {
*/
public static String objectToString(Object obj) {
Gson gson = new Gson();
- if(obj != null) {
+ if (obj != null) {
return gson.toJson(obj);
} else {
return null;
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/RestResponseUtil.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/util/RestResponseUtil.java
index 1c5404f..40ab57e 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/RestResponseUtil.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/util/RestResponseUtil.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.openo.vnfsdk.functest.util;
+package org.onap.vnfsdk.functest.util;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
@@ -25,19 +25,27 @@ public class RestResponseUtil {
}
public static Response getSuccessResponse(Object obj) {
- if(obj != null) {
+ if (obj != null) {
return Response.ok(GsonUtil.objectToString(obj)).build();
} else {
return Response.ok().build();
}
}
- public static Response getCreateSussceeResponse(Object obj) {
+ public static Response getCreateSuccessResponse(Object obj) {
return Response.status(Status.CREATED).entity(obj).build();
}
+ public static Response getNotFoundResponse(Object obj) {
+ if (obj != null) {
+ return Response.status(Status.NOT_FOUND).entity(GsonUtil.objectToString(obj)).build();
+ } else {
+ return Response.serverError().build();
+ }
+ }
+
public static Response getErrorResponse(Object obj) {
- if(obj != null) {
+ if (obj != null) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(GsonUtil.objectToString(obj)).build();
} else {
return Response.serverError().build();
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/ZipCompressor.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/util/ZipCompressor.java
index 94773b3..de2875e 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/ZipCompressor.java
+++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/util/ZipCompressor.java
@@ -14,22 +14,17 @@
* limitations under the License.
*/
-package org.openo.vnfsdk.functest.util;
+package org.onap.vnfsdk.functest.util;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
import java.util.zip.CRC32;
import java.util.zip.CheckedOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
public class ZipCompressor {
public static final Logger LOG = LoggerFactory.getLogger(ZipCompressor.class);
@@ -44,13 +39,13 @@ public class ZipCompressor {
/**
* compress file according file path.
- *
+ *
* @param srcPathName file path name
* @throws IOException
*/
public void compress(String srcPathName) throws IOException {
File file = new File(srcPathName);
- if(!file.exists()) {
+ if (!file.exists()) {
throw new FileNotFoundException(srcPathName + "not exist!");
}
try {
@@ -60,13 +55,13 @@ public class ZipCompressor {
String basedir = "";
compress(file, out, basedir);
out.close();
- } catch(Exception e1) {
+ } catch (Exception e1) {
throw new IOException(e1);
}
}
private void compress(File file, ZipOutputStream out, String basedir) {
- if(file.isDirectory()) {
+ if (file.isDirectory()) {
LOG.info("compress: " + basedir + file.getName());
this.compressDirectory(file, out, basedir);
} else {
@@ -76,18 +71,18 @@ public class ZipCompressor {
}
private void compressDirectory(File dir, ZipOutputStream out, String basedir) {
- if(!dir.exists()) {
+ if (!dir.exists()) {
return;
}
File[] files = dir.listFiles();
- for(int i = 0; i < files.length; i++) {
+ for (int i = 0; i < files.length; i++) {
compress(files[i], out, basedir + dir.getName() + "/");
}
}
private void compressFile(File file, ZipOutputStream out, String basedir) {
- if(!file.exists()) {
+ if (!file.exists()) {
return;
}
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file))) {
@@ -97,11 +92,11 @@ public class ZipCompressor {
ZipEntry entry = new ZipEntry(basedir + file.getName());
out.putNextEntry(entry);
int count;
- while((count = bis.read(data, 0, BUFFER)) != -1) {
+ while ((count = bis.read(data, 0, BUFFER)) != -1) {
out.write(data, 0, count);
}
bis.close();
- } catch(IOException e) {
+ } catch (IOException e) {
LOG.info("Exception wile compress file" + file.getAbsolutePath(), e);
}
}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/ServiceRegistration.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/ServiceRegistration.java
deleted file mode 100644
index f6cffba..0000000
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/ServiceRegistration.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openo.vnfsdk.functest.common;
-
-import org.openo.vnfsdk.functest.externalservice.entity.ServiceRegisterEntity;
-import org.openo.vnfsdk.functest.externalservice.msb.MicroserviceBusConsumer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ServiceRegistration implements Runnable {
-
- private final ServiceRegisterEntity funcTestEntity = new ServiceRegisterEntity();
-
- private static final Logger LOG = LoggerFactory.getLogger(ServiceRegistration.class);
-
- public ServiceRegistration() {
- initServiceEntity();
- }
-
- @Override
- public void run() {
- LOG.info("start extsys microservice register");
- boolean flag = false;
- int retry = 0;
-
- while(!flag) {
- LOG.info("VNF-SDK function test microservice register.retry:" + retry);
- retry++;
-
- flag = MicroserviceBusConsumer.registerService(funcTestEntity);
- if(retry >= 1000) {
- flag = true;
- }
-
- if(flag == false) {
- LOG.warn("microservice register failed, sleep 30S and try again.");
- threadSleep(30000);
- } else {
- LOG.info("microservice register success!");
- break;
- }
- }
- LOG.info("VNF-SDK function test microservice register end.");
- }
-
- private void threadSleep(int second) {
- LOG.info("start sleep ....");
- try {
- Thread.sleep(second);
- } catch(InterruptedException error) {
- LOG.error("thread sleep error.errorMsg:", error);
- Thread.currentThread().interrupt();
- }
- LOG.info("sleep end .");
- }
-
- private void initServiceEntity() {
- funcTestEntity.setServiceName("vnfsdk");
- funcTestEntity.setProtocol("REST");
- funcTestEntity.setVersion("v1");
- funcTestEntity.setUrl("/openoapi/vnfsdk/v1");
- funcTestEntity.setSingleNode(Config.getConfigration().getServiceIp(), "8701", 0);
- funcTestEntity.setVisualRange("1");
- }
-}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusConsumer.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusConsumer.java
deleted file mode 100644
index 7c74545..0000000
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusConsumer.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openo.vnfsdk.functest.externalservice.msb;
-
-import javax.ws.rs.ProcessingException;
-
-import org.glassfish.jersey.client.ClientConfig;
-import org.openo.vnfsdk.functest.common.Config;
-import org.openo.vnfsdk.functest.externalservice.entity.ServiceRegisterEntity;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
-
-public class MicroserviceBusConsumer {
-
- private static final Logger LOG = LoggerFactory.getLogger(MicroserviceBusConsumer.class);
-
- private MicroserviceBusConsumer() {
-
- }
-
- public static boolean registerService(ServiceRegisterEntity entity) {
- ClientConfig config = new ClientConfig();
- try {
- MicroserviceBusRest resourceserviceproxy = ConsumerFactory
- .createConsumer(Config.getConfigration().getMsbServerAddr(), config, MicroserviceBusRest.class);
- resourceserviceproxy.registerService("false", entity);
- } catch(ProcessingException error) {
- LOG.error("Microservice register failed!", error);
- return false;
- }
- return true;
- }
-}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusRest.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusRest.java
deleted file mode 100644
index 1433605..0000000
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusRest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openo.vnfsdk.functest.externalservice.msb;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-
-import org.openo.vnfsdk.functest.externalservice.entity.ServiceRegisterEntity;
-
-@Path("/openoapi/microservices/v1/services")
-public interface MicroserviceBusRest {
-
- @Path("")
- @POST
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public ServiceRegisterEntity registerService(@QueryParam("createOrUpdate") String createOrUpdate,
- ServiceRegisterEntity entity);
-}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/resource/CommonManager.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/resource/CommonManager.java
deleted file mode 100644
index 937073b..0000000
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/resource/CommonManager.java
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
- * Copyright 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openo.vnfsdk.functest.resource;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
-import java.util.List;
-import java.util.StringTokenizer;
-import java.util.UUID;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import org.eclipse.jetty.http.HttpStatus;
-import org.openo.vnfsdk.functest.FileUtil;
-import org.openo.vnfsdk.functest.TaskExecution;
-import org.openo.vnfsdk.functest.constants.ApplicationConstants;
-import org.openo.vnfsdk.functest.externalservice.entity.Environment;
-import org.openo.vnfsdk.functest.externalservice.entity.EnvironmentMap;
-import org.openo.vnfsdk.functest.externalservice.entity.OperationStatusHandler;
-import org.openo.vnfsdk.functest.responsehandler.VnfFuncTestResponseHandler;
-import org.openo.vnfsdk.functest.util.RestResponseUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.codahale.metrics.annotation.Timed;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
-
-@Path("/functest")
-@Api(tags = {" function test Management "})
-public class CommonManager {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(CommonManager.class);
-
- @POST
- @Path("/setenv")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Timed
- public Response setEnvironment(String env) {
- LOGGER.info("set Environment");
-
- try {
-
- // Generate UUID for each environment
- final UUID uniqueKey = UUID.randomUUID();
-
- // Convert input string to Environment class
- ObjectMapper mapper = new ObjectMapper();
- Environment envObj = mapper.readValue(env, Environment.class);
- if(null == envObj) {
- // Converting input to Env object failed
- return null;
- }
-
- // Set to the environment map
- EnvironmentMap.getInstance().addEnv(uniqueKey, envObj);
-
- // Send REST response
- return RestResponseUtil.getSuccessResponse(uniqueKey);
-
- } catch(Exception e) {
- LOGGER.error("Setting the Environment Fail", e);
- }
-
- return null;
- }
-
- @Path("/upload/{functestEnvId}")
- @POST
- @ApiOperation(value = "upload the function test")
- @Produces(MediaType.APPLICATION_JSON)
- @ApiResponses(value = {
- @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
- @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
- @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error", response = String.class)})
- @Timed
- public Response uploadFuncTestPackage(@PathParam("functestEnvId") String functestEnvId,
- @HeaderParam("URL") String url) {
- LOGGER.info("Upload function test package");
-
- try {
- URL oracle = new URL(url);
-
- InputStream fis = new BufferedInputStream(oracle.openStream());
-
- // Convert the stream to script folder
- String nl = File.separator;
- String filePath = storeChunkFileInLocal("temp", "TempFile.zip", fis);
-
- // Unzip the folder
- String tempDir = System.getProperty("user.dir") + nl + "temp";
- List<String> list = FileUtil.unzip(filePath, tempDir);
- LOGGER.info("File path=" + filePath);
-
- String[] directories = FileUtil.getDirectory(tempDir);
- if(null != directories) {
- filePath = tempDir + File.separator + directories[0];
- }
-
- // convert uuid string to UUID
- final UUID uuidEnv = UUID.fromString(functestEnvId);
- // generate UUID for the upload
- final UUID uuidUpload = UUID.randomUUID();
-
- final String finalPath = filePath;
- ExecutorService es = Executors.newFixedThreadPool(3);
- es.submit(new Callable<Integer>() {
-
- @Override
- public Integer call() throws Exception {
-
- new TaskExecution().uploadScript(finalPath, uuidEnv, uuidUpload);
- return 0;
- }
- });
-
- // Send REST response
- return RestResponseUtil.getSuccessResponse(uuidUpload);
-
- } catch(IOException e) {
- LOGGER.error(ApplicationConstants.RUN_SCRIPT_EXECUTE_CMD, e);
- }
-
- return null;
- }
-
- @Path("/{uploadUUID}/{envUUID}/{frameworktype}")
- @POST
- @ApiOperation(value = "execute the function test")
- @Produces(MediaType.APPLICATION_JSON)
- @ApiResponses(value = {
- @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
- @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
- @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error", response = String.class)})
- @Timed
- public Response executeFunctionTest(@PathParam("envUUID") String functestEnvId,
- @PathParam("uploadUUID") String uploadId, @PathParam("frameworktype") String frameworktype) {
- LOGGER.info("Execute function test");
-
- try {
-
- final UUID envUUID = UUID.fromString(functestEnvId);
-
- // generate UUID for execute
- final UUID executeUUID = UUID.randomUUID();
-
- ExecutorService es = Executors.newFixedThreadPool(3);
- es.submit(new Callable<Integer>() {
-
- @Override
- public Integer call() throws Exception {
-
- new TaskExecution().executeRobotScript(envUUID, executeUUID);
- return 0;
- }
- });
-
- // Send REST response
- return RestResponseUtil.getSuccessResponse(executeUUID);
-
- } catch(Exception e) {
- LOGGER.error(ApplicationConstants.RUN_SCRIPT_EXECUTE_CMD, e);
- }
-
- return null;
- }
-
- @Path("")
- @POST
- @ApiOperation(value = "execute the function test")
- @Produces(MediaType.APPLICATION_JSON)
- @ApiResponses(value = {
- @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
- @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
- @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error", response = String.class)})
- @Timed
- public Response executeFuncTest(InputStream csarInputStream) {
- LOGGER.info("execute function test");
-
- try {
-
- // Upload the script and execute the script and run command
- final UUID uniqueKey = UUID.randomUUID();
-
- // Convert the stream to script folder
- String nl = File.separator;
- String filePath =
- storeChunkFileInLocal("package" + nl + uniqueKey.toString(), "TempFile.rar", csarInputStream);
-
- // Unzip the folder
- String tempDir = System.getProperty("user.dir") + nl + "package" + nl + uniqueKey + nl + "temp";
- FileUtil.unzip(filePath, tempDir);
- LOGGER.info("File path=" + filePath);
-
- filePath = tempDir + File.separator + "RobotScript";
- if(!FileUtil.checkFileExist(filePath)) {
- return RestResponseUtil.getErrorResponse(null);
- }
-
- final String finalPath = filePath;
- ExecutorService es = Executors.newFixedThreadPool(3);
- es.submit(new Callable<Integer>() {
-
- public Integer call() throws Exception {
-
- new TaskExecution().executeScript(finalPath, uniqueKey);
- return 0;
- }
- });
-
- // Send REST response
- return RestResponseUtil.getSuccessResponse(uniqueKey.toString());
-
- } catch(IOException e) {
- LOGGER.error(ApplicationConstants.RUN_SCRIPT_EXECUTE_CMD, e);
- }
-
- return null;
- }
-
- @Path("/{functestId}")
- @GET
- @ApiOperation(value = "get function test result by id")
- @Produces(MediaType.APPLICATION_JSON)
- @ApiResponses(value = {
- @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
- @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
- @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error", response = String.class)})
- @Timed
- public Response queryResultByFuncTest(@ApiParam(value = "functestId") @PathParam("functestId") String instanceId) {
- LOGGER.info("query functest result by id." + instanceId);
- // Query VNF Function test result by function test ID
- return VnfFuncTestResponseHandler.getInstance().getResponseByFuncTestId(instanceId);
- }
-
- @Path("/status/{operationId}")
- @GET
- @ApiOperation(value = "get function test result by id")
- @Produces(MediaType.APPLICATION_JSON)
- @ApiResponses(value = {
- @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
- @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
- @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error", response = String.class)})
- @Timed
- public Response getOperationResult(@ApiParam(value = "operationId") @PathParam("operationId") String operationId) {
- LOGGER.info("Query functest status by id." + operationId);
-
- return OperationStatusHandler.getInstance().getOperationStatus(UUID.fromString(operationId));
- }
-
- @Path("/download/{functestId}")
- @GET
- @ApiOperation(value = "get function test result by id")
- @Produces(MediaType.APPLICATION_JSON)
- @ApiResponses(value = {
- @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
- @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
- @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error", response = String.class)})
- @Timed
- public Response downloadResults(@ApiParam(value = "functestId") @PathParam("functestId") String funcTestId) {
- LOGGER.info("query functest result by id." + funcTestId);
- return VnfFuncTestResponseHandler.getInstance().downloadResults(funcTestId);
- }
-
- /**
- * Convert the stream to File Name<br/>
- *
- * @param dirName - Directory name
- * @param fileName - FileName
- * @param uploadedInputStream - Input Stream
- * @return - File Path
- * @throws IOException - Exception while writing file
- * @since VNFSDK
- */
- public String storeChunkFileInLocal(String dirName, String fileName, InputStream uploadedInputStream)
- throws IOException {
- File tmpDir = new File(dirName);
- LOGGER.info("tmpdir=" + dirName);
- if(!tmpDir.exists()) {
- tmpDir.mkdirs();
- }
- StringTokenizer st = new StringTokenizer(fileName, "/");
- String actualFile = null;
- while(st.hasMoreTokens()) {
- actualFile = st.nextToken();
- }
- File file = new File(tmpDir + File.separator + actualFile);
- OutputStream os = null;
- try {
- int read = 0;
- byte[] bytes = new byte[1024];
- os = new FileOutputStream(file, true);
- while((read = uploadedInputStream.read(bytes)) != -1) {
- os.write(bytes, 0, read);
- }
- os.flush();
- return file.getAbsolutePath();
- } finally {
- if(os != null) {
- os.close();
- }
- }
- }
-
-}
diff --git a/vnf-sdk-function-test/src/main/resources/migrations.xml b/vnf-sdk-function-test/src/main/resources/migrations.xml
new file mode 100644
index 0000000..9ec5510
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/resources/migrations.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<databaseChangeLog
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
+ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
+ http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
+
+ <changeSet id="1" author="Kailun Qin">
+ <createTable tableName="TaskRecord">
+ <column name="packageID" type="varchar(255)">
+ <constraints primaryKey="true" nullable="false"/>
+ </column>
+ <column name="taskID" type="varchar(255)">
+ <constraints unique="true" foreignKeyName="CaseRecord.taskID" nullable="false"/>
+ </column>
+ <column name="envID" type="varchar(255)">
+ <constraints nullable="false"/>
+ </column>
+ <column name="uploadID" type="varchar(255)">
+ <constraints nullable="false"/>
+ </column>
+ <column name="operID" type="varchar(255)">
+ <constraints nullable="false"/>
+ </column>
+ <column name="funcID" type="varchar(255)">
+ </column>
+ <column name="status" type="varchar(255)">
+ <constraints nullable="false"/>
+ </column>
+ <column name="operFinished" type="varchar(255)">
+ <constraints nullable="false"/>
+ </column>
+ <column name="operResult" type="varchar(255)">
+ <constraints nullable="false"/>
+ </column>
+ <column name="OperResultMessage" type="varchar(255)">
+ </column>
+ </createTable>
+
+ <createTable tableName="CaseRecord">
+ <column name="taskID" type="varchar(255)">
+ <constraints primaryKey="true" nullable="false"/>
+ </column>
+ <column name="funcID" type="varchar(255)">
+ </column>
+ <column name="testID" type="varchar(255)">
+ </column>
+ <column name="testResult" type="varchar(255)">
+ <constraints nullable="false"/>
+ </column>
+ <column name="testDescription" type="varchar(255)">
+ <constraints nullable="false"/>
+ </column>
+ </createTable>
+ </changeSet>
+</databaseChangeLog>
diff --git a/vnf-sdk-function-test/src/main/resources/sample.xml b/vnf-sdk-function-test/src/main/resources/sample.xml
new file mode 100644
index 0000000..db1d2f0
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/resources/sample.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<class>
+ <TestResult>
+ <test name="Huawei"></test>
+ <test description="Huawei"></test>
+ <test status="success"></test>
+ </TestResult>
+</class> \ No newline at end of file