Example usage for org.apache.commons.io FileUtils openOutputStream

List of usage examples for org.apache.commons.io FileUtils openOutputStream

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils openOutputStream.

Prototype

public static FileOutputStream openOutputStream(File file) throws IOException 

Source Link

Document

Opens a FileOutputStream for the specified file, checking and creating the parent directory if it does not exist.

Usage

From source file:org.apache.hadoop.yarn.server.nodemanager.util.TestCgroupsLCEResourcesHandlerGPU.java

@Test
public void testSubsetGPUsSchedulable() throws IOException {
    LinuxContainerExecutor mockLCE = new MockLinuxContainerExecutor();
    CustomCgroupsLCEResourceHandlerGPU handler = new CustomCgroupsLCEResourceHandlerGPU();
    YarnConfiguration conf = new YarnConfiguration();
    conf.setBoolean(YarnConfiguration.NM_GPU_RESOURCE_ENABLED, true);
    final int numGPUs = 6;
    ResourceCalculatorPlugin plugin = Mockito.mock(ResourceCalculatorPlugin.class);
    Mockito.doReturn(numGPUs).when(plugin).getNumGPUs();
    handler.setConf(conf);/*from  w w w .  ja  v  a 2  s .com*/
    handler.initConfig();

    // create mock cgroup
    File cgroupMountDirCPU = createMockCgroupMount(cgroupDir, "cpu");
    File cgroupMountDirGPU = createMockCgroupMount(cgroupDir, "devices");
    File whiteList = new File(cgroupMountDirGPU, "devices.list");
    FileOutputStream fos1 = FileUtils.openOutputStream(whiteList);
    fos1.write(("a *:* rwm\n").getBytes());

    // create mock mtab
    File mockMtab = createMockMTab(cgroupDir);

    ContainerId id = ContainerId.fromString("container_1_1_1_1");
    GPUAllocator gpuAllocator = null;

    conf.setInt(YarnConfiguration.NM_GPUS, 6);

    gpuAllocator = new GPUAllocator(new CustomGPUmanagementLibrarySubset(), conf);

    Device gpu0 = new Device(195, 0);
    Device gpu1 = new Device(195, 1);
    Device gpu2 = new Device(195, 2);
    Device gpu3 = new Device(195, 3);
    Device gpu4 = new Device(195, 4);
    Device gpu5 = new Device(195, 5);

    // setup our handler and call init()
    handler.setGPUAllocator(gpuAllocator);
    handler.setMtabFile(mockMtab.getAbsolutePath());
    handler.init(mockLCE, plugin);
    File containerDirGPU = new File(cgroupMountDirGPU, id.toString());
    File denyFile = new File(containerDirGPU, "devices.deny");
    Assert.assertFalse(denyFile.exists());
    //FIRST ALLOCATION
    handler.preExecute(id, Resource.newInstance(1024, 1, 2));
    Assert.assertTrue(containerDirGPU.exists());
    Assert.assertTrue(containerDirGPU.isDirectory());
    Assert.assertTrue(denyFile.exists());

    Assert.assertTrue(gpuAllocator.getConfiguredAvailableGPUs().size() == 4);
    //SECOND ALLOCATION
    HashSet<Device> deviceAllocation1 = gpuAllocator.allocate("test_container", 2);

    HashSet<Device> deniedDevices1 = deviceAllocation1;
    //gpu0 and gpu1 already allocated
    Assert.assertTrue(deniedDevices1.contains(gpu0));
    Assert.assertTrue(deniedDevices1.contains(gpu1));
    Assert.assertFalse(deniedDevices1.contains(gpu2));
    Assert.assertFalse(deniedDevices1.contains(gpu3));
    Assert.assertTrue(deniedDevices1.contains(gpu4));
    Assert.assertTrue(deniedDevices1.contains(gpu5));

    handler.postExecute(id);

    HashSet<Device> deviceAllocation2 = gpuAllocator.allocate("test_container2", 2);

    HashSet<Device> deniedDevices2 = deviceAllocation2;
    Assert.assertFalse(deniedDevices2.contains(gpu0)); //allocated in first call
    Assert.assertFalse(deniedDevices2.contains(gpu1));
    Assert.assertTrue(deniedDevices2.contains(gpu2));
    Assert.assertTrue(deniedDevices2.contains(gpu3));
    Assert.assertTrue(deniedDevices2.contains(gpu4));
    Assert.assertTrue(deniedDevices2.contains(gpu5));

    FileUtils.deleteQuietly(cgroupDir);
}

