Search in sources :

Example 1 with SupervisorSpec

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

the class SQLMetadataSupervisorManagerTest method testRemoveTerminatedSupervisorsOlderThanWithSupervisorTerminatedAndOlderThanTimeShouldBeDeleted.

@Test
public void testRemoveTerminatedSupervisorsOlderThanWithSupervisorTerminatedAndOlderThanTimeShouldBeDeleted() {
    final String supervisor1 = "test-supervisor-1";
    final String datasource1 = "datasource-1";
    final Map<String, String> data1rev1 = ImmutableMap.of("key1-1", "value1-1-1", "key1-2", "value1-2-1");
    Assert.assertTrue(supervisorManager.getAll().isEmpty());
    supervisorManager.insert(supervisor1, new TestSupervisorSpec(supervisor1, data1rev1));
    supervisorManager.insert(supervisor1, new NoopSupervisorSpec(supervisor1, ImmutableList.of(datasource1)));
    // Test that supervisor was inserted
    Map<String, List<VersionedSupervisorSpec>> supervisorSpecs = supervisorManager.getAll();
    Assert.assertEquals(1, supervisorSpecs.size());
    Assert.assertEquals(2, supervisorSpecs.get(supervisor1).size());
    Map<String, SupervisorSpec> latestSpecs = supervisorManager.getLatest();
    Assert.assertEquals(1, latestSpecs.size());
    Assert.assertEquals(ImmutableList.of(datasource1), ((NoopSupervisorSpec) latestSpecs.get(supervisor1)).getDataSources());
    // Do delete. Supervisor should be deleted as it is terminated
    int deleteCount = supervisorManager.removeTerminatedSupervisorsOlderThan(System.currentTimeMillis());
    // Verify that supervisor was actually deleted
    Assert.assertEquals(2, deleteCount);
    supervisorSpecs = supervisorManager.getAll();
    Assert.assertEquals(0, supervisorSpecs.size());
    latestSpecs = supervisorManager.getLatest();
    Assert.assertEquals(0, latestSpecs.size());
}
Also used : NoopSupervisorSpec(org.apache.druid.indexing.overlord.supervisor.NoopSupervisorSpec) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) VersionedSupervisorSpec(org.apache.druid.indexing.overlord.supervisor.VersionedSupervisorSpec) SupervisorSpec(org.apache.druid.indexing.overlord.supervisor.SupervisorSpec) NoopSupervisorSpec(org.apache.druid.indexing.overlord.supervisor.NoopSupervisorSpec) Test(org.junit.Test)

Example 2 with SupervisorSpec

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

the class SQLMetadataSupervisorManagerTest method testGetLatestActiveOnly.

@Test
public void testGetLatestActiveOnly() {
    final String supervisor1 = "test-supervisor-1";
    final String datasource1 = "datasource-1";
    final String supervisor2 = "test-supervisor-2";
    final Map<String, String> data1rev1 = ImmutableMap.of("key1-1", "value1-1-1", "key1-2", "value1-2-1");
    Assert.assertTrue(supervisorManager.getAll().isEmpty());
    supervisorManager.insert(supervisor1, new TestSupervisorSpec(supervisor1, data1rev1));
    // supervisor1 is terminated
    supervisorManager.insert(supervisor1, new NoopSupervisorSpec(supervisor1, ImmutableList.of(datasource1)));
    // supervisor2 is still active
    supervisorManager.insert(supervisor2, new TestSupervisorSpec(supervisor2, data1rev1));
    // get latest active should only return supervisor2
    Map<String, SupervisorSpec> actual = supervisorManager.getLatestActiveOnly();
    Assert.assertEquals(1, actual.size());
    Assert.assertTrue(actual.containsKey(supervisor2));
}
Also used : NoopSupervisorSpec(org.apache.druid.indexing.overlord.supervisor.NoopSupervisorSpec) VersionedSupervisorSpec(org.apache.druid.indexing.overlord.supervisor.VersionedSupervisorSpec) SupervisorSpec(org.apache.druid.indexing.overlord.supervisor.SupervisorSpec) NoopSupervisorSpec(org.apache.druid.indexing.overlord.supervisor.NoopSupervisorSpec) Test(org.junit.Test)

Example 3 with SupervisorSpec

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

the class SQLMetadataSupervisorManagerTest method testRemoveTerminatedSupervisorsOlderThanWithSupervisorTerminatedButNotOlderThanTimeShouldNotBeDeleted.

