You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by iyovcheva <gi...@git.apache.org> on 2016/07/18 13:09:33 UTC

[GitHub] brooklyn-server pull request #264: [DO NOT MERGE] Dangling references cleane...

GitHub user iyovcheva opened a pull request:

    https://github.com/apache/brooklyn-server/pull/264

    [DO NOT MERGE] Dangling references cleaner

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/iyovcheva/brooklyn-server dangling-references-cleaner

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/brooklyn-server/pull/264.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #264
    
----
commit 4de6d5c943b421489501e49e2078e5bf8f4ff5a5
Author: Ivana Yovcheva <iv...@gmail.com>
Date:   2016-07-15T13:58:03Z

    Add test resources for orphaned locations cleaner

commit 80bea198383ec5d1d20117fd7805a69860765baa
Author: Ivana Yovcheva <iv...@gmail.com>
Date:   2016-06-15T16:22:43Z

    Cleaner for the old dangling references

----


---
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.
---

[GitHub] brooklyn-server pull request #264: [DO NOT MERGE] Dangling references cleane...

Posted by aledsage-tmp <gi...@git.apache.org>.
Github user aledsage-tmp commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/264#discussion_r71152820
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/transformer/impl/DeleteOrphanedLocationsTransformer.java ---
    @@ -94,6 +126,86 @@ public boolean containsAny(Collection<?> container, Iterable<?> contenders) {
             }
             return result;
         }
    +
    +    public Map<String, String> findLocationsToKeep(BrooklynMementoRawData input) {
    +        Map<String, String> locationsToKeep = MutableMap.of();
    +        Set<String> allReferencedLocations = findAllReferencedLocations(input);
    +
    +        for (Map.Entry location: input.getLocations().entrySet()) {
    +            if (allReferencedLocations.contains(location.getKey())) {
    +                locationsToKeep.put((String) location.getKey(), (String) location.getValue());
    +            }
    +        }
    +        return locationsToKeep;
    +    }
    +
    +    public Set<String> findAllReferencedLocations(BrooklynMementoRawData input) {
    +        Set<String> allReferencedLocations = MutableSet.of();
    +
    +        allReferencedLocations.addAll(searchLocationsToKeepInEntities(input.getEntities()));
    +        allReferencedLocations.addAll(searchLocationsToKeepInPolicies(input.getPolicies()));
    +        allReferencedLocations.addAll(searchLocationsToKeepInEnrichers(input.getEnrichers()));
    +        allReferencedLocations.addAll(searchLocationsToKeepInLocations(input.getLocations(), allReferencedLocations));
    +
    +        return allReferencedLocations;
    +    }
    +
    +    private Set<String> searchLocationsToKeepInEntities(Map<String, String> entities) {
    +        Set<String> result = MutableSet.of();
    +
    +        for(Map.Entry entity: entities.entrySet()) {
    +
    +            String locationProxyPrefix = "<locationProxy>";
    +            String locationProxySuffix = "</locationProxy>";
    +            String locationPrefix = "<locations>\n" +
    +                    "    <string>";
    +            String locationSuffix = "</string>\n" +
    +                    "  </locations>";
    +            String locationPrefixWinEOF = "<locations>\r\n" +
    +                    "    <string>";
    +            String locationSuffixWinEOF = "</string>\r\n" +
    +                    "  </locations>";
    +
    +            String entityString = (String) entity.getValue();
    +            result.addAll(Strings.getAllOccurrencesBetween(entityString, locationProxyPrefix, locationProxySuffix));
    +            result.addAll(Strings.getAllOccurrencesBetween(entityString, locationPrefix, locationSuffix));
    +            result.addAll(Strings.getAllOccurrencesBetween(entityString, locationPrefixWinEOF, locationSuffixWinEOF));
    +        }
    +
    +        return result;
    +    }
    +
    +    private Set<String> searchLocationsToKeepInLocations(Map<String, String> locations, Set<String> alreadyReferencedLocations) {
    --- End diff --
    
    Also need to keep parent to and children.


---
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.
---

[GitHub] brooklyn-server pull request #264: Orphaned locations cleaner

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/264#discussion_r71566442
  
    --- Diff: server-cli/src/main/java/org/apache/brooklyn/cli/Main.java ---
    @@ -827,6 +827,82 @@ public ToStringHelper string() {
             }
         }
     
    +    @Command(name = "clean-orphaned-locations", description = "Removes existing orphaned locations")
    +    public static class CleanOrphanedLocationsCommand extends BrooklynCommandCollectingArgs {
    --- End diff --
    
    Long term, it would be good to have a dry run mode. But not in this PR.


---
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.
---

[GitHub] brooklyn-server pull request #264: [DO NOT MERGE] Dangling references cleane...

Posted by aledsage-tmp <gi...@git.apache.org>.
Github user aledsage-tmp commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/264#discussion_r71154062
  
    --- Diff: launcher/pom.xml ---
    @@ -218,6 +218,17 @@
                 <classifier>tests</classifier>
                 <scope>test</scope>
             </dependency>
    +        <dependency>
    +            <groupId>org.apache.brooklyn</groupId>
    +            <artifactId>brooklyn-core</artifactId>
    +            <version>0.10.0-SNAPSHOT</version>
    --- End diff --
    
    Use project.version


---
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.
---

[GitHub] brooklyn-server pull request #264: Orphaned locations cleaner

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/264#discussion_r71566594
  
    --- Diff: server-cli/src/main/java/org/apache/brooklyn/cli/Main.java ---
    @@ -827,6 +827,82 @@ public ToStringHelper string() {
             }
         }
     
    +    @Command(name = "clean-orphaned-locations", description = "Removes existing orphaned locations")
    +    public static class CleanOrphanedLocationsCommand extends BrooklynCommandCollectingArgs {
    +
    +        @Option(name = { "--localBrooklynProperties" }, title = "local brooklyn.properties file",
    +                description = "local brooklyn.properties file, specific to this launch (appending to and overriding global properties)")
    +        public String localBrooklynProperties;
    +
    +        @Option(name = { "--persistenceDir" }, title = "persistence dir",
    +                description = "The directory to read persisted state (or container name if using an object store)")
    +        public String persistenceDir;
    +
    +        @Option(name = { "--persistenceLocation" }, title = "persistence location",
    +                description = "The location spec for an object store to read persisted state")
    +        public String persistenceLocation;
    +
    +        @Option(name = { "--destinationDir" }, required = true, title = "destination dir",
    +                description = "The directory to copy persistence data to without orphaned locations")
    +        public String destinationDir;
    +
    +        @Option(name = { "--destinationLocation" }, title = "persistence location",
    +                description = "The location spec for an object store to copy data to")
    +        public String destinationLocation;
    +
    +        @Option(name = { "--transformations" }, title = "transformations",
    +                description = "local transformations file, to be applied to the copy of the data before uploading it")
    +        public String transformations;
    +
    +        @Override
    +        public Void call() throws Exception {
    +            checkNotNull(destinationDir, "orphanedReferencesTmpDir");
    --- End diff --
    
    Change "orphanedReferencesTmpDir" to "destinationDir" - that will be the NullPointerException message.


---
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.
---

[GitHub] brooklyn-server pull request #264: Orphaned locations cleaner

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/264#discussion_r71565876
  
    --- Diff: server-cli/src/main/java/org/apache/brooklyn/cli/Main.java ---
    @@ -827,6 +827,82 @@ public ToStringHelper string() {
             }
         }
     
    +    @Command(name = "clean-orphaned-locations", description = "Removes existing orphaned locations")
    +    public static class CleanOrphanedLocationsCommand extends BrooklynCommandCollectingArgs {
    +
    +        @Option(name = { "--localBrooklynProperties" }, title = "local brooklyn.properties file",
    +                description = "local brooklyn.properties file, specific to this launch (appending to and overriding global properties)")
    +        public String localBrooklynProperties;
    +
    +        @Option(name = { "--persistenceDir" }, title = "persistence dir",
    +                description = "The directory to read persisted state (or container name if using an object store)")
    +        public String persistenceDir;
    +
    +        @Option(name = { "--persistenceLocation" }, title = "persistence location",
    +                description = "The location spec for an object store to read persisted state")
    +        public String persistenceLocation;
    +
    +        @Option(name = { "--destinationDir" }, required = true, title = "destination dir",
    +                description = "The directory to copy persistence data to without orphaned locations")
    +        public String destinationDir;
    +
    +        @Option(name = { "--destinationLocation" }, title = "persistence location",
    +                description = "The location spec for an object store to copy data to")
    +        public String destinationLocation;
    +
    +        @Option(name = { "--transformations" }, title = "transformations",
    +                description = "local transformations file, to be applied to the copy of the data before uploading it")
    +        public String transformations;
    +
    +        @Override
    +        public Void call() throws Exception {
    +            checkNotNull(destinationDir, "orphanedReferencesTmpDir");
    +
    +            BrooklynLauncher launcher;
    +            failIfArguments();
    +
    +            try {
    +                log.info("Retrieving and copying persisted state to " + destinationDir + " without orphaned locations");
    +
    +
    +                PersistMode persistMode = PersistMode.AUTO;
    --- End diff --
    
    I wonder if we should use `PersistMode.REBIND` - i.e. fail if there is no persisted state in the given directory.


---
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.
---

[GitHub] brooklyn-server issue #264: [DO NOT MERGE] Dangling references cleaner

Posted by aledsage-tmp <gi...@git.apache.org>.
Github user aledsage-tmp commented on the issue:

    https://github.com/apache/brooklyn-server/pull/264
  
    There are 114 changed/added files. That seems excessive (though struggling to review properly on iPad because of that).
    
    Instead of checking in an entire persisted state folder (eg including brooklyn-server/launcher/src/test/resources/orphaned-locations-test-data/data-without-orphaned-locations/catalog/org.apache.brooklyn.entity.cm.ansible.AnsibleEntity_0.10.0-SNAPSHOT), I'd recommend we have far more focused test cases with just a minimal file. Or even construct the persisted state on the fly.


---
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.
---

[GitHub] brooklyn-server pull request #264: Orphaned locations cleaner

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/264#discussion_r71566145
  
    --- Diff: server-cli/src/main/java/org/apache/brooklyn/cli/Main.java ---
    @@ -931,6 +1007,7 @@ public ToStringHelper string() {
                             HelpCommand.class,
                             cliInfoCommand(),
                             GeneratePasswordCommand.class,
    +                        CleanOrphanedLocationsCommand.class,
    --- End diff --
    
    This should now be called `CleanOrphanedStateCommand`.


---
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.
---

[GitHub] brooklyn-server pull request #264: Orphaned locations cleaner

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/264#discussion_r71566328
  
    --- Diff: server-cli/src/main/java/org/apache/brooklyn/cli/Main.java ---
    @@ -827,6 +827,82 @@ public ToStringHelper string() {
             }
         }
     
    +    @Command(name = "clean-orphaned-locations", description = "Removes existing orphaned locations")
    --- End diff --
    
    How about name "clean-orphaned-state" and description "Removes existing orphaned persisted state (e.g. locations, policies, enrichers and feeds)".


---
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.
---

[GitHub] brooklyn-server issue #264: Orphaned locations cleaner

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the issue:

    https://github.com/apache/brooklyn-server/pull/264
  
    Merging now. I'll address my most recent comments in a new PR later this evening.


---
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.
---

[GitHub] brooklyn-server pull request #264: Orphaned locations cleaner

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/264#discussion_r71565538
  
    --- Diff: server-cli/src/main/java/org/apache/brooklyn/cli/Main.java ---
    @@ -827,6 +827,82 @@ public ToStringHelper string() {
             }
         }
     
    +    @Command(name = "clean-orphaned-locations", description = "Removes existing orphaned locations")
    +    public static class CleanOrphanedLocationsCommand extends BrooklynCommandCollectingArgs {
    +
    +        @Option(name = { "--localBrooklynProperties" }, title = "local brooklyn.properties file",
    +                description = "local brooklyn.properties file, specific to this launch (appending to and overriding global properties)")
    +        public String localBrooklynProperties;
    +
    +        @Option(name = { "--persistenceDir" }, title = "persistence dir",
    +                description = "The directory to read persisted state (or container name if using an object store)")
    +        public String persistenceDir;
    +
    +        @Option(name = { "--persistenceLocation" }, title = "persistence location",
    +                description = "The location spec for an object store to read persisted state")
    +        public String persistenceLocation;
    +
    +        @Option(name = { "--destinationDir" }, required = true, title = "destination dir",
    +                description = "The directory to copy persistence data to without orphaned locations")
    +        public String destinationDir;
    +
    +        @Option(name = { "--destinationLocation" }, title = "persistence location",
    +                description = "The location spec for an object store to copy data to")
    +        public String destinationLocation;
    +
    +        @Option(name = { "--transformations" }, title = "transformations",
    +                description = "local transformations file, to be applied to the copy of the data before uploading it")
    +        public String transformations;
    --- End diff --
    
    The `transformations` field isn't used. We should delete it.


---
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.
---

[GitHub] brooklyn-server pull request #264: [DO NOT MERGE] Dangling references cleane...

Posted by aledsage-tmp <gi...@git.apache.org>.
Github user aledsage-tmp commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/264#discussion_r71155001
  
    --- Diff: launcher/src/test/java/org/apache/brooklyn/launcher/CleanOrphanedLocationsLiveTest.java ---
    @@ -0,0 +1,247 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.launcher;
    +
    +import org.apache.brooklyn.api.mgmt.ManagementContext;
    +import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
    +import org.apache.brooklyn.api.mgmt.rebind.PersistenceExceptionHandler;
    +import org.apache.brooklyn.api.mgmt.rebind.RebindManager;
    +import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoRawData;
    +import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
    +import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
    +import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
    +import org.apache.brooklyn.core.mgmt.persist.BrooklynMementoPersisterToObjectStore;
    +import org.apache.brooklyn.core.mgmt.persist.BrooklynPersistenceUtils;
    +import org.apache.brooklyn.core.mgmt.persist.PersistMode;
    +import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore;
    +import org.apache.brooklyn.core.mgmt.rebind.PersistenceExceptionHandlerImpl;
    +import org.apache.brooklyn.core.mgmt.rebind.RebindManagerImpl;
    +import org.apache.brooklyn.core.mgmt.rebind.transformer.impl.DeleteOrphanedLocationsTransformer;
    +import org.apache.brooklyn.core.server.BrooklynServerConfig;
    +import org.apache.brooklyn.core.server.BrooklynServerPaths;
    +import org.apache.brooklyn.test.Asserts;
    +import org.apache.brooklyn.util.collections.MutableMap;
    +import org.apache.brooklyn.util.collections.MutableSet;
    +import org.apache.brooklyn.util.time.Duration;
    +import org.apache.commons.lang.builder.EqualsBuilder;
    +import org.testng.annotations.AfterMethod;
    +import org.testng.annotations.BeforeMethod;
    +import org.testng.annotations.Test;
    +
    +import org.apache.brooklyn.core.internal.BrooklynProperties;
    +
    +import java.util.Map;
    +import java.util.Set;
    +
    +public class CleanOrphanedLocationsLiveTest {
    --- End diff --
    
    It's very hard to tell from the test code what cases are actually being tested. I'll look at writing some test cases later, to see how we can do this in a more explicit way.


---
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.
---

[GitHub] brooklyn-server pull request #264: Orphaned locations cleaner

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/264#discussion_r71403826
  
    --- Diff: launcher/src/test/java/org/apache/brooklyn/launcher/CleanOrphanedLocationsLiveTest.java ---
    @@ -0,0 +1,257 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.launcher;
    +
    +import org.apache.brooklyn.api.mgmt.ManagementContext;
    +import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
    +import org.apache.brooklyn.api.mgmt.rebind.PersistenceExceptionHandler;
    +import org.apache.brooklyn.api.mgmt.rebind.RebindManager;
    +import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoRawData;
    +import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
    +import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
    +import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
    +import org.apache.brooklyn.core.mgmt.persist.BrooklynMementoPersisterToObjectStore;
    +import org.apache.brooklyn.core.mgmt.persist.BrooklynPersistenceUtils;
    +import org.apache.brooklyn.core.mgmt.persist.PersistMode;
    +import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore;
    +import org.apache.brooklyn.core.mgmt.rebind.PersistenceExceptionHandlerImpl;
    +import org.apache.brooklyn.core.mgmt.rebind.RebindManagerImpl;
    +import org.apache.brooklyn.core.mgmt.rebind.transformer.impl.DeleteOrphanedLocationsTransformer;
    +import org.apache.brooklyn.core.server.BrooklynServerConfig;
    +import org.apache.brooklyn.core.server.BrooklynServerPaths;
    +import org.apache.brooklyn.test.Asserts;
    +import org.apache.brooklyn.util.collections.MutableMap;
    +import org.apache.brooklyn.util.collections.MutableSet;
    +import org.apache.brooklyn.util.time.Duration;
    +import org.apache.commons.lang.builder.EqualsBuilder;
    +import org.testng.annotations.AfterMethod;
    +import org.testng.annotations.BeforeMethod;
    +import org.testng.annotations.Test;
    +
    +import org.apache.brooklyn.core.internal.BrooklynProperties;
    +
    +import java.util.Map;
    +import java.util.Set;
    +
    +public class CleanOrphanedLocationsLiveTest {
    +
    +    private String PERSISTED_STATE_PATH_WITH_ORPHANED_LOCATIONS = "/orphaned-locations-test-data/data-with-orphaned-locations";
    +    private String PERSISTED_STATE_PATH_WITH_MULTIPLE_LOCATIONS_OCCURRENCE = "/orphaned-locations-test-data/fake-multiple-location-for-multiple-search-tests";
    +    private String PERSISTED_STATE_PATH_WITHOUT_ORPHANED_LOCATIONS = "/orphaned-locations-test-data/data-without-orphaned-locations";
    +    private String PERSISTED_STATE_DESTINATION_PATH = "/orphaned-locations-test-data/copy-persisted-state-destination";
    +
    +
    +    private String persistenceDirWithOrphanedLocations;
    +    private String persistenceDirWithoutOrphanedLocations;
    +    private String persistenceDirWithMultipleLocationsOccurrence;
    +    private String destinationDir;
    +    private String destinationLocation;
    +    private String localBrooklynProperties;
    +    private String persistenceLocation;
    +    private String highAvailabilityMode;
    +
    +    private DeleteOrphanedLocationsTransformer transformer;
    +
    +    private ManagementContext managementContext;
    +
    +    @BeforeMethod(alwaysRun = true)
    +    public void initialize() throws Exception {
    +        persistenceDirWithOrphanedLocations = getClass().getResource(PERSISTED_STATE_PATH_WITH_ORPHANED_LOCATIONS).getFile();
    +        persistenceDirWithoutOrphanedLocations = getClass().getResource(PERSISTED_STATE_PATH_WITHOUT_ORPHANED_LOCATIONS).getFile();
    +        persistenceDirWithMultipleLocationsOccurrence = getClass().getResource(PERSISTED_STATE_PATH_WITH_MULTIPLE_LOCATIONS_OCCURRENCE).getFile();
    +
    +        destinationDir = getClass().getResource(PERSISTED_STATE_DESTINATION_PATH).getFile();
    +
    +        transformer = DeleteOrphanedLocationsTransformer.builder().build();
    +    }
    +
    +    private void initManagementContextAndPersistence(String persistenceDir) {
    +
    +        BrooklynProperties brooklynProperties = BrooklynProperties.Factory.builderDefault().build();
    +        brooklynProperties.put(BrooklynServerConfig.MGMT_BASE_DIR.getName(), "");
    +
    +        managementContext = new LocalManagementContext(brooklynProperties);
    +
    +        if (persistenceLocation == null) {
    +            persistenceLocation = brooklynProperties.getConfig(BrooklynServerConfig.PERSISTENCE_LOCATION_SPEC);
    +        }
    +
    +        persistenceDir = BrooklynServerPaths.newMainPersistencePathResolver(brooklynProperties).location(persistenceLocation).dir(persistenceDir).resolve();
    +        PersistenceObjectStore objectStore = BrooklynPersistenceUtils.newPersistenceObjectStore(managementContext, persistenceLocation, persistenceDir,
    +                PersistMode.AUTO, HighAvailabilityMode.HOT_STANDBY);
    +
    +        BrooklynMementoPersisterToObjectStore persister = new BrooklynMementoPersisterToObjectStore(
    +                objectStore,
    +                ((ManagementContextInternal)managementContext).getBrooklynProperties(),
    +                managementContext.getCatalogClassLoader());
    +
    +        RebindManager rebindManager = managementContext.getRebindManager();
    +
    +        PersistenceExceptionHandler persistenceExceptionHandler = PersistenceExceptionHandlerImpl.builder().build();
    +        ((RebindManagerImpl) rebindManager).setPeriodicPersistPeriod(Duration.ONE_SECOND);
    +        rebindManager.setPersister(persister, persistenceExceptionHandler);
    +    }
    +
    +    @Test
    +    public void testSelectionWithOrphanedLocationsInData() {
    +
    +        Set<String> locationsToKeep = MutableSet.of(
    +                "tjdywoxbji",
    +                "pudtixbw89"
    +        );
    +
    +        Set<String> orphanedLocations = MutableSet.of(
    +                "banby1jx4j",
    +                "msyp655po0",
    +                "ppamsemxgo"
    +        );
    +
    +        initManagementContextAndPersistence(persistenceDirWithOrphanedLocations);
    +        BrooklynMementoRawData mementoRawData = managementContext.getRebindManager().retrieveMementoRawData();
    +
    +        Set<String> allReferencedLocationsFoundByTransformer = transformer.findAllReferencedLocations(mementoRawData);
    +        Map<String, String> locationsToKeepFoundByTransformer = transformer.findLocationsToKeep(mementoRawData);
    +
    +        Asserts.assertEquals(allReferencedLocationsFoundByTransformer, locationsToKeep);
    +        Asserts.assertEquals(locationsToKeepFoundByTransformer.keySet(), locationsToKeep);
    +
    +        Map<String, String> locationsNotToKeepDueToTransormer = MutableMap.of();
    +        locationsNotToKeepDueToTransormer.putAll(mementoRawData.getLocations());
    +        for (Map.Entry location: locationsToKeepFoundByTransformer.entrySet()) {
    +            locationsNotToKeepDueToTransormer.remove(location.getKey());
    +        }
    +        Set<String> notReferencedLocationsDueToTransormer = MutableSet.of();
    +        notReferencedLocationsDueToTransormer.addAll(mementoRawData.getLocations().keySet());
    +        for (String location: allReferencedLocationsFoundByTransformer) {
    +            notReferencedLocationsDueToTransormer.remove(location);
    +        }
    +
    +        Asserts.assertEquals(notReferencedLocationsDueToTransormer, orphanedLocations);
    +        Asserts.assertEquals(locationsNotToKeepDueToTransormer.keySet(), orphanedLocations);
    +
    +
    +        BrooklynMementoRawData transformedMemento = transformer.transform(mementoRawData);
    +        Asserts.assertFalse(EqualsBuilder.reflectionEquals(mementoRawData, transformedMemento));
    --- End diff --
    
    @iyovcheva you can use `CleanOrphanedLocationsTest#assertTransformDeletes` and `CleanOrphanedLocationsTest#assertTransformIsNoop`
    I'll try to PR against your PR with so we can minify the size of methods in `CleanOrphanedLocationsLiveTest`


---
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.
---

[GitHub] brooklyn-server pull request #264: [DO NOT MERGE] Dangling references cleane...

Posted by aledsage-tmp <gi...@git.apache.org>.
Github user aledsage-tmp commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/264#discussion_r71153770
  
    --- Diff: launcher-common/pom.xml ---
    @@ -79,6 +79,11 @@
                 <artifactId>brooklyn-locations-jclouds</artifactId>
                 <version>${project.version}</version>
             </dependency>
    +        <dependency>
    +            <groupId>org.apache.brooklyn</groupId>
    +            <artifactId>brooklyn-core</artifactId>
    +            <version>0.10.0-SNAPSHOT</version>
    --- End diff --
    
    Why do we now need this dependency? Also, use project.version.


---
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.
---

[GitHub] brooklyn-server pull request #264: [DO NOT MERGE] Dangling references cleane...

Posted by iyovcheva <gi...@git.apache.org>.
Github user iyovcheva commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/264#discussion_r71283685
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/transformer/impl/DeleteOrphanedLocationsTransformer.java ---
    @@ -94,6 +126,86 @@ public boolean containsAny(Collection<?> container, Iterable<?> contenders) {
             }
             return result;
         }
    +
    +    public Map<String, String> findLocationsToKeep(BrooklynMementoRawData input) {
    +        Map<String, String> locationsToKeep = MutableMap.of();
    +        Set<String> allReferencedLocations = findAllReferencedLocations(input);
    +
    +        for (Map.Entry location: input.getLocations().entrySet()) {
    +            if (allReferencedLocations.contains(location.getKey())) {
    +                locationsToKeep.put((String) location.getKey(), (String) location.getValue());
    +            }
    +        }
    +        return locationsToKeep;
    +    }
    +
    +    public Set<String> findAllReferencedLocations(BrooklynMementoRawData input) {
    +        Set<String> allReferencedLocations = MutableSet.of();
    +
    +        allReferencedLocations.addAll(searchLocationsToKeepInEntities(input.getEntities()));
    +        allReferencedLocations.addAll(searchLocationsToKeepInPolicies(input.getPolicies()));
    +        allReferencedLocations.addAll(searchLocationsToKeepInEnrichers(input.getEnrichers()));
    +        allReferencedLocations.addAll(searchLocationsToKeepInLocations(input.getLocations(), allReferencedLocations));
    +
    +        return allReferencedLocations;
    +    }
    +
    +    private Set<String> searchLocationsToKeepInEntities(Map<String, String> entities) {
    +        Set<String> result = MutableSet.of();
    +
    +        for(Map.Entry entity: entities.entrySet()) {
    +
    +            String locationProxyPrefix = "<locationProxy>";
    +            String locationProxySuffix = "</locationProxy>";
    +            String locationPrefix = "<locations>\n" +
    +                    "    <string>";
    +            String locationSuffix = "</string>\n" +
    +                    "  </locations>";
    +            String locationPrefixWinEOF = "<locations>\r\n" +
    +                    "    <string>";
    +            String locationSuffixWinEOF = "</string>\r\n" +
    +                    "  </locations>";
    +
    +            String entityString = (String) entity.getValue();
    +            result.addAll(Strings.getAllOccurrencesBetween(entityString, locationProxyPrefix, locationProxySuffix));
    +            result.addAll(Strings.getAllOccurrencesBetween(entityString, locationPrefix, locationSuffix));
    +            result.addAll(Strings.getAllOccurrencesBetween(entityString, locationPrefixWinEOF, locationSuffixWinEOF));
    +        }
    +
    +        return result;
    +    }
    +
    +    private Set<String> searchLocationsToKeepInLocations(Map<String, String> locations, Set<String> alreadyReferencedLocations) {
    --- End diff --
    
    Added them as well, but the comment won't show as outdated.


---
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.
---

[GitHub] brooklyn-server pull request #264: [DO NOT MERGE] Dangling references cleane...

Posted by aledsage-tmp <gi...@git.apache.org>.
Github user aledsage-tmp commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/264#discussion_r71153473
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/transformer/impl/DeleteOrphanedLocationsTransformer.java ---
    @@ -94,6 +126,86 @@ public boolean containsAny(Collection<?> container, Iterable<?> contenders) {
             }
             return result;
         }
    +
    +    public Map<String, String> findLocationsToKeep(BrooklynMementoRawData input) {
    +        Map<String, String> locationsToKeep = MutableMap.of();
    +        Set<String> allReferencedLocations = findAllReferencedLocations(input);
    +
    +        for (Map.Entry location: input.getLocations().entrySet()) {
    +            if (allReferencedLocations.contains(location.getKey())) {
    +                locationsToKeep.put((String) location.getKey(), (String) location.getValue());
    +            }
    +        }
    +        return locationsToKeep;
    +    }
    +
    +    public Set<String> findAllReferencedLocations(BrooklynMementoRawData input) {
    +        Set<String> allReferencedLocations = MutableSet.of();
    +
    +        allReferencedLocations.addAll(searchLocationsToKeepInEntities(input.getEntities()));
    +        allReferencedLocations.addAll(searchLocationsToKeepInPolicies(input.getPolicies()));
    +        allReferencedLocations.addAll(searchLocationsToKeepInEnrichers(input.getEnrichers()));
    +        allReferencedLocations.addAll(searchLocationsToKeepInLocations(input.getLocations(), allReferencedLocations));
    +
    +        return allReferencedLocations;
    +    }
    +
    +    private Set<String> searchLocationsToKeepInEntities(Map<String, String> entities) {
    +        Set<String> result = MutableSet.of();
    +
    +        for(Map.Entry entity: entities.entrySet()) {
    +
    +            String locationProxyPrefix = "<locationProxy>";
    +            String locationProxySuffix = "</locationProxy>";
    +            String locationPrefix = "<locations>\n" +
    --- End diff --
    
    Perhaps use xpath for this. See XmlUtils.


---
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.
---

[GitHub] brooklyn-server issue #264: [DO NOT MERGE] Dangling references cleaner

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the issue:

    https://github.com/apache/brooklyn-server/pull/264
  
    @iyovcheva I've created https://github.com/iyovcheva/brooklyn-server/pull/1 to show how we can write unit tests for this.
    
    The absolute must is that we "do no harm". We must never delete a location that is referenced by anything else. These tests show that we are deleting referenced locations.


---
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.
---

[GitHub] brooklyn-server pull request #264: Orphaned locations cleaner

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/brooklyn-server/pull/264


---
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.
---