public bool PodFailure(string _Podname, string _Filename = null, Action <string> _ErrorMessageAction = null) { _ErrorMessageAction?.Invoke($"Pod failure reported : {_Podname}"); try { string Filename = _Filename; if (Filename == null) { GetBucketAndFile(_Podname, out string _, out Filename); if (string.IsNullOrWhiteSpace(Filename)) { _ErrorMessageAction?.Invoke("Could not find pod details"); return(false); } } if (GetModelDetailsFromFilePath(Filename, out string _ModelId, out int _RevisionIndex, _ErrorMessageAction)) { //if we fail then you have a broken model on a broken path Controller_BatchProcess.Get().BroadcastBatchProcessAction(new Action_BatchProcessFailed() { ModelID = _ModelId, RevisionIndex = _RevisionIndex }, _ErrorMessageAction); } var NewDBEntry = new FileConversionDBEntry() { ConversionStatus = (int)EInternalProcessStage.ProcessFailed }; string ConversionId = WebUtility.UrlEncode(Filename); return(DatabaseService.UpdateItem( FileConversionDBEntry.DBSERVICE_FILE_CONVERSIONS_TABLE(), FileConversionDBEntry.KEY_NAME_CONVERSION_ID, new BPrimitiveType(ConversionId), JObject.Parse(JsonConvert.SerializeObject(NewDBEntry)), out JObject _, EBReturnItemBehaviour.ReturnAllNew, null, _ErrorMessageAction)); } catch (Exception ex) { _ErrorMessageAction?.Invoke($"Failed to handle Pod failure - {ex.Message}\n{ex.StackTrace}"); return(false); } }
private BWebServiceResponse OnRequest_Internal(HttpListenerContext _Context, Action <string> _ErrorMessageAction) { _ErrorMessageAction?.Invoke("Job complete called"); if (_Context.Request.HttpMethod != "GET") { return(BWebResponse.BadRequest($"This service does not accept requests of type : {_Context.Request.HttpMethod}")); } string Url = _Context.Request.RawUrl; int CopyStart = Url.LastIndexOf('/') + 1; string Podname = Url.Substring(CopyStart); BatchProcessingCreationService.Instance.GetBucketAndFile(Podname, out string _Bucket, out string _Filename); if (_Bucket == null || _Filename == null) { return(BWebResponse.BadRequest($"The provided pod name does not exist")); } string NewConversionID_FromRelativeUrl_UrlEncoded = WebUtility.UrlEncode(_Filename); var NewDBEntry = new FileConversionDBEntry() { ConversionStatus = (int)EInternalProcessStage.ProcessComplete }; if (!DatabaseService.UpdateItem( FileConversionDBEntry.DBSERVICE_FILE_CONVERSIONS_TABLE(), FileConversionDBEntry.KEY_NAME_CONVERSION_ID, new BPrimitiveType(NewConversionID_FromRelativeUrl_UrlEncoded), JObject.Parse(JsonConvert.SerializeObject(NewDBEntry)), out JObject _, EBReturnItemBehaviour.DoNotReturn, null, _ErrorMessageAction)) { return(BWebResponse.InternalError("Database error")); } if (!BatchProcessingCreationService.Instance.NotifyPodSucceded(Podname.Trim(), _ErrorMessageAction)) { return(BWebResponse.InternalError("Failed to do Pod Completion or connect to kubernetes")); } //Code for initial method of starting optimizer after pixyz completes //if (!BatchProcessingCreationService.Instance.StartUnrealOptimizer(_Bucket, _Filename)) //{ // NewDBEntry.ConversionStatus = (int)EInternalProcessStage.ProcessFailed; // if (!DatabaseService.UpdateItem( // FileConversionDBEntry.DBSERVICE_FILE_CONVERSIONS_TABLE(), // FileConversionDBEntry.KEY_NAME_CONVERSION_ID, // new BPrimitiveType(NewConversionID_FromRelativeUrl_UrlEncoded), // JObject.Parse(JsonConvert.SerializeObject(NewDBEntry)), // out JObject _, EBReturnItemBehaviour.DoNotReturn, // null, // _ErrorMessageAction)) // { // return BWebResponse.InternalError("Failed to start unreal optimizer and experienced a Database error"); // } // return BWebResponse.InternalError("Failed to start unreal optimizer"); //} return(BWebResponse.StatusOK("Job completion confirmed. Unreal Optimizer scheduled.")); }
private BWebServiceResponse OnRequest_Internal(HttpListenerContext _Context, Action <string> _ErrorMessageAction) { if (_Context.Request.HttpMethod != "POST") { _ErrorMessageAction?.Invoke("StopProcessRequest: POST methods is accepted. But received request method: " + _Context.Request.HttpMethod); return(BWebResponse.MethodNotAllowed("POST methods is accepted. But received request method: " + _Context.Request.HttpMethod)); } string BucketName = null; string RelativeFilename = null; string ConversionID_FromRelativeUrl_UrlEncoded = null; using (var InputStream = _Context.Request.InputStream) { var NewObjectJson = new JObject(); using (var ResponseReader = new StreamReader(InputStream)) { try { var ParsedBody = JObject.Parse(ResponseReader.ReadToEnd()); if (!ParsedBody.ContainsKey("bucketName") || !ParsedBody.ContainsKey("rawFileRelativeUrl")) { return(BWebResponse.BadRequest("Request body must contain all necessary fields.")); } var BucketNameToken = ParsedBody["bucketName"]; var RawFileRelativeUrlToken = ParsedBody["rawFileRelativeUrl"]; if (BucketNameToken.Type != JTokenType.String || RawFileRelativeUrlToken.Type != JTokenType.String) { return(BWebResponse.BadRequest("Request body contains invalid fields.")); } BucketName = (string)BucketNameToken; ConversionID_FromRelativeUrl_UrlEncoded = WebUtility.UrlEncode((string)RawFileRelativeUrlToken); RelativeFilename = (string)RawFileRelativeUrlToken; } catch (Exception e) { _ErrorMessageAction?.Invoke("Read request body stage has failed. Exception: " + e.Message + ", Trace: " + e.StackTrace); return(BWebResponse.BadRequest("Malformed request body. Request must be a valid json form.")); } } } //Temporarily, TODO: Change this when the implementation is in place. if (!DatabaseService.DeleteItem( FileConversionDBEntry.DBSERVICE_FILE_CONVERSIONS_TABLE(), FileConversionDBEntry.KEY_NAME_CONVERSION_ID, new BPrimitiveType(ConversionID_FromRelativeUrl_UrlEncoded), out JObject _, EBReturnItemBehaviour.DoNotReturn, _ErrorMessageAction)) { if (!DatabaseService.GetItem( FileConversionDBEntry.DBSERVICE_FILE_CONVERSIONS_TABLE(), FileConversionDBEntry.KEY_NAME_CONVERSION_ID, new BPrimitiveType(ConversionID_FromRelativeUrl_UrlEncoded), FileConversionDBEntry.Properties, out JObject _ReturnObject, _ErrorMessageAction) || _ReturnObject != null) { return(BWebResponse.InternalError("Database error.")); } } if (!BatchProcessingCreationService.Instance.StopBatchProcess(BucketName, RelativeFilename, _ErrorMessageAction)) { return(BWebResponse.InternalError("Failed to stop pod or connect to kubernetess")); } return(BWebResponse.StatusAccepted("Request has been accepted; process is now being stopped.")); }
private BWebServiceResponse OnRequest_Internal(HttpListenerContext _Context, Action <string> _ErrorMessageAction) { _ErrorMessageAction?.Invoke("Trying to get Optimizer Env Vars"); if (_Context.Request.HttpMethod != "GET") { _ErrorMessageAction?.Invoke("Wrong type"); return(BWebResponse.BadRequest($"This service does not accept requests of type : {_Context.Request.HttpMethod}")); } string Url = _Context.Request.RawUrl; int CopyStart = Url.LastIndexOf('/') + 1; string Podname = Url.Substring(CopyStart).TrimEnd('/'); BatchProcessingCreationService.Instance.GetBucketAndFile(Podname, out string _Bucket, out string _Filename); if (!string.IsNullOrWhiteSpace(_Bucket) && !string.IsNullOrWhiteSpace(_Filename)) { string NewConversionID_FromRelativeUrl_UrlEncoded = WebUtility.UrlEncode(_Filename); bool CanProceed = false; bool ProcessError = false; if (DatabaseService.GetItem( FileConversionDBEntry.DBSERVICE_FILE_CONVERSIONS_TABLE(), FileConversionDBEntry.KEY_NAME_CONVERSION_ID, new BPrimitiveType(NewConversionID_FromRelativeUrl_UrlEncoded), FileConversionDBEntry.Properties, out JObject ConversionObject )) { if (ConversionObject != null && ConversionObject.ContainsKey("conversionStatus")) { EInternalProcessStage ExistingStatus = (EInternalProcessStage)(int)ConversionObject["conversionStatus"]; if (ExistingStatus == EInternalProcessStage.ProcessComplete) { CanProceed = true; } else if (ExistingStatus == EInternalProcessStage.ProcessFailed) { ProcessError = true; } } } else { ProcessError = true; } if (CanProceed) { Dictionary <string, string> EnvVars = BatchProcessingCreationService.Instance.GetOptimizerEnvVars(_Bucket, _Filename, Podname, _ErrorMessageAction); if (EnvVars == null) { _ErrorMessageAction?.Invoke("EnvVars null"); return(BWebResponse.InternalError("An error occured trying to generate optimizer parameters")); } return(BWebResponse.StatusOK("success", new JObject() { ["uploadRequestUrl"] = EnvVars["CAD_PROCESS_UPLOAD_REQUEST_URL"], ["downloadHierarchyCfUrl"] = EnvVars["DOWNLOAD_HIERARCHY_CF"], ["downloadGeometryCfUrl"] = EnvVars["DOWNLOAD_GEOMETRY_CF"], ["downloadMetadataCfUrl"] = EnvVars["DOWNLOAD_METADATA_CF"] })); } else if (ProcessError) { _ErrorMessageAction?.Invoke("Cad process Failed"); return(BWebResponse.InternalError("Pixyz process has failed")); } else { _ErrorMessageAction?.Invoke("Not found"); return(BWebResponse.NotFound("Cad process has not completed yet")); } } else { _ErrorMessageAction?.Invoke("General failure"); return(BWebResponse.InternalError("An error occured trying to retreive pod details")); } }
private BWebServiceResponse OnRequest_Internal(HttpListenerContext _Context, Action <string> _ErrorMessageAction) { if (_Context.Request.HttpMethod != "POST") { _ErrorMessageAction?.Invoke("StartProcessRequest: POST methods is accepted. But received request method: " + _Context.Request.HttpMethod); return(BWebResponse.MethodNotAllowed("POST methods is accepted. But received request method: " + _Context.Request.HttpMethod)); } var NewDBEntry = new FileConversionDBEntry() { ConversionStatus = (int)EInternalProcessStage.Queued }; string NewConversionID_FromRelativeUrl_UrlEncoded = null; string BucketName = null; string RelativeFileName = null; string ZipMainAssembly = ""; using (var InputStream = _Context.Request.InputStream) { var NewObjectJson = new JObject(); using (var ResponseReader = new StreamReader(InputStream)) { try { var ParsedBody = JObject.Parse(ResponseReader.ReadToEnd()); if (!ParsedBody.ContainsKey("bucketName") || !ParsedBody.ContainsKey("rawFileRelativeUrl")) { return(BWebResponse.BadRequest("Request body must contain all necessary fields.")); } var BucketNameToken = ParsedBody["bucketName"]; var RawFileRelativeUrlToken = ParsedBody["rawFileRelativeUrl"]; if (BucketNameToken.Type != JTokenType.String || RawFileRelativeUrlToken.Type != JTokenType.String) { return(BWebResponse.BadRequest("Request body contains invalid fields.")); } if (ParsedBody.ContainsKey("zipTypeMainAssemblyFileNameIfAny")) { var ZipMainAssemblyToken = ParsedBody["zipTypeMainAssemblyFileNameIfAny"]; if (ZipMainAssemblyToken.Type != JTokenType.String) { return(BWebResponse.BadRequest("Request body contains invalid fields.")); } ZipMainAssembly = (string)ZipMainAssemblyToken; } NewDBEntry.BucketName = (string)BucketNameToken; NewConversionID_FromRelativeUrl_UrlEncoded = WebUtility.UrlEncode((string)RawFileRelativeUrlToken); BucketName = (string)BucketNameToken; RelativeFileName = (string)RawFileRelativeUrlToken; } catch (Exception e) { _ErrorMessageAction?.Invoke("Read request body stage has failed. Exception: " + e.Message + ", Trace: " + e.StackTrace); return(BWebResponse.BadRequest("Malformed request body. Request must be a valid json form.")); } } } if (BucketName == null || RelativeFileName == null) { return(BWebResponse.InternalError("No BucketName or FileName")); } BDatabaseAttributeCondition UpdateCondition = DatabaseService.BuildAttributeNotExistCondition(FileConversionDBEntry.KEY_NAME_CONVERSION_ID); //If a process was completed (success or failure) then allow reprocessing //Only stop if a process is currently busy processing or already queued if (DatabaseService.GetItem( FileConversionDBEntry.DBSERVICE_FILE_CONVERSIONS_TABLE(), FileConversionDBEntry.KEY_NAME_CONVERSION_ID, new BPrimitiveType(NewConversionID_FromRelativeUrl_UrlEncoded), FileConversionDBEntry.Properties, out JObject ConversionObject )) { if (ConversionObject != null && ConversionObject.ContainsKey("conversionStatus")) { EInternalProcessStage ExistingStatus = (EInternalProcessStage)(int)ConversionObject["conversionStatus"]; if (ExistingStatus == EInternalProcessStage.ProcessFailed || ExistingStatus == EInternalProcessStage.ProcessComplete) { UpdateCondition = null; } } } if (!DatabaseService.UpdateItem( FileConversionDBEntry.DBSERVICE_FILE_CONVERSIONS_TABLE(), FileConversionDBEntry.KEY_NAME_CONVERSION_ID, new BPrimitiveType(NewConversionID_FromRelativeUrl_UrlEncoded), JObject.Parse(JsonConvert.SerializeObject(NewDBEntry)), out JObject _ExistingObject, EBReturnItemBehaviour.DoNotReturn, UpdateCondition, _ErrorMessageAction)) { return(BWebResponse.Conflict("File is already being processed/queued.")); } try { if (BatchProcessingCreationService.Instance.StartBatchProcess(BucketName, RelativeFileName, ZipMainAssembly, out string _PodName, _ErrorMessageAction)) { //Code for initial method of starting optimizer after pixyz completes //return BWebResponse.StatusAccepted("Request has been accepted; process is now being started."); if (BatchProcessingCreationService.Instance.StartFileOptimizer(BucketName, RelativeFileName, _ErrorMessageAction)) { return(BWebResponse.StatusAccepted("Request has been accepted; process is now being started.")); } else { NewDBEntry.ConversionStatus = (int)EInternalProcessStage.ProcessFailed; if (!DatabaseService.UpdateItem( FileConversionDBEntry.DBSERVICE_FILE_CONVERSIONS_TABLE(), FileConversionDBEntry.KEY_NAME_CONVERSION_ID, new BPrimitiveType(NewConversionID_FromRelativeUrl_UrlEncoded), JObject.Parse(JsonConvert.SerializeObject(NewDBEntry)), out JObject _, EBReturnItemBehaviour.DoNotReturn, null, _ErrorMessageAction)) { return(BWebResponse.InternalError("Failed to start the batch process and experienced a Database error")); } //Try kill pixyz pod that we have succeeded in creating if (!BatchProcessingCreationService.Instance.TryKillPod(_PodName, "cip-batch")) { return(BWebResponse.InternalError("Failed to start the unreal optimizer and failed to kill pixyz pod")); } return(BWebResponse.InternalError("Failed to start the batch process and experienced a Database error")); } } else { NewDBEntry.ConversionStatus = (int)EInternalProcessStage.ProcessFailed; if (!DatabaseService.UpdateItem( FileConversionDBEntry.DBSERVICE_FILE_CONVERSIONS_TABLE(), FileConversionDBEntry.KEY_NAME_CONVERSION_ID, new BPrimitiveType(NewConversionID_FromRelativeUrl_UrlEncoded), JObject.Parse(JsonConvert.SerializeObject(NewDBEntry)), out JObject _, EBReturnItemBehaviour.DoNotReturn, null, _ErrorMessageAction)) { return(BWebResponse.InternalError("Failed to start the batch process and experienced a Database error")); } return(BWebResponse.InternalError("Failed to start the batch process")); } }