/** * Return true if we're on an old version */ private MigrationRelationship<MvccLogEntrySerializationStrategy> getMigrationRelationShip() { return this.versions .getMigrationRelationship( migrationInfoCache.getVersion( CollectionMigrationPlugin.PLUGIN_NAME ) ); } }
/** * Given the current system version, return the maximum migration version we can move to * @param currentVersion * @return */ public int getMaxVersion(final int currentVersion){ return getMigrationRelationship( currentVersion ).to.getImplementationVersion(); }
@Override public boolean isRunning() { //we have to get our state from cassandra for(final String pluginName :getPluginNames()){ if( migrationInfoSerialization.getStatusCode(pluginName) == StatusCode.RUNNING.status){ return true; } } return false; }
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 ); } }
@Override public void resetToVersion( final String pluginName, final int version ) { Preconditions.checkNotNull( pluginName, "pluginName cannot be null" ); final MigrationPlugin plugin = migrationPlugins.get( pluginName ); Preconditions.checkArgument( plugin != null, "Plugin " + pluginName + " could not be found" ); final int highestAllowed = plugin.getMaxVersion(); Preconditions.checkArgument( version <= highestAllowed, "You cannot set a version higher than the max of " + highestAllowed + " for plugin " + pluginName ); Preconditions.checkArgument( version >= 0, "You must specify a version of 0 or greater" ); migrationInfoSerialization.setVersion( pluginName, version ); migrationInfoCache.invalidateAll(); }
@Override public Integer load( final String key ) throws Exception { return migrationInfoSerialization.getVersion( key ); } } );
@Override public void migrate() throws MigrationException { /** * Invoke each plugin to attempt a migration */ executionOrder.forEach(plugin -> { final ProgressObserver observer = new CassandraProgressObserver(plugin.getName()); plugin.run(observer); migrationInfoCache.invalidateAll(); }); }
@Override public void setVersion( final String pluginName, final int version ) { migrationInfoSerialization.setVersion( pluginName, version ); versionCache.invalidate( pluginName ); }
@Override public int compare( final MigrationPlugin o1, final MigrationPlugin o2 ) { //first one is less if(o1.getPhase().ordinal() < o2.getPhase().ordinal()){ return -1; } //second one is first if(o2.getPhase().ordinal() < o1.getPhase().ordinal()){ return 1; } //if our phase for return o1.getName().compareTo( o2.getName() ); } }
@Override public void failed( final int migrationVersion, final String reason ) { final String storedMessage = String.format( "Failed to migrate, reason is appended. Error '%s'", reason ); update( migrationVersion, storedMessage ); logger.error( storedMessage ); failed = true; migrationInfoSerialization.setStatusCode( pluginName, StatusCode.ERROR.status ); }
@Override public void complete() { migrationInfoSerialization.setStatusCode( pluginName, StatusCode.COMPLETE.status ); }
@Override public String getLastStatus( final String pluginName ) { Preconditions.checkNotNull( pluginName, "pluginName cannot be null" ); return migrationInfoSerialization.getStatusMessage( pluginName ); }
public MigrationRelationship( T from, T to ) { this.from = from; this.to = to; fromVersion = from.getImplementationVersion(); toVersion = to.getImplementationVersion(); }
@Override public void run( final ProgressObserver observer ) { //run until complete while(runMigration( observer )){ logger.info( "Migration complete, checking for next run" ); } }
@Override public int getMaxVersion() { int max = 0; for(DataMigration entityMigration: entityDataMigrations){ max = Math.max( max, entityMigration.getMaxVersion() ); } return max; }
/** * Return true if we're on an old version */ private MigrationRelationship<MvccEntitySerializationStrategy> getMigrationRelationShip() { return this.versions.getMigrationRelationship( migrationInfoCache.getVersion( CollectionMigrationPlugin.PLUGIN_NAME ) ); }
@Override public void migrate(final String name) throws MigrationException { /** * Invoke each plugin to attempt a migration */ final MigrationPlugin plugin = migrationPlugins.get( name ); if(plugin != null){ final ProgressObserver observer = new CassandraProgressObserver(plugin.getName()); plugin.run(observer); migrationInfoCache.invalidateAll(); }else { throw new IllegalArgumentException(name + " does not match a current plugin."); } }
@Override public void start() { migrationInfoSerialization.setStatusCode( pluginName, StatusCode.RUNNING.status ); }
/** * Return true if we're on an old version */ private MigrationRelationship<UniqueValueSerializationStrategy> getMigrationRelationShip() { return this.versions .getMigrationRelationship( migrationInfoCache.getVersion( CollectionMigrationPlugin.PLUGIN_NAME ) ); }
/** * Return true if we're on an old version */ private MigrationRelationship<EdgeMetadataSerialization> getMigrationRelationShip() { return this.versions.getMigrationRelationship( migrationInfoCache.getVersion( GraphMigrationPlugin.PLUGIN_NAME ) ); }