diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/pom.xml index 45168a9fbc4..4ac4862d574 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/pom.xml @@ -75,6 +75,36 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + + org.apache.hadoop.yarn.service.IntegrationTest + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + org.apache.hadoop.yarn.service.IntegrationTest + + + **/*.java + + + + + + integration-test + + + + diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/test/java/org/apache/hadoop/yarn/service/IntegrationTest.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/test/java/org/apache/hadoop/yarn/service/IntegrationTest.java new file mode 100644 index 00000000000..9b4e7a0610a --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/test/java/org/apache/hadoop/yarn/service/IntegrationTest.java @@ -0,0 +1,20 @@ +/* + * 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.yarn.service; + +public interface IntegrationTest {} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/test/java/org/apache/hadoop/yarn/service/integrationTests/ClusterSetup.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/test/java/org/apache/hadoop/yarn/service/integrationTests/ClusterSetup.java new file mode 100644 index 00000000000..3220c815848 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/test/java/org/apache/hadoop/yarn/service/integrationTests/ClusterSetup.java @@ -0,0 +1,53 @@ +/* + * 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.yarn.service.integrationTests; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ClusterSetup extends TestWatcher { + + private YarnConfiguration conf; + private String rmHost; + + @Override + protected void starting(Description description) { + conf = new YarnConfiguration(); + rmHost = System.getProperty("rm.host", "localhost"); + } + + public String getRMWebAddress() { + if (YarnConfiguration.useHttps(conf)) { + return "https://" + rmHost + ":" + + YarnConfiguration.DEFAULT_RM_WEBAPP_HTTPS_PORT; + } else { + return "http://" + rmHost + ":" + + YarnConfiguration.DEFAULT_RM_WEBAPP_PORT; + } + } + + public Configuration getConf() { + return this.conf; + } + + private static final Logger LOG = LoggerFactory.getLogger(ClusterSetup.class); +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/test/java/org/apache/hadoop/yarn/service/integrationTests/TestBasicOperations.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/test/java/org/apache/hadoop/yarn/service/integrationTests/TestBasicOperations.java new file mode 100644 index 00000000000..c6ade165182 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/test/java/org/apache/hadoop/yarn/service/integrationTests/TestBasicOperations.java @@ -0,0 +1,95 @@ +/* + * 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.yarn.service.integrationTests; + +import com.google.common.base.Charsets; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; +import org.apache.commons.io.IOUtils; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.security.authentication.client.AuthenticatedURL; +import org.apache.hadoop.yarn.service.IntegrationTest; +import org.apache.hadoop.yarn.service.conf.RestApiConstants; +import org.eclipse.jetty.util.UrlEncoded; +import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.ws.rs.core.MediaType; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +@Category(IntegrationTest.class) +public class TestBasicOperations { + + @ClassRule + public static ClusterSetup clusterSetup = new ClusterSetup(); + + @Test + public void testLaunch() throws IOException { + String data = IOUtils.toString(Files.newInputStream( + Paths.get(getClass().getClassLoader().getResource("example-app.json") + .getPath())), Charsets.UTF_8); + String serviceUrl = createServiceUrl(); + LOG.info("service url {}", serviceUrl); + ClientResponse response = getClient(serviceUrl, clusterSetup.getConf()) + .post(ClientResponse.class, data); + Assert.assertTrue("success", response.getStatus() <= 299); + + + } + + private static String createServiceUrl() throws IOException { + StringBuilder uriBuilder = new StringBuilder(); + uriBuilder.append(clusterSetup.getRMWebAddress()); + uriBuilder.append("/app/v1/services"); + appendUserName(uriBuilder); + return uriBuilder.toString(); + } + + private static void appendUserName(StringBuilder uriBuilder) { + if (clusterSetup.getConf().get("hadoop.http.authentication.type") + .equalsIgnoreCase("simple")) { + uriBuilder.append("?user.name=").append(UrlEncoded.encodeString( + System.getProperty("user.name"))); + } + } + + private static WebResource.Builder getClient(String requestPath, + Configuration conf) + throws IOException { + Client client = Client.create(); + client.setChunkedEncodingSize(null); + WebResource.Builder builder = client.resource(requestPath).type( + MediaType.APPLICATION_JSON); + if (conf.get("hadoop.http.authentication.type").equals("kerberos")) { + AuthenticatedURL.Token token = new AuthenticatedURL.Token(); + builder.header("WWW-Authenticate", token); + } + return builder.accept(RestApiConstants.MEDIA_TYPE_JSON_UTF8); + } + + private static final Logger LOG = LoggerFactory.getLogger( + TestBasicOperations.class); + +}