Search in sources :

Example 1 with Payload

use of dev.hawala.xns.level0.Payload in project sdk-java by temporalio.

the class ContextAccessor method readSpanContextFromHeader.

public SpanContext readSpanContextFromHeader(Header header, Tracer tracer) {
    Payload payload = header.getValues().get(TRACER_HEADER_KEY);
    if (payload == null) {
        return null;
    }
    @SuppressWarnings("unchecked") Map<String, String> serializedSpanContext = DataConverter.getDefaultInstance().fromPayload(payload, HashMap.class, HASH_MAP_STRING_STRING_TYPE);
    return codec.decode(serializedSpanContext, tracer);
}
Also used : Payload(io.temporal.api.common.v1.Payload)

Example 2 with Payload

use of dev.hawala.xns.level0.Payload in project sdk-java by temporalio.

the class MemoTest method testMemo.

@Test
public void testMemo() {
    if (testWorkflowRule.getTestEnvironment() == null) {
        return;
    }
    WorkflowOptions workflowOptions = SDKTestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()).toBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).setMemo(MEMO).build();
    TestNoArgsWorkflowFunc stubF = testWorkflowRule.getWorkflowClient().newWorkflowStub(TestNoArgsWorkflowFunc.class, workflowOptions);
    WorkflowExecution executionF = WorkflowClient.start(stubF::func);
    GetWorkflowExecutionHistoryResponse historyResp = WorkflowClientHelper.getHistoryPage(testWorkflowRule.getTestEnvironment().getWorkflowService(), SDKTestWorkflowRule.NAMESPACE, executionF, ByteString.EMPTY, new NoopScope());
    HistoryEvent startEvent = historyResp.getHistory().getEvents(0);
    Memo memoFromEvent = startEvent.getWorkflowExecutionStartedEventAttributes().getMemo();
    Payload memoBytes = memoFromEvent.getFieldsMap().get(MEMO_KEY);
    String memoRetrieved = GsonJsonPayloadConverter.getInstance().fromData(memoBytes, String.class, String.class);
    assertEquals(MEMO_VALUE, memoRetrieved);
}
Also used : TestNoArgsWorkflowFunc(io.temporal.workflow.shared.TestMultiArgWorkflowFunctions.TestNoArgsWorkflowFunc) WorkflowOptions(io.temporal.client.WorkflowOptions) WorkflowExecution(io.temporal.api.common.v1.WorkflowExecution) Payload(io.temporal.api.common.v1.Payload) GetWorkflowExecutionHistoryResponse(io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse) ByteString(com.google.protobuf.ByteString) HistoryEvent(io.temporal.api.history.v1.HistoryEvent) NoopScope(com.uber.m3.tally.NoopScope) Memo(io.temporal.api.common.v1.Memo) Test(org.junit.Test)

Example 3 with Payload

use of dev.hawala.xns.level0.Payload in project sdk-java by temporalio.

the class ProtoPayloadConverterTest method testProtoMessageTypeExclusion.

@Test
public void testProtoMessageTypeExclusion() {
    DataConverter converter = new DefaultDataConverter(new ProtobufPayloadConverter(true));
    WorkflowExecution execution = WorkflowExecution.newBuilder().setWorkflowId(UUID.randomUUID().toString()).setRunId(UUID.randomUUID().toString()).build();
    Optional<Payloads> data = converter.toPayloads(execution);
    Payloads payloads = data.get();
    Object field = payloads.getField(payloads.getDescriptorForType().findFieldByName("payloads"));
    Payload payload = (Payload) ((List<?>) field).get(0);
    Object metadata = payload.getField(payload.getDescriptorForType().findFieldByName("metadata"));
    assertEquals(1, ((List<?>) metadata).size());
}
Also used : WorkflowExecution(io.temporal.api.common.v1.WorkflowExecution) Payload(io.temporal.api.common.v1.Payload) Payloads(io.temporal.api.common.v1.Payloads) Test(org.junit.Test)

Example 4 with Payload

use of dev.hawala.xns.level0.Payload in project sdk-java by temporalio.

the class ProtoPayloadConverterTest method testProtoMessageType.

