crawler/sensor

This commit is contained in:
insanity@loafle.com 2017-06-26 18:33:56 +09:00
parent 762a64c542
commit 67b59381a7
10 changed files with 258 additions and 186 deletions

View File

@ -1,58 +1,59 @@
package crawler package crawler
import ( //
"encoding/json" //import (
"git.loafle.net/overflow/commons_go/model/timestamp" // "encoding/json"
//"git.loafle.net/overflow/overflow_service/proxy" // "git.loafle.net/overflow/commons_go/model/timestamp"
"git.loafle.net/overflow/overflow_service/proxy/utils" // //"git.loafle.net/overflow/overflow_service/proxy"
) // "git.loafle.net/overflow/overflow_service/proxy/utils"
//)
type CrawlerService struct { //
//type CrawlerService struct {
} //
//}
func NewCrawlerService() *CrawlerService { //
return &CrawlerService{} //func NewCrawlerService() *CrawlerService {
} // return &CrawlerService{}
//}
//
type Crawler struct { //
Id json.Number `json:"id,Number,omitempty"` //type Crawler struct {
Name string `json:"name,omitempty"` // Id json.Number `json:"id,Number,omitempty"`
Description string `json:"description,omitempty"` // Name string `json:"name,omitempty"`
CrawlerType string `json:"crawlerType,omitempty"` // Description string `json:"description,omitempty"`
CreateDate timestamp.Timestamp `json:"createDate,omitempty"` // CrawlerType string `json:"crawlerType,omitempty"`
} // CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
//}
//
//
//
//
func (c *CrawlerService)List() (string, error) { //
//func (c *CrawlerService)List() (string, error) {
//
//out := proxy.InvokeDB("crawler", "findAll", nil) //
// //out := proxy.InvokeDB("crawler", "findAll", nil)
out, err := utils.InvokeDB("crawler", "findAll", nil) //
// out, err := utils.InvokeDB("crawler", "findAll", nil)
if err != nil { //
return "", err // if err != nil {
} // return "", err
// }
return out, nil //
} // return out, nil
//}
//
func (c *CrawlerService)Create(ct * Crawler) (string, error) { //
//func (c *CrawlerService)Create(ct * Crawler) (string, error) {
//
//
out, err := utils.InvokeDB("crawler", "create", ct) //
// out, err := utils.InvokeDB("crawler", "create", ct)
if err != nil { //
return "", err // if err != nil {
} // return "", err
// }
//
return out, nil //
} // return out, nil
//}

View File

@ -1,14 +1,15 @@
package crawler package crawler
import "testing" //
//import "testing"
func TestList(t *testing.T) { //
//func TestList(t *testing.T) {
cs := NewCrawlerService() //
// cs := NewCrawlerService()
out := cs.List() //
// out := cs.List()
//
t.Log(out) //
// t.Log(out)
} //
//}

View File

@ -1,38 +1,38 @@
package crawlerInputItem package crawlerInputItem
import ( //import (
"git.loafle.net/overflow/commons_go/model/timestamp" // "git.loafle.net/overflow/commons_go/model/timestamp"
"encoding/json" // "encoding/json"
"git.loafle.net/overflow/overflow_service/proxy/utils" // "git.loafle.net/overflow/overflow_service/proxy/utils"
) //)
//
type CrawlerInputItem struct { //type CrawlerInputItem struct {
Id json.Number `json:"id,Number,omitempty"` // Id json.Number `json:"id,Number,omitempty"`
Name string `json:"name,omitempty"` // Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"` // Description string `json:"description,omitempty"`
DataType string `json:"dataType,omitempty"` // DataType string `json:"dataType,omitempty"`
CreateDate timestamp.Timestamp `json:"createDate,omitempty"` // CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
} //}
//
type CrawlerInputItemSerivce struct { //type CrawlerInputItemSerivce struct {
//
} //}
//
func NewCrawlerInputItemService() *CrawlerInputItemSerivce { //func NewCrawlerInputItemService() *CrawlerInputItemSerivce {
return &CrawlerInputItemSerivce{} // return &CrawlerInputItemSerivce{}
} //}
//
//
//
func (c *CrawlerInputItemSerivce)Create(cii * CrawlerInputItem) (string, error) { //func (c *CrawlerInputItemSerivce)Create(cii * CrawlerInputItem) (string, error) {
//
out, err := utils.InvokeDB("crawlerInputItem", "create", cii) // out, err := utils.InvokeDB("crawlerInputItem", "create", cii)
//
if err != nil { // if err != nil {
return "", err // return "", err
} // }
//
//
return out, nil; // return out, nil;
//
} //}

