You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/12/03 20:59:56 UTC
[46/50] [abbrv] incubator-usergrid git commit: Beginning of a
migration that re-applies mappings to all indexes, i.e. all applications.
Beginning of a migration that re-applies mappings to all indexes, i.e. all applications.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/79f19f8e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/79f19f8e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/79f19f8e
Branch: refs/heads/no-source-in-es
Commit: 79f19f8e1c96fd0799a68196df0fdd6f832f8005
Parents: 716793f
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Dec 3 10:49:46 2014 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Dec 3 10:49:46 2014 -0500
----------------------------------------------------------------------
.../ApplyQueryIndexMappingsMigration.java | 77 ++++++++++++++++++++
1 file changed, 77 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/79f19f8e/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/ApplyQueryIndexMappingsMigration.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/ApplyQueryIndexMappingsMigration.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/ApplyQueryIndexMappingsMigration.java
new file mode 100644
index 0000000..782c48e
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/ApplyQueryIndexMappingsMigration.java
@@ -0,0 +1,77 @@
+/*
+ * 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.migration;
+
+
+import java.util.concurrent.atomic.AtomicLong;
+
+
+import org.apache.usergrid.corepersistence.ManagerCache;
+import org.apache.usergrid.persistence.core.migration.data.DataMigration;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+import com.google.inject.Inject;
+import org.apache.usergrid.corepersistence.rx.ApplicationObservable;
+import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
+import org.apache.usergrid.persistence.index.EntityIndex;
+
+import rx.functions.Action1;
+
+
+/**
+ * Migration applies the current Query Index mappings to every Query Index,
+ * and thus every Application in the system.
+ */
+public class ApplyQueryIndexMappingsMigration implements DataMigration {
+
+ private final ManagerCache managerCache;
+
+ @Inject
+ public ApplyQueryIndexMappingsMigration( final ManagerCache managerCache) {
+ this.managerCache = managerCache;
+ }
+
+
+ @Override
+ public void migrate( final ProgressObserver observer ) throws Throwable {
+
+ ApplicationObservable.getAllApplicationIds( managerCache )
+ .doOnNext( new Action1<Id>() {
+
+ @Override
+ public void call( final Id appId ) {
+ EntityIndex ei = managerCache.getEntityIndex(new ApplicationScopeImpl( appId ));
+ ei.initializeIndex();
+ }
+
+ } ).toBlocking().lastOrDefault( null );
+ }
+
+
+ private void updateStatus( final AtomicLong counter, final ProgressObserver observer ) {
+ observer.update( getVersion(), String.format( "Updated %d entities", counter.get() ) );
+ }
+
+
+ @Override
+ public int getVersion() {
+ return Versions.VERSION_1;
+ }
+}