use of com.accenture.trac.common.exception.EStartup in project tracdap by finos.
the class TracDataService method doStartup.
@Override
protected void doStartup(Duration startupTimeout) {
PlatformConfig platformConfig;
DataServiceConfig dataSvcConfig;
try {
if (MemoryUtil.UNSAFE == null)
throw new NullPointerException("MemoryUtil.UNSAFE == null");
} catch (RuntimeException e) {
log.error("Failed to set up native memory access for Apache Arrow", e);
throw new EStartup("Failed to set up native memory access for Apache Arrow", e);
}
try {
pluginManager.initRegularPlugins();
} catch (Exception e) {
var errorMessage = "There was a problem loading the plugins: " + e.getMessage();
log.error(errorMessage, e);
throw new EStartup(errorMessage, e);
}
try {
log.info("Loading TRAC platform config...");
platformConfig = configManager.loadRootConfigObject(PlatformConfig.class);
dataSvcConfig = platformConfig.getServices().getData();
// TODO: Config validation
log.info("Config looks ok");
} catch (Exception e) {
var errorMessage = "There was a problem loading the platform config: " + e.getMessage();
log.error(errorMessage, e);
throw new EStartup(errorMessage, e);
}
try {
var channelType = NioServerSocketChannel.class;
var clientChannelType = NioSocketChannel.class;
var workerThreads = Runtime.getRuntime().availableProcessors() * 2;
workerGroup = new NioEventLoopGroup(workerThreads, new DefaultThreadFactory("data-svc"));
bossGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("data-boss"));
var execRegister = new ExecutionRegister(workerGroup);
// TODO: Review setup of Arrow allocator, inc. interaction with Netty / Protobuf allocators
var arrowAllocatorConfig = RootAllocator.configBuilder().allocationManagerFactory(NettyAllocationManager.FACTORY).build();
var arrowAllocator = new RootAllocator(arrowAllocatorConfig);
var formats = new CodecManager(pluginManager);
var storage = new StorageManager(pluginManager);
storage.initStorage(dataSvcConfig.getStorageMap(), formats);
// Check default storage and format are available
checkDefaultStorageAndFormat(storage, formats, dataSvcConfig);
var metaClient = prepareMetadataClient(platformConfig, clientChannelType);
var dataSvc = new DataService(dataSvcConfig, arrowAllocator, storage, formats, metaClient);
var fileSvc = new FileService(dataSvcConfig, storage, metaClient);
var publicApi = new TracDataApi(dataSvc, fileSvc);
// Create the main server
this.server = NettyServerBuilder.forPort(dataSvcConfig.getPort()).addService(publicApi).channelType(channelType).bossEventLoopGroup(bossGroup).workerEventLoopGroup(workerGroup).directExecutor().intercept(execRegister.registerExecContext()).build();
// Good to go, let's start!
server.start();
log.info("Data service is listening on port {}", server.getPort());
} catch (IOException e) {
throw new EStartup(e.getMessage(), e);
}
}
use of com.accenture.trac.common.exception.EStartup in project tracdap by finos.
the class JdbcIntegration method beforeAll.
@Override
public void beforeAll(ExtensionContext context) {
// Method for getting standard args from environment instead of command line
// It may be useful to have this in StandardArgsProcessor
var env = System.getenv();
var workingDir = Paths.get(".").toAbsolutePath().normalize();
var configFile = env.get(TRAC_CONFIG_FILE);
var keystoreKey = env.get(TRAC_KEYSTORE_KEY);
if (configFile == null || configFile.isBlank())
throw new EStartup("Missing environment variable for integration testing: " + TRAC_CONFIG_FILE);
var configManager = Startup.quickConfig(workingDir, configFile, keystoreKey);
var platformConfig = configManager.loadRootConfigObject(PlatformConfig.class);
var metaConfig = platformConfig.getServices().getMeta();
var dalProps = new Properties();
dalProps.putAll(metaConfig.getDalPropsMap());
dialect = JdbcSetup.getSqlDialect(dalProps, "");
source = JdbcSetup.createDatasource(dalProps, "");
}
use of com.accenture.trac.common.exception.EStartup in project tracdap by finos.
the class AwsConfigLoader method loadTextFile.
@Override
public String loadTextFile(URI uri) {
var ERROR_MSG_TEMPLATE = "Failed to load config file from S3: %2$s [%1$s]";
final AmazonS3 s3 = AmazonS3ClientBuilder.standard().build();
String path = uri.getPath();
if (path.startsWith("/")) {
path = path.substring(1);
}
String output;
try {
S3Object o = s3.getObject(uri.getHost(), path);
try (S3ObjectInputStream s3is = o.getObjectContent()) {
try (ByteArrayOutputStream fos = new ByteArrayOutputStream()) {
byte[] read_buf = new byte[1024];
int read_len;
while ((read_len = s3is.read(read_buf)) > 0) {
fos.write(read_buf, 0, read_len);
}
output = fos.toString();
}
}
return output;
} catch (AmazonS3Exception | IOException e) {
var message = String.format(ERROR_MSG_TEMPLATE, path, e.getMessage());
throw new EStartup(message, e);
}
}
use of com.accenture.trac.common.exception.EStartup in project tracdap by finos.
the class JdbcSetup method getSqlDialect.
public static JdbcDialect getSqlDialect(Properties props, String configBase) {
var dialectPropKey = configBase + DIALECT_PROPERTY;
var dialect = props.getProperty(dialectPropKey, null);
if (dialect == null || dialect.isBlank())
throw new EStartup("Missing required config property: " + dialectPropKey);
try {
return Enum.valueOf(JdbcDialect.class, dialect);
} catch (IllegalArgumentException e) {
throw new EStartup(String.format("Unsupported SQL dialect: [%s]", dialect));
}
}
use of com.accenture.trac.common.exception.EStartup in project tracdap by finos.
the class TestConfigLoader method loadTextFile.
@Override
public String loadTextFile(URI uri) {
// Ignore leading slash on path component
var relativePath = uri.getPath().substring(1);
var absolutePath = tempDir.resolve(relativePath);
try {
return Files.readString(absolutePath);
} catch (IOException e) {
throw new EStartup("Config file could not be read: " + e.getMessage(), e);
}
}
Aggregations