// processEvent is the callback function that will be executed for every event
// in the EventQueue.
processEvent is the callback function that will be executed for every event
in the EventQueue.
// processEvent is the callback function that will be executed for every event // in the EventQueue .
func (c *AppGwIngressController) processEvent(eventQueueElementInterface interface{}) (bool, error) {
	event := eventQueueElementInterface.(eventQueueElement)
	glog.V(1).Infof("controller.processEvent called with type %T", event.Element)
	ctx := context.Background()
	appGw, err := c.appGwClient.Get(ctx, c.appGwIdentifier.ResourceGroup, c.appGwIdentifier.AppGwName)
	if err != nil {
		glog.Errorf("unable to get specified ApplicationGateway [%v], check ApplicationGateway identifier, error=[%v]", c.appGwIdentifier.AppGwName, err.Error())
		return false, errors.New("unable to get specified ApplicationGateway")
	}
	configBuilder := appgw.NewAppGwConfigBuilder(c.k8sContext, &c.appGwIdentifier, appGw.ApplicationGatewayPropertiesFormat)
	ingressList := c.k8sContext.GetHTTPIngressList()
	configBuilder, err = configBuilder.BackendHTTPSettingsCollection(ingressList)
	if err != nil {
		glog.Errorf("unable to generate backend http settings, error [%v]", err.Error())
		return false, errors.New("unable to generate backend http settings")
	}
	configBuilder, err = configBuilder.BackendAddressPools(ingressList)
	if err != nil {
		glog.Errorf("unable to generate backend address pools, error [%v]", err.Error())
		return false, errors.New("unable to generate backend address pools")
	}
	configBuilder, err = configBuilder.HTTPListeners(ingressList)
	if err != nil {
		glog.Errorf("unable to generate frontend listeners, error [%v]", err.Error())
		return false, errors.New("unable to generate frontend listeners")
	}
	configBuilder, err = configBuilder.RequestRoutingRules(ingressList)
	if err != nil {
		glog.Errorf("unable to generate request routing rules, error [%v]", err.Error())
		return false, errors.New("unable to generate request routing rules")
	}
	appGw.ApplicationGatewayPropertiesFormat = configBuilder.Build()
	glog.V(1).Info("~~~~~~~~ ↓ ApplicationGateway deployment ↓ ~~~~~~~~")
	defer glog.V(1).Info("~~~~~~~~ ↑ ApplicationGateway deployment ↑ ~~~~~~~~")
	deploymentStart := time.Now()
	appGwFuture, err := c.appGwClient.CreateOrUpdate(ctx, c.appGwIdentifier.ResourceGroup, c.appGwIdentifier.AppGwName, appGw)
	if err != nil {
		glog.Warningf("unable to send CreateOrUpdate request, error [%v]", err.Error())
		return false, errors.New("unable to send CreateOrUpdate request")
	}
	err = appGwFuture.WaitForCompletionRef(ctx, c.appGwClient.BaseClient.Client)
	deploymentElapsed := time.Now().Sub(deploymentStart)
	glog.V(1).Infof("deployment took %v", deploymentElapsed.String())
	if err != nil {
		glog.Warningf("unable to deploy ApplicationGateway, error [%v]", err.Error())
		return false, errors.New("unable to deploy ApplicationGateway")
	}
	return true, nil
}
func ( c * AppGwIngressController ) processEvent ( eventQueueElementInterface interface { } ) ( bool , error ) { event := eventQueueElementInterface . ( eventQueueElement ) glog . V ( 1 ) . Infof ( " " , event . Element ) ctx := context . Background ( ) appGw , err := c . appGwClient . Get ( ctx , c . appGwIdentifier . ResourceGroup , c . appGwIdentifier . AppGwName ) if err != nil { glog . Errorf ( " " , c . appGwIdentifier . AppGwName , err . Error ( ) ) return false , errors . New ( " " ) } configBuilder := appgw . NewAppGwConfigBuilder ( c . k8sContext , & c . appGwIdentifier , appGw . ApplicationGatewayPropertiesFormat ) ingressList := c . k8sContext . GetHTTPIngressList ( ) configBuilder , err = configBuilder . BackendHTTPSettingsCollection ( ingressList ) if err != nil { glog . Errorf ( " " , err . Error ( ) ) return false , errors . New ( " " ) } configBuilder , err = configBuilder . BackendAddressPools ( ingressList ) if err != nil { glog . Errorf ( " " , err . Error ( ) ) return false , errors . New ( " " ) } configBuilder , err = configBuilder . HTTPListeners ( ingressList ) if err != nil { glog . Errorf ( " " , err . Error ( ) ) return false , errors . New ( " " ) } configBuilder , err = configBuilder . RequestRoutingRules ( ingressList ) if err != nil { glog . Errorf ( " " , err . Error ( ) ) return false , errors . New ( " " ) } appGw . ApplicationGatewayPropertiesFormat = configBuilder . Build ( ) glog . V ( 1 ) . Info ( " defer glog . V ( 1 ) . Info ( " deploymentStart := time . Now ( ) appGwFuture , err := c . appGwClient . CreateOrUpdate ( ctx , c . appGwIdentifier . ResourceGroup , c . appGwIdentifier . AppGwName , appGw ) if err != nil { glog . Warningf ( " " , err . Error ( ) ) return false , errors . New ( " " ) } err = appGwFuture . WaitForCompletionRef ( ctx , c . appGwClient . BaseClient . Client ) deploymentElapsed := time . Now ( ) . Sub ( deploymentStart ) glog . V ( 1 ) . Infof ( " " , deploymentElapsed . String ( ) ) if err != nil { glog . Warningf ( " " , err . Error ( ) ) return false , errors . New ( " " ) } return true , nil }
processEvent is the callback function that will be executed for every event
in the EventQueue.
processEvent is the callback function that will be executed for every event in the EventQueue .
// Get current application gateway config // Create a configbuilder based on current appgw config // Get all the ingresses // The following operations need to be in sequence // BackendAddressPools depend on BackendHTTPSettings // HTTPListener configures the frontend listeners // RequestRoutingRules depends on the previous operations // Replace the current appgw config with the generated one // Initiate deployment // Wait until deployment finshes and save the error message