Exemplo n.º 1
0
        public static async Task <HttpResponseMessage> GetK8SProcessLog([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequestMessage req, TraceWriter log, ExecutionContext context)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();
            HttpResponseMessage myResponse = null;
            string JobId = req.GetQueryNameValuePairs().FirstOrDefault(q => string.Compare(q.Key, "JobId", true) == 0).Value;

            if (string.IsNullOrEmpty(JobId))
            {
                return(req.CreateResponse(HttpStatusCode.InternalServerError, new { Error = "Parameter JobId is null" }, JsonMediaTypeFormatter.DefaultMediaType));
            }

            var K8S = K8SClientFactory.Create();

            try
            {
                var ResultList = await K8S.GetK8SJobLog(JobId);

                if (ResultList.Count == 0)
                {
                    //Not Found
                    myResponse = req.CreateResponse(HttpStatusCode.NotFound, ResultList, JsonMediaTypeFormatter.DefaultMediaType);
                }
                else
                {
                    //LOG
                    myResponse = req.CreateResponse(HttpStatusCode.OK, ResultList, JsonMediaTypeFormatter.DefaultMediaType);
                }
            }
            catch (Exception X)
            {
                log.Error(X.Message);
                myResponse = req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType);
            }

            watch.Stop();
            log.Info($"[Time] Method GetK8SProcessLog {watch.ElapsedMilliseconds} [ms]");
            return(myResponse);
        }
Exemplo n.º 2
0
        public async Task <K8SResult> SubmiteJobK8S(ManifestInfo manifest, int subId)
        {
            //Create Yamal Job definition
            manifest.JobID = $"{manifest.JobID}-{subId}";
            string manifesttxt = Newtonsoft.Json.JsonConvert.SerializeObject(manifest);
            //Save JOB data on Blob Storage And Generate a SASURL
            string      jobbase64         = SaveBlobData(manifesttxt, $"{manifest.JobID}.json");
            string      imageName         = System.Configuration.ConfigurationManager.AppSettings["imageName"];
            string      PARALLELEMBEDDERS = System.Configuration.ConfigurationManager.AppSettings["PARALLELEMBEDDERS"] ?? "5";
            string      jobtxt            = GetJobYmal(manifest.JobID, jobbase64, imageName, PARALLELEMBEDDERS);
            HttpContent ymal = new StringContent(jobtxt, Encoding.UTF8, "application/yaml");

            SaveBlobData(jobtxt, $"{manifest.JobID}.ymal");
            // Submite JOB
            IK8SClient k8sClient = K8SClientFactory.Create();
            var        rs        = await k8sClient.SubmiteK8SJob(ymal);

            if (!rs.IsSuccessStatusCode)
            {
                Trace.TraceError($"[{manifest.JobID}]SubmiteJobK8S : {jobtxt}");
            }
            return(rs);
        }