use of org.apache.tez.dag.history.DAGHistoryEvent in project tez by apache.
the class TestATSHistoryWithACLs method testDagLoggingDisabled.
/**
* use mini cluster to verify data do not push to ats when the daglogging flag
* in dagsubmittedevent is set off
* @throws Exception
*/
@Test(timeout = 50000)
public void testDagLoggingDisabled() throws Exception {
ATSHistoryLoggingService historyLoggingService;
historyLoggingService = ReflectionUtils.createClazzInstance(ATSHistoryLoggingService.class.getName());
AppContext appContext = mock(AppContext.class);
when(appContext.getApplicationID()).thenReturn(ApplicationId.newInstance(0, 1));
historyLoggingService.setAppContext(appContext);
TezConfiguration tezConf = new TezConfiguration(mrrTezCluster.getConfig());
String viewAcls = "nobody nobody_group";
tezConf.set(TezConfiguration.TEZ_AM_VIEW_ACLS, viewAcls);
tezConf.set(TezConfiguration.TEZ_HISTORY_LOGGING_SERVICE_CLASS, ATSHistoryLoggingService.class.getName());
Path remoteStagingDir = remoteFs.makeQualified(new Path("/tmp", String.valueOf(random.nextInt(100000))));
remoteFs.mkdirs(remoteStagingDir);
tezConf.set(TezConfiguration.TEZ_AM_STAGING_DIR, remoteStagingDir.toString());
historyLoggingService.init(tezConf);
historyLoggingService.start();
ApplicationId appId = ApplicationId.newInstance(100l, 1);
TezDAGID tezDAGID = TezDAGID.getInstance(appId, 100);
ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
DAGPlan dagPlan = DAGPlan.newBuilder().setName("DAGPlanMock").build();
DAGSubmittedEvent submittedEvent = new DAGSubmittedEvent(tezDAGID, 1, dagPlan, appAttemptId, null, "usr", tezConf, null, null);
submittedEvent.setHistoryLoggingEnabled(false);
DAGHistoryEvent event = new DAGHistoryEvent(tezDAGID, submittedEvent);
historyLoggingService.handle(new DAGHistoryEvent(tezDAGID, submittedEvent));
Thread.sleep(1000l);
String url = "http://" + timelineAddress + "/ws/v1/timeline/TEZ_DAG_ID/" + event.getDagID();
Client client = new Client();
WebResource resource = client.resource(url);
ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(404, response.getStatus());
}
use of org.apache.tez.dag.history.DAGHistoryEvent in project tez by apache.
the class ATSV15HistoryLoggingService method getDomainForEvent.
private String getDomainForEvent(DAGHistoryEvent event) {
String domainId = sessionDomainId;
if (historyACLPolicyManager == null) {
return domainId;
}
TezDAGID dagId = event.getDagID();
HistoryEvent historyEvent = event.getHistoryEvent();
if (dagId == null || !HistoryEventType.isDAGSpecificEvent(historyEvent.getEventType())) {
return domainId;
}
if (dagDomainIdMap.containsKey(dagId)) {
// If we already have the domain for the dag id return it
domainId = dagDomainIdMap.get(dagId);
// Cleanup if this is the last event.
if (historyEvent.getEventType() == HistoryEventType.DAG_FINISHED) {
dagDomainIdMap.remove(dagId);
}
} else if (HistoryEventType.DAG_SUBMITTED == historyEvent.getEventType() || HistoryEventType.DAG_RECOVERED == historyEvent.getEventType()) {
// In case this is the first event for the dag, create and populate dag domain.
Configuration conf;
DAGPlan dagPlan;
if (HistoryEventType.DAG_SUBMITTED == historyEvent.getEventType()) {
conf = ((DAGSubmittedEvent) historyEvent).getConf();
dagPlan = ((DAGSubmittedEvent) historyEvent).getDAGPlan();
} else {
conf = appContext.getCurrentDAG().getConf();
dagPlan = appContext.getCurrentDAG().getJobPlan();
}
domainId = createDagDomain(conf, dagPlan, dagId);
// createDagDomain updates skippedDAGs so another check here.
if (skippedDAGs.contains(dagId)) {
return null;
}
dagDomainIdMap.put(dagId, domainId);
}
return domainId;
}
use of org.apache.tez.dag.history.DAGHistoryEvent in project tez by apache.
the class TestATSV15HistoryLoggingService method makeHistoryEvents.
private List<DAGHistoryEvent> makeHistoryEvents(TezDAGID dagId, ATSV15HistoryLoggingService service) {
List<DAGHistoryEvent> historyEvents = new ArrayList<>();
long time = System.currentTimeMillis();
Configuration conf = new Configuration(service.getConfig());
historyEvents.add(new DAGHistoryEvent(null, new AMStartedEvent(attemptId, time, user)));
historyEvents.add(new DAGHistoryEvent(dagId, new DAGSubmittedEvent(dagId, time, DAGPlan.getDefaultInstance(), attemptId, null, user, conf, null, "default")));
TezVertexID vertexID = TezVertexID.getInstance(dagId, 1);
historyEvents.add(new DAGHistoryEvent(dagId, new VertexStartedEvent(vertexID, time, time)));
TezTaskID tezTaskID = TezTaskID.getInstance(vertexID, 1);
historyEvents.add(new DAGHistoryEvent(dagId, new TaskStartedEvent(tezTaskID, "test", time, time)));
historyEvents.add(new DAGHistoryEvent(dagId, new TaskAttemptStartedEvent(TezTaskAttemptID.getInstance(tezTaskID, 1), "test", time, ContainerId.newContainerId(attemptId, 1), NodeId.newInstance("localhost", 8765), null, null, null)));
return historyEvents;
}
use of org.apache.tez.dag.history.DAGHistoryEvent 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.dag.history.DAGHistoryEvent 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();
}
Aggregations