public void TestUpdateModelpayload() { List <Property> _prop = new List <Property>(); List <ModelResponse> _model = new List <ModelResponse>(); TestCreateModelpayload(); _model = ModelPayload.Get(); _prop.Add(new Property { key = "width", value = "200px" }); ModelResponse updateRecord = new ModelResponse() { Id = "HelloModel", Name = "Hello.pmml", User = "", Created_on = DateTime.Now.ToString(), Edited_on = DateTime.Now.ToString(), Extension = ".png", MimeType = "application/image", Size = 111, Type = "IMAGE", Url = "http://localhost/uploads/data/Hello.png", FilePath = "", Loaded = false, Deployed = false, Properties = _prop }; Console.WriteLine(_model[0].Properties); Console.WriteLine(updateRecord.Properties); ModelResponse updated = ModelPayload.Update(updateRecord); Assert.NotEqual(_model[0].Properties, updateRecord.Properties); }
public static bool GetDeployedModel(string fileName, List <ModelResponse> modelsList) { bool status = true; fileName = $"{dirFullpath}{fileName}"; try { if (File.Exists(fileName)) { var jo = Newtonsoft.Json.JsonConvert.DeserializeObject <RootDeployedModel>(File.ReadAllText(fileName)); if (jo.deployedModels.ToList().Count() > 0) { foreach (var model in modelsList) { foreach (var item in jo.deployedModels) { if (model.Id == item.id) { model.Deployed = true; ModelPayload.Update(model); } } } } } } catch (Exception ex) { System.Console.WriteLine("Error while deleting data.. " + ex.StackTrace); return(status = false); } return(status); }
public async Task Execute(IJobExecutionContext context) { #region Variables JobDataMap dataMap = context.JobDetail.JobDataMap; string filePath = dataMap.GetString("filePath"); string zmodId = dataMap.GetString("zmodId"); string id = dataMap.GetString("id"); string onnxResponse = ""; #endregion Console.WriteLine($">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> {id} Model deploy started"); #region deploy model onnxResponse = await OnnxClient.DeployModelAsync(zmodId, filePath); #endregion ModelResponse record = ModelPayload.Get().Where(i => i.Id == id).FirstOrDefault(); // if (string.IsNullOrEmpty(onnxResponse) || onnxResponse.Contains("Fail@@")) { record.Deployed = false; record.ReasonFailed = onnxResponse.Replace("Fail@@", ""); ModelPayload.Update(record); } else { MleResponse mle = JsonSerializer.Deserialize <MleResponse>(onnxResponse); //add response to ModelResponse record.MleResponse = mle; record.Deployed = true; ModelPayload.Update(record); } await Task.FromResult(0); Console.WriteLine($">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> {id} Model deploy completed"); }
public async Task <IActionResult> PostZSUploadPmmlAsync(string id) { string response, modelName, convertedPath = string.Empty; JObject jsonResponse = new JObject(); bool isExists = false; if (responseData.Count > 0) { foreach (var record in responseData) { if (record.Id.ToString() == id) { try { /* TODO: Add code to call ZMK service to get compatible pmml*/ string zmkResponse = await zmeClient.PostConvertPmmlAsync(record.FilePath, record.FilePath.Replace(id, $"Converted_{id}")); if (!string.IsNullOrEmpty(zmkResponse) && !zmkResponse.Contains("Failed")) { JObject jo = JObject.Parse(zmkResponse); convertedPath = jo["filePath"].ToString(); } if (string.IsNullOrEmpty(convertedPath)) { return(BadRequest(new { message = "Model loading failed.", errorCode = 400, exception = ZMMConstants.ErrorFailed })); } string zsResponse = await zsClient.UploadPmml(convertedPath); //remove file after upload if (System.IO.File.Exists(convertedPath)) { System.IO.File.Delete(convertedPath); } if (zsResponse != "Fail" && zsResponse != "FileExists") { // modelName = JObject.Parse(zsResponse)["modelName"].ToString(); ModelResponse updateRecord = new ModelResponse() { Created_on = record.Created_on, Deployed = true, Edited_on = record.Edited_on, Extension = record.Extension, FilePath = record.FilePath, Id = record.Id, Loaded = record.Loaded, MimeType = record.MimeType, ModelName = modelName, Name = record.Name, Size = record.Size, Type = record.Type, Url = record.Url }; // ModelPayload.Update(updateRecord); responseData = ModelPayload.Get(); response = @"{ id: '" + record.Id + "', deployed: true}"; if (!string.IsNullOrEmpty(response)) { jsonResponse = JObject.Parse(response); } isExists = true; } else { return(BadRequest(new { message = "Model loading failed.", errorCode = 500, exception = "No response from server." })); } } catch (Exception ex) { Logger.LogCritical(ex, ex.StackTrace); return(BadRequest(new { message = "Model loading failed.", errorCode = 400, exception = ex.StackTrace })); } } } } if (!isExists) { return(NotFound(new { message = "Model loading failed.", errorCode = 404, exception = "No such model." })); } return(Json(jsonResponse)); }
public async Task <IActionResult> DeletePmmlFromZementisServer(string id) { string response = string.Empty; JObject jsonResponse = new JObject(); bool isExists = false; if (responseData.Count > 0) { foreach (var record in responseData) { if (record.Id.ToString() == id) { try { string zsResponse = await zsClient.DeletePmml(record.ModelName); if (zsResponse != "fail") { // ModelResponse updateRecord = new ModelResponse() { Created_on = record.Created_on, Deployed = false, Edited_on = record.Edited_on, Extension = record.Extension, FilePath = record.FilePath, Id = record.Id, Loaded = record.Loaded, MimeType = record.MimeType, Name = record.Name, Size = record.Size, Type = record.Type, Url = record.Url }; // ModelPayload.Update(updateRecord); responseData = ModelPayload.Get(); response = "{ id: '" + record.Id + "', deployed: false}"; if (!string.IsNullOrEmpty(response)) { jsonResponse = JObject.Parse(response); } isExists = true; } else { return(BadRequest(new { message = "Model loading failed.", errorCode = 500, exception = "No response from server." })); } } catch (Exception ex) { Logger.LogCritical(ex, ex.StackTrace); return(BadRequest(new { message = "Model loading failed.", errorCode = 400, exception = ex.Message })); } } } } if (!isExists) { return(NotFound(new { message = "Model loading failed.", errorCode = 404, exception = "No such model." })); } return(Json(jsonResponse)); }
public async Task <IActionResult> LoadModelAsync(string id) { string response = string.Empty; JObject jsonResponse = new JObject(); bool isExists = false; if (responseData.Count > 0) { foreach (var record in responseData) { if (record.Id.ToString() == id) { try { string pyResponse = await nnclient.PostLoadModel(record.FilePath); if (!pyResponse.Contains(ZMMConstants.ErrorFailed)) { ModelResponse updateRecord = new ModelResponse() { Created_on = record.Created_on, Deployed = record.Deployed, Edited_on = record.Edited_on, Extension = record.Extension, FilePath = record.FilePath, Id = record.Id, Loaded = true, MimeType = record.MimeType, Name = record.Name, Size = record.Size, Type = record.Type, Url = record.Url }; ModelPayload.Update(updateRecord); responseData = ModelPayload.Get(); response = "{ id: '" + record.Id + "', loaded: true}"; if (!string.IsNullOrEmpty(response)) { jsonResponse = JObject.Parse(response); } isExists = true; } else { return(BadRequest(new { message = "Model loading failed.", errorCode = 500, exception = "No response from server." })); } } catch (Exception ex) { Logger.LogCritical(ex, "Model loading failed."); return(BadRequest(new { message = "Model loading failed.", errorCode = 400, exception = ex.Message })); } } } } if (!isExists) { return(NotFound(new { message = "Model loading failed.", errorCode = 404, exception = "No such model." })); } return(Json(jsonResponse)); }