diff options
Diffstat (limited to 'vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp')
5 files changed, 81 insertions, 63 deletions
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 index 599fb774..60cdf65c 100644 --- 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 @@ -36,7 +36,6 @@ public class VTPModelBase { objectMapper.setSerializationInclusion(Include.NON_EMPTY); return objectMapper.writeValueAsString(obj); } catch (JsonProcessingException e) { - logger.error("Exception while processing json {}", e.getMessage()); return "{}"; } } 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 index 1c1c6336..b50e30f1 100644 --- 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 @@ -105,8 +105,7 @@ public class VTPResource { protected JsonNode makeRpcAndGetJson(List<String> args, int timeout) throws VTPException, IOException { Result result = this.makeRpc(args, timeout); ObjectMapper mapper = new ObjectMapper(); - JsonNode resultJson = mapper.readTree(result.getOutput()); - return resultJson; + return mapper.readTree(result.getOutput()); } protected Output makeRpc(String scenario, String requestId, String profile, String testCase, JsonNode argsJsonNode) throws VTPException { 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 index b0cbcad8..6f41f626 100644 --- 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 @@ -70,6 +70,19 @@ import io.swagger.annotations.ApiResponses; @Path("/vtp") @Api(tags = {"VTP Execution"}) public class VTPExecutionResource extends VTPResource{ + private static final String EXECUTION_ID = "execution-id"; + private static final String START_TIME = "start-time"; + private static final String END_TIME = "end-time"; + private static final String REQUEST_ID = "request-id"; + private static final String PRODUCT = "product"; + private static final String SERVICE = "service"; + private static final String COMMAND = "command"; + private static final String PROFILE = "profile"; + private static final String STATUS = "status"; + private static final String OUTPUT = "output"; + private static final String INPUT = "input"; + + public VTPTestExecutionList executeHandler(VTPTestExecutionList executions, String requestId) throws VTPException, IOException { if (requestId == null) { requestId = UUID.randomUUID().toString(); @@ -89,7 +102,7 @@ public class VTPExecutionResource extends VTPResource{ ); String endTime = dateFormatter.format(new Date()); execution.setEndTime(endTime); - execution.setExecutionId(output.getAddonsMap().get("execution-id")); + execution.setExecutionId(output.getAddonsMap().get(EXECUTION_ID)); // set execution status based on success from test. if (output.getSuccess()) { @@ -242,27 +255,32 @@ public class VTPExecutionResource extends VTPResource{ 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()); + 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); } @@ -309,43 +327,43 @@ public class VTPExecutionResource extends VTPResource{ 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(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) { + if (result.get(OUTPUT) != null) { ObjectMapper mapper = new ObjectMapper(); JsonNode resultJson = null; try { - resultJson = mapper.readTree(result.get("output").asText()); + resultJson = mapper.readTree(result.get(OUTPUT).asText()); //workarround, sometimes its null. if (resultJson == null) { - resultJson = mapper.readTree(result.get("output").toString()); + resultJson = mapper.readTree(result.get(OUTPUT).toString()); } } catch (Exception e) { ObjectNode node = JsonNodeFactory.instance.objectNode(); - node.put("error", result.get("output").asText()); + node.put("error", result.get(OUTPUT).asText()); resultJson = node; } @@ -372,7 +390,7 @@ public class VTPExecutionResource extends VTPResource{ } public String getTestExecutionLogsHandler( - String executionId, String action) throws VTPException, IOException{ + String executionId, String action) throws VTPException { List<String> args = new ArrayList<>(); args.addAll(Arrays.asList(new String[] { "--product", "open-cli", "execution-show-" + action, "--execution-id", executionId, "--format", "text" @@ -396,7 +414,7 @@ public class VTPExecutionResource extends VTPResource{ @ApiParam("Test execution Id") @PathParam("executionId") String executionId, @ApiParam("Test console reports, Options: out, err, debug") @DefaultValue("out") @QueryParam("option") String option ) throws VTPException, IOException { - if (!(option.equalsIgnoreCase("out") || option.equalsIgnoreCase("err") || option.equalsIgnoreCase("debug"))) { + if (!("out".equalsIgnoreCase(option) || "err".equalsIgnoreCase(option) || "debug".equalsIgnoreCase(option))) { option = "out"; } 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 index 524b8e5a..e56333be 100644 --- 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 @@ -17,13 +17,13 @@ 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{ @@ -35,7 +35,7 @@ public class VTPTestExecution extends VTPModelBase{ private String profile; private JsonNode parameters = JsonNodeFactory.instance.objectNode(); private JsonNode results = JsonNodeFactory.instance.objectNode(); - public static enum Status { + public enum Status { IN_PROGRESS, COMPLETED, FAILED; } 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 index fda50ca4..575bdc2e 100644 --- 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 @@ -55,6 +55,7 @@ import io.swagger.annotations.ApiResponses; @Path("/vtp") @Api(tags = {"VTP Scenario"}) public class VTPScenarioResource extends VTPResource{ + private static final String DESCRIPTION = "description"; public VTPTestScenarioList listTestScenariosHandler() throws VTPException, IOException{ List<String> args = new ArrayList<>(); @@ -74,10 +75,11 @@ public class VTPScenarioResource extends VTPResource{ if (n.elements().hasNext()) { String name = n.get("product").asText(); - if (name.equalsIgnoreCase("open-cli")) continue; + if ("open-cli".equalsIgnoreCase(name)) + continue; list.getScenarios().add(new VTPTestScenario().setName(name).setDescription( - n.get("description").asText())); + n.get(DESCRIPTION).asText())); } } } @@ -116,7 +118,7 @@ public class VTPScenarioResource extends VTPResource{ JsonNode n = it.next(); if (n.elements().hasNext()) { list.getSuites().add(new VTPTestSuite().setName(n.get("service").asText()).setDescription( - n.get("description").asText())); + n.get(DESCRIPTION).asText())); } } } @@ -198,7 +200,7 @@ public class VTPScenarioResource extends VTPResource{ VTPTestCase tc = new VTPTestCase(); tc.setTestCaseName(schema.get("name").asText()); - tc.setDescription(schema.get("description").asText()); + tc.setDescription(schema.get(DESCRIPTION).asText()); tc.setTestSuiteName(schema.get("service").asText()); tc.setAuthor(schema.get("author").asText()); JsonNode inputsJson = schema.get("inputs"); @@ -207,7 +209,7 @@ public class VTPScenarioResource extends VTPResource{ VTPTestCaseInput input = new VTPTestCaseInput(); input.setName(inputJson.get("name").asText()); - input.setDescription(inputJson.get("description").asText()); + input.setDescription(inputJson.get(DESCRIPTION).asText()); input.setType(inputJson.get("type").asText()); if (inputJson.get("is_optional") != null) @@ -228,7 +230,7 @@ public class VTPScenarioResource extends VTPResource{ for (final JsonNode outputJson: outputsJson) { VTPTestCaseOutput output = new VTPTestCaseOutput(); output.setName(outputJson.get("name").asText()); - output.setDescription(outputJson.get("description").asText()); + output.setDescription(outputJson.get(DESCRIPTION).asText()); output.setType(outputJson.get("type").asText()); tc.getOutputs().add(output); |