Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/506#discussion_r24324430
  
    --- Diff: 
core/src/main/java/brooklyn/entity/rebind/ActivePartialRebindIteration.java ---
    @@ -0,0 +1,158 @@
    +/*
    + * 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 brooklyn.entity.rebind;
    +
    +import java.util.Collection;
    +import java.util.Iterator;
    +import java.util.List;
    +import java.util.Set;
    +import java.util.concurrent.Semaphore;
    +import java.util.concurrent.atomic.AtomicInteger;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import brooklyn.basic.BrooklynObject;
    +import brooklyn.basic.BrooklynObjectInternal;
    +import brooklyn.entity.Entity;
    +import brooklyn.entity.basic.EntityInternal;
    +import 
brooklyn.entity.rebind.persister.BrooklynMementoPersisterToObjectStore;
    +import brooklyn.entity.rebind.persister.PersistenceActivityMetrics;
    +import brooklyn.entity.rebind.transformer.CompoundTransformer;
    +import brooklyn.management.ha.ManagementNodeState;
    +import brooklyn.mementos.BrooklynMementoPersister;
    +import brooklyn.mementos.BrooklynMementoRawData;
    +import brooklyn.mementos.BrooklynMementoRawData.Builder;
    +import brooklyn.mementos.Memento;
    +import brooklyn.util.collections.MutableList;
    +import brooklyn.util.collections.MutableSet;
    +
    +import com.google.common.base.Preconditions;
    +
    +/**
    + * Pauses a set of existing entities, writes their state, applies a 
transformation, then reads them back.
    + */
    +public class ActivePartialRebindIteration extends RebindIteration {
    +
    +    private static final Logger LOG = 
LoggerFactory.getLogger(ActivePartialRebindIteration.class);
    +    
    +    protected Iterator<BrooklynObject> objectsToRebindInitial;
    +    protected Collection<BrooklynObject> objectsToRebindFinal;
    +    protected List<CompoundTransformer> transformers = MutableList.of();
    +    
    +    public ActivePartialRebindIteration(RebindManagerImpl rebindManager, 
    +            ManagementNodeState mode,
    +            ClassLoader classLoader, RebindExceptionHandler 
exceptionHandler,
    +            Semaphore rebindActive, AtomicInteger readOnlyRebindCount, 
PersistenceActivityMetrics rebindMetrics, BrooklynMementoPersister 
persistenceStoreAccess
    +            ) {
    +        super(rebindManager, mode, classLoader, exceptionHandler, 
rebindActive, readOnlyRebindCount, rebindMetrics, persistenceStoreAccess);
    +    }
    +
    +    @Override
    +    protected boolean isRebindingActiveAgain() {
    +        return true;
    +    }
    +    
    +    public void setObjectIterator(Iterator<BrooklynObject> 
objectsToRebind) {
    +        this.objectsToRebindInitial = objectsToRebind;
    +    }
    +    
    +    public void applyTransformer(CompoundTransformer transformer) {
    +        if (transformer!=null)
    +            transformers.add(transformer);
    +    }
    +    
    +    @Override
    +    protected void doRun() throws Exception {
    +        checkEnteringPhase(1);
    +        
Preconditions.checkState(readOnlyRebindCount.get()==Integer.MIN_VALUE, "Partial 
rebind in read-only mode not supported");
    +        Preconditions.checkNotNull(objectsToRebindInitial, "Objects to 
rebind must be set");
    +
    +        LOG.debug("Partial rebind Rebinding ("+mode+") from 
"+rebindManager.getPersister().getBackingStoreDescription()+"...");
    +
    +        Builder mementoRawBuilder = BrooklynMementoRawData.builder();
    +
    +        /*
    +         * Unmanagement is done as part of the "manage" call, entity by 
entity.
    +         */
    +
    +        objectsToRebindFinal = MutableSet.of();
    +        while (objectsToRebindInitial.hasNext()) {
    +            BrooklynObject bo = objectsToRebindInitial.next();
    +            objectsToRebindFinal.add(bo);
    +            
    +            if (bo instanceof Entity) {
    +                // if it's an entity, add all adjuncts. (if doing some 
sort of pause, that's maybe not necessary...)
    +                objectsToRebindFinal.addAll( 
((EntityInternal)bo).getPolicies() );
    +                objectsToRebindFinal.addAll( 
((EntityInternal)bo).getEnrichers() );
    +                objectsToRebindFinal.addAll( 
((EntityInternal)bo).feeds().getFeeds() );
    +            }
    +        }
    +        
    +        // get serialization
    +        for (BrooklynObject bo: objectsToRebindFinal) {
    +            Memento m = 
((BrooklynObjectInternal)bo).getRebindSupport().getMemento();
    +            BrooklynMementoPersister p = rebindManager.getPersister();
    +            String mr = 
((BrooklynMementoPersisterToObjectStore)p).getMementoSerializer().toString(m);
    --- End diff --
    
    there is a `SingleThreadedInMemoryStoreObjectAccessor` for use with the 
`BrooklynMementoPersisterToObjectStore`, giving minimal overhead, and a more 
faithful test pathway.
    
    the deprecated classes aren't used and can be deleted; we just need to cut 
070-GA. i don't think there's point in adding support or compile-time checks 
for the deprecated classes in this pathway.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to