/*
- * Copyright (C) 2017 CTC, Inc. and others. All rights reserved.
+ * Copyright (C) 2021 CTC, Inc. and others. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.apache.commons.collections.MapUtils;
import org.onap.usecaseui.server.bean.HttpResponseResult;
-import org.onap.usecaseui.server.bean.csmf.SlicingOrder;
-import org.onap.usecaseui.server.bean.csmf.SlicingOrderDetail;
import org.onap.usecaseui.server.bean.intent.IntentInstance;
import org.onap.usecaseui.server.bean.intent.IntentModel;
import org.onap.usecaseui.server.bean.intent.IntentResponseBody;
-import org.onap.usecaseui.server.bean.nsmf.common.ServiceResult;
-import org.onap.usecaseui.server.controller.csmf.SlicingController;
import org.onap.usecaseui.server.service.csmf.SlicingService;
import org.onap.usecaseui.server.service.intent.IntentApiService;
import org.onap.usecaseui.server.service.intent.IntentInstanceService;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import retrofit2.Call;
-import retrofit2.Response;
@RestController
@org.springframework.context.annotation.Configuration
@RequestMapping("/uploadModel")
@ResponseBody
- public String uploadModel (@RequestParam("file") MultipartFile file) {
+ public String uploadModel (@RequestParam("file") MultipartFile file,@RequestParam("modelType")String modelType) {
String fileName = file.getOriginalFilename();
String filePath = UPLOADPATH + fileName ;
float sizeM = size/1024;
model.setSize(sizeM);
model.setActive(0);
+ model.setModelType(modelType);
+ Map<String,String> fileMap = new HashMap<>();
+ fileMap.put("file", filePath);
+ UploadFileUtil.formUpload("http://uui-nlp:33013/uploader", null, fileMap, null);
+
intentService.addModel(model);
logger.info("save model, " + model.toString());
File dest = new File(filePath);
if(dest.exists()){
dest.delete();
+ postDeleteFile(fileName);
logger.info("delete file OK: " + filePath);
- if (filePath.endsWith(".zip")) {
- String unzipPath = filePath.substring(0, filePath.length() - 1 - 4);
- File unZipFile = new File(unzipPath);
- if (unZipFile.exists()) {
- unZipFile.delete();
- }
- }
}{
logger.info("file not found: " + filePath);
}
return result;
}
+
+ private String postDeleteFile(String fileName) {
+
+ String url = "http://uui-nlp:33013/deleteFile/"+ fileName;
+ HashMap<String, String> headers = new HashMap<>();
+
+ HttpResponseResult result = HttpUtil.sendGetRequest(url,headers);
+ String respContent = result.getResultContent();
+
+ logger.info("NLP api respond: " + String.valueOf(result.getResultCode()));
+ logger.info(respContent);
+
+ return respContent;
+ }
+
@GetMapping(value = {"/activeModel"}, produces = "application/json")
public String activeModel(@RequestParam String modelId){
String result = "0";
IntentModel model = intentService.activeModel(modelId);
logger.info("active NLP model, model=" + model.getFilePath());
- String dirPath = intentService.activeModelFile(model);
- if (dirPath != null) {
- dirPath = dirPath.replace(UPLOADPATH, NLPLOADPATH);
- load(dirPath);
+ String fileName = intentService.activeModelFile(model);
+ if (fileName != null) {
+ load(NLPLOADPATH + fileName);
}
produces = "application/json; charset=utf-8")
public String predict(@RequestBody Object body) throws ParseException {
String text = (String)((Map)body).get("text");
- //System.out.println(text);
+ String modelType = (String)((Map)body).get("modelType");
+
+ String activeModelType = intentService.getActiveModelType();
+ if (modelType == null || !modelType.equals(activeModelType)) {
+ throw new RuntimeException("The active model file does not support parsing the current text");
+ }
String url = "http://uui-nlp.onap:33011/api/online/predict";
HashMap<String, String> headers = new HashMap<>();
produces = "application/json")
public JSONObject getInstanceId() {
int first = new Random(10).nextInt(8) + 1;
- System.out.println(first);
int hashCodeV = UUID.randomUUID().toString().hashCode();
if (hashCodeV < 0) {//有可能是负数
hashCodeV = -hashCodeV;
return result;
}
@IntentResponseBody
- @GetMapping(value = {"/getInstanceList/{currentPage}/{pageSize}"},
+ @ResponseBody
+ @PostMapping (value = {"/getInstanceList"},consumes = MediaType.APPLICATION_JSON_VALUE,
produces = "application/json")
- public Object getInstanceList(@PathVariable String currentPage, @PathVariable String pageSize) {
- return intentInstanceService.queryIntentInstance(null, Integer.parseInt(currentPage), Integer.parseInt(pageSize));
+ public Object getInstanceList(@RequestBody Object body) {
+ int currentPage = (int) ((Map)body).get("currentPage");
+ int pageSize = (int) ((Map)body).get("pageSize");
+ logger.error("getInstanceList --> currentPage:" + currentPage + ",pageSize:" + pageSize);
+ return intentInstanceService.queryIntentInstance(null, currentPage, pageSize);
}
@IntentResponseBody
@ResponseBody
}
@IntentResponseBody
- @DeleteMapping(value = {"/deleteIntentInstance"},
- produces = "application/json")
- public Object deleteIntentInstance(@RequestParam(value = "instanceId") String instanceId) {
+ @ResponseBody
+ @PostMapping(value = {"/deleteIntentInstance"}, consumes = MediaType.APPLICATION_JSON_VALUE,
+ produces = "application/json; charset=utf-8")
+ public Object deleteIntentInstance(@RequestBody Object body) {
+ String instanceId= (String) ((Map)body).get("instanceId");
intentInstanceService.deleteIntentInstance(instanceId);
return "ok";
}
@IntentResponseBody
- @PutMapping(value = {"/activeIntentInstance"},
- produces = "application/json")
- public Object activeIntentInstance(@RequestParam(value = "instanceId") String instanceId) {
+ @ResponseBody
+ @PostMapping(value = {"/activeIntentInstance"}, consumes = MediaType.APPLICATION_JSON_VALUE,
+ produces = "application/json; charset=utf-8")
+ public Object activeIntentInstance(@RequestBody Object body) {
+ String instanceId= (String) ((Map)body).get("instanceId");
intentInstanceService.activeIntentInstance(instanceId);
return "ok";
}
@IntentResponseBody
- @PutMapping(value = {"/invalidIntentInstance"},
- produces = "application/json")
- public Object invalidIntentInstance(@RequestParam(value = "instanceId") String instanceId) {
+ @ResponseBody
+ @PostMapping(value = {"/invalidIntentInstance"}, consumes = MediaType.APPLICATION_JSON_VALUE,
+ produces = "application/json; charset=utf-8")
+ public Object invalidIntentInstance(@RequestBody Object body) {
+ String instanceId= (String) ((Map)body).get("instanceId");
intentInstanceService.invalidIntentInstance(instanceId);
return "ok";
}
@IntentResponseBody
- @PutMapping(value = {"/queryInstancePerformanceData"},
- produces = "application/json")
- public Object queryInstancePerformanceData(@RequestParam(value = "instanceId") String instanceId) {
+ @ResponseBody
+ @PostMapping(value = {"/queryInstancePerformanceData"}, consumes = MediaType.APPLICATION_JSON_VALUE,
+ produces = "application/json; charset=utf-8")
+ public Object queryInstancePerformanceData(@RequestBody Object body) {
+ String instanceId= (String) ((Map)body).get("instanceId");
return intentInstanceService.queryInstancePerformanceData(instanceId);
}