@Test public void manipulateAppConfig() throws FileStoreException { AppConfig appConfig = fileStore.getAppConfig(); Assert.assertTrue("should be no access key", appConfig.getAccessKey().isEmpty()); appConfig.setAccessKey("gumby"); fileStore.setAppConfig(appConfig); appConfig = fileStore.getAppConfig(); Assert.assertEquals("Should have saved access key", "gumby", appConfig.getAccessKey()); }
public NodePath(Path path, Environment environment) throws IOException { this.path = path; this.indicesPath = path.resolve(INDICES_FOLDER); this.fileStore = environment.getFileStore(path); if (fileStore.supportsFileAttributeView("lucene")) { this.spins = (Boolean) fileStore.getAttribute("lucene:spins"); } else { this.spins = null; } }
private ArrayList<Path> holeLaufwerkeUnix() { ArrayList<Path> laufwerksRoot = new ArrayList<>(); for (FileStore store : FileSystems.getDefault().getFileStores()) { if (store.name().contains("/dev/sd")) { laufwerksRoot.add( Paths.get(store.toString().substring(0, store.toString().indexOf(' ')))); } } return laufwerksRoot; }
static void printFileStore(FileStore store) throws IOException { String total = format(store.getTotalSpace()); String used = format(store.getTotalSpace() - store.getUnallocatedSpace()); String avail = format(store.getUsableSpace()); String s = store.toString(); if (s.length() > 20) { System.out.println(s); s = ""; } System.out.format("%-20s %12s %12s %12s\n", s, total, used, avail); }
public static void main(String[] args) throws IOException { PersistenceObjectModel.register(); FileStore store = new FileStore(JdbmTest.FILE); @SuppressWarnings("unchecked") final TMap<String, TSet<PersistenceClass>> map = (TMap) store.getRoot(); Transaction.setDefaultTrunk(map.getTrunk()); Assert.assertEquals(COUNT + 1, map.size()); Transaction.run( new Runnable() { public void run() { for (int i = 0; i < COUNT + 1; i++) { TSet<PersistenceClass> set = map.get("set" + i); Assert.assertEquals(1, set.size()); for (PersistenceClass current : set) Assert.assertTrue(current.getInt() == i); } } }); if (Stats.ENABLED) { // 2 for log file initialization Assert.assertEquals(2, Stats.getInstance().FileTotalWritten.get()); } TSet<PersistenceClass> set = new TSet<PersistenceClass>(); PersistenceClass object = new PersistenceClass(); object.setInt(COUNT + 1); set.add(object); map.put("set" + (COUNT + 1), set); store.flush(); Log.write("Inserted 1 more set."); if (Stats.ENABLED) { Assert.assertTrue( Stats.getInstance().FileTotalWritten.get() < Stats.getInstance().FileTotalRead.get() / 10); Stats.getInstance().writeAndReset(); } store.close(); PlatformAdapter.shutdown(); }
@RequestMapping(value = "/{id:.+}", method = GET) public void getFile(@PathVariable("id") String id, HttpServletResponse response) throws IOException { FileMeta fileMeta = dataService.findOne(FileMeta.ENTITY_NAME, id, FileMeta.class); if (fileMeta == null) { response.setStatus(HttpStatus.NOT_FOUND.value()); } else { java.io.File fileStoreFile = fileStore.getFile(fileMeta.getFilename()); // if file meta data exists for this file String outputFilename = fileMeta.getFilename(); String contentType = fileMeta.getContentType(); if (contentType != null) { response.setContentType(contentType); } Long size = fileMeta.getSize(); if (size != null) { response.setContentLength(size.intValue()); } response.setHeader( "Content-Disposition", "attachment; filename=" + outputFilename.replace(" ", "_")); InputStream is = new FileInputStream(fileStoreFile); try { FileCopyUtils.copy(is, response.getOutputStream()); } finally { is.close(); } } }
public void doit(String archiveFilename) { f.clear(); try { tar = new TarInputStream(new GZIPInputStream(new FileInputStream(archiveFilename))); while ((current = tar.getNextEntry()) != null) { System.err.println("ok:" + current.getName()); long s = current.getSize(); if (!current.isDirectory()) { // System.err.println(current.getFile()); f.prepareForBulkInsert(tar, current.getName()); } } } catch (Exception e) { e.printStackTrace(); } f.flushFiles(); }
public void startup() { boolean isnew = !getFile().exists(); super.startup(); if (isnew) initializeFile(); else { int totalmapsize = 1 + smallEntriesCount + hashTableSize; try { sizeMap = write(0, 8 * totalmapsize); } catch (Throwable t) { throw new HGException(t); } } }
public static void main(String[] args) throws IOException { PersistenceObjectModel.register(); FileStore store = new FileStore(JdbmTest.FILE); @SuppressWarnings("unchecked") final TMap<String, TSet<PersistenceClass>> map = (TMap) store.getRoot(); Transaction.setDefaultTrunk(map.getTrunk()); Assert.assertEquals(COUNT + 2, map.size()); for (int i = 0; i < COUNT + 2; i++) { final TSet<PersistenceClass> set = map.get("set" + i); Assert.assertEquals(1, set.size()); final int i_ = i; Transaction.run( new Runnable() { public void run() { for (PersistenceClass current : set) Assert.assertTrue(current.getInt() == i_); } }); } Log.write("Reopened and read all."); if (Stats.ENABLED) { // 2 for log file initialization Assert.assertEquals(2, Stats.getInstance().FileTotalWritten.get()); Stats.getInstance().writeAndReset(); } store.close(); PlatformAdapter.shutdown(); }
@Test public void createDelete() throws IOException, FileStoreException { FileStore.DataSetStore store = mock.getDataSetStore(); Assert.assertEquals("Should be no files", 0, mock.getSpecDirectory().listFiles().length); Assert.assertFalse(store.hasSource()); store.importFile(MockFileStoreInput.sampleFile(), null); Assert.assertTrue(store.hasSource()); Assert.assertEquals("Should be one file", 1, mock.getDirectory().listFiles().length); Assert.assertEquals("Should be one spec", 1, fileStore.getDataSetStores().size()); Assert.assertEquals("Should be one file", 1, mock.getSpecDirectory().listFiles().length); log.info("Created " + mock.getSpecDirectory().listFiles()[0].getAbsolutePath()); InputStream inputStream = MockFileStoreInput.sampleInputStream(); InputStream storedStream = mock.getDataSetStore().createXmlInputStream(); int input = 0, stored; while (input != -1) { input = inputStream.read(); stored = storedStream.read(); Assert.assertEquals("Stream discrepancy", input, stored); } store.delete(); Assert.assertEquals("Should be zero files", 0, mock.getDirectory().listFiles().length); }
public void shutdown() { super.shutdown(); }
public static void main(String[] args) throws IOException { PersistenceObjectModel.register(); OF.setConfig( new Config() { @Override public AutoCommitPolicy getAutoCommitPolicy() { return AutoCommitPolicy.DELAYED_MANUAL; } }); FileStore store = new FileStore(JdbmTest.FILE); Transaction trunk = Site.getLocal().createTrunk(store); Transaction.setDefaultTrunk(trunk); TMap<String, TSet<PersistenceClass>> map = new TMap<String, TSet<PersistenceClass>>(); ArrayList<TSet<PersistenceClass>> list = new ArrayList<TSet<PersistenceClass>>(); for (int i = 0; i < COUNT; i++) { TSet<PersistenceClass> set = new TSet<PersistenceClass>(); list.add(set); map.put("set" + i, set); PersistenceClass object = new PersistenceClass(); object.setInt(i); set.add(object); } Assert.assertNull(store.getRoot()); store.setRoot(map); OF.update(); Assert.assertEquals(COUNT, map.size()); Log.write("Inserted " + COUNT + " sets."); long mainWriteLength = 0; if (Stats.ENABLED) { mainWriteLength = Stats.getInstance().FileTotalWritten.get(); Stats.getInstance().writeAndReset(); } TSet<PersistenceClass> set = new TSet<PersistenceClass>(); PersistenceClass object = new PersistenceClass(); object.setInt(COUNT); set.add(object); map.put("set" + list.size(), set); OF.update(); Log.write("Inserted 1 more set."); if (Stats.ENABLED) Assert.assertTrue(Stats.getInstance().FileTotalWritten.get() < mainWriteLength / 10); store.close(); if (Stats.ENABLED) Stats.getInstance().reset(); // Re open FileStore store2 = new FileStore(JdbmTest.FILE); @SuppressWarnings("unchecked") TMap<String, TSet<PersistenceClass>> map2 = (TMap) store2.getRoot(); Assert.assertTrue(map2 == map); for (int i = 0; i < COUNT; i++) { TSet<PersistenceClass> set2 = map.get("set" + i); Assert.assertTrue(set2 == list.get(i)); Assert.assertEquals(1, set2.size()); for (PersistenceClass current : set2) Assert.assertTrue(current.getInt() == i); } Log.write("Reopened and read all."); store2.close(); if (Stats.ENABLED) { // 4 for 2 log file initializations Assert.assertEquals(4, Stats.getInstance().FileTotalWritten.get()); Stats.getInstance().writeAndReset(); } PlatformAdapter.shutdown(); }
/** * Run the Grinder agent process. * * @throws GrinderException If an error occurs. */ public void run() throws GrinderException { StartGrinderMessage startMessage = null; ConsoleCommunication consoleCommunication = null; try { while (true) { m_logger.info(GrinderBuild.getName()); ScriptLocation script = null; GrinderProperties properties; do { properties = createAndMergeProperties(startMessage != null ? startMessage.getProperties() : null); m_agentIdentity.setName(properties.getProperty("grinder.hostID", getHostName())); final Connector connector = properties.getBoolean("grinder.useConsole", true) ? m_connectorFactory.create(properties) : null; // We only reconnect if the connection details have changed. if (consoleCommunication != null && !consoleCommunication.getConnector().equals(connector)) { shutdownConsoleCommunication(consoleCommunication); consoleCommunication = null; // Accept any startMessage from previous console - see bug 2092881. } if (consoleCommunication == null && connector != null) { try { consoleCommunication = new ConsoleCommunication(connector); consoleCommunication.start(); m_logger.info("connected to console at {}", connector.getEndpointAsString()); } catch (CommunicationException e) { if (m_proceedWithoutConsole) { m_logger.warn( "{}, proceeding without the console; set " + "grinder.useConsole=false to disable this warning.", e.getMessage()); } else { m_logger.error(e.getMessage()); return; } } } if (consoleCommunication != null && startMessage == null) { m_logger.info("waiting for console signal"); m_consoleListener.waitForMessage(); if (m_consoleListener.received(ConsoleListener.START)) { startMessage = m_consoleListener.getLastStartGrinderMessage(); continue; // Loop to handle new properties. } else { break; // Another message, check at end of outer while loop. } } if (startMessage != null) { final GrinderProperties messageProperties = startMessage.getProperties(); final Directory fileStoreDirectory = m_fileStore.getDirectory(); // Convert relative path to absolute path. messageProperties.setAssociatedFile( fileStoreDirectory.getFile(messageProperties.getAssociatedFile())); final File consoleScript = messageProperties.resolveRelativeFile( messageProperties.getFile( GrinderProperties.SCRIPT, GrinderProperties.DEFAULT_SCRIPT)); // We only fall back to the agent properties if the start message // doesn't specify a script and there is no default script. if (messageProperties.containsKey(GrinderProperties.SCRIPT) || consoleScript.canRead()) { // The script directory may not be the file's direct parent. script = new ScriptLocation(fileStoreDirectory, consoleScript); } m_agentIdentity.setNumber(startMessage.getAgentNumber()); } else { m_agentIdentity.setNumber(-1); } if (script == null) { final File scriptFile = properties.resolveRelativeFile( properties.getFile(GrinderProperties.SCRIPT, GrinderProperties.DEFAULT_SCRIPT)); script = new ScriptLocation(scriptFile); } if (!script.getFile().canRead()) { m_logger.error("The script file '" + script + "' does not exist or is not readable."); script = null; break; } } while (script == null); if (script != null) { final String jvmArguments = properties.getProperty("grinder.jvm.arguments"); final WorkerFactory workerFactory; if (!properties.getBoolean("grinder.debug.singleprocess", false)) { final WorkerProcessCommandLine workerCommandLine = new WorkerProcessCommandLine( properties, System.getProperties(), jvmArguments, script.getDirectory()); m_logger.info("Worker process command line: {}", workerCommandLine); workerFactory = new ProcessWorkerFactory( workerCommandLine, m_agentIdentity, m_fanOutStreamSender, consoleCommunication != null, script, properties); } else { m_logger.info("DEBUG MODE: Spawning threads rather than processes"); if (jvmArguments != null) { m_logger.warn( "grinder.jvm.arguments ({}) ignored in single process mode", jvmArguments); } workerFactory = new DebugThreadWorkerFactory( m_agentIdentity, m_fanOutStreamSender, consoleCommunication != null, script, properties); } final WorkerLauncher workerLauncher = new WorkerLauncher( properties.getInt("grinder.processes", 1), workerFactory, m_eventSynchronisation, m_logger); final int increment = properties.getInt("grinder.processIncrement", 0); if (increment > 0) { final boolean moreProcessesToStart = workerLauncher.startSomeWorkers( properties.getInt("grinder.initialProcesses", increment)); if (moreProcessesToStart) { final int incrementInterval = properties.getInt("grinder.processIncrementInterval", 60000); final RampUpTimerTask rampUpTimerTask = new RampUpTimerTask(workerLauncher, increment); m_timer.scheduleAtFixedRate(rampUpTimerTask, incrementInterval, incrementInterval); } } else { workerLauncher.startAllWorkers(); } // Wait for a termination event. synchronized (m_eventSynchronisation) { final long maximumShutdownTime = 20000; long consoleSignalTime = -1; while (!workerLauncher.allFinished()) { if (consoleSignalTime == -1 && m_consoleListener.checkForMessage( ConsoleListener.ANY ^ ConsoleListener.START)) { workerLauncher.dontStartAnyMore(); consoleSignalTime = System.currentTimeMillis(); } if (consoleSignalTime >= 0 && System.currentTimeMillis() - consoleSignalTime > maximumShutdownTime) { m_logger.info("forcibly terminating unresponsive processes"); // destroyAllWorkers() prevents further workers from starting. workerLauncher.destroyAllWorkers(); } m_eventSynchronisation.waitNoInterrruptException(maximumShutdownTime); } } workerLauncher.shutdown(); } if (consoleCommunication == null) { break; } else { // Ignore any pending start messages. m_consoleListener.discardMessages(ConsoleListener.START); if (!m_consoleListener.received(ConsoleListener.ANY)) { // We've got here naturally, without a console signal. m_logger.info("finished, waiting for console signal"); m_consoleListener.waitForMessage(); } if (m_consoleListener.received(ConsoleListener.START)) { startMessage = m_consoleListener.getLastStartGrinderMessage(); } else if (m_consoleListener.received(ConsoleListener.STOP | ConsoleListener.SHUTDOWN)) { break; } else { // ConsoleListener.RESET or natural death. startMessage = null; } } } } finally { shutdownConsoleCommunication(consoleCommunication); } }
private void populateRegistryIfEmpty(FileStore fileStore, String name) { if (fileStore.getPathCount() == 0) { logger.info("Populating {} Store Path Registry.", name); fileStore.populateRegistry(); } }