Search in sources :

Example 81 with PTOperator

use of com.datatorrent.stram.plan.physical.PTOperator in project apex-core by apache.

the class ResourceRequestHandler method getHostForContainer.

/**
   * Get host name where container would be allocated give node local constraints
   * @param container
   * @return
   */
public String getHostForContainer(PTContainer container) {
    for (PTOperator oper : container.getOperators()) {
        HostOperatorSet grpObj = oper.getNodeLocalOperators();
        String host = nodeLocalMapping.get(grpObj.getOperatorSet());
        if (host != null) {
            return host;
        }
        if (grpObj.getHost() != null) {
            host = grpObj.getHost();
            return host;
        }
    }
    return null;
}
Also used : HostOperatorSet(com.datatorrent.stram.plan.physical.PTOperator.HostOperatorSet) PTOperator(com.datatorrent.stram.plan.physical.PTOperator)

Example 82 with PTOperator

use of com.datatorrent.stram.plan.physical.PTOperator in project apex-core by apache.

the class StreamingContainerAgent method getDeployInfoList.

/**
   * Create deploy info for StramChild.
   *
   * @param operators
   * @return StreamingContainerContext
   */
public List<OperatorDeployInfo> getDeployInfoList(Collection<PTOperator> operators) {
    if (container.bufferServerAddress == null) {
        throw new AssertionError("No buffer server address assigned");
    }
    Map<OperatorDeployInfo, PTOperator> nodes = new LinkedHashMap<>();
    HashSet<PTOperator.PTOutput> publishers = new HashSet<>();
    PhysicalPlan physicalPlan = dnmgr.getPhysicalPlan();
    for (PTOperator oper : operators) {
        if (oper.getState() != State.PENDING_DEPLOY) {
            LOG.debug("Skipping deploy for operator {} state {}", oper, oper.getState());
            continue;
        }
        OperatorDeployInfo ndi = createOperatorDeployInfo(oper);
        nodes.put(ndi, oper);
        ndi.inputs = new ArrayList<>(oper.getInputs().size());
        ndi.outputs = new ArrayList<>(oper.getOutputs().size());
        for (PTOperator.PTOutput out : oper.getOutputs()) {
            final StreamMeta streamMeta = out.logicalStream;
            // buffer server or inline publisher
            OutputDeployInfo portInfo = new OutputDeployInfo();
            portInfo.declaredStreamId = streamMeta.getName();
            portInfo.portName = out.portName;
            try {
                portInfo.contextAttributes = streamMeta.getSource().getAttributes().clone();
            } catch (CloneNotSupportedException ex) {
                throw new RuntimeException("Cannot clone attributes", ex);
            }
            boolean outputUnified = false;
            for (PTOperator.PTInput input : out.sinks) {
                if (input.target.isUnifier()) {
                    outputUnified = true;
                    break;
                }
            }
            portInfo.contextAttributes.put(PortContext.IS_OUTPUT_UNIFIED, outputUnified);
            if (ndi.type == OperatorDeployInfo.OperatorType.UNIFIER) {
                // input attributes of the downstream operator
                for (InputPortMeta sink : streamMeta.getSinks()) {
                    try {
                        portInfo.contextAttributes = sink.getAttributes().clone();
                    } catch (CloneNotSupportedException e) {
                        throw new RuntimeException("Cannot clone attributes", e);
                    }
                    break;
                }
            }
            if (!out.isDownStreamInline()) {
                portInfo.bufferServerHost = oper.getContainer().bufferServerAddress.getHostName();
                portInfo.bufferServerPort = oper.getContainer().bufferServerAddress.getPort();
                portInfo.bufferServerToken = oper.getContainer().getBufferServerToken();
                // Build the stream codec configuration of all sinks connected to this port
                for (PTOperator.PTInput input : out.sinks) {
                    // Create mappings for all non-inline operators
                    if (input.target.getContainer() != out.source.getContainer()) {
                        final StreamCodec<?> streamCodec = getIdentifyingInputPortMeta(input).getStreamCodec();
                        final Integer id = physicalPlan.getStreamCodecIdentifier(streamCodec);
                        // TODO: replace with inputInfo.streamCodecs.putIfAbsent() after support for JDK 1.7 is dropped.
                        if (!portInfo.streamCodecs.containsKey(id)) {
                            portInfo.streamCodecs.put(id, streamCodec);
                        }
                    }
                }
            }
            ndi.outputs.add(portInfo);
            publishers.add(out);
        }
    }
    for (Map.Entry<OperatorDeployInfo, PTOperator> operEntry : nodes.entrySet()) {
        OperatorDeployInfo ndi = operEntry.getKey();
        PTOperator oper = operEntry.getValue();
        for (PTOperator.PTInput in : oper.getInputs()) {
            final StreamMeta streamMeta = in.logicalStream;
            if (streamMeta.getSource() == null) {
                throw new AssertionError("source is null: " + in);
            }
            PTOperator.PTOutput sourceOutput = in.source;
            InputDeployInfo inputInfo = new InputDeployInfo();
            inputInfo.declaredStreamId = streamMeta.getName();
            inputInfo.portName = in.portName;
            InputPortMeta inputPortMeta = getInputPortMeta(oper.getOperatorMeta(), streamMeta);
            if (inputPortMeta != null) {
                try {
                    inputInfo.contextAttributes = inputPortMeta.getAttributes().clone();
                } catch (CloneNotSupportedException e) {
                    throw new RuntimeException("Cannot clone attributes", e);
                }
            }
            if (inputInfo.contextAttributes == null && ndi.type == OperatorDeployInfo.OperatorType.UNIFIER) {
                try {
                    inputInfo.contextAttributes = in.source.logicalStream.getSource().getAttributes().clone();
                } catch (CloneNotSupportedException e) {
                    throw new RuntimeException("Cannot clone attributes", e);
                }
            }
            inputInfo.sourceNodeId = sourceOutput.source.getId();
            inputInfo.sourcePortName = sourceOutput.portName;
            if (in.partitions != null && in.partitions.mask != 0) {
                inputInfo.partitionMask = in.partitions.mask;
                inputInfo.partitionKeys = in.partitions.partitions;
            }
            if (sourceOutput.source.getContainer() == oper.getContainer()) {
                // both operators in same container
                if (!publishers.contains(sourceOutput)) {
                    throw new AssertionError("Source not deployed for container local stream " + sourceOutput + " " + in);
                }
                if (streamMeta.getLocality() == Locality.THREAD_LOCAL) {
                    inputInfo.locality = Locality.THREAD_LOCAL;
                    ndi.type = OperatorType.OIO;
                } else {
                    inputInfo.locality = Locality.CONTAINER_LOCAL;
                }
            } else {
                // buffer server input
                PTContainer container = sourceOutput.source.getContainer();
                InetSocketAddress addr = container.bufferServerAddress;
                if (addr == null) {
                    throw new AssertionError("upstream address not assigned: " + sourceOutput);
                }
                inputInfo.bufferServerHost = addr.getHostName();
                inputInfo.bufferServerPort = addr.getPort();
                inputInfo.bufferServerToken = container.getBufferServerToken();
            }
            // On the input side there is a unlikely scenario of partitions even for inline stream that is being
            // handled. Always specifying a stream codec configuration in case that scenario happens.
            final StreamCodec<?> streamCodec = getIdentifyingInputPortMeta(in).getStreamCodec();
            final Integer id = physicalPlan.getStreamCodecIdentifier(streamCodec);
            // TODO: replace with inputInfo.streamCodecs.putIfAbsent() after support for JDK 1.7 is dropped.
            if (!inputInfo.streamCodecs.containsKey(id)) {
                inputInfo.streamCodecs.put(id, streamCodec);
            }
            ndi.inputs.add(inputInfo);
        }
    }
    return new ArrayList<>(nodes.keySet());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) StreamMeta(com.datatorrent.stram.plan.logical.LogicalPlan.StreamMeta) PTContainer(com.datatorrent.stram.plan.physical.PTContainer) HashSet(java.util.HashSet) InputDeployInfo(com.datatorrent.stram.api.OperatorDeployInfo.InputDeployInfo) PhysicalPlan(com.datatorrent.stram.plan.physical.PhysicalPlan) OperatorDeployInfo(com.datatorrent.stram.api.OperatorDeployInfo) PTOperator(com.datatorrent.stram.plan.physical.PTOperator) InputPortMeta(com.datatorrent.stram.plan.logical.LogicalPlan.InputPortMeta) OutputDeployInfo(com.datatorrent.stram.api.OperatorDeployInfo.OutputDeployInfo) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 83 with PTOperator

