brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Active partial rebind allowing ca...
Date Mon, 09 Feb 2015 11:31:50 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/506#discussion_r24322344
  
    --- 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 --
    
    Shame we have to cast this. It makes it feel pointless to leave the old implementations
of `BrooklynMementoPersister` deprecated if one will potentially get runtime exceptions using
it (better to have deleted the classes to give compile-time errors, depending under what circumstances
this code-path will be hit).
    
    The `BrooklynMementoPersisterInMemory` feels like a useful thing to keep in the test packages,
but maybe not even worth that if we just accept the performance overhead in our test cases
of always using `BrooklynMementoPersisterToObjectStore`.


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

Mime
View raw message