From source file:org.apache.hadoop.yarn.server.nodemanager.util.TestCgroupsLCEResourcesHandlerGPU.java

@Test
public void testContainerRecovery() throws IOException {
    System.out.println("test");
    LinuxContainerExecutor mockLCE = new MockLinuxContainerExecutor();
    CustomCgroupsLCEResourceHandlerGPU handler = new CustomCgroupsLCEResourceHandlerGPU();
    YarnConfiguration conf = new YarnConfiguration();
    final int numGPUs = 8;
    ResourceCalculatorPlugin plugin = Mockito.mock(ResourceCalculatorPlugin.class);
    Mockito.doReturn(numGPUs).when(plugin).getNumGPUs();
    handler.setConf(conf);/*from   w  w w.j  a va2s .c  o  m*/
    handler.initConfig();
    System.out.println("test2");
    // create mock cgroup
    File cgroupMountDirCPU = createMockCgroupMount(cgroupDir, "cpu");
    File cgroupMountDirGPU = createMockCgroupMount(cgroupDir, "devices");
    File whiteList = new File(cgroupMountDirGPU, "devices.list");
    FileOutputStream outputStream = FileUtils.openOutputStream(whiteList);
    outputStream.write(("a *:* rwm\n").getBytes());
    System.out.println("test3");
    // create mock mtab
    File mockMtab = createMockMTab(cgroupDir);
    handler.setMtabFile(mockMtab.getAbsolutePath());

    conf.setInt(YarnConfiguration.NM_GPUS, 8);
    System.out.println("test4");
    GPUAllocator gpuAllocator = new GPUAllocator(new CustomGPUmanagementLibrary(), conf);

    System.out.println("test5");

    handler.setGPUAllocator(gpuAllocator);
    handler.init(mockLCE, plugin);

    ContainerId id1 = ContainerId.fromString("container_1_1_1_1");
    handler.preExecute(id1, Resource.newInstance(1024, 1, 2));
    File containerDir1 = new File(cgroupMountDirGPU, id1.toString());
    File listFile1 = new File(containerDir1, "devices.list");
    FileOutputStream fos1 = FileUtils.openOutputStream(listFile1);
    fos1.write(("c 195:0 rwm\n" + "c 195:1 rwm\n").getBytes());

    File tasksFile1 = new File(containerDir1, "tasks");
    FileOutputStream tasks1 = FileUtils.openOutputStream(tasksFile1);
    tasks1.write(("12934").getBytes());

    ContainerId id2 = ContainerId.fromString("container_1_1_1_2");
    handler.preExecute(id2, Resource.newInstance(1024, 1, 2));
    File containerDir2 = new File(cgroupMountDirGPU, id2.toString());
    File listFile2 = new File(containerDir2, "devices.list");
    FileOutputStream fos2 = FileUtils.openOutputStream(listFile2);
    fos2.write(("c 195:2 rwm\n" + "c 195:3 rwm\n").getBytes());

    File tasksFile2 = new File(containerDir2, "tasks");
    FileOutputStream tasks2 = FileUtils.openOutputStream(tasksFile2);
    tasks2.write(("12934").getBytes());

    ContainerId id3 = ContainerId.fromString("container_1_1_1_3");
    handler.preExecute(id3, Resource.newInstance(1024, 1, 2));
    File containerDir3 = new File(cgroupMountDirGPU, id3.toString());
    File listFile3 = new File(containerDir3, "devices.list");
    FileOutputStream fos3 = FileUtils.openOutputStream(listFile3);
    fos3.write(("c 195:4 rwm\n" + "c 195:5 rwm\n").getBytes());

    File tasksFile3 = new File(containerDir3, "tasks");
    FileOutputStream tasks3 = FileUtils.openOutputStream(tasksFile3);
    tasks3.write(("12934").getBytes());

    conf.setInt(YarnConfiguration.NM_GPUS, 8);
    gpuAllocator = new GPUAllocator(new CustomGPUmanagementLibrary(), conf);
    gpuAllocator.initialize(conf);
    handler = new CustomCgroupsLCEResourceHandlerGPU();
    conf = new YarnConfiguration();
    conf.setBoolean(YarnConfiguration.NM_GPU_RESOURCE_ENABLED, true);
    plugin = Mockito.mock(ResourceCalculatorPlugin.class);
    Mockito.doReturn(numGPUs).when(plugin).getNumGPUs();
    handler.setConf(conf);
    handler.initConfig();

    handler.setMtabFile(mockMtab.getAbsolutePath());
    handler.setGPUAllocator(gpuAllocator);
    handler.init(mockLCE, plugin);

    //No recovery yet
    Assert.assertEquals(8, gpuAllocator.getConfiguredAvailableGPUs().size());
    Assert.assertTrue(listFile1.exists());
    handler.recoverDeviceControlSystem(id1);
    Assert.assertEquals(6, gpuAllocator.getConfiguredAvailableGPUs().size());
    Assert.assertTrue(listFile2.exists());
    handler.recoverDeviceControlSystem(id2);
    Assert.assertEquals(4, gpuAllocator.getConfiguredAvailableGPUs().size());
    Assert.assertTrue(listFile3.exists());
    handler.recoverDeviceControlSystem(id3);
    Assert.assertEquals(2, gpuAllocator.getConfiguredAvailableGPUs().size());
    HashSet<Device> availableGPUs = new HashSet<>(gpuAllocator.getConfiguredAvailableGPUs());
    Assert.assertTrue(availableGPUs.contains(new Device(195, 6)));
    Assert.assertTrue(availableGPUs.contains(new Device(195, 7)));

    FileUtils.deleteQuietly(cgroupDir);
}

