Skip to content

Commit ea0a600

Browse files
authored
Merge pull request #13 from prakhar2611/poller_visibilty_new
Poller visibility adding new query method to Get all entities of an App
2 parents ebacad0 + 525f18f commit ea0a600

3 files changed

Lines changed: 56 additions & 15 deletions

File tree

dao/cluster_dao.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
type ClusterDao interface {
2828
GetAllEntitiesInfoOfNode(nodeName string) []e.EntityInfo
2929
GetAllEntitiesInfo() []e.EntityInfo
30+
GetAllEntitiesForApp(appId string) ([]e.EntityInfo, error)
3031
GetEntityInfo(id string) e.EntityInfo
3132
UpdateEntityStatus(id string, nodeName string, status int) error
3233
GetApp(appName string) (store.App, error)

dao/cluster_dao_impl.go

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"errors"
2525
"fmt"
2626
"strconv"
27+
"strings"
2728
"sync"
2829

2930
"github.com/golang/glog"
@@ -55,18 +56,19 @@ var (
5556
KeyAppTable = "apps"
5657
MaxConfigApp = "maxConfig"
5758

58-
KeyEntitiesOfNode = "SELECT id, status FROM " + KeyNodeTable + " WHERE nodename='%s';"
59-
KeyGetAllEntities = "SELECT id, nodename, status, history FROM " + KeyEntityTable + ";"
60-
KeyGetEntity = "SELECT id, nodename, status, history FROM " + KeyEntityTable + " WHERE id='%s';"
61-
KeyUpdateEntityInfo = "UPDATE " + KeyEntityTable + " SET nodename='%s', status=%d, history='%s' WHERE id='%s';"
62-
QueryInsertEntity = "INSERT INTO " + KeyEntityTable + " (id, nodename, status) VALUES (?, ?, ?)"
63-
QueryInsertApp = "INSERT INTO " + KeyAppTable + " (id, partitions, active, configuration) VALUES (?, ?, ?, ?)"
64-
KeyAppById = "SELECT id, partitions, active, configuration FROM " + KeyAppTable + " WHERE id='%s';"
65-
KeyAppByIds = "SELECT id, partitions, active, configuration FROM " + KeyAppTable + " WHERE id in (?, ?);"
66-
KeyGelAllApps = "SELECT id, partitions, active, configuration FROM " + KeyAppTable + ";"
67-
QueryUpdateAppStatus = "UPDATE " + KeyAppTable + " set active = %s where id='%s'"
68-
QueryGetConfig = "SELECT configuration FROM " + KeyAppTable + " WHERE id='%s';"
69-
QueryUpdateConfig = "UPDATE " + KeyAppTable + " SET configuration='%s' WHERE id='%s';"
59+
KeyEntitiesOfNode = "SELECT id, status FROM " + KeyNodeTable + " WHERE nodename='%s';"
60+
KeyGetAllEntities = "SELECT id, nodename, status, history FROM " + KeyEntityTable + ";"
61+
KeyGetEntity = "SELECT id, nodename, status, history FROM " + KeyEntityTable + " WHERE id='%s';"
62+
KeyUpdateEntityInfo = "UPDATE " + KeyEntityTable + " SET nodename='%s', status=%d, history='%s' WHERE id='%s';"
63+
QueryInsertEntity = "INSERT INTO " + KeyEntityTable + " (id, nodename, status) VALUES (?, ?, ?)"
64+
QueryInsertApp = "INSERT INTO " + KeyAppTable + " (id, partitions, active, configuration) VALUES (?, ?, ?, ?)"
65+
KeyAppById = "SELECT id, partitions, active, configuration FROM " + KeyAppTable + " WHERE id='%s';"
66+
KeyAppByIds = "SELECT id, partitions, active, configuration FROM " + KeyAppTable + " WHERE id in (?, ?);"
67+
KeyGelAllApps = "SELECT id, partitions, active, configuration FROM " + KeyAppTable + ";"
68+
QueryUpdateAppStatus = "UPDATE " + KeyAppTable + " set active = %s where id='%s'"
69+
QueryGetConfig = "SELECT configuration FROM " + KeyAppTable + " WHERE id='%s';"
70+
QueryUpdateConfig = "UPDATE " + KeyAppTable + " SET configuration='%s' WHERE id='%s';"
71+
KeyGetAllEntitiesForApp = "SELECT id, nodename, status, history FROM " + KeyEntityTable + " WHERE id in %s;"
7072
)
7173

7274
// TODO: Should we make it singleton?
@@ -223,6 +225,47 @@ func (c *ClusterDaoImplCassandra) GetAllEntitiesInfo() []e.EntityInfo {
223225
return entities
224226
}
225227

228+
// Get all the entities of single app
229+
// Raise a Error in case there is any error while retriving pollers for that app
230+
func (c *ClusterDaoImplCassandra) GetAllEntitiesForApp(appId string) ([]e.EntityInfo, error) {
231+
var nodeName string
232+
var status int
233+
var history string
234+
235+
//getting app info
236+
app, err := c.GetApp(appId)
237+
if err != nil {
238+
glog.Errorf("Error: %s while getting app info for GetAllEntitiesForApp: %+v for app: %s", err.Error(), appId)
239+
return nil, err
240+
}
241+
242+
//loop over partitions of an app
243+
parts := make([]string, app.Partitions)
244+
for i := uint32(0); i < app.Partitions; i++ {
245+
parts[i] = fmt.Sprintf("'%v.%d'", app.AppId, i)
246+
}
247+
ids := fmt.Sprintf("(%s)", strings.Join(parts, ","))
248+
249+
//getting all the pollers information for an app id
250+
var entities []e.EntityInfo
251+
query := fmt.Sprintf(KeyGetAllEntitiesForApp, ids)
252+
iter := c.Session.
253+
Query(query).
254+
Consistency(c.Conf.ClusterDB.DBConfig.Consistency).
255+
Iter()
256+
for iter.Scan(&appId, &nodeName, &status, &history) {
257+
entities = append(entities, e.EntityInfo{Id: appId, Node: nodeName, Status: status, History: history})
258+
}
259+
260+
if err := iter.Close(); err != nil {
261+
glog.Errorf("Error: %s while getting poller info for GetAllEntitiesForApp: %+v for app: %s", err.Error(), appId)
262+
return nil, err
263+
}
264+
265+
glog.Infof("GetAllEntitiesInfo result is : %+v", entities)
266+
return entities, nil
267+
}
268+
226269
// Get entity by id
227270
// TODO: Return error
228271
func (c *ClusterDaoImplCassandra) GetEntityInfo(id string) e.EntityInfo {

retrievers/schedule_retriver.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ func (s ScheduleRetriever) GetSchedules(appName string, partitionId int, timeBuc
8989
pageState = iter.PageState()
9090
queryCount++
9191

92-
glog.Infof("Query %d for app %s, partition %d: Fetched %d schedules (Total: %d)",
93-
queryCount, appName, partitionId, scheduleCount, totalSchedules)
94-
9592
if err = iter.Close(); err != nil {
9693
glog.Errorf("Error: %s while fetching schedules for app: %s, partitionId: %d, timeBucket: %v", err.Error(), appName, partitionId, timeBucket)
9794
return err

0 commit comments

Comments
 (0)