use of org.apache.asterix.common.configuration.TransactionLogDir in project asterixdb by apache.
the class AsterixYARNClient method writeAsterixConfig.
/**
* Retrieves necessary information from the cluster configuration and splices it into the Asterix configuration parameters
*
* @param cluster
* @throws FileNotFoundException
* @throws IOException
*/
private void writeAsterixConfig(Cluster cluster) throws FileNotFoundException, IOException {
String metadataNodeId = Utils.getMetadataNode(cluster).getId();
String asterixInstanceName = instanceName;
AsterixConfiguration configuration = locateConfig();
readConfigParams(configuration);
String version = Utils.getAsterixVersionFromClasspath();
configuration.setVersion(version);
configuration.setInstanceName(asterixInstanceName);
List<Store> stores = new ArrayList<Store>();
String storeDir = cluster.getStore().trim();
for (Node node : cluster.getNode()) {
String iodevices = node.getIodevices() == null ? cluster.getIodevices() : node.getIodevices();
String[] nodeIdDevice = iodevices.split(",");
StringBuilder nodeStores = new StringBuilder();
for (int i = 0; i < nodeIdDevice.length; i++) {
nodeStores.append(nodeIdDevice[i] + File.separator + storeDir + ",");
}
//remove last comma
nodeStores.deleteCharAt(nodeStores.length() - 1);
stores.add(new Store(node.getId(), nodeStores.toString()));
}
configuration.setStore(stores);
List<Coredump> coredump = new ArrayList<Coredump>();
String coredumpdir = null;
List<TransactionLogDir> txnLogDirs = new ArrayList<TransactionLogDir>();
String txnLogDir = null;
for (Node node : cluster.getNode()) {
coredumpdir = node.getLogDir() == null ? cluster.getLogDir() : node.getLogDir();
coredump.add(new Coredump(node.getId(), coredumpdir + "coredump" + File.separator));
//node or cluster-wide
txnLogDir = node.getTxnLogDir() == null ? cluster.getTxnLogDir() : node.getTxnLogDir();
txnLogDirs.add(new TransactionLogDir(node.getId(), txnLogDir + (txnLogDir.charAt(txnLogDir.length() - 1) == File.separatorChar ? File.separator : "") + //if the string doesn't have a trailing / add one
"txnLogs" + File.separator));
}
configuration.setMetadataNode(metadataNodeId);
configuration.setCoredump(coredump);
configuration.setTransactionLogDir(txnLogDirs);
FileOutputStream os = new FileOutputStream(MERGED_PARAMETERS_PATH);
try {
JAXBContext ctx = JAXBContext.newInstance(AsterixConfiguration.class);
Marshaller marshaller = ctx.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(configuration, os);
} catch (JAXBException e) {
throw new IOException(e);
} finally {
os.close();
}
}
use of org.apache.asterix.common.configuration.TransactionLogDir in project asterixdb by apache.
the class AsterixEventServiceUtil method writeAsterixConfigurationFile.
private static void writeAsterixConfigurationFile(AsterixInstance asterixInstance) throws IOException, JAXBException {
String asterixInstanceName = asterixInstance.getName();
Cluster cluster = asterixInstance.getCluster();
String metadataNodeId = asterixInstance.getMetadataNodeId();
AsterixConfiguration configuration = asterixInstance.getAsterixConfiguration();
configuration.setInstanceName(asterixInstanceName);
configuration.setMetadataNode(asterixInstanceName + "_" + metadataNodeId);
List<Store> stores = new ArrayList<Store>();
String storeDir = cluster.getStore().trim();
for (Node node : cluster.getNode()) {
String iodevices = node.getIodevices() == null ? cluster.getIodevices() : node.getIodevices();
String[] nodeIdDevice = iodevices.split(",");
StringBuilder nodeStores = new StringBuilder();
for (int i = 0; i < nodeIdDevice.length; i++) {
nodeStores.append(nodeIdDevice[i] + File.separator + storeDir + ",");
}
//remove last comma
nodeStores.deleteCharAt(nodeStores.length() - 1);
stores.add(new Store(asterixInstanceName + "_" + node.getId(), nodeStores.toString()));
}
configuration.setStore(stores);
List<Coredump> coredump = new ArrayList<Coredump>();
List<TransactionLogDir> txnLogDirs = new ArrayList<TransactionLogDir>();
for (Node node : cluster.getNode()) {
String coredumpdir = node.getLogDir() == null ? cluster.getLogDir() : node.getLogDir();
coredump.add(new Coredump(asterixInstanceName + "_" + node.getId(), coredumpdir + File.separator + asterixInstanceName + "_" + node.getId()));
String txnLogDir = node.getTxnLogDir() == null ? cluster.getTxnLogDir() : node.getTxnLogDir();
txnLogDirs.add(new TransactionLogDir(asterixInstanceName + "_" + node.getId(), txnLogDir));
}
configuration.setCoredump(coredump);
configuration.setTransactionLogDir(txnLogDirs);
File asterixConfDir = new File(AsterixEventService.getAsterixDir() + File.separator + asterixInstanceName);
asterixConfDir.mkdirs();
JAXBContext ctx = JAXBContext.newInstance(AsterixConfiguration.class);
Marshaller marshaller = ctx.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
FileOutputStream os = new FileOutputStream(asterixConfDir + File.separator + ASTERIX_CONFIGURATION_FILE);
marshaller.marshal(configuration, os);
os.close();
}
Aggregations