From source file:org.apache.hadoop.yarn.server.nodemanager.util.TestCgroupsLCEResourcesHandlerNVIDIAGPU.java

@Test
public void testContainerGPUAllocation() throws IOException {
    LinuxContainerExecutor mockLCE = new MockLinuxContainerExecutor();
    CustomCgroupsLCEResourceHandlerGPU handler = new CustomCgroupsLCEResourceHandlerGPU();
    YarnConfiguration conf = new YarnConfiguration();
    conf.setBoolean(YarnConfiguration.NM_GPU_RESOURCE_ENABLED, true);
    final int numGPUs = 8;
    ResourceCalculatorPlugin plugin = Mockito.mock(ResourceCalculatorPlugin.class);
    handler.setConf(conf);/*from w ww  .  java2  s. co  m*/
    handler.initConfig();

    // create mock cgroup
    File cgroupMountDirCPU = createMockCgroupMount(cgroupDir, "cpu");
    File cgroupMountDirGPU = createMockCgroupMount(cgroupDir, "devices");
    File whiteList = new File(cgroupMountDirGPU, "devices.list");
    FileOutputStream fos1 = FileUtils.openOutputStream(whiteList);
    fos1.write(("a *:* rwm\n").getBytes());

    // create mock mtab
    File mockMtab = createMockMTab(cgroupDir);

    ContainerId id = ContainerId.fromString("container_1_1_1_1");
    GPUAllocator gpuAllocator = null;

    conf.setInt(YarnConfiguration.NM_GPUS, numGPUs);

    gpuAllocator = new GPUAllocator(new CustomGPUmanagementLibrary(), conf);

    GPU gpu0 = new GPU(new Device(195, 0), null);
    GPU gpu1 = new GPU(new Device(195, 1), null);
    GPU gpu2 = new GPU(new Device(195, 2), null);
    GPU gpu3 = new GPU(new Device(195, 3), null);
    GPU gpu4 = new GPU(new Device(195, 4), null);
    GPU gpu5 = new GPU(new Device(195, 5), null);
    GPU gpu6 = new GPU(new Device(195, 6), null);
    GPU gpu7 = new GPU(new Device(195, 7), null);

    // setup our handler and call init()
    handler.setGPUAllocator(gpuAllocator);
    handler.setMtabFile(mockMtab.getAbsolutePath());
    handler.init(mockLCE, plugin);
    File containerDirGPU = new File(cgroupMountDirGPU, id.toString());
    File denyFile = new File(containerDirGPU, "devices.deny");
    Assert.assertFalse(denyFile.exists());

    HashMap<String, HashSet<GPU>> allocations = gpuAllocator.getAllocations();
    Assert.assertEquals(0, allocations.size());

    //FIRST ALLOCATION
    handler.preExecute(id, Resource.newInstance(1024, 1, 2));
    Assert.assertTrue(containerDirGPU.exists());
    Assert.assertTrue(containerDirGPU.isDirectory());
    Assert.assertTrue(denyFile.exists());

    allocations = gpuAllocator.getAllocations();
    Assert.assertEquals(1, allocations.size());

    Assert.assertTrue(gpuAllocator.getConfiguredAvailableGPUs().size() == 6);
    //SECOND ALLOCATION
    HashSet<GPU> deviceAllocation1 = gpuAllocator.allocate("test_container", 2);

    allocations = gpuAllocator.getAllocations();
    Assert.assertEquals(2, allocations.size());
    Assert.assertEquals(2, allocations.get("test_container").size());
    Assert.assertTrue(allocations.get("test_container").contains(gpu2));
    Assert.assertTrue(allocations.get("test_container").contains(gpu3));

    HashSet<GPU> deniedDevices1 = deviceAllocation1;

    Assert.assertTrue(deniedDevices1.contains(gpu0));
    Assert.assertTrue(deniedDevices1.contains(gpu1));
    Assert.assertFalse(deniedDevices1.contains(gpu2));
    Assert.assertFalse(deniedDevices1.contains(gpu3));
    Assert.assertTrue(deniedDevices1.contains(gpu4));
    Assert.assertTrue(deniedDevices1.contains(gpu5));
    Assert.assertTrue(deniedDevices1.contains(gpu6));
    Assert.assertTrue(deniedDevices1.contains(gpu7));

    handler.postExecute(id);

    HashSet<GPU> availableGPUs = gpuAllocator.getConfiguredAvailableGPUs();

    Assert.assertTrue(availableGPUs.contains(gpu0));
    Assert.assertTrue(availableGPUs.contains(gpu1));
    Assert.assertFalse(availableGPUs.contains(gpu2));
    Assert.assertFalse(availableGPUs.contains(gpu3));
    Assert.assertTrue(availableGPUs.contains(gpu4));
    Assert.assertTrue(availableGPUs.contains(gpu5));
    Assert.assertTrue(availableGPUs.contains(gpu6));
    Assert.assertTrue(availableGPUs.contains(gpu7));

    HashSet<GPU> deviceAllocation2 = gpuAllocator.allocate("test_container2", 3);

    allocations = gpuAllocator.getAllocations();
    Assert.assertEquals(2, allocations.size());

    HashSet<GPU> deniedDevices2 = deviceAllocation2;
    Assert.assertFalse(deniedDevices2.contains(gpu0)); //allocated in first call
    Assert.assertFalse(deniedDevices2.contains(gpu1));
    Assert.assertTrue(deniedDevices2.contains(gpu2));
    Assert.assertTrue(deniedDevices2.contains(gpu3));
    Assert.assertFalse(deniedDevices2.contains(gpu4));
    Assert.assertTrue(deniedDevices2.contains(gpu5));
    Assert.assertTrue(deniedDevices2.contains(gpu6));
    Assert.assertTrue(deniedDevices2.contains(gpu7));

    gpuAllocator.release("test_container");

    allocations = gpuAllocator.getAllocations();
    Assert.assertEquals(1, allocations.size());

    gpuAllocator.release("test_container2");
    allocations = gpuAllocator.getAllocations();
    Assert.assertEquals(0, allocations.size());
    availableGPUs = gpuAllocator.getConfiguredAvailableGPUs();
    Assert.assertTrue(availableGPUs.contains(gpu0)); //allocated in first call
    Assert.assertTrue(availableGPUs.contains(gpu1));
    Assert.assertTrue(availableGPUs.contains(gpu2));
    Assert.assertTrue(availableGPUs.contains(gpu3));
    Assert.assertTrue(availableGPUs.contains(gpu4));
    Assert.assertTrue(availableGPUs.contains(gpu5));
    Assert.assertTrue(availableGPUs.contains(gpu6));
    Assert.assertTrue(availableGPUs.contains(gpu7));

    FileUtils.deleteQuietly(cgroupDir);
}