use of com.datatorrent.stram.plan.physical.PTOperator in project apex-core by apache.

the class StreamingContainerAgent method getContainerInfo.

public ContainerInfo getContainerInfo() {
    ContainerInfo ci = new ContainerInfo();
    ci.id = container.getExternalId();
    ci.host = container.host;
    ci.state = container.getState().name();
    ci.jvmName = this.jvmName;
    ci.numOperators = container.getOperators().size();
    ci.operators = new TreeMap<>();
    for (PTOperator ptOperator : container.getOperators()) {
        ci.operators.put(ptOperator.getId(), ptOperator.getName());
    }
    ci.memoryMBAllocated = container.getAllocatedMemoryMB();
    ci.lastHeartbeat = lastHeartbeatMillis;
    ci.memoryMBFree = this.memoryMBFree;
    ci.gcCollectionCount = this.gcCollectionCount;
    ci.gcCollectionTime = this.gcCollectionTime;
    ci.startedTime = container.getStartedTime();
    ci.finishedTime = container.getFinishedTime();
    if (this.container.nodeHttpAddress != null) {
        YarnConfiguration conf = new YarnConfiguration();
        ci.containerLogsUrl = ConfigUtils.getSchemePrefix(conf) + this.container.nodeHttpAddress + "/node/containerlogs/" + ci.id + "/" + System.getenv(ApplicationConstants.Environment.USER.toString());
        ci.rawContainerLogsUrl = ConfigUtils.getRawContainerLogsUrl(conf, container.nodeHttpAddress, container.getPlan().getLogicalPlan().getAttributes().get(LogicalPlan.APPLICATION_ID), ci.id);
    }
    return ci;
}
Also used : PTOperator(com.datatorrent.stram.plan.physical.PTOperator) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ContainerInfo(com.datatorrent.stram.webapp.ContainerInfo)

