Skip to content

Commit

Permalink
YARN-2571 patch 016 fixup of final javadoc warnings, cleanup of <Stri…
Browse files Browse the repository at this point in the history
…ng> style definitions, and make sure public/private/evolving scope is everywhere appropriate, including package infos
  • Loading branch information
steveloughran committed Nov 22, 2016
1 parent fa75b5e commit 695ad38
Show file tree
Hide file tree
Showing 26 changed files with 155 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* which use the mapper
* @param <T> Type to marshal.
*/
@InterfaceAudience.Private()
@InterfaceAudience.Private
@InterfaceStability.Evolving
public class JsonSerDeser<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static String join(String base, String path) {
public static List<String> split(String path) {
//
String[] pathelements = path.split("/");
List<String> dirs = new ArrayList<String>(pathelements.length);
List<String> dirs = new ArrayList<>(pathelements.length);
for (String pathelement : pathelements) {
if (!pathelement.isEmpty()) {
dirs.add(pathelement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ public static void requireAddressType(String required, Endpoint epr) throws
/**
* Get a single URI endpoint.
* @param epr endpoint
* @return the uri of the first entry in the address list. Null if the endpoint
* itself is null
* @return the uri of the first entry in the address list.
* Null if the endpoint itself is null
* @throws InvalidRecordException if the type is wrong, there are no addresses
* or the payload ill-formatted
*/
Expand All @@ -194,7 +194,7 @@ public static List<String> retrieveAddressesUriType(Endpoint epr)
throw new InvalidRecordException(epr.toString(),
"No addresses in endpoint");
}
List<String> results = new ArrayList<String>(addresses.size());
List<String> results = new ArrayList<>(addresses.size());
for (Map<String, String> address : addresses) {
results.add(getAddressField(address, ADDRESS_URI));
}
Expand Down Expand Up @@ -232,7 +232,7 @@ public static List<URL> retrieveAddressURLs(Endpoint epr)
throw new InvalidRecordException("", "Null endpoint");
}
List<String> addresses = retrieveAddressesUriType(epr);
List<URL> results = new ArrayList<URL>(addresses.size());
List<URL> results = new ArrayList<>(addresses.size());
for (String address : addresses) {
results.add(new URL(address));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static Map<String, RegistryPathStatus> statChildren(
IOException {
List<String> childNames = registryOperations.list(path);
Map<String, RegistryPathStatus> results =
new HashMap<String, RegistryPathStatus>();
new HashMap<>();
for (String childName : childNames) {
String child = join(path, childName);
try {
Expand Down Expand Up @@ -313,7 +313,7 @@ public static Map<String, ServiceRecord> extractServiceRecords(
RegistryOperations operations,
String parentpath,
Collection<RegistryPathStatus> stats) throws IOException {
Map<String, ServiceRecord> results = new HashMap<String, ServiceRecord>(stats.size());
Map<String, ServiceRecord> results = new HashMap<>(stats.size());
for (RegistryPathStatus stat : stats) {
if (stat.size > ServiceRecord.RECORD_TYPE.length()) {
// maybe has data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@

package org.apache.hadoop.registry.client.exceptions;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;

/**
* Exception raised when client access wasn't authenticated.
* That is: the credentials provided were incomplete or invalid.
*/
@InterfaceAudience.Public
@InterfaceStability.Evolving
public class AuthenticationFailedException extends RegistryIOException {
public AuthenticationFailedException(String path, Throwable cause) {
super(path, cause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

/**
* Raised if an attempt to parse a record failed.
*
*/
@InterfaceAudience.Public
@InterfaceStability.Evolving
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

package org.apache.hadoop.registry.client.exceptions;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.fs.PathIOException;

/**
* Raised on path permission exceptions.
* <p>
* This is similar to PathIOException, except that exception doesn't let
*/
@InterfaceAudience.Public
@InterfaceStability.Evolving
public class NoPathPermissionsException extends RegistryIOException {
public NoPathPermissionsException(String path, Throwable cause) {
super(path, cause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@
* All exceptions in this package are derived from
* {@link org.apache.hadoop.registry.client.exceptions.RegistryIOException}
*/
@InterfaceAudience.Public
@InterfaceStability.Evolving
package org.apache.hadoop.registry.client.exceptions;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ protected String createFullPath(String path) throws IOException {
}

/**
* Get the registry binding source ... this can be used to
* create new ensemble providers
* Get the registry binding source; this can be used to
* create new ensemble providers.
* @return the registry binding source in use
*/
public RegistryBindingSource getBindingSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import org.apache.hadoop.classification.InterfaceStability;

/**
* Interface which can be implemented by a registry binding source
* Interface which can be implemented by a registry binding source.
*/
@InterfaceAudience.Public
@InterfaceStability.Evolving
public interface RegistryBindingSource {

/**
* Supply the binding information for this registry
* Supply the binding information for this registry.
* @return the binding information data
*/
BindingInformation supplyBindingInformation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ public RegistryOperationsService(String name,

/**
* Get the aggregate set of ACLs the client should use
* to create directories
* to create directories.
* @return the ACL list
*/
public List<ACL> getClientAcls() {
return getRegistrySecurity().getClientACLs();
}

/**
* Validate a path
* Validate a path.
* @param path path to validate
* @throws InvalidPathnameException if a path is considered invalid
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.authentication.util.KerberosUtil;
import org.apache.hadoop.service.AbstractService;
Expand Down Expand Up @@ -84,13 +85,6 @@ public class RegistrySecurity extends AbstractService {
"No user for ACLs determinable from current user or registry option "
+ KEY_REGISTRY_USER_ACCOUNTS;

/**
* Error raised when the registry is tagged as secure but this
* process doesn't have hadoop security enabled.
*/
public static final String E_NO_KERBEROS =
"Registry security is enabled -but Hadoop security is not enabled";

/**
* Access policy options.
*/
Expand Down Expand Up @@ -253,49 +247,51 @@ private void initSecurity() throws IOException {

// configure security access based on settings.
switch (access) {
case sasl:
// secure + SASL => has to be authenticated
if (!UserGroupInformation.isSecurityEnabled()) {
throw new IOException("Kerberos required for secure registry access");
}
UserGroupInformation currentUser =
UserGroupInformation.getCurrentUser();
jaasClientContext = getOrFail(KEY_REGISTRY_CLIENT_JAAS_CONTEXT,
DEFAULT_REGISTRY_CLIENT_JAAS_CONTEXT);
jaasClientIdentity = currentUser.getShortUserName();
if (LOG.isDebugEnabled()) {
LOG.debug("Auth is SASL user=\"{}\" JAAS context=\"{}\"",
jaasClientIdentity,
jaasClientContext);
}
break;

case digest:
String id = getOrFail(KEY_REGISTRY_CLIENT_AUTHENTICATION_ID, "");
String pass = getOrFail(KEY_REGISTRY_CLIENT_AUTHENTICATION_PASSWORD, "");
if (userACLs.isEmpty()) {
//
throw new ServiceStateException(E_NO_USER_DETERMINED_FOR_ACLS);
}
digest(id, pass);
ACL acl = new ACL(ZooDefs.Perms.ALL, toDigestId(id, pass));
userACLs.add(acl);
digestAuthUser = id;
digestAuthPassword = pass;
String authPair = id + ":" + pass;
digestAuthData = authPair.getBytes("UTF-8");
if (LOG.isDebugEnabled()) {
LOG.debug("Auth is Digest ACL: {}", aclToString(acl));
}
break;
case sasl:
// secure + SASL => has to be authenticated
if (!UserGroupInformation.isSecurityEnabled()) {
throw new AccessControlException("Kerberos required" +
" for secure registry access");
}
UserGroupInformation currentUser =
UserGroupInformation.getCurrentUser();
jaasClientContext = getOrFail(KEY_REGISTRY_CLIENT_JAAS_CONTEXT,
DEFAULT_REGISTRY_CLIENT_JAAS_CONTEXT);
jaasClientIdentity = currentUser.getShortUserName();
if (LOG.isDebugEnabled()) {
LOG.debug("Auth is SASL user=\"{}\" JAAS context=\"{}\"",
jaasClientIdentity,
jaasClientContext);
}
break;

case digest:
String id = getOrFail(KEY_REGISTRY_CLIENT_AUTHENTICATION_ID, "");
String pass = getOrFail(KEY_REGISTRY_CLIENT_AUTHENTICATION_PASSWORD,
"");
if (userACLs.isEmpty()) {
//
throw new ServiceStateException(E_NO_USER_DETERMINED_FOR_ACLS);
}
digest(id, pass);
ACL acl = new ACL(ZooDefs.Perms.ALL, toDigestId(id, pass));
userACLs.add(acl);
digestAuthUser = id;
digestAuthPassword = pass;
String authPair = id + ":" + pass;
digestAuthData = authPair.getBytes("UTF-8");
if (LOG.isDebugEnabled()) {
LOG.debug("Auth is Digest ACL: {}", aclToString(acl));
}
break;

case anon:
// nothing is needed; account is read only.
if (LOG.isDebugEnabled()) {
LOG.debug("Auth is anonymous");
}
userACLs = new ArrayList<>(0);
break;
case anon:
// nothing is needed; account is read only.
if (LOG.isDebugEnabled()) {
LOG.debug("Auth is anonymous");
}
userACLs = new ArrayList<>(0);
break;
}
systemACLs.addAll(userACLs);

Expand Down Expand Up @@ -928,7 +924,8 @@ public static String getDefaultRealmInJVM() {
/**
* Create an ACL For a user.
* @param ugi User identity
* @param perms permissions to pass to {@link #createACLfromUsername(String, int)}
* @param perms permissions to pass to
* {@link #createACLfromUsername(String, int)}
* @return the ACL For the specified user. If the username doesn't end
* in "@" then the realm is added
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
* some operations/instantiating some objects. The definitions of these
* are kept in {@link org.apache.hadoop.registry.client.impl.zk.ZookeeperConfigOptions}.
*
*
*/
@InterfaceAudience.Private
@InterfaceStability.Evolving
package org.apache.hadoop.registry.client.impl.zk;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Endpoint(Endpoint that) {
this.protocolType = that.protocolType;
this.addresses = newAddresses(that.addresses.size());
for (Map<String, String> address : that.addresses) {
Map<String, String> addr2 = new HashMap<String, String>(address.size());
Map<String, String> addr2 = new HashMap<>(address.size());
addr2.putAll(address);
addresses.add(addr2);
}
Expand Down Expand Up @@ -147,9 +147,7 @@ public Endpoint(String api,
String protocolType,
Map<String, String> addr) {
this(api, addressType, protocolType);
if (addr != null) {
addresses.add(addr);
}
maybeAdd(addr);
}

/**
Expand All @@ -159,15 +157,24 @@ public Endpoint(String api,
* @param protocolType protocol type
* @param addrs addresses. Null elements will be skipped
*/
@SafeVarargs
public Endpoint(String api,
String addressType,
String protocolType,
Map<String, String>...addrs) {
this(api, addressType, protocolType);
for (Map<String, String> addr : addrs) {
if (addr!=null) {
addresses.add(addr);
}
maybeAdd(addr);
}
}

/**
* Add an address map if it is not null.
* @param addr addresses
*/
private void maybeAdd(Map<String, String> addr) {
if (addr != null) {
addresses.add(addr);
}
}

Expand All @@ -177,7 +184,7 @@ public Endpoint(String api,
* @return the new list
*/
private List<Map<String, String>> newAddresses(int size) {
return new ArrayList<Map<String, String>>(size);
return new ArrayList<>(size);
}

/**
Expand Down
Loading

0 comments on commit 695ad38

Please sign in to comment.