forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JobFailurePatternExecutor.java
138 lines (102 loc) · 4.26 KB
/
JobFailurePatternExecutor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/***********************************************************************************************************************
*
* Copyright (C) 2010 by the Stratosphere project (https://stratosphere.eu)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
**********************************************************************************************************************/
package eu.stratosphere.addons.visualization.swt;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.widgets.Display;
import eu.stratosphere.core.io.StringRecord;
import eu.stratosphere.nephele.jobgraph.JobID;
import eu.stratosphere.nephele.managementgraph.ManagementGraph;
import eu.stratosphere.nephele.managementgraph.ManagementGraphIterator;
import eu.stratosphere.nephele.managementgraph.ManagementVertex;
import eu.stratosphere.nephele.managementgraph.ManagementVertexID;
import eu.stratosphere.nephele.protocols.ExtendedManagementProtocol;
import eu.stratosphere.util.StringUtils;
public final class JobFailurePatternExecutor implements Runnable {
private static final Log LOG = LogFactory.getLog(JobFailurePatternExecutor.class);
private final Display timer;
private final JobID jobID;
private final ExtendedManagementProtocol jobManager;
private final Map<String, ManagementVertexID> nameToIDMap;
private final Iterator<AbstractFailureEvent> eventIterator;
private final int offset;
private AbstractFailureEvent nextEvent = null;
private boolean stopRequested = false;
JobFailurePatternExecutor(final Display timer, final ExtendedManagementProtocol jobManager,
final ManagementGraph managementGraph, final JobFailurePattern failurePattern, final long referenceTime) {
this.timer = timer;
this.jobManager = jobManager;
this.jobID = managementGraph.getJobID();
final long now = System.currentTimeMillis();
this.offset = (int) (now - referenceTime);
final Map<String, ManagementVertexID> tmpMap = new HashMap<String, ManagementVertexID>();
final Iterator<ManagementVertex> it = new ManagementGraphIterator(managementGraph, true);
while (it.hasNext()) {
final ManagementVertex vertex = it.next();
tmpMap.put(SWTFailurePatternsManager.getSuggestedName(vertex), vertex.getID());
}
this.nameToIDMap = Collections.unmodifiableMap(tmpMap);
this.eventIterator = failurePattern.iterator();
scheduleNextEvent();
}
@Override
public void run() {
if (this.stopRequested) {
LOG.info("Stopping job failure pattern executor for job " + this.jobID);
this.stopRequested = false;
return;
}
LOG.info("Triggering event " + this.nextEvent.getName() + " for job " + this.jobID);
if (this.nextEvent instanceof VertexFailureEvent) {
// Find out the ID of the vertex to be killed
final ManagementVertexID vertexID = this.nameToIDMap.get(this.nextEvent.getName());
if (vertexID == null) {
LOG.error("Cannot determine ID for vertex " + this.nextEvent.getName());
} else {
try {
this.jobManager.killTask(this.jobID, vertexID);
} catch (IOException ioe) {
LOG.error(StringUtils.stringifyException(ioe));
}
}
} else {
try {
this.jobManager.killInstance(new StringRecord(this.nextEvent.getName()));
} catch (IOException ioe) {
LOG.error(StringUtils.stringifyException(ioe));
}
}
// Schedule next event
scheduleNextEvent();
}
public void stop() {
this.stopRequested = true;
}
private void scheduleNextEvent() {
if (this.eventIterator.hasNext()) {
this.nextEvent = this.eventIterator.next();
} else {
this.nextEvent = null;
return;
}
final int interval = this.nextEvent.getInterval() - this.offset;
this.timer.timerExec(interval, this);
}
}