io.deepsense.neptune.clientlibrary.NeptuneContextFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neptune-client-library Show documentation
Show all versions of neptune-client-library Show documentation
Enables integration with Neptune in your Java code
/**
* Copyright (c) 2016, CodiLime Inc.
*/
package io.deepsense.neptune.clientlibrary;
import ch.qos.logback.classic.Level;
import io.deepsense.neptune.apiclient.ApiException;
import io.deepsense.neptune.clientlibrary.models.JobParameters;
import io.deepsense.neptune.clientlibrary.models.NeptuneContext;
import io.deepsense.neptune.clientlibrary.models.impl.context.NeptuneContextBuilderFactory;
import io.deepsense.neptune.clientlibrary.models.impl.parameters.OfflineJobParameters;
import io.deepsense.neptune.clientlibrary.parsers.additionalargumentsparser.AdditionalArgumentsParser;
import io.deepsense.neptune.clientlibrary.parsers.jobargumentsparser.JobArguments;
import io.deepsense.neptune.clientlibrary.parsers.jobargumentsparser.JobArgumentsParser;
import io.deepsense.neptune.clientlibrary.utils.SystemEnvironment;
import io.deepsense.neptune.clientlibrary.utils.exceptions.ApiExceptionWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class NeptuneContextFactory {
private NeptuneContextFactory() {
}
private static JobArguments getJobArguments(String[] programArguments) {
AdditionalArgumentsParser additionalArgumentsParser = new AdditionalArgumentsParser();
JobArguments jobArguments = new JobArgumentsParser(additionalArgumentsParser)
.parse(programArguments, new SystemEnvironment());
if (jobArguments.isDebug()) {
setRootLoggingLevel(Level.DEBUG);
}
return jobArguments;
}
public static NeptuneContext createContext(String[] programArguments) {
return createContext(programArguments, OfflineJobParameters.emptyParameters());
}
public static NeptuneContext createContext(String[] programArguments, JobParameters jobParameters) {
try {
JobArguments jobArguments = getJobArguments(programArguments);
return new NeptuneContextBuilderFactory().create(jobArguments, jobParameters).build();
} catch (ApiException exc) {
throw ApiExceptionWrapper.wrappedApiException(exc);
}
}
private static void setRootLoggingLevel(Level level) {
ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory
.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.setLevel(level);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy