Skip to content

Commit

Permalink
EE license fixes. (#5383) (#5384)
Browse files Browse the repository at this point in the history
( git cherry-pick 4e35cba)
Fixes DGRAPH-1341

This patch make several fixes and improvements
 -  Apply the option enterprise_license only after the node's Raft is initialized and it is the leader.
  - Don't apply the trial license if a license already exists.
  - Disallow the enterprise_license option for OSS build and bail out.
  - Apply the option even if there is a license from a previous life of the Zero (i.e. Zero is restarted with same the zw/
  • Loading branch information
parasssh authored May 7, 2020
1 parent 5566bdd commit a6df573
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
7 changes: 6 additions & 1 deletion dgraph/cmd/zero/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http"

"github.com/dgraph-io/badger/v2/y"
"github.com/dgraph-io/dgraph/protos/pb"
)

// dummy function as enterprise features are not available in oss binary.
Expand All @@ -38,6 +39,10 @@ func (st *state) applyEnterpriseLicense(w http.ResponseWriter, r *http.Request)
w.WriteHeader(http.StatusNotFound)
}

func (st *state) applyLicenseFile(path string) error {
func (s *Server) applyLicenseFile(path string) {
return
}

func (s *Server) license() *pb.License {
return nil
}
13 changes: 7 additions & 6 deletions dgraph/cmd/zero/license_ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (n *node) proposeTrialLicense() error {
return err

}
glog.Infof("Enterprise state proposed to the cluster: %v", proposal)
glog.Infof("Enterprise trial license proposed to the cluster: %v", proposal)
return nil
}

Expand Down Expand Up @@ -135,14 +135,15 @@ func (st *state) applyEnterpriseLicense(w http.ResponseWriter, r *http.Request)
}
}

// applyLicenseFile applies the license file stored at the given path.
func (st *state) applyLicenseFile(path string) error {
func (s *Server) applyLicenseFile(path string) {
content, err := ioutil.ReadFile(path)
if err != nil {
return err
glog.Infof("Unable to apply license at %v due to error %v", path, err)
return
}

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
return st.zero.applyLicense(ctx, bytes.NewReader(content))
if err = s.applyLicense(ctx, bytes.NewReader(content)); err != nil {
glog.Infof("Unable to apply license at %v due to error %v", path, err)
}
}
19 changes: 17 additions & 2 deletions dgraph/cmd/zero/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,11 @@ func (n *node) initAndStartNode() error {
time.Sleep(3 * time.Second)
}

if err := n.proposeTrialLicense(); err != nil {
glog.Errorf("while proposing trial license to cluster: %v", err)
// Apply trial license only if not already licensed.
if n.server.license() == nil {
if err := n.proposeTrialLicense(); err != nil {
glog.Errorf("while proposing trial license to cluster: %v", err)
}
}
}()
}
Expand Down Expand Up @@ -618,6 +621,7 @@ func (n *node) trySnapshot(skip uint64) {

func (n *node) Run() {
var leader bool
licenseApplied := false
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()

Expand Down Expand Up @@ -735,6 +739,17 @@ func (n *node) Run() {
" Num entries: %d. MustSync: %v",
timer.String(), len(rd.Entries), rd.MustSync)
}

// Apply license when I am the leader.
if !licenseApplied && n.AmLeader() {
licenseApplied = true
// Apply the EE License given on CLI which may over-ride previous
// license, if present. That is an intended behavior to allow customers
// to apply new/renewed licenses.
if license := Zero.Conf.GetString("enterprise_license"); len(license) > 0 {
go n.server.applyLicenseFile(license)
}
}
}
}
}
12 changes: 4 additions & 8 deletions dgraph/cmd/zero/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ func run() {
LudicrousMode: Zero.Conf.GetBool("ludicrous_mode"),
}

if !enc.EeBuild && Zero.Conf.GetString("enterprise_license") != "" {
log.Fatalf("ERROR: enterprise_license option cannot be applied to OSS builds. ")
}

if opts.numReplicas < 0 || opts.numReplicas%2 == 0 {
log.Fatalf("ERROR: Number of replicas must be odd for consensus. Found: %d",
opts.numReplicas)
Expand Down Expand Up @@ -241,14 +245,6 @@ func run() {
st.serveGRPC(grpcListener, store)
st.serveHTTP(httpListener)

// Apply enterprise license if one was given.
if license := Zero.Conf.GetString("enterprise_license"); len(license) > 0 {
if err := st.applyLicenseFile(license); err != nil {
glog.Warningf("Applying enterprise license file %s failed with error: %s", license,
err.Error())
}
}

http.HandleFunc("/health", st.pingResponse)
http.HandleFunc("/state", st.getState)
http.HandleFunc("/removeNode", st.removeNode)
Expand Down
2 changes: 1 addition & 1 deletion dgraph/cmd/zero/zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,6 @@ func (s *Server) applyLicense(ctx context.Context, signedData io.Reader) error {
if err != nil {
return errors.Wrapf(err, "while proposing enterprise license state to cluster")
}
glog.Infof("Enterprise license state proposed to the cluster")
glog.Infof("Enterprise license proposed to the cluster %+v", proposal)
return nil
}

0 comments on commit a6df573

Please sign in to comment.