use of org.apache.tez.common.security.HistoryACLPolicyManager in project tez by apache.
the class TestATSHistoryLoggingService method setup.
@Before
public void setup() throws Exception {
appContext = mock(AppContext.class);
historyACLPolicyManager = mock(HistoryACLPolicyManager.class);
atsHistoryLoggingService = new ATSHistoryLoggingService();
atsHistoryLoggingService.setAppContext(appContext);
conf = new Configuration(false);
conf.setLong(TezConfiguration.YARN_ATS_EVENT_FLUSH_TIMEOUT_MILLIS, 1000l);
conf.setInt(TezConfiguration.YARN_ATS_MAX_EVENTS_PER_BATCH, 2);
conf.setBoolean(TezConfiguration.TEZ_AM_ALLOW_DISABLED_TIMELINE_DOMAINS, true);
conf.set(TezConfiguration.YARN_ATS_ACL_SESSION_DOMAIN_ID, "test-domain");
atsInvokeCounter = 0;
atsEntitiesCounter = 0;
atsHistoryLoggingService.init(conf);
atsHistoryLoggingService.historyACLPolicyManager = historyACLPolicyManager;
atsHistoryLoggingService.timelineClient = mock(TimelineClient.class);
when(appContext.getClock()).thenReturn(clock);
when(appContext.getCurrentDAGID()).thenReturn(null);
when(appContext.getApplicationID()).thenReturn(appId);
when(atsHistoryLoggingService.timelineClient.putEntities(Matchers.<TimelineEntity[]>anyVararg())).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
++atsInvokeCounter;
atsEntitiesCounter += invocation.getArguments().length;
try {
Thread.sleep(500l);
} catch (InterruptedException e) {
// do nothing
}
return null;
}
});
}
use of org.apache.tez.common.security.HistoryACLPolicyManager in project tez by apache.
the class TestATSV15HistoryLoggingService method testNonSessionDomainsFailed.
@Test
public void testNonSessionDomainsFailed() throws Exception {
ATSV15HistoryLoggingService service = createService(-1);
HistoryACLPolicyManager historyACLPolicyManager = mock(HistoryACLPolicyManager.class);
service.historyACLPolicyManager = historyACLPolicyManager;
when(historyACLPolicyManager.setupSessionACLs((Configuration) any(), eq(appId))).thenThrow(new IOException());
service.start();
verify(historyACLPolicyManager, times(1)).setupSessionACLs((Configuration) any(), eq(appId));
// Send the event and wait for completion.
TezDAGID dagId1 = TezDAGID.getInstance(appId, 0);
for (DAGHistoryEvent event : makeHistoryEvents(dagId1, service)) {
service.handle(event);
}
while (!service.eventQueue.isEmpty()) {
Thread.sleep(100);
}
// No dag domain were created.
verify(historyACLPolicyManager, times(0)).setupSessionDAGACLs((Configuration) any(), eq(appId), eq("0"), (DAGAccessControls) any());
// History logging is disabled.
verify(historyACLPolicyManager, times(0)).updateTimelineEntityDomain(any(), (String) any());
assertEquals(0, entityLog.size());
service.stop();
}
use of org.apache.tez.common.security.HistoryACLPolicyManager in project tez by apache.
the class TestATSV15HistoryLoggingService method testSessionDomainsFailed.
@Test
public void testSessionDomainsFailed() throws Exception {
ATSV15HistoryLoggingService service = createService(-1);
when(appContext.isSession()).thenReturn(true);
HistoryACLPolicyManager historyACLPolicyManager = mock(HistoryACLPolicyManager.class);
service.historyACLPolicyManager = historyACLPolicyManager;
when(historyACLPolicyManager.setupSessionACLs((Configuration) any(), eq(appId))).thenThrow(new IOException());
service.start();
// Verify that the session domain was created.
verify(historyACLPolicyManager, times(1)).setupSessionACLs((Configuration) any(), eq(appId));
// Mock dag domain creation.
when(historyACLPolicyManager.setupSessionDAGACLs((Configuration) any(), eq(appId), eq("0"), (DAGAccessControls) any())).thenReturn(Collections.singletonMap(TezConfiguration.YARN_ATS_ACL_DAG_DOMAIN_ID, "dag-id"));
// Send the event and wait for completion.
TezDAGID dagId1 = TezDAGID.getInstance(appId, 0);
for (DAGHistoryEvent event : makeHistoryEvents(dagId1, service)) {
service.handle(event);
}
while (!service.eventQueue.isEmpty()) {
Thread.sleep(100);
}
// No dag creation was done.
verify(historyACLPolicyManager, times(0)).setupSessionDAGACLs((Configuration) any(), eq(appId), eq("0"), (DAGAccessControls) any());
// No history logging calls were done
verify(historyACLPolicyManager, times(0)).updateTimelineEntityDomain(any(), (String) any());
assertEquals(0, entityLog.size());
service.stop();
}
use of org.apache.tez.common.security.HistoryACLPolicyManager in project tez by apache.
the class TestATSV15HistoryLoggingService method testSessionDomainsDagFailed.
@Test
public void testSessionDomainsDagFailed() throws Exception {
ATSV15HistoryLoggingService service = createService(-1);
when(appContext.isSession()).thenReturn(true);
HistoryACLPolicyManager historyACLPolicyManager = mock(HistoryACLPolicyManager.class);
service.historyACLPolicyManager = historyACLPolicyManager;
when(historyACLPolicyManager.setupSessionACLs((Configuration) any(), eq(appId))).thenReturn(Collections.singletonMap(TezConfiguration.YARN_ATS_ACL_SESSION_DOMAIN_ID, "session-id"));
service.start();
// Verify that the session domain creation was called.
verify(historyACLPolicyManager, times(1)).setupSessionACLs((Configuration) any(), eq(appId));
// Mock dag domain creation.
when(historyACLPolicyManager.setupSessionDAGACLs((Configuration) any(), eq(appId), eq("0"), (DAGAccessControls) any())).thenThrow(new IOException());
// Send the event and wait for completion.
TezDAGID dagId1 = TezDAGID.getInstance(appId, 0);
for (DAGHistoryEvent event : makeHistoryEvents(dagId1, service)) {
service.handle(event);
}
while (!service.eventQueue.isEmpty()) {
Thread.sleep(100);
}
// Verify dag domain creation was called.
verify(historyACLPolicyManager, times(1)).setupSessionDAGACLs((Configuration) any(), eq(appId), eq("0"), (DAGAccessControls) any());
// AM events sent, dag events are not sent.
verify(historyACLPolicyManager, times(1)).updateTimelineEntityDomain(any(), eq("session-id"));
verify(historyACLPolicyManager, times(0)).updateTimelineEntityDomain(any(), eq("dag-id"));
assertEquals(1, entityLog.size());
service.stop();
}
use of org.apache.tez.common.security.HistoryACLPolicyManager in project tez by apache.
the class TestATSV15HistoryLoggingService method testSessionDomains.
@Test
public void testSessionDomains() throws Exception {
ATSV15HistoryLoggingService service = createService(-1);
when(appContext.isSession()).thenReturn(true);
HistoryACLPolicyManager historyACLPolicyManager = mock(HistoryACLPolicyManager.class);
service.historyACLPolicyManager = historyACLPolicyManager;
when(historyACLPolicyManager.setupSessionACLs((Configuration) any(), eq(appId))).thenReturn(Collections.singletonMap(TezConfiguration.YARN_ATS_ACL_SESSION_DOMAIN_ID, "session-id"));
service.start();
// Verify that the session domain was created.
verify(historyACLPolicyManager, times(1)).setupSessionACLs((Configuration) any(), eq(appId));
// Mock dag domain creation.
when(historyACLPolicyManager.setupSessionDAGACLs((Configuration) any(), eq(appId), eq("0"), (DAGAccessControls) any())).thenReturn(Collections.singletonMap(TezConfiguration.YARN_ATS_ACL_DAG_DOMAIN_ID, "dag-id"));
// Send the event and wait for completion.
TezDAGID dagId1 = TezDAGID.getInstance(appId, 0);
for (DAGHistoryEvent event : makeHistoryEvents(dagId1, service)) {
service.handle(event);
}
while (!service.eventQueue.isEmpty()) {
Thread.sleep(100);
}
// Verify dag domain was created.
verify(historyACLPolicyManager, times(1)).setupSessionDAGACLs((Configuration) any(), eq(appId), eq("0"), (DAGAccessControls) any());
// calls were made with correct domain ids.
verify(historyACLPolicyManager, times(1)).updateTimelineEntityDomain(any(), eq("session-id"));
verify(historyACLPolicyManager, times(5)).updateTimelineEntityDomain(any(), eq("dag-id"));
service.stop();
}
Aggregations