This repository has been archived by the owner on Apr 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/conveyal/analyst-server
- Loading branch information
Showing
35 changed files
with
611 additions
and
625 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,5 @@ s3credentials | |
*.class | ||
conf/application.conf | ||
/bin | ||
/cache/ | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package migrations; | ||
|
||
import java.io.File; | ||
import java.util.Map.Entry; | ||
|
||
import com.google.common.io.Files; | ||
|
||
import models.Attribute; | ||
import models.Project; | ||
import models.Shapefile; | ||
import models.User; | ||
import utils.DataStore; | ||
|
||
/** | ||
* Move the storage of most of the data to Java Serialization format; see discussion in issue 68. | ||
* | ||
* This is a java main class and runs outside the Play framework; I just run it inside Eclipse. | ||
* | ||
* @author mattwigway | ||
*/ | ||
public class MoveToJavaSerialization { | ||
public static void main(String... args) { | ||
File inDir = new File(args[0]); | ||
File outDir = new File(args[1]); | ||
|
||
if (args.length != 2 || !inDir.isDirectory() || !outDir.isDirectory() || outDir.list().length != 0) { | ||
System.out.println("usage: ... old_data_directory new_data_directory"); | ||
System.out.println("both directories must exist. new directory must be empty."); | ||
return; | ||
} | ||
|
||
// we don't want to use the built-in datastores of models, so point them at nowhere | ||
DataStore.dataPath = Files.createTempDir().getAbsolutePath(); | ||
|
||
// for each of the models, get a datastore, read the data, and then write it out | ||
System.out.println("Processing shapefiles"); | ||
int migrated = new Migrator<Shapefile>(inDir, outDir, "shapes").migrate(); | ||
System.out.println("Done processing " + migrated + " shapefiles"); | ||
|
||
System.out.println("Processing users"); | ||
migrated = new Migrator<User>(inDir, outDir, "users").migrate(); | ||
System.out.println("Done processing " + migrated + " users"); | ||
|
||
System.out.println("Processing projects"); | ||
migrated = new Migrator<Project>(inDir, outDir, "projects").migrate(); | ||
System.out.println("Done processing " + migrated + " projects"); | ||
|
||
System.out.println("Processing scenarios"); | ||
migrated = new Migrator<User>(inDir, outDir, "scenario").migrate(); | ||
System.out.println("Done processing " + migrated + " scenarios"); | ||
|
||
System.out.println("Processing queries"); | ||
migrated = new Migrator<User>(inDir, outDir, "queries").migrate(); | ||
System.out.println("Done processing " + migrated + " queries"); | ||
} | ||
|
||
/** Migrate a datastore to Java serialization */ | ||
private static class Migrator<T> { | ||
private File inDir; | ||
private File outDir; | ||
private String name; | ||
|
||
public Migrator(File inDir, File outDir, String name) { | ||
this.inDir = inDir; | ||
this.outDir = outDir; | ||
this.name = name; | ||
} | ||
|
||
public int migrate() { | ||
// note: hard wired to transactional and hard-ref default cache. these things are tiny anyhow. | ||
DataStore<T> in = new DataStore<T>(inDir, name, true, false, false); | ||
DataStore<T> out = new DataStore<T>(outDir, name, true, false, true); | ||
|
||
int migrated = 0; | ||
|
||
for (Entry<String, T> kv : in.getEntries()) { | ||
|
||
// set category IDs on old shapefiles while we're at it. | ||
if (kv instanceof Shapefile) { | ||
Shapefile shp = (Shapefile) kv; | ||
if (shp.categoryId == null) { | ||
shp.categoryId = Attribute.convertNameToId(shp.name); | ||
} | ||
} | ||
|
||
out.saveWithoutCommit(kv.getKey(), kv.getValue()); | ||
migrated++; | ||
} | ||
|
||
out.commit(); | ||
|
||
return migrated; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.