Search in sources :

Example 6 with SeedStore

use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.

the class SeedStoreManager method removeSeed.

/**
 * remove seed from seed store
 *
 * @param seedLocation
 * @return a collection of seeds in the seed store
 * @throws IOException
 */
public Collection<Seed> removeSeed(SeedStoreSubType subType, String seedLocation) throws IOException {
    Collection<Seed> seeds = new HashSet<>();
    SeedStore seedStore = getSeedStore(subType);
    if (seedStore == null) {
        throw new PrestoException(SEED_STORE_FAILURE, "Seed store is null");
    }
    refreshableSeedsMap.remove(seedLocation);
    Optional<Seed> seedOptional;
    if (subType == SeedStoreSubType.ON_YARN) {
        seedOptional = seedStore.get().stream().filter(s -> {
            return s.getLocation().equals(seedLocation) || s.getUniqueInstanceId().equals(seedLocation);
        }).findFirst();
    } else {
        seedOptional = seedStore.get().stream().filter(s -> s.getLocation().equals(seedLocation)).findFirst();
    }
    if (seedOptional.isPresent()) {
        seeds = seedStore.remove(Lists.newArrayList(seedOptional.get()));
        LOG.debug("Seed=%s removed from seed store", seedLocation);
    }
    return seeds;
}
Also used : Seed(io.prestosql.spi.seedstore.Seed) SeedStore(io.prestosql.spi.seedstore.SeedStore) PrestoException(io.prestosql.spi.PrestoException) HashSet(java.util.HashSet)

Example 7 with SeedStore

use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.

the class TestSeedStoreManager method testLoadAndGetSeedStore.

@Test
public void testLoadAndGetSeedStore() throws IOException {
    seedStoreManager.loadSeedStore();
    SeedStore returned = seedStoreManager.getSeedStore(SeedStoreSubType.HAZELCAST);
}
Also used : SeedStore(io.prestosql.spi.seedstore.SeedStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 8 with SeedStore

use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.

the class TestSeedStoreManager method setUp.

@BeforeMethod
private void setUp() throws IOException {
    FileSystemClientManager mockFileSystemClientManager = mock(FileSystemClientManager.class);
    when(mockFileSystemClientManager.getFileSystemClient(anyString(), any())).thenReturn(null);
    seedStoreManager = new SeedStoreManager(mockFileSystemClientManager);
    SeedStore mockSeedStore = new MockSeedStore();
    mockSeedStore.add(new HashSet<>());
    SeedStoreFactory mockSeedStoreFactory = mock(SeedStoreFactory.class);
    when(mockSeedStoreFactory.getName()).thenReturn("filebased");
    when(mockSeedStoreFactory.create(any(String.class), any(SeedStoreSubType.class), any(HetuFileSystemClient.class), any(Map.class))).thenReturn(mockSeedStore);
    seedStoreManager.addSeedStoreFactory(mockSeedStoreFactory);
}
Also used : HetuFileSystemClient(io.prestosql.spi.filesystem.HetuFileSystemClient) SeedStore(io.prestosql.spi.seedstore.SeedStore) SeedStoreFactory(io.prestosql.spi.seedstore.SeedStoreFactory) Matchers.anyString(org.mockito.Matchers.anyString) HashMap(java.util.HashMap) Map(java.util.Map) FileSystemClientManager(io.prestosql.filesystem.FileSystemClientManager) SeedStoreSubType(io.prestosql.spi.seedstore.SeedStoreSubType) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 9 with SeedStore

use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.

the class TestDynamicFilterSourceOperator method prepareConfigFiles.

@BeforeTest
private void prepareConfigFiles() throws Exception {
    File launcherConfigFile = new File(STATE_STORE_CONFIGURATION_PATH);
    if (launcherConfigFile.exists()) {
        launcherConfigFile.delete();
    }
    launcherConfigFile.createNewFile();
    FileWriter configWriter = new FileWriter(STATE_STORE_CONFIGURATION_PATH);
    configWriter.write("state-store.type=hazelcast\n" + "state-store.name=test\n" + "state-store.cluster=test-cluster\n" + "hazelcast.discovery.mode=tcp-ip\n" + "hazelcast.discovery.port=7980\n");
    configWriter.close();
    Set<Seed> seeds = new HashSet<>();
    SeedStore mockSeedStore = mock(SeedStore.class);
    Seed mockSeed = mock(Seed.class);
    seeds.add(mockSeed);
    SeedStoreManager mockSeedStoreManager = mock(SeedStoreManager.class);
    when(mockSeedStoreManager.getSeedStore(SeedStoreSubType.HAZELCAST)).thenReturn(mockSeedStore);
    when(mockSeed.getLocation()).thenReturn("127.0.0.1:6991");
    when(mockSeedStore.get()).thenReturn(seeds);
    StateStoreFactory factory = new HazelcastStateStoreFactory();
    stateStoreProvider = new LocalStateStoreProvider(mockSeedStoreManager);
    stateStoreProvider.addStateStoreFactory(factory);
    createStateStoreCluster("6991");
    stateStoreProvider.loadStateStore();
}
Also used : LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) SeedStoreManager(io.prestosql.seedstore.SeedStoreManager) Seed(io.prestosql.spi.seedstore.Seed) FileWriter(java.io.FileWriter) SeedStore(io.prestosql.spi.seedstore.SeedStore) HazelcastStateStoreFactory(io.hetu.core.statestore.hazelcast.HazelcastStateStoreFactory) File(java.io.File) HashSet(java.util.HashSet) HazelcastStateStoreFactory(io.hetu.core.statestore.hazelcast.HazelcastStateStoreFactory) StateStoreFactory(io.prestosql.spi.statestore.StateStoreFactory) BeforeTest(org.testng.annotations.BeforeTest)

