func testDockerStop() {
	var response cpmserverapi.DockerStopResponse
	var err error
	request := &cpmserverapi.DockerStopRequest{}
	request.ContainerName = "testpoo"
	response, err = cpmserverapi.DockerStopClient("http://192.168.0.106:10001", request)
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println("returned " + response.Output)
}
func AdminStopNode(w rest.ResponseWriter, r *rest.Request) {
	dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
	if err != nil {
		logit.Error.Println("BackupNow: error " + err.Error())
		rest.Error(w, err.Error(), 400)
		return

	}
	defer dbConn.Close()

	err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
	if err != nil {
		logit.Error.Println("AdminStopNode: validate token error " + err.Error())
		rest.Error(w, err.Error(), http.StatusUnauthorized)
		return
	}

	ID := r.PathParam("ID")
	if ID == "" {
		logit.Error.Println("AdminStopNode: error ID required")
		rest.Error(w, "ID required", http.StatusBadRequest)
		return
	}

	node, err := admindb.GetContainer(dbConn, ID)
	if err != nil {
		logit.Error.Println("AdminStopNode:" + err.Error())
		rest.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	server := admindb.Server{}
	server, err = admindb.GetServer(dbConn, node.ServerID)
	if err != nil {
		logit.Error.Println("AdminStopNode:" + err.Error())
		rest.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	request := &cpmserverapi.DockerStopRequest{}
	request.ContainerName = node.Name
	var url = "http://" + server.IPAddress + ":10001"
	_, err = cpmserverapi.DockerStopClient(url, request)
	if err != nil {
		logit.Error.Println("AdminStopNode error when trying to stop container " + err.Error())
	}

	w.WriteHeader(http.StatusOK)
	status := SimpleStatus{}
	status.Status = "OK"
	w.WriteJson(&status)

}
func AdminStopServerContainers(w rest.ResponseWriter, r *rest.Request) {
	dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
	if err != nil {
		logit.Error.Println("BackupNow: error " + err.Error())
		rest.Error(w, err.Error(), 400)
		return

	}
	defer dbConn.Close()

	err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
	if err != nil {
		logit.Error.Println("AdminStopServerContainers: validate token error " + err.Error())
		rest.Error(w, err.Error(), http.StatusUnauthorized)
		return
	}

	//serverID
	serverid := r.PathParam("ID")
	if serverid == "" {
		logit.Error.Println("AdminStopoServerContainers: error ID required")
		rest.Error(w, "ID required", http.StatusBadRequest)
		return
	}

	//fetch the server
	containers, err := admindb.GetAllContainersForServer(dbConn, serverid)
	if err != nil {
		logit.Error.Println("AdminStopServerContainers:" + err.Error())
		rest.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	var url string
	//for each, get server, stop container
	for i := range containers {
		server := admindb.Server{}
		server, err = admindb.GetServer(dbConn, containers[i].ServerID)
		if err != nil {
			logit.Error.Println("AdminStopServerContainers:" + err.Error())
			rest.Error(w, err.Error(), http.StatusBadRequest)
			return
		}

		//send stop command before stopping container
		if containers[i].Role == "pgpool" {
			var stoppoolResp cpmcontainerapi.StopPgpoolResponse
			stoppoolResp, err = cpmcontainerapi.StopPgpoolClient(containers[i].Name)
			logit.Info.Println("AdminStoppg:" + stoppoolResp.Output)
		} else {
			var stopResp cpmcontainerapi.StopPGResponse
			stopResp, err = cpmcontainerapi.StopPGClient(containers[i].Name)
			logit.Info.Println("AdminStoppg:" + stopResp.Output)
		}
		if err != nil {
			logit.Error.Println("AdminStopServerContainers:" + err.Error())
			rest.Error(w, err.Error(), http.StatusBadRequest)
			return
		}

		time.Sleep(2000 * time.Millisecond)
		//stop container
		request := &cpmserverapi.DockerStopRequest{}
		request.ContainerName = containers[i].Name
		url = "http://" + server.IPAddress + ":10001"
		_, err = cpmserverapi.DockerStopClient(url, request)
		if err != nil {
			logit.Error.Println("AdminStopServerContainers: error when trying to start container " + err.Error())
		}
	}

	w.WriteHeader(http.StatusOK)
	status := SimpleStatus{}
	status.Status = "OK"
	w.WriteJson(&status)

}