mooli tayer has uploaded a new change for review.

Change subject: engine: application touches a file to detect un orderly shutdown
......................................................................

engine: application touches a file to detect un orderly shutdown

Used to diagnose unexpected engine stop by the notification service.
Previously we used the pid file, buy this solution becomes irrelevant
for systemd.

Change-Id: Ic8de64637299e7932a5a2761c7bb495373c418aa
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=743660
Signed-off-by: Mooli Tayer <[email protected]>
---
M backend/manager/modules/bll/pom.xml
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java
M 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/EngineLocalConfig.java
M 
backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/EngineMonitorService.java
M ear/src/main/resources/META-INF/MANIFEST.MF
M packaging/services/ovirt-engine/ovirt-engine.conf.in
M pom.xml
7 files changed, 59 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/02/19102/1

diff --git a/backend/manager/modules/bll/pom.xml 
b/backend/manager/modules/bll/pom.xml
index 16e52db..a00be30 100644
--- a/backend/manager/modules/bll/pom.xml
+++ b/backend/manager/modules/bll/pom.xml
@@ -100,6 +100,11 @@
     </dependency>
 
     <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
+
+    <dependency>
       <groupId>javax.transaction</groupId>
       <artifactId>jta</artifactId>
     </dependency>
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java
index ef6d914..984dd02 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java
@@ -1,11 +1,13 @@
 package org.ovirt.engine.core.bll;
 
+import java.io.IOException;
 import java.nio.file.FileSystems;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 import javax.ejb.ConcurrencyManagement;
 import javax.ejb.ConcurrencyManagementType;
 import javax.ejb.DependsOn;
@@ -18,6 +20,7 @@
 import javax.interceptor.Interceptors;
 
 import org.apache.commons.collections.KeyValue;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.exception.ExceptionUtils;
 import org.ovirt.engine.core.bll.context.CommandContext;
@@ -130,6 +133,11 @@
         Initialize();
     }
 
+    @PreDestroy
+    public void destroy() {
+        removeEngineFile();
+    }
+
     private static void checkDBConnectivity() {
         boolean dbUp = false;
         long expectedTimeout =
@@ -181,6 +189,8 @@
         }
         // initialize configuration utils to use DB
         Config.setConfigUtils(new DBConfigUtils());
+
+        touchEngineFile();
 
         log.info("Running ovirt-engine " + 
Config.<String>GetValue(ConfigValues.ProductRPMVersion));
         _resourceManger = new VDSBrokerFrontendImpl();
@@ -252,6 +262,29 @@
         initAttestation();
     }
 
+
+    private void touchEngineFile() {
+        // Inspected by ovirt-engine-notifier to detect improper shutdown
+        EngineLocalConfig config = EngineLocalConfig.getInstance();
+        try {
+            FileUtils.touch(config.getEngineUpFile());
+        } catch (IOException e) {
+            log.error("Could not create application file:" + 
config.getEngineUpFile(), e);
+            throw new RuntimeException("Could not create application file:" + 
config.getEngineUpFile(), e);
+        }
+    }
+
+    private void removeEngineFile() {
+        EngineLocalConfig config = EngineLocalConfig.getInstance();
+        try {
+            FileUtils.forceDelete(config.getEngineUpFile());
+        } catch (IOException e) {
+            log.error("Could not delete application file:" + 
config.getEngineUpFile(), e);
+            throw new RuntimeException("Could not delete application file:" + 
config.getEngineUpFile(), e);
+        }
+
+    }
+
     private void initAttestation() {
         List<VDSGroup> vdsGroups = 
DbFacade.getInstance().getVdsGroupDao().getTrustedClusters();
         List<VDS> trustedVdsList = new ArrayList<>();
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/EngineLocalConfig.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/EngineLocalConfig.java
index d03521b..ec0a43f 100644
--- 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/EngineLocalConfig.java
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/EngineLocalConfig.java
@@ -209,4 +209,8 @@
     public String getPKIEngineStoreAlias() {
         return getProperty("ENGINE_PKI_ENGINE_STORE_ALIAS");
     }
+
+    public File getEngineUpFile(){
+        return getFile("ENGINE_UP_FILE");
+    }
 }
diff --git 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/EngineMonitorService.java
 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/EngineMonitorService.java
index 602fd83..15a3055 100644
--- 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/EngineMonitorService.java
+++ 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/EngineMonitorService.java
@@ -287,8 +287,9 @@
                 }
             } else {
                 // reports an error for non responsive server
-                if(new File(pidFile).exists()) {
-                    // assumed crash, since the pid file is still there
+                EngineLocalConfig config = EngineLocalConfig.getInstance();
+                if(config.getEngineUpFile().exists()) {
+                    // assumed crash, since engine up file is still there
                     insertEventIntoAuditLogSafe(AuditLogType.VDC_STOP,
                             AuditLogSeverity.ERROR,
                             ENGINE_NOT_RESPONDING_ERROR,
diff --git a/ear/src/main/resources/META-INF/MANIFEST.MF 
b/ear/src/main/resources/META-INF/MANIFEST.MF
index cc748ac..2a30658 100644
--- a/ear/src/main/resources/META-INF/MANIFEST.MF
+++ b/ear/src/main/resources/META-INF/MANIFEST.MF
@@ -2,6 +2,7 @@
 Dependencies: asm.asm,
  javax.validation.api,
  org.apache.commons.beanutils,
+ org.apache.commons.io,
  org.apache.commons.codec,
  org.apache.commons.collections,
  org.apache.commons.lang,
diff --git a/packaging/services/ovirt-engine/ovirt-engine.conf.in 
b/packaging/services/ovirt-engine/ovirt-engine.conf.in
index 1131a17..0158bc5 100644
--- a/packaging/services/ovirt-engine/ovirt-engine.conf.in
+++ b/packaging/services/ovirt-engine/ovirt-engine.conf.in
@@ -192,3 +192,10 @@
 ENGINE_PKI_ENGINE_STORE=${ENGINE_PKI}/keys/engine.p12
 ENGINE_PKI_ENGINE_STORE_PASSWORD=
 ENGINE_PKI_ENGINE_STORE_ALIAS=1
+
+
+#
+# A file created on init and removed on orderly shutdown
+# Used to diagnose unexpected engine stop by the notification service.
+#
+ENGINE_UP_FILE=${ENGINE_VAR}/engine.up
diff --git a/pom.xml b/pom.xml
index 822e724..b73dd78 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,6 +51,7 @@
     <commons-compress.version>1.4.1</commons-compress.version>
     <quartz.version>2.1.2</quartz.version>
     <postgres.jdbc.version>9.1-901-1.jdbc4</postgres.jdbc.version>
+    <commons-io.version>2.4</commons-io.version>
     <commons-collections>3.1</commons-collections>
     <javax.transaction>1.1</javax.transaction>
     <javax.activation.version>1.1</javax.activation.version>
@@ -139,6 +140,11 @@
         <artifactId>commons-httpclient</artifactId>
         <version>${httpclient.version}</version>
       </dependency>
+        <dependency>
+        <groupId>commons-io</groupId>
+        <artifactId>commons-io</artifactId>
+        <version>${commons-io.version}</version>
+      </dependency>
       <dependency>
         <groupId>org.springframework.ldap</groupId>
         <artifactId>spring-ldap-core</artifactId>


-- 
To view, visit http://gerrit.ovirt.org/19102
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic8de64637299e7932a5a2761c7bb495373c418aa
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: mooli tayer <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to