Repository: knox Updated Branches: refs/heads/master 2d51810c2 -> 1fdae18db
KNOX-845 refactoring for the release tests Project: http://git-wip-us.apache.org/repos/asf/knox/repo Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/1fdae18d Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/1fdae18d Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/1fdae18d Branch: refs/heads/master Commit: 1fdae18db98de6dd144bb7e25dd49fd760e813b1 Parents: 2d51810 Author: Sumit Gupta <su...@apache.org> Authored: Thu Feb 23 20:55:32 2017 -0500 Committer: Sumit Gupta <su...@apache.org> Committed: Thu Feb 23 20:55:32 2017 -0500 ---------------------------------------------------------------------- gateway-test-release-utils/pom.xml | 155 ++++++ .../hadoop/gateway/GatewayTestConfig.java | 465 ++++++++++++++++++ .../hadoop/gateway/GatewayTestDriver.java | 183 ++++++++ gateway-test-release/pom.xml | 6 + .../hadoop/gateway/GatewayTestConfig.java | 466 ------------------- .../hadoop/gateway/GatewayTestDriver.java | 183 -------- .../hadoop/gateway/GatewayTestConfig.java | 465 ------------------ .../hadoop/gateway/GatewayTestDriver.java | 183 -------- pom.xml | 1 + 9 files changed, 810 insertions(+), 1297 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/knox/blob/1fdae18d/gateway-test-release-utils/pom.xml ---------------------------------------------------------------------- diff --git a/gateway-test-release-utils/pom.xml b/gateway-test-release-utils/pom.xml new file mode 100644 index 0000000..c4d0196 --- /dev/null +++ b/gateway-test-release-utils/pom.xml @@ -0,0 +1,155 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>gateway</artifactId> + <groupId>org.apache.knox</groupId> + <version>0.12.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>gateway-test-release-utils</artifactId> + <name>gateway-test-release-utils</name> + <description>Gateway release tests utils</description> + + <dependencies> + <dependency> + <groupId>org.apache.knox</groupId> + <artifactId>gateway-release</artifactId> + <version>${gateway-version}</version> + <exclusions> + <exclusion> + <groupId>org.apache.directory.server</groupId> + <artifactId>apacheds-all</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.directory.server</groupId> + <artifactId>apacheds-all</artifactId> + <exclusions> + <exclusion> + <groupId>org.apache.directory.api</groupId> + <artifactId>api-ldap-schema-data</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-core</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-library</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.xmlmatchers</groupId> + <artifactId>xml-matchers</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>uk.co.datumedge</groupId> + <artifactId>hamcrest-json</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-servlet</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>com.mycila.xmltool</groupId> + <artifactId>xmltool</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.knox</groupId> + <artifactId>gateway-test-utils</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-servlet</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.velocity</groupId> + <artifactId>velocity</artifactId> + <scope>provided</scope> + </dependency> + + </dependencies> +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/knox/blob/1fdae18d/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestConfig.java ---------------------------------------------------------------------- diff --git a/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestConfig.java b/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestConfig.java new file mode 100644 index 0000000..22f65cc --- /dev/null +++ b/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestConfig.java @@ -0,0 +1,465 @@ +/** + * 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.gateway; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.gateway.config.GatewayConfig; + +import java.net.InetSocketAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class GatewayTestConfig extends Configuration implements GatewayConfig { + + /* Websocket defaults */ + public static final boolean DEFAULT_WEBSOCKET_FEATURE_ENABLED = false; + public static final int DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_SIZE = Integer.MAX_VALUE;; + public static final int DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_SIZE = Integer.MAX_VALUE;; + public static final int DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_BUFFER_SIZE = 32768; + public static final int DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_BUFFER_SIZE = 32768; + public static final int DEFAULT_WEBSOCKET_INPUT_BUFFER_SIZE = 4096; + public static final int DEFAULT_WEBSOCKET_ASYNC_WRITE_TIMEOUT = 60000; + public static final int DEFAULT_WEBSOCKET_IDLE_TIMEOUT = 300000; + + private String gatewayHomeDir = "gateway-home"; + private String hadoopConfDir = "hadoop"; + private String gatewayHost = "localhost"; + private int gatewayPort = 0; + private String gatewayPath = "gateway"; + private boolean hadoopKerberosSecured = false; + private String kerberosConfig = "/etc/knox/conf/krb5.conf"; + private boolean kerberosDebugEnabled = false; + private String kerberosLoginConfig = "/etc/knox/conf/krb5JAASLogin.conf"; + private String frontendUrl = null; + private boolean xForwardedEnabled = true; + + public void setGatewayHomeDir( String gatewayHomeDir ) { + this.gatewayHomeDir = gatewayHomeDir; + } + + @Override + public String getGatewayConfDir() { + return gatewayHomeDir; + } + + @Override + public String getGatewayDataDir() { + return gatewayHomeDir; + } + + @Override + public String getGatewaySecurityDir() { + return gatewayHomeDir + "/security"; + } + + @Override + public String getGatewayTopologyDir() { + return gatewayHomeDir + "/topologies"; + } + + @Override + public String getGatewayDeploymentDir() { + return gatewayHomeDir + "/deployments"; + } + +// public void setDeploymentDir( String clusterConfDir ) { +// this.deployDir = clusterConfDir; +// } + + @Override + public String getHadoopConfDir() { + return hadoopConfDir; + } + +// public void setHadoopConfDir( String hadoopConfDir ) { +// this.hadoopConfDir = hadoopConfDir; +// } + + @Override + public String getGatewayHost() { + return gatewayHost; + } + +// public void setGatewayHost( String gatewayHost ) { +// this.gatewayHost = gatewayHost; +// } + + @Override + public int getGatewayPort() { + return gatewayPort; + } + +// public void setGatewayPort( int gatewayPort ) { +// this.gatewayPort = gatewayPort; +// } + + @Override + public String getGatewayPath() { + return gatewayPath; + } + + public void setGatewayPath( String gatewayPath ) { + this.gatewayPath = gatewayPath; + } + + @Override + public InetSocketAddress getGatewayAddress() throws UnknownHostException { + return new InetSocketAddress( getGatewayHost(), getGatewayPort() ); + } + + @Override + public boolean isSSLEnabled() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isHadoopKerberosSecured() { + return hadoopKerberosSecured; + } + + public void setHadoopKerberosSecured(boolean hadoopKerberosSecured) { + this.hadoopKerberosSecured = hadoopKerberosSecured; + } + + @Override + public String getKerberosConfig() { + return kerberosConfig; + } + + public void setKerberosConfig(String kerberosConfig) { + this.kerberosConfig = kerberosConfig; + } + + + @Override + public boolean isKerberosDebugEnabled() { + return kerberosDebugEnabled; + } + +// public void setKerberosDebugEnabled(boolean kerberosConfigEnabled) { +// this.kerberosDebugEnabled = kerberosDebugEnabled; +// } + + @Override + public String getKerberosLoginConfig() { + return kerberosLoginConfig; + } + + public void setKerberosLoginConfig(String kerberosLoginConfig) { + this.kerberosLoginConfig = kerberosLoginConfig; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getDefaultTopologyName() + */ + @Override + public String getDefaultTopologyName() { + return "default"; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getDefaultAppRedirectPath() + */ + @Override + public String getDefaultAppRedirectPath() { + // TODO Auto-generated method stub + return "/gateway/sandbox"; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getFrontendUrl() + */ + @Override + public String getFrontendUrl() { return frontendUrl; } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getExcludedSSLProtocols() + */ + @Override + public List getExcludedSSLProtocols() { + List<String> protocols = new ArrayList<String>(); + protocols.add("SSLv3"); + return protocols; + } + + @Override + public List getIncludedSSLCiphers() { + return null; + } + + @Override + public List getExcludedSSLCiphers() { + return null; + } + + public void setFrontendUrl( String frontendUrl ) { + this.frontendUrl = frontendUrl; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#isClientAuthNeeded() + */ + @Override + public boolean isClientAuthNeeded() { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getTruststorePath() + */ + @Override + public String getTruststorePath() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getTrustAllCerts() + */ + @Override + public boolean getTrustAllCerts() { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getTruststoreType() + */ + @Override + public String getTruststoreType() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getKeystoreType() + */ + @Override + public String getKeystoreType() { + // TODO Auto-generated method stub + return null; + } + +// public void setKerberosLoginConfig(String kerberosLoginConfig) { +// this.kerberosLoginConfig = kerberosLoginConfig; +// } + + @Override + public String getGatewayServicesDir() { + return gatewayHomeDir + "/data/services"; + } + + @Override + public String getGatewayApplicationsDir() { + return gatewayHomeDir + "/conf/applications"; + } + + @Override + public boolean isXForwardedEnabled() { + return xForwardedEnabled; + } + + public void setXForwardedEnabled(boolean enabled) { + xForwardedEnabled = enabled; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getEphemeralDHKeySize() + */ + @Override + public String getEphemeralDHKeySize() { + return "2048"; + } + + @Override + public int getHttpClientMaxConnections() { + return 16; + } + + @Override + public int getHttpClientConnectionTimeout() { + return -1; + } + + @Override + public int getHttpClientSocketTimeout() { + return -1; + } + + @Override + public int getThreadPoolMax() { + return 16; + } + + @Override + public int getHttpServerRequestBuffer() { + return 16*1024; + } + + @Override + public int getHttpServerRequestHeaderBuffer() { + return 8*1024; + } + + @Override + public int getHttpServerResponseBuffer() { + return 32*1024; + } + + @Override + public int getHttpServerResponseHeaderBuffer() { + return 8*1024; + } + + @Override + public int getGatewayDeploymentsBackupVersionLimit() { + return Integer.MAX_VALUE; + } + + @Override + public long getGatewayDeploymentsBackupAgeLimit() { + return Long.MAX_VALUE; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getSigningKeystoreName() + */ + @Override + public String getSigningKeystoreName() { + return null; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getSigningKeyAlias() + */ + @Override + public String getSigningKeyAlias() { + return null; + } + + @Override + public List<String> getGlobalRulesServices() { + return Collections.EMPTY_LIST; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#isWebsocketEnabled() + */ + @Override + public boolean isWebsocketEnabled() { + return DEFAULT_WEBSOCKET_FEATURE_ENABLED; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketMaxTextMessageSize() + */ + @Override + public int getWebsocketMaxTextMessageSize() { + return DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_SIZE; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketMaxBinaryMessageSize() + */ + @Override + public int getWebsocketMaxBinaryMessageSize() { + return DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_SIZE; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketMaxTextMessageBufferSize() + */ + @Override + public int getWebsocketMaxTextMessageBufferSize() { + return DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_BUFFER_SIZE; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketMaxBinaryMessageBufferSize() + */ + @Override + public int getWebsocketMaxBinaryMessageBufferSize() { + return DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_BUFFER_SIZE; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketInputBufferSize() + */ + @Override + public int getWebsocketInputBufferSize() { + return DEFAULT_WEBSOCKET_INPUT_BUFFER_SIZE; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketAsyncWriteTimeout() + */ + @Override + public int getWebsocketAsyncWriteTimeout() { + return DEFAULT_WEBSOCKET_ASYNC_WRITE_TIMEOUT; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketIdleTimeout() + */ + @Override + public int getWebsocketIdleTimeout() { + return DEFAULT_WEBSOCKET_IDLE_TIMEOUT; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.config.GatewayConfig#getMimeTypesToCompress() + */ + @Override + public List<String> getMimeTypesToCompress() { + return new ArrayList<String>(); + } + + @Override + public boolean isMetricsEnabled() { + return false; + } + + @Override + public boolean isJmxMetricsReportingEnabled() { + return false; + } + + @Override + public boolean isGraphiteMetricsReportingEnabled() { + return false; + } + + @Override + public String getGraphiteHost() { + return null; + } + + @Override + public int getGraphitePort() { + return 0; + } + + @Override + public int getGraphiteReportingFrequency() { + return 0; + } +} http://git-wip-us.apache.org/repos/asf/knox/blob/1fdae18d/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestDriver.java ---------------------------------------------------------------------- diff --git a/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestDriver.java b/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestDriver.java new file mode 100644 index 0000000..b8254fc --- /dev/null +++ b/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestDriver.java @@ -0,0 +1,183 @@ +/** + * 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.gateway; + +import com.mycila.xmltool.XMLTag; +import org.apache.commons.io.FileUtils; +import org.apache.directory.server.protocol.shared.transport.TcpTransport; +import org.apache.hadoop.gateway.config.GatewayConfig; +import org.apache.hadoop.gateway.security.ldap.SimpleLdapDirectoryServer; +import org.apache.hadoop.gateway.services.DefaultGatewayServices; +import org.apache.hadoop.gateway.services.ServiceLifecycleException; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileOutputStream; +import java.net.InetAddress; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; + +public class GatewayTestDriver { + + private static Logger log = LoggerFactory.getLogger(GatewayTestDriver.class); + + public Class<?> resourceBaseClass; + public SimpleLdapDirectoryServer ldap; + public TcpTransport ldapTransport; + public boolean useGateway; + public GatewayServer gateway; + public GatewayConfig config; + public String clusterName; + + /** + * Sets the class from which relative test resource names should be resolved. + * @param resourceBaseClass The class from which relative test resource names should be resolved. + */ + public void setResourceBase( Class<?> resourceBaseClass ) { + this.resourceBaseClass = resourceBaseClass; + } + + /** + * Starts an embedded LDAP server of the specified port. + * @param port The desired port the LDAP server should listen on. + * @return The actual port the LDAP server is listening on. + * @throws Exception Thrown if a failure occurs. + */ + public int setupLdap( int port ) throws Exception { + URL usersUrl = getResourceUrl("users.ldif"); + ldapTransport = new TcpTransport( 0 ); + ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport ); + ldap.start(); + log.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() ); + return port; + } + + + /** + * Creates a GATEWAY_HOME, starts a gateway instance and deploys a test topology. + */ + public void setupGateway( GatewayTestConfig config, String cluster, XMLTag topology, boolean use ) throws Exception { + this.useGateway = use; + this.config = config; + this.clusterName = cluster; + + File targetDir = new File( System.getProperty( "user.dir" ), "target" ); + File gatewayDir = new File( targetDir, "gateway-home-" + UUID.randomUUID() ); + gatewayDir.mkdirs(); + + config.setGatewayHomeDir( gatewayDir.getAbsolutePath() ); + + File topoDir = new File( config.getGatewayTopologyDir() ); + topoDir.mkdirs(); + + File deployDir = new File( config.getGatewayDeploymentDir() ); + deployDir.mkdirs(); + + File descriptor = new File( topoDir, cluster + ".xml" ); + FileOutputStream stream = new FileOutputStream( descriptor ); + topology.toStream( stream ); + stream.close(); + + DefaultGatewayServices srvcs = new DefaultGatewayServices(); + Map<String,String> options = new HashMap<String,String>(); + options.put("persist-master", "false"); + options.put("master", "password"); + try { + srvcs.init(config, options); + } catch (ServiceLifecycleException e) { + e.printStackTrace(); // I18N not required. + } + File stacksDir = new File( config.getGatewayServicesDir() ); + stacksDir.mkdirs(); + //TODO: [sumit] This is a hack for now, need to find a better way to locate the source resources for 'stacks' to be tested + String pathToStacksSource = "gateway-service-definitions/src/main/resources/services"; + File stacksSourceDir = new File( targetDir.getParent(), pathToStacksSource); + if (!stacksSourceDir.exists()) { + stacksSourceDir = new File( targetDir.getParentFile().getParentFile().getParent(), pathToStacksSource); + } + if (stacksSourceDir.exists()) { + FileUtils.copyDirectoryToDirectory(stacksSourceDir, stacksDir); + } + + gateway = GatewayServer.startGateway(config, srvcs); + MatcherAssert.assertThat("Failed to start gateway.", gateway, notNullValue()); + + log.info( "Gateway port = " + gateway.getAddresses()[ 0 ].getPort() ); + } + + public void cleanup() throws Exception { + gateway.stop(); + FileUtils.deleteQuietly( new File( config.getGatewayTopologyDir() ) ); + FileUtils.deleteQuietly( new File( config.getGatewayConfDir() ) ); + FileUtils.deleteQuietly( new File( config.getGatewaySecurityDir() ) ); + FileUtils.deleteQuietly( new File( config.getGatewayDeploymentDir() ) ); + FileUtils.deleteQuietly( new File( config.getGatewayDataDir() ) ); + FileUtils.deleteQuietly( new File( config.getGatewayServicesDir() ) ); + ldap.stop( true ); + } + + + public String getResourceBaseName() { + return resourceBaseClass.getName().replaceAll( "\\.", "/" ) + "/"; + } + + public String getResourceName( String resource ) { + return getResourceBaseName() + resource; + } + + public URL getResourceUrl( String resource ) { + URL url = ClassLoader.getSystemResource( getResourceName( resource ) ); + assertThat( "Failed to find test resource " + resource, url, Matchers.notNullValue() ); + return url; + } + + public String getLdapUrl() { + return "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort(); + } + + public String getClusterUrl() { + String url; + String localHostName = getLocalHostName(); + url = "http://" + localHostName + ":" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath() + "/" + clusterName; + return url; + } + + public int getGatewayPort() { + return gateway.getAddresses()[0].getPort(); + } + + private String getLocalHostName() { + String hostName = "localhost"; + try { + hostName = InetAddress.getByName("127.0.0.1").getHostName(); + } catch( UnknownHostException e ) { + // Ignore and use the default. + } + return hostName; + } + +} http://git-wip-us.apache.org/repos/asf/knox/blob/1fdae18d/gateway-test-release/pom.xml ---------------------------------------------------------------------- diff --git a/gateway-test-release/pom.xml b/gateway-test-release/pom.xml index 8bfddc1..cc088e3 100644 --- a/gateway-test-release/pom.xml +++ b/gateway-test-release/pom.xml @@ -196,6 +196,12 @@ <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.knox</groupId> + <artifactId>gateway-test-release-utils</artifactId> + <version>${gateway-version}</version> + <scope>test</scope> + </dependency> </dependencies> <build> http://git-wip-us.apache.org/repos/asf/knox/blob/1fdae18d/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java ---------------------------------------------------------------------- diff --git a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java deleted file mode 100644 index 7c72541..0000000 --- a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java +++ /dev/null @@ -1,466 +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.hadoop.gateway; - -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.gateway.config.GatewayConfig; - -import java.net.InetSocketAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class GatewayTestConfig extends Configuration implements GatewayConfig { - - /* Websocket defaults */ - public static final boolean DEFAULT_WEBSOCKET_FEATURE_ENABLED = false; - public static final int DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_SIZE = Integer.MAX_VALUE;; - public static final int DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_SIZE = Integer.MAX_VALUE;; - public static final int DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_BUFFER_SIZE = 32768; - public static final int DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_BUFFER_SIZE = 32768; - public static final int DEFAULT_WEBSOCKET_INPUT_BUFFER_SIZE = 4096; - public static final int DEFAULT_WEBSOCKET_ASYNC_WRITE_TIMEOUT = 60000; - public static final int DEFAULT_WEBSOCKET_IDLE_TIMEOUT = 300000; - - private String gatewayHomeDir = "gateway-home"; - private String hadoopConfDir = "hadoop"; - private String gatewayHost = "localhost"; - private int gatewayPort = 0; - private String gatewayPath = "gateway"; - private boolean hadoopKerberosSecured = false; - private String kerberosConfig = "/etc/knox/conf/krb5.conf"; - private boolean kerberosDebugEnabled = false; - private String kerberosLoginConfig = "/etc/knox/conf/krb5JAASLogin.conf"; - private String frontendUrl = null; - private boolean xForwardedEnabled = true; - - public void setGatewayHomeDir( String gatewayHomeDir ) { - this.gatewayHomeDir = gatewayHomeDir; - } - - @Override - public String getGatewayConfDir() { - return gatewayHomeDir; - } - - @Override - public String getGatewayDataDir() { - return gatewayHomeDir; - } - - @Override - public String getGatewaySecurityDir() { - return gatewayHomeDir + "/security"; - } - - @Override - public String getGatewayTopologyDir() { - return gatewayHomeDir + "/topologies"; - } - - @Override - public String getGatewayDeploymentDir() { - return gatewayHomeDir + "/deployments"; - } - -// public void setDeploymentDir( String clusterConfDir ) { -// this.deployDir = clusterConfDir; -// } - - @Override - public String getHadoopConfDir() { - return hadoopConfDir; - } - -// public void setHadoopConfDir( String hadoopConfDir ) { -// this.hadoopConfDir = hadoopConfDir; -// } - - @Override - public String getGatewayHost() { - return gatewayHost; - } - -// public void setGatewayHost( String gatewayHost ) { -// this.gatewayHost = gatewayHost; -// } - - @Override - public int getGatewayPort() { - return gatewayPort; - } - -// public void setGatewayPort( int gatewayPort ) { -// this.gatewayPort = gatewayPort; -// } - - @Override - public String getGatewayPath() { - return gatewayPath; - } - - public void setGatewayPath( String gatewayPath ) { - this.gatewayPath = gatewayPath; - } - - @Override - public InetSocketAddress getGatewayAddress() throws UnknownHostException { - return new InetSocketAddress( getGatewayHost(), getGatewayPort() ); - } - - @Override - public boolean isSSLEnabled() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean isHadoopKerberosSecured() { - return hadoopKerberosSecured; - } - - public void setHadoopKerberosSecured(boolean hadoopKerberosSecured) { - this.hadoopKerberosSecured = hadoopKerberosSecured; - } - - @Override - public String getKerberosConfig() { - return kerberosConfig; - } - - public void setKerberosConfig(String kerberosConfig) { - this.kerberosConfig = kerberosConfig; - } - - - @Override - public boolean isKerberosDebugEnabled() { - return kerberosDebugEnabled; - } - -// public void setKerberosDebugEnabled(boolean kerberosConfigEnabled) { -// this.kerberosDebugEnabled = kerberosDebugEnabled; -// } - - @Override - public String getKerberosLoginConfig() { - return kerberosLoginConfig; - } - - public void setKerberosLoginConfig(String kerberosLoginConfig) { - this.kerberosLoginConfig = kerberosLoginConfig; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getDefaultTopologyName() - */ - @Override - public String getDefaultTopologyName() { - return "default"; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getDefaultAppRedirectPath() - */ - @Override - public String getDefaultAppRedirectPath() { - // TODO Auto-generated method stub - return "/gateway/sandbox"; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getFrontendUrl() - */ - @Override - public String getFrontendUrl() { return frontendUrl; } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getExcludedSSLProtocols() - */ - @Override - public List getExcludedSSLProtocols() { - List<String> protocols = new ArrayList<String>(); - protocols.add("SSLv3"); - return protocols; - } - - @Override - public List getIncludedSSLCiphers() { - return null; - } - - @Override - public List getExcludedSSLCiphers() { - return null; - } - - public void setFrontendUrl( String frontendUrl ) { - this.frontendUrl = frontendUrl; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#isClientAuthNeeded() - */ - @Override - public boolean isClientAuthNeeded() { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getTruststorePath() - */ - @Override - public String getTruststorePath() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getTrustAllCerts() - */ - @Override - public boolean getTrustAllCerts() { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getTruststoreType() - */ - @Override - public String getTruststoreType() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getKeystoreType() - */ - @Override - public String getKeystoreType() { - // TODO Auto-generated method stub - return null; - } - -// public void setKerberosLoginConfig(String kerberosLoginConfig) { -// this.kerberosLoginConfig = kerberosLoginConfig; -// } - - @Override - public String getGatewayServicesDir() { - return gatewayHomeDir + "/data/services"; - } - - @Override - public String getGatewayApplicationsDir() { - return gatewayHomeDir + "/conf/applications"; - } - - @Override - public boolean isXForwardedEnabled() { - return xForwardedEnabled; - } - - public void setXForwardedEnabled(boolean enabled) { - xForwardedEnabled = enabled; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getEphemeralDHKeySize() - */ - @Override - public String getEphemeralDHKeySize() { - return "2048"; - } - - @Override - public int getHttpClientMaxConnections() { - return 16; - } - - @Override - public int getHttpClientConnectionTimeout() { - return -1; - } - - @Override - public int getHttpClientSocketTimeout() { - return -1; - } - - @Override - public int getThreadPoolMax() { - return 16; - } - - @Override - public int getHttpServerRequestBuffer() { - return 16*1024; - } - - @Override - public int getHttpServerRequestHeaderBuffer() { - return 8*1024; - } - - @Override - public int getHttpServerResponseBuffer() { - return 32*1024; - } - - @Override - public int getHttpServerResponseHeaderBuffer() { - return 8*1024; - } - - @Override - public int getGatewayDeploymentsBackupVersionLimit() { - return Integer.MAX_VALUE; - } - - @Override - public long getGatewayDeploymentsBackupAgeLimit() { - return Long.MAX_VALUE; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getSigningKeystoreName() - */ - @Override - public String getSigningKeystoreName() { - return null; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getSigningKeyAlias() - */ - @Override - public String getSigningKeyAlias() { - return null; - } - - @Override - public List<String> getGlobalRulesServices() { - return Collections.EMPTY_LIST; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#isWebsocketEnabled() - */ - @Override - public boolean isWebsocketEnabled() { - return DEFAULT_WEBSOCKET_FEATURE_ENABLED; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketMaxTextMessageSize() - */ - @Override - public int getWebsocketMaxTextMessageSize() { - return DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_SIZE; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketMaxBinaryMessageSize() - */ - @Override - public int getWebsocketMaxBinaryMessageSize() { - return DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_SIZE; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketMaxTextMessageBufferSize() - */ - @Override - public int getWebsocketMaxTextMessageBufferSize() { - return DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_BUFFER_SIZE; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketMaxBinaryMessageBufferSize() - */ - @Override - public int getWebsocketMaxBinaryMessageBufferSize() { - return DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_BUFFER_SIZE; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketInputBufferSize() - */ - @Override - public int getWebsocketInputBufferSize() { - return DEFAULT_WEBSOCKET_INPUT_BUFFER_SIZE; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketAsyncWriteTimeout() - */ - @Override - public int getWebsocketAsyncWriteTimeout() { - return DEFAULT_WEBSOCKET_ASYNC_WRITE_TIMEOUT; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketIdleTimeout() - */ - @Override - public int getWebsocketIdleTimeout() { - return DEFAULT_WEBSOCKET_IDLE_TIMEOUT; - } - - - @Override - public boolean isMetricsEnabled() { - return false; - } - - @Override - public boolean isJmxMetricsReportingEnabled() { - return false; - } - - @Override - public boolean isGraphiteMetricsReportingEnabled() { - return false; - } - - @Override - public String getGraphiteHost() { - return null; - } - - @Override - public int getGraphitePort() { - return 0; - } - - @Override - public int getGraphiteReportingFrequency() { - return 0; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getMimeTypesToCompress() - */ - @Override - public List<String> getMimeTypesToCompress() { - return new ArrayList<String>(); - } -} http://git-wip-us.apache.org/repos/asf/knox/blob/1fdae18d/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestDriver.java ---------------------------------------------------------------------- diff --git a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestDriver.java b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestDriver.java deleted file mode 100644 index b8254fc..0000000 --- a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestDriver.java +++ /dev/null @@ -1,183 +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.hadoop.gateway; - -import com.mycila.xmltool.XMLTag; -import org.apache.commons.io.FileUtils; -import org.apache.directory.server.protocol.shared.transport.TcpTransport; -import org.apache.hadoop.gateway.config.GatewayConfig; -import org.apache.hadoop.gateway.security.ldap.SimpleLdapDirectoryServer; -import org.apache.hadoop.gateway.services.DefaultGatewayServices; -import org.apache.hadoop.gateway.services.ServiceLifecycleException; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.FileOutputStream; -import java.net.InetAddress; -import java.net.URL; -import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; - -public class GatewayTestDriver { - - private static Logger log = LoggerFactory.getLogger(GatewayTestDriver.class); - - public Class<?> resourceBaseClass; - public SimpleLdapDirectoryServer ldap; - public TcpTransport ldapTransport; - public boolean useGateway; - public GatewayServer gateway; - public GatewayConfig config; - public String clusterName; - - /** - * Sets the class from which relative test resource names should be resolved. - * @param resourceBaseClass The class from which relative test resource names should be resolved. - */ - public void setResourceBase( Class<?> resourceBaseClass ) { - this.resourceBaseClass = resourceBaseClass; - } - - /** - * Starts an embedded LDAP server of the specified port. - * @param port The desired port the LDAP server should listen on. - * @return The actual port the LDAP server is listening on. - * @throws Exception Thrown if a failure occurs. - */ - public int setupLdap( int port ) throws Exception { - URL usersUrl = getResourceUrl("users.ldif"); - ldapTransport = new TcpTransport( 0 ); - ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport ); - ldap.start(); - log.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() ); - return port; - } - - - /** - * Creates a GATEWAY_HOME, starts a gateway instance and deploys a test topology. - */ - public void setupGateway( GatewayTestConfig config, String cluster, XMLTag topology, boolean use ) throws Exception { - this.useGateway = use; - this.config = config; - this.clusterName = cluster; - - File targetDir = new File( System.getProperty( "user.dir" ), "target" ); - File gatewayDir = new File( targetDir, "gateway-home-" + UUID.randomUUID() ); - gatewayDir.mkdirs(); - - config.setGatewayHomeDir( gatewayDir.getAbsolutePath() ); - - File topoDir = new File( config.getGatewayTopologyDir() ); - topoDir.mkdirs(); - - File deployDir = new File( config.getGatewayDeploymentDir() ); - deployDir.mkdirs(); - - File descriptor = new File( topoDir, cluster + ".xml" ); - FileOutputStream stream = new FileOutputStream( descriptor ); - topology.toStream( stream ); - stream.close(); - - DefaultGatewayServices srvcs = new DefaultGatewayServices(); - Map<String,String> options = new HashMap<String,String>(); - options.put("persist-master", "false"); - options.put("master", "password"); - try { - srvcs.init(config, options); - } catch (ServiceLifecycleException e) { - e.printStackTrace(); // I18N not required. - } - File stacksDir = new File( config.getGatewayServicesDir() ); - stacksDir.mkdirs(); - //TODO: [sumit] This is a hack for now, need to find a better way to locate the source resources for 'stacks' to be tested - String pathToStacksSource = "gateway-service-definitions/src/main/resources/services"; - File stacksSourceDir = new File( targetDir.getParent(), pathToStacksSource); - if (!stacksSourceDir.exists()) { - stacksSourceDir = new File( targetDir.getParentFile().getParentFile().getParent(), pathToStacksSource); - } - if (stacksSourceDir.exists()) { - FileUtils.copyDirectoryToDirectory(stacksSourceDir, stacksDir); - } - - gateway = GatewayServer.startGateway(config, srvcs); - MatcherAssert.assertThat("Failed to start gateway.", gateway, notNullValue()); - - log.info( "Gateway port = " + gateway.getAddresses()[ 0 ].getPort() ); - } - - public void cleanup() throws Exception { - gateway.stop(); - FileUtils.deleteQuietly( new File( config.getGatewayTopologyDir() ) ); - FileUtils.deleteQuietly( new File( config.getGatewayConfDir() ) ); - FileUtils.deleteQuietly( new File( config.getGatewaySecurityDir() ) ); - FileUtils.deleteQuietly( new File( config.getGatewayDeploymentDir() ) ); - FileUtils.deleteQuietly( new File( config.getGatewayDataDir() ) ); - FileUtils.deleteQuietly( new File( config.getGatewayServicesDir() ) ); - ldap.stop( true ); - } - - - public String getResourceBaseName() { - return resourceBaseClass.getName().replaceAll( "\\.", "/" ) + "/"; - } - - public String getResourceName( String resource ) { - return getResourceBaseName() + resource; - } - - public URL getResourceUrl( String resource ) { - URL url = ClassLoader.getSystemResource( getResourceName( resource ) ); - assertThat( "Failed to find test resource " + resource, url, Matchers.notNullValue() ); - return url; - } - - public String getLdapUrl() { - return "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort(); - } - - public String getClusterUrl() { - String url; - String localHostName = getLocalHostName(); - url = "http://" + localHostName + ":" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath() + "/" + clusterName; - return url; - } - - public int getGatewayPort() { - return gateway.getAddresses()[0].getPort(); - } - - private String getLocalHostName() { - String hostName = "localhost"; - try { - hostName = InetAddress.getByName("127.0.0.1").getHostName(); - } catch( UnknownHostException e ) { - // Ignore and use the default. - } - return hostName; - } - -} http://git-wip-us.apache.org/repos/asf/knox/blob/1fdae18d/gateway-test-release/webhdfs-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java ---------------------------------------------------------------------- diff --git a/gateway-test-release/webhdfs-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java b/gateway-test-release/webhdfs-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java deleted file mode 100644 index 22f65cc..0000000 --- a/gateway-test-release/webhdfs-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java +++ /dev/null @@ -1,465 +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.hadoop.gateway; - -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.gateway.config.GatewayConfig; - -import java.net.InetSocketAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class GatewayTestConfig extends Configuration implements GatewayConfig { - - /* Websocket defaults */ - public static final boolean DEFAULT_WEBSOCKET_FEATURE_ENABLED = false; - public static final int DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_SIZE = Integer.MAX_VALUE;; - public static final int DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_SIZE = Integer.MAX_VALUE;; - public static final int DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_BUFFER_SIZE = 32768; - public static final int DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_BUFFER_SIZE = 32768; - public static final int DEFAULT_WEBSOCKET_INPUT_BUFFER_SIZE = 4096; - public static final int DEFAULT_WEBSOCKET_ASYNC_WRITE_TIMEOUT = 60000; - public static final int DEFAULT_WEBSOCKET_IDLE_TIMEOUT = 300000; - - private String gatewayHomeDir = "gateway-home"; - private String hadoopConfDir = "hadoop"; - private String gatewayHost = "localhost"; - private int gatewayPort = 0; - private String gatewayPath = "gateway"; - private boolean hadoopKerberosSecured = false; - private String kerberosConfig = "/etc/knox/conf/krb5.conf"; - private boolean kerberosDebugEnabled = false; - private String kerberosLoginConfig = "/etc/knox/conf/krb5JAASLogin.conf"; - private String frontendUrl = null; - private boolean xForwardedEnabled = true; - - public void setGatewayHomeDir( String gatewayHomeDir ) { - this.gatewayHomeDir = gatewayHomeDir; - } - - @Override - public String getGatewayConfDir() { - return gatewayHomeDir; - } - - @Override - public String getGatewayDataDir() { - return gatewayHomeDir; - } - - @Override - public String getGatewaySecurityDir() { - return gatewayHomeDir + "/security"; - } - - @Override - public String getGatewayTopologyDir() { - return gatewayHomeDir + "/topologies"; - } - - @Override - public String getGatewayDeploymentDir() { - return gatewayHomeDir + "/deployments"; - } - -// public void setDeploymentDir( String clusterConfDir ) { -// this.deployDir = clusterConfDir; -// } - - @Override - public String getHadoopConfDir() { - return hadoopConfDir; - } - -// public void setHadoopConfDir( String hadoopConfDir ) { -// this.hadoopConfDir = hadoopConfDir; -// } - - @Override - public String getGatewayHost() { - return gatewayHost; - } - -// public void setGatewayHost( String gatewayHost ) { -// this.gatewayHost = gatewayHost; -// } - - @Override - public int getGatewayPort() { - return gatewayPort; - } - -// public void setGatewayPort( int gatewayPort ) { -// this.gatewayPort = gatewayPort; -// } - - @Override - public String getGatewayPath() { - return gatewayPath; - } - - public void setGatewayPath( String gatewayPath ) { - this.gatewayPath = gatewayPath; - } - - @Override - public InetSocketAddress getGatewayAddress() throws UnknownHostException { - return new InetSocketAddress( getGatewayHost(), getGatewayPort() ); - } - - @Override - public boolean isSSLEnabled() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean isHadoopKerberosSecured() { - return hadoopKerberosSecured; - } - - public void setHadoopKerberosSecured(boolean hadoopKerberosSecured) { - this.hadoopKerberosSecured = hadoopKerberosSecured; - } - - @Override - public String getKerberosConfig() { - return kerberosConfig; - } - - public void setKerberosConfig(String kerberosConfig) { - this.kerberosConfig = kerberosConfig; - } - - - @Override - public boolean isKerberosDebugEnabled() { - return kerberosDebugEnabled; - } - -// public void setKerberosDebugEnabled(boolean kerberosConfigEnabled) { -// this.kerberosDebugEnabled = kerberosDebugEnabled; -// } - - @Override - public String getKerberosLoginConfig() { - return kerberosLoginConfig; - } - - public void setKerberosLoginConfig(String kerberosLoginConfig) { - this.kerberosLoginConfig = kerberosLoginConfig; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getDefaultTopologyName() - */ - @Override - public String getDefaultTopologyName() { - return "default"; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getDefaultAppRedirectPath() - */ - @Override - public String getDefaultAppRedirectPath() { - // TODO Auto-generated method stub - return "/gateway/sandbox"; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getFrontendUrl() - */ - @Override - public String getFrontendUrl() { return frontendUrl; } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getExcludedSSLProtocols() - */ - @Override - public List getExcludedSSLProtocols() { - List<String> protocols = new ArrayList<String>(); - protocols.add("SSLv3"); - return protocols; - } - - @Override - public List getIncludedSSLCiphers() { - return null; - } - - @Override - public List getExcludedSSLCiphers() { - return null; - } - - public void setFrontendUrl( String frontendUrl ) { - this.frontendUrl = frontendUrl; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#isClientAuthNeeded() - */ - @Override - public boolean isClientAuthNeeded() { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getTruststorePath() - */ - @Override - public String getTruststorePath() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getTrustAllCerts() - */ - @Override - public boolean getTrustAllCerts() { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getTruststoreType() - */ - @Override - public String getTruststoreType() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getKeystoreType() - */ - @Override - public String getKeystoreType() { - // TODO Auto-generated method stub - return null; - } - -// public void setKerberosLoginConfig(String kerberosLoginConfig) { -// this.kerberosLoginConfig = kerberosLoginConfig; -// } - - @Override - public String getGatewayServicesDir() { - return gatewayHomeDir + "/data/services"; - } - - @Override - public String getGatewayApplicationsDir() { - return gatewayHomeDir + "/conf/applications"; - } - - @Override - public boolean isXForwardedEnabled() { - return xForwardedEnabled; - } - - public void setXForwardedEnabled(boolean enabled) { - xForwardedEnabled = enabled; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getEphemeralDHKeySize() - */ - @Override - public String getEphemeralDHKeySize() { - return "2048"; - } - - @Override - public int getHttpClientMaxConnections() { - return 16; - } - - @Override - public int getHttpClientConnectionTimeout() { - return -1; - } - - @Override - public int getHttpClientSocketTimeout() { - return -1; - } - - @Override - public int getThreadPoolMax() { - return 16; - } - - @Override - public int getHttpServerRequestBuffer() { - return 16*1024; - } - - @Override - public int getHttpServerRequestHeaderBuffer() { - return 8*1024; - } - - @Override - public int getHttpServerResponseBuffer() { - return 32*1024; - } - - @Override - public int getHttpServerResponseHeaderBuffer() { - return 8*1024; - } - - @Override - public int getGatewayDeploymentsBackupVersionLimit() { - return Integer.MAX_VALUE; - } - - @Override - public long getGatewayDeploymentsBackupAgeLimit() { - return Long.MAX_VALUE; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getSigningKeystoreName() - */ - @Override - public String getSigningKeystoreName() { - return null; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getSigningKeyAlias() - */ - @Override - public String getSigningKeyAlias() { - return null; - } - - @Override - public List<String> getGlobalRulesServices() { - return Collections.EMPTY_LIST; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#isWebsocketEnabled() - */ - @Override - public boolean isWebsocketEnabled() { - return DEFAULT_WEBSOCKET_FEATURE_ENABLED; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketMaxTextMessageSize() - */ - @Override - public int getWebsocketMaxTextMessageSize() { - return DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_SIZE; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketMaxBinaryMessageSize() - */ - @Override - public int getWebsocketMaxBinaryMessageSize() { - return DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_SIZE; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketMaxTextMessageBufferSize() - */ - @Override - public int getWebsocketMaxTextMessageBufferSize() { - return DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_BUFFER_SIZE; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketMaxBinaryMessageBufferSize() - */ - @Override - public int getWebsocketMaxBinaryMessageBufferSize() { - return DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_BUFFER_SIZE; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketInputBufferSize() - */ - @Override - public int getWebsocketInputBufferSize() { - return DEFAULT_WEBSOCKET_INPUT_BUFFER_SIZE; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketAsyncWriteTimeout() - */ - @Override - public int getWebsocketAsyncWriteTimeout() { - return DEFAULT_WEBSOCKET_ASYNC_WRITE_TIMEOUT; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getWebsocketIdleTimeout() - */ - @Override - public int getWebsocketIdleTimeout() { - return DEFAULT_WEBSOCKET_IDLE_TIMEOUT; - } - - /* (non-Javadoc) - * @see org.apache.hadoop.gateway.config.GatewayConfig#getMimeTypesToCompress() - */ - @Override - public List<String> getMimeTypesToCompress() { - return new ArrayList<String>(); - } - - @Override - public boolean isMetricsEnabled() { - return false; - } - - @Override - public boolean isJmxMetricsReportingEnabled() { - return false; - } - - @Override - public boolean isGraphiteMetricsReportingEnabled() { - return false; - } - - @Override - public String getGraphiteHost() { - return null; - } - - @Override - public int getGraphitePort() { - return 0; - } - - @Override - public int getGraphiteReportingFrequency() { - return 0; - } -} http://git-wip-us.apache.org/repos/asf/knox/blob/1fdae18d/gateway-test-release/webhdfs-test/src/test/java/org/apache/hadoop/gateway/GatewayTestDriver.java ---------------------------------------------------------------------- diff --git a/gateway-test-release/webhdfs-test/src/test/java/org/apache/hadoop/gateway/GatewayTestDriver.java b/gateway-test-release/webhdfs-test/src/test/java/org/apache/hadoop/gateway/GatewayTestDriver.java deleted file mode 100644 index b8254fc..0000000 --- a/gateway-test-release/webhdfs-test/src/test/java/org/apache/hadoop/gateway/GatewayTestDriver.java +++ /dev/null @@ -1,183 +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.hadoop.gateway; - -import com.mycila.xmltool.XMLTag; -import org.apache.commons.io.FileUtils; -import org.apache.directory.server.protocol.shared.transport.TcpTransport; -import org.apache.hadoop.gateway.config.GatewayConfig; -import org.apache.hadoop.gateway.security.ldap.SimpleLdapDirectoryServer; -import org.apache.hadoop.gateway.services.DefaultGatewayServices; -import org.apache.hadoop.gateway.services.ServiceLifecycleException; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.FileOutputStream; -import java.net.InetAddress; -import java.net.URL; -import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; - -public class GatewayTestDriver { - - private static Logger log = LoggerFactory.getLogger(GatewayTestDriver.class); - - public Class<?> resourceBaseClass; - public SimpleLdapDirectoryServer ldap; - public TcpTransport ldapTransport; - public boolean useGateway; - public GatewayServer gateway; - public GatewayConfig config; - public String clusterName; - - /** - * Sets the class from which relative test resource names should be resolved. - * @param resourceBaseClass The class from which relative test resource names should be resolved. - */ - public void setResourceBase( Class<?> resourceBaseClass ) { - this.resourceBaseClass = resourceBaseClass; - } - - /** - * Starts an embedded LDAP server of the specified port. - * @param port The desired port the LDAP server should listen on. - * @return The actual port the LDAP server is listening on. - * @throws Exception Thrown if a failure occurs. - */ - public int setupLdap( int port ) throws Exception { - URL usersUrl = getResourceUrl("users.ldif"); - ldapTransport = new TcpTransport( 0 ); - ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport ); - ldap.start(); - log.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() ); - return port; - } - - - /** - * Creates a GATEWAY_HOME, starts a gateway instance and deploys a test topology. - */ - public void setupGateway( GatewayTestConfig config, String cluster, XMLTag topology, boolean use ) throws Exception { - this.useGateway = use; - this.config = config; - this.clusterName = cluster; - - File targetDir = new File( System.getProperty( "user.dir" ), "target" ); - File gatewayDir = new File( targetDir, "gateway-home-" + UUID.randomUUID() ); - gatewayDir.mkdirs(); - - config.setGatewayHomeDir( gatewayDir.getAbsolutePath() ); - - File topoDir = new File( config.getGatewayTopologyDir() ); - topoDir.mkdirs(); - - File deployDir = new File( config.getGatewayDeploymentDir() ); - deployDir.mkdirs(); - - File descriptor = new File( topoDir, cluster + ".xml" ); - FileOutputStream stream = new FileOutputStream( descriptor ); - topology.toStream( stream ); - stream.close(); - - DefaultGatewayServices srvcs = new DefaultGatewayServices(); - Map<String,String> options = new HashMap<String,String>(); - options.put("persist-master", "false"); - options.put("master", "password"); - try { - srvcs.init(config, options); - } catch (ServiceLifecycleException e) { - e.printStackTrace(); // I18N not required. - } - File stacksDir = new File( config.getGatewayServicesDir() ); - stacksDir.mkdirs(); - //TODO: [sumit] This is a hack for now, need to find a better way to locate the source resources for 'stacks' to be tested - String pathToStacksSource = "gateway-service-definitions/src/main/resources/services"; - File stacksSourceDir = new File( targetDir.getParent(), pathToStacksSource); - if (!stacksSourceDir.exists()) { - stacksSourceDir = new File( targetDir.getParentFile().getParentFile().getParent(), pathToStacksSource); - } - if (stacksSourceDir.exists()) { - FileUtils.copyDirectoryToDirectory(stacksSourceDir, stacksDir); - } - - gateway = GatewayServer.startGateway(config, srvcs); - MatcherAssert.assertThat("Failed to start gateway.", gateway, notNullValue()); - - log.info( "Gateway port = " + gateway.getAddresses()[ 0 ].getPort() ); - } - - public void cleanup() throws Exception { - gateway.stop(); - FileUtils.deleteQuietly( new File( config.getGatewayTopologyDir() ) ); - FileUtils.deleteQuietly( new File( config.getGatewayConfDir() ) ); - FileUtils.deleteQuietly( new File( config.getGatewaySecurityDir() ) ); - FileUtils.deleteQuietly( new File( config.getGatewayDeploymentDir() ) ); - FileUtils.deleteQuietly( new File( config.getGatewayDataDir() ) ); - FileUtils.deleteQuietly( new File( config.getGatewayServicesDir() ) ); - ldap.stop( true ); - } - - - public String getResourceBaseName() { - return resourceBaseClass.getName().replaceAll( "\\.", "/" ) + "/"; - } - - public String getResourceName( String resource ) { - return getResourceBaseName() + resource; - } - - public URL getResourceUrl( String resource ) { - URL url = ClassLoader.getSystemResource( getResourceName( resource ) ); - assertThat( "Failed to find test resource " + resource, url, Matchers.notNullValue() ); - return url; - } - - public String getLdapUrl() { - return "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort(); - } - - public String getClusterUrl() { - String url; - String localHostName = getLocalHostName(); - url = "http://" + localHostName + ":" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath() + "/" + clusterName; - return url; - } - - public int getGatewayPort() { - return gateway.getAddresses()[0].getPort(); - } - - private String getLocalHostName() { - String hostName = "localhost"; - try { - hostName = InetAddress.getByName("127.0.0.1").getHostName(); - } catch( UnknownHostException e ) { - // Ignore and use the default. - } - return hostName; - } - -} http://git-wip-us.apache.org/repos/asf/knox/blob/1fdae18d/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 2f0ab89..0c92572 100644 --- a/pom.xml +++ b/pom.xml @@ -93,6 +93,7 @@ <module>gateway-applications</module> <module>gateway-shell-samples</module> <module>gateway-shell-release</module> + <module>gateway-test-release-utils</module> </modules> <properties>