コード例 #1
0
func updateSliverToolStatus(c appengine.Context, sliceStatus map[string]string, toolID, family string) error {

	q := datastore.NewQuery("SliverTool").Filter("tool_id =", toolID)
	var sliverTools []*data.SliverTool
	_, err := q.GetAll(c, &sliverTools)
	if err != nil {
		return err
	}
	count, err := q.Count(c)
	if err != nil {
		return err
	}
	updatedSliverTools := make([]*data.SliverTool, count)
	for _, sl := range sliverTools {
		isMatch := false
		for sliverFQDN, status := range sliceStatus {
			if sl.FQDN == sliverFQDN {
				if family == " " {
					sl.StatusIPv4 = status
					if sl.SliverIPv4 == "off" {
						sl.StatusIPv4 = StatusOffline
					}
				} else {
					sl.StatusIPv6 = status
					if sl.SliverIPv6 == "off" {
						sl.StatusIPv6 = StatusOffline
					}
				}
				isMatch = true
				break
			}
		}
		if isMatch {
			sl.When = time.Now()
			slID := data.GetSliverToolID(sl.ToolID, sl.SliceID, sl.ServerID, sl.SiteID)
			sk := datastore.NewKey(c, "SliverTool", slID, 0, nil)
			_, err := datastore.Put(c, sk, sl)
			if err != nil {
				c.Errorf("updateSliverToolStatus: datastore.Put err %v", err)
			} else {
				updatedSliverTools = append(updatedSliverTools, sl)
			}
		}
	}
	//TODO: Update locationMap
	// convert updatedSliverTools and sliverTools to list locmap.Data
	if family == " " {
		// geo.LMapIPv4.UpdateMulti(updatedSliverTools, sliverTools)
	} else {
		// geo.LMapIPv6.UpdateMulti(updatedSliverTools, sliverTools)
	}
	//TODO: Update memcache
	return nil
}
コード例 #2
0
// registerSite puts a Site and corresponding SliverTools in the datastore
func registerSite(c appengine.Context, site *data.Site) ([]*datastore.Key, error) {

	key := datastore.NewKey(c, "Site", site.SiteID, 0, nil)
	site.When = time.Now()
	_, err := datastore.Put(c, key, site)
	if err != nil {
		return nil, err
	}

	q := datastore.NewQuery("Tool")
	var tools []*data.Tool
	_, err = q.GetAll(c, &tools)
	if err != nil {
		return nil, err
	}

	sliverTools := make([]*data.SliverTool, len(tools)*numServers)
	slKeys := make([]*datastore.Key, len(tools)*numServers)
	i := 0
	for _, tool := range tools {
		for _, serverID := range serverIDs {
			sliverToolID := data.GetSliverToolID(tool.ToolID, tool.SliceID, serverID, site.SiteID)
			sliceParts := strings.Split(tool.SliceID, "_")
			sliverTool := &data.SliverTool{
				ToolID:                 tool.ToolID,
				SliceID:                tool.SliceID,
				SiteID:                 site.SiteID,
				ServerID:               serverID,
				FQDN:                   fmt.Sprintf("%s.%s.%s.%s.%s", sliceParts[1], sliceParts[0], serverID, site.SiteID, "measurement-lab.org"),
				ServerPort:             "",
				HTTPPort:               tool.HTTPPort,
				SliverIPv4:             "off",
				SliverIPv6:             "off",
				UpdateRequestTimestamp: site.RegistrationTimestamp,
				StatusIPv4:             "offline",
				StatusIPv6:             "offline",
				Latitude:               site.Latitude,
				Longitude:              site.Longitude,
				City:                   site.City,
				Country:                site.Country,
				When:                   time.Now(),
			}
			slKey := datastore.NewKey(c, "SliverTool", sliverToolID, 0, nil)
			slKeys[i] = slKey
			sliverTools[i] = sliverTool
			i++
		}
	}
	return datastore.PutMulti(c, slKeys, sliverTools)
}
コード例 #3
0
ファイル: ksUpdateHanlder.go プロジェクト: jclohmann/mlab-ns2
// KsUpdateHandler handles IP address updates
func KsUpdateHandler(w http.ResponseWriter, r *http.Request) {

	c := appengine.NewContext(r)
	client := urlfetch.Client(c)
	res, err := client.Get(KsIPUrl)
	if err != nil {
		c.Errorf("KsUpdateHandler:client.Get(KsIPUrl) err = %v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	txtBlob, _ := ioutil.ReadAll(res.Body)
	defer res.Body.Close()
	txt := fmt.Sprintf("%s", txtBlob)
	lines := strings.Split(txt, "\n")
	for _, line := range lines {
		if len(line) == 0 {
			continue
		}
		split := strings.Split(line, ",")
		fqdn := split[0]
		ipv4 := split[1]
		ipv6 := split[2]
		q := datastore.NewQuery("SliverTool").Filter("fqdn=", fqdn)
		var sliverTool []*data.SliverTool
		_, err = q.GetAll(c, &sliverTool)
		if err != nil {
			c.Errorf("KsUpdateHandler:q.GetAll(..sliverTool) err = %v", err)
			continue
		}
		if len(sliverTool) > 1 {
			c.Errorf("KsUpdateHandler:q.GetAll(..sliverTool): Two sliverTools with same fqdn = %s", fqdn)
			continue
		} else if len(sliverTool) < 1 {
			c.Errorf("KsUpdateHandler:q.GetAll(..sliverTool): sliverTool not found with fqdn = %s", fqdn)
			continue
		}

		sliverTool[0].SliverIPv4 = ipv4
		if ipv4 == "" {
			sliverTool[0].SliverIPv4 = "off"
		}
		sliverTool[0].SliverIPv6 = ipv6
		if ipv6 == "" {
			sliverTool[0].SliverIPv6 = "off"
		}

		slID := data.GetSliverToolID(sliverTool[0].ToolID, sliverTool[0].SliceID, sliverTool[0].ServerID, sliverTool[0].SiteID)
		sk := datastore.NewKey(c, "SliverTool", slID, 0, nil)
		_, err := datastore.Put(c, sk, sliverTool[0])
		if err != nil {
			c.Errorf("KsUpdateHandler: datastore.Put err %v ", err)
		} else {
			// TODO: add to data to update LocationMap and memcache
		}
	}
	// TODO: Update locationMap
	// geo.LMapIPv4.ChangeMulti(map[oldIP]newIP)
	// geo.LMapIPv6.ChangeMulti(map[oldIP]newIP)
	// TODO: Update memcache
	fmt.Fprintf(w, "OK")
}