You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@eventmesh.apache.org by GitBox <gi...@apache.org> on 2022/09/01 08:10:02 UTC

[GitHub] [incubator-eventmesh] LIU-WEI-git opened a new pull request, #1203: [ISSUE #270] Pravega connector

LIU-WEI-git opened a new pull request, #1203:
URL: https://github.com/apache/incubator-eventmesh/pull/1203

   Fixes #270 . Here is pravega connector plugin. 
   
   Each topic corresponds to a pravega stream, an EventStreamWriter, an EventStreamReader and a SubscribeTask thread which reads the topic stream in a loop.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] qqeasonchen commented on pull request #1203: [ISSUE #270] Pravega connector

Posted by GitBox <gi...@apache.org>.
qqeasonchen commented on PR #1203:
URL: https://github.com/apache/incubator-eventmesh/pull/1203#issuecomment-1234146326

   @LIU-WEI-git please check the CI fail tasks.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] qqeasonchen merged pull request #1203: [ISSUE #270] Pravega connector

Posted by GitBox <gi...@apache.org>.
qqeasonchen merged PR #1203:
URL: https://github.com/apache/incubator-eventmesh/pull/1203


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] Markliniubility commented on a diff in pull request #1203: [ISSUE #270] Pravega connector

Posted by GitBox <gi...@apache.org>.
Markliniubility commented on code in PR #1203:
URL: https://github.com/apache/incubator-eventmesh/pull/1203#discussion_r960449193


