Search in sources :

Example 1 with TransactionLogDir

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();
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) AsterixConfiguration(org.apache.asterix.common.configuration.AsterixConfiguration) TransactionLogDir(org.apache.asterix.common.configuration.TransactionLogDir) Node(org.apache.asterix.event.schema.yarnCluster.Node) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) Store(org.apache.asterix.common.configuration.Store) JAXBContext(javax.xml.bind.JAXBContext) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) Coredump(org.apache.asterix.common.configuration.Coredump)

Example 2 with TransactionLogDir

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();
}
Also used : Marshaller(javax.xml.bind.Marshaller) AsterixConfiguration(org.apache.asterix.common.configuration.AsterixConfiguration) TransactionLogDir(org.apache.asterix.common.configuration.TransactionLogDir) Node(org.apache.asterix.event.schema.cluster.Node) ArrayList(java.util.ArrayList) Cluster(org.apache.asterix.event.schema.cluster.Cluster) Store(org.apache.asterix.common.configuration.Store) JAXBContext(javax.xml.bind.JAXBContext) FileOutputStream(java.io.FileOutputStream) Coredump(org.apache.asterix.common.configuration.Coredump) JarFile(java.util.jar.JarFile) File(java.io.File)

Aggregations

FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 JAXBContext (javax.xml.bind.JAXBContext)2 Marshaller (javax.xml.bind.Marshaller)2 AsterixConfiguration (org.apache.asterix.common.configuration.AsterixConfiguration)2 Coredump (org.apache.asterix.common.configuration.Coredump)2 Store (org.apache.asterix.common.configuration.Store)2 TransactionLogDir (org.apache.asterix.common.configuration.TransactionLogDir)2 File (java.io.File)1 IOException (java.io.IOException)1 JarFile (java.util.jar.JarFile)1 JAXBException (javax.xml.bind.JAXBException)1 Cluster (org.apache.asterix.event.schema.cluster.Cluster)1 Node (org.apache.asterix.event.schema.cluster.Node)1 Node (org.apache.asterix.event.schema.yarnCluster.Node)1