[ 
https://issues.apache.org/jira/browse/GOBBLIN-1569?focusedWorklogId=673350&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-673350
 ]

ASF GitHub Bot logged work on GOBBLIN-1569:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 02/Nov/21 17:49
            Start Date: 02/Nov/21 17:49
    Worklog Time Spent: 10m 
      Work Description: phet commented on a change in pull request #3421:
URL: https://github.com/apache/gobblin/pull/3421#discussion_r740665535



##########
File path: 
gobblin-runtime/src/main/java/org/apache/gobblin/runtime/spec_serde/JobSpecDeserializer.java
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.spec_serde;
+
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import java.io.IOException;
+import java.io.StringReader;
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Optional;
+import java.util.Properties;
+import org.apache.gobblin.runtime.api.JobSpec;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class JobSpecDeserializer implements JsonDeserializer<JobSpec> {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(JobSpecDeserializer.class);
+
+  @Override
+  public JobSpec deserialize(JsonElement json, Type typeOfT, 
JsonDeserializationContext context) {
+    JsonObject jsonObject = json.getAsJsonObject();
+
+    String uri = 
jsonObject.get(JobSpecSerializer.JOB_SPEC_URI_KEY).getAsString();
+    String version = 
jsonObject.get(JobSpecSerializer.JOB_SPEC_VERSION_KEY).getAsString();
+    String description = 
jsonObject.get(JobSpecSerializer.JOB_SPEC_DESCRIPTION_KEY).getAsString();
+    Optional<URI> templateURI;
+    try {
+      templateURI = 
Optional.ofNullable(jsonObject.get(JobSpecSerializer.JOB_SPEC_TEMPLATE_URI_KEY).getAsString()).map(s
 -> {
+        try {
+          return new URI(s);
+        } catch (URISyntaxException e) {
+          LOGGER.warn(String.format("error deserializing '%s' as a URI",
+              
jsonObject.get(JobSpecSerializer.JOB_SPEC_TEMPLATE_URI_KEY).getAsString()), e);
+          throw new RuntimeException(e);
+        }
+      });
+    } catch (RuntimeException e) {
+      templateURI = Optional.empty();
+    }

Review comment:
       first off, I agree it's unsatisfying.  (I welcome any tips toward 
finessing java's checked exceptions!)
   
   the transformation you suggest doesn't protect against passing `null` to the 
`URI` ctor.  that's why I was working (via `map`) *within* the `Optional`.  
still, you did helped spot a NPE bug from the parens closed in the wrong place. 
 we need:
   ```
   Optional.ofNullable(jsonObj.get(...)).map
   ```
   not the potentially explosive:
   ```
   Optional.ofNullable(jsonObj.get(...).getAsString()).map
   ```
   in addition, I'll use `Optional.flatMap` to eliminate the second level of 
exception handling.  I'll push those corrections, and you please tell me if you 
see any other potential improvement.




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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 673350)
    Time Spent: 2h  (was: 1h 50m)

> Provide JobCatalog backed by MySQL
> ----------------------------------
>
>                 Key: GOBBLIN-1569
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-1569
>             Project: Apache Gobblin
>          Issue Type: New Feature
>          Components: gobblin-service
>            Reporter: Kip Kohn
>            Assignee: Abhishek Tiwari
>            Priority: Major
>          Time Spent: 2h
>  Remaining Estimate: 0h
>
> Present storage bindings for `JobCatalog` are in-memory or file system.  
> While the latter is durable, it requires an NFS-like capability for 
> cross-instance sharing.
> Support alternative multi-instance backing through MySQL, precluding the need 
> for NFS.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to