github.com/sap/cf-mta-plugin@v2.6.3+incompatible/clients/mtaclient_v2/retryable_mta_v2_rest_client.go (about)

     1  package mtaclient_v2
     2  
     3  import (
     4  	"net/http"
     5  	"time"
     6  
     7  	"github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/baseclient"
     8  	"github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/models"
     9  )
    10  
    11  type RetryableMtaRestClient struct {
    12  	mtaClient       MtaV2ClientOperations
    13  	MaxRetriesCount int
    14  	RetryInterval   time.Duration
    15  }
    16  
    17  func NewRetryableMtaRestClient(host string, spaceGUID string, rt http.RoundTripper, tokenFactory baseclient.TokenFactory) RetryableMtaRestClient {
    18  	mtaClient := NewMtaClient(host, spaceGUID, rt, tokenFactory)
    19  	return RetryableMtaRestClient{mtaClient: mtaClient, MaxRetriesCount: 3, RetryInterval: time.Second * 3}
    20  }
    21  
    22  func (c RetryableMtaRestClient) GetMtas(name, namespace *string, spaceGuid string) ([]*models.Mta, error) {
    23  	getMtasCb := func() (interface{}, error) {
    24  		return c.mtaClient.GetMtas(name, namespace, spaceGuid)
    25  	}
    26  	resp, err := baseclient.CallWithRetry(getMtasCb, c.MaxRetriesCount, c.RetryInterval)
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  	return resp.([]*models.Mta), nil
    31  }
    32  
    33  func (c RetryableMtaRestClient) GetMtasForThisSpace(name, namespace *string) ([]*models.Mta, error) {
    34  	getMtasCb := func() (interface{}, error) {
    35  		return c.mtaClient.GetMtasForThisSpace(name, namespace)
    36  	}
    37  	resp, err := baseclient.CallWithRetry(getMtasCb, c.MaxRetriesCount, c.RetryInterval)
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  	return resp.([]*models.Mta), nil
    42  }