aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
authoratulpurohit <atul.purohit1@vodafone.com>2019-11-01 15:01:03 +0530
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-12-20 07:21:05 +0000
commit39116c7da381ff5e5b2ce7ae80f103dfc77c0253 (patch)
treeb8af768fdbacd6116ce7ed145899fac8632ef79d /openecomp-be
parente38ef745ab296de90cb428f26348de32e4295420 (diff)
Unique identifier for test execution
Issue-ID: SDC-2584 Co-authored-by: nikhil.soni@vodafone.com Signed-off-by: atulpurohit <atul.purohit1@vodafone.com> Change-Id: I3e7f1a84935cbcd26f8a42a6e2d2dbcb7533cb19 Signed-off-by: atulpurohit <atul.purohit1@vodafone.com>
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/pom.xml40
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/ExternalTesting.java101
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/services/ExternalTestingImpl.java319
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTest.java468
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManager.java34
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java1517
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VspManagerFactoryImpl.java40
-rw-r--r--openecomp-be/dist/sdc-onboard-backend-docker/artifacts/chef-repo/cookbooks/sdc-onboard-backend/attributes/default.rb2
-rw-r--r--openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/main/java/org/openecomp/core/externaltesting/api/ExternalTestingManager.java174
-rw-r--r--openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/main/java/org/openecomp/core/externaltesting/api/VtpTestExecutionOutput.java32
-rw-r--r--openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/main/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImpl.java1615
-rw-r--r--openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImplTest.java213
12 files changed, 2257 insertions, 2298 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/pom.xml b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/pom.xml
index d7b40a33c5..52011ab651 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/pom.xml
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/pom.xml
@@ -119,19 +119,47 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-common-rest</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4-common</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
</dependency>
<dependency>
- <groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-externaltesting-impl</artifactId>
- <version>${project.version}</version>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito2</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-externaltesting-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <scope>provided</scope>
</dependency>
</dependencies>
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/ExternalTesting.java b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/ExternalTesting.java
index c25456f1ae..5f70570429 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/ExternalTesting.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/ExternalTesting.java
@@ -18,17 +18,23 @@ package org.openecomp.sdcrests.externaltesting.rest;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
+import java.util.List;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+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.cxf.jaxrs.ext.multipart.Attachment;
+import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.openecomp.core.externaltesting.api.ClientConfiguration;
import org.openecomp.core.externaltesting.api.RemoteTestingEndpointDefinition;
-import org.openecomp.core.externaltesting.api.VtpTestExecutionRequest;
import org.springframework.validation.annotation.Validated;
-import javax.ws.rs.*;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.util.List;
-
-
@Path("/v1.0/externaltesting")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@@ -37,55 +43,58 @@ import java.util.List;
public interface ExternalTesting {
- @GET
- @Path("/config")
- Response getConfig();
+ @GET
+ @Path("/config")
+ Response getConfig();
- @PUT
- @Path("/config")
- Response setConfig(ClientConfiguration config);
+ @PUT
+ @Path("/config")
+ Response setConfig(ClientConfiguration config);
- @GET
- @Path("/testcasetree")
- Response getTestCasesAsTree();
+ @GET
+ @Path("/testcasetree")
+ Response getTestCasesAsTree();
- @GET
- @Path("/endpoints")
- Response getEndpoints();
+ @GET
+ @Path("/endpoints")
+ Response getEndpoints();
- @PUT
- @Path("/endpoints")
- Response setEndpoints(List<RemoteTestingEndpointDefinition> endpoints);
+ @PUT
+ @Path("/endpoints")
+ Response setEndpoints(List<RemoteTestingEndpointDefinition> endpoints);
- @GET
- @Path("/endpoints/{endpointId}/scenarios")
- Response getScenarios(@PathParam("endpointId") String endpointId);
+ @GET
+ @Path("/endpoints/{endpointId}/scenarios")
+ Response getScenarios(@PathParam("endpointId") String endpointId);
- @GET
- @Path("/endpoints/{endpointId}/scenarios/{scenario}/testsuites")
- Response getTestsuites(@PathParam("endpointId") String endpointId, @PathParam("scenario") String scenario);
+ @GET
+ @Path("/endpoints/{endpointId}/scenarios/{scenario}/testsuites")
+ Response getTestsuites(@PathParam("endpointId") String endpointId, @PathParam("scenario") String scenario);
- @GET
- @Path("/endpoints/{endpointId}/scenarios/{scenario}/testcases")
- Response getTestcases(@PathParam("endpointId") String endpointId,
- @PathParam("scenario") String scenario);
+ @GET
+ @Path("/endpoints/{endpointId}/scenarios/{scenario}/testcases")
+ Response getTestcases(@PathParam("endpointId") String endpointId, @PathParam("scenario") String scenario);
- @GET
- @Path("/endpoints/{endpointId}/scenarios/{scenario}/testsuites/{testsuite}/testcases/{testcase}")
- Response getTestcase(@PathParam("endpointId") String endpointId,
- @PathParam("scenario") String scenario,
- @PathParam("testsuite") String testsuite,
- @PathParam("testcase") String testcase);
+ @GET
+ @Path("/endpoints/{endpointId}/scenarios/{scenario}/testsuites/{testsuite}/testcases/{testcase}")
+ Response getTestcase(@PathParam("endpointId") String endpointId, @PathParam("scenario") String scenario,
+ @PathParam("testsuite") String testsuite, @PathParam("testcase") String testcase);
- @POST
- @Path("/endpoints/{endpointId}/executions/{executionId}")
- Response getExecution(@PathParam("endpointId") String endpointId,
- @PathParam("executionId") String executionId);
+ @POST
+ @Path("/endpoints/{endpointId}/executions/{executionId}")
+ Response getExecution(@PathParam("endpointId") String endpointId, @PathParam("executionId") String executionId);
- @POST
- @Path("/executions")
- Response execute(List<VtpTestExecutionRequest> req,
- @QueryParam("requestId") String requestId);
+ @POST
+ @Path("/executions")
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ Response execute(@QueryParam("vspId") String vspId, @QueryParam("vspVersionId") String vspVersionId,
+ @QueryParam("requestId") String requestId,
+ @Multipart(value = "files", required = false) List<Attachment> files,
+ @Multipart(value = "testdata", required = false) String testData);
+ @GET
+ @Path("/executions")
+ Response getValidationResult(@QueryParam("requestId") String requestId,
+ @QueryParam("endPoint") List<String> endPoints);
}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/services/ExternalTestingImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/services/ExternalTestingImpl.java
index 1ce89b6748..7e8e98837e 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/services/ExternalTestingImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/main/java/org/openecomp/sdcrests/externaltesting/rest/services/ExternalTestingImpl.java
@@ -19,179 +19,240 @@
package org.openecomp.sdcrests.externaltesting.rest.services;
-
-import org.openecomp.core.externaltesting.api.*;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import javax.inject.Named;
+import javax.ws.rs.core.Response;
+import org.apache.commons.io.IOUtils;
+import org.apache.cxf.jaxrs.ext.multipart.Attachment;
+import org.openecomp.core.externaltesting.api.ClientConfiguration;
+import org.openecomp.core.externaltesting.api.ExternalTestingManager;
+import org.openecomp.core.externaltesting.api.RemoteTestingEndpointDefinition;
+import org.openecomp.core.externaltesting.api.TestErrorBody;
+import org.openecomp.core.externaltesting.api.VtpTestExecutionOutput;
+import org.openecomp.core.externaltesting.api.VtpTestExecutionRequest;
+import org.openecomp.core.externaltesting.api.VtpTestExecutionResponse;
import org.openecomp.core.externaltesting.errors.ExternalTestingException;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
+import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory;
import org.openecomp.sdcrests.externaltesting.rest.ExternalTesting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
-import javax.inject.Named;
-import javax.ws.rs.core.Response;
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
@SuppressWarnings("unused")
@Named
@Service("externaltesting")
@Scope(value = "prototype")
public class ExternalTestingImpl implements ExternalTesting {
- private final ExternalTestingManager testingManager;
-
- private static final Logger logger =
- LoggerFactory.getLogger(ExternalTestingImpl.class);
+ private final ExternalTestingManager testingManager;
+ private static final int REQUEST_ID_LENGTH = 8;
+ private static final String TESTING_INTERNAL_ERROR = "SDC-TEST-005";
+ private final VendorSoftwareProductManager vendorSoftwareProductManager =
+ VspManagerFactory.getInstance().createInterface();
+ private static final Logger logger = LoggerFactory.getLogger(ExternalTestingImpl.class);
- public ExternalTestingImpl(@Autowired ExternalTestingManager testingManager) {
- this.testingManager = testingManager;
- }
-
- /**
- * Return the configuration of the feature to the client.
- * @return JSON response content.
- */
- @Override
- public Response getConfig() {
- try {
- return Response.ok(testingManager.getConfig()).build();
- }
- catch (ExternalTestingException e) {
- return convertTestingException(e);
+ public ExternalTestingImpl(@Autowired ExternalTestingManager testingManager) {
+ this.testingManager = testingManager;
}
- }
- /**
- * To enable automated functional testing, allow
- * a put for the client configuration.
- * @return JSON response content.
- */
- @Override
- public Response setConfig(ClientConfiguration config) {
- try {
- return Response.ok(testingManager.setConfig(config)).build();
+ /**
+ * Return the configuration of the feature to the client.
+ *
+ * @return JSON response content.
+ */
+ @Override
+ public Response getConfig() {
+ try {
+ return Response.ok(testingManager.getConfig()).build();
+ } catch (ExternalTestingException e) {
+ return convertTestingException(e);
+ }
}
- catch (ExternalTestingException e) {
- return convertTestingException(e);
+
+ /**
+ * To enable automated functional testing, allow
+ * a put for the client configuration.
+ *
+ * @return JSON response content.
+ */
+ @Override
+ public Response setConfig(ClientConfiguration config) {
+ try {
+ return Response.ok(testingManager.setConfig(config)).build();
+ } catch (ExternalTestingException e) {
+ return convertTestingException(e);
+ }
}
- }
- /**
- * Return the test tree structure created by the testing manager.
- * @return JSON response content.
- */
- @Override
- public Response getTestCasesAsTree() {
- try {
- return Response.ok(testingManager.getTestCasesAsTree()).build();
+ /**
+ * Return the test tree structure created by the testing manager.
+ *
+ * @return JSON response content.
+ */
+ @Override
+ public Response getTestCasesAsTree() {
+ try {
+ return Response.ok(testingManager.getTestCasesAsTree()).build();
+ } catch (ExternalTestingException e) {
+ return convertTestingException(e);
+ }
}
- catch (ExternalTestingException e) {
- return convertTestingException(e);
- }
- }
- @Override
- public Response getEndpoints() {
- try {
- return Response.ok(testingManager.getEndpoints()).build();
+ @Override
+ public Response getEndpoints() {
+ try {
+ return Response.ok(testingManager.getEndpoints()).build();
+ } catch (ExternalTestingException e) {
+ return convertTestingException(e);
+ }
}
- catch (ExternalTestingException e) {
- return convertTestingException(e);
+
+ /**
+ * To enable automated functional testing, allow a put of the endpoints.
+ *
+ * @return JSON response content.
+ */
+ @Override
+ public Response setEndpoints(List<RemoteTestingEndpointDefinition> endpoints) {
+ try {
+ return Response.ok(testingManager.setEndpoints(endpoints)).build();
+ } catch (ExternalTestingException e) {
+ return convertTestingException(e);
+ }
}
- }
- /**
- * To enable automated functional testing, allow a put of the endpoints.
- * @return JSON response content.
- */
- @Override
- public Response setEndpoints(List<RemoteTestingEndpointDefinition> endpoints) {
- try {
- return Response.ok(testingManager.setEndpoints(endpoints)).build();
+ @Override
+ public Response getScenarios(String endpoint) {
+ try {
+ return Response.ok(testingManager.getScenarios(endpoint)).build();
+ } catch (ExternalTestingException e) {
+ return convertTestingException(e);
+ }
+
}
- catch (ExternalTestingException e) {
- return convertTestingException(e);
+
+ @Override
+ public Response getTestsuites(String endpoint, String scenario) {
+ try {
+ return Response.ok(testingManager.getTestSuites(endpoint, scenario)).build();
+ } catch (ExternalTestingException e) {
+ return convertTestingException(e);
+ }
}
- }
- @Override
- public Response getScenarios(String endpoint) {
- try {
- return Response.ok(testingManager.getScenarios(endpoint)).build();
+ @Override
+ public Response getTestcases(String endpoint, String scenario) {
+ try {
+ return Response.ok(testingManager.getTestCases(endpoint, scenario)).build();
+ } catch (ExternalTestingException e) {
+ return convertTestingException(e);
+ }
}
- catch (ExternalTestingException e) {
- return convertTestingException(e);
+
+ @Override
+ public Response getTestcase(String endpoint, String scenario, String testsuite, String testcase) {
+ try {
+ return Response.ok(testingManager.getTestCase(endpoint, scenario, testsuite, testcase)).build();
+ } catch (ExternalTestingException e) {
+ return convertTestingException(e);
+ }
}
- }
+ @Override
+ public Response execute(String vspId, String vspVersionId, String requestId, List<Attachment> files,
+ String testDataString) {
+ try {
+ List<VtpTestExecutionRequest> req = getVtpTestExecutionRequestObj(testDataString);
+ Map<String, byte[]> fileMap = getFileMap(files);
+ List<VtpTestExecutionResponse> vtpTestExecutionResponses =
+ testingManager.execute(req, vspId, vspVersionId, requestId, fileMap);
+ return Response.status(HttpStatus.OK.value()).entity(vtpTestExecutionResponses).build();
+ } catch (ExternalTestingException e) {
+ return convertTestingException(e);
+ }
- @Override
- public Response getTestsuites(String endpoint, String scenario) {
- try {
- return Response.ok(testingManager.getTestSuites(endpoint, scenario)).build();
- }
- catch (ExternalTestingException e) {
- return convertTestingException(e);
}
- }
- @Override
- public Response getTestcases(String endpoint, String scenario) {
- try {
- return Response.ok(testingManager.getTestCases(endpoint, scenario)).build();
- }
- catch (ExternalTestingException e) {
- return convertTestingException(e);
+ @Override
+ public Response getValidationResult(String requestId, List<String> endPoints) {
+ try {
+ List<VtpTestExecutionResponse> resultsFromVtp = new ArrayList<>();
+ for (String endPoint : endPoints) {
+ List<VtpTestExecutionOutput> vtpTestExecutionOutput =
+ testingManager.getExecutionIds(endPoint, requestId);
+ List<String> execIds = vtpTestExecutionOutput.stream().map(VtpTestExecutionOutput::getExecutionId)
+ .collect(Collectors.toList());
+ List<VtpTestExecutionResponse> resultFromVtp = getVtpResultbyExecutionId(execIds, endPoint);
+ resultsFromVtp.addAll(resultFromVtp);
+ }
+ return Response.status(HttpStatus.OK.value()).entity(resultsFromVtp).build();
+ } catch (ExternalTestingException e) {
+ return convertTestingException(e);
+ }
}
- }
- @Override
- public Response getTestcase(String endpoint, String scenario, String testsuite, String testcase) {
- try {
- return Response.ok(testingManager.getTestCase(endpoint, scenario, testsuite, testcase)).build();
- }
- catch (ExternalTestingException e) {
- return convertTestingException(e);
- }
- }
+ private List<VtpTestExecutionRequest> getVtpTestExecutionRequestObj(String testDataString) {
+ try {
+ return new ObjectMapper().configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true).reader()
+ .forType(new TypeReference<List<VtpTestExecutionRequest>>() { }).readValue(testDataString);
+ } catch (IOException e) {
+ throw new ExternalTestingException(TESTING_INTERNAL_ERROR, 500, e.getMessage(), e);
- @Override
- public Response execute(List<VtpTestExecutionRequest> req, String requestId) {
- try {
- List<VtpTestExecutionResponse> responses = testingManager.execute(req, requestId);
- List<Integer> statuses = responses.stream().map(r-> Optional.ofNullable(r.getHttpStatus()).orElse(HttpStatus.OK.value())).distinct().collect(Collectors.toList());
- if (statuses.size() == 1) {
- return Response.status(HttpStatus.OK.value()).entity(responses).build();
- }
- else {
- return Response.status(HttpStatus.MULTI_STATUS.value()).entity(responses).build();
- }
+ }
}
- catch (ExternalTestingException e) {
- return convertTestingException(e);
+
+ private List<VtpTestExecutionResponse> getVtpResultbyExecutionId(List<String> executionIds, String endPoint) {
+ List<VtpTestExecutionResponse> vtpTestExecutionResponses = new ArrayList<>();
+ executionIds.stream().forEach(executionId -> {
+ VtpTestExecutionResponse executionResult = testingManager.getExecution(endPoint, executionId);
+ vtpTestExecutionResponses.add(executionResult);
+ });
+ return vtpTestExecutionResponses;
}
- }
- @Override
- public Response getExecution(String endpoint, String executionId) {
- try {
- return Response.ok(testingManager.getExecution(endpoint, executionId)).build();
+
+ @Override
+ public Response getExecution(String endpoint, String executionId) {
+ try {
+ return Response.ok(testingManager.getExecution(endpoint, executionId)).build();
+ } catch (ExternalTestingException e) {
+ return convertTestingException(e);
+ }
}
- catch (ExternalTestingException e) {
- return convertTestingException(e);
+
+ private Map<String, byte[]> getFileMap(List<Attachment> files) {
+ if (files != null && !files.isEmpty()) {
+
+ return files.stream().collect(
+ Collectors.toMap(attachment -> attachment.getDataHandler().getName(), attachment -> {
+ try {
+ return IOUtils.toByteArray(attachment.getDataHandler().getInputStream());
+ } catch (IOException e) {
+ throw new ExternalTestingException(TESTING_INTERNAL_ERROR, 500, e.getMessage(), e);
+ }
+ }));
+ }
+
+ return null;
}
- }
- private Response convertTestingException(ExternalTestingException e) {
- if (logger.isErrorEnabled()) {
- logger.error("testing exception {} {} {}", e.getMessageCode(), e.getHttpStatus(), e.getDetail(), e);
+ private Response convertTestingException(ExternalTestingException e) {
+ if (logger.isErrorEnabled()) {
+ logger.error("testing exception {} {} {}", e.getMessageCode(), e.getHttpStatus(), e.getDetail(), e);
+ }
+ TestErrorBody body = new TestErrorBody(e.getMessageCode(), e.getHttpStatus(), e.getDetail());
+ return Response.status(e.getHttpStatus()).entity(body).build();
}
- TestErrorBody body = new TestErrorBody(e.getMessageCode(), e.getHttpStatus(), e.getDetail());
- return Response.status(e.getHttpStatus()).entity(body).build();
- }
}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTest.java
index 5f302bebc6..883b89a16e 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTest.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTest.java
@@ -16,245 +16,287 @@
package org.openecomp.sdcrests.externaltesting.rest.services;
-import org.junit.Assert;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.openecomp.core.externaltesting.api.*;
-import org.openecomp.core.externaltesting.errors.ExternalTestingException;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
-import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
+import javax.ws.rs.core.Response;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.openecomp.core.externaltesting.api.ClientConfiguration;
+import org.openecomp.core.externaltesting.api.ExternalTestingManager;
+import org.openecomp.core.externaltesting.api.RemoteTestingEndpointDefinition;
+import org.openecomp.core.externaltesting.api.TestTreeNode;
+import org.openecomp.core.externaltesting.api.VtpNameDescriptionPair;
+import org.openecomp.core.externaltesting.api.VtpTestCase;
+import org.openecomp.core.externaltesting.api.VtpTestExecutionOutput;
+import org.openecomp.core.externaltesting.api.VtpTestExecutionRequest;
+import org.openecomp.core.externaltesting.api.VtpTestExecutionResponse;
+import org.openecomp.core.externaltesting.errors.ExternalTestingException;
+import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
+import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({VspManagerFactory.class})
public class ApiTest {
- private static final String EP = "ep";
- private static final String EXEC = "exec";
- private static final String SC = "sc";
- private static final String TS = "ts";
- private static final String TC = "tc";
- private static final String EXPECTED = "Expected";
-
-
- @Mock
- private ExternalTestingManager testingManager;
-
- /**
- * At the API level, test that the code does not throw
- * exceptions but there's not much to test.
- */
- @Test
- public void testApi() {
- MockitoAnnotations.initMocks(this);
-
- ExternalTestingImpl testing = new ExternalTestingImpl(testingManager);
- Assert.assertNotNull(testing.getConfig());
- Assert.assertNotNull(testing.getEndpoints());
- Assert.assertNotNull(testing.getExecution(EP, EXEC));
- Assert.assertNotNull(testing.getScenarios(EP));
- Assert.assertNotNull(testing.getTestcase(EP, SC, TS, TC));
- Assert.assertNotNull(testing.getTestcases(EP, SC));
- Assert.assertNotNull(testing.getTestsuites(EP, SC));
- Assert.assertNotNull(testing.getTestCasesAsTree());
-
- List<VtpTestExecutionRequest> requests =
- Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest());
- Assert.assertNotNull(testing.execute(requests, "requestId"));
-
-
- ClientConfiguration cc = new ClientConfiguration();
- Assert.assertNotNull(testing.setConfig(cc));
-
- ArrayList<RemoteTestingEndpointDefinition> lst = new ArrayList<>();
- Assert.assertNotNull(testing.setEndpoints(lst));
- }
-
- class ApiTestExternalTestingManager implements ExternalTestingManager {
- @Override
- public ClientConfiguration getConfig() {
- throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ private static final String EP = "ep";
+ private static final String EXEC = "exec";
+ private static final String SC = "sc";
+ private static final String TS = "ts";
+ private static final String TC = "tc";
+ private static final String EXPECTED = "Expected";
+
+ @Mock
+ private ExternalTestingManager testingManager;
+ @Mock
+ private VspManagerFactory vspManagerFactory;
+ @Mock
+ VendorSoftwareProductManager vendorSoftwareProductManager;
+
+ @Before
+ public void setUp() {
+ try {
+ initMocks(this);
+ mockStatic(VspManagerFactory.class);
+ when(VspManagerFactory.getInstance()).thenReturn(vspManagerFactory);
+ when(vspManagerFactory.createInterface()).thenReturn(vendorSoftwareProductManager);
+ when(vspManagerFactory.getInstance().createInterface()).thenReturn(vendorSoftwareProductManager);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
- @Override
- public ClientConfiguration setConfig(ClientConfiguration config) {
- throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+
+ /**
+ * At the API level, test that the code does not throw
+ * exceptions but there's not much to test.
+ */
+ @Test
+ public void testApi() {
+
+
+ ExternalTestingImpl testing = new ExternalTestingImpl(testingManager);
+ Assert.assertNotNull(testing.getConfig());
+ Assert.assertNotNull(testing.getEndpoints());
+ Assert.assertNotNull(testing.getExecution(EP, EXEC));
+ Assert.assertNotNull(testing.getScenarios(EP));
+ Assert.assertNotNull(testing.getTestcase(EP, SC, TS, TC));
+ Assert.assertNotNull(testing.getTestcases(EP, SC));
+ Assert.assertNotNull(testing.getTestsuites(EP, SC));
+ Assert.assertNotNull(testing.getTestCasesAsTree());
+
+ List<VtpTestExecutionRequest> requests =
+ Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest());
+ Assert.assertNotNull(testing.execute("vspId", "vspVersionId", "abc", null, "[]"));
+
+
+ ClientConfiguration cc = new ClientConfiguration();
+ Assert.assertNotNull(testing.setConfig(cc));
+
+ ArrayList<RemoteTestingEndpointDefinition> lst = new ArrayList<>();
+ Assert.assertNotNull(testing.setEndpoints(lst));
}
- @Override
- public List<RemoteTestingEndpointDefinition> setEndpoints(List<RemoteTestingEndpointDefinition> endpoints) {
- throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ class ApiTestExternalTestingManager implements ExternalTestingManager {
+
+ @Override
+ public ClientConfiguration getConfig() {
+ throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ }
+
+ @Override
+ public ClientConfiguration setConfig(ClientConfiguration config) {
+ throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ }
+
+ @Override
+ public List<RemoteTestingEndpointDefinition> setEndpoints(List<RemoteTestingEndpointDefinition> endpoints) {
+ throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ }
+
+ @Override
+ public TestTreeNode getTestCasesAsTree() {
+ throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ }
+
+ @Override
+ public List<RemoteTestingEndpointDefinition> getEndpoints() {
+ throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ }
+
+ @Override
+ public List<VtpNameDescriptionPair> getScenarios(String endpoint) {
+ throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ }
+
+ @Override
+ public List<VtpNameDescriptionPair> getTestSuites(String endpoint, String scenario) {
+ throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ }
+
+ @Override
+ public List<VtpTestCase> getTestCases(String endpoint, String scenario) {
+ throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ }
+
+ @Override
+ public VtpTestCase getTestCase(String endpoint, String scenario, String testSuite, String testCaseName) {
+ throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ }
+
+ @Override
+ public List<VtpTestExecutionResponse> execute(List<VtpTestExecutionRequest> requests, String vspId,
+ String vspVersionId, String requestId, Map<String, byte[]> fileMap) {
+
+ throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ }
+
+ @Override
+ public VtpTestExecutionResponse getExecution(String endpoint, String executionId) {
+ throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ }
+
+ @Override
+ public List<VtpTestExecutionOutput> getExecutionIds(String endpoint, String requestId) {
+ throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ }
+
}
- @Override
- public TestTreeNode getTestCasesAsTree() {
- throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ /**
+ * Test the exception handler logic for configuration get/set.
+ */
+ @Test()
+ public void testConfigExceptions() {
+ initMocks(this);
+
+ ExternalTestingManager m = new ApiTestExternalTestingManager();
+ ExternalTestingImpl testingF = new ExternalTestingImpl(m);
+
+ Response getResponse = testingF.getConfig();
+ Assert.assertEquals(500, getResponse.getStatus());
+
+ Response setResponse = testingF.setConfig(new ClientConfiguration());
+ Assert.assertEquals(500, setResponse.getStatus());
}
- @Override
- public List<RemoteTestingEndpointDefinition> getEndpoints() {
- throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ /**
+ * Test the exception handler logic for endpoint get/set.
+ */
+ @Test()
+ public void testEndpointExceptions() {
+ initMocks(this);
+
+ ExternalTestingManager m = new ApiTestExternalTestingManager();
+ ExternalTestingImpl testingF = new ExternalTestingImpl(m);
+
+ Response getResponse = testingF.getEndpoints();
+ Assert.assertEquals(500, getResponse.getStatus());
+
+ Response setResponse = testingF.setEndpoints(new ArrayList<>());
+ Assert.assertEquals(500, setResponse.getStatus());
}
- @Override
- public List<VtpNameDescriptionPair> getScenarios(String endpoint) {
- throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ /**
+ * Test the exception handler logic for executions (invocation and query).
+ */
+ @Test()
+ public void testExecutionExceptions() {
+ initMocks(this);
+
+ ExternalTestingManager m = new ApiTestExternalTestingManager();
+ ExternalTestingImpl testingF = new ExternalTestingImpl(m);
+
+ Response invokeResponse = testingF.execute("vspId", "vspVersionId", "abc", null, "[]");
+ Assert.assertEquals(500, invokeResponse.getStatus());
+
+ Response getResponse = testingF.getExecution(EP, EXEC);
+ Assert.assertEquals(500, getResponse.getStatus());
}
- @Override
- public List<VtpNameDescriptionPair> getTestSuites(String endpoint, String scenario) {
- throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+
+ /**
+ * Test the exception handler logic for the cases when the
+ * testing manager throws an accessing the scenarios.
+ */
+ @Test()
+ public void testScenarioExceptions() {
+ initMocks(this);
+
+ ExternalTestingManager m = new ApiTestExternalTestingManager();
+ ExternalTestingImpl testingF = new ExternalTestingImpl(m);
+
+ Response response = testingF.getScenarios(EP);
+ Assert.assertEquals(500, response.getStatus());
}
- @Override
- public List<VtpTestCase> getTestCases(String endpoint, String scenario) {
- throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ /**
+ * Test the exception handler logic for the cases when the
+ * testing manager throws an accessing a test case.
+ */
+ @Test()
+ public void testTestCaseExceptions() {
+ initMocks(this);
+
+ ExternalTestingManager m = new ApiTestExternalTestingManager();
+ ExternalTestingImpl testingF = new ExternalTestingImpl(m);
+
+ Response response = testingF.getTestcase(EP, SC, TS, TC);
+ Assert.assertEquals(500, response.getStatus());
}
- @Override
- public VtpTestCase getTestCase(String endpoint, String scenario, String testSuite, String testCaseName) {
- throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ /**
+ * Test the exception handler logic for the cases when the
+ * testing manager throws an accessing the test cases.
+ */
+ @Test()
+ public void testTestCasesExceptions() {
+ initMocks(this);
+
+ ExternalTestingManager m = new ApiTestExternalTestingManager();
+ ExternalTestingImpl testingF = new ExternalTestingImpl(m);
+
+ Response response = testingF.getTestcases(EP, SC);
+ Assert.assertEquals(500, response.getStatus());
}
- @Override
- public List<VtpTestExecutionResponse> execute(List<VtpTestExecutionRequest> requests, String requestId) {
- throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ /**
+ * Test the exception handler logic for the cases when the
+ * testing manager throws an accessing the test suites.
+ */
+ @Test()
+ public void testTestSuitesExceptions() {
+ initMocks(this);
+
+ ExternalTestingManager m = new ApiTestExternalTestingManager();
+ ExternalTestingImpl testingF = new ExternalTestingImpl(m);
+
+ Response response = testingF.getTestsuites(EP, SC);
+ Assert.assertEquals(500, response.getStatus());
}
- @Override
- public VtpTestExecutionResponse getExecution(String endpoint, String executionId) {
- throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
+ /**
+ * Test the exception handler logic for the cases when the
+ * testing manager throws an accessing the test tree.
+ */
+ @Test()
+ public void testTreeExceptions() {
+ initMocks(this);
+
+ ExternalTestingManager m = new ApiTestExternalTestingManager();
+ ExternalTestingImpl testingF = new ExternalTestingImpl(m);
+
+ Response response = testingF.getTestCasesAsTree();
+ Assert.assertEquals(500, response.getStatus());
}
- }
-
- /**
- * Test the exception handler logic for configuration get/set.
- */
- @Test()
- public void testConfigExceptions() {
- MockitoAnnotations.initMocks(this);
-
- ExternalTestingManager m = new ApiTestExternalTestingManager();
- ExternalTestingImpl testingF = new ExternalTestingImpl(m);
-
- Response getResponse = testingF.getConfig();
- Assert.assertEquals(500, getResponse.getStatus());
-
- Response setResponse = testingF.setConfig(new ClientConfiguration());
- Assert.assertEquals(500, setResponse.getStatus());
- }
-
- /**
- * Test the exception handler logic for endpoint get/set.
- */
- @Test()
- public void testEndpointExceptions() {
- MockitoAnnotations.initMocks(this);
-
- ExternalTestingManager m = new ApiTestExternalTestingManager();
- ExternalTestingImpl testingF = new ExternalTestingImpl(m);
-
- Response getResponse = testingF.getEndpoints();
- Assert.assertEquals(500, getResponse.getStatus());
-
- Response setResponse = testingF.setEndpoints(new ArrayList<>());
- Assert.assertEquals(500, setResponse.getStatus());
- }
-
- /**
- * Test the exception handler logic for executions (invocation and query).
- */
- @Test()
- public void testExecutionExceptions() {
- MockitoAnnotations.initMocks(this);
-
- ExternalTestingManager m = new ApiTestExternalTestingManager();
- ExternalTestingImpl testingF = new ExternalTestingImpl(m);
-
- List<VtpTestExecutionRequest> requests =
- Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest());
-
- Response invokeResponse = testingF.execute(requests, null);
- Assert.assertEquals(500, invokeResponse.getStatus());
-
- Response getResponse = testingF.getExecution(EP, EXEC);
- Assert.assertEquals(500, getResponse.getStatus());
- }
-
-
- /**
- * Test the exception handler logic for the cases when the
- * testing manager throws an accessing the scenarios.
- */
- @Test()
- public void testScenarioExceptions() {
- MockitoAnnotations.initMocks(this);
-
- ExternalTestingManager m = new ApiTestExternalTestingManager();
- ExternalTestingImpl testingF = new ExternalTestingImpl(m);
-
- Response response = testingF.getScenarios(EP);
- Assert.assertEquals(500, response.getStatus());
- }
-
- /**
- * Test the exception handler logic for the cases when the
- * testing manager throws an accessing a test case.
- */
- @Test()
- public void testTestCaseExceptions() {
- MockitoAnnotations.initMocks(this);
-
- ExternalTestingManager m = new ApiTestExternalTestingManager();
- ExternalTestingImpl testingF = new ExternalTestingImpl(m);
-
- Response response = testingF.getTestcase(EP, SC, TS, TC);
- Assert.assertEquals(500, response.getStatus());
- }
-
- /**
- * Test the exception handler logic for the cases when the
- * testing manager throws an accessing the test cases.
- */
- @Test()
- public void testTestCasesExceptions() {
- MockitoAnnotations.initMocks(this);
-
- ExternalTestingManager m = new ApiTestExternalTestingManager();
- ExternalTestingImpl testingF = new ExternalTestingImpl(m);
-
- Response response = testingF.getTestcases(EP, SC);
- Assert.assertEquals(500, response.getStatus());
- }
-
- /**
- * Test the exception handler logic for the cases when the
- * testing manager throws an accessing the test suites.
- */
- @Test()
- public void testTestSuitesExceptions() {
- MockitoAnnotations.initMocks(this);
-
- ExternalTestingManager m = new ApiTestExternalTestingManager();
- ExternalTestingImpl testingF = new ExternalTestingImpl(m);
-
- Response response = testingF.getTestsuites(EP, SC);
- Assert.assertEquals(500, response.getStatus());
- }
-
- /**
- * Test the exception handler logic for the cases when the
- * testing manager throws an accessing the test tree.
- */
- @Test()
- public void testTreeExceptions() {
- MockitoAnnotations.initMocks(this);
-
- ExternalTestingManager m = new ApiTestExternalTestingManager();
- ExternalTestingImpl testingF = new ExternalTestingImpl(m);
-
- Response response = testingF.getTestCasesAsTree();
- Assert.assertEquals(500, response.getStatus());
- }
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManager.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManager.java
index 870c4e762a..2339fa0921 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManager.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManager.java
@@ -36,40 +36,40 @@ import java.util.Optional;
public interface VendorSoftwareProductManager {
- VspDetails createVsp(VspDetails vspDetails);
+ VspDetails createVsp(VspDetails vspDetails);
- void updateVsp(VspDetails vspDetails);
+ void updateVsp(VspDetails vspDetails);
- VspDetails getVsp(String vspId, Version version);
+ VspDetails getVsp(String vspId, Version version);
- void deleteVsp(String vspId, Version version);
+ void deleteVsp(String vspId, Version version);
- ValidationResponse validate(VspDetails vspDetails) throws IOException;
+ ValidationResponse validate(VspDetails vspDetails) throws IOException;
- Map<String, List<ErrorMessage>> compile(String vspId, Version version);
+ Map<String, List<ErrorMessage>> compile(String vspId, Version version);
- QuestionnaireResponse getVspQuestionnaire(String vspId, Version version);
+ QuestionnaireResponse getVspQuestionnaire(String vspId, Version version);
- void updateVspQuestionnaire(String vspId, Version version, String questionnaireData);
+ void updateVspQuestionnaire(String vspId, Version version, String questionnaireData);
- byte[] getOrchestrationTemplateFile(String vspId, Version version);
+ byte[] getOrchestrationTemplateFile(String vspId, Version version);
- OrchestrationTemplateEntity getOrchestrationTemplateInfo(String vspId, Version version);
+ OrchestrationTemplateEntity getOrchestrationTemplateInfo(String vspId, Version version);
- Optional<FilesDataStructure> getOrchestrationTemplateStructure(String vspId, Version version);
+ Optional<FilesDataStructure> getOrchestrationTemplateStructure(String vspId, Version version);
- PackageInfo createPackage(String vspId, Version version) throws IOException;
+ PackageInfo createPackage(String vspId, Version version) throws IOException;
- List<PackageInfo> listPackages(String category, String subCategory);
+ List<PackageInfo> listPackages(String category, String subCategory);
- File getTranslatedFile(String vspId, Version version);
+ File getTranslatedFile(String vspId, Version version);
- File getInformationArtifact(String vspId, Version version);
+ File getInformationArtifact(String vspId, Version version);
- public Optional<Pair<String, byte[]>> get(String vspId, Version version) throws IOException;
+ public Optional<Pair<String, byte[]>> get(String vspId, Version version) throws IOException;
- Collection<ComputeEntity> getComputeByVsp(String vspId, Version version);
+ Collection<ComputeEntity> getComputeByVsp(String vspId, Version version);
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
index 4a44076e46..7de39a4912 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
@@ -135,852 +135,819 @@ import org.openecomp.sdc.versioning.dao.types.Version;
public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductManager {
- private VspMergeDao vspMergeDao;
- private OrchestrationTemplateDao orchestrationTemplateDao;
- private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager;
- private VendorSoftwareProductInfoDao vspInfoDao;
- private VendorLicenseFacade vendorLicenseFacade;
- private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
- private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao;
- private VendorLicenseArtifactsService licenseArtifactsService;
- private InformationArtifactGenerator informationArtifactGenerator;
- private PackageInfoDao packageInfoDao;
- private DeploymentFlavorDao deploymentFlavorDao;
- private ComponentDao componentDao;
- private ComponentDependencyModelDao componentDependencyModelDao;
- private NicDao nicDao;
- private ComputeDao computeDao;
- private ImageDao imageDao;
- private ManualVspToscaManager manualVspToscaManager;
- private UniqueValueUtil uniqueValueUtil;
- private CandidateService candidateService;
-
- @Override
- public ValidationResponse validate(VspDetails vspDetails) throws IOException {
- List<ErrorCode> vspErrors = new ArrayList<>(validateVspFields(vspDetails));
- ValidationResponse validationResponse = new ValidationResponse();
- if (Objects.nonNull(vspDetails.getOnboardingMethod())
- && OnboardingMethod.Manual.name().equals(vspDetails.getOnboardingMethod())) {
- validateManualOnboardingMethod(vspDetails, validationResponse, vspErrors);
- } else {
- validateOrchestrationTemplateCandidate(validationResponse, vspErrors, vspDetails.getId(), vspDetails.getVersion());
- if (!validationResponse.isValid()) {
+ private VspMergeDao vspMergeDao;
+ private OrchestrationTemplateDao orchestrationTemplateDao;
+ private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager;
+ private VendorSoftwareProductInfoDao vspInfoDao;
+ private VendorLicenseFacade vendorLicenseFacade;
+ private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
+ private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao;
+ private VendorLicenseArtifactsService licenseArtifactsService;
+ private InformationArtifactGenerator informationArtifactGenerator;
+ private PackageInfoDao packageInfoDao;
+ private DeploymentFlavorDao deploymentFlavorDao;
+ private ComponentDao componentDao;
+ private ComponentDependencyModelDao componentDependencyModelDao;
+ private NicDao nicDao;
+ private ComputeDao computeDao;
+ private ImageDao imageDao;
+ private ManualVspToscaManager manualVspToscaManager;
+ private UniqueValueUtil uniqueValueUtil;
+ private CandidateService candidateService;
+
+ @Override
+ public ValidationResponse validate(VspDetails vspDetails) throws IOException {
+ List<ErrorCode> vspErrors = new ArrayList<>(validateVspFields(vspDetails));
+ ValidationResponse validationResponse = new ValidationResponse();
+ if (Objects.nonNull(vspDetails.getOnboardingMethod()) && OnboardingMethod.Manual.name()
+ .equals(vspDetails.getOnboardingMethod())) {
+ validateManualOnboardingMethod(vspDetails, validationResponse, vspErrors);
+ } else {
+ validateOrchestrationTemplateCandidate(validationResponse, vspErrors, vspDetails.getId(),
+ vspDetails.getVersion());
+ if (!validationResponse.isValid()) {
+ return validationResponse;
+ }
+ validateLicense(vspDetails, vspErrors);
+ OrchestrationTemplateEntity orchestrationTemplate =
+ orchestrationTemplateDao.get(vspDetails.getId(), vspDetails.getVersion());
+ ToscaServiceModel serviceModel =
+ serviceModelDao.getServiceModel(vspDetails.getId(), vspDetails.getVersion());
+ if (isOrchestrationTemplateMissing(orchestrationTemplate) || isServiceModelMissing(serviceModel)) {
+ vspErrors.add(VendorSoftwareProductInvalidErrorBuilder
+ .vendorSoftwareProductMissingServiceModelErrorBuilder(vspDetails.getId(),
+ vspDetails.getVersion()));
+ }
+ validationResponse.setUploadDataErrors(validateOrchestrationTemplate(orchestrationTemplate));
+ }
+
+ QuestionnaireValidationResult questionnaireValidationResult =
+ validateQuestionnaire(vspDetails.getId(), vspDetails.getVersion(), vspDetails.getOnboardingMethod());
+
+ if (Objects.nonNull(questionnaireValidationResult)) {
+ if (validationResponse.getQuestionnaireValidationResult() == null
+ || validationResponse.getQuestionnaireValidationResult().getValidationData() == null) {
+ validationResponse.setQuestionnaireValidationResult(questionnaireValidationResult);
+ } else {
+ validationResponse.getQuestionnaireValidationResult().getValidationData()
+ .addAll(questionnaireValidationResult.getValidationData());
+ }
+ }
+
+ Collection<ComponentDependencyModelEntity> componentDependencies = componentDependencyModelDao
+ .list(new ComponentDependencyModelEntity(
+ vspDetails.getId(),
+ vspDetails.getVersion(),
+ null));
+
+ if (validateComponentDependencies(componentDependencies)) {
+ vspErrors.add(ComponentDependencyModelErrorBuilder.getCyclicDependencyComponentErrorBuilder());
+ }
+ validationResponse.setVspErrors(vspErrors);
+ validationResponse.setLicensingDataErrors(validateLicensingData(vspDetails));
return validationResponse;
- }
- validateLicense(vspDetails, vspErrors);
- OrchestrationTemplateEntity orchestrationTemplate =
- orchestrationTemplateDao.get(vspDetails.getId(), vspDetails.getVersion());
- ToscaServiceModel serviceModel =
- serviceModelDao.getServiceModel( vspDetails.getId(), vspDetails.getVersion());
- if (isOrchestrationTemplateMissing(orchestrationTemplate)
- || isServiceModelMissing(serviceModel)) {
- vspErrors.add(VendorSoftwareProductInvalidErrorBuilder
- .vendorSoftwareProductMissingServiceModelErrorBuilder(vspDetails.getId(),
- vspDetails.getVersion()));
- }
- validationResponse.setUploadDataErrors(validateOrchestrationTemplate(orchestrationTemplate));
- }
-
- QuestionnaireValidationResult questionnaireValidationResult = validateQuestionnaire
- (vspDetails.getId(), vspDetails.getVersion(), vspDetails.getOnboardingMethod());
-
- if (Objects.nonNull(questionnaireValidationResult)) {
- if (validationResponse.getQuestionnaireValidationResult() == null || validationResponse
- .getQuestionnaireValidationResult().getValidationData() == null) {
- validationResponse.setQuestionnaireValidationResult(questionnaireValidationResult);
- } else {
- validationResponse.getQuestionnaireValidationResult().getValidationData().addAll
- (questionnaireValidationResult.getValidationData());
- }
- }
-
- Collection<ComponentDependencyModelEntity> componentDependencies =
- componentDependencyModelDao.list(new ComponentDependencyModelEntity(vspDetails.getId(), vspDetails.getVersion(), null));
-
- if (validateComponentDependencies(componentDependencies)) {
- vspErrors
- .add(ComponentDependencyModelErrorBuilder.getCyclicDependencyComponentErrorBuilder());
- }
- validationResponse
- .setVspErrors(vspErrors);
- validationResponse.setLicensingDataErrors(validateLicensingData(vspDetails));
- return validationResponse;
- }
-
- private void validateLicense(VspDetails vspDetails, List<ErrorCode> vspErrors) {
- if (vspDetails.getVlmVersion() != null || vspDetails.getLicenseAgreement() != null
- || vspDetails.getFeatureGroups() != null) {
- vspErrors.addAll(validateMandatoryLicenseFields(vspDetails));
- }
- }
-
- private void validateOrchestrationTemplateCandidate(ValidationResponse validationResponse,
- List<ErrorCode> vspErrors, String vspId,
- Version version) {
- orchestrationTemplateCandidateManager.getInfo(vspId, version)
- .ifPresent(candidateInfo -> {
- String fileName = candidateInfo.getFileName();
- vspErrors.add(candidateInfo.getValidationData().isEmpty()
- ? candidateDataNotProcessedOrAbortedErrorBuilder(fileName)
- : invalidProcessedCandidate(fileName));
- validationResponse.setVspErrors(vspErrors);
+ }
+
+ private void validateLicense(VspDetails vspDetails, List<ErrorCode> vspErrors) {
+ if (vspDetails.getVlmVersion() != null || vspDetails.getLicenseAgreement() != null
+ || vspDetails.getFeatureGroups() != null) {
+ vspErrors.addAll(validateMandatoryLicenseFields(vspDetails));
+ }
+ }
+
+ private void validateOrchestrationTemplateCandidate(ValidationResponse validationResponse,
+ List<ErrorCode> vspErrors, String vspId, Version version) {
+ orchestrationTemplateCandidateManager.getInfo(vspId, version).ifPresent(candidateInfo -> {
+ String fileName = candidateInfo.getFileName();
+ vspErrors.add(candidateInfo.getValidationData().isEmpty() ? candidateDataNotProcessedOrAbortedErrorBuilder(
+ fileName) : invalidProcessedCandidate(fileName));
+ validationResponse.setVspErrors(vspErrors);
});
- }
-
- private void validateManualOnboardingMethod(VspDetails vspDetails,
- ValidationResponse validationResponse,
- List<ErrorCode> vspErrors) {
- vspErrors.addAll(validateMandatoryLicenseFields(vspDetails));
-
- Collection<DeploymentFlavorEntity> deploymentFlavors = deploymentFlavorDao
- .list(new DeploymentFlavorEntity(vspDetails.getId(), vspDetails.getVersion(), null));
- if (CollectionUtils.isEmpty(deploymentFlavors)) {
- vspErrors.add(vspMissingDeploymentFlavorErrorBuilder());
- }
- vspErrors.addAll(validateDeploymentFlavors(deploymentFlavors));
-
- Set<CompositionEntityValidationData> componentValidationResult =
- componentValidation(vspDetails.getId(), vspDetails.getVersion());
- if (!CollectionUtils.isEmpty(componentValidationResult)) {
- if (validationResponse.getQuestionnaireValidationResult() == null
- || validationResponse.getQuestionnaireValidationResult().getValidationData() == null) {
- validationResponse.setQuestionnaireValidationResult(
- new QuestionnaireValidationResult(componentValidationResult));
- } else {
- validationResponse.getQuestionnaireValidationResult().getValidationData()
- .addAll(componentValidationResult);
- }
- }
- }
-
- @Override
- public Map<String, List<ErrorMessage>> compile(String vspId, Version version) {
- ToscaServiceModel serviceModel =
- OnboardingMethod.Manual.name().equals(getValidatedVsp(vspId, version).getOnboardingMethod())
- //Generate Tosca service model for Manual Onboarding flow
- ? manualVspToscaManager
- .generateToscaModel(manualVspToscaManager.gatherVspInformation(vspId, version))
- : serviceModelDao.getServiceModel(vspId, version);
-
- return compile(vspId, version, serviceModel);
- }
-
- private boolean validateComponentDependencies(
- Collection<ComponentDependencyModelEntity> componentDependencies) {
- ComponentDependencyTracker dependencyTracker = new ComponentDependencyTracker();
-
- for (ComponentDependencyModelEntity componentDependency : componentDependencies) {
- dependencyTracker.addDependency(componentDependency.getSourceComponentId(),
- componentDependency.getTargetComponentId());
- }
- return dependencyTracker.isCyclicDependencyPresent();
- }
-
- private Collection<ErrorCode> validateDeploymentFlavors(
- Collection<DeploymentFlavorEntity> deploymentFlavors) {
-
- Collection<ErrorCode> errorCodeList = new ArrayList<>();
- if (!CollectionUtils.isEmpty(deploymentFlavors)) {
- deploymentFlavors.forEach(deploymentFlavor -> {
- DeploymentFlavorEntity deployment = deploymentFlavorDao.get(deploymentFlavor);
- DeploymentFlavor deploymentLocalFlavor = deployment.getDeploymentFlavorCompositionData();
- if (deploymentLocalFlavor != null) {
- if (deploymentLocalFlavor.getFeatureGroupId() == null) {
- ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder.
- getFeatureGroupMandatoryErrorBuilder(deploymentLocalFlavor.getModel());
- errorCodeList.add(deploymentFlavorErrorBuilder);
- }
- validateComponentComputeAssociations(errorCodeList, deploymentFlavor,
- deployment, deploymentLocalFlavor);
- }
- });
- }
- return errorCodeList;
- }
-
- private void validateComponentComputeAssociations(Collection<ErrorCode> errorCodeList,
- DeploymentFlavorEntity deploymentFlavor,
- DeploymentFlavorEntity deployment,
- DeploymentFlavor deploymentlocalFlavor) {
- List<ComponentComputeAssociation> componentComputeAssociations =
- deploymentlocalFlavor.getComponentComputeAssociations();
- if (CollectionUtils.isEmpty(componentComputeAssociations)) {
- validateCompositionEntity(errorCodeList, deploymentFlavor, deployment, deploymentlocalFlavor);
- } else {
- componentComputeAssociations.forEach(componentComputeAssociation -> {
- if (componentComputeAssociation == null
- || !(componentComputeAssociation.getComponentId() != null
- && componentComputeAssociation.getComputeFlavorId() != null)) {
- validateCompositionEntity(errorCodeList, deploymentFlavor, deployment, deploymentlocalFlavor);
+ }
+
+ private void validateManualOnboardingMethod(VspDetails vspDetails, ValidationResponse validationResponse,
+ List<ErrorCode> vspErrors) {
+ vspErrors.addAll(validateMandatoryLicenseFields(vspDetails));
+
+ Collection<DeploymentFlavorEntity> deploymentFlavors =
+ deploymentFlavorDao.list(new DeploymentFlavorEntity(vspDetails.getId(), vspDetails.getVersion(), null));
+ if (CollectionUtils.isEmpty(deploymentFlavors)) {
+ vspErrors.add(vspMissingDeploymentFlavorErrorBuilder());
+ }
+ vspErrors.addAll(validateDeploymentFlavors(deploymentFlavors));
+
+ Set<CompositionEntityValidationData> componentValidationResult =
+ componentValidation(vspDetails.getId(), vspDetails.getVersion());
+ if (!CollectionUtils.isEmpty(componentValidationResult)) {
+ if (validationResponse.getQuestionnaireValidationResult() == null
+ || validationResponse.getQuestionnaireValidationResult().getValidationData() == null) {
+ validationResponse
+ .setQuestionnaireValidationResult(new QuestionnaireValidationResult(componentValidationResult));
+ } else {
+ validationResponse.getQuestionnaireValidationResult().getValidationData()
+ .addAll(componentValidationResult);
+ }
}
- });
- }
- }
-
- private void validateCompositionEntity(Collection<ErrorCode> errorCodeList,
- DeploymentFlavorEntity deploymentFlavor,
- DeploymentFlavorEntity deployment,
- DeploymentFlavor deploymentlocalFlavor){
- CompositionEntityValidationData compositionEntityValidationData = new
- CompositionEntityValidationData(CompositionEntityType.deployment, deploymentFlavor
- .getId());
- compositionEntityValidationData.setEntityName(deployment
- .getDeploymentFlavorCompositionData().getModel());
- ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder
- .getInvalidComponentComputeAssociationErrorBuilder(
- deploymentlocalFlavor.getModel());
- errorCodeList.add(deploymentFlavorErrorBuilder);
- }
-
- private Set<CompositionEntityValidationData> componentValidation(String vspId, Version version) {
- Set<CompositionEntityValidationData> validationData = new HashSet<>();
- Collection<ComponentEntity> components =
- componentDao.list(new ComponentEntity(vspId, version, null));
- if (!CollectionUtils.isEmpty(components)) {
- components.forEach(component -> {
- validateImage(vspId, version, validationData, component);
- validateNic(vspId, version, validationData, component);
-
- });
- }
-
- return validationData;
- }
-
- private void validateNic(String vspId, Version version,
- Set<CompositionEntityValidationData> validationData,
- ComponentEntity component) {
- Collection<NicEntity> nics =
- nicDao.list(new NicEntity(vspId, version, component.getId(), null));
- if (CollectionUtils.isNotEmpty(nics)) {
- nics.forEach(nicEntity -> {
- NicEntity nic = nicDao.get(new NicEntity(vspId, version, component.getId(),
- nicEntity.getId()));
- NetworkType networkType = nic.getNicCompositionData().getNetworkType();
- String networkId = nic.getNicCompositionData().getNetworkId();
- if (networkType.equals(NetworkType.Internal) && networkId == null) {
- CompositionEntityValidationData compositionEntityValidationData = new
- CompositionEntityValidationData(CompositionEntityType.nic, nic.getId());
- compositionEntityValidationData.setEntityName(nic.getNicCompositionData().getName());
- ErrorCode nicInternalNetworkErrorBuilder = NicInternalNetworkErrorBuilder
- .getNicNullNetworkIdInternalNetworkIdErrorBuilder();
- List<String> errors = new ArrayList<>();
- errors.add(nicInternalNetworkErrorBuilder.message());
- compositionEntityValidationData.setErrors(errors);
- validationData.add(compositionEntityValidationData);
- }
- });
- }
- }
-
- private void validateImage(String vspId, Version version,
- Set<CompositionEntityValidationData> validationData,
- ComponentEntity component) {
- Collection<ImageEntity> images =
- imageDao.list(new ImageEntity(vspId, version, component.getId(), null));
- if (CollectionUtils.isEmpty(images)) {
- CompositionEntityValidationData compositionEntityValidationData = new
- CompositionEntityValidationData(component.getType(), component.getId());
- compositionEntityValidationData
- .setEntityName(component.getComponentCompositionData().getDisplayName());
- ErrorCode vfcMissingImageErrorBuilder =
- ComponentErrorBuilder.vfcMissingImageErrorBuilder();
- List<String> errors = new ArrayList<>();
- errors.add(vfcMissingImageErrorBuilder.message());
- compositionEntityValidationData.setErrors(errors);
- validationData.add(compositionEntityValidationData);
- }
- }
-
- private List<ErrorCode> validateVspFields(VspDetails vspDetails) {
- List<ErrorCode> errors = new ArrayList<>();
-
- if (vspDetails.getName() == null) {
- errors.add(createMissingMandatoryFieldError("name"));
- }
- if (vspDetails.getDescription() == null) {
- errors.add(createMissingMandatoryFieldError("description"));
- }
- if (vspDetails.getVendorId() == null) {
- errors.add(createMissingMandatoryFieldError("vendor Id"));
- }
- if (vspDetails.getCategory() == null) {
- errors.add(createMissingMandatoryFieldError("category"));
- }
- if (vspDetails.getSubCategory() == null) {
- errors.add(createMissingMandatoryFieldError("sub category"));
- }
- return errors;
- }
-
- private List<ErrorCode> validateMandatoryLicenseFields(VspDetails vspDetails) {
- List<ErrorCode> errors = new ArrayList<>();
- if (vspDetails.getVlmVersion() == null) {
- errors.add(createMissingMandatoryFieldError("licensing version"));
- }
- if (vspDetails.getLicenseAgreement() == null) {
- errors.add(createMissingMandatoryFieldError("license agreement"));
- }
- if (CollectionUtils.isEmpty(vspDetails.getFeatureGroups())) {
- errors.add(createMissingMandatoryFieldError("feature groups"));
- }
- return errors;
- }
-
- private static ErrorCode createMissingMandatoryFieldError(String fieldName) {
- return new ValidationErrorBuilder("must be supplied", fieldName).build();
- }
-
- private Map<String, List<ErrorMessage>> compile(String vendorSoftwareProductId, Version version,
- ToscaServiceModel serviceModel) {
- if (isServiceModelMissing(serviceModel)) {
- return null;
- }
-
- enrichedServiceModelDao.deleteAll(vendorSoftwareProductId, version);
-
- EnrichmentManager<ToscaServiceModel> enrichmentManager =
- EnrichmentManagerFactory.getInstance().createInterface();
- enrichmentManager.init(vendorSoftwareProductId, version);
- enrichmentManager.setModel(serviceModel);
- Map<String, List<ErrorMessage>> enrichErrors = enrichmentManager.enrich();
-
- enrichedServiceModelDao
- .storeServiceModel(vendorSoftwareProductId, version, enrichmentManager.getModel());
-
- return enrichErrors;
- }
-
- private Collection<ErrorCode> validateLicensingData(VspDetails vspDetails) {
- if (vspDetails.getVendorId() != null) {
- Optional<ErrorCode> errorCode = vendorLicenseFacade.validateVendorForUsage(vspDetails.getVendorId(),vspDetails.getVlmVersion());
- if (errorCode.isPresent()) {
- return Collections.singleton(errorCode.get());
- }
- }
-
- if (vspDetails.getVendorId() == null || vspDetails.getVlmVersion() == null
- || vspDetails.getLicenseAgreement() == null
- || CollectionUtils.isEmpty(vspDetails.getFeatureGroups())) {
- return Collections.emptyList();
- }
- return vendorLicenseFacade
- .validateLicensingData(vspDetails.getVendorId(), vspDetails.getVlmVersion(),
- vspDetails.getLicenseAgreement(), vspDetails.getFeatureGroups());
- }
-
- @Override
- public VspDetails createVsp(VspDetails vspDetails) {
- vspInfoDao.create(vspDetails);
- vspInfoDao.updateQuestionnaireData(vspDetails.getId(), vspDetails.getVersion(),
- new JsonSchemaDataGenerator(getVspQuestionnaireSchema(null)).generateData());
- return vspDetails;
- }
-
- @Override
- public void updateVsp(VspDetails vspDetails) {
- VspDetails retrieved = vspInfoDao.get(vspDetails);
- if (retrieved == null) {
- throw new CoreException((new ErrorCode.ErrorCodeBuilder()
- .withMessage(String.format("Vsp with id %s and version %s does not exist.",
- vspDetails.getId(), vspDetails.getVersion().getId()))).build());
}
- vspDetails.setOnboardingMethod(retrieved.getOnboardingMethod());
- //If any existing feature group is removed from VSP which is also associated in DF then
- //update DF to remove feature group associations.
- updateDeploymentFlavor(vspDetails);
+ @Override
+ public Map<String, List<ErrorMessage>> compile(String vspId, Version version) {
+ ToscaServiceModel serviceModel =
+ OnboardingMethod.Manual.name().equals(getValidatedVsp(vspId, version).getOnboardingMethod())
+ //Generate Tosca service model for Manual Onboarding flow
+ ? manualVspToscaManager
+ .generateToscaModel(manualVspToscaManager.gatherVspInformation(vspId, version))
+ : serviceModelDao.getServiceModel(vspId, version);
- updateUniqueName(retrieved.getName(), vspDetails.getName());
- vspInfoDao.update(vspDetails);
- }
+ return compile(vspId, version, serviceModel);
+ }
- private void updateDeploymentFlavor(VspDetails vspDetails) {
- final List<String> featureGroups = vspDetails.getFeatureGroups();
- if (featureGroups != null) {
- final Collection<DeploymentFlavorEntity> deploymentFlavorEntities = deploymentFlavorDao
- .list(new DeploymentFlavorEntity(vspDetails.getId(), vspDetails
- .getVersion(), null));
- if (Objects.nonNull(deploymentFlavorEntities)) {
- for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) {
- updateDeploymentFlavourEntity(featureGroups, deploymentFlavorEntity);
- }
- }
- }
- }
-
- private void updateDeploymentFlavourEntity(List<String> featureGroups,
- DeploymentFlavorEntity deploymentFlavorEntity) {
- final String featureGroupId =
- deploymentFlavorEntity.getDeploymentFlavorCompositionData().getFeatureGroupId();
- if (!featureGroups.contains(featureGroupId)) {
- DeploymentFlavor deploymentFlavorCompositionData =
- deploymentFlavorEntity.getDeploymentFlavorCompositionData();
- deploymentFlavorCompositionData.setFeatureGroupId(null);
- deploymentFlavorEntity.setDeploymentFlavorCompositionData
- (deploymentFlavorCompositionData);
- deploymentFlavorDao.update(deploymentFlavorEntity);
- }
- }
-
-
- @Override
- public VspDetails getVsp(String vspId, Version version) {
- return getValidatedVsp(vspId, version);
- }
-
- private VspDetails getValidatedVsp(String vspId, Version version) {
- VspDetails vsp = vspInfoDao.get(new VspDetails(vspId, version));
- if (vsp == null) {
- throw new CoreException(new VendorSoftwareProductNotFoundErrorBuilder(vspId).build());
- }
- return vsp;
- }
-
- @Override
- public void deleteVsp(String vspId, Version version) {
- vspMergeDao.deleteHint(vspId, version);
- }
-
- @Override
- public List<PackageInfo> listPackages(String category, String subCategory) {
- return packageInfoDao.listByCategory(category, subCategory);
- }
-
- @Override
- public File getTranslatedFile(String vspId, Version version) {
- PackageInfo packageInfo = packageInfoDao.get(new PackageInfo(vspId, version));
- if (packageInfo == null) {
- throw new CoreException(new PackageNotFoundErrorBuilder(vspId, version).build());
- }
-
- ByteBuffer translatedFileBuffer = packageInfo.getTranslatedFile();
- if (translatedFileBuffer == null) {
- throw new CoreException(new PackageInvalidErrorBuilder(vspId, version).build());
- }
-
- File translatedFile = new File(VendorSoftwareProductConstants.VSP_PACKAGE_ZIP);
-
- try (FileOutputStream fos = new FileOutputStream(translatedFile)) {
- fos.write(translatedFileBuffer.array());
- } catch (IOException exception) {
- throw new CoreException(new TranslationFileCreationErrorBuilder(vspId, version).build(),
- exception);
- }
- return translatedFile;
- }
-
- @Override
- public byte[] getOrchestrationTemplateFile(String vspId, Version version) {
- OrchestrationTemplateEntity uploadData = orchestrationTemplateDao.get(vspId, version);
- ByteBuffer contentData = uploadData.getContentData();
- if (contentData == null) {
- return new byte[0];
- }
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- try (final ZipOutputStream zos = new ZipOutputStream(baos);
- ZipInputStream ignored = new ZipInputStream(
- new ByteArrayInputStream(contentData.array()))) {
- zos.write(contentData.array());
- } catch (IOException exception) {
- throw new CoreException(new FileCreationErrorBuilder(vspId).build(), exception);
- }
- return baos.toByteArray();
- }
-
- @Override
- public OrchestrationTemplateEntity getOrchestrationTemplateInfo(String vspId, Version version) {
- return orchestrationTemplateDao.getInfo(vspId, version);
- }
-
- @Override
- public Optional<FilesDataStructure> getOrchestrationTemplateStructure(String vspId,
- Version version) {
- Optional<String> jsonFileDataStructure =
- orchestrationTemplateDao.getOrchestrationTemplateStructure(vspId, version);
-
- if (jsonFileDataStructure.isPresent() && JsonUtil.isValidJson(jsonFileDataStructure.get())) {
- return Optional
- .of(JsonUtil.json2Object(jsonFileDataStructure.get(), FilesDataStructure.class));
- } else {
- return Optional.empty();
- }
- }
-
- @Override
- public PackageInfo createPackage(final String vspId, final Version version) throws IOException {
- final ToscaServiceModel toscaServiceModel = enrichedServiceModelDao.getServiceModel(vspId, version);
- final VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version));
- final Version vlmVersion = vspDetails.getVlmVersion();
- if (vlmVersion != null) {
- populateVersionsForVlm(vspDetails.getVendorId(), vlmVersion);
- }
- final PackageInfo packageInfo = createPackageInfo(vspDetails);
-
- final ToscaFileOutputServiceCsarImpl toscaServiceTemplateServiceCsar =
- new ToscaFileOutputServiceCsarImpl();
- final FileContentHandler licenseArtifacts = licenseArtifactsService
- .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion,
- vspDetails.getFeatureGroups());
- final ETSIService etsiService = new ETSIServiceImpl();
- if (etsiService.isSol004WithToscaMetaDirectory(toscaServiceModel.getArtifactFiles())) {
- final FileContentHandler handler = toscaServiceModel.getArtifactFiles();
- final Manifest manifest = etsiService.getManifest(handler);
- final Optional<Map<String, Path>> fromToMovedPaths = etsiService.moveNonManoFileToArtifactFolder(handler);
- fromToMovedPaths
- .ifPresent(it -> etsiService.updateMainDescriptorPaths(toscaServiceModel, it));
- packageInfo.setResourceType(etsiService.getResourceType(manifest).name());
- }
- packageInfo.setTranslatedFile(ByteBuffer.wrap(
- toscaServiceTemplateServiceCsar.createOutputFile(toscaServiceModel, licenseArtifacts)));
-
- packageInfoDao.create(packageInfo);
- return packageInfo;
- }
-
- void populateVersionsForVlm(String vlmId, Version vlmVersion) {
- VersioningManager versioningManager = VersioningManagerFactory.getInstance().createInterface();
- versioningManager.list(vlmId).stream()
- .filter(version -> version.getId().equalsIgnoreCase(vlmVersion.getId()))
- .findAny()
- .ifPresent(version -> {
- vlmVersion.setMinor(version.getMinor());
- vlmVersion.setMajor(version.getMajor());
- });
- }
-
- private PackageInfo createPackageInfo(VspDetails vspDetails) {
- PackageInfo packageInfo = new PackageInfo(vspDetails.getId(), vspDetails.getVersion());
- packageInfo.setVspName(vspDetails.getName());
- packageInfo.setVspDescription(vspDetails.getDescription());
- packageInfo.setCategory(vspDetails.getCategory());
- packageInfo.setSubCategory(vspDetails.getSubCategory());
- packageInfo.setVendorName(vspDetails.getVendorName());
- packageInfo.setPackageType(VendorSoftwareProductConstants.CSAR);
- packageInfo.setVendorRelease("1.0"); //todo TBD
- return packageInfo;
- }
+ private boolean validateComponentDependencies(Collection<ComponentDependencyModelEntity> componentDependencies) {
+ ComponentDependencyTracker dependencyTracker = new ComponentDependencyTracker();
- @Override
+ for (ComponentDependencyModelEntity componentDependency : componentDependencies) {
+ dependencyTracker.addDependency(componentDependency.getSourceComponentId(),
+ componentDependency.getTargetComponentId());
+ }
+ return dependencyTracker.isCyclicDependencyPresent();
+ }
+
+ private Collection<ErrorCode> validateDeploymentFlavors(Collection<DeploymentFlavorEntity> deploymentFlavors) {
+
+ Collection<ErrorCode> errorCodeList = new ArrayList<>();
+ if (!CollectionUtils.isEmpty(deploymentFlavors)) {
+ deploymentFlavors.forEach(deploymentFlavor -> {
+ DeploymentFlavorEntity deployment = deploymentFlavorDao.get(deploymentFlavor);
+ DeploymentFlavor deploymentLocalFlavor = deployment.getDeploymentFlavorCompositionData();
+ if (deploymentLocalFlavor != null) {
+ if (deploymentLocalFlavor.getFeatureGroupId() == null) {
+ ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder.
+ getFeatureGroupMandatoryErrorBuilder(
+ deploymentLocalFlavor
+ .getModel());
+ errorCodeList.add(deploymentFlavorErrorBuilder);
+ }
+ validateComponentComputeAssociations(errorCodeList, deploymentFlavor, deployment,
+ deploymentLocalFlavor);
+ }
+ });
+ }
+ return errorCodeList;
+ }
- public QuestionnaireResponse getVspQuestionnaire(String vspId, Version version) {
- VspQuestionnaireEntity retrieved = vspInfoDao.getQuestionnaire(vspId, version);
- VersioningUtil.validateEntityExistence(retrieved, new VspQuestionnaireEntity(vspId, version),
- VspDetails.ENTITY_TYPE);
-
- String questionnaireData = retrieved.getQuestionnaireData();
-
- QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse();
- questionnaireResponse.setData(questionnaireData);
- questionnaireResponse.setSchema(getVspQuestionnaireSchema(null));
- return questionnaireResponse;
- }
-
- @Override
- public void updateVspQuestionnaire(String vspId, Version version, String questionnaireData) {
- vspInfoDao.updateQuestionnaireData(vspId, version, questionnaireData);
- }
+ private void validateComponentComputeAssociations(Collection<ErrorCode> errorCodeList,
+ DeploymentFlavorEntity deploymentFlavor, DeploymentFlavorEntity deployment,
+ DeploymentFlavor deploymentlocalFlavor) {
+ List<ComponentComputeAssociation> componentComputeAssociations =
+ deploymentlocalFlavor.getComponentComputeAssociations();
+ if (CollectionUtils.isEmpty(componentComputeAssociations)) {
+ validateCompositionEntity(errorCodeList, deploymentFlavor, deployment, deploymentlocalFlavor);
+ } else {
+ componentComputeAssociations.forEach(componentComputeAssociation -> {
+ if (componentComputeAssociation == null || !(componentComputeAssociation.getComponentId() != null
+ && componentComputeAssociation.getComputeFlavorId()
+ != null)) {
+ validateCompositionEntity(errorCodeList, deploymentFlavor, deployment, deploymentlocalFlavor);
+ }
+ });
+ }
+ }
+ private void validateCompositionEntity(Collection<ErrorCode> errorCodeList, DeploymentFlavorEntity deploymentFlavor,
+ DeploymentFlavorEntity deployment, DeploymentFlavor deploymentlocalFlavor) {
+ CompositionEntityValidationData compositionEntityValidationData =
+ new CompositionEntityValidationData(CompositionEntityType.deployment, deploymentFlavor.getId());
+ compositionEntityValidationData.setEntityName(deployment.getDeploymentFlavorCompositionData().getModel());
+ ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder
+ .getInvalidComponentComputeAssociationErrorBuilder(
+ deploymentlocalFlavor.getModel());
+ errorCodeList.add(deploymentFlavorErrorBuilder);
+ }
- private Map<String, List<ErrorMessage>> validateOrchestrationTemplate(
- OrchestrationTemplateEntity orchestrationTemplate) throws IOException {
-
- if (isOrchestrationTemplateMissing(orchestrationTemplate)) {
- return null;
- }
- Map<String, List<ErrorMessage>> validationErrors = new HashMap<>();
+ private Set<CompositionEntityValidationData> componentValidation(String vspId, Version version) {
+ Set<CompositionEntityValidationData> validationData = new HashSet<>();
+ Collection<ComponentEntity> components = componentDao.list(new ComponentEntity(vspId, version, null));
+ if (!CollectionUtils.isEmpty(components)) {
+ components.forEach(component -> {
+ validateImage(vspId, version, validationData, component);
+ validateNic(vspId, version, validationData, component);
- FileContentHandler fileContentMap = CommonUtil.validateAndUploadFileContent(
- OnboardingTypesEnum.getOnboardingTypesEnum(orchestrationTemplate.getFileSuffix()),
- orchestrationTemplate.getContentData().array());
+ });
+ }
- if (CommonUtil.isFileOriginFromZip(orchestrationTemplate.getFileSuffix())) {
- ValidationManager validationManager =
- ValidationManagerUtil.initValidationManager(fileContentMap);
- validationErrors.putAll(validationManager.validate());
+ return validationData;
+ }
+
+ private void validateNic(String vspId, Version version, Set<CompositionEntityValidationData> validationData,
+ ComponentEntity component) {
+ Collection<NicEntity> nics = nicDao.list(new NicEntity(vspId, version, component.getId(), null));
+ if (CollectionUtils.isNotEmpty(nics)) {
+ nics.forEach(nicEntity -> {
+ NicEntity nic = nicDao.get(new NicEntity(vspId, version, component.getId(), nicEntity.getId()));
+ NetworkType networkType = nic.getNicCompositionData().getNetworkType();
+ String networkId = nic.getNicCompositionData().getNetworkId();
+ if (networkType.equals(NetworkType.Internal) && networkId == null) {
+ CompositionEntityValidationData compositionEntityValidationData =
+ new CompositionEntityValidationData(CompositionEntityType.nic, nic.getId());
+ compositionEntityValidationData.setEntityName(nic.getNicCompositionData().getName());
+ ErrorCode nicInternalNetworkErrorBuilder =
+ NicInternalNetworkErrorBuilder.getNicNullNetworkIdInternalNetworkIdErrorBuilder();
+ List<String> errors = new ArrayList<>();
+ errors.add(nicInternalNetworkErrorBuilder.message());
+ compositionEntityValidationData.setErrors(errors);
+ validationData.add(compositionEntityValidationData);
+ }
+ });
+ }
}
- return
- MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, validationErrors))
- ? null : validationErrors;
- }
+ private void validateImage(String vspId, Version version, Set<CompositionEntityValidationData> validationData,
+ ComponentEntity component) {
+ Collection<ImageEntity> images = imageDao.list(new ImageEntity(vspId, version, component.getId(), null));
+ if (CollectionUtils.isEmpty(images)) {
+ CompositionEntityValidationData compositionEntityValidationData =
+ new CompositionEntityValidationData(component.getType(), component.getId());
+ compositionEntityValidationData.setEntityName(component.getComponentCompositionData().getDisplayName());
+ ErrorCode vfcMissingImageErrorBuilder = ComponentErrorBuilder.vfcMissingImageErrorBuilder();
+ List<String> errors = new ArrayList<>();
+ errors.add(vfcMissingImageErrorBuilder.message());
+ compositionEntityValidationData.setErrors(errors);
+ validationData.add(compositionEntityValidationData);
+ }
+ }
- private QuestionnaireValidationResult validateQuestionnaire(String vspId, Version version,
- String onboardingMethod) {
- // The apis of CompositionEntityDataManager used here are stateful!
- // so, it must be re-created from scratch when it is used!
- CompositionEntityDataManager compositionEntityDataManager =
- CompositionEntityDataManagerFactory.getInstance().createInterface();
- compositionEntityDataManager
- .addEntity(vspInfoDao.getQuestionnaire(vspId, version), null);
+ private List<ErrorCode> validateVspFields(VspDetails vspDetails) {
+ List<ErrorCode> errors = new ArrayList<>();
- Collection<NicEntity> nics = nicDao.listByVsp(vspId, version);
+ if (vspDetails.getName() == null) {
+ errors.add(createMissingMandatoryFieldError("name"));
+ }
+ if (vspDetails.getDescription() == null) {
+ errors.add(createMissingMandatoryFieldError("description"));
+ }
+ if (vspDetails.getVendorId() == null) {
+ errors.add(createMissingMandatoryFieldError("vendor Id"));
+ }
+ if (vspDetails.getCategory() == null) {
+ errors.add(createMissingMandatoryFieldError("category"));
+ }
+ if (vspDetails.getSubCategory() == null) {
+ errors.add(createMissingMandatoryFieldError("sub category"));
+ }
+ return errors;
+ }
- Map<String, List<String>> nicNamesByComponent = new HashMap<>();
- for (NicEntity nicEntity : nics) {
- compositionEntityDataManager.addEntity(nicEntity, null);
-
- Nic nic = nicEntity.getNicCompositionData();
- if (nic != null && nic.getName() != null) {
- List<String> nicNames =
- nicNamesByComponent.computeIfAbsent(nicEntity.getComponentId(), k -> new ArrayList<>());
- nicNames.add(nic.getName());
- }
- }
-
- Collection<ComponentEntity> components =
- componentDao.listCompositionAndQuestionnaire(vspId, version);
- components.forEach(component -> compositionEntityDataManager.addEntity(component,
- new ComponentQuestionnaireSchemaInput(nicNamesByComponent.get(component.getId()),
- JsonUtil.json2Object(component.getQuestionnaireData(), Map.class), null,
- OnboardingMethod.Manual.name().equals(onboardingMethod))));
-
- Collection<ComputeEntity> computes = computeDao.listByVsp(vspId, version);
- computes.forEach(compute -> compositionEntityDataManager.addEntity(compute, null));
-
- if (OnboardingMethod.Manual.name().equals(onboardingMethod)) {
- Collection<ImageEntity> images = imageDao.listByVsp(vspId, version);
- images.forEach(image -> compositionEntityDataManager.addEntity(image, null));
- }
-
- Map<CompositionEntityId, Collection<String>> errorsByEntityId =
- compositionEntityDataManager.validateEntitiesQuestionnaire();
- if (MapUtils.isNotEmpty(errorsByEntityId)) {
- compositionEntityDataManager.buildTrees();
- compositionEntityDataManager.addErrorsToTrees(errorsByEntityId);
- return new QuestionnaireValidationResult(
- compositionEntityDataManager.getAllErrorsByVsp(vspId));
- }
- return null;
- }
-
- @Override
- public File getInformationArtifact(String vspId, Version version) {
- VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version));
+ private List<ErrorCode> validateMandatoryLicenseFields(VspDetails vspDetails) {
+ List<ErrorCode> errors = new ArrayList<>();
+ if (vspDetails.getVlmVersion() == null) {
+ errors.add(createMissingMandatoryFieldError("licensing version"));
+ }
+ if (vspDetails.getLicenseAgreement() == null) {
+ errors.add(createMissingMandatoryFieldError("license agreement"));
+ }
+ if (CollectionUtils.isEmpty(vspDetails.getFeatureGroups())) {
+ errors.add(createMissingMandatoryFieldError("feature groups"));
+ }
+ return errors;
+ }
- if (vspDetails == null) {
- return null;
+ private static ErrorCode createMissingMandatoryFieldError(String fieldName) {
+ return new ValidationErrorBuilder("must be supplied", fieldName).build();
}
- String vspName = vspDetails.getName();
- ByteBuffer infoArtifactAsByteBuffer;
- File infoArtifactFile;
- try {
- infoArtifactAsByteBuffer = ByteBuffer.wrap(informationArtifactGenerator.generate(vspId,
- version).getBytes());
+ private Map<String, List<ErrorMessage>> compile(String vendorSoftwareProductId, Version version,
+ ToscaServiceModel serviceModel) {
+ if (isServiceModelMissing(serviceModel)) {
+ return null;
+ }
+
+ enrichedServiceModelDao.deleteAll(vendorSoftwareProductId, version);
+
+ EnrichmentManager<ToscaServiceModel> enrichmentManager =
+ EnrichmentManagerFactory.getInstance().createInterface();
+ enrichmentManager.init(vendorSoftwareProductId, version);
+ enrichmentManager.setModel(serviceModel);
+ Map<String, List<ErrorMessage>> enrichErrors = enrichmentManager.enrich();
- infoArtifactFile =
- new File(
- String.format(VendorSoftwareProductConstants.INFORMATION_ARTIFACT_NAME, vspName));
- try (OutputStream out = new BufferedOutputStream(new FileOutputStream(infoArtifactFile))) {
- out.write(infoArtifactAsByteBuffer.array());
- }
+ enrichedServiceModelDao.storeServiceModel(vendorSoftwareProductId, version, enrichmentManager.getModel());
- } catch (IOException ex) {
- throw new CoreException(new InformationArtifactCreationErrorBuilder(vspId).build(), ex);
+ return enrichErrors;
}
- return infoArtifactFile;
- }
- String getVspQuestionnaireSchema(SchemaTemplateInput schemaInput) {
- return SchemaGenerator
- .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, schemaInput);
- }
+ private Collection<ErrorCode> validateLicensingData(VspDetails vspDetails) {
+ if (vspDetails.getVendorId() != null) {
+ Optional<ErrorCode> errorCode =
+ vendorLicenseFacade.validateVendorForUsage(vspDetails.getVendorId(), vspDetails.getVlmVersion());
+ if (errorCode.isPresent()) {
+ return Collections.singleton(errorCode.get());
+ }
+ }
- @Override
- public Optional<Pair<String, byte[]>> get(String vspId, Version version) throws IOException {
-
- OrchestrationTemplateEntity orchestrationTemplateEntity =
- orchestrationTemplateDao.get(vspId, version);
-
- if (isOrchestrationTemplateMissing(orchestrationTemplateEntity)) {
- return Optional.empty();
- }
-
- if (CommonUtil.isFileOriginFromZip(orchestrationTemplateEntity.getFileSuffix())) {
- return Optional.of(new ImmutablePair<>(OnboardingTypesEnum.ZIP.toString(), candidateService
- .getZipData(orchestrationTemplateEntity.getContentData())));
- }
- return Optional.of(new ImmutablePair<>(orchestrationTemplateEntity.getFileSuffix(),
- orchestrationTemplateEntity.getContentData().array()));
- }
-
- void updateUniqueName(String oldVspName, String newVspName) {
- uniqueValueUtil.updateUniqueValue(
- VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
- oldVspName, newVspName);
- }
+ if (vspDetails.getVendorId() == null || vspDetails.getVlmVersion() == null
+ || vspDetails.getLicenseAgreement() == null || CollectionUtils
+ .isEmpty(vspDetails.getFeatureGroups())) {
+ return Collections.emptyList();
+ }
+ return vendorLicenseFacade.validateLicensingData(vspDetails.getVendorId(), vspDetails.getVlmVersion(),
+ vspDetails.getLicenseAgreement(), vspDetails.getFeatureGroups());
+ }
- @Override
- public Collection<ComputeEntity> getComputeByVsp(String vspId, Version version) {
- return computeDao.listByVsp(vspId, version);
- }
+ @Override
+ public VspDetails createVsp(VspDetails vspDetails) {
+ vspInfoDao.create(vspDetails);
+ vspInfoDao.updateQuestionnaireData(vspDetails.getId(), vspDetails.getVersion(),
+ new JsonSchemaDataGenerator(getVspQuestionnaireSchema(null)).generateData());
+ return vspDetails;
+ }
- private boolean isOrchestrationTemplateMissing(
- OrchestrationTemplateEntity orchestrationTemplate) {
- return orchestrationTemplate == null
- || orchestrationTemplate.getContentData() == null
- || orchestrationTemplate.getFileSuffix() == null
- || orchestrationTemplate.getFileName() == null;
- }
+ @Override
+ public void updateVsp(VspDetails vspDetails) {
+ VspDetails retrieved = vspInfoDao.get(vspDetails);
+ if (retrieved == null) {
+ throw new CoreException((new ErrorCode.ErrorCodeBuilder().withMessage(
+ String.format("Vsp with id %s and version %s does not exist.", vspDetails.getId(),
+ vspDetails.getVersion().getId()))).build());
+ }
+ vspDetails.setOnboardingMethod(retrieved.getOnboardingMethod());
+
+ //If any existing feature group is removed from VSP which is also associated in DF then
+ //update DF to remove feature group associations.
+ updateDeploymentFlavor(vspDetails);
+
+ updateUniqueName(retrieved.getName(), vspDetails.getName());
+ vspInfoDao.update(vspDetails);
+ }
+
+ private void updateDeploymentFlavor(VspDetails vspDetails) {
+ final List<String> featureGroups = vspDetails.getFeatureGroups();
+ if (featureGroups != null) {
+ final Collection<DeploymentFlavorEntity> deploymentFlavorEntities = deploymentFlavorDao
+ .list(new DeploymentFlavorEntity(
+ vspDetails.getId(),
+ vspDetails.getVersion(),
+ null));
+ if (Objects.nonNull(deploymentFlavorEntities)) {
+ for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) {
+ updateDeploymentFlavourEntity(featureGroups, deploymentFlavorEntity);
+ }
+ }
+ }
+ }
- private boolean isServiceModelMissing(ToscaServiceModel serviceModel) {
- return serviceModel == null || serviceModel.getEntryDefinitionServiceTemplate() == null;
- }
+ private void updateDeploymentFlavourEntity(List<String> featureGroups,
+ DeploymentFlavorEntity deploymentFlavorEntity) {
+ final String featureGroupId = deploymentFlavorEntity.getDeploymentFlavorCompositionData().getFeatureGroupId();
+ if (!featureGroups.contains(featureGroupId)) {
+ DeploymentFlavor deploymentFlavorCompositionData =
+ deploymentFlavorEntity.getDeploymentFlavorCompositionData();
+ deploymentFlavorCompositionData.setFeatureGroupId(null);
+ deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavorCompositionData);
+ deploymentFlavorDao.update(deploymentFlavorEntity);
+ }
+ }
- public static class Builder{
- private VspMergeDao vspMergeDao;
- private OrchestrationTemplateDao orchestrationTemplateDao;
- private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager;
- private VendorSoftwareProductInfoDao vspInfoDao;
- private VendorLicenseFacade vendorLicenseFacade;
- private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
- private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao;
- private VendorLicenseArtifactsService licenseArtifactsService;
- private InformationArtifactGenerator informationArtifactGenerator;
- private PackageInfoDao packageInfoDao;
- private DeploymentFlavorDao deploymentFlavorDao;
- private ComponentDao componentDao;
- private ComponentDependencyModelDao componentDependencyModelDao;
- private NicDao nicDao;
- private ComputeDao computeDao;
- private ImageDao imageDao;
- private ManualVspToscaManager manualVspToscaManager;
- private UniqueValueDao uniqueValueDao;
- private CandidateService candidateService;
- public Builder vspMerge(VspMergeDao vspMergeDao){
- this.vspMergeDao = vspMergeDao;
- return this;
+ @Override
+ public VspDetails getVsp(String vspId, Version version) {
+ return getValidatedVsp(vspId, version);
}
- public Builder orchestrationTemplate(OrchestrationTemplateDao orchestrationTemplateDao) {
- this.orchestrationTemplateDao = orchestrationTemplateDao;
- return this;
+ private VspDetails getValidatedVsp(String vspId, Version version) {
+ VspDetails vsp = vspInfoDao.get(new VspDetails(vspId, version));
+ if (vsp == null) {
+ throw new CoreException(new VendorSoftwareProductNotFoundErrorBuilder(vspId).build());
+ }
+ return vsp;
}
- public Builder orchestrationTemplateCandidateManager(OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager) {
- this.orchestrationTemplateCandidateManager = orchestrationTemplateCandidateManager;
- return this;
+ @Override
+ public void deleteVsp(String vspId, Version version) {
+ vspMergeDao.deleteHint(vspId, version);
}
- public Builder vspInfo(VendorSoftwareProductInfoDao vspInfoDao) {
- this.vspInfoDao = vspInfoDao;
- return this;
+ @Override
+ public List<PackageInfo> listPackages(String category, String subCategory) {
+ return packageInfoDao.listByCategory(category, subCategory);
}
- public Builder vendorLicenseFacade(VendorLicenseFacade vendorLicenseFacade) {
- this.vendorLicenseFacade = vendorLicenseFacade;
- return this;
+ @Override
+ public File getTranslatedFile(String vspId, Version version) {
+ PackageInfo packageInfo = packageInfoDao.get(new PackageInfo(vspId, version));
+ if (packageInfo == null) {
+ throw new CoreException(new PackageNotFoundErrorBuilder(vspId, version).build());
+ }
+
+ ByteBuffer translatedFileBuffer = packageInfo.getTranslatedFile();
+ if (translatedFileBuffer == null) {
+ throw new CoreException(new PackageInvalidErrorBuilder(vspId, version).build());
+ }
+
+ File translatedFile = new File(VendorSoftwareProductConstants.VSP_PACKAGE_ZIP);
+
+ try (FileOutputStream fos = new FileOutputStream(translatedFile)) {
+ fos.write(translatedFileBuffer.array());
+ } catch (IOException exception) {
+ throw new CoreException(new TranslationFileCreationErrorBuilder(vspId, version).build(), exception);
+ }
+ return translatedFile;
}
- public Builder serviceModel(ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao) {
- this.serviceModelDao = serviceModelDao;
- return this;
+ @Override
+ public byte[] getOrchestrationTemplateFile(String vspId, Version version) {
+ OrchestrationTemplateEntity uploadData = orchestrationTemplateDao.get(vspId, version);
+ ByteBuffer contentData = uploadData.getContentData();
+ if (contentData == null) {
+ return new byte[0];
+ }
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ try (final ZipOutputStream zos = new ZipOutputStream(baos);
+ ZipInputStream ignored = new ZipInputStream(new ByteArrayInputStream(contentData.array()))) {
+ zos.write(contentData.array());
+ } catch (IOException exception) {
+ throw new CoreException(new FileCreationErrorBuilder(vspId).build(), exception);
+ }
+ return baos.toByteArray();
}
- public Builder enrichedServiceModel(EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao) {
- this.enrichedServiceModelDao = enrichedServiceModelDao;
- return this;
+ @Override
+ public OrchestrationTemplateEntity getOrchestrationTemplateInfo(String vspId, Version version) {
+ return orchestrationTemplateDao.getInfo(vspId, version);
}
- public Builder licenseArtifactsService(VendorLicenseArtifactsService licenseArtifactsService) {
- this.licenseArtifactsService = licenseArtifactsService;
- return this;
+ @Override
+ public Optional<FilesDataStructure> getOrchestrationTemplateStructure(String vspId, Version version) {
+ Optional<String> jsonFileDataStructure =
+ orchestrationTemplateDao.getOrchestrationTemplateStructure(vspId, version);
+
+ if (jsonFileDataStructure.isPresent() && JsonUtil.isValidJson(jsonFileDataStructure.get())) {
+ return Optional.of(JsonUtil.json2Object(jsonFileDataStructure.get(), FilesDataStructure.class));
+ } else {
+ return Optional.empty();
+ }
}
- public Builder informationArtifactGenerator(InformationArtifactGenerator informationArtifactGenerator) {
- this.informationArtifactGenerator = informationArtifactGenerator;
- return this;
+ @Override
+ public PackageInfo createPackage(final String vspId, final Version version) throws IOException {
+ final ToscaServiceModel toscaServiceModel = enrichedServiceModelDao.getServiceModel(vspId, version);
+ final VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version));
+ final Version vlmVersion = vspDetails.getVlmVersion();
+ if (vlmVersion != null) {
+ populateVersionsForVlm(vspDetails.getVendorId(), vlmVersion);
+ }
+ final PackageInfo packageInfo = createPackageInfo(vspDetails);
+
+ final ToscaFileOutputServiceCsarImpl toscaServiceTemplateServiceCsar = new ToscaFileOutputServiceCsarImpl();
+ final FileContentHandler licenseArtifacts = licenseArtifactsService.createLicenseArtifacts(vspDetails.getId(),
+ vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups());
+ final ETSIService etsiService = new ETSIServiceImpl();
+ if (etsiService.isSol004WithToscaMetaDirectory(toscaServiceModel.getArtifactFiles())) {
+ final FileContentHandler handler = toscaServiceModel.getArtifactFiles();
+ final Manifest manifest = etsiService.getManifest(handler);
+ final Optional<Map<String, Path>> fromToMovedPaths = etsiService.moveNonManoFileToArtifactFolder(handler);
+ fromToMovedPaths.ifPresent(it -> etsiService.updateMainDescriptorPaths(toscaServiceModel, it));
+ packageInfo.setResourceType(etsiService.getResourceType(manifest).name());
+ }
+ packageInfo.setTranslatedFile(
+ ByteBuffer.wrap(toscaServiceTemplateServiceCsar.createOutputFile(toscaServiceModel, licenseArtifacts)));
+
+ packageInfoDao.create(packageInfo);
+ return packageInfo;
}
- public Builder packageInfo(PackageInfoDao packageInfoDao) {
- this.packageInfoDao = packageInfoDao;
- return this;
+ void populateVersionsForVlm(String vlmId, Version vlmVersion) {
+ VersioningManager versioningManager = VersioningManagerFactory.getInstance().createInterface();
+ versioningManager.list(vlmId).stream().filter(version -> version.getId().equalsIgnoreCase(vlmVersion.getId()))
+ .findAny().ifPresent(version -> {
+ vlmVersion.setMinor(version.getMinor());
+ vlmVersion.setMajor(version.getMajor());
+ });
}
- public Builder deploymentFlavor(DeploymentFlavorDao deploymentFlavorDao) {
- this.deploymentFlavorDao = deploymentFlavorDao;
- return this;
+ private PackageInfo createPackageInfo(VspDetails vspDetails) {
+ PackageInfo packageInfo = new PackageInfo(vspDetails.getId(), vspDetails.getVersion());
+ packageInfo.setVspName(vspDetails.getName());
+ packageInfo.setVspDescription(vspDetails.getDescription());
+ packageInfo.setCategory(vspDetails.getCategory());
+ packageInfo.setSubCategory(vspDetails.getSubCategory());
+ packageInfo.setVendorName(vspDetails.getVendorName());
+ packageInfo.setPackageType(VendorSoftwareProductConstants.CSAR);
+ packageInfo.setVendorRelease("1.0"); //todo TBD
+ return packageInfo;
}
- public Builder component(ComponentDao componentDao) {
- this.componentDao = componentDao;
- return this;
+ @Override
+
+ public QuestionnaireResponse getVspQuestionnaire(String vspId, Version version) {
+ VspQuestionnaireEntity retrieved = vspInfoDao.getQuestionnaire(vspId, version);
+ VersioningUtil
+ .validateEntityExistence(retrieved, new VspQuestionnaireEntity(vspId, version), VspDetails.ENTITY_TYPE);
+
+ String questionnaireData = retrieved.getQuestionnaireData();
+
+ QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse();
+ questionnaireResponse.setData(questionnaireData);
+ questionnaireResponse.setSchema(getVspQuestionnaireSchema(null));
+ return questionnaireResponse;
}
- public Builder componentDependencyModel(ComponentDependencyModelDao componentDependencyModelDao) {
- this.componentDependencyModelDao = componentDependencyModelDao;
- return this;
+ @Override
+ public void updateVspQuestionnaire(String vspId, Version version, String questionnaireData) {
+ vspInfoDao.updateQuestionnaireData(vspId, version, questionnaireData);
}
- public Builder nic(NicDao nicDao) {
- this.nicDao = nicDao;
- return this;
+
+ private Map<String, List<ErrorMessage>> validateOrchestrationTemplate(
+ OrchestrationTemplateEntity orchestrationTemplate) throws IOException {
+
+ if (isOrchestrationTemplateMissing(orchestrationTemplate)) {
+ return null;
+ }
+ Map<String, List<ErrorMessage>> validationErrors = new HashMap<>();
+
+ FileContentHandler fileContentMap = CommonUtil.validateAndUploadFileContent(
+ OnboardingTypesEnum.getOnboardingTypesEnum(orchestrationTemplate.getFileSuffix()),
+ orchestrationTemplate.getContentData().array());
+
+ if (CommonUtil.isFileOriginFromZip(orchestrationTemplate.getFileSuffix())) {
+ ValidationManager validationManager = ValidationManagerUtil.initValidationManager(fileContentMap);
+ validationErrors.putAll(validationManager.validate());
+ }
+
+ return MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, validationErrors)) ? null
+ : validationErrors;
+ }
+
+ private QuestionnaireValidationResult validateQuestionnaire(String vspId, Version version,
+ String onboardingMethod) {
+ // The apis of CompositionEntityDataManager used here are stateful!
+ // so, it must be re-created from scratch when it is used!
+ CompositionEntityDataManager compositionEntityDataManager =
+ CompositionEntityDataManagerFactory.getInstance().createInterface();
+ compositionEntityDataManager.addEntity(vspInfoDao.getQuestionnaire(vspId, version), null);
+
+ Collection<NicEntity> nics = nicDao.listByVsp(vspId, version);
+
+ Map<String, List<String>> nicNamesByComponent = new HashMap<>();
+ for (NicEntity nicEntity : nics) {
+ compositionEntityDataManager.addEntity(nicEntity, null);
+
+ Nic nic = nicEntity.getNicCompositionData();
+ if (nic != null && nic.getName() != null) {
+ List<String> nicNames =
+ nicNamesByComponent.computeIfAbsent(nicEntity.getComponentId(), k -> new ArrayList<>());
+ nicNames.add(nic.getName());
+ }
+ }
+
+ Collection<ComponentEntity> components = componentDao.listCompositionAndQuestionnaire(vspId, version);
+ components.forEach(component -> compositionEntityDataManager.addEntity(component,
+ new ComponentQuestionnaireSchemaInput(nicNamesByComponent.get(component.getId()),
+ JsonUtil.json2Object(component.getQuestionnaireData(), Map.class), null,
+ OnboardingMethod.Manual.name().equals(onboardingMethod))));
+
+ Collection<ComputeEntity> computes = computeDao.listByVsp(vspId, version);
+ computes.forEach(compute -> compositionEntityDataManager.addEntity(compute, null));
+
+ if (OnboardingMethod.Manual.name().equals(onboardingMethod)) {
+ Collection<ImageEntity> images = imageDao.listByVsp(vspId, version);
+ images.forEach(image -> compositionEntityDataManager.addEntity(image, null));
+ }
+
+ Map<CompositionEntityId, Collection<String>> errorsByEntityId =
+ compositionEntityDataManager.validateEntitiesQuestionnaire();
+ if (MapUtils.isNotEmpty(errorsByEntityId)) {
+ compositionEntityDataManager.buildTrees();
+ compositionEntityDataManager.addErrorsToTrees(errorsByEntityId);
+ return new QuestionnaireValidationResult(compositionEntityDataManager.getAllErrorsByVsp(vspId));
+ }
+ return null;
}
- public Builder compute(ComputeDao computeDao) {
- this.computeDao = computeDao;
- return this;
+ @Override
+ public File getInformationArtifact(String vspId, Version version) {
+ VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version));
+
+ if (vspDetails == null) {
+ return null;
+ }
+
+ String vspName = vspDetails.getName();
+ ByteBuffer infoArtifactAsByteBuffer;
+ File infoArtifactFile;
+ try {
+ infoArtifactAsByteBuffer =
+ ByteBuffer.wrap(informationArtifactGenerator.generate(vspId, version).getBytes());
+
+ infoArtifactFile =
+ new File(String.format(VendorSoftwareProductConstants.INFORMATION_ARTIFACT_NAME, vspName));
+ try (OutputStream out = new BufferedOutputStream(new FileOutputStream(infoArtifactFile))) {
+ out.write(infoArtifactAsByteBuffer.array());
+ }
+
+ } catch (IOException ex) {
+ throw new CoreException(new InformationArtifactCreationErrorBuilder(vspId).build(), ex);
+ }
+ return infoArtifactFile;
}
- public Builder image(ImageDao imageDao) {
- this.imageDao = imageDao;
- return this;
+ String getVspQuestionnaireSchema(SchemaTemplateInput schemaInput) {
+ return SchemaGenerator.generate(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, schemaInput);
+ }
+
+ @Override
+ public Optional<Pair<String, byte[]>> get(String vspId, Version version) throws IOException {
+
+ OrchestrationTemplateEntity orchestrationTemplateEntity = orchestrationTemplateDao.get(vspId, version);
+
+ if (isOrchestrationTemplateMissing(orchestrationTemplateEntity)) {
+ return Optional.empty();
+ }
+
+ if (CommonUtil.isFileOriginFromZip(orchestrationTemplateEntity.getFileSuffix())) {
+ return Optional.of(new ImmutablePair<>(OnboardingTypesEnum.ZIP.toString(),
+ candidateService.getZipData(orchestrationTemplateEntity.getContentData())));
+ }
+ return Optional.of(new ImmutablePair<>(orchestrationTemplateEntity.getFileSuffix(),
+ orchestrationTemplateEntity.getContentData().array()));
}
- public Builder manualVspToscaManager(ManualVspToscaManager manualVspToscaManager) {
- this.manualVspToscaManager = manualVspToscaManager;
- return this;
+ void updateUniqueName(String oldVspName, String newVspName) {
+ uniqueValueUtil
+ .updateUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, oldVspName,
+ newVspName);
}
- public Builder uniqueValue(UniqueValueDao uniqueValueDao) {
- this.uniqueValueDao = uniqueValueDao;
- return this;
+ @Override
+ public Collection<ComputeEntity> getComputeByVsp(String vspId, Version version) {
+ return computeDao.listByVsp(vspId, version);
}
- public Builder candidateService(CandidateService candidateService) {
- this.candidateService = candidateService;
- return this;
+ private boolean isOrchestrationTemplateMissing(OrchestrationTemplateEntity orchestrationTemplate) {
+ return orchestrationTemplate == null || orchestrationTemplate.getContentData() == null
+ || orchestrationTemplate.getFileSuffix() == null || orchestrationTemplate.getFileName() == null;
}
- private void registerToVersioning() {
- if(serviceModelDao != null) {
- serviceModelDao.registerVersioning(
- VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
- }
- if(enrichedServiceModelDao != null) {
- enrichedServiceModelDao.registerVersioning(
- VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
- }
+ private boolean isServiceModelMissing(ToscaServiceModel serviceModel) {
+ return serviceModel == null || serviceModel.getEntryDefinitionServiceTemplate() == null;
}
- public VendorSoftwareProductManager build(){
- VendorSoftwareProductManagerImpl vendorSoftwareProductManager = new VendorSoftwareProductManagerImpl();
- vendorSoftwareProductManager.vspMergeDao = this.vspMergeDao;
- vendorSoftwareProductManager.orchestrationTemplateDao = this.orchestrationTemplateDao;
- vendorSoftwareProductManager.orchestrationTemplateCandidateManager = this.orchestrationTemplateCandidateManager;
- vendorSoftwareProductManager.vspInfoDao = this.vspInfoDao;
- vendorSoftwareProductManager.vendorLicenseFacade = this.vendorLicenseFacade;
- vendorSoftwareProductManager.serviceModelDao = this.serviceModelDao;
- vendorSoftwareProductManager.enrichedServiceModelDao = this.enrichedServiceModelDao;
- vendorSoftwareProductManager.licenseArtifactsService = this.licenseArtifactsService;
- vendorSoftwareProductManager.informationArtifactGenerator = this.informationArtifactGenerator;
- vendorSoftwareProductManager.packageInfoDao = this.packageInfoDao;
- vendorSoftwareProductManager.deploymentFlavorDao = this.deploymentFlavorDao;
- vendorSoftwareProductManager.componentDao = this.componentDao;
- vendorSoftwareProductManager.componentDependencyModelDao = this.componentDependencyModelDao;
- vendorSoftwareProductManager.nicDao = this.nicDao;
- vendorSoftwareProductManager.computeDao = this.computeDao;
- vendorSoftwareProductManager.imageDao = this.imageDao;
- vendorSoftwareProductManager.manualVspToscaManager = this.manualVspToscaManager;
- vendorSoftwareProductManager.uniqueValueUtil = new UniqueValueUtil(this.uniqueValueDao);
- vendorSoftwareProductManager.candidateService = candidateService;
- this.registerToVersioning();
- return vendorSoftwareProductManager;
+ public static class Builder {
+
+ private VspMergeDao vspMergeDao;
+ private OrchestrationTemplateDao orchestrationTemplateDao;
+ private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager;
+ private VendorSoftwareProductInfoDao vspInfoDao;
+ private VendorLicenseFacade vendorLicenseFacade;
+ private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
+ private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao;
+ private VendorLicenseArtifactsService licenseArtifactsService;
+ private InformationArtifactGenerator informationArtifactGenerator;
+ private PackageInfoDao packageInfoDao;
+ private DeploymentFlavorDao deploymentFlavorDao;
+ private ComponentDao componentDao;
+ private ComponentDependencyModelDao componentDependencyModelDao;
+ private NicDao nicDao;
+ private ComputeDao computeDao;
+ private ImageDao imageDao;
+ private ManualVspToscaManager manualVspToscaManager;
+ private UniqueValueDao uniqueValueDao;
+ private CandidateService candidateService;
+
+ public Builder vspMerge(VspMergeDao vspMergeDao) {
+ this.vspMergeDao = vspMergeDao;
+ return this;
+ }
+
+ public Builder orchestrationTemplate(OrchestrationTemplateDao orchestrationTemplateDao) {
+ this.orchestrationTemplateDao = orchestrationTemplateDao;
+ return this;
+ }
+
+ public Builder orchestrationTemplateCandidateManager(
+ OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager) {
+ this.orchestrationTemplateCandidateManager = orchestrationTemplateCandidateManager;
+ return this;
+ }
+
+ public Builder vspInfo(VendorSoftwareProductInfoDao vspInfoDao) {
+ this.vspInfoDao = vspInfoDao;
+ return this;
+ }
+
+ public Builder vendorLicenseFacade(VendorLicenseFacade vendorLicenseFacade) {
+ this.vendorLicenseFacade = vendorLicenseFacade;
+ return this;
+ }
+
+ public Builder serviceModel(ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao) {
+ this.serviceModelDao = serviceModelDao;
+ return this;
+ }
+
+ public Builder enrichedServiceModel(
+ EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao) {
+ this.enrichedServiceModelDao = enrichedServiceModelDao;
+ return this;
+ }
+
+ public Builder licenseArtifactsService(VendorLicenseArtifactsService licenseArtifactsService) {
+ this.licenseArtifactsService = licenseArtifactsService;
+ return this;
+ }
+
+ public Builder informationArtifactGenerator(InformationArtifactGenerator informationArtifactGenerator) {
+ this.informationArtifactGenerator = informationArtifactGenerator;
+ return this;
+ }
+
+ public Builder packageInfo(PackageInfoDao packageInfoDao) {
+ this.packageInfoDao = packageInfoDao;
+ return this;
+ }
+
+ public Builder deploymentFlavor(DeploymentFlavorDao deploymentFlavorDao) {
+ this.deploymentFlavorDao = deploymentFlavorDao;
+ return this;
+ }
+
+ public Builder component(ComponentDao componentDao) {
+ this.componentDao = componentDao;
+ return this;
+ }
+
+ public Builder componentDependencyModel(ComponentDependencyModelDao componentDependencyModelDao) {
+ this.componentDependencyModelDao = componentDependencyModelDao;
+ return this;
+ }
+
+ public Builder nic(NicDao nicDao) {
+ this.nicDao = nicDao;
+ return this;
+ }
+
+ public Builder compute(ComputeDao computeDao) {
+ this.computeDao = computeDao;
+ return this;
+ }
+
+ public Builder image(ImageDao imageDao) {
+ this.imageDao = imageDao;
+ return this;
+ }
+
+ public Builder manualVspToscaManager(ManualVspToscaManager manualVspToscaManager) {
+ this.manualVspToscaManager = manualVspToscaManager;
+ return this;
+ }
+
+ public Builder uniqueValue(UniqueValueDao uniqueValueDao) {
+ this.uniqueValueDao = uniqueValueDao;
+ return this;
+ }
+
+ public Builder candidateService(CandidateService candidateService) {
+ this.candidateService = candidateService;
+ return this;
+ }
+
+ private void registerToVersioning() {
+ if (serviceModelDao != null) {
+ serviceModelDao
+ .registerVersioning(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
+ }
+ if (enrichedServiceModelDao != null) {
+ enrichedServiceModelDao
+ .registerVersioning(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
+ }
+ }
+
+ public VendorSoftwareProductManager build() {
+ VendorSoftwareProductManagerImpl vendorSoftwareProductManager = new VendorSoftwareProductManagerImpl();
+ vendorSoftwareProductManager.vspMergeDao = this.vspMergeDao;
+ vendorSoftwareProductManager.orchestrationTemplateDao = this.orchestrationTemplateDao;
+ vendorSoftwareProductManager.orchestrationTemplateCandidateManager =
+ this.orchestrationTemplateCandidateManager;
+ vendorSoftwareProductManager.vspInfoDao = this.vspInfoDao;
+ vendorSoftwareProductManager.vendorLicenseFacade = this.vendorLicenseFacade;
+ vendorSoftwareProductManager.serviceModelDao = this.serviceModelDao;
+ vendorSoftwareProductManager.enrichedServiceModelDao = this.enrichedServiceModelDao;
+ vendorSoftwareProductManager.licenseArtifactsService = this.licenseArtifactsService;
+ vendorSoftwareProductManager.informationArtifactGenerator = this.informationArtifactGenerator;
+ vendorSoftwareProductManager.packageInfoDao = this.packageInfoDao;
+ vendorSoftwareProductManager.deploymentFlavorDao = this.deploymentFlavorDao;
+ vendorSoftwareProductManager.componentDao = this.componentDao;
+ vendorSoftwareProductManager.componentDependencyModelDao = this.componentDependencyModelDao;
+ vendorSoftwareProductManager.nicDao = this.nicDao;
+ vendorSoftwareProductManager.computeDao = this.computeDao;
+ vendorSoftwareProductManager.imageDao = this.imageDao;
+ vendorSoftwareProductManager.manualVspToscaManager = this.manualVspToscaManager;
+ vendorSoftwareProductManager.uniqueValueUtil = new UniqueValueUtil(this.uniqueValueDao);
+ vendorSoftwareProductManager.candidateService = candidateService;
+ this.registerToVersioning();
+ return vendorSoftwareProductManager;
+ }
}
- }
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VspManagerFactoryImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VspManagerFactoryImpl.java
index b0385a373b..a504f35026 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VspManagerFactoryImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VspManagerFactoryImpl.java
@@ -39,26 +39,26 @@ import org.openecomp.sdc.vendorsoftwareproduct.factory.InformationArtifactGenera
public class VspManagerFactoryImpl extends VspManagerFactory {
private static final VendorSoftwareProductManager INSTANCE = new VendorSoftwareProductManagerImpl.Builder()
- .vspMerge(VspMergeDaoFactory.getInstance().createInterface())
- .orchestrationTemplate(OrchestrationTemplateDaoFactory.getInstance().createInterface())
- .orchestrationTemplateCandidateManager(OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface())
- .vspInfo(VendorSoftwareProductInfoDaoFactory.getInstance().createInterface())
- .vendorLicenseFacade(VendorLicenseFacadeFactory.getInstance().createInterface())
- .serviceModel(ServiceModelDaoFactory.getInstance().createInterface())
- .enrichedServiceModel(EnrichedServiceModelDaoFactory.getInstance().createInterface())
- .licenseArtifactsService(VendorLicenseArtifactServiceFactory.getInstance().createInterface())
- .informationArtifactGenerator(InformationArtifactGeneratorFactory.getInstance().createInterface())
- .packageInfo(PackageInfoDaoFactory.getInstance().createInterface())
- .deploymentFlavor(DeploymentFlavorDaoFactory.getInstance().createInterface())
- .component(ComponentDaoFactory.getInstance().createInterface())
- .componentDependencyModel(ComponentDependencyModelDaoFactory.getInstance().createInterface())
- .nic(NicDaoFactory.getInstance().createInterface())
- .compute(ComputeDaoFactory.getInstance().createInterface())
- .image(ImageDaoFactory.getInstance().createInterface())
- .manualVspToscaManager(new ManualVspToscaManagerImpl())
- .uniqueValue(UniqueValueDaoFactory.getInstance().createInterface())
- .candidateService(CandidateServiceFactory.getInstance().createInterface())
- .build();
+ .vspMerge(VspMergeDaoFactory.getInstance().createInterface())
+ .orchestrationTemplate(OrchestrationTemplateDaoFactory.getInstance().createInterface())
+ .orchestrationTemplateCandidateManager(OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface())
+ .vspInfo(VendorSoftwareProductInfoDaoFactory.getInstance().createInterface())
+ .vendorLicenseFacade(VendorLicenseFacadeFactory.getInstance().createInterface())
+ .serviceModel(ServiceModelDaoFactory.getInstance().createInterface())
+ .enrichedServiceModel(EnrichedServiceModelDaoFactory.getInstance().createInterface())
+ .licenseArtifactsService(VendorLicenseArtifactServiceFactory.getInstance().createInterface())
+ .informationArtifactGenerator(InformationArtifactGeneratorFactory.getInstance().createInterface())
+ .packageInfo(PackageInfoDaoFactory.getInstance().createInterface())
+ .deploymentFlavor(DeploymentFlavorDaoFactory.getInstance().createInterface())
+ .component(ComponentDaoFactory.getInstance().createInterface())
+ .componentDependencyModel(ComponentDependencyModelDaoFactory.getInstance().createInterface())
+ .nic(NicDaoFactory.getInstance().createInterface())
+ .compute(ComputeDaoFactory.getInstance().createInterface())
+ .image(ImageDaoFactory.getInstance().createInterface())
+ .manualVspToscaManager(new ManualVspToscaManagerImpl())
+ .uniqueValue(UniqueValueDaoFactory.getInstance().createInterface())
+ .candidateService(CandidateServiceFactory.getInstance().createInterface())
+ .build();
@Override
public VendorSoftwareProductManager createInterface() {
diff --git a/openecomp-be/dist/sdc-onboard-backend-docker/artifacts/chef-repo/cookbooks/sdc-onboard-backend/attributes/default.rb b/openecomp-be/dist/sdc-onboard-backend-docker/artifacts/chef-repo/cookbooks/sdc-onboard-backend/attributes/default.rb
index 8a7cf208e5..e7b6766ae8 100644
--- a/openecomp-be/dist/sdc-onboard-backend-docker/artifacts/chef-repo/cookbooks/sdc-onboard-backend/attributes/default.rb
+++ b/openecomp-be/dist/sdc-onboard-backend-docker/artifacts/chef-repo/cookbooks/sdc-onboard-backend/attributes/default.rb
@@ -21,5 +21,5 @@ default['cassandra']['socket_connect_timeout'] = 20000
default['cassandra']['janusgraph_connection_timeout'] = 10000
#ExternalTesting
-default['EXTTEST']['ep1_config'] = "vtp,VTP,true,http://192.168.50.5:8702/onapapi/vnfsdk-marketplace,c.*"
+default['EXTTEST']['ep1_config'] = "vtp,VTP,true,http://192.168.50.5:8702/onapapi/vnfsdk-marketplace,onap.*"
default['EXTTEST']['ep2_config'] = "repository,Repository,false,,.*"
diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/main/java/org/openecomp/core/externaltesting/api/ExternalTestingManager.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/main/java/org/openecomp/core/externaltesting/api/ExternalTestingManager.java
index ac2f7fcafa..21d09edc91 100644
--- a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/main/java/org/openecomp/core/externaltesting/api/ExternalTestingManager.java
+++ b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/main/java/org/openecomp/core/externaltesting/api/ExternalTestingManager.java
@@ -18,82 +18,104 @@ package org.openecomp.core.externaltesting.api;
import java.util.List;
+import java.util.Map;
public interface ExternalTestingManager {
- /**
- * Return the configuration of this feature that we want to
- * expose to the client. Treated as a JSON blob for flexibility.
- */
- ClientConfiguration getConfig();
-
- /**
- * For testing purposes, set the client configuration.
- */
- ClientConfiguration setConfig(ClientConfiguration config);
-
- /**
- * Build a tree of all test cases for the client including all
- * defined endpoints, scenarios, and test suites.
- * @return test case tree.
- */
- TestTreeNode getTestCasesAsTree();
-
- /**
- * Get a list of testing endpoints.
- */
- List<RemoteTestingEndpointDefinition> getEndpoints();
-
-
- /**
- * For functional testing purposes, allow the endpoint configuration
- * to be provisioned to the BE.
- */
- List<RemoteTestingEndpointDefinition> setEndpoints(List<RemoteTestingEndpointDefinition> endpoints);
-
- /**
- * Get a list of scenarios from and endpoint.
- */
- List<VtpNameDescriptionPair> getScenarios(String endpoint);
-
- /**
- * Get a list of test suites given the endpoint and scenario.
- */
- List<VtpNameDescriptionPair> getTestSuites(String endpoint, String scenario);
-
- /**
- * Get a list of test cases.
- * @param endpoint endpoint to contact (e.g. VTP)
- * @param scenario test scenario to get tests for
- * @return list of test cases.
- */
- List<VtpTestCase> getTestCases(String endpoint, String scenario);
-
- /**
- * Get the details about a particular test case.
- * @param endpoint endpoint to contact (e.g. VTP)
- * @param scenario test scenario to get tests for
- * @param testSuite suite to get tests for
- * @param testCaseName test case name to query.
- * @return details about the test case.
- */
- VtpTestCase getTestCase(String endpoint, String scenario, String testSuite, String testCaseName);
-
- /**
- * Execute a collection of tests where the manager must distribute
- * the tests to the appropriate endpoint and correlate the responses.
- * @param requests collection of request items.
- * @param requestId optional request ID provided from client.
- * @return response from endpoint (don't bother to parse).
- */
- List<VtpTestExecutionResponse> execute(List<VtpTestExecutionRequest> requests, String requestId);
-
- /**
- * Return a previous results.
- * @param endpoint endpoint to query
- * @param executionId execution to query.
- * @return response from endpoint.
- */
- VtpTestExecutionResponse getExecution(String endpoint, String executionId);
-
-}
+ /**
+ * Return the configuration of this feature that we want to
+ * expose to the client. Treated as a JSON blob for flexibility.
+ */
+ ClientConfiguration getConfig();
+
+ /**
+ * For testing purposes, set the client configuration.
+ */
+ ClientConfiguration setConfig(ClientConfiguration config);
+
+ /**
+ * Build a tree of all test cases for the client including all
+ * defined endpoints, scenarios, and test suites.
+ *
+ * @return test case tree.
+ */
+ TestTreeNode getTestCasesAsTree();
+
+ /**
+ * Get a list of testing endpoints.
+ */
+ List<RemoteTestingEndpointDefinition> getEndpoints();
+
+
+ /**
+ * For functional testing purposes, allow the endpoint configuration
+ * to be provisioned to the BE.
+ */
+ List<RemoteTestingEndpointDefinition> setEndpoints(List<RemoteTestingEndpointDefinition> endpoints);
+
+ /**
+ * Get a list of scenarios from and endpoint.
+ */
+ List<VtpNameDescriptionPair> getScenarios(String endpoint);
+
+ /**
+ * Get a list of test suites given the endpoint and scenario.
+ */
+ List<VtpNameDescriptionPair> getTestSuites(String endpoint, String scenario);
+
+ /**
+ * Get a list of test cases.
+ *
+ * @param endpoint endpoint to contact (e.g. VTP)
+ * @param scenario test scenario to get tests for
+ * @return list of test cases.
+ */
+ List<VtpTestCase> getTestCases(String endpoint, String scenario);
+
+ /**
+ * Get the details about a particular test case.
+ *
+ * @param endpoint endpoint to contact (e.g. VTP)
+ * @param scenario test scenario to get tests for
+ * @param testSuite suite to get tests for
+ * @param testCaseName test case name to query.
+ * @return details about the test case.
+ */
+ VtpTestCase getTestCase(String endpoint, String scenario, String testSuite, String testCaseName);
+
+ /**
+ * Execute a collection of tests where the manager must distribute
+ * the tests to the appropriate endpoint and correlate the responses.
+ *
+ * @param requests collection of request items.
+ * @param requestId optional request ID provided from client.
+ * @param vspVersionId vsp version id
+ * @param requestId request id
+ * @param fileMap file map
+ * @return response from endpoint (don't bother to parse).
+ */
+
+ List<VtpTestExecutionResponse> execute(List<VtpTestExecutionRequest> requests, String vspId, String vspVersionId,
+ String requestId, Map<String, byte[]> fileMap);
+
+
+ /**
+ * Return a previous results.
+ *
+ * @param endpoint endpoint to query
+ * @param executionId execution to query.
+ * @return response from endpoint.
+ */
+ VtpTestExecutionResponse getExecution(String endpoint, String executionId);
+
+ /**
+ * Get ExceutionIds by requestId
+ *
+ * @param endpoint
+ * @param requestId
+ * @return response from endpoint
+ */
+ List<VtpTestExecutionOutput> getExecutionIds(String endpoint, String requestId);
+
+
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/main/java/org/openecomp/core/externaltesting/api/VtpTestExecutionOutput.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/main/java/org/openecomp/core/externaltesting/api/VtpTestExecutionOutput.java
new file mode 100644
index 0000000000..e59fb6008a
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/main/java/org/openecomp/core/externaltesting/api/VtpTestExecutionOutput.java
@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) 2019 Vodafone Group
+ *
+ * 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.openecomp.core.externaltesting.api;
+
+import lombok.Data;
+
+@Data
+public class VtpTestExecutionOutput {
+
+ private String scenario;
+ private String testCaseName;
+ private String testSuiteName;
+ private String executionId;
+ private String requestId;
+ private String status;
+ private String startTime;
+ private String endTime;
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/main/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImpl.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/main/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImpl.java
index 22ac1e8ed8..dfabf31568 100644
--- a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/main/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/main/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImpl.java
@@ -16,25 +16,39 @@
package org.openecomp.core.externaltesting.impl;
-import com.amdocs.zusammen.utils.fileutils.json.JsonUtil;
+
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.collect.ImmutableSet;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
-import java.util.Map.Entry;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.annotation.PostConstruct;
import lombok.EqualsAndHashCode;
-import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.sdc.tosca.services.YamlUtil;
-import org.openecomp.core.externaltesting.api.*;
+import org.openecomp.core.externaltesting.api.ClientConfiguration;
+import org.openecomp.core.externaltesting.api.ExternalTestingManager;
+import org.openecomp.core.externaltesting.api.RemoteTestingEndpointDefinition;
+import org.openecomp.core.externaltesting.api.TestTreeNode;
+import org.openecomp.core.externaltesting.api.VtpNameDescriptionPair;
+import org.openecomp.core.externaltesting.api.VtpTestCase;
+import org.openecomp.core.externaltesting.api.VtpTestExecutionOutput;
+import org.openecomp.core.externaltesting.api.VtpTestExecutionRequest;
+import org.openecomp.core.externaltesting.api.VtpTestExecutionResponse;
import org.openecomp.core.externaltesting.errors.ExternalTestingException;
-import org.openecomp.sdc.common.zip.ZipUtils;
-import org.openecomp.sdc.common.zip.exception.ZipException;
-import org.openecomp.sdc.heat.datatypes.manifest.FileData;
-import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent;
import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManagerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
@@ -46,7 +60,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.io.ByteArrayResource;
-import org.springframework.http.*;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@@ -54,887 +72,728 @@ import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
-import org.yaml.snakeyaml.Yaml;
-
-import javax.annotation.PostConstruct;
-import java.io.*;
-import java.util.*;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
public class ExternalTestingManagerImpl implements ExternalTestingManager {
- private Logger logger = LoggerFactory.getLogger(ExternalTestingManagerImpl.class);
-
- private static final String FILE_URL_PREFIX = "file://";
- private static final String MANIFEST_JSON = "MANIFEST.json";
- private static final String HTTP_STATUS = "httpStatus";
- private static final String CODE = "code";
- private static final String ERROR = "error";
- private static final String MESSAGE = "message";
- private static final String DETAIL = "detail";
- private static final String PATH = "path";
-
- private static final String VTP_SCENARIOS_URI = "%s/v1/vtp/scenarios";
- private static final String VTP_TESTSUITE_URI = "%s/v1/vtp/scenarios/%s/testsuites";
- private static final String VTP_TESTCASES_URI = "%s/v1/vtp/scenarios/%s/testcases";
- private static final String VTP_TESTCASE_URI = "%s/v1/vtp/scenarios/%s/testsuites/%s/testcases/%s";
- private static final String VTP_EXECUTIONS_URI = "%s/v1/vtp/executions";
- private static final String VTP_EXECUTION_URI = "%s/v1/vtp/executions/%s";
-
- private static final String INVALIDATE_STATE_ERROR_CODE = "SDC-TEST-001";
- private static final String NO_ACCESS_CONFIGURATION_DEFINED = "No access configuration defined";
-
- private static final String NO_SUCH_ENDPOINT_ERROR_CODE = "SDC-TEST-002";
- private static final String ENDPOINT_ERROR_CODE = "SDC-TEST-003";
- private static final String TESTING_HTTP_ERROR_CODE = "SDC-TEST-004";
- private static final String SDC_RESOLVER_ERR = "SDC-TEST-005";
-
- private static final String TOSCA_META = "TOSCA-Metadata/TOSCA.meta";
- private static final String MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME = "MainServiceTemplate.yaml";
- private static final String TOSCA_META_ENTRY_DEFINITIONS="Entry-Definitions";
- static final String VSP_ID = "vspId";
- static final String VSP_VERSION = "vspVersion";
-
- private static final String SDC_CSAR = "sdc-csar";
- private static final String SDC_HEAT = "sdc-heat";
- private final ImmutableSet<String> relevantArchiveFileExtensionSet =
- ImmutableSet.of("yaml", "meta", "yml", "json", "env");
-
-
- private VersioningManager versioningManager;
- private VendorSoftwareProductManager vendorSoftwareProductManager;
- private OrchestrationTemplateCandidateManager candidateManager;
-
- private TestingAccessConfig accessConfig;
- private List<RemoteTestingEndpointDefinition> endpoints;
-
- private RestTemplate restTemplate;
-
- public ExternalTestingManagerImpl() {
- restTemplate = new RestTemplate();
- }
-
- ExternalTestingManagerImpl(VersioningManager versioningManager,
- VendorSoftwareProductManager vendorSoftwareProductManager,
- OrchestrationTemplateCandidateManager candidateManager) {
- this();
- this.versioningManager = versioningManager;
- this.vendorSoftwareProductManager = vendorSoftwareProductManager;
- this.candidateManager = candidateManager;
- }
-
- /**
- * Read the configuration from the yaml file for this bean. If we get an exception during load,
- * don't force an error starting SDC but log a warning. Do no warm...
- */
- @PostConstruct
- public void init() {
-
- if (versioningManager == null) {
- versioningManager = VersioningManagerFactory.getInstance().createInterface();
- }
- if (vendorSoftwareProductManager == null) {
- vendorSoftwareProductManager =
- VspManagerFactory.getInstance().createInterface();
- }
- if (candidateManager == null) {
- candidateManager =
- OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface();
- }
-
- loadConfig();
- }
-
- private Stream<RemoteTestingEndpointDefinition> mapEndpointString(String ep) {
- RemoteTestingEndpointDefinition rv = new RemoteTestingEndpointDefinition();
- String[] cfg = ep.split(",");
- if (cfg.length < 4) {
- logger.error("invalid endpoint definition {}", ep);
- return Stream.empty();
- }
- else {
- rv.setId(cfg[0]);
- rv.setTitle(cfg[1]);
- rv.setEnabled("true".equals(cfg[2]));
- rv.setUrl(cfg[3]);
- if (cfg.length > 4) {
- rv.setScenarioFilter(cfg[4]);
- }
- if (cfg.length > 5) {
- rv.setApiKey(cfg[5]);
- }
- return Stream.of(rv);
- }
- }
-
- /**
- * Load the configuration for this component. When the SDC onboarding backend
- * runs, it gets a system property called config.location. We can use that
- * to locate the config-externaltesting.yaml file.
- */
- private void loadConfig() {
- String loc = System.getProperty("config.location");
- File file = new File(loc, "externaltesting-configuration.yaml");
- try (InputStream fileInput = new FileInputStream(file)) {
- YamlUtil yamlUtil = new YamlUtil();
- accessConfig = yamlUtil.yamlToObject(fileInput, TestingAccessConfig.class);
-
- if (logger.isInfoEnabled()) {
- String s = new ObjectMapper().writeValueAsString(accessConfig);
- logger.info("loaded external testing config {}", s);
- }
-
- endpoints = accessConfig.getEndpoints().stream()
- .flatMap(this::mapEndpointString)
- .collect(Collectors.toList());
-
- if (logger.isInfoEnabled()) {
- String s = new ObjectMapper().writeValueAsString(endpoints);
- logger.info("processed external testing config {}", s);
- }
- }
- catch (IOException ex) {
- logger.error("failed to read external testing config. Disabling the feature", ex);
- accessConfig = new TestingAccessConfig();
- accessConfig.setEndpoints(new ArrayList<>());
- accessConfig.setClient(new ClientConfiguration());
- accessConfig.getClient().setEnabled(false);
- endpoints = new ArrayList<>();
- }
- }
-
- /**
- * Return the configuration of this feature that we want to
- * expose to the client. Treated as a JSON blob for flexibility.
- */
- @Override
- public ClientConfiguration getConfig() {
- ClientConfiguration cc = null;
- if (accessConfig != null) {
- cc = accessConfig.getClient();
- }
- if (cc == null) {
- cc = new ClientConfiguration();
- cc.setEnabled(false);
- }
- return cc;
- }
-
- /**
- * To allow for functional testing, we let a caller invoke
- * a setConfig request to enable/disable the client. This
- * new value is not persisted.
- * @return new client configuration
- */
- @Override
- public ClientConfiguration setConfig(ClientConfiguration cc) {
- if (accessConfig == null) {
- accessConfig = new TestingAccessConfig();
- }
- accessConfig.setClient(cc);
- return getConfig();
- }
-
- /**
- * To allow for functional testing, we let a caller invoke
- * a setEndpoints request to configure where the BE makes request to.
- * @return new endpoint definitions.
- */
- @Override
- public List<RemoteTestingEndpointDefinition> setEndpoints(List<RemoteTestingEndpointDefinition> endpoints) {
- this.endpoints = endpoints;
- return this.getEndpoints();
- }
-
-
-
- @Override
- public TestTreeNode getTestCasesAsTree() {
- TestTreeNode root = new TestTreeNode("root", "root");
-
- // quick out in case of non-configured SDC
- if (endpoints == null) {
- return root;
- }
-
- for (RemoteTestingEndpointDefinition ep : endpoints) {
- if (ep.isEnabled()) {
- buildTreeFromEndpoint(ep, root);
- }
- }
- return root;
- }
-
- private void buildTreeFromEndpoint(RemoteTestingEndpointDefinition ep, TestTreeNode root) {
- try {
- logger.debug("process endpoint {}", ep.getId());
- getScenarios(ep.getId()).stream().filter(s ->
- ((ep.getScenarioFilter() == null) || ep.getScenarioFilterPattern().matcher(s.getName()).matches()))
- .forEach(s -> {
+ private Logger logger = LoggerFactory.getLogger(ExternalTestingManagerImpl.class);
+
+ private static final String FILE_URL_PREFIX = "file://";
+ private static final String HTTP_STATUS = "httpStatus";
+ private static final String CODE = "code";
+ private static final String ERROR = "error";
+ private static final String MESSAGE = "message";
+ private static final String DETAIL = "detail";
+ private static final String PATH = "path";
+
+ private static final String VTP_SCENARIOS_URI = "%s/v1/vtp/scenarios";
+ private static final String VTP_TESTSUITE_URI = "%s/v1/vtp/scenarios/%s/testsuites";
+ private static final String VTP_TESTCASES_URI = "%s/v1/vtp/scenarios/%s/testcases";
+ private static final String VTP_TESTCASE_URI = "%s/v1/vtp/scenarios/%s/testsuites/%s/testcases/%s";
+ private static final String VTP_EXECUTIONS_URI = "%s/v1/vtp/executions";
+ private static final String VTP_EXECUTION_URI = "%s/v1/vtp/executions/%s";
+ private static final String VTP_EXECUTION_ID_URL = "%s/v1/vtp/executions?requestId=%s";
+
+
+ private static final String INVALIDATE_STATE_ERROR_CODE = "SDC-TEST-001";
+ private static final String NO_ACCESS_CONFIGURATION_DEFINED = "No access configuration defined";
+
+ private static final String NO_SUCH_ENDPOINT_ERROR_CODE = "SDC-TEST-002";
+ private static final String ENDPOINT_ERROR_CODE = "SDC-TEST-003";
+ private static final String TESTING_HTTP_ERROR_CODE = "SDC-TEST-004";
+ private static final String SDC_RESOLVER_ERR = "SDC-TEST-005";
+
+ static final String VSP_ID = "vspId";
+ static final String VSP_VERSION = "vspVersion";
+
+ private static final String VSP_CSAR = "vsp";
+ private static final String VSP_HEAT = "vsp-zip";
+
+
+ private VersioningManager versioningManager;
+ private VendorSoftwareProductManager vendorSoftwareProductManager;
+ private OrchestrationTemplateCandidateManager candidateManager;
+
+ private TestingAccessConfig accessConfig;
+ private List<RemoteTestingEndpointDefinition> endpoints;
+
+ private RestTemplate restTemplate;
+
+ public ExternalTestingManagerImpl() {
+ restTemplate = new RestTemplate();
+ }
+
+ ExternalTestingManagerImpl(VersioningManager versioningManager,
+ VendorSoftwareProductManager vendorSoftwareProductManager,
+ OrchestrationTemplateCandidateManager candidateManager) {
+ this();
+ this.versioningManager = versioningManager;
+ this.vendorSoftwareProductManager = vendorSoftwareProductManager;
+ this.candidateManager = candidateManager;
+ }
+
+ /**
+ * Read the configuration from the yaml file for this bean. If we get an exception during load,
+ * don't force an error starting SDC but log a warning. Do no warm...
+ */
+ @PostConstruct
+ public void init() {
+
+ if (versioningManager == null) {
+ versioningManager = VersioningManagerFactory.getInstance().createInterface();
+ }
+ if (vendorSoftwareProductManager == null) {
+ vendorSoftwareProductManager = VspManagerFactory.getInstance().createInterface();
+ }
+ if (candidateManager == null) {
+ candidateManager = OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface();
+ }
+
+ loadConfig();
+ }
+
+ private Stream<RemoteTestingEndpointDefinition> mapEndpointString(String ep) {
+ RemoteTestingEndpointDefinition rv = new RemoteTestingEndpointDefinition();
+ String[] cfg = ep.split(",");
+ if (cfg.length < 4) {
+ logger.error("invalid endpoint definition {}", ep);
+ return Stream.empty();
+ } else {
+ rv.setId(cfg[0]);
+ rv.setTitle(cfg[1]);
+ rv.setEnabled("true".equals(cfg[2]));
+ rv.setUrl(cfg[3]);
+ if (cfg.length > 4) {
+ rv.setScenarioFilter(cfg[4]);
+ }
+ if (cfg.length > 5) {
+ rv.setApiKey(cfg[5]);
+ }
+ return Stream.of(rv);
+ }
+ }
+
+ /**
+ * Load the configuration for this component. When the SDC onboarding backend
+ * runs, it gets a system property called config.location. We can use that
+ * to locate the config-externaltesting.yaml file.
+ */
+ private void loadConfig() {
+ String loc = System.getProperty("config.location");
+ File file = new File(loc, "externaltesting-configuration.yaml");
+ try (InputStream fileInput = new FileInputStream(file)) {
+ YamlUtil yamlUtil = new YamlUtil();
+ accessConfig = yamlUtil.yamlToObject(fileInput, TestingAccessConfig.class);
+
+ if (logger.isInfoEnabled()) {
+ String s = new ObjectMapper().writeValueAsString(accessConfig);
+ logger.info("loaded external testing config {}", s);
+ }
+
+ endpoints =
+ accessConfig.getEndpoints().stream().flatMap(this::mapEndpointString).collect(Collectors.toList());
+
+ if (logger.isInfoEnabled()) {
+ String s = new ObjectMapper().writeValueAsString(endpoints);
+ logger.info("processed external testing config {}", s);
+ }
+ } catch (IOException ex) {
+ logger.error("failed to read external testing config. Disabling the feature", ex);
+ accessConfig = new TestingAccessConfig();
+ accessConfig.setEndpoints(new ArrayList<>());
+ accessConfig.setClient(new ClientConfiguration());
+ accessConfig.getClient().setEnabled(false);
+ endpoints = new ArrayList<>();
+ }
+ }
+
+ /**
+ * Return the configuration of this feature that we want to
+ * expose to the client. Treated as a JSON blob for flexibility.
+ */
+ @Override
+ public ClientConfiguration getConfig() {
+ ClientConfiguration cc = null;
+ if (accessConfig != null) {
+ cc = accessConfig.getClient();
+ }
+ if (cc == null) {
+ cc = new ClientConfiguration();
+ cc.setEnabled(false);
+ }
+ return cc;
+ }
+
+ /**
+ * To allow for functional testing, we let a caller invoke
+ * a setConfig request to enable/disable the client. This
+ * new value is not persisted.
+ *
+ * @return new client configuration
+ */
+ @Override
+ public ClientConfiguration setConfig(ClientConfiguration cc) {
+ if (accessConfig == null) {
+ accessConfig = new TestingAccessConfig();
+ }
+ accessConfig.setClient(cc);
+ return getConfig();
+ }
+
+ /**
+ * To allow for functional testing, we let a caller invoke
+ * a setEndpoints request to configure where the BE makes request to.
+ *
+ * @return new endpoint definitions.
+ */
+ @Override
+ public List<RemoteTestingEndpointDefinition> setEndpoints(List<RemoteTestingEndpointDefinition> endpoints) {
+ this.endpoints = endpoints;
+ return this.getEndpoints();
+ }
+
+
+ @Override
+ public TestTreeNode getTestCasesAsTree() {
+ TestTreeNode root = new TestTreeNode("root", "root");
+
+ // quick out in case of non-configured SDC
+ if (endpoints == null) {
+ return root;
+ }
+
+ for (RemoteTestingEndpointDefinition ep : endpoints) {
+ if (ep.isEnabled()) {
+ buildTreeFromEndpoint(ep, root);
+ }
+ }
+ return root;
+ }
+
+ private void buildTreeFromEndpoint(RemoteTestingEndpointDefinition ep, TestTreeNode root) {
+ try {
+ logger.debug("process endpoint {}", ep.getId());
+ getScenarios(ep.getId()).stream()
+ .filter(s -> ((ep.getScenarioFilter() == null) || ep.getScenarioFilterPattern().matcher(s.getName())
+ .matches())).forEach(s -> {
addScenarioToTree(root, s);
getTestSuites(ep.getId(), s.getName()).forEach(suite -> addSuiteToTree(root, s, suite));
getTestCases(ep.getId(), s.getName()).forEach(tc -> {
- try {
- VtpTestCase details = getTestCase(ep.getId(), s.getName(), tc.getTestSuiteName(), tc.getTestCaseName());
- addTestCaseToTree(root, ep.getId(), s.getName(), tc.getTestSuiteName(), details);
- }
- catch (@SuppressWarnings("squid:S1166") ExternalTestingException ex) {
- // Not logging stack trace on purpose. VTP was throwing exceptions for certain test cases.
- logger.warn("failed to load test case {}", tc.getTestCaseName());
- }
+ try {
+ VtpTestCase details =
+ getTestCase(ep.getId(), s.getName(), tc.getTestSuiteName(), tc.getTestCaseName());
+ addTestCaseToTree(root, ep.getId(), s.getName(), tc.getTestSuiteName(), details);
+ } catch (@SuppressWarnings("squid:S1166") ExternalTestingException ex) {
+ // Not logging stack trace on purpose. VTP was throwing exceptions for certain test cases.
+ logger.warn("failed to load test case {}", tc.getTestCaseName());
+ }
});
- });
- }
- catch (ExternalTestingException ex) {
- logger.error("unable to contact testing endpoint {}", ep.getId(), ex);
- }
- }
-
- private Optional<TestTreeNode> findNamedChild(TestTreeNode root, String name) {
- if (root.getChildren() == null) {
- return Optional.empty();
- }
- return root.getChildren().stream().filter(n->n.getName().equals(name)).findFirst();
- }
-
- /**
- * Find the place in the tree to add the test case.
- * @param root root of the tree.
- * @param endpointName name of the endpoint to assign to the test case.
- * @param scenarioName scenario to add this case to
- * @param testSuiteName suite in the scenario to add this case to
- * @param tc test case to add.
- */
- private void addTestCaseToTree(TestTreeNode root, String endpointName, String scenarioName, String testSuiteName, VtpTestCase tc) {
- // return quickly.
- if (tc == null) {
- return;
- }
- findNamedChild(root, scenarioName)
- .ifPresent(scenarioNode -> findNamedChild(scenarioNode, testSuiteName)
- .ifPresent(suiteNode -> {
- massageTestCaseForUI(tc, endpointName, scenarioName);
- if (suiteNode.getTests() == null) {
+ });
+ } catch (ExternalTestingException ex) {
+ logger.error("unable to contact testing endpoint {}", ep.getId(), ex);
+ }
+ }
+
+ private Optional<TestTreeNode> findNamedChild(TestTreeNode root, String name) {
+ if (root.getChildren() == null) {
+ return Optional.empty();
+ }
+ return root.getChildren().stream().filter(n -> n.getName().equals(name)).findFirst();
+ }
+
+ /**
+ * Find the place in the tree to add the test case.
+ *
+ * @param root root of the tree.
+ * @param endpointName name of the endpoint to assign to the test case.
+ * @param scenarioName scenario to add this case to
+ * @param testSuiteName suite in the scenario to add this case to
+ * @param tc test case to add.
+ */
+ private void addTestCaseToTree(TestTreeNode root, String endpointName, String scenarioName, String testSuiteName,
+ VtpTestCase tc) {
+ // return quickly.
+ if (tc == null) {
+ return;
+ }
+ findNamedChild(root, scenarioName)
+ .ifPresent(scenarioNode -> findNamedChild(scenarioNode, testSuiteName).ifPresent(suiteNode -> {
+ massageTestCaseForUI(tc, endpointName, scenarioName);
+ if (suiteNode.getTests() == null) {
suiteNode.setTests(new ArrayList<>());
- }
- suiteNode.getTests().add(tc);
- }));
- }
-
- private void massageTestCaseForUI(VtpTestCase testcase, String endpoint, String scenario) {
- testcase.setEndpoint(endpoint);
- // VTP workaround.
- if (testcase.getScenario() == null) {
- testcase.setScenario(scenario);
- }
- }
-
- /**
- * Add the test suite to the tree at the appropriate place if it does not already exist in the tree.
- * @param root root of the tree.
- * @param scenario scenario under which this suite should be placed
- * @param suite test suite to add.
- */
- private void addSuiteToTree(final TestTreeNode root, final VtpNameDescriptionPair scenario, final VtpNameDescriptionPair suite) {
- findNamedChild(root, scenario.getName()).ifPresent(parent -> {
- if (parent.getChildren() == null) {
- parent.setChildren(new ArrayList<>());
- }
- if (parent.getChildren().stream().noneMatch(n -> StringUtils.equals(n.getName(), suite.getName()))) {
- parent.getChildren().add(new TestTreeNode(suite.getName(), suite.getDescription()));
- }
- });
- }
-
- /**
- * Add the scenario to the tree if it does not already exist.
- * @param root root of the tree.
- * @param s scenario to add.
- */
- private void addScenarioToTree(TestTreeNode root, VtpNameDescriptionPair s) {
- logger.debug("addScenario {} to {} with {}", s.getName(), root.getName(), root.getChildren());
- if (root.getChildren() == null) {
- root.setChildren(new ArrayList<>());
- }
- if (root.getChildren().stream().noneMatch(n->StringUtils.equals(n.getName(),s.getName()))) {
- logger.debug("createScenario {} in {}", s.getName(), root.getName());
- root.getChildren().add(new TestTreeNode(s.getName(), s.getDescription()));
- }
- }
-
- /**
- * Get the list of endpoints defined to the testing manager.
- * @return list of endpoints or empty list if the manager is not configured.
- */
- public List<RemoteTestingEndpointDefinition> getEndpoints() {
- if (endpoints != null) {
- return endpoints.stream()
- .filter(RemoteTestingEndpointDefinition::isEnabled)
- .collect(Collectors.toList());
- }
- else {
- return new ArrayList<>();
- }
- }
-
- /**
- * Code shared by getScenarios and getTestSuites.
- */
- private List<VtpNameDescriptionPair> returnNameDescriptionPairFromUrl(String url) {
- ParameterizedTypeReference<List<VtpNameDescriptionPair>> t = new ParameterizedTypeReference<List<VtpNameDescriptionPair>>() {};
- List<VtpNameDescriptionPair> rv = proxyGetRequestToExternalTestingSite(url, t);
- if (rv == null) {
- rv = new ArrayList<>();
- }
- return rv;
- }
-
- /**
- * Get the list of scenarios at a given endpoint.
- */
- public List<VtpNameDescriptionPair> getScenarios(final String endpoint) {
- String url = buildEndpointUrl(VTP_SCENARIOS_URI, endpoint, ArrayUtils.EMPTY_STRING_ARRAY);
- return returnNameDescriptionPairFromUrl(url);
- }
-
- /**
- * Get the list of test suites for an endpoint for the given scenario.
- */
- public List<VtpNameDescriptionPair> getTestSuites(final String endpoint, final String scenario) {
- String url = buildEndpointUrl(VTP_TESTSUITE_URI, endpoint, new String[] {scenario});
- return returnNameDescriptionPairFromUrl(url);
- }
-
- /**
- * Get the list of test cases under a scenario. This is the VTP API. It would
- * seem better to get the list of cases under a test suite but that is not supported.
- */
- @Override
- public List<VtpTestCase> getTestCases(String endpoint, String scenario) {
- String url = buildEndpointUrl(VTP_TESTCASES_URI, endpoint, new String[] {scenario});
- ParameterizedTypeReference<List<VtpTestCase>> t = new ParameterizedTypeReference<List<VtpTestCase>>() {};
- List<VtpTestCase> rv = proxyGetRequestToExternalTestingSite(url, t);
- if (rv == null) {
- rv = new ArrayList<>();
- }
- return rv;
- }
-
- /**
- * Get a test case definition.
- */
- @Override
- public VtpTestCase getTestCase(String endpoint, String scenario, String testSuite, String testCaseName) {
- String url = buildEndpointUrl(VTP_TESTCASE_URI, endpoint, new String[] {scenario, testSuite, testCaseName});
- ParameterizedTypeReference<VtpTestCase> t = new ParameterizedTypeReference<VtpTestCase>() {};
- return proxyGetRequestToExternalTestingSite(url, t);
- }
-
- /**
- * Return the results of a previous test execution.
- * @param endpoint endpoint to query
- * @param executionId execution to query.
- * @return execution response from testing endpoint.
- */
- @Override
- public VtpTestExecutionResponse getExecution(String endpoint,String executionId) {
- String url = buildEndpointUrl(VTP_EXECUTION_URI, endpoint, new String[] {executionId});
- ParameterizedTypeReference<VtpTestExecutionResponse> t = new ParameterizedTypeReference<VtpTestExecutionResponse>() {};
- return proxyGetRequestToExternalTestingSite(url, t);
- }
-
- /**
- * Execute a set of tests at a given endpoint.
- * @param endpointName name of the endpoint
- * @param testsToRun set of tests to run
- * @return list of execution responses.
- */
- private List<VtpTestExecutionResponse> execute(final String endpointName, final List<VtpTestExecutionRequest> testsToRun, String requestId) {
- if (endpoints == null) {
- throw new ExternalTestingException(INVALIDATE_STATE_ERROR_CODE, 500, NO_ACCESS_CONFIGURATION_DEFINED);
- }
-
- RemoteTestingEndpointDefinition endpoint = endpoints.stream()
- .filter(e -> StringUtils.equals(endpointName, e.getId()))
- .findFirst()
- .orElseThrow(() -> new ExternalTestingException(NO_SUCH_ENDPOINT_ERROR_CODE, 400, "No endpoint named " + endpointName + " is defined"));
-
- // if the endpoint requires an API key, specify it in the headers.
- HttpHeaders headers = new HttpHeaders();
- if (endpoint.getApiKey() != null) {
- headers.add("X-API-Key", endpoint.getApiKey());
- }
- headers.setContentType(MediaType.MULTIPART_FORM_DATA);
-
- // build the body.
- MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
-
- for(VtpTestExecutionRequest test: testsToRun) {
- if ((test.getParameters() != null) &&
- (test.getParameters().containsKey(SDC_CSAR) || test.getParameters().containsKey(SDC_HEAT))) {
- attachArchiveContent(test, body);
- }
- }
-
- try {
- // remove the endpoint from the test request since that is a FE/BE attribute
- testsToRun.forEach(t -> t.setEndpoint(null));
-
- body.add("executions", new ObjectMapper().writeValueAsString(testsToRun));
- }
- catch (IOException ex) {
- logger.error("exception converting tests to string", ex);
- VtpTestExecutionResponse err = new VtpTestExecutionResponse();
- err.setHttpStatus(500);
- err.setCode(TESTING_HTTP_ERROR_CODE);
- err.setMessage("Execution failed due to " + ex.getMessage());
- return Collections.singletonList(err);
- }
-
- // form and send request.
- HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
- String url = buildEndpointUrl(VTP_EXECUTIONS_URI, endpointName, ArrayUtils.EMPTY_STRING_ARRAY);
- UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
- if (requestId != null) {
- builder = builder.queryParam("requestId", requestId);
- }
- ParameterizedTypeReference<List<VtpTestExecutionResponse>> t = new ParameterizedTypeReference<List<VtpTestExecutionResponse>>() {};
- try {
- return proxyRequestToExternalTestingSite(builder.toUriString(), requestEntity, t);
- }
- catch (ExternalTestingException ex) {
- logger.error("exception caught invoking endpoint {}", endpointName, ex);
- VtpTestExecutionResponse err = new VtpTestExecutionResponse();
- err.setHttpStatus(ex.getHttpStatus());
- err.setCode(TESTING_HTTP_ERROR_CODE);
- err.setMessage(ex.getMessageCode() + ": " + ex.getDetail());
- return Collections.singletonList(err);
- }
- }
-
-
- /**
- * Execute tests splitting them across endpoints and collecting the results.
- * @param testsToRun list of tests to be executed.
- * @return collection of result objects.
- */
- @Override
- public List<VtpTestExecutionResponse> execute(final List<VtpTestExecutionRequest> testsToRun, String requestId) {
- if (endpoints == null) {
- throw new ExternalTestingException(INVALIDATE_STATE_ERROR_CODE, 500, NO_ACCESS_CONFIGURATION_DEFINED);
- }
-
- // partition the requests by endpoint.
- Map<String, List<VtpTestExecutionRequest>> partitions =
- testsToRun.stream().collect(Collectors.groupingBy(VtpTestExecutionRequest::getEndpoint));
-
- // process each group and collect the results.
- return partitions.entrySet().stream()
- .flatMap(e -> execute(e.getKey(), e.getValue(), requestId).stream())
- .collect(Collectors.toList());
- }
-
- /**
- * Return URL with endpoint url as prefix.
- * @param format format string.
- * @param endpointName endpoint to address
- * @param args args for format.
- * @return qualified url.
- */
- private String buildEndpointUrl(String format, String endpointName, String[] args) {
- if (endpoints != null) {
- RemoteTestingEndpointDefinition ep = endpoints.stream()
- .filter(e -> e.isEnabled() && e.getId().equals(endpointName))
- .findFirst()
- .orElseThrow(() -> new ExternalTestingException(NO_SUCH_ENDPOINT_ERROR_CODE, 500, "No endpoint named " + endpointName + " is defined")
- );
-
- Object[] newArgs = ArrayUtils.add(args, 0, ep.getUrl());
- return String.format(format, newArgs);
- }
- throw new ExternalTestingException(INVALIDATE_STATE_ERROR_CODE, 500, NO_ACCESS_CONFIGURATION_DEFINED);
- }
-
- /**
- * Proxy a get request to a testing endpoint.
- * @param url URL to invoke.
- * @param responseType type of response expected.
- * @param <T> type of response expected
- * @return instance of <T> parsed from the JSON response from endpoint.
- */
- private <T> T proxyGetRequestToExternalTestingSite(String url, ParameterizedTypeReference<T> responseType) {
- return proxyRequestToExternalTestingSite(url, null, responseType);
- }
-
- /**
- * Make the actual HTTP post (using Spring RestTemplate) to an endpoint.
- * @param url URL to the endpoint
- * @param request optional request body to send
- * @param responseType expected type
- * @param <T> extended type
- * @return instance of expected type
- */
- private <R,T> T proxyRequestToExternalTestingSite(String url, HttpEntity<R> request, ParameterizedTypeReference<T> responseType) {
- if (request != null) {
- logger.debug("POST request to {} with {} for {}", url, request, responseType.getType().getTypeName());
- }
- else {
- logger.debug("GET request to {} for {}", url, responseType.getType().getTypeName());
- }
- SimpleClientHttpRequestFactory rf =
- (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
- if (rf != null) {
- rf.setReadTimeout(10000);
- rf.setConnectTimeout(10000);
- }
- ResponseEntity<T> re;
- try {
- if (request != null) {
- re = restTemplate.exchange(url, HttpMethod.POST, request, responseType);
- } else {
- re = restTemplate.exchange(url, HttpMethod.GET, null, responseType);
- }
- }
- catch (HttpStatusCodeException ex) {
- // make my own exception out of this.
- logger.warn("Unexpected HTTP Status from endpoint {}", ex.getRawStatusCode());
- if ((ex.getResponseHeaders().getContentType() != null) &&
- ((ex.getResponseHeaders().getContentType().isCompatibleWith(MediaType.APPLICATION_JSON)) ||
- (ex.getResponseHeaders().getContentType().isCompatibleWith(MediaType.parseMediaType("application/problem+json"))))) {
- String s = ex.getResponseBodyAsString();
- logger.warn("endpoint body content is {}", s);
- try {
- JsonObject o = new GsonBuilder().create().fromJson(s, JsonObject.class);
- throw buildTestingException(ex.getRawStatusCode(), o);
- }
- catch (JsonParseException e) {
- logger.warn("unexpected JSON response", e);
- throw new ExternalTestingException(ENDPOINT_ERROR_CODE, ex.getStatusCode().value(), ex.getResponseBodyAsString(), ex);
- }
- }
- else {
- throw new ExternalTestingException(ENDPOINT_ERROR_CODE, ex.getStatusCode().value(), ex.getResponseBodyAsString(), ex);
- }
- }
- catch (ResourceAccessException ex) {
- throw new ExternalTestingException(ENDPOINT_ERROR_CODE, 500, ex.getMessage(), ex);
- }
- catch (Exception ex) {
- throw new ExternalTestingException(ENDPOINT_ERROR_CODE, 500, "Generic Exception " + ex.getMessage(), ex);
+ }
+ suiteNode.getTests().add(tc);
+ }));
}
- if (re != null) {
- logger.debug("http status of {} from external testing entity {}", re.getStatusCodeValue(), url);
- return re.getBody();
+
+ private void massageTestCaseForUI(VtpTestCase testcase, String endpoint, String scenario) {
+ testcase.setEndpoint(endpoint);
+ // VTP workaround.
+ if (testcase.getScenario() == null) {
+ testcase.setScenario(scenario);
+ }
}
- else {
- logger.error("null response from endpoint");
- return null;
- }
- }
-
- /**
- * Errors from the endpoint could conform to the expected ETSI body or not.
- * Here we try to handle various response body elements.
- * @param statusCode http status code in response.
- * @param o JSON object parsed from the http response body
- * @return Testing error body that should be returned to the caller
- */
- private ExternalTestingException buildTestingException(int statusCode, JsonObject o) {
- String code = null;
- String message = null;
-
- if (o.has(CODE)) {
- code = o.get(CODE).getAsString();
- }
- else if (o.has(ERROR)) {
- code = o.get(ERROR).getAsString();
- }
- else {
- if (o.has(HTTP_STATUS)) {
- code = o.get(HTTP_STATUS).getAsJsonPrimitive().getAsString();
- }
- }
- if (o.has(MESSAGE)) {
- if (!o.get(MESSAGE).isJsonNull()) {
- message = o.get(MESSAGE).getAsString();
- }
- }
- else if (o.has(DETAIL)) {
- message = o.get(DETAIL).getAsString();
- }
- if (o.has(PATH)) {
- if (message == null) {
- message = o.get(PATH).getAsString();
- }
- else {
- message = message + " " + o.get(PATH).getAsString();
- }
- }
- return new ExternalTestingException(code, statusCode, message);
- }
-
- void attachArchiveContent(VtpTestExecutionRequest test, MultiValueMap<String, Object> body) {
- Map<String, String> params = test.getParameters();
- String vspId = params.get(VSP_ID);
- String version = params.get(VSP_VERSION);
-
- try {
- extractMetadata(test, body, vspId, version);
- } catch (IOException ex) {
- logger.error("metadata extraction failed", ex);
- }
- }
-
- /**
- * Extract the metadata from the VSP CSAR file.
- *
- * @param requestItem item to add metadata to for processing
- * @param vspId VSP identifier
- * @param version VSP version
- */
- private void extractMetadata(VtpTestExecutionRequest requestItem, MultiValueMap<String, Object> body, String vspId, String version) throws IOException {
-
- Version ver = new Version(version);
- logger.debug("attempt to retrieve archive for VSP {} version {}", vspId, ver.getId());
-
- Optional<Pair<String, byte[]>> ozip = candidateManager.get(vspId, ver);
- if (!ozip.isPresent()) {
- ozip = vendorSoftwareProductManager.get(vspId, ver);
- }
-
- if (!ozip.isPresent()) {
- List<Version> versions = versioningManager.list(vspId);
- String knownVersions = versions
- .stream()
- .map(v -> String.format("%d.%d: %s (%s)", v.getMajor(), v.getMinor(), v.getStatus(), v.getId()))
- .collect(Collectors.joining("\n"));
-
- String detail = String.format("Archive processing failed. Unable to find archive for VSP ID %s and Version %s. Known versions are:\n%s",
- vspId, version, knownVersions);
-
- throw new ExternalTestingException(SDC_RESOLVER_ERR, 500, detail);
- }
-
- // safe here to do get.
- Pair<String, byte[]> zip = ozip.get();
- processArchive(requestItem, body, zip.getRight());
- }
-
- private void processArchive(final VtpTestExecutionRequest test, final MultiValueMap<String, Object> body, final byte[] zip) {
-
- // We need to make one pass through the zip input stream. Pull out files that match our expectations into a temporary
- // map that we can process over. These are not huge files so we shouldn't need to worry about memory.
- final Map<String, byte[]> contentWeCareAbout = extractRelevantContent(zip);
-
- // VTP does not support concurrent executions of the same test with the same associated file name.
- // It writes files to /tmp and if we were to send two requests with the same file, the results are unpredictable.
- String key = UUID.randomUUID().toString();
- key = key.substring(0, key.indexOf('-'));
-
- // if there's a MANIFEST.json file, we're dealing with a heat archive.
- // otherwise, we will treat it as a CSAR.
- if (contentWeCareAbout.containsKey(MANIFEST_JSON)) {
- byte[] data = processHeatArchive(contentWeCareAbout);
- if (data != null) {
- body.add("file", new NamedByteArrayResource(data, key + ".heat.zip"));
- test.getParameters().put(SDC_HEAT, FILE_URL_PREFIX + key + ".heat.zip");
- }
- }
- else {
- byte[] data = processCsarArchive(contentWeCareAbout);
- if ((data != null) && (data.length != 0)) {
- body.add("file", new NamedByteArrayResource(data, key + ".csar.zip"));
- test.getParameters().put(SDC_CSAR, FILE_URL_PREFIX + key + ".csar.zip");
- }
- }
- }
-
- /**
- * Process the archive as a heat archive. Load the MANIFEST.json file and pull out the referenced
- * heat and environment files.
- * @param content relevant content from the heat archive.
- * @return byte array of client to send to endpoint.
- */
- private byte[] processHeatArchive(Map<String,byte[]> content) {
- byte[] manifestBytes = content.get(MANIFEST_JSON);
- ManifestContent manifest = JsonUtil.json2Object(new String(manifestBytes), ManifestContent.class);
-
- try(ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
- try(ZipOutputStream zipOutput = new ZipOutputStream(baos)) {
- for (FileData item : manifest.getData()) {
- processManifestItem(item, zipOutput, content);
- }
-
- return baos.toByteArray();
- }
- } catch (IOException ex) {
- logger.error("IO Exception parsing zip", ex);
- throw new ExternalTestingException(SDC_RESOLVER_ERR, 500, ex.getMessage());
- }
- }
-
- private void processManifestItem(FileData item, ZipOutputStream zipOutput, Map<String,byte[]> contentMap) throws IOException {
- if ((item.getType() == FileData.Type.HEAT) || (item.getType() == FileData.Type.HEAT_ENV)) {
- byte[] content = contentMap.get(item.getFile());
- if (content == null) {
- logger.warn("manifest included {} but not in content extracted", item.getFile());
- }
- else {
- ZipEntry zi = new ZipEntry(item.getFile());
- zipOutput.putNextEntry(zi);
- zipOutput.write(content);
- zipOutput.closeEntry();
- }
-
- // recurse
- if (item.getData() != null) {
- for(FileData subitem: item.getData()) {
- processManifestItem(subitem, zipOutput, contentMap);
- }
- }
- }
- }
-
- /**
- * Process the archive as a CSAR file.
- * @param content relevant extracted content.
- * @return byte array of client to send to endpoint.
- */
- private byte[] processCsarArchive(Map<String,byte[]> content) {
- // look for the entry point file.
- String fileToGet = null;
- if (content.containsKey(TOSCA_META)) {
- fileToGet = getEntryDefinitionPointer(content.get(TOSCA_META)).orElse(null);
- }
- if (fileToGet == null) {
- // fall back to the SDC standard location. not required to be here though...
- fileToGet = MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME;
- }
-
- if (!content.containsKey(fileToGet)) {
- // user story says to let the call to the VTP go through without the attachment.
- return ArrayUtils.EMPTY_BYTE_ARRAY;
- }
-
- try(ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
- try(ZipOutputStream zipOutput = new ZipOutputStream(baos)) {
- processCsarArchiveEntry(fileToGet, zipOutput, content);
- return baos.toByteArray();
- }
- } catch (IOException ex) {
- logger.error("IO Exception parsing zip", ex);
- throw new ExternalTestingException(SDC_RESOLVER_ERR, 500, ex.getMessage());
- }
- }
-
- /**
- * Add the named file (if it exists) from the contentMap into the output zip to send to VTP.
- * If the file is a yaml file, peek inside and also add any imported files.
- * @param filename name to apply to the zip entry being created
- * @param zipOutput zip output stream to append new entry to
- * @param contentMap map of content we are processing
- * @throws IOException thrown in the event of processing errors.
- */
- private void processCsarArchiveEntry(String filename, ZipOutputStream zipOutput, Map<String, byte[]> contentMap) throws IOException {
- byte[] content = contentMap.get(filename);
- if (content == null) {
- // no such content, just return.
- return;
- }
-
- ZipEntry zi = new ZipEntry(filename);
- zipOutput.putNextEntry(zi);
- zipOutput.write(content);
- zipOutput.closeEntry();
-
- // if this is a yaml file, we should peek inside for includes.
- if (filename.endsWith(".yaml") || filename.endsWith(".yml")) {
- Yaml yaml = new Yaml();
- @SuppressWarnings("unchecked")
- Map<String, Object> yamlContent = (Map<String, Object>) yaml.load(new ByteArrayInputStream(content));
- if (!yamlContent.containsKey("imports")) {
- return;
- }
-
- Object imports = yamlContent.get("imports");
- if (imports instanceof ArrayList) {
- @SuppressWarnings("unchecked") ArrayList<String> lst = (ArrayList<String>) imports;
- for (String imp : lst) {
- File f = new File(filename);
- File impFile = new File(f.getParent(), imp);
- logger.debug("look for import {} with {}", imp, impFile.getPath());
- processCsarArchiveEntry(impFile.getPath(), zipOutput, contentMap);
- }
- }
- else {
- logger.warn("archive {} contains imports but it is not an array. Unexpected, this is.", filename);
- }
- }
- }
-
- private Optional<String> getEntryDefinitionPointer(byte[] toscaMetadataFile) {
- try {
- Properties p = new Properties();
- p.load(new ByteArrayInputStream(toscaMetadataFile));
- return Optional.ofNullable(p.getProperty(TOSCA_META_ENTRY_DEFINITIONS));
- }
- catch (IOException ex) {
- logger.error("failed to process tosca metadata file {}", TOSCA_META, ex);
- }
-
- return Optional.empty();
- }
-
- /**
- * We don't want to send the entire CSAR file to VTP. Here we take a pass through the
- * archive (heat/csar) file and pull out the files we care about.
- * @param zip csar/heat zip to iterate over
- * @return relevant content from the archive file as a map.
- */
- private Map<String, byte[]> extractRelevantContent(final byte[] zip) {
- final Map<String, byte[]> zipFileAndByteMap;
- try {
- zipFileAndByteMap = ZipUtils.readZip(zip, false);
- } catch (final ZipException ex) {
- logger.error("An error occurred while processing archive", ex);
- throw new ExternalTestingException(SDC_RESOLVER_ERR, 500, ex.getMessage(), ex);
- }
-
- return zipFileAndByteMap.entrySet().stream()
- .filter(stringEntry -> hasRelevantExtension(stringEntry.getKey()))
- .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
- }
-
- /**
- * Checks if the file matches with a expected extension.
- *
- * @param filePath the file path
- * @return {@code true} if the file extension matches with {@link #relevantArchiveFileExtensionSet}, {@code false}
- * otherwise
- */
- private boolean hasRelevantExtension(final String filePath) {
- final String entryExtension = FilenameUtils.getExtension(filePath);
- return StringUtils.isNotEmpty(entryExtension) && (relevantArchiveFileExtensionSet.contains(entryExtension));
- }
-
- /**
- * We need to name the byte array we add to the multipart request sent to the VTP.
- */
- @EqualsAndHashCode(callSuper = false)
- protected class NamedByteArrayResource extends ByteArrayResource {
- private String filename;
- NamedByteArrayResource(byte[] bytes, String filename) {
- super(bytes, filename);
- this.filename = filename;
+
+ /**
+ * Add the test suite to the tree at the appropriate place if it does not already exist in the tree.
+ *
+ * @param root root of the tree.
+ * @param scenario scenario under which this suite should be placed
+ * @param suite test suite to add.
+ */
+ private void addSuiteToTree(final TestTreeNode root, final VtpNameDescriptionPair scenario,
+ final VtpNameDescriptionPair suite) {
+ findNamedChild(root, scenario.getName()).ifPresent(parent -> {
+ if (parent.getChildren() == null) {
+ parent.setChildren(new ArrayList<>());
+ }
+ if (parent.getChildren().stream().noneMatch(n -> StringUtils.equals(n.getName(), suite.getName()))) {
+ parent.getChildren().add(new TestTreeNode(suite.getName(), suite.getDescription()));
+ }
+ });
+ }
+
+ /**
+ * Add the scenario to the tree if it does not already exist.
+ *
+ * @param root root of the tree.
+ * @param s scenario to add.
+ */
+ private void addScenarioToTree(TestTreeNode root, VtpNameDescriptionPair s) {
+ logger.debug("addScenario {} to {} with {}", s.getName(), root.getName(), root.getChildren());
+ if (root.getChildren() == null) {
+ root.setChildren(new ArrayList<>());
+ }
+ if (root.getChildren().stream().noneMatch(n -> StringUtils.equals(n.getName(), s.getName()))) {
+ logger.debug("createScenario {} in {}", s.getName(), root.getName());
+ root.getChildren().add(new TestTreeNode(s.getName(), s.getDescription()));
+ }
}
+
+ /**
+ * Get the list of endpoints defined to the testing manager.
+ *
+ * @return list of endpoints or empty list if the manager is not configured.
+ */
+ public List<RemoteTestingEndpointDefinition> getEndpoints() {
+ if (endpoints != null) {
+ return endpoints.stream().filter(RemoteTestingEndpointDefinition::isEnabled).collect(Collectors.toList());
+ } else {
+ return new ArrayList<>();
+ }
+ }
+
+ /**
+ * Code shared by getScenarios and getTestSuites.
+ */
+ private List<VtpNameDescriptionPair> returnNameDescriptionPairFromUrl(String url) {
+ ParameterizedTypeReference<List<VtpNameDescriptionPair>> t =
+ new ParameterizedTypeReference<List<VtpNameDescriptionPair>>() { };
+ List<VtpNameDescriptionPair> rv = proxyGetRequestToExternalTestingSite(url, t);
+ if (rv == null) {
+ rv = new ArrayList<>();
+ }
+ return rv;
+ }
+
+ /**
+ * Get the list of scenarios at a given endpoint.
+ */
+ public List<VtpNameDescriptionPair> getScenarios(final String endpoint) {
+ String url = buildEndpointUrl(VTP_SCENARIOS_URI, endpoint, ArrayUtils.EMPTY_STRING_ARRAY);
+ return returnNameDescriptionPairFromUrl(url);
+ }
+
+ /**
+ * Get the list of test suites for an endpoint for the given scenario.
+ */
+ public List<VtpNameDescriptionPair> getTestSuites(final String endpoint, final String scenario) {
+ String url = buildEndpointUrl(VTP_TESTSUITE_URI, endpoint, new String[] {scenario});
+ return returnNameDescriptionPairFromUrl(url);
+ }
+
+ /**
+ * Get the list of test cases under a scenario. This is the VTP API. It would
+ * seem better to get the list of cases under a test suite but that is not supported.
+ */
@Override
- public String getFilename() {
- return this.filename;
+ public List<VtpTestCase> getTestCases(String endpoint, String scenario) {
+ String url = buildEndpointUrl(VTP_TESTCASES_URI, endpoint, new String[] {scenario});
+ ParameterizedTypeReference<List<VtpTestCase>> t = new ParameterizedTypeReference<List<VtpTestCase>>() { };
+ List<VtpTestCase> rv = proxyGetRequestToExternalTestingSite(url, t);
+ if (rv == null) {
+ rv = new ArrayList<>();
+ }
+ return rv;
+ }
+
+ /**
+ * Get a test case definition.
+ */
+ @Override
+ public VtpTestCase getTestCase(String endpoint, String scenario, String testSuite, String testCaseName) {
+ String url = buildEndpointUrl(VTP_TESTCASE_URI, endpoint, new String[] {scenario, testSuite, testCaseName});
+ ParameterizedTypeReference<VtpTestCase> t = new ParameterizedTypeReference<VtpTestCase>() { };
+ return proxyGetRequestToExternalTestingSite(url, t);
+ }
+
+ /**
+ * Return the results of a previous test execution.
+ *
+ * @param endpoint endpoint to query
+ * @param executionId execution to query.
+ * @return execution response from testing endpoint.
+ */
+ @Override
+ public VtpTestExecutionResponse getExecution(String endpoint, String executionId) {
+ String url = buildEndpointUrl(VTP_EXECUTION_URI, endpoint, new String[] {executionId});
+ ParameterizedTypeReference<VtpTestExecutionResponse> t =
+ new ParameterizedTypeReference<VtpTestExecutionResponse>() { };
+ return proxyGetRequestToExternalTestingSite(url, t);
+ }
+
+
+ /**
+ * Execute tests splitting them across endpoints and collecting the results.
+ *
+ * @param testsToRun list of tests to be executed.
+ * @return collection of result objects.
+ */
+
+ @Override
+ public List<VtpTestExecutionResponse> execute(final List<VtpTestExecutionRequest> testsToRun, String vspId,
+ String vspVersionId, String requestId, Map<String, byte[]> fileMap) {
+ if (endpoints == null) {
+ throw new ExternalTestingException(INVALIDATE_STATE_ERROR_CODE, 500, NO_ACCESS_CONFIGURATION_DEFINED);
+ }
+
+ // partition the requests by endpoint.
+ Map<String, List<VtpTestExecutionRequest>> partitions =
+ testsToRun.stream().collect(Collectors.groupingBy(VtpTestExecutionRequest::getEndpoint));
+
+ // process each group and collect the results.
+ return partitions.entrySet().stream().flatMap(
+ e -> doExecute(e.getKey(), e.getValue(), vspId, vspVersionId, requestId, fileMap).stream())
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Get the list of Execution by requestId.
+ */
+ @Override
+ public List<VtpTestExecutionOutput> getExecutionIds(String endpoint, String requestId) {
+ String url = buildEndpointUrl(VTP_EXECUTION_ID_URL, endpoint, new String[] {requestId});
+ ParameterizedTypeReference<List<VtpTestExecutionOutput>> t =
+ new ParameterizedTypeReference<List<VtpTestExecutionOutput>>() { };
+ List<VtpTestExecutionOutput> rv = proxyGetRequestToExternalTestingSite(url, t);
+ if (rv == null) {
+ rv = new ArrayList<>();
+ }
+ return rv;
+ }
+
+ /**
+ * Execute a set of tests at a given endpoint.
+ *
+ * @param endpointName name of the endpoint
+ * @param testsToRun set of tests to run
+ * @return list of execution responses.
+ */
+ private List<VtpTestExecutionResponse> doExecute(final String endpointName,
+ final List<VtpTestExecutionRequest> testsToRun, String vspId, String vspVersionId, String requestId,
+ Map<String, byte[]> fileMap) {
+ if (endpoints == null) {
+ throw new ExternalTestingException(INVALIDATE_STATE_ERROR_CODE, 500, NO_ACCESS_CONFIGURATION_DEFINED);
+ }
+
+ RemoteTestingEndpointDefinition endpoint =
+ endpoints.stream().filter(e -> StringUtils.equals(endpointName, e.getId())).findFirst().orElseThrow(
+ () -> new ExternalTestingException(NO_SUCH_ENDPOINT_ERROR_CODE, 400,
+ "No endpoint named " + endpointName + " is defined"));
+
+ // if the endpoint requires an API key, specify it in the headers.
+ HttpHeaders headers = new HttpHeaders();
+ if (endpoint.getApiKey() != null) {
+ headers.add("X-API-Key", endpoint.getApiKey());
+ }
+ headers.setContentType(MediaType.MULTIPART_FORM_DATA);
+
+ // build the body.
+ MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
+
+
+ for (VtpTestExecutionRequest test : testsToRun) {
+ // it will true only noramal validation not for certification
+ if ((test.getParameters() != null) && (test.getParameters().containsKey(VSP_CSAR) || test.getParameters()
+ .containsKey(
+ VSP_HEAT))) {
+ attachArchiveContent(test, body, vspId, vspVersionId);
+ }
+
+ }
+
+ attachFileContentInTest(body, fileMap);
+ try {
+ // remove the endpoint from the test request since that is a FE/BE attribute
+ testsToRun.forEach(t -> t.setEndpoint(null));
+ String strExecution = new ObjectMapper().writeValueAsString(testsToRun);
+ body.add("executions", strExecution);
+
+ } catch (IOException ex) {
+ logger.error("exception converting tests to string", ex);
+ VtpTestExecutionResponse err = new VtpTestExecutionResponse();
+ err.setHttpStatus(500);
+ err.setCode(TESTING_HTTP_ERROR_CODE);
+ err.setMessage("Execution failed due to " + ex.getMessage());
+ return Collections.singletonList(err);
+ }
+
+ // form and send request.
+ HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
+ String url = buildEndpointUrl(VTP_EXECUTIONS_URI, endpointName, ArrayUtils.EMPTY_STRING_ARRAY);
+ UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
+ if (requestId != null) {
+ builder = builder.queryParam("requestId", requestId);
+ }
+ ParameterizedTypeReference<List<VtpTestExecutionResponse>> t =
+ new ParameterizedTypeReference<List<VtpTestExecutionResponse>>() { };
+ try {
+ return proxyRequestToExternalTestingSite(builder.toUriString(), requestEntity, t);
+ } catch (ExternalTestingException ex) {
+ logger.info("exception caught invoking endpoint {}", endpointName, ex);
+ if (ex.getHttpStatus() == 504) {
+ return Collections.singletonList(new VtpTestExecutionResponse());
+ }
+ VtpTestExecutionResponse err = new VtpTestExecutionResponse();
+ err.setHttpStatus(ex.getHttpStatus());
+ err.setCode(TESTING_HTTP_ERROR_CODE);
+ err.setMessage(ex.getMessageCode() + ": " + ex.getDetail());
+ return Collections.singletonList(err);
+ }
+ }
+
+ /**
+ * Return URL with endpoint url as prefix.
+ *
+ * @param format format string.
+ * @param endpointName endpoint to address
+ * @param args args for format.
+ * @return qualified url.
+ */
+ private String buildEndpointUrl(String format, String endpointName, String[] args) {
+ if (endpoints != null) {
+ RemoteTestingEndpointDefinition ep =
+ endpoints.stream().filter(e -> e.isEnabled() && e.getId().equals(endpointName)).findFirst()
+ .orElseThrow(() -> new ExternalTestingException(NO_SUCH_ENDPOINT_ERROR_CODE, 500,
+ "No endpoint named " + endpointName + " is defined"));
+
+ Object[] newArgs = ArrayUtils.add(args, 0, ep.getUrl());
+ return String.format(format, newArgs);
+ }
+ throw new ExternalTestingException(INVALIDATE_STATE_ERROR_CODE, 500, NO_ACCESS_CONFIGURATION_DEFINED);
+ }
+
+ /**
+ * Proxy a get request to a testing endpoint.
+ *
+ * @param url URL to invoke.
+ * @param responseType type of response expected.
+ * @param <T> type of response expected
+ * @return instance of <T> parsed from the JSON response from endpoint.
+ */
+ private <T> T proxyGetRequestToExternalTestingSite(String url, ParameterizedTypeReference<T> responseType) {
+ return proxyRequestToExternalTestingSite(url, null, responseType);
+ }
+
+ /**
+ * Make the actual HTTP post (using Spring RestTemplate) to an endpoint.
+ *
+ * @param url URL to the endpoint
+ * @param request optional request body to send
+ * @param responseType expected type
+ * @param <T> extended type
+ * @return instance of expected type
+ */
+ private <R, T> T proxyRequestToExternalTestingSite(String url, HttpEntity<R> request,
+ ParameterizedTypeReference<T> responseType) {
+ if (request != null) {
+ logger.debug("POST request to {} with {} for {}", url, request, responseType.getType().getTypeName());
+ } else {
+ logger.debug("GET request to {} for {}", url, responseType.getType().getTypeName());
+ }
+ SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
+ if (rf != null) {
+ rf.setReadTimeout(10000);
+ rf.setConnectTimeout(10000);
+ }
+ ResponseEntity<T> re;
+ try {
+ if (request != null) {
+ re = restTemplate.exchange(url, HttpMethod.POST, request, responseType);
+ } else {
+ re = restTemplate.exchange(url, HttpMethod.GET, null, responseType);
+ }
+ } catch (HttpStatusCodeException ex) {
+ // make my own exception out of this.
+ logger.warn("Unexpected HTTP Status from endpoint {}", ex.getRawStatusCode());
+ if ((ex.getResponseHeaders().getContentType() != null) && (
+ (ex.getResponseHeaders().getContentType().isCompatibleWith(MediaType.APPLICATION_JSON))
+ || (ex.getResponseHeaders().getContentType()
+ .isCompatibleWith(MediaType.parseMediaType("application/problem+json"))))) {
+ String s = ex.getResponseBodyAsString();
+ logger.warn("endpoint body content is {}", s);
+ try {
+ JsonObject o = new GsonBuilder().create().fromJson(s, JsonObject.class);
+ throw buildTestingException(ex.getRawStatusCode(), o);
+ } catch (JsonParseException e) {
+ logger.warn("unexpected JSON response", e);
+ throw new ExternalTestingException(ENDPOINT_ERROR_CODE, ex.getStatusCode().value(),
+ ex.getResponseBodyAsString(), ex);
+ }
+ } else {
+ throw new ExternalTestingException(ENDPOINT_ERROR_CODE, ex.getStatusCode().value(),
+ ex.getResponseBodyAsString(), ex);
+ }
+ } catch (ResourceAccessException ex) {
+ throw new ExternalTestingException(ENDPOINT_ERROR_CODE, 500, ex.getMessage(), ex);
+ } catch (Exception ex) {
+ throw new ExternalTestingException(ENDPOINT_ERROR_CODE, 500, "Generic Exception " + ex.getMessage(), ex);
+ }
+ if (re != null) {
+ logger.debug("http status of {} from external testing entity {}", re.getStatusCodeValue(), url);
+ return re.getBody();
+ } else {
+ logger.error("null response from endpoint");
+ return null;
+ }
+ }
+
+ private void attachFileContentInTest(MultiValueMap<String, Object> body, Map<String, byte[]> fileMap) {
+ if (fileMap != null) {
+ fileMap.forEach((name, inputStream) -> body.add("file", new NamedByteArrayResource(inputStream, name)));
+ }
+
+ }
+
+ /**
+ * Errors from the endpoint could conform to the expected ETSI body or not.
+ * Here we try to handle various response body elements.
+ *
+ * @param statusCode http status code in response.
+ * @param o JSON object parsed from the http response body
+ * @return Testing error body that should be returned to the caller
+ */
+ private ExternalTestingException buildTestingException(int statusCode, JsonObject o) {
+ String code = null;
+ String message = null;
+
+ if (o.has(CODE)) {
+ code = o.get(CODE).getAsString();
+ } else if (o.has(ERROR)) {
+ code = o.get(ERROR).getAsString();
+ } else {
+ if (o.has(HTTP_STATUS)) {
+ code = o.get(HTTP_STATUS).getAsJsonPrimitive().getAsString();
+ }
+ }
+ if (o.has(MESSAGE)) {
+ if (!o.get(MESSAGE).isJsonNull()) {
+ message = o.get(MESSAGE).getAsString();
+ }
+ } else if (o.has(DETAIL)) {
+ message = o.get(DETAIL).getAsString();
+ }
+ if (o.has(PATH)) {
+ if (message == null) {
+ message = o.get(PATH).getAsString();
+ } else {
+ message = message + " " + o.get(PATH).getAsString();
+ }
+ }
+ return new ExternalTestingException(code, statusCode, message);
+ }
+
+ void attachArchiveContent(VtpTestExecutionRequest test, MultiValueMap<String, Object> body, String vspId,
+ String vspVersionId) {
+ try {
+ extractMetadata(test, body, vspId, vspVersionId);
+ } catch (IOException ex) {
+ logger.error("metadata extraction failed", ex);
+ }
+ }
+
+ /**
+ * Extract the metadata from the VSP CSAR file.
+ *
+ * @param requestItem item to add metadata to for processing
+ * @param vspId VSP identifier
+ * @param version VSP version
+ */
+ private void extractMetadata(VtpTestExecutionRequest requestItem, MultiValueMap<String, Object> body, String vspId,
+ String version) throws IOException {
+
+ Version ver = new Version(version);
+ logger.debug("attempt to retrieve archive for VSP {} version {}", vspId, ver.getId());
+
+ Optional<Pair<String, byte[]>> ozip = candidateManager.get(vspId, ver);
+ if (!ozip.isPresent()) {
+ ozip = vendorSoftwareProductManager.get(vspId, ver);
+ }
+
+ if (!ozip.isPresent()) {
+ List<Version> versions = versioningManager.list(vspId);
+ String knownVersions = versions.stream()
+ .map(v -> String.format("%d.%d: %s (%s)", v.getMajor(), v.getMinor(),
+ v.getStatus(), v.getId())).collect(Collectors.joining("\n"));
+
+ String detail = String.format(
+ "Archive processing failed. Unable to find archive for VSP ID %s and Version %s. Known versions are:\n%s",
+ vspId, version, knownVersions);
+
+ throw new ExternalTestingException(SDC_RESOLVER_ERR, 500, detail);
+ }
+
+ // safe here to do get.
+ Pair<String, byte[]> zip = ozip.get();
+ processArchive(requestItem, body, zip.getRight());
+ }
+
+ private void processArchive(final VtpTestExecutionRequest test, final MultiValueMap<String, Object> body,
+ final byte[] zip) {
+
+
+ // VTP does not support concurrent executions of the same test with the same associated file name.
+ // It writes files to /tmp and if we were to send two requests with the same file, the results
+ // are unpredictable.
+ String key = UUID.randomUUID().toString();
+ key = key.substring(0, key.indexOf('-'));
+
+ if (test.getParameters().containsKey(VSP_HEAT)) {
+ body.add("file", new NamedByteArrayResource(zip, key + ".heat.zip"));
+ test.getParameters().put(VSP_HEAT, FILE_URL_PREFIX + key + ".heat.zip");
+ } else {
+ body.add("file", new NamedByteArrayResource(zip, key + ".csar"));
+ test.getParameters().put(VSP_CSAR, FILE_URL_PREFIX + key + ".csar");
+ }
+ }
+
+ /**
+ * We need to name the byte array we add to the multipart request sent to the VTP.
+ */
+ @EqualsAndHashCode(callSuper = false)
+ protected class NamedByteArrayResource extends ByteArrayResource {
+
+ private String filename;
+
+ NamedByteArrayResource(byte[] bytes, String filename) {
+ super(bytes, filename);
+ this.filename = filename;
+ }
+
+ @Override
+ public String getFilename() {
+ return this.filename;
+ }
}
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImplTest.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImplTest.java
index 4f9631250d..66acd16227 100644
--- a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImplTest.java
+++ b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImplTest.java
@@ -98,20 +98,22 @@ public class ExternalTestingManagerImplTest {
// read mock data for API calls.
File scenarioFile = new File("src/test/data/scenarios.json");
- TypeReference<List<VtpNameDescriptionPair>> typ = new TypeReference<List<VtpNameDescriptionPair>>(){};
+ TypeReference<List<VtpNameDescriptionPair>> typ = new TypeReference<List<VtpNameDescriptionPair>>() { };
List<VtpNameDescriptionPair> scenarios = mapper.readValue(scenarioFile, typ);
File testSuitesFile = new File("src/test/data/testsuites.json");
- List<VtpNameDescriptionPair> testSuites = mapper.readValue(testSuitesFile, new TypeReference<List<VtpNameDescriptionPair>>(){});
+ List<VtpNameDescriptionPair> testSuites =
+ mapper.readValue(testSuitesFile, new TypeReference<List<VtpNameDescriptionPair>>() { });
File testCasesFile = new File("src/test/data/testcases.json");
- List<VtpTestCase> testCases = mapper.readValue(testCasesFile, new TypeReference<List<VtpTestCase>>(){});
+ List<VtpTestCase> testCases = mapper.readValue(testCasesFile, new TypeReference<List<VtpTestCase>>() { });
File testCaseFile = new File("src/test/data/testcase-sriov.json");
VtpTestCase testCase = mapper.readValue(testCaseFile, VtpTestCase.class);
File runResultFile = new File("src/test/data/runresult.json");
- List<VtpTestExecutionResponse> runResults = mapper.readValue(runResultFile, new TypeReference<List<VtpTestExecutionResponse>>(){});
+ List<VtpTestExecutionResponse> runResults =
+ mapper.readValue(runResultFile, new TypeReference<List<VtpTestExecutionResponse>>() { });
File priorExecutionFile = new File("src/test/data/priorexecution.json");
VtpTestExecutionResponse priorExecution = mapper.readValue(priorExecutionFile, VtpTestExecutionResponse.class);
@@ -119,9 +121,11 @@ public class ExternalTestingManagerImplTest {
// create an error response as well
String notFound = FileUtils.readFileToString(new File("src/test/data/notfound.json"), "UTF-8");
- ParameterizedTypeReference<List<VtpNameDescriptionPair>> listOfPairType = new ParameterizedTypeReference<List<VtpNameDescriptionPair>>() {};
- ParameterizedTypeReference<List<VtpTestCase>> listOfCasesType = new ParameterizedTypeReference<List<VtpTestCase>>() {};
- ParameterizedTypeReference<VtpTestCase> caseType = new ParameterizedTypeReference<VtpTestCase>() {};
+ ParameterizedTypeReference<List<VtpNameDescriptionPair>> listOfPairType =
+ new ParameterizedTypeReference<List<VtpNameDescriptionPair>>() { };
+ ParameterizedTypeReference<List<VtpTestCase>> listOfCasesType =
+ new ParameterizedTypeReference<List<VtpTestCase>>() { };
+ ParameterizedTypeReference<VtpTestCase> caseType = new ParameterizedTypeReference<VtpTestCase>() { };
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/problem+json"));
@@ -132,127 +136,75 @@ public class ExternalTestingManagerImplTest {
List<Version> versionList = new ArrayList<>();
versionList.add(new Version(UUID.randomUUID().toString()));
- Mockito
- .when(candidateManager.get(
- ArgumentMatchers.contains("csar"),
- ArgumentMatchers.any()))
- .thenReturn(Optional.of(Pair.of("Processed.zip", csar)));
+ Mockito.when(candidateManager.get(ArgumentMatchers.contains("csar"), ArgumentMatchers.any()))
+ .thenReturn(Optional.of(Pair.of("Processed.zip", csar)));
- Mockito
- .when(candidateManager.get(
- ArgumentMatchers.contains("heat"),
- ArgumentMatchers.any()))
- .thenReturn(Optional.empty());
+ Mockito.when(candidateManager.get(ArgumentMatchers.contains("heat"), ArgumentMatchers.any()))
+ .thenReturn(Optional.empty());
- Mockito
- .when(vendorSoftwareProductManager.get(
- ArgumentMatchers.contains("heat"),
- ArgumentMatchers.any()))
- .thenReturn(Optional.of(Pair.of("Processed.zip", heat)));
+ Mockito.when(vendorSoftwareProductManager.get(ArgumentMatchers.contains("heat"), ArgumentMatchers.any()))
+ .thenReturn(Optional.of(Pair.of("Processed.zip", heat)));
+ Mockito.when(vendorSoftwareProductManager.get(ArgumentMatchers.contains("missing"), ArgumentMatchers.any()))
+ .thenReturn(Optional.empty());
- Mockito
- .when(vendorSoftwareProductManager.get(
- ArgumentMatchers.contains("missing"),
- ArgumentMatchers.any()))
- .thenReturn(Optional.empty());
+ Mockito.when(candidateManager.get(ArgumentMatchers.contains("missing"), ArgumentMatchers.any()))
+ .thenReturn(Optional.empty());
- Mockito
- .when(candidateManager.get(
- ArgumentMatchers.contains("missing"),
- ArgumentMatchers.any()))
- .thenReturn(Optional.empty());
+ Mockito.when(versioningManager.list(ArgumentMatchers.contains("missing"))).thenReturn(versionList);
- Mockito
- .when(versioningManager.list(
- ArgumentMatchers.contains("missing")))
- .thenReturn(versionList);
+ Mockito.when(restTemplate.exchange(ArgumentMatchers.endsWith("/scenarios"), ArgumentMatchers.eq(HttpMethod.GET),
+ ArgumentMatchers.any(), ArgumentMatchers.eq(listOfPairType)))
+ .thenReturn(new ResponseEntity(scenarios, HttpStatus.OK));
+ Mockito.when(restTemplate
+ .exchange(ArgumentMatchers.endsWith("/testsuites"), ArgumentMatchers.eq(HttpMethod.GET),
+ ArgumentMatchers.any(), ArgumentMatchers.eq(listOfPairType)))
+ .thenReturn(new ResponseEntity(testSuites, HttpStatus.OK));
+ Mockito.when(restTemplate.exchange(ArgumentMatchers.endsWith("/testcases"), ArgumentMatchers.eq(HttpMethod.GET),
+ ArgumentMatchers.any(), ArgumentMatchers.eq(listOfCasesType)))
+ .thenReturn(new ResponseEntity(testCases, HttpStatus.OK));
+ Mockito.when(restTemplate.exchange(ArgumentMatchers.endsWith("/sriov"), ArgumentMatchers.eq(HttpMethod.GET),
+ ArgumentMatchers.any(), ArgumentMatchers.eq(caseType)))
+ .thenReturn(new ResponseEntity(testCase, HttpStatus.OK));
- Mockito
- .when(restTemplate.exchange(
- ArgumentMatchers.endsWith("/scenarios"),
- ArgumentMatchers.eq(HttpMethod.GET),
- ArgumentMatchers.any(),
- ArgumentMatchers.eq(listOfPairType)))
- .thenReturn(new ResponseEntity(scenarios, HttpStatus.OK));
+ // POST for execution
- Mockito
- .when(restTemplate.exchange(
- ArgumentMatchers.endsWith("/testsuites"),
- ArgumentMatchers.eq(HttpMethod.GET),
- ArgumentMatchers.any(),
- ArgumentMatchers.eq(listOfPairType)))
- .thenReturn(new ResponseEntity(testSuites, HttpStatus.OK));
+ Mockito.when(restTemplate
+ .exchange(ArgumentMatchers.contains("executions"), ArgumentMatchers.eq(HttpMethod.POST),
+ ArgumentMatchers.any(), ArgumentMatchers
+ .eq(new ParameterizedTypeReference<List<VtpTestExecutionResponse>>() { })))
+ .thenReturn(new ResponseEntity(runResults, HttpStatus.OK));
- Mockito
- .when(restTemplate.exchange(
- ArgumentMatchers.endsWith("/testcases"),
- ArgumentMatchers.eq(HttpMethod.GET),
- ArgumentMatchers.any(),
- ArgumentMatchers.eq(listOfCasesType)))
- .thenReturn(new ResponseEntity(testCases, HttpStatus.OK));
- Mockito
- .when(restTemplate.exchange(
- ArgumentMatchers.endsWith("/sriov"),
- ArgumentMatchers.eq(HttpMethod.GET),
- ArgumentMatchers.any(),
- ArgumentMatchers.eq(caseType)))
- .thenReturn(new ResponseEntity(testCase, HttpStatus.OK));
+ Mockito.when(restTemplate
+ .exchange(ArgumentMatchers.contains("/executions/"), ArgumentMatchers.eq(HttpMethod.GET),
+ ArgumentMatchers.any(), ArgumentMatchers
+ .eq(new ParameterizedTypeReference<VtpTestExecutionResponse>() { })))
+ .thenReturn(new ResponseEntity(priorExecution, HttpStatus.OK));
- // POST for execution
+ HttpStatusCodeException missingException =
+ new HttpServerErrorException(HttpStatus.NOT_FOUND, "Not Found", headers, notFound.getBytes(),
+ Charset.defaultCharset());
+ Mockito.when(restTemplate.exchange(ArgumentMatchers.endsWith("/missing"), ArgumentMatchers.eq(HttpMethod.GET),
+ ArgumentMatchers.any(), ArgumentMatchers.eq(caseType))).thenThrow(missingException);
+
- Mockito
- .when(restTemplate.exchange(
- ArgumentMatchers.contains("executions"),
- ArgumentMatchers.eq(HttpMethod.POST),
- ArgumentMatchers.any(),
- ArgumentMatchers.eq(new ParameterizedTypeReference<List<VtpTestExecutionResponse>>() {})))
- .thenReturn(new ResponseEntity(runResults, HttpStatus.OK));
-
-
- Mockito
- .when(restTemplate.exchange(
- ArgumentMatchers.contains("/executions/"),
- ArgumentMatchers.eq(HttpMethod.GET),
- ArgumentMatchers.any(),
- ArgumentMatchers.eq(new ParameterizedTypeReference<VtpTestExecutionResponse>() {})))
- .thenReturn(new ResponseEntity(priorExecution, HttpStatus.OK));
-
-
- HttpStatusCodeException missingException = new HttpServerErrorException(HttpStatus.NOT_FOUND, "Not Found", headers, notFound.getBytes(), Charset.defaultCharset());
- Mockito
- .when(restTemplate.exchange(
- ArgumentMatchers.endsWith("/missing"),
- ArgumentMatchers.eq(HttpMethod.GET),
- ArgumentMatchers.any(),
- ArgumentMatchers.eq(caseType)))
- .thenThrow(missingException);
-
-
- Mockito
- .when(restTemplate.exchange(
- ArgumentMatchers.endsWith("/sitedown"),
- ArgumentMatchers.eq(HttpMethod.GET),
- ArgumentMatchers.any(),
- ArgumentMatchers.eq(caseType)))
- .thenThrow(new ResourceAccessException("Remote site is down"));
-
- Mockito
- .when(restTemplate.exchange(
- ArgumentMatchers.endsWith("throwexception"),
- ArgumentMatchers.eq(HttpMethod.POST),
- ArgumentMatchers.any(),
- ArgumentMatchers.eq(new ParameterizedTypeReference<List<VtpTestExecutionResponse>>() {})))
- .thenThrow(missingException);
+ Mockito.when(restTemplate.exchange(ArgumentMatchers.endsWith("/sitedown"), ArgumentMatchers.eq(HttpMethod.GET),
+ ArgumentMatchers.any(), ArgumentMatchers.eq(caseType)))
+ .thenThrow(new ResourceAccessException("Remote site is down"));
+
+ Mockito.when(restTemplate.exchange(ArgumentMatchers.endsWith("throwexception"),
+ ArgumentMatchers.eq(HttpMethod.POST), ArgumentMatchers.any(),
+ ArgumentMatchers.eq(new ParameterizedTypeReference<List<VtpTestExecutionResponse>>() { })))
+ .thenThrow(missingException);
return mgr;
@@ -283,8 +235,7 @@ public class ExternalTestingManagerImplTest {
try {
m.getTestCase("repository", "scen", "suite", "sitedown");
Assert.fail("not expected to retrieve sitedown test case");
- }
- catch (ExternalTestingException e) {
+ } catch (ExternalTestingException e) {
// expecting this exception.
Assert.assertNotNull(e.getDetail());
Assert.assertNotEquals(0, e.getHttpStatus());
@@ -295,8 +246,7 @@ public class ExternalTestingManagerImplTest {
try {
m.getTestCase("repository", "scen", "suite", "missing");
Assert.fail("not expected to retrieve missing test case");
- }
- catch (ExternalTestingException e) {
+ } catch (ExternalTestingException e) {
// expecting this exception.
Assert.assertNotNull(e.getDetail());
Assert.assertNotEquals(0, e.getHttpStatus());
@@ -315,7 +265,7 @@ public class ExternalTestingManagerImplTest {
requests.add(req);
// send a request with the endpoint defined.
- List<VtpTestExecutionResponse> responses = m.execute(requests, "rid");
+ List<VtpTestExecutionResponse> responses = m.execute(requests, "vspId", "vspVersionId", "rid", null);
Assert.assertEquals(1, responses.size());
// send a request for a prior execution.
@@ -344,9 +294,8 @@ public class ExternalTestingManagerImplTest {
// send a request with the endpoint defined.
try {
- m.execute(requests, "throwexception");
- }
- catch (ExternalTestingException e) {
+ m.execute(requests, "vspId", "vspVersionId", "throwexception", null);
+ } catch (ExternalTestingException e) {
// expected.
}
}
@@ -365,7 +314,7 @@ public class ExternalTestingManagerImplTest {
lst.add(new RemoteTestingEndpointDefinition());
lst.get(0).setEnabled(true);
m.setEndpoints(lst);
- Assert.assertEquals(1,m.getEndpoints().size());
+ Assert.assertEquals(1, m.getEndpoints().size());
}
@Test
@@ -377,8 +326,7 @@ public class ExternalTestingManagerImplTest {
try {
m.getEndpoints();
Assert.assertTrue("should have exception here", true);
- }
- catch (ExternalTestingException e) {
+ } catch (ExternalTestingException e) {
// eat the exception cause this is what should happen.
}
}
@@ -399,7 +347,8 @@ public class ExternalTestingManagerImplTest {
r3.setScenario("scenario3");
r3.setEndpoint("repository");
- List<VtpTestExecutionResponse> results = m.execute(Arrays.asList(r1,r2,r3), "rid");
+ List<VtpTestExecutionResponse> results =
+ m.execute(Arrays.asList(r1, r2, r3), "vspId", "vspVersionId", "rid", null);
Assert.assertEquals("three in two out merged", 2, results.size());
}
@@ -410,30 +359,20 @@ public class ExternalTestingManagerImplTest {
r1.setScenario("scenario1");
r1.setEndpoint("vtp");
r1.setParameters(new HashMap<>());
- r1.getParameters().put(ExternalTestingManagerImpl.VSP_ID, "something.with.csar.content");
- r1.getParameters().put(ExternalTestingManagerImpl.VSP_VERSION, UUID.randomUUID().toString());
-
- LinkedMultiValueMap<String,Object> body = new LinkedMultiValueMap<>();
- m.attachArchiveContent(r1, body);
+ LinkedMultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
+ m.attachArchiveContent(r1, body, "something.with.csar.content", UUID.randomUUID().toString());
r1.setParameters(new HashMap<>());
- r1.getParameters().put(ExternalTestingManagerImpl.VSP_ID, "something.with.heat.content");
- r1.getParameters().put(ExternalTestingManagerImpl.VSP_VERSION, UUID.randomUUID().toString());
-
- LinkedMultiValueMap<String,Object> body2 = new LinkedMultiValueMap<>();
- m.attachArchiveContent(r1, body2);
+ LinkedMultiValueMap<String, Object> body2 = new LinkedMultiValueMap<>();
+ m.attachArchiveContent(r1, body2, "something.with.heat.content", UUID.randomUUID().toString());
// now, let's handle a missing archive.
r1.setParameters(new HashMap<>());
- r1.getParameters().put(ExternalTestingManagerImpl.VSP_ID, "something.with.missing.content");
- r1.getParameters().put(ExternalTestingManagerImpl.VSP_VERSION, UUID.randomUUID().toString());
-
- LinkedMultiValueMap<String,Object> body3 = new LinkedMultiValueMap<>();
+ LinkedMultiValueMap<String, Object> body3 = new LinkedMultiValueMap<>();
try {
- m.attachArchiveContent(r1, body3);
+ m.attachArchiveContent(r1, body3, "something.with.missing.content", UUID.randomUUID().toString());
Assert.fail("expected to receive an exception here");
- }
- catch (ExternalTestingException ex) {
+ } catch (ExternalTestingException ex) {
Assert.assertEquals(500, ex.getHttpStatus());
}