Example 10 with SeedStore

use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.

the class TestHazelcastStateStoreFactory method testUnableGetSeeds.

/**
 * Test what happens to hazelcast factory if no seeds get from seed store
 *
 * @throws IOException IOException thrown if seedStore read write errors happen
 */
@Test(expectedExceptions = RuntimeException.class)
public void testUnableGetSeeds() throws IOException {
    HazelcastStateStoreFactory factory = new HazelcastStateStoreFactory();
    assertEquals(factory.getName(), HAZELCAST);
    SeedStoreFactory seedStoreFactory = new FileBasedSeedStoreFactory();
    assertEquals(seedStoreFactory.getName(), "filebased");
    Map<String, String> properties = new HashMap<>(0);
    properties.put(STATE_STORE_CLUSTER_CONFIG_NAME, TEST_CLUSTER_NAME);
    properties.put(DISCOVERY_MODE_CONFIG_NAME, DISCOVERY_MODE_TCPIP);
    SeedStore seedStore = mock(SeedStore.class);
    when(seedStore.get()).thenReturn(ImmutableList.of());
    factory.create(TEST_STATE_STORE_NAME, seedStore, properties);
}
Also used : HashMap(java.util.HashMap) SeedStore(io.prestosql.spi.seedstore.SeedStore) SeedStoreFactory(io.prestosql.spi.seedstore.SeedStoreFactory) FileBasedSeedStoreFactory(io.hetu.core.seedstore.filebased.FileBasedSeedStoreFactory) FileBasedSeedStoreFactory(io.hetu.core.seedstore.filebased.FileBasedSeedStoreFactory) Test(org.testng.annotations.Test)

Aggregations

SeedStore (io.prestosql.spi.seedstore.SeedStore)18 Seed (io.prestosql.spi.seedstore.Seed)15 PrestoException (io.prestosql.spi.PrestoException)9 HashSet (java.util.HashSet)9 HashMap (java.util.HashMap)7 Map (java.util.Map)6 BeforeTest (org.testng.annotations.BeforeTest)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 SeedStoreManager (io.prestosql.seedstore.SeedStoreManager)4 SeedStoreFactory (io.prestosql.spi.seedstore.SeedStoreFactory)4 SeedStoreSubType (io.prestosql.spi.seedstore.SeedStoreSubType)4 IOException (java.io.IOException)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Logger (io.airlift.log.Logger)3 ThreadContextClassLoader (io.prestosql.spi.classloader.ThreadContextClassLoader)3 StateStore (io.prestosql.spi.statestore.StateStore)3 LocalStateStoreProvider (io.prestosql.statestore.LocalStateStoreProvider)3 String.format (java.lang.String.format)3 Collection (java.util.Collection)3 Test (org.testng.annotations.Test)3