@Test
public void testProtoMessageType() {
    DataConverter converter = DataConverter.getDefaultInstance();
    WorkflowExecution execution = WorkflowExecution.newBuilder().setWorkflowId(UUID.randomUUID().toString()).setRunId(UUID.randomUUID().toString()).build();
    Optional<Payloads> data = converter.toPayloads(execution);
    Payloads payloads = data.get();
    Object field = payloads.getField(payloads.getDescriptorForType().findFieldByName("payloads"));
    Payload payload = (Payload) ((List<?>) field).get(0);
    Object metadata = payload.getField(payload.getDescriptorForType().findFieldByName("metadata"));
    MapEntry<?, ?> secondMetadata = (MapEntry<?, ?>) ((List<?>) metadata).get(1);
    assertEquals("messageType", secondMetadata.getKey());
    assertEquals("temporal.api.common.v1.WorkflowExecution", ((ByteString) secondMetadata.getValue()).toString(StandardCharsets.UTF_8));
}
Also used : MapEntry(com.google.protobuf.MapEntry) WorkflowExecution(io.temporal.api.common.v1.WorkflowExecution) Payload(io.temporal.api.common.v1.Payload) Payloads(io.temporal.api.common.v1.Payloads) Test(org.junit.Test)

Example 5 with Payload

use of dev.hawala.xns.level0.Payload in project dodo by devhawala.

the class GetXNSPackets method main.

/**
 * Main startup method
 *
 * @param args
 *          ignored
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    // Will be filled with NICs
    List<PcapIf> alldevs = new ArrayList<PcapIf>();
    // For any error msgs
    StringBuilder errbuf = new StringBuilder();
    /**
     *************************************************************************
     * First get a list of devices on this system
     *************************************************************************
     */
    int r = Pcap.findAllDevs(alldevs, errbuf);
    if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
        System.err.printf("Can't read list of devices, error is %s", errbuf.toString());
        return;
    }
    System.err.printf("r -> %d\n", r);
    System.err.printf("alldevs.size() = %d\n", alldevs.size());
    System.out.println("Network devices found:");
    PcapIf matchedDev = null;
    int i = 0;
    for (PcapIf device : alldevs) {
        String description = (device.getDescription() != null) ? device.getDescription() : "No description available";
        if ("tap0".equals(description)) {
            System.err.println("** found tap0 by description");
            matchedDev = device;
        }
        if ("tap0".equals(device.getName())) {
            System.err.println("** found tap0 by name");
            matchedDev = device;
        }
        byte[] addr = device.getHardwareAddress();
        String addrLen = "X";
        String sep = "";
        String mac = "";
        if (addr != null) {
            addrLen = "" + addr.length;
            for (byte b : addr) {
                mac = String.format("%s%s%02X", mac, sep, b);
                sep = "-";
            }
        }
        System.out.printf("#%d: %s (%s)[%s] [%s]\n", i++, device.getName(), addrLen, mac, description);
    }
    // We know we have at least 1 device
    PcapIf device = (matchedDev != null) ? matchedDev : alldevs.get(alldevs.size() - 1);
    System.out.printf("\nChoosing '%s' on your behalf:\n", (device.getDescription() != null) ? device.getDescription() : device.getName());
    /**
     *************************************************************************
     * Second we open up the selected device
     *************************************************************************
     */
    // Capture all packets, no trucation
    int snaplen = 64 * 1024;
    // capture all packets
    int flags = Pcap.MODE_PROMISCUOUS;
    // 10 * 1000;           // 10 seconds in millis
    int timeout = 1;
    Pcap pcap = Pcap.openLive(device.getName(), snaplen, flags, timeout, errbuf);
    if (pcap == null) {
        System.err.printf("Error while opening device for capture: " + errbuf.toString());
        return;
    }
    /**
     *************************************************************************
     * Third we create a packet handler which will receive packets from the
     * libpcap loop.
     *************************************************************************
     */
    PcapPacketHandler<String> jpacketHandler = new PcapPacketHandler<String>() {

        public void nextPacket(PcapPacket packet, String user) {
            if (packet.getByte(12) != (byte) 0x06 || packet.getByte(13) != (byte) 0x00) {
                // System.out.println("packet skipped...");
                return;
            }
            System.out.printf("\n\nReceived packet at %s caplen=%-4d len=%-4d %s\n", new Date(packet.getCaptureHeader().timestampInMillis()), // Length actually captured
            packet.getCaptureHeader().caplen(), // Original length
            packet.getCaptureHeader().wirelen(), // User supplied object
            user);
            // System.out.println(packet);
            int payloadStart = 14;
            int payloadLength = packet.getCaptureHeader().caplen() - payloadStart;
            NetPacket np = new NetPacket(packet.getByteArray(payloadStart, payloadLength));
            IDP idp = new IDP(np);
            PacketType packetType = idp.getPacketType();
            if (packetType == PacketType.SPP) {
                SPP spp = new SPP(idp);
                System.out.printf("%s\n", spp.toString());
                System.out.printf("payload: %s\n", spp.payloadToString());
            } else if (packetType == PacketType.ERROR) {
                Error err = new Error(idp);
                System.out.printf("%s\n", err.toString());
                System.out.printf("payload: %s\n", err.payloadToString());
            } else if (packetType == PacketType.PEX) {
                PEX pex = new PEX(idp);
                System.out.printf("%s\n", pex.toString());
                System.out.printf("payload: %s\n", pex.payloadToString());
            } else {
                System.out.printf("%s\n", np.toString());
                System.out.printf("payload: %s\n", np.payloadToString());
            }
        }
    };
    // JBufferHandler<String> jbufferHandler = new JBufferHandler<String>() {
    // 
    // @Override
    // public void nextPacket(PcapHeader header, JBuffer buffer, String userDate) {
    // buffer.
    // }
    // 
    // }
    /**
     *************************************************************************
     * Fourth we enter the loop and tell it to capture 10 packets. The loop
     * method does a mapping of pcap.datalink() DLT value to JProtocol ID, which
     * is needed by JScanner. The scanner scans the packet buffer and decodes
     * the headers. The mapping is done automatically, although a variation on
     * the loop method exists that allows the programmer to sepecify exactly
     * which protocol ID to use as the data link type for this pcap interface.
     *************************************************************************
     */
    pcap.loop(100000, jpacketHandler, "jNetPcap rocks!");
    /**
     *************************************************************************
     * Last thing to do is close the pcap handle
     *************************************************************************
     */
    pcap.close();
    System.out.printf("GetXNSPackets done\n");
}
Also used : PEX(dev.hawala.xns.level2.PEX) Pcap(org.jnetpcap.Pcap) ArrayList(java.util.ArrayList) NetPacket(dev.hawala.xns.level0.NetPacket) Error(dev.hawala.xns.level2.Error) Date(java.util.Date) SPP(dev.hawala.xns.level2.SPP) IDP(dev.hawala.xns.level1.IDP) PcapPacket(org.jnetpcap.packet.PcapPacket) PacketType(dev.hawala.xns.level1.IDP.PacketType) PcapPacketHandler(org.jnetpcap.packet.PcapPacketHandler) PcapIf(org.jnetpcap.PcapIf)

