pramodbiligiri commented on code in PR #6665:
URL: https://github.com/apache/hudi/pull/6665#discussion_r979609501


##########
hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/gcs/MetadataMsg.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.hudi.utilities.sources.helpers.gcs;
+
+import com.google.pubsub.v1.PubsubMessage;
+import static org.apache.hudi.common.util.StringUtils.isNullOrEmpty;
+import static 
org.apache.hudi.utilities.sources.helpers.gcs.MessageValidity.DO_PROCESS;
+import static 
org.apache.hudi.utilities.sources.helpers.gcs.MessageValidity.DO_SKIP;
+
+/**
+ * Wraps a PubsubMessage assuming it's from Cloud Storage Pubsub Notifications 
(CSPN), and
+ * adds relevant helper methods.
+ * For details of CSPN messages see: 
https://cloud.google.com/storage/docs/pubsub-notifications
+ */
+public class MetadataMsg {
+
+  // The CSPN message to wrap
+  private final PubsubMessage message;
+
+  private static final String EVENT_NAME_OBJECT_FINALIZE = "OBJECT_FINALIZE";
+
+  private static final String ATTR_EVENT_TYPE = "eventType";
+  private static final String ATTR_OBJECT_ID = "objectId";
+  private static final String ATTR_OVERWROTE_GENERATION = 
"overwroteGeneration";
+
+  public MetadataMsg(PubsubMessage message) {
+    this.message = message;
+  }
+
+  public String toStringUtf8() {
+    return message.getData().toStringUtf8();
+  }
+
+  /**
+   * Whether a message is valid to be ingested and stored by this Metadata 
puller.
+   * Ref: https://cloud.google.com/storage/docs/pubsub-notifications#events
+   */
+  public MessageValidity shouldBeProcessed() {
+    if (!isNewFileCreation()) {
+      return DO_SKIP.setReasonToSkip(
+              "eventType: " + getEventType() + ". Not a file creation message."
+      );
+    }
+
+    if (isOverwriteOfExistingFile()) {
+      return DO_SKIP.setReasonToSkip(
+              "eventType: " + getEventType()
+                      + ". Overwrite of existing objectId: " + getObjectId()
+                      + " with generation numner: " + getOverwroteGeneration()
+      );
+    }
+
+    return DO_PROCESS;
+  }
+
+  /**
+   * Whether message represents an overwrite of an existing file.
+   * Ref: 
https://cloud.google.com/storage/docs/pubsub-notifications#replacing_objects
+   */
+  private boolean isOverwriteOfExistingFile() {
+    return !isNullOrEmpty(getOverwroteGeneration());
+  }
+
+  /**
+   * Returns true if message corresponds to new file creation, false if not.
+   * Ref: https://cloud.google.com/storage/docs/pubsub-notifications#events
+   */
+  private boolean isNewFileCreation() {

Review Comment:
   Same response as above.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to