Example 84 with PTOperator

use of com.datatorrent.stram.plan.physical.PTOperator in project apex-core by apache.

the class StreamingContainerAgent method getIdentifyingInputPortMeta.

public static InputPortMeta getIdentifyingInputPortMeta(PTOperator.PTInput input) {
    InputPortMeta inputPortMeta;
    PTOperator inputTarget = input.target;
    StreamMeta streamMeta = input.logicalStream;
    if (!inputTarget.isUnifier()) {
        inputPortMeta = getInputPortMeta(inputTarget.getOperatorMeta(), streamMeta);
    } else {
        PTOperator destTarget = getIdentifyingOperator(inputTarget);
        inputPortMeta = getInputPortMeta(destTarget.getOperatorMeta(), streamMeta);
    }
    return inputPortMeta;
}
Also used : StreamMeta(com.datatorrent.stram.plan.logical.LogicalPlan.StreamMeta) InputPortMeta(com.datatorrent.stram.plan.logical.LogicalPlan.InputPortMeta) PTOperator(com.datatorrent.stram.plan.physical.PTOperator)

Aggregations

PTOperator (com.datatorrent.stram.plan.physical.PTOperator)84 Test (org.junit.Test)39 PhysicalPlan (com.datatorrent.stram.plan.physical.PhysicalPlan)38 GenericTestOperator (com.datatorrent.stram.engine.GenericTestOperator)36 PTContainer (com.datatorrent.stram.plan.physical.PTContainer)34 Checkpoint (com.datatorrent.stram.api.Checkpoint)23 LogicalPlan (com.datatorrent.stram.plan.logical.LogicalPlan)22 MemoryStorageAgent (com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent)16 OperatorDeployInfo (com.datatorrent.stram.api.OperatorDeployInfo)15 OperatorMeta (com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta)15 PhysicalPlanTest (com.datatorrent.stram.plan.physical.PhysicalPlanTest)14 TestGeneratorInputOperator (com.datatorrent.stram.engine.TestGeneratorInputOperator)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 AsyncFSStorageAgent (com.datatorrent.common.util.AsyncFSStorageAgent)9 StramTestSupport (com.datatorrent.stram.support.StramTestSupport)9 Map (java.util.Map)9 TestPlanContext (com.datatorrent.stram.plan.TestPlanContext)7 Operator (com.datatorrent.api.Operator)6 StatsListener (com.datatorrent.api.StatsListener)6