From source file:org.apache.hadoop.yarn.server.nodemanager.util.TestCgroupsLCEResourcesHandlerNVIDIAGPU.java

@Test
public void testSubsetGPUsSchedulable() throws IOException {
    LinuxContainerExecutor mockLCE = new MockLinuxContainerExecutor();
    CustomCgroupsLCEResourceHandlerGPU handler = new CustomCgroupsLCEResourceHandlerGPU();
    YarnConfiguration conf = new YarnConfiguration();
    conf.setBoolean(YarnConfiguration.NM_GPU_RESOURCE_ENABLED, true);
    final int numGPUs = 6;
    ResourceCalculatorPlugin plugin = Mockito.mock(ResourceCalculatorPlugin.class);
    handler.setConf(conf);//from   w w w .  j  a v a  2 s  .c o  m
    handler.initConfig();

    // create mock cgroup
    File cgroupMountDirCPU = createMockCgroupMount(cgroupDir, "cpu");
    File cgroupMountDirGPU = createMockCgroupMount(cgroupDir, "devices");
    File whiteList = new File(cgroupMountDirGPU, "devices.list");
    FileOutputStream fos1 = FileUtils.openOutputStream(whiteList);
    fos1.write(("a *:* rwm\n").getBytes());

    // create mock mtab
    File mockMtab = createMockMTab(cgroupDir);

    ContainerId id = ContainerId.fromString("container_1_1_1_1");
    GPUAllocator gpuAllocator = null;

    conf.setInt(YarnConfiguration.NM_GPUS, numGPUs);

    gpuAllocator = new GPUAllocator(new CustomGPUmanagementLibrarySubset(), conf);

    GPU gpu0 = new GPU(new Device(195, 0), null);
    GPU gpu1 = new GPU(new Device(195, 1), null);
    GPU gpu2 = new GPU(new Device(195, 2), null);
    GPU gpu3 = new GPU(new Device(195, 3), null);
    GPU gpu4 = new GPU(new Device(195, 4), null);
    GPU gpu5 = new GPU(new Device(195, 5), null);

    // setup our handler and call init()
    handler.setGPUAllocator(gpuAllocator);
    handler.setMtabFile(mockMtab.getAbsolutePath());
    handler.init(mockLCE, plugin);
    File containerDirGPU = new File(cgroupMountDirGPU, id.toString());
    File denyFile = new File(containerDirGPU, "devices.deny");
    Assert.assertFalse(denyFile.exists());
    //FIRST ALLOCATION
    handler.preExecute(id, Resource.newInstance(1024, 1, 2));
    Assert.assertTrue(containerDirGPU.exists());
    Assert.assertTrue(containerDirGPU.isDirectory());
    Assert.assertTrue(denyFile.exists());

    Assert.assertTrue(gpuAllocator.getConfiguredAvailableGPUs().size() == 4);
    //SECOND ALLOCATION
    HashSet<GPU> deviceAllocation1 = gpuAllocator.allocate("test_container", 2);

    HashSet<GPU> deniedDevices1 = deviceAllocation1;
    //gpu0 and gpu1 already allocated
    Assert.assertTrue(deniedDevices1.contains(gpu0));
    Assert.assertTrue(deniedDevices1.contains(gpu1));
    Assert.assertFalse(deniedDevices1.contains(gpu2));
    Assert.assertFalse(deniedDevices1.contains(gpu3));
    Assert.assertTrue(deniedDevices1.contains(gpu4));
    Assert.assertTrue(deniedDevices1.contains(gpu5));

    handler.postExecute(id);

    HashSet<GPU> deviceAllocation2 = gpuAllocator.allocate("test_container2", 2);

    HashSet<GPU> deniedDevices2 = deviceAllocation2;
    Assert.assertFalse(deniedDevices2.contains(gpu0)); //allocated in first call
    Assert.assertFalse(deniedDevices2.contains(gpu1));
    Assert.assertTrue(deniedDevices2.contains(gpu2));
    Assert.assertTrue(deniedDevices2.contains(gpu3));
    Assert.assertTrue(deniedDevices2.contains(gpu4));
    Assert.assertTrue(deniedDevices2.contains(gpu5));

    FileUtils.deleteQuietly(cgroupDir);
}

