/*
   * Adds Server on the specified Cluster
   */
  public boolean addServer(ServerMap serverMap) {
    storageSahiTasks.selectPage(serverMap.getResourceLocation());
    storageSahiTasks.clickRefresh("Host");
    if (serverMap.isPositive()) {
      if (storageSahiTasks.div(serverMap.getServerName()).exists()) {
        failTest("Server [" + serverMap.getServerName() + "] is already on the list!");
        return false;
      }
    } else {
      if (serverMap.getServerAlreadyOnList()) {
        if (!storageSahiTasks.div(serverMap.getServerName()).exists()) {
          failTest(
              "Pre-Requirement not met: Server ["
                  + serverMap.getServerName()
                  + "] not available on the list!");
          return false;
        }
      } else {
        if (storageSahiTasks.div(serverMap.getServerName()).exists()) {
          failTest(
              "Pre-Requirement not met: Server ["
                  + serverMap.getServerName()
                  + "] already on the list!");
          return false;
        }
      }
    }

    storageSahiTasks.div("MainTabHostView_table_New").click();
    storageSahiTasks.select("HostPopupView_cluster").choose(serverMap.getClusterName());
    storageSahiTasks.textbox("HostPopupView_name").setValue(serverMap.getServerName());
    storageSahiTasks.textbox("HostPopupView_host").setValue(serverMap.getServerHostIP());
    storageSahiTasks.password("HostPopupView_userPassword").setValue(serverMap.getServerPassword());
    // storageSahiTasks.div("HostPopupView_OnSaveFalse").click();
    // storageSahiTasks.clickRefresh("Host");
    for (int i = 0; i < 10; i++) {
      if (storageSahiTasks.div("OK").exists()) {
        storageSahiTasks.div("OK").click();
      }
    }
    if (serverMap.isPositive()) {
      if (!waitForServerUpStatus(serverMap)) {
        failTest("timed out waiting for sever status to be in Up status");
        return false;
      }
    } else {
      if (storageSahiTasks.div("/" + serverMap.getErrorMsg() + "/i").exists()) {
        storageSahiTasks._logger.log(
            Level.FINE, "Volume [" + serverMap.getServerName() + "] server error pop-up appeared!");
        storageSahiTasks.closePopup("Close");
        storageSahiTasks.div("HostPopupView_Cancel").click();
        return true;
      } else {
        closeErrorDialogIfExists();
        cancelServerCreateDialogIfExists();
        failTest("Volume [" + serverMap.getServerName() + "] server error pop-up did not appear!");
        return false;
      }
    }

    return true;
  }
  /*
   * Removes the specified server
   */
  public boolean removeServer(ServerMap serverMap) {
    int wait = 1000;
    int retryCount = 35;

    if (!storageSahiTasks.selectPage(serverMap.getResourceLocation())) {
      return false;
    }
    storageSahiTasks.clickRefresh("Host");

    HashMap<String, String> row = moveServerToMaintenanceMode(serverMap);
    if (row == null) {
      return false;
    }

    for (int y = 0; y < 3; y++) {
      storageSahiTasks.div(serverMap.getServerHostIP()).click();
      storageSahiTasks.div("MainTabHostView_table_Remove").click();
      storageSahiTasks.div("RemoveConfirmationPopupView_OnRemove").click();

      storageSahiTasks.waitFor(5000);

      if (storageSahiTasks
          .div("Cannot remove Host. Related operation is currently in progress")
          .exists()) {
        storageSahiTasks._logger.log(
            Level.WARNING,
            "Server["
                + serverMap.getServerName()
                + "("
                + serverMap.getServerHostIP()
                + ")] Error: operation in progress!");
        storageSahiTasks.closePopup("Close");
      } else {
        break;
      }
    }

    if (serverMap.getErrorMsg() != null) { // Server having bricks should not be removed.
      if (storageSahiTasks.div(serverMap.getErrorMsg()).exists()) {
        storageSahiTasks.closePopup("Close");
        // this.div(serverMap.getServerName()).click();
        storageSahiTasks.div(row.get(GuiTables.NAME)).click();
        storageSahiTasks.div("Activate").click();
        return true;
      }
    }
    storageSahiTasks.clickRefresh("Host");

    for (int x = 0; x < retryCount; x++) {
      if (!storageSahiTasks.div(serverMap.getServerHostIP()).exists()) {
        break;
      } else {
        storageSahiTasks.wait(wait, retryCount, x);
      }
    }

    if (storageSahiTasks.div(serverMap.getServerHostIP()).exists()) {
      storageSahiTasks._logger.log(
          Level.WARNING,
          "Server["
              + serverMap.getServerName()
              + "("
              + serverMap.getServerHostIP()
              + ")] is available on the list!");
      return false;
    }

    return true;
  }