Search in sources :

Example 16 with VoltFile

use of org.voltdb.utils.VoltFile in project voltdb by VoltDB.

the class SnapshotUtil method retrieveRelevantFiles.

public static File[] retrieveRelevantFiles(String filePath, final String fileNonce) {
    FilenameFilter has_nonce = new FilenameFilter() {

        @Override
        public boolean accept(File dir, String file) {
            return file.startsWith(fileNonce) && file.endsWith(".vpt");
        }
    };
    File save_dir = new VoltFile(filePath);
    File[] save_files = save_dir.listFiles(has_nonce);
    return save_files;
}
Also used : FilenameFilter(java.io.FilenameFilter) VoltFile(org.voltdb.utils.VoltFile) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File)

Example 17 with VoltFile

use of org.voltdb.utils.VoltFile in project voltdb by VoltDB.

the class TestInitStartAction method validateStagedCatalog.

/*
     * "voltdb init --schema --procedures" tests:
     * 1.  Positive test with valid schema that requires no procedures
     * 2a. Positive test with valid schema and procedures that are in CLASSPATH
     * 2b. Negative test with valid files but not "init --force"
     * 3.  Negative test with a bad schema
     * 4.  Negative test with procedures missing
     *
     * Note that SimulatedExitException is thrown by the command line parser with no descriptive details.
     * VoltDB.crashLocalVoltDB() throws an AssertionError with the message "Faux crash of VoltDB successful."
     */
/** Verifies that the staged catalog matches what VoltCompiler emits given the supplied schema.
     * @param schema Schema used to generate the staged catalog
     * @throws Exception upon test failure or error (unable to write temp file for example)
     */
private void validateStagedCatalog(String schema, InMemoryJarfile proceduresJar) throws Exception {
    // setup reference point for the supplied schema
    File schemaFile = VoltProjectBuilder.writeStringToTempFile(schema);
    schemaFile.deleteOnExit();
    File referenceFile = File.createTempFile("reference", ".jar");
    referenceFile.deleteOnExit();
    VoltCompiler compiler = new VoltCompiler(false);
    compiler.setInitializeDDLWithFiltering(true);
    final boolean success = compiler.compileFromDDL(referenceFile.getAbsolutePath(), schemaFile.getPath());
    assertEquals(true, success);
    InMemoryJarfile referenceCatalogJar = new InMemoryJarfile(referenceFile);
    Catalog referenceCatalog = new Catalog();
    referenceCatalog.execute(CatalogUtil.getSerializedCatalogStringFromJar(referenceCatalogJar));
    // verify that the staged catalog is identical
    File stagedJarFile = new VoltFile(RealVoltDB.getStagedCatalogPath(rootDH.getPath() + File.separator + "voltdbroot"));
    assertEquals(true, stagedJarFile.isFile());
    InMemoryJarfile stagedCatalogJar = new InMemoryJarfile(stagedJarFile);
    Catalog stagedCatalog = new Catalog();
    stagedCatalog.execute(CatalogUtil.getSerializedCatalogStringFromJar(stagedCatalogJar));
    assertEquals(true, referenceCatalog.equals(stagedCatalog));
    assertEquals(true, stagedCatalog.equals(referenceCatalog));
    assertEquals(true, referenceFile.delete());
    assertEquals(true, schemaFile.delete());
    if (proceduresJar != null) {
        // Validate that the list of files in the supplied jarfile are present in the staged catalog also.
        InMemoryJarfile strippedReferenceJar = CatalogUtil.getCatalogJarWithoutDefaultArtifacts(proceduresJar);
        InMemoryJarfile strippedTestJar = CatalogUtil.getCatalogJarWithoutDefaultArtifacts(stagedCatalogJar);
        for (Entry<String, byte[]> entry : strippedReferenceJar.entrySet()) {
            System.out.println("Checking " + entry.getKey());
            byte[] testClass = strippedTestJar.get(entry.getKey());
            assertNotNull(entry.getKey() + " was not found in staged catalog", testClass);
            assertArrayEquals(entry.getValue(), testClass);
        }
    }
}
Also used : VoltCompiler(org.voltdb.compiler.VoltCompiler) VoltFile(org.voltdb.utils.VoltFile) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File) Catalog(org.voltdb.catalog.Catalog)

Example 18 with VoltFile

use of org.voltdb.utils.VoltFile in project voltdb by VoltDB.

the class TestStartWithSchema method countNodesWithStagedCatalog.

/** Counts how many nodes contain staged catalogs (user-initialized schemas)
     * @param cluster
     * @return number of nodes in cluster that have staged catalogs
     */