From source file:org.apache.hadoop.yarn.server.nodemanager.util.TestCgroupsLCEResourcesHandlerNVIDIAGPU.java

@Test
public void testContainerRecovery() throws IOException {
    LinuxContainerExecutor mockLCE = new MockLinuxContainerExecutor();
    CustomCgroupsLCEResourceHandlerGPU handler = new CustomCgroupsLCEResourceHandlerGPU();
    YarnConfiguration conf = new YarnConfiguration();
    final int numGPUs = 8;
    ResourceCalculatorPlugin plugin = Mockito.mock(ResourceCalculatorPlugin.class);
    handler.setConf(conf);// www .  j a v a2s . c  o m
    handler.initConfig();
    // create mock cgroup
    File cgroupMountDirCPU = createMockCgroupMount(cgroupDir, "cpu");
    File cgroupMountDirGPU = createMockCgroupMount(cgroupDir, "devices");
    File whiteList = new File(cgroupMountDirGPU, "devices.list");
    FileOutputStream outputStream = FileUtils.openOutputStream(whiteList);
    outputStream.write(("a *:* rwm\n").getBytes());
    // create mock mtab
    File mockMtab = createMockMTab(cgroupDir);
    handler.setMtabFile(mockMtab.getAbsolutePath());

    conf.setInt(YarnConfiguration.NM_GPUS, numGPUs);
    GPUAllocator gpuAllocator = new GPUAllocator(new CustomGPUmanagementLibrary(), conf);

    handler.setGPUAllocator(gpuAllocator);
    handler.init(mockLCE, plugin);

    ContainerId id1 = ContainerId.fromString("container_1_1_1_1");
    handler.preExecute(id1, Resource.newInstance(1024, 1, 2));
    File containerDir1 = new File(cgroupMountDirGPU, id1.toString());
    File listFile1 = new File(containerDir1, "devices.list");
    FileOutputStream fos1 = FileUtils.openOutputStream(listFile1);
    fos1.write(("c 195:0 rwm\n" + "c 195:1 rwm\n").getBytes());

    File tasksFile1 = new File(containerDir1, "tasks");
    FileOutputStream tasks1 = FileUtils.openOutputStream(tasksFile1);
    tasks1.write(("12934").getBytes());

    ContainerId id2 = ContainerId.fromString("container_1_1_1_2");
    handler.preExecute(id2, Resource.newInstance(1024, 1, 2));
    File containerDir2 = new File(cgroupMountDirGPU, id2.toString());
    File listFile2 = new File(containerDir2, "devices.list");
    FileOutputStream fos2 = FileUtils.openOutputStream(listFile2);
    fos2.write(("c 195:2 rwm\n" + "c 195:3 rwm\n").getBytes());

    File tasksFile2 = new File(containerDir2, "tasks");
    FileOutputStream tasks2 = FileUtils.openOutputStream(tasksFile2);
    tasks2.write(("12934").getBytes());

    ContainerId id3 = ContainerId.fromString("container_1_1_1_3");
    handler.preExecute(id3, Resource.newInstance(1024, 1, 2));
    File containerDir3 = new File(cgroupMountDirGPU, id3.toString());
    File listFile3 = new File(containerDir3, "devices.list");
    FileOutputStream fos3 = FileUtils.openOutputStream(listFile3);
    fos3.write(("c 195:4 rwm\n" + "c 195:5 rwm\n").getBytes());

    File tasksFile3 = new File(containerDir3, "tasks");
    FileOutputStream tasks3 = FileUtils.openOutputStream(tasksFile3);
    tasks3.write(("12934").getBytes());

    conf.setInt(YarnConfiguration.NM_GPUS, 8);
    gpuAllocator = new GPUAllocator(new CustomGPUmanagementLibrary(), conf);
    gpuAllocator.initialize(conf);
    handler = new CustomCgroupsLCEResourceHandlerGPU();
    conf = new YarnConfiguration();
    conf.setBoolean(YarnConfiguration.NM_GPU_RESOURCE_ENABLED, true);
    plugin = Mockito.mock(ResourceCalculatorPlugin.class);
    //Mockito.doReturn(numGPUs).when(plugin).getNumGPUs();
    handler.setConf(conf);
    handler.initConfig();

    handler.setMtabFile(mockMtab.getAbsolutePath());
    handler.setGPUAllocator(gpuAllocator);
    handler.init(mockLCE, plugin);

    //No recovery yet
    Assert.assertEquals(8, gpuAllocator.getConfiguredAvailableGPUs().size());
    Assert.assertTrue(listFile1.exists());
    handler.recoverDeviceControlSystem(id1);
    Assert.assertEquals(6, gpuAllocator.getConfiguredAvailableGPUs().size());
    Assert.assertTrue(listFile2.exists());
    handler.recoverDeviceControlSystem(id2);
    Assert.assertEquals(4, gpuAllocator.getConfiguredAvailableGPUs().size());
    Assert.assertTrue(listFile3.exists());
    handler.recoverDeviceControlSystem(id3);
    Assert.assertEquals(2, gpuAllocator.getConfiguredAvailableGPUs().size());
    HashSet<GPU> availableGPUs = new HashSet<>(gpuAllocator.getConfiguredAvailableGPUs());
    Assert.assertFalse(availableGPUs.contains(new GPU(new Device(195, 0), null)));
    Assert.assertFalse(availableGPUs.contains(new GPU(new Device(195, 1), null)));
    Assert.assertFalse(availableGPUs.contains(new GPU(new Device(195, 2), null)));
    Assert.assertFalse(availableGPUs.contains(new GPU(new Device(195, 3), null)));
    Assert.assertFalse(availableGPUs.contains(new GPU(new Device(195, 4), null)));
    Assert.assertFalse(availableGPUs.contains(new GPU(new Device(195, 5), null)));
    Assert.assertTrue(availableGPUs.contains(new GPU(new Device(195, 6), null)));
    Assert.assertTrue(availableGPUs.contains(new GPU(new Device(195, 7), null)));

    FileUtils.deleteQuietly(cgroupDir);
}

