Search in sources :

Example 1 with LogFileInformation

use of org.apache.apex.log.LogFileInformation 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);
        }
    }
}
Also used : OperatorDeployInfo(com.datatorrent.stram.api.OperatorDeployInfo) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) StreamActivationEvent(com.datatorrent.stram.api.ContainerEvent.StreamActivationEvent) LogFileInformation(org.apache.apex.log.LogFileInformation) Iterator(java.util.Iterator) OiOStream(com.datatorrent.stram.stream.OiOStream) InlineStream(com.datatorrent.stram.stream.InlineStream) MuxStream(com.datatorrent.stram.stream.MuxStream) HashSet(java.util.HashSet)

Example 2 with LogFileInformation

use of org.apache.apex.log.LogFileInformation in project apex-core by apache.

the class StreamingContainer method main.

/**
   * Initialize container. Establishes heartbeat connection to the master
   * distribute through the callback address provided on the command line. Deploys
   * initial modules, then enters the heartbeat loop, which will only terminate
   * once container receives shutdown request from the master. On shutdown,
   * after exiting heartbeat loop, shutdown all modules and terminate
   * processing threads.
   *
   * @param args
   * @throws Throwable
   */
public static void main(String[] args) throws Throwable {
    StdOutErrLog.tieSystemOutAndErrToLog();
    logger.debug("PID: " + System.getenv().get("JVM_PID"));
    logger.info("Child starting with classpath: {}", System.getProperty("java.class.path"));
    String appPath = System.getProperty(PROP_APP_PATH);
    if (appPath == null) {
        logger.error("{} not set in container environment.", PROP_APP_PATH);
        System.exit(1);
    }
    // interpreted as unrecoverable container failure
    int exitStatus = 1;
    RecoverableRpcProxy rpcProxy = null;
    StreamingContainerUmbilicalProtocol umbilical = null;
    final String childId = System.getProperty(StreamingApplication.DT_PREFIX + "cid");
    try {
        rpcProxy = new RecoverableRpcProxy(appPath, new Configuration());
        umbilical = rpcProxy.getProxy();
        StreamingContainerContext ctx = umbilical.getInitContext(childId);
        StreamingContainer stramChild = new StreamingContainer(childId, umbilical);
        logger.debug("Container Context = {}", ctx);
        stramChild.setup(ctx);
        try {
            /* main thread enters heartbeat loop */
            stramChild.heartbeatLoop();
            exitStatus = 0;
        } finally {
            stramChild.teardown();
        }
    } catch (Error | Exception e) {
        LogFileInformation logFileInfo = LoggerUtil.getLogFileInformation();
        logger.error("Fatal {} in container!", (e instanceof Error) ? "Error" : "Exception", e);
        /* Report back any failures, for diagnostic purposes */
        try {
            umbilical.reportError(childId, null, ExceptionUtils.getStackTrace(e), logFileInfo);
        } catch (Exception ex) {
            logger.debug("Fail to log", ex);
        }
    } finally {
        if (rpcProxy != null) {
            rpcProxy.close();
        }
        DefaultMetricsSystem.shutdown();
        logger.info("Exit status for container: {}", exitStatus);
        LogManager.shutdown();
        if (exitStatus != 0) {
            System.exit(exitStatus);
        }
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) BusConfiguration(net.engio.mbassy.bus.config.BusConfiguration) LogFileInformation(org.apache.apex.log.LogFileInformation) StreamingContainerContext(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.StreamingContainerContext) RecoverableRpcProxy(com.datatorrent.stram.RecoverableRpcProxy) StreamingContainerUmbilicalProtocol(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol) Checkpoint(com.datatorrent.stram.api.Checkpoint) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 3 with LogFileInformation

use of org.apache.apex.log.LogFileInformation in project apex-core by apache.

the class LoggerUtil method getLogFileInformation.

/**
   * Returns logger log file {@link LogFileInformation}
   * @return logFileInformation
   */
public static LogFileInformation getLogFileInformation() {
    FileAppender fileAppender = getFileAppender();
    if (shouldFetchLogFileInformation(fileAppender)) {
        File logFile = new File(fileAppender.getFile());
        LogFileInformation logFileInfo = new LogFileInformation(fileAppender.getFile(), logFile.length());
        return logFileInfo;
    }
    return null;
}
Also used : FileAppender(org.apache.log4j.FileAppender) LogFileInformation(org.apache.apex.log.LogFileInformation) File(java.io.File)

Aggregations

LogFileInformation (org.apache.apex.log.LogFileInformation)3 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 RecoverableRpcProxy (com.datatorrent.stram.RecoverableRpcProxy)1 Checkpoint (com.datatorrent.stram.api.Checkpoint)1 StreamActivationEvent (com.datatorrent.stram.api.ContainerEvent.StreamActivationEvent)1 OperatorDeployInfo (com.datatorrent.stram.api.OperatorDeployInfo)1 StreamingContainerUmbilicalProtocol (com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol)1 StreamingContainerContext (com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.StreamingContainerContext)1 InlineStream (com.datatorrent.stram.stream.InlineStream)1 MuxStream (com.datatorrent.stram.stream.MuxStream)1 OiOStream (com.datatorrent.stram.stream.OiOStream)1 File (java.io.File)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 BusConfiguration (net.engio.mbassy.bus.config.BusConfiguration)1 Configuration (org.apache.hadoop.conf.Configuration)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 FileAppender (org.apache.log4j.FileAppender)1