Esempio n. 1
0
	"strings"
	"sync"
	"time"

	"github.com/yangzhao28/phantom/commonlog"
)

// 收取请求(http)        √
// cache, 本地存储       √
// Agent管理             X
// 对Agent 3 routine:
//   - 配置              X
//   - 探活              X
//   - diff              X

var managerLogger = commonlog.NewLogger("AgentManager", "log", commonlog.DEBUG)

type AgentManager struct {
	enableAgents map[string]Configurable
	enableMutex  sync.RWMutex

	availableAgents map[string]Configurable
	availableMutex  sync.RWMutex

	agentEnableChannel  chan *AgentEvent
	agentDisablechannel chan *AgentEvent
	agentCreateChannel  chan *AgentEvent
	agentRemoveChannel  chan *AgentEvent

	agentRunDetector    chan int
	agentRunDiffer      chan int
Esempio n. 2
0
package main

import (
	"github.com/yangzhao28/phantom/commonlog"
	"github.com/yangzhao28/phantom/motherbase"
)

var logger = commonlog.NewLogger("main", "log", commonlog.DEBUG)

func main() {
	logger.Notice("service start")
	motherbase.CreateServer()
}
Esempio n. 3
0
package motherbase

import (
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net/http"

	"github.com/yangzhao28/phantom/commonlog"
)

var httpLogger = commonlog.NewLogger("httpserver", "log", commonlog.DEBUG)

var manager = NewAgentGateway()

func ListConfig(w http.ResponseWriter, req *http.Request) {
	httpLogger.Debug("receive getconfig request from", req.Host)
	itemList, err := manager.Cache.List()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		httpLogger.Warning(err.Error())
		return
	}
	body, err := json.Marshal(itemList)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		httpLogger.Warning(err.Error())
		return
	}
Esempio n. 4
0
	"crypto/md5"
	"encoding/hex"
	"errors"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"regexp"
	"strconv"
	"sync"
	"time"

	"github.com/yangzhao28/phantom/commonlog"
)

var cacheLogger = commonlog.NewLogger("cache", "log", commonlog.DEBUG)

func Md5Sum(content []byte) string {
	md5Ctx := md5.New()
	md5Ctx.Write(content)
	cipher := md5Ctx.Sum(nil)
	return hex.EncodeToString(cipher)
}

type CacheItem struct {
	id         string
	body       string
	md5sum     string
	updateTime int64
}