You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by GitBox <gi...@apache.org> on 2021/07/06 15:20:41 UTC

[GitHub] [brooklyn-server] iuliana commented on a change in pull request #1191: Adding a feature to automatically capture a persistence export archiv…

iuliana commented on a change in pull request #1191:
URL: https://github.com/apache/brooklyn-server/pull/1191#discussion_r662909742



##########
File path: core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynPersistenceUtils.java
##########
@@ -286,4 +289,32 @@ public static void createBackup(ManagementContext managementContext, CreateBacku
             log.warn("Unable to backup management plane sync state on "+mode+" (ignoring): "+e, e);
         }
     }
+
+    public static void createStateExport (ManagementContext managementContext, File persistenceBaseDir){
+        try {
+            File dir = null;
+            BrooklynMementoRawData memento = null;

Review comment:
       Same comment as above.

##########
File path: core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynPersistenceUtils.java
##########
@@ -286,4 +289,32 @@ public static void createBackup(ManagementContext managementContext, CreateBacku
             log.warn("Unable to backup management plane sync state on "+mode+" (ignoring): "+e, e);
         }
     }
+
+    public static void createStateExport (ManagementContext managementContext, File persistenceBaseDir){
+        try {
+            File dir = null;
+            BrooklynMementoRawData memento = null;
+            ManagementPlaneSyncRecord planeState = null;
+            MementoCopyMode source = (managementContext.getHighAvailabilityManager().getNodeState()==ManagementNodeState.MASTER ? MementoCopyMode.LOCAL : MementoCopyMode.REMOTE);
+
+            memento = newStateMemento(managementContext, source);
+            planeState = newManagerMemento(managementContext, source);
+
+            PersistenceObjectStore targetStore = BrooklynPersistenceUtils.newPersistenceObjectStore(managementContext, null,
+                    "tmp/persistence-state-export");
+            dir = ((FileBasedObjectStore)targetStore).getBaseDir();
+            Os.deleteOnExitEmptyParentsUpTo(dir.getParentFile(), dir.getParentFile());
+
+            BrooklynPersistenceUtils.writeMemento(managementContext, memento, targetStore);
+            BrooklynPersistenceUtils.writeManagerMemento(managementContext, planeState, targetStore);
+
+            ArchiveBuilder.zip().addDirContentsAt(((FileBasedObjectStore)targetStore).getBaseDir(), ((FileBasedObjectStore)targetStore).getBaseDir().getName())

Review comment:
       Also, what is the point of these inline conversions?  `dir` is intialized with `((FileBasedObjectStore)targetStore).getBaseDir()` ... why not use it ?

##########
File path: core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynPersistenceUtils.java
##########
@@ -286,4 +289,32 @@ public static void createBackup(ManagementContext managementContext, CreateBacku
             log.warn("Unable to backup management plane sync state on "+mode+" (ignoring): "+e, e);
         }
     }
+
+    public static void createStateExport (ManagementContext managementContext, File persistenceBaseDir){
+        try {
+            File dir = null;
+            BrooklynMementoRawData memento = null;
+            ManagementPlaneSyncRecord planeState = null;

Review comment:
       Same comment as above.

##########
File path: core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynPersistenceUtils.java
##########
@@ -286,4 +289,32 @@ public static void createBackup(ManagementContext managementContext, CreateBacku
             log.warn("Unable to backup management plane sync state on "+mode+" (ignoring): "+e, e);
         }
     }
+
+    public static void createStateExport (ManagementContext managementContext, File persistenceBaseDir){
+        try {
+            File dir = null;

Review comment:
       Is this necessary? Why not declare it in the some spot where is being initialized?
   

##########
File path: core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynPersistenceUtils.java
##########
@@ -286,4 +289,32 @@ public static void createBackup(ManagementContext managementContext, CreateBacku
             log.warn("Unable to backup management plane sync state on "+mode+" (ignoring): "+e, e);
         }
     }
+
+    public static void createStateExport (ManagementContext managementContext, File persistenceBaseDir){
+        try {
+            File dir = null;
+            BrooklynMementoRawData memento = null;
+            ManagementPlaneSyncRecord planeState = null;
+            MementoCopyMode source = (managementContext.getHighAvailabilityManager().getNodeState()==ManagementNodeState.MASTER ? MementoCopyMode.LOCAL : MementoCopyMode.REMOTE);
+
+            memento = newStateMemento(managementContext, source);
+            planeState = newManagerMemento(managementContext, source);
+
+            PersistenceObjectStore targetStore = BrooklynPersistenceUtils.newPersistenceObjectStore(managementContext, null,
+                    "tmp/persistence-state-export");
+            dir = ((FileBasedObjectStore)targetStore).getBaseDir();

Review comment:
       Aslo, should we need a check here? What if the casting fails? Can `targetStore` be null at this point? It would make sense to try to handle this here and throw an exception with an appropriate message than propagate any exception indiscriminately.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org