From source file:org.apache.jackrabbit.harness.compatibility.AbstractRepositoryTest.java

/**
 * Creates a named test repository with the given configuration file.
 *
 * @param name name of the repository/*w ww  .j  a  v  a2 s .co m*/
 * @param xml input stream for reading the repository configuration
 * @throws Exception if the repository could not be created
 */
protected void doCreateRepository(String name, InputStream xml) throws Exception {
    File directory = new File(new File("target", "repository"), name);
    File configuration = new File(directory, "repository.xml");

    // Copy the configuration file into the repository directory
    try {
        OutputStream output = FileUtils.openOutputStream(configuration);
        try {
            IOUtils.copy(xml, output);
        } finally {
            output.close();
        }
    } finally {
        xml.close();
    }

    // Create the repository
    try {
        RepositoryConfig config = RepositoryConfig.create(configuration.getPath(), directory.getPath());
        RepositoryImpl repository = RepositoryImpl.create(config);
        try {
            Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
            try {
                createTestData(session);
            } finally {
                session.logout();
            }
        } finally {
            repository.shutdown();
        }
    } catch (RepositoryException e) {
        e.printStackTrace();
        fail("Create repository " + name);
    }
}

From source file:org.apache.jackrabbit.j2ee.RepositoryStartupServlet.java

