Search in sources :

Example 26 with CatalogEntity

use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.

the class TestHetuMetastoreGlobalCache method testAlterCatalog.

/**
 * test alter catalog with metastore cache
 */
@Test
public void testAlterCatalog() {
    Map<String, String> properties = ImmutableMap.<String, String>builder().build();
    CatalogEntity catalog1 = CatalogEntity.builder().setCatalogName("catalog6").setOwner("root6").setComment(Optional.of("Hetu create catalog")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalog1);
    CatalogEntity catalog2 = CatalogEntity.builder().setCatalogName("catalog6").setOwner("hive").setComment(Optional.of("Hetu alter catalog")).setParameters(emptyMap()).setCreateTime(System.currentTimeMillis()).build();
    metastore.alterCatalog("catalog6", catalog2);
    assertEquals(catalogsCache.getIfPresent(""), null);
    metastore.dropCatalog(catalog2.getName());
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 27 with CatalogEntity

use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.

the class TestHetuMetastoreGlobalCache method testGetCatalog.

/**
 * test get catalog with metastore cache
 */
@Test
public void testGetCatalog() {
    Map<String, String> properties = ImmutableMap.<String, String>builder().build();
    CatalogEntity catalogEntity = CatalogEntity.builder().setCatalogName("catalog3").setOwner("root3").setComment(Optional.of("Hetu create catalog")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalogEntity);
    Optional<CatalogEntity> catalogInfo = metastore.getCatalog("catalog3");
    assertTrue(catalogInfo.isPresent());
    assertEquals(catalogInfo.get(), catalogEntity);
    metastore.dropCatalog(catalogEntity.getName());
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 28 with CatalogEntity

use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.

the class TestHetuMetastoreGlobalCache method testCreateCatalog.

/**
 * test create catalog with metastore cache
 */
@Test
public void testCreateCatalog() {
    Map<String, String> properties = ImmutableMap.<String, String>builder().build();
    CatalogEntity catalogEntity = CatalogEntity.builder().setCatalogName("catalog1").setOwner("root1").setComment(Optional.of("Hetu create catalog")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalogEntity);
    assertEquals(catalogsCache.getIfPresent(""), null);
    metastore.dropCatalog(catalogEntity.getName());
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 29 with CatalogEntity

use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.

the class HetuFsMetastore method alterCatalogParameter.

@Override
public void alterCatalogParameter(String catalogName, String key, String value) {
    checkArgument(catalogName.matches("[\\p{Alnum}_]+"), "Invalid catalog name");
    runTransaction(() -> {
        assertCatalogExist(catalogName);
        try {
            Path catalogMetadataPath = getCatalogMetadataPath(catalogName);
            CatalogEntity catalogEntity;
            try (InputStream inputStream = client.newInputStream(catalogMetadataPath)) {
                String catalogJson = CharStreams.toString(new InputStreamReader(inputStream, UTF_8));
                catalogEntity = CATALOG_CODEC.fromJson(catalogJson);
            }
            if (value == null) {
                catalogEntity.getParameters().remove(key);
            } else {
                catalogEntity.getParameters().put(key, value);
            }
            try (OutputStream outputStream = client.newOutputStream(catalogMetadataPath)) {
                outputStream.write(CATALOG_CODEC.toJsonBytes(catalogEntity));
            }
        } catch (IOException e) {
            throw new PrestoException(HETU_METASTORE_CODE, e);
        }
    });
}
Also used : Path(java.nio.file.Path) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) PrestoException(io.prestosql.spi.PrestoException) IOException(java.io.IOException)

Example 30 with CatalogEntity

use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.

the class HetuFsMetastore method alterCatalog.

@Override
public void alterCatalog(String catalogName, CatalogEntity newCatalog) {
    checkArgument(catalogName.matches("[\\p{Alnum}_]+"), "Invalid catalog name");
    checkArgument(newCatalog.getName().matches("[\\p{Alnum}_]+"), "Invalid new catalog name");
    runTransaction(() -> {
        if (!catalogName.equals(newCatalog.getName())) {
            throw new PrestoException(HETU_METASTORE_CODE, "Cannot alter a catalog's name");
        }
        assertCatalogExist(catalogName);
        try {
            CatalogEntity orgCatalog;
            try (InputStream inputStream = client.newInputStream(getCatalogMetadataPath(catalogName))) {
                String catalogJson = CharStreams.toString(new InputStreamReader(inputStream, UTF_8));
                orgCatalog = CATALOG_CODEC.fromJson(catalogJson);
            }
            try (OutputStream outputStream = client.newOutputStream(getCatalogMetadataPath(catalogName))) {
                // can not update the create time.
                newCatalog.setCreateTime(orgCatalog.getCreateTime());
                outputStream.write(CATALOG_CODEC.toJsonBytes(newCatalog));
            }
        } catch (IOException e) {
            throw new PrestoException(HETU_METASTORE_CODE, e);
        }
    });
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) PrestoException(io.prestosql.spi.PrestoException) IOException(java.io.IOException)

Aggregations

CatalogEntity (io.prestosql.spi.metastore.model.CatalogEntity)34 Test (org.testng.annotations.Test)24 PrestoException (io.prestosql.spi.PrestoException)15 DatabaseEntity (io.prestosql.spi.metastore.model.DatabaseEntity)7 BeforeTest (org.testng.annotations.BeforeTest)5 ImmutableList (com.google.common.collect.ImmutableList)4 TableEntity (io.prestosql.spi.metastore.model.TableEntity)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 OutputStream (java.io.OutputStream)3 List (java.util.List)3 Logger (io.airlift.log.Logger)2 Path (java.nio.file.Path)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 CharStreams (com.google.common.io.CharStreams)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1