summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVenu Nanditha Jampani <venunanditha568@gmail.com>2017-03-24 18:23:26 +0530
committerVenu Nanditha Jampani <venunanditha568@gmail.com>2017-03-24 18:27:32 +0530
commit8dcfd784d1739b29e63d5729908b71d41f986995 (patch)
treeeddbfd0f0f1f305006b71f9f65590cd82ba55383
parentfdd6a02d934205cd7b468b1c97be2dfed3293c8e (diff)
Added UPLOAD and EXECUTE interfaces.
issue_id:VNFSDK-21 Change-Id: Ia5cd6d51ff4c96e2da3bdf650988b71fbc635f67 Signed-off-by: Venu Nanditha Jampani <venunanditha568@gmail.com>
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/TaskExecution.java139
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/EnvironmentMap.java4
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java10
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/resource/CommonManager.java101
4 files changed, 248 insertions, 6 deletions
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/openo/vnfsdk/functest/TaskExecution.java
index aa89f30..0865d03 100644
--- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/TaskExecution.java
+++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/TaskExecution.java
@@ -25,6 +25,11 @@ import java.util.Map.Entry;
import java.util.UUID;
import org.apache.commons.lang3.SystemUtils;
+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;
@@ -100,4 +105,138 @@ public class TaskExecution {
}
}
+ public void executeRobotScript(UUID envId, UUID uploadId, UUID executeId, String frameworktype) {
+
+ String nl = File.separator;
+ String curDir = System.getProperty("user.dir");
+ String confDir = curDir + nl + "conf" + nl + "robot" + nl;
+
+ // Read the MetaData from the VNF package
+ ObjectMapper mapper = new ObjectMapper();
+ Map<String, String> mapValues = null;
+ try {
+ mapValues = 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;
+ }
+
+ // Get environment of given UUID
+ Environment functestEnv = EnvironmentMap.getInstance().getEnv(envId);
+
+ String remoteDir = functestEnv.getPath() + mapValues.get("SCRIPT_NAME");
+ String remoteScriptFile = remoteDir + "/" + mapValues.get("MAIN_SCRIPT");
+ String remoteScriptResult = remoteDir + "/" + "output ";
+ String dirResult = mapValues.get("DIR_RESULT") + executeId;
+
+ // set the argument parameters
+ String remoteArgs = "";
+ remoteArgs = remoteArgs + " -v " + "NODE_IP" + ":" + functestEnv.getRemoteIp() + " ";
+ remoteArgs = remoteArgs + " -v " + "NODE_USERNAME" + ":" + functestEnv.getUserName() + " ";
+ remoteArgs = remoteArgs + " -v " + "NODE_PASSWORD" + ":" + functestEnv.getPassword() + " ";
+
+ String remoteCommand = "robot " + "-d " + remoteScriptResult + remoteArgs + remoteScriptFile;
+
+ // set the parameters required by the execute script
+ remoteCommand = "\"" + remoteCommand + "\"";
+ remoteArgs = remoteArgs + " -v " + "REMOTE_COMMAND" + ":" + remoteCommand + " ";
+
+ remoteArgs = remoteArgs + " -v " + "DIR_RESULT" + ":" + dirResult + " ";
+ remoteArgs = remoteArgs + " -v " + "DIR_REMOTE_RESULT" + ":" + remoteScriptResult + " ";
+
+ // Execute script directory
+ String robotScript = confDir + "execute.robot";
+ String shellcommand = "cmd.exe /c ";
+ if(SystemUtils.IS_OS_LINUX) {
+ shellcommand = "bash ";
+ }
+ Process process = null;
+ InputStream inputStream = null;
+ int ch;
+ try {
+ String command = shellcommand + "robot" + remoteArgs + robotScript;
+ process = Runtime.getRuntime().exec(command);
+ inputStream = process.getInputStream();
+ while((ch = inputStream.read()) != -1) {
+ LOGGER.info("character ..." + Integer.toString(ch));
+ }
+ } catch(Exception e) {
+ LOGGER.error("TaskExecution ... executeScript() ... [Exception] ...", e);
+ }
+
+ OperationStatus operstatus = new OperationStatus();
+ operstatus.setoResultCode(operResultCode.SUCCESS);
+ operstatus.setOperResultMessage("Execute function test finished");
+ operstatus.setOperFinished(true);
+ OperationStatusHandler.getInstance().setOperStatusMap(executeId, operstatus);
+ }
+
+ public void uploadScript(String dirPath, UUID UUIDEnv, UUID UUIDUpload) {
+
+ String nl = File.separator;
+ String curDir = System.getProperty("user.dir");
+ String confDir = curDir + nl + "conf" + nl + "robot" + nl;
+
+ // Read the MetaData from the VNF package
+ ObjectMapper mapper = new ObjectMapper();
+
+ Map<String, String> mapValues = null;
+ try {
+
+ mapValues = mapper.readValue(new FileInputStream(confDir + "robotMetaData.json"), Map.class);
+ } catch(Exception e) {
+
+ LOGGER.error("Reading Json Meta data file failed or file do not exist", e);
+ return;
+ }
+
+ // Form the variables for the upload, transfer and execute command
+ String scriptDirName = new File(dirPath).getName();
+ mapValues.put("SCRIPT_DIR", dirPath);
+
+ String robotvariables = "";
+ for(Entry<String, String> values : mapValues.entrySet()) {
+
+ robotvariables = robotvariables + " -v " + values.getKey() + ":" + values.getValue() + " ";
+ }
+
+ // Append the Func test environment variables
+ Environment functestEnv = EnvironmentMap.getInstance().getEnv(UUIDEnv);
+ robotvariables = robotvariables + " -v " + "NODE_IP" + ":" + functestEnv.getRemoteIp() + " ";
+ robotvariables = robotvariables + " -v " + "NODE_USERNAME" + ":" + functestEnv.getUserName() + " ";
+ robotvariables = robotvariables + " -v " + "NODE_PASSWORD" + ":" + functestEnv.getPassword() + " ";
+ robotvariables = robotvariables + " -v " + "DIR_REMOTE" + ":" + functestEnv.getPath() + " ";
+
+ // Execute the command
+ String robotScript = confDir + "upload.robot";
+
+ String shellcommand = "cmd.exe /c ";
+ if(SystemUtils.IS_OS_LINUX) {
+ shellcommand = "bash ";
+ }
+
+ Process process = null;
+ InputStream inputStream = null;
+ int ch;
+ try {
+ String command = shellcommand + "robot " + robotvariables + robotScript;
+ process = Runtime.getRuntime().exec(command);
+ inputStream = process.getInputStream();
+ while((ch = inputStream.read()) != -1) {
+ LOGGER.info("character ..." + Integer.toString(ch));
+ }
+
+ } catch(Exception e) {
+ LOGGER.error("TaskExecution ... executeScript() ... [Exception] ...", e);
+ }
+
+ OperationStatus operstatus = new OperationStatus();
+ operstatus.setoResultCode(operResultCode.SUCCESS);
+ operstatus.setOperResultMessage("");
+ operstatus.setOperFinished(true);
+ OperationStatusHandler.getInstance().setOperStatusMap(UUIDUpload, operstatus);
+
+ }
+
}
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/openo/vnfsdk/functest/externalservice/entity/EnvironmentMap.java
index 4b347d3..e2a9ebb 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/openo/vnfsdk/functest/externalservice/entity/EnvironmentMap.java
@@ -46,4 +46,8 @@ public class EnvironmentMap {
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/OperationStatusHandler.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java
index fd93136..fa57c3c 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/openo/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java
@@ -42,19 +42,19 @@ public class OperationStatusHandler {
return oInstance;
}
- public static synchronized Map<UUID, OperationStatus> getOperStatusMap() {
+ public synchronized Map<UUID, OperationStatus> getOperStatusMap() {
return operStatusMap;
}
- public static synchronized void setOperStatusMap(UUID uuid, OperationStatus InputOperStatusMap) {
+ public synchronized void setOperStatusMap(UUID uuid, OperationStatus InputOperStatusMap) {
operStatusMap.put(uuid, InputOperStatusMap);
}
- public Response operationStatusfunc(UUID uuid) {
+ public Response getOperationStatus(UUID uuid) {
- if(OperationStatusHandler.getOperStatusMap().containsKey(uuid)) {
+ if(getOperStatusMap().containsKey(uuid)) {
- OperationStatus operstatus = OperationStatusHandler.getOperStatusMap().get(uuid);
+ OperationStatus operstatus = getOperStatusMap().get(uuid);
LOGGER.info("Operation Finished?" + operstatus.isOperFinished());
LOGGER.info("Operation Result Message" + operstatus.getOperResultMessage());
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
index 9563f52..6c61e1a 100644
--- 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
@@ -21,6 +21,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.List;
import java.util.StringTokenizer;
import java.util.UUID;
import java.util.concurrent.Callable;
@@ -96,6 +97,103 @@ public class CommonManager {
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(InputStream csarInputStream,
+ @PathParam("functestEnvId") String functestEnvId) {
+ LOGGER.info("Upload function test package");
+
+ try {
+
+ // Convert the stream to script folder
+ String nl = File.separator;
+ String filePath = storeChunkFileInLocal("temp", "TempFile.rar", csarInputStream);
+
+ // 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("Upload the script and execute the script and run command", 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);
+ final UUID uploadUUID = UUID.fromString(uploadId);
+
+ // 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, uploadUUID, executeUUID, frameworktype);
+ return 0;
+ }
+ });
+
+ // Send REST response
+ return RestResponseUtil.getSuccessResponse(executeUUID);
+
+ } catch(Exception e) {
+ LOGGER.error("Upload the script and execute the script and run command", e);
+ }
+
+ return null;
+ }
@Path("")
@POST
@ApiOperation(value = "execute the function test")
@@ -131,6 +229,7 @@ public class CommonManager {
ExecutorService es = Executors.newFixedThreadPool(3);
es.submit(new Callable<Integer>() {
+
public Integer call() throws Exception {
new TaskExecution().executeScript(finalPath, uniqueKey);
@@ -175,7 +274,7 @@ public class CommonManager {
public Response getOperationResult(@ApiParam(value = "operationId") @PathParam("operationId") String operationId) {
LOGGER.info("Query functest status by id." + operationId);
- return OperationStatusHandler.getInstance().operationStatusfunc(UUID.fromString(operationId));
+ return OperationStatusHandler.getInstance().getOperationStatus(UUID.fromString(operationId));
}
@Path("/download/{functestId}")