@Override public int migrate( final int currentVersion, final ProgressObserver observer ) { final int migrationVersion = getMaxVersion(); observer.start(); connectionService.deDupeConnections( allApplicationsObservable.getData() ).reduce( 0l, ( count, deDuped ) -> { final long newCount = count + 1; /** * Update our progress observer */ if ( newCount % UPDATE_COUNT == 0 ) { logger.info( "De duped {} edges", newCount ); observer.update( migrationVersion, String.format( "De duped %d edges", newCount ) ); } return newCount; } ).doOnNext( total -> { logger.info( "Completed de-duping {} edges", total ); observer.complete(); } ).toBlocking().lastOrDefault( null ); //want this to run through all records return migrationVersion; }
protected void executeBatch(final int targetVersion, final MutationBatch batch, final ProgressObserver po, final AtomicLong count, com.datastax.driver.core.BatchStatement uniqueBatch) { try { batch.execute(); session.execute(uniqueBatch); po.update( targetVersion, "Finished copying " + count + " entities to the new format" ); } catch ( ConnectionException e ) { po.failed( targetVersion, "Failed to execute mutation in cassandra" ); throw new DataMigrationException( "Unable to migrate batches ", e ); } }
observer.update(getMaxVersion(), "running update for " + index); }) .doOnError(t -> { observer.failed(getMaxVersion(),"failed to update",t); }) .doOnCompleted(() -> { migrationInfoSerialization.setVersion(getName(), getMaxVersion()); observer.complete(); }) observer.failed(getMaxVersion(),"failed to update",ee); throw new RuntimeException(ee);
@Override public void run( ProgressObserver observer ) { final int version = migrationInfoSerialization.getVersion( getName() ); if ( version == getMaxVersion() ) { if (logger.isDebugEnabled()) { logger.debug("Skipping Migration Plugin: {}", getName()); } return; } observer.start(); AtomicInteger count = new AtomicInteger(); //get old app infos to migrate final Observable<Entity> oldAppInfos = getOldAppInfos(); oldAppInfos.doOnNext( oldAppInfoEntity -> { migrateAppInfo( oldAppInfoEntity, observer ); count.incrementAndGet(); } ) //we want a doOnError to catch something going wrong, otherwise we'll mark as complete .doOnError( error -> { logger.error( "Unable to migrate applications, an error occurred. Please try again", error ); observer.failed( getMaxVersion(), "Unable to migrate applications", error ); } ) //if we complete successfully, set the version and notify the observer .doOnCompleted( () -> { migrationInfoSerialization.setVersion( getName(), getMaxVersion() ); observer.complete(); } ).subscribe();//let this run through since it handles errors }
observer.update( migration.to.getImplementationVersion(), String .format( "Currently running. Rewritten %d edge types", newCount ) );
Mockito.verify( po, Mockito.times(10) ).update( Mockito.anyInt(), Mockito.anyString() ); setup.refreshIndex(mgmtAppId);