github.com/Cloud-Foundations/Dominator@v0.3.4/objectserver/rpcd/api.go (about)

     1  package rpcd
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/Cloud-Foundations/Dominator/lib/log"
     7  	"github.com/Cloud-Foundations/Dominator/lib/objectserver"
     8  	"github.com/Cloud-Foundations/Dominator/lib/srpc"
     9  	"github.com/Cloud-Foundations/tricorder/go/tricorder"
    10  	"github.com/Cloud-Foundations/tricorder/go/tricorder/units"
    11  )
    12  
    13  type Config struct {
    14  	AllowPublicAddObjects   bool
    15  	AllowPublicCheckObjects bool
    16  	AllowPublicGetObjects   bool
    17  	ReplicationMaster       string
    18  }
    19  
    20  type Params struct {
    21  	Logger       log.DebugLogger
    22  	ObjectServer objectserver.StashingObjectServer
    23  }
    24  
    25  type srpcType struct {
    26  	objectServer      objectserver.StashingObjectServer
    27  	replicationMaster string
    28  	getSemaphore      chan bool
    29  	logger            log.DebugLogger
    30  }
    31  
    32  type htmlWriter struct {
    33  	getSemaphore chan bool
    34  }
    35  
    36  func (hw *htmlWriter) WriteHtml(writer io.Writer) {
    37  	hw.writeHtml(writer)
    38  }
    39  
    40  func Setup(config Config, params Params) *htmlWriter {
    41  	getSemaphore := make(chan bool, 100)
    42  	srpcObj := &srpcType{
    43  		objectServer:      params.ObjectServer,
    44  		replicationMaster: config.ReplicationMaster,
    45  		getSemaphore:      getSemaphore,
    46  		logger:            params.Logger,
    47  	}
    48  	var publicMethods []string
    49  	if config.AllowPublicAddObjects {
    50  		publicMethods = append(publicMethods, "AddObjects")
    51  	}
    52  	if config.AllowPublicCheckObjects {
    53  		publicMethods = append(publicMethods, "CheckObjects")
    54  	}
    55  	if config.AllowPublicGetObjects {
    56  		publicMethods = append(publicMethods, "GetObjects")
    57  	}
    58  	srpc.RegisterNameWithOptions("ObjectServer", srpcObj,
    59  		srpc.ReceiverOptions{PublicMethods: publicMethods})
    60  	tricorder.RegisterMetric("/get-requests",
    61  		func() uint { return uint(len(getSemaphore)) },
    62  		units.None, "number of GetObjects() requests in progress")
    63  	return &htmlWriter{getSemaphore}
    64  }