From ddc79e252a0ec710e6ae701aef7e07f233534b63 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Thu, 28 Feb 2019 15:31:00 +0530 Subject: CVC: Update VTP with scenario, execution Issue-ID: VNFSDK-352 Change-Id: I3cb2f5d3bcfda16a6bb01121878533f527e226fe Signed-off-by: Kanagaraj Manickam k00365106 --- .../marketplace/resource/PackageResource.java | 5 - .../vnfsdk/marketplace/resource/VTPResource.java | 129 -------- .../vnfsdk/marketplace/wrapper/PackageWrapper.java | 33 +- .../src/main/java/org/onap/vtp/VTPModelBase.java | 42 +++ .../src/main/java/org/onap/vtp/VTPResource.java | 117 +++++++ .../src/main/java/org/onap/vtp/error/VTPError.java | 91 ++++++ .../org/onap/vtp/error/VTPExceptionMapper.java | 51 +++ .../onap/vtp/execution/VTPExecutionResource.java | 364 +++++++++++++++++++++ .../onap/vtp/execution/model/VTPTestExecution.java | 147 +++++++++ .../org/onap/vtp/scenario/VTPScenarioResource.java | 258 +++++++++++++++ .../org/onap/vtp/scenario/model/VTPTestCase.java | 171 ++++++++++ .../onap/vtp/scenario/model/VTPTestScenario.java | 57 ++++ .../org/onap/vtp/scenario/model/VTPTestSuite.java | 58 ++++ 13 files changed, 1375 insertions(+), 148 deletions(-) delete mode 100644 vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/VTPResource.java create mode 100644 vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java create mode 100644 vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java create mode 100644 vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/error/VTPError.java create mode 100644 vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/error/VTPExceptionMapper.java create mode 100644 vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java create mode 100644 vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/model/VTPTestExecution.java create mode 100644 vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java create mode 100644 vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestCase.java create mode 100644 vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestScenario.java create mode 100644 vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestSuite.java (limited to 'vnfmarket-be/vnf-sdk-marketplace/src/main/java') diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java index 74d8aeb3..e4b947f5 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java @@ -36,17 +36,12 @@ import javax.ws.rs.core.Response; import org.eclipse.jetty.http.HttpStatus; import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataParam; -import org.onap.vnfsdk.marketplace.common.CommonConstant; import org.onap.vnfsdk.marketplace.db.connection.ConnectionUtil; import org.onap.vnfsdk.marketplace.db.exception.MarketplaceResourceException; -import org.onap.vnfsdk.marketplace.db.resource.PackageManager; import org.onap.vnfsdk.marketplace.entity.response.CsarFileUriResponse; import org.onap.vnfsdk.marketplace.entity.response.PackageMeta; import org.onap.vnfsdk.marketplace.entity.response.UploadPackageResponse; import org.onap.vnfsdk.marketplace.onboarding.entity.OnBoardingResult; -import org.onap.vnfsdk.marketplace.rest.RestConstant; -import org.onap.vnfsdk.marketplace.rest.RestResponse; -import org.onap.vnfsdk.marketplace.rest.RestfulClient; import org.onap.vnfsdk.marketplace.wrapper.PackageWrapper; import io.swagger.annotations.Api; diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/VTPResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/VTPResource.java deleted file mode 100644 index a59a8856..00000000 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/VTPResource.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * Copyright 2018 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.marketplace.resource; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -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.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.apache.commons.io.IOUtils; -import org.eclipse.jetty.http.HttpStatus; -import org.onap.vnfsdk.marketplace.common.ToolUtil; -import org.onap.vnfsdk.marketplace.db.exception.MarketplaceResourceException; -import org.open.infc.grpc.Result; -import org.open.infc.grpc.client.OpenRemoteCli; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.gson.internal.LinkedTreeMap; - -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("/vtp") -@Api(tags = { "VNF Test Platform" }) -public class VTPResource { - @Path("/tests") - @GET - @ApiOperation(value = "VTP Test cases", response = String.class) - @Produces(MediaType.APPLICATION_JSON) - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Failed to retrieve the tests", response = String.class) }) - public Response listTests() throws IOException, MarketplaceResourceException { - Result result = null; - try { - result = OpenRemoteCli.run(new String[] { "-P", "open-cli", "schema-list", "--product", "onap-vtp", "--format", "json" }); - } catch (Exception e) { - return Response.serverError().build(); - } - - if (result.getExitCode() != 0) { - return Response.serverError().entity(result.getOutput()).build(); - } - - return Response.ok(result.getOutput(), MediaType.APPLICATION_JSON).build(); - } - - @Path("/tests/{testName}/run") - @POST - @ApiOperation(value = "Run VTP testcase") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "Test case not found", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "VTP internal failure", response = String.class) }) - public Response runTest(@ApiParam(value = "test Name") @PathParam("testName") String testName, - @Context HttpServletRequest request) - throws IOException, MarketplaceResourceException { - String details = IOUtils.toString(request.getInputStream()); - Result result = null; - try { - List cmdArgsList = new ArrayList<>(); - for (String defaultArg: new String[] { "-P", "onap-vtp", testName, "--format", "json" }) { - cmdArgsList.add(defaultArg); - } - - LinkedTreeMap cmdArgs = ToolUtil.fromJson(details, LinkedTreeMap.class); - for (Entry arg : cmdArgs.entrySet()) { - cmdArgsList.add("--" + arg.getKey()); - cmdArgsList.add(arg.getValue()); - } - - result = OpenRemoteCli.run(cmdArgsList.toArray(new String []{})); - } catch (Exception e) { - return Response.serverError().build(); - } - - if (result.getExitCode() != 0) { - return Response.serverError().entity(result.getOutput()).build(); - } - - ObjectMapper mapper = new ObjectMapper(); - JsonNode resultJson = mapper.readTree(result.getOutput()); - - ((ObjectNode)resultJson).put("build_tag", System.getenv("BUILD_TAG")); - - JsonNode results = resultJson.get("results"); - if (results != null && results.isArray()) { - ArrayNode resultsArray = (ArrayNode)results; - if (resultsArray.size() >= 0) { - String error = resultsArray.get(0).get("error").asText(); - ((ObjectNode)resultJson).put("criteria", "SUCCESS".equalsIgnoreCase(error) ? "PASS" : "FAILED"); - } - } - - return Response.ok(resultJson.toString(), MediaType.APPLICATION_JSON).build(); - } -} diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java index a1730632..cc79ca10 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java @@ -22,6 +22,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; @@ -69,6 +70,8 @@ public class PackageWrapper { private static final Logger LOG = LoggerFactory.getLogger(PackageWrapper.class); + private static final boolean disableValidation = true; + /** * get PackageWrapper instance. * @@ -287,23 +290,25 @@ public class PackageWrapper { uploadedInputStream.close(); - try { - Result result = OpenRemoteCli.run(new String[] { "-P", "onap-vtp", "csar-validate", "--csar", fileLocation, "--format", "json" }); - LOG.info("CSAR validation is successful" + result.getOutput()); + if (!disableValidation) { + try { + Result result = OpenRemoteCli.run("localhost", 50051, null, Arrays.asList(new String[] { "--product", "onap-vtp", "csar-validate", "--csar", fileLocation, "--format", "json" })); + LOG.info("CSAR validation is successful" + result.getOutput()); - int exitCode = result.getExitCode(); - String output = result.getOutput(); + int exitCode = result.getExitCode(); + String output = result.getOutput(); - if((exitCode != 0) || !output.contains("\"error\":\"SUCCESS\"")) { - LOG.error("Could not validate failed"); - return Response.status(Status.EXPECTATION_FAILED).entity(new CommonErrorResponse(output)) - .build(); + if((exitCode != 0) || !output.contains("\"error\":\"SUCCESS\"")) { + LOG.error("Could not validate failed"); + return Response.status(Status.EXPECTATION_FAILED).entity(new CommonErrorResponse(output)) + .build(); + } + } catch (Exception e) { + LOG.error("CSAR validation panicked", e); + return Response.serverError().entity( + new CommonErrorResponse("Exception occurred while validating csar package:" + e.getMessage())) + .build(); } - } catch (Exception e) { - LOG.error("CSAR validation panicked", e); - return Response.serverError().entity( - new CommonErrorResponse("Exception occurred while validating csar package:" + e.getMessage())) - .build(); } UploadPackageResponse result = null; diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java new file mode 100644 index 00000000..f9ec6b5c --- /dev/null +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java @@ -0,0 +1,42 @@ +/** + * Copyright 2019 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.vtp; + +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class VTPModelBase { + public String toJsonString() { + return toJsonString(this); + } + + public static String toJsonString(Object obj) { + try { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setSerializationInclusion(Include.NON_NULL); + objectMapper.setSerializationInclusion(Include.NON_EMPTY); + return objectMapper.writeValueAsString(obj); + } catch (JsonProcessingException e) { + return "{}"; + } + } + + public String toString() { + return this.toJsonString(); + } +} diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java new file mode 100644 index 00000000..83158ed9 --- /dev/null +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java @@ -0,0 +1,117 @@ +/** + * Copyright 2018 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.vtp; + +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Properties; +import java.util.TimeZone; +import java.util.UUID; + +import org.apache.http.HttpStatus; +import org.onap.vtp.error.VTPError; +import org.onap.vtp.error.VTPError.VTPException; +import org.open.infc.grpc.Output; +import org.open.infc.grpc.Result; +import org.open.infc.grpc.client.OpenInterfaceGrpcClient; +import org.open.infc.grpc.client.OpenRemoteCli; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class VTPResource { + + protected static final Logger LOG = LoggerFactory.getLogger(VTPResource.class); + + public static String VTP_TEST_CENTER_IP = "localhost"; + public static int VTP_TEST_CENTER_PORT = 50051; + public static String VTP_ARTIFACT_STORE = "d:/temp/data/artifacts/"; + public static String VTP_EXECUTION_TEMP_STORE = "d:/temp/data/transient"; + + public static SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US); + + static { + dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); + + Properties prp = new Properties(); + try { + prp.load(VTPResource.class.getClassLoader().getResourceAsStream("vtp.properties")); + VTP_TEST_CENTER_IP = prp.getProperty("vtp.grpc.server"); + VTP_TEST_CENTER_PORT = Integer.parseInt(prp.getProperty("vtp.grpc.port")); + VTP_ARTIFACT_STORE = prp.getProperty("vtp.artifact.store"); + VTP_EXECUTION_TEMP_STORE = prp.getProperty("vtp.file.store"); + } catch (Exception e) { + LOG.error(e.getMessage()); + } + } + + protected Result makeRpc(List args) throws VTPException { + Result result = null; + String requestId = UUID.randomUUID().toString(); + try { + result = OpenRemoteCli.run( + VTP_TEST_CENTER_IP, VTP_TEST_CENTER_PORT, requestId, + args); +// } catch(OpenInterfaceGrpcClient.OpenInterfaceGrpcTimeoutExecption e) { +// throw new VTPException( +// new VTPError().setHttpStatus(HttpStatus.SC_GATEWAY_TIMEOUT).setMessage("Timeout.").setCode(VTPError.TIMEOUT)); + } catch (Exception e) { + throw new VTPException(new VTPError().setMessage(e.getMessage())); + } + + if (result.getExitCode() != 0) { + throw new VTPException( + new VTPError().setMessage(result.getOutput())); + } + + return result; + } + + public static String getStorePath() { + return VTP_ARTIFACT_STORE; + } + + protected JsonNode makeRpcAndGetJson(List args) throws VTPException, IOException { + Result result = this.makeRpc(args); + ObjectMapper mapper = new ObjectMapper(); + JsonNode resultJson = mapper.readTree(result.getOutput()); + return resultJson; + } + + + protected Output makeRpc(String scenario, String requestId, String profile, String testCase, JsonNode argsJsonNode) throws VTPException { + Output output = null; + ObjectMapper mapper = new ObjectMapper(); + Map args = mapper.convertValue(argsJsonNode, Map.class); + try { + output = OpenRemoteCli.invoke(VTP_TEST_CENTER_IP, VTP_TEST_CENTER_PORT, scenario, profile, testCase, requestId, args); +// } catch(OpenInterfaceGrpcClient.OpenInterfaceGrpcTimeoutExecption e) { +// throw new VTPException( +// new VTPError().setHttpStatus(HttpStatus.SC_GATEWAY_TIMEOUT).setMessage(e.getMessage()).setCode(VTPError.TIMEOUT)); + } catch (Exception e) { + throw new VTPException( + new VTPError().setMessage(e.getMessage())); + } + + return output; + } +} diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/error/VTPError.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/error/VTPError.java new file mode 100644 index 00000000..0f0219ed --- /dev/null +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/error/VTPError.java @@ -0,0 +1,91 @@ +/** + * Copyright 2019 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.vtp.error; + +import org.eclipse.jetty.http.HttpStatus; +import org.onap.vtp.VTPModelBase; + +public class VTPError extends VTPModelBase { + private String code = ""; + + private String message; + + private int httpStatus = HttpStatus.INTERNAL_SERVER_ERROR_500; + + public static String TIMEOUT = "0x9999"; + + public static String []NOT_FOUND = new String []{ + "0xc002", //Profile not found + "0x6003", //Command not found + "0x6009", //Execution not found + "0x21003" //Artifact not found + }; + + public String getCode() { + return code; + } + + public VTPError setCode(String code) { + this.code = code; + return this; + } + + public String getMessage() { + return message; + } + + public VTPError setMessage(String message) { + this.message = message; + + for (String errorCode : NOT_FOUND) { + if (message.startsWith(errorCode)) { + this.code = errorCode; + this.httpStatus = HttpStatus.NOT_FOUND_404; + this.message = message.split("::")[1]; + break; + } + } + return this; + } + + public int getHttpStatus() { + return httpStatus; + } + + public VTPError setHttpStatus(int httpStatus) { + this.httpStatus = httpStatus; + return this; + } + + public static class VTPException extends Exception { + private static final long serialVersionUID = -2894780740467107391L; + + VTPError error; + + public VTPException(VTPError error) { + this.error = error; + } + + public String getMessage() { + return this.error.toJsonString(); + } + + public VTPError getVTPError() { + return this.error; + } + } +} diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/error/VTPExceptionMapper.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/error/VTPExceptionMapper.java new file mode 100644 index 00000000..93f08a4f --- /dev/null +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/error/VTPExceptionMapper.java @@ -0,0 +1,51 @@ +/** + * Copyright 2018 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.vtp.error; + +import javax.inject.Singleton; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; + +import org.apache.http.HttpStatus; +import org.onap.vtp.error.VTPError.VTPException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +@Provider +@Singleton +public class VTPExceptionMapper implements ExceptionMapper { + private static final Logger LOG = LoggerFactory.getLogger(VTPExceptionMapper.class); + + public Response toResponse(Exception e) { + LOG.error(e.toString(), e); + + if (e instanceof VTPException) { + VTPException ex = (VTPException) e; + return Response.status(ex.getVTPError().getHttpStatus()).entity(ex.getVTPError().toString()).build(); + } else { + ObjectNode node = JsonNodeFactory.instance.objectNode(); + node.put("message", e.getMessage()); + node.put("code", "UNKNOWN"); + return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(node.toString()).build(); + } + + } +} diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java new file mode 100644 index 00000000..1f588c1f --- /dev/null +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java @@ -0,0 +1,364 @@ +/** + * Copyright 2018 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.vtp.execution; + +import java.io.File; +import java.io.IOException; +import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.eclipse.jetty.http.HttpStatus; +import org.glassfish.jersey.media.multipart.BodyPartEntity; +import org.glassfish.jersey.media.multipart.FormDataBodyPart; +import org.glassfish.jersey.media.multipart.FormDataParam; +import org.onap.vtp.VTPResource; +import org.onap.vtp.error.VTPError; +import org.onap.vtp.error.VTPError.VTPException; +import org.onap.vtp.execution.model.VTPTestExecution; +import org.onap.vtp.execution.model.VTPTestExecution.VTPTestExecutionList; +import org.open.infc.grpc.Output; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +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("/vtp") +@Api(tags = {"VTP Execution"}) +public class VTPExecutionResource extends VTPResource{ + public VTPTestExecutionList executeHandler(VTPTestExecutionList executions, String requestId) throws VTPException, IOException { + if (requestId == null) { + requestId = UUID.randomUUID().toString(); + } + + for (VTPTestExecution execution: executions.getExecutions()) { + String startTime = dateFormatter.format(new Date()); + execution.setStartTime(startTime); + + //Run execution + Output output = this.makeRpc( + execution.getScenario(), + requestId, + execution.getProfile(), + execution.getTestCaseName(), + execution.getParameters() + ); + String endTime = dateFormatter.format(new Date()); + execution.setEndTime(endTime); + execution.setExecutionId(output.getAddonsMap().get("execution-id")); + + if (output.getSuccess()) { + execution.setStatus(VTPTestExecution.Status.COMPLETED.name()); + + ObjectMapper mapper = new ObjectMapper(); + JsonNode resultJson = mapper.readTree(output.getAttrsMap().get("results")); + execution.setResults(resultJson); + } else { + execution.setStatus(VTPTestExecution.Status.FAILED.name()); + ObjectMapper mapper = new ObjectMapper(); + JsonNode resultJson = mapper.readTree(output.getAttrsMap().get("error")); + execution.setResults(resultJson); + } + } + + return executions; + } + + private Map storeTestCaseInputFiles(List bodyParts) throws IOException { + Map map = new HashMap<>(); + if (bodyParts != null) + for (FormDataBodyPart part: bodyParts) { + String name = part.getContentDisposition().getFileName(); + String path = VTP_EXECUTION_TEMP_STORE + "/" + name; + + File f = new File(path); + if (f.exists()) { + FileUtils.forceDelete(f); + } + FileUtils.forceMkdir(f.getParentFile()); + + BodyPartEntity fileEntity = (BodyPartEntity) part.getEntity(); + java.nio.file.Files.copy( + fileEntity.getInputStream(), + f.toPath(), + StandardCopyOption.REPLACE_EXISTING); + + IOUtils.closeQuietly(fileEntity.getInputStream()); + + map.put(name, path); + } + + return map; + } + + @Path("/executions") + @POST + @ApiOperation(tags = "VTP Execution", value = "Execute the test case with given inputs in 'executions' form-data " + + "as key-value pair of parameter's name vs parameter's value. If parameter is binary type then" + + "multi-part form-data 'file' should be used to feed the binary file content and it can be more than once. " + + "To use the given file as input parameter, prefix the value with file://." , + response = VTPTestExecution.class, responseContainer = "List") + @Consumes({MediaType.MULTIPART_FORM_DATA, MediaType.APPLICATION_JSON}) + @Produces(MediaType.APPLICATION_JSON) + @ApiResponses(value = { + @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, + message = "Failed to perform the operation", + response = VTPError.class)}) + public Response executeTestcases( + @ApiParam(value = "Request Id") @QueryParam("requestId") String requestId, + @ApiParam(value = "Testcase File arguments", required = false) @FormDataParam("file") List bodyParts, + @FormDataParam("executions") String executionsJson) throws VTPException, IOException { + + VTPTestExecutionList executions = new VTPTestExecution.VTPTestExecutionList(); + Map map = this.storeTestCaseInputFiles(bodyParts); + + for (Map.Entry entry: map.entrySet()) { + if (executionsJson.contains("file://" + entry.getKey())) { + executionsJson = executionsJson.replaceAll("file://" + entry.getKey(), entry.getValue()); + } + } + + if (executionsJson.contains("file://")) { + VTPError err = new VTPError() + .setMessage("Some file form-data is missing as executions has input parameter tagged with file://") + .setHttpStatus(HttpStatus.BAD_REQUEST_400); + throw new VTPException(err); + + } + + executions.setExecutions( + new ObjectMapper().readValue(executionsJson, new TypeReference>(){})); + + executions = this.executeHandler(executions, requestId); + + for (Map.Entry entry: map.entrySet()) { + FileUtils.forceDelete(new File(entry.getValue())); + } + + return Response.ok(executions.getExecutions().toString(), MediaType.APPLICATION_JSON).build(); + } + + public VTPTestExecutionList listTestExecutionsHandler( + String requestId, + String scenario, + String testSuiteName, + String testCaseName, + String profile, + String startTime, + String endTime) throws VTPException, IOException{ + List args = new ArrayList<>(); + args.addAll(Arrays.asList(new String[] { + "--product", "open-cli", "execution-list", "--format", "json" + })); + + if (startTime != null && !startTime.isEmpty()) { + args.add("--start-time"); + args.add(startTime); + } + + if (endTime != null && !endTime.isEmpty()) { + args.add("--end-time"); + args.add(endTime); + } + + if (requestId != null && !requestId.isEmpty()) { + args.add("--request-id"); + args.add(requestId); + } + + if (testSuiteName != null && !testSuiteName.isEmpty()) { + args.add("--service"); + args.add(testSuiteName); + } + + if (scenario != null && !scenario.isEmpty()) { + args.add("--product"); + args.add(scenario); + } + + if (testCaseName != null && !testCaseName.isEmpty()) { + args.add("--command"); + args.add(testCaseName); + } + + JsonNode results = this.makeRpcAndGetJson(args); + + VTPTestExecutionList list = new VTPTestExecutionList(); + + if (results != null && results.isArray()) { + ArrayNode resultsArray = (ArrayNode)results; + if (resultsArray.size() >= 0) { + for (Iterator it = resultsArray.iterator(); it.hasNext();) { + JsonNode n = it.next(); + if (n.elements().hasNext()) { + VTPTestExecution exec = new VTPTestExecution(); + if (n.get("start-time") != null) + exec.setStartTime(n.get("start-time").asText()); + + if (n.get("end-time") != null) + exec.setEndTime(n.get("end-time").asText()); + + if (n.get("execution-id") != null) + exec.setExecutionId(n.get("execution-id").asText()); + if (n.get("request-id") != null) + exec.setRequestId(n.get("request-id").asText()); + + if (n.get("product") != null) + exec.setScenario(n.get("product").asText()); + if (n.get("service") != null) + exec.setTestSuiteName(n.get("service").asText()); + if (n.get("command") != null) + exec.setTestCaseName(n.get("command").asText()); + if (n.get("profile") != null) + exec.setExecutionId(n.get("profile").asText()); + if (n.get("status") != null) + exec.setStatus(n.get("status").asText()); + + list.getExecutions().add(exec); + } + + } + } + } + + return list; + } + + @Path("/executions") + @GET + @ApiOperation(tags = "VTP Execution", value = " List test executions", response = VTPTestExecution.class, responseContainer = "List") + @Produces(MediaType.APPLICATION_JSON) + @ApiResponses(value = { + @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, + message = "Failed to perform the operation", + response = VTPError.class) }) + public Response listTestExecutions( + @ApiParam("Test request Id") @QueryParam("requestId") String requestId, + @ApiParam("Test scenario name") @QueryParam("scenario") String scenario, + @ApiParam("Test suite name") @QueryParam("testsuiteName") String testsuiteName, + @ApiParam("Test case name") @QueryParam("testcaseName") String testcaseName, + @ApiParam("Test profile name") @QueryParam("profileName") String profileName, + @ApiParam("Test execution start time") @QueryParam("startTime") String startTime, + @ApiParam("Test execution end time") @QueryParam("endTime") String endTime + ) throws VTPException, IOException { + + return Response.ok(this.listTestExecutionsHandler( + requestId, scenario, testsuiteName, testcaseName, profileName, startTime, endTime).getExecutions().toString(), MediaType.APPLICATION_JSON).build(); + } + + public VTPTestExecution getTestExecutionHandler( + String executionId) throws VTPException, IOException{ + List args = new ArrayList<>(); + args.addAll(Arrays.asList(new String[] { + "--product", "open-cli", "execution-show", "--execution-id", executionId, "--format", "json" + })); + + + JsonNode result = this.makeRpcAndGetJson(args); + + VTPTestExecution exec = new VTPTestExecution(); + + if (result != null && result.elements().hasNext()) { + if (result.get("start-time") != null) + exec.setStartTime(result.get("start-time").asText()); + + if (result.get("end-time") != null) + exec.setEndTime(result.get("end-time").asText()); + + if (result.get("execution-id") != null) + exec.setExecutionId(result.get("execution-id").asText()); + if (result.get("request-id") != null) + exec.setExecutionId(result.get("request-id").asText()); + + if (result.get("product") != null) + exec.setScenario(result.get("product").asText()); + if (result.get("service") != null) + exec.setTestSuiteName(result.get("service").asText()); + if (result.get("command") != null) + exec.setTestCaseName(result.get("command").asText()); + if (result.get("profile") != null) + exec.setExecutionId(result.get("profile").asText()); + if (result.get("status") != null) + exec.setStatus(result.get("status").asText()); + if (result.get("input") != null) { + exec.setParameters(result.get("input")); + } + if (result.get("output") != null) { + ObjectMapper mapper = new ObjectMapper(); + JsonNode resultJson = null; + try { + resultJson = mapper.readTree(result.get("output").asText()); + + //workarround, sometimes its null. + if (resultJson == null) { + resultJson = mapper.readTree(result.get("output").toString()); + } + } catch (Exception e) { + ObjectNode node = JsonNodeFactory.instance.objectNode(); + node.put("error", result.get("output").asText()); + resultJson = node; + } + + exec.setResults(resultJson); + } + } + + return exec; + } + + @Path("/executions/{executionId}") + @GET + @ApiOperation(tags = "VTP Execution", value = " Retrieve test execution complete details", response = VTPTestExecution.class) + @Produces(MediaType.APPLICATION_JSON) + @ApiResponses(value = { + @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, + message = "Failed to perform the operation", + response = VTPError.class) }) + public Response getTestExecution( + @ApiParam("Test execution Id") @PathParam("executionId") String executionId + ) throws VTPException, IOException { + + return Response.ok(this.getTestExecutionHandler(executionId).toString(), MediaType.APPLICATION_JSON).build(); + } +} diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/model/VTPTestExecution.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/model/VTPTestExecution.java new file mode 100644 index 00000000..524b8e5a --- /dev/null +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/model/VTPTestExecution.java @@ -0,0 +1,147 @@ +/** + * Copyright 2019 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.vtp.execution.model; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.onap.vtp.VTPModelBase; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; + +public class VTPTestExecution extends VTPModelBase{ + private String scenario; + private String testCaseName; + private String testSuiteName; + private String executionId; + private String requestId; + private String profile; + private JsonNode parameters = JsonNodeFactory.instance.objectNode(); + private JsonNode results = JsonNodeFactory.instance.objectNode(); + public static enum Status { + IN_PROGRESS, COMPLETED, FAILED; + } + + private String status = Status.FAILED.name(); + + private String startTime; + + private String endTime; + + public String getProfile() { + return profile; + } + public VTPTestExecution setProfile(String profile) { + this.profile = profile; + return this; + } + + public String getTestSuiteName() { + return testSuiteName; + } + public VTPTestExecution setTestSuiteName(String testSuiteName) { + this.testSuiteName = testSuiteName; + return this; + } + public String getTestCaseName() { + return testCaseName; + } + public VTPTestExecution setTestCaseName(String testCaseName) { + this.testCaseName = testCaseName; + return this; + } + + public String getExecutionId() { + return executionId; + } + public VTPTestExecution setExecutionId(String executionId) { + this.executionId = executionId; + return this; + } + + public JsonNode getResults() { + return results; + } + public VTPTestExecution setResults(JsonNode results) { + this.results = results; + return this; + } + + public String getStatus() { + return status; + } + + public VTPTestExecution setStatus(String status) { + this.status = status; + return this; + } + + public String getStartTime() { + return startTime; + } + + public VTPTestExecution setStartTime(String startTime) { + this.startTime = startTime; + return this; + } + + public String getEndTime() { + return endTime; + } + + public VTPTestExecution setEndTime(String endTime) { + this.endTime = endTime; + return this; + } + + public String getScenario() { + return scenario; + } + public void setScenario(String scenario) { + this.scenario = scenario; + } + + public String getRequestId() { + return requestId; + } + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public JsonNode getParameters() { + return parameters; + } + public void setParameters(JsonNode parameters) { + this.parameters = parameters; + } + + public static class VTPTestExecutionList extends VTPModelBase { + List executions = new ArrayList<>(); + + public List getExecutions() { + return executions; + } + + public VTPTestExecutionList setExecutions(List executions) { + this.executions = executions; + return this; + } + } +} diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java new file mode 100644 index 00000000..66849f34 --- /dev/null +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java @@ -0,0 +1,258 @@ +/** + * Copyright 2018 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.vtp.scenario; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.eclipse.jetty.http.HttpStatus; +import org.onap.vtp.VTPResource; +import org.onap.vtp.error.VTPError; +import org.onap.vtp.error.VTPError.VTPException; +import org.onap.vtp.scenario.model.VTPTestCase; +import org.onap.vtp.scenario.model.VTPTestScenario; +import org.onap.vtp.scenario.model.VTPTestSuite; +import org.onap.vtp.scenario.model.VTPTestCase.VTPTestCaseInput; +import org.onap.vtp.scenario.model.VTPTestCase.VTPTestCaseList; +import org.onap.vtp.scenario.model.VTPTestCase.VTPTestCaseOutput; +import org.onap.vtp.scenario.model.VTPTestScenario.VTPTestScenarioList; +import org.onap.vtp.scenario.model.VTPTestSuite.VTPTestSuiteList; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; + +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("/vtp") +@Api(tags = {"VTP Scenario"}) +public class VTPScenarioResource extends VTPResource{ + public VTPTestScenarioList listTestScenariosHandler() throws VTPException, IOException{ + List args = new ArrayList<>(); + + args.addAll(Arrays.asList(new String[] { + "--product", "open-cli", "product-list", "--format", "json" + })); + + JsonNode results = this.makeRpcAndGetJson(args); + + VTPTestScenarioList list = new VTPTestScenarioList(); + + if (results != null && results.isArray()) { + ArrayNode resultsArray = (ArrayNode)results; + if (resultsArray.size() >= 0) { + for (Iterator it = resultsArray.iterator(); it.hasNext();) { + JsonNode n = it.next(); + if (n.elements().hasNext()) { + String name = n.get("product").asText(); + + if (name.equalsIgnoreCase("open-cli")) continue; + + list.getScenarios().add(new VTPTestScenario().setName(name).setDescription( + n.get("description").asText())); + } + } + } + } + + return list; + } + + @Path("/scenarios") + @GET + @ApiOperation(tags = "VTP Scenario", value = " List available test scenarios", response = VTPTestScenario.class, responseContainer = "List") + @Produces(MediaType.APPLICATION_JSON) + @ApiResponses(value = { + @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, + message = "Failed to perform the operation", + response = VTPError.class) }) + public Response listTestScenarios() throws VTPException, IOException { + return Response.ok(this.listTestScenariosHandler().getScenarios().toString(), MediaType.APPLICATION_JSON).build(); + } + + public VTPTestSuiteList listTestSutiesHandler(String scenario) throws VTPException, IOException{ + List args = new ArrayList<>(); + + args.addAll(Arrays.asList(new String[] { + "--product", "open-cli", "service-list", "--product", scenario, "--format", "json" + })); + + JsonNode results = this.makeRpcAndGetJson(args); + + VTPTestSuiteList list = new VTPTestSuiteList(); + + if (results != null && results.isArray()) { + ArrayNode resultsArray = (ArrayNode)results; + if (resultsArray.size() >= 0) { + for (Iterator it = resultsArray.iterator(); it.hasNext();) { + JsonNode n = it.next(); + if (n.elements().hasNext()) { + list.getSuites().add(new VTPTestSuite().setName(n.get("service").asText()).setDescription( + n.get("description").asText())); + } + } + } + } + + return list; + } + + @Path("/scenarios/{scenario}/testsuites") + @GET + @ApiOperation(tags = "VTP Scenario", value = " List available test suties in given scenario", response = VTPTestSuite.class, responseContainer = "List") + @Produces(MediaType.APPLICATION_JSON) + @ApiResponses(value = { + @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, + message = "Failed to perform the operation", + response = VTPError.class) }) + public Response listTestSuties( + @ApiParam("Test scenario name") @PathParam("scenario") String scenario) throws VTPException, IOException { + + return Response.ok(this.listTestSutiesHandler(scenario).getSuites().toString(), MediaType.APPLICATION_JSON).build(); + } + + public VTPTestCaseList listTestcasesHandler(String testSuiteName, String scenario) throws VTPException, IOException{ + List args = new ArrayList<>(); + + args.addAll(Arrays.asList(new String[] { + "--product", "open-cli", "schema-list", "--product", scenario, "--format", "json" + })); + if (testSuiteName != null) { + args.add("--service"); + args.add(testSuiteName); + } + + JsonNode results = this.makeRpcAndGetJson(args); + + VTPTestCaseList list = new VTPTestCaseList(); + + if (results != null && results.isArray()) { + ArrayNode resultsArray = (ArrayNode)results; + if (resultsArray.size() >= 0) { + for (Iterator it = resultsArray.iterator(); it.hasNext();) { + JsonNode n = it.next(); + if (n.elements().hasNext()) + list.getTestCases().add( + new VTPTestCase().setTestCaseName( + n.get("command").asText()).setTestSuiteName( + n.get("service").asText())); + } + } + } + + return list; + } + + @Path("/scenarios/{scenario}/testcases") + @GET + @ApiOperation(tags = "VTP Scenario", value = " List available test cases", response = VTPTestCase.class, responseContainer = "List") + @Produces(MediaType.APPLICATION_JSON) + @ApiResponses(value = { + @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, + message = "Failed to perform the operation", + response = VTPError.class) }) + public Response listTestcases( + @ApiParam("Test scenario name") @PathParam("scenario") String scenario, + @ApiParam("Test suite name") @QueryParam("testSuiteName") String testSuiteName + ) throws VTPException, IOException { + + return Response.ok(this.listTestcasesHandler(testSuiteName, scenario).getTestCases().toString(), MediaType.APPLICATION_JSON).build(); + } + + public VTPTestCase getTestcaseHandler(String scenario, String testSuiteName, String testCaseName) throws VTPException, IOException { + List args = new ArrayList<>(); + args.addAll(Arrays.asList(new String[] { + "--product", "open-cli", "schema-show", "--product", scenario, "--service", testSuiteName, "--command", testCaseName , "--format", "json" + })); + JsonNode results = this.makeRpcAndGetJson(args); + + JsonNode schema = results.get("schema"); + + VTPTestCase tc = new VTPTestCase(); + tc.setTestCaseName(schema.get("name").asText()); + tc.setDescripton(schema.get("description").asText()); + tc.setTestSuiteName(schema.get("service").asText()); + tc.setAuthor(schema.get("author").asText()); + JsonNode inputsJson = schema.get("inputs"); + if (inputsJson != null && inputsJson.isArray()) { + for (final JsonNode inputJson: inputsJson) { + VTPTestCaseInput input = new VTPTestCaseInput(); + + input.setName(inputJson.get("name").asText()); + input.setDescription(inputJson.get("description").asText()); + input.setType(inputJson.get("type").asText()); + + if (inputJson.get("is_optional") != null) + input.setIsOptional(inputJson.get("is_optional").asBoolean()); + + if (inputJson.get("default_value") != null) + input.setDefaultValue(inputJson.get("default_value").asText()); + + if (inputJson.get("metadata") != null) + input.setMetadata(inputJson.get("metadata")); + + tc.getInputs().add(input); + } + } + + JsonNode outputsJson = schema.get("outputs"); + if (outputsJson != null && outputsJson.isArray()) { + for (final JsonNode outputJson: outputsJson) { + VTPTestCaseOutput output = new VTPTestCaseOutput(); + output.setName(outputJson.get("name").asText()); + output.setDescription(outputJson.get("description").asText()); + output.setType(outputJson.get("type").asText()); + + tc.getOutputs().add(output); + } + } + + return tc; + } + + @Path("/scenarios/{scenario}/testsuites/{testSuiteName}/testcases/{testCaseName}") + @GET + @ApiOperation(tags = "VTP Scenario", value = "Retrieve test cases details like inputs outputs and test suite name", response = VTPTestCase.class) + @Produces(MediaType.APPLICATION_JSON) + @ApiResponses(value = { + @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, + message = "Failed to perform the operation", response = VTPError.class), + @ApiResponse(code = HttpStatus.NOT_FOUND_404, + message = "Test case does not exist", response = VTPError.class)}) + public Response getTestcase( + @ApiParam("Test scenario name") @PathParam("scenario") String scenario, + @ApiParam(value = "Test case name") @PathParam("testSuiteName") String testSuiteName, + @ApiParam(value = "Test case name") @PathParam("testCaseName") String testCaseName) + throws IOException, VTPException { + + return Response.ok(this.getTestcaseHandler(scenario, testSuiteName, testCaseName).toString(), MediaType.APPLICATION_JSON).build(); + } +} diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestCase.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestCase.java new file mode 100644 index 00000000..f0ab2e38 --- /dev/null +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestCase.java @@ -0,0 +1,171 @@ +/** + * Copyright 2019 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.vtp.scenario.model; + +import java.util.ArrayList; +import java.util.List; + +import org.onap.vtp.VTPModelBase; + +import com.fasterxml.jackson.databind.JsonNode; + +public class VTPTestCase extends VTPModelBase{ + private String scenario; + private String testCaseName; + private String testSuiteName; + private String descripton; + private String author; + private List inputs = new ArrayList<>(); + private List outputs = new ArrayList<>(); + + public String getTestSuiteName() { + return testSuiteName; + } + public VTPTestCase setTestSuiteName(String testSuiteName) { + this.testSuiteName = testSuiteName; + return this; + } + public String getTestCaseName() { + return testCaseName; + } + public VTPTestCase setTestCaseName(String testCaseName) { + this.testCaseName = testCaseName; + return this; + } + + public String getDescripton() { + return descripton; + } + public void setDescripton(String descripton) { + this.descripton = descripton; + } + + public List getInputs() { + return inputs; + } + public VTPTestCase setInputs(List inputs) { + this.inputs = inputs; + return this; + } + + public List getOutputs() { + return outputs; + } + public VTPTestCase setOutputs(List outputs) { + this.outputs = outputs; + return this; + } + + public String getScenario() { + return scenario; + } + public VTPTestCase setScenario(String scenario) { + this.scenario = scenario; + return this; + } + + public String getAuthor() { + return author; + } + public void setAuthor(String author) { + this.author = author; + } + + public static class VTPTestCaseList extends VTPModelBase { + List testCases = new ArrayList<>(); + + public List getTestCases() { + return testCases; + } + + public VTPTestCaseList setTestCases(List testCases) { + this.testCases = testCases; + return this; + } + } + + public static class VTPTestCaseInput extends VTPModelBase { + private String name; + private String description; + private String type; + private String defaultValue; + private Boolean isOptional; + private JsonNode metadata; + + 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 getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public String getDefaultValue() { + return defaultValue; + } + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + public Boolean getIsOptional() { + return isOptional; + } + public void setIsOptional(Boolean isOptional) { + this.isOptional = isOptional; + } + public JsonNode getMetadata() { + return metadata; + } + public void setMetadata(JsonNode metadata) { + this.metadata = metadata; + } + } + + public static class VTPTestCaseOutput extends VTPModelBase { + private String name; + private String description; + private String type; + + public String getName() { + return this.name; + } + public void setName(String name) { + this.name = name; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + } +} diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestScenario.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestScenario.java new file mode 100644 index 00000000..9ddac81b --- /dev/null +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestScenario.java @@ -0,0 +1,57 @@ +/** + * Copyright 2019 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.vtp.scenario.model; + +import java.util.ArrayList; +import java.util.List; + +import org.onap.vtp.VTPModelBase; + +public class VTPTestScenario extends VTPModelBase{ + private String name; + private String description; + public String getName() { + return name; + } + + public VTPTestScenario setName(String name) { + this.name = name; + return this; + } + + public String getDescription() { + return description; + } + + public VTPTestScenario setDescription(String description) { + this.description = description; + return this; + } + + public static class VTPTestScenarioList extends VTPModelBase { + List scenarios = new ArrayList<>(); + + public List getScenarios() { + return scenarios; + } + + public VTPTestScenarioList setScenarios(List scenarios) { + this.scenarios = scenarios; + return this; + } + } +} diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestSuite.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestSuite.java new file mode 100644 index 00000000..0759975a --- /dev/null +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestSuite.java @@ -0,0 +1,58 @@ +/** + * Copyright 2019 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.vtp.scenario.model; + +import java.util.ArrayList; +import java.util.List; + +import org.onap.vtp.VTPModelBase; + +public class VTPTestSuite extends VTPModelBase{ + private String name; + + private String description; + + public String getDescription() { + return description; + } + + public VTPTestSuite setDescription(String description) { + this.description = description; + return this; + } + public String getName() { + return name; + } + + public VTPTestSuite setName(String name) { + this.name = name; + return this; + } + + public static class VTPTestSuiteList extends VTPModelBase { + List suites = new ArrayList<>(); + + public List getSuites() { + return suites; + } + + public VTPTestSuiteList setSuites(List suites) { + this.suites = suites; + return this; + } + } +} -- cgit 1.2.3-korg