View File

@ -1,55 +1,55 @@
package crawlerinputitemmapping package crawlerinputitemmapping
import ( //import (
"git.loafle.net/overflow/commons_go/model/timestamp" // "git.loafle.net/overflow/commons_go/model/timestamp"
"encoding/json" // "encoding/json"
"git.loafle.net/overflow/overflow_service/proxy/crawler" // "git.loafle.net/overflow/overflow_service/proxy/crawler"
"git.loafle.net/overflow/overflow_service/proxy/crawlerInputItem" // "git.loafle.net/overflow/overflow_service/proxy/crawlerInputItem"
"git.loafle.net/overflow/overflow_service/proxy/utils" // "git.loafle.net/overflow/overflow_service/proxy/utils"
) //)
//
type CrawlerInputItemMapping struct { //type CrawlerInputItemMapping struct {
Id json.Number `json:"id,Number,omitempty"` // Id json.Number `json:"id,Number,omitempty"`
Crawler crawler.Crawler `json:"crawler,omitempty"` // Crawler crawler.Crawler `json:"crawler,omitempty"`
CrawlerInputItem crawlerInputItem.CrawlerInputItem `json:"crawlerInputItem,omitempty"` // CrawlerInputItem crawlerInputItem.CrawlerInputItem `json:"crawlerInputItem,omitempty"`
//
Priority json.Number `json:"priority,Number,omitempty"` // Priority json.Number `json:"priority,Number,omitempty"`
RequiredType bool `json:"requiredType,omitempty"` // RequiredType bool `json:"requiredType,omitempty"`
CreateDate timestamp.Timestamp `json:"createDate,omitempty"` // CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
} //}
//
//
type CrawlerInputItemMappingService struct { //type CrawlerInputItemMappingService struct {
//
} //}
//
func NewCrawlerInputItemMappingService() *CrawlerInputItemMappingService { //func NewCrawlerInputItemMappingService() *CrawlerInputItemMappingService {
return &CrawlerInputItemMappingService{} // return &CrawlerInputItemMappingService{}
} //}
//
func (c *CrawlerInputItemMappingService)Create(ciim *CrawlerInputItemMapping) (string, error) { //func (c *CrawlerInputItemMappingService)Create(ciim *CrawlerInputItemMapping) (string, error) {
//
out, err := utils.InvokeDB("crawlerInputItemMapping", "create", ciim) // out, err := utils.InvokeDB("crawlerInputItemMapping", "create", ciim)
//
if err != nil { // if err != nil {
return "", err // return "", err
} // }
//
//
return out, nil; // return out, nil;
//
} //}
//
func (c *CrawlerInputItemMappingService)List(cr *crawler.Crawler) (string, error) { //func (c *CrawlerInputItemMappingService)List(cr *crawler.Crawler) (string, error) {
//
//
out, err := utils.InvokeDBByModel("crawlerInputItemMapping", "findByCrawlerId", cr, "com.loafle.overflow.crawler.model.Crawler") // out, err := utils.InvokeDBByModel("crawlerInputItemMapping", "findByCrawlerId", cr, "com.loafle.overflow.crawler.model.Crawler")
//
if err != nil { // if err != nil {
return "", err // return "", err
} // }
//
//
return out, nil; // return out, nil;
//
} //}

