public static ManagementPlaneSyncRecord newManagerMemento(ManagementContext mgmt, MementoCopyMode source) { switch (source) { case LOCAL: return mgmt.getHighAvailabilityManager().getLastManagementPlaneSyncRecord(); case REMOTE: return mgmt.getHighAvailabilityManager().loadManagementPlaneSyncRecord(true); case AUTO: throw new IllegalStateException("Copy mode AUTO not supported here"); } throw new IllegalStateException("Should not come here, unknown mode "+source); }
@Override public Response clearHighAvailabilityPlaneStates() { mgmt().getHighAvailabilityManager().publishClearNonMaster(); return Response.ok().build(); }
public boolean isHaHotStatus() { ManagementNodeState state = mgmt().getHighAvailabilityManager().getNodeState(); return HOT_STATES.contains(state); }
@Override public Map<String, Object> getHighAvailabilityMetrics() { return mgmt().getHighAvailabilityManager().getMetrics(); }
@Override public long getHighAvailabitlityPriority() { return mgmt().getHighAvailabilityManager().getPriority(); }
private boolean isMaster() { return ManagementNodeState.MASTER.equals(mgmt.getHighAvailabilityManager().getNodeState()); }
@Override public ManagementNodeState setHighAvailabilityNodeState(HighAvailabilityMode mode) { if (mode==null) throw new IllegalStateException("Missing parameter: mode"); HighAvailabilityManager haMgr = mgmt().getHighAvailabilityManager(); ManagementNodeState existingState = haMgr.getNodeState(); haMgr.changeMode(mode); return existingState; }
private boolean isMaster() { return ManagementNodeState.MASTER.equals( mgmt.getContext(ManagementContext.class) .getHighAvailabilityManager() .getNodeState()); }
@Override public long setHighAvailabilityPriority(long priority) { HighAvailabilityManager haMgr = mgmt().getHighAvailabilityManager(); long oldPrio = haMgr.getPriority(); haMgr.setPriority(priority); return oldPrio; }
private void stopWriteNode() { writeMgmt.getHighAvailabilityManager().stop(); }
private boolean isMaster() { return ManagementNodeState.MASTER.equals(mgmt().getHighAvailabilityManager().getNodeState()); }
private void assertReadIsMaster() { assertEquals(readMgmt.getHighAvailabilityManager().getNodeState(), ManagementNodeState.MASTER); }
protected void populateCatalog(CatalogInitialization catInit) { try { // run cat init now if it hasn't yet been run; // will also run if there was an ignored error in catalog above, allowing it to fail startup here if requested if (catInit!=null && !catInit.hasRunOfficialInitialization()) { if (persistMode==PersistMode.DISABLED) { LOG.debug("Loading catalog as part of launch sequence (it was not loaded as part of any rebind sequence)"); catInit.populateCatalog(ManagementNodeState.MASTER, true, true, null); } else { // should have loaded during rebind ManagementNodeState state = managementContext.getHighAvailabilityManager().getNodeState(); LOG.warn("Loading catalog for "+state+" as part of launch sequence (it was not loaded as part of the rebind sequence)"); catInit.populateCatalog(state, true, true, null); } } } catch (Exception e) { handleSubsystemStartupError(ignoreCatalogErrors, "initial catalog", e); } }
@Override public Integer call() { ManagementNodeState state = readMgmt.getHighAvailabilityManager().getNodeState(); if (state != ManagementNodeState.MASTER) { throw new RuntimeException("Not master yet " + state); } return super.call(); } }
/** generates and writes mementos for the given mgmt context to the given targetStore; * this may be taken from {@link MementoCopyMode#LOCAL} current state * or {@link MementoCopyMode#REMOTE} persisted state, or the default {@link MementoCopyMode#AUTO} detected */ public static void writeMemento(ManagementContext mgmt, PersistenceObjectStore targetStore, MementoCopyMode source) { if (source==null || source==MementoCopyMode.AUTO) source = (mgmt.getHighAvailabilityManager().getNodeState()==ManagementNodeState.MASTER ? MementoCopyMode.LOCAL : MementoCopyMode.REMOTE); Stopwatch timer = Stopwatch.createStarted(); BrooklynMementoRawData dataRecord = newStateMemento(mgmt, source); ManagementPlaneSyncRecord mgmtRecord = newManagerMemento(mgmt, source); writeMemento(mgmt, dataRecord, targetStore); writeManagerMemento(mgmt, mgmtRecord, targetStore); log.debug("Wrote full memento to "+targetStore+" in "+Time.makeTimeStringRounded(Duration.of(timer))); }
@Override public HighAvailabilitySummary getHighAvailabilityPlaneStates() { if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SERVER_STATUS, null)) throw WebResourceUtils.forbidden("User '%s' is not authorized for this operation", Entitlements.getEntitlementContext().user()); ManagementPlaneSyncRecord memento = mgmt().getHighAvailabilityManager().getLastManagementPlaneSyncRecord(); if (memento==null) memento = mgmt().getHighAvailabilityManager().loadManagementPlaneSyncRecord(true); if (memento==null) return null; return HighAvailabilityTransformer.highAvailabilitySummary(mgmt().getManagementNodeId(), memento); }
private static Server startServer(ManagementContext mgmt, ContextHandler context, String summary, boolean disableHighAvailability) { // TODO this repeats code in BrooklynLauncher / WebServer. should merge the two paths. boolean secure = mgmt != null && !BrooklynWebConfig.hasNoSecurityOptions(mgmt.getConfig()); if (secure) { log.debug("Detected security configured, launching server on all network interfaces"); } else { log.debug("Detected no security configured, launching server on loopback (localhost) network interface only"); if (mgmt!=null) { log.debug("Detected no security configured, running on loopback; disabling authentication"); ((BrooklynProperties)mgmt.getConfig()).put(BrooklynWebConfig.SECURITY_PROVIDER_CLASSNAME, AnyoneSecurityProvider.class.getName()); } } if (mgmt != null && disableHighAvailability) mgmt.getHighAvailabilityManager().disabled(); InetSocketAddress bindLocation = new InetSocketAddress( secure ? Networking.ANY_NIC : Networking.LOOPBACK, Networking.nextAvailablePort(FAVOURITE_PORT)); return startServer(mgmt, context, summary, bindLocation); }
private ManagementContext createManagementContext(File mementoDir, HighAvailabilityMode mode) { ManagementContext mgmt = RebindTestUtils.managementContextBuilder(mementoDir, getClass().getClassLoader()) .persistPeriodMillis(1) .forLive(false) .emptyCatalog(true) .buildUnstarted(); if (mode == HighAvailabilityMode.DISABLED) { mgmt.getHighAvailabilityManager().disabled(); } else { mgmt.getHighAvailabilityManager().start(mode); } new BrooklynCampPlatformLauncherNoServer() .useManagementContext(mgmt) .launch(); return mgmt; }
@Override public ManagementNodeState getHighAvailabilityNodeState() { if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SERVER_STATUS, null)) throw WebResourceUtils.forbidden("User '%s' is not authorized for this operation", Entitlements.getEntitlementContext().user()); Maybe<ManagementContext> mm = mgmtMaybe(); if (mm.isAbsent()) return ManagementNodeState.INITIALIZING; return mm.get().getHighAvailabilityManager().getNodeState(); }
protected void setUpServer(ManagementContext mgmt, boolean skipSecurity) { try { if (serverMgmt!=null) throw new IllegalStateException("server already set up"); serverMgmt = mgmt; server = new BrooklynWebServer(mgmt); server.skipSecurity(skipSecurity); server.start(); serverMgmt.getHighAvailabilityManager().disabled(); serverApp = TestApplication.Factory.newManagedInstanceForTests(serverMgmt); ((LocalManagementContextForTests)serverMgmt).noteStartupComplete(); } catch (Exception e) { throw Exceptions.propagate(e); } }