Aggregations

Payload (io.temporal.api.common.v1.Payload)12 Payload (dev.hawala.xns.level0.Payload)6 PEX (dev.hawala.xns.level2.PEX)6 ByteString (com.google.protobuf.ByteString)5 Error (dev.hawala.xns.level2.Error)5 Test (org.junit.Test)5 NetPacket (dev.hawala.xns.level0.NetPacket)4 WorkflowExecution (io.temporal.api.common.v1.WorkflowExecution)4 DataConverter (io.temporal.common.converter.DataConverter)4 IDP (dev.hawala.xns.level1.IDP)3 HashMap (java.util.HashMap)3 NoopScope (com.uber.m3.tally.NoopScope)2 Payloads (io.temporal.api.common.v1.Payloads)2 SearchAttributes (io.temporal.api.common.v1.SearchAttributes)2 HistoryEvent (io.temporal.api.history.v1.HistoryEvent)2 GetWorkflowExecutionHistoryResponse (io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse)2 WorkflowOptions (io.temporal.client.WorkflowOptions)2 DataConverterException (io.temporal.common.converter.DataConverterException)2 TestNoArgsWorkflowFunc (io.temporal.workflow.shared.TestMultiArgWorkflowFunctions.TestNoArgsWorkflowFunc)2 IOException (java.io.IOException)2