View File

@ -1,25 +1,25 @@
package crawlerinputitemmapping package crawlerinputitemmapping
import ( //import (
"testing" // "testing"
//
"git.loafle.net/overflow/overflow_service/proxy/crawler" // "git.loafle.net/overflow/overflow_service/proxy/crawler"
) //)
//
func TestListCrawler(t *testing.T) { //func TestListCrawler(t *testing.T) {
//
//
//
niin := NewCrawlerInputItemMappingService() // niin := NewCrawlerInputItemMappingService()
//
//
cc := &crawler.Crawler{} // cc := &crawler.Crawler{}
//
cc.Id = "1"; // cc.Id = "1";
//
out := niin.List(cc) // out := niin.List(cc)
//
//
t.Log(out) // t.Log(out)
//
} //}

View File

@ -0,0 +1,13 @@
package meta
import (
"encoding/json"
"git.loafle.net/overflow/commons_go/model/timestamp"
)
type MetaCrawler struct {
Id json.Number `json:"id,Number,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
}

View File

@ -0,0 +1,34 @@
package meta
import (
"encoding/json"
"strconv"
)
const (
PROBE_STATUS_RUNNING = 1
PROBE_STATUS_STOPPED = 2
)
var metaSensorStatusMap = map[int]string{
1: "RUNNING",
2: "STOPPED",
}
type MetaSensorStatus struct {
Id json.Number `json:"id,Number,omitempty"`
Name string `json:"name,omitempty"`
}
func NewMetaSensorStatus(types int) *MetaProbeStatus {
str := metaSensorStatusMap[types]
if len(str) <= 0 {
return nil
}
return &MetaProbeStatus{
Id: json.Number(strconv.Itoa(types)),
Name: str,
}
}

View File

@ -3,17 +3,19 @@ package sensor
import ( import (
"encoding/json" "encoding/json"
"git.loafle.net/overflow/commons_go/model/timestamp" "git.loafle.net/overflow/commons_go/model/timestamp"
"git.loafle.net/overflow/overflow_service/proxy/meta"
"git.loafle.net/overflow/overflow_service/proxy/target" "git.loafle.net/overflow/overflow_service/proxy/target"
"git.loafle.net/overflow/overflow_service/proxy/utils" "git.loafle.net/overflow/overflow_service/proxy/utils"
"git.loafle.net/overflow/overflow_service/proxy/crawler"
) )
type Sensor struct { type Sensor struct {
Id json.Number `json:"id,Number,omitempty"` Id json.Number `json:"id,Number,omitempty"`
Target target.Target `json:"target,omitempty"`
Notification string `json:"notification,omitempty"`
Crawler crawler.Crawler `json:"crawler,omitempty"`
CreateDate timestamp.Timestamp `json:"createDate,omitempty"` CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
Description string `json:"description,omitempty"`
MetaSensorStatus meta.MetaSensorStatus `json:"status,omitempty"`
Target target.Target `json:"target,omitempty"`
Crawler meta.MetaCrawler `json:"crawler,omitempty"`
CrawlerInputItems string `json:"crawlerInputItems,omitempty"`
} }
type SensorService struct { type SensorService struct {

View File

@ -46,3 +46,15 @@ func (t *TargetService) Regist(target *Target) (string, error) {
return out, nil return out, nil
} }
func (t *TargetService) Read(id string) (string, error) {
out,err :=utils.InvokeDBByModel("target","findOne",id,utils.MODEL_LONG)
if err != nil {
return "", err
}
return out, nil
}

View File

@ -40,3 +40,12 @@ func TestTargetList(t *testing.T) {
} }
t.Log(res) t.Log(res)
} }
func TestTargetRead(t *testing.T) {
ts := NewTargetService()
res, err := ts.Read("1")
if err != nil {
t.Fatal(err)
}
t.Log(res)
}