Java Code Examples for org.apache.brooklyn.util.os.Os#newTempDir()

The following examples show how to use org.apache.brooklyn.util.os.Os#newTempDir() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractBlueprintTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@BeforeMethod(alwaysRun=true)
public void setUp() throws Exception {
    mementoDir = Os.newTempDir(getClass());
    mgmt = createOrigManagementContext();
    LOG.info("Test "+getClass()+" persisting to "+mementoDir);

    launcher = new SimpleYamlLauncherForTests() {
        @Override
        protected BrooklynCampPlatformLauncherAbstract newPlatformLauncher() {
            return new BrooklynCampPlatformLauncher() {
                @Override
                protected ManagementContext newManagementContext() {
                    return AbstractBlueprintTest.this.mgmt;
                }
            };
        }
    };
    viewer = BrooklynViewerLauncher.newInstance()
            .managementContext(mgmt)
            .start();
}
 
Example 2
Source File: HaMasterCheckFilterTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
private void initHaCluster(HighAvailabilityMode writeMode, HighAvailabilityMode readMode) throws InterruptedException, TimeoutException {
    mementoDir = Os.newTempDir(getClass());

    writeMgmt = createManagementContext(mementoDir, writeMode);
    appId = createApp(writeMgmt);
    writeMgmt.getRebindManager().waitForPendingComplete(TIMEOUT, true);

    if (readMode == HighAvailabilityMode.DISABLED) {
        //no HA, one node only
        readMgmt = writeMgmt;
    } else {
        readMgmt = createManagementContext(mementoDir, readMode);
    }

    server = useServerForTest(baseLauncher()
            .securityProvider(AnyoneSecurityProvider.class)
            .managementContext(readMgmt)
            .forceUseOfDefaultCatalogWithJavaClassPath(true)
            .withoutJsgui()
            .disableHighAvailability(false)
            .start());
    client = getClient(server);
}
 
Example 3
Source File: CompoundTransformerTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected File persist(BrooklynMementoRawData rawData) throws Exception {
    File newMementoDir = Os.newTempDir(getClass());
    
    FileBasedObjectStore objectStore = new FileBasedObjectStore(newMementoDir);
    objectStore.injectManagementContext(origManagementContext);
    objectStore.prepareForSharedUse(PersistMode.CLEAN, HighAvailabilityMode.DISABLED);

    BrooklynMementoPersisterToObjectStore persister = new BrooklynMementoPersisterToObjectStore(
            objectStore, origManagementContext);
    persister.enableWriteAccess();

    PersistenceExceptionHandler exceptionHandler = PersistenceExceptionHandlerImpl.builder().build();
    persister.checkpoint(rawData, exceptionHandler);
    
    LOG.info("Test "+getClass()+" persisted raw data to "+newMementoDir);
    return newMementoDir;
}
 
Example 4
Source File: HighAvailabilityManagerFileBasedTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
protected FileBasedObjectStore newPersistenceObjectStore() {
    if (dir!=null)
        throw new IllegalStateException("Test does not support multiple object stores");
    dir = Os.newTempDir(getClass());
    return new FileBasedObjectStore(dir);
}
 
Example 5
Source File: FileBasedStoreObjectAccessorWriterTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups="Integration")
public void testPutCreatesNewFileAndParentDir() throws Exception {
    File nonExistantDir = Os.newTempDir(getClass());
    nonExistantDir.delete();
    File nonExistantFile = new File(nonExistantDir, "file.txt");
    StoreObjectAccessorLocking accessor = new StoreObjectAccessorLocking(new FileBasedStoreObjectAccessor(nonExistantFile, ".tmp"));
    try {
        accessor.put("abc");
        assertEquals(Files.readLines(nonExistantFile, Charsets.UTF_8), ImmutableList.of("abc"));
    } finally {
        accessor.delete();
    }
}
 
