brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [10/21] incubator-brooklyn git commit: code review to #314, use enum and create unmanaged location
Date Sat, 15 Nov 2014 00:05:19 GMT
code review to #314, use enum and create unmanaged location


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/f6cd0314
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/f6cd0314
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/f6cd0314

Branch: refs/heads/master
Commit: f6cd031428f2f355d56e6eedef14fcabb0abd8e5
Parents: f90faf4
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Thu Nov 13 15:33:31 2014 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Thu Nov 13 23:38:54 2014 +0000

----------------------------------------------------------------------
 .../entity/rebind/RebindManagerImpl.java        |  3 +-
 .../persister/BrooklynPersistenceUtils.java     | 51 +++++++++++---------
 .../ha/HighAvailabilityManagerImpl.java         |  9 ++--
 3 files changed, 34 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f6cd0314/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java b/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
index e24a818..9dad632 100644
--- a/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
+++ b/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
@@ -59,6 +59,7 @@ import brooklyn.entity.proxying.InternalPolicyFactory;
 import brooklyn.entity.rebind.persister.BrooklynMementoPersisterToObjectStore;
 import brooklyn.entity.rebind.persister.BrooklynPersistenceUtils;
 import brooklyn.entity.rebind.persister.PersistenceActivityMetrics;
+import brooklyn.entity.rebind.persister.BrooklynPersistenceUtils.CreateBackupMode;
 import brooklyn.event.feed.AbstractFeed;
 import brooklyn.internal.BrooklynFeatureEnablement;
 import brooklyn.location.Location;
