github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/upgrade_cluster/send_notification.go (about) 1 package upgrade_cluster 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/sirupsen/logrus" 8 9 "github.com/kyma-project/kyma-environment-broker/internal" 10 kebError "github.com/kyma-project/kyma-environment-broker/internal/error" 11 "github.com/kyma-project/kyma-environment-broker/internal/notification" 12 "github.com/kyma-project/kyma-environment-broker/internal/process" 13 "github.com/kyma-project/kyma-environment-broker/internal/storage" 14 ) 15 16 type SendNotificationStep struct { 17 operationManager *process.UpgradeClusterOperationManager 18 bundleBuilder notification.BundleBuilder 19 } 20 21 func (s *SendNotificationStep) Name() string { 22 return "Send_Notification" 23 } 24 25 func NewSendNotificationStep(os storage.Operations, bundleBuilder notification.BundleBuilder) *SendNotificationStep { 26 return &SendNotificationStep{ 27 operationManager: process.NewUpgradeClusterOperationManager(os), 28 bundleBuilder: bundleBuilder, 29 } 30 } 31 32 func (s *SendNotificationStep) Run(operation internal.UpgradeClusterOperation, log logrus.FieldLogger) (internal.UpgradeClusterOperation, time.Duration, error) { 33 if operation.RuntimeOperation.Notification { 34 tenants := []notification.NotificationTenant{ 35 { 36 InstanceID: operation.InstanceID, 37 StartDate: time.Now().Format("2006-01-02 15:04:05"), 38 State: notification.UnderMaintenanceEventState, 39 }, 40 } 41 notificationParams := notification.NotificationParams{ 42 OrchestrationID: operation.OrchestrationID, 43 Tenants: tenants, 44 } 45 notificationBundle, err := s.bundleBuilder.NewBundle(operation.OrchestrationID, notificationParams) 46 if err != nil { 47 log.Errorf("%s: %s", "Failed to create Notification Bundle", err) 48 return operation, 5 * time.Second, nil 49 } 50 51 log.Infof("Sending http request to customer notification service") 52 err = notificationBundle.UpdateNotificationEvent() 53 //currently notification error can only be temporary error 54 if err != nil && kebError.IsTemporaryError(err) { 55 msg := fmt.Sprintf("cannot update notification for orchestration %s", operation.OrchestrationID) 56 log.Errorf("%s: %s", msg, err) 57 return operation, 5 * time.Second, nil 58 } 59 } 60 61 return operation, 0, nil 62 }