static int countNodesWithStagedCatalog(LocalCluster cluster) throws IOException {
    final String pathWithinSubroot = File.separator + Constants.DBROOT + File.separator + CatalogUtil.STAGED_CATALOG_PATH;
    int total = 0;
    for (Map.Entry<String, String> entry : cluster.getHostRoots().entrySet()) {
        assert (entry.getValue().contains(Constants.DBROOT) == false) : entry.getValue();
        File testFile = new VoltFile(entry.getValue() + pathWithinSubroot);
        if (testFile.canRead() && (testFile.length() > 0)) {
            InMemoryJarfile jar = new InMemoryJarfile(testFile);
            ensureAllCatalogDefaultArtifactsExists(jar, testFile.getAbsolutePath());
            total++;
        }
    }
    return total;
}
Also used : VoltFile(org.voltdb.utils.VoltFile) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Map(java.util.Map) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File)

Example 19 with VoltFile

use of org.voltdb.utils.VoltFile in project voltdb by VoltDB.

the class LocalCluster method initOne.

private void initOne(int hostId, boolean clearLocalDataDirectories) throws IOException {
    PipeToFile ptf = null;
    CommandLine cmdln = (templateCmdLine.makeCopy());
    cmdln.setJavaProperty(clusterHostIdProperty, String.valueOf(hostId));
    if (this.m_additionalProcessEnv != null) {
        for (String name : this.m_additionalProcessEnv.keySet()) {
            cmdln.setJavaProperty(name, this.m_additionalProcessEnv.get(name));
        }
    }
    File root = null;
    try {
        //If clear clean VoltFile.getServerSpecificRoot(String.valueOf(hostId))
        root = VoltFile.getServerSpecificRoot(String.valueOf(hostId), clearLocalDataDirectories);
        assert (root.getName().equals(Constants.DBROOT) == false) : root.getAbsolutePath();
        cmdln = cmdln.voltdbRoot(new File(root, Constants.DBROOT));
        cmdln = cmdln.startCommand(StartAction.INITIALIZE);
        if (clearLocalDataDirectories) {
            cmdln.setForceVoltdbCreate(true);
        } else {
            cmdln.setForceVoltdbCreate(false);
        }
        if (new Integer(hostId).equals(m_mismatchNode)) {
            assert m_usesStagedSchema;
            cmdln.m_userSchema = m_mismatchSchema == null ? null : VoltProjectBuilder.createFileForSchema(m_mismatchSchema);
        }
        m_procBuilder.command().clear();
        List<String> cmdlnList = cmdln.createCommandLine();
        String cmdLineFull = "Init cmd host=" + String.valueOf(hostId) + " :";
        for (String element : cmdlnList) {
            assert (element != null);
            cmdLineFull += " " + element;
        }
        log.info(cmdLineFull);
        m_procBuilder.command().addAll(cmdlnList);
        // write output to obj/release/testoutput/<test name>-n.txt
        // this may need to be more unique? Also very useful to just
        // set this to a hardcoded path and use "tail -f" to debug.
        String testoutputdir = cmdln.buildDir() + File.separator + "testoutput";
        System.out.println("Process output will be redirected to: " + testoutputdir);
        // make sure the directory exists
        File dir = new File(testoutputdir);
        if (dir.exists()) {
            assert (dir.isDirectory());
        } else {
            boolean status = dir.mkdirs();
            assert (status);
        }
        File dirFile = new VoltFile(testoutputdir);
        if (dirFile.listFiles() != null) {
            for (File f : dirFile.listFiles()) {
                if (f.getName().startsWith(getName() + "-" + hostId)) {
                    f.delete();
                }
            }
        }
        Process proc = m_procBuilder.start();
        String fileName = testoutputdir + File.separator + "LC-" + getFileName() + "-" + m_clusterId + "-init-" + hostId + "-" + "idx" + String.valueOf(perLocalClusterExtProcessIndex++) + ".txt";
        System.out.println("Process output can be found in: " + fileName);
        ptf = new PipeToFile(fileName, proc.getInputStream(), String.valueOf(hostId), false, proc);
        ptf.setName("ClusterPipe:" + String.valueOf(hostId));
        ptf.start();
        proc.waitFor();
    } catch (IOException ex) {
        log.error("Failed to start cluster process:" + ex.getMessage(), ex);
        assert (false);
    } catch (InterruptedException ex) {
        log.error("Failed to start cluster process:" + ex.getMessage(), ex);
        assert (false);
    }
    if (root != null) {
        String hostIdStr = cmdln.getJavaProperty(clusterHostIdProperty);
        m_hostRoots.put(hostIdStr, root.getPath());
    }
}
Also used : CommandLine(org.voltdb.utils.CommandLine) VoltFile(org.voltdb.utils.VoltFile) IOException(java.io.IOException) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File)

Aggregations

File (java.io.File)19 VoltFile (org.voltdb.utils.VoltFile)19 IOException (java.io.IOException)8 FileOutputStream (java.io.FileOutputStream)5 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 JSONException (org.json_voltpatches.JSONException)3 FileWriter (java.io.FileWriter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 SocketException (java.net.SocketException)2 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)2 JSONObject (org.json_voltpatches.JSONObject)2 CatalogMap (org.voltdb.catalog.CatalogMap)2 VoltCompiler (org.voltdb.compiler.VoltCompiler)2 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)2 ImmutableList (com.google_voltpatches.common.collect.ImmutableList)1