Example 6
Source File: BrooklynMementoPersisterFileBasedTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
protected ManagementContext newPersistingManagementContext() {
    mementoDir = Os.newTempDir(JavaClassNames.cleanSimpleClassName(this));
    Os.deleteOnExitRecursively(mementoDir);
    return RebindTestUtils.managementContextBuilder(classLoader, new FileBasedObjectStore(mementoDir))
        .persistPeriod(Duration.millis(10)).buildStarted();
}
 
Example 7
Source File: SystemTasksTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@BeforeMethod(alwaysRun=true)
public void setup() throws Exception {
    mgmt = new LocalManagementContext();
    
    clearExpectedFailure();
    tempDir = Os.newTempDir(getClass());
}
 
Example 8
Source File: SshTasksTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@BeforeMethod(alwaysRun=true)
public void setup() throws Exception {
    mgmt = new LocalManagementContext();
    
    LocalhostMachineProvisioningLocation lhc = mgmt.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class));
    host = lhc.obtain();
    clearExpectedFailure();
    tempDir = Os.newTempDir(getClass());
}
 
Example 9
Source File: ArchiveBuilderTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 10
Source File: ArchiveUtilsTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 11
Source File: ArchiveUtilsTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@BeforeMethod(alwaysRun=true)
@Override
public void setUp() throws Exception {
    super.setUp();
    machine = app.newLocalhostProvisioningLocation().obtain();
    resourceUtils = ResourceUtils.create(ArchiveUtilsTest.class);
    destDir = Os.newTempDir(getClass().getSimpleName());
}
 
Example 12
Source File: SoftwareProcessDriverCopyResourcesTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@BeforeMethod(alwaysRun = true)
@Override
public void setUp() throws Exception {
    super.setUp();

    sourceFileDir = Os.newTempDir(getClass().getSimpleName());
    sourceTemplateDir = Os.newTempDir(getClass().getSimpleName());

    installDir = Os.newTempDir(getClass().getSimpleName());
    runDir = Os.newTempDir(getClass().getSimpleName());

    location = app.newLocalhostProvisioningLocation();
}
 
Example 13
Source File: CleanOrphanedLocationsIntegrationTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@BeforeMethod(alwaysRun = true)
@Override
public void setUp() throws Exception {
    super.setUp();
    persistenceDirWithOrphanedLocations = copyResourcePathToTempPath(PERSISTED_STATE_PATH_WITH_ORPHANED_LOCATIONS);
    persistenceDirWithoutOrphanedLocations = copyResourcePathToTempPath(PERSISTED_STATE_PATH_WITHOUT_ORPHANED_LOCATIONS);
    persistenceDirWithMultipleLocationsOccurrence = copyResourcePathToTempPath(PERSISTED_STATE_PATH_WITH_MULTIPLE_LOCATIONS_OCCURRENCE);

    destinationDir = Os.newTempDir(getClass());
    
    mgmts = Sets.newLinkedHashSet();
}
 
Example 14
Source File: CleanOrphanedLocationsIntegrationTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private String copyResourcePathToTempPath(String resourcePath) {
    BundleMaker bm = new BundleMaker(ResourceUtils.create(this));
    bm.setDefaultClassForLoading(CleanOrphanedLocationsIntegrationTest.class);
    File jar = bm.createJarFromClasspathDir(resourcePath);
    File output = Os.newTempDir("brooklyn-test-resouce-from-"+resourcePath);
    try {
        ArchiveUtils.extractZip(new ZipFile(jar), output.getAbsolutePath());
        return output.getAbsolutePath();
    } catch (Exception e) {
        throw Exceptions.propagate(e);
    }
}
 
Example 15
Source File: OsTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteRecursivelySubDirs() throws Exception {
    File dir = Os.newTempDir(OsTest.class);
    File subdir = new File(dir, "mysubdir");
    File subfile = new File(subdir, "mysubfile");
    subdir.mkdirs();
    Files.write("abc".getBytes(), subfile);
    
    DeletionResult result = Os.deleteRecursively(dir);
    assertTrue(result.wasSuccessful());
    assertFalse(dir.exists());
}
 
