ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexantone...@apache.org
Subject [01/12] ambari git commit: AMBARI-9676. Initial Hive View Submission to Contrib (alexantonenko)
Date Tue, 24 Feb 2015 16:32:19 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 3114fb5dc -> 47401e798


http://git-wip-us.apache.org/repos/asf/ambari/blob/47401e79/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/resources/udfs/UDFServiceTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/resources/udfs/UDFServiceTest.java
b/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/resources/udfs/UDFServiceTest.java
new file mode 100644
index 0000000..9271e97
--- /dev/null
+++ b/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/resources/udfs/UDFServiceTest.java
@@ -0,0 +1,119 @@
+/**
+ * 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.view.hive.resources.udfs;
+
+import org.apache.ambari.view.hive.BaseHiveTest;
+import org.apache.ambari.view.hive.resources.udfs.UDF;
+import org.apache.ambari.view.hive.resources.udfs.UDFService;
+import org.apache.ambari.view.hive.utils.NotFoundFormattedException;
+import org.json.simple.JSONObject;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+import java.net.URI;
+
+import static org.easymock.EasyMock.*;
+
+public class UDFServiceTest extends BaseHiveTest {
+  @Rule public ExpectedException thrown = ExpectedException.none();
+  private UDFService udfService;
+
+  @Override
+  @Before
+  public void setUp() throws Exception {
+    super.setUp();
+    udfService = getService(UDFService.class, handler, context);
+  }
+
+  private Response doCreateUDF() {
+    UDFService.UDFRequest request = new UDFService.UDFRequest();
+    request.udf = new UDF();
+    request.udf.setClassname("/tmp/udf.jar");
+    request.udf.setName("TestUDF");
+
+    UriInfo uriInfo = createNiceMock(UriInfo.class);
+    URI uri = UriBuilder.fromUri("http://host/a/b").build();
+    expect(uriInfo.getAbsolutePath()).andReturn(uri);
+
+    HttpServletResponse resp_obj = createNiceMock(HttpServletResponse.class);
+
+    resp_obj.setHeader(eq("Location"), anyString());
+
+    replay(uriInfo, resp_obj);
+    return udfService.create(request, resp_obj, uriInfo);
+  }
+
+  @Test
+  public void createUDF() {
+    Response response = doCreateUDF();
+    Assert.assertEquals(201, response.getStatus());
+
+    JSONObject obj = (JSONObject)response.getEntity();
+    Assert.assertTrue(obj.containsKey("udf"));
+    Assert.assertNotNull(((UDF) obj.get("udf")).getId());
+    Assert.assertFalse(((UDF) obj.get("udf")).getId() == null);
+  }
+
+  @Test
+  public void udfNotFound() {
+    thrown.expect(NotFoundFormattedException.class);
+    udfService.getOne("4242");
+  }
+
+  @Test
+  public void updateUDF() {
+    Response createdUDF = doCreateUDF();
+    Integer createdUdfId = ((UDF) ((JSONObject) createdUDF.getEntity()).get("udf")).getId();
+
+    UDFService.UDFRequest request = new UDFService.UDFRequest();
+    request.udf = new UDF();
+    request.udf.setClassname("/tmp/updatedUDF.jar");
+    request.udf.setName("TestUDF2");
+
+    Response response = udfService.update(request, String.valueOf(createdUdfId));
+    Assert.assertEquals(204, response.getStatus());
+
+    Response response2 = udfService.getOne(String.valueOf(createdUdfId));
+    Assert.assertEquals(200, response2.getStatus());
+
+    JSONObject obj = ((JSONObject) response2.getEntity());
+    Assert.assertTrue(obj.containsKey("udf"));
+    Assert.assertEquals(((UDF) obj.get("udf")).getName(), request.udf.getName());
+    Assert.assertEquals(((UDF) obj.get("udf")).getClassname(), request.udf.getClassname());
+  }
+
+  @Test
+  public void deleteUDF() {
+    Response createdUDF = doCreateUDF();
+    Integer createdUdfId = ((UDF) ((JSONObject) createdUDF.getEntity()).get("udf")).getId();
+
+    Response response = udfService.delete(String.valueOf(createdUdfId));
+    Assert.assertEquals(204, response.getStatus());
+
+    thrown.expect(NotFoundFormattedException.class);
+    udfService.getOne(String.valueOf(createdUdfId));
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/47401e79/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/utils/HdfsApiMock.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/utils/HdfsApiMock.java
b/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/utils/HdfsApiMock.java
new file mode 100644
index 0000000..bb922e2
--- /dev/null
+++ b/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/utils/HdfsApiMock.java
@@ -0,0 +1,84 @@
+/**
+ * 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.view.hive.utils;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import static org.easymock.EasyMock.*;
+
+/**
+* Created by roma on 2/6/15.
+*/
+public class HdfsApiMock {
+  private ByteArrayOutputStream fsQueryOutputStream;
+  private ByteArrayOutputStream fsLogsOutputStream;
+  private HdfsApi hdfsApi;
+
+  public HdfsApiMock(String inputFileContent) throws IOException, InterruptedException {
+    setupHdfsApi(inputFileContent);
+  }
+
+  protected void setupHdfsApi(String inputFileContent) throws IOException, InterruptedException
{
+    hdfsApi = createNiceMock(HdfsApi.class);
+
+    hdfsApi.copy(anyString(), anyString());
+
+    fsQueryOutputStream = setupQueryOutputStream(hdfsApi);
+    fsLogsOutputStream = setupLogsOutputStream(hdfsApi);
+    setupQueryInputStream(hdfsApi, inputFileContent);
+
+    expect(hdfsApi.mkdir(anyString())).andReturn(true).anyTimes();
+  }
+
+  protected SeekableByteArrayInputStream setupQueryInputStream(HdfsApi hdfsApi, String query)
throws IOException, InterruptedException {
+    SeekableByteArrayInputStream inputStreamHQL = new SeekableByteArrayInputStream(query.getBytes());
+    expect(hdfsApi.open(endsWith(".hql"))).andReturn(new FSDataInputStream(inputStreamHQL)).anyTimes();
+    return inputStreamHQL;
+  }
+
+  protected ByteArrayOutputStream setupQueryOutputStream(HdfsApi hdfsApi) throws IOException,
InterruptedException {
+    ByteArrayOutputStream queryOutputStream = new ByteArrayOutputStream();
+    FSDataOutputStream fsQueryOutputStream = new FSDataOutputStream(queryOutputStream);
+    expect(hdfsApi.create(endsWith(".hql"), anyBoolean())).andReturn(fsQueryOutputStream);
+    return queryOutputStream;
+  }
+
+  protected ByteArrayOutputStream setupLogsOutputStream(HdfsApi hdfsApi) throws IOException,
InterruptedException {
+    ByteArrayOutputStream logsOutputStream = new ByteArrayOutputStream();
+    FSDataOutputStream fsLogsOutputStream = new FSDataOutputStream(logsOutputStream);
+    expect(hdfsApi.create(endsWith("logs"), anyBoolean())).andReturn(fsLogsOutputStream).anyTimes();
+    return logsOutputStream;
+  }
+
+  public HdfsApi getHdfsApi() {
+    return hdfsApi;
+  }
+
+  public ByteArrayOutputStream getQueryOutputStream() {
+    return fsQueryOutputStream;
+  }
+
+  public ByteArrayOutputStream getLogsOutputStream() {
+    return fsLogsOutputStream;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/47401e79/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/utils/SeekableByteArrayInputStream.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/utils/SeekableByteArrayInputStream.java
b/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/utils/SeekableByteArrayInputStream.java
new file mode 100644
index 0000000..332dc5d
--- /dev/null
+++ b/contrib/views/hive/src/test/java/org/apache/ambari/view/hive/utils/SeekableByteArrayInputStream.java
@@ -0,0 +1,71 @@
+/**
+ * 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.view.hive.utils;
+
+import org.apache.hadoop.fs.PositionedReadable;
+import org.apache.hadoop.fs.Seekable;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+/**
+* Created by roma on 2/6/15.
+*/
+public class SeekableByteArrayInputStream extends ByteArrayInputStream
+    implements Seekable, PositionedReadable {
+  public SeekableByteArrayInputStream(byte[] buf) {
+    super(buf);
+  }
+
+  public SeekableByteArrayInputStream(byte buf[], int offset, int length) {
+    super(buf, offset, length);
+    throw new UnsupportedOperationException("Seek code assumes offset is zero");
+  }
+
+  public void seek(long position) {
+    if (position < 0 || position >= buf.length)
+      throw new IllegalArgumentException("pos = " + position + " buf.lenght = " + buf.length);
+    this.pos = (int) position;
+  }
+
+  public long getPos() {
+    return this.pos;
+  }
+
+  @Override
+  public boolean seekToNewSource(long l) throws IOException {
+    throw new UnsupportedOperationException("seekToNewSource is not supported");
+  }
+
+  @Override
+  public int read(long l, byte[] buffer, int offset, int length) throws IOException {
+    this.seek(l);
+    return this.read(buffer, offset, length);
+  }
+
+  @Override
+  public void readFully(long l, byte[] bytes, int i, int i1) throws IOException {
+    throw new UnsupportedOperationException("readFully is not supported");
+  }
+
+  @Override
+  public void readFully(long l, byte[] bytes) throws IOException {
+    throw new UnsupportedOperationException("readFully is not supported");
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/47401e79/contrib/views/pom.xml
----------------------------------------------------------------------
diff --git a/contrib/views/pom.xml b/contrib/views/pom.xml
index 608a8b0..60c3b71 100644
--- a/contrib/views/pom.xml
+++ b/contrib/views/pom.xml
@@ -38,6 +38,7 @@
     <module>pig</module>
     <module>slider</module>
     <module>capacity-scheduler</module>
+    <module>hive</module>
     <module>tez</module>
   </modules>
   <build>

http://git-wip-us.apache.org/repos/asf/ambari/blob/47401e79/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 3436450..9fc2c90 100644
--- a/pom.xml
+++ b/pom.xml
@@ -299,6 +299,7 @@
             <exclude>contrib/ambari-scom/*/rat.txt</exclude>
             <exclude>contrib/ambari-scom/metrics-sink/target/**</exclude>
             <exclude>contrib/views/*/target/**</exclude>
+            <exclude>contrib/views/hive/src/main/resources/ui/hive-web/vendor/codemirror/**</exclude>
             <exclude>contrib/views/files/src/main/resources/ui/bower_components/**</exclude>
             <exclude>contrib/views/files/src/main/resources/ui/node/**</exclude>
             <exclude>contrib/views/files/src/main/resources/ui/node_modules/**</exclude>


Mime
View raw message