Search in sources :

Example 51 with VisibleForTesting

use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting in project beam by apache.

the class SimpleExecutionState method getLullMessage.

@VisibleForTesting
public String getLullMessage(Thread trackedThread, Duration millis) {
    // TODO(ajamato): Share getLullMessage code with DataflowExecutionState.
    String userStepName = this.labelsMetadata.getOrDefault(MonitoringInfoConstants.Labels.PTRANSFORM, null);
    StringBuilder message = new StringBuilder();
    message.append("Operation ongoing");
    if (userStepName != null) {
        message.append(" in step ").append(userStepName);
    }
    message.append(" for at least ").append(formatDuration(millis)).append(" without outputting or completing in state ").append(getStateName());
    message.append("\n");
    StackTraceElement[] fullTrace = trackedThread.getStackTrace();
    for (StackTraceElement e : fullTrace) {
        message.append("  at ").append(e).append("\n");
    }
    return message.toString();
}
Also used : ByteString(org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString) VisibleForTesting(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)

Example 52 with VisibleForTesting

use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting in project beam by apache.

the class MemoryMonitor method tryUploadHeapDumpIfItExists.

@VisibleForTesting
boolean tryUploadHeapDumpIfItExists() {
    if (uploadToGCSPath == null) {
        return false;
    }
    boolean uploadedHeapDump = false;
    File localSource = getDefaultHeapDumpPath();
    LOG.info("Looking for heap dump at {}", localSource);
    if (localSource.exists()) {
        LOG.warn("Heap dump {} detected, attempting to upload to GCS", localSource);
        String remoteDest = String.format("%s/heap_dump%s.hprof", uploadToGCSPath, UUID.randomUUID().toString());
        ResourceId resource = FileSystems.matchNewResource(remoteDest, false);
        try {
            uploadFileToGCS(localSource, resource);
            uploadedHeapDump = true;
            LOG.warn("Heap dump {} uploaded to {}", localSource, remoteDest);
        } catch (IOException e) {
            LOG.error("Error uploading heap dump to {}", remoteDest, e);
        }
        try {
            Files.delete(localSource.toPath());
            LOG.info("Deleted local heap dump {}", localSource);
        } catch (IOException e) {
            LOG.warn("Unable to delete local heap dump {}", localSource, e);
        }
    }
    return uploadedHeapDump;
}
Also used : ResourceId(org.apache.beam.sdk.io.fs.ResourceId) IOException(java.io.IOException) File(java.io.File) VisibleForTesting(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)

Example 53 with VisibleForTesting

use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting in project beam by apache.

the class LengthPrefixUnknownCoders method forInstructionOutput.

/**
 * Wrap unknown coders with a {@link LengthPrefixCoder} for the given {@link InstructionOutput}.
 */
@VisibleForTesting
static InstructionOutput forInstructionOutput(InstructionOutput input, boolean replaceWithByteArrayCoder) throws Exception {
    InstructionOutput cloudOutput = clone(input, InstructionOutput.class);
    cloudOutput.setCodec(forCodec(cloudOutput.getCodec(), replaceWithByteArrayCoder));
    return cloudOutput;
}
Also used : InstructionOutput(com.google.api.services.dataflow.model.InstructionOutput) VisibleForTesting(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)

Example 54 with VisibleForTesting

use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting in project beam by apache.

the class BeamIOPushDownRule method findUtilizedInputRefs.

/**
 * Given a {@code RexNode}, find all {@code RexInputRef}s a node or it's children nodes use.
 *
 * @param inputRowType {@code RelDataType} used for looking up names of {@code RexInputRef}.
 * @param startNode A node to start at.
 * @param usedFields Names of {@code RexInputRef}s are added to this list.
 */
