</exclusion>
</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>
import java.util.List;\r
import org.onap.aai.modelloader.config.ModelLoaderConfig;\r
import org.onap.aai.modelloader.restclient.AaiRestClient;\r
-import org.springframework.web.client.RestTemplate;\r
\r
public abstract class ArtifactHandler {\r
\r
import org.springframework.http.MediaType;\r
import org.springframework.http.ResponseEntity;\r
import org.springframework.stereotype.Component;\r
-import org.springframework.web.client.RestTemplate;\r
import org.w3c.dom.Document;\r
import org.w3c.dom.Element;\r
import org.w3c.dom.Node;\r
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;
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;
*/
@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);
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);
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);
} 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;
}
+++ /dev/null
-/**
- * ============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;
-}
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;
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;
/**
@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));
}
}
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;
/**
@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));
}