wilfred-s commented on a change in pull request #72: Add ability to support 3rd 
party K8s operator integration
URL: 
https://github.com/apache/incubator-yunikorn-k8shim/pull/72#discussion_r382575687
 
 

 ##########
 File path: pkg/appmgmt/appmgmt_recovery.go
 ##########
 @@ -0,0 +1,93 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package appmgmt
+
+import (
+       "fmt"
+       "time"
+
+       "github.com/apache/incubator-yunikorn-k8shim/pkg/appmgmt/interfaces"
+       "github.com/apache/incubator-yunikorn-k8shim/pkg/common/events"
+       "github.com/apache/incubator-yunikorn-k8shim/pkg/common/utils"
+       "github.com/apache/incubator-yunikorn-k8shim/pkg/log"
+       "go.uber.org/zap"
+)
+
+func (svc *AppManagementService) WaitForRecovery(maxTimeout time.Duration) 
error {
+       if !svc.apiProvider.IsTestingMode() {
+               apps := svc.kickoffRecovery()
+               return svc.waitForAppRecovery(apps, maxTimeout)
+       }
+       return nil
+}
+
+func (svc *AppManagementService) kickoffRecovery() 
map[string]interfaces.ManagedApp {
+       recoveringApps := make(map[string]interfaces.ManagedApp)
+       for _, mgr := range svc.managers {
+               if m, ok := mgr.(interfaces.Recoverable); ok {
+                       appMetas, err := m.ListApplications()
+                       if err != nil {
+                               log.Logger.Error("failed to list apps", 
zap.Error(err))
+                               return recoveringApps
+                       }
+
+                       // trigger recovery of the apps
+                       // this is simply submit the app again
+                       for _, appMeta := range appMetas {
+                               if app, recovering := 
svc.amProtocol.AddApplication(
+                                       &interfaces.AddApplicationRequest{
+                                               Metadata: appMeta,
+                                               Recovery: true,
+                                       }); recovering {
+                                       recoveringApps[app.GetApplicationID()] 
= app
+                               }
+                       }
+               }
+       }
+       return recoveringApps
+}
+
+func (svc *AppManagementService) waitForAppRecovery(
+       recoveringApps map[string]interfaces.ManagedApp, maxTimeout 
time.Duration) error {
+       if len(recoveringApps) > 0 {
+               // check app states periodically, ensure all apps exit from 
recovering state
+               if err := utils.WaitForCondition(func() bool {
+                       for _, app := range recoveringApps {
+                               log.Logger.Info("appInfo",
+                                       zap.String("appId", 
app.GetApplicationID()),
+                                       zap.String("state", 
app.GetApplicationState()))
 
 Review comment:
   This could generate a lot of logs, repeating the same app over and over 
again.
   We should do this inside the `if` when  the app is restored.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to