##########
eventmesh-connector-plugin/eventmesh-connector-pravega/src/main/java/org/apache/eventmesh/connector/pravega/client/PravegaEvent.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.connector.pravega.client;
+
+import org.apache.eventmesh.common.utils.JsonUtils;
+import org.apache.eventmesh.connector.pravega.exception.PravegaConnectorException;
+
+import java.io.Serializable;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+
+import io.cloudevents.CloudEvent;
+import io.cloudevents.SpecVersion;
+import io.cloudevents.core.builder.CloudEventBuilder;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+public class PravegaEvent implements Serializable {
+    private SpecVersion version;
+    private String topic;
+    private String data;
+    private Map<String, String> extensions = new HashMap<>();
+    private long createTimestamp;
+
+    public static byte[] toByteArray(PravegaEvent pravegaEvent) {
+        return JsonUtils.serialize(pravegaEvent).getBytes(StandardCharsets.UTF_8);
+    }
+
+    public static PravegaEvent getFromByteArray(byte[] body) {
+        return JsonUtils.deserialize(new String(body, StandardCharsets.UTF_8), PravegaEvent.class);
+    }
+
+    public CloudEvent convertToCloudEvent() {
+        CloudEventBuilder builder;
+        switch (version) {
+            case V03:
+                builder = CloudEventBuilder.v03();
+                break;
+            case V1:
+                builder = CloudEventBuilder.v1();
+                break;
+            default:
+                throw new PravegaConnectorException(String.format("CloudEvent version %s does not support.", version));
+        }
+        builder.withData(data.getBytes())
+               .withId(extensions.remove("id"))
+               .withSource(URI.create(extensions.remove("source")))
+               .withType(extensions.remove("type"))
+               .withDataContentType(extensions.remove("datacontenttype"))
+               .withSubject(extensions.remove("subject"));
+        for (Map.Entry<String, String> extension : extensions.entrySet()) {
+            builder.withExtension(extension.getKey(), extension.getValue());
+        }

Review Comment:
   nit (maybe?): 
   `extensions.entrySet().stream().forEach(extension -> builder.withExtension(extension.getKey(), extension.getValue())`



##########
eventmesh-connector-plugin/eventmesh-connector-pravega/src/main/java/org/apache/eventmesh/connector/pravega/PravegaProducerImpl.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.connector.pravega;
+
+import io.cloudevents.CloudEvent;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.eventmesh.api.RequestReplyCallback;
+import org.apache.eventmesh.api.SendCallback;
+import org.apache.eventmesh.api.SendResult;
+import org.apache.eventmesh.api.exception.ConnectorRuntimeException;
+import org.apache.eventmesh.api.exception.OnExceptionContext;
+import org.apache.eventmesh.api.producer.Producer;
+import org.apache.eventmesh.connector.pravega.client.PravegaClient;
+import org.apache.eventmesh.connector.pravega.exception.PravegaConnectorException;
+
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+@Slf4j
+public class PravegaProducerImpl implements Producer {
+    private final AtomicBoolean started = new AtomicBoolean(false);
+    private PravegaClient client;
+
+    @Override
+    public void init(Properties properties) throws Exception {
+        client = PravegaClient.getInstance();
+    }
+
+    @Override
+    public void start() {
+        started.compareAndSet(false, true);
+    }
+
+    @Override
+    public void shutdown() {
+        started.compareAndSet(true, false);
+    }
+
+    @Override
+    public boolean isStarted() {
+        return started.get();
+    }
+
+    @Override
+    public boolean isClosed() {
+        return !started.get();
+    }
+
+    @Override
+    public void publish(CloudEvent cloudEvent, SendCallback sendCallback) throws Exception {
+        try {
+            SendResult sendResult = client.publish(cloudEvent.getSubject(), cloudEvent);
+            sendCallback.onSuccess(sendResult);
+        } catch (Exception e) {
+            log.error("send message error, topic: {}", cloudEvent.getSubject());
+            OnExceptionContext onExceptionContext = OnExceptionContext.builder()
+                    .messageId("-1")
+                    .topic(cloudEvent.getSubject())
+                    .exception(new ConnectorRuntimeException(e))
+                    .build();
+            sendCallback.onException(onExceptionContext);
+        }
+    }
+
+    @Override
+    public void sendOneway(CloudEvent cloudEvent) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void request(CloudEvent cloudEvent, RequestReplyCallback rrCallback, long timeout) throws Exception {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean reply(CloudEvent cloudEvent, SendCallback sendCallback) throws Exception {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void checkTopicExist(String topic) throws Exception {
+        boolean exist = client.checkTopicExist(topic);
+        if (!exist) {

Review Comment:
   nit: may merge them to one line



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] codecov[bot] commented on pull request #1203: [ISSUE #270] Pravega connector

Posted by GitBox <gi...@apache.org>.
codecov[bot] commented on PR #1203:
URL: https://github.com/apache/incubator-eventmesh/pull/1203#issuecomment-1235176421

   # [Codecov](https://codecov.io/gh/apache/incubator-eventmesh/pull/1203?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#1203](https://codecov.io/gh/apache/incubator-eventmesh/pull/1203?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (11e52b6) into [master](https://codecov.io/gh/apache/incubator-eventmesh/commit/3e6c58053aee140fbe641116cc005f409e0c1fa2?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (3e6c580) will **increase** coverage by `0.03%`.
   > The diff coverage is `17.98%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #1203      +/-   ##
   ============================================
   + Coverage     10.34%   10.37%   +0.03%     
   - Complexity      672      685      +13     
   ============================================
     Files           385      395      +10     
     Lines         23832    24098     +266     
     Branches       2648     2662      +14     
   ============================================
   + Hits           2465     2500      +35     
   - Misses        21144    21359     +215     
   - Partials        223      239      +16     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-eventmesh/pull/1203?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...r/pravega/PravegaConnectorResourceServiceImpl.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1203/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1wcmF2ZWdhL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3ByYXZlZ2EvUHJhdmVnYUNvbm5lY3RvclJlc291cmNlU2VydmljZUltcGwuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...entmesh/connector/pravega/PravegaConsumerImpl.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1203/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1wcmF2ZWdhL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3ByYXZlZ2EvUHJhdmVnYUNvbnN1bWVySW1wbC5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...entmesh/connector/pravega/PravegaProducerImpl.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1203/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1wcmF2ZWdhL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3ByYXZlZ2EvUHJhdmVnYVByb2R1Y2VySW1wbC5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...che/eventmesh/connector/pravega/SubscribeTask.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1203/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1wcmF2ZWdhL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3ByYXZlZ2EvU3Vic2NyaWJlVGFzay5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...ntmesh/connector/pravega/client/PravegaClient.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1203/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1wcmF2ZWdhL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3ByYXZlZ2EvY2xpZW50L1ByYXZlZ2FDbGllbnQuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...nector/pravega/client/PravegaCloudEventWriter.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1203/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1wcmF2ZWdhL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3ByYXZlZ2EvY2xpZW50L1ByYXZlZ2FDbG91ZEV2ZW50V3JpdGVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...entmesh/connector/pravega/client/PravegaEvent.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1203/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1wcmF2ZWdhL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3ByYXZlZ2EvY2xpZW50L1ByYXZlZ2FFdmVudC5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...r/pravega/exception/PravegaConnectorException.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1203/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1wcmF2ZWdhL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3ByYXZlZ2EvZXhjZXB0aW9uL1ByYXZlZ2FDb25uZWN0b3JFeGNlcHRpb24uamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [.../pravega/config/PravegaConnectorConfigWrapper.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1203/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1wcmF2ZWdhL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3ByYXZlZ2EvY29uZmlnL1ByYXZlZ2FDb25uZWN0b3JDb25maWdXcmFwcGVyLmphdmE=) | `52.63% <52.63%> (ø)` | |
   | [...nnector/pravega/config/PravegaConnectorConfig.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1203/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1wcmF2ZWdhL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3ByYXZlZ2EvY29uZmlnL1ByYXZlZ2FDb25uZWN0b3JDb25maWcuamF2YQ==) | `71.42% <71.42%> (ø)` | |
   | ... and [9 more](https://codecov.io/gh/apache/incubator-eventmesh/pull/1203/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] LIU-WEI-git commented on a diff in pull request #1203: [ISSUE #270] Pravega connector

Posted by GitBox <gi...@apache.org>.
LIU-WEI-git commented on code in PR #1203:
URL: https://github.com/apache/incubator-eventmesh/pull/1203#discussion_r960460670


##########
eventmesh-connector-plugin/eventmesh-connector-pravega/src/main/java/org/apache/eventmesh/connector/pravega/client/PravegaEvent.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.connector.pravega.client;
+
+import org.apache.eventmesh.common.utils.JsonUtils;
+import org.apache.eventmesh.connector.pravega.exception.PravegaConnectorException;
+
+import java.io.Serializable;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+
+import io.cloudevents.CloudEvent;
+import io.cloudevents.SpecVersion;
+import io.cloudevents.core.builder.CloudEventBuilder;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+public class PravegaEvent implements Serializable {
+    private SpecVersion version;
+    private String topic;
+    private String data;
+    private Map<String, String> extensions = new HashMap<>();
+    private long createTimestamp;
+
+    public static byte[] toByteArray(PravegaEvent pravegaEvent) {
+        return JsonUtils.serialize(pravegaEvent).getBytes(StandardCharsets.UTF_8);
+    }
+
+    public static PravegaEvent getFromByteArray(byte[] body) {
+        return JsonUtils.deserialize(new String(body, StandardCharsets.UTF_8), PravegaEvent.class);
+    }
+
+    public CloudEvent convertToCloudEvent() {
+        CloudEventBuilder builder;
+        switch (version) {
+            case V03:
+                builder = CloudEventBuilder.v03();
+                break;
+            case V1:
+                builder = CloudEventBuilder.v1();
+                break;
+            default:
+                throw new PravegaConnectorException(String.format("CloudEvent version %s does not support.", version));
+        }
+        builder.withData(data.getBytes())
+               .withId(extensions.remove("id"))
+               .withSource(URI.create(extensions.remove("source")))
+               .withType(extensions.remove("type"))
+               .withDataContentType(extensions.remove("datacontenttype"))
+               .withSubject(extensions.remove("subject"));
+        for (Map.Entry<String, String> extension : extensions.entrySet()) {
+            builder.withExtension(extension.getKey(), extension.getValue());
+        }

Review Comment:
   Thanks, I has cleaned it up.



##########
eventmesh-connector-plugin/eventmesh-connector-pravega/src/main/java/org/apache/eventmesh/connector/pravega/client/PravegaEvent.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.connector.pravega.client;
+
+import org.apache.eventmesh.common.utils.JsonUtils;
+import org.apache.eventmesh.connector.pravega.exception.PravegaConnectorException;
+
+import java.io.Serializable;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+
+import io.cloudevents.CloudEvent;
+import io.cloudevents.SpecVersion;
+import io.cloudevents.core.builder.CloudEventBuilder;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+public class PravegaEvent implements Serializable {
+    private SpecVersion version;
+    private String topic;
+    private String data;
+    private Map<String, String> extensions = new HashMap<>();
+    private long createTimestamp;
+
+    public static byte[] toByteArray(PravegaEvent pravegaEvent) {
+        return JsonUtils.serialize(pravegaEvent).getBytes(StandardCharsets.UTF_8);
+    }
+
+    public static PravegaEvent getFromByteArray(byte[] body) {
+        return JsonUtils.deserialize(new String(body, StandardCharsets.UTF_8), PravegaEvent.class);
+    }
+
+    public CloudEvent convertToCloudEvent() {
+        CloudEventBuilder builder;
+        switch (version) {
+            case V03:
+                builder = CloudEventBuilder.v03();
+                break;
+            case V1:
+                builder = CloudEventBuilder.v1();
+                break;
+            default:
+                throw new PravegaConnectorException(String.format("CloudEvent version %s does not support.", version));
+        }
+        builder.withData(data.getBytes())
+               .withId(extensions.remove("id"))
+               .withSource(URI.create(extensions.remove("source")))
+               .withType(extensions.remove("type"))
+               .withDataContentType(extensions.remove("datacontenttype"))
+               .withSubject(extensions.remove("subject"));
+        for (Map.Entry<String, String> extension : extensions.entrySet()) {
+            builder.withExtension(extension.getKey(), extension.getValue());
+        }

Review Comment:
   Thanks, I have cleaned it up.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] LIU-WEI-git commented on a diff in pull request #1203: [ISSUE #270] Pravega connector

Posted by GitBox <gi...@apache.org>.
LIU-WEI-git commented on code in PR #1203:
URL: https://github.com/apache/incubator-eventmesh/pull/1203#discussion_r960459995


##########
eventmesh-connector-plugin/eventmesh-connector-pravega/src/main/java/org/apache/eventmesh/connector/pravega/PravegaProducerImpl.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.connector.pravega;
+
+import io.cloudevents.CloudEvent;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.eventmesh.api.RequestReplyCallback;
+import org.apache.eventmesh.api.SendCallback;
+import org.apache.eventmesh.api.SendResult;
+import org.apache.eventmesh.api.exception.ConnectorRuntimeException;
+import org.apache.eventmesh.api.exception.OnExceptionContext;
+import org.apache.eventmesh.api.producer.Producer;
+import org.apache.eventmesh.connector.pravega.client.PravegaClient;
+import org.apache.eventmesh.connector.pravega.exception.PravegaConnectorException;
+
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+@Slf4j
+public class PravegaProducerImpl implements Producer {
+    private final AtomicBoolean started = new AtomicBoolean(false);
+    private PravegaClient client;
+
+    @Override
+    public void init(Properties properties) throws Exception {
+        client = PravegaClient.getInstance();
+    }
+
+    @Override
+    public void start() {
+        started.compareAndSet(false, true);
+    }
+
+    @Override
+    public void shutdown() {
+        started.compareAndSet(true, false);
+    }
+
+    @Override
+    public boolean isStarted() {
+        return started.get();
+    }
+
+    @Override
+    public boolean isClosed() {
+        return !started.get();
+    }
+
+    @Override
+    public void publish(CloudEvent cloudEvent, SendCallback sendCallback) throws Exception {
+        try {
+            SendResult sendResult = client.publish(cloudEvent.getSubject(), cloudEvent);
+            sendCallback.onSuccess(sendResult);
+        } catch (Exception e) {
+            log.error("send message error, topic: {}", cloudEvent.getSubject());
+            OnExceptionContext onExceptionContext = OnExceptionContext.builder()
+                    .messageId("-1")
+                    .topic(cloudEvent.getSubject())
+                    .exception(new ConnectorRuntimeException(e))
+                    .build();
+            sendCallback.onException(onExceptionContext);
+        }
+    }
+
+    @Override
+    public void sendOneway(CloudEvent cloudEvent) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void request(CloudEvent cloudEvent, RequestReplyCallback rrCallback, long timeout) throws Exception {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean reply(CloudEvent cloudEvent, SendCallback sendCallback) throws Exception {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void checkTopicExist(String topic) throws Exception {
+        boolean exist = client.checkTopicExist(topic);
+        if (!exist) {

Review Comment:
   Thank for your suggestion.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org