public BaseAction GetAction() { if (actionType == ActionType.Move) { return(MoveAction.Create(v31, b1, b2, duration, Ease.FromType(easeType), direction)); } if (actionType == ActionType.Scale) { return(ScaleAction.Create(v31, b1, duration, Ease.FromType(easeType), direction)); } if (actionType == ActionType.Rotate) { return(RotateAction.Create(f1, b1, duration, Ease.FromType(easeType), direction)); } if (actionType == ActionType.Fade) { return(FadeAction.Create(f1, b1, b2, duration, Ease.FromType(easeType), direction)); } if (actionType == ActionType.Tint) { return(TintAction.Create(c1.RGB(), b1, b2, duration, Ease.FromType(easeType), direction)); } if (actionType == ActionType.Delay) { return(DelayAction.Create(duration)); } return(null); }
public static void ShowPopup(GameObject popup, Action callback = null) { // Reset button scale popup.ResetButtonScale(true); // Show popup popup.Show(); // Fade-in popup.Play(FadeAction.FadeTo(popupEndOpacity, popupDuration)); // Content GameObject content = popup.FindInChildren("Popup"); if (content != null) { content.transform.localScale = popupStartScale; var zoomOut = ScaleAction.ScaleTo(popupEndScale, popupDuration * 0.7f); var zoomIn = ScaleAction.ScaleTo(Vector3.one, popupDuration * 0.3f); var action = SequenceAction.Create(zoomOut, zoomIn); content.Play(action, callback); } else { if (callback != null) { callback(); } } }
void Start() { gameObject.Play(ScaleAction.Create(end, isRelative, duration, Ease.FromType(easeType), direction)); // Self-destroy Destroy(this); }
public async Task GetMetricsWorksAsExpectedAsync(ScaleAction action, int currentWorkerCount, long targetCount) { var fixture = new ServiceFixture(action, currentWorkerCount); var service = fixture.ExternalScaleService; var response = await service.GetMetrics(fixture.GetMetricsRequest, fixture.ServerCallContext); Assert.Equal(targetCount, response.MetricValues.First().MetricValue_); }
/// <summary> /// Initializes a new instance of the ScaleRule class. /// </summary> /// <param name="metricTrigger">The metric trigger object</param> /// <param name="scaleAction">The scale action object</param> public ScaleRule(Monitor.Models.MetricTrigger metricTrigger, Monitor.Models.ScaleAction scaleAction) : base( metricTrigger: metricTrigger, scaleAction: scaleAction) { this.MetricTrigger = metricTrigger != null ? new MetricTrigger(metricTrigger) : null; this.ScaleAction = scaleAction != null ? new ScaleAction(scaleAction) : null; }
public static BaseAction GetJellyAction() { var scale1 = ScaleAction.ScaleTo(new Vector3(1.1f, 0.9f, 1), 0.1f); var scale2 = ScaleAction.ScaleTo(new Vector3(0.9f, 1.1f, 1), 0.1f); var scale3 = ScaleAction.ScaleTo(new Vector3(1f, 1f, 1), 0.1f); var sequence = SequenceAction.Create(scale1, scale2, scale3); return(sequence); }
private static void AreEqual(ScaleAction exp, ScaleAction act) { if (exp != null) { Assert.Equal(exp.Cooldown, act.Cooldown); Assert.Equal(exp.Direction, act.Direction); Assert.Equal(exp.Value, act.Value); } }
void Start() { // Set scale transform.localScale = scale; gameObject.Play(ParallelAction.ParallelAll(ScaleAction.ScaleTo(scale * Random.Range(minScale, maxScale), scaleDuration), FadeAction.FadeOut(fadeDuration)), () => { GameObject.Destroy(gameObject); }); }
public void OnHint() { gameObject.StopAction("hint", true); var zoom = ScaleAction.ScaleTo(hintScale, 0.1f, Ease.Linear, LerpDirection.PingPong); var action = RepeatAction.Create(zoom, 3, false); gameObject.Play(action).name = "hint"; }
/// <summary> /// Initializes a new instance of the ScaleRule class. /// </summary> /// <param name="scaleRule">The scale rule</param> public ScaleRule(Monitor.Models.ScaleRule scaleRule) : base() { if (scaleRule != null) { base.MetricTrigger = scaleRule.MetricTrigger; base.ScaleAction = scaleRule.ScaleAction; this.MetricTrigger = scaleRule.MetricTrigger != null ? new MetricTrigger(scaleRule.MetricTrigger) : null; this.ScaleAction = scaleRule.ScaleAction != null ? new ScaleAction(scaleRule.ScaleAction) : null; } }
private static ScaleRecommendation CreateScaleRecommendation(ScaleAction scaleAction, bool keepWorkersAlive, string reason) { var s = typeof(ScaleRecommendation); var ctor = s.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).First(); return(ctor.Invoke(new object[] { scaleAction, keepWorkersAlive, reason }) as ScaleRecommendation); }
public void StartTransformAction(LocalOrientation localOrientation, DragActionType dragActionType, int part = -1, IRevertable revertable = null) { AbstractTransformAction transformAction; Vector3 pivot; draggingDepth = control.PickingDepth; if (part != -1) { pivot = localOrientation.Origin; } else { BoundingBox box = BoundingBox.Default; foreach (IEditableObject obj in GetObjects()) { obj.GetSelectionBox(ref box); } pivot = box.GetCenter(); if (box == BoundingBox.Default) { return; } } switch (dragActionType) { case DragActionType.TRANSLATE: transformAction = new TranslateAction(control, control.GetMousePos(), pivot, draggingDepth); break; case DragActionType.ROTATE: transformAction = new RotateAction(control, control.GetMousePos(), pivot, draggingDepth); break; case DragActionType.SCALE: transformAction = new ScaleAction(control, control.GetMousePos(), pivot); break; case DragActionType.SCALE_INDIVIDUAL: transformAction = new ScaleActionIndividual(control, control.GetMousePos(), localOrientation); break; default: return; } StartTransformAction(transformAction, part, revertable); }
public ServiceFixture(ScaleAction action, int currentWorkerCount, bool inputKeepWorkersAlive = true) { _kubernetesRepositoryMock = new Mock <IKubernetesRepository>(); _performanceMonitorRepositoryMock = new Mock <IPerformanceMonitorRepository>(); var performanceHeartbeat = new PerformanceHeartbeat(); var scaleRecommendation = CreateScaleRecommendation(action, inputKeepWorkersAlive, "baz"); SetScaleRecommendation(performanceHeartbeat, scaleRecommendation); _performanceMonitorRepositoryMock.Setup(p => p.PulseAsync(currentWorkerCount)).ReturnsAsync(performanceHeartbeat); _kubernetesRepositoryMock.Setup(p => p.GetNumberOfPodAsync(ExpectedName, ExpectedNamespace)).ReturnsAsync(currentWorkerCount); _loggerMock = new Mock <ILogger <ExternalScalerService> >(); }
/// <summary> /// A string representation of the ScaleAction including indentation /// </summary> /// <param name="scaleAction">The ScaleAction object</param> /// <param name="indentationTabs">The number of tabs to insert in front of each member</param> /// <returns>A string representation of the ScaleAction including indentation</returns> public static string ToString(this ScaleAction scaleAction, int indentationTabs) { StringBuilder output = new StringBuilder(); if (scaleAction != null) { output.AppendLine(); output.AddSpacesInFront(indentationTabs).AppendLine("Cooldown : " + scaleAction.Cooldown); output.AddSpacesInFront(indentationTabs).AppendLine("Direction : " + scaleAction.Direction); output.AddSpacesInFront(indentationTabs).AppendLine("Type : " + scaleAction.Type); output.AddSpacesInFront(indentationTabs).Append("Value : " + scaleAction.Value); } return(output.ToString()); }
void Awake() { _Draw._Cam = Camera.main; lineMaterial = new Material(Shader.Find("Custom/GizmoShader")); transformAction = new TransformAction(this); rotateAction = new RotateAction(this); scaleAction = new ScaleAction(this); Item = gameObject; CurrentScale = Item.transform.localScale; TimerForArrows = TimerdelayForArrows; }
static public ScaleAction ConvertNamespace(Management.Monitor.Management.Models.ScaleAction scaleAction) { if (scaleAction == null) { return(null); } ScaleAction action = new ScaleAction( direction: ConvertNamespace(scaleAction.Direction), type: ConvertNamespace(scaleAction.Type), cooldown: scaleAction.Cooldown, value: scaleAction.Value); return(action); }
/// <summary> /// Create an Autoscale setting rule based on the properties of the object /// </summary> /// <returns>A ScaleRule created based on the properties of the object</returns> public ScaleRule CreateSettingRule() { if (this.TimeWindow != default(TimeSpan) && this.TimeWindow < MinimumTimeWindow) { throw new ArgumentOutOfRangeException("TimeWindow", this.TimeWindow, ResourcesForAutoscaleCmdlets.MinimumTimeWindow5min); } if (this.TimeGrain < MinimumTimeGrain) { throw new ArgumentOutOfRangeException("TimeGrain", this.TimeGrain, ResourcesForAutoscaleCmdlets.MinimumTimeGrain1min); } MetricTrigger trigger = new MetricTrigger() { MetricName = this.MetricName, MetricResourceUri = this.MetricResourceId, OperatorProperty = this.Operator, Statistic = this.MetricStatistic, Threshold = this.Threshold, TimeAggregation = this.TimeAggregationOperator, TimeGrain = this.TimeGrain, TimeWindow = this.TimeWindow == default(TimeSpan) ? MinimumTimeWindow : this.TimeWindow, }; // Notice ChangeCount is (ScaleType)0, so this is the default in this version. It was the only value in the previous version. ScaleAction action = new ScaleAction() { Cooldown = this.ScaleActionCooldown, Direction = this.ScaleActionDirection, Value = this.ScaleActionValue, Type = this.ScaleActionScaleType }; return(new ScaleRule() { MetricTrigger = trigger, ScaleAction = action, }); }
void UpdateTime() { // Get current time int time = Mathf.CeilToInt(_time); if (time != _currentTime) { if (_currentTime > 0) { // Frame frame.StopAction(); frame.Show(); frame.Play(BlinkAction.Create(2, 0.3f, false, false), () => { frame.Hide(); }); // Play effect GameObject effect = numberEffect.gameObject; effect.StopAction(true); effect.Show(); effect.transform.localScale = Vector3.one; effect.SetColor(_currentTime > 3 ? Color.white : alarmColor, true); numberEffect.Number = _currentTime; var zoomOut = ScaleAction.ScaleTo(alarmScale, alarmDuration); var fadeOut = FadeAction.RecursiveFadeOut(alarmDuration); var hide = HideAction.Create(); effect.Play(SequenceAction.Create(ParallelAction.ParallelAll(zoomOut, fadeOut), hide)); } // Set current time _currentTime = time; // Update number number.Number = time; } }
/// <param name='resourceId'> /// Required. The resource ID. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.Monitoring.Autoscale.Models.AutoscaleSettingGetResponse> GetAsync(string resourceId, CancellationToken cancellationToken) { // Validate if (resourceId == null) { throw new ArgumentNullException("resourceId"); } // Tracing bool shouldTrace = CloudContext.Configuration.Tracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = Tracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceId", resourceId); Tracing.Enter(invocationId, this, "GetAsync", tracingParameters); } // Construct URL string url = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/services/monitoring/autoscalesettings?"; url = url + "resourceId=" + Uri.EscapeDataString(resourceId.Trim()); string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("Accept", "application/json"); httpRequest.Headers.Add("x-ms-version", "2013-10-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { Tracing.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { Tracing.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result AutoscaleSettingGetResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new AutoscaleSettingGetResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { AutoscaleSetting settingInstance = new AutoscaleSetting(); result.Setting = settingInstance; JToken profilesArray = responseDoc["Profiles"]; if (profilesArray != null && profilesArray.Type != JTokenType.Null) { foreach (JToken profilesValue in ((JArray)profilesArray)) { AutoscaleProfile autoscaleProfileInstance = new AutoscaleProfile(); settingInstance.Profiles.Add(autoscaleProfileInstance); JToken nameValue = profilesValue["Name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); autoscaleProfileInstance.Name = nameInstance; } JToken capacityValue = profilesValue["Capacity"]; if (capacityValue != null && capacityValue.Type != JTokenType.Null) { ScaleCapacity capacityInstance = new ScaleCapacity(); autoscaleProfileInstance.Capacity = capacityInstance; JToken minimumValue = capacityValue["Minimum"]; if (minimumValue != null && minimumValue.Type != JTokenType.Null) { string minimumInstance = ((string)minimumValue); capacityInstance.Minimum = minimumInstance; } JToken maximumValue = capacityValue["Maximum"]; if (maximumValue != null && maximumValue.Type != JTokenType.Null) { string maximumInstance = ((string)maximumValue); capacityInstance.Maximum = maximumInstance; } JToken defaultValue = capacityValue["Default"]; if (defaultValue != null && defaultValue.Type != JTokenType.Null) { string defaultInstance = ((string)defaultValue); capacityInstance.Default = defaultInstance; } } JToken rulesArray = profilesValue["Rules"]; if (rulesArray != null && rulesArray.Type != JTokenType.Null) { foreach (JToken rulesValue in ((JArray)rulesArray)) { ScaleRule scaleRuleInstance = new ScaleRule(); autoscaleProfileInstance.Rules.Add(scaleRuleInstance); JToken metricTriggerValue = rulesValue["MetricTrigger"]; if (metricTriggerValue != null && metricTriggerValue.Type != JTokenType.Null) { MetricTrigger metricTriggerInstance = new MetricTrigger(); scaleRuleInstance.MetricTrigger = metricTriggerInstance; JToken metricNameValue = metricTriggerValue["MetricName"]; if (metricNameValue != null && metricNameValue.Type != JTokenType.Null) { string metricNameInstance = ((string)metricNameValue); metricTriggerInstance.MetricName = metricNameInstance; } JToken metricNamespaceValue = metricTriggerValue["MetricNamespace"]; if (metricNamespaceValue != null && metricNamespaceValue.Type != JTokenType.Null) { string metricNamespaceInstance = ((string)metricNamespaceValue); metricTriggerInstance.MetricNamespace = metricNamespaceInstance; } JToken metricSourceValue = metricTriggerValue["MetricSource"]; if (metricSourceValue != null && metricSourceValue.Type != JTokenType.Null) { string metricSourceInstance = ((string)metricSourceValue); metricTriggerInstance.MetricSource = metricSourceInstance; } JToken timeGrainValue = metricTriggerValue["TimeGrain"]; if (timeGrainValue != null && timeGrainValue.Type != JTokenType.Null) { TimeSpan timeGrainInstance = TypeConversion.From8601TimeSpan(((string)timeGrainValue)); metricTriggerInstance.TimeGrain = timeGrainInstance; } JToken statisticValue = metricTriggerValue["Statistic"]; if (statisticValue != null && statisticValue.Type != JTokenType.Null) { MetricStatisticType statisticInstance = ((MetricStatisticType)Enum.Parse(typeof(MetricStatisticType), ((string)statisticValue), true)); metricTriggerInstance.Statistic = statisticInstance; } JToken timeWindowValue = metricTriggerValue["TimeWindow"]; if (timeWindowValue != null && timeWindowValue.Type != JTokenType.Null) { TimeSpan timeWindowInstance = TypeConversion.From8601TimeSpan(((string)timeWindowValue)); metricTriggerInstance.TimeWindow = timeWindowInstance; } JToken timeAggregationValue = metricTriggerValue["TimeAggregation"]; if (timeAggregationValue != null && timeAggregationValue.Type != JTokenType.Null) { TimeAggregationType timeAggregationInstance = ((TimeAggregationType)Enum.Parse(typeof(TimeAggregationType), ((string)timeAggregationValue), true)); metricTriggerInstance.TimeAggregation = timeAggregationInstance; } JToken operatorValue = metricTriggerValue["Operator"]; if (operatorValue != null && operatorValue.Type != JTokenType.Null) { ComparisonOperationType operatorInstance = ((ComparisonOperationType)Enum.Parse(typeof(ComparisonOperationType), ((string)operatorValue), true)); metricTriggerInstance.Operator = operatorInstance; } JToken thresholdValue = metricTriggerValue["Threshold"]; if (thresholdValue != null && thresholdValue.Type != JTokenType.Null) { double thresholdInstance = ((double)thresholdValue); metricTriggerInstance.Threshold = thresholdInstance; } } JToken scaleActionValue = rulesValue["ScaleAction"]; if (scaleActionValue != null && scaleActionValue.Type != JTokenType.Null) { ScaleAction scaleActionInstance = new ScaleAction(); scaleRuleInstance.ScaleAction = scaleActionInstance; JToken directionValue = scaleActionValue["Direction"]; if (directionValue != null && directionValue.Type != JTokenType.Null) { ScaleDirection directionInstance = ((ScaleDirection)Enum.Parse(typeof(ScaleDirection), ((string)directionValue), true)); scaleActionInstance.Direction = directionInstance; } JToken typeValue = scaleActionValue["Type"]; if (typeValue != null && typeValue.Type != JTokenType.Null) { ScaleType typeInstance = ((ScaleType)Enum.Parse(typeof(ScaleType), ((string)typeValue), true)); scaleActionInstance.Type = typeInstance; } JToken valueValue = scaleActionValue["Value"]; if (valueValue != null && valueValue.Type != JTokenType.Null) { string valueInstance = ((string)valueValue); scaleActionInstance.Value = valueInstance; } JToken cooldownValue = scaleActionValue["Cooldown"]; if (cooldownValue != null && cooldownValue.Type != JTokenType.Null) { TimeSpan cooldownInstance = TypeConversion.From8601TimeSpan(((string)cooldownValue)); scaleActionInstance.Cooldown = cooldownInstance; } } } } JToken fixedDateValue = profilesValue["FixedDate"]; if (fixedDateValue != null && fixedDateValue.Type != JTokenType.Null) { TimeWindow fixedDateInstance = new TimeWindow(); autoscaleProfileInstance.FixedDate = fixedDateInstance; JToken timeZoneValue = fixedDateValue["TimeZone"]; if (timeZoneValue != null && timeZoneValue.Type != JTokenType.Null) { string timeZoneInstance = ((string)timeZoneValue); fixedDateInstance.TimeZone = timeZoneInstance; } JToken startValue = fixedDateValue["Start"]; if (startValue != null && startValue.Type != JTokenType.Null) { DateTime startInstance = ((DateTime)startValue); fixedDateInstance.Start = startInstance; } JToken endValue = fixedDateValue["End"]; if (endValue != null && endValue.Type != JTokenType.Null) { DateTime endInstance = ((DateTime)endValue); fixedDateInstance.End = endInstance; } } JToken recurrenceValue = profilesValue["Recurrence"]; if (recurrenceValue != null && recurrenceValue.Type != JTokenType.Null) { Recurrence recurrenceInstance = new Recurrence(); autoscaleProfileInstance.Recurrence = recurrenceInstance; JToken frequencyValue = recurrenceValue["Frequency"]; if (frequencyValue != null && frequencyValue.Type != JTokenType.Null) { RecurrenceFrequency frequencyInstance = ((RecurrenceFrequency)Enum.Parse(typeof(RecurrenceFrequency), ((string)frequencyValue), true)); recurrenceInstance.Frequency = frequencyInstance; } JToken scheduleValue = recurrenceValue["Schedule"]; if (scheduleValue != null && scheduleValue.Type != JTokenType.Null) { RecurrentSchedule scheduleInstance = new RecurrentSchedule(); recurrenceInstance.Schedule = scheduleInstance; JToken timeZoneValue2 = scheduleValue["TimeZone"]; if (timeZoneValue2 != null && timeZoneValue2.Type != JTokenType.Null) { string timeZoneInstance2 = ((string)timeZoneValue2); scheduleInstance.TimeZone = timeZoneInstance2; } JToken daysArray = scheduleValue["Days"]; if (daysArray != null && daysArray.Type != JTokenType.Null) { foreach (JToken daysValue in ((JArray)daysArray)) { scheduleInstance.Days.Add(((string)daysValue)); } } JToken hoursArray = scheduleValue["Hours"]; if (hoursArray != null && hoursArray.Type != JTokenType.Null) { foreach (JToken hoursValue in ((JArray)hoursArray)) { scheduleInstance.Hours.Add(((int)hoursValue)); } } JToken minutesArray = scheduleValue["Minutes"]; if (minutesArray != null && minutesArray.Type != JTokenType.Null) { foreach (JToken minutesValue in ((JArray)minutesArray)) { scheduleInstance.Minutes.Add(((int)minutesValue)); } } } } } } JToken enabledValue = responseDoc["Enabled"]; if (enabledValue != null && enabledValue.Type != JTokenType.Null) { bool enabledInstance = ((bool)enabledValue); settingInstance.Enabled = enabledInstance; } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { Tracing.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
public static async Task <ScalingState> ScalingFunction( [OrchestrationTrigger] DurableOrchestrationContext context, ILogger log) { log.LogScalingFunction("Get new input."); var scalingState = context.GetInput <ScalingState>(); log.LogScalingFunction($"Scaling for {scalingState.CurrentPartOfPeriod} part of period."); log.LogScalingFunction("Waiting for event from Metrics Collection"); if (scalingState.Wait) { var @event = await context.WaitForExternalEvent <MetricCollected>(nameof(MetricCollected)); log.LogScalingFunction($"Update current metrics data."); scalingState.AddMetric(@event.Metric); } log.LogScalingFunction($"Prepare ARIMA model. Autoregresive: {AutoregresiveParam}, Integration: {IntegrationParam}, Move Averrage: {MoveAverrageParam}"); var vectorMetricsData = Vector.Create(scalingState.MetricData.ToArray()); var model = new ArimaModel(vectorMetricsData, AutoregresiveParam, IntegrationParam, MoveAverrageParam); model.EstimateMean = true; log.LogScalingFunction("Fit ARIMA model."); model.Fit(); log.LogScalingFunction("Forecast capacity for rest period."); var period = MasterPerformMetricsCollector.Period - scalingState.CurrentPartOfPeriod - 1; var forecastedData = model.Forecast(period); log.LogScalingFunction("Calculate capacity"); var capacityPerDay = forecastedData.Select(z => CapacityHelpers.CalculateCapacity(z)).ToList(); var cost = capacityPerDay.Select(z => CapacityHelpers.CalculateCostOfCapacity(z)).Sum(); var restCost = scalingState.RestCost - cost; var division = (int)restCost / period; if (division >= 1) { var additionalMachine = division > 2 ? division / MasterPerformMetricsCollector.Q : 1; capacityPerDay = capacityPerDay.Select(z => z + additionalMachine).ToList(); restCost -= (additionalMachine * capacityPerDay.Count); } log.LogScalingFunction("Get capacity for part of period."); var capacity = capacityPerDay.First(); log.LogScalingFunction($"Capacity to set: {capacity}"); var action = new ScaleAction(capacity); await context.CallActivityAsync(nameof(Scaler), action); log.LogScalingFunction("Start new Scaling Function with new scaling state."); scalingState.NextPart(CapacityHelpers.CalculateCostOfCapacity(capacity)); context.ContinueAsNew(scalingState); return(scalingState); }
public BaseAction GetAction() { if (actionType == ActionType.Move) { return(MoveAction.Create(v31.VarianceXY(variance), b1, b2, duration, Ease.FromType(easeType), direction)); } if (actionType == ActionType.HorizontalMove) { return(HMoveAction.Create(f1.Variance(variance), b1, b2, duration, Ease.FromType(easeType), direction)); } if (actionType == ActionType.VerticalMove) { return(VMoveAction.Create(f1.Variance(variance), b1, b2, duration, Ease.FromType(easeType), direction)); } if (actionType == ActionType.Scale) { return(ScaleAction.Create(v31.VarianceXY(variance), b1, duration, Ease.FromType(easeType), direction)); } if (actionType == ActionType.Rotate) { return(RotateAction.Create(f1.Variance(variance), b1, duration, Ease.FromType(easeType), direction)); } if (actionType == ActionType.Fade) { return(FadeAction.Create(f1.Variance(variance), b1, b2, duration, Ease.FromType(easeType), direction)); } if (actionType == ActionType.Tint) { return(TintAction.Create(c1.RGB().Variance(variance), b1, b2, duration, Ease.FromType(easeType), direction)); } if (actionType == ActionType.SetPosition) { return(SetPositionAction.Create(v31, v32, b1, b2)); } if (actionType == ActionType.SetScale) { return(SetScaleAction.Create(v31, v32, b1)); } if (actionType == ActionType.SetRotation) { return(SetRotationAction.Create(f1, f2)); } if (actionType == ActionType.SetAlpha) { return(SetAlphaAction.Create(f1, f2, b1)); } if (actionType == ActionType.SetRGB) { return(SetRGBAction.Create(c1.RGB(), c2.RGB(), b1)); } if (actionType == ActionType.Delay) { return(DelayAction.Create(duration, f2)); } if (actionType == ActionType.AnimatorTrigger) { return(AnimatorTriggerAction.Create(s1)); } if (actionType == ActionType.PlaySound) { return(PlaySoundAction.Create(soundId, soundType, f1)); } if (actionType == ActionType.CallEvent) { return(CallEventAction.Create(e1)); } if (actionType == ActionType.PlayParticleSystem) { return(PlayPSAction.Create(b1)); } return(null); }
void Start() { objFlipAction = otherObject.GetComponent("FlipAction") as FlipAction; objScaleAction = otherObject.GetComponent("ScaleAction") as ScaleAction; }
public void Reset() { ActionsTyped = new ScaleAction(); ActionsTyped.Transform = this.transform; ActionsTyped.sensibility = new Vector3(0.2F, 0.2F, 0.2F); }
// Update is called once per frame void Update() { if (running) { Action action = actionsList[actionIndex]; actionTime += Time.unscaledDeltaTime; if (action.type == ActionType.Fade) { FadeAction faction = (FadeAction)action; if (!faction.started) { faction.SetupColor(GetColor()); } if (actionTime >= action.time) { faction.started = false; SetColor(faction.targetColor); nextAction(); return; } SetColor(Color.Lerp(faction.originalColor, faction.targetColor, actionTime / action.time)); } else if (action.type == ActionType.Func) { ((FuncAction)action).function(); nextAction(); } else if (action.type == ActionType.Delay && actionTime >= action.time) { nextAction(); } else if (action.type == ActionType.ImageFill) { ImageFillAction iaction = (ImageFillAction)action; if (!iaction.started) { iaction.SetupFill(GetFillAmount()); } if (actionTime >= action.time) { iaction.started = false; SetFillAmount(iaction.targetFill); nextAction(); return; } SetFillAmount(Mathf.Lerp(iaction.originalFill, iaction.targetFill, actionTime / action.time)); } else if (action.type == ActionType.Scale) { ScaleAction saction = (ScaleAction)action; if (!saction.started) { saction.SetupScale(transform.localScale); } if (actionTime >= action.time) { saction.started = false; transform.localScale = saction.targetScale; nextAction(); return; } transform.localScale = Vector3.Lerp(saction.originalScale, saction.targetScale, actionTime / action.time); } else if (action.type == ActionType.Size) { SizeAction saction = (SizeAction)action; if (!saction.started) { saction.SetupSize(GetSize()); } if (actionTime >= action.time) { saction.started = false; SetSize(saction.targetSize); nextAction(); return; } Vector2 size = Vector2.Lerp(saction.originalSize, saction.targetSize, actionTime / action.time); SetSize(size); if (sizeUpdatebc && bc2d != null) { bc2d.size = size; bc2d.offset = new Vector2(size.x * pivot.x, size.y * pivot.y); } } } }
public async Task MonitorIncreasingControlQueueLoadDisconnected() { var settings = new AzureStorageOrchestrationServiceSettings() { StorageConnectionString = TestHelpers.GetTestStorageAccountConnectionString(), TaskHubName = nameof(MonitorIncreasingControlQueueLoadDisconnected), PartitionCount = 4, }; var service = new AzureStorageOrchestrationService(settings); var monitor = new DisconnectedPerformanceMonitor(settings.StorageConnectionString, settings.TaskHubName); int simulatedWorkerCount = 0; await service.CreateAsync(); // A heartbeat should come back with no recommendation since there is no data. PerformanceHeartbeat heartbeat = await monitor.PulseAsync(simulatedWorkerCount); Assert.IsNotNull(heartbeat); Assert.IsNotNull(heartbeat.ScaleRecommendation); Assert.AreEqual(ScaleAction.None, heartbeat.ScaleRecommendation.Action); Assert.IsFalse(heartbeat.ScaleRecommendation.KeepWorkersAlive); var client = new TaskHubClient(service); var previousTotalLatency = TimeSpan.Zero; for (int i = 1; i < settings.PartitionCount + 10; i++) { await client.CreateOrchestrationInstanceAsync(typeof(NoOpOrchestration), input : null); heartbeat = await monitor.PulseAsync(simulatedWorkerCount); Assert.IsNotNull(heartbeat); ScaleRecommendation recommendation = heartbeat.ScaleRecommendation; Assert.IsNotNull(recommendation); Assert.IsTrue(recommendation.KeepWorkersAlive); Assert.AreEqual(settings.PartitionCount, heartbeat.PartitionCount); Assert.AreEqual(settings.PartitionCount, heartbeat.ControlQueueLengths.Count); Assert.AreEqual(i, heartbeat.ControlQueueLengths.Sum()); Assert.AreEqual(0, heartbeat.WorkItemQueueLength); Assert.AreEqual(TimeSpan.Zero, heartbeat.WorkItemQueueLatency); TimeSpan currentTotalLatency = TimeSpan.FromTicks(heartbeat.ControlQueueLatencies.Sum(ts => ts.Ticks)); Assert.IsTrue(currentTotalLatency > previousTotalLatency); if (i + 1 < DisconnectedPerformanceMonitor.QueueLengthSampleSize) { int queuesWithNonZeroLatencies = heartbeat.ControlQueueLatencies.Count(t => t > TimeSpan.Zero); Assert.IsTrue(queuesWithNonZeroLatencies > 0 && queuesWithNonZeroLatencies <= i); int queuesWithAtLeastOneMessage = heartbeat.ControlQueueLengths.Count(l => l > 0); Assert.IsTrue(queuesWithAtLeastOneMessage > 0 && queuesWithAtLeastOneMessage <= i); ScaleAction expectedScaleAction = simulatedWorkerCount == 0 ? ScaleAction.AddWorker : ScaleAction.None; Assert.AreEqual(expectedScaleAction, recommendation.Action); } else { // Validate that control queue latencies are going up with each iteration. Assert.IsTrue(currentTotalLatency.Ticks > previousTotalLatency.Ticks); previousTotalLatency = currentTotalLatency; } Assert.AreEqual(0, heartbeat.WorkItemQueueLength); Assert.AreEqual(0.0, heartbeat.WorkItemQueueLatencyTrend); if (recommendation.Action == ScaleAction.AddWorker) { simulatedWorkerCount++; } // The high-latency threshold is 1 second Thread.Sleep(TimeSpan.FromSeconds(1.1)); } }
internal ScaleRecommendation(ScaleAction scaleAction, bool keepWorkersAlive, string reason) { this.Action = scaleAction; this.KeepWorkersAlive = keepWorkersAlive; this.Reason = reason; }
private static void ActionOnInstanceCount(ScaleAction action) { string deploymentInfo = AzureMngmntHandler.GetDeploymentInfo(); string svcconfig = AzureMngmntHandler.GetServiceConfig(deploymentInfo); int InstanceCount = System.Convert.ToInt32(AzureMngmntHandler.GetInstanceCount(svcconfig, "FTPServerRole")); if (action == ScaleAction.ScaleIn && InstanceCount > 1) { InstanceCount--; string UpdatedSvcConfig = AzureMngmntHandler.ChangeInstanceCount(svcconfig, "FTPServerRole", InstanceCount.ToString()); AzureMngmntHandler.ChangeConfigFile(UpdatedSvcConfig); } else if (action == ScaleAction.ScaleOut && InstanceCount < MAX_INSTANCE_COUNT) { InstanceCount++; string UpdatedSvcConfig = AzureMngmntHandler.ChangeInstanceCount(svcconfig, "FTPServerRole", InstanceCount.ToString()); AzureMngmntHandler.ChangeConfigFile(UpdatedSvcConfig); } }