public static async Task <HttpResponseMessage> DeleteSucceededPods([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log, ExecutionContext context)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();
            HttpResponseMessage myResponse = null;
            bool DeleteSucceededPods       = int.Parse(System.Configuration.ConfigurationManager.AppSettings["DeleteSucceededPods"] ?? "1") == 1;

            if (DeleteSucceededPods)
            {
                dynamic BodyData = await req.Content.ReadAsAsync <object>();

                string     JobId = BodyData.JobId;
                IK8SClient k     = K8SClientFactory.Create();
                try
                {
                    var r = await k.DeleteJobs(JobId);

                    myResponse = req.CreateResponse(r.Code, r, JsonMediaTypeFormatter.DefaultMediaType);
                }
                catch (Exception X)
                {
                    myResponse = req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType);
                }
            }
            else
            {
                return(req.CreateResponse(HttpStatusCode.OK, new { mesagge = "Ignored" }, JsonMediaTypeFormatter.DefaultMediaType));
            }
            watch.Stop();
            log.Info($"[Time] Method GetK8SProcessLog {watch.ElapsedMilliseconds} [ms]");
            return(myResponse);
        }
        public async Task <K8SResult> SubmiteJobK8S(ManifestInfo manifest, int subId)
        {
            //Create Yamal Job definition
            string      manifesttxt = Newtonsoft.Json.JsonConvert.SerializeObject(manifest);
            string      jobbase64   = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(manifesttxt), Base64FormattingOptions.None);
            string      imageName   = System.Configuration.ConfigurationManager.AppSettings["imageName"];
            string      jobtxt      = GetJobYmal(manifest.JobID + "-" + subId.ToString(), jobbase64, imageName);
            HttpContent ymal        = new StringContent(jobtxt, Encoding.UTF8, "application/yaml");

            // Submite JOB
            IK8SClient k8sClient = K8SClientFactory.Create();
            var        rs        = await k8sClient.SubmiteK8SJob(ymal);

            return(rs);
        }
        public static async Task <HttpResponseMessage> DeleteSucceededPods([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log, ExecutionContext context)
        {
            dynamic BodyData = await req.Content.ReadAsAsync <object>();

            string JobId = BodyData.JobId;

            IK8SClient k          = K8SClientFactory.Create();
            string     prefixName = $"allinone-job-{JobId}";

            try
            {
                var r = await k.DeletePods(prefixName, "Succeeded");

                return(req.CreateResponse(r.Code, r, JsonMediaTypeFormatter.DefaultMediaType));
            }
            catch (Exception X)
            {
                return(req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType));
            }
        }
Example #4
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);
        }