Search in sources :

Example 1 with UtilizationSchemaDefinition

use of org.hadoop.ozone.recon.schema.UtilizationSchemaDefinition in project ozone by apache.

the class TestFileSizeCountTask method setUp.

@Before
public void setUp() {
    fileCountBySizeDao = getDao(FileCountBySizeDao.class);
    UtilizationSchemaDefinition utilizationSchemaDefinition = getSchemaDefinition(UtilizationSchemaDefinition.class);
    fileSizeCountTask = new FileSizeCountTask(fileCountBySizeDao, utilizationSchemaDefinition);
    dslContext = utilizationSchemaDefinition.getDSLContext();
    // Truncate table before running each test
    dslContext.truncate(FILE_COUNT_BY_SIZE);
}
Also used : UtilizationSchemaDefinition(org.hadoop.ozone.recon.schema.UtilizationSchemaDefinition) FileCountBySizeDao(org.hadoop.ozone.recon.schema.tables.daos.FileCountBySizeDao) Before(org.junit.Before)

Example 2 with UtilizationSchemaDefinition

use of org.hadoop.ozone.recon.schema.UtilizationSchemaDefinition in project ozone by apache.

the class TestEndpoints method initializeInjector.

private void initializeInjector() throws Exception {
    reconOMMetadataManager = getTestReconOmMetadataManager(initializeNewOmMetadataManager(temporaryFolder.newFolder()), temporaryFolder.newFolder());
    datanodeDetails = randomDatanodeDetails();
    datanodeDetails2 = randomDatanodeDetails();
    datanodeDetails.setHostName(HOST1);
    datanodeDetails.setIpAddress(IP1);
    datanodeDetails2.setHostName(HOST2);
    datanodeDetails2.setIpAddress(IP2);
    pipeline = getRandomPipeline(datanodeDetails);
    pipelineId = pipeline.getId().getId().toString();
    ContainerInfo containerInfo = new ContainerInfo.Builder().setContainerID(containerId).setReplicationConfig(RatisReplicationConfig.getInstance(ReplicationFactor.ONE)).setState(LifeCycleState.OPEN).setOwner("test").setPipelineID(pipeline.getId()).build();
    ContainerWithPipeline containerWithPipeline = new ContainerWithPipeline(containerInfo, pipeline);
    StorageContainerLocationProtocol mockScmClient = mock(StorageContainerLocationProtocol.class);
    StorageContainerServiceProvider mockScmServiceProvider = mock(StorageContainerServiceProviderImpl.class);
    when(mockScmServiceProvider.getPipeline(pipeline.getId().getProtobuf())).thenReturn(pipeline);
    when(mockScmServiceProvider.getContainerWithPipeline(containerId)).thenReturn(containerWithPipeline);
    List<Long> containerIDs = new LinkedList<>();
    containerIDs.add(containerId);
    List<ContainerWithPipeline> cpw = new LinkedList<>();
    cpw.add(containerWithPipeline);
    when(mockScmServiceProvider.getExistContainerWithPipelinesInBatch(containerIDs)).thenReturn(cpw);
    InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(PROMETHEUS_TEST_RESPONSE_FILE);
    reconUtilsMock = mock(ReconUtils.class);
    HttpURLConnection urlConnectionMock = mock(HttpURLConnection.class);
    when(urlConnectionMock.getResponseCode()).thenReturn(HttpServletResponse.SC_OK);
    when(urlConnectionMock.getInputStream()).thenReturn(inputStream);
    when(reconUtilsMock.makeHttpCall(any(URLConnectionFactory.class), anyString(), anyBoolean())).thenReturn(urlConnectionMock);
    when(reconUtilsMock.getReconDbDir(any(OzoneConfiguration.class), anyString())).thenReturn(GenericTestUtils.getRandomizedTestDir());
    ReconTestInjector reconTestInjector = new ReconTestInjector.Builder(temporaryFolder).withReconSqlDb().withReconOm(reconOMMetadataManager).withOmServiceProvider(mock(OzoneManagerServiceProviderImpl.class)).addBinding(StorageContainerServiceProvider.class, mockScmServiceProvider).addBinding(OzoneStorageContainerManager.class, ReconStorageContainerManagerFacade.class).withContainerDB().addBinding(ClusterStateEndpoint.class).addBinding(NodeEndpoint.class).addBinding(MetricsServiceProviderFactory.class).addBinding(ContainerHealthSchemaManager.class).addBinding(UtilizationEndpoint.class).addBinding(ReconUtils.class, reconUtilsMock).addBinding(StorageContainerLocationProtocol.class, mockScmClient).build();
    nodeEndpoint = reconTestInjector.getInstance(NodeEndpoint.class);
    pipelineEndpoint = reconTestInjector.getInstance(PipelineEndpoint.class);
    fileCountBySizeDao = getDao(FileCountBySizeDao.class);
    GlobalStatsDao globalStatsDao = getDao(GlobalStatsDao.class);
    UtilizationSchemaDefinition utilizationSchemaDefinition = getSchemaDefinition(UtilizationSchemaDefinition.class);
    Configuration sqlConfiguration = reconTestInjector.getInstance(Configuration.class);
    utilizationEndpoint = new UtilizationEndpoint(fileCountBySizeDao, utilizationSchemaDefinition);
    fileSizeCountTask = new FileSizeCountTask(fileCountBySizeDao, utilizationSchemaDefinition);
    tableCountTask = new TableCountTask(globalStatsDao, sqlConfiguration, reconOMMetadataManager);
    reconScm = (ReconStorageContainerManagerFacade) reconTestInjector.getInstance(OzoneStorageContainerManager.class);
    clusterStateEndpoint = new ClusterStateEndpoint(reconScm, globalStatsDao);
    MetricsServiceProviderFactory metricsServiceProviderFactory = reconTestInjector.getInstance(MetricsServiceProviderFactory.class);
    metricsProxyEndpoint = new MetricsProxyEndpoint(metricsServiceProviderFactory);
    dslContext = getDslContext();
}
Also used : StorageContainerServiceProvider(org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider) TableCountTask(org.apache.hadoop.ozone.recon.tasks.TableCountTask) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) Configuration(org.jooq.Configuration) UtilizationSchemaDefinition(org.hadoop.ozone.recon.schema.UtilizationSchemaDefinition) ContainerWithPipeline(org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline) OzoneStorageContainerManager(org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager) HttpURLConnection(java.net.HttpURLConnection) StorageContainerLocationProtocol(org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol) GlobalStatsDao(org.hadoop.ozone.recon.schema.tables.daos.GlobalStatsDao) ReconTestInjector(org.apache.hadoop.ozone.recon.ReconTestInjector) FileSizeCountTask(org.apache.hadoop.ozone.recon.tasks.FileSizeCountTask) URLConnectionFactory(org.apache.hadoop.hdfs.web.URLConnectionFactory) ReconStorageContainerManagerFacade(org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade) MetricsServiceProviderFactory(org.apache.hadoop.ozone.recon.MetricsServiceProviderFactory) ReconUtils(org.apache.hadoop.ozone.recon.ReconUtils) InputStream(java.io.InputStream) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) FileCountBySizeDao(org.hadoop.ozone.recon.schema.tables.daos.FileCountBySizeDao) LinkedList(java.util.LinkedList) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo)

