VOL-2224 Event Filter Mechanism

         This commit contains the inital changes required for the event
         filtering so that when the protos get merged the rw and ro core
         could be built without compilation errors

         Note: This patchset and the patchset for voltha-protos needs to be merged
               as close to as possible otherwise there will be compilation errors

Change-Id: Id092fa19a0b302a33176a82e41b92a36ea8ede29
diff --git a/ro_core/core/grpc_nbi_api_handler.go b/ro_core/core/grpc_nbi_api_handler.go
index ee8d736..a611337 100644
--- a/ro_core/core/grpc_nbi_api_handler.go
+++ b/ro_core/core/grpc_nbi_api_handler.go
@@ -238,16 +238,16 @@
 	return handler.deviceMgr.GetImages(ctx, id.Id)
 }
 
-// ListAlarmFilters return all alarm filters known to the system
-func (handler *APIHandler) ListAlarmFilters(ctx context.Context, empty *empty.Empty) (*voltha.AlarmFilters, error) {
-	log.Debug("ListAlarmFilters")
-	return handler.commonMgr.ListAlarmFilters(ctx)
+// ListEventFilters return all event filters known to the system
+func (handler *APIHandler) ListEventFilters(ctx context.Context, empty *empty.Empty) (*voltha.EventFilters, error) {
+	log.Debug("ListEventFilters")
+	return handler.commonMgr.ListEventFilters(ctx)
 }
 
-// GetAlarmFilter returns a specific alarm filter entry
-func (handler *APIHandler) GetAlarmFilter(ctx context.Context, id *voltha.ID) (*voltha.AlarmFilter, error) {
-	log.Debugw("GetAlarmFilter", log.Fields{"alarmid": id})
-	return handler.commonMgr.GetAlarmFilter(ctx, id.Id)
+// GetEventFilter returns a  filter for a specific device
+func (handler *APIHandler) GetEventFilter(ctx context.Context, id *voltha.ID) (*voltha.EventFilters, error) {
+	log.Debugw("GetEventFilter", log.Fields{"deviceid": id})
+	return handler.commonMgr.GetEventFilter(ctx, id.Id)
 }
 
 //ReconcileDevices is a request to a voltha core to managed a list of devices  based on their IDs
diff --git a/ro_core/core/model_proxy_manager.go b/ro_core/core/model_proxy_manager.go
index d3b278d..d971c4a 100644
--- a/ro_core/core/model_proxy_manager.go
+++ b/ro_core/core/model_proxy_manager.go
@@ -34,7 +34,7 @@
 // Enumerated list of data path agents
 const (
 	Adapters DataModelType = 1 + iota
-	AlarmFilters
+	EventFilters
 	CoreInstances
 	DeviceTypes
 	DeviceGroups
@@ -47,7 +47,7 @@
 // String equivalent for data path agents
 var commonTypes = []string{
 	"Adapters",
-	"AlarmFilters",
+	"EventFilters",
 	"CoreInstances",
 	"DeviceTypes",
 	"DeviceGroups",
@@ -260,19 +260,19 @@
 	return &voltha.DeviceGroup{}, status.Errorf(codes.NotFound, "device-group-%s", id)
 }
 
-// ListAlarmFilters returns all the alarm filters known to the system
-func (mpMgr *ModelProxyManager) ListAlarmFilters(ctx context.Context) (*voltha.AlarmFilters, error) {
-	log.Debug("ListAlarmFilters")
+// ListEventFilters returns all the event filters known to the system
+func (mpMgr *ModelProxyManager) ListEventFilters(ctx context.Context) (*voltha.EventFilters, error) {
+	log.Debug("ListEventFilters")
 
 	var agent *ModelProxy
 	var exists bool
 
-	if agent, exists = mpMgr.modelProxy[AlarmFilters.String()]; !exists {
-		agent = newModelProxy("alarm_filters", mpMgr.clusterDataProxy)
-		mpMgr.modelProxy[AlarmFilters.String()] = agent
+	if agent, exists = mpMgr.modelProxy[EventFilters.String()]; !exists {
+		agent = newModelProxy("event_filters", mpMgr.clusterDataProxy)
+		mpMgr.modelProxy[EventFilters.String()] = agent
 	}
 
-	alarmFilters := &voltha.AlarmFilters{}
+	eventFilters := &voltha.EventFilters{}
 	if items, err := agent.Get(); err != nil {
 		return nil, status.Errorf(codes.Internal, err.Error())
 	} else if items != nil {
@@ -281,35 +281,30 @@
 			list = []interface{}{items}
 		}
 		for _, item := range list {
-			alarmFilters.Filters = append(alarmFilters.Filters, item.(*voltha.AlarmFilter))
+			eventFilters.Filters = append(eventFilters.Filters, item.(*voltha.EventFilter))
 		}
-		return alarmFilters, nil
+		return eventFilters, nil
 	}
 
-	return alarmFilters, status.Errorf(codes.NotFound, "no-alarm-filters")
+	return eventFilters, status.Errorf(codes.NotFound, "no-event-filters")
 }
 
-// GetAlarmFilter returns the alarm filter associated to the provided id
-func (mpMgr *ModelProxyManager) GetAlarmFilter(ctx context.Context, id string) (*voltha.AlarmFilter, error) {
-	log.Debugw("GetAlarmFilter", log.Fields{"id": id})
+// GetEventFilter returns the event filter associated to the provided device id
+func (mpMgr *ModelProxyManager) GetEventFilter(ctx context.Context, id string) (*voltha.EventFilters, error) {
+	log.Debugw("GetEventFilter", log.Fields{"id": id})
 
 	var agent *ModelProxy
 	var exists bool
 
-	if agent, exists = mpMgr.modelProxy[AlarmFilters.String()]; !exists {
-		agent = newModelProxy("alarm_filters", mpMgr.clusterDataProxy)
-		mpMgr.modelProxy[AlarmFilters.String()] = agent
+	if agent, exists = mpMgr.modelProxy[EventFilters.String()]; !exists {
+		agent = newModelProxy("event_filters", mpMgr.clusterDataProxy)
+		mpMgr.modelProxy[EventFilters.String()] = agent
 	}
 
-	if alarmFilter, err := agent.Get(id); err != nil {
+	if _, err := agent.Get(id); err != nil {
 		return nil, status.Errorf(codes.Internal, err.Error())
-	} else if alarmFilter != nil {
-		_, ok := alarmFilter.(*voltha.AlarmFilter)
-		if !ok {
-			return nil, status.Errorf(codes.Internal, MultipleValuesMsg,
-				id, AlarmFilters.String())
-		}
-		return alarmFilter.(*voltha.AlarmFilter), nil
 	}
-	return &voltha.AlarmFilter{}, status.Errorf(codes.NotFound, "alarm-filter-%s", id)
+	//TODO: VOL-2305 Code to get filters for a particular device once Event filtering mechanism is implemented
+
+	return &voltha.EventFilters{}, status.Errorf(codes.NotFound, "event-filter-%s", id)
 }
diff --git a/ro_core/core/model_proxy_manager_test.go b/ro_core/core/model_proxy_manager_test.go
index 4437afa..10411bf 100644
--- a/ro_core/core/model_proxy_manager_test.go
+++ b/ro_core/core/model_proxy_manager_test.go
@@ -229,9 +229,9 @@
 	assert.Equal(t, "id", result1.Id)
 }
 
-func TestListAlarmFilters(t *testing.T) {
-	wantResult := &voltha.AlarmFilters{
-		Filters: []*voltha.AlarmFilter{
+func TestListEventFilters(t *testing.T) {
+	wantResult := &voltha.EventFilters{
+		Filters: []*voltha.EventFilter{
 			{
 				Id: "id",
 			},
@@ -241,47 +241,53 @@
 	mpMgr := makeModelProxyManagerObj()
 
 	// Case 1: Not Found
-	result0, err0 := mpMgr.ListAlarmFilters(context.Background())
+	result0, err0 := mpMgr.ListEventFilters(context.Background())
 	if reflect.TypeOf(result0) != reflect.TypeOf(wantResult) {
-		t.Errorf("ListAlarmFilters() = %v, want %v", result0, wantResult)
+		t.Errorf("ListEventFilters() = %v, want %v", result0, wantResult)
 	}
 	assert.Nil(t, result0.Filters)
 	assert.Nil(t, err0)
 
 	// Case 2: Found
-	if added := mpMgr.clusterDataProxy.Add(context.Background(), "/alarm_filters", &voltha.AlarmFilter{Id: "id"}, ""); added == nil {
-		t.Error("Failed to add alarm filter")
+	if added := mpMgr.clusterDataProxy.Add(context.Background(), "/event_filters", &voltha.EventFilter{Id: "id"}, ""); added == nil {
+		t.Error("Failed to add event filter")
 	}
-	result1, err1 := mpMgr.ListAlarmFilters(context.Background())
+	result1, err1 := mpMgr.ListEventFilters(context.Background())
 	if reflect.TypeOf(result1) != reflect.TypeOf(wantResult) {
-		t.Errorf("ListAlarmFilters() = %v, want %v", result1, wantResult)
+		t.Errorf("ListEventFilters() = %v, want %v", result1, wantResult)
 	}
 	assert.NotNil(t, result1.Filters)
 	assert.Nil(t, err1)
 	assert.Equal(t, wantResult, result1)
 }
 
-func TestGetAlarmFilter(t *testing.T) {
-	wantResult := &voltha.AlarmFilter{}
+func TestGetEventFilter(t *testing.T) {
+	wantResult := &voltha.EventFilters{
+		Filters: []*voltha.EventFilter{
+			{
+				Id: "id",
+			},
+		},
+	}
+
 	mpMgr := makeModelProxyManagerObj()
 
 	// Case 1: Not Found
-	result0, err0 := mpMgr.GetAlarmFilter(context.Background(), "id")
+	result0, _ := mpMgr.GetEventFilter(context.Background(), "id")
 	if reflect.TypeOf(result0) != reflect.TypeOf(wantResult) {
-		t.Errorf("GetAlarmFilter() = %v, want %v", result0, wantResult)
+		t.Errorf("GetEventFilters() = %v, want %v", result0, wantResult)
 	}
 	assert.Nil(t, result0)
-	assert.NotNil(t, err0)
-
 	// Case 2: Found
-	if added := mpMgr.clusterDataProxy.Add(context.Background(), "/alarm_filters", &voltha.AlarmFilter{Id: "id"}, ""); added == nil {
-		t.Error("Failed to add alarm filter")
+	if added := mpMgr.clusterDataProxy.Add(context.Background(), "/event_filters", &voltha.EventFilter{Id: "id"}, ""); added == nil {
+		t.Error("Failed to add event filter")
 	}
-	result1, err1 := mpMgr.GetAlarmFilter(context.Background(), "id")
+	result1, err1 := mpMgr.ListEventFilters(context.Background())
 	if reflect.TypeOf(result1) != reflect.TypeOf(wantResult) {
-		t.Errorf("GetAlarmFilter() = %v, want %v", result1, wantResult)
+		t.Errorf("GetEventFilters() = %v, want %v", result1, wantResult)
 	}
 	assert.NotNil(t, result1)
 	assert.Nil(t, err1)
-	assert.Equal(t, "id", result1.Id)
+	assert.Equal(t, wantResult, result1)
+
 }