Search in sources :

Example 6 with BootException

use of org.commonjava.propulsor.boot.BootException in project indy by Commonjava.

the class JaxRsBooter method main.

public static void main(final String[] args) {
    setDefaultUncaughtExceptionHandler();
    BootOptions boot;
    try {
        boot = loadFromSysProps("indy", BOOT_DEFAULTS_PROP, HOME_PROP);
    } catch (final BootException e) {
        e.printStackTrace();
        System.err.printf("ERROR: %s", e.getMessage());
        System.exit(ERR_LOAD_BOOT_OPTIONS);
        return;
    }
    try {
        if (boot.parseArgs(args)) {
            Booter booter = new JaxRsBooter();
            booter.runAndWait(boot);
        }
    } catch (final BootException e) {
        e.printStackTrace();
        System.err.printf("ERROR: %s", e.getMessage());
        System.exit(ERR_START);
    }
}
Also used : BootException(org.commonjava.propulsor.boot.BootException) BootOptions(org.commonjava.propulsor.boot.BootOptions) Booter(org.commonjava.propulsor.boot.Booter)

Example 7 with BootException

use of org.commonjava.propulsor.boot.BootException in project indy by Commonjava.

the class Main method loadFromJsonFile.

private void loadFromJsonFile(CacheHandle<Object, Object> cache, MigrationOptions options) throws BootException {
    AtomicReference<Throwable> error = new AtomicReference<>();
    try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(options.getDataFile())))) {
        cache.executeCache((c) -> {
            try {
                String key;
                int count = 0;
                while ((key = in.readLine()) != null) {
                    try {
                        Object k = objectMapper.readValue(key, TrackingKey.class);
                        Object v = objectMapper.readValue(in.readLine(), TrackedContent.class);
                        c.putAsync(k, v);
                        count++;
                    } catch (Exception e) {
                        logger.error("Failed to read entry key: {}", key, e);
                        error.set(e);
                    }
                }
                logger.info("Load entries: {}", count);
            } catch (Exception 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());
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) BootException(org.commonjava.propulsor.boot.BootException) FileInputStream(java.io.FileInputStream) IndyLifecycleException(org.commonjava.indy.action.IndyLifecycleException) BootException(org.commonjava.propulsor.boot.BootException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with BootException

use of org.commonjava.propulsor.boot.BootException in project indy by Commonjava.

the class Main method dumpJsonFile.

private void dumpJsonFile(CacheHandle<Object, Object> cache, MigrationOptions options) throws BootException {
    AtomicReference<Throwable> error = new AtomicReference<>();
    try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(options.getDataFile()))) {
        String lineSeparator = System.getProperty("line.separator");
        cache.executeCache((c) -> {
            if (error.get() == null) {
                c.forEach((k, v) -> {
                    if (error.get() == null) {
                        try {
                            out.write(objectMapper.writeValueAsBytes(k));
                            out.write(lineSeparator.getBytes());
                            out.write(objectMapper.writeValueAsBytes(v));
                            out.write(lineSeparator.getBytes());
                            out.flush();
                        } 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());
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) BootException(org.commonjava.propulsor.boot.BootException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 9 with BootException

use of org.commonjava.propulsor.boot.BootException in project indy by Commonjava.

the class Main method main.

public static void main(String[] args) {
    Thread.currentThread().setUncaughtExceptionHandler((thread, error) -> {
        if (error instanceof InvocationTargetException) {
            final InvocationTargetException ite = (InvocationTargetException) error;
            System.err.println("In: " + thread.getName() + "(" + thread.getId() + "), caught InvocationTargetException:");
            ite.getTargetException().printStackTrace();
            System.err.println("...via:");
            error.printStackTrace();
        } else {
            System.err.println("In: " + thread.getName() + "(" + thread.getId() + ") Uncaught error:");
            error.printStackTrace();
        }
    });
    MigrationOptions options = new MigrationOptions();
    try {
        if (options.parseArgs(args)) {
            try {
                int result = new Main().run(options);
                if (result != 0) {
                    System.exit(result);
                }
            } catch (final BootException e) {
                System.err.printf("ERROR INITIALIZING BOOTER: %s", e.getMessage());
                System.exit(ERR_INIT);
            }
        }
    } catch (final BootException e) {
        System.err.printf("ERROR: %s", e.getMessage());
        System.exit(ERR_PARSE_ARGS);
    }
}
Also used : BootException(org.commonjava.propulsor.boot.BootException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

BootException (org.commonjava.propulsor.boot.BootException)9 IOException (java.io.IOException)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 IndyLifecycleException (org.commonjava.indy.action.IndyLifecycleException)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 BufferedOutputStream (java.io.BufferedOutputStream)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Properties (java.util.Properties)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 TrackedContent (org.commonjava.indy.folo.model.TrackedContent)1 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)1