func (t *Task) Reconfigure() (err error) {
	service, err := services.NewService("pgbouncer")
	if err != nil {
		log.Error(fmt.Sprintf(`tasks.Task#Reconfigure(%s) services.NewService(pgbouncer) ! %s`, t.ClusterID, err))
	}
	err = service.Configure()
	if err != nil {
		log.Error(fmt.Sprintf(`tasks.TaskReconfigure(%s) service.Configure() ! %s`, t.ClusterID, err))
	}
	return
}
func (r *RDPG) reconfigureServices() (err error) {
	svcs := []string{`pgbdr`, `pgbouncer`, `haproxy`}
	for index, _ := range svcs {
		s, err := services.NewService(svcs[index])
		err = s.Configure()
		if err != nil {
			log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#reconfigureServices() s.Configure(%s) ! %s`, ClusterID, svcs[index], err))
		}
	}
	return
}
Exemple #3
0
/*
POST /services/{service}/{action}
*/
func ServiceHandler(w http.ResponseWriter, request *http.Request) {
	vars := mux.Vars(request)
	log.Trace(fmt.Sprintf(`%s /services/%s/%s`, request.Method, vars[`service`], vars[`action`]))
	switch request.Method {
	case `PUT`:
		service, err := services.NewService(vars[`service`])
		if err != nil {
			msg := fmt.Sprintf(`{"status": %d, "description": "%s"}`+"\n", http.StatusInternalServerError, err)
			log.Error(fmt.Sprintf(`admin.ServiceHandler(): NewService(%s) %+v %s`, service, vars, msg))
			http.Error(w, msg, http.StatusInternalServerError)
			return
		}

		switch vars[`action`] {
		case `configure`:
			err := service.Configure()
			if err != nil {
				msg := fmt.Sprintf(`{"status": %d, "description": "%s"}`+"\n", http.StatusInternalServerError, err)
				log.Error(fmt.Sprintf(`admin.ServiceHandler(): NewService(%s) %+v %s`, service, vars, msg))
				http.Error(w, msg, http.StatusInternalServerError)
			}
			msg := fmt.Sprintf(`{"status": %d, "description": "%s %s"}`+"\n", http.StatusOK, vars[`service`], vars[`action`])
			log.Trace(fmt.Sprintf(`admin.ServiceHandler(): NewService(%s) %s`, service, msg))
			w.WriteHeader(http.StatusOK)
			fmt.Fprintf(w, msg)
		default:
			msg := fmt.Sprintf(`{"status": %d, "description": "Invalid Action %s for %s"}`+"\n", http.StatusBadRequest, vars[`action`], vars[`service`])
			log.Error(fmt.Sprintf(`admin.ServiceHandler(): NewService(%s) %s`, service, msg))
			http.Error(w, msg, http.StatusBadRequest)
		}
	default:
		msg := fmt.Sprintf(`{"status": %d, "description": "Method not allowed %s"}`+"\n", http.StatusMethodNotAllowed, request.Method)
		log.Error(fmt.Sprintf(`admin.ServiceHandler(): NewService() %+v %s`, vars, msg))
		http.Error(w, msg, http.StatusMethodNotAllowed)
	}
}
Exemple #4
0
// Bootstrap the RDPG Database and associated services.
func Bootstrap() (err error) {
	r := newRDPG()
	log.Info(fmt.Sprintf(`rdpg.RDPG<%s>#Bootstrap() Bootstrapping Cluster Node...`, ClusterID))
	err = r.initialBootstrap()
	if err != nil {
		log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#Bootstrap() r.initialBootstrap() ! %s`, ClusterID, err))
		return
	}
	// Record clusterService in consul
	kv := r.ConsulClient.KV()
	key := fmt.Sprintf(`rdpg/%s/cluster/service`, ClusterID)
	kvp := &consulapi.KVPair{Key: key, Value: []byte(globals.ClusterService)}
	_, err = kv.Put(kvp, &consulapi.WriteOptions{})
	if err != nil {
		log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#BootStrap(): key=%s globals.ClusterService=%s ! %s`, ClusterID, key, globals.ClusterService, err))
	}

	s, err := services.NewService(globals.ClusterService) // postgresql or pgbdr
	err = s.Configure()
	if err != nil {
		log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#Bootstrap() s.Configure(%s) ! %s`, ClusterID, globals.ClusterService, err))
	}

	if globals.ClusterService == "pgbdr" {
		r.bdrBootstrap()
	} else { // TODO: This will be a switch statement when we have more than 2 service types.

		err = r.serviceClusterCapacityStore()
		if err != nil {
			log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#bootstrapSystem() Store Service CLuster Instance Capacity in Consul KeyValue! %s`, ClusterID, err))
			return
		}

		err = r.bootstrapSystem()
		if err != nil {
			log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#bdrLeaderBootstrap() r.bootstrapSystem(%s,%s) ! %s`, ClusterID, globals.ServiceRole, globals.ClusterService, err))
			return
		}
	}

	svcs := []string{`pgbouncer`, `haproxy`}
	for index := range svcs {
		s, err := services.NewService(svcs[index])
		err = s.Configure()
		if err != nil {
			log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#Bootstrap() s.Configure(%s) ! %s`, ClusterID, svcs[index], err))
		}
	}

	err = r.registerConsulServices()
	if err != nil {
		log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#Bootstrap() r.registerConsulServices() ! %s`, ClusterID, err))
	}

	err = r.registerConsulWatches()
	if err != nil {
		log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#Bootstrap() r.registerConsulWatches() ! %s`, ClusterID, err))
	}

	log.Trace(fmt.Sprintf(`rdpg.RDPG<%s>#Bootstrap() Bootstrapping Cluster Node Completed.`, ClusterID))
	return
}