@@ -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
228271func (c * ClusterDaoImplCassandra ) GetEntityInfo (id string ) e.EntityInfo {
0 commit comments