=========================
Adding and removing nodes
=========================

You can view, add, edit and delete server nodes from Data Science & AI Workbench using
the Admin Console's Operations Center. If you would prefer to use a command
line to join additional nodes to the Workbench master, follow :ref:`the instructions
provided below <join-node>`.

**NOTES:**

* Workbench does not support running heterogeneous versions in the same
  cluster. Before adding a new node, *verify that the node is operating the same
  version of the OS as the rest of the cluster*.

* If you're adding a GPU node, make sure it meets the :ref:`GPU requirements
  <grav_gpu_reqs>`.

* Each installation can only support a single Workbench master node, as this node
  includes storage for the platform. **DO NOT add an additional Workbench master node
  to your installation**. 
     
--------------

**To manage the servers on your system:**

#. Log in to Workbench, select |menu| **Menu** in the top
   right corner and click the **Administrative Console** link displayed at the
   bottom of the slide out window. You must be logged in with a user assigned to
   the ``ae-admin`` role.
          
#. Click **Manage Resources**.

#. Log in to the Operations Center using the Administrator credentials
   :doc:`configured after installation <../../../install/config>`.

#. Select **Nodes** from the menu on the left to display the configured nodes
   in your cluster, their IP address, hostname and profile.

**To add an existing server to Workbench:**

#. Click the **Add Node** button at the top right.

   .. thumbnail:: ../../../images/add_node.png
      :align: center

#. Select an appropriate profile for the server and click **Continue**. 

#. Copy and paste the command provided into a terminal window to add the server. 

   When you refresh the page, your server will appear in the list.

**To remove a server node:**

Click |act-menu| **Actions** at the far right of the node you want to remove and select **Delete...**.

.. thumbnail:: ../../../images/server-delete.png
   :align: center

**To log on to a server:**

Click the |term-menu| terminal of the server you want to work with, and select **root** to open a terminal window. It will open a new tab in your browser.

.. thumbnail:: ../../../images/server-log-in.png
   :align: center

When you are finished, simply close the console window by clicking
|close| **Close**.

--------------

.. _join-node:

Using the command line to add nodes
===================================

#. Download the gravity binary that corresponds to your version of Workbench 
   from the S3 location provided to you by Anaconda onto the server
   you're adding to the cluster.

#. Rename the file to something simpler, then make it executable. For example::

     mv gravity-binary-6.1.9 gravity
     chmod +x gravity

#. *On the Workbench master*, run the following command to obtain the join token and
   IP address for the Workbench master node::

     gravity status

   The results should look similar to the following:

   .. thumbnail:: ../../../images/join-token.png
      :align: center

#. Copy and paste the join token for the cluster and the IP address for the Workbench
   master somewhere accessible. You'll need to provide this information when you
   add a new worker node. You'll also need the IP address of the server node
   you're adding.

#. *On the worker node*, run the following command to add the node to the cluster::

     ./gravity join --token JOIN-TOKEN --advertise-addr=NODE-IP --role=NODE-ROLE --cloud-provider=CLOUD-PROVIDER MASTER-IP-ADDR
     
   Where:

   ``JOIN-TOKEN`` = The join token that you obtained in Step 3.

   ``NODE-IP`` = The IP address of the worker node. This can be a private IP address, as long as the network it's on can access the Workbench master.

   ``NODE-ROLE`` = The type of node you're adding: ``ae-worker``, ``gpu-worker``, or ``k8s-master``.

   ``CLOUD-PROVIDER`` = This is auto-detected, and can therefore be excluded unless you don't have Internet access. In this case, use ``generic``.

   ``MASTER-IP-ADDR`` = The IP address of the Workbench master that you obtained in Step 3.

   .. warning::
      The ``--role`` flag must be provided and assigned to either ``ae-worker``, ``gpu-worker``, or ``k8s-master``. Without it, the node will be added with the role ``ae-master`` and may cause your cluster to crash.

   The progress of the join operation is displayed:

   .. thumbnail:: ../../../images/join-status2.png
      :align: center

#. To monitor the impact of the join operation on the cluster, run the ``gravity status`` command *on the Workbench master*. 

The output will look similar to the following:

.. thumbnail:: ../../../images/join-status.png
   :align: center

Note that the size of the cluster is ``expanding`` and the status of the new node being added is ``offline``. When the node has successfully joined, the cluster returns to an ``active`` state, and the status of the new node changes to ``healthy``:

.. thumbnail:: ../../../images/join-complete.png
   :align: center

.. |menu| image:: ../../../images/icons/menu.png
          :width: 25 px

.. |act-menu| image:: ../../../images/icons/actions-menu.png
              :width: 25 px

.. |term-menu| image:: ../../../images/icons/terminal-menu.png
          :width: 25 px

.. |close| image:: ../../../images/icons/close-terminal.png
          :width: 25 px
