Fixes exception on missing keyspace during bootstrap
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/8fde7c5d Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/8fde7c5d Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/8fde7c5d Branch: refs/heads/USERGRID-641 Commit: 8fde7c5dfd7d06c17b0a2c2a3ac1053bf3d97e76 Parents: 5a7f9c0 Author: Todd Nine <[email protected]> Authored: Fri May 15 19:38:19 2015 -0600 Committer: Todd Nine <[email protected]> Committed: Fri May 15 19:38:19 2015 -0600 ---------------------------------------------------------------------- .../data/MigrationInfoSerializationImpl.java | 4 +- .../migration/schema/MigrationManagerImpl.java | 14 ++---- .../core/migration/util/AstayanxUtils.java | 49 ++++++++++++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8fde7c5d/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/MigrationInfoSerializationImpl.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/MigrationInfoSerializationImpl.java b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/MigrationInfoSerializationImpl.java index 4a349fd..3def798 100644 --- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/MigrationInfoSerializationImpl.java +++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/MigrationInfoSerializationImpl.java @@ -35,6 +35,7 @@ import org.apache.usergrid.persistence.core.astyanax.MultiTennantColumnFamilyDef import org.apache.usergrid.persistence.core.astyanax.ScopedRowKey; import org.apache.usergrid.persistence.core.astyanax.ScopedRowKeySerializer; import org.apache.usergrid.persistence.core.astyanax.StringRowCompositeSerializer; +import org.apache.usergrid.persistence.core.migration.util.AstayanxUtils; import org.apache.usergrid.persistence.model.entity.Id; import org.apache.usergrid.persistence.model.entity.SimpleId; @@ -149,7 +150,8 @@ public class MigrationInfoSerializationImpl implements MigrationInfoSerializatio return 0; } catch ( ConnectionException e ) { - throw new DataMigrationException( "Unable to retrieve status", e ); + AstayanxUtils.isKeyspaceMissing("Unable to connect to cassandra to retrieve status", e); + return 0; } } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8fde7c5d/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/schema/MigrationManagerImpl.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/schema/MigrationManagerImpl.java b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/schema/MigrationManagerImpl.java index 31aa1b3..26351cf 100644 --- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/schema/MigrationManagerImpl.java +++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/schema/MigrationManagerImpl.java @@ -28,6 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.usergrid.persistence.core.astyanax.MultiTennantColumnFamilyDefinition; +import org.apache.usergrid.persistence.core.migration.util.AstayanxUtils; import com.google.common.collect.ImmutableMap; import com.google.inject.Inject; @@ -131,22 +132,15 @@ public class MigrationManagerImpl implements MigrationManager { try { keyspaceDefinition = keyspace.describeKeyspace(); - } - catch ( BadRequestException badRequestException ) { - - //check if it's b/c the keyspace is missing, if so - final String message = badRequestException.getMessage(); - - boolean missingKeyspace = message.contains( "why:Keyspace" ) && message.contains( "does not exist" ); - if ( !missingKeyspace ) { - throw badRequestException; - } }catch( NotFoundException nfe){ //if we execute this immediately after a drop keyspace in 1.2.x, Cassandra is returning the NFE instead of a BadRequestException //swallow and log, then continue to create the keyspaces. logger.info( "Received a NotFoundException when attempting to describe keyspace. It does not exist" ); } + catch(Exception e){ + AstayanxUtils.isKeyspaceMissing("Unable to connect to cassandra", e); + } if ( keyspaceDefinition != null ) { http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8fde7c5d/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/util/AstayanxUtils.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/util/AstayanxUtils.java b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/util/AstayanxUtils.java new file mode 100644 index 0000000..7ae4748 --- /dev/null +++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/util/AstayanxUtils.java @@ -0,0 +1,49 @@ +/* + * 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.usergrid.persistence.core.migration.util; + + +import com.netflix.astyanax.connectionpool.exceptions.BadRequestException; + + +public class AstayanxUtils { + + /** + * Return true if the exception is an instance of a missing keysapce + * @param rethrowMessage The message to add to the exception if rethrown + * @param cassandraException The exception from cassandar + * @return + */ + public static void isKeyspaceMissing(final String rethrowMessage, final Exception cassandraException ) { + + if ( cassandraException instanceof BadRequestException ) { + + //check if it's b/c the keyspace is missing, if so + final String message = cassandraException.getMessage(); + + //no op, just swallow + if(message.contains( "why:Keyspace" ) && message.contains( "does not exist" )){ + return; + }; + } + + throw new RuntimeException( rethrowMessage, cassandraException ); + } +}