Example 3 with UtilizationSchemaDefinition

use of org.hadoop.ozone.recon.schema.UtilizationSchemaDefinition in project ozone by apache.

the class TestUtilizationSchemaDefinition method testFileCountBySizeCRUDOperations.

@Test
public void testFileCountBySizeCRUDOperations() throws SQLException {
    Connection connection = getConnection();
    DatabaseMetaData metaData = connection.getMetaData();
    ResultSet resultSet = metaData.getTables(null, null, FILE_COUNT_BY_SIZE_TABLE_NAME, null);
    while (resultSet.next()) {
        Assert.assertEquals(FILE_COUNT_BY_SIZE_TABLE_NAME, resultSet.getString("TABLE_NAME"));
    }
    FileCountBySizeDao fileCountBySizeDao = getDao(FileCountBySizeDao.class);
    UtilizationSchemaDefinition utilizationSchemaDefinition = getSchemaDefinition(UtilizationSchemaDefinition.class);
    FileCountBySize newRecord = new FileCountBySize();
    newRecord.setVolume("vol1");
    newRecord.setBucket("bucket1");
    newRecord.setFileSize(1024L);
    newRecord.setCount(1L);
    fileCountBySizeDao.insert(newRecord);
    Record3<String, String, Long> recordToFind = utilizationSchemaDefinition.getDSLContext().newRecord(FILE_COUNT_BY_SIZE.VOLUME, FILE_COUNT_BY_SIZE.BUCKET, FILE_COUNT_BY_SIZE.FILE_SIZE).value1("vol1").value2("bucket1").value3(1024L);
    FileCountBySize dbRecord = fileCountBySizeDao.findById(recordToFind);
    assertEquals(Long.valueOf(1), dbRecord.getCount());
    dbRecord.setCount(2L);
    fileCountBySizeDao.update(dbRecord);
    dbRecord = fileCountBySizeDao.findById(recordToFind);
    assertEquals(Long.valueOf(2), dbRecord.getCount());
    Table<FileCountBySizeRecord> fileCountBySizeRecordTable = fileCountBySizeDao.getTable();
    List<UniqueKey<FileCountBySizeRecord>> tableKeys = fileCountBySizeRecordTable.getKeys();
    for (UniqueKey key : tableKeys) {
        String name = key.getName();
    }
}
Also used : UtilizationSchemaDefinition(org.hadoop.ozone.recon.schema.UtilizationSchemaDefinition) Connection(java.sql.Connection) FileCountBySizeDao(org.hadoop.ozone.recon.schema.tables.daos.FileCountBySizeDao) DatabaseMetaData(java.sql.DatabaseMetaData) UniqueKey(org.jooq.UniqueKey) ResultSet(java.sql.ResultSet) FileCountBySize(org.hadoop.ozone.recon.schema.tables.pojos.FileCountBySize) FileCountBySizeRecord(org.hadoop.ozone.recon.schema.tables.records.FileCountBySizeRecord) Test(org.junit.Test)

Aggregations

UtilizationSchemaDefinition (org.hadoop.ozone.recon.schema.UtilizationSchemaDefinition)3 FileCountBySizeDao (org.hadoop.ozone.recon.schema.tables.daos.FileCountBySizeDao)3 InputStream (java.io.InputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 LinkedList (java.util.LinkedList)1 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)1 ContainerInfo (org.apache.hadoop.hdds.scm.container.ContainerInfo)1 ContainerWithPipeline (org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline)1 StorageContainerLocationProtocol (org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol)1 OzoneStorageContainerManager (org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager)1 URLConnectionFactory (org.apache.hadoop.hdfs.web.URLConnectionFactory)1 MetricsServiceProviderFactory (org.apache.hadoop.ozone.recon.MetricsServiceProviderFactory)1 ReconTestInjector (org.apache.hadoop.ozone.recon.ReconTestInjector)1 ReconUtils (org.apache.hadoop.ozone.recon.ReconUtils)1 ReconStorageContainerManagerFacade (org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade)1 StorageContainerServiceProvider (org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider)1 FileSizeCountTask (org.apache.hadoop.ozone.recon.tasks.FileSizeCountTask)1