brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Persistence hardening - creates c...
Date Thu, 13 Nov 2014 15:02:13 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/314#discussion_r20296070
  
    --- Diff: core/src/main/java/brooklyn/entity/rebind/persister/BrooklynPersistenceUtils.java
---
    @@ -0,0 +1,258 @@
    +/*
    + * 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.persister;
    +
    +import java.util.List;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import brooklyn.basic.BrooklynObject;
    +import brooklyn.catalog.CatalogItem;
    +import brooklyn.config.BrooklynServerConfig;
    +import brooklyn.config.BrooklynServerPaths;
    +import brooklyn.entity.Entity;
    +import brooklyn.entity.Feed;
    +import brooklyn.entity.basic.Entities;
    +import brooklyn.entity.basic.EntityInternal;
    +import brooklyn.entity.rebind.BrooklynObjectType;
    +import brooklyn.entity.rebind.PersistenceExceptionHandler;
    +import brooklyn.entity.rebind.PersistenceExceptionHandlerImpl;
    +import brooklyn.entity.rebind.dto.MementosGenerators;
    +import brooklyn.entity.rebind.transformer.CompoundTransformer;
    +import brooklyn.entity.rebind.transformer.CompoundTransformerLoader;
    +import brooklyn.location.Location;
    +import brooklyn.location.LocationSpec;
    +import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
    +import brooklyn.management.ManagementContext;
    +import brooklyn.management.ha.HighAvailabilityMode;
    +import brooklyn.management.ha.ManagementNodeState;
    +import brooklyn.management.ha.ManagementPlaneSyncRecord;
    +import brooklyn.management.ha.ManagementPlaneSyncRecordPersisterToObjectStore;
    +import brooklyn.management.ha.MementoCopyMode;
    +import brooklyn.management.internal.ManagementContextInternal;
    +import brooklyn.mementos.BrooklynMementoRawData;
    +import brooklyn.mementos.Memento;
    +import brooklyn.policy.Enricher;
    +import brooklyn.policy.Policy;
    +import brooklyn.util.ResourceUtils;
    +import brooklyn.util.exceptions.Exceptions;
    +import brooklyn.util.text.Strings;
    +import brooklyn.util.time.Duration;
    +import brooklyn.util.time.Time;
    +
    +import com.google.common.annotations.Beta;
    +import com.google.common.base.Stopwatch;
    +import com.google.common.collect.ImmutableList;
    +
    +public class BrooklynPersistenceUtils {
    +
    +    private static final Logger log = LoggerFactory.getLogger(BrooklynPersistenceUtils.class);
    +    
    +    @Beta
    +    public static final List<BrooklynObjectType> STANDARD_BROOKLYN_OBJECT_TYPE_PERSISTENCE_ORDER
= ImmutableList.of( 
    +        BrooklynObjectType.ENTITY, BrooklynObjectType.LOCATION, BrooklynObjectType.POLICY,
    +        BrooklynObjectType.ENRICHER, BrooklynObjectType.FEED, BrooklynObjectType.CATALOG_ITEM);
    +
    +    /** Creates a {@link PersistenceObjectStore} for general-purpose use. */
    +    public static PersistenceObjectStore newPersistenceObjectStore(ManagementContext
managementContext,
    +            String locationSpec, String locationContainer) {
    +        
    +        return newPersistenceObjectStore(managementContext, locationSpec, locationContainer,
    +            PersistMode.AUTO, HighAvailabilityMode.STANDBY);
    +    }
    +    
    +    /** Creates a {@link PersistenceObjectStore} for use with a specified set of modes.
*/
    +    public static PersistenceObjectStore newPersistenceObjectStore(ManagementContext
managementContext,
    +            String locationSpec, String locationContainer, PersistMode persistMode, HighAvailabilityMode
highAvailabilityMode) {
    +        PersistenceObjectStore destinationObjectStore;
    +        locationContainer = BrooklynServerPaths.newMainPersistencePathResolver(managementContext).location(locationSpec).dir(locationContainer).resolve();
    +
    +        Location location = null;
    +        try {
    +            if (Strings.isBlank(locationSpec)) {
    +                location = managementContext.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class));
    +            } else {
    +                location = managementContext.getLocationRegistry().resolve(locationSpec);
    +                if (!(location instanceof LocationWithObjectStore)) {
    +                    throw new IllegalArgumentException("Destination location "+location+"
does not offer a persistent store");
    +                }
    +            }
    +        } finally {
    +            if (location!=null) managementContext.getLocationManager().unmanage(location);
    --- End diff --
    
    unmanage clears the config and subsequent calls to getIdentity & co fail.
    
    Should request unmanaged location explicitly instead.


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