Lots of renaming to change from "index schema" to "collection settings" and _indexes to _settings.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/3f4bd02d Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/3f4bd02d Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/3f4bd02d Branch: refs/heads/usergrid-1268-akka-211 Commit: 3f4bd02da63d064a3dce59306d8f57ed24050aad Parents: 45bb03e Author: Dave Johnson <[email protected]> Authored: Wed Apr 20 10:19:49 2016 -0400 Committer: Dave Johnson <[email protected]> Committed: Mon Apr 25 14:40:11 2016 -0400 ---------------------------------------------------------------------- .../usergrid/corepersistence/CoreModule.java | 1 - .../corepersistence/CpEntityManager.java | 29 +++-- .../corepersistence/CpRelationManager.java | 7 +- .../index/CollectionSettingsCache.java | 47 +++++++ .../index/CollectionSettingsCacheImpl.java | 122 +++++++++++++++++++ .../corepersistence/index/IndexSchemaCache.java | 50 -------- .../index/IndexSchemaCacheFactory.java | 4 +- .../index/IndexSchemaCacheImpl.java | 119 ------------------ .../corepersistence/index/IndexServiceImpl.java | 7 +- .../index/ReIndexServiceImpl.java | 34 ++++-- .../service/ApplicationServiceImpl.java | 7 +- .../usergrid/persistence/EntityManager.java | 6 +- stack/corepersistence/collection/pom.xml | 2 +- .../rest/applications/CollectionResource.java | 74 ++++++----- .../rest/applications/ServiceResource.java | 8 +- .../collection/CollectionsResourceIT.java | 22 ++-- .../services/AbstractCollectionService.java | 12 +- .../services/AbstractConnectionsService.java | 4 +- .../usergrid/services/AbstractService.java | 53 +++----- .../applications/ApplicationsService.java | 4 +- 20 files changed, 309 insertions(+), 303 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java index 2d57131..0457000 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java @@ -16,7 +16,6 @@ package org.apache.usergrid.corepersistence; -import org.apache.usergrid.corepersistence.index.IndexSchemaCache; import org.apache.usergrid.corepersistence.index.IndexSchemaCacheFactory; import org.apache.usergrid.corepersistence.index.IndexSchemaCacheFig; import org.apache.usergrid.locking.guice.LockModule; http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java index b74995a..0db63be 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java @@ -42,7 +42,7 @@ import org.slf4j.LoggerFactory; import org.springframework.util.Assert; import org.apache.usergrid.corepersistence.asyncevents.AsyncEventService; -import org.apache.usergrid.corepersistence.index.IndexSchemaCache; +import org.apache.usergrid.corepersistence.index.CollectionSettingsCache; import org.apache.usergrid.corepersistence.index.IndexSchemaCacheFactory; import org.apache.usergrid.corepersistence.service.CollectionService; import org.apache.usergrid.corepersistence.service.ConnectionService; @@ -620,9 +620,10 @@ public class CpEntityManager implements EntityManager { boolean skipIndexing = false; MapManager mm = getMapManagerForTypes(); - IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( mm ); + CollectionSettingsCache collectionSettingsCache = indexSchemaCacheFactory.getInstance( mm ); String collectionName = Schema.defaultCollectionName( type ); - Optional<Map> collectionIndexingSchema = indexSchemaCache.getCollectionSchema( collectionName ); + Optional<Map<String, Object>> collectionIndexingSchema = + collectionSettingsCache.getCollectionSettings( collectionName ); if ( collectionIndexingSchema.isPresent()) { Map jsonMapData = collectionIndexingSchema.get(); @@ -1778,7 +1779,7 @@ public class CpEntityManager implements EntityManager { } @Override - public Map createCollectionSchema( String collectionName, String owner ,Map<String, Object> properties ){ + public Map createCollectionSettings( String collectionName, String owner ,Map<String, Object> properties ){ //TODO: change timeservice as below then use timeservice. @@ -1796,9 +1797,10 @@ public class CpEntityManager implements EntityManager { MapManager mm = getMapManagerForTypes(); - IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( mm ); + CollectionSettingsCache collectionSettingsCache = indexSchemaCacheFactory.getInstance( mm ); - Optional<Map> collectionIndexingSchema = indexSchemaCache.getCollectionSchema( collectionName ); + Optional<Map<String, Object>> collectionIndexingSchema = + collectionSettingsCache.getCollectionSettings( collectionName ); //If there is an existing schema then take the lastReindexed time and keep it around.Otherwise initialize to 0. @@ -1828,30 +1830,31 @@ public class CpEntityManager implements EntityManager { schemaMap.putAll( properties ); } - indexSchemaCache.putCollectionSchema( collectionName, JsonUtils.mapToJsonString( schemaMap ) ); + collectionSettingsCache.putCollectionSettings( collectionName, JsonUtils.mapToJsonString( schemaMap ) ); return schemaMap; } @Override - public void deleteCollectionSchema( String collectionName ){ + public void deleteCollectionSettings( String collectionName ){ MapManager mm = getMapManagerForTypes(); - IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( mm ); + CollectionSettingsCache collectionSettingsCache = indexSchemaCacheFactory.getInstance( mm ); - indexSchemaCache.deleteCollectionSchema( collectionName ); + collectionSettingsCache.deleteCollectionSettings( collectionName ); } @Override - public Object getCollectionSchema( String collectionName ){ + public Object getCollectionSettings( String collectionName ){ MapManager mm = getMapManagerForTypes(); - IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( mm ); + CollectionSettingsCache collectionSettingsCache = indexSchemaCacheFactory.getInstance( mm ); - Optional<Map> collectionIndexingSchema = indexSchemaCache.getCollectionSchema( collectionName ); + Optional<Map<String, Object>> collectionIndexingSchema = + collectionSettingsCache.getCollectionSettings( collectionName ); if(collectionIndexingSchema.isPresent()){ return collectionIndexingSchema.get(); http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java index 4082b45..6c6dc55 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java @@ -19,7 +19,7 @@ package org.apache.usergrid.corepersistence; import java.util.*; -import org.apache.usergrid.corepersistence.index.IndexSchemaCache; +import org.apache.usergrid.corepersistence.index.CollectionSettingsCache; import org.apache.usergrid.corepersistence.index.IndexSchemaCacheFactory; import org.apache.usergrid.corepersistence.results.IdQueryExecutor; import org.apache.usergrid.persistence.map.MapManager; @@ -1087,9 +1087,10 @@ public class CpRelationManager implements RelationManager { boolean skipIndexing = false; MapManager mm = getMapManagerForTypes(); - IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( mm ); + CollectionSettingsCache collectionSettingsCache = indexSchemaCacheFactory.getInstance( mm ); String collectionName = Schema.defaultCollectionName( type ); - Optional<Map> collectionIndexingSchema = indexSchemaCache.getCollectionSchema( collectionName ); + Optional<Map<String, Object>> collectionIndexingSchema = + collectionSettingsCache.getCollectionSettings( collectionName ); if ( collectionIndexingSchema.isPresent()) { Map jsonMapData = collectionIndexingSchema.get(); http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCache.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCache.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCache.java new file mode 100644 index 0000000..941f7cc --- /dev/null +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCache.java @@ -0,0 +1,47 @@ +/* + * 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.corepersistence.index; + + +import java.util.Map; + +import com.google.common.base.Optional; + + +public interface CollectionSettingsCache { + + /** + * Get the collection schema from the cache. + */ + Optional<Map<String, Object>> getCollectionSettings(String collectionName ); + + void putCollectionSettings(String collectionName, String collectionSettings ); + + void deleteCollectionSettings(String collectionName ); + + /** + * Evict the collection schema from the cache. + */ + void evictCollectionSettings(String collectionName); + + /** + * Evict everything from the cache. + */ + void evictCache(); + + +} http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCacheImpl.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCacheImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCacheImpl.java new file mode 100644 index 0000000..1cd81b9 --- /dev/null +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCacheImpl.java @@ -0,0 +1,122 @@ +/* + * 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.corepersistence.index; + + +import com.google.common.base.Optional; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.inject.Singleton; +import org.apache.usergrid.persistence.map.MapManager; +import org.apache.usergrid.utils.JsonUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; + + +/** + * Cache collection settings to reduce load on Cassandra. + */ +@Singleton +public class CollectionSettingsCacheImpl implements CollectionSettingsCache { + private static final Logger logger = LoggerFactory.getLogger(CollectionSettingsCacheImpl.class ); + + private final LoadingCache<String,Optional<Map<String, Object>>> indexSchemaCache; + private final MapManager mapManager; + + + public CollectionSettingsCacheImpl( MapManager mapManager, IndexSchemaCacheFig indexSchemaCacheFig) { + this.mapManager = mapManager; + + indexSchemaCache = CacheBuilder.newBuilder() + .maximumSize( indexSchemaCacheFig.getCacheSize() ) + // I don't think we want this to expire this quickly: + //.expireAfterWrite( indexSchemaCacheFig.getCacheTimeout(), TimeUnit.MILLISECONDS ) + .build( new CacheLoader<String, Optional<Map<String, Object>>>() { + @Override + public Optional<Map<String, Object>> load( final String collectionName ) throws Exception { + return Optional.fromNullable( retrieveCollectionSchema( collectionName ) ); + } + } ); + } + + private Map retrieveCollectionSchema( final String collectionName ){ + String collectionIndexingSchema = mapManager.getString( collectionName ); + Map parsedCollectionIndexingSchema = null; + if(collectionIndexingSchema!=null){ + return (Map) JsonUtils.parse( collectionIndexingSchema ); + + } + return parsedCollectionIndexingSchema; + } + + + @Override + public Optional<Map<String, Object>> getCollectionSettings(final String collectionName ) { + + try { + Optional<Map<String, Object>> optionalCollectionSchema = indexSchemaCache.get( collectionName ); + if(!optionalCollectionSchema.isPresent()){ + indexSchemaCache.invalidate( collectionName ); + return Optional.absent(); + } + return optionalCollectionSchema; + + } catch ( Exception e ) { + if(logger.isDebugEnabled()){ + logger.debug( "Returning for collection name: {} " + + "resulted in the following failure: {}",collectionName,e ); + } + } + return null; + } + + @Override + public void putCollectionSettings(final String collectionName, final String collectionSchema ){ + mapManager.putString( collectionName, collectionSchema ); + evictCollectionSettings( collectionName ); + } + + + @Override + public void deleteCollectionSettings(final String collectionName){ + mapManager.delete( collectionName ); + evictCollectionSettings( collectionName ); + } + + + @Override + public void evictCollectionSettings(final String collectionName ) { + indexSchemaCache.invalidate( collectionName ); + if(logger.isDebugEnabled() ){ + logger.debug( "Invalidated key {}",collectionName ); + } + + } + + + @Override + public void evictCache() { + indexSchemaCache.invalidateAll(); + if(logger.isDebugEnabled()){ + logger.debug( "Invalidated all keys" ); + } + } +} http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCache.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCache.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCache.java deleted file mode 100644 index 0ef92e9..0000000 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCache.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.corepersistence.index; - - -import java.util.Map; - -import com.google.common.base.Optional; - - -public interface IndexSchemaCache { - - /** - * Get the collection schema from the cache. - * @param collectionName - * @return - */ - public Optional<Map> getCollectionSchema( String collectionName ); - - void putCollectionSchema( String collectionName, String collectionSchema ); - - void deleteCollectionSchema( String collectionName ); - - /** - * Evict the collection schema from the cache. - * @param collectionName - */ - public void evictCollectionSchema(String collectionName); - - /** - * Evict everything from the cache. - */ - public void evictCache(); - - -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheFactory.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheFactory.java index 6f72103..694132c 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheFactory.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheFactory.java @@ -36,8 +36,8 @@ public class IndexSchemaCacheFactory { this.fig = fig; } - public IndexSchemaCache getInstance(MapManager mapManager ){ - return new IndexSchemaCacheImpl( mapManager,fig ); + public CollectionSettingsCache getInstance(MapManager mapManager ){ + return new CollectionSettingsCacheImpl( mapManager,fig ); } http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java deleted file mode 100644 index fd0b676..0000000 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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.corepersistence.index; - - -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.usergrid.persistence.map.MapManager; -import org.apache.usergrid.utils.JsonUtils; - -import com.google.common.base.Optional; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.google.inject.Singleton; - - -/** - * Cache the calls to update and get the map manager so we don't overload cassandra when we update - * after each call? - */ -@Singleton -public class IndexSchemaCacheImpl implements IndexSchemaCache { - private static final Logger logger = LoggerFactory.getLogger(IndexSchemaCacheImpl.class ); - - private final LoadingCache<String,Optional<Map>> indexSchemaCache; - private final MapManager mapManager; - - - public IndexSchemaCacheImpl(MapManager mapManager,IndexSchemaCacheFig indexSchemaCacheFig){ - this.mapManager = mapManager; - indexSchemaCache = CacheBuilder.newBuilder() - .maximumSize( indexSchemaCacheFig.getCacheSize() ) - //.expireAfterWrite( indexSchemaCacheFig.getCacheTimeout(), TimeUnit.MILLISECONDS ) <-- I don't think we want this to expire that quickly. - .build( new CacheLoader<String, Optional<Map>>() { - @Override - public Optional<Map> load( final String collectionName ) throws Exception { - return Optional.fromNullable( retrieveCollectionSchema( collectionName ) ); - } - } ); - } - - private Map retrieveCollectionSchema( final String collectionName ){ - String collectionIndexingSchema = mapManager.getString( collectionName ); - Map parsedCollectionIndexingSchema = null; - if(collectionIndexingSchema!=null){ - return (Map) JsonUtils.parse( collectionIndexingSchema ); - - } - return parsedCollectionIndexingSchema; - } - - - @Override - public Optional<Map> getCollectionSchema( final String collectionName ) { - try { - Optional<Map> optionalCollectionSchema = indexSchemaCache.get( collectionName ); - if(!optionalCollectionSchema.isPresent()){ - indexSchemaCache.invalidate( collectionName ); - return Optional.absent(); - } - return optionalCollectionSchema; - }catch(Exception e){ - if(logger.isDebugEnabled()){ - logger.debug( "Returning for collection name: {} " - + "resulted in the following failure: {}",collectionName,e ); - } - } - return null; - } - - @Override - public void putCollectionSchema( final String collectionName, final String collectionSchema ){ - mapManager.putString( collectionName, collectionSchema ); - evictCollectionSchema( collectionName ); - } - - @Override - public void deleteCollectionSchema(final String collectionName){ - mapManager.delete( collectionName ); - evictCollectionSchema( collectionName ); - } - - @Override - public void evictCollectionSchema( final String collectionName ) { - indexSchemaCache.invalidate( collectionName ); - if(logger.isDebugEnabled() ){ - logger.debug( "Invalidated key {}",collectionName ); - } - - } - - - @Override - public void evictCache() { - indexSchemaCache.invalidateAll(); - if(logger.isDebugEnabled()){ - logger.debug( "Invalidated all keys" ); - } - } -} http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java index 9509626..bfe60fd 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java @@ -25,7 +25,6 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.UUID; -import java.util.concurrent.TimeUnit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,7 +55,6 @@ import org.apache.usergrid.persistence.model.entity.Entity; import org.apache.usergrid.persistence.model.entity.Id; import org.apache.usergrid.persistence.model.entity.SimpleId; import org.apache.usergrid.utils.InflectionUtils; -import org.apache.usergrid.utils.JsonUtils; import org.apache.usergrid.utils.UUIDUtils; import com.codahale.metrics.Timer; @@ -210,9 +208,10 @@ public class IndexServiceImpl implements IndexService { String collectionName = CpNamingUtils.getCollectionNameFromEdgeName( indexEdge.getEdgeName() ); - IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( mm ); + CollectionSettingsCache collectionSettingsCache = indexSchemaCacheFactory.getInstance( mm ); - Optional<Map> collectionIndexingSchema = indexSchemaCache.getCollectionSchema( collectionName ); + Optional<Map<String, Object>> collectionIndexingSchema = + collectionSettingsCache.getCollectionSettings( collectionName ); //If we do have a schema then parse it and add it to a list of properties we want to keep.Otherwise return. if ( collectionIndexingSchema.isPresent()) { http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java index 250e7fc..fc06100 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java @@ -137,20 +137,29 @@ public class ReIndexServiceImpl implements ReIndexService { // create an observable that loads a batch to be indexed if(reIndexRequestBuilder.getCollectionName().isPresent()) { - String collectionName = InflectionUtils.pluralize( CpNamingUtils.getNameFromEdgeType(reIndexRequestBuilder.getCollectionName().get() )); - MapManager collectionMapStorage = mapManagerFactory.createMapManager( CpNamingUtils.getEntityTypeMapScope( appId.get().getApplication() ) ); - IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( collectionMapStorage ); - Optional<Map> collectionIndexingSchema = indexSchemaCache.getCollectionSchema( collectionName ); + String collectionName = InflectionUtils.pluralize( + CpNamingUtils.getNameFromEdgeType(reIndexRequestBuilder.getCollectionName().get() )); - //If we do have a schema then parse it and add it to a list of properties we want to keep.Otherwise return. + MapManager collectionMapStorage = mapManagerFactory.createMapManager( + CpNamingUtils.getEntityTypeMapScope( appId.get().getApplication() ) ); + + CollectionSettingsCache collectionSettingsCache = + indexSchemaCacheFactory.getInstance( collectionMapStorage ); + + Optional<Map<String, Object>> collectionIndexingSchema = + collectionSettingsCache.getCollectionSettings( collectionName ); + + // If we do have a schema then parse it and add it to a list of properties we want to keep.Otherwise return. if ( collectionIndexingSchema.isPresent() ) { Map jsonMapData = collectionIndexingSchema.get(); jsonMapData.put( "lastReindexed", Instant.now().toEpochMilli() ); - //should probably roll this into the cache. - indexSchemaCache.putCollectionSchema( collectionName, JsonUtils.mapToJsonString(jsonMapData ) ); + + // should probably roll this into the cache. + collectionSettingsCache.putCollectionSettings( + collectionName, JsonUtils.mapToJsonString(jsonMapData ) ); } } @@ -168,13 +177,14 @@ public class ReIndexServiceImpl implements ReIndexService { .subscribeOn( Schedulers.io() ), indexProcessorFig.getReindexConcurrencyFactor()); - //start our sampler and state persistence - //take a sample every sample interval to allow us to resume state with minimal loss - //create our flushing collector and flush the edge scopes to it + // start our sampler and state persistence + // take a sample every sample interval to allow us to resume state with minimal loss + // create our flushing collector and flush the edge scopes to it runningReIndex.collect(() -> new FlushingCollector(jobId), - ((flushingCollector, edgeScopes) -> flushingCollector.flushBuffer(edgeScopes))).doOnNext( flushingCollector-> flushingCollector.complete() ) + ((flushingCollector, edgeScopes) -> flushingCollector.flushBuffer(edgeScopes))) + .doOnNext( flushingCollector-> flushingCollector.complete() ) //subscribe on our I/O scheduler and run the task - .subscribeOn( Schedulers.io() ).subscribe(); //want reindex to continually run so leave subscribe. + .subscribeOn( Schedulers.io() ).subscribe(); //want reindex to continually run so leave subscribe. return new ReIndexStatus( jobId, Status.STARTED, 0, 0 ); http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java index ca2b9a2..82e0695 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java @@ -23,7 +23,7 @@ import com.google.common.base.Optional; import com.google.inject.Inject; import org.apache.usergrid.corepersistence.asyncevents.AsyncEventService; import org.apache.usergrid.corepersistence.asyncevents.EventBuilder; -import org.apache.usergrid.corepersistence.index.IndexSchemaCache; +import org.apache.usergrid.corepersistence.index.CollectionSettingsCache; import org.apache.usergrid.corepersistence.index.IndexSchemaCacheFactory; import org.apache.usergrid.corepersistence.rx.impl.AllEntityIdsObservable; import org.apache.usergrid.corepersistence.util.CpNamingUtils; @@ -149,9 +149,10 @@ public class ApplicationServiceImpl implements ApplicationService{ boolean skipIndexing = false; MapManager mm = getMapManagerForTypes(applicationScope); - IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( mm ); + CollectionSettingsCache collectionSettingsCache = indexSchemaCacheFactory.getInstance( mm ); String collectionName = Schema.defaultCollectionName( type ); - Optional<Map> collectionIndexingSchema = indexSchemaCache.getCollectionSchema( collectionName ); + Optional<Map<String, Object>> collectionIndexingSchema = + collectionSettingsCache.getCollectionSettings( collectionName ); if ( collectionIndexingSchema.isPresent()) { Map jsonMapData = collectionIndexingSchema.get(); http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java index ef96f10..004a8b7 100644 --- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java +++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java @@ -512,11 +512,11 @@ public interface EntityManager { */ public Entity createRole( String roleName, String roleTitle, long inactivity ) throws Exception; - public Map createCollectionSchema( String collectionName, String owner ,Map<String, Object> properties ); + public Map createCollectionSettings( String collectionName, String owner ,Map<String, Object> properties ); - void deleteCollectionSchema( String collectionName ); + void deleteCollectionSettings( String collectionName ); - Object getCollectionSchema( String collectionName ); + Object getCollectionSettings( String collectionName ); public void grantRolePermission( String roleName, String permission ) throws Exception; http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/corepersistence/collection/pom.xml ---------------------------------------------------------------------- diff --git a/stack/corepersistence/collection/pom.xml b/stack/corepersistence/collection/pom.xml index ad9cefd..1deb675 100644 --- a/stack/corepersistence/collection/pom.xml +++ b/stack/corepersistence/collection/pom.xml @@ -6,7 +6,7 @@ <parent> <artifactId>persistence</artifactId> <groupId>org.apache.usergrid</groupId> - <version>2.1.1-SNAPSHOT</version> + <version>2.2.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java index 5bd895c..d0e675b 100644 --- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java +++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java @@ -73,8 +73,7 @@ import com.fasterxml.jackson.jaxrs.json.annotation.JSONP; */ @Component @Scope("prototype") -@Produces({ - MediaType.APPLICATION_JSON, "application/javascript", "application/x-javascript", "text/ecmascript", +@Produces({ MediaType.APPLICATION_JSON, "application/javascript", "application/x-javascript", "text/ecmascript", "application/ecmascript", "text/jscript" }) public class CollectionResource extends ServiceResource { @@ -82,26 +81,27 @@ public class CollectionResource extends ServiceResource { public CollectionResource() { } + /** - * THE BEGINNINGS OF AN ENDPOINT THAT WILL ALLOW TO DEFINE WHAT TO - * STORE IN ELASTICSEARCH. - * @param ui - * @param callback - * @return - * @throws Exception + * POST settings for a collection. + * + * Expects a JSON object which may include: + * - fields: (array) field names to be indexed, '*' for all and 'none' for no indexing + * - region: (string) name of the authoritative region for this collection */ @POST - @Path( "{itemName}/_indexes" ) + @Path( "{itemName}/_settings" ) @Produces({ MediaType.APPLICATION_JSON,"application/javascript"}) @RequireApplicationAccess @JSONP - public ApiResponse executePostOnIndexesWithCollectionName( @Context UriInfo ui, @PathParam("itemName") PathSegment itemName, - String body, - @QueryParam("callback") @DefaultValue("callback") String callback ) - throws Exception { + public ApiResponse executePostOnSettingsWithCollectionName( + @Context UriInfo ui, + @PathParam("itemName") PathSegment itemName, + String body, + @QueryParam("callback") @DefaultValue("callback") String callback ) throws Exception { if(logger.isTraceEnabled()){ - logger.trace( "ServiceResource.executePostOnIndexes" ); + logger.trace( "CollectionResource.executePostOnSettingsWithCollectionName" ); } addItemToServiceContext( ui, itemName ); @@ -130,11 +130,12 @@ public class CollectionResource extends ServiceResource { } - executeServicePostRequestForSchema( ui,response, ServiceAction.POST,payload ); + executeServicePostRequestForSettings( ui,response, ServiceAction.POST,payload ); return response; } + private void addItemToServiceContext( final @Context UriInfo ui, final @PathParam( "itemName" ) PathSegment itemName ) throws Exception { //The below is duplicated because it could change in the future and is probably not all needed but @@ -152,18 +153,24 @@ public class CollectionResource extends ServiceResource { addMatrixParams( getServiceParameters(), ui, itemName ); } + + /** + * Delete settings for a collection. + */ @DELETE - @Path( "{itemName}/_indexes" ) + @Path( "{itemName}/_settings" ) @Produces({ MediaType.APPLICATION_JSON,"application/javascript"}) @RequireApplicationAccess @JSONP - public ApiResponse executeDeleteOnIndexesWithCollectionName( @Context UriInfo ui, @PathParam("itemName") PathSegment itemName, - String body, - @QueryParam("callback") @DefaultValue("callback") String callback ) + public ApiResponse executeDeleteOnSettingsWithCollectionName( + @Context UriInfo ui, + @PathParam("itemName") PathSegment itemName, + String body, + @QueryParam("callback") @DefaultValue("callback") String callback ) throws Exception { if(logger.isTraceEnabled()){ - logger.trace( "CollectionResource.executeDeleteOnIndexesWithCollectionName" ); + logger.trace( "CollectionResource.executeDeleteOnSettingsWithCollectionName" ); } addItemToServiceContext( ui, itemName ); @@ -175,7 +182,7 @@ public class CollectionResource extends ServiceResource { response.setParams( ui.getQueryParameters() ); - emf.getEntityManager( services.getApplicationId() ).deleteCollectionSchema( itemName.getPath().toLowerCase() ); + emf.getEntityManager( services.getApplicationId() ).deleteCollectionSettings( itemName.getPath().toLowerCase() ); return response; } @@ -187,9 +194,10 @@ public class CollectionResource extends ServiceResource { @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) @RequireApplicationAccess @JSONP - public ApiResponse executeGetOnIndex( @Context UriInfo ui,@PathParam("itemName") PathSegment itemName, - @QueryParam("callback") @DefaultValue("callback") String callback ) - throws Exception { + public ApiResponse executeGetOnIndex( + @Context UriInfo ui, + @PathParam("itemName") PathSegment itemName, + @QueryParam("callback") @DefaultValue("callback") String callback ) throws Exception { if(logger.isTraceEnabled()){ logger.trace( "CollectionResource.executeGetOnIndex" ); @@ -202,23 +210,24 @@ public class CollectionResource extends ServiceResource { response.setApplication( services.getApplication() ); response.setParams( ui.getQueryParameters() ); - executeServiceGetRequestForSchema( ui,response,ServiceAction.GET,null ); + executeServiceGetRequestForSettings( ui,response,ServiceAction.GET,null ); return response; } - //TODO: this can't be controlled and until it can be controlled we shouldn' allow muggles to do this. So system access only. - //TODO: use scheduler here to get around people sending a reindex call 30 times. + // TODO: this can't be controlled and until it can be controlled we shouldn' allow muggles to do this. + // So system access only. + // TODO: use scheduler here to get around people sending a reindex call 30 times. @POST @Path("{itemName}/_reindex") @Produces({ MediaType.APPLICATION_JSON,"application/javascript"}) @RequireSystemAccess @JSONP - public ApiResponse executePostForReindexing( @Context UriInfo ui, String body, - @PathParam("itemName") PathSegment itemName, - @QueryParam("callback") @DefaultValue("callback") String callback ) - throws Exception { + public ApiResponse executePostForReindexing( + @Context UriInfo ui, String body, + @PathParam("itemName") PathSegment itemName, + @QueryParam("callback") @DefaultValue("callback") String callback ) throws Exception { addItemToServiceContext( ui, itemName ); @@ -227,7 +236,8 @@ public class CollectionResource extends ServiceResource { // String.valueOf( getServiceParameters().get( 0 ) ) ).withDelay( 50, TimeUnit.MILLISECONDS ); // IndexResource indexResource = new IndexResource(injector); - return indexResource.rebuildIndexesPost( services.getApplicationId().toString(),itemName.getPath(),false,callback ); + return indexResource.rebuildIndexesPost( + services.getApplicationId().toString(),itemName.getPath(),false,callback ); } } http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java index c500e6e..05b4aa7 100644 --- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java +++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java @@ -245,7 +245,7 @@ public class ServiceResource extends AbstractContextResource { } - public ServiceResults executeServiceGetRequestForSchema(UriInfo ui, ApiResponse response, ServiceAction action, + public ServiceResults executeServiceGetRequestForSettings(UriInfo ui, ApiResponse response, ServiceAction action, ServicePayload payload) throws Exception { if(logger.isTraceEnabled()){ @@ -270,7 +270,7 @@ public class ServiceResource extends AbstractContextResource { AbstractCollectionService abstractCollectionService = new AbstractCollectionService(); // abstractCollectionService - ServiceResults results = abstractCollectionService.getCollectionSchema( r ); + ServiceResults results = abstractCollectionService.getCollectionSettings( r ); // ServiceResults results = r.execute(); if ( results != null ) { @@ -299,7 +299,7 @@ public class ServiceResource extends AbstractContextResource { return results; } - public ServiceResults executeServicePostRequestForSchema(UriInfo ui, ApiResponse response, ServiceAction action, + public ServiceResults executeServicePostRequestForSettings(UriInfo ui, ApiResponse response, ServiceAction action, ServicePayload payload) throws Exception { if(logger.isTraceEnabled()){ @@ -323,7 +323,7 @@ public class ServiceResource extends AbstractContextResource { AbstractCollectionService abstractCollectionService = new AbstractCollectionService(); - ServiceResults results = abstractCollectionService.postCollectionSchema( r ); + ServiceResults results = abstractCollectionService.postCollectionSettings( r ); // ServiceResults results = r.execute(); if ( results != null ) { http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java index 0e682a7..9396758 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java @@ -136,7 +136,7 @@ public class CollectionsResourceIT extends AbstractRestIT { try { - this.pathResource( getOrgAppPath( "testcollections/_indexes" ) ).post( false, payload, + this.pathResource( getOrgAppPath( "testcollections/_settings" ) ).post( false, payload, new QueryParameters().addParam( "grant_type", "client_credentials" ).addParam( "client_id", String.valueOf( ( ( Map ) appCredentials.get( "credentials" ) ).get( "client_id" ) ) ) .addParam( "client_secret", String.valueOf( @@ -167,7 +167,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - Entity thing = this.app().collection( "testCollections" ).collection( "_indexes" ).post( payload ); + Entity thing = this.app().collection( "testCollections" ).collection( "_settings" ).post( payload ); refreshIndex(); @@ -206,7 +206,7 @@ public class CollectionsResourceIT extends AbstractRestIT { //to prove that the entity exists //next part is to delete the schema then reindex it and it should work. - this.app().collection( "testCollections" ).collection( "_indexes" ).delete(); + this.app().collection( "testCollections" ).collection( "_settings" ).delete(); refreshIndex(); this.app().collection( "testCollections" ).collection( "_reindex" ) @@ -245,7 +245,7 @@ public class CollectionsResourceIT extends AbstractRestIT { //Post index to the collection metadata try { - this.app().collection( "testCollections" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollections" ).collection( "_settings" ).post( payload ); fail(); }catch(BadRequestException bre){ //this is expected. @@ -259,7 +259,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingMap); try { - this.app().collection( "testCollections" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollections" ).collection( "_settings" ).post( payload ); fail(); }catch(BadRequestException bre){ //this is expected. @@ -269,7 +269,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); try { - this.app().collection( "testCollections" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollections" ).collection( "_settings" ).post( payload ); }catch(BadRequestException bre){ fail( "This shouldn't fail" ); } @@ -292,7 +292,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - Entity thing = this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + Entity thing = this.app().collection( "testCollection" ).collection( "_settings" ).post( payload ); refreshIndex(); @@ -366,7 +366,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - Entity thing = this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + Entity thing = this.app().collection( "testCollection" ).collection( "_settings" ).post( payload ); refreshIndex(); @@ -417,7 +417,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - Entity thing = this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + Entity thing = this.app().collection( "testCollection" ).collection( "_settings" ).post( payload ); refreshIndex(); Collection collection = this.app().collection( "testCollection" ).collection( "_index" ).get(); @@ -445,7 +445,7 @@ public class CollectionsResourceIT extends AbstractRestIT { payload.put( "fields", indexingArray); //Post index to the collection metadata - this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload ); + this.app().collection( "testCollection" ).collection( "_settings" ).post( payload ); collection = this.app().collection( "testCollection" ).collection( "_index" ).get(); @@ -961,7 +961,7 @@ public class CollectionsResourceIT extends AbstractRestIT { String randomizer = RandomStringUtils.randomAlphanumeric(10); String collectionName = "col_" + randomizer; - app().collection( collectionName ).collection( "_indexes" ).post( payload ); + app().collection( collectionName ).collection( "_settings" ).post( payload ); refreshIndex(); // was the no-index wildcard saved and others ignored? http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java ---------------------------------------------------------------------- diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java index c5473cf..63f0fa6 100644 --- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java +++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java @@ -331,7 +331,7 @@ public class AbstractCollectionService extends AbstractService { } @Override - public ServiceResults postCollectionSchema( ServiceRequest serviceRequest ) throws Exception { + public ServiceResults postCollectionSettings( ServiceRequest serviceRequest ) throws Exception { setServiceManager( serviceRequest.getServices() ); ServiceContext context = serviceRequest.getAppContext(); @@ -345,15 +345,15 @@ public class AbstractCollectionService extends AbstractService { if(currentUserPrincipal instanceof AdminUserPrincipal) { AdminUserPrincipal adminUserPrincipal = ( AdminUserPrincipal ) currentUserPrincipal; - collectionSchema = em.createCollectionSchema( context.getCollectionName(), + collectionSchema = em.createCollectionSettings( context.getCollectionName(), adminUserPrincipal.getUser().getEmail(), context.getProperties() ); } else if(currentUserPrincipal instanceof ApplicationPrincipal){ - collectionSchema = em.createCollectionSchema( context.getCollectionName(), + collectionSchema = em.createCollectionSettings( context.getCollectionName(), "app credentials", context.getProperties() ); } else if ( currentUserPrincipal instanceof PrincipalIdentifier ) { - collectionSchema = em.createCollectionSchema( context.getCollectionName(), + collectionSchema = em.createCollectionSettings( context.getCollectionName(), "generic credentials", context.getProperties() ); } @@ -362,13 +362,13 @@ public class AbstractCollectionService extends AbstractService { } @Override - public ServiceResults getCollectionSchema( ServiceRequest serviceRequest ) throws Exception { + public ServiceResults getCollectionSettings( ServiceRequest serviceRequest ) throws Exception { setServiceManager( serviceRequest.getServices() ); ServiceContext context = serviceRequest.getAppContext(); context.setAction( ServiceAction.GET ); checkPermissionsForCollection( context ); - Object collectionSchema = em.getCollectionSchema( context.getCollectionName() ); + Object collectionSchema = em.getCollectionSettings( context.getCollectionName() ); return new ServiceResults( this, context, Type.COLLECTION, Results.fromData( collectionSchema ), null, null ); http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java ---------------------------------------------------------------------- diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java b/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java index 395f2d4..f1fd004 100644 --- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java +++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java @@ -392,13 +392,13 @@ public class AbstractConnectionsService extends AbstractService { @Override - public ServiceResults postCollectionSchema( final ServiceRequest request ) throws Exception { + public ServiceResults postCollectionSettings( final ServiceRequest request ) throws Exception { throw new UnsupportedServiceOperationException( request ); } @Override - public ServiceResults getCollectionSchema( final ServiceRequest serviceRequest ) throws Exception { + public ServiceResults getCollectionSettings( final ServiceRequest serviceRequest ) throws Exception { throw new UnsupportedServiceOperationException( serviceRequest ); } http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/services/src/main/java/org/apache/usergrid/services/AbstractService.java ---------------------------------------------------------------------- diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractService.java b/stack/services/src/main/java/org/apache/usergrid/services/AbstractService.java index 927678c..c627730 100644 --- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractService.java +++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractService.java @@ -17,37 +17,19 @@ package org.apache.usergrid.services; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - import com.codahale.metrics.Timer; -import org.apache.usergrid.persistence.cache.CacheFactory; - +import com.google.inject.Injector; +import com.google.inject.Key; +import org.apache.commons.lang.NotImplementedException; +import org.apache.shiro.subject.Subject; import org.apache.usergrid.corepersistence.rx.impl.ResponseImportTasks; import org.apache.usergrid.corepersistence.service.ServiceSchedulerFig; +import org.apache.usergrid.persistence.*; +import org.apache.usergrid.persistence.cache.CacheFactory; import org.apache.usergrid.persistence.core.metrics.MetricsFactory; import org.apache.usergrid.persistence.core.metrics.ObservableTimer; -import org.apache.usergrid.security.shiro.utils.LocalShiroCache; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.ApplicationContext; - -import org.apache.commons.lang.NotImplementedException; -import org.apache.shiro.subject.Subject; - -import org.apache.usergrid.persistence.Entity; -import org.apache.usergrid.persistence.EntityManager; -import org.apache.usergrid.persistence.EntityRef; -import org.apache.usergrid.persistence.Query; -import org.apache.usergrid.persistence.Results; -import org.apache.usergrid.persistence.Schema; import org.apache.usergrid.persistence.core.rx.RxTaskScheduler; +import org.apache.usergrid.security.shiro.utils.LocalShiroCache; import org.apache.usergrid.security.shiro.utils.SubjectUtils; import org.apache.usergrid.services.ServiceParameter.IdParameter; import org.apache.usergrid.services.ServiceParameter.NameParameter; @@ -56,15 +38,15 @@ import org.apache.usergrid.services.ServiceResults.Type; import org.apache.usergrid.services.exceptions.ServiceInvocationException; import org.apache.usergrid.services.exceptions.ServiceResourceNotFoundException; import org.apache.usergrid.services.exceptions.UnsupportedServiceOperationException; -import org.apache.usergrid.services.generic.RootCollectionService; - -import com.google.inject.Injector; -import com.google.inject.Key; - +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationContext; import rx.Observable; import rx.Scheduler; import rx.Subscriber; +import java.util.*; + import static org.apache.usergrid.security.shiro.utils.SubjectUtils.getPermissionFromPath; import static org.apache.usergrid.services.ServiceParameter.filter; import static org.apache.usergrid.services.ServiceParameter.mergeQueries; @@ -125,7 +107,8 @@ public abstract class AbstractService implements Service { this.sm = sm; em = sm.getEntityManager(); final Injector injector = sm.getApplicationContext().getBean( Injector.class ); - rxScheduler = injector.getInstance( Key.get(RxTaskScheduler.class, ResponseImportTasks.class ) ).getAsyncIOScheduler(); + rxScheduler = injector.getInstance( Key.get(RxTaskScheduler.class, ResponseImportTasks.class ) ) + .getAsyncIOScheduler(); rxSchedulerFig = injector.getInstance(ServiceSchedulerFig.class ); metricsFactory = injector.getInstance(MetricsFactory.class); this.entityGetTimer = metricsFactory.getTimer(this.getClass(), "importEntity.get"); @@ -892,10 +875,10 @@ public abstract class AbstractService implements Service { return getItemsByQuery( context, query ); } - public abstract ServiceResults postCollectionSchema( ServiceRequest serviceRequest ) throws Exception; + public abstract ServiceResults postCollectionSettings( ServiceRequest serviceRequest ) throws Exception; - public abstract ServiceResults getCollectionSchema( ServiceRequest serviceRequest ) throws Exception; + public abstract ServiceResults getCollectionSettings( ServiceRequest serviceRequest ) throws Exception; public ServiceResults postCollection( ServiceContext context ) throws Exception { @@ -1370,8 +1353,8 @@ public abstract class AbstractService implements Service { return; } - String perm = getPermissionFromPath( em.getApplicationRef().getUuid(), context.getAction().toString().toLowerCase(), - path ); + String perm = getPermissionFromPath( + em.getApplicationRef().getUuid(), context.getAction().toString().toLowerCase(), path ); boolean permitted = currentUser.isPermitted( perm ); if ( logger.isDebugEnabled() ) { http://git-wip-us.apache.org/repos/asf/usergrid/blob/3f4bd02d/stack/services/src/main/java/org/apache/usergrid/services/applications/ApplicationsService.java ---------------------------------------------------------------------- diff --git a/stack/services/src/main/java/org/apache/usergrid/services/applications/ApplicationsService.java b/stack/services/src/main/java/org/apache/usergrid/services/applications/ApplicationsService.java index 0eef711..86ba153 100644 --- a/stack/services/src/main/java/org/apache/usergrid/services/applications/ApplicationsService.java +++ b/stack/services/src/main/java/org/apache/usergrid/services/applications/ApplicationsService.java @@ -96,13 +96,13 @@ public class ApplicationsService extends AbstractService { @Override - public ServiceResults postCollectionSchema( final ServiceRequest request ) throws Exception { + public ServiceResults postCollectionSettings( final ServiceRequest request ) throws Exception { throw new UnsupportedServiceOperationException( request ); } @Override - public ServiceResults getCollectionSchema( final ServiceRequest serviceRequest ) throws Exception { + public ServiceResults getCollectionSettings( final ServiceRequest serviceRequest ) throws Exception { throw new UnsupportedServiceOperationException( serviceRequest ); }
