summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pom.xml10
-rw-r--r--src/main/java/org/onap/aai/modelloader/entity/ArtifactHandler.java1
-rw-r--r--src/main/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandler.java1
-rw-r--r--src/main/java/org/onap/aai/modelloader/service/ModelController.java47
-rw-r--r--src/main/java/org/onap/aai/modelloader/service/ModelLoaderInterface.java43
-rw-r--r--src/test/java/org/onap/aai/modelloader/service/TestModelController.java20
-rw-r--r--src/test/java/org/onap/aai/modelloader/service/TestModelLoaderServiceWithSdc.java8
7 files changed, 33 insertions, 97 deletions
diff --git a/pom.xml b/pom.xml
index 633350a..45f8a77 100644
--- a/pom.xml
+++ b/pom.xml
@@ -273,16 +273,6 @@
</exclusions>
</dependency>
<dependency>
- <groupId>org.glassfish.jersey.core</groupId>
- <artifactId>jersey-common</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.onap.aai</groupId>
- <artifactId>rest-client</artifactId>
- <version>${aai.rest.client.version}</version>
- </dependency>
- <dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
diff --git a/src/main/java/org/onap/aai/modelloader/entity/ArtifactHandler.java b/src/main/java/org/onap/aai/modelloader/entity/ArtifactHandler.java
index c630822..50abdd0 100644
--- a/src/main/java/org/onap/aai/modelloader/entity/ArtifactHandler.java
+++ b/src/main/java/org/onap/aai/modelloader/entity/ArtifactHandler.java
@@ -23,7 +23,6 @@ package org.onap.aai.modelloader.entity;
import java.util.List;
import org.onap.aai.modelloader.config.ModelLoaderConfig;
import org.onap.aai.modelloader.restclient.AaiRestClient;
-import org.springframework.web.client.RestTemplate;
public abstract class ArtifactHandler {
diff --git a/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandler.java b/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandler.java
index 95d3426..9b05024 100644
--- a/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandler.java
+++ b/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandler.java
@@ -46,7 +46,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
-import org.springframework.web.client.RestTemplate;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
diff --git a/src/main/java/org/onap/aai/modelloader/service/ModelController.java b/src/main/java/org/onap/aai/modelloader/service/ModelController.java
index 41a7c86..343fdca 100644
--- a/src/main/java/org/onap/aai/modelloader/service/ModelController.java
+++ b/src/main/java/org/onap/aai/modelloader/service/ModelController.java
@@ -25,9 +25,6 @@ import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.modelloader.config.ModelLoaderConfig;
@@ -37,7 +34,11 @@ import org.onap.aai.modelloader.notification.NotificationDataImpl;
import org.onap.aai.modelloader.notification.NotificationPublisher;
import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.api.notification.IArtifactInfo;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -47,7 +48,7 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("/services/model-loader/v1/model-service")
-public class ModelController implements ModelLoaderInterface {
+public class ModelController {
private static final Logger logger = LoggerFactory.getInstance().getLogger(ModelController.class);
@@ -63,47 +64,37 @@ public class ModelController implements ModelLoaderInterface {
this.artifactDownloadManager = artifactDownloadManager;
}
- /**
- * (non-Javadoc)
- *
- * @see org.onap.aai.modelloader.service.ModelLoaderInterface#loadModel(java.lang.String)
- */
- @Override
- public Response loadModel(@PathVariable String modelid) {
- return Response.ok("{\"model_loaded\":\"" + modelid + "\"}").build();
+ @GetMapping(value = "/loadModel/{modelid}", produces = "application/json")
+ public ResponseEntity<String> loadModel(@PathVariable String modelid) {
+ return ResponseEntity.ok("{\"model_loaded\":\"" + modelid + "\"}");
}
- /**
- * (non-Javadoc)
- *
- * @see org.onap.aai.modelloader.service.ModelLoaderInterface#saveModel(java.lang.String, java.lang.String)
- */
- @Override
- public Response saveModel(@PathVariable String modelid, @PathVariable String modelname) {
- return Response.ok("{\"model_saved\":\"" + modelid + "-" + modelname + "\"}").build();
+ @PutMapping(value = "/saveModel/{modelid}/{modelname}", produces = "application/json")
+ public ResponseEntity<String> saveModel(@PathVariable String modelid, @PathVariable String modelname) {
+ return ResponseEntity.ok("{\"model_saved\":\"" + modelid + "-" + modelname + "\"}");
}
- @Override
- public Response ingestModel(@PathVariable String modelName, @PathVariable String modelVersion,
+ @PostMapping(value = "/ingestModel/{modelName}/{modelVersion}", produces = "application/json")
+ public ResponseEntity<String> ingestModel(@PathVariable String modelName, @PathVariable String modelVersion,
@RequestBody String payload) throws IOException {
- Response response;
+ ResponseEntity<String> response;
if (config.getIngestSimulatorEnabled()) {
response = processTestArtifact(modelName, modelVersion, payload);
} else {
logger.debug("Simulation interface disabled");
- response = Response.serverError().build();
+ response = ResponseEntity.internalServerError().build();
}
return response;
}
- private Response processTestArtifact(String modelName, String modelVersion, String payload) {
+ private ResponseEntity<String> processTestArtifact(String modelName, String modelVersion, String payload) {
IArtifactInfo artifactInfo = new ArtifactInfoImpl();
((ArtifactInfoImpl) artifactInfo).setArtifactName(modelName);
((ArtifactInfoImpl) artifactInfo).setArtifactVersion(modelVersion);
- Response response;
+ ResponseEntity<String> response;
try {
logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Received test artifact " + modelName + " " + modelVersion);
@@ -125,7 +116,7 @@ public class ModelController implements ModelLoaderInterface {
boolean success =
artifactDeploymentManager.deploy(notificationData, modelArtifacts, catalogArtifacts);
logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Deployment success was " + success);
- response = success ? Response.ok().build() : Response.serverError().build();
+ response = success ? ResponseEntity.ok().build() : ResponseEntity.internalServerError().build();
} catch (Exception e) {
String responseMessage = e.getMessage();
logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Exception handled: " + responseMessage);
@@ -135,7 +126,7 @@ public class ModelController implements ModelLoaderInterface {
} else {
responseMessage += "\nSDC publishing is enabled but has been bypassed";
}
- response = Response.serverError().entity(responseMessage).type(MediaType.APPLICATION_XML).build();
+ response = ResponseEntity.internalServerError().body(responseMessage);
}
return response;
}
diff --git a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderInterface.java b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderInterface.java
deleted file mode 100644
index 4c7b182..0000000
--- a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderInterface.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 European Software Marketing Ltd.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.modelloader.service;
-
-import java.io.IOException;
-import javax.ws.rs.core.Response;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-public interface ModelLoaderInterface {
-
- @GetMapping(value = "/loadModel/{modelid}", produces = "application/json")
- @ResponseBody
- Response loadModel(String modelid);
-
- @PutMapping(value = "/saveModel/{modelid}/{modelname}", produces = "application/json")
- @ResponseBody
- Response saveModel(String modelid, String modelname);
-
- @PostMapping(value = "/ingestModel/{modelName}/{modelVersion}", produces = "application/json")
- @ResponseBody
- Response ingestModel(String modelid, String modelVersion, String payload) throws IOException;
-}
diff --git a/src/test/java/org/onap/aai/modelloader/service/TestModelController.java b/src/test/java/org/onap/aai/modelloader/service/TestModelController.java
index 970aa7a..6cfeb65 100644
--- a/src/test/java/org/onap/aai/modelloader/service/TestModelController.java
+++ b/src/test/java/org/onap/aai/modelloader/service/TestModelController.java
@@ -29,8 +29,6 @@ import java.io.IOException;
import java.util.Base64;
import java.util.Collections;
-import javax.ws.rs.core.Response;
-
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
@@ -47,6 +45,8 @@ import org.onap.aai.modelloader.util.ArtifactTestUtils;
import org.onap.sdc.api.IDistributionClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
/**
@@ -80,28 +80,28 @@ public class TestModelController {
@Test
public void testLoadModel() {
- Response response = modelController.loadModel("");
- assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
+ ResponseEntity<String> response = modelController.loadModel("");
+ assertThat(response.getStatusCode(), is(HttpStatus.OK));
}
@Test
public void testSaveModel() {
- Response response = modelController.saveModel("", "");
- assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
+ ResponseEntity<String> response = modelController.saveModel("", "");
+ assertThat(response.getStatusCode(), is(HttpStatus.OK));
}
@Test
public void testIngestModel() throws IOException {
byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
- Response response = modelController.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
- assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
+ ResponseEntity<String> response = modelController.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
+ assertThat(response.getStatusCode(), is(HttpStatus.OK));
}
@Test
public void testIngestModelMissingName() throws IOException {
byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
- Response response = modelController.ingestModel("", "", Base64.getEncoder().encodeToString(csarPayload));
- assertThat(response.getStatus(), is(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
+ ResponseEntity<String> response = modelController.ingestModel("", "", Base64.getEncoder().encodeToString(csarPayload));
+ assertThat(response.getStatusCode(), is(HttpStatus.INTERNAL_SERVER_ERROR));
}
}
diff --git a/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderServiceWithSdc.java b/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderServiceWithSdc.java
index 6dc1b3d..e9ab7c0 100644
--- a/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderServiceWithSdc.java
+++ b/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderServiceWithSdc.java
@@ -26,12 +26,12 @@ import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
import java.util.Base64;
-import javax.ws.rs.core.Response;
-
import org.junit.jupiter.api.Test;
import org.onap.aai.modelloader.util.ArtifactTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
/**
@@ -48,8 +48,8 @@ public class TestModelLoaderServiceWithSdc {
@Test
public void testIngestModel() throws IOException {
byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
- Response response = controller.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
- assertThat(response.getStatus(), is(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
+ ResponseEntity<String> response = controller.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
+ assertThat(response.getStatusCode(), is(HttpStatus.INTERNAL_SERVER_ERROR));
}