Search in sources :

Example 6 with SupervisorSpec

use of org.apache.druid.indexing.overlord.supervisor.SupervisorSpec in project druid by druid-io.

the class SupervisorResourceFilterTest method testSupervisorNotFound.

@Test
public void testSupervisorNotFound() {
    String dataSource = "not_exist_data_source";
    expect(containerRequest.getPathSegments()).andReturn(getPathSegments("/druid/indexer/v1/supervisor/" + dataSource)).anyTimes();
    expect(containerRequest.getMethod()).andReturn("POST").anyTimes();
    SupervisorSpec supervisorSpec = EasyMock.createMock(SupervisorSpec.class);
    expect(supervisorSpec.getDataSources()).andReturn(Collections.singletonList(dataSource)).anyTimes();
    expect(supervisorManager.getSupervisorSpec(dataSource)).andReturn(Optional.absent()).atLeastOnce();
    EasyMock.replay(containerRequest);
    EasyMock.replay(supervisorManager);
    WebApplicationException expected = null;
    try {
        resourceFilter.filter(containerRequest);
    } catch (WebApplicationException e) {
        expected = e;
    }
    Assert.assertNotNull(expected);
    Assert.assertEquals(expected.getResponse().getStatus(), Response.Status.NOT_FOUND.getStatusCode());
    EasyMock.verify(containerRequest);
    EasyMock.verify(supervisorManager);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) SupervisorSpec(org.apache.druid.indexing.overlord.supervisor.SupervisorSpec) Test(org.junit.Test)

Example 7 with SupervisorSpec

use of org.apache.druid.indexing.overlord.supervisor.SupervisorSpec in project druid by druid-io.

the class OverlordSecurityResourceFilterTest method setUp.

@Before
public void setUp() {
    if (resourceFilter instanceof TaskResourceFilter && !mockedOnceTsqa) {
        // Since we are creating the mocked tsqa object only once and getting that object from Guice here therefore
        // if the mockedOnce check is not done then we will call EasyMock.expect and EasyMock.replay on the mocked object
        // multiple times and it will throw exceptions
        tsqa = injector.getInstance(TaskStorageQueryAdapter.class);
        EasyMock.expect(tsqa.getTask(EasyMock.anyString())).andReturn(Optional.of(noopTask)).anyTimes();
        EasyMock.replay(tsqa);
        mockedOnceTsqa = true;
    }
    if (resourceFilter instanceof SupervisorResourceFilter && !mockedOnceSM) {
        supervisorManager = injector.getInstance(SupervisorManager.class);
        SupervisorSpec supervisorSpec = new SupervisorSpec() {

            @Override
            public String getId() {
                return "id";
            }

            @Override
            public Supervisor createSupervisor() {
                return null;
            }

            @Override
            public SupervisorTaskAutoScaler createAutoscaler(Supervisor supervisor) {
                return new NoopTaskAutoScaler();
            }

            @Override
            public List<String> getDataSources() {
                return ImmutableList.of("test");
            }

            @Override
            public SupervisorSpec createSuspendedSpec() {
                return null;
            }

            @Override
            public SupervisorSpec createRunningSpec() {
                return null;
            }

            @Override
            public boolean isSuspended() {
                return false;
            }

            @Override
            public String getType() {
                return null;
            }

            @Override
            public String getSource() {
                return null;
            }
        };
        EasyMock.expect(supervisorManager.getSupervisorSpec(EasyMock.anyString())).andReturn(Optional.of(supervisorSpec)).anyTimes();
        EasyMock.replay(supervisorManager);
        mockedOnceSM = true;
    }
    setUp(resourceFilter);
}
Also used : Supervisor(org.apache.druid.indexing.overlord.supervisor.Supervisor) SupervisorManager(org.apache.druid.indexing.overlord.supervisor.SupervisorManager) NoopTaskAutoScaler(org.apache.druid.indexing.seekablestream.supervisor.autoscaler.NoopTaskAutoScaler) TaskStorageQueryAdapter(org.apache.druid.indexing.overlord.TaskStorageQueryAdapter) SupervisorSpec(org.apache.druid.indexing.overlord.supervisor.SupervisorSpec) Before(org.junit.Before)

Example 8 with SupervisorSpec

use of org.apache.druid.indexing.overlord.supervisor.SupervisorSpec in project druid by druid-io.

the class SQLMetadataSupervisorManager method removeTerminatedSupervisorsOlderThan.

@Override
public int removeTerminatedSupervisorsOlderThan(long timestamp) {
    DateTime dateTime = DateTimes.utc(timestamp);
    Map<String, SupervisorSpec> terminatedSupervisors = getLatestTerminatedOnly();
    return dbi.withHandle(handle -> {
        final PreparedBatch batch = handle.prepareBatch(StringUtils.format("DELETE FROM %1$s WHERE spec_id = :spec_id AND created_date < '%2$s'", getSupervisorsTable(), dateTime.toString()));
        for (Map.Entry<String, SupervisorSpec> supervisor : terminatedSupervisors.entrySet()) {
            batch.bind("spec_id", supervisor.getKey()).add();
        }
        int[] result = batch.execute();
        return IntStream.of(result).sum();
    });
}
Also used : PreparedBatch(org.skife.jdbi.v2.PreparedBatch) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) DateTime(org.joda.time.DateTime) VersionedSupervisorSpec(org.apache.druid.indexing.overlord.supervisor.VersionedSupervisorSpec) SupervisorSpec(org.apache.druid.indexing.overlord.supervisor.SupervisorSpec) NoopSupervisorSpec(org.apache.druid.indexing.overlord.supervisor.NoopSupervisorSpec)

