You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by gn...@apache.org on 2016/08/06 12:50:36 UTC
ambari git commit: Revert "AMBARI-18045. Pig view - Pig script
creation fails.(gauravn7)"
Repository: ambari
Updated Branches:
refs/heads/branch-2.4 3c2b02bbe -> 777522f2d
Revert "AMBARI-18045. Pig view - Pig script creation fails.(gauravn7)"
This reverts commit 3c2b02bbe5880b4f62689c3463332fc1638c33f3.
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/777522f2
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/777522f2
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/777522f2
Branch: refs/heads/branch-2.4
Commit: 777522f2d375ad5d9f5f2a27d9fe15d8132ba2cd
Parents: 3c2b02b
Author: Gaurav Nagar <gn...@hortonworks.com>
Authored: Sat Aug 6 18:20:03 2016 +0530
Committer: Gaurav Nagar <gn...@hortonworks.com>
Committed: Sat Aug 6 18:20:03 2016 +0530
----------------------------------------------------------------------
.../ambari/server/api/DateJsonDeserializer.java | 93 --------------------
.../ambari/server/api/GsonJsonProvider.java | 4 +-
.../ambari/server/api/TestDateDeserializer.java | 89 -------------------
3 files changed, 1 insertion(+), 185 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/777522f2/ambari-server/src/main/java/org/apache/ambari/server/api/DateJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/DateJsonDeserializer.java b/ambari-server/src/main/java/org/apache/ambari/server/api/DateJsonDeserializer.java
deleted file mode 100644
index 69fed88..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/DateJsonDeserializer.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.ambari.server.api;
-
-
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParseException;
-import com.google.gson.JsonSyntaxException;
-import com.google.gson.internal.bind.util.ISO8601Utils;
-
-import java.lang.reflect.Type;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.ParsePosition;
-import java.util.Date;
-import java.util.Locale;
-
-/**
- * Custom deserializer for date conversion.
- * This will support following formats:
- * <ul>
- * <li> Epoch </li>
- * <li> Local Date </li>
- * <li> US Date </li>
- * <li> ISO8601 Date </li>
- * </ul>
- */
-public class DateJsonDeserializer implements JsonDeserializer<Date> {
-
- /**
- * Date Format for US Date.
- */
- private static final DateFormat EN_US_FORMAT = DateFormat.getDateTimeInstance(2, 2, Locale.US);
-
- /**
- * Date Format for local Date
- */
- private static final DateFormat LOCAL_FORMAT = DateFormat.getDateTimeInstance(2, 2);
-
- @Override
- public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
- if (json.isJsonNull()) {
- return null;
- }
-
- return deserializeToDate(json);
- }
-
- /**
- * Convert {@link JsonElement} to {@link Date} object
- *
- * @param json
- * @return
- * @throws JsonSyntaxException
- */
- private synchronized Date deserializeToDate(JsonElement json) throws JsonSyntaxException {
- try {
- return new Date(json.getAsJsonPrimitive().getAsLong());
- } catch (Exception ex1) {
- try {
- return LOCAL_FORMAT.parse(json.getAsJsonPrimitive().getAsString());
- } catch (ParseException ex2) {
- try {
- return EN_US_FORMAT.parse(json.getAsJsonPrimitive().getAsString());
- } catch (ParseException ex3) {
- try {
- return ISO8601Utils.parse(json.getAsJsonPrimitive().getAsString(), new ParsePosition(0));
- } catch (ParseException ex4) {
- throw new JsonSyntaxException(json.getAsJsonPrimitive().getAsString(), ex4);
- }
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/777522f2/ambari-server/src/main/java/org/apache/ambari/server/api/GsonJsonProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/GsonJsonProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/api/GsonJsonProvider.java
index 53f07f9..8ba9ff7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/GsonJsonProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/GsonJsonProvider.java
@@ -35,7 +35,6 @@ import javax.ws.rs.ext.Provider;
import java.io.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
-import java.util.Date;
@Provider
@Consumes({MediaType.APPLICATION_JSON, "text/json"})
@@ -47,8 +46,7 @@ public class GsonJsonProvider implements MessageBodyReader<Object>,
static final Gson gson = new GsonBuilder()
// .setPrettyPrinting()
- .registerTypeAdapter(Date.class, new DateJsonDeserializer())
- .create();
+ .create();
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/777522f2/ambari-server/src/test/java/org/apache/ambari/server/api/TestDateDeserializer.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/TestDateDeserializer.java b/ambari-server/src/test/java/org/apache/ambari/server/api/TestDateDeserializer.java
deleted file mode 100644
index 244094a..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/TestDateDeserializer.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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.ambari.server.api;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonNull;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonPrimitive;
-import com.google.gson.JsonSyntaxException;
-import com.google.gson.internal.bind.util.ISO8601Utils;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-import java.lang.reflect.Type;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.ParsePosition;
-import java.util.Date;
-import java.util.Locale;
-
-import static org.junit.Assert.assertEquals;
-
-public class TestDateDeserializer {
-
- Gson gson = new Gson();
- DateJsonDeserializer deserializer = new DateJsonDeserializer();
-
- @Test
- public void testDeserializeWithEpochDate() {
- String date = "1470301497";
- assertEquals(parseDate(date), new Date(1470301497));
- }
-
- @Test
- public void testDeserializeWithLocalDate() throws ParseException {
- String date = "12 Aug, 2016 11:02:47 PM";
- assertEquals(parseDate(date), DateFormat.getDateTimeInstance(2, 2).parse(date));
- }
-
- @Test
- public void testDeserializeWithUSDate() throws ParseException {
- String date = "Aug 12, 2016 11:01:21 PM";
- assertEquals(parseDate(date), DateFormat.getDateTimeInstance(2, 2, Locale.US).parse(date));
- }
-
- @Test
- public void testDeserializeWithISODate() throws ParseException {
- String dateString = "2016-07-07T15:15:15Z";
- assertEquals(parseDate(dateString), ISO8601Utils.parse(dateString, new ParsePosition(0)));
- }
-
- @Test(expected = JsonSyntaxException.class)
- public void testDeserializeWithInvalidDate() {
- String date = "nopattern";
- parseDate(date);
- }
-
- @Test
- public void testDeserializeWithNullDate() {
- String json = "{\"date\" : null}";
- JsonElement jsonDate = new JsonParser().parse(json).getAsJsonObject().get("date");
- Date date = deserializer.deserialize(jsonDate,
- Mockito.mock(Type.class), Mockito.mock(JsonDeserializationContext.class));
- assertEquals(date, null);
- }
-
- private Date parseDate(String date) {
- return deserializer.deserialize(new JsonPrimitive(date),
- Mockito.mock(Type.class), Mockito.mock(JsonDeserializationContext.class));
- }
-}