@VisibleForTesting
void findUtilizedInputRefs(RelDataType inputRowType, RexNode startNode, Set<String> usedFields) {
    Queue<RexNode> prerequisites = new ArrayDeque<>();
    prerequisites.add(startNode);
    // Assuming there are no cyclic nodes, traverse dependency tree until all RexInputRefs are found
    while (!prerequisites.isEmpty()) {
        RexNode node = prerequisites.poll();
        if (node instanceof RexCall) {
            // Composite expression, example: "=($t11, $t12)"
            RexCall compositeNode = (RexCall) node;
            // Expression from example above contains 2 operands: $t11, $t12
            prerequisites.addAll(compositeNode.getOperands());
        } else if (node instanceof RexInputRef) {
            // Input reference
            // Find a field in an inputRowType for the input reference
            int inputFieldIndex = ((RexInputRef) node).getIndex();
            RelDataTypeField field = inputRowType.getFieldList().get(inputFieldIndex);
            // If we have not seen it before - add it to the list (hash set)
            usedFields.add(field.getName());
        } else if (node instanceof RexLiteral) {
        // Does not contain information about columns utilized by a Calc
        } else {
            throw new UnsupportedOperationException("Unexpected RexNode encountered: " + node.getClass().getSimpleName());
        }
    }
}
Also used : RexCall(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexCall) RexLiteral(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexLiteral) RelDataTypeField(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField) RexInputRef(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexInputRef) ArrayDeque(java.util.ArrayDeque) RexNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode) VisibleForTesting(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)

Example 55 with VisibleForTesting

use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting in project beam by apache.

the class BeamFnStatusClient method getActiveProcessBundleState.

@VisibleForTesting
String getActiveProcessBundleState() {
    StringJoiner activeBundlesState = new StringJoiner("\n");
    activeBundlesState.add("========== ACTIVE PROCESSING BUNDLES ==========");
    if (processBundleCache.getActiveBundleProcessors().isEmpty()) {
        activeBundlesState.add("No active processing bundles.");
    } else {
        List<BundleState> bundleStates = new ArrayList<>();
        processBundleCache.getActiveBundleProcessors().keySet().stream().forEach(instruction -> {
            BundleProcessor bundleProcessor = processBundleCache.find(instruction);
            if (bundleProcessor != null) {
                ExecutionStateTracker executionStateTracker = bundleProcessor.getStateTracker();
                Thread trackedTread = executionStateTracker.getTrackedThread();
                if (trackedTread != null) {
                    bundleStates.add(new BundleState(instruction, trackedTread.getName(), executionStateTracker.getMillisSinceLastTransition()));
                }
            }
        });
        bundleStates.stream().sorted(Comparator.comparing(BundleState::getTimeSinceTransition).reversed()).limit(// only keep top 10
        10).forEachOrdered(bundleState -> {
            activeBundlesState.add(String.format("---- Instruction %s ----", bundleState.getInstruction()));
            activeBundlesState.add(String.format("Tracked thread: %s", bundleState.getTrackedThreadName()));
            activeBundlesState.add(String.format("Time since transition: %.2f seconds%n", bundleState.getTimeSinceTransition() / 1000.0));
        });
    }
    return activeBundlesState.toString();
}
Also used : ExecutionStateTracker(org.apache.beam.runners.core.metrics.ExecutionStateTracker) BundleProcessor(org.apache.beam.fn.harness.control.ProcessBundleHandler.BundleProcessor) ArrayList(java.util.ArrayList) StringJoiner(java.util.StringJoiner) VisibleForTesting(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)81 ArrayList (java.util.ArrayList)18 IOException (java.io.IOException)17 ParameterizedType (java.lang.reflect.ParameterizedType)15 Type (java.lang.reflect.Type)15 Parameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter)14 BundleFinalizerParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.BundleFinalizerParameter)14 PipelineOptionsParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.PipelineOptionsParameter)14 RestrictionParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.RestrictionParameter)14 RestrictionTrackerParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.RestrictionTrackerParameter)14 SchemaElementParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.SchemaElementParameter)14 StateParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.StateParameter)14 TimerFamilyParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.TimerFamilyParameter)14 TimerParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.TimerParameter)14 WatermarkEstimatorParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.WatermarkEstimatorParameter)14 WatermarkEstimatorStateParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.WatermarkEstimatorStateParameter)14 WindowParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.WindowParameter)14 TypeParameter (org.apache.beam.sdk.values.TypeParameter)14 DoFn (org.apache.beam.sdk.transforms.DoFn)10 Map (java.util.Map)7