public Builder resetGlobalFiles() { defaultLocationMetadataUrl = "classpath://brooklyn/location-metadata.properties"; globalLocationMetadataFile = Os.mergePaths(Os.home(), ".brooklyn", "location-metadata.properties"); globalPropertiesFile = Os.mergePaths(Os.home(), ".brooklyn", "brooklyn.properties"); return this; }
public static void deleteCompletely(File d) { DeletionResult result = Os.deleteRecursively(d); if (!result.wasSuccessful()) log.warn("Unable to delete persistence dir "+d); } }
public ToolAbstractAsyncExecScript(Map<String,?> props) { super(props); stdoutPath = Os.mergePathsUnix(scriptDir, scriptNameWithoutExtension + ".stdout"); stderrPath = Os.mergePathsUnix(scriptDir, scriptNameWithoutExtension + ".stderr"); exitStatusPath = Os.mergePathsUnix(scriptDir, scriptNameWithoutExtension + ".exitstatus"); pidPath = Os.mergePathsUnix(scriptDir, scriptNameWithoutExtension + ".pid"); }
/** like {@link #deleteOnExitRecursively(File)} followed by {@link #deleteOnExitEmptyParentsUpTo(File, File)} */ public static void deleteOnExitRecursivelyAndEmptyParentsUpTo(File directoryToCleanOrFile, File highestAncestorToDelete) { deleteOnExitRecursively(directoryToCleanOrFile); deleteOnExitEmptyParentsUpTo(directoryToCleanOrFile, highestAncestorToDelete); }
@Inject public Alien4CloudFacade(ICSARRepositorySearchService repositorySearchService, TopologyTreeBuilderService treeBuilder, ICsarRepositry csarFileRepository, TopologyServiceCore topologyService, TopologyTemplateVersionService topologyTemplateVersionService, DeploymentTopologyService deploymentTopologyService, ApplicationService applicationService) { this.repositorySearchService = repositorySearchService; this.treeBuilder = treeBuilder; this.csarFileRepository = csarFileRepository; this.topologyService = topologyService; this.topologyTemplateVersionService = topologyTemplateVersionService; this.deploymentTopologyService = deploymentTopologyService; this.applicationService = applicationService; tmpRoot = Os.newTempDir("brooklyn-a4c"); Os.deleteOnExitRecursively(tmpRoot); }
@Test(groups = "Integration") public void testStartsInDifferentRunAndInstallSpecifiedDirectories() throws Exception { String dir1 = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4)); String dir2 = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4)); app.config().set(BrooklynConfigKeys.INSTALL_DIR, dir1); app.config().set(BrooklynConfigKeys.RUN_DIR, dir2); doTestSpecifiedDirectory(dir1, dir2); Os.deleteRecursively(dir1); Os.deleteRecursively(dir2); }
private void assertSubFilesEqual(File parentDir, Map<String, String> files) throws Exception { for (Map.Entry<String, String> entry : archiveContents.entrySet()) { File subFile = new File(Os.mergePaths(parentDir.getAbsolutePath(), entry.getKey())); assertEquals(Joiner.on("\n").join(Files.readLines(subFile, Charsets.UTF_8)), entry.getValue()); } } }
/** @deprecated since 0.7.0; use method {@link Os#tidyPath(String)} */ @Deprecated public static String tidyFilePath(String path) { return Os.tidyPath(path); }
@Test public void testDeleteRecursivelyNonExistantDir() throws Exception { DeletionResult result = Os.deleteRecursively(Os.mergePaths(Os.tmp(), Identifiers.makeRandomId(8))); assertTrue(result.wasSuccessful()); }
@Test public void testDeleteRecursivelyEmptyDir() throws Exception { File dir = Os.newTempDir(OsTest.class); DeletionResult result = Os.deleteRecursively(dir); assertTrue(result.wasSuccessful()); assertFalse(dir.exists()); }
private File newZip(Map<String, String> files) throws Exception { File parentDir = Os.newTempDir(getClass().getSimpleName()+"-archive"); for (Map.Entry<String, String> entry : files.entrySet()) { File subFile = new File(Os.mergePaths(parentDir.getAbsolutePath(), entry.getKey())); subFile.getParentFile().mkdirs(); Files.write(entry.getValue(), subFile, Charsets.UTF_8); } return ArchiveBuilder.zip().addDirContentsAt(parentDir, ".").create(); }
@Test(groups = {"Integration"}) public void testOutputAsExpected() throws Exception { final String CONTENTS = "hello world\n" + "bye bye\n"; execCommands("cat > "+Os.mergePaths(Os.tmp(), "test1")+" << X\n" + CONTENTS + "X\n"); String read = execCommands("echo START_FOO", "cat "+Os.mergePaths(Os.tmp(), "test1"), "echo END_FOO"); log.debug("read back data written, as:\n"+read); String contents = Strings.getFragmentBetween(read, "START_FOO", "END_FOO"); Assert.assertEquals(CONTENTS.trim(), contents.trim()); }
@BeforeMethod public void setUp() { mementoDir = Os.newTempDir(getClass()); managementContextForTermination = new ArrayList<>(); }
/** as {@link #newTempFile(String, String)} using the class as the basis for a prefix */ public static File newTempFile(Class<?> clazz, String ext) { return newTempFile(JavaClassNames.cleanSimpleClassName(clazz), ext); }
@Test(groups = "Integration") public void testStartsInAppSpecifiedDirectoryUnderHome() throws Exception { String dir = Os.mergePathsUnix("~/.brooklyn-test-"+Strings.makeRandomId(4)); try { app.config().set(BrooklynConfigKeys.ONBOX_BASE_DIR, dir); doTestSpecifiedDirectory(dir, dir); } finally { Os.deleteRecursively(dir); } }
/** allow the temp dir where ssh temporary files on the brooklyn server side are placed */ public static void setLocalTempDir(Map<String,?> source, ConfigBag target) { // TODO better would be to use BrooklynServerConfig, requiring management passed in String brooklynDataDir = (String) source.get(BrooklynServerConfig.getMgmtBaseDir(source)); if (brooklynDataDir != null && brooklynDataDir.length() > 0) { String tempDir = Os.mergePaths(brooklynDataDir, "tmp", "ssh"); target.putIfAbsentAndNotNull(SshTool.PROP_LOCAL_TEMP_DIR, tempDir); Os.deleteOnExitEmptyParentsUpTo(new File(tempDir), new File(brooklynDataDir)); } }
@Test public void testInstallDirAndRunDirUsingTilde() throws Exception { String dataDirName = ".brooklyn-foo"+Strings.makeRandomId(4); String dataDir = "~/"+dataDirName; String resolvedDataDir = Os.mergePaths(Os.home(), dataDirName); MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class) .configure(BrooklynConfigKeys.ONBOX_BASE_DIR, dataDir)); entity.start(ImmutableList.of(loc)); Assert.assertEquals(Os.nativePath(entity.getAttribute(SoftwareProcess.INSTALL_DIR)), Os.nativePath(Os.mergePaths(resolvedDataDir, "installs/MyService"))); Assert.assertEquals(Os.nativePath(entity.getAttribute(SoftwareProcess.RUN_DIR)), Os.nativePath(Os.mergePaths(resolvedDataDir, "apps/"+entity.getApplicationId()+"/entities/MyService_"+entity.getId()))); }
@BeforeClass public void createTmpDirAndFiles() throws IOException { parentDir = Os.newTempDir(getClass().getSimpleName()); Os.deleteOnExitRecursively(parentDir); tmpDir = new File(parentDir, Identifiers.makeRandomId(4)); Os.mkdirs(tmpDir); Files.write("abcdef", new File(tmpDir, "data01.txt"), Charsets.US_ASCII); Files.write("123456", new File(tmpDir, "data02.txt"), Charsets.US_ASCII); Files.write("qqqqqq", new File(tmpDir, "data03.txt"), Charsets.US_ASCII); tmpDir2 = new File(parentDir, Identifiers.makeRandomId(4)); Os.mkdirs(tmpDir2); Files.write("zzzzzz", new File(tmpDir2, "data04.txt"), Charsets.US_ASCII); }
public static File getOsgiCacheDirCleanedIfNeeded(ManagementContext mgmt) { File cacheDirF = getOsgiCacheDir(mgmt); boolean clean = isOsgiCacheForCleaning(mgmt, cacheDirF); log.debug("OSGi cache dir computed as "+cacheDirF.getAbsolutePath()+" ("+ (cacheDirF.exists() ? "already exists" : "does not exist")+", "+ (clean ? "cleaning now (and on exit)" : "cleaning not requested")); if (clean) { Os.deleteRecursively(cacheDirF); Os.deleteOnExitRecursively(cacheDirF); } return cacheDirF; }
/** @deprecated since 0.7.0; use same method in {@link Os} */ @Deprecated public static File writeToTempFile(InputStream is, String prefix, String suffix) { return Os.writeToTempFile(is, prefix, suffix); }