github.com/kubewharf/katalyst-core@v0.5.3/pkg/agent/resourcemanager/reporter/manager_stub.go (about)

     1  /*
     2  Copyright 2022 The Katalyst Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package reporter
    18  
    19  import (
    20  	"context"
    21  	"sync"
    22  
    23  	"github.com/kubewharf/katalyst-api/pkg/protocol/reporterplugin/v1alpha1"
    24  )
    25  
    26  // ManagerStub a reporter manager stub
    27  type ManagerStub struct {
    28  	mutex                 sync.RWMutex
    29  	reportContentResponse map[string]*v1alpha1.GetReportContentResponse
    30  }
    31  
    32  // Run start the reporter manager stub
    33  func (s *ManagerStub) Run(context.Context) {}
    34  
    35  // NewReporterManagerStub new a reporter stub
    36  func NewReporterManagerStub() *ManagerStub {
    37  	return &ManagerStub{
    38  		reportContentResponse: make(map[string]*v1alpha1.GetReportContentResponse),
    39  	}
    40  }
    41  
    42  // PushContents store response to local cache
    43  func (s *ManagerStub) PushContents(_ context.Context, responses map[string]*v1alpha1.GetReportContentResponse) error {
    44  	s.mutex.Lock()
    45  	defer s.mutex.Unlock()
    46  
    47  	s.reportContentResponse = responses
    48  	return nil
    49  }
    50  
    51  // GetReportContentResponse get reporter content from local cache
    52  func (s *ManagerStub) GetReportContentResponse(pluginName string) *v1alpha1.GetReportContentResponse {
    53  	s.mutex.RLock()
    54  	defer s.mutex.RUnlock()
    55  
    56  	return s.reportContentResponse[pluginName]
    57  }