Search in sources :

Example 11 with ServiceEnvironment

use of org.apache.accumulo.core.spi.common.ServiceEnvironment in project accumulo by apache.

the class DefaultCompactionPlannerTest method testErrorExternalNoQueue.

/**
 * Tests external type executor missing queue throws error
 */
@Test
public void testErrorExternalNoQueue() {
    DefaultCompactionPlanner planner = new DefaultCompactionPlanner();
    Configuration conf = EasyMock.createMock(Configuration.class);
    EasyMock.expect(conf.isSet(EasyMock.anyString())).andReturn(false).anyTimes();
    ServiceEnvironment senv = EasyMock.createMock(ServiceEnvironment.class);
    EasyMock.expect(senv.getConfiguration()).andReturn(conf).anyTimes();
    EasyMock.replay(conf, senv);
    String executors = getExecutors("'type': 'internal','maxSize':'32M','numThreads':1", "'type': 'internal','maxSize':'128M','numThreads':2", "'type': 'external','maxSize':'512M'");
    var e = assertThrows(NullPointerException.class, () -> planner.init(getInitParams(senv, executors)), "Failed to throw error");
    assertTrue(e.getMessage().contains("queue"), "Error message didn't contain queue");
}
Also used : ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) Configuration(org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration) Test(org.junit.jupiter.api.Test)

Example 12 with ServiceEnvironment

use of org.apache.accumulo.core.spi.common.ServiceEnvironment in project accumulo by apache.

the class DefaultCompactionPlannerTest method testErrorExternalTypeNumThreads.

/**
 * Test external type executor with numThreads set throws error.
 */
@Test
public void testErrorExternalTypeNumThreads() {
    DefaultCompactionPlanner planner = new DefaultCompactionPlanner();
    Configuration conf = EasyMock.createMock(Configuration.class);
    EasyMock.expect(conf.isSet(EasyMock.anyString())).andReturn(false).anyTimes();
    ServiceEnvironment senv = EasyMock.createMock(ServiceEnvironment.class);
    EasyMock.expect(senv.getConfiguration()).andReturn(conf).anyTimes();
    EasyMock.replay(conf, senv);
    String executors = getExecutors("'type': 'internal','maxSize':'32M','numThreads':1", "'type': 'internal','maxSize':'128M','numThreads':2", "'type': 'external','maxSize':'512M','numThreads':3");
    var e = assertThrows(IllegalArgumentException.class, () -> planner.init(getInitParams(senv, executors)), "Failed to throw error");
    assertTrue(e.getMessage().contains("numThreads"), "Error message didn't contain numThreads");
}
Also used : ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) Configuration(org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration) Test(org.junit.jupiter.api.Test)

Example 13 with ServiceEnvironment

use of org.apache.accumulo.core.spi.common.ServiceEnvironment in project accumulo by apache.

the class CheckCompactionConfig method execute.

@Override
public void execute(String[] args) throws Exception {
    Opts opts = new Opts();
    opts.parseArgs(keyword(), args);
    if (opts.filePath == null) {
        throw new IllegalArgumentException("No properties file was given");
    }
    Path path = Path.of(opts.filePath);
    if (!path.toFile().exists())
        throw new FileNotFoundException("File at given path could not be found");
    AccumuloConfiguration config = SiteConfiguration.fromFile(path.toFile()).build();
    var servicesConfig = new CompactionServicesConfig(config, log::warn);
    ServiceEnvironment senv = createServiceEnvironment(config);
    Set<String> defaultServices = Set.of(DEFAULT, META, ROOT);
    if (servicesConfig.getPlanners().keySet().equals(defaultServices)) {
        log.warn("Only the default compaction services were created - {}", defaultServices);
        return;
    }
    for (var entry : servicesConfig.getPlanners().entrySet()) {
        String serviceId = entry.getKey();
        String plannerClassName = entry.getValue();
        log.info("Service id: {}, planner class:{}", serviceId, plannerClassName);
        Class<? extends CompactionPlanner> plannerClass = Class.forName(plannerClassName).asSubclass(CompactionPlanner.class);
        CompactionPlanner planner = plannerClass.getDeclaredConstructor().newInstance();
        var initParams = new CompactionPlannerInitParams(CompactionServiceId.of(serviceId), servicesConfig.getOptions().get(serviceId), senv);
        planner.init(initParams);
        initParams.getRequestedExecutors().forEach((execId, numThreads) -> log.info("Compaction service '{}' requested creation of thread pool '{}' with {} threads.", serviceId, execId, numThreads));
        initParams.getRequestedExternalExecutors().forEach(execId -> log.info("Compaction service '{}' requested with external execution queue '{}'", serviceId, execId));
    }
    log.info("Properties file has passed all checks.");
}
Also used : Path(java.nio.file.Path) CompactionServicesConfig(org.apache.accumulo.core.util.compaction.CompactionServicesConfig) FileNotFoundException(java.io.FileNotFoundException) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) CompactionPlannerInitParams(org.apache.accumulo.core.util.compaction.CompactionPlannerInitParams) CompactionPlanner(org.apache.accumulo.core.spi.compaction.CompactionPlanner) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 14 with ServiceEnvironment

