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

View File

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

View File

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

View File

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

View File

@ -1,25 +1,25 @@
package crawlerinputitemmapping
import (
"testing"
"git.loafle.net/overflow/overflow_service/proxy/crawler"
)
func TestListCrawler(t *testing.T) {
niin := NewCrawlerInputItemMappingService()
cc := &crawler.Crawler{}
cc.Id = "1";
out := niin.List(cc)
t.Log(out)
}
//import (
// "testing"
//
// "git.loafle.net/overflow/overflow_service/proxy/crawler"
//)
//
//func TestListCrawler(t *testing.T) {
//
//
//
// niin := NewCrawlerInputItemMappingService()
//
//
// cc := &crawler.Crawler{}
//
// cc.Id = "1";
//
// out := niin.List(cc)
//
//
// 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 (
"encoding/json"
"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/utils"
"git.loafle.net/overflow/overflow_service/proxy/crawler"
)
type Sensor struct {
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"`
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 {

View File

@ -46,3 +46,15 @@ func (t *TargetService) Regist(target *Target) (string, error) {
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)
}
func TestTargetRead(t *testing.T) {
ts := NewTargetService()
res, err := ts.Read("1")
if err != nil {
t.Fatal(err)
}
t.Log(res)
}