use of com.datatorrent.stram.api.ContainerEvent.StreamActivationEvent in project apex-core by apache.
the class StreamingContainer method activate.
public synchronized void activate(final Map<Integer, OperatorDeployInfo> nodeMap, Map<String, ComponentContextPair<Stream, StreamContext>> newStreams) {
for (ComponentContextPair<Stream, StreamContext> pair : newStreams.values()) {
activeStreams.put(pair.component, pair.context);
pair.component.activate(pair.context);
eventBus.publish(new StreamActivationEvent(pair));
}
for (final OperatorDeployInfo ndi : nodeMap.values()) {
/*
* OiO nodes get activated with their primary nodes.
*/
if (ndi.type == OperatorType.OIO) {
continue;
}
final Node<?> node = nodes.get(ndi.id);
final String name = new StringBuilder(Integer.toString(ndi.id)).append('/').append(ndi.name).append(':').append(node.getOperator().getClass().getSimpleName()).toString();
final Thread thread = new Thread(name) {
@Override
public void run() {
HashSet<OperatorDeployInfo> setOperators = new HashSet<>();
OperatorDeployInfo currentdi = ndi;
try {
/* primary operator initialization */
setupNode(currentdi);
setOperators.add(currentdi);
/* lets go for OiO operator initialization */
List<Integer> oioNodeIdList = oioGroups.get(ndi.id);
if (oioNodeIdList != null) {
for (Integer oioNodeId : oioNodeIdList) {
currentdi = nodeMap.get(oioNodeId);
setupNode(currentdi);
setOperators.add(currentdi);
}
}
currentdi = null;
node.run();
/* this is a blocking call */
} catch (Error error) {
int[] operators;
//fetch logFileInfo before logging exception, to get offset before exception
LogFileInformation logFileInfo = LoggerUtil.getLogFileInformation();
if (currentdi == null) {
logger.error("Voluntary container termination due to an error in operator set {}.", setOperators, error);
operators = new int[setOperators.size()];
int i = 0;
for (Iterator<OperatorDeployInfo> it = setOperators.iterator(); it.hasNext(); i++) {
operators[i] = it.next().id;
}
} else {
logger.error("Voluntary container termination due to an error in operator {}.", currentdi, error);
operators = new int[] { currentdi.id };
}
try {
umbilical.reportError(containerId, operators, "Voluntary container termination due to an error. " + ExceptionUtils.getStackTrace(error), logFileInfo);
} catch (Exception e) {
logger.debug("Fail to log", e);
} finally {
System.exit(1);
}
} catch (Exception ex) {
//fetch logFileInfo before logging exception, to get offset before exception
LogFileInformation logFileInfo = LoggerUtil.getLogFileInformation();
if (currentdi == null) {
failedNodes.add(ndi.id);
logger.error("Operator set {} stopped running due to an exception.", setOperators, ex);
int[] operators = new int[] { ndi.id };
try {
umbilical.reportError(containerId, operators, "Stopped running due to an exception. " + ExceptionUtils.getStackTrace(ex), logFileInfo);
} catch (Exception e) {
logger.debug("Fail to log", e);
}
} else {
failedNodes.add(currentdi.id);
logger.error("Abandoning deployment of operator {} due to setup failure.", currentdi, ex);
int[] operators = new int[] { currentdi.id };
try {
umbilical.reportError(containerId, operators, "Abandoning deployment due to setup failure. " + ExceptionUtils.getStackTrace(ex), logFileInfo);
} catch (Exception e) {
logger.debug("Fail to log", e);
}
}
} finally {
if (setOperators.contains(ndi)) {
try {
teardownNode(ndi);
} catch (Exception ex) {
failedNodes.add(ndi.id);
logger.error("Shutdown of operator {} failed due to an exception.", ndi, ex);
}
}
List<Integer> oioNodeIdList = oioGroups.get(ndi.id);
if (oioNodeIdList != null) {
for (Integer oioNodeId : oioNodeIdList) {
OperatorDeployInfo oiodi = nodeMap.get(oioNodeId);
if (setOperators.contains(oiodi)) {
try {
teardownNode(oiodi);
} catch (Exception ex) {
failedNodes.add(oiodi.id);
logger.error("Shutdown of operator {} failed due to an exception.", oiodi, ex);
}
}
}
}
}
}
};
node.context.setThread(thread);
List<Integer> oioNodeIdList = oioGroups.get(ndi.id);
if (oioNodeIdList != null) {
for (Integer oioNodeId : oioNodeIdList) {
Node<?> oioNode = nodes.get(oioNodeId);
oioNode.context.setThread(thread);
}
}
thread.start();
}
for (WindowGenerator wg : generators.values()) {
if (!activeGenerators.containsKey(wg)) {
activeGenerators.put(wg, generators);
wg.activate(null);
}
}
}
Aggregations