@@ -285,7 +286,7 @@ public class RebindManagerImpl implements RebindManager {
         LOG.debug("Starting persistence ("+this+"), mgmt "+managementContext.getManagementNodeId());
         if (!persistenceRunning) {
             if (managementContext.getBrooklynProperties().getConfig(BrooklynServerConfig.PERSISTENCE_BACKUPS_REQUIRED_ON_PROMOTION))
{
-                BrooklynPersistenceUtils.createBackup(managementContext, "promotion", MementoCopyMode.REMOTE);
+                BrooklynPersistenceUtils.createBackup(managementContext, CreateBackupMode.PROMOTION,
MementoCopyMode.REMOTE);
             }
         }
         persistenceRunning = true;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f6cd0314/core/src/main/java/brooklyn/entity/rebind/persister/BrooklynPersistenceUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/persister/BrooklynPersistenceUtils.java
b/core/src/main/java/brooklyn/entity/rebind/persister/BrooklynPersistenceUtils.java
index 8b5317d..ea52f36 100644
--- a/core/src/main/java/brooklyn/entity/rebind/persister/BrooklynPersistenceUtils.java
+++ b/core/src/main/java/brooklyn/entity/rebind/persister/BrooklynPersistenceUtils.java
@@ -46,6 +46,7 @@ import brooklyn.management.ha.ManagementNodeState;
 import brooklyn.management.ha.ManagementPlaneSyncRecord;
 import brooklyn.management.ha.ManagementPlaneSyncRecordPersisterToObjectStore;
 import brooklyn.management.ha.MementoCopyMode;
+import brooklyn.management.internal.LocalLocationManager;
 import brooklyn.management.internal.ManagementContextInternal;
 import brooklyn.mementos.BrooklynMementoRawData;
 import brooklyn.mementos.Memento;
@@ -85,17 +86,14 @@ public class BrooklynPersistenceUtils {
         locationContainer = BrooklynServerPaths.newMainPersistencePathResolver(managementContext).location(locationSpec).dir(locationContainer).resolve();
 
         Location location = null;
-        try {
-            if (Strings.isBlank(locationSpec)) {
-                location = managementContext.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class));
-            } else {
-                location = managementContext.getLocationRegistry().resolve(locationSpec);
-                if (!(location instanceof LocationWithObjectStore)) {
-                    throw new IllegalArgumentException("Destination location "+location+"
does not offer a persistent store");
-                }
+        if (Strings.isBlank(locationSpec)) {
+            location = managementContext.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class)
+                .configure(LocalLocationManager.CREATE_UNMANAGED, true));
+        } else {
+            location = managementContext.getLocationRegistry().resolve(locationSpec, false,
null).get();
+            if (!(location instanceof LocationWithObjectStore)) {
+                throw new IllegalArgumentException("Destination location "+location+" does
not offer a persistent store");
             }
-        } finally {
-            if (location!=null) managementContext.getLocationManager().unmanage(location);
         }
         destinationObjectStore = ((LocationWithObjectStore)location).newPersistenceObjectStore(locationContainer);
         
@@ -204,35 +202,42 @@ public class BrooklynPersistenceUtils {
         log.debug("Wrote full memento to "+targetStore+" in "+Time.makeTimeStringRounded(Duration.of(timer)));
     }
 
-    public static void createBackup(ManagementContext managementContext, String label, MementoCopyMode
source) {
+    public static enum CreateBackupMode { PROMOTION, DEMOTION, CUSTOM;
+        @Override public String toString() { return super.toString().toLowerCase(); }
+    }
+    
+    public static void createBackup(ManagementContext managementContext, CreateBackupMode
mode, MementoCopyMode source) {
         if (source==null || source==MementoCopyMode.AUTO) {
-            if ("promotion".equalsIgnoreCase(label)) source = MementoCopyMode.REMOTE;
-            else if ("demotion".equalsIgnoreCase(label)) source = MementoCopyMode.LOCAL;
-            else throw new IllegalArgumentException("Cannot detect copy mode for "+label+"/"+source);
+            switch (mode) {
+            case PROMOTION: source = MementoCopyMode.REMOTE; break;
+            case DEMOTION: source = MementoCopyMode.LOCAL; break;
+            default:
+                throw new IllegalArgumentException("Cannot detect copy mode for "+mode+"/"+source);
+            }
         }
         BrooklynMementoRawData memento = null;
         ManagementPlaneSyncRecord planeState = null;
         
         try {
-            log.debug("Loading persisted state on "+label+" for backup purposes");
+            log.debug("Loading persisted state on "+mode+" for backup purposes");
             memento = newStateMemento(managementContext, source);
             try {
                 planeState = newManagerMemento(managementContext, source);
             } catch (Exception e) {
                 Exceptions.propagateIfFatal(e);
-                log.warn("Unable to access management plane sync state on "+label+" (ignoring):
"+e, e);
+                log.warn("Unable to access management plane sync state on "+mode+" (ignoring):
"+e, e);
             }
         
             PersistenceObjectStore destinationObjectStore = null;
             String backupSpec = managementContext.getConfig().getConfig(BrooklynServerConfig.PERSISTENCE_BACKUPS_LOCATION_SPEC);
             try {
                 String backupContainer = BrooklynServerPaths.newBackupPersistencePathResolver(managementContext).location(backupSpec)
-                    .resolveWithSubpathFor(managementContext, label);
+                    .resolveWithSubpathFor(managementContext, mode.toString());
                 destinationObjectStore = BrooklynPersistenceUtils.newPersistenceObjectStore(managementContext,
backupSpec, backupContainer);
-                log.debug("Backing up persisted state on "+label+", to "+destinationObjectStore.getSummaryName());
+                log.debug("Backing up persisted state on "+mode+", to "+destinationObjectStore.getSummaryName());
                 BrooklynPersistenceUtils.writeMemento(managementContext, memento, destinationObjectStore);
                 BrooklynPersistenceUtils.writeManagerMemento(managementContext, planeState,
destinationObjectStore);
-                log.info("Back-up of persisted state created on "+label+", in "+destinationObjectStore.getSummaryName());
+                log.info("Back-up of persisted state created on "+mode+", in "+destinationObjectStore.getSummaryName());
                 
             } catch (Exception e) {
                 Exceptions.propagateIfFatal(e);
@@ -240,19 +245,19 @@ public class BrooklynPersistenceUtils {
                 if (!Strings.isBlank(backupSpec) && !"localhost".equals(backupSpec))
{
                     backupSpec = "localhost";
                     String backupContainer = BrooklynServerPaths.newBackupPersistencePathResolver(managementContext).location(backupSpec)
-                        .resolveWithSubpathFor(managementContext, label);
+                        .resolveWithSubpathFor(managementContext, mode.toString());
                     destinationObjectStore = BrooklynPersistenceUtils.newPersistenceObjectStore(managementContext,
backupSpec, backupContainer);
                     log.warn("Persisted state back-up to "+failedStore.getSummaryName()+"
failed with "+e, e);
                     
-                    log.debug("Backing up persisted state on "+label+", locally because remote
failed, to "+destinationObjectStore.getSummaryName());
+                    log.debug("Backing up persisted state on "+mode+", locally because remote
failed, to "+destinationObjectStore.getSummaryName());
                     BrooklynPersistenceUtils.writeMemento(managementContext, memento, destinationObjectStore);
                     BrooklynPersistenceUtils.writeManagerMemento(managementContext, planeState,
destinationObjectStore);
-                    log.info("Back-up of persisted state created on "+label+", locally because
remote failed, in "+destinationObjectStore.getSummaryName());
+                    log.info("Back-up of persisted state created on "+mode+", locally because
remote failed, in "+destinationObjectStore.getSummaryName());
                 }
             }
         } catch (Exception e) {
             Exceptions.propagateIfFatal(e);
-            log.warn("Unable to backup management plane sync state on "+label+" (ignoring):
"+e, e);
+            log.warn("Unable to backup management plane sync state on "+mode+" (ignoring):
"+e, e);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f6cd0314/core/src/main/java/brooklyn/management/ha/HighAvailabilityManagerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/ha/HighAvailabilityManagerImpl.java b/core/src/main/java/brooklyn/management/ha/HighAvailabilityManagerImpl.java
index 73d431d..08c1d06 100644
--- a/core/src/main/java/brooklyn/management/ha/HighAvailabilityManagerImpl.java
+++ b/core/src/main/java/brooklyn/management/ha/HighAvailabilityManagerImpl.java
@@ -44,6 +44,7 @@ import brooklyn.entity.basic.ConfigKeys;
 import brooklyn.entity.basic.EntityInternal;
 import brooklyn.entity.rebind.RebindManager;
 import brooklyn.entity.rebind.persister.BrooklynPersistenceUtils;
+import brooklyn.entity.rebind.persister.BrooklynPersistenceUtils.CreateBackupMode;
 import brooklyn.entity.rebind.persister.PersistenceActivityMetrics;
 import brooklyn.entity.rebind.plane.dto.BasicManagementNodeSyncRecord;
 import brooklyn.entity.rebind.plane.dto.ManagementPlaneSyncRecordImpl;
@@ -174,9 +175,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager
{
      * including e.g. {@link Duration#PRACTICALLY_FOREVER} to disable polling;
      * or <code>null</code> to clear a local override */
     public HighAvailabilityManagerImpl setPollPeriod(Duration val) {
-        synchronized (this) {
-            this.pollPeriodLocalOverride = val;
-        }
+        this.pollPeriodLocalOverride = val;
         if (running) {
             registerPollTask();
         }
@@ -196,7 +195,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager
{
     /** Overrides {@link #HEARTBEAT_TIMEOUT} from brooklyn config, 
      * including e.g. {@link Duration#PRACTICALLY_FOREVER} to prevent failover due to heartbeat
absence;
      * or <code>null</code> to clear a local override */
-    public synchronized HighAvailabilityManagerImpl setHeartbeatTimeout(Duration val) {
+    public HighAvailabilityManagerImpl setHeartbeatTimeout(Duration val) {
         this.heartbeatTimeoutOverride = val;
         return this;
     }
@@ -776,7 +775,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager
{
     
     protected void backupOnDemotionIfNeeded() {
         if (managementContext.getBrooklynProperties().getConfig(BrooklynServerConfig.PERSISTENCE_BACKUPS_REQUIRED_ON_DEMOTION))
{
-            BrooklynPersistenceUtils.createBackup(managementContext, "demotion", MementoCopyMode.LOCAL);
+            BrooklynPersistenceUtils.createBackup(managementContext, CreateBackupMode.DEMOTION,
MementoCopyMode.LOCAL);
         }
     }
 


Mime
View raw message