You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@gobblin.apache.org by GitBox <gi...@apache.org> on 2021/06/10 18:42:39 UTC

[GitHub] [gobblin] umustafi commented on a change in pull request #3299: [GOBBLIN-1457] Add automatic troubleshooter to Gobblin service

umustafi commented on a change in pull request #3299:
URL: https://github.com/apache/gobblin/pull/3299#discussion_r649435102



##########
File path: gobblin-runtime/src/main/java/org/apache/gobblin/runtime/troubleshooter/IssueEventBuilder.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.gobblin.runtime.troubleshooter;
+
+import java.util.Map;
+
+import org.apache.commons.lang.StringUtils;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import org.apache.gobblin.metrics.GobblinTrackingEvent;
+import org.apache.gobblin.metrics.event.GobblinEventBuilder;
+import org.apache.gobblin.runtime.util.GsonUtils;
+
+
+/**
+ * The builder builds builds a specific {@link GobblinTrackingEvent} whose metadata has
+ * {@value GobblinEventBuilder#EVENT_TYPE} to be {@value #ISSUE_EVENT_TYPE}
+ *
+ * <p>
+ * Note: A {@link IssueEventBuilder} instance is not reusable
+ */
+public class IssueEventBuilder extends GobblinEventBuilder {
+  public static final String JOB_ISSUE = "JobIssue";
+
+  private static final String ISSUE_EVENT_TYPE = "IssueEvent";
+  private static final String METADATA_ISSUE = "issue";
+
+  @Getter
+  @Setter
+  private Issue issue;
+
+  public IssueEventBuilder(String name) {
+    this(name, NAMESPACE);
+  }
+
+  public IssueEventBuilder(String name, String namespace) {
+    super(name, namespace);
+    metadata.put(EVENT_TYPE, ISSUE_EVENT_TYPE);
+  }
+
+  public static boolean isIssueEvent(GobblinTrackingEvent event) {
+    String eventType = (event.getMetadata() == null) ? "" : event.getMetadata().get(EVENT_TYPE);
+    return StringUtils.isNotEmpty(eventType) && eventType.equals(ISSUE_EVENT_TYPE);
+  }
+
+  /**
+   * Create a {@link IssueEventBuilder} from a {@link GobblinTrackingEvent}.
+   * Will return null if the event is not of the correct type.
+   */
+  public static IssueEventBuilder fromEvent(GobblinTrackingEvent event) {
+    if (!isIssueEvent(event)) {
+      return null;
+    }
+    Map<String, String> metadata = event.getMetadata();
+    IssueEventBuilder issueEventBuilder = new IssueEventBuilder(event.getName(), event.getNamespace());
+
+    metadata.forEach((key, value) -> {
+      if (METADATA_ISSUE.equals(key)) {
+        issueEventBuilder.issue = GsonUtils.GSON_WITH_DATE_HANDLING.fromJson(value, Issue.class);
+      } else {
+        issueEventBuilder.addMetadata(key, value);
+      }
+    });
+    return issueEventBuilder;
+  }
+
+  public static Issue getIssueFromEvent(GobblinTrackingEvent event) {
+    String serializedIssue = event.getMetadata().get(METADATA_ISSUE);
+    return GsonUtils.GSON_WITH_DATE_HANDLING.fromJson(serializedIssue, Issue.class);
+  }
+
+  public GobblinTrackingEvent build() {

Review comment:
       previously we never returned GobblinTrackingEvents for exception/error propogation right?




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

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