/**
 * Creates a new Repository based on the configuration and initializes the
 * {@link #repository} field if successful.
 *
 * @throws ServletException if an error occurs
 *///from ww w  .  ja v  a  2  s . c  om
private void initRepository() throws ServletException {
    // get repository config
    File repHome;
    try {
        repHome = new File(config.getRepositoryHome()).getCanonicalFile();
    } catch (IOException e) {
        throw new ServletExceptionWithCause("Repository configuration failure: " + config.getRepositoryHome(),
                e);
    }
    String repConfig = config.getRepositoryConfig();
    if (repConfig != null) {
        File configJson = new File(repHome, repConfig);
        if (!configJson.exists()) {
            InputStream in = getServletContext().getResourceAsStream(repConfig);
            if (in == null) {
                throw new ServletException("No config file found in classpath " + repConfig);
            }
            OutputStream os = null;
            try {
                os = FileUtils.openOutputStream(configJson);
                IOUtils.copy(in, os);
            } catch (IOException e1) {
                throw new ServletExceptionWithCause("Error copying the repository config json", e1);
            } finally {
                IOUtils.closeQuietly(os);
                IOUtils.closeQuietly(in);
            }
        }

        try {
            repository = createRepository(configJson, repHome);
            if (getBootstrapConfig().isRepositoryCreateDefaultIndexes()) {
                new IndexInitializer(repository).initialize();
            }
        } catch (RepositoryException e) {
            throw new ServletExceptionWithCause("Error while creating repository", e);
        }
    }
}

