public List <RubyHash> WithGearRotation(RubyHash options, GearRotationCallback action) { dynamic localGearEnv = Environ.ForGear(this.ContainerDir); Manifest proxyCart = this.Cartridge.WebProxy(); List <object> gears = new List <object>(); // TODO: vladi: verify if this is needed for scalable apps //if (options.ContainsKey("all") && proxyCart != null) //{ // if ((bool)options["all"]) // { // gears = this.GearRegist.Entries["web"].Keys.ToList<object>(); // } // else if (options.ContainsKey("gears")) // { // List<string> g = (List<string>)options["gears"]; // gears = this.GearRegist.Entries["web"].Keys.Where(e => g.Contains(e)).ToList<object>(); // } // else // { // try // { // gears.Add(this.GearRegist.Entries["web"][this.Uuid]); // } // catch // { // gears.Add(this.Uuid); // } // } //} //else { gears.Add(this.Uuid); } double parallelConcurrentRatio = PARALLEL_CONCURRENCY_RATIO; if (options.ContainsKey("parallel_concurrency_ratio")) { parallelConcurrentRatio = (double)options["parallel_concurrency_ratio"]; } int batchSize = CalculateBatchSize(gears.Count, parallelConcurrentRatio); int threads = Math.Max(batchSize, MAX_THREADS); List <RubyHash> result = new List <RubyHash>(); // need to parallelize foreach (var targetGear in gears) { result.Add(RotateAndYield(targetGear, localGearEnv, options, action)); } return(result); }
public RubyHash RotateAndYield(object targetGear, Dictionary <string, string> localGearEnv, RubyHash options, GearRotationCallback action) { RubyHash result = new RubyHash() { { "status", RESULT_FAILURE }, { "messages", new List <string>() }, { "errors", new List <string>() } }; string proxyCart = options["proxy_cart"]; string targetGearUuid = targetGear is string?(string)targetGear : ((GearRegistry.Entry)targetGear).Uuid; // TODO: vladi: check if this condition also needs boolean verification on the value in the hash if (options["init"] == null && options["rotate"] != null && options["rotate"] && options["hot_deploy"] != null && options["hot_deploy"]) { result["messages"].Add("Rotating out gear in proxies"); RubyHash rotateOutResults = this.UpdateProxyStatus(new RubyHash() { { "action", "disable" }, { "gear_uuid", targetGearUuid }, { "cartridge", proxyCart } }); result["rotate_out_results"] = rotateOutResults; if (rotateOutResults["status"] != RESULT_SUCCESS) { result["errors"].Add("Rotating out gear in proxies failed."); return(result); } } RubyHash yieldResult = action(targetGear, localGearEnv, options); dynamic yieldStatus = yieldResult.Delete("status"); dynamic yieldMessages = yieldResult.Delete("messages"); dynamic yieldErrors = yieldResult.Delete("errors"); result["messages"].AddRange(yieldMessages); result["errors"].AddRange(yieldErrors); result = result.Merge(yieldResult); if (yieldStatus != RESULT_SUCCESS) { return(result); } if (options["init"] == null && options["rotate"] != null && options["rotate"] && options["hot_deploy"] != null && options["hot_deploy"]) { result["messages"].Add("Rotating in gear in proxies"); RubyHash rotateInResults = this.UpdateProxyStatus(new RubyHash() { { "action", "enable" }, { "gear_uuid", targetGearUuid }, { "cartridge", proxyCart } }); result["rotate_in_results"] = rotateInResults; if (rotateInResults["status"] != RESULT_SUCCESS) { result["errors"].Add("Rotating in gear in proxies failed"); return(result); } } result["status"] = RESULT_SUCCESS; return(result); }
public RubyHash RotateAndYield(object targetGear, Dictionary<string, string> localGearEnv, RubyHash options, GearRotationCallback action) { RubyHash result = new RubyHash() { { "status", RESULT_FAILURE }, { "messages", new List<string>() }, { "errors", new List<string>() } }; string proxyCart = options["proxy_cart"]; string targetGearUuid = targetGear is string ? (string)targetGear : ((GearRegistry.Entry)targetGear).Uuid; // TODO: vladi: check if this condition also needs boolean verification on the value in the hash if (options["init"] == null && options["rotate"] != null && options["rotate"] && options["hot_deploy"] != null && options["hot_deploy"]) { result["messages"].Add("Rotating out gear in proxies"); RubyHash rotateOutResults = this.UpdateProxyStatus(new RubyHash() { { "action", "disable" }, { "gear_uuid", targetGearUuid }, { "cartridge", proxyCart } }); result["rotate_out_results"] = rotateOutResults; if (rotateOutResults["status"] != RESULT_SUCCESS) { result["errors"].Add("Rotating out gear in proxies failed."); return result; } } RubyHash yieldResult = action(targetGear, localGearEnv, options); dynamic yieldStatus = yieldResult.Delete("status"); dynamic yieldMessages = yieldResult.Delete("messages"); dynamic yieldErrors = yieldResult.Delete("errors"); result["messages"].AddRange(yieldMessages); result["errors"].AddRange(yieldErrors); result = result.Merge(yieldResult); if (yieldStatus != RESULT_SUCCESS) { return result; } if (options["init"] == null && options["rotate"] != null && options["rotate"] && options["hot_deploy"] != null && options["hot_deploy"]) { result["messages"].Add("Rotating in gear in proxies"); RubyHash rotateInResults = this.UpdateProxyStatus(new RubyHash() { { "action", "enable" }, { "gear_uuid", targetGearUuid }, { "cartridge", proxyCart } }); result["rotate_in_results"] = rotateInResults; if (rotateInResults["status"] != RESULT_SUCCESS) { result["errors"].Add("Rotating in gear in proxies failed"); return result; } } result["status"] = RESULT_SUCCESS; return result; }
public List<RubyHash> WithGearRotation(RubyHash options, GearRotationCallback action) { dynamic localGearEnv = Environ.ForGear(this.ContainerDir); Manifest proxyCart = this.Cartridge.WebProxy(); List<object> gears = new List<object>(); // TODO: vladi: verify if this is needed for scalable apps //if (options.ContainsKey("all") && proxyCart != null) //{ // if ((bool)options["all"]) // { // gears = this.GearRegist.Entries["web"].Keys.ToList<object>(); // } // else if (options.ContainsKey("gears")) // { // List<string> g = (List<string>)options["gears"]; // gears = this.GearRegist.Entries["web"].Keys.Where(e => g.Contains(e)).ToList<object>(); // } // else // { // try // { // gears.Add(this.GearRegist.Entries["web"][this.Uuid]); // } // catch // { // gears.Add(this.Uuid); // } // } //} //else { gears.Add(this.Uuid); } double parallelConcurrentRatio = PARALLEL_CONCURRENCY_RATIO; if (options.ContainsKey("parallel_concurrency_ratio")) { parallelConcurrentRatio = (double)options["parallel_concurrency_ratio"]; } int batchSize = CalculateBatchSize(gears.Count, parallelConcurrentRatio); int threads = Math.Max(batchSize, MAX_THREADS); List<RubyHash> result = new List<RubyHash>(); // need to parallelize foreach (var targetGear in gears) { result.Add(RotateAndYield(targetGear, localGearEnv, options, action)); } return result; }