Search in sources :

Example 1 with NodeActivationEvent

use of com.datatorrent.stram.api.ContainerEvent.NodeActivationEvent in project apex-core by apache.

the class StreamingContainer method setupNode.

private void setupNode(OperatorDeployInfo ndi) {
    failedNodes.remove(ndi.id);
    final Node<?> node = nodes.get(ndi.id);
    node.setup(node.context);
    /* setup context for all the input ports */
    LinkedHashMap<String, PortContextPair<InputPort<?>>> inputPorts = node.getPortMappingDescriptor().inputPorts;
    LinkedHashMap<String, PortContextPair<InputPort<?>>> newInputPorts = new LinkedHashMap<>(inputPorts.size());
    for (OperatorDeployInfo.InputDeployInfo idi : ndi.inputs) {
        InputPort<?> port = inputPorts.get(idi.portName).component;
        PortContext context = new PortContext(idi.contextAttributes, node.context);
        newInputPorts.put(idi.portName, new PortContextPair<InputPort<?>>(port, context));
        port.setup(context);
    }
    inputPorts.putAll(newInputPorts);
    /* setup context for all the output ports */
    LinkedHashMap<String, PortContextPair<OutputPort<?>>> outputPorts = node.getPortMappingDescriptor().outputPorts;
    LinkedHashMap<String, PortContextPair<OutputPort<?>>> newOutputPorts = new LinkedHashMap<>(outputPorts.size());
    for (OperatorDeployInfo.OutputDeployInfo odi : ndi.outputs) {
        OutputPort<?> port = outputPorts.get(odi.portName).component;
        PortContext context = new PortContext(odi.contextAttributes, node.context);
        newOutputPorts.put(odi.portName, new PortContextPair<OutputPort<?>>(port, context));
        port.setup(context);
    }
    outputPorts.putAll(newOutputPorts);
    logger.debug("activating {} in container {}", node, containerId);
    /* This introduces need for synchronization on processNodeRequest which was solved by adding deleted field in StramToNodeRequest  */
    processNodeRequests(false);
    node.activate();
    eventBus.publish(new NodeActivationEvent(node));
}
Also used : OutputPort(com.datatorrent.api.Operator.OutputPort) OperatorDeployInfo(com.datatorrent.stram.api.OperatorDeployInfo) InputPort(com.datatorrent.api.Operator.InputPort) LinkedHashMap(java.util.LinkedHashMap) PortContextPair(com.datatorrent.stram.plan.logical.Operators.PortContextPair) NodeActivationEvent(com.datatorrent.stram.api.ContainerEvent.NodeActivationEvent)

Aggregations

InputPort (com.datatorrent.api.Operator.InputPort)1 OutputPort (com.datatorrent.api.Operator.OutputPort)1 NodeActivationEvent (com.datatorrent.stram.api.ContainerEvent.NodeActivationEvent)1 OperatorDeployInfo (com.datatorrent.stram.api.OperatorDeployInfo)1 PortContextPair (com.datatorrent.stram.plan.logical.Operators.PortContextPair)1 LinkedHashMap (java.util.LinkedHashMap)1