X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Fservice%2FModelController.java;h=233f2ab9d2a47cbb30ef9dcce708af110227adf8;hb=HEAD;hp=41a7c867d506744bcf495f82b1d919c61f0136b1;hpb=e820afb80b830453f667280d94f6e86279ad4f2c;p=aai%2Fmodel-loader.git 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..233f2ab 100644 --- a/src/main/java/org/onap/aai/modelloader/service/ModelController.java +++ b/src/main/java/org/onap/aai/modelloader/service/ModelController.java @@ -25,19 +25,22 @@ 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; import org.onap.aai.modelloader.entity.Artifact; +import org.onap.aai.modelloader.entity.ArtifactType; import org.onap.aai.modelloader.notification.ArtifactDownloadManager; 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.HttpStatus; +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 +50,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 +66,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 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 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 ingestModel(@PathVariable String modelName, @PathVariable String modelVersion, @RequestBody String payload) throws IOException { - Response response; + ResponseEntity response; if (config.getIngestSimulatorEnabled()) { response = processTestArtifact(modelName, modelVersion, payload); } else { logger.debug("Simulation interface disabled"); - response = Response.serverError().build(); + response = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } return response; } - private Response processTestArtifact(String modelName, String modelVersion, String payload) { + private ResponseEntity processTestArtifact(String modelName, String modelVersion, String payload) { IArtifactInfo artifactInfo = new ArtifactInfoImpl(); ((ArtifactInfoImpl) artifactInfo).setArtifactName(modelName); ((ArtifactInfoImpl) artifactInfo).setArtifactVersion(modelVersion); - Response response; + ResponseEntity response; try { logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Received test artifact " + modelName + " " + modelVersion); @@ -111,11 +104,16 @@ public class ModelController implements ModelLoaderInterface { logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Generating XML models from test artifact"); + List artifacts = artifactDownloadManager.processToscaArtifacts(csarFile, artifactInfo, "test-transaction-id", modelVersion); List modelArtifacts = new ArrayList<>(); List catalogArtifacts = new ArrayList<>(); - - artifactDownloadManager.processToscaArtifacts(modelArtifacts, - catalogArtifacts, csarFile, artifactInfo, "test-transaction-id", modelVersion); + for(Artifact artifact : artifacts) { + if(artifact.getType().equals(ArtifactType.MODEL)) { + modelArtifacts.add(artifact); + } else { + catalogArtifacts.add(artifact); + } + } logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Loading xml models from test artifacts: " + modelArtifacts.size() + " model(s) and " + catalogArtifacts.size() + " catalog(s)"); @@ -123,9 +121,9 @@ public class ModelController implements ModelLoaderInterface { NotificationDataImpl notificationData = new NotificationDataImpl(); notificationData.setDistributionID("TestDistributionID"); boolean success = - artifactDeploymentManager.deploy(notificationData, modelArtifacts, catalogArtifacts); + artifactDeploymentManager.deploy(notificationData.getDistributionID(), 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.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } catch (Exception e) { String responseMessage = e.getMessage(); logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Exception handled: " + responseMessage); @@ -135,7 +133,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.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseMessage); } return response; }