use of org.apache.accumulo.core.spi.common.ServiceEnvironment in project accumulo by apache.

the class TableConfiguration method createCompactionDispatcher.

private static CompactionDispatcher createCompactionDispatcher(AccumuloConfiguration conf, ServerContext context, TableId tableId) {
    CompactionDispatcher newDispatcher = Property.createTableInstanceFromPropertyName(conf, Property.TABLE_COMPACTION_DISPATCHER, CompactionDispatcher.class, null);
    Map<String, String> opts = conf.getAllPropertiesWithPrefixStripped(Property.TABLE_COMPACTION_DISPATCHER_OPTS);
    newDispatcher.init(new CompactionDispatcher.InitParameters() {

        private final ServiceEnvironment senv = new ServiceEnvironmentImpl(context);

        @Override
        public TableId getTableId() {
            return tableId;
        }

        @Override
        public Map<String, String> getOptions() {
            return opts;
        }

        @Override
        public ServiceEnvironment getServiceEnv() {
            return senv;
        }
    });
    return newDispatcher;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) CompactionDispatcher(org.apache.accumulo.core.spi.compaction.CompactionDispatcher) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) HashMap(java.util.HashMap) Map(java.util.Map) EnumMap(java.util.EnumMap)

Example 15 with ServiceEnvironment

use of org.apache.accumulo.core.spi.common.ServiceEnvironment in project accumulo by apache.

the class TableConfiguration method createScanDispatcher.

private static ScanDispatcher createScanDispatcher(AccumuloConfiguration conf, ServerContext context, TableId tableId) {
    ScanDispatcher newDispatcher = Property.createTableInstanceFromPropertyName(conf, Property.TABLE_SCAN_DISPATCHER, ScanDispatcher.class, null);
    Map<String, String> opts = conf.getAllPropertiesWithPrefixStripped(Property.TABLE_SCAN_DISPATCHER_OPTS);
    newDispatcher.init(new ScanDispatcher.InitParameters() {

        private final ServiceEnvironment senv = new ServiceEnvironmentImpl(context);

        @Override
        public TableId getTableId() {
            return tableId;
        }

        @Override
        public Map<String, String> getOptions() {
            return opts;
        }

        @Override
        public ServiceEnvironment getServiceEnv() {
            return senv;
        }
    });
    return newDispatcher;
}
Also used : ScanDispatcher(org.apache.accumulo.core.spi.scan.ScanDispatcher) TableId(org.apache.accumulo.core.data.TableId) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) HashMap(java.util.HashMap) Map(java.util.Map) EnumMap(java.util.EnumMap)

Aggregations

ServiceEnvironment (org.apache.accumulo.core.spi.common.ServiceEnvironment)15 Map (java.util.Map)8 HashMap (java.util.HashMap)7 ServiceEnvironmentImpl (org.apache.accumulo.server.ServiceEnvironmentImpl)7 Configuration (org.apache.accumulo.core.spi.common.ServiceEnvironment.Configuration)6 TableId (org.apache.accumulo.core.data.TableId)5 Test (org.junit.jupiter.api.Test)5 Collection (java.util.Collection)3 SortedMap (java.util.SortedMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)3 Cache (com.google.common.cache.Cache)2 CacheBuilder (com.google.common.cache.CacheBuilder)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 EnumMap (java.util.EnumMap)2 Optional (java.util.Optional)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 PluginEnvironment (org.apache.accumulo.core.client.PluginEnvironment)2 ScanDispatcher (org.apache.accumulo.core.spi.scan.ScanDispatcher)2