@Test
public void testRemoveTerminatedSupervisorsOlderThanWithSupervisorTerminatedButNotOlderThanTimeShouldNotBeDeleted() {
    final String supervisor1 = "test-supervisor-1";
    final String datasource1 = "datasource-1";
    final Map<String, String> data1rev1 = ImmutableMap.of("key1-1", "value1-1-1", "key1-2", "value1-2-1");
    Assert.assertTrue(supervisorManager.getAll().isEmpty());
    supervisorManager.insert(supervisor1, new TestSupervisorSpec(supervisor1, data1rev1));
    supervisorManager.insert(supervisor1, new NoopSupervisorSpec(supervisor1, ImmutableList.of(datasource1)));
    // Test that supervisor was inserted
    Map<String, List<VersionedSupervisorSpec>> supervisorSpecs = supervisorManager.getAll();
    Assert.assertEquals(1, supervisorSpecs.size());
    Assert.assertEquals(2, supervisorSpecs.get(supervisor1).size());
    Map<String, SupervisorSpec> latestSpecs = supervisorManager.getLatest();
    Assert.assertEquals(1, latestSpecs.size());
    Assert.assertEquals(ImmutableList.of(datasource1), ((NoopSupervisorSpec) latestSpecs.get(supervisor1)).getDataSources());
    // Do delete. Supervisor should not be deleted. Supervisor is terminated but it was created just now so it's
    // created timestamp will be later than the timestamp 2012-01-01T00:00:00Z
    int deleteCount = supervisorManager.removeTerminatedSupervisorsOlderThan(DateTimes.of("2012-01-01T00:00:00Z").getMillis());
    // Verify that supervisor was not deleted
    Assert.assertEquals(0, deleteCount);
    supervisorSpecs = supervisorManager.getAll();
    Assert.assertEquals(1, supervisorSpecs.size());
    Assert.assertEquals(2, supervisorSpecs.get(supervisor1).size());
    latestSpecs = supervisorManager.getLatest();
    Assert.assertEquals(1, latestSpecs.size());
    Assert.assertEquals(ImmutableList.of(datasource1), ((NoopSupervisorSpec) latestSpecs.get(supervisor1)).getDataSources());
}
Also used : NoopSupervisorSpec(org.apache.druid.indexing.overlord.supervisor.NoopSupervisorSpec) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) VersionedSupervisorSpec(org.apache.druid.indexing.overlord.supervisor.VersionedSupervisorSpec) SupervisorSpec(org.apache.druid.indexing.overlord.supervisor.SupervisorSpec) NoopSupervisorSpec(org.apache.druid.indexing.overlord.supervisor.NoopSupervisorSpec) Test(org.junit.Test)

Example 4 with SupervisorSpec

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

the class SupervisorResourceFilter method filter.

@Override
public ContainerRequest filter(ContainerRequest request) {
    final String supervisorId = Preconditions.checkNotNull(request.getPathSegments().get(Iterables.indexOf(request.getPathSegments(), new Predicate<PathSegment>() {

        @Override
        public boolean apply(PathSegment input) {
            return "supervisor".equals(input.getPath());
        }
    }) + 1).getPath());
    Optional<SupervisorSpec> supervisorSpecOptional = supervisorManager.getSupervisorSpec(supervisorId);
    if (!supervisorSpecOptional.isPresent()) {
        throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity(StringUtils.format("Cannot find any supervisor with id: [%s]", supervisorId)).build());
    }
    final SupervisorSpec spec = supervisorSpecOptional.get();
    Preconditions.checkArgument(spec.getDataSources() != null && spec.getDataSources().size() > 0, "No dataSources found to perform authorization checks");
    Function<String, ResourceAction> resourceActionFunction = getAction(request) == Action.READ ? AuthorizationUtils.DATASOURCE_READ_RA_GENERATOR : AuthorizationUtils.DATASOURCE_WRITE_RA_GENERATOR;
    Access authResult = AuthorizationUtils.authorizeAllResourceActions(getReq(), Iterables.transform(spec.getDataSources(), resourceActionFunction), getAuthorizerMapper());
    if (!authResult.isAllowed()) {
        throw new ForbiddenException(authResult.toString());
    }
    return request;
}
Also used : ForbiddenException(org.apache.druid.server.security.ForbiddenException) WebApplicationException(javax.ws.rs.WebApplicationException) Access(org.apache.druid.server.security.Access) PathSegment(javax.ws.rs.core.PathSegment) SupervisorSpec(org.apache.druid.indexing.overlord.supervisor.SupervisorSpec) ResourceAction(org.apache.druid.server.security.ResourceAction)

Example 5 with SupervisorSpec

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

the class SupervisorResourceFilterTest method setExpectations.

private void setExpectations(String path, String requestMethod, String datasource, Action expectedAction, boolean userHasAccess) {
    expect(containerRequest.getPathSegments()).andReturn(getPathSegments(path)).anyTimes();
    expect(containerRequest.getMethod()).andReturn(requestMethod).anyTimes();
    SupervisorSpec supervisorSpec = EasyMock.createMock(SupervisorSpec.class);
    expect(supervisorSpec.getDataSources()).andReturn(Collections.singletonList(datasource)).anyTimes();
    expect(supervisorManager.getSupervisorSpec(datasource)).andReturn(Optional.of(supervisorSpec)).atLeastOnce();
    HttpServletRequest servletRequest = EasyMock.createMock(HttpServletRequest.class);
    expect(servletRequest.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes();
    expect(servletRequest.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).anyTimes();
    servletRequest.setAttribute(isA(String.class), anyObject());
    final String authorizerName = "authorizer";
    AuthenticationResult authResult = EasyMock.createMock(AuthenticationResult.class);
    expect(authResult.getAuthorizerName()).andReturn(authorizerName).anyTimes();
    Authorizer authorizer = EasyMock.createMock(Authorizer.class);
    expect(authorizer.authorize(authResult, new Resource(datasource, ResourceType.DATASOURCE), expectedAction)).andReturn(new Access(userHasAccess)).anyTimes();
    expect(authorizerMapper.getAuthorizer(authorizerName)).andReturn(authorizer).atLeastOnce();
    expect(servletRequest.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(authResult).atLeastOnce();
    resourceFilter.setReq(servletRequest);
    mocksToVerify = Arrays.asList(authorizerMapper, supervisorSpec, supervisorManager, servletRequest, authorizer, authResult, containerRequest);
    replayMocks();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Authorizer(org.apache.druid.server.security.Authorizer) Resource(org.apache.druid.server.security.Resource) Access(org.apache.druid.server.security.Access) SupervisorSpec(org.apache.druid.indexing.overlord.supervisor.SupervisorSpec) AuthenticationResult(org.apache.druid.server.security.AuthenticationResult)

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