gardenia commented on code in PR #10318:
URL: https://github.com/apache/ozone/pull/10318#discussion_r3277246956


##########
hadoop-ozone/ozone-manager-plugins/src/main/java/org/apache/hadoop/ozone/om/eventlistener/s3/S3EventNotificationStrategy.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.hadoop.ozone.om.eventlistener.s3;
+
+import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.time.Instant;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.commons.lang3.StringUtils;
+import 
org.apache.hadoop.ozone.om.eventlistener.OMEventListenerNotificationStrategy;
+import 
org.apache.hadoop.ozone.om.eventlistener.s3.S3EventNotification.OzoneEventDataKey;
+import org.apache.hadoop.ozone.om.helpers.OmCompletedRequestInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This is a notification strategy to generate events according to S3
+ * notification semantics.
+ */
+public class S3EventNotificationStrategy implements 
OMEventListenerNotificationStrategy {
+  public static final Logger LOG = 
LoggerFactory.getLogger(S3EventNotificationStrategy.class);
+
+  private static final ObjectMapper MAPPER = new ObjectMapper();
+
+  @Override
+  public List<String> determineEventsForOperation(OmCompletedRequestInfo 
requestInfo) {
+
+    switch (requestInfo.getCmdType()) {
+    case CreateKey:
+    case CommitKey:
+      return Collections.singletonList(createS3Event("ObjectCreated:Put",
+              requestInfo.getVolumeName(),
+              requestInfo.getBucketName(),
+              requestInfo.getKeyName(),
+              Collections.emptyMap())
+      );
+    case CreateFile:
+      OmCompletedRequestInfo.OperationArgs.CreateFileArgs createFileArgs
+          = (OmCompletedRequestInfo.OperationArgs.CreateFileArgs) 
requestInfo.getOpArgs();
+
+      // XXX: ozoneEventData is an Ozone extension. Its is unclear if this
+      // schema makes sense but the general S3 schema is somewhat
+      // freeform.  These arguments are more informational than
+      // required so it is unclear as to their necessity.
+      Map<String, Object> renameEventData = new HashMap<>();
+      renameEventData.put(OzoneEventDataKey.IS_DIRECTORY.toString(), false);
+      renameEventData.put(OzoneEventDataKey.IS_RECURSIVE.toString(), 
createFileArgs.isRecursive());
+      renameEventData.put(OzoneEventDataKey.IS_OVERWRITE.toString(), 
createFileArgs.isOverwrite());

Review Comment:
   good catch. I will update.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to