use of org.commonjava.propulsor.boot.BootException in project indy by Commonjava.
the class Main method loadFromObjectFile.
private void loadFromObjectFile(CacheHandle<Object, Object> cache, MigrationOptions options) throws BootException {
AtomicReference<Throwable> error = new AtomicReference<>();
try (ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new FileInputStream(options.getDataFile())))) {
cache.executeCache((c) -> {
try {
long records = in.readLong();
for (long i = 0; i < records; i++) {
try {
Object k = in.readObject();
Object v = in.readObject();
c.putAsync(k, v);
} catch (Exception e) {
logger.error("Failed to read entry at index: " + i, e);
error.set(e);
}
}
logger.info("Load {} complete, size: {}", options.getCacheName(), records);
} catch (IOException e) {
logger.error("Failed to read data file header.", e);
error.set(e);
}
return true;
});
} catch (IOException e) {
error.set(e);
}
if (error.get() != null) {
throw new BootException("Failed to read data from file: " + options.getDataFile(), error.get());
}
}
use of org.commonjava.propulsor.boot.BootException in project indy by Commonjava.
the class Main method dumpObjectFile.
private void dumpObjectFile(CacheHandle<Object, Object> cache, MigrationOptions options) throws BootException {
AtomicReference<Throwable> error = new AtomicReference<>();
try (ObjectOutputStream out = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(options.getDataFile())))) {
cache.executeCache((c) -> {
try {
out.writeLong(c.size());
} catch (IOException e) {
logger.error("Failed to write data file header.", e);
error.set(e);
}
if (error.get() == null) {
c.forEach((k, v) -> {
if (error.get() == null) {
try {
out.writeObject(k);
out.writeObject(v);
} catch (IOException e) {
logger.error("Failed to write entry with key: " + k, e);
error.set(e);
}
}
});
}
return true;
});
} catch (IOException e) {
error.set(e);
}
if (error.get() != null) {
throw new BootException("Failed to write data to file: " + options.getDataFile(), error.get());
}
}
use of org.commonjava.propulsor.boot.BootException in project indy by Commonjava.
the class Main method dumpZipFiles.
private void dumpZipFiles(CacheHandle<Object, Object> cache, MigrationOptions options) throws BootException {
AtomicReference<Throwable> error = new AtomicReference<>();
cache.executeCache((c) -> {
if (error.get() == null) {
int count = 0;
int batchSize = options.getBatchSize() != null ? options.getBatchSize() : 1000;
Iterable<List<Object>> subLists = Iterables.partition(c.keySet(), batchSize);
logger.info("Handle the cache in batch size:{}", batchSize);
for (List<Object> subList : subLists) {
if (error.get() == null) {
Set<TrackedContent> sealed = new HashSet<>();
File out = new File(options.getDataFile().getParent() + "/folo-" + count + ".zip");
if (error.get() == null) {
for (Object key : subList) {
sealed.add((TrackedContent) c.get(key));
}
try {
zipTrackedContent(out, sealed);
} catch (IOException e) {
logger.error("Failed to zip entries : " + subList.toString(), e);
error.set(e);
}
}
count++;
}
}
}
return true;
});
if (error.get() != null) {
throw new BootException("Failed to write data to zip.", error.get());
}
}
use of org.commonjava.propulsor.boot.BootException in project indy by Commonjava.
the class Main method run.
private int run(final MigrationOptions options) throws BootException {
try {
File inXml = options.getInfinispanXml();
if (inXml != null) {
File outXmlDir = new File(System.getProperty("java.io.tmpdir", "/tmp"), "infinispan-config-" + System.currentTimeMillis());
if (!outXmlDir.isDirectory() && !outXmlDir.mkdirs()) {
throw new BootException("Failed to create temporary direcory for infinispan configuration loading");
}
File outXml = new File(outXmlDir, "infinispan.xml");
FileUtils.copyFile(inXml, outXml);
Properties props = System.getProperties();
props.setProperty("indy.config.dir", outXmlDir.getAbsolutePath());
System.setProperties(props);
}
producer = new SimpleCacheProducer();
objectMapper = new IndyObjectMapper(true);
objectMapper.disable(SerializationFeature.INDENT_OUTPUT);
CacheHandle<Object, Object> cache = producer.getCache(options.getCacheName());
if (MigrationCommand.dump == options.getMigrationCommand()) {
if (DataType.json == options.getDataType()) {
dumpJsonFile(cache, options);
} else if (DataType.object == options.getDataType()) {
dumpObjectFile(cache, options);
} else {
dumpZipFiles(cache, options);
}
} else {
if (DataType.json == options.getDataType()) {
loadFromJsonFile(cache, options);
} else {
loadFromObjectFile(cache, options);
}
}
} catch (final Throwable e) {
if (e instanceof BootException)
throw (BootException) e;
logger.error("Failed to initialize Booter: " + e.getMessage(), e);
return ERR_INIT;
} finally {
try {
producer.stop();
} catch (final IndyLifecycleException e) {
logger.error("Failed to stop cache subsystem: " + e.getMessage(), e);
}
}
return 0;
}
use of org.commonjava.propulsor.boot.BootException in project indy by Commonjava.
the class MigrationOptions method parseArgs.
public boolean parseArgs(final String[] args) throws BootException {
final CmdLineParser parser = new CmdLineParser(this);
boolean canStart = true;
try {
parser.parseArgument(args);
} catch (final CmdLineException e) {
throw new BootException("Failed to parse command-line args: %s", e, e.getMessage());
}
if (isHelp()) {
printUsage(parser, null);
canStart = false;
} else if (getMigrationCommand() == null || getDataFile() == null || getCacheName() == null) {
System.err.println("You must provide 'action', 'cache-name', and 'data-file' arguments!");
printUsage(parser, null);
canStart = false;
}
return canStart;
}
Aggregations