Upgrades the cluster to the provided dgraph version
(version string, strategy UpgradeStrategy)
| 902 | |
| 903 | // Upgrades the cluster to the provided dgraph version |
| 904 | func (c *LocalCluster) Upgrade(version string, strategy UpgradeStrategy) error { |
| 905 | if version == c.conf.version { |
| 906 | return fmt.Errorf("cannot upgrade to the same version") |
| 907 | } |
| 908 | |
| 909 | log.Printf("[INFO] upgrading the cluster from [%v] to [%v] using [%v]", c.conf.version, version, strategy) |
| 910 | switch strategy { |
| 911 | case BackupRestore: |
| 912 | hc, err := c.HTTPClient() |
| 913 | if err != nil { |
| 914 | return err |
| 915 | } |
| 916 | if c.conf.acl { |
| 917 | if err := hc.LoginIntoNamespace(dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.RootNamespace); err != nil { |
| 918 | return errors.Wrapf(err, "error during login before upgrade") |
| 919 | } |
| 920 | } |
| 921 | if err := hc.Backup(c, true, DefaultBackupDir); err != nil { |
| 922 | return errors.Wrap(err, "error taking backup during upgrade") |
| 923 | } |
| 924 | if err := c.Stop(); err != nil { |
| 925 | return err |
| 926 | } |
| 927 | c.conf.version = version |
| 928 | if err := c.recreateContainers(); err != nil { |
| 929 | return err |
| 930 | } |
| 931 | if err := c.Start(); err != nil { |
| 932 | return err |
| 933 | } |
| 934 | |
| 935 | hc, err = c.HTTPClient() |
| 936 | if err != nil { |
| 937 | return errors.Wrapf(err, "error creating HTTP client after upgrade") |
| 938 | } |
| 939 | if c.conf.acl { |
| 940 | if err := hc.LoginIntoNamespace(dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.RootNamespace); err != nil { |
| 941 | return errors.Wrapf(err, "error during login after upgrade") |
| 942 | } |
| 943 | } |
| 944 | if err := hc.Restore(c, DefaultBackupDir, "", 0, 1); err != nil { |
| 945 | return errors.Wrap(err, "error doing restore during upgrade") |
| 946 | } |
| 947 | if err := dgraphapi.WaitForRestore(c); err != nil { |
| 948 | return errors.Wrap(err, "error waiting for restore to complete") |
| 949 | } |
| 950 | return nil |
| 951 | |
| 952 | case ExportImport: |
| 953 | hc, err := c.HTTPClient() |
| 954 | if err != nil { |
| 955 | return err |
| 956 | } |
| 957 | if c.conf.acl { |
| 958 | if err := hc.LoginIntoNamespace(dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.RootNamespace); err != nil { |
| 959 | return errors.Wrapf(err, "error during login before upgrade") |
| 960 | } |
| 961 | } |