Add VIP service decision maker 36/130536/6
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Mon, 22 May 2017 16:49:25 +0000 (18:49 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Wed, 31 May 2017 15:42:05 +0000 (17:42 +0200)
Add a decision maker which will reboot the system if VIP
service has entered a failed state

Change-Id: I05bc657bb48b7ba826da922b8d8f6cc1a72a2846
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Makefile.am
src/decision_makers/vip_fault_dm.c [new file with mode: 0644]

index f9a25a9507040d5e078096c4d442c359195559b2..9673ed1ae64beb9c2d134b3163778b59b867feee 100644 (file)
@@ -47,6 +47,7 @@ faultd_SOURCES = \
     src/core/module.c \
     src/core/service.c \
     src/decision_makers/rv_dm.c \
+    src/decision_makers/vip_fault_dm.c \
     src/event_types/decision_made_event.c \
     src/event_types/resource_violation_event.c \
     src/event_types/service_failed_event.c \
diff --git a/src/decision_makers/vip_fault_dm.c b/src/decision_makers/vip_fault_dm.c
new file mode 100644 (file)
index 0000000..14a38fb
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * This file is part of faultd.
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <malloc.h>
+#include <errno.h>
+
+#include "service_failed_event.h"
+#include "decision_made_event.h"
+#include "action.h"
+#include "event_processor.h"
+#include "log.h"
+#include "service.h"
+
+#define MODULE_NAME "vip_fault_decision_maker"
+
+static int vf_event_match(struct faultd_event_handler *handler,
+                                                 struct faultd_event *ev)
+{
+       struct service_failed_event *sf_ev = to_service_failed_event(ev);
+
+       return faultd_event_is_of_type(ev, SERVICE_FAILED_EVENT_ID)
+               && systemd_service_is_of_type(&sf_ev->service, FAULTD_SERVICE_TYPE_VIP);
+}
+
+static int vf_make_decision(struct faultd_event_handler *handler)
+{
+       struct faultd_event *ev = nqueue_pop(&handler->event_queue,
+                                                                                struct faultd_event,
+                                                                                nq_node);
+       struct faultd_event *new_ev;
+       struct dm_event_data ev_data = {
+               .reason = ev,
+               .who_made = MODULE_NAME,
+               .action = FAULTD_ACTION_REBOOT_ID,
+               .action_data = NULL,
+               .action_data_release = free,
+       };
+       int ret;
+
+       ret = faultd_event_create(DECISION_MADE_EVENT_ID, &ev_data, &new_ev);
+       faultd_event_unref(ev);
+       if (ret) {
+               log_error("Unable to create event");
+               goto out;
+       }
+
+       ret = event_processor_report_event(new_ev);
+       if (ret) {
+               log_error("Unable to report event");
+               goto put_new_event;
+       }
+
+       return 0;
+
+put_new_event:
+       faultd_event_unref(new_ev);
+out:
+       return 0;
+}
+
+static struct faultd_event_handler vip_fault_event_handler = {
+       .name = MODULE_NAME,
+       .event_match = vf_event_match,
+       .handle_event = vf_make_decision,
+
+       .node = LIST_HEAD_INIT(vip_fault_event_handler.node),
+};
+
+FAULTD_EVENT_HANDLER_REGISTER(vip_fault_event_handler,
+                              vip_fault_eh,
+                              FAULTD_MODULE_TYPE_DECISION_MAKER)