Skip to content

Commit

Permalink
HADOOP-14386. Rewind trunk from Guava 21.0 back to Guava 11.0.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
umbrant committed May 9, 2017
1 parent c60164f commit 543aac9
Show file tree
Hide file tree
Showing 15 changed files with 341 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;

import com.google.common.base.Enums;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;

import org.apache.hadoop.HadoopIllegalArgumentException;
Expand Down Expand Up @@ -66,8 +63,6 @@ public static class GetfattrCommand extends FsCommand {
" and values encoded as hexadecimal and base64 are prefixed with " +
"0x and 0s, respectively.\n" +
"<path>: The file or directory.\n";
private final static Function<String, XAttrCodec> enValueOfFunc =
Enums.stringConverter(XAttrCodec.class);

private String name = null;
private boolean dump = false;
Expand All @@ -79,7 +74,7 @@ protected void processOptions(LinkedList<String> args) throws IOException {
String en = StringUtils.popOptionWithArgument("-e", args);
if (en != null) {
try {
encoding = enValueOfFunc.apply(StringUtils.toUpperCase(en));
encoding = XAttrCodec.valueOf(StringUtils.toUpperCase(en));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(
"Invalid/unsupported encoding option specified: " + en);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.Futures;

/**
* Data storage information file.
Expand Down Expand Up @@ -1109,7 +1108,14 @@ public Void call() throws IOException {
}
linkWorkers.shutdown();
for (Future<Void> f : futures) {
Futures.getChecked(f, IOException.class);
try {
f.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException(e);
} catch (ExecutionException e) {
throw new IOException(e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.Iterator;
import java.util.List;

import com.google.common.base.MoreObjects;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
Expand Down Expand Up @@ -366,8 +365,10 @@ private static void calculateMasks(List<AclEntry> aclBuilder,
for (AclEntry entry: aclBuilder) {
scopeFound.add(entry.getScope());
if (entry.getType() == GROUP || entry.getName() != null) {
FsAction scopeUnionPerms = MoreObjects.firstNonNull(
unionPerms.get(entry.getScope()), FsAction.NONE);
FsAction scopeUnionPerms = unionPerms.get(entry.getScope());
if (scopeUnionPerms == null) {
scopeUnionPerms = FsAction.NONE;
}
unionPerms.put(entry.getScope(),
scopeUnionPerms.or(entry.getPermission()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.apache.hadoop.hdfs.server.protocol.RemoteEditLogManifest;

import com.google.common.base.Preconditions;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.Lists;
Expand All @@ -57,28 +56,18 @@ public class JournalSet implements JournalManager {

static final Log LOG = LogFactory.getLog(FSEditLog.class);

// we want local logs to be ordered earlier in the collection, and true
// is considered larger than false, so reverse the comparator
private static final Comparator<EditLogInputStream>
LOCAL_LOG_PREFERENCE_COMPARATOR = new Comparator<EditLogInputStream>() {
@Override
public int compare(EditLogInputStream elis1, EditLogInputStream elis2) {
// we want local logs to be ordered earlier in the collection, and true
// is considered larger than false, so we want to invert the booleans here
return ComparisonChain.start().compareFalseFirst(!elis1.isLocalLog(),
!elis2.isLocalLog()).result();
}
};

static final public Comparator<EditLogInputStream>
EDIT_LOG_INPUT_STREAM_COMPARATOR = new Comparator<EditLogInputStream>() {
@Override
public int compare(EditLogInputStream a, EditLogInputStream b) {
return ComparisonChain.start().
compare(a.getFirstTxId(), b.getFirstTxId()).
compare(b.getLastTxId(), a.getLastTxId()).
result();
}
};

LOCAL_LOG_PREFERENCE_COMPARATOR = Comparator
.comparing(EditLogInputStream::isLocalLog)
.reversed();

public static final Comparator<EditLogInputStream>
EDIT_LOG_INPUT_STREAM_COMPARATOR = Comparator
.comparing(EditLogInputStream::getFirstTxId)
.thenComparing(EditLogInputStream::getLastTxId);

/**
* Container for a JournalManager paired with its currently
* active stream.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/**
* 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.hdfs.qjournal.client;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
* A very basic ExecutorService for running submitted Callables serially.
* Many bits of functionality are not implemented.
*/
public class DirectExecutorService implements ExecutorService {

private static class DirectFuture<V> implements Future<V> {
private V result = null;
private Exception ex = null;

DirectFuture(Callable<V> c) {
try {
result = c.call();
} catch (Exception e) {
ex = e;
}
}

@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}

@Override
public boolean isCancelled() {
return false;
}

@Override
public boolean isDone() {
return true;
}

@Override
public V get() throws InterruptedException, ExecutionException {
if (ex != null) {
throw new ExecutionException(ex);
}
return result;
}

@Override
public V get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
return get();
}
}

private boolean isShutdown = false;

@Override
synchronized public void shutdown() {
isShutdown = true;
}

@Override
public List<Runnable> shutdownNow() {
throw new UnsupportedOperationException();
}

@Override
public boolean isShutdown() {
return isShutdown;
}

@Override
synchronized public boolean isTerminated() {
return isShutdown;
}

@Override
public boolean awaitTermination(long timeout, TimeUnit unit)
throws InterruptedException {
throw new UnsupportedOperationException();
}

@Override
synchronized public <T> Future<T> submit(Callable<T> task) {
if (isShutdown) {
throw new RejectedExecutionException("ExecutorService was shutdown");
}
return new DirectFuture<>(task);
}

@Override
public <T> Future<T> submit(Runnable task, T result) {
throw new UnsupportedOperationException();
}

@Override
public Future<?> submit(Runnable task) {
throw new UnsupportedOperationException();
}

@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
throws InterruptedException {
throw new UnsupportedOperationException();
}

@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,
long timeout, TimeUnit unit) throws InterruptedException {
throw new UnsupportedOperationException();
}

@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
throws InterruptedException, ExecutionException {
throw new UnsupportedOperationException();
}

@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout,
TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
throw new UnsupportedOperationException();
}

@Override
synchronized public void execute(Runnable command) {
command.run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.MoreExecutors;


public class TestQJMWithFaults {
Expand Down Expand Up @@ -402,7 +401,7 @@ public void afterCall(InvocationOnMock invocation, boolean succeeded) {

@Override
protected ExecutorService createSingleThreadExecutor() {
return MoreExecutors.newDirectExecutorService();
return new DirectExecutorService();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import org.mockito.stubbing.Stubber;

import com.google.common.collect.Lists;
import com.google.common.util.concurrent.MoreExecutors;

/**
* Functional tests for QuorumJournalManager.
Expand Down Expand Up @@ -946,7 +945,7 @@ public AsyncLogger createLogger(Configuration conf, NamespaceInfo nsInfo,
protected ExecutorService createSingleThreadExecutor() {
// Don't parallelize calls to the quorum in the tests.
// This makes the tests more deterministic.
return MoreExecutors.newDirectExecutorService();
return new DirectExecutorService();
}
};

Expand Down
2 changes: 1 addition & 1 deletion hadoop-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<findbugs.version>3.0.0</findbugs.version>
<spotbugs.version>3.1.0-RC1</spotbugs.version>

<guava.version>21.0</guava.version>
<guava.version>11.0.2</guava.version>
<guice.version>4.0</guice.version>
<joda-time.version>2.9.4</joda-time.version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.apache.hadoop.yarn.proto.YarnProtos.ResourceProto;
import org.apache.hadoop.yarn.proto.YarnProtos.ResourceRequestProto;

import com.google.common.base.CharMatcher;
import com.google.protobuf.TextFormat;

@Private
Expand Down Expand Up @@ -286,7 +285,7 @@ private void checkTags(Set<String> tags) {
"maximum allowed length of a tag is " +
YarnConfiguration.APPLICATION_MAX_TAG_LENGTH);
}
if (!CharMatcher.ascii().matchesAllOf(tag)) {
if (!org.apache.commons.lang3.StringUtils.isAsciiPrintable(tag)) {
throw new IllegalArgumentException("A tag can only have ASCII " +
"characters! Invalid tag - " + tag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.http.HttpServer2;
import org.apache.hadoop.yarn.webapp.view.RobotsTextPage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.inject.Provides;
Expand Down Expand Up @@ -275,7 +275,7 @@ static List<String> parseRoute(String pathSpec) {

static String getPrefix(String pathSpec) {
int start = 0;
while (CharMatcher.whitespace().matches(pathSpec.charAt(start))) {
while (StringUtils.isAnyBlank(Character.toString(pathSpec.charAt(start)))) {
++start;
}
if (pathSpec.charAt(start) != '/') {
Expand All @@ -291,7 +291,7 @@ static String getPrefix(String pathSpec) {
char c;
do {
c = pathSpec.charAt(--ci);
} while (c == '/' || CharMatcher.whitespace().matches(c));
} while (c == '/' || StringUtils.isAnyBlank(Character.toString(c)));
return pathSpec.substring(start, ci + 1);
}

Expand Down
Loading

0 comments on commit 543aac9

Please sign in to comment.