From source file:org.apache.jackrabbit.oak.standalone.RepositoryInitializer.java

private void copyDefaultConfig(File repoConfig, Resource defaultRepoConfig)
        throws IOException, RepositoryException {
    if (!repoConfig.exists()) {
        log.info("Copying default repository config to {}", repoConfig.getAbsolutePath());
        InputStream in = defaultRepoConfig.getInputStream();
        if (in == null) {
            throw new RepositoryException("No config file found in classpath " + defaultRepoConfig);
        }/*from  w  ww.  j  av  a2 s .co  m*/
        OutputStream os = null;
        try {
            os = FileUtils.openOutputStream(repoConfig);
            IOUtils.copy(in, os);
        } finally {
            IOUtils.closeQuietly(os);
            IOUtils.closeQuietly(in);
        }
    }
}

From source file:org.apache.jackrabbit.oak.upgrade.AbstractRepositoryUpgradeTest.java

protected RepositoryImpl createSourceRepository(File repositoryHome) throws IOException, RepositoryException {
    InputStream repoConfig = getRepositoryConfig();
    RepositoryConfig config;/*from   ww  w . j a v a  2  s  .c  o  m*/
    if (repoConfig == null) {
        config = RepositoryConfig.install(repositoryHome);
    } else {
        OutputStream out = FileUtils.openOutputStream(new File(repositoryHome, "repository.xml"));
        IOUtils.copy(repoConfig, out);
        out.close();
        repoConfig.close();
        config = RepositoryConfig.create(repositoryHome);
    }
    return RepositoryImpl.create(config);
}

From source file:org.apache.jackrabbit.performance.AbstractPerformanceTest.java

private void runTest(AbstractTest test, String name, byte[] conf) {
    if (repoPattern.matcher(name).matches() && testPattern.matcher(test.toString()).matches()) {
        // Create the repository directory
        File dir = new File(new File("target", "repository"), name + "-" + test);
        dir.mkdirs();/* w w  w .ja va 2 s .  c  om*/

        try {
            // Copy the configuration file into the repository directory
            File xml = new File(dir, "repository.xml");
            OutputStream output = FileUtils.openOutputStream(xml);
            try {
                output.write(conf, 0, conf.length);
            } finally {
                output.close();
            }

            // Create the repository
            RepositoryImpl repository = createRepository(dir, xml);
            try {
                // Run the test
                DescriptiveStatistics statistics = runTest(test, repository);
                if (statistics.getN() > 0) {
                    writeReport(test.toString(), name, statistics);
                }
            } finally {
                repository.shutdown();
            }
        } catch (Throwable t) {
            System.out.println("Unable to run " + test + ": " + t.getMessage());
        } finally {
            FileUtils.deleteQuietly(dir);
        }
    }
}