Return-Path: X-Original-To: apmail-brooklyn-dev-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 826C317C13 for ; Tue, 19 May 2015 23:38:29 +0000 (UTC) Received: (qmail 64970 invoked by uid 500); 19 May 2015 23:38:29 -0000 Delivered-To: apmail-brooklyn-dev-archive@brooklyn.apache.org Received: (qmail 64934 invoked by uid 500); 19 May 2015 23:38:29 -0000 Mailing-List: contact dev-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list dev@brooklyn.incubator.apache.org Received: (qmail 64921 invoked by uid 99); 19 May 2015 23:38:29 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 May 2015 23:38:29 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id AD3FB1A303E for ; Tue, 19 May 2015 23:38:28 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.971 X-Spam-Level: X-Spam-Status: No, score=0.971 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id BDS1Eu5Ukiir for ; Tue, 19 May 2015 23:38:23 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with SMTP id 188CB22F28 for ; Tue, 19 May 2015 23:38:23 +0000 (UTC) Received: (qmail 64879 invoked by uid 99); 19 May 2015 23:38:22 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 May 2015 23:38:22 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D302DE35A4; Tue, 19 May 2015 23:38:22 +0000 (UTC) From: ahgittin To: dev@brooklyn.incubator.apache.org Reply-To: dev@brooklyn.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-brooklyn pull request: CLI commands for manipulating cat... Content-Type: text/plain Message-Id: <20150519233822.D302DE35A4@git1-us-west.apache.org> Date: Tue, 19 May 2015 23:38:22 +0000 (UTC) Github user ahgittin commented on a diff in the pull request: https://github.com/apache/incubator-brooklyn/pull/617#discussion_r30659421 --- Diff: core/src/main/java/brooklyn/entity/rebind/RebindIteration.java --- @@ -341,38 +340,67 @@ protected void rebuildCatalog() { } } } + + // See notes in CatalogInitialization - // Register catalogue items with the management context. Loads the bundles in the OSGi framework. - CatalogLoadMode catalogLoadMode = managementContext.getConfig().getConfig(BrooklynServerConfig.CATALOG_LOAD_MODE); + Collection> catalogItems = rebindContext.getCatalogItems(); + CatalogInitialization catInit = ((ManagementContextInternal)managementContext).getCatalogInitialization(); + catInit.injectManagementContext(managementContext); + catInit.applyCatalogLoadMode(); + Collection> itemsForResettingCatalog = null; + boolean needsInitialCatalog; if (rebindManager.persistCatalogItemsEnabled) { - boolean shouldResetCatalog = catalogLoadMode == CatalogLoadMode.LOAD_PERSISTED_STATE - || (!isEmpty && catalogLoadMode == CatalogLoadMode.LOAD_BROOKLYN_CATALOG_URL_IF_NO_PERSISTED_STATE); - boolean shouldLoadDefaultCatalog = catalogLoadMode == CatalogLoadMode.LOAD_BROOKLYN_CATALOG_URL - || (isEmpty && catalogLoadMode == CatalogLoadMode.LOAD_BROOKLYN_CATALOG_URL_IF_NO_PERSISTED_STATE); - if (shouldResetCatalog) { - // Reset catalog with previously persisted state - logRebindingDebug("RebindManager resetting management context catalog to previously persisted state"); - managementContext.getCatalog().reset(rebindContext.getCatalogItems()); - } else if (shouldLoadDefaultCatalog) { - // Load catalogue as normal - // TODO in read-only mode, should do this less frequently than entities etc - logRebindingDebug("RebindManager loading default catalog"); - ((BasicBrooklynCatalog) managementContext.getCatalog()).resetCatalogToContentsAtConfiguredUrl(); + if (!catInit.hasRunOfficial() && catInit.isInitialResetRequested()) { + String message = "RebindManager resetting catalog on first run (catalog persistence enabled, but reset explicitly specified). "; + if (catalogItems.isEmpty()) { + message += "Catalog was empty anyway."; + } else { + message += "Deleting "+catalogItems.size()+" persisted catalog item"+Strings.s(catalogItems)+": "+catalogItems; + if (shouldLogRebinding()) { + LOG.info(message); + } + } + logRebindingDebug(message); + + itemsForResettingCatalog = MutableList.>of(); + + PersisterDeltaImpl delta = new PersisterDeltaImpl(); + for (String catalogItemId: mementoRawData.getCatalogItems().keySet()) { + delta.removedCatalogItemIds.add(catalogItemId); + } + getPersister().queueDelta(delta); + + mementoRawData.clearCatalogItems(); + needsInitialCatalog = true; } else { - // Management context should have taken care of loading the catalogue - Collection> catalogItems = rebindContext.getCatalogItems(); - String message = "RebindManager not resetting catalog to persisted state. Catalog load mode is {}."; - if (!catalogItems.isEmpty() && shouldLogRebinding()) { - LOG.info(message + " There {} {} item{} persisted.", new Object[]{ - catalogLoadMode, catalogItems.size() == 1 ? "was" : "were", catalogItems.size(), Strings.s(catalogItems)}); - } else if (LOG.isDebugEnabled()) { - logRebindingDebug(message, catalogLoadMode); + if (!isEmpty) { + logRebindingDebug("RebindManager clearing local catalog and loading from persisted state"); + itemsForResettingCatalog = rebindContext.getCatalogItems(); + needsInitialCatalog = false; + } else { + if (catInit.hasRunOfficial()) { + logRebindingDebug("RebindManager will re-add any new items (persisted state empty)"); + needsInitialCatalog = false; + } else { + logRebindingDebug("RebindManager loading initial catalog locally because persisted state empty"); + needsInitialCatalog = true; + } } } - // TODO destroy old (as above) } else { - logRebindingDebug("RebindManager not resetting catalog because catalog persistence is disabled"); + if (catInit.hasRunOfficial()) { + logRebindingDebug("RebindManager skipping catalog init because it has already run (catalog persistence disabled)"); + needsInitialCatalog = false; + } else { + logRebindingDebug("RebindManager will initialize catalog locally because catalog persistence is disabled"); + needsInitialCatalog = true; + } } + + // TODO in read-only mode, perhaps do this less frequently than entities etc ? + // both in RW and in RO mode, the first run reads the initialization data; + // maybe not desired for RO as it defers problems, although if it's standalone it is desired + catInit.populateCatalog(needsInitialCatalog, itemsForResettingCatalog); --- End diff -- meh i dislike `Optional` except when null is ambiguous or you want to chain or maintain an error on access (and in that last case `Maybe` is better). --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---