Example 16
Source File: OsTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteRecursivelyEmptyDir() throws Exception {
    File dir = Os.newTempDir(OsTest.class);
    DeletionResult result = Os.deleteRecursively(dir);
    assertTrue(result.wasSuccessful());
    assertFalse(dir.exists());
}
 
Example 17
Source File: RebindTestFixture.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@BeforeMethod(alwaysRun=true)
public void setUp() throws Exception {
    mementoDir = Os.newTempDir(getClass());
    File mementoDirParent = mementoDir.getParentFile();
    mementoDirBackup = new File(mementoDirParent, mementoDir.getName()+"."+Identifiers.makeRandomId(4)+".bak");

    origApp = null;
    newApp = null;
    newManagementContext = null;
    
    origManagementContext = createOrigManagementContext();
    origApp = createApp();
    
    LOG.info("Test "+getClass()+" persisting to "+mementoDir);
}
 
Example 18
Source File: ManagementPlaneIdTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@BeforeMethod
public void setUp() {
    mementoDir = Os.newTempDir(getClass());
    managementContextForTermination = new ArrayList<>();
}
 
Example 19
Source File: OsgiManager.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public void start() {
        if (framework!=null) {
            throw new IllegalStateException("OSGi framework already set in this management context");
        }
        
        try {
            brooklynBundlesCacheDir = Os.newTempDir("brooklyn-osgi-brooklyn-bundles-cache");
            Os.deleteOnExitRecursively(brooklynBundlesCacheDir);
            
            if (mgmt.getConfig().getConfig(REUSE_OSGI)) {
                reuseFramework = true;
                
                synchronized (OSGI_FRAMEWORK_CONTAINERS_FOR_REUSE) {
                    if (!OSGI_FRAMEWORK_CONTAINERS_FOR_REUSE.isEmpty()) {
                        framework = OSGI_FRAMEWORK_CONTAINERS_FOR_REUSE.remove(0);
                    }
                }
                if (framework!=null) {
                    if (!REUSED_FRAMEWORKS_ARE_KEPT_RUNNING) {
                        // don't think we need to do 'init'
//                        framework.init();
                        framework.start();
                    }
                    
                    log.debug("Reusing OSGi framework container from "+framework.getBundleContext().getProperty(Constants.FRAMEWORK_STORAGE)+" for mgmt node "+mgmt.getManagementNodeId());
                    
                    return;
                }
                osgiFrameworkCacheDir = Os.newTempDir("brooklyn-osgi-reusable-container");
                Os.deleteOnExitRecursively(osgiFrameworkCacheDir);
                if (numberOfReusableFrameworksCreated.incrementAndGet()%10==0) {
                    log.warn("Possible leak of reusable OSGi containers ("+numberOfReusableFrameworksCreated+" total)");
                }
                
            } else {
                osgiFrameworkCacheDir = BrooklynServerPaths.getOsgiCacheDirCleanedIfNeeded(mgmt);
            }
            
            // any extra OSGi startup args could go here
            framework = Osgis.getFramework(osgiFrameworkCacheDir.getAbsolutePath(), false);
            log.debug("OSGi framework container created in "+osgiFrameworkCacheDir+" mgmt node "+mgmt.getManagementNodeId()+
                (reuseFramework ? "(reusable, "+numberOfReusableFrameworksCreated.get()+" total)" : "") );
            
        } catch (Exception e) {
            throw Exceptions.propagate(e);
        } finally {
            if (reuseFramework) {
                bundlesAtStartup = MutableSet.copyOf(Arrays.asList(framework.getBundleContext().getBundles()));
            }
        }
    }
 
Example 20
Source File: EmbeddedFelixFrameworkTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception {
    storageTempDir = Os.newTempDir("osgi-standalone");
    framework = EmbeddedFelixFramework.newFrameworkStarted(storageTempDir.getAbsolutePath(), true, null);
}