public static ProcedureProtos.Procedure convertToProtoProcedure(Procedure<?> proc)
    throws IOException {
    Preconditions.checkArgument(proc != null);
    validateClass(proc);

    final ProcedureProtos.Procedure.Builder builder = ProcedureProtos.Procedure.newBuilder()
      .setClassName(proc.getClass().getName()).setProcId(proc.getProcId()).setState(proc.getState())
      .setSubmittedTime(proc.getSubmittedTime()).setLastUpdate(proc.getLastUpdate());

    if (proc.hasParent()) {
      builder.setParentId(proc.getParentProcId());
    }

    if (proc.hasTimeout()) {
      builder.setTimeout(proc.getTimeout());
    }

    if (proc.hasOwner()) {
      builder.setOwner(proc.getOwner());
    }

    final int[] stackIds = proc.getStackIndexes();
    if (stackIds != null) {
      for (int i = 0; i < stackIds.length; ++i) {
        builder.addStackId(stackIds[i]);
      }
    }
    builder.setExecuted(proc.wasExecuted());

    if (proc.hasException()) {
      RemoteProcedureException exception = proc.getException();
      builder.setException(
        RemoteProcedureException.toProto(exception.getSource(), exception.getCause()));
    }

    final byte[] result = proc.getResult();
    if (result != null) {
      builder.setResult(UnsafeByteOperations.unsafeWrap(result));
    }

    ProcedureStateSerializer serializer = new StateSerializer(builder);
    proc.serializeStateData(serializer);

    if (proc.getNonceKey() != null) {
      builder.setNonceGroup(proc.getNonceKey().getNonceGroup());
      builder.setNonce(proc.getNonceKey().getNonce());
    }

    if (proc.hasLock()) {
      builder.setLocked(true);
    }

    if (proc.isBypass()) {
      builder.setBypass(true);
    }
    return builder.build();
  }
Helper to convert the procedure to protobuf.
<p/>
Used by ProcedureStore implementations.
hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/ProcedureUtil.java