Example 9 with SupervisorSpec

use of org.apache.druid.indexing.overlord.supervisor.SupervisorSpec in project druid by druid-io.

the class TaskResourceFilterTest method testTaskNotFound.

@Test
public void testTaskNotFound() {
    String taskId = "not_exist_task_id";
    expect(containerRequest.getPathSegments()).andReturn(getPathSegments("/task/" + taskId)).anyTimes();
    expect(containerRequest.getMethod()).andReturn("POST").anyTimes();
    SupervisorSpec supervisorSpec = EasyMock.createMock(SupervisorSpec.class);
    expect(supervisorSpec.getDataSources()).andReturn(Collections.singletonList(taskId)).anyTimes();
    expect(taskStorageQueryAdapter.getTask(taskId)).andReturn(Optional.absent()).atLeastOnce();
    EasyMock.replay(containerRequest);
    EasyMock.replay(taskStorageQueryAdapter);
    WebApplicationException expected = null;
    try {
        resourceFilter.filter(containerRequest);
    } catch (WebApplicationException e) {
        expected = e;
    }
    Assert.assertNotNull(expected);
    Assert.assertEquals(expected.getResponse().getStatus(), Response.Status.NOT_FOUND.getStatusCode());
    EasyMock.verify(containerRequest);
    EasyMock.verify(taskStorageQueryAdapter);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) SupervisorSpec(org.apache.druid.indexing.overlord.supervisor.SupervisorSpec) Test(org.junit.Test)

Example 10 with SupervisorSpec

use of org.apache.druid.indexing.overlord.supervisor.SupervisorSpec in project druid by druid-io.

the class KillDatasourceMetadata method run.

@Override
public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams params) {
    long currentTimeMillis = System.currentTimeMillis();
    if ((lastKillTime + period) < currentTimeMillis) {
        lastKillTime = currentTimeMillis;
        long timestamp = currentTimeMillis - retainDuration;
        try {
            // Datasource metadata only exists for datasource with supervisor
            // To determine if datasource metadata is still active, we check if the supervisor for that particular datasource
            // is still active or not
            Map<String, SupervisorSpec> allActiveSupervisor = metadataSupervisorManager.getLatestActiveOnly();
            Set<String> allDatasourceWithActiveSupervisor = allActiveSupervisor.values().stream().map(supervisorSpec -> supervisorSpec.getDataSources()).flatMap(Collection::stream).filter(datasource -> !Strings.isNullOrEmpty(datasource)).collect(Collectors.toSet());
            // We exclude removing datasource metadata with active supervisor
            int datasourceMetadataRemovedCount = indexerMetadataStorageCoordinator.removeDataSourceMetadataOlderThan(timestamp, allDatasourceWithActiveSupervisor);
            ServiceEmitter emitter = params.getEmitter();
            emitter.emit(new ServiceMetricEvent.Builder().build("metadata/kill/datasource/count", datasourceMetadataRemovedCount));
            log.info("Finished running KillDatasourceMetadata duty. Removed %,d datasource metadata", datasourceMetadataRemovedCount);
        } catch (Exception e) {
            log.error(e, "Failed to kill datasource metadata");
        }
    }
    return params;
}
Also used : Logger(org.apache.druid.java.util.common.logger.Logger) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Inject(com.google.inject.Inject) Collection(java.util.Collection) DruidCoordinatorRuntimeParams(org.apache.druid.server.coordinator.DruidCoordinatorRuntimeParams) Set(java.util.Set) Collectors(java.util.stream.Collectors) SupervisorSpec(org.apache.druid.indexing.overlord.supervisor.SupervisorSpec) Strings(com.google.common.base.Strings) MetadataSupervisorManager(org.apache.druid.metadata.MetadataSupervisorManager) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) DruidCoordinatorConfig(org.apache.druid.server.coordinator.DruidCoordinatorConfig) Map(java.util.Map) IndexerMetadataStorageCoordinator(org.apache.druid.indexing.overlord.IndexerMetadataStorageCoordinator) Preconditions(com.google.common.base.Preconditions) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) Collection(java.util.Collection) SupervisorSpec(org.apache.druid.indexing.overlord.supervisor.SupervisorSpec)

Aggregations

SupervisorSpec (org.apache.druid.indexing.overlord.supervisor.SupervisorSpec)11 Test (org.junit.Test)6 NoopSupervisorSpec (org.apache.druid.indexing.overlord.supervisor.NoopSupervisorSpec)5 VersionedSupervisorSpec (org.apache.druid.indexing.overlord.supervisor.VersionedSupervisorSpec)5 WebApplicationException (javax.ws.rs.WebApplicationException)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 Map (java.util.Map)2 Access (org.apache.druid.server.security.Access)2 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Inject (com.google.inject.Inject)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 PathSegment (javax.ws.rs.core.PathSegment)1 IndexerMetadataStorageCoordinator (org.apache.druid.indexing.overlord.IndexerMetadataStorageCoordinator)1