From 16d6d00031cea2cc3b1c7102533efeacff795812 Mon Sep 17 00:00:00 2001 From: vanshikaagupta22 Date: Tue, 28 Apr 2026 08:45:18 +0000 Subject: [PATCH 1/7] Upgrade Guava library to version 32.0.0-jre-preview pod --- .../java/io/cdap/cdap/client/MetricsClient.java | 3 +-- .../java/io/cdap/cdap/client/ProgramClient.java | 2 +- .../cdap/cdap/client/config/ConnectionConfig.java | 3 ++- .../sourcecontrol/PatAuthenticationStrategy.java | 5 +++-- .../cdap/cdap/sourcecontrol/RepositoryManager.java | 14 +++++++------- .../sourcecontrol/worker/SourceControlTask.java | 2 +- .../java/io/cdap/cdap/test/MetricsManager.java | 7 +++---- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cdap-client/src/main/java/io/cdap/cdap/client/MetricsClient.java b/cdap-client/src/main/java/io/cdap/cdap/client/MetricsClient.java index 4b21dd937b02..fdf3733faf50 100644 --- a/cdap-client/src/main/java/io/cdap/cdap/client/MetricsClient.java +++ b/cdap-client/src/main/java/io/cdap/cdap/client/MetricsClient.java @@ -17,7 +17,6 @@ package io.cdap.cdap.client; import com.google.common.base.Joiner; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -324,7 +323,7 @@ private long getTotalCounter(Map tags, String metricName) { // since it is totals, we know there's one value only return timeValues[0].getValue(); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-client/src/main/java/io/cdap/cdap/client/ProgramClient.java b/cdap-client/src/main/java/io/cdap/cdap/client/ProgramClient.java index 68d4617170bb..d4f1973a57b5 100644 --- a/cdap-client/src/main/java/io/cdap/cdap/client/ProgramClient.java +++ b/cdap-client/src/main/java/io/cdap/cdap/client/ProgramClient.java @@ -407,7 +407,7 @@ public String call() throws Exception { Throwables.propagateIfPossible(e.getCause(), UnauthenticatedException.class); Throwables.propagateIfPossible(e.getCause(), ProgramNotFoundException.class); Throwables.propagateIfPossible(e.getCause(), IOException.class); - throw Throwables.propagate(e.getCause()); + throw new RuntimeException(e.getCause()); } } diff --git a/cdap-client/src/main/java/io/cdap/cdap/client/config/ConnectionConfig.java b/cdap-client/src/main/java/io/cdap/cdap/client/config/ConnectionConfig.java index b50f7b23f3d2..d82894ddcc0a 100644 --- a/cdap-client/src/main/java/io/cdap/cdap/client/config/ConnectionConfig.java +++ b/cdap-client/src/main/java/io/cdap/cdap/client/config/ConnectionConfig.java @@ -15,6 +15,7 @@ */ package io.cdap.cdap.client.config; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.base.Preconditions; import io.cdap.cdap.common.conf.CConfiguration; @@ -137,7 +138,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("hostname", hostname) .add("port", port) .add("sslEnabled", sslEnabled) diff --git a/cdap-source-control/src/main/java/io/cdap/cdap/sourcecontrol/PatAuthenticationStrategy.java b/cdap-source-control/src/main/java/io/cdap/cdap/sourcecontrol/PatAuthenticationStrategy.java index afa336a149f6..81b006f20d57 100644 --- a/cdap-source-control/src/main/java/io/cdap/cdap/sourcecontrol/PatAuthenticationStrategy.java +++ b/cdap-source-control/src/main/java/io/cdap/cdap/sourcecontrol/PatAuthenticationStrategy.java @@ -16,7 +16,6 @@ package io.cdap.cdap.sourcecontrol; -import com.google.common.base.Throwables; import io.cdap.cdap.api.security.store.SecureStore; import io.cdap.cdap.proto.sourcecontrol.PatConfig; import io.cdap.cdap.proto.sourcecontrol.RepositoryConfig; @@ -79,7 +78,9 @@ public void refresh() throws IOException, AuthenticationConfigException { try { data = secureStore.getData(namespaceId, passwordKeyName); } catch (Exception e) { - Throwables.propagateIfInstanceOf(e, IOException.class); + if (e instanceof IOException){ + throw (IOException) e; + } throw new AuthenticationConfigException("Failed to get password from secure store", e); } if (data == null) { diff --git a/cdap-source-control/src/main/java/io/cdap/cdap/sourcecontrol/RepositoryManager.java b/cdap-source-control/src/main/java/io/cdap/cdap/sourcecontrol/RepositoryManager.java index 919ad38fac36..279609676308 100644 --- a/cdap-source-control/src/main/java/io/cdap/cdap/sourcecontrol/RepositoryManager.java +++ b/cdap-source-control/src/main/java/io/cdap/cdap/sourcecontrol/RepositoryManager.java @@ -19,7 +19,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Stopwatch; import com.google.common.base.Strings; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import io.cdap.cdap.api.metrics.MetricsCollectionService; import io.cdap.cdap.api.metrics.MetricsContext; @@ -204,8 +203,9 @@ public static void validateConfig(final SecureStore secureStore, "Failed to list remotes in remote repository: " + e.getMessage(), e); } catch (Exception e) { - Throwables.propagateIfInstanceOf(e, - RepositoryConfigValidationException.class); + if (e instanceof RepositoryConfigValidationException) { + throw (RepositoryConfigValidationException) e; + } throw new RemoteRepositoryValidationException( "Failed to list remotes in remote repository.", e); @@ -233,7 +233,7 @@ public > CommitResult commitAndPush( CommitMeta commitMeta, Collection filesChanged, BiFunction hashConsumer) throws NoChangesToPushException, GitAPIException { validateInitialized(); - final Stopwatch stopwatch = new Stopwatch().start(); + final Stopwatch stopwatch = Stopwatch.createUnstarted().start(); // if the status is clean skip Status preStageStatus = git.status().call(); @@ -275,7 +275,7 @@ public > CommitResult commitAndPush( metricsContext.event( SourceControlManagement.COMMIT_PUSH_LATENCY_MILLIS, - stopwatch.stop().elapsedTime(TimeUnit.MILLISECONDS)); + stopwatch.stop().elapsed(TimeUnit.MILLISECONDS)); return new CommitResult<>(commit.getName(), output); } @@ -318,10 +318,10 @@ public String cloneRemote() .setBranch(branch); } - final Stopwatch stopwatch = new Stopwatch().start(); + final Stopwatch stopwatch = Stopwatch.createUnstarted().start(); git = command.call(); final long cloneTimeMillis = stopwatch.stop() - .elapsedTime(TimeUnit.MILLISECONDS); + .elapsed(TimeUnit.MILLISECONDS); // Record the repository size metric. try { diff --git a/cdap-source-control/src/main/java/io/cdap/cdap/sourcecontrol/worker/SourceControlTask.java b/cdap-source-control/src/main/java/io/cdap/cdap/sourcecontrol/worker/SourceControlTask.java index b2a3066f10a8..09e9716ee27e 100644 --- a/cdap-source-control/src/main/java/io/cdap/cdap/sourcecontrol/worker/SourceControlTask.java +++ b/cdap-source-control/src/main/java/io/cdap/cdap/sourcecontrol/worker/SourceControlTask.java @@ -56,7 +56,7 @@ abstract class SourceControlTask implements RunnableTask { @Override public void run(RunnableTaskContext context) throws Exception { - inMemoryOperationRunner.startAndWait(); + inMemoryOperationRunner.startAsync().awaitRunning(); doRun(context); } diff --git a/cdap-test/src/main/java/io/cdap/cdap/test/MetricsManager.java b/cdap-test/src/main/java/io/cdap/cdap/test/MetricsManager.java index 82dc6b5e780b..6bdeb4651045 100644 --- a/cdap-test/src/main/java/io/cdap/cdap/test/MetricsManager.java +++ b/cdap-test/src/main/java/io/cdap/cdap/test/MetricsManager.java @@ -19,7 +19,6 @@ import com.google.common.base.Joiner; import com.google.common.base.Preconditions; import com.google.common.base.Stopwatch; -import com.google.common.base.Throwables; import io.cdap.cdap.api.dataset.lib.cube.AggregationFunction; import io.cdap.cdap.api.dataset.lib.cube.TimeValue; import io.cdap.cdap.api.metrics.MetricDataQuery; @@ -134,8 +133,8 @@ public void waitForTotalMetricCount(Map tags, String metricName, // Min sleep time is 10ms, max sleep time is 1 seconds long sleepMillis = Math.max(10, Math.min(timeoutUnit.toMillis(timeout) / 10, TimeUnit.SECONDS.toMillis(1))); - Stopwatch stopwatch = new Stopwatch().start(); - while (value < count && stopwatch.elapsedTime(timeoutUnit) < timeout) { + Stopwatch stopwatch = Stopwatch.createUnstarted().start(); + while (value < count && stopwatch.elapsed(timeoutUnit) < timeout) { TimeUnit.MILLISECONDS.sleep(sleepMillis); value = getTotalMetric(tags, metricName); } @@ -239,7 +238,7 @@ private long getSingleValueFromTotals(MetricDataQuery query) { // since it is totals, we know there's one value only return timeValues.get(0).getValue(); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } From ace1fa1bd64c7d9bd8f5b6700aebefafba3cd862 Mon Sep 17 00:00:00 2001 From: Dheeraj Kholia Date: Wed, 22 Apr 2026 19:52:19 +0530 Subject: [PATCH 2/7] Upgrade Guava library to version 32.0.0-jre in CDAP common module - Updated the Guava dependency version in `pom.xml` to 32.0.0-jre. - Ensured compatibility with the upgraded Guava version. fixes commnet fixes fixes comments --- .vscode/settings.json | 3 + .../com/google/common/io/InputSupplier.java | 38 +++ .../com/google/common/io/OutputSupplier.java | 38 +++ .../cdap/common/HttpExceptionHandler.java | 6 +- .../cdap/cdap/common/app/MainClassLoader.java | 17 +- .../common/guice/FileContextProvider.java | 3 +- .../cdap/common/guice/KafkaClientModule.java | 114 +++++-- .../common/http/AbstractBodyConsumer.java | 13 +- .../cdap/common/http/CombineInputStream.java | 7 +- .../common/http/LocationBodyProducer.java | 10 +- .../common/http/SpillableBodyConsumer.java | 19 +- .../cdap/common/internal/guava/ClassPath.java | 2 +- .../common/io/DFSSeekableInputStream.java | 8 +- .../common/io/DefaultCachingPathProvider.java | 3 +- .../io/cdap/cdap/common/io/InputSupplier.java | 36 +++ .../io/cdap/cdap/common/io/Locations.java | 33 +- .../cdap/cdap/common/io/OutputSupplier.java | 36 +++ .../cdap/cdap/common/lang/ClassLoaders.java | 7 +- .../common/lang/DirectoryClassLoader.java | 3 +- .../cdap/common/lang/GuavaClassRewriter.java | 291 ------------------ .../cdap/common/lang/InstantiatorFactory.java | 6 +- .../cdap/common/lang/PropertyFieldSetter.java | 6 +- .../logging/AbstractLoggingContext.java | 6 +- .../resource/ResourceBalancerService.java | 19 +- .../cdap/common/security/YarnTokenUtils.java | 3 +- .../AbstractRetryableScheduledService.java | 30 +- .../common/service/CommandPortService.java | 6 +- .../service/RetryOnStartFailureService.java | 58 +++- .../io/cdap/cdap/common/service/Services.java | 14 +- .../twill/AbstractMasterTwillRunnable.java | 24 +- .../common/twill/NoopTwillController.java | 43 ++- .../cdap/common/utils/BatchingConsumer.java | 3 +- .../cdap/cdap/common/utils/ImmutablePair.java | 3 +- .../cdap/common/utils/TimeBoundIterator.java | 6 +- .../common/zookeeper/ZKExtOperations.java | 3 +- .../coordination/PartitionReplica.java | 3 +- .../coordination/ResourceCoordinator.java | 3 +- .../ResourceCoordinatorClient.java | 12 +- .../coordination/ResourceRequirement.java | 5 +- .../election/LeaderElectionInfoService.java | 8 +- .../java/io/cdap/cdap/data2/util/TableId.java | 3 +- .../extension/AbstractExtensionLoader.java | 3 +- .../internal/app/store/RunRecordDetail.java | 4 +- .../internal/io/ASMDatumWriterFactory.java | 3 +- .../internal/io/DatumWriterGenerator.java | 3 +- .../internal/io/FieldAccessorGenerator.java | 4 +- .../io/ReflectionFieldAccessorFactory.java | 6 +- .../cdap/common/conf/CConfigurationTest.java | 7 +- .../cdap/common/conf/ZKPropertyStoreTest.java | 8 +- .../common/guice/KafkaClientModuleTest.java | 36 +-- .../common/guice/ZkDiscoveryModuleTest.java | 12 +- .../remote/RemoteTaskExecutorTest.java | 69 +++-- .../resource/ResourceBalancerServiceTest.java | 22 +- .../service/CommandPortServiceTest.java | 15 +- .../RetryOnStartFailureServiceTest.java | 15 +- .../RetryableScheduledServiceTest.java | 16 +- .../cdap/cdap/common/ssh/SSHSessionTest.java | 25 +- .../cdap/common/test/MockTwillContext.java | 3 +- .../common/utils/TimeBoundIteratorTest.java | 6 +- .../common/zookeeper/ZKExtOperationsTest.java | 23 +- .../coordination/ResourceCoordinatorTest.java | 16 +- .../LeaderElectionInfoServiceTest.java | 18 +- pom.xml | 15 +- 63 files changed, 702 insertions(+), 578 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 cdap-common/src/main/java/com/google/common/io/InputSupplier.java create mode 100644 cdap-common/src/main/java/com/google/common/io/OutputSupplier.java create mode 100644 cdap-common/src/main/java/io/cdap/cdap/common/io/InputSupplier.java create mode 100644 cdap-common/src/main/java/io/cdap/cdap/common/io/OutputSupplier.java delete mode 100644 cdap-common/src/main/java/io/cdap/cdap/common/lang/GuavaClassRewriter.java diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000000..be975570a20c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.compile.nullAnalysis.mode": "disabled" +} \ No newline at end of file diff --git a/cdap-common/src/main/java/com/google/common/io/InputSupplier.java b/cdap-common/src/main/java/com/google/common/io/InputSupplier.java new file mode 100644 index 000000000000..5500bef7e440 --- /dev/null +++ b/cdap-common/src/main/java/com/google/common/io/InputSupplier.java @@ -0,0 +1,38 @@ +/* + * Copyright © 2026 Cask Data, Inc. + * + * Licensed 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 com.google.common.io; + +import java.io.IOException; + +/** + * Stub for the removed {@code com.google.common.io.InputSupplier} interface. + * This interface was removed in Guava 21 but is still referenced by the + * {@code common-http} library. This stub allows compilation to succeed. + * + * @param the type of input object supplied + */ +@FunctionalInterface +public interface InputSupplier { + + /** + * Returns an input object that can be used for reading. + * + * @return the input object + * @throws IOException if an I/O error occurs + */ + T getInput() throws IOException; +} diff --git a/cdap-common/src/main/java/com/google/common/io/OutputSupplier.java b/cdap-common/src/main/java/com/google/common/io/OutputSupplier.java new file mode 100644 index 000000000000..e06a643d8b7d --- /dev/null +++ b/cdap-common/src/main/java/com/google/common/io/OutputSupplier.java @@ -0,0 +1,38 @@ +/* + * Copyright © 2026 Cask Data, Inc. + * + * Licensed 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 com.google.common.io; + +import java.io.IOException; + +/** + * Stub for the removed {@code com.google.common.io.OutputSupplier} interface. + * This interface was removed in Guava 21 but is still referenced by the + * {@code twill} library. This stub allows compilation to succeed. + * + * @param the type of output object supplied + */ +@FunctionalInterface +public interface OutputSupplier { + + /** + * Returns an output object that can be used for writing. + * + * @return the output object + * @throws IOException if an I/O error occurs + */ + T getOutput() throws IOException; +} diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/HttpExceptionHandler.java b/cdap-common/src/main/java/io/cdap/cdap/common/HttpExceptionHandler.java index 5e345694fd8b..a688b88e8f9c 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/HttpExceptionHandler.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/HttpExceptionHandler.java @@ -16,7 +16,7 @@ package io.cdap.cdap.common; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.common.base.Throwables; import io.cdap.cdap.api.common.HttpErrorStatusProvider; import io.cdap.cdap.api.service.ServiceUnavailableException; @@ -76,7 +76,7 @@ public void handle(Throwable t, HttpRequest request, HttpResponder responder) { // If it is not some known exception type, response with 500. LOG.error("Unexpected error: request={} {} user={}:", request.method().name(), request.getUri(), - Objects.firstNonNull(SecurityRequestContext.getUserId(), ""), t); + MoreObjects.firstNonNull(SecurityRequestContext.getUserId(), ""), t); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, Throwables.getRootCause(t).getMessage()); } @@ -84,6 +84,6 @@ public void handle(Throwable t, HttpRequest request, HttpResponder responder) { private void logWithTrace(HttpRequest request, Throwable t) { LOG.trace("Error in handling request={} {} for user={}:", request.method().name(), request.getUri(), - Objects.firstNonNull(SecurityRequestContext.getUserId(), ""), t); + MoreObjects.firstNonNull(SecurityRequestContext.getUserId(), ""), t); } } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/app/MainClassLoader.java b/cdap-common/src/main/java/io/cdap/cdap/common/app/MainClassLoader.java index f5012269ab72..4a65226a3da3 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/app/MainClassLoader.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/app/MainClassLoader.java @@ -16,7 +16,6 @@ package io.cdap.cdap.common.app; -import com.google.common.base.Splitter; import com.google.common.base.Throwables; import io.cdap.cdap.api.dataset.Dataset; import io.cdap.cdap.common.dataset.DatasetClassRewriter; @@ -24,17 +23,13 @@ import io.cdap.cdap.common.lang.ClassPathResources; import io.cdap.cdap.common.lang.CombineClassLoader; import io.cdap.cdap.common.lang.FilterClassLoader; -import io.cdap.cdap.common.lang.GuavaClassRewriter; import io.cdap.cdap.common.lang.InterceptableClassLoader; import io.cdap.cdap.common.leveldb.LevelDBClassRewriter; import io.cdap.cdap.common.security.AuthEnforceRewriter; -import io.cdap.cdap.common.utils.DirUtils; import io.cdap.cdap.internal.asm.Classes; import java.io.ByteArrayInputStream; -import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; @@ -53,7 +48,6 @@ public class MainClassLoader extends InterceptableClassLoader { private static final String DATASET_CLASS_NAME = Dataset.class.getName(); - private final GuavaClassRewriter guavaClassRewriter; private final DatasetClassRewriter datasetRewriter; private final AuthEnforceRewriter authEnforceRewriter; private final LevelDBClassRewriter levelDBClassRewriter; @@ -137,7 +131,6 @@ public static MainClassLoader createFromContext(FilterClassLoader.Filter filter, */ public MainClassLoader(URL[] urls, ClassLoader parent) { super(urls, parent); - this.guavaClassRewriter = new GuavaClassRewriter(); this.datasetRewriter = new DatasetClassRewriter(); this.authEnforceRewriter = new AuthEnforceRewriter(); this.levelDBClassRewriter = new LevelDBClassRewriter(); @@ -150,7 +143,8 @@ protected boolean needIntercept(String className) { try { return isRewriteNeeded(className); } catch (IOException e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } @@ -159,10 +153,6 @@ protected boolean needIntercept(String className) { public byte[] rewriteClass(String className, InputStream input) throws IOException { byte[] rewrittenCode = null; - if (guavaClassRewriter.needRewrite(className)) { - rewrittenCode = guavaClassRewriter.rewriteClass(className, input); - } - if (isDatasetRewriteNeeded(className)) { rewrittenCode = datasetRewriter.rewriteClass(className, input); } @@ -179,8 +169,7 @@ public byte[] rewriteClass(String className, InputStream input) throws IOExcepti } private boolean isRewriteNeeded(String className) throws IOException { - return guavaClassRewriter.needRewrite(className) - || levelDBClassRewriter.needRewrite(className) + return levelDBClassRewriter.needRewrite(className) || isDatasetRewriteNeeded(className) || isAuthRewriteNeeded(className); } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/guice/FileContextProvider.java b/cdap-common/src/main/java/io/cdap/cdap/common/guice/FileContextProvider.java index 456954618a13..2af2ece5d34d 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/guice/FileContextProvider.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/guice/FileContextProvider.java @@ -69,7 +69,8 @@ private UserGroupInformation createUGI() { return UserGroupInformation.createRemoteUser(hdfsUser); } } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/guice/KafkaClientModule.java b/cdap-common/src/main/java/io/cdap/cdap/common/guice/KafkaClientModule.java index a90f9d361a51..3a9cc5e76801 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/guice/KafkaClientModule.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/guice/KafkaClientModule.java @@ -17,8 +17,6 @@ package io.cdap.cdap.common.guice; import com.google.common.util.concurrent.AbstractIdleService; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.Service; import com.google.inject.Inject; import com.google.inject.Injector; @@ -32,6 +30,7 @@ import io.cdap.cdap.common.conf.KafkaConstants; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; import org.apache.twill.common.Cancellable; import org.apache.twill.internal.kafka.client.ZKBrokerService; @@ -129,23 +128,90 @@ public ZKClientService get() { // The logic doesn't need to be sophisticated since it is a private binding and only used by the // wrapping KafkaClientService and BrokerService, which they will make sure no duplicate calls will be // made to the start/stop methods. - return new ForwardingZKClientService(zkClientService) { - @Override - public ListenableFuture start() { - if (startedCount.getAndIncrement() == 0) { - return super.start(); - } - return Futures.immediateFuture(State.RUNNING); - } + final ZKClientService delegate = zkClientService; + return new RefCountZKClientService(delegate, startedCount); + } + } - @Override - public ListenableFuture stop() { - if (startedCount.decrementAndGet() == 0) { - return super.stop(); - } - return Futures.immediateFuture(State.TERMINATED); - } - }; + /** + * A {@link ZKClientService} wrapper using simple reference counting for start/stop. + * This wrapper is necessary because the underlying {@link ZKClientService} instance is shared between + * {@link DefaultKafkaClientService} and {@link DefaultBrokerService}. Both services manage its lifecycle; + * reference counting ensures the ZK client is only started once and remains open until both services are stopped. + */ + private static final class RefCountZKClientService extends ForwardingZKClientService { + + private final ZKClientService delegate; + private final AtomicInteger startedCount; + + RefCountZKClientService(ZKClientService delegate, AtomicInteger startedCount) { + super(delegate); + this.delegate = delegate; + this.startedCount = startedCount; + } + + @Override + public Service startAsync() { + if (startedCount.getAndIncrement() == 0) { + delegate.startAsync(); + } + return this; + } + + @Override + public Service stopAsync() { + if (startedCount.decrementAndGet() == 0) { + delegate.stopAsync(); + } + return this; + } + + @Override + public Throwable failureCause() { + return delegate.failureCause(); + } + + @Override + public void awaitRunning() { + delegate.awaitRunning(); + } + + @Override + public void awaitRunning(long timeout, TimeUnit unit) throws TimeoutException { + delegate.awaitRunning(timeout, unit); + } + + @Override + public void awaitTerminated() { + // If the delegate was not actually stopped (ref count > 0), return immediately + if (startedCount.get() > 0) { + return; + } + delegate.awaitTerminated(); + } + + @Override + public void awaitTerminated(long timeout, TimeUnit unit) throws TimeoutException { + // If the delegate was not actually stopped (ref count > 0), return immediately + if (startedCount.get() > 0) { + return; + } + delegate.awaitTerminated(timeout, unit); + } + + @Override + public State state() { + return delegate.state(); + } + + @Override + public boolean isRunning() { + return delegate.isRunning(); + } + + @Override + public void addListener(Listener listener, Executor executor) { + delegate.addListener(listener, executor); } } @@ -166,12 +232,12 @@ private abstract static class AbstractServiceWithZkClient ext @Override protected final void startUp() throws Exception { - zkClientService.startAndWait(); + zkClientService.startAsync().awaitRunning(); try { - delegate.startAndWait(); + delegate.startAsync().awaitRunning(); } catch (Exception e) { try { - zkClientService.stopAndWait(); + zkClientService.stopAsync().awaitTerminated(); } catch (Exception se) { e.addSuppressed(se); } @@ -182,16 +248,16 @@ protected final void startUp() throws Exception { @Override protected final void shutDown() throws Exception { try { - delegate.stopAndWait(); + delegate.stopAsync().awaitTerminated(); } catch (Exception e) { try { - zkClientService.stopAndWait(); + zkClientService.stopAsync().awaitTerminated(); } catch (Exception se) { e.addSuppressed(se); } throw e; } - zkClientService.stopAndWait(); + zkClientService.stopAsync().awaitTerminated(); } protected T getDelegate() { diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/http/AbstractBodyConsumer.java b/cdap-common/src/main/java/io/cdap/cdap/common/http/AbstractBodyConsumer.java index 9543e33fa80c..c991b2140798 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/http/AbstractBodyConsumer.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/http/AbstractBodyConsumer.java @@ -17,7 +17,6 @@ package io.cdap.cdap.common.http; import com.google.common.base.Throwables; -import com.google.common.io.Closeables; import io.cdap.http.BodyConsumer; import io.cdap.http.HttpResponder; import io.netty.buffer.ByteBuf; @@ -51,7 +50,8 @@ public void chunk(ByteBuf request, HttpResponder responder) { } request.readBytes(output, request.readableBytes()); } catch (IOException e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } @@ -63,7 +63,8 @@ public final void finished(HttpResponder responder) { } onFinish(responder, file); } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } finally { cleanup(); } @@ -74,7 +75,11 @@ public final void handleError(Throwable cause) { try { LOG.error("Failed to handle upload", cause); if (output != null) { - Closeables.closeQuietly(output); + try { + output.close(); + } catch (Exception ignored) { + // Ignored, as we are already in error handling mode and want to continue cleanup + } } onError(cause); // The netty-http framework will response with 500, no need to response in here. diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/http/CombineInputStream.java b/cdap-common/src/main/java/io/cdap/cdap/common/http/CombineInputStream.java index e0c0ddfd8809..98d8433b35cc 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/http/CombineInputStream.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/http/CombineInputStream.java @@ -16,7 +16,6 @@ package io.cdap.cdap.common.http; -import com.google.common.io.Closeables; import io.cdap.cdap.common.io.FileSeekableInputStream; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufInputStream; @@ -82,7 +81,11 @@ public int available() throws IOException { @Override public void close() throws IOException { - Closeables.closeQuietly(bufferStream); + try { + bufferStream.close(); + } catch (IOException ignored) { + // Ignored to ensure spillStream is closed even if bufferStream.close() fails + } if (spillStream != null) { spillStream.close(); } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/http/LocationBodyProducer.java b/cdap-common/src/main/java/io/cdap/cdap/common/http/LocationBodyProducer.java index 5e0447a43518..0166ffb54dc4 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/http/LocationBodyProducer.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/http/LocationBodyProducer.java @@ -16,10 +16,10 @@ package io.cdap.cdap.common.http; -import com.google.common.io.Closeables; import io.cdap.http.BodyProducer; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; +import java.io.IOException; import java.io.InputStream; import javax.annotation.Nullable; import org.apache.twill.filesystem.Location; @@ -65,6 +65,12 @@ public void handleError(@Nullable Throwable throwable) { if (throwable != null) { LOG.warn("Error in sending location {}", location, throwable); } - Closeables.closeQuietly(inputStream); + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException ignored) { + // Ignored during cleanup + } + } } } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/http/SpillableBodyConsumer.java b/cdap-common/src/main/java/io/cdap/cdap/common/http/SpillableBodyConsumer.java index 10ee554be82f..5416c2a4c561 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/http/SpillableBodyConsumer.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/http/SpillableBodyConsumer.java @@ -17,7 +17,6 @@ package io.cdap.cdap.common.http; import com.google.common.base.Throwables; -import com.google.common.io.Closeables; import io.cdap.http.BodyConsumer; import io.cdap.http.HttpResponder; import io.netty.buffer.ByteBuf; @@ -88,12 +87,18 @@ public void chunk(ByteBuf request, HttpResponder responder) { @Override public void finished(HttpResponder responder) { - Closeables.closeQuietly(outputStream); + try { + if (outputStream != null) { + outputStream.close(); + } + } catch (IOException ignored) { + // Ignored during cleanup + } try (InputStream is = new CombineInputStream(buffer, outputStream == null ? null : spillPath)) { processInput(is, responder); } catch (Exception e) { - Throwables.propagateIfPossible(e); + Throwables.throwIfUnchecked(e); throw new RuntimeException(String.format("Failed to process input from buffer%s", outputStream == null ? "" : " and spill path " + spillPath), e); } finally { @@ -103,7 +108,13 @@ public void finished(HttpResponder responder) { @Override public void handleError(Throwable cause) { - Closeables.closeQuietly(outputStream); + try { + if (outputStream != null) { + outputStream.close(); + } + } catch (IOException ignored) { + // Ignored during cleanup + } cleanup(); } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/internal/guava/ClassPath.java b/cdap-common/src/main/java/io/cdap/cdap/common/internal/guava/ClassPath.java index 2f7d0e9c1fd9..d9152169006a 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/internal/guava/ClassPath.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/internal/guava/ClassPath.java @@ -328,7 +328,7 @@ public String getSimpleName() { String innerClassName = className.substring(lastDollarSign + 1); // local and anonymous classes are prefixed with number (1,2,3...), anonymous classes are // entirely numeric whereas local classes have the user supplied name as a suffix - return CharMatcher.DIGIT.trimLeadingFrom(innerClassName); + return CharMatcher.inRange('0', '9').trimLeadingFrom(innerClassName); } String packageName = getPackageName(); if (packageName.isEmpty()) { diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/io/DFSSeekableInputStream.java b/cdap-common/src/main/java/io/cdap/cdap/common/io/DFSSeekableInputStream.java index 16ca5b46db1c..9e6575539a4a 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/io/DFSSeekableInputStream.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/io/DFSSeekableInputStream.java @@ -16,12 +16,10 @@ package io.cdap.cdap.common.io; -import com.google.common.io.Closeables; import java.io.Closeable; import java.io.IOException; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.Seekable; -import org.apache.twill.filesystem.Location; /** * Implementation of {@link SeekableInputStream} for {@link Location}. @@ -69,7 +67,11 @@ public void close() throws IOException { super.close(); } finally { if (sizeProvider instanceof Closeable) { - Closeables.closeQuietly((Closeable) sizeProvider); + try { + ((Closeable) sizeProvider).close(); + } catch (Exception ignored) { + // Ignored during cleanup + } } } } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/io/DefaultCachingPathProvider.java b/cdap-common/src/main/java/io/cdap/cdap/common/io/DefaultCachingPathProvider.java index 15e0c8988c43..c36b99e3de6f 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/io/DefaultCachingPathProvider.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/io/DefaultCachingPathProvider.java @@ -25,6 +25,7 @@ import io.cdap.cdap.common.utils.DirUtils; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -123,7 +124,7 @@ void clearCache(String fileName, long lastModified) { } String getCacheName(Location location) { - return Hashing.md5().hashString(location.toURI().getPath()).toString() + "-" + return Hashing.md5().hashString(location.toURI().getPath(), StandardCharsets.UTF_8).toString() + "-" + location.getName(); } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/io/InputSupplier.java b/cdap-common/src/main/java/io/cdap/cdap/common/io/InputSupplier.java new file mode 100644 index 000000000000..1ff1f6b18693 --- /dev/null +++ b/cdap-common/src/main/java/io/cdap/cdap/common/io/InputSupplier.java @@ -0,0 +1,36 @@ +/* + * Copyright © 2026 Cask Data, Inc. + * + * Licensed 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 io.cdap.cdap.common.io; + +import java.io.IOException; + +/** + * A replacement for the removed {@code com.google.common.io.InputSupplier}. + * Supplies an input stream of type {@code T}. + * + * @param the type of input object supplied + */ +@FunctionalInterface +public interface InputSupplier { + + /** + * Returns an input object that can be used for reading. + * + * @return the input object + * @throws IOException if an I/O error occurs + */ + T getInput() throws IOException; +} diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/io/Locations.java b/cdap-common/src/main/java/io/cdap/cdap/common/io/Locations.java index 4eb04253b402..eb227edf175b 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/io/Locations.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/io/Locations.java @@ -20,9 +20,6 @@ import com.google.common.base.Suppliers; import com.google.common.base.Throwables; import com.google.common.io.ByteStreams; -import com.google.common.io.Closeables; -import com.google.common.io.InputSupplier; -import com.google.common.io.OutputSupplier; import io.cdap.cdap.common.lang.FunctionWithException; import io.cdap.cdap.common.lang.jar.BundleJarUtil; import io.cdap.cdap.common.utils.DirUtils; @@ -115,8 +112,14 @@ public SeekableInputStream getInput() throws IOException { return new DFSSeekableInputStream(input, createDFSStreamSizeProvider(fs, false, path, input)); } catch (Throwable t) { - Closeables.closeQuietly(input); - Throwables.propagateIfInstanceOf(t, IOException.class); + try { + input.close(); + } catch (Exception ignored) { + // Ignored during cleanup + } + if (t instanceof IOException) { + throw (IOException) t; + } throw new IOException(t); } } @@ -169,8 +172,14 @@ public SeekableInputStream run() throws IOException { throw new IOException("Failed to create SeekableInputStream from location " + location); } catch (Throwable t) { - Closeables.closeQuietly(input); - Throwables.propagateIfInstanceOf(t, IOException.class); + try { + input.close(); + } catch (Exception ignored) { + // Ignored during cleanup + } + if (t instanceof IOException) { + throw (IOException) t; + } throw new IOException(t); } } @@ -343,7 +352,9 @@ private static void expandTarStream(TarArchiveInputStream tis, File targetDir) DirUtils.mkdirs(output); } else { DirUtils.mkdirs(output.getParentFile()); - ByteStreams.copy(tis, com.google.common.io.Files.newOutputStreamSupplier(output)); + try (OutputStream os = java.nio.file.Files.newOutputStream(output.toPath())) { + ByteStreams.copy(tis, os); + } } entry = tis.getNextTarEntry(); } @@ -484,7 +495,8 @@ public static Location getLocationFromAbsolutePath(LocationFactory locationFacto return locationFactory.create(uri); } catch (URISyntaxException e) { // Should not happen. - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } @@ -570,7 +582,8 @@ public Method get() { } return getFileLengthMethod; } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } }); diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/io/OutputSupplier.java b/cdap-common/src/main/java/io/cdap/cdap/common/io/OutputSupplier.java new file mode 100644 index 000000000000..52062bec9517 --- /dev/null +++ b/cdap-common/src/main/java/io/cdap/cdap/common/io/OutputSupplier.java @@ -0,0 +1,36 @@ +/* + * Copyright © 2026 Cask Data, Inc. + * + * Licensed 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 io.cdap.cdap.common.io; + +import java.io.IOException; + +/** + * A replacement for the removed {@code com.google.common.io.OutputSupplier}. + * Supplies an output stream of type {@code T}. + * + * @param the type of output object supplied + */ +@FunctionalInterface +public interface OutputSupplier { + + /** + * Returns an output object that can be used for writing. + * + * @return the output object + * @throws IOException if an I/O error occurs + */ + T getOutput() throws IOException; +} diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/lang/ClassLoaders.java b/cdap-common/src/main/java/io/cdap/cdap/common/lang/ClassLoaders.java index dfc46ccabd46..830dbeadd3e0 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/lang/ClassLoaders.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/lang/ClassLoaders.java @@ -16,7 +16,7 @@ package io.cdap.cdap.common.lang; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.common.base.Splitter; import com.google.common.base.Throwables; import java.io.File; @@ -67,7 +67,7 @@ private ClassLoaders() { */ public static Class loadClass(String className, @Nullable ClassLoader classLoader, Object caller) throws ClassNotFoundException { - ClassLoader cl = Objects.firstNonNull(classLoader, caller.getClass().getClassLoader()); + ClassLoader cl = MoreObjects.firstNonNull(classLoader, caller.getClass().getClassLoader()); return cl.loadClass(className); } @@ -283,7 +283,8 @@ public static URL getClassPathURL(String className, URL classUrl) { return URI.create(path.substring(0, path.indexOf("!/"))).toURL(); } } catch (MalformedURLException e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } throw new IllegalStateException("Unsupported class URL: " + classUrl); } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/lang/DirectoryClassLoader.java b/cdap-common/src/main/java/io/cdap/cdap/common/lang/DirectoryClassLoader.java index 01f2299b37b9..4ce3f69e3801 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/lang/DirectoryClassLoader.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/lang/DirectoryClassLoader.java @@ -135,7 +135,8 @@ private static URL[] getClassPathURLs(File dir, @Nullable String extraClassPath, } catch (MalformedURLException e) { // Should never happen LOG.error("Error in adding jar URLs to classPathUrls", e); - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/lang/GuavaClassRewriter.java b/cdap-common/src/main/java/io/cdap/cdap/common/lang/GuavaClassRewriter.java deleted file mode 100644 index 87a848708337..000000000000 --- a/cdap-common/src/main/java/io/cdap/cdap/common/lang/GuavaClassRewriter.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Copyright © 2020 Cask Data, Inc. - * - * Licensed 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 io.cdap.cdap.common.lang; - -import com.google.common.base.Preconditions; -import com.google.common.util.concurrent.MoreExecutors; -import io.cdap.cdap.internal.asm.Methods; -import java.io.IOException; -import java.io.InputStream; -import java.lang.invoke.LambdaMetafactory; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Executor; -import javax.annotation.Nullable; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Handle; -import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.Type; -import org.objectweb.asm.commons.GeneratorAdapter; -import org.objectweb.asm.commons.Method; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * A {@link ClassRewriter} for rewriting Guava library classes to add missing functions that are - * available in later Guava library. Those new methods are being used by Hadoop 3 until 3.4 - * (HADOOP-17288). - * - * In particular, in the Preconditions class, there are new checkState and checkArgument methods - * that take different number of arguments for error message formatting purpose, instead of just the - * generic vararg method. Also, in the MoreExecutors class, there is a new directExecutor() method - * that replace the functionality of the the sameThreadExecutor(). - */ -public class GuavaClassRewriter implements ClassRewriter { - - private static final Logger LOG = LoggerFactory.getLogger(GuavaClassRewriter.class); - private static final String PRECONDTIONS_CLASS_NAME = "com.google.common.base.Preconditions"; - private static final String MORE_EXECUTORS_CLASS_NAME = "com.google.common.util.concurrent.MoreExecutors"; - private static final Type OBJECT_TYPE = Type.getType(Object.class); - private static final Type STRING_TYPE = Type.getType(String.class); - private static final Type RUNNABLE_TYPE = Type.getType(Runnable.class); - - /** - * Returns {@code true} if the given class needs to be rewritten. - */ - public boolean needRewrite(String className) { - return PRECONDTIONS_CLASS_NAME.equals(className) || MORE_EXECUTORS_CLASS_NAME.equals(className); - } - - @Nullable - @Override - public byte[] rewriteClass(String className, InputStream input) throws IOException { - if (PRECONDTIONS_CLASS_NAME.equals(className)) { - return rewritePreconditions(input); - } - if (MORE_EXECUTORS_CLASS_NAME.equals(className)) { - return rewriteMoreExecutors(input); - } - return null; - } - - /** - * Rewrites the {@link Preconditions} class to add various {@code checkArgument}, {@code - * checkState}, and {@code checkNotNull} methods that are missing in earlier Guava library. - * - * @param input the bytecode stream of the Preconditions class - * @return the rewritten bytecode - * @throws IOException if failed to rewrite - */ - private byte[] rewritePreconditions(InputStream input) throws IOException { - Type[] types = new Type[]{ - OBJECT_TYPE, - Type.CHAR_TYPE, - Type.INT_TYPE, - Type.LONG_TYPE - }; - - // Generates all the methods that we need to add to the Preconditions class - // There are multiple of them, each take one or combinations of two parameters of type Object, char, int, and long - // for the string formatting template to use - List methods = new ArrayList<>(); - // Carry the list of method templates for generating new methods. - // Each template contains the method name, the first argument type, and the return type. - List methodTemplates = Arrays.asList( - new Method("checkArgument", Type.VOID_TYPE, new Type[]{Type.BOOLEAN_TYPE}), - new Method("checkState", Type.VOID_TYPE, new Type[]{Type.BOOLEAN_TYPE}), - new Method("checkNotNull", Type.getType(Object.class), - new Type[]{Type.getType(Object.class)}) - ); - - for (Method method : methodTemplates) { - String methodName = method.getName(); - Type returnType = method.getReturnType(); - Type firstArgType = method.getArgumentTypes()[0]; - - for (Type type : types) { - methods.add(new Method(methodName, returnType, - new Type[]{firstArgType, STRING_TYPE, type})); - for (Type type2 : types) { - methods.add(new Method(methodName, returnType, - new Type[]{firstArgType, STRING_TYPE, type, type2})); - } - } - - // Later version of Preconditions class also added methods that take three and four Objects - methods.add(new Method(methodName, returnType, - new Type[]{firstArgType, STRING_TYPE, OBJECT_TYPE, OBJECT_TYPE, OBJECT_TYPE})); - methods.add(new Method(methodName, returnType, - new Type[]{firstArgType, STRING_TYPE, - OBJECT_TYPE, OBJECT_TYPE, OBJECT_TYPE, OBJECT_TYPE})); - } - - ClassReader cr = new ClassReader(input); - ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); - cr.accept(new PreconditionsRewriter(Opcodes.ASM7, cw, methods), ClassReader.EXPAND_FRAMES); - return cw.toByteArray(); - } - - /** - * Rewrites the {@link MoreExecutors} class to add the {@code directExecutor} method. - * - * @param input the bytecode stream of the MoreExecutors class - * @return the rewritten bytecode - * @throws IOException if failed to rewrite - */ - private byte[] rewriteMoreExecutors(InputStream input) throws IOException { - ClassReader cr = new ClassReader(input); - ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); - - Method method = new Method("directExecutor", Type.getType(Executor.class), new Type[0]); - cr.accept(new ClassVisitor(Opcodes.ASM7, cw) { - - private boolean hasMethod; - - @Override - public void visit(int version, int access, String name, String signature, String superName, - String[] interfaces) { - // Rewrite the class to 1.7 format so that we can use lambda to implement the directExecutor() method - super.visit(Opcodes.V1_7, access, name, signature, superName, interfaces); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String descriptor, - String signature, String[] exceptions) { - if (method.equals(new Method(name, descriptor)) - && (access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC - && (access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) { - hasMethod = true; - } - return super.visitMethod(access, name, descriptor, signature, exceptions); - } - - @Override - public void visitEnd() { - if (hasMethod) { - super.visitEnd(); - return; - } - - // Generate the method - // public static Executor directExecutor() { - // return Runnable::run; - // } - MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, - method.getName(), method.getDescriptor(), null, null); - GeneratorAdapter adapter = new GeneratorAdapter(mv, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, - method.getName(), method.getDescriptor()); - // Perform the lambda invocation. - Handle metaFactoryHandle = new Handle(Opcodes.H_INVOKESTATIC, - Type.getType(LambdaMetafactory.class).getInternalName(), - "metafactory", Methods.LAMBDA_META_FACTORY_METHOD_DESC, false); - Handle lambdaMethodHandle = new Handle(Opcodes.H_INVOKEINTERFACE, - RUNNABLE_TYPE.getInternalName(), - "run", Type.getMethodDescriptor(Type.VOID_TYPE), true); - - // Signature of the Executor.execute(Runnable) - Type samMethodType = Type.getType(Type.getMethodDescriptor(Type.VOID_TYPE, RUNNABLE_TYPE)); - adapter.invokeDynamic("execute", Type.getMethodDescriptor(Type.getType(Executor.class)), - metaFactoryHandle, samMethodType, lambdaMethodHandle, samMethodType); - adapter.returnValue(); - adapter.endMethod(); - super.visitEnd(); - } - }, ClassReader.EXPAND_FRAMES); - - return cw.toByteArray(); - } - - /** - * A {@link ClassVisitor} to add a set of missing methods to the {@link Preconditions} class. - */ - private static final class PreconditionsRewriter extends ClassVisitor { - - private final Set methods; - - PreconditionsRewriter(int api, ClassVisitor classVisitor, Collection methods) { - super(api, classVisitor); - this.methods = new LinkedHashSet<>(methods); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String descriptor, - String signature, String[] exceptions) { - Method method = new Method(name, descriptor); - if (methods.contains(method) - && (access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC - && (access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) { - methods.remove(method); - } - return super.visitMethod(access, name, descriptor, signature, exceptions); - } - - @Override - public void visitEnd() { - for (Method method : methods) { - LOG.trace("{}.{} not found. Rewriting class to inject the missing method", - PRECONDTIONS_CLASS_NAME, method); - - // Generate the missing method that calls the version with varargs - // For example, - // - // public static void checkArgument(boolean expression, String template, Object arg) { - // checkArgument(expression, template, new Object[] { arg }); - // } - MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, - method.getName(), method.getDescriptor(), null, null); - GeneratorAdapter adapter = new GeneratorAdapter(mv, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, - method.getName(), method.getDescriptor()); - adapter.loadArg(0); - adapter.loadArg(1); - - // New an array of size based on the number of parameters - int objectArray = adapter.newLocal(Type.getType(Object[].class)); - - Type[] argTypes = method.getArgumentTypes(); - adapter.push(argTypes.length - 2); - adapter.newArray(OBJECT_TYPE); - adapter.storeLocal(objectArray); - - // Put the arguments into the Object array - for (int i = 0; i < argTypes.length - 2; i++) { - Type argType = argTypes[i + 2]; - adapter.loadLocal(objectArray); - adapter.push(i); - adapter.loadArg(i + 2); - // If the given argument is not an Object, turn it into a String - if (argType.getSort() != Type.OBJECT) { - adapter.invokeStatic(STRING_TYPE, - new Method("valueOf", STRING_TYPE, new Type[]{argType})); - } - adapter.arrayStore(OBJECT_TYPE); - } - adapter.loadLocal(objectArray); - - // Call the varargs method - adapter.invokeStatic(Type.getObjectType(PRECONDTIONS_CLASS_NAME.replace('.', '/')), - new Method(method.getName(), method.getReturnType(), - new Type[]{ - method.getArgumentTypes()[0], - method.getArgumentTypes()[1], - Type.getType(Object[].class) - })); - adapter.returnValue(); - adapter.endMethod(); - } - - super.visitEnd(); - } - } -} diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/lang/InstantiatorFactory.java b/cdap-common/src/main/java/io/cdap/cdap/common/lang/InstantiatorFactory.java index 3616bc6fba22..5c42c215166d 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/lang/InstantiatorFactory.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/lang/InstantiatorFactory.java @@ -98,7 +98,8 @@ public T create() { try { return (T) defaultCons.newInstance(); } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } }; @@ -184,7 +185,8 @@ public T create() { } return (T) instance; } catch (InstantiationException | IllegalAccessException e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } }; diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/lang/PropertyFieldSetter.java b/cdap-common/src/main/java/io/cdap/cdap/common/lang/PropertyFieldSetter.java index fa1c3863b9bc..fb0aa5cefe48 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/lang/PropertyFieldSetter.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/lang/PropertyFieldSetter.java @@ -79,10 +79,12 @@ private void setValue(Object instance, Field field, String value) throws Illegal field.set(instance, fieldType.getMethod("valueOf", String.class).invoke(null, value)); } catch (NoSuchMethodException e) { // Should never happen, as boxed type always have the valueOf(String) method. - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } catch (InvocationTargetException e) { // Also should never happen, as calling method on Java bootstrap classes should always succeed. - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/logging/AbstractLoggingContext.java b/cdap-common/src/main/java/io/cdap/cdap/common/logging/AbstractLoggingContext.java index 11f95f46aaa0..fe88d0b2d816 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/logging/AbstractLoggingContext.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/logging/AbstractLoggingContext.java @@ -16,7 +16,7 @@ package io.cdap.cdap.common.logging; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.common.collect.Maps; import java.lang.reflect.Method; import java.util.Collection; @@ -113,7 +113,7 @@ public Map getSystemTagsAsString() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("systemTags", systemTags) .toString(); } @@ -140,7 +140,7 @@ public String getValue() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("name", name) .add("value", value) .toString(); diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/resource/ResourceBalancerService.java b/cdap-common/src/main/java/io/cdap/cdap/common/resource/ResourceBalancerService.java index 42283b6e1fcf..6941c3de4120 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/resource/ResourceBalancerService.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/resource/ResourceBalancerService.java @@ -94,13 +94,13 @@ public void leader() { coordinator = new ResourceCoordinator(zk, discoveryServiceClient, new BalancedAssignmentStrategy()); - coordinator.startAndWait(); + coordinator.startAsync().awaitRunning(); } @Override public void follower() { if (coordinator != null) { - coordinator.stopAndWait(); + coordinator.stopAsync().awaitTerminated(); coordinator = null; } } @@ -130,8 +130,8 @@ protected void startUp() throws Exception { Discoverable discoverable = createDiscoverable(serviceName); cancelDiscoverable = discoveryService.register(ResolvingDiscoverable.of(discoverable)); - election.start(); - resourceClient.startAndWait(); + election.startAsync(); + resourceClient.startAsync().awaitRunning(); cancelResourceHandler = resourceClient.subscribe(serviceName, createResourceHandler(discoverable)); @@ -162,7 +162,8 @@ protected void shutDown() throws Exception { LOG.error("Exception while shutting down{}.", serviceName, th); } if (throwable != null) { - throw Throwables.propagate(throwable); + Throwables.throwIfUnchecked(throwable); + throw new RuntimeException(throwable); } LOG.info("Stopped ResourceBalancer {} service.", serviceName); } @@ -181,18 +182,18 @@ public void onChange(Collection partitionReplicas) { LOG.info("Partitions changed {}, service: {}", partitions, serviceName); try { if (service != null) { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } if (partitions.isEmpty() || !election.isRunning()) { service = null; } else { service = createService(partitions); - service.startAndWait(); + service.startAsync().awaitRunning(); } } catch (Throwable t) { LOG.error("Failed to change partitions, service: {}.", serviceName, t); completion.setException(t); - stop(); + stopAsync(); } } @@ -200,7 +201,7 @@ public void onChange(Collection partitionReplicas) { public void finished(Throwable failureCause) { try { if (service != null) { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); service = null; } completion.set(null); diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/security/YarnTokenUtils.java b/cdap-common/src/main/java/io/cdap/cdap/common/security/YarnTokenUtils.java index f0cb950723f6..c92fadf93e88 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/security/YarnTokenUtils.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/security/YarnTokenUtils.java @@ -97,7 +97,8 @@ public static Credentials obtainToken(YarnConfiguration configuration, Credentia return credentials; } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/service/AbstractRetryableScheduledService.java b/cdap-common/src/main/java/io/cdap/cdap/common/service/AbstractRetryableScheduledService.java index 47a52840859f..0c65b55a7608 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/service/AbstractRetryableScheduledService.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/service/AbstractRetryableScheduledService.java @@ -17,6 +17,7 @@ package io.cdap.cdap.common.service; import com.google.common.util.concurrent.AbstractScheduledService; +import com.google.common.util.concurrent.Service; import io.cdap.cdap.api.retry.RetriesExhaustedException; import io.cdap.cdap.common.logging.LogSamplers; import io.cdap.cdap.common.logging.Loggers; @@ -24,7 +25,6 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import org.apache.twill.common.Threads; -import org.apache.twill.internal.ServiceListenerAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,10 +56,22 @@ public abstract class AbstractRetryableScheduledService extends AbstractSchedule */ protected AbstractRetryableScheduledService(RetryStrategy retryStrategy) { this.retryStrategy = retryStrategy; - addListener(new ServiceListenerAdapter() { + addListener(new Service.Listener() { + @Override + public void starting() {} + + @Override + public void running() {} + + @Override + public void stopping(State from) {} + + @Override + public void terminated(State from) {} + @Override public void failed(State from, Throwable failure) { - LOG.error("Scheduled service {} terminated due to failure", getServiceName(), failure); + LOG.error("Scheduled service {} terminated due to failure", serviceName(), failure); } }, Threads.SAME_THREAD_EXECUTOR); } @@ -99,7 +111,7 @@ protected boolean shouldRetry(Exception ex) { * @throws Exception if startup of this service failed */ protected void doStartUp() throws Exception { - LOG.debug("Starting scheduled service {}", getServiceName()); + LOG.debug("Starting scheduled service {}", serviceName()); } /** @@ -109,20 +121,20 @@ protected void doStartUp() throws Exception { * @throws Exception if shutdown of this service failed */ protected void doShutdown() throws Exception { - LOG.debug("Stopping scheduled service {}", getServiceName()); + LOG.debug("Stopping scheduled service {}", serviceName()); } /** * Returns the name of this service. */ - protected String getServiceName() { + protected String serviceName() { return getClass().getSimpleName(); } @Override protected ScheduledExecutorService executor() { executor = Executors.newSingleThreadScheduledExecutor( - Threads.createDaemonThreadFactory(getServiceName())); + Threads.createDaemonThreadFactory(serviceName())); return executor; } @@ -191,7 +203,7 @@ protected final void runOneIteration() throws Exception { this.delayMillis = delayMillis; } } catch (Throwable t) { - LOG.error("Aborting service {} due to non-retryable error", getServiceName(), t); + LOG.error("Aborting service {} due to non-retryable error", serviceName(), t); throw t; } } @@ -210,6 +222,6 @@ protected Schedule getNextSchedule() { * Logs an exception raised by {@link #runTask()}. */ protected void logTaskFailure(Throwable t) { - outageLog.warn("Failed to execute task for scheduled service {}", getServiceName(), t); + outageLog.warn("Failed to execute task for scheduled service {}", serviceName(), t); } } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/service/CommandPortService.java b/cdap-common/src/main/java/io/cdap/cdap/common/service/CommandPortService.java index 654cf870dad2..d66cb3789ea2 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/service/CommandPortService.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/service/CommandPortService.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; -import java.io.Writer; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; @@ -44,7 +43,7 @@ * CommandPortService service = CommandPortService.builder("myservice") * .addCommandHandler("ruok", "Are you okay?", ruokHandler) * .build(); - * service.startAndWait(); + * service.startAsync().awaitRunning(); * * * To stop the service, invoke {@link #stop()} or {@link #stopAndWait()}. @@ -109,7 +108,8 @@ protected void triggerShutdown() { serverSocket.close(); } } catch (IOException e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/service/RetryOnStartFailureService.java b/cdap-common/src/main/java/io/cdap/cdap/common/service/RetryOnStartFailureService.java index 55f616d5020e..aeee80b7fbe4 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/service/RetryOnStartFailureService.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/service/RetryOnStartFailureService.java @@ -18,8 +18,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.AbstractService; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.Service; import com.google.common.util.concurrent.Uninterruptibles; import java.util.concurrent.TimeUnit; @@ -68,12 +67,10 @@ public void run() { while (!stopped) { try { - currentDelegate.start().get(); + currentDelegate.startAsync().awaitRunning(); // Only assigned the delegate if and only if the delegate service started successfully startedService = currentDelegate; break; - } catch (InterruptedException e) { - // This thread will be interrupted from the doStop() method. Don't reset the interrupt flag. } catch (Throwable t) { LOG.debug("Exception raised when starting service {}", delegateServiceName, t); @@ -112,25 +109,62 @@ protected void doStop() { // the setting of the startedService field. When that happens, the stop failure state is not propagated. // Nevertheless, there won't be any service left behind without stopping. if (startedService != null) { - Futures.addCallback(startedService.stop(), new FutureCallback() { + startedService.addListener(new Service.Listener() { @Override - public void onSuccess(State result) { + public void starting() {} + + @Override + public void running() {} + + @Override + public void stopping(State from) {} + + @Override + public void terminated(State from) { notifyStopped(); } @Override - public void onFailure(Throwable t) { - notifyFailed(t); + public void failed(State from, Throwable failure) { + notifyFailed(failure); } - }, Threads.SAME_THREAD_EXECUTOR); + }, MoreExecutors.directExecutor()); + startedService.stopAsync(); return; } - // If there is no started service, stop the current delete, but no need to propagate the stop state + // If there is no started service, stop the current delegate, but no need to propagate the stop state // because if the underlying service is not yet started due to failure, it shouldn't affect the stop state // of this retrying service. if (currentDelegate != null) { - currentDelegate.stop().addListener(this::notifyStopped, Threads.SAME_THREAD_EXECUTOR); + // If the delegate is already in a terminal state (FAILED or TERMINATED), stopAsync() won't + // trigger any listener callbacks, so we need to notify directly. + State delegateState = currentDelegate.state(); + if (delegateState == State.TERMINATED || delegateState == State.FAILED) { + notifyStopped(); + return; + } + currentDelegate.addListener(new Service.Listener() { + @Override + public void starting() {} + + @Override + public void running() {} + + @Override + public void stopping(State from) {} + + @Override + public void terminated(State from) { + notifyStopped(); + } + + @Override + public void failed(State from, Throwable failure) { + notifyStopped(); + } + }, Threads.SAME_THREAD_EXECUTOR); + currentDelegate.stopAsync(); return; } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/service/Services.java b/cdap-common/src/main/java/io/cdap/cdap/common/service/Services.java index 74d619454692..5d0dafed298c 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/service/Services.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/service/Services.java @@ -16,7 +16,6 @@ package io.cdap.cdap.common.service; -import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.Service; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -51,9 +50,8 @@ private Services() { public static void startAndWait(Service service, long timeout, TimeUnit timeoutUnit, @Nullable String timeoutErrorMessage) throws TimeoutException, InterruptedException, ExecutionException { - ListenableFuture startFuture = service.start(); try { - startFuture.get(timeout, timeoutUnit); + service.startAsync().awaitRunning(timeout, timeoutUnit); } catch (TimeoutException e) { LOG.error(timeoutErrorMessage != null ? timeoutErrorMessage : "Timeout while waiting to start service.", e); @@ -62,19 +60,19 @@ public static void startAndWait(Service service, long timeout, TimeUnit timeoutU timeoutException.setStackTrace(e.getStackTrace()); } try { - service.stop(); + service.stopAsync(); } catch (Exception stopException) { LOG.error("Error while trying to stop service: ", stopException); } throw timeoutException; - } catch (InterruptedException e) { - LOG.error("Interrupted while waiting to start service.", e); + } catch (IllegalStateException e) { + LOG.error("Failed to start service.", e); try { - service.stop(); + service.stopAsync(); } catch (Exception stopException) { LOG.error("Error while trying to stop service:", stopException); } - throw e; + throw new ExecutionException(e); } } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/twill/AbstractMasterTwillRunnable.java b/cdap-common/src/main/java/io/cdap/cdap/common/twill/AbstractMasterTwillRunnable.java index d9fd6c75729c..95465b514f95 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/twill/AbstractMasterTwillRunnable.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/twill/AbstractMasterTwillRunnable.java @@ -37,7 +37,6 @@ import org.apache.twill.api.TwillContext; import org.apache.twill.api.TwillRunnableSpecification; import org.apache.twill.common.Threads; -import org.apache.twill.internal.ServiceListenerAdapter; import org.apache.twill.internal.Services; import org.apache.twill.kafka.client.BrokerService; import org.apache.twill.kafka.client.KafkaClientService; @@ -110,7 +109,8 @@ public final void initialize(TwillContext context) { Preconditions.checkArgument(!services.isEmpty(), "Should have at least one service"); LOG.info("Runnable initialized {}", name); } catch (Throwable t) { - throw Throwables.propagate(t); + Throwables.throwIfUnchecked(t); + throw new RuntimeException(t); } } @@ -137,7 +137,8 @@ public void run() { } catch (InterruptedException e) { LOG.debug("Waiting on latch interrupted {}", name); } catch (ExecutionException e) { - throw Throwables.propagate(e.getCause()); + Throwables.throwIfUnchecked(e.getCause()); + throw new RuntimeException(e.getCause()); } } @@ -153,7 +154,22 @@ public void destroy() { private Service.Listener createServiceListener(final String name, final SettableFuture future) { - return new ServiceListenerAdapter() { + return new Service.Listener() { + @Override + public void starting() { + // no-op + } + + @Override + public void running() { + // no-op + } + + @Override + public void stopping(Service.State from) { + // no-op + } + @Override public void terminated(Service.State from) { LOG.info("Service " + name + " terminated"); diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/twill/NoopTwillController.java b/cdap-common/src/main/java/io/cdap/cdap/common/twill/NoopTwillController.java index 3074529dcf19..38432ef02361 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/twill/NoopTwillController.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/twill/NoopTwillController.java @@ -16,6 +16,7 @@ package io.cdap.cdap.common.twill; +import com.google.common.util.concurrent.Service; import java.util.Collections; import java.util.Iterator; import java.util.Map; @@ -23,6 +24,8 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import javax.annotation.Nullable; import org.apache.twill.api.Command; import org.apache.twill.api.ResourceReport; @@ -134,7 +137,7 @@ public Future> updateLogLevels( @Override public Future> updateLogLevels(String runnableName, - Map logLevelsForRunnable) { + Map logLevelsForRunnable) { CompletableFuture> future = new CompletableFuture<>(); future.completeExceptionally( new UnsupportedOperationException("Update log levels is not supported")); @@ -157,6 +160,38 @@ public Future resetRunnableLogLevels(String runnableName, String... lo return future; } + @Override + public void awaitRunning() { + // no-op + } + + @Override + public void awaitRunning(long timeout, TimeUnit unit) throws TimeoutException { + // no-op + } + + @Override + public void awaitTerminated() { + // no-op + } + + @Override + public void awaitTerminated(long timeout, TimeUnit unit) throws TimeoutException { + // no-op + } + + @Override + public Service startAsync() { + start(); + return this; + } + + @Override + public Service stopAsync() { + stop(); + return this; + } + @Override protected void startUp() { // no-op @@ -177,6 +212,12 @@ public Future sendCommand(String runnableName, Command command) { return CompletableFuture.completedFuture(command); } + @Nullable + @Override + public Throwable failureCause() { + return null; + } + @Override public void kill() { terminate(); diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/utils/BatchingConsumer.java b/cdap-common/src/main/java/io/cdap/cdap/common/utils/BatchingConsumer.java index cdda0dd18b21..18aae382f839 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/utils/BatchingConsumer.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/utils/BatchingConsumer.java @@ -79,7 +79,8 @@ public void close() { try { ((AutoCloseable) child).close(); } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/utils/ImmutablePair.java b/cdap-common/src/main/java/io/cdap/cdap/common/utils/ImmutablePair.java index 6e3e9d69f9a8..7a8dea597912 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/utils/ImmutablePair.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/utils/ImmutablePair.java @@ -16,6 +16,7 @@ package io.cdap.cdap.common.utils; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; /** @@ -83,7 +84,7 @@ public B getSecond() { */ @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("first", first) .add("second", second) .toString(); diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/utils/TimeBoundIterator.java b/cdap-common/src/main/java/io/cdap/cdap/common/utils/TimeBoundIterator.java index 4598513fe11b..4839e454faaa 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/utils/TimeBoundIterator.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/utils/TimeBoundIterator.java @@ -17,10 +17,10 @@ package io.cdap.cdap.common.utils; -import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Stopwatch; import com.google.common.collect.AbstractIterator; import java.util.Iterator; +import java.util.concurrent.TimeUnit; /** * An iterator that will act as if there are no more elements if a certain amount of time has @@ -35,7 +35,7 @@ public class TimeBoundIterator extends AbstractIterator { private final Stopwatch stopwatch; public TimeBoundIterator(Iterator delegate, long timeBoundMillis) { - this(delegate, timeBoundMillis, new Stopwatch()); + this(delegate, timeBoundMillis, Stopwatch.createUnstarted()); } public TimeBoundIterator(Iterator delegate, long timeBoundMillis, Stopwatch stopwatch) { @@ -49,7 +49,7 @@ public TimeBoundIterator(Iterator delegate, long timeBoundMillis, Stopwatch s @Override protected T computeNext() { - if (stopwatch.elapsedMillis() < timeBoundMillis && delegate.hasNext()) { + if (stopwatch.elapsed(TimeUnit.MILLISECONDS) < timeBoundMillis && delegate.hasNext()) { return delegate.next(); } return endOfData(); diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/ZKExtOperations.java b/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/ZKExtOperations.java index b01bb6da0cc1..941355af6a48 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/ZKExtOperations.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/ZKExtOperations.java @@ -369,8 +369,7 @@ public void onFailure(Throwable t) { resultFuture.setException(t); } } - }, Threads.SAME_THREAD_EXECUTOR - ); + }, Threads.SAME_THREAD_EXECUTOR); return resultFuture; } diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/PartitionReplica.java b/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/PartitionReplica.java index f9aae9efccdb..37032f9058f1 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/PartitionReplica.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/PartitionReplica.java @@ -15,6 +15,7 @@ */ package io.cdap.cdap.common.zookeeper.coordination; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.primitives.Ints; import java.util.Comparator; @@ -82,7 +83,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("partition", name) .add("replica", replicaId) .toString(); diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/ResourceCoordinator.java b/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/ResourceCoordinator.java index 9bcea77d9a40..4e96a1eaf10d 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/ResourceCoordinator.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/ResourceCoordinator.java @@ -412,8 +412,7 @@ public void onFailure(Throwable t) { LOG.error("Failed to save assignment {}", Bytes.toStringBinary(data), t); doNotifyFailed(t); } - }, executor - ); + }, executor); } catch (Exception e) { // Something very wrong LOG.error("Failed to save assignment: {}", assignmentName, e); diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/ResourceCoordinatorClient.java b/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/ResourceCoordinatorClient.java index 01aeb7996ad7..ca39477538f4 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/ResourceCoordinatorClient.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/ResourceCoordinatorClient.java @@ -27,6 +27,7 @@ import com.google.common.util.concurrent.AbstractService; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.ListenableFuture; import io.cdap.cdap.api.common.Bytes; import io.cdap.cdap.common.zookeeper.ZKExtOperations; @@ -66,7 +67,8 @@ public ResourceRequirement apply(@Nullable NodeData input) { } catch (Throwable t) { LOG.error("Failed to decode resource requirement: {}", Bytes.toStringBinary(input.getData()), t); - throw Throwables.propagate(t); + Throwables.throwIfUnchecked(t); + throw new RuntimeException(t); } } }; @@ -132,8 +134,8 @@ public ListenableFuture fetchRequirement(String resourceNam return Futures.transform( ZKOperations.ignoreError(zkClient.getData(zkPath), KeeperException.NoNodeException.class, null), - NODE_DATA_TO_REQUIREMENT - ); + NODE_DATA_TO_REQUIREMENT, + MoreExecutors.directExecutor()); } /** @@ -150,8 +152,8 @@ public ListenableFuture deleteRequirement(String resourceName) { return Futures.transform( ZKOperations.ignoreError(zkClient.delete(zkPath), KeeperException.NoNodeException.class, resourceName), - Functions.constant(resourceName) - ); + Functions.constant(resourceName), + MoreExecutors.directExecutor()); } /** diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/ResourceRequirement.java b/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/ResourceRequirement.java index 15ad26371137..f01815938ce9 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/ResourceRequirement.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/coordination/ResourceRequirement.java @@ -15,6 +15,7 @@ */ package io.cdap.cdap.common.zookeeper.coordination; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSortedSet; @@ -60,7 +61,7 @@ public Set getPartitions() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("name", name) .add("partitions", partitions) .toString(); @@ -139,7 +140,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("name", name) .add("replicas", replicas) .toString(); diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/election/LeaderElectionInfoService.java b/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/election/LeaderElectionInfoService.java index 15fa2d73582f..d64291c1687c 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/election/LeaderElectionInfoService.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/zookeeper/election/LeaderElectionInfoService.java @@ -22,6 +22,7 @@ import com.google.common.util.concurrent.AbstractIdleService; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.SettableFuture; import java.nio.charset.StandardCharsets; import java.util.Collections; @@ -81,9 +82,9 @@ public LeaderElectionInfoService(ZKClient zkClient, String leaderElectionPath) { public SortedMap getParticipants(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException { try { - Stopwatch stopwatch = new Stopwatch().start(); + Stopwatch stopwatch = Stopwatch.createStarted(); CountDownLatch readyLatch = readyFuture.get(timeout, unit); - long latchTimeout = Math.max(0, stopwatch.elapsedTime(unit) - timeout); + long latchTimeout = Math.max(0, stopwatch.elapsed(unit) - timeout); readyLatch.await(latchTimeout, unit); } catch (ExecutionException e) { // The ready future never throw on get. If this happen, just return an empty map @@ -237,7 +238,8 @@ public void onFailure(Throwable t) { readyLatch.countDown(); } } - }); + }, + MoreExecutors.directExecutor()); } /** diff --git a/cdap-common/src/main/java/io/cdap/cdap/data2/util/TableId.java b/cdap-common/src/main/java/io/cdap/cdap/data2/util/TableId.java index 35c5e51fc9ee..b6391bc80d16 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/data2/util/TableId.java +++ b/cdap-common/src/main/java/io/cdap/cdap/data2/util/TableId.java @@ -16,6 +16,7 @@ package io.cdap.cdap.data2.util; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -70,7 +71,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("namespace", namespace) .add("tableName", tableName) .toString(); diff --git a/cdap-common/src/main/java/io/cdap/cdap/extension/AbstractExtensionLoader.java b/cdap-common/src/main/java/io/cdap/cdap/extension/AbstractExtensionLoader.java index e37d4229b634..16b7867d634c 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/extension/AbstractExtensionLoader.java +++ b/cdap-common/src/main/java/io/cdap/cdap/extension/AbstractExtensionLoader.java @@ -322,7 +322,8 @@ private ServiceLoader createServiceLoader(File dir) { return input.toURI().toURL(); } catch (MalformedURLException e) { // Shouldn't happen - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } }).toArray(URL[]::new); diff --git a/cdap-common/src/main/java/io/cdap/cdap/internal/app/store/RunRecordDetail.java b/cdap-common/src/main/java/io/cdap/cdap/internal/app/store/RunRecordDetail.java index a2b5d7e945a9..0757b69e28ae 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/internal/app/store/RunRecordDetail.java +++ b/cdap-common/src/main/java/io/cdap/cdap/internal/app/store/RunRecordDetail.java @@ -15,6 +15,7 @@ */ package io.cdap.cdap.internal.app.store; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.gson.Gson; import com.google.gson.annotations.SerializedName; @@ -26,7 +27,6 @@ import io.cdap.cdap.proto.RunRecord; import io.cdap.cdap.proto.id.ProfileId; import io.cdap.cdap.proto.id.ProgramRunId; -import io.cdap.cdap.runtime.spi.provisioner.Cluster; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -186,7 +186,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("programRunId", getProgramRunId()) .add("startTs", getStartTs()) .add("runTs", getRunTs()) diff --git a/cdap-common/src/main/java/io/cdap/cdap/internal/io/ASMDatumWriterFactory.java b/cdap-common/src/main/java/io/cdap/cdap/internal/io/ASMDatumWriterFactory.java index b715d217e44d..003c01035547 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/internal/io/ASMDatumWriterFactory.java +++ b/cdap-common/src/main/java/io/cdap/cdap/internal/io/ASMDatumWriterFactory.java @@ -63,7 +63,8 @@ public DatumWriter create(TypeToken type, Schema schema) { return (DatumWriter) writerClass.getConstructor(Schema.class, FieldAccessorFactory.class) .newInstance(schema, fieldAccessorFactory); } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } diff --git a/cdap-common/src/main/java/io/cdap/cdap/internal/io/DatumWriterGenerator.java b/cdap-common/src/main/java/io/cdap/cdap/internal/io/DatumWriterGenerator.java index d1a43f3c1279..c8d721a12104 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/internal/io/DatumWriterGenerator.java +++ b/cdap-common/src/main/java/io/cdap/cdap/internal/io/DatumWriterGenerator.java @@ -798,7 +798,8 @@ private void encodeRecord(GeneratorAdapter mg, Schema schema, TypeToken outpu mg.invokeVirtual(classType, getEncodeMethod(fieldType, field.getSchema())); } } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } diff --git a/cdap-common/src/main/java/io/cdap/cdap/internal/io/FieldAccessorGenerator.java b/cdap-common/src/main/java/io/cdap/cdap/internal/io/FieldAccessorGenerator.java index 49656c470ee7..5b3b47cd0c65 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/internal/io/FieldAccessorGenerator.java +++ b/cdap-common/src/main/java/io/cdap/cdap/internal/io/FieldAccessorGenerator.java @@ -117,7 +117,7 @@ private void initializeReflectionField(GeneratorAdapter mg, Field field) { this.field = field; } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } */ Label beginTry = mg.newLabel(); @@ -202,7 +202,7 @@ private void invokeReflection(Method method, String signature) { * try { * // Call method * } catch (IllegalAccessException e) { - * throw Throwables.propagate(e); + * throw new RuntimeException(e); * } */ Label beginTry = mg.newLabel(); diff --git a/cdap-common/src/main/java/io/cdap/cdap/internal/io/ReflectionFieldAccessorFactory.java b/cdap-common/src/main/java/io/cdap/cdap/internal/io/ReflectionFieldAccessorFactory.java index 98ae5bef4638..b97967cc05ae 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/internal/io/ReflectionFieldAccessorFactory.java +++ b/cdap-common/src/main/java/io/cdap/cdap/internal/io/ReflectionFieldAccessorFactory.java @@ -62,7 +62,8 @@ public void set(Object object, T value) { try { finalField.set(object, value); } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } @@ -72,7 +73,8 @@ public T get(Object object) { try { return (T) finalField.get(object); } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } diff --git a/cdap-common/src/test/java/io/cdap/cdap/common/conf/CConfigurationTest.java b/cdap-common/src/test/java/io/cdap/cdap/common/conf/CConfigurationTest.java index c45f9fe87886..a64806ad4f80 100644 --- a/cdap-common/src/test/java/io/cdap/cdap/common/conf/CConfigurationTest.java +++ b/cdap-common/src/test/java/io/cdap/cdap/common/conf/CConfigurationTest.java @@ -16,7 +16,6 @@ package io.cdap.cdap.common.conf; -import com.google.common.io.Closeables; import io.cdap.cdap.api.common.Bytes; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -192,7 +191,11 @@ public void testDeprecatedConfigProperties() throws Exception { } // Close the InputStream - Closeables.closeQuietly(resource); + try { + resource.close(); + } catch (Exception ignored) { + // Ignored during cleanup + } } } diff --git a/cdap-common/src/test/java/io/cdap/cdap/common/conf/ZKPropertyStoreTest.java b/cdap-common/src/test/java/io/cdap/cdap/common/conf/ZKPropertyStoreTest.java index 63396168949b..e06e60466b4d 100644 --- a/cdap-common/src/test/java/io/cdap/cdap/common/conf/ZKPropertyStoreTest.java +++ b/cdap-common/src/test/java/io/cdap/cdap/common/conf/ZKPropertyStoreTest.java @@ -39,16 +39,16 @@ public class ZKPropertyStoreTest extends PropertyStoreTestBase { @BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(tmpFolder.newFolder()).build(); - zkServer.startAndWait(); + zkServer.startAsync().awaitRunning(); zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); } @AfterClass public static void finish() { - zkClient.stopAndWait(); - zkServer.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); + zkServer.stopAsync().awaitTerminated(); } @Override diff --git a/cdap-common/src/test/java/io/cdap/cdap/common/guice/KafkaClientModuleTest.java b/cdap-common/src/test/java/io/cdap/cdap/common/guice/KafkaClientModuleTest.java index b41436c0b7bb..2288796dd1e2 100644 --- a/cdap-common/src/test/java/io/cdap/cdap/common/guice/KafkaClientModuleTest.java +++ b/cdap-common/src/test/java/io/cdap/cdap/common/guice/KafkaClientModuleTest.java @@ -62,7 +62,7 @@ public class KafkaClientModuleTest { @Before public void beforeTest() throws Exception { zkServer = InMemoryZKServer.builder().setDataDir(TEMP_FOLDER.newFolder()).build(); - zkServer.startAndWait(); + zkServer.startAsync().awaitRunning(); CConfiguration cConf = CConfiguration.create(); String kafkaZkNamespace = cConf.get(KafkaConstants.ConfigKeys.ZOOKEEPER_NAMESPACE_CONFIG); @@ -71,21 +71,21 @@ public void beforeTest() throws Exception { if (kafkaZkNamespace != null) { ZKClientService zkClient = new DefaultZKClientService(zkServer.getConnectionStr(), 2000, null, ImmutableMultimap.of()); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); zkClient.create("/" + kafkaZkNamespace, null, CreateMode.PERSISTENT); - zkClient.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); kafkaZkConnect += "/" + kafkaZkNamespace; } kafkaServer = createKafkaServer(kafkaZkConnect, TEMP_FOLDER.newFolder()); - kafkaServer.startAndWait(); + kafkaServer.startAsync().awaitRunning(); } @After public void afterTest() { - kafkaServer.stopAndWait(); - zkServer.stopAndWait(); + kafkaServer.stopAsync().awaitTerminated(); + zkServer.stopAsync().awaitTerminated(); } @Test @@ -101,7 +101,7 @@ public void testWithSharedZkClient() throws Exception { // Get the shared zkclient and start it ZKClientService zkClientService = injector.getInstance(ZKClientService.class); - zkClientService.startAndWait(); + zkClientService.startAsync().awaitRunning(); final int baseZkConns = getZkConnections(); @@ -109,8 +109,8 @@ public void testWithSharedZkClient() throws Exception { final BrokerService brokerService = injector.getInstance(BrokerService.class); // Start both kafka and broker services, it shouldn't affect the state of the shared zk client - kafkaClientService.startAndWait(); - brokerService.startAndWait(); + kafkaClientService.startAsync().awaitRunning(); + brokerService.startAsync().awaitRunning(); // Shouldn't affect the shared zk client state Assert.assertTrue(zkClientService.isRunning()); @@ -127,8 +127,8 @@ public Boolean call() throws Exception { }, 5L, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); // Stop both, still shouldn't affect the state of the shared zk client - kafkaClientService.stopAndWait(); - brokerService.stopAndWait(); + kafkaClientService.stopAsync().awaitTerminated(); + brokerService.stopAsync().awaitTerminated(); // Still shouldn't affect the shared zk client Assert.assertTrue(zkClientService.isRunning()); @@ -136,7 +136,7 @@ public Boolean call() throws Exception { // It still shouldn't increase the number of zk client connections Assert.assertEquals(baseZkConns, getZkConnections()); - zkClientService.stopAndWait(); + zkClientService.stopAsync().awaitTerminated(); } @Test @@ -154,7 +154,7 @@ public void testWithDedicatedZkClient() throws Exception { // Get the shared zkclient and start it ZKClientService zkClientService = injector.getInstance(ZKClientService.class); - zkClientService.startAndWait(); + zkClientService.startAsync().awaitRunning(); int baseZkConns = getZkConnections(); @@ -162,12 +162,12 @@ public void testWithDedicatedZkClient() throws Exception { final BrokerService brokerService = injector.getInstance(BrokerService.class); // Start the kafka client, it should increase the zk connections by 1 - kafkaClientService.startAndWait(); + kafkaClientService.startAsync().awaitRunning(); Assert.assertEquals(baseZkConns + 1, getZkConnections()); // Start the broker service, // it shouldn't affect the zk connections, as it share the same zk client with kafka client - brokerService.startAndWait(); + brokerService.startAsync().awaitRunning(); Assert.assertEquals(baseZkConns + 1, getZkConnections()); // Make sure it is talking to Kafka. @@ -182,17 +182,17 @@ public Boolean call() throws Exception { Assert.assertTrue(zkClientService.isRunning()); // Stop the broker service, it shouldn't affect the zk connections, as it is still used by the kafka client - brokerService.stopAndWait(); + brokerService.stopAsync().awaitTerminated(); Assert.assertEquals(baseZkConns + 1, getZkConnections()); // Stop the kafka client, the zk connections should be reduced by 1 - kafkaClientService.stopAndWait(); + kafkaClientService.stopAsync().awaitTerminated(); Assert.assertEquals(baseZkConns, getZkConnections()); // Still shouldn't affect the shared zk client Assert.assertTrue(zkClientService.isRunning()); - zkClientService.stopAndWait(); + zkClientService.stopAsync().awaitTerminated(); } /** diff --git a/cdap-common/src/test/java/io/cdap/cdap/common/guice/ZkDiscoveryModuleTest.java b/cdap-common/src/test/java/io/cdap/cdap/common/guice/ZkDiscoveryModuleTest.java index c809a29c2824..278b6f2ca178 100644 --- a/cdap-common/src/test/java/io/cdap/cdap/common/guice/ZkDiscoveryModuleTest.java +++ b/cdap-common/src/test/java/io/cdap/cdap/common/guice/ZkDiscoveryModuleTest.java @@ -59,7 +59,7 @@ public class ZkDiscoveryModuleTest { @BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(TEMP_FOLDER.newFolder()).build(); - zkServer.startAndWait(); + zkServer.startAsync().awaitRunning(); cConf = CConfiguration.create(); cConf.set(Constants.Zookeeper.QUORUM, zkServer.getConnectionStr()); @@ -68,7 +68,7 @@ public static void init() throws IOException { @AfterClass public static void finish() { - zkServer.stopAndWait(); + zkServer.stopAsync().awaitTerminated(); } @Test @@ -80,7 +80,7 @@ public void testMasterDiscovery() { ); ZKClientService zkClient = injector.getInstance(ZKClientService.class); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); try { DiscoveryService discoveryService = injector.getInstance(DiscoveryService.class); DiscoveryServiceClient discoveryServiceClient = injector @@ -106,7 +106,7 @@ public void testMasterDiscovery() { } } finally { - zkClient.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); } } @@ -119,7 +119,7 @@ public void testProgramDiscovery() { ); ZKClientService zkClient = injector.getInstance(ZKClientService.class); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); try { // Register a service using the twill ZKClient. This is to simulate how a user Service program register ProgramId programId = NamespaceId.DEFAULT.app("app").service("service"); @@ -149,7 +149,7 @@ public void testProgramDiscovery() { } } } finally { - zkClient.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); } } } diff --git a/cdap-common/src/test/java/io/cdap/cdap/common/internal/remote/RemoteTaskExecutorTest.java b/cdap-common/src/test/java/io/cdap/cdap/common/internal/remote/RemoteTaskExecutorTest.java index 5781de705674..3993eca11ce6 100644 --- a/cdap-common/src/test/java/io/cdap/cdap/common/internal/remote/RemoteTaskExecutorTest.java +++ b/cdap-common/src/test/java/io/cdap/cdap/common/internal/remote/RemoteTaskExecutorTest.java @@ -16,7 +16,8 @@ package io.cdap.cdap.common.internal.remote; -import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.AbstractService; +import com.google.common.util.concurrent.Service; import io.cdap.cdap.api.metrics.MetricsCollectionService; import io.cdap.cdap.api.metrics.MetricsContext; import io.cdap.cdap.api.service.worker.RemoteExecutionException; @@ -39,6 +40,8 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.Executor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.apache.twill.common.Cancellable; import org.apache.twill.discovery.InMemoryDiscoveryService; import org.junit.After; @@ -90,7 +93,7 @@ public void modify(ChannelPipeline pipeline) { public void beforeTest() { metricCollectors = new HashMap<>(); mockMetricsCollector = createMockMetricsCollectionService(); - mockMetricsCollector.startAndWait(); + mockMetricsCollector.startAsync().awaitRunning(); registered = discoveryService.register(URIScheme.createDiscoverable(Constants.Service.TASK_WORKER, httpService)); } @@ -110,39 +113,69 @@ public byte[] decrypt(byte[] cipherData, byte[] associatedData) throws CipherExc private MetricsCollectionService createMockMetricsCollectionService() { return new MetricsCollectionService() { + private final AbstractService delegate = new AbstractService() { + @Override + protected void doStart() { + notifyStarted(); + } - @Override - public ListenableFuture start() { - return null; - } + @Override + protected void doStop() { + notifyStopped(); + } + }; @Override - public State startAndWait() { - return null; + public Service startAsync() { + delegate.startAsync(); + return this; } @Override public boolean isRunning() { - return false; + return delegate.isRunning(); } @Override public State state() { - return null; + return delegate.state(); } @Override - public ListenableFuture stop() { - return null; + public Service stopAsync() { + delegate.stopAsync(); + return this; } @Override - public State stopAndWait() { - return null; + public void awaitRunning() { + delegate.awaitRunning(); } @Override - public void addListener(final Listener listener, final Executor executor) {} + public void awaitRunning(long timeout, TimeUnit unit) throws TimeoutException { + delegate.awaitRunning(timeout, unit); + } + + @Override + public void awaitTerminated() { + delegate.awaitTerminated(); + } + + @Override + public void awaitTerminated(long timeout, TimeUnit unit) throws TimeoutException { + delegate.awaitTerminated(timeout, unit); + } + + @Override + public Throwable failureCause() { + return delegate.failureCause(); + } + + @Override + public void addListener(final Listener listener, final Executor executor) { + delegate.addListener(listener, executor); + } @Override public MetricsContext getContext(Map context) { @@ -205,7 +238,7 @@ public void testFailedMetrics() throws Exception { // Exception thrown in the task executor should be in the exception message in the caller Assert.assertEquals("Invalid", e.getMessage()); } - mockMetricsCollector.stopAndWait(); + mockMetricsCollector.stopAsync().awaitTerminated(); Assert.assertSame(1, metricCollectors.size()); //check the metrics are present @@ -224,7 +257,7 @@ public void testSuccessMetrics() throws Exception { RunnableTaskRequest runnableTaskRequest = RunnableTaskRequest.getBuilder(ValidRunnableClass.class.getName()). withParam("param").withNamespace("testNamespace").build(); remoteTaskExecutor.runTask(runnableTaskRequest); - mockMetricsCollector.stopAndWait(); + mockMetricsCollector.stopAsync().awaitTerminated(); Assert.assertSame(1, metricCollectors.size()); //check the metrics are present @@ -249,7 +282,7 @@ public void testRetryMetrics() throws Exception { } catch (Exception e) { // expected } - mockMetricsCollector.stopAndWait(); + mockMetricsCollector.stopAsync().awaitTerminated(); Assert.assertSame(1, metricCollectors.size()); //check the metrics are present diff --git a/cdap-common/src/test/java/io/cdap/cdap/common/resource/ResourceBalancerServiceTest.java b/cdap-common/src/test/java/io/cdap/cdap/common/resource/ResourceBalancerServiceTest.java index 8a5d4b815491..46c13726714f 100644 --- a/cdap-common/src/test/java/io/cdap/cdap/common/resource/ResourceBalancerServiceTest.java +++ b/cdap-common/src/test/java/io/cdap/cdap/common/resource/ResourceBalancerServiceTest.java @@ -59,12 +59,12 @@ public ResourceBalancerServiceTest() { @BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(TEMP_FOLDER.newFolder()).build(); - zkServer.startAndWait(); + zkServer.startAsync().awaitRunning(); } @AfterClass public static void finish() { - zkServer.stopAndWait(); + zkServer.stopAsync().awaitTerminated(); } @Test @@ -72,13 +72,13 @@ public void testResourceBalancerService() throws Exception { // Simple test for resource balancer does react to discovery changes correct // More detailed tests are in ResourceCoordinatorTest, which the ResourceBalancerService depends on ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); try (ZKDiscoveryService discoveryService = new ZKDiscoveryService(zkClient)) { // Test the failure on stop case final TestBalancerService stopFailureService = new TestBalancerService("test", 4, zkClient, discoveryService, discoveryService, false, false); - stopFailureService.startAndWait(); + stopFailureService.startAsync().awaitRunning(); // Should get all four partitions Tasks.waitFor(ImmutableSet.of(0, 1, 2, 3), new Callable>() { @@ -103,20 +103,20 @@ public Integer call() throws Exception { cancellable.cancel(); } } finally { - zkClient.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); } } @Test public void testServiceStartFailure() throws Exception { ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); try (ZKDiscoveryService discoveryService = new ZKDiscoveryService(zkClient)) { // Test the failure on start case final TestBalancerService startFailureService = new TestBalancerService("test", 4, zkClient, discoveryService, discoveryService, true, false); - startFailureService.startAndWait(); + startFailureService.startAsync().awaitRunning(); // The resource balance service should fail Tasks.waitFor(Service.State.FAILED, new Callable() { @@ -126,20 +126,20 @@ public Service.State call() throws Exception { } }, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); } finally { - zkClient.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); } } @Test public void testServiceStopFailure() throws Exception { ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); try (ZKDiscoveryService discoveryService = new ZKDiscoveryService(zkClient)) { // Test the failure on stop case final TestBalancerService stopFailureService = new TestBalancerService("test", 4, zkClient, discoveryService, discoveryService, false, true); - stopFailureService.startAndWait(); + stopFailureService.startAsync().awaitRunning(); // Should get four partitions Tasks.waitFor(ImmutableSet.of(0, 1, 2, 3), new Callable>() { @@ -165,7 +165,7 @@ public Service.State call() throws Exception { cancellable.cancel(); } } finally { - zkClient.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); } } diff --git a/cdap-common/src/test/java/io/cdap/cdap/common/service/CommandPortServiceTest.java b/cdap-common/src/test/java/io/cdap/cdap/common/service/CommandPortServiceTest.java index 6aee3250ddb2..ddbbf6bcea4b 100644 --- a/cdap-common/src/test/java/io/cdap/cdap/common/service/CommandPortServiceTest.java +++ b/cdap-common/src/test/java/io/cdap/cdap/common/service/CommandPortServiceTest.java @@ -16,8 +16,6 @@ package io.cdap.cdap.common.service; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Service; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -62,19 +60,18 @@ public void testCommandPortServer() throws Exception { .build(); final CountDownLatch stopLatch = new CountDownLatch(1); - Futures.addCallback(server.start(), new FutureCallback() { + server.addListener(new Service.Listener() { @Override - public void onSuccess(Service.State result) { + public void terminated(Service.State from) { stopLatch.countDown(); } @Override - public void onFailure(Throwable t) { + public void failed(Service.State from, Throwable failure) { stopLatch.countDown(); } - }); - // wait a bit for service to start - TimeUnit.SECONDS.sleep(1); + }, Runnable::run); + server.startAsync().awaitRunning(); try { for (int i = 0; i < 10; i++) { @@ -95,7 +92,7 @@ public void onFailure(Throwable t) { } } finally { - server.stopAndWait(); + server.stopAsync().awaitTerminated(); } Assert.assertEquals(10, handler.getCounter()); diff --git a/cdap-common/src/test/java/io/cdap/cdap/common/service/RetryOnStartFailureServiceTest.java b/cdap-common/src/test/java/io/cdap/cdap/common/service/RetryOnStartFailureServiceTest.java index b2233dc07704..360027d0aa41 100644 --- a/cdap-common/src/test/java/io/cdap/cdap/common/service/RetryOnStartFailureServiceTest.java +++ b/cdap-common/src/test/java/io/cdap/cdap/common/service/RetryOnStartFailureServiceTest.java @@ -27,7 +27,6 @@ import java.util.concurrent.TimeoutException; import java.util.function.Supplier; import org.apache.twill.common.Threads; -import org.apache.twill.internal.ServiceListenerAdapter; import org.junit.Assert; import org.junit.Test; @@ -42,7 +41,7 @@ public void testRetrySucceed() throws InterruptedException { Service service = new RetryOnStartFailureService( createServiceSupplier(3, startLatch, new CountDownLatch(1), false), RetryStrategies.fixDelay(10, TimeUnit.MILLISECONDS)); - service.startAndWait(); + service.startAsync().awaitRunning(); Assert.assertTrue(startLatch.await(1, TimeUnit.SECONDS)); } @@ -54,14 +53,14 @@ public void testRetryFail() throws InterruptedException { RetryStrategies.limit(10, RetryStrategies.fixDelay(10, TimeUnit.MILLISECONDS))); final CountDownLatch failureLatch = new CountDownLatch(1); - service.addListener(new ServiceListenerAdapter() { + service.addListener(new Service.Listener() { @Override public void failed(Service.State from, Throwable failure) { failureLatch.countDown(); } }, Threads.SAME_THREAD_EXECUTOR); - service.start(); + service.startAsync(); Assert.assertTrue(failureLatch.await(1, TimeUnit.SECONDS)); Assert.assertFalse(startLatch.await(100, TimeUnit.MILLISECONDS)); } @@ -73,9 +72,9 @@ public void testStopWhileRetrying() throws InterruptedException { Service service = new RetryOnStartFailureService( createServiceSupplier(1000, new CountDownLatch(1), failureLatch, false), RetryStrategies.fixDelay(10, TimeUnit.MILLISECONDS)); - service.startAndWait(); + service.startAsync().awaitRunning(); Assert.assertTrue(failureLatch.await(1, TimeUnit.SECONDS)); - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } @Test @@ -85,7 +84,7 @@ public void testStopFailurePropagate() throws InterruptedException, TimeoutExcep final RetryOnStartFailureService service = new RetryOnStartFailureService( createServiceSupplier(0, startLatch, new CountDownLatch(1), true), RetryStrategies.fixDelay(10, TimeUnit.MILLISECONDS)); - service.startAndWait(); + service.startAsync().awaitRunning(); // block until the underlying service started successfully Assert.assertTrue(startLatch.await(1, TimeUnit.SECONDS)); // As documented in the RetryOnStartFailureService, there is a small race after the @@ -99,7 +98,7 @@ public Boolean call() throws Exception { } }, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); try { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); Assert.fail("Expected failure in stopping"); } catch (Exception e) { Assert.assertEquals("Intentional failure to shutdown", Throwables.getRootCause(e).getMessage()); diff --git a/cdap-common/src/test/java/io/cdap/cdap/common/service/RetryableScheduledServiceTest.java b/cdap-common/src/test/java/io/cdap/cdap/common/service/RetryableScheduledServiceTest.java index 2ce4ce226215..6fe1bb793b01 100644 --- a/cdap-common/src/test/java/io/cdap/cdap/common/service/RetryableScheduledServiceTest.java +++ b/cdap-common/src/test/java/io/cdap/cdap/common/service/RetryableScheduledServiceTest.java @@ -45,9 +45,9 @@ protected long runTask() { } }; - service.start(); + service.startAsync(); Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } @Test @@ -59,12 +59,12 @@ protected long runTask() throws Exception { } }; - service.start(); + service.startAsync(); // Wait for the service to fail Tasks.waitFor(Service.State.FAILED, service::state, 5, TimeUnit.SECONDS, 10, TimeUnit.MILLISECONDS); try { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } catch (Exception e) { // The root cause should be the one throw from the runTask. It should suppressed the retry exhausted exception. Throwable rootCause = Throwables.getRootCause(e); @@ -89,12 +89,12 @@ protected boolean shouldRetry(Exception ex) { } }; - service.start(); + service.startAsync(); // Wait for the service to fail Tasks.waitFor(Service.State.FAILED, service::state, 5, TimeUnit.SECONDS, 10, TimeUnit.MILLISECONDS); try { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } catch (Exception e) { // The root cause should be the one throw from the runTask. Throwable rootCause = Throwables.getRootCause(e); @@ -118,8 +118,8 @@ protected long runTask() throws Exception { return 1L; } }; - service.start(); + service.startAsync(); Assert.assertTrue(latch.await(3, TimeUnit.SECONDS)); - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } } diff --git a/cdap-common/src/test/java/io/cdap/cdap/common/ssh/SSHSessionTest.java b/cdap-common/src/test/java/io/cdap/cdap/common/ssh/SSHSessionTest.java index 8fcf8a0014b8..137d24cf3843 100644 --- a/cdap-common/src/test/java/io/cdap/cdap/common/ssh/SSHSessionTest.java +++ b/cdap-common/src/test/java/io/cdap/cdap/common/ssh/SSHSessionTest.java @@ -18,7 +18,6 @@ import com.google.common.base.Splitter; -import com.google.common.io.Closeables; import com.google.common.util.concurrent.AbstractExecutionThreadService; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; @@ -131,7 +130,7 @@ public void testLocalPortForwarding() throws Exception { // Starts an echo server for testing the port forwarding EchoServer echoServer = new EchoServer(); - echoServer.startAndWait(); + echoServer.startAsync().awaitRunning(); try { // Creates the DataConsumer for receiving data and validating the lifecycle StringBuilder received = new StringBuilder(); @@ -185,7 +184,7 @@ public void finished() { } } finally { - echoServer.stopAndWait(); + echoServer.stopAsync().awaitTerminated(); } } @@ -193,7 +192,7 @@ public void finished() { public void testForwardingOnSessionClose() throws Exception { EchoServer echoServer = new EchoServer(); - echoServer.startAndWait(); + echoServer.startAsync().awaitRunning(); try { SSHConfig sshConfig = getSSHConfig(); AtomicBoolean finished = new AtomicBoolean(false); @@ -236,7 +235,7 @@ public void finished() { } } finally { - echoServer.stopAndWait(); + echoServer.stopAsync().awaitTerminated(); } } @@ -244,7 +243,7 @@ public void finished() { public void testRemotePortForwarding() throws Exception { EchoServer echoServer = new EchoServer(); - echoServer.startAndWait(); + echoServer.startAsync().awaitRunning(); try { SSHConfig sshConfig = getSSHConfig(); @@ -264,7 +263,7 @@ public void testRemotePortForwarding() throws Exception { } } } finally { - echoServer.stopAndWait(); + echoServer.stopAsync().awaitTerminated(); } } @@ -320,7 +319,11 @@ protected void run() throws IOException { } catch (IOException e) { LOG.error("Exception raised from the EchoServer handling thread", e); } finally { - Closeables.closeQuietly(socket); + try { + socket.close(); + } catch (Exception ignored) { + // Ignored during cleanup + } } }); @@ -337,7 +340,11 @@ protected void run() throws IOException { @Override protected void triggerShutdown() { stopped = true; - Closeables.closeQuietly(serverSocket); + try { + serverSocket.close(); + } catch (Exception ignored) { + // Ignored during cleanup + } } } } diff --git a/cdap-common/src/test/java/io/cdap/cdap/common/test/MockTwillContext.java b/cdap-common/src/test/java/io/cdap/cdap/common/test/MockTwillContext.java index 061ca4f0e2bd..b6fe043d3735 100644 --- a/cdap-common/src/test/java/io/cdap/cdap/common/test/MockTwillContext.java +++ b/cdap-common/src/test/java/io/cdap/cdap/common/test/MockTwillContext.java @@ -56,7 +56,8 @@ public InetAddress getHost() { try { return InetAddress.getLocalHost(); } catch (UnknownHostException e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } } diff --git a/cdap-common/src/test/java/io/cdap/cdap/common/utils/TimeBoundIteratorTest.java b/cdap-common/src/test/java/io/cdap/cdap/common/utils/TimeBoundIteratorTest.java index 34758d971a5a..84635401c982 100644 --- a/cdap-common/src/test/java/io/cdap/cdap/common/utils/TimeBoundIteratorTest.java +++ b/cdap-common/src/test/java/io/cdap/cdap/common/utils/TimeBoundIteratorTest.java @@ -34,7 +34,7 @@ public class TimeBoundIteratorTest { @Test public void testTimeBoundNotHit() { SettableTicker ticker = new SettableTicker(0); - Stopwatch stopwatch = new Stopwatch(ticker); + Stopwatch stopwatch = Stopwatch.createUnstarted(ticker); List list = new ArrayList<>(); list.add(0); @@ -54,7 +54,7 @@ public void testTimeBoundNotHit() { @Test public void testTimeBoundImmediatelyHit() { SettableTicker ticker = new SettableTicker(0); - Stopwatch stopwatch = new Stopwatch(ticker); + Stopwatch stopwatch = Stopwatch.createUnstarted(ticker); List list = new ArrayList<>(); list.add(0); @@ -70,7 +70,7 @@ public void testTimeBoundImmediatelyHit() { @Test public void testEarlyStop() { SettableTicker ticker = new SettableTicker(0); - Stopwatch stopwatch = new Stopwatch(ticker); + Stopwatch stopwatch = Stopwatch.createUnstarted(ticker); List list = new ArrayList<>(); list.add(0); diff --git a/cdap-common/src/test/java/io/cdap/cdap/common/zookeeper/ZKExtOperationsTest.java b/cdap-common/src/test/java/io/cdap/cdap/common/zookeeper/ZKExtOperationsTest.java index 4abd581060df..434508723f4c 100644 --- a/cdap-common/src/test/java/io/cdap/cdap/common/zookeeper/ZKExtOperationsTest.java +++ b/cdap-common/src/test/java/io/cdap/cdap/common/zookeeper/ZKExtOperationsTest.java @@ -59,7 +59,7 @@ public Integer decode(byte[] data) throws IOException { @BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(tmpFolder.newFolder()).build(); - zkServer.startAndWait(); + zkServer.startAsync().awaitRunning(); } @Test @@ -68,8 +68,8 @@ public void testGetAndSet() throws Exception { ZKClientService zkClient1 = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); ZKClientService zkClient2 = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); - zkClient1.startAndWait(); - zkClient2.startAndWait(); + zkClient1.startAsync().awaitRunning(); + zkClient2.startAsync().awaitRunning(); // First a node would get created since no node there. ZKExtOperations.updateOrCreate(zkClient1, path, new Function() { @@ -108,7 +108,8 @@ public Integer apply(@Nullable Integer input) { return 3; } } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + throw new RuntimeException(e); } throw new IllegalStateException("Illegal input " + input); } @@ -134,15 +135,15 @@ public Integer apply(@Nullable Integer input) { Assert.assertNull(result); - zkClient1.stopAndWait(); - zkClient2.stopAndWait(); + zkClient1.stopAsync().awaitTerminated(); + zkClient2.stopAsync().awaitTerminated(); } @Test public void testCreateOrSet() throws Exception { String path = "/parent/testCreateOrSet"; ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); // Create with "1" Assert.assertEquals(1, ZKExtOperations.createOrSet(zkClient, path, @@ -156,14 +157,14 @@ public void testCreateOrSet() throws Exception { // Should get "2" back Assert.assertEquals(2, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue()); - zkClient.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); } @Test public void testSetOrCreate() throws Exception { String path = "/parent/testSetOrCreate"; ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); // Create with "1" Assert.assertEquals(1, ZKExtOperations.setOrCreate(zkClient, path, @@ -177,11 +178,11 @@ public void testSetOrCreate() throws Exception { // Should get "2" back Assert.assertEquals(2, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue()); - zkClient.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); } @AfterClass public static void finish() { - zkServer.stopAndWait(); + zkServer.stopAsync().awaitTerminated(); } } diff --git a/cdap-common/src/test/java/io/cdap/cdap/common/zookeeper/coordination/ResourceCoordinatorTest.java b/cdap-common/src/test/java/io/cdap/cdap/common/zookeeper/coordination/ResourceCoordinatorTest.java index b7813fb679bc..8cef4bf30471 100644 --- a/cdap-common/src/test/java/io/cdap/cdap/common/zookeeper/coordination/ResourceCoordinatorTest.java +++ b/cdap-common/src/test/java/io/cdap/cdap/common/zookeeper/coordination/ResourceCoordinatorTest.java @@ -71,18 +71,18 @@ public void testAssignment() throws InterruptedException, ExecutionException { new ZkClientModule(), new ZkDiscoveryModule()); ZKClientService zkClient = injector.getInstance(ZKClientService.class); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); DiscoveryService discoveryService = injector.getInstance(DiscoveryService.class); try { ResourceCoordinator coordinator = new ResourceCoordinator(zkClient, injector.getInstance(DiscoveryServiceClient.class), new BalancedAssignmentStrategy()); - coordinator.startAndWait(); + coordinator.startAsync().awaitRunning(); try { ResourceCoordinatorClient client = new ResourceCoordinatorClient(zkClient); - client.startAndWait(); + client.startAsync().awaitRunning(); try { // Create a requirement @@ -171,26 +171,26 @@ public void testAssignment() throws InterruptedException, ExecutionException { cancelDiscoverable2.cancel(); } finally { - client.stopAndWait(); + client.stopAsync().awaitTerminated(); } } finally { - coordinator.stopAndWait(); + coordinator.stopAsync().awaitTerminated(); } } finally { - zkClient.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); } } @BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(TMP_FOLDER.newFolder()).build(); - zkServer.startAndWait(); + zkServer.startAsync().awaitRunning(); } @AfterClass public static void finish() { - zkServer.stopAndWait(); + zkServer.stopAsync().awaitTerminated(); } private Cancellable subscribe(ResourceCoordinatorClient client, diff --git a/cdap-common/src/test/java/io/cdap/cdap/common/zookeeper/election/LeaderElectionInfoServiceTest.java b/cdap-common/src/test/java/io/cdap/cdap/common/zookeeper/election/LeaderElectionInfoServiceTest.java index 7ce62d05dbb2..10b5c4660aaf 100644 --- a/cdap-common/src/test/java/io/cdap/cdap/common/zookeeper/election/LeaderElectionInfoServiceTest.java +++ b/cdap-common/src/test/java/io/cdap/cdap/common/zookeeper/election/LeaderElectionInfoServiceTest.java @@ -55,12 +55,12 @@ public class LeaderElectionInfoServiceTest { @BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(TEMP_FOLDER.newFolder()).build(); - zkServer.startAndWait(); + zkServer.startAsync().awaitRunning(); } @AfterClass public static void finish() { - zkServer.stopAndWait(); + zkServer.stopAsync().awaitTerminated(); } @Test @@ -71,12 +71,12 @@ public void testParticipants() throws Exception { List zkClients = new ArrayList<>(); ZKClientService infoZKClient = DefaultZKClientService.Builder.of(zkServer.getConnectionStr()).build(); - infoZKClient.startAndWait(); + infoZKClient.startAsync().awaitRunning(); zkClients.add(infoZKClient); // Start the LeaderElectionInfoService LeaderElectionInfoService infoService = new LeaderElectionInfoService(infoZKClient, prefix); - infoService.startAndWait(); + infoService.startAsync().awaitRunning(); // This will timeout as there is no leader election node created yet try { @@ -90,7 +90,7 @@ public void testParticipants() throws Exception { List leaderElections = new ArrayList<>(); for (int i = 0; i < size; i++) { ZKClientService zkClient = DefaultZKClientService.Builder.of(zkServer.getConnectionStr()).build(); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); zkClients.add(zkClient); final int participantId = i; @@ -105,7 +105,7 @@ public void follower() { LOG.info("Follow: {}", participantId); } }); - leaderElection.start(); + leaderElection.startAsync(); leaderElections.add(leaderElection); } @@ -136,7 +136,7 @@ public boolean apply(LeaderElectionInfoService.Participant input) { int expectedSize = size; for (LeaderElection leaderElection : leaderElections) { - leaderElection.stopAndWait(); + leaderElection.stopAsync().awaitTerminated(); Tasks.waitFor(--expectedSize, new Callable() { @Override public Integer call() throws Exception { @@ -150,10 +150,10 @@ public Integer call() throws Exception { Assert.assertTrue(snapshot.isEmpty()); Assert.assertEquals(participants, snapshot); - infoService.stopAndWait(); + infoService.stopAsync().awaitTerminated(); for (ZKClientService zkClient : zkClients) { - zkClient.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); } } } diff --git a/pom.xml b/pom.xml index 64c19fa20c92..0205bc56be43 100644 --- a/pom.xml +++ b/pom.xml @@ -108,7 +108,7 @@ 1.9.40 1.11.4 1.70 - 0.13.1 + 0.15.0-SNAPSHOT 1.4.0 1.2 3.2.2 @@ -123,7 +123,7 @@ 2.0.0 0.1.0 2.3.1 - 13.0.1 + 32.0.0-jre 4.0 3.3.6 2.2.4 @@ -148,7 +148,7 @@ 3.0.8.Final 2.0 - 2.12.15 + 2.12.18 3.1.0 1.7.15 1.1.1.7 @@ -158,7 +158,7 @@ 0.15.0-incubating 0.8.4 0.9.3 - 1.4.0 + 1.5.0-SNAPSHOT 2.3.6 3.4.5 1.3.1 @@ -302,6 +302,11 @@ guava ${guava.version} + + com.google.guava + failureaccess + 1.0.2 + com.google.inject guice @@ -1579,7 +1584,7 @@ plugins/** **/LICENSES/** **/VERSION - **/*.patch + **/*.patch **/logrotate.d/** **/limits.d/** From 339da19ed96d452cf02a1874fe8de592719caae2 Mon Sep 17 00:00:00 2001 From: abhishkkumar Date: Mon, 8 Jun 2026 21:33:04 +0000 Subject: [PATCH 3/7] new changes fixes comments resolved fixes new --- .../TransactionServiceClientTest.java | 18 ++--- .../distributed/TransactionServiceTest.java | 22 +++--- .../dataset/SystemDatasetInstantiator.java | 10 +-- .../data2/audit/DefaultAuditPublisher.java | 4 +- .../datafabric/dataset/DatasetsUtil.java | 4 +- .../dataset/RemoteDatasetFramework.java | 9 +-- .../AuthorizationDatasetTypeService.java | 4 +- .../dataset/service/DatasetService.java | 14 ++-- .../service/DefaultDatasetTypeService.java | 24 +++--- .../service/executor/DatasetAdminService.java | 19 ++++- .../executor/DatasetOpExecutorService.java | 4 +- .../executor/ImpersonatingDatasetAdmin.java | 4 +- .../type/ConstantClassLoaderProvider.java | 4 +- .../dataset/type/DatasetTypeManager.java | 37 +++++---- .../type/DirectoryClassLoaderProvider.java | 6 +- .../dataset2/DatasetDefinitionRegistries.java | 4 +- .../dataset2/DatasetExistenceVerifier.java | 3 +- .../data2/dataset2/DynamicDatasetCache.java | 10 ++- .../dataset2/InMemoryDatasetFramework.java | 3 +- .../dataset2/MultiThreadDatasetCache.java | 3 +- .../dataset2/SingleThreadDatasetCache.java | 8 +- .../cdap/data2/dataset2/SingleTypeModule.java | 3 +- .../dataset2/StaticDatasetFramework.java | 5 +- .../dataset2/lib/file/FileSetDataset.java | 2 +- .../lib/kv/LevelDBKVTableDefinition.java | 3 +- .../PartitionedFileSetDataset.java | 2 +- .../dataset2/lib/table/AbstractTable.java | 3 +- .../lib/table/MetadataStoreDataset.java | 15 ++-- .../lib/table/leveldb/LevelDBTableCore.java | 3 +- .../table/leveldb/LevelDBTableService.java | 6 +- .../dataset2/lib/timeseries/EntityTable.java | 4 +- .../cdap/cdap/data2/queue/ConsumerConfig.java | 3 +- .../cdap/data2/queue/ConsumerGroupConfig.java | 3 +- .../cdap/cdap/data2/queue/DequeueResult.java | 4 +- .../DynamicTransactionExecutor.java | 3 +- ...NoSqlStructuredTableDatasetDefinition.java | 2 +- .../data/sql/PostgreSqlStorageProvider.java | 3 +- .../spi/metadata/dataset/SearchHelper.java | 9 ++- .../api/dataset/lib/ReflectionTableTest.java | 3 +- .../lib/TimeseriesTableScannerTest.java | 4 +- .../dataset/RemoteDatasetFrameworkTest.java | 6 +- .../service/DatasetServiceTestBase.java | 6 +- .../DatasetOpExecutorServiceTest.java | 13 ++-- .../dataset2/DatasetFrameworkTestUtil.java | 4 +- .../cache/DynamicDatasetCacheTest.java | 7 +- .../dataset2/lib/cube/AbstractCubeTest.java | 3 + .../dataset2/lib/cube/CubeDatasetTest.java | 4 +- .../lib/table/TableConcurrentTest.java | 5 +- .../data2/dataset2/lib/table/TableTest.java | 2 +- .../transaction/TransactionContextTest.java | 4 +- .../java/io/cdap/cdap/kafka/KafkaTester.java | 20 ++--- .../nosql/NoSqlStructuredTableAdminTest.java | 4 +- .../NoSqlStructuredTableConcurrencyTest.java | 4 +- .../NoSqlStructuredTableRegistryTest.java | 4 +- .../data/nosql/NoSqlStructuredTableTest.java | 4 +- .../dataset/DatasetMetadataStorageTest.java | 11 ++- .../cdap/store/DefaultOwnerStoreTest.java | 2 +- .../elastic/ElasticsearchMetadataStorage.java | 6 +- .../ElasticsearchMetadataStorageTest.java | 7 +- .../spi/metadata/MetadataStorageTest.java | 17 ++--- .../AbstractClientMessagingService.java | 9 ++- .../client/ClientRollbackDetail.java | 3 +- .../LeaderElectionMessagingService.java | 18 ++--- .../server/MessagingHttpService.java | 3 +- .../service/ConcurrentMessageWriter.java | 5 +- .../service/CoreMessagingService.java | 23 +++--- .../store/leveldb/DBScanIterator.java | 3 +- .../store/leveldb/LevelDBTableFactory.java | 35 +++++++-- .../AbstractMessagingSubscriberService.java | 2 +- .../LeaderElectionMessagingServiceTest.java | 26 +++---- .../server/MessagingHttpServiceTest.java | 4 +- .../service/ConcurrentMessageWriterTest.java | 9 ++- .../messaging/store/MessageTableTest.java | 3 +- .../messaging/store/PayloadTableTest.java | 3 +- ...bstractMessagingSubscriberServiceTest.java | 12 +-- .../appender/AbstractLogPublisher.java | 6 +- .../cdap/logging/appender/LogMessage.java | 4 +- .../appender/kafka/KafkaLogAppender.java | 6 +- .../appender/kafka/StringPartitioner.java | 3 +- .../appender/remote/RemoteLogAppender.java | 9 ++- .../appender/system/LogFileManager.java | 11 ++- .../appender/system/LogFileOutputStream.java | 11 ++- .../logging/appender/tms/TMSLogAppender.java | 9 ++- .../cdap/cdap/logging/filter/AndFilter.java | 4 +- .../cdap/logging/filter/FilterParser.java | 9 +-- .../cdap/logging/filter/MdcExpression.java | 4 +- .../io/cdap/cdap/logging/filter/OrFilter.java | 4 +- .../distributed/DistributedLogFramework.java | 76 ++++++++++--------- .../framework/local/LocalLogAppender.java | 8 +- .../handlers/AbstractChunkedCallback.java | 7 +- .../handlers/AbstractJSONCallback.java | 3 +- .../gateway/handlers/RemoteLogsFetcher.java | 6 +- .../logbuffer/ConcurrentLogBufferWriter.java | 6 +- .../logging/logbuffer/LogBufferService.java | 19 +++-- .../logging/logbuffer/LogBufferWriter.java | 13 +++- .../logbuffer/recover/LogBufferReader.java | 6 +- .../recover/LogBufferRecoveryService.java | 2 +- .../io/cdap/cdap/logging/meta/Checkpoint.java | 4 +- .../kafka/KafkaLogProcessorPipeline.java | 6 +- .../logbuffer/LogBufferProcessorPipeline.java | 2 +- .../cdap/logging/plugins/LocationManager.java | 6 +- .../cdap/cdap/logging/read/FileLogReader.java | 7 +- .../cdap/logging/read/KafkaLogReader.java | 5 +- .../io/cdap/cdap/logging/read/LogOffset.java | 4 +- .../io/cdap/cdap/logging/read/ReadRange.java | 4 +- .../serialize/LoggingEventSerializer.java | 3 +- .../service/LogSaverStatusService.java | 4 +- .../cdap/cdap/logging/write/LogLocation.java | 3 +- .../LocalMetricsCollectionService.java | 8 +- .../guice/DistributedMetricsClientModule.java | 5 +- ...ssagingMetricsProcessorManagerService.java | 5 +- .../MessagingMetricsProcessorService.java | 3 +- .../MetricsProcessorStatusService.java | 4 +- .../cdap/cdap/metrics/query/TimeseriesId.java | 3 +- .../store/DefaultMetricDatasetFactory.java | 3 +- .../cdap/logging/ErrorLogsClassifierTest.java | 10 +-- .../ErrorClassificationLoggingTest.java | 2 +- .../appender/ErrorTagProviderLoggingTest.java | 2 +- .../LocalLogAppenderResilientTest.java | 6 +- .../cdap/logging/appender/LoggingTester.java | 2 +- .../appender/TestDistributedLogReader.java | 4 +- .../appender/file/TestFileLogging.java | 2 +- .../appender/system/CDAPLogAppenderTest.java | 4 +- .../appender/system/LogFileManagerTest.java | 4 +- .../clean/FileMetadataCleanerTest.java | 4 +- .../cdap/logging/clean/LogCleanerTest.java | 4 +- .../DistributedLogFrameworkTest.java | 20 ++--- .../ConcurrentLogBufferWriterTest.java | 8 +- .../handler/LogBufferHandlerTest.java | 4 +- .../recover/LogBufferRecoveryServiceTest.java | 8 +- .../kafka/KafkaLogProcessorPipelineTest.java | 20 ++--- .../LogBufferProcessorPipelineTest.java | 4 +- .../RollingLocationLogAppenderTest.java | 4 +- .../cdap/logging/read/FileMetadataTest.java | 4 +- .../io/cdap/cdap/metrics/MetricsTestBase.java | 4 +- ...ggregatedMetricsCollectionServiceTest.java | 8 +- ...MessagingMetricsCollectionServiceTest.java | 4 +- ...ingMetricsProcessorManagerServiceTest.java | 10 +-- .../MetricsAdminSubscriberServiceTest.java | 16 ++-- .../process/MetricsProcessorServiceTest.java | 14 ++-- 140 files changed, 572 insertions(+), 490 deletions(-) diff --git a/cdap-data-fabric-tests/src/test/java/io/cdap/cdap/data2/transaction/distributed/TransactionServiceClientTest.java b/cdap-data-fabric-tests/src/test/java/io/cdap/cdap/data2/transaction/distributed/TransactionServiceClientTest.java index 72884ad277c8..f6936d5bb73e 100644 --- a/cdap-data-fabric-tests/src/test/java/io/cdap/cdap/data2/transaction/distributed/TransactionServiceClientTest.java +++ b/cdap-data-fabric-tests/src/test/java/io/cdap/cdap/data2/transaction/distributed/TransactionServiceClientTest.java @@ -98,7 +98,7 @@ public static void beforeClass() throws Exception { hConf.setBoolean("fs.hdfs.impl.disable.cache", true); zkServer = InMemoryZKServer.builder().build(); - zkServer.startAndWait(); + zkServer.startAsync().awaitRunning(); CConfiguration cConf = CConfiguration.create(); // tests should use the current user for HDFS @@ -121,7 +121,7 @@ public static void beforeClass() throws Exception { server = TransactionServiceTest .createTxService(zkServer.getConnectionStr(), Networks.getRandomPort(), hConf, tmpFolder.newFolder(), cConf); - server.startAndWait(); + server.startAsync().awaitRunning(); injector = Guice.createInjector( new ConfigModule(cConf, hConf), @@ -150,25 +150,25 @@ protected void configure() { new AuthenticationContextModules().getNoOpModule()); zkClient = injector.getInstance(ZKClientService.class); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); txStateStorage = injector.getInstance(TransactionStateStorage.class); - txStateStorage.startAndWait(); + txStateStorage.startAsync().awaitRunning(); } @AfterClass public static void afterClass() { try { try { - server.stopAndWait(); + server.stopAsync().awaitTerminated(); miniDfsCluster.shutdown(); } finally { - zkClient.stopAndWait(); - txStateStorage.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); + txStateStorage.stopAsync().awaitTerminated(); } } finally { - zkServer.stopAndWait(); - txStateStorage.stopAndWait(); + zkServer.stopAsync().awaitTerminated(); + txStateStorage.stopAsync().awaitTerminated(); } } diff --git a/cdap-data-fabric-tests/src/test/java/io/cdap/cdap/data2/transaction/distributed/TransactionServiceTest.java b/cdap-data-fabric-tests/src/test/java/io/cdap/cdap/data2/transaction/distributed/TransactionServiceTest.java index 0f3d4ea8b623..808906c59a61 100644 --- a/cdap-data-fabric-tests/src/test/java/io/cdap/cdap/data2/transaction/distributed/TransactionServiceTest.java +++ b/cdap-data-fabric-tests/src/test/java/io/cdap/cdap/data2/transaction/distributed/TransactionServiceTest.java @@ -91,7 +91,7 @@ public void before() throws Exception { hConf.setBoolean("fs.hdfs.impl.disable.cache", true); zkServer = InMemoryZKServer.builder().build(); - zkServer.startAndWait(); + zkServer.startAsync().awaitRunning(); } @After @@ -100,7 +100,7 @@ public void after() throws Exception { miniDfsCluster.shutdown(); } finally { if (zkServer != null) { - zkServer.stopAndWait(); + zkServer.stopAsync().awaitTerminated(); } } } @@ -146,7 +146,7 @@ protected void configure() { ); ZKClientService zkClient = injector.getInstance(ZKClientService.class); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); try { final Table table = createTable("myTable"); @@ -161,7 +161,7 @@ protected void configure() { TransactionService first = createTxService(zkServer.getConnectionStr(), Networks.getRandomPort(), hConf, tmpFolder.newFolder()); - first.startAndWait(); + first.startAsync().awaitRunning(); Assert.assertNotNull(txClient.startShort()); verifyGetAndPut(table, txExecutor, null, "val1"); @@ -171,7 +171,7 @@ protected void configure() { hConf, tmpFolder.newFolder()); // NOTE: we don't have to wait for start as client should pick it up anyways, but we do wait to ensure // the case with two active is handled well - second.startAndWait(); + second.startAsync().awaitRunning(); // wait for affect a bit TimeUnit.SECONDS.sleep(1); @@ -179,7 +179,7 @@ protected void configure() { verifyGetAndPut(table, txExecutor, "val1", "val2"); // shutting down the first one is fine: we have another one to pick up the leader role - first.stopAndWait(); + first.stopAsync().awaitTerminated(); Assert.assertNotNull(txClient.startShort()); verifyGetAndPut(table, txExecutor, "val2", "val3"); @@ -189,21 +189,21 @@ protected void configure() { Networks.getRandomPort(), hConf, tmpFolder.newFolder()); // NOTE: we don't have to wait for start as client should pick it up anyways - third.start(); + third.startAsync(); // stopping second one - second.stopAndWait(); + second.stopAsync().awaitTerminated(); Assert.assertNotNull(txClient.startShort()); verifyGetAndPut(table, txExecutor, "val3", "val4"); // releasing resources - third.stop(); + third.stopAsync().awaitTerminated(); } finally { try { dropTable("myTable"); } finally { - zkClient.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); } } } @@ -268,7 +268,7 @@ protected void configure() { new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getNoOpModule()); - injector.getInstance(ZKClientService.class).startAndWait(); + injector.getInstance(ZKClientService.class).startAsync().awaitRunning(); return injector.getInstance(TransactionService.class); } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data/dataset/SystemDatasetInstantiator.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data/dataset/SystemDatasetInstantiator.java index 406e01cd009d..3acc3ec80077 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data/dataset/SystemDatasetInstantiator.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data/dataset/SystemDatasetInstantiator.java @@ -16,8 +16,7 @@ package io.cdap.cdap.data.dataset; -import com.google.common.base.Objects; -import com.google.common.base.Throwables; +import com.google.common.base.MoreObjects; import io.cdap.cdap.api.data.DatasetInstantiationException; import io.cdap.cdap.api.dataset.Dataset; import io.cdap.cdap.api.dataset.DatasetAdmin; @@ -26,7 +25,6 @@ import io.cdap.cdap.api.service.ServiceUnavailableException; import io.cdap.cdap.data2.datafabric.dataset.type.ConstantClassLoaderProvider; import io.cdap.cdap.data2.datafabric.dataset.type.DatasetClassLoaderProvider; -import io.cdap.cdap.data2.datafabric.dataset.type.DirectoryClassLoaderProvider; import io.cdap.cdap.data2.dataset2.DatasetFramework; import io.cdap.cdap.data2.metadata.lineage.AccessType; import io.cdap.cdap.proto.id.DatasetId; @@ -74,7 +72,7 @@ public SystemDatasetInstantiator(DatasetFramework datasetFramework, this.classLoaderProvider = classLoaderProvider; this.datasetFramework = datasetFramework; this.parentClassLoader = parentClassLoader == null - ? Objects.firstNonNull(Thread.currentThread().getContextClassLoader(), + ? MoreObjects.firstNonNull(Thread.currentThread().getContextClassLoader(), getClass().getClassLoader()) : parentClassLoader; } @@ -110,7 +108,9 @@ public T getDataset(DatasetId datasetId, Map } return dataset; } catch (Exception e) { - Throwables.propagateIfInstanceOf(e, ServiceUnavailableException.class); + if (e instanceof ServiceUnavailableException) { + throw (ServiceUnavailableException) e; + } throw new DatasetInstantiationException("Failed to access dataset: " + datasetId, e); } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/audit/DefaultAuditPublisher.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/audit/DefaultAuditPublisher.java index aa1d4c039388..035c9cbfe7d8 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/audit/DefaultAuditPublisher.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/audit/DefaultAuditPublisher.java @@ -16,7 +16,7 @@ package io.cdap.cdap.data2.audit; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.gson.Gson; import com.google.inject.Inject; import io.cdap.cdap.api.messaging.TopicNotFoundException; @@ -69,7 +69,7 @@ public void publish(EntityId entityId, AuditType auditType, AuditPayload auditPa @Override public void publish(MetadataEntity metadataEntity, AuditType auditType, AuditPayload auditPayload) { - String userId = Objects.firstNonNull(SecurityRequestContext.getUserId(), ""); + String userId = MoreObjects.firstNonNull(SecurityRequestContext.getUserId(), ""); AuditMessage auditMessage = new AuditMessage(System.currentTimeMillis(), metadataEntity, userId, auditType, auditPayload); LOG.trace("Publishing audit message {}", auditMessage); diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/DatasetsUtil.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/DatasetsUtil.java index 48c4944afa3b..79604d2710d4 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/DatasetsUtil.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/DatasetsUtil.java @@ -17,11 +17,9 @@ package io.cdap.cdap.data2.datafabric.dataset; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import io.cdap.cdap.api.data.DatasetContext; import io.cdap.cdap.api.data.DatasetInstantiationException; import io.cdap.cdap.api.dataset.Dataset; -import io.cdap.cdap.api.dataset.DatasetDefinition; import io.cdap.cdap.api.dataset.DatasetManagementException; import io.cdap.cdap.api.dataset.DatasetProperties; import io.cdap.cdap.api.dataset.DatasetSpecification; @@ -128,7 +126,7 @@ public static void createIfNotExists(DatasetFramework datasetFramework, } catch (DatasetManagementException e) { LOG.error("Could NOT add dataset instance {} of type {} with props {}", datasetInstanceId, typeName, props, e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/RemoteDatasetFramework.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/RemoteDatasetFramework.java index 14e0fbca6c3d..fa1b6cdd44b5 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/RemoteDatasetFramework.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/RemoteDatasetFramework.java @@ -16,8 +16,7 @@ package io.cdap.cdap.data2.datafabric.dataset; -import com.google.common.base.Objects; -import com.google.common.base.Throwables; +import com.google.common.base.MoreObjects; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -380,7 +379,7 @@ private T getType(DatasetTypeMeta datasetTypeMeta, DatasetClassLoaderProvider classLoaderProvider) { if (classLoader == null) { - classLoader = Objects.firstNonNull(Thread.currentThread().getContextClassLoader(), + classLoader = MoreObjects.firstNonNull(Thread.currentThread().getContextClassLoader(), getClass().getClassLoader()); } @@ -392,7 +391,7 @@ private T getType(DatasetTypeMeta datasetTypeMeta, } catch (IOException e) { LOG.error("Was not able to init classloader for module {} while trying to load type {}", moduleMeta, datasetTypeMeta, e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } try { @@ -400,7 +399,7 @@ private T getType(DatasetTypeMeta datasetTypeMeta, } catch (Exception e) { LOG.error("Was not able to load dataset module class {} while trying to load type {}", moduleMeta.getClassName(), datasetTypeMeta, e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/AuthorizationDatasetTypeService.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/AuthorizationDatasetTypeService.java index c3510fc0022b..31f4ca50d80a 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/AuthorizationDatasetTypeService.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/AuthorizationDatasetTypeService.java @@ -56,12 +56,12 @@ public AuthorizationDatasetTypeService( @Override protected void startUp() throws Exception { - delegate.startAndWait(); + delegate.startAsync().awaitRunning(); } @Override protected void shutDown() throws Exception { - delegate.stopAndWait(); + delegate.stopAsync().awaitTerminated(); } @Override diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/DatasetService.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/DatasetService.java index d6e2971dd2d9..c2914624d19a 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/DatasetService.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/DatasetService.java @@ -16,7 +16,7 @@ package io.cdap.cdap.data2.datafabric.dataset.service; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.common.collect.Iterables; import com.google.common.util.concurrent.AbstractService; import com.google.common.util.concurrent.MoreExecutors; @@ -142,7 +142,7 @@ protected void doStop() { private void startUp() { try { LOG.info("Starting DatasetService..."); - typeService.startAndWait(); + typeService.startAsync().awaitRunning(); httpService.start(); // setting watch for ops executor service that we need to be running to operate correctly @@ -155,10 +155,10 @@ private void startUp() { LOG.info("Discovered {} service", Constants.Service.DATASET_EXECUTOR); opExecutorDiscovered.set(serviceDiscovered); } - }, MoreExecutors.sameThreadExecutor()); + }, MoreExecutors.directExecutor()); for (DatasetMetricsReporter metricsReporter : metricReporters) { - metricsReporter.start(); + metricsReporter.startAsync(); } } catch (Throwable t) { notifyFailed(t); @@ -234,14 +234,14 @@ private void doShutdown() throws Exception { } for (DatasetMetricsReporter metricsReporter : metricReporters) { - metricsReporter.stop(); + metricsReporter.stopAsync(); } if (opExecutorServiceWatch != null) { opExecutorServiceWatch.cancel(); } - typeService.stopAndWait(); + typeService.stopAsync().awaitTerminated(); // Wait for a few seconds for requests to stop httpService.stop(); @@ -250,7 +250,7 @@ private void doShutdown() throws Exception { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("bindAddress", httpService.getBindAddress()) .toString(); } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/DefaultDatasetTypeService.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/DefaultDatasetTypeService.java index 03be04d8481b..96721a111dfe 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/DefaultDatasetTypeService.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/DefaultDatasetTypeService.java @@ -20,11 +20,10 @@ import com.google.common.base.Splitter; import com.google.common.base.Throwables; import com.google.common.collect.Lists; -import com.google.common.io.Files; import com.google.common.util.concurrent.AbstractIdleService; +import java.nio.file.Files; import com.google.inject.Inject; import io.cdap.cdap.api.dataset.module.DatasetModule; -import io.cdap.cdap.api.dataset.module.DatasetType; import io.cdap.cdap.common.ConflictException; import io.cdap.cdap.common.DatasetModuleCannotBeDeletedException; import io.cdap.cdap.common.DatasetModuleNotFoundException; @@ -108,7 +107,7 @@ public DefaultDatasetTypeService(DatasetTypeManager typeManager, @Override protected void startUp() throws Exception { - txClientService.startAndWait(); + txClientService.startAsync().awaitRunning(); deleteSystemModules(); deployDefaultModules(); if (!extensionModules.isEmpty()) { @@ -118,7 +117,7 @@ protected void startUp() throws Exception { @Override protected void shutDown() throws Exception { - txClientService.stopAndWait(); + txClientService.stopAsync().awaitTerminated(); } /** @@ -271,8 +270,11 @@ public Location call() throws Exception { }); } catch (Exception e) { // the only checked exception that the callable throws is IOException - Throwables.propagateIfInstanceOf(e, IOException.class); - throw Throwables.propagate(e); + Throwables.throwIfUnchecked(e); + if (e instanceof IOException) { + throw (IOException) e; + } + throw new RuntimeException(e); } // verify namespace directory exists @@ -322,7 +324,9 @@ protected void onFinish(HttpResponder responder, File uploadedFile) throws Excep Locations.mkdirsIfNotExists(archiveDir); LOG.debug("Copy from {} to {}", uploadedFile, tmpLocation); - Files.copy(uploadedFile, Locations.newOutputSupplier(tmpLocation)); + try (java.io.OutputStream os = tmpLocation.getOutputStream()) { + Files.copy(uploadedFile.toPath(), os); + } // Finally, move archive to final location LOG.debug("Storing module {} jar at {}", datasetModuleId, archive); @@ -383,7 +387,8 @@ private void deployDefaultModules() throws Exception { LOG.debug("Not adding {} module: it already exists", module.getKey()); } catch (Throwable th) { LOG.error("Failed to add {} module. Aborting.", module.getKey(), th); - throw Throwables.propagate(th); + Throwables.throwIfUnchecked(th); + throw new RuntimeException(th); } } } @@ -419,7 +424,8 @@ private void deployExtensionModules() { LOG.debug("Not adding {} extension module: it already exists", module.getKey()); } catch (Throwable th) { LOG.error("Failed to add {} extension module. Aborting.", module.getKey(), th); - throw Throwables.propagate(th); + Throwables.throwIfUnchecked(th); + throw new RuntimeException(th); } } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/executor/DatasetAdminService.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/executor/DatasetAdminService.java index 513e26cf05cb..697240301ef6 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/executor/DatasetAdminService.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/service/executor/DatasetAdminService.java @@ -16,7 +16,6 @@ package io.cdap.cdap.data2.datafabric.dataset.service.executor; -import com.google.common.io.Closeables; import com.google.inject.Inject; import io.cdap.cdap.api.dataset.Dataset; import io.cdap.cdap.api.dataset.DatasetAdmin; @@ -138,7 +137,11 @@ public DatasetCreationResponse createOrUpdate(final DatasetId datasetInstanceId, typeMeta.getName()); } } finally { - Closeables.closeQuietly(admin); + try { + admin.close(); + } catch (Exception ignored) { + // Ignored because we are in a finally block performing cleanup. + } } return spec1; }); @@ -223,7 +226,11 @@ public void drop(final DatasetId datasetInstanceId, final DatasetTypeMeta typeMe try { admin.drop(); } finally { - Closeables.closeQuietly(admin); + try { + admin.close(); + } catch (Exception ignored) { + // Ignored because we are in a finally block performing cleanup. + } } return null; }); @@ -267,7 +274,11 @@ private T performDatasetAdmin(final DatasetId datasetInstanceId, Operation T execute(final Callable callable) throws IOException { } catch (IOException ioe) { throw ioe; } catch (Exception t) { - Throwables.propagateIfPossible(t); + Throwables.throwIfUnchecked(t); // since the callables we execute only throw IOException (besides unchecked exceptions), // this should never happen @@ -124,7 +124,7 @@ private T execute(final Callable callable) throws IOException { // catch statement. So, no checked exceptions should be wrapped by the following statement. However, we need it // because ImpersonationUtils#doAs declares 'throws Exception', because it can throw other checked exceptions // in the general case - throw Throwables.propagate(t); + throw new RuntimeException(t); } } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/type/ConstantClassLoaderProvider.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/type/ConstantClassLoaderProvider.java index b964107d4a4a..fe82a880a4f7 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/type/ConstantClassLoaderProvider.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/type/ConstantClassLoaderProvider.java @@ -16,7 +16,7 @@ package io.cdap.cdap.data2.datafabric.dataset.type; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import io.cdap.cdap.proto.DatasetModuleMeta; import java.io.IOException; import javax.annotation.Nullable; @@ -37,7 +37,7 @@ public ConstantClassLoaderProvider() { public ConstantClassLoaderProvider(@Nullable ClassLoader classLoader) { this.classLoader = classLoader == null - ? Objects.firstNonNull(Thread.currentThread().getContextClassLoader(), + ? MoreObjects.firstNonNull(Thread.currentThread().getContextClassLoader(), getClass().getClassLoader()) : classLoader; } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/type/DatasetTypeManager.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/type/DatasetTypeManager.java index 4fb895bd158d..6852940b918e 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/type/DatasetTypeManager.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/type/DatasetTypeManager.java @@ -21,7 +21,6 @@ import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; -import com.google.common.io.Closeables; import com.google.inject.Inject; import io.cdap.cdap.api.dataset.DatasetDefinition; import io.cdap.cdap.api.dataset.DatasetSpecification; @@ -145,11 +144,19 @@ public void addModule(final DatasetModuleId datasetModuleId, final String classN LOG.error( "Could not instantiate instance of dataset module class {} for module {} using jarLocation {}", className, datasetModuleId, jarLocation); - throw Throwables.propagate(e); + throw new RuntimeException(e); } finally { // Close the ProgramClassLoader - Closeables.closeQuietly(cl); - Closeables.closeQuietly(classLoaderFolder); + try { + cl.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup in a finally block. + } + try { + classLoaderFolder.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup in a finally block. + } } // 4. determine whether any type were removed from the module, and whether any other modules depend on them @@ -215,10 +222,10 @@ public void addModule(final DatasetModuleId datasetModuleId, final String classN throw new DatasetModuleConflictException(cause.getMessage(), cause); } } - throw Throwables.propagate(e); + throw new RuntimeException(e); } catch (Exception e) { LOG.error("Operation failed", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -342,8 +349,10 @@ public boolean deleteModule(final DatasetModuleId datasetModuleId) } } catch (Exception e) { // the only checked exception the try-catch throws is IOException - Throwables.propagateIfInstanceOf(e, IOException.class); - throw Throwables.propagate(e); + if (e instanceof IOException) { + throw (IOException) e; + } + throw new RuntimeException(e); } return true; @@ -354,10 +363,10 @@ public boolean deleteModule(final DatasetModuleId datasetModuleId) throw (DatasetModuleConflictException) cause; } } - throw Throwables.propagate(e); + throw new RuntimeException(e); } catch (Exception e) { LOG.error("Operation failed", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -392,7 +401,7 @@ public Void call() throws Exception { }); } catch (Exception e) { // the callable throws no checked exceptions - throw Throwables.propagate(e); + throw new RuntimeException(e); } // check if there are any instances that use types of these modules? @@ -420,10 +429,10 @@ public Void call() throws Exception { } } LOG.error("Failed to delete all modules from namespace {}", namespaceId); - throw Throwables.propagate(e); + throw new RuntimeException(e); } catch (Exception e) { LOG.error("Operation failed", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -522,7 +531,7 @@ public T get(String datasetTypeName) { // are registered because modules only register their types and but not the module id. So here we // just assume that this may happen if the module was already loaded. } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/type/DirectoryClassLoaderProvider.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/type/DirectoryClassLoaderProvider.java index 619eb787f7c0..c0d210ed3f93 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/type/DirectoryClassLoaderProvider.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/datafabric/dataset/type/DirectoryClassLoaderProvider.java @@ -22,7 +22,6 @@ import com.google.common.cache.LoadingCache; import com.google.common.cache.RemovalListener; import com.google.common.cache.RemovalNotification; -import com.google.common.io.Closeables; import io.cdap.cdap.common.conf.CConfiguration; import io.cdap.cdap.common.conf.Constants; import io.cdap.cdap.common.io.Locations; @@ -95,7 +94,10 @@ private static final class ClassLoaderRemovalListener implements public void onRemoval(RemovalNotification notification) { ClassLoader cl = notification.getValue(); if (cl instanceof Closeable) { - Closeables.closeQuietly((Closeable) cl); + try { + ((Closeable) cl).close(); + } catch (Exception ignored) { + } } } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/DatasetDefinitionRegistries.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/DatasetDefinitionRegistries.java index 9022bffad52c..135da2bf3906 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/DatasetDefinitionRegistries.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/DatasetDefinitionRegistries.java @@ -16,7 +16,7 @@ package io.cdap.cdap.data2.dataset2; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import io.cdap.cdap.api.dataset.module.DatasetDefinitionRegistry; import io.cdap.cdap.api.dataset.module.DatasetModule; import io.cdap.cdap.common.lang.ClassLoaders; @@ -35,7 +35,7 @@ public static void register(String moduleClassName, ClassLoader systemClassLoader = DatasetDefinitionRegistries.class.getClassLoader(); // Either uses the given classloader or the system one - ClassLoader moduleClassLoader = Objects.firstNonNull(classLoader, systemClassLoader); + ClassLoader moduleClassLoader = MoreObjects.firstNonNull(classLoader, systemClassLoader); Class moduleClass; try { diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/DatasetExistenceVerifier.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/DatasetExistenceVerifier.java index 4398a2a5c88f..687e253499c5 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/DatasetExistenceVerifier.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/DatasetExistenceVerifier.java @@ -16,7 +16,6 @@ package io.cdap.cdap.data2.dataset2; -import com.google.common.base.Throwables; import com.google.inject.Inject; import io.cdap.cdap.api.dataset.DatasetManagementException; import io.cdap.cdap.common.DatasetNotFoundException; @@ -44,7 +43,7 @@ public void ensureExists(DatasetId datasetId) throw new DatasetNotFoundException(datasetId); } } catch (DatasetManagementException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/DynamicDatasetCache.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/DynamicDatasetCache.java index 5af816043870..473280d4c370 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/DynamicDatasetCache.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/DynamicDatasetCache.java @@ -16,8 +16,8 @@ package io.cdap.cdap.data2.dataset2; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; -import com.google.common.io.Closeables; import io.cdap.cdap.api.common.RuntimeArguments; import io.cdap.cdap.api.common.Scope; import io.cdap.cdap.api.data.DatasetContext; @@ -300,7 +300,10 @@ protected abstract T getDataset(DatasetCacheKey key, boolean */ @Override public void close() { - Closeables.closeQuietly(instantiator); + try { + instantiator.close(); + } catch (Exception ignored) { + } } /** @@ -378,7 +381,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("namespace", namespace) .add("name", name) .add("arguments", arguments) @@ -387,4 +390,3 @@ public String toString() { } } } - diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/InMemoryDatasetFramework.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/InMemoryDatasetFramework.java index b49558a4c8f4..8a074dbbc127 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/InMemoryDatasetFramework.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/InMemoryDatasetFramework.java @@ -18,7 +18,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Supplier; -import com.google.common.base.Throwables; import com.google.common.collect.HashBasedTable; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; @@ -506,7 +505,7 @@ protected DatasetDefinitionRegistry createRegistry(LinkedHashSet availab DatasetDefinitionRegistries.register(moduleClassName, classLoader, registry); } catch (Exception e) { LOG.error("Was not able to load dataset module class {}", moduleClassName, e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/MultiThreadDatasetCache.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/MultiThreadDatasetCache.java index c7623109c044..58ad6c740ffb 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/MultiThreadDatasetCache.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/MultiThreadDatasetCache.java @@ -17,7 +17,6 @@ package io.cdap.cdap.data2.dataset2; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -159,7 +158,7 @@ private DynamicDatasetCache entryForCurrentThread() { return perThreadMap.get(Thread.currentThread()); } catch (ExecutionException e) { // this should never happen because all we do in the cache loader is crete a new entry. - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/SingleThreadDatasetCache.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/SingleThreadDatasetCache.java index b9b2a6237904..b0253213c41a 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/SingleThreadDatasetCache.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/SingleThreadDatasetCache.java @@ -24,9 +24,7 @@ import com.google.common.cache.RemovalNotification; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; -import com.google.common.io.Closeables; import com.google.common.util.concurrent.UncheckedExecutionException; -import io.cdap.cdap.api.data.DatasetContext; import io.cdap.cdap.api.data.DatasetInstantiationException; import io.cdap.cdap.api.dataset.Dataset; import io.cdap.cdap.api.dataset.metrics.MeteredDataset; @@ -367,7 +365,10 @@ public void invalidate() { public void close() { for (TransactionAware txAware : extraTxAwares) { if (txAware instanceof Closeable) { - Closeables.closeQuietly((Closeable) txAware); + try { + ((Closeable) txAware).close(); + } catch (Exception ignored) { + } } } invalidate(); @@ -496,4 +497,3 @@ public int hashCode() { } } } - diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/SingleTypeModule.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/SingleTypeModule.java index 7a8be647977e..e3240e08bb59 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/SingleTypeModule.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/SingleTypeModule.java @@ -18,7 +18,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Predicates; -import com.google.common.base.Throwables; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import io.cdap.cdap.api.dataset.Dataset; @@ -152,7 +151,7 @@ public Dataset getDataset(DatasetContext datasetContext, DatasetSpecification sp try { return (Dataset) ctor.newInstance(params.toArray()); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } }); diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/StaticDatasetFramework.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/StaticDatasetFramework.java index bb9d740b1d69..512c4c53b0d3 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/StaticDatasetFramework.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/StaticDatasetFramework.java @@ -16,7 +16,6 @@ package io.cdap.cdap.data2.dataset2; -import com.google.common.base.Throwables; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import io.cdap.cdap.api.dataset.DatasetManagementException; @@ -62,7 +61,7 @@ public Object call() throws Exception { } }); } catch (ExecutionException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -80,7 +79,7 @@ public Object call() throws Exception { }); return modules; } catch (ExecutionException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/file/FileSetDataset.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/file/FileSetDataset.java index 8668832aa2f5..3bb74ff0bd96 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/file/FileSetDataset.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/file/FileSetDataset.java @@ -117,7 +117,7 @@ public FileSetDataset(DatasetContext datasetContext, CConfiguration cConf, FileSetProperties.getFilePermissions(spec.getProperties())); } - // similar to Objects.firstNonNull, but we allow both parameters to be null + // similar to MoreObjects.firstNonNull, but we allow both parameters to be null private T secondIfFirstIsNull(T first, T second) { return first != null ? first : second; } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/kv/LevelDBKVTableDefinition.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/kv/LevelDBKVTableDefinition.java index 1185c7abd92b..e026998e6eee 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/kv/LevelDBKVTableDefinition.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/kv/LevelDBKVTableDefinition.java @@ -16,7 +16,6 @@ package io.cdap.cdap.data2.dataset2.lib.kv; -import com.google.common.base.Throwables; import com.google.inject.Inject; import io.cdap.cdap.api.annotation.ReadOnly; import io.cdap.cdap.api.annotation.WriteOnly; @@ -140,7 +139,7 @@ private DB getTable() { try { return service.getTable(tableName); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/partitioned/PartitionedFileSetDataset.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/partitioned/PartitionedFileSetDataset.java index 4c7c897612a3..e643d78b0860 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/partitioned/PartitionedFileSetDataset.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/partitioned/PartitionedFileSetDataset.java @@ -17,9 +17,9 @@ package io.cdap.cdap.data2.dataset2.lib.partitioned; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Throwables; import com.google.common.base.Function; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/AbstractTable.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/AbstractTable.java index c9ef226b41ba..e5f207136f53 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/AbstractTable.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/AbstractTable.java @@ -17,7 +17,6 @@ package io.cdap.cdap.data2.dataset2.lib.table; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Lists; import io.cdap.cdap.api.annotation.ReadOnly; @@ -257,7 +256,7 @@ public StructuredRecord getCurrentRecord() throws InterruptedException { return rowReader.read(row, tableSchema); } catch (IOException e) { LOG.error("Unable to read row.", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/MetadataStoreDataset.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/MetadataStoreDataset.java index f96df002e21b..61f9ac2bdf77 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/MetadataStoreDataset.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/MetadataStoreDataset.java @@ -17,7 +17,6 @@ package io.cdap.cdap.data2.dataset2.lib.table; -import com.google.common.base.Throwables; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.gson.Gson; @@ -150,7 +149,7 @@ public T getFirst(MDSKey id, Type typeOfT) { return deserialize(id, value, typeOfT); } } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -460,7 +459,7 @@ public void deleteAll(MDSKey id, @Nullable Predicate filter) { } } } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -473,7 +472,7 @@ public void delete(MDSKey id) { try { table.delete(id.getKey(), COLUMN); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -487,7 +486,7 @@ public void write(MDSKey id, T value) { try { table.put(new Put(id.getKey()).add(COLUMN, serialize(value))); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -501,7 +500,7 @@ public void increment(MDSKey id, long amount) { try { table.increment(id.getKey(), COLUMN, amount); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -531,7 +530,7 @@ private Map listCombinedFilterKV(Scan runScan, Type typeOfT, int return map; } } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -566,7 +565,7 @@ private Map listKV(Scan runScan, Type typeOfT, int limit, return map; } } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/leveldb/LevelDBTableCore.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/leveldb/LevelDBTableCore.java index 47742943dab9..1cfbc452de97 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/leveldb/LevelDBTableCore.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/leveldb/LevelDBTableCore.java @@ -16,7 +16,6 @@ package io.cdap.cdap.data2.dataset2.lib.table.leveldb; -import com.google.common.base.Throwables; import io.cdap.cdap.api.common.Bytes; import io.cdap.cdap.api.dataset.table.Result; import io.cdap.cdap.api.dataset.table.Row; @@ -618,7 +617,7 @@ public Row next() { return new Result(result.getFirst(), result.getSecond()); } } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/leveldb/LevelDBTableService.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/leveldb/LevelDBTableService.java index f1cae276603d..0b5d1f60c3cf 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/leveldb/LevelDBTableService.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/table/leveldb/LevelDBTableService.java @@ -24,7 +24,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; -import com.google.common.io.Closeables; import com.google.inject.Inject; import com.google.inject.Singleton; import io.cdap.cdap.common.conf.CConfiguration; @@ -212,7 +211,10 @@ public void compact(String tableName) { */ public void clearTables() { for (DB entries : tables.values()) { - Closeables.closeQuietly(entries); + try { + entries.close(); + } catch (Exception ignored) { + } } tables.clear(); } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/timeseries/EntityTable.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/timeseries/EntityTable.java index 13dd05ff715d..2ae473ab2b34 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/timeseries/EntityTable.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/dataset2/lib/timeseries/EntityTable.java @@ -15,7 +15,7 @@ */ package io.cdap.cdap.data2.dataset2.lib.timeseries; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; @@ -293,7 +293,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("type", type) .add("name", name) .toString(); diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/queue/ConsumerConfig.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/queue/ConsumerConfig.java index 468093f9c826..74f513c01070 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/queue/ConsumerConfig.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/queue/ConsumerConfig.java @@ -15,6 +15,7 @@ */ package io.cdap.cdap.data2.queue; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.base.Preconditions; @@ -52,7 +53,7 @@ public int getInstanceId() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("groupId", getGroupId()) .add("instanceId", instanceId) .add("groupSize", getGroupSize()) diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/queue/ConsumerGroupConfig.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/queue/ConsumerGroupConfig.java index c169d0871b45..bc961d25e598 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/queue/ConsumerGroupConfig.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/queue/ConsumerGroupConfig.java @@ -16,6 +16,7 @@ package io.cdap.cdap.data2.queue; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; /** @@ -58,7 +59,7 @@ public String getHashKey() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("groupId", groupId) .add("groupSize", groupSize) .add("dequeueStrategy", dequeueStrategy) diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/queue/DequeueResult.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/queue/DequeueResult.java index 38704b937a19..4516b2e4c83f 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/queue/DequeueResult.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/queue/DequeueResult.java @@ -16,7 +16,7 @@ package io.cdap.cdap.data2.queue; -import com.google.common.collect.Iterators; +import java.util.Collections; import java.util.Iterator; @@ -88,7 +88,7 @@ public int size() { @Override public Iterator iterator() { - return Iterators.emptyIterator(); + return Collections.emptyIterator(); } }; } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/transaction/DynamicTransactionExecutor.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/transaction/DynamicTransactionExecutor.java index 33f3e845a415..061c84eb2496 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/transaction/DynamicTransactionExecutor.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/data2/transaction/DynamicTransactionExecutor.java @@ -20,7 +20,6 @@ import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import org.apache.tephra.AbstractTransactionExecutor; -import org.apache.tephra.RetryOnConflictStrategy; import org.apache.tephra.RetryStrategies; import org.apache.tephra.RetryStrategy; import org.apache.tephra.TransactionContext; @@ -48,7 +47,7 @@ public class DynamicTransactionExecutor extends AbstractTransactionExecutor { public DynamicTransactionExecutor(TransactionContextFactory txContextFactory, RetryStrategy retryStrategy) { - super(MoreExecutors.sameThreadExecutor()); + super(MoreExecutors.newDirectExecutorService()); this.txContextFactory = txContextFactory; this.retryStrategy = retryStrategy; } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableDatasetDefinition.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableDatasetDefinition.java index 9d9614bf3536..30a4ea23c7d7 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableDatasetDefinition.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableDatasetDefinition.java @@ -83,7 +83,7 @@ public Dataset getDataset(DatasetContext datasetContext, DatasetSpecification sp datasetContext, spec, arguments, classLoader)); } catch (Exception e) { Throwables.propagateIfPossible(e, IOException.class); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/spi/data/sql/PostgreSqlStorageProvider.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/spi/data/sql/PostgreSqlStorageProvider.java index 66dc246db295..54b03d4e2aca 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/spi/data/sql/PostgreSqlStorageProvider.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/spi/data/sql/PostgreSqlStorageProvider.java @@ -17,7 +17,6 @@ package io.cdap.cdap.spi.data.sql; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import com.google.inject.Inject; import io.cdap.cdap.api.metrics.MetricsCollectionService; import io.cdap.cdap.common.conf.CConfiguration; @@ -197,7 +196,7 @@ private static void loadJDBCDriver(CConfiguration cConf, String storageImpl) { JDBCDriverShim driverShim = new JDBCDriverShim(driver); DriverManager.registerDriver(driverShim); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | SQLException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } LOG.info("Successfully loaded {} from {}", driverName, driverExtensionPath); diff --git a/cdap-data-fabric/src/main/java/io/cdap/cdap/spi/metadata/dataset/SearchHelper.java b/cdap-data-fabric/src/main/java/io/cdap/cdap/spi/metadata/dataset/SearchHelper.java index 1d81a2c91614..140553cd12cc 100644 --- a/cdap-data-fabric/src/main/java/io/cdap/cdap/spi/metadata/dataset/SearchHelper.java +++ b/cdap-data-fabric/src/main/java/io/cdap/cdap/spi/metadata/dataset/SearchHelper.java @@ -22,7 +22,6 @@ import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.io.Closeables; import com.google.inject.Inject; import com.google.inject.name.Named; import io.cdap.cdap.api.Transactional; @@ -155,7 +154,7 @@ public T getDataset(String scope) throws DatasetInstantiatio dataset = metaDatasetDefinition.getDataset( SYSTEM_CONTEXT, datasetSpecs.get(scope), Collections.emptyMap(), null); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } datasets.put(scope, dataset); txContext.addTransactionAware(dataset); @@ -198,7 +197,11 @@ public void discardDataset(Dataset dataset) { @Override public void close() { for (String scope : datasets.keySet()) { - Closeables.closeQuietly(datasets.get(scope)); + try { + datasets.get(scope).close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup in close(). + } } datasets.clear(); } diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/api/dataset/lib/ReflectionTableTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/api/dataset/lib/ReflectionTableTest.java index fa9df5f086a8..38f6fd2c7efd 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/api/dataset/lib/ReflectionTableTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/api/dataset/lib/ReflectionTableTest.java @@ -16,6 +16,7 @@ package io.cdap.cdap.api.dataset.lib; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.reflect.TypeToken; import io.cdap.cdap.api.common.Bytes; @@ -144,7 +145,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("firstName", firstName) .add("lastName", lastName) .add("id", id) diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/api/dataset/lib/TimeseriesTableScannerTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/api/dataset/lib/TimeseriesTableScannerTest.java index 2aa94e6b77ea..216cddca94ed 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/api/dataset/lib/TimeseriesTableScannerTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/api/dataset/lib/TimeseriesTableScannerTest.java @@ -16,7 +16,7 @@ package io.cdap.cdap.api.dataset.lib; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; @@ -263,7 +263,7 @@ public byte[] buildKey() { @Override public String toString() { - return Objects.toStringHelper(Fact.class) + return MoreObjects.toStringHelper(Fact.class) .add("ts", ts) .add("dimensions", dimensions) .toString(); diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/datafabric/dataset/RemoteDatasetFrameworkTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/datafabric/dataset/RemoteDatasetFrameworkTest.java index f479f08b2189..0b40e2340765 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/datafabric/dataset/RemoteDatasetFrameworkTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/datafabric/dataset/RemoteDatasetFrameworkTest.java @@ -131,7 +131,7 @@ protected void configure() { // Tx Manager to support working with datasets txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); TransactionRunner transactionRunner = injector.getInstance(TransactionRunner.class); StructuredTableAdmin structuredTableAdmin = injector.getInstance(StructuredTableAdmin.class); StoreDefinition.createAllTables(structuredTableAdmin); @@ -155,7 +155,7 @@ protected void configure() { ImmutableSet.of(new DatasetAdminOpHTTPHandler(datasetAdminService)); opExecutorService = new DatasetOpExecutorService(cConf, SConfiguration.create(), discoveryService, commonNettyHttpServiceFactory, handlers); - opExecutorService.startAndWait(); + opExecutorService.startAsync().awaitRunning(); AccessEnforcer accessEnforcer = injector.getInstance(AccessEnforcer.class); @@ -182,7 +182,7 @@ protected void configure() { new HashSet<>(), typeService, instanceService); // Start dataset service, wait for it to be discoverable - service.startAndWait(); + service.startAsync().awaitRunning(); EndpointStrategy endpointStrategy = new RandomEndpointStrategy( () -> discoveryServiceClient.discover(Constants.Service.DATASET_MANAGER)); Preconditions.checkNotNull(endpointStrategy.pick(5, TimeUnit.SECONDS), diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/datafabric/dataset/service/DatasetServiceTestBase.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/datafabric/dataset/service/DatasetServiceTestBase.java index 5e59b8189f03..008825e21d2a 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/datafabric/dataset/service/DatasetServiceTestBase.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/datafabric/dataset/service/DatasetServiceTestBase.java @@ -187,7 +187,7 @@ protected void configure() { dsFramework = injector.getInstance(RemoteDatasetFramework.class); // Tx Manager to support working with datasets txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); StructuredTableAdmin structuredTableAdmin = injector.getInstance(StructuredTableAdmin.class); StoreDefinition.createAllTables(structuredTableAdmin); @@ -206,7 +206,7 @@ protected void configure() { opExecutorService = new DatasetOpExecutorService(cConf, SConfiguration.create(), discoveryService, commonNettyHttpServiceFactory, handlers); - opExecutorService.startAndWait(); + opExecutorService.startAsync().awaitRunning(); Map defaultModules = injector.getInstance(Key.get(new TypeLiteral>() { }, @@ -252,7 +252,7 @@ protected void configure() { new HashSet<>(), typeService, instanceService); // Start dataset service, wait for it to be discoverable - service.startAndWait(); + service.startAsync().awaitRunning(); waitForService(Constants.Service.DATASET_EXECUTOR); waitForService(Constants.Service.DATASET_MANAGER); // this usually happens while creating a namespace, however not doing that in data fabric tests diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/datafabric/dataset/service/executor/DatasetOpExecutorServiceTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/datafabric/dataset/service/executor/DatasetOpExecutorServiceTest.java index 7558ede43a0b..1b49aae71f91 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/datafabric/dataset/service/executor/DatasetOpExecutorServiceTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/datafabric/dataset/service/executor/DatasetOpExecutorServiceTest.java @@ -16,6 +16,7 @@ package io.cdap.cdap.data2.datafabric.dataset.service.executor; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import com.google.gson.Gson; @@ -147,15 +148,15 @@ protected void configure() { }); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); dsOpExecService = injector.getInstance(DatasetOpExecutorService.class); - dsOpExecService.startAndWait(); + dsOpExecService.startAsync().awaitRunning(); managerService = injector.getInstance(DatasetService.class); - managerService.startAndWait(); + managerService.startAsync().awaitRunning(); dsFramework = injector.getInstance(DatasetFramework.class); @@ -173,10 +174,10 @@ protected void configure() { public void tearDown() throws Exception { dsFramework = null; - dsOpExecService.stopAndWait(); + dsOpExecService.stopAsync().awaitTerminated(); dsOpExecService = null; - managerService.stopAndWait(); + managerService.stopAsync().awaitTerminated(); managerService = null; namespaceAdmin.delete(NamespaceId.DEFAULT); @@ -269,7 +270,7 @@ private URL resolve(String path) throws MalformedURLException { } private DatasetAdminOpResponse getResponse(byte[] body) { - return Objects.firstNonNull(GSON.fromJson(Bytes.toString(body), DatasetAdminOpResponse.class), + return MoreObjects.firstNonNull(GSON.fromJson(Bytes.toString(body), DatasetAdminOpResponse.class), new DatasetAdminOpResponse(null, null)); } } diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/DatasetFrameworkTestUtil.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/DatasetFrameworkTestUtil.java index ee2d66f00e23..97272b5bae44 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/DatasetFrameworkTestUtil.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/DatasetFrameworkTestUtil.java @@ -102,7 +102,7 @@ protected void configure() { ); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); framework = injector.getInstance(DatasetFramework.class); } @@ -110,7 +110,7 @@ protected void configure() { @Override protected void after() { if (txManager != null) { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } if (tmpFolder != null) { tmpFolder.delete(); diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/cache/DynamicDatasetCacheTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/cache/DynamicDatasetCacheTest.java index 90b809a981af..0afca8d98c4c 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/cache/DynamicDatasetCacheTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/cache/DynamicDatasetCacheTest.java @@ -16,7 +16,6 @@ package io.cdap.cdap.data2.dataset2.cache; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; @@ -295,7 +294,7 @@ public void testThatDatasetsStayInTransaction() throws TransactionFailureExcepti Assert.assertSame(ds, ds2); ref.set(ds); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } try { // get the same dataset again. It should be the same object @@ -303,7 +302,7 @@ public void testThatDatasetsStayInTransaction() throws TransactionFailureExcepti Assert.assertSame(ref.get(), ds); cache.discardDataset(ds); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } }); @@ -315,7 +314,7 @@ public void testThatDatasetsStayInTransaction() throws TransactionFailureExcepti // validate that we now have a different instance because the old one was discarded Assert.assertNotSame(ref.get(), ds); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } // validate that only the new instance of the dataset remained active Assert.assertEquals(1, diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/cube/AbstractCubeTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/cube/AbstractCubeTest.java index 633440c77618..820c53aec771 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/cube/AbstractCubeTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/cube/AbstractCubeTest.java @@ -34,6 +34,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -587,6 +588,8 @@ public void testMetricsAggregationOptionSum() throws Exception { null); result = new ArrayList<>(cube.query(query)); Assert.assertEquals(2, result.size()); + // Sort by first timestamp to ensure deterministic ordering across Guava versions + result.sort(Comparator.comparingLong(ts -> ts.getTimeValues().get(0).getTimestamp())); // agg1 gets increment by 1 for 100 seconds, so sum will be 100/5=20, agg2 gets increment by 3 for 50 seconds, so // sum will be 3*50/5=30 verifySumAggregation(result.get(0), "metric1", 5, 30, 10, 0, 0); diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/cube/CubeDatasetTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/cube/CubeDatasetTest.java index 5f4c92c3c481..545c13c5ecb5 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/cube/CubeDatasetTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/cube/CubeDatasetTest.java @@ -102,7 +102,7 @@ public void testTxRetryOnFailure() throws Exception { Configuration txConf = new Configuration(); TransactionManager txManager = new TransactionManager(txConf); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); try { TransactionSystemClient txClient = new InMemoryTxSystemClient(txManager); @@ -141,7 +141,7 @@ public void testTxRetryOnFailure() throws Exception { txClient.commitOrThrow(tx); ((TransactionAware) cube2).postTxCommit(); } finally { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } } diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/table/TableConcurrentTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/table/TableConcurrentTest.java index ea2a3ae423b1..ad8e4eecb8b1 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/table/TableConcurrentTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/table/TableConcurrentTest.java @@ -16,7 +16,6 @@ package io.cdap.cdap.data2.dataset2.lib.table; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import io.cdap.cdap.api.common.Bytes; @@ -168,7 +167,7 @@ public void apply() throws Exception { continue; } catch (Throwable t) { LOG.warn("failed to increment, bailing out", t); - throw Throwables.propagate(t); + throw new RuntimeException(t); } executed[0]++; } @@ -226,7 +225,7 @@ private void appendColumn(byte[] row, Map columns) throws Except continue; } catch (Throwable t) { LOG.warn("failed to append, bailing out", t); - throw Throwables.propagate(t); + throw new RuntimeException(t); } appended = true; diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/table/TableTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/table/TableTest.java index b45514e571d5..14b84bd59897 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/table/TableTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/dataset2/lib/table/TableTest.java @@ -127,7 +127,7 @@ protected DatasetAdmin getTableAdmin(DatasetContext datasetContext, String name) public void before() { Configuration txConf = new Configuration(); TransactionManager txManager = new TransactionManager(txConf); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); txClient = new InMemoryTxSystemClient(txManager); } diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/transaction/TransactionContextTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/transaction/TransactionContextTest.java index 5313eb9bdb5a..734462e97e2f 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/transaction/TransactionContextTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/data2/transaction/TransactionContextTest.java @@ -58,13 +58,13 @@ public class TransactionContextTest { @BeforeClass public static void setup() { txManager = new TransactionManager(new Configuration()); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); txClient = new DummyTxClient(txManager); } @AfterClass public static void finish() { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } private TransactionContext newTransactionContext(TransactionAware... txAwares) { diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/kafka/KafkaTester.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/kafka/KafkaTester.java index dfef63007771..22fe007e7213 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/kafka/KafkaTester.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/kafka/KafkaTester.java @@ -128,19 +128,19 @@ public KafkaTester(Map extraConfigs, Iterable extraModul protected void before() throws Throwable { tmpFolder.create(); zkServer = InMemoryZKServer.builder().setDataDir(tmpFolder.newFolder()).build(); - zkServer.startAndWait(); + zkServer.startAsync().awaitRunning(); LOG.info("In memory ZK started on {}", zkServer.getConnectionStr()); kafkaServer = new EmbeddedKafkaServer(generateKafkaConfig()); - kafkaServer.startAndWait(); + kafkaServer.startAsync().awaitRunning(); initializeCconf(); injector = createInjector(); zkClient = injector.getInstance(ZKClientService.class); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); kafkaClient = injector.getInstance(KafkaClientService.class); - kafkaClient.startAndWait(); + kafkaClient.startAsync().awaitRunning(); brokerService = injector.getInstance(BrokerService.class); - brokerService.startAndWait(); + brokerService.startAsync().awaitRunning(); String brokerList = updateKafkaBrokerList(injector.getInstance(CConfiguration.class), brokerService); @@ -151,11 +151,11 @@ protected void before() throws Throwable { @Override protected void after() { - brokerService.stopAndWait(); - kafkaClient.stopAndWait(); - zkClient.stopAndWait(); - kafkaServer.stopAndWait(); - zkServer.stopAndWait(); + brokerService.stopAsync().awaitTerminated(); + kafkaClient.stopAsync().awaitTerminated(); + zkClient.stopAsync().awaitTerminated(); + kafkaServer.stopAsync().awaitTerminated(); + zkServer.stopAsync().awaitTerminated(); } private void initializeCconf() throws IOException { diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableAdminTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableAdminTest.java index 642696716f39..e700b26da8b7 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableAdminTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableAdminTest.java @@ -42,7 +42,7 @@ public class NoSqlStructuredTableAdminTest extends StructuredTableAdminTest { public static void beforeClass() throws IOException { Configuration txConf = new Configuration(); txManager = new TransactionManager(txConf); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); CConfiguration cConf = dsFrameworkUtil.getConfiguration(); cConf.set(Constants.Dataset.DATA_STORAGE_IMPLEMENTATION, Constants.Dataset.DATA_STORAGE_NOSQL); @@ -57,7 +57,7 @@ protected StructuredTableAdmin getStructuredTableAdmin() throws Exception { @AfterClass public static void afterClass() { if (txManager != null) { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } } } diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableConcurrencyTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableConcurrencyTest.java index f7379bf1aa40..18795d8e4818 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableConcurrencyTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableConcurrencyTest.java @@ -54,7 +54,7 @@ protected TransactionRunner getTransactionRunner() { public static void beforeClass() throws IOException { Configuration txConf = new Configuration(); txManager = new TransactionManager(txConf); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); CConfiguration cConf = dsFrameworkUtil.getConfiguration(); cConf.set(Constants.Dataset.DATA_STORAGE_IMPLEMENTATION, Constants.Dataset.DATA_STORAGE_NOSQL); @@ -65,7 +65,7 @@ public static void beforeClass() throws IOException { @AfterClass public static void afterClass() { if (txManager != null) { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } } } diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableRegistryTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableRegistryTest.java index 4a807929890a..37da4093318d 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableRegistryTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableRegistryTest.java @@ -48,13 +48,13 @@ protected StructuredTableRegistry getStructuredTableRegistry() { public static void beforeClass() { Configuration txConf = new Configuration(); txManager = new TransactionManager(txConf); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); } @AfterClass public static void afterClass() { if (txManager != null) { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } } } diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableTest.java index a11bd0d7f9ff..8723bd198d76 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/data/nosql/NoSqlStructuredTableTest.java @@ -76,7 +76,7 @@ protected TransactionRunner getTransactionRunner() { public static void beforeClass() throws IOException { Configuration txConf = new Configuration(); txManager = new TransactionManager(txConf); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); CConfiguration cConf = dsFrameworkUtil.getConfiguration(); cConf.set(Constants.Dataset.DATA_STORAGE_IMPLEMENTATION, Constants.Dataset.DATA_STORAGE_NOSQL); @@ -87,7 +87,7 @@ public static void beforeClass() throws IOException { @AfterClass public static void afterClass() { if (txManager != null) { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } } diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/metadata/dataset/DatasetMetadataStorageTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/metadata/dataset/DatasetMetadataStorageTest.java index 82f5036b2fd3..817e246bf29f 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/metadata/dataset/DatasetMetadataStorageTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/spi/metadata/dataset/DatasetMetadataStorageTest.java @@ -25,7 +25,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.io.Closeables; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; @@ -107,7 +106,7 @@ protected void configure() { Injector injector = Guice.createInjector(modules); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); storage = injector.getInstance(DatasetMetadataStorage.class); storage.createIndex(); @@ -116,9 +115,13 @@ protected void configure() { @AfterClass public static void teardown() throws IOException { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); storage.dropIndex(); - Closeables.closeQuietly(storage); + try { + storage.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup in teardown. + } } @Override diff --git a/cdap-data-fabric/src/test/java/io/cdap/cdap/store/DefaultOwnerStoreTest.java b/cdap-data-fabric/src/test/java/io/cdap/cdap/store/DefaultOwnerStoreTest.java index d7d88b415f50..03344c0d737b 100644 --- a/cdap-data-fabric/src/test/java/io/cdap/cdap/store/DefaultOwnerStoreTest.java +++ b/cdap-data-fabric/src/test/java/io/cdap/cdap/store/DefaultOwnerStoreTest.java @@ -86,7 +86,7 @@ protected void configure() { } ); - injector.getInstance(TransactionManager.class).startAndWait(); + injector.getInstance(TransactionManager.class).startAsync().awaitRunning(); txRunner = injector.getInstance(TransactionRunner.class); StoreDefinition.OwnerStore.create(injector.getInstance(StructuredTableAdmin.class)); diff --git a/cdap-elastic/src/main/java/io/cdap/cdap/metadata/elastic/ElasticsearchMetadataStorage.java b/cdap-elastic/src/main/java/io/cdap/cdap/metadata/elastic/ElasticsearchMetadataStorage.java index 2f6e1dd5b9bc..1376cfff15dc 100644 --- a/cdap-elastic/src/main/java/io/cdap/cdap/metadata/elastic/ElasticsearchMetadataStorage.java +++ b/cdap-elastic/src/main/java/io/cdap/cdap/metadata/elastic/ElasticsearchMetadataStorage.java @@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import com.google.common.io.Closeables; import com.google.common.io.Resources; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -226,7 +225,10 @@ public String getName() { @Override public void close() { - Closeables.closeQuietly(client); + try { + client.close(); + } catch (Exception ignored) { + } } @Override diff --git a/cdap-elastic/src/test/java/io/cdap/cdap/metadata/elastic/ElasticsearchMetadataStorageTest.java b/cdap-elastic/src/test/java/io/cdap/cdap/metadata/elastic/ElasticsearchMetadataStorageTest.java index 60e63cc8d862..d6c69013afa0 100644 --- a/cdap-elastic/src/test/java/io/cdap/cdap/metadata/elastic/ElasticsearchMetadataStorageTest.java +++ b/cdap-elastic/src/test/java/io/cdap/cdap/metadata/elastic/ElasticsearchMetadataStorageTest.java @@ -18,7 +18,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.io.Closeables; import io.cdap.cdap.api.metadata.MetadataEntity; import io.cdap.cdap.api.metadata.MetadataScope; import io.cdap.cdap.common.conf.CConfiguration; @@ -86,7 +85,11 @@ public static void dropIndex() throws IOException { try { elasticStore.dropIndex(); } finally { - Closeables.closeQuietly(elasticStore); + try { + elasticStore.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup in teardown. + } } } } diff --git a/cdap-metadata-spi/src/test/java/io/cdap/cdap/spi/metadata/MetadataStorageTest.java b/cdap-metadata-spi/src/test/java/io/cdap/cdap/spi/metadata/MetadataStorageTest.java index caacf755ce9d..c86f8599c6b4 100644 --- a/cdap-metadata-spi/src/test/java/io/cdap/cdap/spi/metadata/MetadataStorageTest.java +++ b/cdap-metadata-spi/src/test/java/io/cdap/cdap/spi/metadata/MetadataStorageTest.java @@ -25,7 +25,6 @@ import static io.cdap.cdap.spi.metadata.MetadataKind.PROPERTY; import static io.cdap.cdap.spi.metadata.MetadataKind.TAG; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -508,7 +507,7 @@ public void testBatch() throws IOException { try { return mds.apply(mutation, MutationOptions.DEFAULT); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } }).collect(Collectors.toList()); @@ -1654,7 +1653,7 @@ public void testConcurrency() throws IOException { try { completionService.take(); } catch (InterruptedException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } }); // validate that all "r" tags were removed and all "c" and "t" tags were added @@ -1715,7 +1714,7 @@ public void testBatchConcurrency() throws IOException { try { completionService.take(); } catch (InterruptedException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } }); // validate that all "r" tags were removed and all "c" and "t" tags were added @@ -1725,7 +1724,7 @@ public void testBatchConcurrency() throws IOException { Assert.assertEquals("For entity " + entities.get(e), expected.get(e), mds.read(new Read(entities.get(e))).getTags(USER)); } catch (Exception ex) { - throw Throwables.propagate(ex); + throw new RuntimeException(ex); } }); // clean up @@ -1768,7 +1767,7 @@ public void testUpdateDropConflict() throws IOException { Assert.assertTrue(ImmutableSet.of(Metadata.EMPTY, new Metadata(USER, tags("b"))) .contains(mds.read(new Read(entity)))); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } }); // clean up @@ -1816,7 +1815,7 @@ public void testUpdateDropConflictInBatch() throws IOException { try { completionService.take(); } catch (InterruptedException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } }); IntStream.range(0, numEntities).forEach( @@ -1827,11 +1826,11 @@ public void testUpdateDropConflictInBatch() throws IOException { Assert.assertTrue(ImmutableSet.of(Metadata.EMPTY, new Metadata(USER, tags("b"))) .contains(mds.read(new Read(entities.get(e))))); } catch (Exception ex) { - throw Throwables.propagate(ex); + throw new RuntimeException(ex); } }); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } }); mds.batch(entities.values().stream().map(Drop::new).collect(Collectors.toList()), MutationOptions.DEFAULT); diff --git a/cdap-tms/src/main/java/io/cdap/cdap/messaging/client/AbstractClientMessagingService.java b/cdap-tms/src/main/java/io/cdap/cdap/messaging/client/AbstractClientMessagingService.java index be5aebd1ab71..b8a70b885abb 100644 --- a/cdap-tms/src/main/java/io/cdap/cdap/messaging/client/AbstractClientMessagingService.java +++ b/cdap-tms/src/main/java/io/cdap/cdap/messaging/client/AbstractClientMessagingService.java @@ -16,10 +16,8 @@ package io.cdap.cdap.messaging.client; -import com.google.common.base.Throwables; import com.google.common.collect.Iterables; import com.google.common.io.ByteStreams; -import com.google.common.io.Closeables; import com.google.common.net.HttpHeaders; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -494,13 +492,16 @@ protected RawMessage computeNext() { .setPayload(Bytes.toBytes((ByteBuffer) messageRecord.get("payload"))) .build(); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @Override public void close() { - Closeables.closeQuietly(inputStream); + try { + inputStream.close(); + } catch (Exception ignored) { + } urlConn.disconnect(); } }; diff --git a/cdap-tms/src/main/java/io/cdap/cdap/messaging/client/ClientRollbackDetail.java b/cdap-tms/src/main/java/io/cdap/cdap/messaging/client/ClientRollbackDetail.java index 7961457e27ee..3065587628e7 100644 --- a/cdap-tms/src/main/java/io/cdap/cdap/messaging/client/ClientRollbackDetail.java +++ b/cdap-tms/src/main/java/io/cdap/cdap/messaging/client/ClientRollbackDetail.java @@ -16,7 +16,6 @@ package io.cdap.cdap.messaging.client; -import com.google.common.base.Throwables; import io.cdap.cdap.messaging.spi.RollbackDetail; import io.cdap.cdap.messaging.Schemas; import java.io.ByteArrayInputStream; @@ -92,7 +91,7 @@ private synchronized GenericRecord getDecoded() { return decoded; } catch (IOException e) { // This shouldn't happen, otherwise the server and client is not compatible - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-tms/src/main/java/io/cdap/cdap/messaging/distributed/LeaderElectionMessagingService.java b/cdap-tms/src/main/java/io/cdap/cdap/messaging/distributed/LeaderElectionMessagingService.java index 6e1a8b8f84e2..0e6ff7ffedd0 100644 --- a/cdap-tms/src/main/java/io/cdap/cdap/messaging/distributed/LeaderElectionMessagingService.java +++ b/cdap-tms/src/main/java/io/cdap/cdap/messaging/distributed/LeaderElectionMessagingService.java @@ -127,14 +127,14 @@ public void follower() { latch.countDown(); } }); - leaderElection.startAndWait(); + leaderElection.startAsync().awaitRunning(); latch.await(); } @Override protected void shutDown() throws Exception { try { - leaderElection.stopAndWait(); + leaderElection.stopAsync().awaitTerminated(); } catch (Exception e) { // It can happen if it is currently disconnected from ZK. There is no harm in just continue the shutdown process. LOG.warn("Exception during shutting down leader election", e); @@ -209,7 +209,7 @@ private void updateDelegate(@Nullable DelegateService newService) { } if (oldService != null) { - oldService.stopAndWait(); + oldService.stopAsync().awaitTerminated(); } } @@ -217,11 +217,11 @@ private void fencingStart(final DelegateService service) { Runnable runnable = new Runnable() { @Override public void run() { - service.startAndWait(); + service.startAsync().awaitRunning(); // If failed to mark the service to become available, this means the follower() call happened before this, // so just go ahead and shutdown the service. if (!delegate.attemptMark(service, true)) { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } } }; @@ -260,15 +260,15 @@ private final class DelegateService extends AbstractIdleService { @Override protected void startUp() throws Exception { - messagingService.startAndWait(); - httpService.startAndWait(); + messagingService.startAsync().awaitRunning(); + httpService.startAsync().awaitRunning(); } @Override protected void shutDown() throws Exception { try { - httpService.stopAndWait(); - messagingService.stopAndWait(); + httpService.stopAsync().awaitTerminated(); + messagingService.stopAsync().awaitTerminated(); } finally { // Clear the table cache on shutting down. cacheProvider.clear(); diff --git a/cdap-tms/src/main/java/io/cdap/cdap/messaging/server/MessagingHttpService.java b/cdap-tms/src/main/java/io/cdap/cdap/messaging/server/MessagingHttpService.java index d828231be269..13ccae053581 100644 --- a/cdap-tms/src/main/java/io/cdap/cdap/messaging/server/MessagingHttpService.java +++ b/cdap-tms/src/main/java/io/cdap/cdap/messaging/server/MessagingHttpService.java @@ -16,6 +16,7 @@ package io.cdap.cdap.messaging.server; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.util.concurrent.AbstractIdleService; import com.google.inject.Inject; @@ -90,7 +91,7 @@ public void handle(Throwable t, HttpRequest request, HttpResponder responder) { private void logWithTrace(HttpRequest request, Throwable t) { LOG.trace("Error in handling request={} {} for user={}:", request.method().name(), request.uri(), - Objects.firstNonNull(SecurityRequestContext.getUserId(), ""), t); + MoreObjects.firstNonNull(SecurityRequestContext.getUserId(), ""), t); } }) .setHttpHandlers(handlers); diff --git a/cdap-tms/src/main/java/io/cdap/cdap/messaging/service/ConcurrentMessageWriter.java b/cdap-tms/src/main/java/io/cdap/cdap/messaging/service/ConcurrentMessageWriter.java index 0ddf745dc96d..194c7cce9a8c 100644 --- a/cdap-tms/src/main/java/io/cdap/cdap/messaging/service/ConcurrentMessageWriter.java +++ b/cdap-tms/src/main/java/io/cdap/cdap/messaging/service/ConcurrentMessageWriter.java @@ -17,7 +17,6 @@ package io.cdap.cdap.messaging.service; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import io.cdap.cdap.api.metrics.MetricsCollector; import io.cdap.cdap.api.metrics.NoopMetricsContext; import io.cdap.cdap.messaging.spi.RollbackDetail; @@ -128,7 +127,9 @@ RollbackDetail persist(StoreRequest storeRequest, TopicMetadata metadata) throws pendingStoreRequest.getEndTimestamp(), pendingStoreRequest.getEndSequenceId()); } else { metricsCollector.increment("persist.failure", 1L); - Throwables.propagateIfInstanceOf(pendingStoreRequest.getFailureCause(), IOException.class); + if (pendingStoreRequest.getFailureCause() instanceof IOException) { + throw (IOException) pendingStoreRequest.getFailureCause(); + } throw new IOException("Unable to write message to " + storeRequest.getTopicId(), pendingStoreRequest.getFailureCause()); } diff --git a/cdap-tms/src/main/java/io/cdap/cdap/messaging/service/CoreMessagingService.java b/cdap-tms/src/main/java/io/cdap/cdap/messaging/service/CoreMessagingService.java index 16fa1735ed82..b6bd69f5e9ce 100644 --- a/cdap-tms/src/main/java/io/cdap/cdap/messaging/service/CoreMessagingService.java +++ b/cdap-tms/src/main/java/io/cdap/cdap/messaging/service/CoreMessagingService.java @@ -17,6 +17,7 @@ package io.cdap.cdap.messaging.service; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.base.Throwables; import com.google.common.cache.CacheBuilder; @@ -25,7 +26,6 @@ import com.google.common.cache.RemovalListener; import com.google.common.cache.RemovalNotification; import com.google.common.collect.ImmutableMap; -import com.google.common.io.Closeables; import com.google.common.util.concurrent.AbstractIdleService; import com.google.inject.Inject; import io.cdap.cdap.api.dataset.lib.CloseableIterator; @@ -195,9 +195,9 @@ public RollbackDetail publish(StoreRequest request) throws TopicNotFoundExceptio } return messageTableWriterCache.get(request.getTopicId()).persist(request, metadata); } catch (ExecutionException e) { - Throwable cause = Objects.firstNonNull(e.getCause(), e); + Throwable cause = MoreObjects.firstNonNull(e.getCause(), e); Throwables.propagateIfPossible(cause, TopicNotFoundException.class, IOException.class); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -207,9 +207,9 @@ public void storePayload(StoreRequest request) throws TopicNotFoundException, IO TopicMetadata metadata = topicCache.get(request.getTopicId()); payloadTableWriterCache.get(request.getTopicId()).persist(request, metadata); } catch (ExecutionException e) { - Throwable cause = Objects.firstNonNull(e.getCause(), e); + Throwable cause = MoreObjects.firstNonNull(e.getCause(), e); Throwables.propagateIfPossible(cause, TopicNotFoundException.class, IOException.class); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -227,7 +227,7 @@ public void rollback(TopicId topicId, RollbackDetail rollbackDetail) // Throw if there is any failure in rollback. if (failure != null) { Throwables.propagateIfPossible(failure, TopicNotFoundException.class, IOException.class); - throw Throwables.propagate(failure); + throw new RuntimeException(failure); } } @@ -267,7 +267,10 @@ private void createSystemTopic(TopicId topicId, Queue creationFailureTo protected void shutDown() throws Exception { messageTableWriterCache.invalidateAll(); payloadTableWriterCache.invalidateAll(); - Closeables.closeQuietly(tableFactory); + try { + tableFactory.close(); + } catch (Exception ignored) { + } LOG.info("Core Messaging Service stopped"); } @@ -441,9 +444,9 @@ private TopicMetadata getTopic(TopicId topicId) throws TopicNotFoundException, I try { return topicCache.get(topicId); } catch (ExecutionException e) { - Throwable cause = Objects.firstNonNull(e.getCause(), e); + Throwable cause = MoreObjects.firstNonNull(e.getCause(), e); Throwables.propagateIfPossible(cause, TopicNotFoundException.class, IOException.class); - throw Throwables.propagate(e.getCause()); + throw new RuntimeException(e.getCause()); } } @@ -659,7 +662,7 @@ public boolean hasNext() { // The start offset is only used for the first payloadIterator being constructed. startOffset = null; } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } else { // Otherwise, the message entry is the next message diff --git a/cdap-tms/src/main/java/io/cdap/cdap/messaging/store/leveldb/DBScanIterator.java b/cdap-tms/src/main/java/io/cdap/cdap/messaging/store/leveldb/DBScanIterator.java index f7e701f009dc..80cd1cb0ff1b 100644 --- a/cdap-tms/src/main/java/io/cdap/cdap/messaging/store/leveldb/DBScanIterator.java +++ b/cdap-tms/src/main/java/io/cdap/cdap/messaging/store/leveldb/DBScanIterator.java @@ -16,7 +16,6 @@ package io.cdap.cdap.messaging.store.leveldb; -import com.google.common.base.Throwables; import io.cdap.cdap.api.common.Bytes; import io.cdap.cdap.api.dataset.lib.AbstractCloseableIterator; import java.io.IOException; @@ -64,7 +63,7 @@ public void close() { try { iterator.close(); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } finally { endOfData(); closed = true; diff --git a/cdap-tms/src/main/java/io/cdap/cdap/messaging/store/leveldb/LevelDBTableFactory.java b/cdap-tms/src/main/java/io/cdap/cdap/messaging/store/leveldb/LevelDBTableFactory.java index f1729714327d..ce69439933b0 100644 --- a/cdap-tms/src/main/java/io/cdap/cdap/messaging/store/leveldb/LevelDBTableFactory.java +++ b/cdap-tms/src/main/java/io/cdap/cdap/messaging/store/leveldb/LevelDBTableFactory.java @@ -17,7 +17,6 @@ package io.cdap.cdap.messaging.store.leveldb; import com.google.common.annotations.VisibleForTesting; -import com.google.common.io.Closeables; import com.google.gson.Gson; import com.google.inject.Inject; import io.cdap.cdap.api.dataset.lib.CloseableIterator; @@ -195,12 +194,28 @@ public void close() { this.metadataTable = null; } if (metadataTable != null) { - Closeables.closeQuietly(metadataTable.getLevelDB()); + try { + metadataTable.getLevelDB().close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup during close. + } } Collection dbs = levelDBs.values(); - dbs.forEach(Closeables::closeQuietly); + dbs.forEach(db -> { + try { + db.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup during close. + } + }); dbs.clear(); - partitionedLevelDBs.values().forEach(Closeables::closeQuietly); + partitionedLevelDBs.values().forEach(db -> { + try { + db.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup during close. + } + }); partitionedLevelDBs.clear(); } @@ -312,7 +327,11 @@ public void run() { break; } // We can safely remove and close the levelDB as no one should be accessing them anymore - Closeables.closeQuietly(levelDBs.remove(dataDBPath)); + try { + levelDBs.remove(dataDBPath).close(); + } catch (Exception ignored) { + // Ignored because we are performing background data cleanup. + } filesToDelete.add(dataDBPath); // Payload table @@ -321,7 +340,11 @@ public void run() { break; } // We can safely remove and close the levelDB as no one should be accessing them anymore - Closeables.closeQuietly(levelDBs.remove(dataDBPath)); + try { + levelDBs.remove(dataDBPath).close(); + } catch (Exception ignored) { + // Ignored because we are performing background data cleanup. + } filesToDelete.add(dataDBPath); } diff --git a/cdap-tms/src/main/java/io/cdap/cdap/messaging/subscriber/AbstractMessagingSubscriberService.java b/cdap-tms/src/main/java/io/cdap/cdap/messaging/subscriber/AbstractMessagingSubscriberService.java index a1054eed6350..97e2b8daad67 100644 --- a/cdap-tms/src/main/java/io/cdap/cdap/messaging/subscriber/AbstractMessagingSubscriberService.java +++ b/cdap-tms/src/main/java/io/cdap/cdap/messaging/subscriber/AbstractMessagingSubscriberService.java @@ -185,7 +185,7 @@ protected String processMessages(Iterable> messages) th List> currentTxMessages; String lastMessageId = null; MessageTrackingIterator iterator = new MessageTrackingIterator(messages.iterator()); - Stopwatch stopwatch = new Stopwatch(); + Stopwatch stopwatch = Stopwatch.createUnstarted(); while (iterator.hasNext()) { currentTxMessages = new ArrayList<>(); diff --git a/cdap-tms/src/test/java/io/cdap/cdap/messaging/distributed/LeaderElectionMessagingServiceTest.java b/cdap-tms/src/test/java/io/cdap/cdap/messaging/distributed/LeaderElectionMessagingServiceTest.java index c1bd9925bf65..e88041f752f7 100644 --- a/cdap-tms/src/test/java/io/cdap/cdap/messaging/distributed/LeaderElectionMessagingServiceTest.java +++ b/cdap-tms/src/test/java/io/cdap/cdap/messaging/distributed/LeaderElectionMessagingServiceTest.java @@ -89,7 +89,7 @@ public class LeaderElectionMessagingServiceTest { @BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(TEMP_FOLDER.newFolder()).build(); - zkServer.startAndWait(); + zkServer.startAsync().awaitRunning(); cConf = CConfiguration.create(); cConf.set(Constants.Zookeeper.QUORUM, zkServer.getConnectionStr()); @@ -106,7 +106,7 @@ public static void init() throws IOException { @AfterClass public static void finish() { - zkServer.stopAndWait(); + zkServer.stopAsync().awaitTerminated(); } @Test @@ -118,11 +118,11 @@ public void testTransition() throws Throwable { // Start a messaging service, which would becomes leader ZKClientService zkClient1 = injector1.getInstance(ZKClientService.class); - zkClient1.startAndWait(); + zkClient1.startAsync().awaitRunning(); final MessagingService firstService = injector1.getInstance(MessagingService.class); if (firstService instanceof Service) { - ((Service) firstService).startAndWait(); + ((Service) firstService).startAsync().awaitRunning(); } // Publish a message with the leader @@ -130,11 +130,11 @@ public void testTransition() throws Throwable { // Start another messaging service, this one would be follower ZKClientService zkClient2 = injector2.getInstance(ZKClientService.class); - zkClient2.startAndWait(); + zkClient2.startAsync().awaitRunning(); final MessagingService secondService = injector2.getInstance(MessagingService.class); if (secondService instanceof Service) { - ((Service) secondService).startAndWait(); + ((Service) secondService).startAsync().awaitRunning(); } // Try to call the follower, should get service unavailable. @@ -175,7 +175,7 @@ public List call() throws Throwable { // Shutdown the current leader. The session timeout one should becomes leader again. if (secondService instanceof Service) { - ((Service) secondService).stopAndWait(); + ((Service) secondService).stopAsync().awaitTerminated(); } // Try to fetch message from the current leader again. @@ -201,8 +201,8 @@ public List call() throws Throwable { Assert.assertEquals(Arrays.asList("Testing1", "Testing2"), messages); - zkClient1.stopAndWait(); - zkClient2.stopAndWait(); + zkClient1.stopAsync().awaitTerminated(); + zkClient2.stopAsync().awaitTerminated(); } @Test @@ -217,11 +217,11 @@ public void testFencing() try { Injector injector = createInjector(0); ZKClientService zkClient = injector.getInstance(ZKClientService.class); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); final MessagingService messagingService = injector.getInstance(MessagingService.class); if (messagingService instanceof Service) { - ((Service) messagingService).startAndWait(); + ((Service) messagingService).startAsync().awaitRunning(); } // Shouldn't be serving request yet. @@ -246,9 +246,9 @@ public TopicId call() throws Exception { }, 10L, TimeUnit.SECONDS, 200, TimeUnit.MILLISECONDS); if (messagingService instanceof Service) { - ((Service) messagingService).stopAndWait(); + ((Service) messagingService).stopAsync().awaitTerminated(); } - zkClient.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); } finally { cConf.setLong(Constants.MessagingSystem.HA_FENCING_DELAY_SECONDS, oldFencingDelay); diff --git a/cdap-tms/src/test/java/io/cdap/cdap/messaging/server/MessagingHttpServiceTest.java b/cdap-tms/src/test/java/io/cdap/cdap/messaging/server/MessagingHttpServiceTest.java index 43ff77d868b8..11a5d7286d85 100644 --- a/cdap-tms/src/test/java/io/cdap/cdap/messaging/server/MessagingHttpServiceTest.java +++ b/cdap-tms/src/test/java/io/cdap/cdap/messaging/server/MessagingHttpServiceTest.java @@ -130,13 +130,13 @@ protected void configure() { ); httpService = injector.getInstance(MessagingHttpService.class); - httpService.startAndWait(); + httpService.startAsync().awaitRunning(); client = new DefaultClientMessagingService(injector.getInstance(RemoteClientFactory.class), compressPayload); } @After public void afterTest() { - httpService.stopAndWait(); + httpService.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-tms/src/test/java/io/cdap/cdap/messaging/service/ConcurrentMessageWriterTest.java b/cdap-tms/src/test/java/io/cdap/cdap/messaging/service/ConcurrentMessageWriterTest.java index 2e0184b493e3..aaa1375ad8a6 100644 --- a/cdap-tms/src/test/java/io/cdap/cdap/messaging/service/ConcurrentMessageWriterTest.java +++ b/cdap-tms/src/test/java/io/cdap/cdap/messaging/service/ConcurrentMessageWriterTest.java @@ -232,14 +232,15 @@ public void testConcurrentWrites() throws InterruptedException, BrokenBarrierExc executor.submit(new Runnable() { @Override public void run() { - Stopwatch stopwatch = new Stopwatch(); + Stopwatch stopwatch = Stopwatch.createUnstarted(); try { barrier.await(); stopwatch.start(); for (int i = 0; i < requestPerThread; i++) { writer.persist(new TestStoreRequest(topicId, payload), metadata); } - LOG.info("Complete time for thread {} is {} ms", threadId, stopwatch.elapsedMillis()); + LOG.info("Complete time for thread {} is {} ms", threadId, + stopwatch.elapsed(java.util.concurrent.TimeUnit.MILLISECONDS)); } catch (Exception e) { LOG.error("Exception raised when persisting.", e); } @@ -247,13 +248,13 @@ public void run() { }); } - Stopwatch stopwatch = new Stopwatch(); + Stopwatch stopwatch = Stopwatch.createUnstarted(); barrier.await(); stopwatch.start(); executor.shutdown(); Assert.assertTrue(executor.awaitTermination(1, TimeUnit.MINUTES)); - LOG.info("Total time passed: {} ms", stopwatch.elapsedMillis()); + LOG.info("Total time passed: {} ms", stopwatch.elapsed(java.util.concurrent.TimeUnit.MILLISECONDS)); // Validate that the total number of messages written is correct List messages = testWriter.getMessages().get(topicId); diff --git a/cdap-tms/src/test/java/io/cdap/cdap/messaging/store/MessageTableTest.java b/cdap-tms/src/test/java/io/cdap/cdap/messaging/store/MessageTableTest.java index 5a180d2893c5..75098aaae7e8 100644 --- a/cdap-tms/src/test/java/io/cdap/cdap/messaging/store/MessageTableTest.java +++ b/cdap-tms/src/test/java/io/cdap/cdap/messaging/store/MessageTableTest.java @@ -16,7 +16,6 @@ package io.cdap.cdap.messaging.store; -import com.google.common.base.Throwables; import com.google.common.collect.AbstractIterator; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -282,7 +281,7 @@ protected MessageTable.Entry computeNext() { try { barrier.await(); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } return new TestMessageEntry( topicId, diff --git a/cdap-tms/src/test/java/io/cdap/cdap/messaging/store/PayloadTableTest.java b/cdap-tms/src/test/java/io/cdap/cdap/messaging/store/PayloadTableTest.java index 6b29867b886b..e5ed178a93df 100644 --- a/cdap-tms/src/test/java/io/cdap/cdap/messaging/store/PayloadTableTest.java +++ b/cdap-tms/src/test/java/io/cdap/cdap/messaging/store/PayloadTableTest.java @@ -16,7 +16,6 @@ package io.cdap.cdap.messaging.store; -import com.google.common.base.Throwables; import com.google.common.collect.AbstractIterator; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -179,7 +178,7 @@ protected PayloadTable.Entry computeNext() { try { barrier.await(); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } return new TestPayloadEntry(topicId, GENERATION, threadId, 0, messageCount, Bytes.toBytes("message " + threadId + " " + messageCount++)); diff --git a/cdap-tms/src/test/java/io/cdap/cdap/messaging/subscriber/AbstractMessagingSubscriberServiceTest.java b/cdap-tms/src/test/java/io/cdap/cdap/messaging/subscriber/AbstractMessagingSubscriberServiceTest.java index 98068afe8adf..ff2ea8661d9c 100644 --- a/cdap-tms/src/test/java/io/cdap/cdap/messaging/subscriber/AbstractMessagingSubscriberServiceTest.java +++ b/cdap-tms/src/test/java/io/cdap/cdap/messaging/subscriber/AbstractMessagingSubscriberServiceTest.java @@ -120,14 +120,14 @@ public void close() { TestMessagingSubscriberService service = new TestMessagingSubscriberService( NamespaceId.DEFAULT.topic("test"), 100, 100, 1, RetryStrategies.noRetry(), metricsContext, 100); - service.startAndWait(); + service.startAsync().awaitRunning(); //First one Assert.assertEquals(Arrays.asList(ImmutablePair.of(null, 0), ImmutablePair.of(null, 1)), processedMessages.poll(10, TimeUnit.SECONDS)); //Retry Assert.assertEquals(Arrays.asList(ImmutablePair.of(null, 0), ImmutablePair.of(null, 1)), processedMessages.poll(10, TimeUnit.SECONDS)); - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } @Test @@ -158,7 +158,7 @@ public void close() { TestMessagingSubscriberService service = new TestMessagingSubscriberService( NamespaceId.DEFAULT.topic("test"), 100, 100, 1, RetryStrategies.noRetry(), metricsContext, 3); - service.startAndWait(); + service.startAsync().awaitRunning(); Assert.assertEquals(Arrays.asList(ImmutablePair.of(null, 0), ImmutablePair.of(null, 1), ImmutablePair.of(null, 2)), processedMessages.poll(10, TimeUnit.SECONDS)); Assert.assertEquals(Arrays.asList(ImmutablePair.of(null, 3)), @@ -167,7 +167,7 @@ public void close() { processedMessages.poll(10, TimeUnit.SECONDS)); Assert.assertEquals(Arrays.asList(ImmutablePair.of(null, 5), ImmutablePair.of(null, 6)), processedMessages.poll(10, TimeUnit.SECONDS)); - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } /** @@ -202,10 +202,10 @@ public void close() { TestMessagingSubscriberService service = new TestMessagingSubscriberService( NamespaceId.DEFAULT.topic("test"), 100, 2, 1, RetryStrategies.noRetry(), metricsContext, 2); - service.startAndWait(); + service.startAsync().awaitRunning(); Assert.assertEquals(Arrays.asList(ImmutablePair.of(null, 0), ImmutablePair.of(null, 1)), processedMessages.poll(10, TimeUnit.SECONDS)); - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } class TestMessagingSubscriberService extends AbstractMessagingSubscriberService { diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/AbstractLogPublisher.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/AbstractLogPublisher.java index 78f0a8978678..b7eba7b007a3 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/AbstractLogPublisher.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/AbstractLogPublisher.java @@ -115,12 +115,12 @@ protected long runTask() throws Exception { @Override protected void logTaskFailure(Throwable t) { - OUTAGE_LOG.error("Publish log message failed for {}. Will be retried.", getServiceName(), t); + OUTAGE_LOG.error("Publish log message failed for {}. Will be retried.", serviceName(), t); } @Override protected long handleRetriesExhausted(Exception e) { - logError("Failed to publish log message by " + getServiceName(), e); + logError("Failed to publish log message by " + serviceName(), e); return 0; } @@ -146,7 +146,7 @@ protected void doShutdown() throws Exception { try { publishMessages(buffer, false); } catch (Exception e) { - logError("Failed to publish log message by " + getServiceName(), e); + logError("Failed to publish log message by " + serviceName(), e); } // Ignore those that cannot be publish since we are already in shutdown sequence buffer.clear(); diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/LogMessage.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/LogMessage.java index b2f6d5a1918d..42552034c0c3 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/LogMessage.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/LogMessage.java @@ -20,7 +20,7 @@ import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.classic.spi.IThrowableProxy; import ch.qos.logback.classic.spi.LoggerContextVO; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import io.cdap.cdap.common.logging.LoggingContext; import java.util.Map; import org.slf4j.Marker; @@ -130,7 +130,7 @@ public void prepareForDeferredProcessing() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("loggingEvent", loggingEvent) .add("loggingContext", loggingContext) .toString(); diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/kafka/KafkaLogAppender.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/kafka/KafkaLogAppender.java index 0cc13bbafc93..384d095d8a7c 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/kafka/KafkaLogAppender.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/kafka/KafkaLogAppender.java @@ -50,8 +50,8 @@ public final class KafkaLogAppender extends LogAppender { public void start() { KafkaLogPublisher publisher = new KafkaLogPublisher(cConf); Optional.ofNullable(kafkaLogPublisher.getAndSet(publisher)) - .ifPresent(KafkaLogPublisher::stopAndWait); - publisher.startAndWait(); + .ifPresent(s -> s.stopAsync().awaitTerminated()); + publisher.startAsync().awaitRunning(); addInfo("Successfully started KafkaLogAppender."); super.start(); } @@ -60,7 +60,7 @@ public void start() { public void stop() { super.stop(); Optional.ofNullable(kafkaLogPublisher.getAndSet(null)) - .ifPresent(KafkaLogPublisher::stopAndWait); + .ifPresent(s -> s.stopAsync().awaitTerminated()); } @Override diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/kafka/StringPartitioner.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/kafka/StringPartitioner.java index 838bdadcf2e4..48466c8ee07d 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/kafka/StringPartitioner.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/kafka/StringPartitioner.java @@ -16,6 +16,7 @@ package io.cdap.cdap.logging.appender.kafka; +import java.nio.charset.StandardCharsets; import com.google.common.base.Preconditions; import com.google.common.hash.Hashing; import com.google.inject.Inject; @@ -47,6 +48,6 @@ public StringPartitioner(CConfiguration cConf) { @Override public int partition(Object key, int numPartitions) { - return Math.abs(Hashing.md5().hashString(key.toString()).asInt()) % this.numPartitions; + return Math.abs(Hashing.md5().hashString(key.toString(), StandardCharsets.UTF_8).asInt()) % this.numPartitions; } } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/remote/RemoteLogAppender.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/remote/RemoteLogAppender.java index e1a79e182df8..6760707123ed 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/remote/RemoteLogAppender.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/remote/RemoteLogAppender.java @@ -17,6 +17,7 @@ package io.cdap.cdap.logging.appender.remote; +import java.nio.charset.StandardCharsets; import com.google.common.hash.Hashing; import com.google.common.net.HttpHeaders; import com.google.inject.Inject; @@ -75,8 +76,8 @@ public RemoteLogAppender(CConfiguration cConf, RemoteClientFactory remoteClientF public void start() { RemoteLogPublisher publisher = new RemoteLogPublisher(cConf, remoteClientFactory); Optional.ofNullable(this.publisher.getAndSet(publisher)) - .ifPresent(RemoteLogPublisher::stopAndWait); - publisher.startAndWait(); + .ifPresent(p -> p.stopAsync().awaitTerminated()); + publisher.startAsync().awaitRunning(); addInfo("Successfully started " + APPENDER_NAME); super.start(); } @@ -84,7 +85,7 @@ public void start() { @Override public void stop() { super.stop(); - Optional.ofNullable(this.publisher.getAndSet(null)).ifPresent(RemoteLogPublisher::stopAndWait); + Optional.ofNullable(this.publisher.getAndSet(null)).ifPresent(p -> p.stopAsync().awaitTerminated()); addInfo("Successfully stopped " + APPENDER_NAME); } @@ -178,7 +179,7 @@ protected void logError(String errorMessage, Exception exception) { * do not want kafka dependencies in this class, this method is added here. */ private static int partition(String key, int numPartitions) { - return Math.abs(Hashing.md5().hashString(key).asInt()) % numPartitions; + return Math.abs(Hashing.md5().hashString(key, StandardCharsets.UTF_8).asInt()) % numPartitions; } private void encodeEvents(OutputStream os, DatumWriter> datumWriter, diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/system/LogFileManager.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/system/LogFileManager.java index 29cf129f60eb..8d9faf40300d 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/system/LogFileManager.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/system/LogFileManager.java @@ -17,7 +17,6 @@ package io.cdap.cdap.logging.appender.system; import com.google.common.annotations.VisibleForTesting; -import com.google.common.io.Closeables; import com.google.common.util.concurrent.Uninterruptibles; import io.cdap.cdap.common.io.Locations; import io.cdap.cdap.common.io.Syncable; @@ -119,7 +118,10 @@ public void close() throws IOException { location.getLocation()); } catch (Throwable e) { // delete created file as there was exception while writing meta data - Closeables.closeQuietly(logFileOutputStream); + try { + logFileOutputStream.close(); + } catch (Exception ignored) { + } Locations.deleteQuietly(location.getLocation()); throw new IOException(e); } @@ -173,7 +175,10 @@ public void close() { outputStreamMap.clear(); for (LogFileOutputStream stream : streams) { - Closeables.closeQuietly(stream); + try { + stream.close(); + } catch (Exception ignored) { + } } } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/system/LogFileOutputStream.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/system/LogFileOutputStream.java index d505fe7e2cf8..d8126ce6cbfc 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/system/LogFileOutputStream.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/system/LogFileOutputStream.java @@ -17,7 +17,6 @@ package io.cdap.cdap.logging.appender.system; import ch.qos.logback.classic.spi.ILoggingEvent; -import com.google.common.io.Closeables; import io.cdap.cdap.common.io.ByteBuffers; import io.cdap.cdap.common.io.Syncable; import io.cdap.cdap.logging.serialize.LoggingEvent; @@ -72,8 +71,14 @@ class LogFileOutputStream implements Closeable, Flushable, Syncable { this.createTime = createTime; this.fileSize = 0; } catch (IOException e) { - Closeables.closeQuietly(outputStream); - Closeables.closeQuietly(dataFileWriter); + try { + outputStream.close(); + } catch (Exception ignored) { + } + try { + dataFileWriter.close(); + } catch (Exception ignored) { + } throw e; } } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/tms/TMSLogAppender.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/tms/TMSLogAppender.java index be8f229a4195..4c76bebb5990 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/tms/TMSLogAppender.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/tms/TMSLogAppender.java @@ -16,6 +16,7 @@ package io.cdap.cdap.logging.appender.tms; +import java.nio.charset.StandardCharsets; import com.google.common.annotations.VisibleForTesting; import com.google.common.hash.Hashing; import com.google.inject.Inject; @@ -66,8 +67,8 @@ public class TMSLogAppender extends LogAppender { public void start() { TMSLogPublisher publisher = new TMSLogPublisher(cConf, messagingService); Optional.ofNullable(tmsLogPublisher.getAndSet(publisher)) - .ifPresent(TMSLogPublisher::stopAndWait); - publisher.startAndWait(); + .ifPresent(s -> s.stopAsync().awaitTerminated()); + publisher.startAsync().awaitRunning(); addInfo("Successfully started " + APPENDER_NAME); super.start(); } @@ -75,7 +76,7 @@ public void start() { @Override public void stop() { super.stop(); - Optional.ofNullable(tmsLogPublisher.getAndSet(null)).ifPresent(TMSLogPublisher::stopAndWait); + Optional.ofNullable(tmsLogPublisher.getAndSet(null)).ifPresent(s -> s.stopAsync().awaitTerminated()); addInfo("Successfully stopped " + APPENDER_NAME); } @@ -95,7 +96,7 @@ protected void appendEvent(LogMessage logMessage) { // in Standalone @VisibleForTesting static int partition(Object key, int numPartitions) { - return Math.abs(Hashing.md5().hashString(key.toString()).asInt()) % numPartitions; + return Math.abs(Hashing.md5().hashString(key.toString(), StandardCharsets.UTF_8).asInt()) % numPartitions; } /** diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/AndFilter.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/AndFilter.java index 777a556685cb..281efca9a5a9 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/AndFilter.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/AndFilter.java @@ -17,7 +17,7 @@ package io.cdap.cdap.logging.filter; import ch.qos.logback.classic.spi.ILoggingEvent; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; import java.util.List; @@ -44,7 +44,7 @@ public boolean match(ILoggingEvent event) { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("expressions", expressions) .toString(); } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/FilterParser.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/FilterParser.java index 32ec5758f9a5..b4c334caf6c6 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/FilterParser.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/FilterParser.java @@ -16,7 +16,6 @@ package io.cdap.cdap.logging.filter; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import java.io.IOException; import java.io.StreamTokenizer; @@ -58,7 +57,7 @@ public static Filter parse(String expression) { } } } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } // Not an empty expression @@ -116,7 +115,7 @@ private static String parseString(StreamTokenizer tokenizer) { } } } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } throw new IllegalStateException("Expected operand but got end of expression"); } @@ -136,7 +135,7 @@ private static void parseEquals(StreamTokenizer tokenizer) { } } } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } throw new IllegalStateException("Expected operator = but got end of expression"); } @@ -156,7 +155,7 @@ private static Operator parseOperator(StreamTokenizer tokenizer) { } } } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } // No operator present diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/MdcExpression.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/MdcExpression.java index 9dfcf8b1620f..71c633752a32 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/MdcExpression.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/MdcExpression.java @@ -17,7 +17,7 @@ package io.cdap.cdap.logging.filter; import ch.qos.logback.classic.spi.ILoggingEvent; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; /** * Represents an expression that can match a key,value in MDC. @@ -48,7 +48,7 @@ public String getValue() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("key", key) .add("value", value) .toString(); diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/OrFilter.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/OrFilter.java index 9a993b36a3f7..29952c8f538f 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/OrFilter.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/filter/OrFilter.java @@ -17,7 +17,7 @@ package io.cdap.cdap.logging.filter; import ch.qos.logback.classic.spi.ILoggingEvent; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; import java.util.List; @@ -44,7 +44,7 @@ public boolean match(ILoggingEvent event) { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("expressions", expressions) .toString(); } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/framework/distributed/DistributedLogFramework.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/framework/distributed/DistributedLogFramework.java index 871e0d2cd187..94292366aeac 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/framework/distributed/DistributedLogFramework.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/framework/distributed/DistributedLogFramework.java @@ -17,10 +17,8 @@ package io.cdap.cdap.logging.framework.distributed; import com.google.common.base.Preconditions; -import com.google.common.collect.Iterables; +import com.google.common.base.Throwables; import com.google.common.util.concurrent.AbstractIdleService; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.Service; import com.google.inject.Inject; import com.google.inject.Provider; @@ -42,7 +40,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.ExecutionException; import org.apache.twill.discovery.DiscoveryService; import org.apache.twill.discovery.DiscoveryServiceClient; import org.apache.twill.kafka.client.BrokerService; @@ -111,47 +108,52 @@ protected Service createService(Set partitions) { return new AbstractIdleService() { @Override protected void startUp() throws Exception { - // Starts all pipeline - validateAllFutures(Iterables.transform(pipelines, Service::start)); + // Starts all pipelines in parallel + List failures = new ArrayList<>(); + for (Service pipeline : pipelines) { + pipeline.startAsync(); + } + for (Service pipeline : pipelines) { + try { + pipeline.awaitRunning(); + } catch (IllegalStateException e) { + failures.add(pipeline.failureCause()); + } + } + throwIfNeeded(failures); } @Override protected void shutDown() throws Exception { - // Stops all pipeline - validateAllFutures(Iterables.transform(pipelines, Service::stop)); - } - }; - } - - /** - * Blocks and validates all the given futures completed successfully. - */ - private void validateAllFutures(Iterable> futures) - throws Exception { - // The get call shouldn't throw exception. It just block until all futures completed. - Futures.successfulAsList(futures).get(); - - // Iterates all futures to make sure all of them completed successfully - Throwable exception = null; - for (ListenableFuture future : futures) { - try { - future.get(); - } catch (ExecutionException e) { - if (exception == null) { - exception = e.getCause(); - } else { - exception.addSuppressed(e.getCause()); + // Stops all pipelines in parallel + List failures = new ArrayList<>(); + for (Service pipeline : pipelines) { + pipeline.stopAsync(); + } + for (Service pipeline : pipelines) { + try { + pipeline.awaitTerminated(); + } catch (IllegalStateException e) { + failures.add(pipeline.failureCause()); + } } + throwIfNeeded(failures); } - } - // Throw exception if any of the future failed. - if (exception != null) { - if (exception instanceof Exception) { - throw (Exception) exception; + private void throwIfNeeded(List failures) throws Exception { + if (!failures.isEmpty()) { + Throwable first = failures.get(0); + for (int i = 1; i < failures.size(); i++) { + first.addSuppressed(failures.get(i)); + } + Throwables.throwIfUnchecked(first); + if (first instanceof Exception) { + throw (Exception) first; + } + throw new RuntimeException(first); + } } - throw new RuntimeException(exception); - } + }; } /** diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/framework/local/LocalLogAppender.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/framework/local/LocalLogAppender.java index 1e4b0b91b20f..bffffbc2c7f7 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/framework/local/LocalLogAppender.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/framework/local/LocalLogAppender.java @@ -96,12 +96,12 @@ public void start() { spec.getContext().getMetricsContext(), spec.getContext().getInstanceId()); LocalLogProcessorPipeline pipeline = new LocalLogProcessorPipeline(context, syncIntervalMillis); - pipeline.startAndWait(); + pipeline.startAsync().awaitRunning(); pipelineThreads.add(pipeline.getAppenderThread()); pipelines.add(pipeline); } - this.pipelines.getAndSet(pipelines).forEach(LocalLogProcessorPipeline::stopAndWait); + this.pipelines.getAndSet(pipelines).forEach(s -> s.stopAsync().awaitTerminated()); this.pipelineThreads.set(pipelineThreads); super.start(); @@ -113,7 +113,7 @@ public void stop() { super.stop(); for (LocalLogProcessorPipeline pipeline : pipelines.getAndSet(Collections.emptyList())) { try { - pipeline.stopAndWait(); + pipeline.stopAsync().awaitTerminated(); } catch (Throwable t) { addError("Exception raised when stopping log processing pipeline " + pipeline.getName(), t); } @@ -174,7 +174,7 @@ Thread getAppenderThread() { @Override protected Executor executor() { // Copy from parent, but using a different thread name - // Can't override the getServiceName() method as it is missing from some Guava version. + // Using custom thread name instead of serviceName(). return command -> new Thread(command, "LocalLogProcessor-" + getName()).start(); } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/gateway/handlers/AbstractChunkedCallback.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/gateway/handlers/AbstractChunkedCallback.java index 7638ea8c7c4b..3af3a0bf0e32 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/gateway/handlers/AbstractChunkedCallback.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/gateway/handlers/AbstractChunkedCallback.java @@ -16,8 +16,6 @@ package io.cdap.cdap.logging.gateway.handlers; -import com.google.common.collect.Multimap; -import com.google.common.io.Closeables; import io.cdap.cdap.logging.read.Callback; import io.cdap.cdap.logging.read.LogEvent; import io.cdap.http.ChunkResponder; @@ -112,7 +110,10 @@ public void close() { // Just log the error as debug. LOG.debug("Failed to send chunk", e); } finally { - Closeables.closeQuietly(chunkResponder); + try { + chunkResponder.close(); + } catch (Exception ignored) { + } } } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/gateway/handlers/AbstractJSONCallback.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/gateway/handlers/AbstractJSONCallback.java index 75b24005f587..87ad33749d98 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/gateway/handlers/AbstractJSONCallback.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/gateway/handlers/AbstractJSONCallback.java @@ -16,7 +16,6 @@ package io.cdap.cdap.logging.gateway.handlers; -import com.google.common.base.Throwables; import com.google.gson.Gson; import io.cdap.cdap.logging.read.LogEvent; import io.cdap.http.HttpResponder; @@ -69,7 +68,7 @@ public void handleEvent(LogEvent logEvent) { encodeSend(CharBuffer.wrap(GSON.toJson(encodeSend(logEvent))), false); } catch (IOException e) { // Just propagate the exception, the caller of this Callback should be handling it. - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/gateway/handlers/RemoteLogsFetcher.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/gateway/handlers/RemoteLogsFetcher.java index 303a1dccf150..a1e057200c4b 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/gateway/handlers/RemoteLogsFetcher.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/gateway/handlers/RemoteLogsFetcher.java @@ -16,7 +16,6 @@ package io.cdap.cdap.logging.gateway.handlers; -import com.google.common.io.Closeables; import com.google.inject.Inject; import io.cdap.cdap.common.conf.Constants; import io.cdap.cdap.common.conf.Constants.Gateway; @@ -114,7 +113,10 @@ public boolean onReceived(ByteBuffer buffer) { @Override public void onFinished() { - Closeables.closeQuietly(channel); + try { + channel.close(); + } catch (Exception ignored) { + } } }).build(); remoteClient.executeStreamingRequest(request); diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/ConcurrentLogBufferWriter.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/ConcurrentLogBufferWriter.java index 8154c913939a..de3d48bd98fd 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/ConcurrentLogBufferWriter.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/ConcurrentLogBufferWriter.java @@ -16,7 +16,6 @@ package io.cdap.cdap.logging.logbuffer; -import com.google.common.base.Throwables; import com.google.common.collect.AbstractIterator; import io.cdap.cdap.common.conf.CConfiguration; import io.cdap.cdap.common.conf.Constants; @@ -92,8 +91,9 @@ public void process(LogBufferRequest request) throws IOException { } if (!pendingLogBufferRequest.isSuccess()) { - Throwables.propagateIfInstanceOf(pendingLogBufferRequest.getFailureCause(), - IOException.class); + if (pendingLogBufferRequest.getFailureCause() instanceof IOException) { + throw (IOException) pendingLogBufferRequest.getFailureCause(); + } throw new IOException("Unable to write log event to log buffer", pendingLogBufferRequest.getFailureCause()); } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/LogBufferService.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/LogBufferService.java index 99e475757a18..ae3aa9aa966f 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/LogBufferService.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/LogBufferService.java @@ -17,7 +17,6 @@ package io.cdap.cdap.logging.logbuffer; import com.google.common.base.Preconditions; -import com.google.common.collect.Iterables; import com.google.common.util.concurrent.AbstractIdleService; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; @@ -102,7 +101,12 @@ protected void startUp() throws Exception { // load log pipelines List bufferPipelines = loadLogPipelines(); // start all the log pipelines - validateAllFutures(Iterables.transform(pipelines, Service::start)); + for (Service pipeline : pipelines) { + pipeline.startAsync(); + } + for (Service pipeline : pipelines) { + pipeline.awaitRunning(); + } // recovery service and http handler will send log events to log pipelines. In order to avoid deleting file while // reading them in recovery service, we will pass in an atomic boolean will be set to true by recovery service @@ -111,7 +115,7 @@ protected void startUp() throws Exception { // start log recovery service to recover all the pending logs. recoveryService = new LogBufferRecoveryService(cConf, bufferPipelines, checkpointManagers, startCleanup); - recoveryService.startAndWait(); + recoveryService.startAsync().awaitRunning(); // create concurrent writer ConcurrentLogBufferWriter concurrentWriter = new ConcurrentLogBufferWriter(cConf, @@ -231,9 +235,14 @@ private void stopAllServices() throws Exception { httpService.stop(); } if (recoveryService != null) { - recoveryService.stopAndWait(); + recoveryService.stopAsync().awaitTerminated(); } // Stops all pipeline - validateAllFutures(Iterables.transform(pipelines, Service::stop)); + for (Service pipeline : pipelines) { + pipeline.stopAsync(); + } + for (Service pipeline : pipelines) { + pipeline.awaitTerminated(); + } } } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/LogBufferWriter.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/LogBufferWriter.java index b21cc2994013..a8c5d3fbec07 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/LogBufferWriter.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/LogBufferWriter.java @@ -16,7 +16,6 @@ package io.cdap.cdap.logging.logbuffer; -import com.google.common.io.Closeables; import io.cdap.cdap.api.common.Bytes; import io.cdap.cdap.logging.serialize.LoggingEventSerializer; import java.io.BufferedOutputStream; @@ -154,7 +153,11 @@ public void close() throws IOException { LOG.warn("Error while flushing log buffer output stream.", e); } - Closeables.closeQuietly(currOutputStream); + try { + currOutputStream.close(); + } catch (Exception ignored) { + // Ignored because we are closing the writer and performing final cleanup. + } executorService.shutdown(); } @@ -184,7 +187,11 @@ private long getNextFileId(File baseDir) { private Location rotateFile(OutputStream currOutputStream) throws IOException { currOutputStream.flush(); // close current location output stream - Closeables.closeQuietly(currOutputStream); + try { + currOutputStream.close(); + } catch (Exception ignored) { + // Ignored because we are rotating the file and creating a new output stream. + } writtenBytes = 0; currOffset = 0; diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/recover/LogBufferReader.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/recover/LogBufferReader.java index d460d83d61ac..a6ebce2b230f 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/recover/LogBufferReader.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/recover/LogBufferReader.java @@ -16,7 +16,6 @@ package io.cdap.cdap.logging.logbuffer.recover; -import com.google.common.io.Closeables; import io.cdap.cdap.api.common.Bytes; import io.cdap.cdap.logging.logbuffer.LogBufferEvent; import io.cdap.cdap.logging.logbuffer.LogBufferFileOffset; @@ -169,7 +168,10 @@ LogBufferEvent read() throws IOException { */ public void close() { // close input stream wrapped by this reader - Closeables.closeQuietly(inputStream); + try { + inputStream.close(); + } catch (Exception ignored) { + } } } } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/recover/LogBufferRecoveryService.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/recover/LogBufferRecoveryService.java index 4888002bb813..4c47d5719cb3 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/recover/LogBufferRecoveryService.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/logbuffer/recover/LogBufferRecoveryService.java @@ -127,7 +127,7 @@ protected void triggerShutdown() { } @Override - protected String getServiceName() { + protected String serviceName() { return SERVICE_NAME; } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/meta/Checkpoint.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/meta/Checkpoint.java index 33db81b178a7..fd9f2cc0f367 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/meta/Checkpoint.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/meta/Checkpoint.java @@ -16,7 +16,7 @@ package io.cdap.cdap.logging.meta; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; /** * Represents a checkpoint that can be saved when reading logs. @@ -52,7 +52,7 @@ public long getMaxEventTime() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("Offset", offset) .add("maxEventTime", maxEventTime) .toString(); diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/pipeline/kafka/KafkaLogProcessorPipeline.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/pipeline/kafka/KafkaLogProcessorPipeline.java index 2e4bc7b24261..ad2c8ebe4986 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/pipeline/kafka/KafkaLogProcessorPipeline.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/pipeline/kafka/KafkaLogProcessorPipeline.java @@ -46,16 +46,12 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; -import kafka.api.OffsetRequest$; import kafka.javaapi.consumer.SimpleConsumer; import kafka.javaapi.message.ByteBufferMessageSet; import kafka.message.MessageAndOffset; import org.apache.kafka.common.KafkaException; import org.apache.kafka.common.errors.LeaderNotAvailableException; -import org.apache.kafka.common.errors.NotLeaderForPartitionException; import org.apache.kafka.common.errors.OffsetOutOfRangeException; -import org.apache.kafka.common.errors.UnknownServerException; -import org.apache.kafka.common.errors.UnknownTopicOrPartitionException; import org.apache.twill.common.Threads; import org.apache.twill.kafka.client.BrokerInfo; import org.apache.twill.kafka.client.BrokerService; @@ -223,7 +219,7 @@ protected void shutDown() throws Exception { } @Override - protected String getServiceName() { + protected String serviceName() { return "LogPipeline-" + name; } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/pipeline/logbuffer/LogBufferProcessorPipeline.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/pipeline/logbuffer/LogBufferProcessorPipeline.java index 15332657b026..cb1088e10627 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/pipeline/logbuffer/LogBufferProcessorPipeline.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/pipeline/logbuffer/LogBufferProcessorPipeline.java @@ -139,7 +139,7 @@ protected void shutDown() throws Exception { } @Override - protected String getServiceName() { + protected String serviceName() { return "LogPipeline-" + name; } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/plugins/LocationManager.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/plugins/LocationManager.java index a95186d7be9e..5572b47c0b7d 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/plugins/LocationManager.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/plugins/LocationManager.java @@ -20,7 +20,6 @@ import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.io.ByteStreams; -import com.google.common.io.Closeables; import io.cdap.cdap.common.conf.Constants; import io.cdap.cdap.common.io.Syncable; import java.io.Closeable; @@ -175,7 +174,10 @@ public void close() { for (LocationOutputStream locationOutputStream : locations) { // we do not want to throw any exception rather close all the open output streams. so close quietly - Closeables.closeQuietly(locationOutputStream); + try { + locationOutputStream.close(); + } catch (Exception ignored) { + } } activeLocations.clear(); diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/FileLogReader.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/FileLogReader.java index 2a31b39af0c9..74239d0a0105 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/FileLogReader.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/FileLogReader.java @@ -17,7 +17,6 @@ package io.cdap.cdap.logging.read; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -87,7 +86,7 @@ public void getLogNext(final LoggingContext loggingContext, final ReadRange read } } catch (Throwable e) { LOG.error("Got exception: ", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -133,7 +132,7 @@ public void getLogPrev(final LoggingContext loggingContext, final ReadRange read } } catch (Throwable e) { LOG.error("Got exception: ", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -204,7 +203,7 @@ public void remove() { return concat(closeableIterator); } catch (Throwable e) { LOG.error("Got exception: ", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/KafkaLogReader.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/KafkaLogReader.java index df563233049d..5203ab6ec2d1 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/KafkaLogReader.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/KafkaLogReader.java @@ -18,7 +18,6 @@ import ch.qos.logback.classic.spi.ILoggingEvent; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.inject.Inject; import io.cdap.cdap.api.dataset.lib.CloseableIterator; @@ -112,7 +111,7 @@ public void getLogNext(LoggingContext loggingContext, ReadRange readRange, int m fetchLogEvents(kafkaConsumer, kafkaCallback, startOffset, latestOffset, maxEvents, readRange); } catch (Throwable e) { LOG.error("Got exception: ", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } finally { try { kafkaConsumer.close(); @@ -190,7 +189,7 @@ public void getLogPrev(LoggingContext loggingContext, ReadRange readRange, int m } } catch (Throwable e) { LOG.error("Got exception: ", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } finally { try { kafkaConsumer.close(); diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/LogOffset.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/LogOffset.java index 90bfbeb8b087..e7de5c993665 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/LogOffset.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/LogOffset.java @@ -16,7 +16,7 @@ package io.cdap.cdap.logging.read; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; /** * Represents log offset containing Kafka offset and time of logging event. @@ -45,7 +45,7 @@ public long getTime() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("kafkaOffset", kafkaOffset) .add("time", time) .toString(); diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/ReadRange.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/ReadRange.java index 2d3958da0708..8f299588518c 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/ReadRange.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/read/ReadRange.java @@ -16,7 +16,7 @@ package io.cdap.cdap.logging.read; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; /** * Boundary of a log read request. @@ -64,7 +64,7 @@ public static ReadRange createToRange(LogOffset logOffset) { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("fromMillis", fromMillis) .add("toMillis", toMillis) .add("kafkaOffset", kafkaOffset) diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/serialize/LoggingEventSerializer.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/serialize/LoggingEventSerializer.java index ba7c253f7a57..33f530ea3a73 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/serialize/LoggingEventSerializer.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/serialize/LoggingEventSerializer.java @@ -18,7 +18,6 @@ import ch.qos.logback.classic.Level; import ch.qos.logback.classic.spi.ILoggingEvent; -import com.google.common.base.Throwables; import io.cdap.cdap.api.common.Bytes; import io.cdap.cdap.logging.LoggingUtil; import java.io.ByteArrayOutputStream; @@ -67,7 +66,7 @@ public byte[] toBytes(ILoggingEvent event) { writer.write(toGenericRecord(event), encoder); } catch (IOException e) { // This shouldn't happen since we are writing to byte array output stream. - throw Throwables.propagate(e); + throw new RuntimeException(e); } return out.toByteArray(); } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/service/LogSaverStatusService.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/service/LogSaverStatusService.java index 4e1192df1888..813d6c4148f3 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/service/LogSaverStatusService.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/service/LogSaverStatusService.java @@ -16,7 +16,7 @@ package io.cdap.cdap.logging.service; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.common.util.concurrent.AbstractIdleService; import com.google.inject.Inject; import com.google.inject.name.Named; @@ -90,7 +90,7 @@ protected void shutDown() throws Exception { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("bindAddress", httpService.getBindAddress()) .toString(); } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/write/LogLocation.java b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/write/LogLocation.java index b67452fd1988..80b284b22dde 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/logging/write/LogLocation.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/logging/write/LogLocation.java @@ -17,7 +17,6 @@ package io.cdap.cdap.logging.write; import ch.qos.logback.classic.spi.ILoggingEvent; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -418,7 +417,7 @@ public SeekableInputStream call() throws Exception { throw e; } catch (Exception e) { // should not happen - throw Throwables.propagate(e); + throw new RuntimeException(e); } this.len = location.length(); diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/collect/LocalMetricsCollectionService.java b/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/collect/LocalMetricsCollectionService.java index 1470953249cf..ef0b68c0ee0f 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/collect/LocalMetricsCollectionService.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/collect/LocalMetricsCollectionService.java @@ -88,11 +88,11 @@ protected void startUp() throws Exception { IntStream.range(0, cConf.getInt(Constants.Metrics.MESSAGING_TOPIC_NUM)).boxed() .collect(Collectors.toSet()), getContext(METRICS_PROCESSOR_CONTEXT), 0); - messagingMetricsProcessor.startAndWait(); + messagingMetricsProcessor.startAsync().awaitRunning(); } // The local metrics store do not have ttl, so start the clean up service - metricsCleanUpService.startAndWait(); + metricsCleanUpService.startAsync().awaitRunning(); } @Override @@ -101,7 +101,7 @@ protected void shutDown() throws Exception { Exception failure = null; try { if (messagingMetricsProcessor != null) { - messagingMetricsProcessor.stopAndWait(); + messagingMetricsProcessor.stopAsync().awaitTerminated(); } } catch (Exception e) { failure = e; @@ -120,7 +120,7 @@ protected void shutDown() throws Exception { // Shutdown the clean up service try { - metricsCleanUpService.stopAndWait(); + metricsCleanUpService.stopAsync().awaitTerminated(); } catch (Exception e) { if (failure != null) { failure.addSuppressed(e); diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/guice/DistributedMetricsClientModule.java b/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/guice/DistributedMetricsClientModule.java index 5b4a044c77a9..929a8ed6b68b 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/guice/DistributedMetricsClientModule.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/guice/DistributedMetricsClientModule.java @@ -15,7 +15,6 @@ */ package io.cdap.cdap.metrics.guice; -import com.google.common.base.Throwables; import com.google.common.reflect.TypeToken; import com.google.inject.PrivateModule; import com.google.inject.Provides; @@ -24,11 +23,9 @@ import io.cdap.cdap.api.metrics.MetricValues; import io.cdap.cdap.api.metrics.MetricsCollectionService; import io.cdap.cdap.api.metrics.MetricsSystemClient; -import io.cdap.cdap.common.guice.IOModule; import io.cdap.cdap.common.io.DatumWriter; import io.cdap.cdap.internal.io.DatumWriterFactory; import io.cdap.cdap.internal.io.SchemaGenerator; -import io.cdap.cdap.messaging.spi.MessagingService; import io.cdap.cdap.metrics.collect.MessagingMetricsCollectionService; import io.cdap.cdap.metrics.process.RemoteMetricsSystemClient; @@ -58,7 +55,7 @@ public DatumWriter providesDatumWriter(SchemaGenerator schemaGener return datumWriterFactory.create(METRIC_RECORD_TYPE, schemaGenerator.generate(METRIC_RECORD_TYPE.getType())); } catch (UnsupportedTypeException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/process/MessagingMetricsProcessorManagerService.java b/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/process/MessagingMetricsProcessorManagerService.java index 7df8daf9d5db..d5947b7f0fec 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/process/MessagingMetricsProcessorManagerService.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/process/MessagingMetricsProcessorManagerService.java @@ -144,7 +144,7 @@ protected void startUp() throws Exception { } for (MessagingMetricsProcessorService processorService : metricsProcessorServices) { - processorService.startAndWait(); + processorService.startAsync().awaitRunning(); } } @@ -192,7 +192,7 @@ protected void shutDown() throws Exception { Exception exceptions = new Exception(); for (MessagingMetricsProcessorService processorService : metricsProcessorServices) { try { - processorService.stopAndWait(); + processorService.stopAsync().awaitTerminated(); for (MetricsWriter metricsWriter : metricsWriters) { metricsWriter.close(); } @@ -205,4 +205,3 @@ protected void shutDown() throws Exception { } } } - diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/process/MessagingMetricsProcessorService.java b/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/process/MessagingMetricsProcessorService.java index 7076ba979cef..c6f1254c5b27 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/process/MessagingMetricsProcessorService.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/process/MessagingMetricsProcessorService.java @@ -17,7 +17,6 @@ package io.cdap.cdap.metrics.process; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import com.google.common.reflect.TypeToken; import com.google.common.util.concurrent.AbstractExecutionThreadService; import com.google.inject.Inject; @@ -150,7 +149,7 @@ public class MessagingMetricsProcessorService extends AbstractExecutionThreadSer this.metricReader = readerFactory.create(TypeToken.of(MetricValues.class), metricSchema); } catch (UnsupportedTypeException e) { // This should never happen - throw Throwables.propagate(e); + throw new RuntimeException(e); } this.metricsWriter = metricsWriter; this.maxDelayMillis = cConf.getLong(Constants.Metrics.PROCESSOR_MAX_DELAY_MS); diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/process/MetricsProcessorStatusService.java b/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/process/MetricsProcessorStatusService.java index 8c343826b2ef..09044a9c85b7 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/process/MetricsProcessorStatusService.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/process/MetricsProcessorStatusService.java @@ -16,7 +16,7 @@ package io.cdap.cdap.metrics.process; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.common.util.concurrent.AbstractIdleService; import com.google.inject.Inject; import com.google.inject.name.Named; @@ -99,7 +99,7 @@ protected void shutDown() throws Exception { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("bindAddress", httpService.getBindAddress()) .toString(); } diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/query/TimeseriesId.java b/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/query/TimeseriesId.java index d56ce0c080ab..17522e41e5d2 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/query/TimeseriesId.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/query/TimeseriesId.java @@ -16,6 +16,7 @@ package io.cdap.cdap.metrics.query; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; /** @@ -54,7 +55,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("context", context) .add("metric", metric) .add("tag", tag) diff --git a/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/store/DefaultMetricDatasetFactory.java b/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/store/DefaultMetricDatasetFactory.java index 8f4e81f003d4..848a642d0d40 100644 --- a/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/store/DefaultMetricDatasetFactory.java +++ b/cdap-watchdog/src/main/java/io/cdap/cdap/metrics/store/DefaultMetricDatasetFactory.java @@ -18,7 +18,6 @@ import com.google.common.base.Supplier; import com.google.common.base.Suppliers; -import com.google.common.base.Throwables; import com.google.inject.Inject; import io.cdap.cdap.api.dataset.DatasetAdmin; import io.cdap.cdap.api.dataset.DatasetContext; @@ -102,7 +101,7 @@ private MetricsTable getOrCreateMetricsTable(String tableName, DatasetProperties // metrics tables are in the system namespace return getOrCreateTable(NamespaceId.SYSTEM.dataset(tableName), props); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/ErrorLogsClassifierTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/ErrorLogsClassifierTest.java index 6afa86b36245..2b5e535937da 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/ErrorLogsClassifierTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/ErrorLogsClassifierTest.java @@ -70,13 +70,13 @@ public void testClassifyLogsWithFailureDetailsProvider() { List metricValuesList = new ArrayList<>(); MetricsCollectionService mockMetricsCollectionService = getMockCollectionService(metricValuesList); - mockMetricsCollectionService.startAndWait(); + mockMetricsCollectionService.startAsync().awaitRunning(); CConfiguration cConf = Mockito.mock(CConfiguration.class); ErrorLogsClassifier classifier = new ErrorLogsClassifier(cConf, mockMetricsCollectionService); classifier.classify(closeableIterator, responder, "namespace", "program", "app", "run"); List responses = GSON.fromJson(responder.getResponseContentAsString(), LIST_TYPE); - mockMetricsCollectionService.stopAndWait(); + mockMetricsCollectionService.stopAsync().awaitTerminated(); Assert.assertEquals(1, responses.size()); Assert.assertEquals("stageName", responses.get(0).getStageName()); Assert.assertEquals("errorCategory-'stageName'", responses.get(0).getErrorCategory()); @@ -98,7 +98,7 @@ public void testClassifyLogsWithRuleBasedClassification() { List metricValuesList = new ArrayList<>(); MetricsCollectionService mockMetricsCollectionService = getMockCollectionService(metricValuesList); - mockMetricsCollectionService.startAndWait(); + mockMetricsCollectionService.startAsync().awaitRunning(); CConfiguration cConf = Mockito.mock(CConfiguration.class); ErrorLogsClassifier classifier = new ErrorLogsClassifier(cConf, mockMetricsCollectionService); LogEvent logEvent3 = new LogEvent(getEvent3(IllegalArgumentException.class.getName()), @@ -112,10 +112,10 @@ public void testClassifyLogsWithRuleBasedClassification() { Mockito.when(spy.getRuleList()).thenReturn(getRulesList()); Mockito.doCallRealMethod().when(spy).classify(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); - mockMetricsCollectionService.startAndWait(); + mockMetricsCollectionService.startAsync().awaitRunning(); CloseableIterator closeableIterator = getCloseableIterator(events.iterator()); spy.classify(closeableIterator, responder, "namespace", "program", "app", "run2"); - mockMetricsCollectionService.stopAndWait(); + mockMetricsCollectionService.stopAsync().awaitTerminated(); List responses = GSON.fromJson(responder.getResponseContentAsString(), LIST_TYPE); Assert.assertEquals(1, responses.size()); diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/ErrorClassificationLoggingTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/ErrorClassificationLoggingTest.java index 2c488481b870..18644d02d99c 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/ErrorClassificationLoggingTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/ErrorClassificationLoggingTest.java @@ -147,6 +147,6 @@ public void testErrorClassificationTagsArePresentWithWrappedStageException() { @AfterClass public static void cleanUp() { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } } diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/ErrorTagProviderLoggingTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/ErrorTagProviderLoggingTest.java index 0aaf03ad451c..5288ca5a2bec 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/ErrorTagProviderLoggingTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/ErrorTagProviderLoggingTest.java @@ -104,7 +104,7 @@ public void testErrorCodeProviderException() { @AfterClass public static void cleanUp() throws Exception { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } } diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/LocalLogAppenderResilientTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/LocalLogAppenderResilientTest.java index 0258033b4c17..324176207b97 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/LocalLogAppenderResilientTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/LocalLogAppenderResilientTest.java @@ -134,12 +134,12 @@ protected void configure() { }); TransactionManager txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); DatasetOpExecutorService opExecutorService = injector .getInstance(DatasetOpExecutorService.class); - opExecutorService.startAndWait(); + opExecutorService.startAsync().awaitRunning(); // Start the logging before starting the service. LoggingContextAccessor @@ -187,7 +187,7 @@ public void addStatusEvent(Status status) { // Start dataset service, wait for it to be discoverable DatasetService dsService = injector.getInstance(DatasetService.class); - dsService.startAndWait(); + dsService.startAsync().awaitRunning(); final CountDownLatch startLatch = new CountDownLatch(1); DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class); diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/LoggingTester.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/LoggingTester.java index b88a7a88506c..196ffba053cf 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/LoggingTester.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/LoggingTester.java @@ -113,7 +113,7 @@ protected void configure() { public static TransactionManager createTransactionManager(Injector injector) throws IOException { TransactionManager txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); return txManager; } diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/TestDistributedLogReader.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/TestDistributedLogReader.java index ce7a499e6dd6..8f5eab5e680f 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/TestDistributedLogReader.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/TestDistributedLogReader.java @@ -97,7 +97,7 @@ public static void setUpContext() throws Exception { stringPartitioner.partition(LOGGING_CONTEXT_KAFKA.getLogPartition(), -1)); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); @@ -152,7 +152,7 @@ public static void setUpContext() throws Exception { @AfterClass public static void cleanUp() throws Exception { InMemoryTableService.reset(); - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/file/TestFileLogging.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/file/TestFileLogging.java index eb4a831eb093..1ce373a30c2f 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/file/TestFileLogging.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/file/TestFileLogging.java @@ -66,7 +66,7 @@ public static void setUpContext() throws Exception { @AfterClass public static void cleanUp() throws Exception { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/system/CDAPLogAppenderTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/system/CDAPLogAppenderTest.java index c10d7574a8c2..109128a1242f 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/system/CDAPLogAppenderTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/system/CDAPLogAppenderTest.java @@ -110,14 +110,14 @@ protected void configure() { ); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); StoreDefinition.LogFileMetaStore.create(injector.getInstance(StructuredTableAdmin.class)); } @AfterClass public static void cleanUp() { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/system/LogFileManagerTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/system/LogFileManagerTest.java index da165f4a050f..a709d1ac0a7e 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/system/LogFileManagerTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/appender/system/LogFileManagerTest.java @@ -96,14 +96,14 @@ protected void configure() { ); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); StoreDefinition.LogFileMetaStore.create(injector.getInstance(StructuredTableAdmin.class)); } @AfterClass public static void cleanUp() { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/clean/FileMetadataCleanerTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/clean/FileMetadataCleanerTest.java index 267a8bbeed97..92be6df7f60b 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/clean/FileMetadataCleanerTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/clean/FileMetadataCleanerTest.java @@ -108,13 +108,13 @@ protected void configure() { ); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); StoreDefinition.LogFileMetaStore.create(injector.getInstance(StructuredTableAdmin.class)); } @AfterClass public static void cleanUp() { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/clean/LogCleanerTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/clean/LogCleanerTest.java index 6f968f2b295b..f5616618a653 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/clean/LogCleanerTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/clean/LogCleanerTest.java @@ -109,13 +109,13 @@ protected void configure() { ); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); StoreDefinition.LogFileMetaStore.create(injector.getInstance(StructuredTableAdmin.class)); } @AfterClass public static void cleanUp() { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/framework/distributed/DistributedLogFrameworkTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/framework/distributed/DistributedLogFrameworkTest.java index 79a282ec35d9..aca1bc4ca70a 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/framework/distributed/DistributedLogFrameworkTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/framework/distributed/DistributedLogFrameworkTest.java @@ -112,19 +112,19 @@ public static void init() { @Before public void beforeTest() throws Exception { injector = createInjector(); - injector.getInstance(ZKClientService.class).startAndWait(); - injector.getInstance(KafkaClientService.class).startAndWait(); - injector.getInstance(BrokerService.class).startAndWait(); - injector.getInstance(TransactionManager.class).startAndWait(); + injector.getInstance(ZKClientService.class).startAsync().awaitRunning(); + injector.getInstance(KafkaClientService.class).startAsync().awaitRunning(); + injector.getInstance(BrokerService.class).startAsync().awaitRunning(); + injector.getInstance(TransactionManager.class).startAsync().awaitRunning(); StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); } @After public void afterTest() { - injector.getInstance(TransactionManager.class).stopAndWait(); - injector.getInstance(BrokerService.class).stopAndWait(); - injector.getInstance(KafkaClientService.class).stopAndWait(); - injector.getInstance(ZKClientService.class).stopAndWait(); + injector.getInstance(TransactionManager.class).stopAsync().awaitTerminated(); + injector.getInstance(BrokerService.class).stopAsync().awaitTerminated(); + injector.getInstance(KafkaClientService.class).stopAsync().awaitTerminated(); + injector.getInstance(ZKClientService.class).stopAsync().awaitTerminated(); injector = null; } @@ -133,7 +133,7 @@ public void testFramework() throws Exception { DistributedLogFramework framework = injector.getInstance(DistributedLogFramework.class); CConfiguration cConf = injector.getInstance(CConfiguration.class); - framework.startAndWait(); + framework.startAsync().awaitRunning(); // Send some logs to Kafka. LoggingContext context = new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), @@ -186,7 +186,7 @@ public void testFramework() throws Exception { } }, 10, TimeUnit.SECONDS, msgCount, TimeUnit.MILLISECONDS); - framework.stopAndWait(); + framework.stopAsync().awaitTerminated(); String kafkaTopic = cConf.get(Constants.Logging.KAFKA_TOPIC); // Check the checkpoint is persisted correctly. Since all messages are processed, diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/logbuffer/ConcurrentLogBufferWriterTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/logbuffer/ConcurrentLogBufferWriterTest.java index 9328e8654c33..d94bb6086bba 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/logbuffer/ConcurrentLogBufferWriterTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/logbuffer/ConcurrentLogBufferWriterTest.java @@ -81,7 +81,7 @@ public void testWrites() throws Exception { new LogProcessorPipelineContext(CConfiguration.create(), "test", loggerContext, NO_OP_METRICS_CONTEXT, 0), config, checkpointManager, 0); // start the pipeline - pipeline.startAndWait(); + pipeline.startAsync().awaitRunning(); ConcurrentLogBufferWriter writer = new ConcurrentLogBufferWriter(cConf, ImmutableList.of(pipeline), () -> { }); ImmutableList events = getLoggingEvents(); @@ -97,7 +97,7 @@ public void testWrites() throws Exception { // verify if the pipeline has processed the messages. Tasks.waitFor(5, () -> appender.getEvents().size(), 60, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); - pipeline.stopAndWait(); + pipeline.stopAsync().awaitTerminated(); loggerContext.stop(); } @@ -122,7 +122,7 @@ public void testConcurrentWrites() throws Exception { new LogProcessorPipelineContext(CConfiguration.create(), "test", loggerContext, NO_OP_METRICS_CONTEXT, 0), config, checkpointManager, 0); // start the pipeline - pipeline.startAndWait(); + pipeline.startAsync().awaitRunning(); ConcurrentLogBufferWriter writer = new ConcurrentLogBufferWriter(cConf, ImmutableList.of(pipeline), () -> { }); ImmutableList events = getLoggingEvents(); @@ -156,7 +156,7 @@ public void testConcurrentWrites() throws Exception { // verify if the pipeline has processed the messages. Tasks.waitFor(100, () -> appender.getEvents().size(), 60, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); - pipeline.stopAndWait(); + pipeline.stopAsync().awaitTerminated(); loggerContext.stop(); } diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/logbuffer/handler/LogBufferHandlerTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/logbuffer/handler/LogBufferHandlerTest.java index 78aa27e9775d..1f5e9dee9dac 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/logbuffer/handler/LogBufferHandlerTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/logbuffer/handler/LogBufferHandlerTest.java @@ -73,7 +73,7 @@ public void testHandler() throws Exception { "Test", MockAppender.class); LogBufferProcessorPipeline pipeline = getLogPipeline(loggerContext); - pipeline.startAndWait(); + pipeline.startAsync().awaitRunning(); ConcurrentLogBufferWriter writer = new ConcurrentLogBufferWriter(cConf, ImmutableList.of(pipeline), () -> { }); @@ -98,7 +98,7 @@ public void testHandler() throws Exception { remoteLogAppender.stop(); httpService.stop(); - pipeline.stopAndWait(); + pipeline.stopAsync().awaitTerminated(); loggerContext.stop(); } diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/logbuffer/recover/LogBufferRecoveryServiceTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/logbuffer/recover/LogBufferRecoveryServiceTest.java index 7e254b8b59a7..3d7cee3f57d7 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/logbuffer/recover/LogBufferRecoveryServiceTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/logbuffer/recover/LogBufferRecoveryServiceTest.java @@ -72,7 +72,7 @@ public void testLogBufferRecoveryService() throws Exception { config, checkpointManager, 0); // start the pipeline - pipeline.startAndWait(); + pipeline.startAsync().awaitRunning(); // write directly to log buffer LogBufferWriter writer = new LogBufferWriter(absolutePath, 250, () -> { }); @@ -85,12 +85,12 @@ public void testLogBufferRecoveryService() throws Exception { LogBufferRecoveryService service = new LogBufferRecoveryService(ImmutableList.of(pipeline), ImmutableList.of(checkpointManager), absolutePath, 2, new AtomicBoolean(true)); - service.startAndWait(); + service.startAsync().awaitRunning(); Tasks.waitFor(5, () -> appender.getEvents().size(), 120, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); - service.stopAndWait(); - pipeline.stopAndWait(); + service.stopAsync().awaitTerminated(); + pipeline.stopAsync().awaitTerminated(); loggerContext.stop(); } diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/pipeline/kafka/KafkaLogProcessorPipelineTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/pipeline/kafka/KafkaLogProcessorPipelineTest.java index 182c46c6fde7..9faf86d1f55c 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/pipeline/kafka/KafkaLogProcessorPipelineTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/pipeline/kafka/KafkaLogProcessorPipelineTest.java @@ -134,7 +134,7 @@ public void testBasicSort() throws Exception { checkpointManager, KAFKA_TESTER.getBrokerService(), config); - pipeline.startAndWait(); + pipeline.startAsync().awaitRunning(); // Publish some log messages to Kafka long now = System.currentTimeMillis(); @@ -176,7 +176,7 @@ public void testBasicSort() throws Exception { Assert.assertEquals("Large logger " + i, events.get(i).getMessage()); } - pipeline.stopAndWait(); + pipeline.stopAsync().awaitTerminated(); loggerContext.stop(); Assert.assertNull(appender.getEvents()); @@ -203,7 +203,7 @@ public void testRegularFlush() throws Exception { checkpointManager, KAFKA_TESTER.getBrokerService(), config); - pipeline.startAndWait(); + pipeline.startAsync().awaitRunning(); // Even when there is no event, the flush should still get called. Tasks.waitFor(5, appender::getFlushCount, 3, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); @@ -219,7 +219,7 @@ public void testRegularFlush() throws Exception { // Wait until getting all logs. Tasks.waitFor(3, () -> appender.getEvents().size(), 3, TimeUnit.SECONDS, 200, TimeUnit.MILLISECONDS); - pipeline.stopAndWait(); + pipeline.stopAsync().awaitTerminated(); // Should get at least 20 flush calls, since the checkpoint is every 2 seconds Assert.assertTrue(appender.getFlushCount() >= 20); @@ -229,7 +229,7 @@ public void testRegularFlush() throws Exception { public void testMetricsAppender() throws Exception { Injector injector = KAFKA_TESTER.getInjector(); MetricsCollectionService collectionService = injector.getInstance(MetricsCollectionService.class); - collectionService.startAndWait(); + collectionService.startAsync().awaitRunning(); LoggerContext loggerContext = new LocalAppenderContext(injector.getInstance(TransactionRunner.class), injector.getInstance(LocationFactory.class), injector.getInstance(MetricsCollectionService.class)); @@ -254,7 +254,7 @@ public void testMetricsAppender() throws Exception { checkpointManager, KAFKA_TESTER.getBrokerService(), config); - pipeline.startAndWait(); + pipeline.startAsync().awaitRunning(); // Publish some log messages to Kafka long now = System.currentTimeMillis(); @@ -337,9 +337,9 @@ public void testMetricsAppender() throws Exception { LoggingContextHelper.getMetricsTags(serviceLoggingContext), new ArrayList<>()), 3L); } finally { - pipeline.stopAndWait(); + pipeline.stopAsync().awaitTerminated(); loggerContext.stop(); - collectionService.stopAndWait(); + collectionService.stopAsync().awaitTerminated(); } } @@ -379,7 +379,7 @@ public void testMultiAppenders() throws Exception { checkpointManager, KAFKA_TESTER.getBrokerService(), config); - pipeline.startAndWait(); + pipeline.startAsync().awaitRunning(); // Publish some log messages to Kafka using a non-specific logger long now = System.currentTimeMillis(); @@ -439,7 +439,7 @@ public void testMultiAppenders() throws Exception { return Arrays.asList("TRACE", "DEBUG", "INFO", "WARN", "ERROR", "ERROR").equals(lines1); }, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); - pipeline.stopAndWait(); + pipeline.stopAsync().awaitTerminated(); loggerContext.stop(); } diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/pipeline/logbuffer/LogBufferProcessorPipelineTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/pipeline/logbuffer/LogBufferProcessorPipelineTest.java index ad28dae00ec2..8f9b85e57eed 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/pipeline/logbuffer/LogBufferProcessorPipelineTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/pipeline/logbuffer/LogBufferProcessorPipelineTest.java @@ -67,7 +67,7 @@ public void testSingleAppender() throws Exception { new LogProcessorPipelineContext(CConfiguration.create(), "test", loggerContext, NO_OP_METRICS_CONTEXT, 0), config, checkpointManager, 0); // start the pipeline - pipeline.startAndWait(); + pipeline.startAsync().awaitRunning(); // start thread to write to incomingEventQueue List events = getLoggingEvents(); @@ -95,7 +95,7 @@ public void testSingleAppender() throws Exception { // wait for pipeline to append all the logs to appender. The DEBUG message should get filtered out. Tasks.waitFor(200, () -> appender.getEvents().size(), 60, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); executorService.shutdown(); - pipeline.stopAndWait(); + pipeline.stopAsync().awaitTerminated(); loggerContext.stop(); } diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/plugins/RollingLocationLogAppenderTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/plugins/RollingLocationLogAppenderTest.java index 350709ec9cb9..e9a3b495cdc9 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/plugins/RollingLocationLogAppenderTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/plugins/RollingLocationLogAppenderTest.java @@ -110,12 +110,12 @@ protected void configure() { ); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); } @AfterClass public static void cleanUp() throws Exception { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/read/FileMetadataTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/read/FileMetadataTest.java index 1003b4845e15..46b82d6b56e7 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/logging/read/FileMetadataTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/logging/read/FileMetadataTest.java @@ -99,13 +99,13 @@ protected void configure() { ); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); StoreDefinition.LogFileMetaStore.create(injector.getInstance(StructuredTableAdmin.class)); } @AfterClass public static void cleanUp() { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/MetricsTestBase.java b/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/MetricsTestBase.java index c3d6f4bc8a6a..0e18f1d72918 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/MetricsTestBase.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/MetricsTestBase.java @@ -82,7 +82,7 @@ public void init() throws IOException, UnsupportedTypeException { injector = Guice.createInjector(getModules()); messagingService = injector.getInstance(MessagingService.class); if (messagingService instanceof Service) { - ((Service) messagingService).startAndWait(); + ((Service) messagingService).startAsync().awaitRunning(); } metricValueType = TypeToken.of(MetricValues.class); schema = new ReflectionSchemaGenerator().generate(metricValueType.getType()); @@ -93,7 +93,7 @@ public void init() throws IOException, UnsupportedTypeException { @After public void stop() { if (messagingService instanceof Service) { - ((Service) messagingService).stopAndWait(); + ((Service) messagingService).stopAsync().awaitTerminated(); } } diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/collect/AggregatedMetricsCollectionServiceTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/collect/AggregatedMetricsCollectionServiceTest.java index 6066bbfb3961..aa1783ae48f8 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/collect/AggregatedMetricsCollectionServiceTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/collect/AggregatedMetricsCollectionServiceTest.java @@ -74,7 +74,7 @@ protected void publish(Iterator metrics) { } }; - service.startAndWait(); + service.startAsync().awaitRunning(); // non-empty tags. final Map baseTags = ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, NAMESPACE, @@ -139,7 +139,7 @@ protected void publish(Iterator metrics) { metricsContext.gauge(GAUGE_METRIC, 0); verifyCounterMetricsValue(published, ImmutableMap.of(6, ImmutableMap.of(GAUGE_METRIC, 0L))); } finally { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } } @@ -211,7 +211,7 @@ protected void publish(Iterator metrics) { } }; - service.startAndWait(); + service.startAsync().awaitRunning(); // non-empty tags. final Map baseTags = ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, NAMESPACE, @@ -245,7 +245,7 @@ protected void publish(Iterator metrics) { verifyDistribtionMetricValues(published, 2, 4); } finally { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } } diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/collect/MessagingMetricsCollectionServiceTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/collect/MessagingMetricsCollectionServiceTest.java index 36322dd160d5..52abf3070fb5 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/collect/MessagingMetricsCollectionServiceTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/collect/MessagingMetricsCollectionServiceTest.java @@ -62,14 +62,14 @@ public void testMessagingPublish() throws TopicNotFoundException { MetricsCollectionService collectionService = new MessagingMetricsCollectionService(CConfiguration.create(), messagingService, recordWriter); - collectionService.startAndWait(); + collectionService.startAsync().awaitRunning(); // publish metrics for different context for (int i = 1; i <= 3; i++) { collectionService.getContext(ImmutableMap.of("tag", "" + i)).increment("processed", i); } - collectionService.stopAndWait(); + collectionService.stopAsync().awaitTerminated(); // Table expected = HashBasedTable.create(); diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/process/MessagingMetricsProcessorManagerServiceTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/process/MessagingMetricsProcessorManagerServiceTest.java index 99951102a14a..b47886b50c5a 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/process/MessagingMetricsProcessorManagerServiceTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/process/MessagingMetricsProcessorManagerServiceTest.java @@ -68,10 +68,10 @@ public class MessagingMetricsProcessorManagerServiceTest extends MetricsProcesso @Test public void persistMetricsTests() throws Exception { - injector.getInstance(TransactionManager.class).startAndWait(); + injector.getInstance(TransactionManager.class).startAsync().awaitRunning(); StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); - injector.getInstance(DatasetOpExecutorService.class).startAndWait(); - injector.getInstance(DatasetService.class).startAndWait(); + injector.getInstance(DatasetOpExecutorService.class).startAsync().awaitRunning(); + injector.getInstance(DatasetService.class).startAsync().awaitRunning(); Set partitions = IntStream.range(0, cConf.getInt(Constants.Metrics.MESSAGING_TOPIC_NUM)) .boxed().collect(Collectors.toSet()); @@ -106,7 +106,7 @@ public void persistMetricsTests() throws Exception { injector.getInstance(DatumReaderFactory.class), metricStore, injector.getInstance(MetricsWriterProvider.class), partitions, new NoopMetricsContext(), 50, 0); - messagingMetricsProcessorManagerService.startAndWait(); + messagingMetricsProcessorManagerService.startAsync().awaitRunning(); // Wait for the 1 aggregated counter metric (with value 50) and 50 gauge metrics to be stored in the metricStore Tasks.waitFor(51, () -> metricStore.getAllCounterAndGaugeMetrics().size(), 15, @@ -139,7 +139,7 @@ public void persistMetricsTests() throws Exception { metricStore.deleteAll(); expected.clear(); // Stop messagingMetricsProcessorManagerService - messagingMetricsProcessorManagerService.stopAndWait(); + messagingMetricsProcessorManagerService.stopAsync().awaitTerminated(); } } diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/process/MetricsAdminSubscriberServiceTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/process/MetricsAdminSubscriberServiceTest.java index d699e4d73475..0c9a9a5c1d09 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/process/MetricsAdminSubscriberServiceTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/process/MetricsAdminSubscriberServiceTest.java @@ -116,25 +116,25 @@ protected void configure() { metricsQueryService = injector.getInstance(MetricsQueryService.class); if (messagingService instanceof Service) { - ((Service) messagingService).startAndWait(); + ((Service) messagingService).startAsync().awaitRunning(); } - metricsCollectionService.startAndWait(); - metricsQueryService.startAndWait(); + metricsCollectionService.startAsync().awaitRunning(); + metricsQueryService.startAsync().awaitRunning(); } @AfterClass public static void finish() { - metricsQueryService.stopAndWait(); - metricsCollectionService.stopAndWait(); + metricsQueryService.stopAsync().awaitTerminated(); + metricsCollectionService.stopAsync().awaitTerminated(); if (messagingService instanceof Service) { - ((Service) messagingService).stopAndWait(); + ((Service) messagingService).stopAsync().awaitTerminated(); } } @Test public void test() throws Exception { MetricsAdminSubscriberService adminService = injector.getInstance(MetricsAdminSubscriberService.class); - adminService.startAndWait(); + adminService.startAsync().awaitRunning(); // publish a metrics MetricsContext metricsContext = metricsCollectionService.getContext( @@ -222,6 +222,6 @@ public void test() throws Exception { return !foundInc && !foundGauge; }, 1000, TimeUnit.SECONDS, 1, TimeUnit.SECONDS); - adminService.stopAndWait(); + adminService.stopAsync().awaitTerminated(); } } diff --git a/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/process/MetricsProcessorServiceTest.java b/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/process/MetricsProcessorServiceTest.java index 6168b40cd6ed..4f5c657783ed 100644 --- a/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/process/MetricsProcessorServiceTest.java +++ b/cdap-watchdog/src/test/java/io/cdap/cdap/metrics/process/MetricsProcessorServiceTest.java @@ -59,10 +59,10 @@ public class MetricsProcessorServiceTest extends MetricsProcessorServiceTestBase @Test public void testMetricsProcessor() throws Exception { - injector.getInstance(TransactionManager.class).startAndWait(); + injector.getInstance(TransactionManager.class).startAsync().awaitRunning(); StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); - injector.getInstance(DatasetOpExecutorService.class).startAndWait(); - injector.getInstance(DatasetService.class).startAndWait(); + injector.getInstance(DatasetOpExecutorService.class).startAsync().awaitRunning(); + injector.getInstance(DatasetService.class).startAsync().awaitRunning(); final MetricStore metricStore = injector.getInstance(MetricStore.class); @@ -81,7 +81,7 @@ public void testMetricsProcessor() throws Exception { injector.getInstance(DatumReaderFactory.class), metricStore, injector.getInstance(MetricsWriterProvider.class), partitions, new NoopMetricsContext(), 50, 0); - messagingMetricsProcessorManagerService.startAndWait(); + messagingMetricsProcessorManagerService.startAsync().awaitRunning(); long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()); // Publish metrics with messaging service and record expected metrics @@ -91,7 +91,7 @@ public void testMetricsProcessor() throws Exception { Thread.sleep(500); // Stop and restart messagingMetricsProcessorManagerService - messagingMetricsProcessorManagerService.stopAndWait(); + messagingMetricsProcessorManagerService.stopAsync().awaitTerminated(); // Intentionally set queue size to a large value, so that MessagingMetricsProcessorManagerService // internally only persists metrics during terminating. messagingMetricsProcessorManagerService = @@ -100,7 +100,7 @@ public void testMetricsProcessor() throws Exception { injector.getInstance(DatumReaderFactory.class), metricStore, injector.getInstance(MetricsWriterProvider.class), partitions, new NoopMetricsContext(), 50, 0); - messagingMetricsProcessorManagerService.startAndWait(); + messagingMetricsProcessorManagerService.startAsync().awaitRunning(); // Publish metrics after MessagingMetricsProcessorManagerService restarts and record expected metrics for (int i = 20; i < 30; i++) { @@ -138,7 +138,7 @@ public Boolean call() throws Exception { } // Stop services and servers - messagingMetricsProcessorManagerService.stopAndWait(); + messagingMetricsProcessorManagerService.stopAsync().awaitTerminated(); // Delete all metrics metricStore.deleteAll(); } From c8786b99da9024d50d99cac4cd6e354829cf08c2 Mon Sep 17 00:00:00 2001 From: abhishkkumar Date: Tue, 5 May 2026 05:26:32 +0000 Subject: [PATCH 4/7] fix the router pod fixes haddop fixes fixes --- cdap-common/pom.xml | 1 - .../io/cdap/cdap/common/service/Services.java | 50 +++++++++++++++++ .../cdap/cdap/gateway/router/NettyRouter.java | 10 ++-- .../cdap/cdap/gateway/router/RouterMain.java | 11 ++-- .../io/cdap/cdap/gateway/GatewayTestBase.java | 54 ++++++++++--------- .../handlers/log/LogHttpHandlerTest.java | 20 +++---- .../metrics/MetricsSuiteTestBase.java | 21 ++++---- .../cdap/gateway/router/AuditLogTest.java | 5 +- .../router/AuthServerAnnounceTest.java | 5 +- .../ConfigBasedRequestBlockingTest.java | 4 +- .../gateway/router/NettyRouterHttpTest.java | 5 +- .../gateway/router/NettyRouterHttpsTest.java | 4 +- .../router/NettyRouterPipelineTest.java | 4 +- .../gateway/router/NettyRouterTestBase.java | 35 ++++++------ .../cdap/gateway/router/RouterResource.java | 4 +- .../gateway/router/RoutingToDataSetsTest.java | 9 ++-- .../cdap/gateway/router/ServerResource.java | 3 +- cdap-security/pom.xml | 2 - .../security/auth/AbstractKeyManager.java | 3 +- .../cdap/cdap/security/auth/AccessToken.java | 3 +- .../security/auth/AccessTokenValidator.java | 4 +- .../security/auth/DistributedKeyManager.java | 7 ++- .../cdap/security/auth/KeyIdentifier.java | 8 +-- .../cdap/cdap/security/auth/TokenManager.java | 7 ++- .../cdap/cdap/security/auth/UserIdentity.java | 3 +- .../context/AuthenticationContextModules.java | 3 +- .../context/MasterAuthenticationContext.java | 3 +- .../context/SystemAuthenticationContext.java | 3 +- .../AccessControllerInstantiator.java | 10 ++-- .../authorization/AuthorizerWrapper.java | 6 ++- .../impersonation/ImpersonationUtils.java | 15 +++++- .../runtime/AuthenticationServerMain.java | 2 +- .../server/ExternalAuthenticationServer.java | 5 +- .../security/server/GrantAccessToken.java | 5 +- .../server/LdapAuthenticationHandler.java | 5 +- .../cdap/security/server/LdapLoginModule.java | 3 +- .../store/DefaultSecureStoreService.java | 4 +- .../tools/AccessTokenGeneratorService.java | 2 +- .../zookeeper/SharedResourceCache.java | 39 +++++++++----- .../auth/DistributedKeyManagerTest.java | 14 ++--- .../auth/FileBasedTokenManagerTest.java | 10 ++-- .../auth/TestInMemoryTokenManager.java | 1 - .../cdap/security/auth/TestTokenManager.java | 8 +-- .../ExternalAuthenticationServerTestBase.java | 5 +- .../SecretManagerSecureStoreServiceTest.java | 4 +- .../zookeeper/SharedResourceCacheTest.java | 9 ++-- pom.xml | 1 + 47 files changed, 263 insertions(+), 176 deletions(-) diff --git a/cdap-common/pom.xml b/cdap-common/pom.xml index cc81058e854b..22892e382584 100644 --- a/cdap-common/pom.xml +++ b/cdap-common/pom.xml @@ -261,7 +261,6 @@ org.apache.maven.plugins maven-jar-plugin - 2.4 test-jar diff --git a/cdap-common/src/main/java/io/cdap/cdap/common/service/Services.java b/cdap-common/src/main/java/io/cdap/cdap/common/service/Services.java index 74d619454692..2a5510d6d110 100644 --- a/cdap-common/src/main/java/io/cdap/cdap/common/service/Services.java +++ b/cdap-common/src/main/java/io/cdap/cdap/common/service/Services.java @@ -85,4 +85,54 @@ public static void startAndWait(Service service, long timeout, TimeUnit timeoutU throws TimeoutException, InterruptedException, ExecutionException { startAndWait(service, timeout, timeoutUnit, null); } + + /** + * Starts a service and waits for it to be running, using reflection + * to be compatible with both Guava 13 and Guava 15+ / 20+. + */ + public static void startAndWait(Service service) { + try { + try { + // Guava 15+ + service.getClass().getMethod("startAsync").invoke(service); + service.getClass().getMethod("awaitRunning").invoke(service); + } catch (NoSuchMethodException e) { + // Guava 13 + Object future = service.getClass().getMethod("start").invoke(service); + if (future instanceof ListenableFuture) { + ((ListenableFuture) future).get(); + } + } + } catch (Exception e) { + if (e.getCause() instanceof RuntimeException) { + throw (RuntimeException) e.getCause(); + } + throw new RuntimeException(e.getCause() != null ? e.getCause() : e); + } + } + + /** + * Stops a service and waits for it to be terminated, using reflection + * to be compatible with both Guava 13 and Guava 15+ / 20+. + */ + public static void stopAndWait(Service service) { + try { + try { + // Guava 15+ + service.getClass().getMethod("stopAsync").invoke(service); + service.getClass().getMethod("awaitTerminated").invoke(service); + } catch (NoSuchMethodException e) { + // Guava 13 + Object future = service.getClass().getMethod("stop").invoke(service); + if (future instanceof ListenableFuture) { + ((ListenableFuture) future).get(); + } + } + } catch (Exception e) { + if (e.getCause() instanceof RuntimeException) { + throw (RuntimeException) e.getCause(); + } + throw new RuntimeException(e.getCause() != null ? e.getCause() : e); + } + } } diff --git a/cdap-gateway/src/main/java/io/cdap/cdap/gateway/router/NettyRouter.java b/cdap-gateway/src/main/java/io/cdap/cdap/gateway/router/NettyRouter.java index 022874607582..62e0956a1cb3 100644 --- a/cdap-gateway/src/main/java/io/cdap/cdap/gateway/router/NettyRouter.java +++ b/cdap-gateway/src/main/java/io/cdap/cdap/gateway/router/NettyRouter.java @@ -16,8 +16,8 @@ package io.cdap.cdap.gateway.router; -import com.google.common.base.Strings; import com.google.common.base.Throwables; +import com.google.common.base.Strings; import com.google.common.util.concurrent.AbstractIdleService; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.inject.Inject; @@ -30,6 +30,7 @@ import io.cdap.cdap.common.encryption.guice.UserCredentialAeadEncryptionModule; import io.cdap.cdap.common.security.HttpsEnabler; import io.cdap.cdap.common.security.KeyStores; +import io.cdap.cdap.common.service.Services; import io.cdap.cdap.gateway.router.handlers.AuditLogHandler; import io.cdap.cdap.gateway.router.handlers.AuthenticationHandler; import io.cdap.cdap.gateway.router.handlers.ConfigBasedRequestBlockingHandler; @@ -141,7 +142,7 @@ public Optional getBoundAddress() { protected void startUp() throws Exception { // If internal authorization enforcement is enabled, we avoid re-initialization of the token manager. if (SecurityUtil.isManagedSecurity(cConf) && !SecurityUtil.isInternalAuthEnabled(cConf)) { - tokenValidator.startAndWait(); + Services.startAndWait(tokenValidator); } ChannelGroup channelGroup = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE); serverCancellable = startServer(createServerBootstrap(channelGroup), channelGroup); @@ -157,14 +158,13 @@ protected void shutDown() { serverCancellable.cancel(); // If internal authorization enforcement is enabled, we avoid duplicate cleanup of the token manager. if (SecurityUtil.isManagedSecurity(cConf) && !SecurityUtil.isInternalAuthEnabled(cConf)) { - tokenValidator.stopAndWait(); + Services.stopAndWait(tokenValidator); } LOG.info("Stopped Netty Router."); } - @Override - protected Executor executor(final State state) { + protected Executor executor() { final AtomicInteger id = new AtomicInteger(); return runnable -> { Thread t = new Thread(runnable, String.format("NettyRouter-%d", id.incrementAndGet())); diff --git a/cdap-gateway/src/main/java/io/cdap/cdap/gateway/router/RouterMain.java b/cdap-gateway/src/main/java/io/cdap/cdap/gateway/router/RouterMain.java index 970a6135fbd8..3de1f0e45185 100644 --- a/cdap-gateway/src/main/java/io/cdap/cdap/gateway/router/RouterMain.java +++ b/cdap-gateway/src/main/java/io/cdap/cdap/gateway/router/RouterMain.java @@ -30,11 +30,11 @@ import io.cdap.cdap.common.guice.ZkClientModule; import io.cdap.cdap.common.guice.ZkDiscoveryModule; import io.cdap.cdap.common.runtime.DaemonMain; +import io.cdap.cdap.common.service.Services; import io.cdap.cdap.security.guice.CoreSecurityRuntimeModule; import io.cdap.cdap.security.guice.ExternalAuthenticationModule; import io.cdap.cdap.security.impersonation.SecurityUtil; import java.util.concurrent.TimeUnit; -import org.apache.twill.internal.Services; import org.apache.twill.zookeeper.ZKClientService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,14 +101,15 @@ public void init(String[] args) { LOG.info("Router initialized."); } catch (Throwable t) { LOG.error(t.getMessage(), t); - throw Throwables.propagate(t); + Throwables.propagateIfPossible(t); + throw new RuntimeException(t); } } @Override public void start() throws Exception { LOG.info("Starting Router..."); - io.cdap.cdap.common.service.Services.startAndWait(zkClientService, + Services.startAndWait(zkClientService, cConf.getLong(Constants.Zookeeper.CLIENT_STARTUP_TIMEOUT_MILLIS), TimeUnit.MILLISECONDS, String.format("Connection timed out while trying to start " @@ -116,14 +117,14 @@ public void start() throws Exception { + "ZooKeeper quorum settings are correct in " + "cdap-site.xml. Currently configured as: %s", zkClientService.getConnectString())); - router.startAndWait(); + Services.startAndWait(router); LOG.info("Router started."); } @Override public void stop() { LOG.info("Stopping Router..."); - Futures.getUnchecked(Services.chainStop(router, zkClientService)); + Futures.getUnchecked(org.apache.twill.internal.Services.chainStop(router, zkClientService)); LOG.info("Router stopped."); } diff --git a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/GatewayTestBase.java b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/GatewayTestBase.java index b23aaca4a0ea..1639509a0e0b 100644 --- a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/GatewayTestBase.java +++ b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/GatewayTestBase.java @@ -16,7 +16,6 @@ package io.cdap.cdap.gateway; -import com.google.common.io.Closeables; import com.google.common.util.concurrent.Service; import com.google.gson.Gson; import com.google.gson.JsonObject; @@ -32,6 +31,7 @@ import io.cdap.cdap.common.conf.CConfiguration; import io.cdap.cdap.common.conf.Constants; import io.cdap.cdap.common.namespace.NamespaceAdmin; +import io.cdap.cdap.common.service.Services; import io.cdap.cdap.common.utils.Networks; import io.cdap.cdap.common.utils.Tasks; import io.cdap.cdap.data2.datafabric.dataset.service.DatasetService; @@ -179,38 +179,38 @@ protected void configure() { messagingService = injector.getInstance(MessagingService.class); if (messagingService instanceof Service) { - ((Service) messagingService).startAndWait(); + Services.startAndWait((Service) messagingService); } txService = injector.getInstance(TransactionManager.class); - txService.startAndWait(); + Services.startAndWait(txService); // Define all StructuredTable before starting any services that need StructuredTable StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); metadataStorage = injector.getInstance(MetadataStorage.class); metadataStorage.createIndex(); metadataService = injector.getInstance(MetadataService.class); - metadataService.startAndWait(); + Services.startAndWait(metadataService); dsOpService = injector.getInstance(DatasetOpExecutorService.class); - dsOpService.startAndWait(); + Services.startAndWait(dsOpService); datasetService = injector.getInstance(DatasetService.class); - datasetService.startAndWait(); + Services.startAndWait(datasetService); appFabricServer = injector.getInstance(AppFabricServer.class); - appFabricServer.startAndWait(); + Services.startAndWait(appFabricServer); appFabricProcessorService = injector.getInstance(AppFabricProcessorService.class); - appFabricProcessorService.startAndWait(); + Services.startAndWait(appFabricProcessorService); logQueryService = injector.getInstance(LogQueryService.class); - logQueryService.startAndWait(); + Services.startAndWait(logQueryService); metricsQueryService = injector.getInstance(MetricsQueryService.class); - metricsQueryService.startAndWait(); + Services.startAndWait(metricsQueryService); metricsCollectionService = injector.getInstance(MetricsCollectionService.class); - metricsCollectionService.startAndWait(); + Services.startAndWait(metricsCollectionService); namespaceAdmin = injector.getInstance(NamespaceAdmin.class); namespaceAdmin.create(TEST_NAMESPACE_META1); namespaceAdmin.create(TEST_NAMESPACE_META2); // Restart handlers to check if they are resilient across restarts. router = injector.getInstance(NettyRouter.class); - router.startAndWait(); + Services.startAndWait(router); port = router.getBoundAddress().orElseThrow(IllegalStateException::new).getPort(); return injector; @@ -220,19 +220,25 @@ public static void stopGateway(CConfiguration conf) throws Exception { namespaceAdmin.delete(new NamespaceId(TEST_NAMESPACE1)); namespaceAdmin.delete(new NamespaceId(TEST_NAMESPACE2)); namespaceAdmin.delete(NamespaceId.DEFAULT); - appFabricServer.stopAndWait(); - appFabricProcessorService.stopAndWait(); - metricsCollectionService.stopAndWait(); - metricsQueryService.stopAndWait(); - logQueryService.stopAndWait(); - router.stopAndWait(); - datasetService.stopAndWait(); - dsOpService.stopAndWait(); - metadataService.stopAndWait(); - Closeables.closeQuietly(metadataStorage); - txService.stopAndWait(); + Services.stopAndWait(appFabricServer); + Services.stopAndWait(appFabricProcessorService); + Services.stopAndWait(metricsCollectionService); + Services.stopAndWait(metricsQueryService); + Services.stopAndWait(logQueryService); + Services.stopAndWait(router); + Services.stopAndWait(datasetService); + Services.stopAndWait(dsOpService); + Services.stopAndWait(metadataService); + try { + + metadataStorage.close(); + + } catch (Exception ignored) { + + } + Services.stopAndWait(txService); if (messagingService instanceof Service) { - ((Service) messagingService).stopAndWait(); + Services.stopAndWait((Service) messagingService); } conf.clear(); } diff --git a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/handlers/log/LogHttpHandlerTest.java b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/handlers/log/LogHttpHandlerTest.java index 0f9300c579c4..c8bc1a68486e 100644 --- a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/handlers/log/LogHttpHandlerTest.java +++ b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/handlers/log/LogHttpHandlerTest.java @@ -43,6 +43,7 @@ import io.cdap.cdap.common.guice.RemoteAuthenticatorModules; import io.cdap.cdap.common.http.DefaultHttpRequestConfig; import io.cdap.cdap.common.metrics.NoOpMetricsCollectionService; +import io.cdap.cdap.common.service.Services; import io.cdap.cdap.data.runtime.DataFabricModules; import io.cdap.cdap.data.runtime.DataSetServiceModules; import io.cdap.cdap.data.runtime.DataSetsModules; @@ -149,18 +150,18 @@ protected void configure() { })); transactionManager = injector.getInstance(TransactionManager.class); - transactionManager.startAndWait(); + Services.startAndWait(transactionManager); StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); dsOpService = injector.getInstance(DatasetOpExecutorService.class); - dsOpService.startAndWait(); + Services.startAndWait(dsOpService); datasetService = injector.getInstance(DatasetService.class); - datasetService.startAndWait(); + Services.startAndWait(datasetService); logQueryService = injector.getInstance(LogQueryService.class); - logQueryService.startAndWait(); + Services.startAndWait(logQueryService); - mockLogReader = (MockLogReader) injector.getInstance(LogReader.class); + mockLogReader = (MockLogReader) injector.getInstance(LogReader.class); mockLogReader.generateLogs(); discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class); @@ -168,11 +169,10 @@ protected void configure() { @AfterClass public static void tearDown() { - logQueryService.stopAndWait(); - - datasetService.stopAndWait(); - dsOpService.stopAndWait(); - transactionManager.stopAndWait(); + Services.stopAndWait(logQueryService); + Services.stopAndWait(datasetService); + Services.stopAndWait(dsOpService); + Services.stopAndWait(transactionManager); } @Test diff --git a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/handlers/metrics/MetricsSuiteTestBase.java b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/handlers/metrics/MetricsSuiteTestBase.java index 58375282b8b3..4dd97a11c12d 100644 --- a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/handlers/metrics/MetricsSuiteTestBase.java +++ b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/handlers/metrics/MetricsSuiteTestBase.java @@ -24,6 +24,7 @@ import com.google.inject.util.Modules; import io.cdap.cdap.api.metrics.MetricStore; import io.cdap.cdap.api.metrics.MetricsCollectionService; +import io.cdap.cdap.common.service.Services; import io.cdap.cdap.app.metrics.MapReduceMetrics; import io.cdap.cdap.app.store.Store; import io.cdap.cdap.common.conf.CConfiguration; @@ -174,20 +175,20 @@ protected void configure() { })); transactionManager = injector.getInstance(TransactionManager.class); - transactionManager.startAndWait(); + Services.startAndWait(transactionManager); StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); dsOpService = injector.getInstance(DatasetOpExecutorService.class); - dsOpService.startAndWait(); + Services.startAndWait(dsOpService); datasetService = injector.getInstance(DatasetService.class); - datasetService.startAndWait(); + Services.startAndWait(datasetService); metrics = injector.getInstance(MetricsQueryService.class); - metrics.startAndWait(); + Services.startAndWait(metrics); collectionService = injector.getInstance(MetricsCollectionService.class); - collectionService.startAndWait(); + Services.startAndWait(collectionService); // initialize the dataset instantiator DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class); @@ -202,11 +203,11 @@ protected void configure() { } public static void stopMetricsService(CConfiguration conf) { - collectionService.stopAndWait(); - datasetService.stopAndWait(); - dsOpService.stopAndWait(); - transactionManager.stopAndWait(); - metrics.stopAndWait(); + Services.stopAndWait(collectionService); + Services.stopAndWait(datasetService); + Services.stopAndWait(dsOpService); + Services.stopAndWait(transactionManager); + Services.stopAndWait(metrics); conf.clear(); } diff --git a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/AuditLogTest.java b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/AuditLogTest.java index 30db4cab8093..9e32cc68c442 100644 --- a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/AuditLogTest.java +++ b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/AuditLogTest.java @@ -31,6 +31,7 @@ import io.cdap.cdap.common.encryption.NoOpAeadCipher; import io.cdap.cdap.common.security.AuditDetail; import io.cdap.cdap.common.security.AuditPolicy; +import io.cdap.cdap.common.service.Services; import io.cdap.cdap.security.auth.TokenValidator; import io.cdap.http.AbstractHttpHandler; import io.cdap.http.HttpResponder; @@ -103,7 +104,7 @@ public static void init() throws Exception { successValidator, new MockAccessTokenIdentityExtractor(successValidator), discoveryService, new NoOpAeadCipher()); - router.startAndWait(); + Services.startAndWait(router); httpService = NettyHttpService.builder("test").setHttpHandlers(new TestHandler()).build(); httpService.start(); @@ -119,7 +120,7 @@ public static void init() throws Exception { public static void finish() throws Exception { cancelDiscovery.cancel(); httpService.stop(); - router.stopAndWait(); + Services.stopAndWait(router); } @Test diff --git a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/AuthServerAnnounceTest.java b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/AuthServerAnnounceTest.java index 2bffff417718..1b74a9304997 100644 --- a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/AuthServerAnnounceTest.java +++ b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/AuthServerAnnounceTest.java @@ -27,6 +27,7 @@ import io.cdap.cdap.common.conf.SConfiguration; import io.cdap.cdap.common.encryption.NoOpAeadCipher; import io.cdap.cdap.common.guice.InMemoryDiscoveryModule; +import io.cdap.cdap.common.service.Services; import io.cdap.cdap.internal.guava.reflect.TypeToken; import io.cdap.cdap.internal.guice.AppFabricTestModule; import io.cdap.cdap.security.auth.AuthenticationMode; @@ -145,12 +146,12 @@ protected void startUp() { new RouterServiceLookup(cConf, (DiscoveryServiceClient) discoveryService, new RouterPathLookup()), validator, userIdentityExtractor, discoveryServiceClient, new NoOpAeadCipher()); - router.startAndWait(); + Services.startAndWait(router); } @Override protected void shutDown() { - router.stopAndWait(); + Services.stopAndWait(router); } InetSocketAddress getRouterAddress() { diff --git a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/ConfigBasedRequestBlockingTest.java b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/ConfigBasedRequestBlockingTest.java index 48ff938ef4bf..066053deac35 100644 --- a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/ConfigBasedRequestBlockingTest.java +++ b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/ConfigBasedRequestBlockingTest.java @@ -68,7 +68,7 @@ public static void init() throws Exception { successValidator, new MockAccessTokenIdentityExtractor(successValidator), discoveryService, new NoOpAeadCipher()); - router.startAndWait(); + io.cdap.cdap.common.service.Services.startAndWait(router); httpService = NettyHttpService.builder("test").setHttpHandlers(new AuditLogTest.TestHandler()) .build(); @@ -121,7 +121,7 @@ public void testRouterStatus() throws Exception { public static void finish() throws Exception { cancelDiscovery.cancel(); httpService.stop(); - router.stopAndWait(); + io.cdap.cdap.common.service.Services.stopAndWait(router); } private void testGet(int expectedStatus, String expectedResponse, String path) diff --git a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterHttpTest.java b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterHttpTest.java index 3169cc9caa25..b635f12d86c9 100644 --- a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterHttpTest.java +++ b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterHttpTest.java @@ -27,6 +27,7 @@ import io.cdap.cdap.common.conf.SConfiguration; import io.cdap.cdap.common.encryption.NoOpAeadCipher; import io.cdap.cdap.common.guice.InMemoryDiscoveryModule; +import io.cdap.cdap.common.service.Services; import io.cdap.cdap.internal.guice.AppFabricTestModule; import io.cdap.cdap.security.auth.UserIdentityExtractor; import io.cdap.cdap.security.guice.CoreSecurityRuntimeModule; @@ -107,12 +108,12 @@ protected void startUp() { new RouterPathLookup()), new SuccessTokenValidator(), userIdentityExtractor, discoveryServiceClient, new NoOpAeadCipher()); - router.startAndWait(); + Services.startAndWait(router); } @Override protected void shutDown() { - router.stopAndWait(); + Services.stopAndWait(router); } public InetSocketAddress getRouterAddress() { diff --git a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterHttpsTest.java b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterHttpsTest.java index e112b344a1a7..aefd9c98489f 100644 --- a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterHttpsTest.java +++ b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterHttpsTest.java @@ -201,12 +201,12 @@ protected void startUp() { new RouterPathLookup()), new SuccessTokenValidator(), userIdentityExtractor, discoveryServiceClient, new NoOpAeadCipher()); - router.startAndWait(); + io.cdap.cdap.common.service.Services.startAndWait(router); } @Override protected void shutDown() { - router.stopAndWait(); + io.cdap.cdap.common.service.Services.stopAndWait(router); } public InetSocketAddress getRouterAddress() { diff --git a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterPipelineTest.java b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterPipelineTest.java index 422557635380..6a27c99c7dfb 100644 --- a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterPipelineTest.java +++ b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterPipelineTest.java @@ -209,7 +209,7 @@ private void deploy(int num) throws Exception { LocationFactory lf = new LocalLocationFactory(TMP_FOLDER.newFolder()); Location programJar = AppJarHelper.createDeploymentJar(lf, DummyApp.class); - GATEWAY_SERVER.setExpectedJarBytes(ByteStreams.toByteArray(Locations.newInputSupplier(programJar))); + GATEWAY_SERVER.setExpectedJarBytes(ByteStreams.toByteArray(Locations.newInputSupplier(programJar).getInput())); for (int i = 0; i < num; i++) { LOG.info("Deploying {}/{}", i, num); @@ -220,7 +220,7 @@ private void deploy(int num) throws Exception { urlConn.setDoOutput(true); urlConn.setDoInput(true); - ByteStreams.copy(Locations.newInputSupplier(programJar), urlConn.getOutputStream()); + ByteStreams.copy(Locations.newInputSupplier(programJar).getInput(), urlConn.getOutputStream()); Assert.assertEquals(200, urlConn.getResponseCode()); urlConn.getInputStream().close(); urlConn.disconnect(); diff --git a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterTestBase.java b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterTestBase.java index 06ec876f3b8e..056023408884 100644 --- a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterTestBase.java +++ b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/NettyRouterTestBase.java @@ -21,9 +21,6 @@ import com.google.common.collect.Lists; import com.google.common.io.ByteStreams; import com.google.common.util.concurrent.AbstractIdleService; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.Service; import com.ning.http.client.AsyncCompletionHandler; import com.ning.http.client.AsyncHttpClient; import com.ning.http.client.AsyncHttpClientConfig; @@ -38,6 +35,7 @@ import io.cdap.cdap.common.discovery.ResolvingDiscoverable; import io.cdap.cdap.common.encryption.NoOpAeadCipher; import io.cdap.cdap.common.http.AbstractBodyConsumer; +import io.cdap.cdap.common.service.Services; import io.cdap.cdap.security.auth.TokenValidator; import io.cdap.http.AbstractHttpHandler; import io.cdap.http.BodyConsumer; @@ -69,7 +67,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; @@ -148,13 +145,10 @@ private String resolveUri(String path) throws URISyntaxException { @Before public void startUp() throws Exception { routerService = createRouterService(HOSTNAME, discoveryService); - List> futures = new ArrayList<>(); - futures.add(routerService.start()); + Services.startAndWait(routerService); for (ServerService server : allServers) { - futures.add(server.start()); + Services.startAndWait(server); } - Futures.allAsList(futures).get(); - // Wait for both servers of defaultService to be registered ServiceDiscovered discover = ((DiscoveryServiceClient) discoveryService) .discover(APP_FABRIC_SERVICE); @@ -173,12 +167,10 @@ public void onChange(ServiceDiscovered serviceDiscovered) { @After public void tearDown() throws Exception { - List> futures = new ArrayList<>(); for (ServerService server : allServers) { - futures.add(server.stop()); + Services.stopAndWait(server); } - futures.add(routerService.stop()); - Futures.successfulAsList(futures).get(); + Services.stopAndWait(routerService); } @Test @@ -531,7 +523,7 @@ public void testConnectionClose2() throws Exception { }); t.start(); - defaultServer1.stopAndWait(); + Services.stopAndWait(defaultServer1); Assert.assertEquals(200, result.get().intValue()); Assert.assertEquals(1, defaultServer1.getNumRequests()); Assert.assertEquals(1, defaultServer2.getNumRequests()); @@ -561,9 +553,10 @@ public void testConfigReloading() throws Exception { successValidator, new MockAccessTokenIdentityExtractor(successValidator), discoveryService, new NoOpAeadCipher()); - router1.startAndWait(); + Services.startAndWait(router1); + - // Configure router with config-reloading time set to 0 + // Configure router with config-reloading time set to 0 CConfiguration cConfSpy2 = Mockito.spy(CConfiguration.create()); cConfSpy2.setLong(Constants.Router.CCONF_RELOAD_INTERVAL_SECONDS, 0); cConfSpy2.setInt(Constants.Router.ROUTER_PORT, 0); @@ -573,15 +566,17 @@ public void testConfigReloading() throws Exception { successValidator, new MockAccessTokenIdentityExtractor(successValidator), discoveryService, new NoOpAeadCipher()); - router2.startAndWait(); + Services.startAndWait(router2); - // Wait sometime for cConf to reload + + // Wait sometime for cConf to reload Thread.sleep(TimeUnit.MILLISECONDS.convert(reloadIntervalSeconds + 2, TimeUnit.SECONDS)); Mockito.verify(cConfSpy1, Mockito.times(1)).reloadConfiguration(); Mockito.verify(cConfSpy2, Mockito.never()).reloadConfiguration(); - router1.stopAndWait(); - router2.stopAndWait(); + Services.stopAndWait(router1); + Services.stopAndWait(router2); + } protected HttpURLConnection openUrl(URL url) throws Exception { diff --git a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/RouterResource.java b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/RouterResource.java index cca9d8d4bfc7..867e38748b75 100644 --- a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/RouterResource.java +++ b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/RouterResource.java @@ -77,12 +77,12 @@ protected void before() { new RouterServiceLookup(cConf, (DiscoveryServiceClient) discoveryService, new RouterPathLookup()), mockValidator, extractor, discoveryServiceClient, new NoOpAeadCipher()); - router.startAndWait(); + io.cdap.cdap.common.service.Services.startAndWait(router); } @Override protected void after() { - router.stopAndWait(); + io.cdap.cdap.common.service.Services.stopAndWait(router); } InetSocketAddress getRouterAddress() { diff --git a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/RoutingToDataSetsTest.java b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/RoutingToDataSetsTest.java index b565b5ce1067..d4b9dee004c7 100644 --- a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/RoutingToDataSetsTest.java +++ b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/RoutingToDataSetsTest.java @@ -26,6 +26,7 @@ import io.cdap.cdap.common.conf.SConfiguration; import io.cdap.cdap.common.encryption.NoOpAeadCipher; import io.cdap.cdap.common.guice.InMemoryDiscoveryModule; +import io.cdap.cdap.common.service.Services; import io.cdap.cdap.common.utils.Networks; import io.cdap.cdap.internal.guice.AppFabricTestModule; import io.cdap.cdap.security.auth.UserIdentityExtractor; @@ -84,21 +85,21 @@ public static void before() throws Exception { new RouterServiceLookup(cConf, discoveryServiceClient, new RouterPathLookup()), new SuccessTokenValidator(), userIdentityExtractor, discoveryServiceClient, new NoOpAeadCipher()); - nettyRouter.startAndWait(); + Services.startAndWait(nettyRouter); // Starting mock DataSet service DiscoveryService discoveryService = injector.getInstance(DiscoveryService.class); mockService = new MockHttpService(discoveryService, Constants.Service.DATASET_MANAGER, new MockDatasetTypeHandler(), new MockDatasetInstanceHandler()); - mockService.startAndWait(); + Services.startAndWait(mockService); } @AfterClass public static void after() { try { - nettyRouter.stopAndWait(); + Services.stopAndWait(nettyRouter); } finally { - mockService.stopAndWait(); + Services.stopAndWait(mockService); } } diff --git a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/ServerResource.java b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/ServerResource.java index e67444d6ba7e..edee324dcb22 100644 --- a/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/ServerResource.java +++ b/cdap-gateway/src/test/java/io/cdap/cdap/gateway/router/ServerResource.java @@ -179,7 +179,8 @@ public void finished(HttpResponder responder) { @Override public void handleError(Throwable cause) { - throw Throwables.propagate(cause); + Throwables.propagateIfPossible(cause); + throw new RuntimeException(cause); } }; } diff --git a/cdap-security/pom.xml b/cdap-security/pom.xml index b534ac3ee133..94b69f1d4d4f 100644 --- a/cdap-security/pom.xml +++ b/cdap-security/pom.xml @@ -190,7 +190,6 @@ org.apache.maven.plugins maven-jar-plugin - 2.4 test-jar @@ -214,7 +213,6 @@ org.apache.maven.plugins maven-jar-plugin - 2.4 org.apache.maven.plugins diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/AbstractKeyManager.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/AbstractKeyManager.java index d440b0443066..63d80590a1b9 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/AbstractKeyManager.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/AbstractKeyManager.java @@ -18,7 +18,6 @@ import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import com.google.common.util.concurrent.AbstractIdleService; import io.cdap.cdap.api.common.Bytes; import io.cdap.cdap.common.conf.CConfiguration; @@ -157,7 +156,7 @@ public final void validateMAC(Codec codec, Signed signedMessage) throw new InvalidDigestException("Token signature is not valid!"); } } catch (IOException ioe) { - throw Throwables.propagate(ioe); + throw new RuntimeException(ioe); } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessToken.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessToken.java index 9d2941fc1479..a5d7c01852e4 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessToken.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessToken.java @@ -16,6 +16,7 @@ package io.cdap.cdap.security.auth; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.collect.Maps; import io.cdap.cdap.api.common.Bytes; @@ -124,7 +125,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("identifier", identifier) .add("keyId", keyId) .add("digest", Bytes.toStringBinary(digest)) diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessTokenValidator.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessTokenValidator.java index 25a4896eed36..d3dd34172c85 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessTokenValidator.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessTokenValidator.java @@ -42,13 +42,13 @@ public AccessTokenValidator(TokenManager tokenManager, Codec access @Override protected void startUp() throws Exception { LOG.info("Starting up AccessTokenValidator service"); - tokenManager.startAndWait(); + io.cdap.cdap.common.service.Services.startAndWait(tokenManager); } @Override protected void shutDown() throws Exception { LOG.info("Shutting down AccessTokenValidator service"); - tokenManager.stopAndWait(); + io.cdap.cdap.common.service.Services.stopAndWait(tokenManager); } @Override diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/DistributedKeyManager.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/DistributedKeyManager.java index 2b0493c7b196..e06b764b62d9 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/DistributedKeyManager.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/DistributedKeyManager.java @@ -16,7 +16,6 @@ package io.cdap.cdap.security.auth; -import com.google.common.base.Throwables; import com.google.inject.Inject; import io.cdap.cdap.common.conf.CConfiguration; import io.cdap.cdap.common.conf.Constants; @@ -96,7 +95,7 @@ protected void doInit() { try { keyCache.init(); } catch (InterruptedException ie) { - throw Throwables.propagate(ie); + throw new RuntimeException(ie); } this.leaderElection = new LeaderElection(zookeeper, "/leader", new ElectionHandler() { @Override @@ -114,7 +113,7 @@ public void follower() { LOG.debug("Transitioned to follower"); } }); - this.leaderElection.start(); + io.cdap.cdap.common.service.Services.startAndWait(this.leaderElection); startExpirationThread(); } @@ -123,7 +122,7 @@ public void shutDown() { if (timer != null) { timer.cancel(); } - leaderElection.stopAndWait(); + io.cdap.cdap.common.service.Services.stopAndWait(leaderElection); } @Override diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/KeyIdentifier.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/KeyIdentifier.java index 69f5d2a81bb5..6982df5bb8d0 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/KeyIdentifier.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/KeyIdentifier.java @@ -106,9 +106,9 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) - .add("keyId", keyId) - .add("expiration", expiration) - .toString(); + return "KeyIdentifier{" + + "keyId=" + keyId + + ", expiration=" + expiration + + "}"; } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/TokenManager.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/TokenManager.java index 3749baf1e6fb..1263da20cbd2 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/TokenManager.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/TokenManager.java @@ -16,7 +16,6 @@ package io.cdap.cdap.security.auth; -import com.google.common.base.Throwables; import com.google.common.util.concurrent.AbstractIdleService; import com.google.inject.Inject; import io.cdap.cdap.common.io.Codec; @@ -44,13 +43,13 @@ public TokenManager(KeyManager keyManager, Codec identifierCodec) @Override public void startUp() { LOG.info("Starting TokenManager service"); - this.keyManager.startAndWait(); + io.cdap.cdap.common.service.Services.startAndWait(this.keyManager); } @Override public void shutDown() { LOG.info("Shutting down TokenManager service."); - this.keyManager.stopAndWait(); + io.cdap.cdap.common.service.Services.stopAndWait(this.keyManager); } /** @@ -64,7 +63,7 @@ public AccessToken signIdentifier(UserIdentity identifier) { KeyManager.DigestId digest = keyManager.generateMAC(identifierCodec.encode(identifier)); return new AccessToken(identifier, digest.getId(), digest.getDigest()); } catch (IOException ioe) { - throw Throwables.propagate(ioe); + throw new RuntimeException(ioe); } catch (InvalidKeyException ike) { throw new IllegalStateException("Invalid key configured for KeyManager.", ike); } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/UserIdentity.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/UserIdentity.java index c1690d982a77..e8c39346a2f5 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/UserIdentity.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/UserIdentity.java @@ -16,6 +16,7 @@ package io.cdap.cdap.security.auth; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; @@ -162,7 +163,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("username", username) .add("tokenType", identifierType) .add("groups", groups) diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/AuthenticationContextModules.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/AuthenticationContextModules.java index c451542c0415..a2f652833911 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/AuthenticationContextModules.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/AuthenticationContextModules.java @@ -158,7 +158,8 @@ private String getUsername() { try { return UserGroupInformation.getCurrentUser().getShortUserName(); } catch (IOException e) { - throw Throwables.propagate(e); + Throwables.propagateIfPossible(e); + throw new RuntimeException(e); } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/MasterAuthenticationContext.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/MasterAuthenticationContext.java index 06657748e00d..f1effacea415 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/MasterAuthenticationContext.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/MasterAuthenticationContext.java @@ -51,7 +51,8 @@ public Principal getPrincipal() { try { userId = UserGroupInformation.getCurrentUser().getShortUserName(); } catch (IOException e) { - throw Throwables.propagate(e); + Throwables.propagateIfPossible(e); + throw new RuntimeException(e); } } return new Principal(userId, Principal.PrincipalType.USER, userCredential); diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/SystemAuthenticationContext.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/SystemAuthenticationContext.java index c3e19e4b647b..52130ce282da 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/SystemAuthenticationContext.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/SystemAuthenticationContext.java @@ -16,7 +16,6 @@ package io.cdap.cdap.security.auth.context; -import com.google.common.base.Throwables; import com.google.inject.Inject; import io.cdap.cdap.proto.security.Credential; import io.cdap.cdap.proto.security.Principal; @@ -80,7 +79,7 @@ public Principal getPrincipal() { try { userId = UserGroupInformation.getCurrentUser().getShortUserName(); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } long currentTimestamp = System.currentTimeMillis(); UserIdentity identity = new UserIdentity(userId, UserIdentity.IdentifierType.INTERNAL, diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AccessControllerInstantiator.java b/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AccessControllerInstantiator.java index 9b52be01fdde..ac930747fe8f 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AccessControllerInstantiator.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AccessControllerInstantiator.java @@ -20,7 +20,6 @@ import com.google.common.base.Strings; import com.google.common.base.Supplier; import com.google.common.base.Throwables; -import com.google.common.io.Closeables; import com.google.common.reflect.TypeToken; import com.google.inject.Inject; import io.cdap.cdap.common.conf.CConfiguration; @@ -158,7 +157,8 @@ public AccessControllerSpi get() { accessControllerClassLoader); return accessController; } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.propagateIfUnchecked(e); + throw new RuntimeException(e); } } } @@ -311,7 +311,11 @@ public void close() throws IOException { } catch (Throwable t) { LOG.warn("Failed to destroy accessController.", t); } finally { - Closeables.closeQuietly(accessControllerClassLoader); + try { + accessControllerClassLoader.close(); + } catch (Exception ignored) { + // Ignored because we are shutting down and cannot do anything if classloader fails to close. + } } } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AuthorizerWrapper.java b/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AuthorizerWrapper.java index c326dd6cf3e9..c72e09040fc5 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AuthorizerWrapper.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AuthorizerWrapper.java @@ -54,7 +54,8 @@ public void initialize(AuthorizationContext context) { try { authorizer.initialize(context); } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.propagateIfUnchecked(e); + throw new RuntimeException(e); } } @@ -117,7 +118,8 @@ public void destroy() { try { authorizer.destroy(); } catch (Exception e) { - throw Throwables.propagate(e); + Throwables.propagateIfUnchecked(e); + throw new RuntimeException(e); } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/impersonation/ImpersonationUtils.java b/cdap-security/src/main/java/io/cdap/cdap/security/impersonation/ImpersonationUtils.java index da4c942075b2..44aa777fb65b 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/impersonation/ImpersonationUtils.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/impersonation/ImpersonationUtils.java @@ -50,7 +50,17 @@ public T run() throws Exception { } catch (UndeclaredThrowableException e) { // UserGroupInformation#doAs will wrap any checked exceptions, so unwrap and rethrow here Throwable wrappedException = e.getUndeclaredThrowable(); - Throwables.propagateIfPossible(wrappedException); + if (wrappedException instanceof RuntimeException) { + + throw (RuntimeException) wrappedException; + + } + + if (wrappedException instanceof Error) { + + throw (Error) wrappedException; + + } if (wrappedException instanceof Exception) { throw (Exception) wrappedException; @@ -59,7 +69,8 @@ public T run() throws Exception { // this should never happen LOG.warn("Unexpected exception while executing callable as {}.", ugi.getUserName(), wrappedException); - throw Throwables.propagate(wrappedException); + Throwables.propagateIfUnchecked(wrappedException); + throw new RuntimeException(wrappedException); } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/runtime/AuthenticationServerMain.java b/cdap-security/src/main/java/io/cdap/cdap/security/runtime/AuthenticationServerMain.java index 85399509197a..2cc7d1b05110 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/runtime/AuthenticationServerMain.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/runtime/AuthenticationServerMain.java @@ -87,7 +87,7 @@ public void start() throws Exception { + "ZooKeeper quorum settings are correct in " + "cdap-site.xml. Currently configured as: %s", zkClientService.getConnectString())); - authServer.startAndWait(); + io.cdap.cdap.common.service.Services.startAndWait(authServer); } catch (Exception e) { Throwable rootCause = Throwables.getRootCause(e); if (rootCause instanceof ServiceBindException) { diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/server/ExternalAuthenticationServer.java b/cdap-security/src/main/java/io/cdap/cdap/security/server/ExternalAuthenticationServer.java index 2edf817d29c8..5fe32042374d 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/server/ExternalAuthenticationServer.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/server/ExternalAuthenticationServer.java @@ -16,9 +16,9 @@ package io.cdap.cdap.security.server; +import com.google.common.base.Throwables; import com.google.common.base.Preconditions; import com.google.common.base.Strings; -import com.google.common.base.Throwables; import com.google.common.util.concurrent.AbstractIdleService; import com.google.inject.Inject; import com.google.inject.name.Named; @@ -293,8 +293,7 @@ private Map getAuthHandlerConfigs(Configuration configuration) { return props; } - @Override - protected Executor executor(State state) { + protected Executor executor() { final AtomicInteger id = new AtomicInteger(); //noinspection NullableProblems diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/server/GrantAccessToken.java b/cdap-security/src/main/java/io/cdap/cdap/security/server/GrantAccessToken.java index 96c57e21b042..e8846e54156b 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/server/GrantAccessToken.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/server/GrantAccessToken.java @@ -22,6 +22,7 @@ import io.cdap.cdap.common.conf.CConfiguration; import io.cdap.cdap.common.conf.Constants; import io.cdap.cdap.common.io.Codec; +import io.cdap.cdap.common.service.Services; import io.cdap.cdap.security.auth.AccessToken; import io.cdap.cdap.security.auth.TokenManager; import io.cdap.cdap.security.auth.UserIdentity; @@ -73,7 +74,7 @@ public GrantAccessToken(TokenManager tokenManager, public void init() { // TokenManager may have already been started in AbstractServiceMain if internal auth is enabled. if (!tokenManager.isRunning()) { - tokenManager.start(); + Services.startAndWait(tokenManager); } } @@ -81,7 +82,7 @@ public void init() { * Stop the TokenManager. */ public void destroy() { - tokenManager.stop(); + Services.stopAndWait(tokenManager); } /** diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapAuthenticationHandler.java b/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapAuthenticationHandler.java index c98cb26b481a..94fa6f8cebaf 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapAuthenticationHandler.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapAuthenticationHandler.java @@ -16,6 +16,7 @@ package io.cdap.cdap.security.server; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import io.cdap.cdap.common.conf.Constants; @@ -61,9 +62,9 @@ public AppConfigurationEntry[] getAppConfigurationEntry(String s) { String ldapsVerifyCertificate = handlerProps.get("ldapsVerifyCertificate"); String useLdaps = handlerProps.get("useLdaps"); - if (Boolean.parseBoolean(Objects.firstNonNull(useLdaps, "false"))) { + if (Boolean.parseBoolean(MoreObjects.firstNonNull(useLdaps, "false"))) { ldapSSLVerifyCertificate = Boolean.parseBoolean( - Objects.firstNonNull(ldapsVerifyCertificate, "true")); + MoreObjects.firstNonNull(ldapsVerifyCertificate, "true")); } return new AppConfigurationEntry[]{ diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapLoginModule.java b/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapLoginModule.java index 75e5d14ff503..2d755b010eca 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapLoginModule.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapLoginModule.java @@ -16,7 +16,6 @@ package io.cdap.cdap.security.server; -import com.google.common.base.Throwables; import java.io.IOException; import java.net.InetAddress; import java.net.Socket; @@ -76,7 +75,7 @@ public X509Certificate[] getAcceptedIssuers() { trustAllFactory = sc.getSocketFactory(); } catch (GeneralSecurityException e) { LOG.error("Could not disable certificate verification for connections to LDAP.", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/store/DefaultSecureStoreService.java b/cdap-security/src/main/java/io/cdap/cdap/security/store/DefaultSecureStoreService.java index 268b3cb93b59..79830661470d 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/store/DefaultSecureStoreService.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/store/DefaultSecureStoreService.java @@ -145,11 +145,11 @@ public final void delete(String namespace, String name) throws Exception { @Override protected void startUp() throws Exception { - secureStoreService.startAndWait(); + io.cdap.cdap.common.service.Services.startAndWait(secureStoreService); } @Override protected void shutDown() throws Exception { - secureStoreService.stopAndWait(); + io.cdap.cdap.common.service.Services.stopAndWait(secureStoreService); } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/tools/AccessTokenGeneratorService.java b/cdap-security/src/main/java/io/cdap/cdap/security/tools/AccessTokenGeneratorService.java index a6491022cfb6..3728de11b6c6 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/tools/AccessTokenGeneratorService.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/tools/AccessTokenGeneratorService.java @@ -109,7 +109,7 @@ public void stop() { } catch (Exception e) { LOG.warn("Exception when stopping AccessTokenGeneratorService", e); } - handler.tokenManager.stopAndWait(); + io.cdap.cdap.common.service.Services.stopAndWait(handler.tokenManager); } @Override diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/zookeeper/SharedResourceCache.java b/cdap-security/src/main/java/io/cdap/cdap/security/zookeeper/SharedResourceCache.java index c87e464c6b8a..c0870c10bbe8 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/zookeeper/SharedResourceCache.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/zookeeper/SharedResourceCache.java @@ -60,6 +60,7 @@ public class SharedResourceCache extends AbstractLoadingCache { private static final String ZNODE_PATH_SEP = "/"; private static final int MAX_RETRIES = 3; private static final Logger LOG = LoggerFactory.getLogger(SharedResourceCache.class); + private static final java.util.concurrent.Executor DIRECT_EXECUTOR = Runnable::run; private final List znodeACL; @@ -91,7 +92,8 @@ public void init() throws InterruptedException { } } catch (ExecutionException ee) { // recheck if already created - throw Throwables.propagate(ee.getCause()); + Throwables.propagateIfUnchecked(ee.getCause()); + throw new RuntimeException(ee.getCause()); } this.resources = reloadAll(); listeners.notifyUpdate(); @@ -117,7 +119,7 @@ public void onSuccess(NodeData result) { loaded.put(nodeName, resource); listeners.notifyResourceUpdate(nodeName, resource); } catch (IOException ioe) { - throw Throwables.propagate(ioe); + throw new RuntimeException(ioe); } } @@ -126,7 +128,8 @@ public void onFailure(Throwable t) { LOG.error("Failed to get data for child node {}", nodeName, t); listeners.notifyError(nodeName, t); } - }); + }, + DIRECT_EXECUTOR); LOG.debug("Added future for {}", child); } } @@ -192,14 +195,14 @@ public void onFailure(Throwable t) { listeners.notifyError(name, t); completion.setException(t); } - } - ); + }, + DIRECT_EXECUTOR); - // Block until it is done + // Block until it is done completion.get(); } catch (Exception ioe) { - throw Throwables.propagate(ioe); + throw new RuntimeException(ioe); } } @@ -228,7 +231,8 @@ public void onFailure(Throwable t) { LOG.error("Failed to remove znode {}", znode, t); listeners.notifyError(name, t); } - }); + }, + DIRECT_EXECUTOR); } /** @@ -348,7 +352,8 @@ public void onSuccess(NodeData result) { public void onFailure(Throwable t) { resourceCallback.onFailure(t); } - }); + }, + DIRECT_EXECUTOR); } private class ZKWatcher implements Watcher { @@ -403,7 +408,9 @@ public void run() { listener.onUpdate(); } catch (Throwable t) { LOG.error("Exception notifying listener {}", listener, t); - Throwables.propagateIfInstanceOf(t, Error.class); + if (t instanceof Error) { + throw (Error) t; + } } } } @@ -419,7 +426,9 @@ public void run() { listener.onResourceUpdate(name, resource); } catch (Throwable t) { LOG.error("Exception notifying listener {}", listener, t); - Throwables.propagateIfInstanceOf(t, Error.class); + if (t instanceof Error) { + throw (Error) t; + } } } } @@ -435,7 +444,9 @@ public void run() { listener.onResourceDelete(name); } catch (Throwable t) { LOG.error("Exception notifying listener {}", listener, t); - Throwables.propagateIfInstanceOf(t, Error.class); + if (t instanceof Error) { + throw (Error) t; + } } } } @@ -451,7 +462,9 @@ public void run() { listener.onError(name, throwable); } catch (Throwable t) { LOG.error("Exception notifying listener {}", listener, t); - Throwables.propagateIfInstanceOf(t, Error.class); + if (t instanceof Error) { + throw (Error) t; + } } } } diff --git a/cdap-security/src/test/java/io/cdap/cdap/security/auth/DistributedKeyManagerTest.java b/cdap-security/src/test/java/io/cdap/cdap/security/auth/DistributedKeyManagerTest.java index c37de574bf86..df152f9b55d4 100644 --- a/cdap-security/src/test/java/io/cdap/cdap/security/auth/DistributedKeyManagerTest.java +++ b/cdap-security/src/test/java/io/cdap/cdap/security/auth/DistributedKeyManagerTest.java @@ -31,6 +31,7 @@ import io.cdap.cdap.common.guice.ZkClientModule; import io.cdap.cdap.common.guice.ZkDiscoveryModule; import io.cdap.cdap.common.io.Codec; +import io.cdap.cdap.common.service.Services; import io.cdap.cdap.common.utils.ImmutablePair; import io.cdap.cdap.common.utils.Tasks; import io.cdap.cdap.security.guice.CoreSecurityModule; @@ -117,8 +118,8 @@ public void testKeyDistribution() throws Exception { new TestingTokenManager(manager1, injector1.getInstance(UserIdentityCodec.class)); TestingTokenManager tokenManager2 = new TestingTokenManager(manager2, injector2.getInstance(UserIdentityCodec.class)); - tokenManager1.startAndWait(); - tokenManager2.startAndWait(); + Services.startAndWait(tokenManager1); + Services.startAndWait(tokenManager2); long now = System.currentTimeMillis(); UserIdentity ident1 = new UserIdentity("testuser", UserIdentity.IdentifierType.EXTERNAL, @@ -136,8 +137,8 @@ public void testKeyDistribution() throws Exception { assertEquals(token1.getIdentifier().getGroups(), token2.getIdentifier().getGroups()); assertEquals(token1, token2); - tokenManager1.stopAndWait(); - tokenManager2.stopAndWait(); + Services.stopAndWait(tokenManager1); + Services.stopAndWait(tokenManager2); } @Test @@ -160,21 +161,20 @@ protected ImmutablePair> getTokenManagerAndCode DistributedKeyManager keyManager = getKeyManager(injector1, true); TokenManager tokenManager = new TokenManager(keyManager, injector1.getInstance(UserIdentityCodec.class)); - tokenManager.startAndWait(); return new ImmutablePair<>(tokenManager, injector1.getInstance(AccessTokenCodec.class)); } private DistributedKeyManager getKeyManager(Injector injector, boolean expectLeader) throws Exception { ZKClientService zk = injector.getInstance(ZKClientService.class); - zk.startAndWait(); + Services.startAndWait(zk); WaitableDistributedKeyManager keyManager = new WaitableDistributedKeyManager(injector.getInstance(CConfiguration.class), injector.getInstance(Key.get(new TypeLiteral>() { })), zk); - keyManager.startAndWait(); + Services.startAndWait(keyManager); if (expectLeader) { Tasks.waitFor(true, () -> keyManager.getCurrentKey() != null, 5L, TimeUnit.SECONDS); } diff --git a/cdap-security/src/test/java/io/cdap/cdap/security/auth/FileBasedTokenManagerTest.java b/cdap-security/src/test/java/io/cdap/cdap/security/auth/FileBasedTokenManagerTest.java index e535d834b1b0..7e2b6e73d71a 100644 --- a/cdap-security/src/test/java/io/cdap/cdap/security/auth/FileBasedTokenManagerTest.java +++ b/cdap-security/src/test/java/io/cdap/cdap/security/auth/FileBasedTokenManagerTest.java @@ -27,6 +27,7 @@ import io.cdap.cdap.common.guice.IOModule; import io.cdap.cdap.common.guice.InMemoryDiscoveryModule; import io.cdap.cdap.common.io.Codec; +import io.cdap.cdap.common.service.Services; import io.cdap.cdap.common.utils.ImmutablePair; import io.cdap.cdap.common.utils.Tasks; import io.cdap.cdap.security.guice.FileBasedCoreSecurityModule; @@ -60,7 +61,6 @@ protected ImmutablePair> getTokenManagerAndCode new FileBasedCoreSecurityModule(), new InMemoryDiscoveryModule()); TokenManager tokenManager = injector.getInstance(TokenManager.class); - tokenManager.startAndWait(); Codec tokenCodec = injector.getInstance(AccessTokenCodec.class); return new ImmutablePair<>(tokenManager, tokenCodec); } @@ -79,14 +79,14 @@ public void testFileBasedKey() throws Exception { new ConfigModule(cConf), new FileBasedCoreSecurityModule(), new InMemoryDiscoveryModule()).getInstance(TokenManager.class); - tokenManager.startAndWait(); + Services.startAndWait(tokenManager); TokenManager tokenManager2 = Guice.createInjector( new IOModule(), new ConfigModule(cConf), new FileBasedCoreSecurityModule(), new InMemoryDiscoveryModule()).getInstance(TokenManager.class); - tokenManager2.startAndWait(); + Services.startAndWait(tokenManager2); Assert.assertNotSame("ERROR: Both token managers refer to the same object.", tokenManager, tokenManager2); @@ -129,7 +129,7 @@ public void testKeyUpdate() throws Exception { keyFile.setLastModified(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(10)); try { - keyManager.startAndWait(); + Services.startAndWait(keyManager); // Upon the key manager starts, the current key should be the same as the one from the key file. Assert.assertEquals(keyIdentifier, keyManager.currentKey); @@ -142,7 +142,7 @@ public void testKeyUpdate() throws Exception { Tasks.waitFor(keyIdentifier, () -> keyManager.currentKey, 20, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); } finally { - keyManager.stopAndWait(); + Services.stopAndWait(keyManager); } } diff --git a/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestInMemoryTokenManager.java b/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestInMemoryTokenManager.java index 2c61c976fdbf..ec8a44b4dc9c 100644 --- a/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestInMemoryTokenManager.java +++ b/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestInMemoryTokenManager.java @@ -36,7 +36,6 @@ protected ImmutablePair> getTokenManagerAndCode Injector injector = Guice.createInjector(new IOModule(), new CoreSecurityRuntimeModule().getStandaloneModules(), new ConfigModule(), new InMemoryDiscoveryModule()); TokenManager tokenManager = injector.getInstance(TokenManager.class); - tokenManager.startAndWait(); Codec tokenCodec = injector.getInstance(AccessTokenCodec.class); return new ImmutablePair<>(tokenManager, tokenCodec); } diff --git a/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestTokenManager.java b/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestTokenManager.java index a4a29eb1eb54..4ee91b8ac8f1 100644 --- a/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestTokenManager.java +++ b/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestTokenManager.java @@ -42,7 +42,7 @@ public abstract class TestTokenManager { public void testTokenValidation() throws Exception { ImmutablePair> pair = getTokenManagerAndCodec(); TokenManager tokenManager = pair.getFirst(); - tokenManager.startAndWait(); + io.cdap.cdap.common.service.Services.startAndWait(tokenManager); Codec tokenCodec = pair.getSecond(); long now = System.currentTimeMillis(); @@ -91,14 +91,14 @@ public void testTokenValidation() throws Exception { // expected } - tokenManager.stopAndWait(); + io.cdap.cdap.common.service.Services.stopAndWait(tokenManager); } @Test public void testTokenSerialization() throws Exception { ImmutablePair> pair = getTokenManagerAndCodec(); TokenManager tokenManager = pair.getFirst(); - tokenManager.startAndWait(); + io.cdap.cdap.common.service.Services.startAndWait(tokenManager); Codec tokenCodec = pair.getSecond(); long now = System.currentTimeMillis(); @@ -116,6 +116,6 @@ public void testTokenSerialization() throws Exception { // should be valid since we just signed it tokenManager.validateSecret(token2); - tokenManager.stopAndWait(); + io.cdap.cdap.common.service.Services.stopAndWait(tokenManager); } } diff --git a/cdap-security/src/test/java/io/cdap/cdap/security/server/ExternalAuthenticationServerTestBase.java b/cdap-security/src/test/java/io/cdap/cdap/security/server/ExternalAuthenticationServerTestBase.java index 9e378e10531c..f82ea8d19a5d 100644 --- a/cdap-security/src/test/java/io/cdap/cdap/security/server/ExternalAuthenticationServerTestBase.java +++ b/cdap-security/src/test/java/io/cdap/cdap/security/server/ExternalAuthenticationServerTestBase.java @@ -38,6 +38,7 @@ import io.cdap.cdap.common.guice.IOModule; import io.cdap.cdap.common.guice.InMemoryDiscoveryModule; import io.cdap.cdap.common.io.Codec; +import io.cdap.cdap.common.service.Services; import io.cdap.cdap.security.auth.AccessToken; import io.cdap.cdap.security.auth.AccessTokenCodec; import io.cdap.cdap.security.guice.CoreSecurityRuntimeModule; @@ -124,14 +125,14 @@ protected void configure() { startExternalAuthenticationServer(); - server.startAndWait(); + Services.startAndWait(server); LOG.info("Auth server running on address {}", server.getSocketAddress()); TimeUnit.SECONDS.sleep(3); } protected void tearDown() throws Exception { stopExternalAuthenticationServer(); - server.stopAndWait(); + Services.stopAndWait(server); // Clear any security properties for zookeeper. System.clearProperty(Constants.External.Zookeeper.ENV_AUTH_PROVIDER_1); Configuration.setConfiguration(null); diff --git a/cdap-security/src/test/java/io/cdap/cdap/security/store/secretmanager/SecretManagerSecureStoreServiceTest.java b/cdap-security/src/test/java/io/cdap/cdap/security/store/secretmanager/SecretManagerSecureStoreServiceTest.java index b6d2cb829b02..2cdbe0250888 100644 --- a/cdap-security/src/test/java/io/cdap/cdap/security/store/secretmanager/SecretManagerSecureStoreServiceTest.java +++ b/cdap-security/src/test/java/io/cdap/cdap/security/store/secretmanager/SecretManagerSecureStoreServiceTest.java @@ -48,12 +48,12 @@ public static void setUp() throws Exception { namespaceClient.create(namespaceMeta); secureStoreService = new SecretManagerSecureStoreService(namespaceClient, new MockSecretManagerContext(), "mock", new MockSecretManager()); - secureStoreService.startAndWait(); + io.cdap.cdap.common.service.Services.startAndWait(secureStoreService); } @AfterClass public static void cleanUp() { - secureStoreService.stopAndWait(); + io.cdap.cdap.common.service.Services.stopAndWait(secureStoreService); } @Test diff --git a/cdap-security/src/test/java/io/cdap/cdap/security/zookeeper/SharedResourceCacheTest.java b/cdap-security/src/test/java/io/cdap/cdap/security/zookeeper/SharedResourceCacheTest.java index 40fa80649cb4..b16c3f46dbca 100644 --- a/cdap-security/src/test/java/io/cdap/cdap/security/zookeeper/SharedResourceCacheTest.java +++ b/cdap-security/src/test/java/io/cdap/cdap/security/zookeeper/SharedResourceCacheTest.java @@ -21,6 +21,7 @@ import com.google.common.base.Stopwatch; import com.google.common.collect.Lists; +import io.cdap.cdap.common.service.Services; import com.google.common.util.concurrent.SettableFuture; import com.google.inject.Guice; import com.google.inject.Injector; @@ -84,7 +85,7 @@ public void testCache() throws Exception { // create 2 cache instances ZKClientService zkClient1 = injector1.getInstance(ZKClientService.class); - zkClient1.startAndWait(); + Services.startAndWait(zkClient1); SharedResourceCache cache1 = new SharedResourceCache<>(zkClient1, new StringCodec(), parentNode, acls); cache1.init(); @@ -95,7 +96,7 @@ public void testCache() throws Exception { cache1.put(key1, value1); ZKClientService zkClient2 = injector2.getInstance(ZKClientService.class); - zkClient2.startAndWait(); + Services.startAndWait(zkClient2); SharedResourceCache cache2 = new SharedResourceCache<>(zkClient2, new StringCodec(), parentNode, acls); cache2.init(); @@ -194,8 +195,8 @@ private void waitForEntry(SharedResourceCache cache, String key, String String value = cache.get(key); boolean isPresent = expectedValue.equals(value); - Stopwatch watch = new Stopwatch().start(); - while (!isPresent && watch.elapsedTime(TimeUnit.MILLISECONDS) < timeToWaitMillis) { + Stopwatch watch = Stopwatch.createStarted(); + while (!isPresent && watch.elapsed(TimeUnit.MILLISECONDS) < timeToWaitMillis) { TimeUnit.MILLISECONDS.sleep(200); value = cache.get(key); isPresent = expectedValue.equals(value); diff --git a/pom.xml b/pom.xml index 64c19fa20c92..ca994c6b016b 100644 --- a/pom.xml +++ b/pom.xml @@ -1596,6 +1596,7 @@ third-party-licenses/** .gitpod.yml .gitpod.Dockerfile + **/target/** From d273a3c86b73cc3978c0565413075fed8a380953 Mon Sep 17 00:00:00 2001 From: abhishkkumar Date: Thu, 14 May 2026 05:31:14 +0000 Subject: [PATCH 5/7] fixes for runtime Optimize AppScanEntry artifact filtering to avoid full JSON deserialization Restore GSON ExclusionStrategy in DefaultDataTracer to avoid reflection access errors on Java 9+ Restore testScanApplicationsWithArtifactFilter and testScanApplicationsWithArtifactFilterCoverage in AppMetadataStoreTest.java Clean up try-catch block formatting in TwillAppLifecycleEventHandler.java Clean up formatting and add comments inside empty catch block in AbstractProgramRuntimeService.java Clean up try-catch formatting and add catch block comments in TransactionHttpHandler.java Clean up formatting and add comments inside catch blocks in ArtifactClassLoaderFactory.java Use simple imports for java.io stream types in MapReduceRuntimeService.java Clean up try-catch block formatting in DefaultRuntimeJob.java Clean up try-catch formatting in PluginInstantiator.java Clean up try-catch formatting in DefaultProgramWorkflowRunner.java Use simple imports for java.io streams and java.nio Files in LocalizationUtils.java Clean up try-catch block formatting in HubPackage.java Clean up InterruptedException catch block formatting in OperationalStatsService.java Use Guava Files.copy instead of java.nio.file.Files.copy in HttpHandlerGeneratorTest.java Clean up try-catch block formatting in OperationLifecycleManagerTest.java --- .../guice/AppFabricServiceRuntimeModule.java | 3 +- .../guice/ImpersonatedTwillController.java | 2 +- .../app/guice/ImpersonatedTwillPreparer.java | 3 +- .../guice/ImpersonatedTwillRunnerService.java | 3 +- .../preview/DefaultPreviewRunnerManager.java | 15 ++-- .../cdap/app/preview/PreviewHttpServer.java | 4 +- .../AbstractProgramRuntimeService.java | 7 +- .../app/runtime/DelayedProgramController.java | 4 +- .../twill/TwillAppLifecycleEventHandler.java | 15 ++-- .../AbstractAppLifecycleHttpHandler.java | 3 +- .../gateway/handlers/ArtifactHttpHandler.java | 3 +- .../handlers/ArtifactHttpHandlerInternal.java | 3 +- .../handlers/AuthorizationHandler.java | 8 +- .../gateway/handlers/DatasetServiceStore.java | 9 ++- .../gateway/handlers/JsonListResponder.java | 3 +- .../handlers/ProgramScheduleHttpHandler.java | 13 ++-- .../handlers/TransactionHttpHandler.java | 19 ++++- .../util/AbstractAppFabricHttpHandler.java | 11 ++- .../handlers/util/NamespaceHelper.java | 3 +- .../app/AbstractInMemoryProgramRunner.java | 5 +- .../internal/app/DefaultPluginConfigurer.java | 5 +- .../app/DefaultServicePluginConfigurer.java | 3 +- .../deploy/InMemoryProgramRunDispatcher.java | 30 ++++--- .../namespace/NamespaceExistenceVerifier.java | 3 +- .../app/preview/DefaultDataTracer.java | 11 ++- .../app/preview/DefaultPreviewManager.java | 10 +-- .../app/preview/DefaultPreviewRunner.java | 40 +++++----- .../app/preview/PreviewRunnerService.java | 3 +- .../preview/PreviewRunnerTwillRunnable.java | 16 ++-- .../MessagingProgramStatePublisher.java | 5 +- .../runtime/AbstractProgramController.java | 4 +- .../AbstractProgramRunnerWithPlugin.java | 12 ++- .../app/runtime/DefaultPluginContext.java | 5 +- .../app/runtime/LocalizationUtils.java | 16 +++- .../ProgramControllerServiceAdapter.java | 8 +- .../internal/app/runtime/ProgramRunners.java | 8 +- .../artifact/AbstractArtifactManager.java | 17 +++- .../artifact/ArtifactClassLoaderFactory.java | 42 +++++++--- .../artifact/ArtifactExistenceVerifier.java | 3 +- .../app/runtime/artifact/ArtifactStore.java | 13 ++-- .../artifact/DefaultArtifactInspector.java | 5 +- .../runtime/artifact/LocalPluginFinder.java | 3 +- .../artifact/RemoteArtifactManager.java | 3 +- .../runtime/artifact/RemotePluginFinder.java | 3 +- .../batch/BasicMapReduceTaskContext.java | 13 ++-- .../runtime/batch/MainOutputCommitter.java | 17 ++-- .../runtime/batch/MapReduceClassLoader.java | 16 ++-- .../runtime/batch/MapReduceContextConfig.java | 3 +- .../batch/MapReduceProgramController.java | 3 +- .../runtime/batch/MapReduceProgramRunner.java | 7 +- .../batch/MapReduceRuntimeService.java | 25 +++--- .../app/runtime/batch/MapperWrapper.java | 4 +- .../app/runtime/batch/ReducerWrapper.java | 11 ++- .../app/runtime/batch/WrapperUtil.java | 3 +- .../batch/dataset/DataSetInputSplit.java | 4 +- ...stributedMapReduceTaskContextProvider.java | 13 +++- .../distributed/MapReduceContainerHelper.java | 3 +- .../AbstractProgramTwillRunnable.java | 37 ++++++--- .../distributed/DistributedProgramRunner.java | 4 +- .../DistributedWorkflowProgramRunner.java | 10 ++- .../runtime/distributed/LocalizeResource.java | 4 +- .../remote/AbstractRuntimeTwillPreparer.java | 4 +- .../remote/RemoteExecutionJobMain.java | 4 +- .../remote/RemoteExecutionService.java | 4 +- .../RemoteExecutionTwillController.java | 7 +- .../remote/RemoteExecutionTwillPreparer.java | 4 +- .../RemoteExecutionTwillRunnerService.java | 11 ++- .../remote/SSHRemoteExecutionService.java | 17 +++- .../runtimejob/DefaultRuntimeJob.java | 18 +++-- .../AbstractServiceRoutingHandler.java | 33 ++++++-- .../DirectRuntimeRequestValidator.java | 12 +-- .../runtime/monitor/RuntimeClientService.java | 2 +- .../app/runtime/monitor/RuntimeHandler.java | 25 +++++- .../app/runtime/plugin/FindPluginHelper.java | 3 +- .../runtime/plugin/PluginClassLoaders.java | 3 +- .../runtime/plugin/PluginInstantiator.java | 32 +++++--- .../DistributedTimeSchedulerService.java | 4 +- .../schedule/LocalScheduleManager.java | 3 +- .../app/runtime/schedule/queue/JobKey.java | 3 +- .../runtime/schedule/queue/JobQueueTable.java | 7 +- .../app/runtime/schedule/queue/SimpleJob.java | 3 +- .../store/DatasetBasedTimeScheduleStore.java | 15 ++-- .../runtime/schedule/store/Schedulers.java | 3 +- .../runtime/service/ServiceProgramRunner.java | 12 ++- .../http/DelayedHttpServiceResponder.java | 3 +- .../service/http/HttpHandlerFactory.java | 3 +- .../service/http/HttpHandlerGenerator.java | 9 +-- .../http/LocationHttpContentProducer.java | 9 ++- .../runtime/worker/WorkerProgramRunner.java | 13 ++-- .../workflow/CustomActionExecutor.java | 4 +- .../DefaultProgramWorkflowRunner.java | 44 ++++++++--- .../app/runtime/workflow/WorkflowDriver.java | 5 +- .../workflow/WorkflowProgramController.java | 5 +- .../workflow/WorkflowProgramRunner.java | 7 +- ...AbstractNotificationSubscriberService.java | 2 +- .../services/AppFabricProcessorService.java | 78 +++++++++++-------- .../app/services/AppFabricServer.java | 45 ++++++----- .../services/ApplicationLifecycleService.java | 8 +- .../ProgramNotificationSubscriberService.java | 4 +- .../internal/app/store/AppMetadataStore.java | 56 ++++++------- .../internal/app/store/ApplicationMeta.java | 3 +- .../app/store/adapters/PluginKey.java | 3 +- .../internal/app/worker/ConfiguratorTask.java | 4 +- .../app/worker/TaskWorkerService.java | 3 +- .../app/worker/TaskWorkerTwillRunnable.java | 19 ++--- .../ArtifactLocalizerTwillRunnable.java | 19 ++--- .../worker/system/SystemWorkerService.java | 5 +- .../system/SystemWorkerTwillRunnable.java | 23 +++--- .../internal/bootstrap/BootstrapService.java | 12 +-- .../capability/autoinstall/HubPackage.java | 7 +- .../events/EventSubscriberManager.java | 4 +- .../events/ProgramStatusEventPublisher.java | 4 +- .../InMemoryOperationController.java | 5 +- .../operation/InMemoryOperationRunner.java | 2 +- .../MessagingOperationStatePublisher.java | 5 +- ...perationNotificationSubscriberService.java | 4 +- .../internal/profile/AdminEventPublisher.java | 3 +- .../provision/ProvisioningService.java | 2 +- .../environment/k8s/AbstractServiceMain.java | 4 +- .../k8s/MasterEnvironmentMain.java | 6 +- .../cdap/cdap/metadata/MetadataValidator.java | 2 +- .../operations/OperationalStatsService.java | 8 +- .../scheduler/ConstraintCheckerService.java | 4 +- .../cdap/scheduler/CoreSchedulerService.java | 29 ++++--- .../scheduler/ProgramScheduleService.java | 20 ++--- ...ScheduleNotificationSubscriberService.java | 16 ++-- .../auth/AuditLogSubscriberService.java | 4 +- .../hive/JobHistoryServerTokenUtils.java | 5 +- .../cdap/cdap/AppWithMisbehavedDataset.java | 3 +- .../java/io/cdap/cdap/AppWithSchedule.java | 3 +- .../test/java/io/cdap/cdap/AppWithWorker.java | 3 +- .../java/io/cdap/cdap/AppWithWorkflow.java | 3 +- .../cdap/cdap/CapabilityAppWithWorkflow.java | 3 +- .../io/cdap/cdap/ConcurrentWorkflowApp.java | 3 +- .../io/cdap/cdap/WorkflowAppWithFork.java | 3 +- .../mapreduce/LocalMRJobInfoFetcherTest.java | 6 +- .../AbstractProgramRuntimeServiceTest.java | 30 +++---- .../app/runtime/ProgramControllerTest.java | 7 +- .../monitor/TrafficRelayServerTest.java | 4 +- .../cdap/cdap/internal/AppFabricClient.java | 3 +- .../cdap/internal/AppFabricTestHelper.java | 13 +++- .../io/cdap/cdap/internal/TempFolder.java | 5 +- .../SystemMetadataWriterStageTest.java | 4 +- .../StorageProviderNamespaceAdminTest.java | 8 +- .../app/preview/PreviewRunnerServiceTest.java | 10 +-- .../AppWithMapReduceUsingObjectStore.java | 3 +- .../batch/MapReduceProgramRunnerTest.java | 9 ++- .../batch/MapReduceRunnerTestBase.java | 7 +- .../AppWithMapReduceUsingMultipleInputs.java | 3 +- .../MapReduceWithMultipleInputsTest.java | 8 +- .../MapReduceWithMultipleOutputsTest.java | 6 +- .../remote/RemoteExecutionJobMainTest.java | 4 +- .../InternalServiceRoutingHandlerTest.java | 4 +- .../monitor/RuntimeClientServerTest.java | 8 +- .../monitor/RuntimeClientServiceTest.java | 40 +++++----- .../monitor/RuntimeServiceRoutingTest.java | 13 ++-- .../monitor/proxy/ServiceSocksProxyTest.java | 4 +- .../queue/NoSqlJobQueueTableTest.java | 4 +- .../DatasetBasedTimeScheduleStoreTest.java | 12 +-- .../http/HttpHandlerGeneratorTest.java | 22 ++++-- .../worker/WorkerProgramRunnerTest.java | 7 +- .../app/scheduler/LogPrintingJob.java | 3 +- .../AppFabricProcessorServiceTest.java | 8 +- .../app/services/AppFabricServerTest.java | 11 +-- .../DefaultSecureStoreServiceTest.java | 8 +- ...gramLifecycleServiceAuthorizationTest.java | 8 +- .../services/ProgramLifecycleServiceTest.java | 4 +- .../ProgramRunStatusMonitorServiceTest.java | 6 +- .../SystemProgramManagementServiceTest.java | 2 +- .../app/services/http/AppFabricTestBase.java | 57 +++++++------- .../app/store/AppMetadataStoreTest.java | 19 +---- .../remote/RemoteNamespaceQueryTest.java | 12 +-- .../remote/RemotePermissionsTestBase.java | 4 +- .../app/store/state/AppStateHandlerTest.java | 4 +- .../app/store/state/AppStateTableTest.java | 4 +- .../app/worker/TaskWorkerMetricsTest.java | 6 +- .../app/worker/TaskWorkerServiceTest.java | 18 ++--- .../app/worker/TaskWorkerTestUtil.java | 3 +- .../sidecar/ArtifactLocalizerServiceTest.java | 4 +- .../system/SystemWorkerServiceTest.java | 4 +- .../cdap/internal/audit/AuditPublishTest.java | 4 +- .../CapabilityManagementServiceTest.java | 7 +- .../CredentialProviderTestBase.java | 4 +- ...rogramStatusEventPublisherMetricsTest.java | 4 +- .../OperationLifecycleManagerTest.java | 7 +- ...ationSingleTopicSubscriberServiceTest.java | 9 ++- .../operation/SqlOperationRunsStoreTest.java | 9 ++- .../internal/profile/ProfileMetadataTest.java | 4 +- .../provision/ProvisioningServiceTest.java | 16 ++-- .../tethering/ArtifactCacheServiceTest.java | 4 +- .../tethering/TetheringClientHandlerTest.java | 12 +-- .../tethering/TetheringServerHandlerTest.java | 8 +- .../TetheringRuntimeJobManagerTest.java | 8 +- .../MetadataAdminAuthorizationTest.java | 8 +- .../SystemMetadataAuditPublishTest.java | 4 +- .../cdap/runtime/OpenCloseDataSetTest.java | 3 +- .../scheduler/CoreSchedulerServiceTest.java | 4 +- ...itLogSingleTopicSubscriberServiceTest.java | 9 ++- .../impersonation/DefaultUGIProviderTest.java | 6 +- .../data/runtime/main/MasterServiceMain.java | 55 +++++++++---- .../cdap/data/tools/JobQueueDebugger.java | 12 +-- .../environment/k8s/MetadataServiceMain.java | 9 ++- .../master/startup/MasterStartupTool.java | 3 +- .../master/upgrade/UpgradeUserIDProvider.java | 3 +- .../environment/MockMasterEnvironment.java | 4 +- .../environment/k8s/LogsServiceMainTest.java | 6 +- .../k8s/MasterServiceMainTestBase.java | 4 +- .../k8s/PreviewServiceMainTest.java | 4 +- .../SystemMetricsExporterServiceMainTest.java | 4 +- .../metrics/jmx/JmxMetricsCollectorTest.java | 4 +- .../security/auth/AbstractKeyManager.java | 3 +- .../cdap/cdap/security/auth/AccessToken.java | 3 +- .../security/auth/AccessTokenValidator.java | 4 +- .../security/auth/DistributedKeyManager.java | 7 +- .../cdap/security/auth/KeyIdentifier.java | 3 +- .../cdap/cdap/security/auth/TokenManager.java | 7 +- .../cdap/cdap/security/auth/UserIdentity.java | 3 +- .../context/AuthenticationContextModules.java | 3 +- .../context/MasterAuthenticationContext.java | 3 +- .../context/SystemAuthenticationContext.java | 3 +- .../AccessControllerInstantiator.java | 12 ++- .../authorization/AuthorizerWrapper.java | 5 +- .../impersonation/ImpersonationUtils.java | 15 +++- .../runtime/AuthenticationServerMain.java | 2 +- .../server/ExternalAuthenticationServer.java | 4 +- .../security/server/GrantAccessToken.java | 4 +- .../server/LdapAuthenticationHandler.java | 5 +- .../cdap/security/server/LdapLoginModule.java | 3 +- .../store/DefaultSecureStoreService.java | 4 +- .../tools/AccessTokenGeneratorService.java | 2 +- .../zookeeper/SharedResourceCache.java | 44 ++++++++--- .../auth/DistributedKeyManagerTest.java | 14 ++-- .../auth/FileBasedTokenManagerTest.java | 10 +-- .../auth/TestInMemoryTokenManager.java | 2 +- .../cdap/security/auth/TestTokenManager.java | 8 +- .../ExternalAuthenticationServerTestBase.java | 4 +- .../SecretManagerSecureStoreServiceTest.java | 4 +- .../zookeeper/SharedResourceCacheTest.java | 8 +- 238 files changed, 1212 insertions(+), 995 deletions(-) diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/AppFabricServiceRuntimeModule.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/AppFabricServiceRuntimeModule.java index 15077d215f52..357c20d3a65e 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/AppFabricServiceRuntimeModule.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/AppFabricServiceRuntimeModule.java @@ -17,7 +17,6 @@ package io.cdap.cdap.app.guice; import com.google.common.base.Supplier; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.inject.AbstractModule; @@ -607,7 +606,7 @@ public synchronized org.quartz.Scheduler get() { } return scheduler; } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } }; diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/ImpersonatedTwillController.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/ImpersonatedTwillController.java index ff7865134aa4..8804c6872e8b 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/ImpersonatedTwillController.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/ImpersonatedTwillController.java @@ -183,7 +183,7 @@ public Void call() throws Exception { } }); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/ImpersonatedTwillPreparer.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/ImpersonatedTwillPreparer.java index 32bc5dc63e26..9bfeb490396d 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/ImpersonatedTwillPreparer.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/ImpersonatedTwillPreparer.java @@ -16,7 +16,6 @@ package io.cdap.cdap.app.guice; -import com.google.common.base.Throwables; import io.cdap.cdap.internal.app.runtime.distributed.ForwardingTwillPreparer; import io.cdap.cdap.proto.id.ProgramId; import io.cdap.cdap.security.TokenSecureStoreRenewer; @@ -66,7 +65,7 @@ public TwillController start(final long timeout, final TimeUnit timeoutUnit) { impersonator, programId); }); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/ImpersonatedTwillRunnerService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/ImpersonatedTwillRunnerService.java index c5a93a3f3c2c..183894af902f 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/ImpersonatedTwillRunnerService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/guice/ImpersonatedTwillRunnerService.java @@ -16,7 +16,6 @@ package io.cdap.cdap.app.guice; -import com.google.common.base.Throwables; import io.cdap.cdap.common.conf.Constants; import io.cdap.cdap.common.twill.TwillAppNames; import io.cdap.cdap.internal.app.runtime.distributed.ProgramTwillApplication; @@ -188,7 +187,7 @@ public void renew(final String application, final RunId runId, } catch (Exception e) { // it should already be a runtime exception anyways, since none of the methods in the above callable // throw any checked exceptions - throw Throwables.propagate(e); + throw new RuntimeException(e); } } }; diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/preview/DefaultPreviewRunnerManager.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/preview/DefaultPreviewRunnerManager.java index d8f5829b1356..d1cf01fda3d6 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/preview/DefaultPreviewRunnerManager.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/preview/DefaultPreviewRunnerManager.java @@ -67,7 +67,6 @@ import org.apache.tephra.TransactionSystemClient; import org.apache.twill.common.Threads; import org.apache.twill.discovery.DiscoveryServiceClient; -import org.apache.twill.internal.ServiceListenerAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -124,12 +123,12 @@ protected void startUp() throws Exception { // Starts common services runner = previewInjector.getInstance(PreviewRunner.class); if (runner instanceof Service) { - ((Service) runner).startAndWait(); + ((Service) runner).startAsync().awaitRunning(); } // Create and start the preview poller services. for (int i = 0; i < maxConcurrentPreviews; i++) { - createPreviewRunnerService().startAndWait(); + createPreviewRunnerService().startAsync().awaitRunning(); } } @@ -144,7 +143,7 @@ protected void shutDown() throws Exception { private void stopQuietly(Service service) { try { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } catch (Exception e) { LOG.warn("Error stopping the preview runner.", e); } @@ -163,8 +162,8 @@ public void stop(ApplicationId preview) throws Exception { } PreviewRunnerService newRunnerService = createPreviewRunnerService(); - runnerService.stopAndWait(); - newRunnerService.startAndWait(); + runnerService.stopAsync().awaitTerminated(); + newRunnerService.startAsync().awaitRunning(); } @Override @@ -237,14 +236,14 @@ public InetAddress providesHostname(CConfiguration cConf) { private PreviewRunnerService createPreviewRunnerService() { PreviewRunnerService previewRunnerService = previewRunnerServiceFactory.create(runner); - previewRunnerService.addListener(new ServiceListenerAdapter() { + previewRunnerService.addListener(new Service.Listener() { @Override public void terminated(State from) { previewRunnerServices.remove(previewRunnerService); if (previewRunnerServices.isEmpty()) { try { - stop(); + stopAsync(); } catch (Exception e) { // should not happen LOG.error("Failed to shutdown the preview runner manager service.", e); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/preview/PreviewHttpServer.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/preview/PreviewHttpServer.java index d93067bb3668..0433d5beb02f 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/preview/PreviewHttpServer.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/preview/PreviewHttpServer.java @@ -101,7 +101,7 @@ protected void startUp() throws Exception { Constants.Logging.COMPONENT_NAME, Constants.Service.PREVIEW_HTTP)); if (previewManager instanceof Service) { - ((Service) previewManager).startAndWait(); + ((Service) previewManager).startAsync().awaitRunning(); } httpService.start(); @@ -117,7 +117,7 @@ protected void shutDown() throws Exception { try { cancelHttpService.cancel(); if (previewManager instanceof Service) { - ((Service) previewManager).stopAndWait(); + ((Service) previewManager).stopAsync().awaitTerminated(); } } finally { httpService.stop(); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/runtime/AbstractProgramRuntimeService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/runtime/AbstractProgramRuntimeService.java index d664d16171ff..2ead228499f4 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/runtime/AbstractProgramRuntimeService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/runtime/AbstractProgramRuntimeService.java @@ -21,7 +21,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import com.google.common.collect.Table; -import com.google.common.io.Closeables; import com.google.common.util.concurrent.AbstractIdleService; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.inject.Inject; @@ -472,7 +471,11 @@ private ProgramController createController(ProgramId programId, RunId runId, */ private void cleanupRuntimeInfo(@Nullable RuntimeInfo info) { if (info instanceof Closeable) { - Closeables.closeQuietly((Closeable) info); + try { + ((Closeable) info).close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup of RuntimeInfo. + } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/runtime/DelayedProgramController.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/runtime/DelayedProgramController.java index 0e8f402aab22..1642f58b4b19 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/app/runtime/DelayedProgramController.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/app/runtime/DelayedProgramController.java @@ -18,6 +18,7 @@ import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; import com.google.common.util.concurrent.Uninterruptibles; @@ -189,7 +190,8 @@ public void onSuccess(ProgramController result) { public void onFailure(Throwable t) { resultFuture.setException(t); } - }); + }, + MoreExecutors.directExecutor()); }); return resultFuture; } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/common/twill/TwillAppLifecycleEventHandler.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/common/twill/TwillAppLifecycleEventHandler.java index 4d5342a5882a..24b1f866ad08 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/common/twill/TwillAppLifecycleEventHandler.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/common/twill/TwillAppLifecycleEventHandler.java @@ -15,8 +15,6 @@ */ package io.cdap.cdap.common.twill; -import com.google.common.base.Throwables; -import com.google.common.io.Closeables; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.inject.Guice; @@ -45,7 +43,6 @@ import java.nio.file.Files; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.hadoop.conf.Configuration; -import org.apache.twill.api.EventHandler; import org.apache.twill.api.EventHandlerContext; import org.apache.twill.api.RunId; import org.apache.twill.zookeeper.ZKClientService; @@ -124,7 +121,7 @@ public void initialize(EventHandlerContext context) { if (clusterMode == ClusterMode.ON_PREMISE) { zkClientService = injector.getInstance(ZKClientService.class); - zkClientService.startAndWait(); + zkClientService.startAsync().awaitRunning(); } LoggingContextAccessor.setLoggingContext( @@ -141,7 +138,7 @@ public void initialize(EventHandlerContext context) { new ProgramStateWriterWithHeartBeat(programRunId, programStateWriter, messagingService, cConf); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -210,9 +207,13 @@ public void aborted() { @Override public void destroy() { - Closeables.closeQuietly(logAppenderInitializer); + try { + logAppenderInitializer.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup in the destroy method. + } if (zkClientService != null) { - zkClientService.stop(); + zkClientService.stopAsync(); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/AbstractAppLifecycleHttpHandler.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/AbstractAppLifecycleHttpHandler.java index ab3dd3476ef4..53c5b95265c5 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/AbstractAppLifecycleHttpHandler.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/AbstractAppLifecycleHttpHandler.java @@ -16,7 +16,6 @@ package io.cdap.cdap.gateway.handlers; -import com.google.common.base.Throwables; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import io.cdap.cdap.api.artifact.ArtifactSummary; @@ -134,7 +133,7 @@ protected NamespaceId validateNamespace(@Nullable String namespace) // This can only happen when NamespaceAdmin uses HTTP calls to interact with namespaces. // In AppFabricServer, NamespaceAdmin is bound to DefaultNamespaceAdmin, which interacts directly with the MDS. // Hence, this exception will never be thrown - throw Throwables.propagate(e); + throw new RuntimeException(e); } return namespaceId; } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/ArtifactHttpHandler.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/ArtifactHttpHandler.java index 52a049ebadc6..54bdf8f3619e 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/ArtifactHttpHandler.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/ArtifactHttpHandler.java @@ -18,7 +18,6 @@ import com.google.common.base.Predicate; import com.google.common.base.Splitter; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Sets; @@ -854,7 +853,7 @@ private NamespaceId validateAndGetScopedNamespace(NamespaceId namespace, Artifac // This can only happen when NamespaceAdmin uses HTTP to interact with namespaces. // Within AppFabric, NamespaceAdmin is bound to DefaultNamespaceAdmin which directly interacts with MDS. // Hence, this should never happen. - throw Throwables.propagate(e); + throw new RuntimeException(e); } return ArtifactScope.SYSTEM.equals(scope) ? NamespaceId.SYSTEM : namespace; diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/ArtifactHttpHandlerInternal.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/ArtifactHttpHandlerInternal.java index 0fd6c6a72b98..225844ea4672 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/ArtifactHttpHandlerInternal.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/ArtifactHttpHandlerInternal.java @@ -18,7 +18,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; -import com.google.common.base.Throwables; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -265,7 +264,7 @@ private NamespaceId validateAndGetScopedNamespace(NamespaceId namespace, Artifac // This can only happen when NamespaceAdmin uses HTTP to interact with namespaces. // Within AppFabric, NamespaceAdmin is bound to DefaultNamespaceAdmin which directly interacts with MDS. // Hence, this should never happen. - throw Throwables.propagate(e); + throw new RuntimeException(e); } return namespace; } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/AuthorizationHandler.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/AuthorizationHandler.java index af6697eeb6ff..b293d8ae5efb 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/AuthorizationHandler.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/AuthorizationHandler.java @@ -16,7 +16,7 @@ package io.cdap.cdap.gateway.handlers; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.common.reflect.TypeToken; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -33,10 +33,8 @@ import io.cdap.cdap.proto.codec.EntityIdTypeAdapter; import io.cdap.cdap.proto.id.EntityId; import io.cdap.cdap.proto.security.Action; -import io.cdap.cdap.proto.security.Authorizable; import io.cdap.cdap.proto.security.AuthorizationRequest; import io.cdap.cdap.proto.security.GrantRequest; -import io.cdap.cdap.proto.security.GrantedPermission; import io.cdap.cdap.proto.security.Permission; import io.cdap.cdap.proto.security.PermissionAdapterFactory; import io.cdap.cdap.proto.security.Principal; @@ -326,7 +324,7 @@ private void ensureSecurityEnabled() throws FeatureDisabledException { private void createLogEntry(HttpRequest httpRequest, HttpResponseStatus responseStatus) throws UnknownHostException { InetAddress clientAddr = InetAddress.getByName( - Objects.firstNonNull(SecurityRequestContext.getUserIp(), "0.0.0.0")); + MoreObjects.firstNonNull(SecurityRequestContext.getUserIp(), "0.0.0.0")); AuditLogEntry logEntry = new AuditLogEntry(httpRequest, clientAddr.getHostAddress()); logEntry.setUserName(authenticationContext.getPrincipal().getName()); logEntry.setResponse(responseStatus.code(), 0L); @@ -334,7 +332,7 @@ private void createLogEntry(HttpRequest httpRequest, HttpResponseStatus response } private Set getRequestPermissions(AuthorizationRequest request) { - Set permissions = Objects.firstNonNull(request.getPermissions(), + Set permissions = MoreObjects.firstNonNull(request.getPermissions(), Collections.emptySet()); if (request.getActions() != null) { permissions = Stream.concat(permissions.stream(), diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/DatasetServiceStore.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/DatasetServiceStore.java index 795e8d771e93..811dbc90c289 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/DatasetServiceStore.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/DatasetServiceStore.java @@ -17,9 +17,10 @@ package io.cdap.cdap.gateway.handlers; import com.google.common.base.Preconditions; -import com.google.common.collect.DiscreteDomains; +import com.google.common.collect.ContiguousSet; +import com.google.common.collect.DiscreteDomain; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Ranges; +import com.google.common.collect.Range; import com.google.common.util.concurrent.AbstractIdleService; import com.google.gson.Gson; import com.google.inject.Inject; @@ -120,8 +121,8 @@ public synchronized void setRestartAllInstancesRequest(String serviceName, long RestartStatus status = isSuccess ? RestartStatus.SUCCESS : RestartStatus.FAILURE; Integer serviceInstance = getServiceInstance(serviceName); int instanceCount = (serviceInstance == null) ? 0 : serviceInstance; - Set instancesToRestart = Ranges.closedOpen(0, instanceCount) - .asSet(DiscreteDomains.integers()); + Set instancesToRestart = ContiguousSet.create( + Range.closedOpen(0, instanceCount), DiscreteDomain.integers()); RestartServiceInstancesStatus restartStatus = new RestartServiceInstancesStatus(serviceName, startTimeMs, endTimeMs, status, diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/JsonListResponder.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/JsonListResponder.java index b50f2f2672fa..5e90a9e8e580 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/JsonListResponder.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/JsonListResponder.java @@ -16,7 +16,6 @@ package io.cdap.cdap.gateway.handlers; -import com.google.common.base.Throwables; import com.google.gson.Gson; import com.google.gson.stream.JsonWriter; import io.cdap.http.ChunkResponder; @@ -83,7 +82,7 @@ public void send(Object value) { prepareWrite(); gson.toJson(value, value.getClass(), jsonWriter); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/ProgramScheduleHttpHandler.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/ProgramScheduleHttpHandler.java index cf3028ba0c8e..5fd4a346f3bb 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/ProgramScheduleHttpHandler.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/ProgramScheduleHttpHandler.java @@ -18,7 +18,7 @@ import com.google.common.base.Charsets; import com.google.common.base.Joiner; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; @@ -37,15 +37,12 @@ import io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule; import io.cdap.cdap.internal.app.runtime.schedule.ProgramScheduleRecord; import io.cdap.cdap.internal.app.runtime.schedule.ProgramScheduleStatus; -import io.cdap.cdap.internal.app.runtime.schedule.SchedulerException; import io.cdap.cdap.internal.app.runtime.schedule.store.Schedulers; -import io.cdap.cdap.internal.app.runtime.schedule.trigger.ProgramStatusTrigger; import io.cdap.cdap.internal.app.services.ProgramLifecycleService; import io.cdap.cdap.internal.app.store.ApplicationMeta; import io.cdap.cdap.internal.schedule.constraint.Constraint; import io.cdap.cdap.proto.BatchProgram; import io.cdap.cdap.proto.BatchProgramSchedule; -import io.cdap.cdap.proto.ProgramStatus; import io.cdap.cdap.proto.ProgramType; import io.cdap.cdap.proto.ProtoTrigger; import io.cdap.cdap.proto.ScheduleDetail; @@ -592,13 +589,13 @@ private void doAddSchedule(FullHttpRequest request, HttpResponder responder, Str // Schedules are versionless lifecycleService.ensureLatestProgramExists(programId.getProgramReference()); - String description = Objects.firstNonNull(scheduleFromRequest.getDescription(), ""); - Map properties = Objects.firstNonNull(scheduleFromRequest.getProperties(), + String description = MoreObjects.firstNonNull(scheduleFromRequest.getDescription(), ""); + Map properties = MoreObjects.firstNonNull(scheduleFromRequest.getProperties(), Collections.emptyMap()); - List constraints = Objects.firstNonNull( + List constraints = MoreObjects.firstNonNull( scheduleFromRequest.getConstraints(), NO_CONSTRAINTS); long timeoutMillis = - Objects.firstNonNull(scheduleFromRequest.getTimeoutMillis(), + MoreObjects.firstNonNull(scheduleFromRequest.getTimeoutMillis(), Schedulers.JOB_QUEUE_TIMEOUT_MILLIS); ProgramSchedule schedule = new ProgramSchedule(scheduleName, description, programId, properties, scheduleFromRequest.getTrigger(), constraints, timeoutMillis); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/TransactionHttpHandler.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/TransactionHttpHandler.java index 976dfe936113..4bc1f3b08f4a 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/TransactionHttpHandler.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/TransactionHttpHandler.java @@ -16,7 +16,6 @@ package io.cdap.cdap.gateway.handlers; -import com.google.common.io.Closeables; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.google.inject.Inject; @@ -115,16 +114,28 @@ public ByteBuf nextChunk() throws Exception { @Override public void finished() throws Exception { - Closeables.closeQuietly(in); + try { + in.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup after sending content. + } } @Override public void handleError(@Nullable Throwable cause) { - Closeables.closeQuietly(in); + try { + in.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup after error handling. + } } }, EmptyHttpHeaders.INSTANCE); } catch (Exception e) { - Closeables.closeQuietly(in); + try { + in.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup on exception. + } throw e; } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/util/AbstractAppFabricHttpHandler.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/util/AbstractAppFabricHttpHandler.java index 138acef07b1d..959820e301f4 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/util/AbstractAppFabricHttpHandler.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/util/AbstractAppFabricHttpHandler.java @@ -16,12 +16,11 @@ package io.cdap.cdap.gateway.handlers.util; +import com.google.common.base.Throwables; import com.google.common.base.Function; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; -import com.google.common.io.Closeables; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonSyntaxException; @@ -111,7 +110,13 @@ protected T parseBody(FullHttpRequest request, Type type) LOG.info("Failed to parse body on {} as {}", request.uri(), type, e); throw e; } finally { - Closeables.closeQuietly(reader); + try { + + reader.close(); + + } catch (Exception ignored) { + + } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/util/NamespaceHelper.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/util/NamespaceHelper.java index 63224673bef9..d5aad55cb1e6 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/util/NamespaceHelper.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/util/NamespaceHelper.java @@ -16,7 +16,6 @@ package io.cdap.cdap.gateway.handlers.util; -import com.google.common.base.Throwables; import io.cdap.cdap.common.NamespaceNotFoundException; import io.cdap.cdap.common.namespace.NamespaceQueryAdmin; import io.cdap.cdap.proto.id.NamespaceId; @@ -49,7 +48,7 @@ public static NamespaceId validateNamespace(NamespaceQueryAdmin namespaceQueryAd // This can only happen when NamespaceAdmin uses HTTP to interact with namespaces. // Within AppFabric, NamespaceAdmin is bound to DefaultNamespaceAdmin which directly interacts with MDS. // Hence, this should never happen. - throw Throwables.propagate(e); + throw new RuntimeException(e); } return namespaceId; } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/AbstractInMemoryProgramRunner.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/AbstractInMemoryProgramRunner.java index 249fcc43a678..8f45174eedc0 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/AbstractInMemoryProgramRunner.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/AbstractInMemoryProgramRunner.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app; import com.google.common.base.Function; -import com.google.common.base.Throwables; import com.google.common.collect.HashBasedTable; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -101,10 +100,10 @@ public ListenableFuture apply(ProgramController controller) { } })).get(); - throw Throwables.propagate(t); + throw new RuntimeException(t); } catch (Exception e) { LOG.error("Failed to stop all program instances upon startup failure.", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/DefaultPluginConfigurer.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/DefaultPluginConfigurer.java index 804d17e6de1d..8a311b70504e 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/DefaultPluginConfigurer.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/DefaultPluginConfigurer.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app; -import com.google.common.base.Throwables; import com.google.common.collect.Iterables; import io.cdap.cdap.api.artifact.ArtifactScope; import io.cdap.cdap.api.macro.InvalidMacroException; @@ -90,7 +89,7 @@ public final T usePlugin(String pluginType, String pluginName, String plugin return null; } catch (ClassNotFoundException e) { // Shouldn't happen - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -108,7 +107,7 @@ public final Class usePluginClass(String pluginType, String pluginName, S return null; } catch (ClassNotFoundException e) { // Shouldn't happen - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/DefaultServicePluginConfigurer.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/DefaultServicePluginConfigurer.java index aa189d614d14..eff0bc0cc161 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/DefaultServicePluginConfigurer.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/DefaultServicePluginConfigurer.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app; -import com.google.common.base.Throwables; import io.cdap.cdap.api.macro.MacroEvaluator; import io.cdap.cdap.api.macro.MacroParserOptions; import io.cdap.cdap.api.plugin.Plugin; @@ -75,7 +74,7 @@ public T usePlugin(String pluginType, String pluginName, String pluginId, return null; } catch (ClassNotFoundException e) { // Shouldn't happen - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/deploy/InMemoryProgramRunDispatcher.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/deploy/InMemoryProgramRunDispatcher.java index 3bbe1bf42171..b90b96d4664b 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/deploy/InMemoryProgramRunDispatcher.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/deploy/InMemoryProgramRunDispatcher.java @@ -16,15 +16,14 @@ package io.cdap.cdap.internal.app.deploy; +import com.google.common.base.Throwables; import com.google.common.base.Joiner; import com.google.common.base.Strings; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; import com.google.common.hash.Hasher; import com.google.common.hash.Hashing; -import com.google.common.io.Closeables; import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.Inject; import com.google.inject.name.Named; @@ -88,6 +87,7 @@ import java.io.InputStream; import java.net.InetAddress; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; import java.nio.file.Path; @@ -297,10 +297,10 @@ public ProgramController dispatchProgram(ProgramRunDispatcherContext dispatcherC if (artifactsComputeHash && (artifactsComputeHashSnapshot || !artifactDescriptor.getArtifactId().getVersion().isSnapshot())) { Hasher hasher = Hashing.sha256().newHasher(); - hasher.putString(artifactDescriptor.getNamespace()); - hasher.putString(artifactDescriptor.getArtifactId().getName()); - hasher.putString(artifactDescriptor.getArtifactId().getScope().name()); - hasher.putString(artifactDescriptor.getArtifactId().getVersion().getVersion()); + hasher.putString(artifactDescriptor.getNamespace(), StandardCharsets.UTF_8); + hasher.putString(artifactDescriptor.getArtifactId().getName(), StandardCharsets.UTF_8); + hasher.putString(artifactDescriptor.getArtifactId().getScope().name(), StandardCharsets.UTF_8); + hasher.putString(artifactDescriptor.getArtifactId().getVersion().getVersion(), StandardCharsets.UTF_8); Map arguments = new HashMap<>(options.getArguments().asMap()); arguments.put(ProgramOptionConstants.PROGRAM_JAR_HASH, getArtifactHash(hasher)); @@ -446,7 +446,7 @@ protected Program createProgram(CConfiguration cConf, ProgramRunner programRunne throw ioe; } catch (Exception e) { // should not happen - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -493,7 +493,13 @@ private Runnable createCleanupTask(final Object... resources) { file.delete(); } } else if (resource instanceof Closeable) { - Closeables.closeQuietly((Closeable) resource); + try { + + ((Closeable) resource).close(); + + } catch (Exception ignored) { + + } } else if (resource instanceof Runnable) { ((Runnable) resource).run(); } @@ -558,9 +564,9 @@ private ProgramOptions updateProgramOptions(ArtifactId artifactId, ProgramId pro } private static void hashArtifactId(Hasher hasher, ArtifactId artifactId) { - hasher.putString(artifactId.getParent().toString()); - hasher.putString(artifactId.getArtifact()); - hasher.putString(artifactId.getVersion()); + hasher.putString(artifactId.getParent().toString(), StandardCharsets.UTF_8); + hasher.putString(artifactId.getArtifact(), StandardCharsets.UTF_8); + hasher.putString(artifactId.getVersion(), StandardCharsets.UTF_8); } /** @@ -673,7 +679,7 @@ private void copyArtifact(ArtifactId artifactId, File targetFile, boolean isDist } catch (Exception e) { Throwables.propagateIfPossible(e, IOException.class); // should not happen - throw Throwables.propagate(e); + throw new RuntimeException(e); } } else { operation.call(); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/namespace/NamespaceExistenceVerifier.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/namespace/NamespaceExistenceVerifier.java index 92a9cc46162b..5d3c9b0b2b73 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/namespace/NamespaceExistenceVerifier.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/namespace/NamespaceExistenceVerifier.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.namespace; -import com.google.common.base.Throwables; import com.google.inject.Inject; import io.cdap.cdap.common.NamespaceNotFoundException; import io.cdap.cdap.common.NotFoundException; @@ -44,7 +43,7 @@ public void ensureExists(NamespaceId namespaceId) throws NotFoundException { try { exists = namespaceQueryAdmin.exists(namespaceId); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } if (!exists) { throw new NamespaceNotFoundException(namespaceId); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/DefaultDataTracer.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/DefaultDataTracer.java index d03b3199cadf..8dad1aff5a8e 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/DefaultDataTracer.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/DefaultDataTracer.java @@ -13,9 +13,10 @@ * License for the specific language governing permissions and limitations under * the License. */ - package io.cdap.cdap.internal.app.preview; +import com.google.gson.ExclusionStrategy; +import com.google.gson.FieldAttributes; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import io.cdap.cdap.api.data.format.StructuredRecord; @@ -31,17 +32,15 @@ import io.cdap.cdap.proto.id.ApplicationId; /** - * Default implementation of {@link DataTracer}, the data are preserved using {@link PreviewStore}. + * Default implementation of {@link DataTracer}, the data are preserved using {@link PreviewStore} */ class DefaultDataTracer implements DataTracer { private static final Gson GSON = new GsonBuilder().registerTypeAdapter(Schema.class, new SchemaTypeAdapter()) - // Starting java 9, some java internal modules are private and cannot be used by current - // version of gson. https://cdap.atlassian.net/browse/CDAP-21212 - .setExclusionStrategies(new com.google.gson.ExclusionStrategy() { + .setExclusionStrategies(new ExclusionStrategy() { @Override - public boolean shouldSkipField(com.google.gson.FieldAttributes f) { + public boolean shouldSkipField(FieldAttributes f) { return false; } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/DefaultPreviewManager.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/DefaultPreviewManager.java index 0f7ef6d06697..5d0f393fb61e 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/DefaultPreviewManager.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/DefaultPreviewManager.java @@ -191,7 +191,7 @@ public class DefaultPreviewManager extends AbstractIdleService implements Previe protected void startUp() throws Exception { previewInjector = createPreviewInjector(); StoreDefinition.createAllTables(previewInjector.getInstance(StructuredTableAdmin.class)); - metricsCollectionService.start(); + metricsCollectionService.startAsync(); logAppender = previewInjector.getInstance(LogAppender.class); logAppender.start(); LoggingContextAccessor.setLoggingContext( @@ -199,10 +199,10 @@ protected void startUp() throws Exception { Constants.Logging.COMPONENT_NAME, Constants.Service.PREVIEW_HTTP)); logSubscriberService = previewInjector.getInstance(PreviewTMSLogSubscriber.class); - logSubscriberService.startAndWait(); + logSubscriberService.startAsync().awaitRunning(); dataSubscriberService = previewInjector.getInstance(PreviewDataSubscriberService.class); - dataSubscriberService.startAndWait(); - previewDataCleanupService.startAndWait(); + dataSubscriberService.startAsync().awaitRunning(); + previewDataCleanupService.startAsync().awaitRunning(); } @Override @@ -449,7 +449,7 @@ private Principal encryptCredential() { private void stopQuietly(Service service) { try { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } catch (Exception e) { LOG.warn("Exception when stopping service {}", service, e); } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/DefaultPreviewRunner.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/DefaultPreviewRunner.java index 1754eb19f496..d646136d6f01 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/DefaultPreviewRunner.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/DefaultPreviewRunner.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.preview; import com.google.common.util.concurrent.AbstractIdleService; -import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Service; import com.google.common.util.concurrent.Uninterruptibles; import com.google.gson.Gson; @@ -329,10 +328,10 @@ protected void startUp() throws Exception { LOG.debug("Starting preview runner service"); StoreDefinition.createAllTables(structuredTableAdmin); if (messagingService instanceof Service) { - ((Service) messagingService).startAndWait(); + ((Service) messagingService).startAsync().awaitRunning(); } - dsOpExecService.startAndWait(); - datasetService.startAndWait(); + dsOpExecService.startAsync().awaitRunning(); + datasetService.startAsync().awaitRunning(); // It is recommended to initialize log appender after datasetService is started, // since log appender instantiates a dataset. @@ -342,13 +341,16 @@ protected void startUp() throws Exception { new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, Constants.Service.PREVIEW_HTTP)); - Futures.allAsList( - applicationLifecycleService.start(), - programRuntimeService.start(), - metricsCollectionService.start(), - programNotificationSubscriberService.start(), - programStopSubscriberService.start() - ).get(); + applicationLifecycleService.startAsync(); + programRuntimeService.startAsync(); + metricsCollectionService.startAsync(); + programNotificationSubscriberService.startAsync(); + programStopSubscriberService.startAsync(); + applicationLifecycleService.awaitRunning(); + programRuntimeService.awaitRunning(); + metricsCollectionService.awaitRunning(); + programNotificationSubscriberService.awaitRunning(); + programStopSubscriberService.awaitRunning(); Files.createDirectories(previewIdDirPath); @@ -375,16 +377,16 @@ protected void startUp() throws Exception { @Override protected void shutDown() throws Exception { LOG.debug("Stopping preview runner service"); - programRuntimeService.stopAndWait(); - applicationLifecycleService.stopAndWait(); + programRuntimeService.stopAsync().awaitTerminated(); + applicationLifecycleService.stopAsync().awaitTerminated(); logAppenderInitializer.close(); - metricsCollectionService.stopAndWait(); - programNotificationSubscriberService.stopAndWait(); - programStopSubscriberService.stopAndWait(); - datasetService.stopAndWait(); - dsOpExecService.stopAndWait(); + metricsCollectionService.stopAsync().awaitTerminated(); + programNotificationSubscriberService.stopAsync().awaitTerminated(); + programStopSubscriberService.stopAsync().awaitTerminated(); + datasetService.stopAsync().awaitTerminated(); + dsOpExecService.stopAsync().awaitTerminated(); if (messagingService instanceof Service) { - ((Service) messagingService).stopAndWait(); + ((Service) messagingService).stopAsync().awaitTerminated(); } levelDBTableService.close(); } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/PreviewRunnerService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/PreviewRunnerService.java index 7ff51c9e54e9..7bf644df5013 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/PreviewRunnerService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/PreviewRunnerService.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.preview; -import com.google.common.base.Throwables; import com.google.common.util.concurrent.AbstractExecutionThreadService; import com.google.common.util.concurrent.Uninterruptibles; import com.google.inject.Inject; @@ -139,7 +138,7 @@ private PreviewRequest getPreviewRequest() throws IOException, UnauthorizedExcep } catch (IOException | UnauthorizedException e) { throw e; } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/PreviewRunnerTwillRunnable.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/PreviewRunnerTwillRunnable.java index 16eae6e73bfa..ba5f475f32e9 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/PreviewRunnerTwillRunnable.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/PreviewRunnerTwillRunnable.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.preview; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.Service; import com.google.common.util.concurrent.Uninterruptibles; @@ -34,7 +33,6 @@ import io.cdap.cdap.app.deploy.Configurator; import io.cdap.cdap.app.guice.AuditLogWriterModule; import io.cdap.cdap.app.preview.PreviewConfigModule; -import io.cdap.cdap.app.preview.PreviewRunner; import io.cdap.cdap.app.preview.PreviewRunnerManager; import io.cdap.cdap.app.preview.PreviewRunnerManagerModule; import io.cdap.cdap.common.conf.CConfiguration; @@ -86,11 +84,9 @@ import org.apache.tephra.TransactionSystemClient; import org.apache.twill.api.AbstractTwillRunnable; import org.apache.twill.api.TwillContext; -import org.apache.twill.api.TwillRunnable; import org.apache.twill.common.Threads; import org.apache.twill.discovery.DiscoveryService; import org.apache.twill.discovery.DiscoveryServiceClient; -import org.apache.twill.internal.ServiceListenerAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -116,7 +112,11 @@ public void initialize(TwillContext context) { try { doInitialize(context); } catch (Exception e) { - Throwables.propagateIfPossible(e); + if (e instanceof RuntimeException) { + + throw (RuntimeException) e; + + } throw new RuntimeException(e); } } @@ -124,7 +124,7 @@ public void initialize(TwillContext context) { @Override public void run() { CompletableFuture future = new CompletableFuture<>(); - previewRunnerManager.addListener(new ServiceListenerAdapter() { + previewRunnerManager.addListener(new Service.Listener() { @Override public void terminated(Service.State from) { future.complete(from); @@ -137,7 +137,7 @@ public void failed(Service.State from, Throwable failure) { }, Threads.SAME_THREAD_EXECUTOR); LOG.debug("Starting preview runner manager"); - previewRunnerManager.start(); + previewRunnerManager.startAsync(); try { Uninterruptibles.getUninterruptibly(future); @@ -150,7 +150,7 @@ public void failed(Service.State from, Throwable failure) { @Override public void stop() { LOG.info("Stopping preview runner manager"); - previewRunnerManager.stop(); + previewRunnerManager.stopAsync(); } @Override diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/program/MessagingProgramStatePublisher.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/program/MessagingProgramStatePublisher.java index c1cba7557f60..8e05774676bd 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/program/MessagingProgramStatePublisher.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/program/MessagingProgramStatePublisher.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.program; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.inject.Inject; @@ -151,7 +150,7 @@ public void publish(Notification.Type notificationType, Map prop long retryMillis = retryStrategy.nextRetry(++failureCount, startTime); if (retryMillis < 0) { LOG.error("Failed to publish messages to TMS and exceeded retry limit.", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } LOG.debug("Failed to publish messages to TMS due to {}. Will be retried in {} ms.", e.getMessage(), retryMillis); @@ -164,7 +163,7 @@ public void publish(Notification.Type notificationType, Map prop done = true; } } catch (AccessException | IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/AbstractProgramController.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/AbstractProgramController.java index fd3b1ea2cea7..4fa2abf41224 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/AbstractProgramController.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/AbstractProgramController.java @@ -16,9 +16,9 @@ package io.cdap.cdap.internal.app.runtime; +import com.google.common.base.Throwables; import com.google.common.base.Objects; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; @@ -246,7 +246,7 @@ public final Cancellable addListener(Listener listener, final Executor listenerE // Not expecting exception since the Callable only do action on Map and calling caller.init, which // already have exceptions handled inside the method. Also, we never shutdown the executor explicitly, // there shouldn't be interrupted exception as well. - throw Throwables.propagate(Throwables.getRootCause(e)); + throw new RuntimeException(Throwables.getRootCause(e)); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/AbstractProgramRunnerWithPlugin.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/AbstractProgramRunnerWithPlugin.java index 4681ade570e4..16601d3c6472 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/AbstractProgramRunnerWithPlugin.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/AbstractProgramRunnerWithPlugin.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.runtime; -import com.google.common.io.Closeables; import com.google.common.util.concurrent.Service; import io.cdap.cdap.app.runtime.ProgramOptions; import io.cdap.cdap.app.runtime.ProgramRunner; @@ -25,7 +24,6 @@ import java.io.Closeable; import java.io.File; import javax.annotation.Nullable; -import org.apache.twill.internal.ServiceListenerAdapter; /** * Provides method to create {@link PluginInstantiator} for Program Runners @@ -61,7 +59,7 @@ protected PluginInstantiator createPluginInstantiator(ProgramOptions options, * Creates a service listener to cleanup closeables. */ protected Service.Listener createRuntimeServiceListener(final Iterable closeables) { - return new ServiceListenerAdapter() { + return new Service.Listener() { @Override public void terminated(Service.State from) { closeAllQuietly(closeables); @@ -76,7 +74,13 @@ public void failed(Service.State from, @Nullable final Throwable failure) { protected void closeAllQuietly(Iterable closeables) { for (Closeable c : closeables) { - Closeables.closeQuietly(c); + try { + + c.close(); + + } catch (Exception ignored) { + + } } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/DefaultPluginContext.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/DefaultPluginContext.java index fe0902c255ed..b33a750c007b 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/DefaultPluginContext.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/DefaultPluginContext.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.runtime; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import io.cdap.cdap.api.feature.FeatureFlagsProvider; import io.cdap.cdap.api.macro.MacroEvaluator; import io.cdap.cdap.api.plugin.InvalidPluginConfigException; @@ -77,7 +76,7 @@ public Class loadPluginClass(String pluginId) { throw new IllegalArgumentException("Plugin class not found", e); } catch (IOException e) { // This is fatal, since jar cannot be expanded. - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -102,7 +101,7 @@ public T newPluginInstance(String pluginId, @Nullable MacroEvaluator evaluat throw new IllegalArgumentException("Plugin class not found", e); } catch (IOException e) { // This is fatal, since jar cannot be expanded. - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/LocalizationUtils.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/LocalizationUtils.java index 7c8bab098fdb..1b90995a30ee 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/LocalizationUtils.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/LocalizationUtils.java @@ -16,15 +16,19 @@ package io.cdap.cdap.internal.app.runtime; -import com.google.common.io.Files; import com.google.common.io.Resources; import io.cdap.cdap.common.io.Locations; import io.cdap.cdap.internal.app.runtime.distributed.LocalizeResource; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.net.URI; import java.net.URL; +import java.nio.file.Files; import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,11 +58,12 @@ public static File localizeResource(String fileName, LocalizeResource resource, } else { try { LOG.debug("Hard link file from {} to {}", input, localizedResource); - java.nio.file.Files.createLink(Paths.get(localizedResource.toURI()), + Files.createLink(Paths.get(localizedResource.toURI()), Paths.get(input.toURI())); } catch (Exception e) { LOG.debug("Copy file from {} to {}", input, localizedResource); - Files.copy(input, localizedResource); + Files.copy(input.toPath(), localizedResource.toPath(), + StandardCopyOption.REPLACE_EXISTING); } } return localizedResource; @@ -84,7 +89,10 @@ private static File getFileToLocalize(LocalizeResource resource, File tempDir) URL url = uri.toURL(); String name = new File(uri.getPath()).getName(); File tempFile = new File(tempDir, name); - Files.copy(Resources.newInputStreamSupplier(url), tempFile); + try (InputStream in = Resources.asByteSource(url).openStream(); + OutputStream out = new FileOutputStream(tempFile)) { + com.google.common.io.ByteStreams.copy(in, out); + } return tempFile; } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/ProgramControllerServiceAdapter.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/ProgramControllerServiceAdapter.java index 5a1c4b8159a0..6540addbc716 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/ProgramControllerServiceAdapter.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/ProgramControllerServiceAdapter.java @@ -18,12 +18,10 @@ import com.google.common.util.concurrent.Service; import io.cdap.cdap.api.exception.WrappedStageException; -import io.cdap.cdap.app.runtime.ProgramController; import io.cdap.cdap.common.conf.Constants; import io.cdap.cdap.common.logging.Loggers; import io.cdap.cdap.proto.id.ProgramRunId; import org.apache.twill.common.Threads; -import org.apache.twill.internal.ServiceListenerAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,7 +62,7 @@ protected void doStop() throws Exception { stopRequested = true; long gracefulTimeoutMillis = getGracefulTimeoutMillis(); if (gracefulTimeoutMillis < 0) { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } else { gracefulStop(gracefulTimeoutMillis); } @@ -77,7 +75,7 @@ protected void doStop() throws Exception { * supports graceful termination with timeout. */ protected void gracefulStop(long gracefulTimeoutMillis) { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } @Override @@ -86,7 +84,7 @@ protected void doCommand(String name, Object value) throws Exception { } private void listenToRuntimeState(Service service) { - service.addListener(new ServiceListenerAdapter() { + service.addListener(new Service.Listener() { @Override public void running() { started(); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/ProgramRunners.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/ProgramRunners.java index c5b402e31a6c..075bbdb4b44b 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/ProgramRunners.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/ProgramRunners.java @@ -24,7 +24,6 @@ import com.google.common.base.Strings; import com.google.common.collect.Maps; import com.google.common.io.ByteStreams; -import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.Service; import io.cdap.cdap.api.metrics.MetricsCollectionService; import io.cdap.cdap.api.metrics.MetricsContext; @@ -32,7 +31,6 @@ import io.cdap.cdap.app.guice.ClusterMode; import io.cdap.cdap.app.runtime.Arguments; import io.cdap.cdap.app.runtime.ProgramOptions; -import io.cdap.cdap.app.runtime.ProgramRunner; import io.cdap.cdap.common.app.RunIds; import io.cdap.cdap.common.conf.Constants; import io.cdap.cdap.common.io.Locations; @@ -75,10 +73,10 @@ public final class ProgramRunners { */ public static void startAsUser(String user, final Service service) throws IOException, InterruptedException { - runAsUser(user, new Callable>() { + runAsUser(user, new Callable() { @Override - public ListenableFuture call() throws Exception { - return service.start(); + public Service call() throws Exception { + return service.startAsync(); } }); } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/AbstractArtifactManager.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/AbstractArtifactManager.java index 4bc0ff98aa64..d3b7d215d22b 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/AbstractArtifactManager.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/AbstractArtifactManager.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.runtime.artifact; -import com.google.common.io.Closeables; import io.cdap.cdap.api.artifact.ArtifactInfo; import io.cdap.cdap.api.artifact.ArtifactManager; import io.cdap.cdap.api.artifact.CloseableClassLoader; @@ -113,8 +112,20 @@ private ClassLoaderCleanup(DirectoryClassLoader directoryClassLoader, @Override public void close() throws IOException { - Closeables.closeQuietly(directoryClassLoader); - Closeables.closeQuietly(folder); + try { + + directoryClassLoader.close(); + + } catch (Exception ignored) { + + } + try { + + folder.close(); + + } catch (Exception ignored) { + + } } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/ArtifactClassLoaderFactory.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/ArtifactClassLoaderFactory.java index 2704901782c1..896a13d6be07 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/ArtifactClassLoaderFactory.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/ArtifactClassLoaderFactory.java @@ -17,8 +17,6 @@ package io.cdap.cdap.internal.app.runtime.artifact; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; -import com.google.common.io.Closeables; import io.cdap.cdap.api.artifact.CloseableClassLoader; import io.cdap.cdap.common.conf.CConfiguration; import io.cdap.cdap.common.conf.Constants; @@ -104,10 +102,18 @@ CloseableClassLoader createClassLoader(File unpackDir) { final ClassLoader finalSparkClassLoader = sparkClassLoader; return new CloseableClassLoader(programClassLoader, () -> { if (finalProgramClassLoader instanceof Closeable) { - Closeables.closeQuietly((Closeable) finalProgramClassLoader); + try { + ((Closeable) finalProgramClassLoader).close(); + } catch (Exception ignored) { + // Ignored because we are closing the classloader and cleaning up resources. + } } if (finalSparkClassLoader instanceof Closeable) { - Closeables.closeQuietly((Closeable) finalSparkClassLoader); + try { + ((Closeable) finalSparkClassLoader).close(); + } catch (Exception ignored) { + // Ignored because we are closing the classloader and cleaning up resources. + } } }); } @@ -130,11 +136,19 @@ CloseableClassLoader createClassLoader(Location artifactLocation, CloseableClassLoader classLoader = createClassLoader(classLoaderFolder.getDir()); return new CloseableClassLoader(classLoader, () -> { - Closeables.closeQuietly(classLoader); - Closeables.closeQuietly(classLoaderFolder); + try { + classLoader.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup on close. + } + try { + classLoaderFolder.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup on close. + } }); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -167,11 +181,19 @@ CloseableClassLoader createClassLoader(Iterator artifactLocations, entityImpersonator); return new CloseableClassLoader(new DirectoryClassLoader(classLoaderFolder.getDir(), parentClassLoader, "lib"), () -> { - Closeables.closeQuietly(parentClassLoader); - Closeables.closeQuietly(classLoaderFolder); + try { + parentClassLoader.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup on close. + } + try { + classLoaderFolder.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup on close. + } }); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/ArtifactExistenceVerifier.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/ArtifactExistenceVerifier.java index c9d7617fc633..4ca7f14e488b 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/ArtifactExistenceVerifier.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/ArtifactExistenceVerifier.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.runtime.artifact; -import com.google.common.base.Throwables; import com.google.inject.Inject; import io.cdap.cdap.common.ArtifactNotFoundException; import io.cdap.cdap.common.entity.EntityExistenceVerifier; @@ -41,7 +40,7 @@ public void ensureExists(ArtifactId artifactId) throws ArtifactNotFoundException try { artifactStore.getArtifact(Id.Artifact.fromEntityId(artifactId)); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/ArtifactStore.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/ArtifactStore.java index ac5f4bfa5683..3aa258eb7cda 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/ArtifactStore.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/ArtifactStore.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.runtime.artifact; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -411,7 +410,7 @@ public ArtifactDetail getArtifact(final Id.Artifact artifactId) return new ArtifactDetail(new ArtifactDescriptor(artifactId.getNamespace().getId(), artifactId.toArtifactId(), artifactLocation), artifactMeta); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -756,8 +755,12 @@ public ArtifactDetail write( try { destination = copyFileToDestination(artifactId, artifactContent, entityImpersonator); } catch (Exception e) { - Throwables.propagateIfInstanceOf(e, IOException.class); - throw Throwables.propagate(e); + if (e instanceof IOException) { + + throw (IOException) e; + + } + throw new RuntimeException(e); } // now try and write the metadata for the artifact @@ -1066,7 +1069,7 @@ private void deleteMeta(StructuredTableContext context, Id.Artifact artifactId, throw ioe; } catch (Exception e) { // this should not happen - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/DefaultArtifactInspector.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/DefaultArtifactInspector.java index 662695ff324d..d338943f9cde 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/DefaultArtifactInspector.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/DefaultArtifactInspector.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.runtime.artifact; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import com.google.common.collect.Maps; import com.google.common.primitives.Primitives; import com.google.common.reflect.TypeToken; @@ -386,13 +385,13 @@ private Iterable> getPluginClasses(Collection packages, return pluginClassLoader.loadClass(className); } catch (ClassNotFoundException | NoClassDefFoundError e) { // Cannot happen, since the class name is from the list of the class files under the classloader. - throw Throwables.propagate(e); + throw new RuntimeException(e); } }) .collect(Collectors.toList()); } catch (IOException e) { // Cannot happen - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/LocalPluginFinder.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/LocalPluginFinder.java index 0247d6ffbd98..69b49f43c0cb 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/LocalPluginFinder.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/LocalPluginFinder.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.runtime.artifact; -import com.google.common.base.Throwables; import com.google.inject.Inject; import io.cdap.cdap.api.artifact.ArtifactRange; import io.cdap.cdap.api.artifact.ArtifactVersion; @@ -56,7 +55,7 @@ public Map.Entry findPlugin(NamespaceId pluginN selector); } catch (IOException | ArtifactNotFoundException e) { // If there is error accessing artifact store or if the parent artifact is missing, just propagate - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/RemoteArtifactManager.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/RemoteArtifactManager.java index 2c638f38b440..388856347b48 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/RemoteArtifactManager.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/RemoteArtifactManager.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.runtime.artifact; -import com.google.common.base.Throwables; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.inject.Inject; @@ -124,7 +123,7 @@ public List listArtifacts(String namespace) } catch (UnauthorizedException | IOException e) { throw e; } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/RemotePluginFinder.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/RemotePluginFinder.java index f142b16e60b6..c86e9df02969 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/RemotePluginFinder.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/artifact/RemotePluginFinder.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.runtime.artifact; -import com.google.common.base.Throwables; import com.google.common.collect.Maps; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -141,7 +140,7 @@ public Map.Entry findPlugin(NamespaceId pluginN } catch (ArtifactNotFoundException e) { throw new PluginNotExistsException(pluginNamespaceId, pluginType, pluginName); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/BasicMapReduceTaskContext.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/BasicMapReduceTaskContext.java index 1ca6516129fd..bf961e4f992f 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/BasicMapReduceTaskContext.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/BasicMapReduceTaskContext.java @@ -17,8 +17,6 @@ package io.cdap.cdap.internal.app.runtime.batch; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; @@ -69,7 +67,6 @@ import io.cdap.cdap.messaging.spi.MessagingService; import io.cdap.cdap.proto.id.NamespaceId; import io.cdap.cdap.proto.id.TopicId; -import io.cdap.cdap.proto.security.Principal; import io.cdap.cdap.security.spi.authentication.AuthenticationContext; import io.cdap.cdap.security.spi.authorization.AccessEnforcer; import io.cdap.cdap.security.spi.authorization.UnauthorizedException; @@ -485,7 +482,7 @@ public List getSplits() { flushOperations(); } } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -501,7 +498,7 @@ public void close() { flushOperations(); } } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } }; @@ -531,7 +528,11 @@ public void close() throws IOException { try { flushOperations(); } catch (Exception e) { - Throwables.propagateIfInstanceOf(e, IOException.class); + if (e instanceof IOException) { + + throw (IOException) e; + + } throw new IOException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MainOutputCommitter.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MainOutputCommitter.java index 052e0ff06303..d13e740bdb74 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MainOutputCommitter.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MainOutputCommitter.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.runtime.batch; -import com.google.common.base.Throwables; import com.google.inject.Injector; import io.cdap.cdap.api.data.batch.DatasetOutputCommitter; import io.cdap.cdap.app.guice.ClusterMode; @@ -169,8 +168,12 @@ private void commitTx(Transaction transaction) throws IOException { } taskContext.postTxCommit(); } catch (Exception e) { - Throwables.propagateIfInstanceOf(e, IOException.class); - throw Throwables.propagate(e); + if (e instanceof IOException) { + + throw (IOException) e; + + } + throw new RuntimeException(e); } } @@ -204,8 +207,12 @@ private void onFinish(JobContext jobContext, boolean success) throws IOException } finishDatasets(jobContext, success); } catch (Exception e) { - Throwables.propagateIfInstanceOf(e, IOException.class); - throw Throwables.propagate(e); + if (e instanceof IOException) { + + throw (IOException) e; + + } + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceClassLoader.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceClassLoader.java index 2d3c264cda65..a1998e731478 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceClassLoader.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceClassLoader.java @@ -16,10 +16,9 @@ package io.cdap.cdap.internal.app.runtime.batch; -import com.google.common.base.Optional; +import java.util.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Supplier; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.Service; import com.google.inject.Injector; @@ -38,12 +37,9 @@ import io.cdap.cdap.internal.app.runtime.ProgramClassLoader; import io.cdap.cdap.internal.app.runtime.ProgramRunners; import io.cdap.cdap.internal.app.runtime.batch.distributed.DistributedMapReduceTaskContextProvider; -import io.cdap.cdap.internal.app.runtime.batch.distributed.MapReduceContainerLauncher; import io.cdap.cdap.internal.app.runtime.plugin.PluginClassLoaders; import io.cdap.cdap.internal.app.runtime.plugin.PluginInstantiator; import io.cdap.cdap.logging.context.LoggingContextHelper; -import io.cdap.cdap.logging.context.MapReduceLoggingContext; -import io.cdap.cdap.logging.context.WorkflowProgramLoggingContext; import io.cdap.cdap.proto.id.ProgramId; import java.io.File; import java.io.IOException; @@ -150,10 +146,10 @@ public MapReduceTaskContextProvider getTaskContextProvider() { LoggingContextAccessor.setLoggingContext(loggingContext); synchronized (this) { - taskContextProvider = Optional.fromNullable(taskContextProvider) - .or(taskContextProviderSupplier); + taskContextProvider = Optional.ofNullable(taskContextProvider) + .orElseGet(taskContextProviderSupplier::get); } - taskContextProvider.startAndWait(); + taskContextProvider.startAsync().awaitRunning(); return taskContextProvider; } @@ -196,7 +192,7 @@ public void close() { if (provider != null) { Service.State state = provider.state(); if (state == Service.State.STARTING || state == Service.State.RUNNING) { - provider.stopAndWait(); + provider.stopAsync().awaitTerminated(); } } } catch (Exception e) { @@ -304,7 +300,7 @@ private static ClassLoader createProgramClassLoader(MapReduceContextConfig conte FilterClassLoader.create(contextConfig.getHConf().getClassLoader())); } catch (IOException e) { LOG.error("Failed to create ProgramClassLoader", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceContextConfig.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceContextConfig.java index fc5b66820395..58f7b0ac8275 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceContextConfig.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceContextConfig.java @@ -19,7 +19,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Charsets; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.google.common.reflect.TypeToken; import com.google.gson.Gson; @@ -240,7 +239,7 @@ private void setConf(CConfiguration conf) { conf.writeXml(stringWriter); } catch (IOException e) { LOG.error("Unable to serialize CConfiguration into xml"); - throw Throwables.propagate(e); + throw new RuntimeException(e); } hConf.set(HCONF_ATTR_CCONF, stringWriter.toString()); } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceProgramController.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceProgramController.java index 74da17e32c92..bc7cc2a11f97 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceProgramController.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceProgramController.java @@ -15,7 +15,6 @@ */ package io.cdap.cdap.internal.app.runtime.batch; -import com.google.common.base.Throwables; import com.google.common.util.concurrent.Service; import io.cdap.cdap.api.lineage.field.Operation; import io.cdap.cdap.api.workflow.WorkflowToken; @@ -53,7 +52,7 @@ public WorkflowToken getWorkflowToken() { workflowTokenFromContext.setMapReduceCounters(((Job) context.getHadoopJob()).getCounters()); return workflowTokenFromContext; } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceProgramRunner.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceProgramRunner.java index d1a39f718efc..3cfc3131f044 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceProgramRunner.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceProgramRunner.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.runtime.batch; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.common.reflect.TypeToken; import com.google.common.util.concurrent.Service; import com.google.inject.Inject; @@ -173,7 +172,7 @@ public ProgramController run(final Program program, ProgramOptions options) { TypeToken.of(program.getMainClass())).create(); } catch (Exception e) { LOG.error("Failed to instantiate MapReduce class for {}", spec.getClassName(), e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } // List of all Closeable resources that needs to be cleanup @@ -231,14 +230,14 @@ public ProgramController run(final Program program, ProgramOptions options) { // tries to access cdap data. For example, writing to a FileSet will fail, as the yarn user will // be running the job, but the data directory will be owned by cdap. if (MapReduceTaskContextProvider.isLocal(hConf) || UserGroupInformation.isSecurityEnabled()) { - mapReduceRuntimeService.start(); + mapReduceRuntimeService.startAsync(); } else { ProgramRunners.startAsUser(cConf.get(Constants.CFG_HDFS_USER), mapReduceRuntimeService); } return controller; } catch (Exception e) { closeAllQuietly(closeables); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceRuntimeService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceRuntimeService.java index c858bbf08fb4..cb2dacc33cf8 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceRuntimeService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceRuntimeService.java @@ -19,10 +19,8 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.common.collect.Sets; import com.google.common.io.ByteStreams; -import com.google.common.io.Files; import com.google.common.reflect.TypeToken; import com.google.common.util.concurrent.AbstractExecutionThreadService; import com.google.inject.Injector; @@ -67,8 +65,11 @@ import io.cdap.cdap.proto.id.ProgramRunId; import io.cdap.cdap.security.store.SecureStoreUtils; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.net.URI; @@ -112,7 +113,6 @@ import org.apache.twill.api.ClassAcceptor; import org.apache.twill.api.Configs; import org.apache.twill.filesystem.Location; -import org.apache.twill.filesystem.LocationFactory; import org.apache.twill.internal.ApplicationBundler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -190,7 +190,7 @@ public void destroy() { } @Override - protected String getServiceName() { + protected String serviceName() { return "MapReduceRunner-" + specification.getName(); } @@ -434,7 +434,7 @@ protected void triggerShutdown() { } } catch (IOException e) { LOG.error("Failed to kill MapReduce job {}", context, e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -454,7 +454,7 @@ public void run() { } }); t.setDaemon(true); - t.setName(getServiceName()); + t.setName(serviceName()); t.start(); } }; @@ -1012,7 +1012,10 @@ private Location createPluginArchive(Location targetDir) throws IOException { */ private Location copyFileToLocation(File file, Location targetDir) throws IOException { Location targetLocation = targetDir.append(file.getName()).getTempFile(".jar"); - Files.copy(file, Locations.newOutputSupplier(targetLocation)); + try (InputStream in = new FileInputStream(file); + OutputStream out = Locations.newOutputSupplier(targetLocation).getOutput()) { + ByteStreams.copy(in, out); + } return targetLocation; } @@ -1024,8 +1027,10 @@ private Location copyFileToLocation(File file, Location targetDir) throws IOExce private Location copyProgramJar(Location targetDir) throws IOException { Location programJarCopy = targetDir.append("program.jar"); - ByteStreams.copy(Locations.newInputSupplier(programJarLocation), - Locations.newOutputSupplier(programJarCopy)); + try (InputStream in = Locations.newInputSupplier(programJarLocation).getInput(); + OutputStream out = Locations.newOutputSupplier(programJarCopy).getOutput()) { + ByteStreams.copy(in, out); + } LOG.debug("Copied Program Jar to {}, source: {}", programJarCopy, programJarLocation); return programJarCopy; } @@ -1222,7 +1227,7 @@ private Map localizeUserResources(Job job, File targetDir) throw } catch (URISyntaxException e) { // Most of the URI is constructed from the passed URI. So ideally, this should not happen. // If it does though, there is nothing that clients can do to recover, so not propagating a checked exception. - throw Throwables.propagate(e); + throw new RuntimeException(e); } if (entry.getValue().isArchive()) { job.addCacheArchive(actualURI); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapperWrapper.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapperWrapper.java index 60c23b9d732d..8e70437dc263 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapperWrapper.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/MapperWrapper.java @@ -198,7 +198,7 @@ public boolean nextKeyValue() throws IOException, InterruptedException { basicMapReduceContext.flushOperations(); } catch (Exception e) { LOG.error("Failed to persist changes", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } processedRecords = 0; } @@ -249,7 +249,7 @@ private Mapper createMapperInstance(ClassLoader classLoader, String userMapper, "Failed to create mapper instance for program '{}' with error: {}. Please check the system logs " + "for more details.", program, rootCause.getMessage(), rootCause); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/ReducerWrapper.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/ReducerWrapper.java index 6ea108609f62..9503f0f76241 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/ReducerWrapper.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/ReducerWrapper.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.runtime.batch; -import com.google.common.base.Throwables; import io.cdap.cdap.api.ProgramLifecycle; import io.cdap.cdap.api.RuntimeContext; import io.cdap.cdap.common.lang.ClassLoaders; @@ -89,7 +88,7 @@ public void run(Context context) throws IOException, InterruptedException { new DataSetFieldSetter(basicMapReduceContext)); } catch (Throwable t) { LOG.error("Failed to inject fields to {}.", delegate.getClass(), t); - throw Throwables.propagate(t); + throw new RuntimeException(t); } ClassLoader oldClassLoader; @@ -100,7 +99,7 @@ public void run(Context context) throws IOException, InterruptedException { new MapReduceLifecycleContext(basicMapReduceContext)); } catch (Exception e) { LOG.error("Failed to initialize reducer with {}", basicMapReduceContext, e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } finally { ClassLoaders.setContextClassLoader(oldClassLoader); } @@ -119,7 +118,7 @@ public void run(Context context) throws IOException, InterruptedException { basicMapReduceContext.flushOperations(); } catch (Exception e) { LOG.error("Failed to flush operations at the end of reducer of " + basicMapReduceContext, e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } // Close all writers created by MultipleOutputs @@ -162,7 +161,7 @@ public boolean nextKeyValue() throws IOException, InterruptedException { basicMapReduceContext.flushOperations(); } catch (Exception e) { LOG.error("Failed to persist changes", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } processedRecords = 0; } @@ -182,7 +181,7 @@ private Reducer createReducerInstance(ClassLoader classLoader, String userReduce return (Reducer) classLoader.loadClass(userReducer).newInstance(); } catch (Exception e) { LOG.error("Failed to create instance of the user-defined Reducer class: " + userReducer); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/WrapperUtil.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/WrapperUtil.java index f9a87f92fa40..326c7ebb75d6 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/WrapperUtil.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/WrapperUtil.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.runtime.batch; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import io.cdap.cdap.api.ProgramLifecycle; import io.cdap.cdap.common.lang.ClassLoaders; import org.apache.hadoop.conf.Configuration; @@ -63,7 +62,7 @@ static T createDelegate(Configuration conf, String attrClass) { return delegate; } catch (Exception e) { LOG.error("Failed to initialize delegate with {}", basicMapReduceContext, e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } finally { ClassLoaders.setContextClassLoader(oldClassLoader); } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/dataset/DataSetInputSplit.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/dataset/DataSetInputSplit.java index 788cff1a535e..70ee9480d5db 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/dataset/DataSetInputSplit.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/dataset/DataSetInputSplit.java @@ -16,10 +16,8 @@ package io.cdap.cdap.internal.app.runtime.batch.dataset; -import com.google.common.base.Throwables; import io.cdap.cdap.api.data.batch.Split; import io.cdap.cdap.api.data.batch.Splits; -import io.cdap.cdap.api.dataset.Dataset; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -72,7 +70,7 @@ public void readFields(final DataInput in) throws IOException { } split = Splits.deserialize(in, classLoader); } catch (ClassNotFoundException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/distributed/DistributedMapReduceTaskContextProvider.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/distributed/DistributedMapReduceTaskContextProvider.java index fcc1cd564e9c..e22469a11e20 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/distributed/DistributedMapReduceTaskContextProvider.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/distributed/DistributedMapReduceTaskContextProvider.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.runtime.batch.distributed; -import com.google.common.io.Closeables; import com.google.common.util.concurrent.Service; import com.google.inject.Guice; import com.google.inject.Injector; @@ -91,7 +90,7 @@ protected void startUp() throws Exception { } for (Service service : coreServices) { - service.startAndWait(); + service.startAsync().awaitRunning(); } } catch (Exception e) { // Try our best to stop services. Chain stop guarantees it will stop everything, even some of them failed. @@ -107,12 +106,18 @@ protected void startUp() throws Exception { @Override protected void shutDown() throws Exception { super.shutDown(); - Closeables.closeQuietly(logAppenderInitializer); + try { + + logAppenderInitializer.close(); + + } catch (Exception ignored) { + + } Exception failure = null; for (Service service : (Iterable) coreServices::descendingIterator) { try { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } catch (Exception e) { if (failure != null) { failure.addSuppressed(e); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/distributed/MapReduceContainerHelper.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/distributed/MapReduceContainerHelper.java index cbe9839cbb16..25406f0549c0 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/distributed/MapReduceContainerHelper.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/batch/distributed/MapReduceContainerHelper.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.runtime.batch.distributed; import com.google.common.base.Splitter; -import com.google.common.base.Throwables; import com.google.common.collect.Iterables; import io.cdap.cdap.internal.app.runtime.LocalizationUtils; import io.cdap.cdap.internal.app.runtime.distributed.LocalizeResource; @@ -143,7 +142,7 @@ public static > T localizeFramework(Conf return result; } catch (URISyntaxException e) { // Shouldn't happen since the frameworkURI is already parsed. - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/AbstractProgramTwillRunnable.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/AbstractProgramTwillRunnable.java index 6c48872f7224..c16ce5838a04 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/AbstractProgramTwillRunnable.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/AbstractProgramTwillRunnable.java @@ -16,9 +16,8 @@ package io.cdap.cdap.internal.app.runtime.distributed; -import com.google.common.base.Preconditions; import com.google.common.base.Throwables; -import com.google.common.io.Closeables; +import com.google.common.base.Preconditions; import com.google.common.reflect.TypeToken; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.Service; @@ -159,7 +158,7 @@ public final void initialize(TwillContext context) { LOG.info("Runnable initialized: {}", name); } catch (Throwable t) { LOG.error(t.getMessage(), t); - throw Throwables.propagate(t); + throw new RuntimeException(t); } } @@ -291,14 +290,26 @@ public void error(Throwable cause) { LOG.warn("Program {} interrupted.", name, e); } catch (ExecutionException e) { LOG.error("Program {} execution failed.", name, e); - throw Throwables.propagate(Throwables.getRootCause(e)); + throw new RuntimeException(Throwables.getRootCause(e)); } finally { LOG.info("Program run {} completed. Releasing resources.", programRunId); // Close the Program and the ProgramRunner - Closeables.closeQuietly(program); + try { + + program.close(); + + } catch (Exception ignored) { + + } if (programRunner instanceof Closeable) { - Closeables.closeQuietly((Closeable) programRunner); + try { + + ((Closeable) programRunner).close(); + + } catch (Exception ignored) { + + } } stopCoreServices(); @@ -351,7 +362,7 @@ public void stop() { System.currentTimeMillis() - startTime); } catch (InterruptedException | ExecutionException | TimeoutException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -483,16 +494,22 @@ private void addOnPremiseServices(Injector injector, ProgramOptions programOptio private void startCoreServices() { // Starts the core services for (Service service : coreServices) { - service.startAndWait(); + service.startAsync().awaitRunning(); } } private void stopCoreServices() { - Closeables.closeQuietly(logAppenderInitializer); + try { + + logAppenderInitializer.close(); + + } catch (Exception ignored) { + + } // Stop all services. Reverse the order. for (Service service : (Iterable) coreServices::descendingIterator) { try { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } catch (Exception e) { LOG.warn("Exception raised when stopping service {} during program termination.", service, e); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/DistributedProgramRunner.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/DistributedProgramRunner.java index 3565c78ee98e..0f75d8f70667 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/DistributedProgramRunner.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/DistributedProgramRunner.java @@ -21,7 +21,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; import com.google.common.base.Strings; -import com.google.common.base.Throwables; import com.google.common.io.Resources; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -104,7 +103,6 @@ import org.apache.twill.api.TwillPreparer; import org.apache.twill.api.TwillRunner; import org.apache.twill.api.logging.LogEntry; -import org.apache.twill.api.logging.LogHandler; import org.apache.twill.common.Cancellable; import org.apache.twill.common.Threads; import org.apache.twill.filesystem.Location; @@ -335,7 +333,7 @@ public final ProgramController run(final Program program, ProgramOptions oldOpti } catch (Exception e) { deleteDirectory(tempDir); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/DistributedWorkflowProgramRunner.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/DistributedWorkflowProgramRunner.java index b3822eb518c5..2ddb8838ff4d 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/DistributedWorkflowProgramRunner.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/DistributedWorkflowProgramRunner.java @@ -18,7 +18,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Maps; -import com.google.common.io.Closeables; import com.google.inject.Inject; import com.google.inject.Injector; import io.cdap.cdap.api.Resources; @@ -26,7 +25,6 @@ import io.cdap.cdap.api.common.RuntimeArguments; import io.cdap.cdap.api.schedule.SchedulableProgramType; import io.cdap.cdap.api.workflow.ScheduleProgramInfo; -import io.cdap.cdap.api.workflow.Workflow; import io.cdap.cdap.api.workflow.WorkflowActionNode; import io.cdap.cdap.api.workflow.WorkflowConditionNode; import io.cdap.cdap.api.workflow.WorkflowForkNode; @@ -169,7 +167,13 @@ protected void setupLaunchConfig(ProgramLaunchConfig launchConfig, Program progr } } finally { if (runner instanceof Closeable) { - Closeables.closeQuietly((Closeable) runner); + try { + + ((Closeable) runner).close(); + + } catch (Exception ignored) { + + } } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/LocalizeResource.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/LocalizeResource.java index fdc664bb3b36..138bcd66b1d9 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/LocalizeResource.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/LocalizeResource.java @@ -16,7 +16,7 @@ package io.cdap.cdap.internal.app.runtime.distributed; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import java.io.File; import java.net.URI; @@ -51,7 +51,7 @@ public URI getURI() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("archive", archive) .add("uri", uri) .toString(); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/AbstractRuntimeTwillPreparer.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/AbstractRuntimeTwillPreparer.java index 9a8001dfabfd..3601a0e528cf 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/AbstractRuntimeTwillPreparer.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/AbstractRuntimeTwillPreparer.java @@ -520,10 +520,10 @@ private void createApplicationJar(ApplicationBundler bundler, .collect(Collectors.toList()); Hasher hasher = Hashing.md5().newHasher(); for (String name : classList) { - hasher.putString(name); + hasher.putString(name, StandardCharsets.UTF_8); } // Add cdap version to the hash so that application jars are distinguishable when upgrade happens. - hasher.putString(ProjectInfo.getVersion().toString()); + hasher.putString(ProjectInfo.getVersion().toString(), StandardCharsets.UTF_8); // Only depends on class list and cdap version so that it can be reused across different launches String hashVal = hasher.hash().toString(); String name = hashVal + "-" + Constants.Files.APPLICATION_JAR; diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionJobMain.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionJobMain.java index c60dbff4d03a..a2144f6e6b42 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionJobMain.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionJobMain.java @@ -127,7 +127,7 @@ private void doMain(String[] args) throws Exception { @VisibleForTesting RemoteExecutionRuntimeJobEnvironment initialize(CConfiguration cConf) throws Exception { zkServer = InMemoryZKServer.builder().build(); - zkServer.startAndWait(); + zkServer.startAsync().awaitRunning(); InetSocketAddress zkAddr = ResolvingDiscoverable.resolve(zkServer.getLocalAddress()); String zkConnectStr = String.format("%s:%d", zkAddr.getHostString(), zkAddr.getPort()); @@ -214,7 +214,7 @@ void destroy() { if (zkServer != null) { try { - zkServer.stopAndWait(); + zkServer.stopAsync().awaitTerminated(); } catch (Exception e) { LOG.warn("Failed to stop ZK server", e); } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionService.java index 1075b5925465..05b94ec41ddc 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionService.java @@ -88,7 +88,7 @@ protected final long runTask() throws Exception { LOG.debug("Program {} is not running", programRunId); programStateWriter.error(programRunId, new IllegalStateException("Program terminated " + programRunId)); - stop(); + stopAsync(); return 0; } nextCheckRunningMillis = now + pollTimeMillis * 10; @@ -159,7 +159,7 @@ protected long handleRetriesExhausted(Exception e) throws Exception { } @Override - protected String getServiceName() { + protected String serviceName() { return "runtime-service-" + programRunId.getRun(); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionTwillController.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionTwillController.java index 906197359e01..b8985c1f28f0 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionTwillController.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionTwillController.java @@ -47,7 +47,6 @@ import org.apache.twill.api.logging.LogHandler; import org.apache.twill.common.Threads; import org.apache.twill.discovery.ServiceDiscovered; -import org.apache.twill.internal.ServiceListenerAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -88,7 +87,7 @@ class RemoteExecutionTwillController implements TwillController { completion.completeExceptionally(throwable); return RemoteExecutionTwillController.this; }); - service.addListener(new ServiceListenerAdapter() { + service.addListener(new Service.Listener() { @Override public void terminated(Service.State from) { if (terminateOnServiceStop) { @@ -113,12 +112,12 @@ public void failed(Service.State from, Throwable failure) { public void release() { terminateOnServiceStop = false; - executionService.stop(); + executionService.stopAsync(); } public void complete() { terminateOnServiceStop = true; - executionService.stop(); + executionService.stopAsync(); try { RuntimeJobStatus status; RetryStrategy retryStrategy = RetryStrategies.timeLimit( diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionTwillPreparer.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionTwillPreparer.java index 73612175c011..aa01f41e0b23 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionTwillPreparer.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionTwillPreparer.java @@ -53,8 +53,6 @@ import org.apache.twill.api.ClassAcceptor; import org.apache.twill.api.LocalFile; import org.apache.twill.api.RuntimeSpecification; -import org.apache.twill.api.TwillPreparer; -import org.apache.twill.api.TwillRunnable; import org.apache.twill.api.TwillSpecification; import org.apache.twill.filesystem.Location; import org.apache.twill.filesystem.LocationFactory; @@ -250,7 +248,7 @@ private void localizeFiles( String localizedFile = localizedFiles.get(uri); if (localizedFile == null) { String fileName = - Hashing.md5().hashString(uri.toString()).toString() + "-" + getFileName(uri); + Hashing.md5().hashString(uri.toString(), StandardCharsets.UTF_8).toString() + "-" + getFileName(uri); localizedFile = localizedDir + "/" + fileName; try (InputStream inputStream = openUri(uri)) { LOG.debug( diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionTwillRunnerService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionTwillRunnerService.java index 97b8b9ff0829..ee3b73f7d9e6 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionTwillRunnerService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionTwillRunnerService.java @@ -119,7 +119,6 @@ import org.apache.twill.discovery.DiscoveryServiceClient; import org.apache.twill.filesystem.Location; import org.apache.twill.filesystem.LocationFactory; -import org.apache.twill.internal.ServiceListenerAdapter; import org.apache.twill.internal.SingleRunnableApplication; import org.apache.twill.internal.io.BasicLocationCache; import org.apache.twill.internal.io.LocationCache; @@ -217,7 +216,7 @@ public void stop() { try { if (EnumSet.of(Service.State.STARTING, Service.State.RUNNING) .contains(serviceSocksProxy.state())) { - serviceSocksProxy.stopAndWait(); + serviceSocksProxy.stopAsync().awaitTerminated(); } } catch (Exception e) { LOG.warn("Exception raised when stopping runtime monitor socks proxy", e); @@ -389,7 +388,7 @@ private TwillPreparer createPreparer(CConfiguration cConf, Configuration hConf, private int getServiceSocksProxyPort() { if (serviceSocksProxy.state() == Service.State.NEW) { // It's ok to have multiple threads calling start if the proxy is not running. - serviceSocksProxy.startAndWait(); + serviceSocksProxy.startAsync().awaitRunning(); } return serviceSocksProxy.getBindAddress().getPort(); } @@ -428,7 +427,7 @@ private Location generateAndSaveServiceProxySecret(ProgramRunId programRunId, Lo String secret = Hashing.sha1().newHasher() .putBytes(salt) - .putString(programRunId.getRun()) + .putString(programRunId.getRun(), StandardCharsets.UTF_8) .hash().toString(); Location location = keysDir.append(Constants.RuntimeMonitor.SERVICE_PROXY_PASSWORD_FILE); @@ -549,7 +548,7 @@ protected void monitorController(ProgramRunId programRunId, CompletableFuture startupTaskCompletion, RemoteExecutionTwillController controller, RemoteExecutionService remoteExecutionService) { - startupTaskCompletion.thenAccept(o -> remoteExecutionService.start()); + startupTaskCompletion.thenAccept(o -> remoteExecutionService.startAsync()); // On this controller termination, make sure it is removed from the controllers map and have resources released. controller.onTerminated(() -> { @@ -751,7 +750,7 @@ private RemoteExecutionService createRemoteExecutionService(ProgramRunId program programStateWriter, scheduler); LOG.debug("Monitor program run {} with SSH config {}", programRunId, sshConfig); String proxySecret = clusterKeyInfo.getServerProxySecret(); - remoteExecutionService.addListener(new ServiceListenerAdapter() { + remoteExecutionService.addListener(new Service.Listener() { @Override public void running() { serviceSocksProxyAuthenticator.add(proxySecret); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/SSHRemoteExecutionService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/SSHRemoteExecutionService.java index f3249c088e77..31a6f29e2a1c 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/SSHRemoteExecutionService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/remote/SSHRemoteExecutionService.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.runtime.distributed.remote; -import com.google.common.io.Closeables; import com.google.gson.Gson; import io.cdap.cdap.app.runtime.ProgramStateWriter; import io.cdap.cdap.common.conf.CConfiguration; @@ -61,13 +60,25 @@ protected void doRunTask() throws Exception { if (sshSession != null && sshSession.isAlive()) { return; } - Closeables.closeQuietly(sshSession); + try { + + sshSession.close(); + + } catch (Exception ignored) { + + } sshSession = createServiceProxyTunnel(); } @Override protected void doShutdown() { - Closeables.closeQuietly(sshSession); + try { + + sshSession.close(); + + } catch (Exception ignored) { + + } LOG.debug("Stopped ssh service for run {}", getProgramRunId()); } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/runtimejob/DefaultRuntimeJob.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/runtimejob/DefaultRuntimeJob.java index 94d1d33eba49..b18c01cebc17 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/runtimejob/DefaultRuntimeJob.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/runtimejob/DefaultRuntimeJob.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.runtime.distributed.runtimejob; import com.google.common.annotations.VisibleForTesting; -import com.google.common.io.Closeables; import com.google.common.util.concurrent.AbstractIdleService; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.Service; @@ -150,7 +149,6 @@ import org.apache.twill.common.Cancellable; import org.apache.twill.common.Threads; import org.apache.twill.filesystem.Location; -import org.apache.twill.internal.ServiceListenerAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.bridge.SLF4JBridgeHandler; @@ -291,7 +289,11 @@ public void run(RuntimeJobEnvironment runtimeJobEnv) throws Exception { programCompletion.get(); } finally { if (programRunner instanceof Closeable) { - Closeables.closeQuietly((Closeable) programRunner); + try { + ((Closeable) programRunner).close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup of the program runner on completion. + } } } } catch (Throwable t) { @@ -527,7 +529,7 @@ private void startCoreServices(Deque coreServices) { // Starts the core services for (Service service : coreServices) { LOG.debug("Starting core service {}", service); - service.startAndWait(); + service.startAsync().awaitRunning(); } } @@ -540,7 +542,7 @@ private void stopCoreServices(Deque coreServices, for (Service service : (Iterable) coreServices::descendingIterator) { LOG.debug("Stopping core service {}", service); try { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } catch (Exception e) { LOG.warn( "Exception raised when stopping service {} during program termination.", @@ -624,7 +626,7 @@ private void monitorServicesHealth(ProgramRunId programRunId, ProgramController controller) { for (Service service : services) { - service.addListener(new ServiceListenerAdapter() { + service.addListener(new Service.Listener() { @Override public void failed(Service.State from, Throwable failure) { LOG.error( @@ -721,7 +723,7 @@ private static final class TrafficRelayService extends AbstractIdleService { protected void startUp() throws Exception { // Bind the traffic relay on the host, not on the loopback interface. It needs to be accessible from all workers. relayServer = new TrafficRelayServer(InetAddress.getLocalHost(), this::getTrafficRelayTarget); - relayServer.startAndWait(); + relayServer.startAsync().awaitRunning(); // Set the traffic relay service address to cConf. It will be used as the proxy address for all worker processes Networks.setAddress(cConf, Constants.RuntimeMonitor.SERVICE_PROXY_ADDRESS, @@ -732,7 +734,7 @@ protected void startUp() throws Exception { @Override protected void shutDown() { - relayServer.stopAndWait(); + relayServer.stopAsync().awaitTerminated(); getServiceProxyFile().delete(); } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/AbstractServiceRoutingHandler.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/AbstractServiceRoutingHandler.java index 3b49421b5dd5..c3cd82c3aecd 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/AbstractServiceRoutingHandler.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/AbstractServiceRoutingHandler.java @@ -19,7 +19,6 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; -import com.google.common.io.Closeables; import io.cdap.cdap.api.service.ServiceUnavailableException; import io.cdap.cdap.common.BadRequestException; import io.cdap.cdap.common.ServiceException; @@ -236,7 +235,13 @@ private static final class ResponseInfo implements Closeable { try { is = urlConn.getInputStream(); if (this.responseCode >= 400) { - Closeables.closeQuietly(is); + try { + + is.close(); + + } catch (Exception ignored) { + + } is = null; } } catch (UnknownServiceException e) { @@ -275,7 +280,13 @@ InputStream getInput() { @Override public void close() { - Closeables.closeQuietly(input); + try { + + input.close(); + + } catch (Exception ignored) { + + } urlConn.disconnect(); } } @@ -305,13 +316,25 @@ public ByteBuf nextChunk() throws Exception { @Override public void finished() { - Closeables.closeQuietly(responseInfo); + try { + + responseInfo.close(); + + } catch (Exception ignored) { + + } } @Override public void handleError(@Nullable Throwable cause) { LOG.warn("Exception raised when handling request to {}", url, cause); - Closeables.closeQuietly(responseInfo); + try { + + responseInfo.close(); + + } catch (Exception ignored) { + + } } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/DirectRuntimeRequestValidator.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/DirectRuntimeRequestValidator.java index 0c90be3fcaa5..54ccf314b91f 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/DirectRuntimeRequestValidator.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/DirectRuntimeRequestValidator.java @@ -16,7 +16,7 @@ package io.cdap.cdap.internal.app.runtime.monitor; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -165,24 +165,24 @@ private void insertRunRecord(ProgramRunId programRunId, RunRecordDetail runRecor store.recordProgramStart(programRunId, null, runRecord.getSystemArgs(), runRecord.getSourceId()); store.recordProgramRunning(programRunId, - Objects.firstNonNull(runRecord.getRunTs(), System.currentTimeMillis()), + MoreObjects.firstNonNull(runRecord.getRunTs(), System.currentTimeMillis()), null, runRecord.getSourceId()); switch (runRecord.getStatus()) { case SUSPENDED: store.recordProgramSuspend(programRunId, runRecord.getSourceId(), - Objects.firstNonNull(runRecord.getSuspendTs(), System.currentTimeMillis())); + MoreObjects.firstNonNull(runRecord.getSuspendTs(), System.currentTimeMillis())); break; case STOPPING: store.recordProgramStopping(programRunId, runRecord.getSourceId(), - Objects.firstNonNull(runRecord.getStoppingTs(), System.currentTimeMillis()), + MoreObjects.firstNonNull(runRecord.getStoppingTs(), System.currentTimeMillis()), // if terminate timestamp is null we will shut down gracefully - Objects.firstNonNull(runRecord.getTerminateTs(), Long.MAX_VALUE)); + MoreObjects.firstNonNull(runRecord.getTerminateTs(), Long.MAX_VALUE)); break; case COMPLETED: case KILLED: case FAILED: store.recordProgramStop(programRunId, - Objects.firstNonNull(runRecord.getStopTs(), System.currentTimeMillis()), + MoreObjects.firstNonNull(runRecord.getStopTs(), System.currentTimeMillis()), runRecord.getStatus(), null, runRecord.getSourceId()); // We don't need to retain records for terminated programs, hence just delete it store.deleteRunIfTerminated(programRunId, runRecord.getSourceId()); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeClientService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeClientService.java index 5e4bd6e6f1ed..fac00e8d7827 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeClientService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeClientService.java @@ -141,7 +141,7 @@ > getProgramCompletionDetails().getEndTimestamp())) { LOG.debug( "Program {} terminated. Shutting down runtime client service.", programRunId); - stop(); + stopAsync(); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeHandler.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeHandler.java index 75f040e91524..0a23ab0fdc5f 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeHandler.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeHandler.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.runtime.monitor; -import com.google.common.io.Closeables; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.inject.Inject; @@ -227,7 +226,13 @@ public void finished(HttpResponder responder) { @Override public void handleError(Throwable cause) { LOG.error("Failed to write spark event logs for {}", programRunId, cause); - Closeables.closeQuietly(os); + try { + + os.close(); + + } catch (Exception ignored) { + + } try { location.delete(); } catch (IOException e) { @@ -346,7 +351,13 @@ public void finished(HttpResponder responder) { "Failed to process all messages due to " + e.getMessage()); } } finally { - Closeables.closeQuietly(inputStream); + try { + + inputStream.close(); + + } catch (Exception ignored) { + + } buffer.release(); } } @@ -368,7 +379,13 @@ private static final class DelegatingInputStream extends FilterInputStream { } void setDelegate(InputStream delegate) { - Closeables.closeQuietly(in); + try { + + in.close(); + + } catch (Exception ignored) { + + } in = delegate; } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/plugin/FindPluginHelper.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/plugin/FindPluginHelper.java index d472061dc589..9abed943bab9 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/plugin/FindPluginHelper.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/plugin/FindPluginHelper.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.runtime.plugin; -import com.google.common.base.Throwables; import io.cdap.cdap.api.artifact.ArtifactId; import io.cdap.cdap.api.macro.MacroParserOptions; import io.cdap.cdap.api.plugin.Plugin; @@ -65,7 +64,7 @@ public static Plugin getPlugin(Iterable parents, try { pluginInstantiator.addArtifact(pluginEntry.getKey().getLocation(), artifact); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } return new Plugin(parents, artifact, pluginEntry.getValue(), properties.setMacros(collectMacroEvaluator.getMacros())); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/plugin/PluginClassLoaders.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/plugin/PluginClassLoaders.java index 9bd7de60da02..1a149bc34674 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/plugin/PluginClassLoaders.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/plugin/PluginClassLoaders.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.runtime.plugin; import com.google.common.base.Function; -import com.google.common.base.Throwables; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -79,7 +78,7 @@ public static ClassLoader createFilteredPluginsClassLoader(Map p } return new CombineClassLoader(null, pluginClassLoaders); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/plugin/PluginInstantiator.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/plugin/PluginInstantiator.java index 60a50516435c..6c4d9fd4d410 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/plugin/PluginInstantiator.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/plugin/PluginInstantiator.java @@ -18,14 +18,12 @@ import com.google.common.base.Defaults; import com.google.common.base.Strings; -import com.google.common.base.Throwables; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.cache.RemovalListener; import com.google.common.cache.RemovalNotification; import com.google.common.collect.ImmutableMap; -import com.google.common.io.Closeables; import com.google.common.primitives.Primitives; import com.google.common.reflect.TypeToken; import com.google.gson.Gson; @@ -167,8 +165,12 @@ public PluginClassLoader getArtifactClassLoader(ArtifactId artifactId) throws IO try { return classLoaders.get(new ClassLoaderKey(artifactId)); } catch (ExecutionException e) { - Throwables.propagateIfInstanceOf(e.getCause(), IOException.class); - throw Throwables.propagate(e.getCause()); + if (e.getCause() instanceof IOException) { + + throw (IOException) e.getCause(); + + } + throw new RuntimeException(e.getCause()); } } @@ -196,8 +198,12 @@ public PluginClassLoader getPluginClassLoader(ArtifactId artifactId, try { return classLoaders.get(new ClassLoaderKey(artifactId, pluginParents)); } catch (ExecutionException e) { - Throwables.propagateIfInstanceOf(e.getCause(), IOException.class); - throw Throwables.propagate(e.getCause()); + if (e.getCause() instanceof IOException) { + + throw (IOException) e.getCause(); + + } + throw new RuntimeException(e.getCause()); } } @@ -495,7 +501,7 @@ private T newInstance(TypeToken pluginType, Field configField, return (T) constructor.newInstance(config); } catch (InvocationTargetException e) { // If there is exception thrown from the constructor, propagate it. - throw Throwables.propagate(e.getCause()); + throw new RuntimeException(e.getCause()); } catch (Exception e) { // Failed to instantiate. Resort to field injection LOG.warn("Failed to invoke plugin constructor {}. Resort to config field injection.", @@ -517,7 +523,11 @@ public void close() throws IOException { // Cleanup the ClassLoader cache and the temporary directory for the expanded plugin jar. classLoaders.invalidateAll(); if (ownedParentClassLoader) { - Closeables.closeQuietly((Closeable) parentClassLoader); + try { + ((Closeable) parentClassLoader).close(); + } catch (Exception ignored) { + // Ignored because we are closing the plugin instantiator and performing final cleanup. + } } try { DirUtils.deleteDirectoryContents(tmpDir); @@ -618,7 +628,11 @@ private static final class ClassLoaderRemovalListener implements @Override public void onRemoval(RemovalNotification notification) { - Closeables.closeQuietly(notification.getValue()); + try { + notification.getValue().close(); + } catch (Exception ignored) { + // Ignored because we are removing the classloader from the cache and performing cleanup. + } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/DistributedTimeSchedulerService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/DistributedTimeSchedulerService.java index f91b134705ab..f00a2837c6d4 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/DistributedTimeSchedulerService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/DistributedTimeSchedulerService.java @@ -73,13 +73,13 @@ protected void doStop() { protected void startUp() throws Exception { LOG.info("Starting scheduler."); // RetryOnStartFailureservice#startAndWait returns before its service's startAndWait completes - serviceDelegate.startAndWait(); + serviceDelegate.startAsync().awaitRunning(); startUpLatch.await(); } @Override protected void shutDown() throws Exception { LOG.info("Stopping scheduler."); - serviceDelegate.stopAndWait(); + serviceDelegate.stopAsync().awaitTerminated(); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/LocalScheduleManager.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/LocalScheduleManager.java index 7ba652f8dff5..a1f40eb37456 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/LocalScheduleManager.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/LocalScheduleManager.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.runtime.schedule; -import com.google.common.base.Throwables; import com.google.inject.Inject; import io.cdap.cdap.common.AlreadyExistsException; import io.cdap.cdap.common.BadRequestException; @@ -125,7 +124,7 @@ public void addSchedules(Iterable schedules) } catch (NotFoundException | ProfileConflictException | AlreadyExistsException e) { throw e; } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/queue/JobKey.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/queue/JobKey.java index 7267b32df0d6..9e77af7c5234 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/queue/JobKey.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/queue/JobKey.java @@ -16,6 +16,7 @@ package io.cdap.cdap.internal.app.runtime.schedule.queue; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import io.cdap.cdap.proto.id.ScheduleId; @@ -68,7 +69,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("scheduleId", scheduleId) .add("generationId", generationId) .toString(); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/queue/JobQueueTable.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/queue/JobQueueTable.java index 19cc03e7669d..52007f2ec7d1 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/queue/JobQueueTable.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/queue/JobQueueTable.java @@ -47,6 +47,7 @@ import io.cdap.cdap.spi.data.table.field.Range; import io.cdap.cdap.store.StoreDefinition; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -425,9 +426,9 @@ int getPartition(ScheduleId scheduleId) { // Similar to ScheduleId#hashCode, but that is not consistent across runtimes due to how Enum#hashCode works. // Ensure that the hash won't change across runtimes: int hash = Hashing.murmur3_32().newHasher() - .putString(scheduleId.getNamespace()) - .putString(scheduleId.getApplication()) - .putString(scheduleId.getSchedule()) + .putString(scheduleId.getNamespace(), StandardCharsets.UTF_8) + .putString(scheduleId.getApplication(), StandardCharsets.UTF_8) + .putString(scheduleId.getSchedule(), StandardCharsets.UTF_8) .hash().asInt(); return Math.abs(hash) % numPartitions; } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/queue/SimpleJob.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/queue/SimpleJob.java index 37b78b0e10cd..909f7f0fb53c 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/queue/SimpleJob.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/queue/SimpleJob.java @@ -16,6 +16,7 @@ package io.cdap.cdap.internal.app.runtime.schedule.queue; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule; @@ -115,7 +116,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("schedule", schedule) .add("creationTime", creationTime) .add("jobKey", jobKey) diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/store/DatasetBasedTimeScheduleStore.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/store/DatasetBasedTimeScheduleStore.java index d9d84b75835c..0df7ce34bf71 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/store/DatasetBasedTimeScheduleStore.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/store/DatasetBasedTimeScheduleStore.java @@ -18,7 +18,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.inject.Inject; @@ -87,7 +86,7 @@ public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler schedSignal setMisfireThreshold(cConf.getLong(Constants.Scheduler.CFG_SCHEDULER_MISFIRE_THRESHOLD_MS)); readSchedulesFromPersistentStore(); } catch (Throwable th) { - throw Throwables.propagate(th); + throw new RuntimeException(th); } } @@ -143,7 +142,7 @@ public boolean removeTrigger(TriggerKey triggerKey) { executeDelete(triggerKey); return true; } catch (Throwable t) { - throw Throwables.propagate(t); + throw new RuntimeException(t); } } @@ -154,7 +153,7 @@ public boolean removeJob(JobKey jobKey) { executeDelete(jobKey); return true; } catch (Throwable t) { - throw Throwables.propagate(t); + throw new RuntimeException(t); } } @@ -169,7 +168,7 @@ private void executeDelete(final TriggerKey triggerKey) { delete(getTimeScheduleStructuredTable(context), TRIGGER_KEY, triggerKey.getName()); }); } catch (Throwable th) { - throw Throwables.propagate(th); + throw new RuntimeException(th); } } @@ -179,7 +178,7 @@ private void executeDelete(final JobKey jobKey) { delete(getTimeScheduleStructuredTable(context), JOB_KEY, jobKey.getName()); }); } catch (Throwable t) { - throw Throwables.propagate(t); + throw new RuntimeException(t); } } @@ -200,7 +199,7 @@ private void persistChangeOfState(final TriggerKey triggerKey, } }); } catch (Throwable th) { - throw Throwables.propagate(th); + throw new RuntimeException(th); } } @@ -223,7 +222,7 @@ private void persistJobAndTrigger(final JobDetail newJob, final OperableTrigger } }); } catch (Throwable th) { - throw Throwables.propagate(th); + throw new RuntimeException(th); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/store/Schedulers.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/store/Schedulers.java index 990bda2fb9a3..d687b1db7905 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/store/Schedulers.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/store/Schedulers.java @@ -18,7 +18,6 @@ import com.google.common.base.Joiner; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSet; import com.google.gson.reflect.TypeToken; import io.cdap.cdap.api.ProgramStatus; @@ -84,7 +83,7 @@ public static ProgramScheduleStoreDataset getScheduleStore(StructuredTableContex context.getTable(StoreDefinition.ProgramScheduleStore.PROGRAM_TRIGGER_TABLE) ); } catch (TableNotFoundException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/ServiceProgramRunner.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/ServiceProgramRunner.java index 5f8dbf0a7ffb..7fc69a553d47 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/ServiceProgramRunner.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/ServiceProgramRunner.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.runtime.service; import com.google.common.base.Preconditions; -import com.google.common.io.Closeables; import com.google.inject.Inject; import com.google.inject.name.Named; import io.cdap.cdap.api.app.ApplicationSpecification; @@ -30,7 +29,6 @@ import io.cdap.cdap.app.program.Program; import io.cdap.cdap.app.runtime.ProgramController; import io.cdap.cdap.app.runtime.ProgramOptions; -import io.cdap.cdap.app.runtime.ProgramRunner; import io.cdap.cdap.common.conf.CConfiguration; import io.cdap.cdap.common.conf.SConfiguration; import io.cdap.cdap.common.encryption.AeadCipher; @@ -195,10 +193,16 @@ public ProgramController run(Program program, ProgramOptions options) { ProgramController controller = new ServiceProgramControllerAdapter(component, program.getId().run(runId)); - component.start(); + component.startAsync(); return controller; } catch (Throwable t) { - Closeables.closeQuietly(pluginInstantiator); + try { + + pluginInstantiator.close(); + + } catch (Exception ignored) { + + } throw t; } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/DelayedHttpServiceResponder.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/DelayedHttpServiceResponder.java index 50e6bf89e9c3..7c3ac3d12b76 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/DelayedHttpServiceResponder.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/DelayedHttpServiceResponder.java @@ -16,13 +16,12 @@ package io.cdap.cdap.internal.app.runtime.service.http; +import com.google.common.base.Throwables; import com.google.common.base.Charsets; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import io.cdap.cdap.api.common.HttpErrorStatusProvider; import io.cdap.cdap.api.metrics.MetricsContext; import io.cdap.cdap.api.service.http.HttpContentProducer; -import io.cdap.cdap.api.service.http.HttpServiceResponder; import io.cdap.http.BodyProducer; import io.cdap.http.HttpResponder; import io.netty.buffer.ByteBuf; diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/HttpHandlerFactory.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/HttpHandlerFactory.java index 359aacc8d691..ad140f54025d 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/HttpHandlerFactory.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/HttpHandlerFactory.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.runtime.service.http; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -88,7 +87,7 @@ public HttpHandler createHttpHandler(TypeToken delegateType, DelegatorCon return constructor.newInstance(context, metricsContext); } catch (Exception e) { LOG.error("Failed to instantiate generated HttpHandler {}", handlerClass, e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/HttpHandlerGenerator.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/HttpHandlerGenerator.java index 614e2c29faf9..fd9277533ede 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/HttpHandlerGenerator.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/HttpHandlerGenerator.java @@ -16,7 +16,7 @@ package io.cdap.cdap.internal.app.runtime.service.http; -import com.google.common.base.Throwables; +import java.nio.charset.StandardCharsets; import com.google.common.collect.ImmutableSet; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.ListMultimap; @@ -35,7 +35,6 @@ import io.cdap.cdap.internal.asm.Methods; import io.cdap.cdap.internal.asm.Signatures; import io.cdap.http.BodyConsumer; -import io.cdap.http.HttpHandler; import io.cdap.http.HttpResponder; import io.netty.handler.codec.http.HttpRequest; import java.io.IOException; @@ -150,7 +149,7 @@ ClassDefinition generate(TypeToken delegateType, String pathPrefix) throws IO ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES); String internalName = Type.getInternalName(rawType); - String className = internalName + Hashing.md5().hashString(internalName); + String className = internalName + Hashing.md5().hashString(internalName, StandardCharsets.UTF_8); // Generate the class Type classType = Type.getObjectType(className); @@ -472,7 +471,7 @@ public void visitEnd() { } catch (ClassNotFoundException e) { // Shouldn't happen since the delegateType (user handler class) is already loaded and the method return // type should be loadable through the same classloader - throw Throwables.propagate(e); + throw new RuntimeException(e); } } else if (!returnType.equals(Type.VOID_TYPE)) { throw new IllegalArgumentException("Handler method must either return void or a " @@ -529,7 +528,7 @@ private void preserveParameterClasses(Type[] argTypes) { } } catch (ClassNotFoundException e) { // Shouldn't happen, as the parameter class should be loading from the user handler ClassLoader - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/LocationHttpContentProducer.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/LocationHttpContentProducer.java index 2c6f68cc12bb..6a78092b7a6d 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/LocationHttpContentProducer.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/http/LocationHttpContentProducer.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.runtime.service.http; -import com.google.common.io.Closeables; import io.cdap.cdap.api.Transactional; import io.cdap.cdap.api.annotation.TransactionControl; import io.cdap.cdap.api.annotation.TransactionPolicy; @@ -82,7 +81,13 @@ public void onFinish() throws Exception { @Override @TransactionPolicy(TransactionControl.EXPLICIT) public void onError(Throwable failureCause) { - Closeables.closeQuietly(input); + try { + + input.close(); + + } catch (Exception ignored) { + + } LOG.warn("Failure in producing http content from location {}", location, failureCause); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/worker/WorkerProgramRunner.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/worker/WorkerProgramRunner.java index 5a3cc0427568..24c387d98537 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/worker/WorkerProgramRunner.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/worker/WorkerProgramRunner.java @@ -17,19 +17,16 @@ package io.cdap.cdap.internal.app.runtime.worker; import com.google.common.base.Preconditions; -import com.google.common.io.Closeables; import com.google.inject.Inject; import io.cdap.cdap.api.app.ApplicationSpecification; import io.cdap.cdap.api.metadata.MetadataReader; import io.cdap.cdap.api.metrics.MetricsCollectionService; import io.cdap.cdap.api.security.store.SecureStore; import io.cdap.cdap.api.security.store.SecureStoreManager; -import io.cdap.cdap.api.worker.Worker; import io.cdap.cdap.api.worker.WorkerSpecification; import io.cdap.cdap.app.program.Program; import io.cdap.cdap.app.runtime.ProgramController; import io.cdap.cdap.app.runtime.ProgramOptions; -import io.cdap.cdap.app.runtime.ProgramRunner; import io.cdap.cdap.common.conf.CConfiguration; import io.cdap.cdap.common.internal.remote.RemoteClientFactory; import io.cdap.cdap.common.namespace.NamespaceQueryAdmin; @@ -160,10 +157,16 @@ public ProgramController run(Program program, ProgramOptions options) { ProgramController controller = new WorkerControllerServiceAdapter(worker, program.getId().run(runId)); - worker.start(); + worker.startAsync(); return controller; } catch (Throwable t) { - Closeables.closeQuietly(pluginInstantiator); + try { + + pluginInstantiator.close(); + + } catch (Exception ignored) { + + } throw t; } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/CustomActionExecutor.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/CustomActionExecutor.java index 6af3f3e55555..35d7f5bb1510 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/CustomActionExecutor.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/CustomActionExecutor.java @@ -16,8 +16,8 @@ package io.cdap.cdap.internal.app.runtime.workflow; -import com.google.common.base.Preconditions; import com.google.common.base.Throwables; +import com.google.common.base.Preconditions; import com.google.common.reflect.TypeToken; import io.cdap.cdap.api.ProgramState; import io.cdap.cdap.api.ProgramStatus; @@ -94,7 +94,7 @@ void execute() throws Exception { customActionContext.setState( new ProgramState(ProgramStatus.FAILED, Exceptions.condenseThrowableMessage(t))); Throwables.propagateIfPossible(t, Exception.class); - throw Throwables.propagate(t); + throw new RuntimeException(t); } finally { TransactionControl txControl = Transactions.getTransactionControl(defaultTxControl, diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/DefaultProgramWorkflowRunner.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/DefaultProgramWorkflowRunner.java index 01ba0a9b1a00..bddac7c55774 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/DefaultProgramWorkflowRunner.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/DefaultProgramWorkflowRunner.java @@ -16,8 +16,6 @@ package io.cdap.cdap.internal.app.runtime.workflow; -import com.google.common.base.Throwables; -import com.google.common.io.Closeables; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.SettableFuture; import com.google.gson.Gson; @@ -102,7 +100,7 @@ public Runnable create(String name) { return getProgramRunnable(name, programRunner, program); } catch (Exception e) { closeProgramRunner(programRunner); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -142,7 +140,7 @@ public void run() { try { runAndWait(programRunner, program, options); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } }; @@ -166,7 +164,11 @@ private void runAndWait(ProgramRunner programRunner, Program program, ProgramOpt // If there is any exception when running the program, close the program to release resources. // Otherwise it will be released when the execution completed. programStateWriter.error(program.getId().run(runId), t); - Closeables.closeQuietly(closeable); + try { + closeable.close(); + } catch (Exception ignored) { + // Ignored because we are already handling the original program execution error. + } throw t; } blockForCompletion(closeable, controller); @@ -210,7 +212,11 @@ public void init(ProgramController.State currentState, @Nullable Throwable cause @Override public void completed() { - Closeables.closeQuietly(closeable); + try { + closeable.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup of the program on completion. + } Set fieldLineageOperations = new HashSet<>(); if (controller instanceof WorkflowDataProvider) { fieldLineageOperations.addAll( @@ -224,7 +230,11 @@ public void completed() { @Override public void killed() { - Closeables.closeQuietly(closeable); + try { + closeable.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup of the program on kill. + } nodeStates.put(nodeId, new WorkflowNodeState(nodeId, NodeStatus.KILLED, controller.getRunId().getId(), null)); completion.set(null); @@ -232,7 +242,11 @@ public void killed() { @Override public void error(Throwable cause) { - Closeables.closeQuietly(closeable); + try { + closeable.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup of the program on error. + } nodeStates.put(nodeId, new WorkflowNodeState(nodeId, NodeStatus.FAILED, controller.getRunId().getId(), cause)); completion.setException(cause); @@ -247,7 +261,7 @@ public void error(Throwable cause) { if (cause instanceof Exception) { throw (Exception) cause; } - throw Throwables.propagate(cause); + throw new RuntimeException(cause); } catch (InterruptedException e) { try { Futures.getUnchecked(controller.stop()); @@ -271,7 +285,11 @@ private Closeable createCloseable(final ProgramRunner programRunner, final Progr return new Closeable() { @Override public void close() throws IOException { - Closeables.closeQuietly(program); + try { + program.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup of the program on close. + } closeProgramRunner(programRunner); } }; @@ -282,7 +300,11 @@ public void close() throws IOException { */ private void closeProgramRunner(ProgramRunner programRunner) { if (programRunner instanceof Closeable) { - Closeables.closeQuietly((Closeable) programRunner); + try { + ((Closeable) programRunner).close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup of the program runner on close. + } } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/WorkflowDriver.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/WorkflowDriver.java index 455f8af0abab..9bfc79f5ec78 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/WorkflowDriver.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/WorkflowDriver.java @@ -102,7 +102,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; @@ -356,7 +355,7 @@ public Void call() throws Exception { future.get(); } catch (Throwable t) { Throwables.propagateIfPossible(t, Exception.class); - throw Throwables.propagate(t); + throw new RuntimeException(t); } finally { executorService.shutdownNow(); executorTerminateLatch.await(); @@ -402,7 +401,7 @@ public Map.Entry call() throws Exception { } catch (ExecutionException e) { // Unwrap the cause Throwables.propagateIfPossible(e.getCause(), Exception.class); - throw Throwables.propagate(e.getCause()); + throw new RuntimeException(e.getCause()); } } } finally { diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/WorkflowProgramController.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/WorkflowProgramController.java index bd2b44807ed7..aa7283646cc2 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/WorkflowProgramController.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/WorkflowProgramController.java @@ -21,7 +21,6 @@ import io.cdap.cdap.proto.id.ProgramRunId; import org.apache.twill.api.RunId; import org.apache.twill.common.Threads; -import org.apache.twill.internal.ServiceListenerAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,7 +53,7 @@ protected void doResume() throws Exception { @Override protected void doStop() throws Exception { - driver.stopAndWait(); + driver.stopAsync().awaitTerminated(); } @Override @@ -64,7 +63,7 @@ protected void doCommand(String name, Object value) throws Exception { private void startListen(Service service) { // Forward state changes from the given service to this controller. - service.addListener(new ServiceListenerAdapter() { + service.addListener(new Service.Listener() { @Override public void running() { diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/WorkflowProgramRunner.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/WorkflowProgramRunner.java index d20dea64f0ad..ff71a2c57314 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/WorkflowProgramRunner.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/workflow/WorkflowProgramRunner.java @@ -17,19 +17,16 @@ package io.cdap.cdap.internal.app.runtime.workflow; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.inject.Inject; import io.cdap.cdap.api.app.ApplicationSpecification; import io.cdap.cdap.api.metadata.MetadataReader; import io.cdap.cdap.api.metrics.MetricsCollectionService; import io.cdap.cdap.api.security.store.SecureStore; import io.cdap.cdap.api.security.store.SecureStoreManager; -import io.cdap.cdap.api.workflow.Workflow; import io.cdap.cdap.api.workflow.WorkflowSpecification; import io.cdap.cdap.app.program.Program; import io.cdap.cdap.app.runtime.ProgramController; import io.cdap.cdap.app.runtime.ProgramOptions; -import io.cdap.cdap.app.runtime.ProgramRunner; import io.cdap.cdap.app.runtime.ProgramRunnerFactory; import io.cdap.cdap.app.runtime.ProgramStateWriter; import io.cdap.cdap.common.conf.CConfiguration; @@ -153,11 +150,11 @@ public ProgramController run(final Program program, final ProgramOptions options // service can be fully captured by the controller. ProgramController controller = new WorkflowProgramController(program.getId().run(runId), driver); - driver.start(); + driver.startAsync(); return controller; } catch (Exception e) { closeAllQuietly(closeables); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/AbstractNotificationSubscriberService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/AbstractNotificationSubscriberService.java index fdc581d178fb..0f2bb2b9b32e 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/AbstractNotificationSubscriberService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/AbstractNotificationSubscriberService.java @@ -81,7 +81,7 @@ protected AbstractNotificationSubscriberService(String name, CConfiguration cCon } @Override - protected String getServiceName() { + protected String serviceName() { return name; } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/AppFabricProcessorService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/AppFabricProcessorService.java index 97fafa95f819..0ba01f973aae 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/AppFabricProcessorService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/AppFabricProcessorService.java @@ -16,10 +16,7 @@ package io.cdap.cdap.internal.app.services; -import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.AbstractIdleService; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.Inject; import com.google.inject.name.Named; import io.cdap.cdap.api.feature.FeatureFlagsProvider; @@ -146,29 +143,42 @@ protected void startUp() throws Exception { Constants.Logging.COMPONENT_NAME, Service.APP_FABRIC_PROCESSOR)); LOG.info("Starting AppFabric processor service."); - List> futuresList = new ArrayList<>(); FeatureFlagsProvider featureFlagsProvider = new DefaultFeatureFlagsProvider(cConf); // Only for RBAC instances if (Feature.DATAPLANE_AUDIT_LOGGING.isEnabled(featureFlagsProvider) && cConf.getBoolean(Constants.Security.ENABLED)) { - futuresList.add(auditLogSubscriberService.start()); + auditLogSubscriberService.startAsync(); } - futuresList.addAll(ImmutableList.of( - provisioningService.start(), - applicationLifecycleService.start(), - bootstrapService.start(), - programRuntimeService.start(), - programNotificationSubscriberService.start(), - programStopSubscriberService.start(), - runRecordCorrectorService.start(), - programRunStatusMonitorService.start(), - coreSchedulerService.start(), - runRecordCounterService.start(), - runDataTimeToLiveService.start(), - operationNotificationSubscriberService.start() - )); - Futures.allAsList(futuresList).get(); + provisioningService.startAsync(); + applicationLifecycleService.startAsync(); + bootstrapService.startAsync(); + programRuntimeService.startAsync(); + programNotificationSubscriberService.startAsync(); + programStopSubscriberService.startAsync(); + runRecordCorrectorService.startAsync(); + programRunStatusMonitorService.startAsync(); + coreSchedulerService.startAsync(); + runRecordCounterService.startAsync(); + runDataTimeToLiveService.startAsync(); + operationNotificationSubscriberService.startAsync(); + + if (Feature.DATAPLANE_AUDIT_LOGGING.isEnabled(featureFlagsProvider) + && cConf.getBoolean(Constants.Security.ENABLED)) { + auditLogSubscriberService.awaitRunning(); + } + provisioningService.awaitRunning(); + applicationLifecycleService.awaitRunning(); + bootstrapService.awaitRunning(); + programRuntimeService.awaitRunning(); + programNotificationSubscriberService.awaitRunning(); + programStopSubscriberService.awaitRunning(); + runRecordCorrectorService.awaitRunning(); + programRunStatusMonitorService.awaitRunning(); + coreSchedulerService.awaitRunning(); + runRecordCounterService.awaitRunning(); + runDataTimeToLiveService.awaitRunning(); + operationNotificationSubscriberService.awaitRunning(); // Run http service on random port NettyHttpService.Builder httpServiceBuilder = commonNettyHttpServiceFactory @@ -196,20 +206,20 @@ protected void startUp() throws Exception { protected void shutDown() throws Exception { LOG.info("Stopping AppFabric processor service."); cancelHttpService.cancel(); - coreSchedulerService.stopAndWait(); - bootstrapService.stopAndWait(); - systemAppManagementService.stopAndWait(); - programRuntimeService.stopAndWait(); - applicationLifecycleService.stopAndWait(); - programNotificationSubscriberService.stopAndWait(); - programStopSubscriberService.stopAndWait(); - runRecordCorrectorService.stopAndWait(); - programRunStatusMonitorService.stopAndWait(); - provisioningService.stopAndWait(); - runRecordCounterService.stopAndWait(); - runDataTimeToLiveService.stopAndWait(); - operationNotificationSubscriberService.stopAndWait(); - auditLogSubscriberService.stopAndWait(); + coreSchedulerService.stopAsync().awaitTerminated(); + bootstrapService.stopAsync().awaitTerminated(); + systemAppManagementService.stopAsync().awaitTerminated(); + programRuntimeService.stopAsync().awaitTerminated(); + applicationLifecycleService.stopAsync().awaitTerminated(); + programNotificationSubscriberService.stopAsync().awaitTerminated(); + programStopSubscriberService.stopAsync().awaitTerminated(); + runRecordCorrectorService.stopAsync().awaitTerminated(); + programRunStatusMonitorService.stopAsync().awaitTerminated(); + provisioningService.stopAsync().awaitTerminated(); + runRecordCounterService.stopAsync().awaitTerminated(); + runDataTimeToLiveService.stopAsync().awaitTerminated(); + operationNotificationSubscriberService.stopAsync().awaitTerminated(); + auditLogSubscriberService.stopAsync().awaitTerminated(); LOG.info("AppFabric processor service stopped."); } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/AppFabricServer.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/AppFabricServer.java index bf6d0eb9d423..8a891525b248 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/AppFabricServer.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/AppFabricServer.java @@ -16,10 +16,7 @@ package io.cdap.cdap.internal.app.services; -import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.AbstractIdleService; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.Inject; import com.google.inject.name.Named; import io.cdap.cdap.api.feature.FeatureFlagsProvider; @@ -143,20 +140,26 @@ protected void startUp() throws Exception { new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, Constants.Service.APP_FABRIC_HTTP)); - List> futuresList = new ArrayList<>(); FeatureFlagsProvider featureFlagsProvider = new DefaultFeatureFlagsProvider(cConf); if (Feature.NAMESPACED_SERVICE_ACCOUNTS.isEnabled(featureFlagsProvider)) { - futuresList.add(namespaceCredentialProviderService.start()); + namespaceCredentialProviderService.startAsync(); } - futuresList.addAll(ImmutableList.of( - provisioningService.start(), - applicationLifecycleService.start(), - bootstrapService.start(), - credentialProviderService.start(), - sourceControlOperationRunner.start(), - repositoryCleanupService.start() - )); - Futures.allAsList(futuresList).get(); + provisioningService.startAsync(); + applicationLifecycleService.startAsync(); + bootstrapService.startAsync(); + credentialProviderService.startAsync(); + sourceControlOperationRunner.startAsync(); + repositoryCleanupService.startAsync(); + + if (Feature.NAMESPACED_SERVICE_ACCOUNTS.isEnabled(featureFlagsProvider)) { + namespaceCredentialProviderService.awaitRunning(); + } + provisioningService.awaitRunning(); + applicationLifecycleService.awaitRunning(); + bootstrapService.awaitRunning(); + credentialProviderService.awaitRunning(); + sourceControlOperationRunner.awaitRunning(); + repositoryCleanupService.awaitRunning(); // Create handler hooks List handlerHooks = handlerHookNames.stream() @@ -212,13 +215,13 @@ protected void startUp() throws Exception { @Override protected void shutDown() throws Exception { cancelHttpService.cancel(); - applicationLifecycleService.stopAndWait(); - bootstrapService.stopAndWait(); - provisioningService.stopAndWait(); - sourceControlOperationRunner.stopAndWait(); - repositoryCleanupService.stopAndWait(); - credentialProviderService.stopAndWait(); - namespaceCredentialProviderService.stopAndWait(); + applicationLifecycleService.stopAsync().awaitTerminated(); + bootstrapService.stopAsync().awaitTerminated(); + provisioningService.stopAsync().awaitTerminated(); + sourceControlOperationRunner.stopAsync().awaitTerminated(); + repositoryCleanupService.stopAsync().awaitTerminated(); + credentialProviderService.stopAsync().awaitTerminated(); + namespaceCredentialProviderService.stopAsync().awaitTerminated(); } private Cancellable startHttpService(NettyHttpService httpService) throws Exception { diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/ApplicationLifecycleService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/ApplicationLifecycleService.java index 22eef1f32806..df1ebccce7bb 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/ApplicationLifecycleService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/ApplicationLifecycleService.java @@ -24,7 +24,6 @@ import com.google.common.util.concurrent.AbstractIdleService; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.JsonIOException; import com.google.gson.stream.JsonWriter; import com.google.inject.Inject; import io.cdap.cdap.api.ProgramSpecification; @@ -53,7 +52,6 @@ import io.cdap.cdap.app.store.ScanApplicationsRequest; import io.cdap.cdap.app.store.Store; import io.cdap.cdap.common.ApplicationNotFoundException; -import io.cdap.cdap.common.ArtifactAlreadyExistsException; import io.cdap.cdap.common.ArtifactNotFoundException; import io.cdap.cdap.common.BadRequestException; import io.cdap.cdap.common.CannotBeDeletedException; @@ -346,7 +344,7 @@ private void processApplications(List> consumer.accept(applicationDetail); } } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -825,7 +823,7 @@ private ApplicationId updateApplicationInternal(ApplicationId appId, applicationWithPrograms = manager.deploy(deploymentInfo).get(); } catch (ExecutionException e) { Throwables.propagateIfPossible(e.getCause(), Exception.class); - throw Throwables.propagate(e.getCause()); + throw new RuntimeException(e.getCause()); } adminEventPublisher.publishAppCreation(applicationWithPrograms.getApplicationId(), applicationWithPrograms.getSpecification()); @@ -1147,7 +1145,7 @@ private ApplicationWithPrograms deployApp(NamespaceId namespaceId, @Nullable Str applicationWithPrograms = manager.deploy(deploymentInfo).get(); } catch (ExecutionException e) { Throwables.propagateIfPossible(e.getCause(), Exception.class); - throw Throwables.propagate(e.getCause()); + throw new RuntimeException(e.getCause()); } adminEventPublisher.publishAppCreation(applicationWithPrograms.getApplicationId(), diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/ProgramNotificationSubscriberService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/ProgramNotificationSubscriberService.java index 4b5b377fa234..74473d995c6c 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/ProgramNotificationSubscriberService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/services/ProgramNotificationSubscriberService.java @@ -162,7 +162,7 @@ protected void startUp() throws Exception { .forEach(i -> children.add(createChildService("program.status." + i, topicPrefix + i))); } delegate = new CompositeService(children); - delegate.startAndWait(); + delegate.startAsync().awaitRunning(); // Explicitly emit both launching and running counts on startup. emitFlowControlMetrics(); } @@ -218,7 +218,7 @@ private void restoreActiveRuns() { @Override protected void shutDown() throws Exception { - delegate.stopAndWait(); + delegate.stopAsync().awaitTerminated(); } @Inject(optional = true) diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/AppMetadataStore.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/AppMetadataStore.java index b610fba5b08b..c451a58f3f77 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/AppMetadataStore.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/AppMetadataStore.java @@ -373,9 +373,10 @@ public void scanApplications(ScanApplicationsRequest request, e -> ((ApplicationFilter.ApplicationIdFilter) filter).test(e.getKey())); } else if (filter instanceof ApplicationFilter.ArtifactIdFilter) { scanEntryPredicate = scanEntryPredicate.and( - e -> e.getArtifactId() - .map(((ApplicationFilter.ArtifactIdFilter) filter)::test) - .orElse(false)); + e -> { + ArtifactId artifactId = e.getArtifactId(); + return artifactId != null && ((ApplicationFilter.ArtifactIdFilter) filter).test(artifactId); + }); } else { throw new UnsupportedOperationException( "Application filter " + filter + " is not supported"); @@ -3136,9 +3137,6 @@ public static final class Cursor { private static final class AppScanEntry implements Map.Entry { - private static final String SPEC_KEY = "spec"; - private static final String ARTIFACT_ID_KEY = "artifactId"; - private final ApplicationId appId; private final String rawAppMeta; private volatile ApplicationMeta appMeta; @@ -3149,7 +3147,6 @@ private static final class AppScanEntry implements Map.Entry getArtifactId() { - ArtifactId id = artifactId; - if (id != null) { - return Optional.of(id); + @Nullable + public ArtifactId getArtifactId() { + ApplicationMeta meta = appMeta; + if (meta != null) { + return meta.getSpec().getArtifactId(); + } + if (rawAppMeta == null) { + return null; } - try (JsonReader reader = new JsonReader(new StringReader(rawAppMeta))) { reader.beginObject(); - - while (reader.hasNext()) { - if (SPEC_KEY.equals(reader.nextName())) { + while (reader.peek() != JsonToken.END_OBJECT) { + String name = reader.nextName(); + if (name.equals("spec")) { reader.beginObject(); - while (reader.hasNext()) { - if (ARTIFACT_ID_KEY.equals(reader.nextName())) { - id = GSON.fromJson(reader, ArtifactId.class); - artifactId = id; - return Optional.of(id); + while (reader.peek() != JsonToken.END_OBJECT) { + String specName = reader.nextName(); + if (specName.equals("artifactId")) { + return GSON.fromJson(reader, ArtifactId.class); } else { reader.skipValue(); } } - break; + reader.endObject(); } else { reader.skipValue(); } } - } catch (IOException | IllegalStateException e) { - throw new IllegalStateException("Failed to parse artifact ID from app meta", e); + reader.endObject(); + } catch (IOException e) { + LOG.warn("Failed to extract artifact id from raw application metadata", e); } - - return Optional.empty(); + return null; } @Override diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/ApplicationMeta.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/ApplicationMeta.java index 1db650299aeb..40305a28ccdf 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/ApplicationMeta.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/ApplicationMeta.java @@ -16,6 +16,7 @@ package io.cdap.cdap.internal.app.store; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import io.cdap.cdap.api.app.ApplicationSpecification; import io.cdap.cdap.internal.app.ApplicationSpecificationAdapter; @@ -69,7 +70,7 @@ public SourceControlMeta getSourceControlMeta() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("id", id) .add("spec", ADAPTER.toJson(spec)) .add("change", change) diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/adapters/PluginKey.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/adapters/PluginKey.java index 70f53476f686..f0f81895c5a6 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/adapters/PluginKey.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/adapters/PluginKey.java @@ -16,6 +16,7 @@ package io.cdap.cdap.internal.app.store.adapters; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; /** @@ -120,7 +121,7 @@ public boolean equals(Object o) { */ @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("parentName", parentName) .add("parentNamespace", parentNamespace) .add("artifactName", artifactName) diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/ConfiguratorTask.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/ConfiguratorTask.java index e810f6c015cd..19a3244b3e98 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/ConfiguratorTask.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/ConfiguratorTask.java @@ -14,8 +14,8 @@ package io.cdap.cdap.internal.app.worker; -import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Throwables; +import com.google.common.annotations.VisibleForTesting; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.inject.Guice; @@ -184,7 +184,7 @@ public ConfigResponse configure(AppDeploymentInfo info) throws Exception { // We don't need the ExecutionException being reported back to the RemoteTaskExecutor, hence only // propagating the actual cause. Throwables.propagateIfPossible(e.getCause(), Exception.class); - throw Throwables.propagate(e.getCause()); + throw new RuntimeException(e.getCause()); } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/TaskWorkerService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/TaskWorkerService.java index 294cbef60e50..07e117425772 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/TaskWorkerService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/TaskWorkerService.java @@ -20,7 +20,6 @@ import com.google.common.util.concurrent.AbstractIdleService; import com.google.inject.Inject; import io.cdap.cdap.api.metrics.MetricsCollectionService; -import io.cdap.cdap.api.service.worker.RunnableTask; import io.cdap.cdap.common.conf.CConfiguration; import io.cdap.cdap.common.conf.Constants; import io.cdap.cdap.common.conf.Constants.TaskWorker; @@ -126,7 +125,7 @@ private void stopService(String className) { * based on number of requests per particular class, * the service gets stopped. */ - stop(); + stopAsync(); } @VisibleForTesting diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/TaskWorkerTwillRunnable.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/TaskWorkerTwillRunnable.java index 527c158a8295..988ebb8e94f9 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/TaskWorkerTwillRunnable.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/TaskWorkerTwillRunnable.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.worker; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.Service; import com.google.common.util.concurrent.Uninterruptibles; @@ -61,11 +60,9 @@ import org.apache.hadoop.conf.Configuration; import org.apache.twill.api.AbstractTwillRunnable; import org.apache.twill.api.TwillContext; -import org.apache.twill.api.TwillRunnable; import org.apache.twill.common.Threads; import org.apache.twill.discovery.DiscoveryService; import org.apache.twill.discovery.DiscoveryServiceClient; -import org.apache.twill.internal.ServiceListenerAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -139,7 +136,11 @@ public void initialize(TwillContext context) { doInitialize(context); } catch (Exception e) { LOG.error("Encountered error while initializing TaskWorkerTwillRunnable", e); - Throwables.propagateIfPossible(e); + if (e instanceof RuntimeException) { + + throw (RuntimeException) e; + + } throw new RuntimeException(e); } } @@ -147,7 +148,7 @@ public void initialize(TwillContext context) { @Override public void run() { CompletableFuture future = new CompletableFuture<>(); - taskWorker.addListener(new ServiceListenerAdapter() { + taskWorker.addListener(new Service.Listener() { @Override public void terminated(Service.State from) { future.complete(from); @@ -160,7 +161,7 @@ public void failed(Service.State from, Throwable failure) { }, Threads.SAME_THREAD_EXECUTOR); LOG.debug("Starting task worker"); - taskWorker.start(); + taskWorker.startAsync(); try { Uninterruptibles.getUninterruptibly(future); @@ -173,9 +174,9 @@ public void failed(Service.State from, Throwable failure) { @Override public void stop() { LOG.info("Stopping task worker"); - Optional.ofNullable(metricsCollectionService).map(MetricsCollectionService::stop); + Optional.ofNullable(metricsCollectionService).ifPresent(MetricsCollectionService::stopAsync); if (taskWorker != null) { - taskWorker.stop(); + taskWorker.stopAsync(); } } @@ -203,7 +204,7 @@ private void doInitialize(TwillContext context) throws Exception { logAppenderInitializer.initialize(); metricsCollectionService = injector.getInstance(MetricsCollectionService.class); - metricsCollectionService.startAndWait(); + metricsCollectionService.startAsync().awaitRunning(); LoggingContext loggingContext = new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/sidecar/ArtifactLocalizerTwillRunnable.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/sidecar/ArtifactLocalizerTwillRunnable.java index 67091c898206..f189b88bdfdb 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/sidecar/ArtifactLocalizerTwillRunnable.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/sidecar/ArtifactLocalizerTwillRunnable.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.worker.sidecar; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.Service; import com.google.common.util.concurrent.Uninterruptibles; @@ -65,11 +64,9 @@ import org.apache.hadoop.conf.Configuration; import org.apache.twill.api.AbstractTwillRunnable; import org.apache.twill.api.TwillContext; -import org.apache.twill.api.TwillRunnable; import org.apache.twill.common.Threads; import org.apache.twill.discovery.DiscoveryService; import org.apache.twill.discovery.DiscoveryServiceClient; -import org.apache.twill.internal.ServiceListenerAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -159,7 +156,11 @@ public void initialize(TwillContext context) { doInitialize(); } catch (Exception e) { LOG.error("Encountered error while initializing ArtifactLocalizerTwillRunnable", e); - Throwables.propagateIfPossible(e); + if (e instanceof RuntimeException) { + + throw (RuntimeException) e; + + } throw new RuntimeException(e); } } @@ -167,7 +168,7 @@ public void initialize(TwillContext context) { @Override public void run() { CompletableFuture future = new CompletableFuture<>(); - artifactLocalizerService.addListener(new ServiceListenerAdapter() { + artifactLocalizerService.addListener(new Service.Listener() { @Override public void terminated(Service.State from) { future.complete(from); @@ -180,7 +181,7 @@ public void failed(Service.State from, Throwable failure) { }, Threads.SAME_THREAD_EXECUTOR); LOG.debug("Starting artifact localizer"); - artifactLocalizerService.start(); + artifactLocalizerService.startAsync(); try { Uninterruptibles.getUninterruptibly(future); @@ -191,13 +192,13 @@ public void failed(Service.State from, Throwable failure) { @Override public void stop() { - artifactLocalizerService.stop(); + artifactLocalizerService.stopAsync(); } @Override public void destroy() { try { - tokenManager.stopAndWait(); + tokenManager.stopAsync().awaitTerminated(); } finally { logAppenderInitializer.close(); } @@ -225,7 +226,7 @@ void doInitialize() throws Exception { LoggingContextAccessor.setLoggingContext(loggingContext); tokenManager = injector.getInstance(TokenManager.class); - tokenManager.startAndWait(); + tokenManager.startAsync().awaitRunning(); artifactLocalizerService = injector.getInstance(ArtifactLocalizerService.class); } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/system/SystemWorkerService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/system/SystemWorkerService.java index c374f8e77da5..5060aad39c4b 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/system/SystemWorkerService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/system/SystemWorkerService.java @@ -21,7 +21,6 @@ import com.google.inject.Inject; import com.google.inject.Injector; import io.cdap.cdap.api.metrics.MetricsCollectionService; -import io.cdap.cdap.api.service.worker.RunnableTask; import io.cdap.cdap.common.conf.CConfiguration; import io.cdap.cdap.common.conf.Constants; import io.cdap.cdap.common.conf.SConfiguration; @@ -106,7 +105,7 @@ public void modify(ChannelPipeline pipeline) { @Override protected void startUp() throws Exception { LOG.debug("Starting SystemWorkerService"); - tokenManager.startAndWait(); + tokenManager.startAsync().awaitRunning(); provisioningService.initializeProvisionersAndExecutors(); twillRunnerService.start(); remoteTwillRunnerService.start(); @@ -121,7 +120,7 @@ protected void startUp() throws Exception { @Override protected void shutDown() throws Exception { LOG.debug("Shutting down SystemWorkerService"); - tokenManager.stop(); + tokenManager.stopAsync(); twillRunnerService.stop(); remoteTwillRunnerService.stop(); httpService.stop(1, 2, TimeUnit.SECONDS); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/system/SystemWorkerTwillRunnable.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/system/SystemWorkerTwillRunnable.java index 18c27da9c734..6fd04bd4b7d3 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/system/SystemWorkerTwillRunnable.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/worker/system/SystemWorkerTwillRunnable.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.worker.system; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.Service; import com.google.common.util.concurrent.Uninterruptibles; @@ -100,13 +99,11 @@ import org.apache.tephra.TransactionSystemClient; import org.apache.twill.api.AbstractTwillRunnable; import org.apache.twill.api.TwillContext; -import org.apache.twill.api.TwillRunnable; import org.apache.twill.api.TwillRunner; import org.apache.twill.api.TwillRunnerService; import org.apache.twill.common.Threads; import org.apache.twill.discovery.DiscoveryService; import org.apache.twill.discovery.DiscoveryServiceClient; -import org.apache.twill.internal.ServiceListenerAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -265,7 +262,11 @@ public void initialize(TwillContext context) { doInitialize(); } catch (Exception e) { LOG.error("Encountered error while initializing SystemWorkerTwillRunnable", e); - Throwables.propagateIfPossible(e); + if (e instanceof RuntimeException) { + + throw (RuntimeException) e; + + } throw new RuntimeException(e); } } @@ -273,7 +274,7 @@ public void initialize(TwillContext context) { @Override public void run() { CompletableFuture future = new CompletableFuture<>(); - systemWorker.addListener(new ServiceListenerAdapter() { + systemWorker.addListener(new Service.Listener() { @Override public void terminated(Service.State from) { future.complete(from); @@ -286,9 +287,9 @@ public void failed(Service.State from, Throwable failure) { }, Threads.SAME_THREAD_EXECUTOR); LOG.debug("Starting system worker"); - systemWorker.start(); + systemWorker.startAsync(); if (artifactLocalizerService != null) { - artifactLocalizerService.start(); + artifactLocalizerService.startAsync(); } try { @@ -302,12 +303,12 @@ public void failed(Service.State from, Throwable failure) { @Override public void stop() { LOG.info("Stopping system worker"); - Optional.ofNullable(metricsCollectionService).map(MetricsCollectionService::stop); + Optional.ofNullable(metricsCollectionService).ifPresent(MetricsCollectionService::stopAsync); if (systemWorker != null) { - systemWorker.stop(); + systemWorker.stopAsync(); } if (artifactLocalizerService != null) { - artifactLocalizerService.stop(); + artifactLocalizerService.stopAsync(); } } @@ -342,7 +343,7 @@ void doInitialize() throws Exception { logAppenderInitializer.initialize(); metricsCollectionService = injector.getInstance(MetricsCollectionService.class); - metricsCollectionService.startAndWait(); + metricsCollectionService.startAsync().awaitRunning(); LoggingContext loggingContext = new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/bootstrap/BootstrapService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/bootstrap/BootstrapService.java index 70f95fe93b77..fa4a8bda1af4 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/bootstrap/BootstrapService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/bootstrap/BootstrapService.java @@ -108,13 +108,13 @@ protected void startUp() { // LOAD_SYSTEM_ARTIFACT step. // TODO(CDAP-16243): Find better way to add dependency between BootStrapService and SystemAppManagementService. try { - this.systemAppManagementService.start(); + this.systemAppManagementService.startAsync(); } catch (Exception e) { LOG.info("SystemAppManagementService could not start due to exception.", e); } // TODO - Move this back to AppFabricServer once CDAP-17578 is fixed - systemProgramManagementService.start(); - capabilityManagementService.start(); + systemProgramManagementService.startAsync(); + capabilityManagementService.startAsync(); }); LOG.info("Started {}", getClass().getSimpleName()); } @@ -125,9 +125,9 @@ protected void shutDown() throws Exception { // Shutdown the executor, which will issue an interrupt to the running thread. // There is only a single daemon thread, so no need to wait for termination executorService.shutdownNow(); - this.systemAppManagementService.stopAndWait(); - capabilityManagementService.stopAndWait(); - systemProgramManagementService.stopAndWait(); + this.systemAppManagementService.stopAsync().awaitTerminated(); + capabilityManagementService.stopAsync().awaitTerminated(); + systemProgramManagementService.stopAsync().awaitTerminated(); LOG.info("Stopped {}", getClass().getSimpleName()); } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/capability/autoinstall/HubPackage.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/capability/autoinstall/HubPackage.java index acfca6459846..f76a43bc704a 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/capability/autoinstall/HubPackage.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/capability/autoinstall/HubPackage.java @@ -18,7 +18,6 @@ import com.google.common.base.Joiner; import com.google.common.collect.ImmutableSet; -import com.google.common.io.Closeables; import com.google.gson.Gson; import com.google.gson.JsonObject; import io.cdap.cdap.api.artifact.ArtifactRange; @@ -180,7 +179,11 @@ public boolean onReceived(ByteBuffer buffer) { @Override public void onFinished() { - Closeables.closeQuietly(channel); + try { + channel.close(); + } catch (Exception ignored) { + // Ignored because we are performing resource cleanup of the file channel on finishing. + } } }).build(); HttpClients.executeStreamingRequest(request); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/events/EventSubscriberManager.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/events/EventSubscriberManager.java index f41539a1db32..d73d894bac9b 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/events/EventSubscriberManager.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/events/EventSubscriberManager.java @@ -50,7 +50,7 @@ protected void startUp() throws Exception { // Initialize the event subscribers with all the event readers provided by provider try { eventSubscriber.initialize(); - eventSubscriber.startAndWait(); + eventSubscriber.startAsync().awaitRunning(); LOG.info("Successfully initialized eventSubscriber: {}", eventSubscriber); } catch (Exception e) { @@ -67,7 +67,7 @@ protected void shutDown() throws Exception { } eventSubscribers.forEach(eventSubscriber -> { try { - eventSubscriber.stopAndWait(); + eventSubscriber.stopAsync().awaitTerminated(); } catch (Exception e) { LOG.error("Failed to stop subscriber", e); } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/events/ProgramStatusEventPublisher.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/events/ProgramStatusEventPublisher.java index ff2461fd8387..32fd1477ffc1 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/events/ProgramStatusEventPublisher.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/events/ProgramStatusEventPublisher.java @@ -108,12 +108,12 @@ public void initialize(Collection eventWriters) { @Override public void startPublish() { - super.startAndWait(); + super.startAsync().awaitRunning(); } @Override public void stopPublish() { - this.stop(); + this.stopAsync(); } @Override diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/InMemoryOperationController.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/InMemoryOperationController.java index 17973486d2a4..99f85b611272 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/InMemoryOperationController.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/InMemoryOperationController.java @@ -24,7 +24,6 @@ import io.cdap.cdap.proto.operation.OperationError; import java.util.Collections; import org.apache.twill.common.Threads; -import org.apache.twill.internal.ServiceListenerAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,7 +51,7 @@ public class InMemoryOperationController implements @Override public ListenableFuture stop() { LOG.trace("Stopping operation {}", runId); - driver.stop(); + driver.stopAsync(); return completionFuture; } @@ -62,7 +61,7 @@ public ListenableFuture complete() { } private void startListen(Service service) { - service.addListener(new ServiceListenerAdapter() { + service.addListener(new Service.Listener() { @Override public void running() { statePublisher.publishRunning(runId); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/InMemoryOperationRunner.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/InMemoryOperationRunner.java index 513b160b5e3b..6946cd15d9d2 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/InMemoryOperationRunner.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/InMemoryOperationRunner.java @@ -45,7 +45,7 @@ public OperationController run(OperationRunDetail detail) throws IllegalStateExc OperationDriver driver = new OperationDriver(createOperation(detail), context); OperationController controller = new InMemoryOperationController(context.getRunId(), statePublisher, driver); - driver.start(); + driver.startAsync(); return controller; } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/MessagingOperationStatePublisher.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/MessagingOperationStatePublisher.java index 8f24bb74d542..f6bd00dd3314 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/MessagingOperationStatePublisher.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/MessagingOperationStatePublisher.java @@ -18,7 +18,6 @@ import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.google.gson.Gson; import com.google.inject.Inject; @@ -186,7 +185,7 @@ public void publish(OperationRunId runId, Map properties) { LOG.trace("Published operation status notification: {}", notification); done = true; } catch (IOException | AccessException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } catch (TopicNotFoundException | ServiceUnavailableException e) { // These exceptions are retry-able due to TMS not completely started if (startTime < 0) { @@ -195,7 +194,7 @@ public void publish(OperationRunId runId, Map properties) { long retryMillis = retryStrategy.nextRetry(++failureCount, startTime); if (retryMillis < 0) { LOG.error("Failed to publish messages to TMS and exceeded retry limit.", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } LOG.debug("Failed to publish messages to TMS due to {}. Will be retried in {} ms.", e.getMessage(), retryMillis); diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/OperationNotificationSubscriberService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/OperationNotificationSubscriberService.java index ae20897617f2..afc28ee4af41 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/OperationNotificationSubscriberService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/OperationNotificationSubscriberService.java @@ -93,7 +93,7 @@ protected void startUp() throws Exception { .forEach(i -> children.add(createChildService("operation.status." + i, topicPrefix + i))); delegate = new CompositeService(children); - delegate.startAndWait(); + delegate.startAsync().awaitRunning(); } // Sends STARTING notification for all STARTING operations @@ -130,7 +130,7 @@ private void processStoppingOperations(StructuredTableContext context) throws Ex @Override protected void shutDown() throws Exception { - delegate.stopAndWait(); + delegate.stopAsync().awaitTerminated(); } private OperationNotificationSingleTopicSubscriberService createChildService( diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/profile/AdminEventPublisher.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/profile/AdminEventPublisher.java index 2a73635cbd34..2584f07d0f82 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/profile/AdminEventPublisher.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/profile/AdminEventPublisher.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.profile; -import com.google.common.base.Throwables; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import io.cdap.cdap.api.app.ApplicationSpecification; @@ -151,7 +150,7 @@ private void publishMessage(EntityId entityId, MetadataMessage.Type type, } catch (TopicNotFoundException | ServiceUnavailableException e) { throw new RetryableException(e); } catch (IOException | AccessException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } return null; }, diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/provision/ProvisioningService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/provision/ProvisioningService.java index a23e15788f96..58cc2d31f059 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/provision/ProvisioningService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/provision/ProvisioningService.java @@ -16,8 +16,8 @@ package io.cdap.cdap.internal.provision; -import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Throwables; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Sets; import com.google.common.util.concurrent.AbstractIdleService; import com.google.gson.Gson; diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/master/environment/k8s/AbstractServiceMain.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/master/environment/k8s/AbstractServiceMain.java index 8f4996468171..599039b50b46 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/master/environment/k8s/AbstractServiceMain.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/master/environment/k8s/AbstractServiceMain.java @@ -226,7 +226,7 @@ public final void start() { LOG.info("Starting all services for {}", getClass().getName()); for (Service service : services) { LOG.info("Starting service {} for {}", service, getClass().getName()); - service.startAndWait(); + service.startAsync().awaitRunning(); } LOG.info("All services for {} started", getClass().getName()); } @@ -237,7 +237,7 @@ public final void stop() { for (Service service : Lists.reverse(services)) { LOG.info("Stopping service {} for {}", service, getClass().getName()); try { - service.stopAndWait(); + service.stopAsync().awaitTerminated(); } catch (Exception e) { // Catch and log exception on stopping to make sure each service has a chance to stop LOG.warn("Exception raised when stopping service {} for {}", service, getClass().getName(), diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/master/environment/k8s/MasterEnvironmentMain.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/master/environment/k8s/MasterEnvironmentMain.java index 71bef4a011c9..e5b0c1ba756f 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/master/environment/k8s/MasterEnvironmentMain.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/master/environment/k8s/MasterEnvironmentMain.java @@ -39,8 +39,6 @@ import io.cdap.cdap.master.spi.environment.MasterEnvironmentRunnableContext; import io.cdap.cdap.security.auth.TokenManager; import io.cdap.cdap.security.auth.context.AuthenticationContextModules; -import io.cdap.cdap.security.auth.context.SystemAuthenticationContext; -import io.cdap.cdap.security.auth.context.WorkerAuthenticationContext; import io.cdap.cdap.security.guice.CoreSecurityRuntimeModule; import io.cdap.cdap.security.impersonation.SecurityUtil; import io.cdap.cdap.security.spi.authenticator.RemoteAuthenticator; @@ -159,7 +157,7 @@ public static void doMain(String[] args) throws Exception { runnable.stop(); Uninterruptibles.awaitUninterruptibly(shutdownLatch, 30, TimeUnit.SECONDS); } - Optional.ofNullable(tokenManager).ifPresent(TokenManager::stopAndWait); + Optional.ofNullable(tokenManager).ifPresent(s -> s.stopAsync().awaitTerminated()); })); runnable.run(runnableArgs); completed.set(true); @@ -192,7 +190,7 @@ private static InternalAuthenticator getInternalAuthenticator(CConfiguration cCo new AuthenticationContextModules().getMasterModule()); if (cConf.getBoolean(Constants.Security.INTERNAL_AUTH_ENABLED)) { tokenManager = injector.getInstance(TokenManager.class); - tokenManager.startAndWait(); + tokenManager.startAsync().awaitRunning(); } } else { // cdap-secret is NOT mounted, use worker authentication context diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/metadata/MetadataValidator.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/metadata/MetadataValidator.java index 40dd0c34e134..5cc856f794c7 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/metadata/MetadataValidator.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/metadata/MetadataValidator.java @@ -42,7 +42,7 @@ public class MetadataValidator { .or(CharMatcher.inRange('0', '9')) .or(CharMatcher.is('_')) .or(CharMatcher.is('-')) - .or(CharMatcher.WHITESPACE); + .or(CharMatcher.whitespace()); private final int maxCharacters; diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/operations/OperationalStatsService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/operations/OperationalStatsService.java index ca2b3f30df3e..a366f8edd745 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/operations/OperationalStatsService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/operations/OperationalStatsService.java @@ -34,7 +34,6 @@ import javax.management.InstanceNotFoundException; import javax.management.MBeanRegistrationException; import javax.management.MBeanServer; -import javax.management.MXBean; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import org.apache.thrift.TException; @@ -137,7 +136,10 @@ private void collectOperationalStats() throws InterruptedException { try { stats.collect(); } catch (Throwable t) { - Throwables.propagateIfInstanceOf(t, InterruptedException.class); + if (t instanceof InterruptedException) { + // Propagate InterruptedException to allow the service run loop to stop properly. + throw (InterruptedException) t; + } Throwable rootCause = Throwables.getRootCause(t); if (rootCause instanceof ServiceUnavailableException || rootCause instanceof TException) { // Required service (for example DatasetService in case of ServiceUnavailableException @@ -214,7 +216,7 @@ private ObjectName getObjectName(OperationalStats operationalStats) { return new ObjectName(OperationalStatsUtils.JMX_DOMAIN, properties); } catch (MalformedObjectNameException e) { // should never happen, since we're constructing a valid domain name, and properties is non-empty - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/ConstraintCheckerService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/ConstraintCheckerService.java index e6f12fcbff06..65d12099f726 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/ConstraintCheckerService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/ConstraintCheckerService.java @@ -192,9 +192,9 @@ private boolean checkJobConstraints(JobQueue jobQueue) throws IOException { boolean emptyScan = true; try (CloseableIterator jobQueueIter = jobQueue.getJobs(partition, lastConsumed)) { - Stopwatch stopWatch = new Stopwatch().start(); + Stopwatch stopWatch = Stopwatch.createUnstarted().start(); // limit the batches of the scan to 1000ms - while (!stopping && stopWatch.elapsedMillis() < 1000) { + while (!stopping && stopWatch.elapsed(java.util.concurrent.TimeUnit.MILLISECONDS) < 1000) { if (!jobQueueIter.hasNext()) { lastConsumed = null; return emptyScan; diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/CoreSchedulerService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/CoreSchedulerService.java index 51507d596861..37530b026f73 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/CoreSchedulerService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/CoreSchedulerService.java @@ -17,7 +17,6 @@ package io.cdap.cdap.scheduler; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import com.google.common.util.concurrent.AbstractIdleService; import com.google.common.util.concurrent.Service; import com.google.common.util.concurrent.Uninterruptibles; @@ -115,25 +114,25 @@ public class CoreSchedulerService extends AbstractIdleService implements Schedul this.internalService = new RetryOnStartFailureService(() -> new AbstractIdleService() { @Override - protected Executor executor(final State state) { - return command -> new Thread(command, "core scheduler service " + state).start(); + protected Executor executor() { + return command -> new Thread(command, "core scheduler service " + state()).start(); } @Override protected void startUp() { - timeSchedulerService.startAndWait(); + timeSchedulerService.startAsync().awaitRunning(); cleanupJobs(); - constraintCheckerService.startAndWait(); - scheduleNotificationSubscriberService.startAndWait(); + constraintCheckerService.startAsync().awaitRunning(); + scheduleNotificationSubscriberService.startAsync().awaitRunning(); startedLatch.countDown(); LOG.info("Started core scheduler service."); } @Override protected void shutDown() { - scheduleNotificationSubscriberService.stopAndWait(); - constraintCheckerService.stopAndWait(); - timeSchedulerService.stopAndWait(); + scheduleNotificationSubscriberService.stopAsync().awaitTerminated(); + constraintCheckerService.stopAsync().awaitTerminated(); + timeSchedulerService.stopAsync().awaitTerminated(); LOG.info("Stopped core scheduler service."); } }, io.cdap.cdap.common.service.RetryStrategies.exponentialDelay(200, 5000, @@ -203,12 +202,12 @@ private void checkStarted() { @Override protected void startUp() throws Exception { - internalService.startAndWait(); + internalService.startAsync().awaitRunning(); } @Override protected void shutDown() throws Exception { - internalService.stopAndWait(); + internalService.stopAsync().awaitTerminated(); } @Override @@ -276,7 +275,7 @@ public void addSchedules(Iterable schedules) } catch (NotFoundException | ProfileConflictException | AlreadyExistsException e) { throw e; } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -320,7 +319,7 @@ public void enableSchedule(ScheduleId scheduleId) throws NotFoundException, Conf // TODO: [CDAP-11574] temporarily catch the SchedulerException and throw RuntimeException. throw new RuntimeException("Exception occurs when enabling schedule " + scheduleId, e); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -344,7 +343,7 @@ public void disableSchedule(ScheduleId scheduleId) throws NotFoundException, Con // TODO: [CDAP-11574] temporarily catch the SchedulerException and throw RuntimeException. throw new RuntimeException("Exception occurs when enabling schedule " + scheduleId, e); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -565,7 +564,7 @@ public void reEnableSchedules(NamespaceId namespaceId, long startTimeMillis, lon // TODO: [CDAP-11574] temporarily catch the SchedulerException and throw RuntimeException. throw new RuntimeException("Exception occurs when enabling schedules", e); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/ProgramScheduleService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/ProgramScheduleService.java index 751bb8d6d0dd..6ab969a8bfa8 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/ProgramScheduleService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/ProgramScheduleService.java @@ -16,19 +16,14 @@ package io.cdap.cdap.scheduler; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.inject.Inject; import io.cdap.cdap.api.ProgramStatus; import io.cdap.cdap.api.schedule.Trigger; -import io.cdap.cdap.common.AlreadyExistsException; import io.cdap.cdap.common.BadRequestException; -import io.cdap.cdap.common.ConflictException; -import io.cdap.cdap.common.NotFoundException; -import io.cdap.cdap.common.ProfileConflictException; import io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule; import io.cdap.cdap.internal.app.runtime.schedule.ProgramScheduleRecord; import io.cdap.cdap.internal.app.runtime.schedule.ProgramScheduleStatus; -import io.cdap.cdap.internal.app.runtime.schedule.SchedulerException; import io.cdap.cdap.internal.app.runtime.schedule.TimeSchedulerService; import io.cdap.cdap.internal.app.runtime.schedule.store.Schedulers; import io.cdap.cdap.internal.schedule.constraint.Constraint; @@ -43,7 +38,6 @@ import io.cdap.cdap.proto.security.StandardPermission; import io.cdap.cdap.security.spi.authentication.AuthenticationContext; import io.cdap.cdap.security.spi.authorization.AccessEnforcer; -import io.cdap.cdap.security.spi.authorization.UnauthorizedException; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -153,13 +147,13 @@ public void update(ScheduleId scheduleId, ScheduleDetail scheduleDetail) throws ApplicationPermission.EXECUTE); ProgramSchedule existing = scheduler.getSchedule(scheduleId); - String description = Objects.firstNonNull(scheduleDetail.getDescription(), + String description = MoreObjects.firstNonNull(scheduleDetail.getDescription(), existing.getDescription()); ProgramId programId = scheduleDetail.getProgram() == null ? existing.getProgramId() : existing.getProgramId().getParent().program( scheduleDetail.getProgram().getProgramType() == null ? existing.getProgramId().getType() : ProgramType.valueOfSchedulableType(scheduleDetail.getProgram().getProgramType()), - Objects.firstNonNull(scheduleDetail.getProgram().getProgramName(), + MoreObjects.firstNonNull(scheduleDetail.getProgram().getProgramName(), existing.getProgramId().getProgram())); if (!programId.equals(existing.getProgramId())) { throw new BadRequestException( @@ -167,12 +161,12 @@ public void update(ScheduleId scheduleId, ScheduleDetail scheduleDetail) throws + "To change the program in a schedule, please delete the schedule and create a new one.", existing.getName(), existing.getProgramId().toString())); } - Map properties = Objects.firstNonNull(scheduleDetail.getProperties(), + Map properties = MoreObjects.firstNonNull(scheduleDetail.getProperties(), existing.getProperties()); - Trigger trigger = Objects.firstNonNull(scheduleDetail.getTrigger(), existing.getTrigger()); + Trigger trigger = MoreObjects.firstNonNull(scheduleDetail.getTrigger(), existing.getTrigger()); List constraints = - Objects.firstNonNull(scheduleDetail.getConstraints(), existing.getConstraints()); - Long timeoutMillis = Objects.firstNonNull(scheduleDetail.getTimeoutMillis(), + MoreObjects.firstNonNull(scheduleDetail.getConstraints(), existing.getConstraints()); + Long timeoutMillis = MoreObjects.firstNonNull(scheduleDetail.getTimeoutMillis(), existing.getTimeoutMillis()); ProgramSchedule updatedSchedule = new ProgramSchedule(existing.getName(), description, programId, properties, diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/ScheduleNotificationSubscriberService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/ScheduleNotificationSubscriberService.java index 8790002ce660..24bd7130df87 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/ScheduleNotificationSubscriberService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/ScheduleNotificationSubscriberService.java @@ -18,7 +18,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.AbstractIdleService; -import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Service; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; @@ -51,10 +50,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; -import java.util.stream.Collectors; import javax.annotation.Nullable; import org.apache.twill.common.Threads; import org.slf4j.Logger; @@ -96,22 +93,19 @@ protected void startUp() throws Exception { 1, Threads.createDaemonThreadFactory("scheduler-notification-subscriber-%d")); // Start all subscriber services. All of them has no-op in start, so they shouldn't fail. - Futures.successfulAsList( - subscriberServices.stream().map(Service::start).collect(Collectors.toList())).get(); + subscriberServices.forEach(Service::startAsync); } @Override protected void shutDown() throws Exception { // This never throw - Futures.successfulAsList( - subscriberServices.stream().map(Service::stop).collect(Collectors.toList())).get(); + subscriberServices.forEach(Service::stopAsync); for (Service service : subscriberServices) { - // The service must have been stopped, and calling stop again will just return immediate with the - // future that carries the stop state. + // The service must have been stopped, and calling stopAsync again is a no-op. try { - service.stop().get(); - } catch (ExecutionException e) { + service.awaitTerminated(); + } catch (IllegalStateException e) { LOG.warn("Exception raised when stopping service {}", service, e.getCause()); } } diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/security/auth/AuditLogSubscriberService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/security/auth/AuditLogSubscriberService.java index d18d0bc2d55a..539d764f1353 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/security/auth/AuditLogSubscriberService.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/security/auth/AuditLogSubscriberService.java @@ -69,13 +69,13 @@ protected void startUp() throws Exception { .forEach(i -> children.add(createChildService(topicPrefix + i))); delegate = new CompositeService(children); - delegate.startAndWait(); + delegate.startAsync().awaitRunning(); LOG.debug("Started Audit Log subscriber service for {} partitions.", numPartitions); } @Override protected void shutDown() throws Exception { - delegate.stopAndWait(); + delegate.stopAsync().awaitTerminated(); } private AuditLogSingleTopicSubscriberService createChildService(String topicName) { diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/security/hive/JobHistoryServerTokenUtils.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/security/hive/JobHistoryServerTokenUtils.java index 3bb1f4746914..d8159d149b5a 100644 --- a/cdap-app-fabric/src/main/java/io/cdap/cdap/security/hive/JobHistoryServerTokenUtils.java +++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/security/hive/JobHistoryServerTokenUtils.java @@ -16,7 +16,6 @@ package io.cdap.cdap.security.hive; -import com.google.common.base.Throwables; import com.google.common.net.HostAndPort; import io.cdap.cdap.common.security.YarnTokenUtils; import java.io.IOException; @@ -65,7 +64,7 @@ public static Credentials obtainToken(Configuration configuration, Credentials c GetDelegationTokenRequest request = new GetDelegationTokenRequestPBImpl(); request.setRenewer(YarnUtils.getYarnTokenRenewer(configuration)); - InetSocketAddress address = new InetSocketAddress(hostAndPort.getHostText(), + InetSocketAddress address = new InetSocketAddress(hostAndPort.getHost(), hostAndPort.getPort()); Token token = ConverterUtils.convertFromYarn(hsProxy.getDelegationToken(request).getDelegationToken(), @@ -75,7 +74,7 @@ public static Credentials obtainToken(Configuration configuration, Credentials c LOG.debug("Adding JobHistoryServer delegation token {}.", token); return credentials; } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithMisbehavedDataset.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithMisbehavedDataset.java index 92f00682edcb..48a8506462e5 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithMisbehavedDataset.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithMisbehavedDataset.java @@ -16,7 +16,6 @@ package io.cdap.cdap; -import com.google.common.base.Throwables; import io.cdap.cdap.api.TxRunnable; import io.cdap.cdap.api.app.AbstractApplication; import io.cdap.cdap.api.data.DatasetContext; @@ -120,7 +119,7 @@ public void run(DatasetContext context) throws Exception { } }); } catch (TransactionFailureException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithSchedule.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithSchedule.java index 5c42a5052598..9c60776b55f5 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithSchedule.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithSchedule.java @@ -17,7 +17,6 @@ package io.cdap.cdap; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.common.collect.Maps; import com.google.common.util.concurrent.Uninterruptibles; import io.cdap.cdap.api.Config; @@ -90,7 +89,7 @@ public void configure() { .triggerByTime("0/30 * * * * ?")); } } catch (UnsupportedTypeException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithWorker.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithWorker.java index 17c8d1025e74..8cdc282fa488 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithWorker.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithWorker.java @@ -16,7 +16,6 @@ package io.cdap.cdap; -import com.google.common.base.Throwables; import io.cdap.cdap.api.TxRunnable; import io.cdap.cdap.api.app.AbstractApplication; import io.cdap.cdap.api.data.DatasetContext; @@ -95,7 +94,7 @@ public void run(DatasetContext context) throws Exception { } }); } catch (TransactionFailureException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithWorkflow.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithWorkflow.java index 740a4e94629f..32f0aee2aa1b 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithWorkflow.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/AppWithWorkflow.java @@ -16,7 +16,6 @@ package io.cdap.cdap; -import com.google.common.base.Throwables; import io.cdap.cdap.api.app.AbstractApplication; import io.cdap.cdap.api.customaction.AbstractCustomAction; import io.cdap.cdap.api.data.schema.UnsupportedTypeException; @@ -52,7 +51,7 @@ public void configure() { addMapReduce(new WordCountMapReduce()); addWorkflow(new SampleWorkflow()); } catch (UnsupportedTypeException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/CapabilityAppWithWorkflow.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/CapabilityAppWithWorkflow.java index 54ebf0c4eda5..868dcd469c77 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/CapabilityAppWithWorkflow.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/CapabilityAppWithWorkflow.java @@ -16,7 +16,6 @@ package io.cdap.cdap; -import com.google.common.base.Throwables; import io.cdap.cdap.api.annotation.Requirements; import io.cdap.cdap.api.app.AbstractApplication; import io.cdap.cdap.api.customaction.AbstractCustomAction; @@ -54,7 +53,7 @@ public void configure() { addMapReduce(new WordCountMapReduce()); addWorkflow(new SampleWorkflow()); } catch (UnsupportedTypeException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/ConcurrentWorkflowApp.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/ConcurrentWorkflowApp.java index 8d56675e3571..5fab4a3bc131 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/ConcurrentWorkflowApp.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/ConcurrentWorkflowApp.java @@ -17,7 +17,6 @@ package io.cdap.cdap; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import io.cdap.cdap.api.app.AbstractApplication; import io.cdap.cdap.api.customaction.AbstractCustomAction; import io.cdap.cdap.api.workflow.AbstractWorkflow; @@ -68,7 +67,7 @@ public void run() { Preconditions.checkArgument(file.createNewFile()); } catch (IOException e) { LOG.error("Exception while creating file {}", file, e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } File doneFile = new File(runtimeArguments.get(DONE_FILE_ARG)); diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/WorkflowAppWithFork.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/WorkflowAppWithFork.java index 1b1778b26ece..4042f4f48ae3 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/WorkflowAppWithFork.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/WorkflowAppWithFork.java @@ -17,7 +17,6 @@ package io.cdap.cdap; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import io.cdap.cdap.api.app.AbstractApplication; import io.cdap.cdap.api.app.ProgramType; import io.cdap.cdap.api.customaction.AbstractCustomAction; @@ -77,7 +76,7 @@ public void run() { try { Preconditions.checkArgument(file.createNewFile(), "Failed to create file '%s'", file); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } File doneFile = new File(runtimeArguments.get(name + ".donefile")); try { diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/app/mapreduce/LocalMRJobInfoFetcherTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/app/mapreduce/LocalMRJobInfoFetcherTest.java index 6a05608c3b84..b1dfd5ab59ce 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/app/mapreduce/LocalMRJobInfoFetcherTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/app/mapreduce/LocalMRJobInfoFetcherTest.java @@ -57,10 +57,10 @@ public static void beforeClass() throws Exception { public static Injector startMetricsService(CConfiguration conf) throws Exception { Injector injector = Guice.createInjector(new AppFabricTestModule(conf)); - injector.getInstance(TransactionManager.class).startAndWait(); + injector.getInstance(TransactionManager.class).startAsync().awaitRunning(); StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); - injector.getInstance(DatasetOpExecutorService.class).startAndWait(); - injector.getInstance(DatasetService.class).startAndWait(); + injector.getInstance(DatasetOpExecutorService.class).startAsync().awaitRunning(); + injector.getInstance(DatasetService.class).startAsync().awaitRunning(); return injector; } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/app/runtime/AbstractProgramRuntimeServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/app/runtime/AbstractProgramRuntimeServiceTest.java index 4b1922a33ca6..071eb68c74d4 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/app/runtime/AbstractProgramRuntimeServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/app/runtime/AbstractProgramRuntimeServiceTest.java @@ -110,7 +110,7 @@ public void testConcurrentStartLimit() throws Exception { Service service = new FastService(); ProgramController controller = new ProgramControllerServiceAdapter(service, programId.run(RunIds.generate())); - service.start(); + service.startAsync().awaitRunning(); return controller; }; @@ -123,7 +123,7 @@ public void testConcurrentStartLimit() throws Exception { program, null, null); ProgramRuntimeService runtimeService = new TestProgramRuntimeService(cConf, runnerFactory, null, launchDispatcher); - runtimeService.startAndWait(); + runtimeService.startAsync().awaitRunning(); try { List controllers = new ArrayList<>(); for (int i = 0; i < 5; i++) { @@ -151,7 +151,7 @@ public void testConcurrentStartLimit() throws Exception { Assert.assertEquals(2, threadNames.size()); } finally { - runtimeService.stopAndWait(); + runtimeService.stopAsync().awaitTerminated(); } } @@ -166,7 +166,7 @@ public void testDeadlock() throws IOException, ExecutionException, InterruptedEx program, null, null); ProgramRuntimeService runtimeService = new TestProgramRuntimeService(cConf, runnerFactory, null, launchDispatcher); - runtimeService.startAndWait(); + runtimeService.startAsync().awaitRunning(); try { ProgramDescriptor descriptor = new ProgramDescriptor(program.getId(), null, NamespaceId.DEFAULT.artifact("test", "1.0")); @@ -178,7 +178,7 @@ public void testDeadlock() throws IOException, ExecutionException, InterruptedEx Tasks.waitFor(true, () -> runtimeService.list(ProgramType.WORKER).isEmpty(), 5, TimeUnit.SECONDS, 100, TimeUnit.MICROSECONDS); } finally { - runtimeService.stopAndWait(); + runtimeService.stopAsync().awaitTerminated(); } } @@ -190,20 +190,20 @@ public void testUpdateDeadLock() { ProgramId programId = NamespaceId.DEFAULT.app("dummyApp").program(ProgramType.WORKER, "dummy"); RunId runId = RunIds.generate(); ProgramRuntimeService.RuntimeInfo extraInfo = createRuntimeInfo(service, programId.run(runId)); - service.startAndWait(); + service.startAsync().awaitRunning(); ProgramRunnerFactory runnerFactory = createProgramRunnerFactory(); TestProgramRunDispatcher launchDispatcher = new TestProgramRunDispatcher(cConf, runnerFactory, null, null, null); TestProgramRuntimeService runtimeService = new TestProgramRuntimeService(cConf, runnerFactory, extraInfo, launchDispatcher); - runtimeService.startAndWait(); + runtimeService.startAsync().awaitRunning(); // The lookup will get deadlock for CDAP-3716 Assert.assertNotNull(runtimeService.lookup(programId, runId)); - service.stopAndWait(); + service.stopAsync().awaitTerminated(); - runtimeService.stopAndWait(); + runtimeService.stopAsync().awaitTerminated(); } @Test @@ -229,7 +229,7 @@ public ProgramLiveInfo getLiveInfo(ProgramId programId) { } }; - runtimeService.startAndWait(); + runtimeService.startAsync().awaitRunning(); try { try { ProgramDescriptor descriptor = new ProgramDescriptor(program.getId(), null, @@ -268,11 +268,11 @@ public ProgramLiveInfo getLiveInfo(ProgramId programId) { } } finally { - runtimeService.stopAndWait(); + runtimeService.stopAsync().awaitTerminated(); } } finally { - runtimeService.stopAndWait(); + runtimeService.stopAsync().awaitTerminated(); } } @@ -289,7 +289,7 @@ public void testTetheredRun() throws IOException, ExecutionException, Interrupte remoteClientFactory, true); ProgramRuntimeService runtimeService = new TestProgramRuntimeService(cConf, runnerFactory, null, launchDispatcher); - runtimeService.startAndWait(); + runtimeService.startAsync().awaitRunning(); try { ProgramDescriptor descriptor = new ProgramDescriptor(program.getId(), null, NamespaceId.DEFAULT.artifact("test", "1.0")); @@ -301,7 +301,7 @@ public void testTetheredRun() throws IOException, ExecutionException, Interrupte Tasks.waitFor(ProgramController.State.COMPLETED, controller::getState, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); } finally { - runtimeService.stopAndWait(); + runtimeService.stopAsync().awaitTerminated(); } } @@ -323,7 +323,7 @@ private ProgramRunnerFactory createProgramRunnerFactory(final Map startCompletion = service.start(); + service.startAsync(); controller.addListener(new AbstractListener() { private volatile boolean initCalled; @@ -86,8 +85,8 @@ public void alive() { } }, executor); - startCompletion.get(); - service.stopAndWait(); + service.awaitRunning(); + service.stopAsync().awaitTerminated(); } Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/app/runtime/monitor/TrafficRelayServerTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/app/runtime/monitor/TrafficRelayServerTest.java index 9d7cefc64ac6..ac901ae39731 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/app/runtime/monitor/TrafficRelayServerTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/app/runtime/monitor/TrafficRelayServerTest.java @@ -45,7 +45,7 @@ public void testRelay() throws Exception { try { TrafficRelayServer relayServer = new TrafficRelayServer(InetAddress.getLoopbackAddress(), httpServer::getBindAddress); - relayServer.startAndWait(); + relayServer.startAsync().awaitRunning(); try { InetSocketAddress relayAddr = relayServer.getBindAddress(); @@ -63,7 +63,7 @@ public void testRelay() throws Exception { Assert.assertEquals("Testing", response.getResponseBodyAsString()); } finally { - relayServer.stopAndWait(); + relayServer.stopAsync().awaitTerminated(); } } finally { httpServer.stop(); diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/AppFabricClient.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/AppFabricClient.java index f9e02e62d815..e5a181f62bb4 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/AppFabricClient.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/AppFabricClient.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; @@ -297,7 +296,7 @@ public List getProgramSchedules(String namespace, String app, St programScheduleHttpHandler.getProgramSchedules(request, responder, namespace, app, workflow, null, null, null); } catch (Exception e) { // cannot happen - throw Throwables.propagate(e); + throw new RuntimeException(e); } List schedules = responder.decodeResponseContent(SCHEDULE_DETAILS_TYPE, GSON); diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/AppFabricTestHelper.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/AppFabricTestHelper.java index 778af9f0d967..069290926eba 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/AppFabricTestHelper.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/AppFabricTestHelper.java @@ -20,7 +20,6 @@ import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; -import com.google.common.io.Closeables; import com.google.common.util.concurrent.Service; import com.google.gson.Gson; import com.google.inject.AbstractModule; @@ -213,10 +212,16 @@ public static synchronized Injector getInjector(CConfiguration conf, @Nullable S * This must be called by all tests that create their injector through this class. */ public static void shutdown() { - Closeables.closeQuietly(metadataStorage); + try { + + metadataStorage.close(); + + } catch (Exception ignored) { + + } if (services != null) { - Lists.reverse(services).forEach(Service::stopAndWait); + Lists.reverse(services).forEach(s -> s.stopAsync().awaitTerminated()); } InMemoryTableService.reset(); @@ -276,7 +281,7 @@ private static T startService(Injector injector, Class cls) { T instance = injector.getInstance(cls); if (instance instanceof Service) { services.add((Service) instance); - ((Service) instance).startAndWait(); + ((Service) instance).startAsync().awaitRunning(); } return instance; } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/TempFolder.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/TempFolder.java index 5b256f362a45..6ca704b8b61c 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/TempFolder.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/TempFolder.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal; -import com.google.common.base.Throwables; import io.cdap.cdap.common.utils.DirUtils; import java.io.File; import java.io.IOException; @@ -45,7 +44,7 @@ public TempFolder() { throw new RuntimeException("Could NOT create temp dir at " + folder.getAbsolutePath()); } } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -60,7 +59,7 @@ public File newFile(String fileName) throws IOException { } return file; } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/deploy/pipeline/SystemMetadataWriterStageTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/deploy/pipeline/SystemMetadataWriterStageTest.java index bc3c67b31a24..8dc21fa39fb0 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/deploy/pipeline/SystemMetadataWriterStageTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/deploy/pipeline/SystemMetadataWriterStageTest.java @@ -77,12 +77,12 @@ public static void setup() { metadataStorage = injector.getInstance(MetadataStorage.class); metadataServiceClient = injector.getInstance(MetadataServiceClient.class); metadataSubscriber = injector.getInstance(MetadataSubscriberService.class); - metadataSubscriber.startAndWait(); + metadataSubscriber.startAsync().awaitRunning(); } @AfterClass public static void stop() { - metadataSubscriber.stopAndWait(); + metadataSubscriber.stopAsync().awaitTerminated(); AppFabricTestHelper.shutdown(); } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/namespace/StorageProviderNamespaceAdminTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/namespace/StorageProviderNamespaceAdminTest.java index 0384430654cf..9c7f653a2e1e 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/namespace/StorageProviderNamespaceAdminTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/namespace/StorageProviderNamespaceAdminTest.java @@ -76,12 +76,12 @@ protected void configure() { storageProviderNamespaceAdmin = injector.getInstance(StorageProviderNamespaceAdmin.class); // start the dataset service for namespace store to work transactionManager = injector.getInstance(TransactionManager.class); - transactionManager.startAndWait(); + transactionManager.startAsync().awaitRunning(); // Define all StructuredTable before starting any services that need StructuredTable StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); datasetService = injector.getInstance(DatasetService.class); - datasetService.startAndWait(); + datasetService.startAsync().awaitRunning(); // we don't use namespace admin here but the store because namespaceadmin will try to create the // home directory for namespace which we don't want. We just want to store the namespace meta in store // to look up during the delete. @@ -234,7 +234,7 @@ public void testLocalStorageProviderNamespaceAdminWithExistingTempDirectory() th @AfterClass public static void cleanup() throws Exception { - transactionManager.stopAndWait(); - datasetService.stopAndWait(); + transactionManager.stopAsync().awaitTerminated(); + datasetService.stopAsync().awaitTerminated(); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/preview/PreviewRunnerServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/preview/PreviewRunnerServiceTest.java index b0c7ffc66a59..67d6f05846d9 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/preview/PreviewRunnerServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/preview/PreviewRunnerServiceTest.java @@ -56,10 +56,10 @@ public void testStartAndStop() throws InterruptedException, ExecutionException, MockPreviewRunner mockRunner = new MockPreviewRunner(); MockPreviewRequestFetcher fetcher = new MockPreviewRequestFetcher(); PreviewRunnerService runnerService = new PreviewRunnerService(createCConf(), fetcher, mockRunner); - runnerService.startAndWait(); + runnerService.startAsync().awaitRunning(); Tasks.waitFor(true, () -> fetcher.fetchCount.get() > 0, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); - runnerService.stopAndWait(); + runnerService.stopAsync().awaitTerminated(); Tasks.waitFor(Service.State.TERMINATED, runnerService::state, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); } @@ -68,14 +68,14 @@ public void testStopPreview() throws InterruptedException, ExecutionException, T MockPreviewRunner mockRunner = new MockPreviewRunner(); MockPreviewRequestFetcher fetcher = new MockPreviewRequestFetcher(); PreviewRunnerService runnerService = new PreviewRunnerService(createCConf(), fetcher, mockRunner); - runnerService.startAndWait(); + runnerService.startAsync().awaitRunning(); ProgramId programId = NamespaceId.DEFAULT.app("app").program(ProgramType.WORKFLOW, "workflow"); fetcher.addRequest(new PreviewRequest(programId, null, null)); Tasks.waitFor(true, () -> mockRunner.requests.get(programId) != null, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); - runnerService.stopAndWait(); + runnerService.stopAsync().awaitTerminated(); Tasks.waitFor(PreviewStatus.Status.KILLED, () -> mockRunner.requests.get(programId).status.getStatus(), 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); Tasks.waitFor(Service.State.TERMINATED, runnerService::state, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); @@ -89,7 +89,7 @@ public void testMaxRuns() throws InterruptedException, ExecutionException, Timeo MockPreviewRunner mockRunner = new MockPreviewRunner(); MockPreviewRequestFetcher fetcher = new MockPreviewRequestFetcher(); PreviewRunnerService runnerService = new PreviewRunnerService(cConf, fetcher, mockRunner); - runnerService.startAndWait(); + runnerService.startAsync().awaitRunning(); ProgramId programId = NamespaceId.DEFAULT.app("app").program(ProgramType.WORKFLOW, "workflow"); fetcher.addRequest(new PreviewRequest(programId, null, null)); diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/AppWithMapReduceUsingObjectStore.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/AppWithMapReduceUsingObjectStore.java index b2b5a3c200b4..3d4a07f41de8 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/AppWithMapReduceUsingObjectStore.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/AppWithMapReduceUsingObjectStore.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.app.runtime.batch; -import com.google.common.base.Throwables; import io.cdap.cdap.api.app.AbstractApplication; import io.cdap.cdap.api.common.Bytes; import io.cdap.cdap.api.data.batch.Input; @@ -44,7 +43,7 @@ public void configure() { ObjectStores.createObjectStore(getConfigurer(), "keys", String.class); addMapReduce(new ComputeCounts()); } catch (Throwable t) { - throw Throwables.propagate(t); + throw new RuntimeException(t); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceProgramRunnerTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceProgramRunnerTest.java index d4ee727b2b5c..c2baa32b7e61 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceProgramRunnerTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceProgramRunnerTest.java @@ -55,6 +55,7 @@ import java.io.FileWriter; import java.io.FilenameFilter; import java.io.IOException; +import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.URI; @@ -324,9 +325,11 @@ private void testMapreduceWithFile(String inputDatasetName, String inputPaths, Assert.assertFalse(resultLocation.isDirectory()); // read output and verify result - String line = CharStreams.readFirstLine( - CharStreams.newReaderSupplier( - Locations.newInputSupplier(resultLocation), Charsets.UTF_8)); + String line; + try (InputStreamReader reader = new InputStreamReader(Locations.newInputSupplier(resultLocation).getInput(), + Charsets.UTF_8)) { + line = CharStreams.readLines(reader).stream().findFirst().orElse(null); + } Assert.assertNotNull(line); String[] fields = line.split(outputSeparator == null ? ":" : outputSeparator); Assert.assertEquals(2, fields.length); diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceRunnerTestBase.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceRunnerTestBase.java index dada5c9f5f27..af8b09fb3e0f 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceRunnerTestBase.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceRunnerTestBase.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.runtime.batch; import com.google.common.base.Supplier; -import com.google.common.base.Throwables; import com.google.gson.Gson; import com.google.inject.Injector; import io.cdap.cdap.api.Config; @@ -93,7 +92,7 @@ public File get() { try { return TEMP_FOLDER.newFolder(); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } }; @@ -120,7 +119,7 @@ public static void beforeClass() throws Exception { NamespaceId.DEFAULT, DatasetDefinition.NO_ARGUMENTS, null, null); metricStore = injector.getInstance(MetricStore.class); - txService.startAndWait(); + txService.startAsync().awaitRunning(); // Always create the default namespace injector.getInstance(NamespaceAdmin.class).create(NamespaceMeta.DEFAULT); @@ -128,7 +127,7 @@ public static void beforeClass() throws Exception { @AfterClass public static void afterClass() { - txService.stopAndWait(); + txService.stopAsync().awaitTerminated(); AppFabricTestHelper.shutdown(); } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/dataset/input/AppWithMapReduceUsingMultipleInputs.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/dataset/input/AppWithMapReduceUsingMultipleInputs.java index 4a01541c36c8..3c14cc5588d2 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/dataset/input/AppWithMapReduceUsingMultipleInputs.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/dataset/input/AppWithMapReduceUsingMultipleInputs.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.runtime.batch.dataset.input; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import io.cdap.cdap.api.ProgramLifecycle; import io.cdap.cdap.api.app.AbstractApplication; @@ -145,7 +144,7 @@ protected void setup(Context context) throws IOException, InterruptedException { // assert that the user gets the TextInputFormat, as opposed to the MultiInputFormat from the context Preconditions.checkArgument(context.getInputFormatClass() == TextInputFormat.class); } catch (ClassNotFoundException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/dataset/input/MapReduceWithMultipleInputsTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/dataset/input/MapReduceWithMultipleInputsTest.java index a28a67b501fe..0f15a323a4b4 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/dataset/input/MapReduceWithMultipleInputsTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/dataset/input/MapReduceWithMultipleInputsTest.java @@ -24,6 +24,7 @@ import io.cdap.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms; import io.cdap.cdap.internal.app.runtime.BasicArguments; import io.cdap.cdap.internal.app.runtime.batch.MapReduceRunnerTestBase; +import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.List; import org.apache.twill.filesystem.Location; @@ -80,8 +81,11 @@ public void testSimpleJoin() throws Exception { // will only be 1 part file, due to the small amount of data Location outputLocation = outputFileSet.getBaseLocation().append("output").append("part-r-00000"); - List lines = CharStreams.readLines( - CharStreams.newReaderSupplier(Locations.newInputSupplier(outputLocation), Charsets.UTF_8)); + List lines; + try (InputStreamReader reader = new InputStreamReader(Locations.newInputSupplier(outputLocation).getInput(), + Charsets.UTF_8)) { + lines = CharStreams.readLines(reader); + } Assert.assertEquals(ImmutableList.of("1 Bob 75", "2 Samuel 18", "3 Joe 60"), lines); diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/dataset/output/MapReduceWithMultipleOutputsTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/dataset/output/MapReduceWithMultipleOutputsTest.java index 74c9f8983ce7..61460867c34f 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/dataset/output/MapReduceWithMultipleOutputsTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/dataset/output/MapReduceWithMultipleOutputsTest.java @@ -25,6 +25,7 @@ import io.cdap.cdap.internal.app.runtime.BasicArguments; import io.cdap.cdap.internal.app.runtime.batch.MapReduceRunnerTestBase; import java.io.IOException; +import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.List; import org.apache.twill.filesystem.Location; @@ -70,7 +71,10 @@ public void testMultipleOutputs() throws Exception { private List readFromOutput(FileSet fileSet, String relativePath) throws IOException { // small amount of data, so expect all data from just 1 file Location location = fileSet.getLocation(relativePath).append("part-m-00000"); - return CharStreams.readLines(CharStreams.newReaderSupplier(Locations.newInputSupplier(location), Charsets.UTF_8)); + try (InputStreamReader reader = new InputStreamReader(Locations.newInputSupplier(location).getInput(), + Charsets.UTF_8)) { + return CharStreams.readLines(reader); + } } @Test diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionJobMainTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionJobMainTest.java index 7ba50a84eba7..04e1696391df 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionJobMainTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/distributed/remote/RemoteExecutionJobMainTest.java @@ -48,11 +48,11 @@ public void testJobEnvironment() throws Exception { Map properties = jobEnv.getProperties(); ZKClientService zkClient = ZKClientService.Builder.of(properties.get(Constants.Zookeeper.QUORUM)).build(); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); try { Assert.assertNotNull(zkClient.exists("/").get()); } finally { - zkClient.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); } } finally { runner.destroy(); diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/InternalServiceRoutingHandlerTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/InternalServiceRoutingHandlerTest.java index 867110e5c8c1..7363973dafbc 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/InternalServiceRoutingHandlerTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/InternalServiceRoutingHandlerTest.java @@ -102,7 +102,7 @@ protected void configure() { ); internalRouterService = injector.getInstance(InternalRouterService.class); - internalRouterService.startAndWait(); + internalRouterService.startAsync().awaitRunning(); mockService = NettyHttpService.builder(MOCK_SERVICE) .setHost(InetAddress.getLocalHost().getCanonicalHostName()) @@ -118,7 +118,7 @@ protected void configure() { public void afterTest() throws Exception { mockServiceCancellable.cancel(); mockService.stop(); - internalRouterService.stopAndWait(); + internalRouterService.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeClientServerTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeClientServerTest.java index 6c848de4a609..b26983c8e96f 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeClientServerTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeClientServerTest.java @@ -146,12 +146,12 @@ protected void configure() { messagingService = injector.getInstance(MessagingService.class); if (messagingService instanceof Service) { - ((Service) messagingService).startAndWait(); + ((Service) messagingService).startAsync().awaitRunning(); } messagingService.createTopic(new DefaultTopicMetadata(NamespaceId.SYSTEM.topic("topic"))); runtimeServer = injector.getInstance(RuntimeServer.class); - runtimeServer.startAndWait(); + runtimeServer.startAsync().awaitRunning(); runtimeClient = injector.getInstance(RuntimeClient.class); locationFactory = injector.getInstance(LocationFactory.class); @@ -160,9 +160,9 @@ protected void configure() { @After public void afterTest() { logEntries.clear(); - runtimeServer.stopAndWait(); + runtimeServer.stopAsync().awaitTerminated(); if (messagingService instanceof Service) { - ((Service) messagingService).stopAndWait(); + ((Service) messagingService).stopAsync().awaitTerminated(); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeClientServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeClientServiceTest.java index a01ed0700847..486c5ab1d03e 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeClientServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeClientServiceTest.java @@ -16,9 +16,7 @@ package io.cdap.cdap.internal.app.runtime.monitor; -import com.google.common.base.Throwables; import com.google.common.reflect.TypeToken; -import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.Service; import com.google.gson.Gson; import com.google.inject.AbstractModule; @@ -198,11 +196,11 @@ protected void configure() { messagingService = injector.getInstance(MessagingService.class); if (messagingService instanceof Service) { - ((Service) messagingService).startAndWait(); + ((Service) messagingService).startAsync().awaitRunning(); } runtimeServer = injector.getInstance(RuntimeServer.class); - runtimeServer.startAndWait(); + runtimeServer.startAsync().awaitRunning(); // Injector for the client side clientCConf = CConfiguration.create(); @@ -244,7 +242,7 @@ protected void configure() { clientMessagingService = clientInjector.getInstance(MessagingService.class); if (clientMessagingService instanceof Service) { - ((Service) clientMessagingService).startAndWait(); + ((Service) clientMessagingService).startAsync().awaitRunning(); } clientProgramStatePublisher = clientInjector.getInstance( ProgramStatePublisher.class); @@ -253,16 +251,16 @@ protected void configure() { @After public void afterTest() { if (runtimeClientService != null) { - runtimeClientService.stopAndWait(); + runtimeClientService.stopAsync().awaitTerminated(); } runtimeClientService = null; if (clientMessagingService instanceof Service) { - ((Service) clientMessagingService).stopAndWait(); + ((Service) clientMessagingService).stopAsync().awaitTerminated(); } - runtimeServer.stopAndWait(); + runtimeServer.stopAsync().awaitTerminated(); if (messagingService instanceof Service) { - ((Service) messagingService).stopAndWait(); + ((Service) messagingService).stopAsync().awaitTerminated(); } } @@ -270,7 +268,7 @@ public void afterTest() { public void testBasicRelay() throws Exception { runtimeClientService = clientInjector.getInstance( RuntimeClientService.class); - runtimeClientService.startAndWait(); + runtimeClientService.startAsync().awaitRunning(); // Send some messages to multiple topics in the client side TMS, they should get replicated to the server side TMS. MessagingContext messagingContext = new MultiThreadMessagingContext( clientMessagingService); @@ -327,7 +325,7 @@ public void testRelayWithAggregation() throws Exception { runtimeClientService = clientInjector.getInstance( RuntimeClientService.class); - runtimeClientService.startAndWait(); + runtimeClientService.startAsync().awaitRunning(); Map tags = new HashMap<>(); tags.put("key1", "value1"); tags.put("key2", "value2"); @@ -435,7 +433,7 @@ public void testRelayWithAggregation() throws Exception { public void testProgramTerminate() throws Exception { runtimeClientService = clientInjector.getInstance( RuntimeClientService.class); - runtimeClientService.startAndWait(); + runtimeClientService.startAsync().awaitRunning(); MessagingContext messagingContext = new MultiThreadMessagingContext( clientMessagingService); MessagePublisher messagePublisher = messagingContext.getDirectMessagePublisher(); @@ -483,13 +481,13 @@ public void testProgramTerminate() throws Exception { public void testRuntimeClientStop() throws Exception { runtimeClientService = clientInjector.getInstance( RuntimeClientService.class); - runtimeClientService.startAndWait(); + runtimeClientService.startAsync().awaitRunning(); ProgramStateWriter programStateWriter = new MessagingProgramStateWriter( clientProgramStatePublisher); - ListenableFuture stopFuture = runtimeClientService.stop(); + runtimeClientService.stopAsync(); try { - stopFuture.get(2, TimeUnit.SECONDS); + runtimeClientService.awaitTerminated(2, TimeUnit.SECONDS); Assert.fail("Expected runtime client service not stopped"); } catch (TimeoutException e) { // Expected @@ -497,7 +495,7 @@ public void testRuntimeClientStop() throws Exception { // Publish a program completed state, which should unblock the client service stop. programStateWriter.completed(PROGRAM_RUN_ID); - stopFuture.get(); + runtimeClientService.awaitTerminated(); } /** @@ -507,7 +505,7 @@ public void testRuntimeClientStop() throws Exception { public void testExternalStop() throws Exception { runtimeClientService = clientInjector.getInstance( RuntimeClientService.class); - runtimeClientService.startAndWait(); + runtimeClientService.startAsync().awaitRunning(); ProgramStateWriter programStateWriter = new MessagingProgramStateWriter( clientProgramStatePublisher); MessagingContext messagingContext = new MultiThreadMessagingContext( @@ -527,9 +525,9 @@ public void testExternalStop() throws Exception { messagePublisher.publish(NamespaceId.SYSTEM.getNamespace(), topic, "msg1" + topic, "msg2" + topic); - ListenableFuture stopFuture = runtimeClientService.stop(); + runtimeClientService.stopAsync(); try { - stopFuture.get(2, TimeUnit.SECONDS); + runtimeClientService.awaitTerminated(2, TimeUnit.SECONDS); Assert.fail("Expected runtime client service not stopped"); } catch (TimeoutException e) { // Expected @@ -537,7 +535,7 @@ public void testExternalStop() throws Exception { // Publish a program completed state, which should unblock the client service stop. programStateWriter.completed(PROGRAM_RUN_ID); - stopFuture.get(); + runtimeClientService.awaitTerminated(); } private List fetchMessages(MessagingContext messagingContext, @@ -553,7 +551,7 @@ private List fetchMessages(MessagingContext messagingContext, .collect(Collectors.toList()); } } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeServiceRoutingTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeServiceRoutingTest.java index 1ef6ca49a8f0..2624d21cff56 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeServiceRoutingTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/RuntimeServiceRoutingTest.java @@ -117,7 +117,7 @@ protected void bindRequestValidator() { bind(RuntimeRequestValidator.class).toInstance((programRunId, request) -> { String authHeader = request.headers().get(HttpHeaderNames.AUTHORIZATION); String expected = "Bearer " + Base64.getEncoder().encodeToString( - Hashing.md5().hashString(programRunId.toString()).asBytes()); + Hashing.md5().hashString(programRunId.toString(), StandardCharsets.UTF_8).asBytes()); if (!expected.equals(authHeader)) { throw new UnauthenticatedException("Program run " + programRunId + " is not authorized"); } @@ -143,12 +143,12 @@ protected void configure() { messagingService = injector.getInstance(MessagingService.class); if (messagingService instanceof Service) { - ((Service) messagingService).startAndWait(); + ((Service) messagingService).startAsync().awaitRunning(); } messagingService.createTopic(new DefaultTopicMetadata(NamespaceId.SYSTEM.topic("topic"))); runtimeServer = injector.getInstance(RuntimeServer.class); - runtimeServer.startAndWait(); + runtimeServer.startAsync().awaitRunning(); mockService = NettyHttpService.builder(MOCK_SERVICE) .setHost(InetAddress.getLocalHost().getCanonicalHostName()) @@ -164,9 +164,9 @@ protected void configure() { public void afterTest() throws Exception { mockServiceCancellable.cancel(); mockService.stop(); - runtimeServer.stopAndWait(); + runtimeServer.stopAsync().awaitTerminated(); if (messagingService instanceof Service) { - ((Service) messagingService).stopAndWait(); + ((Service) messagingService).stopAsync().awaitTerminated(); } } @@ -269,7 +269,8 @@ public String getName() { @Override public Credential getCredentials() { - String credentialValue = Base64.getEncoder().encodeToString(Hashing.md5().hashString(programRunId.toString()) + String credentialValue = Base64.getEncoder().encodeToString(Hashing.md5().hashString(programRunId.toString(), + StandardCharsets.UTF_8) .asBytes()); return new Credential(credentialValue, Credential.CredentialType.EXTERNAL_BEARER); } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/proxy/ServiceSocksProxyTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/proxy/ServiceSocksProxyTest.java index 110b9cab2186..22abacc85cae 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/proxy/ServiceSocksProxyTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/monitor/proxy/ServiceSocksProxyTest.java @@ -81,7 +81,7 @@ public static void init() throws Exception { discoveryService.register(ResolvingDiscoverable.of((new Discoverable("test-service", httpService.getBindAddress())))); proxyServer = new ServiceSocksProxy(discoveryService, (user, pass) -> USER.equals(user) && PASS.equals(pass)); - proxyServer.startAndWait(); + proxyServer.startAsync().awaitRunning(); defaultProxySelector = ProxySelector.getDefault(); @@ -113,7 +113,7 @@ protected PasswordAuthentication getPasswordAuthentication() { public static void finish() throws Exception { Authenticator.setDefault(null); ProxySelector.setDefault(defaultProxySelector); - proxyServer.stopAndWait(); + proxyServer.stopAsync().awaitTerminated(); httpService.stop(); } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/schedule/queue/NoSqlJobQueueTableTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/schedule/queue/NoSqlJobQueueTableTest.java index 65cd9f225d2c..2d350dcd9aab 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/schedule/queue/NoSqlJobQueueTableTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/schedule/queue/NoSqlJobQueueTableTest.java @@ -61,7 +61,7 @@ public static void beforeClass() throws IOException, TableAlreadyExistsException cConf.set(Constants.Dataset.DATA_STORAGE_IMPLEMENTATION, Constants.Dataset.DATA_STORAGE_NOSQL); txManager = new TransactionManager(new Configuration()); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); Injector injector = Guice.createInjector( new ConfigModule(cConf), @@ -90,7 +90,7 @@ protected void configure() { @AfterClass public static void afterClass() { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } @Override diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/schedule/store/DatasetBasedTimeScheduleStoreTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/schedule/store/DatasetBasedTimeScheduleStoreTest.java index 40460053d486..5b5d40313db2 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/schedule/store/DatasetBasedTimeScheduleStoreTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/schedule/store/DatasetBasedTimeScheduleStoreTest.java @@ -124,20 +124,20 @@ protected void configure() { } }); txService = injector.getInstance(TransactionManager.class); - txService.startAndWait(); + txService.startAsync().awaitRunning(); StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); dsOpsService = injector.getInstance(DatasetOpExecutorService.class); - dsOpsService.startAndWait(); + dsOpsService.startAsync().awaitRunning(); dsService = injector.getInstance(DatasetService.class); - dsService.startAndWait(); + dsService.startAsync().awaitRunning(); transactionRunner = injector.getInstance(TransactionRunner.class); } @AfterClass public static void afterClass() { - dsService.stopAndWait(); - dsOpsService.stopAndWait(); - txService.stopAndWait(); + dsService.stopAsync().awaitTerminated(); + dsOpsService.stopAsync().awaitTerminated(); + txService.stopAsync().awaitTerminated(); } private static void schedulerSetup(boolean enablePersistence) throws SchedulerException { diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/service/http/HttpHandlerGeneratorTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/service/http/HttpHandlerGeneratorTest.java index 3efcdab0b02f..4959b632d68d 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/service/http/HttpHandlerGeneratorTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/service/http/HttpHandlerGeneratorTest.java @@ -23,7 +23,6 @@ import com.google.common.collect.Maps; import com.google.common.hash.Hashing; import com.google.common.io.ByteStreams; -import com.google.common.io.Closeables; import com.google.common.io.Files; import com.google.common.reflect.TypeToken; import io.cdap.cdap.api.Admin; @@ -275,7 +274,13 @@ public void onFinish(HttpServiceResponder responder) throws Exception { @Override public void onError(HttpServiceResponder responder, Throwable failureCause) { validateTransaction(); - Closeables.closeQuietly(channel); + try { + + channel.close(); + + } catch (Exception ignored) { + + } LOG.error("Failed when handling upload", failureCause); } @@ -481,7 +486,9 @@ protected FileHandler createHandler() { String.format("http://%s:%d/content/download/test.txt", bindAddress.getHostName(), bindAddress.getPort())).openConnection(); try { - ByteStreams.copy(urlConn.getInputStream(), Files.newOutputStreamSupplier(downloadFile)); + try (FileOutputStream fos = new FileOutputStream(downloadFile)) { + ByteStreams.copy(urlConn.getInputStream(), fos); + } } finally { urlConn.disconnect(); } @@ -506,7 +513,9 @@ protected FileHandler createHandler() { urlConn.setDoOutput(true); urlConn.setRequestMethod("POST"); Files.copy(file, urlConn.getOutputStream()); - ByteStreams.copy(urlConn.getInputStream(), Files.newOutputStreamSupplier(downloadFile)); + try (FileOutputStream fos = new FileOutputStream(downloadFile)) { + ByteStreams.copy(urlConn.getInputStream(), fos); + } Assert.assertEquals(200, urlConn.getResponseCode()); Assert.assertTrue(Files.equal(file, downloadFile)); } finally { @@ -558,8 +567,9 @@ protected NoAnnotationHandler createHandler() { bindAddress.getHostName(), bindAddress.getPort())).openConnection(); urlConn.setReadTimeout(2000); urlConn.setDoOutput(true); - ByteStreams.copy(ByteStreams.newInputStreamSupplier("Hello".getBytes(Charsets.UTF_8)), - urlConn.getOutputStream()); + try (java.io.ByteArrayInputStream bais = new java.io.ByteArrayInputStream("Hello".getBytes(Charsets.UTF_8))) { + ByteStreams.copy(bais, urlConn.getOutputStream()); + } Assert.assertEquals("Hello test", new String(ByteStreams.toByteArray(urlConn.getInputStream()), Charsets.UTF_8)); diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/worker/WorkerProgramRunnerTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/worker/WorkerProgramRunnerTest.java index 66e8204661e9..539114731326 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/worker/WorkerProgramRunnerTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/worker/WorkerProgramRunnerTest.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.runtime.worker; import com.google.common.base.Supplier; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.google.inject.Injector; import io.cdap.cdap.AppWithMisbehavedDataset; @@ -96,7 +95,7 @@ public File get() { try { return TEMP_FOLDER.newFolder(); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } }; @@ -119,12 +118,12 @@ public static void beforeClass() { NamespaceId.DEFAULT, DatasetDefinition.NO_ARGUMENTS, null, null); metricStore = injector.getInstance(MetricStore.class); - txService.startAndWait(); + txService.startAsync().awaitRunning(); } @AfterClass public static void afterClass() { - txService.stopAndWait(); + txService.stopAsync().awaitTerminated(); AppFabricTestHelper.shutdown(); } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/scheduler/LogPrintingJob.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/scheduler/LogPrintingJob.java index 13252df9f23d..3ea6492a824f 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/scheduler/LogPrintingJob.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/scheduler/LogPrintingJob.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.scheduler; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import org.quartz.Job; import org.quartz.JobDataMap; import org.quartz.JobExecutionContext; @@ -56,7 +55,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException { LOG.info("Parameter key: {}, value: {}", key, map.get(key)); } } catch (Throwable e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } throw new JobExecutionException("exception"); } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/AppFabricProcessorServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/AppFabricProcessorServiceTest.java index a147f710fff3..319193a4fe27 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/AppFabricProcessorServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/AppFabricProcessorServiceTest.java @@ -16,10 +16,8 @@ package io.cdap.cdap.internal.app.services; -import com.google.common.util.concurrent.Service; import com.google.inject.Injector; import io.cdap.cdap.internal.AppFabricTestHelper; -import org.junit.Assert; import org.junit.Test; public class AppFabricProcessorServiceTest { @@ -29,11 +27,9 @@ public void startStopService() { try { Injector injector = AppFabricTestHelper.getInjector(); AppFabricProcessorService service = injector.getInstance(AppFabricProcessorService.class); - Service.State state = service.startAndWait(); - Assert.assertSame(state, Service.State.RUNNING); + service.startAsync().awaitRunning(); - state = service.stopAndWait(); - Assert.assertSame(state, Service.State.TERMINATED); + service.stopAsync().awaitTerminated(); } finally { AppFabricTestHelper.shutdown(); } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/AppFabricServerTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/AppFabricServerTest.java index 6a1ca2f3cb01..c51a950f1866 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/AppFabricServerTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/AppFabricServerTest.java @@ -17,7 +17,6 @@ package io.cdap.cdap.internal.app.services; import com.google.common.base.Suppliers; -import com.google.common.util.concurrent.Service; import com.google.inject.Injector; import io.cdap.cdap.common.conf.CConfiguration; import io.cdap.cdap.common.conf.Constants; @@ -49,15 +48,13 @@ public void startStopServer() throws Exception { try { AppFabricServer server = injector.getInstance(AppFabricServer.class); DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class); - Service.State state = server.startAndWait(); - Assert.assertSame(state, Service.State.RUNNING); + server.startAsync().awaitRunning(); final EndpointStrategy endpointStrategy = new RandomEndpointStrategy( () -> discoveryServiceClient.discover(Constants.Service.APP_FABRIC_HTTP)); Assert.assertNotNull(endpointStrategy.pick(5, TimeUnit.SECONDS)); - state = server.stopAndWait(); - Assert.assertSame(state, Service.State.TERMINATED); + server.stopAsync().awaitTerminated(); Tasks.waitFor(true, () -> endpointStrategy.pick() == null, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); } finally { @@ -74,7 +71,7 @@ public void testSsl() throws IOException { try { final DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class); AppFabricServer appFabricServer = injector.getInstance(AppFabricServer.class); - appFabricServer.startAndWait(); + appFabricServer.startAsync().awaitRunning(); Assert.assertTrue(appFabricServer.isRunning()); Supplier endpointStrategySupplier = Suppliers.memoize( @@ -91,7 +88,7 @@ public void testSsl() throws IOException { // Would throw exception if the server does not support ssl. // "javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?" socket.startHandshake(); - appFabricServer.stopAndWait(); + appFabricServer.stopAsync().awaitTerminated(); } finally { AppFabricTestHelper.shutdown(); } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/DefaultSecureStoreServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/DefaultSecureStoreServiceTest.java index a8b3ae336149..e2ddf1e8024d 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/DefaultSecureStoreServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/DefaultSecureStoreServiceTest.java @@ -93,9 +93,9 @@ public static void setup() throws Exception { final Injector injector = AppFabricTestHelper.getInjector(cConf, sConf); discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class); appFabricServer = injector.getInstance(AppFabricServer.class); - appFabricServer.startAndWait(); + appFabricServer.startAsync().awaitRunning(); appFabricProcessor = injector.getInstance(AppFabricProcessorService.class); - appFabricProcessor.startAndWait(); + appFabricProcessor.startAsync().awaitRunning(); waitForService(Constants.Service.DATASET_MANAGER); secureStore = injector.getInstance(SecureStore.class); secureStoreManager = injector.getInstance(SecureStoreManager.class); @@ -127,8 +127,8 @@ private static void waitForService(String service) { @AfterClass public static void cleanup() { - appFabricServer.stopAndWait(); - appFabricProcessor.stopAndWait(); + appFabricServer.stopAsync().awaitTerminated(); + appFabricProcessor.stopAsync().awaitTerminated(); AppFabricTestHelper.shutdown(); } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/ProgramLifecycleServiceAuthorizationTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/ProgramLifecycleServiceAuthorizationTest.java index 5f785986d2ae..d84d0d993a45 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/ProgramLifecycleServiceAuthorizationTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/ProgramLifecycleServiceAuthorizationTest.java @@ -78,9 +78,9 @@ public static void setup() throws Exception { final Injector injector = AppFabricTestHelper.getInjector(cConf); permissionManager = injector.getInstance(PermissionManager.class); appFabricServer = injector.getInstance(AppFabricServer.class); - appFabricServer.startAndWait(); + appFabricServer.startAsync().awaitRunning(); appFabricProcessor = injector.getInstance(AppFabricProcessorService.class); - appFabricProcessor.startAndWait(); + appFabricProcessor.startAsync().awaitRunning(); programLifecycleService = injector.getInstance(ProgramLifecycleService.class); // Wait for the default namespace creation @@ -161,8 +161,8 @@ public void testProgramList() throws Exception { @AfterClass public static void tearDown() { - appFabricServer.stopAndWait(); - appFabricProcessor.stopAndWait(); + appFabricServer.stopAsync().awaitTerminated(); + appFabricProcessor.stopAsync().awaitTerminated(); AppFabricTestHelper.shutdown(); } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/ProgramLifecycleServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/ProgramLifecycleServiceTest.java index 12f5700ff401..35393fa01ee5 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/ProgramLifecycleServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/ProgramLifecycleServiceTest.java @@ -77,12 +77,12 @@ public static void beforeClass() throws Throwable { programLifecycleService = injector.getInstance(ProgramLifecycleService.class); profileService = injector.getInstance(ProfileService.class); provisioningService = injector.getInstance(ProvisioningService.class); - provisioningService.startAndWait(); + provisioningService.startAsync().awaitRunning(); } @AfterClass public static void shutdown() { - provisioningService.stopAndWait(); + provisioningService.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/ProgramRunStatusMonitorServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/ProgramRunStatusMonitorServiceTest.java index cf0bebb6d857..408c8eb081a5 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/ProgramRunStatusMonitorServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/ProgramRunStatusMonitorServiceTest.java @@ -125,7 +125,7 @@ public RuntimeInfo lookup(ProgramId programId, RunId runId) { = new ProgramRunStatusMonitorService(cConf, store, testService, metricsCollectionService, new NoOpProgramStateWriter(), 5, 3, 2, 2); - programRunStatusMonitorService.startAndWait(); + programRunStatusMonitorService.startAsync().awaitRunning(); Assert.assertEquals(1, latch.getCount()); programRunStatusMonitorService.terminatePrograms(); Assert.assertTrue(latch.await(10, TimeUnit.SECONDS)); @@ -198,7 +198,7 @@ public RuntimeInfo lookup(ProgramId programId, RunId runId) { = new ProgramRunStatusMonitorService(cConf, store, testService, metricsCollectionService, new NoOpProgramStateWriter(), 5, 3, 2, 2); - programRunStatusMonitorService.startAndWait(); + programRunStatusMonitorService.startAsync().awaitRunning(); Assert.assertEquals(1, latch.getCount()); programRunStatusMonitorService.terminatePrograms(); Assert.assertTrue(latch.await(10, TimeUnit.SECONDS)); @@ -238,7 +238,7 @@ public void testStoppingRemoteTetheredProgramsBeyondTerminateTimeAreKilled() thr ProgramRunStatusMonitorService programRunStatusMonitorService = new ProgramRunStatusMonitorService(cConf, store, testService, metricsCollectionService, psw, 5, 3, 2, 2); - programRunStatusMonitorService.startAndWait(); + programRunStatusMonitorService.startAsync().awaitRunning(); Assert.assertEquals(1, latch.getCount()); programRunStatusMonitorService.terminatePrograms(); Assert.assertTrue(latch.await(10, TimeUnit.SECONDS)); diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/SystemProgramManagementServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/SystemProgramManagementServiceTest.java index 620e3225942f..9601e8aa6ab7 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/SystemProgramManagementServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/SystemProgramManagementServiceTest.java @@ -73,7 +73,7 @@ public static void setup() { progmMgmtSvc = new SystemProgramManagementService(getInjector().getInstance(CConfiguration.class), getInjector().getInstance(ProgramRuntimeService.class), programLifecycleService); - progmMgmtSvc.stopAndWait(); + progmMgmtSvc.stopAsync().awaitTerminated(); } @AfterClass diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/http/AppFabricTestBase.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/http/AppFabricTestBase.java index e74c4b10b691..be0731812e86 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/http/AppFabricTestBase.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/http/AppFabricTestBase.java @@ -20,8 +20,7 @@ import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; -import com.google.common.io.Closeables; -import com.google.common.io.InputSupplier; +import io.cdap.cdap.common.io.InputSupplier; import com.google.common.util.concurrent.Service; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -268,38 +267,38 @@ protected static void initializeAndStartServices(CConfiguration cConf, Module ov messagingService = injector.getInstance(MessagingService.class); if (messagingService instanceof Service) { - ((Service) messagingService).startAndWait(); + ((Service) messagingService).startAsync().awaitRunning(); } txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); // Define all StructuredTable before starting any services that need StructuredTable StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); metadataStorage = injector.getInstance(MetadataStorage.class); metadataStorage.createIndex(); dsOpService = injector.getInstance(DatasetOpExecutorService.class); - dsOpService.startAndWait(); + dsOpService.startAsync().awaitRunning(); datasetService = injector.getInstance(DatasetService.class); - datasetService.startAndWait(); + datasetService.startAsync().awaitRunning(); appFabricServer = injector.getInstance(AppFabricServer.class); - appFabricServer.startAndWait(); + appFabricServer.startAsync().awaitRunning(); appFabricProcessorService = injector.getInstance(AppFabricProcessorService.class); - appFabricProcessorService.startAndWait(); + appFabricProcessorService.startAsync().awaitRunning(); DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class); appFabricEndpointStrategy = new RandomEndpointStrategy( () -> discoveryClient.discover(Constants.Service.APP_FABRIC_HTTP)); txClient = injector.getInstance(TransactionSystemClient.class); metricsCollectionService = injector.getInstance(MetricsCollectionService.class); - metricsCollectionService.startAndWait(); + metricsCollectionService.startAsync().awaitRunning(); serviceStore = injector.getInstance(ServiceStore.class); - serviceStore.startAndWait(); + serviceStore.startAsync().awaitRunning(); metadataService = injector.getInstance(MetadataService.class); - metadataService.startAndWait(); + metadataService.startAsync().awaitRunning(); metadataSubscriberService = injector.getInstance(MetadataSubscriberService.class); - metadataSubscriberService.startAndWait(); + metadataSubscriberService.startAsync().awaitRunning(); logQueryService = injector.getInstance(LogQueryService.class); - logQueryService.startAndWait(); + logQueryService.startAsync().awaitRunning(); locationFactory = getInjector().getInstance(LocationFactory.class); datasetClient = new DatasetClient(getClientConfig(discoveryClient, Constants.Service.DATASET_MANAGER)); remoteClientFactory = new RemoteClientFactory(discoveryClient, @@ -323,20 +322,26 @@ protected static void initializeAndStartServices(CConfiguration cConf, Module ov @AfterClass public static void afterClass() { - appFabricServer.stopAndWait(); - appFabricProcessorService.stopAndWait(); - metricsCollectionService.stopAndWait(); - datasetService.stopAndWait(); - dsOpService.stopAndWait(); - txManager.stopAndWait(); - serviceStore.stopAndWait(); - metadataSubscriberService.stopAndWait(); - metadataService.stopAndWait(); - logQueryService.stopAndWait(); + appFabricServer.stopAsync().awaitTerminated(); + appFabricProcessorService.stopAsync().awaitTerminated(); + metricsCollectionService.stopAsync().awaitTerminated(); + datasetService.stopAsync().awaitTerminated(); + dsOpService.stopAsync().awaitTerminated(); + txManager.stopAsync().awaitTerminated(); + serviceStore.stopAsync().awaitTerminated(); + metadataSubscriberService.stopAsync().awaitTerminated(); + metadataService.stopAsync().awaitTerminated(); + logQueryService.stopAsync().awaitTerminated(); if (messagingService instanceof Service) { - ((Service) messagingService).stopAndWait(); + ((Service) messagingService).stopAsync().awaitTerminated(); + } + try { + + metadataStorage.close(); + + } catch (Exception ignored) { + } - Closeables.closeQuietly(metadataStorage); } protected static CConfiguration createBasicCconf() throws IOException { @@ -527,7 +532,7 @@ private HttpResponse addArtifact(Id.Artifact artifactId, InputSupplier true); }); - Assert.fail("Expected IllegalStateException"); + Assert.fail("Expected Exception"); } catch (Exception e) { - boolean found = false; - Throwable t = e; - while (t != null) { - if (t instanceof IllegalStateException && t.getMessage() - .contains("Failed to parse artifact ID from app meta")) { - found = true; - break; - } - t = t.getCause(); - } - Assert.assertTrue( - "Expected IllegalStateException with message 'Failed to parse artifact ID from app meta'", - found); + // It's expected to fail due to malformed JSON } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/remote/RemoteNamespaceQueryTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/remote/RemoteNamespaceQueryTest.java index ae94d92c25c5..1fe12ca5e1ed 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/remote/RemoteNamespaceQueryTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/remote/RemoteNamespaceQueryTest.java @@ -63,11 +63,11 @@ public static void setup() throws Exception { cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMPORARY_FOLDER.newFolder().getAbsolutePath()); Injector injector = AppFabricTestHelper.getInjector(cConf); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); datasetService = injector.getInstance(DatasetService.class); - datasetService.startAndWait(); + datasetService.startAsync().awaitRunning(); appFabricServer = injector.getInstance(AppFabricServer.class); - appFabricServer.startAndWait(); + appFabricServer.startAsync().awaitRunning(); DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class); waitForService(discoveryServiceClient, Constants.Service.DATASET_MANAGER); waitForService(discoveryServiceClient, Constants.Service.APP_FABRIC_HTTP); @@ -78,9 +78,9 @@ public static void setup() throws Exception { @AfterClass public static void tearDown() { - appFabricServer.stopAndWait(); - datasetService.stopAndWait(); - txManager.stopAndWait(); + appFabricServer.stopAsync().awaitTerminated(); + datasetService.stopAsync().awaitTerminated(); + txManager.stopAsync().awaitTerminated(); AppFabricTestHelper.shutdown(); } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/remote/RemotePermissionsTestBase.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/remote/RemotePermissionsTestBase.java index 595e4f0a42ca..4aa03ed521eb 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/remote/RemotePermissionsTestBase.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/remote/RemotePermissionsTestBase.java @@ -87,7 +87,7 @@ protected static void setup() throws IOException, InterruptedException { Injector injector = AppFabricTestHelper.getInjector(cConf); discoveryService = injector.getInstance(DiscoveryServiceClient.class); appFabricServer = injector.getInstance(AppFabricServer.class); - appFabricServer.startAndWait(); + appFabricServer.startAsync().awaitRunning(); waitForService(Constants.Service.APP_FABRIC_HTTP); accessEnforcer = injector.getInstance(RemoteAccessEnforcer.class); permissionManager = injector.getInstance(PermissionManager.class); @@ -226,7 +226,7 @@ private void assertUnauthorized(Retries.Runnable runnable) thro @AfterClass public static void tearDown() { - appFabricServer.stopAndWait(); + appFabricServer.stopAsync().awaitTerminated(); AppFabricTestHelper.shutdown(); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/state/AppStateHandlerTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/state/AppStateHandlerTest.java index 3ca2f4ef46ec..9d60556e1384 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/state/AppStateHandlerTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/state/AppStateHandlerTest.java @@ -88,7 +88,7 @@ public static void setup() throws Exception { applicationLifecycleService = injector.getInstance(ApplicationLifecycleService.class); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); // Endpoint for all state APIs endpoint = "namespaces/" + NAMESPACE_1 + "/apps/" + APP_NAME + "/states/" + STATE_KEY; @@ -104,7 +104,7 @@ public static void teardown() throws Exception { } if (txManager != null) { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/state/AppStateTableTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/state/AppStateTableTest.java index a41ce9acb37e..43a8c4ac2ceb 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/state/AppStateTableTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/store/state/AppStateTableTest.java @@ -66,7 +66,7 @@ public static void setup() throws Exception { Injector injector = getInjector(); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); transactionRunner = getInjector().getInstance(TransactionRunner.class); @@ -79,7 +79,7 @@ public static void setup() throws Exception { @AfterClass public static void teardown() throws Exception { if (txManager != null) { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/TaskWorkerMetricsTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/TaskWorkerMetricsTest.java index 4533afa424b4..fa0715918400 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/TaskWorkerMetricsTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/TaskWorkerMetricsTest.java @@ -84,7 +84,7 @@ protected void publish(Iterator metrics) { } }; - mockMetricsCollector.startAndWait(); + mockMetricsCollector.startAsync().awaitRunning(); InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService(); AeadCipher aeadCipher = new NoOpAeadCipher(); taskWorkerService = new TaskWorkerService(cConf, sConf, discoveryService, discoveryService, @@ -93,7 +93,7 @@ protected void publish(Iterator metrics) { auditLogContexts -> {}, aeadCipher)); taskWorkerStateFuture = TaskWorkerTestUtil.getServiceCompletionFuture(taskWorkerService); // start the service - taskWorkerService.startAndWait(); + taskWorkerService.startAsync().awaitRunning(); InetSocketAddress addr = taskWorkerService.getBindAddress(); this.uri = URI.create(String.format("http://%s:%s", addr.getHostName(), addr.getPort())); } @@ -101,7 +101,7 @@ protected void publish(Iterator metrics) { @After public void afterTest() { if (taskWorkerService != null) { - taskWorkerService.stopAndWait(); + taskWorkerService.stopAsync().awaitTerminated(); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/TaskWorkerServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/TaskWorkerServiceTest.java index 6fd7227670b2..484039e4daab 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/TaskWorkerServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/TaskWorkerServiceTest.java @@ -105,7 +105,7 @@ public void beforeTest() throws Exception { serviceCompletionFuture = TaskWorkerTestUtil.getServiceCompletionFuture( taskWorkerService); // start the service - taskWorkerService.startAndWait(); + taskWorkerService.startAsync().awaitRunning(); this.taskWorkerService = taskWorkerService; securityManager = System.getSecurityManager(); System.setSecurityManager(new NoExitSecurityManager()); @@ -114,7 +114,7 @@ public void beforeTest() throws Exception { @After public void afterTest() { if (taskWorkerService != null) { - taskWorkerService.stopAndWait(); + taskWorkerService.stopAsync().awaitTerminated(); taskWorkerService = null; } System.setSecurityManager(securityManager); @@ -135,7 +135,7 @@ public void testPeriodicRestart() { serviceCompletionFuture = TaskWorkerTestUtil.getServiceCompletionFuture( taskWorkerService); // start the service - taskWorkerService.startAndWait(); + taskWorkerService.startAsync().awaitRunning(); TaskWorkerTestUtil.waitForServiceCompletion(serviceCompletionFuture); Assert.assertEquals(Service.State.TERMINATED, taskWorkerService.state()); @@ -156,7 +156,7 @@ public void testPeriodicRestartWithInflightRequest() throws IOException { serviceCompletionFuture = TaskWorkerTestUtil.getServiceCompletionFuture( taskWorkerService); // start the service - taskWorkerService.startAndWait(); + taskWorkerService.startAsync().awaitRunning(); InetSocketAddress addr = taskWorkerService.getBindAddress(); URI uri = URI.create( @@ -199,7 +199,7 @@ public void testPeriodicRestartWithNeverEndingInflightRequest() { serviceCompletionFuture = TaskWorkerTestUtil.getServiceCompletionFuture( taskWorkerService); // start the service - taskWorkerService.startAndWait(); + taskWorkerService.startAsync().awaitRunning(); new Thread( () -> { @@ -244,7 +244,7 @@ public void testRestartAfterMultipleExecutions() throws IOException { serviceCompletionFuture = TaskWorkerTestUtil.getServiceCompletionFuture( taskWorkerService); // start the service - taskWorkerService.startAndWait(); + taskWorkerService.startAsync().awaitRunning(); InetSocketAddress addr = taskWorkerService.getBindAddress(); URI uri = URI.create( @@ -370,7 +370,7 @@ public void testConcurrentRequestsWithIsolationDisabled() throws Exception { createSConf(), discoveryService, discoveryService, metricsCollectionService, new CommonNettyHttpServiceFactory(cConf, metricsCollectionService, auditLogContexts -> {}, aeadCipher)); - taskWorkerService.startAndWait(); + taskWorkerService.startAsync().awaitRunning(); InetSocketAddress addr = taskWorkerService.getBindAddress(); URI uri = URI.create( String.format("http://%s:%s", addr.getHostName(), addr.getPort())); @@ -413,7 +413,7 @@ public void testConcurrentRequestsWithIsolationDisabled() throws Exception { } catch (TimeoutException e) { // ignore. } - taskWorkerService.stopAndWait(); + taskWorkerService.stopAsync().awaitTerminated(); Assert.assertEquals(2, okResponse); Assert.assertEquals(concurrentRequests, okResponse + conflictResponse); Assert.assertEquals(Service.State.TERMINATED, taskWorkerService.state()); @@ -433,7 +433,7 @@ public void testRestartWithConcurrentRequests() throws Exception { new CommonNettyHttpServiceFactory(cConf, metricsCollectionService, auditLogContexts -> {}, aeadCipher)); serviceCompletionFuture = TaskWorkerTestUtil.getServiceCompletionFuture( taskWorkerService); - taskWorkerService.startAndWait(); + taskWorkerService.startAsync().awaitRunning(); InetSocketAddress addr = taskWorkerService.getBindAddress(); URI uri = URI.create( String.format("http://%s:%s", addr.getHostName(), addr.getPort())); diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/TaskWorkerTestUtil.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/TaskWorkerTestUtil.java index d2992bc53235..ab9b85f2b0bc 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/TaskWorkerTestUtil.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/TaskWorkerTestUtil.java @@ -20,7 +20,6 @@ import com.google.common.util.concurrent.Uninterruptibles; import java.util.concurrent.CompletableFuture; import org.apache.twill.common.Threads; -import org.apache.twill.internal.ServiceListenerAdapter; /** * Common TaskWorker test utility functions @@ -38,7 +37,7 @@ private TaskWorkerTestUtil() { */ static CompletableFuture getServiceCompletionFuture(TaskWorkerService taskWorker) { CompletableFuture future = new CompletableFuture<>(); - taskWorker.addListener(new ServiceListenerAdapter() { + taskWorker.addListener(new Service.Listener() { @Override public void terminated(Service.State from) { future.complete(from); diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/sidecar/ArtifactLocalizerServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/sidecar/ArtifactLocalizerServiceTest.java index 16254b402aa7..7f343175ed9e 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/sidecar/ArtifactLocalizerServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/sidecar/ArtifactLocalizerServiceTest.java @@ -90,7 +90,7 @@ cConf, new ArtifactLocalizer(cConf, remoteClientFactory, (namespaceId, retryStra new NoOpAeadCipher()), remoteClientFactory, new NoOpRemoteAuthenticator()); // start the service - artifactLocalizerService.startAndWait(); + artifactLocalizerService.startAsync().awaitRunning(); return artifactLocalizerService; } @@ -104,7 +104,7 @@ public void setUp() throws Exception { @After public void tearDown() throws Exception { - this.localizerService.stopAndWait(); + this.localizerService.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/system/SystemWorkerServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/system/SystemWorkerServiceTest.java index d29dff65625b..22854ab8b4e3 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/system/SystemWorkerServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/worker/system/SystemWorkerServiceTest.java @@ -116,14 +116,14 @@ public void beforeTest() throws IOException { new RunnableTaskModule(discoveryService, discoveryService, new NoOpMetricsCollectionService())), new AuthenticationTestContext(), new NoOpAccessController()); - service.startAndWait(); + service.startAsync().awaitRunning(); this.systemWorkerService = service; } @After public void afterTest() { if (systemWorkerService != null) { - systemWorkerService.stopAndWait(); + systemWorkerService.stopAsync().awaitTerminated(); systemWorkerService = null; } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/audit/AuditPublishTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/audit/AuditPublishTest.java index 9c93e434f4d6..fe049309a491 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/audit/AuditPublishTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/audit/AuditPublishTest.java @@ -87,7 +87,7 @@ public static void init() throws Exception { Injector injector = AppFabricTestHelper.getInjector(cConf, new AuditModule()); messagingService = injector.getInstance(MessagingService.class); if (messagingService instanceof Service) { - ((Service) messagingService).startAndWait(); + ((Service) messagingService).startAsync().awaitRunning(); } auditTopic = NamespaceId.SYSTEM.topic(cConf.get(Constants.Audit.TOPIC)); } @@ -95,7 +95,7 @@ public static void init() throws Exception { @AfterClass public static void stop() { if (messagingService instanceof Service) { - ((Service) messagingService).stopAndWait(); + ((Service) messagingService).stopAsync().awaitTerminated(); } AppFabricTestHelper.shutdown(); } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/capability/CapabilityManagementServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/capability/CapabilityManagementServiceTest.java index 2f24fb2d850a..b24263ded59f 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/capability/CapabilityManagementServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/capability/CapabilityManagementServiceTest.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.capability; -import com.google.common.base.Throwables; import com.google.common.io.Files; import com.google.gson.Gson; import com.google.gson.JsonObject; @@ -100,7 +99,7 @@ public static void setup() { programLifecycleService = getInjector().getInstance(ProgramLifecycleService.class); programStateWriter = getInjector().getInstance(ProgramStateWriter.class); runtimeService = getInjector().getInstance(ProgramRuntimeService.class); - capabilityManagementService.stopAndWait(); + capabilityManagementService.stopAsync().awaitTerminated(); } @AfterClass @@ -117,7 +116,7 @@ public void reset() throws Exception { programLifecycleService.stopAll( new ApplicationReference(NamespaceId.SYSTEM.getNamespace(), d.getName())); } catch (Exception e) { - Throwables.propagate(e); + throw new RuntimeException(e); } }); @@ -127,7 +126,7 @@ public void reset() throws Exception { programLifecycleService.stopAll( new ApplicationReference(NamespaceId.DEFAULT.getNamespace(), d.getName())); } catch (Exception e) { - Throwables.propagate(e); + throw new RuntimeException(e); } }); diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/credential/CredentialProviderTestBase.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/credential/CredentialProviderTestBase.java index fc6082f7ee34..f0b3c0cbb222 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/credential/CredentialProviderTestBase.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/credential/CredentialProviderTestBase.java @@ -94,7 +94,7 @@ protected void configure() { } }); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); contextAccessEnforcer = injector.getInstance(ContextAccessEnforcer.class); CredentialProviderStore.create(injector .getInstance(StructuredTableAdmin.class)); @@ -131,7 +131,7 @@ protected void configure() { @AfterClass public static void teardown() throws Exception { if (txManager != null) { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/events/ProgramStatusEventPublisherMetricsTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/events/ProgramStatusEventPublisherMetricsTest.java index 8428ff36dea6..52a9629200ab 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/events/ProgramStatusEventPublisherMetricsTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/events/ProgramStatusEventPublisherMetricsTest.java @@ -51,13 +51,13 @@ public void testMetrics() throws IOException { MetricsProvider mockMetricsProvider = getMockMetricsProvider(); List metricValuesList = new ArrayList<>(); MetricsCollectionService mockMetricsCollectionService = getMockCollectionService(metricValuesList); - mockMetricsCollectionService.startAndWait(); + mockMetricsCollectionService.startAsync().awaitRunning(); ProgramStatusEventPublisher programStatusEventPublisher = new ProgramStatusEventPublisher( CConfiguration.create(), null, mockMetricsCollectionService, null, mockMetricsProvider ); programStatusEventPublisher.initialize(Collections.singleton(new DummyEventWriter())); programStatusEventPublisher.processMessages(null, getMockNotification()); - mockMetricsCollectionService.stopAndWait(); + mockMetricsCollectionService.stopAsync().awaitTerminated(); Assert.assertSame(1, metricValuesList.size()); Assert.assertTrue(containsMetric(metricValuesList.get(0), Constants.Metrics.ProgramEvent.PUBLISHED_COUNT)); } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/operation/OperationLifecycleManagerTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/operation/OperationLifecycleManagerTest.java index 6a6efdd61ff8..685f32424325 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/operation/OperationLifecycleManagerTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/operation/OperationLifecycleManagerTest.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.operation; -import com.google.common.io.Closeables; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; @@ -98,7 +97,11 @@ protected void configure() { @AfterClass public static void afterClass() { - Closeables.closeQuietly(postgres); + try { + postgres.close(); + } catch (Exception ignored) { + // Ignored because we are shutting down the test class and cleaning up the embedded postgres. + } } @Test diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/operation/OperationNotificationSingleTopicSubscriberServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/operation/OperationNotificationSingleTopicSubscriberServiceTest.java index 1b7498eb9fe5..1eed97ebd90a 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/operation/OperationNotificationSingleTopicSubscriberServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/operation/OperationNotificationSingleTopicSubscriberServiceTest.java @@ -19,7 +19,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.io.Closeables; import com.google.gson.Gson; import com.google.inject.AbstractModule; import com.google.inject.Guice; @@ -99,7 +98,13 @@ protected void configure() { @AfterClass public static void afterClass() { - Closeables.closeQuietly(pg); + try { + + pg.close(); + + } catch (Exception ignored) { + + } } @Test diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/operation/SqlOperationRunsStoreTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/operation/SqlOperationRunsStoreTest.java index 25b5df7aea83..1999b5be892c 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/operation/SqlOperationRunsStoreTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/operation/SqlOperationRunsStoreTest.java @@ -16,7 +16,6 @@ package io.cdap.cdap.internal.operation; -import com.google.common.io.Closeables; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; @@ -71,6 +70,12 @@ protected void configure() { @AfterClass public static void afterClass() { - Closeables.closeQuietly(pg); + try { + + pg.close(); + + } catch (Exception ignored) { + + } } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/profile/ProfileMetadataTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/profile/ProfileMetadataTest.java index 2e118e21b7ab..9f6ef15869ce 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/profile/ProfileMetadataTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/profile/ProfileMetadataTest.java @@ -48,12 +48,12 @@ public class ProfileMetadataTest extends AppFabricTestBase { @BeforeClass public static void setUp() { metadataSubscriberService = getInjector().getInstance(MetadataSubscriberService.class); - metadataSubscriberService.startAndWait(); + metadataSubscriberService.startAsync().awaitRunning(); } @AfterClass public static void tearDown() { - metadataSubscriberService.stopAndWait(); + metadataSubscriberService.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/provision/ProvisioningServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/provision/ProvisioningServiceTest.java index 1aeec499b62c..57505143ae88 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/provision/ProvisioningServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/provision/ProvisioningServiceTest.java @@ -98,32 +98,32 @@ public static void setupClass() throws Exception { Injector injector = Guice.createInjector(new AppFabricTestModule(cConf)); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); // Define all StructuredTable before starting any services that need StructuredTable StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); datasetService = injector.getInstance(DatasetService.class); - datasetService.startAndWait(); + datasetService.startAsync().awaitRunning(); messagingService = injector.getInstance(MessagingService.class); provisionerStore = injector.getInstance(ProvisionerStore.class); if (messagingService instanceof Service) { - ((Service) messagingService).startAndWait(); + ((Service) messagingService).startAsync().awaitRunning(); } provisioningService = injector.getInstance(ProvisioningService.class); - provisioningService.startAndWait(); + provisioningService.startAsync().awaitRunning(); transactionRunner = injector.getInstance(TransactionRunner.class); } @AfterClass public static void cleanupClass() { - provisioningService.stopAndWait(); - datasetService.stopAndWait(); - txManager.stopAndWait(); + provisioningService.stopAsync().awaitTerminated(); + datasetService.stopAsync().awaitTerminated(); + txManager.stopAsync().awaitTerminated(); if (messagingService instanceof Service) { - ((Service) messagingService).stopAndWait(); + ((Service) messagingService).stopAsync().awaitTerminated(); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/ArtifactCacheServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/ArtifactCacheServiceTest.java index 61b55bae62f9..a8a16a35e277 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/ArtifactCacheServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/ArtifactCacheServiceTest.java @@ -82,7 +82,7 @@ public void setUp() throws Exception { cConf, artifactCache, tetheringStore, null, discoveryService, new CommonNettyHttpServiceFactory(cConf, new NoOpMetricsCollectionService(), auditLogContexts -> {}, new NoOpAeadCipher())); - artifactCacheService.startAndWait(); + artifactCacheService.startAsync().awaitRunning(); getInjector().getInstance(ArtifactRepository.class).clear(NamespaceId.DEFAULT); LocationFactory locationFactory = getInjector().getInstance(LocationFactory.class); appJar = AppJarHelper.createDeploymentJar(locationFactory, TaskWorkerServiceTest.TestRunnableClass.class); @@ -97,7 +97,7 @@ public void setUp() throws Exception { @After public void tearDown() throws Exception { - artifactCacheService.stopAndWait(); + artifactCacheService.stopAsync().awaitTerminated(); artifactRepository.deleteArtifact(artifactId); appJar.delete(); deletePeer(); diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/TetheringClientHandlerTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/TetheringClientHandlerTest.java index 07cc8edee887..af04fcb38a31 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/TetheringClientHandlerTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/TetheringClientHandlerTest.java @@ -189,7 +189,7 @@ protected void configure() { }); tetheringStore = new TetheringStore(injector.getInstance(TransactionRunner.class)); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); profileService = injector.getInstance(ProfileService.class); namespaceAdmin = injector.getInstance(NamespaceAdmin.class); namespaceAdmin.create(new NamespaceMeta.Builder().setName(NAMESPACE_1).build()); @@ -203,7 +203,7 @@ public static void teardown() throws Exception { namespaceAdmin.delete(new NamespaceId(NAMESPACE_2)); namespaceAdmin.delete(new NamespaceId(NAMESPACE_3)); if (txManager != null) { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } } @@ -259,7 +259,7 @@ public void setUp() throws Exception { tetheringEventPublisher = new TetheringProgramEventPublisher(cConf, tetheringStore, messagingService, injector.getInstance(ProgramRunRecordFetcher.class), transactionRunner); - Assert.assertEquals(Service.State.RUNNING, tetheringEventPublisher.startAndWait()); + tetheringEventPublisher.startAsync().awaitRunning(); tetheringAgentService = new TetheringAgentService(cConf, tetheringStore, injector.getInstance(ProgramStateWriter.class), @@ -268,14 +268,14 @@ public void setUp() throws Exception { injector.getInstance(LocationFactory.class), injector.getInstance(ProvisionerNotifier.class), injector.getInstance(NamespaceQueryAdmin.class)); - Assert.assertEquals(Service.State.RUNNING, tetheringAgentService.startAndWait()); + tetheringAgentService.startAsync().awaitRunning(); } @After public void tearDown() throws Exception { deleteTetheringIfNeeded(SERVER_INSTANCE); - Assert.assertEquals(Service.State.TERMINATED, tetheringEventPublisher.stopAndWait()); - Assert.assertEquals(Service.State.TERMINATED, tetheringAgentService.stopAndWait()); + tetheringEventPublisher.stopAsync().awaitTerminated(); + tetheringAgentService.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/TetheringServerHandlerTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/TetheringServerHandlerTest.java index be6b386bccc1..69b2ce818bd0 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/TetheringServerHandlerTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/TetheringServerHandlerTest.java @@ -174,21 +174,21 @@ protected void configure() { tetheringStore = new TetheringStore(injector.getInstance(TransactionRunner.class)); messagingService = injector.getInstance(MessagingService.class); if (messagingService instanceof Service) { - ((Service) messagingService).startAndWait(); + ((Service) messagingService).startAsync().awaitRunning(); } messagingProgramStatePublisher = injector.getInstance(MessagingProgramStatePublisher.class); profileService = injector.getInstance(ProfileService.class); txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); } @AfterClass public static void teardown() { if (txManager != null) { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } if (messagingService instanceof Service) { - ((Service) messagingService).stopAndWait(); + ((Service) messagingService).stopAsync().awaitTerminated(); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/runtime/spi/runtimejob/TetheringRuntimeJobManagerTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/runtime/spi/runtimejob/TetheringRuntimeJobManagerTest.java index 52ec53b9932a..d6faee812ecf 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/runtime/spi/runtimejob/TetheringRuntimeJobManagerTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/tethering/runtime/spi/runtimejob/TetheringRuntimeJobManagerTest.java @@ -137,11 +137,11 @@ protected void configure() { StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); messagingService = injector.getInstance(MessagingService.class); if (messagingService instanceof Service) { - ((Service) messagingService).startAndWait(); + ((Service) messagingService).startAsync().awaitRunning(); } txManager = injector.getInstance(TransactionManager.class); - txManager.startAndWait(); + txManager.startAsync().awaitRunning(); tetheringStore = injector.getInstance(TetheringStore.class); PeerMetadata metadata = new PeerMetadata(Collections.singletonList(new NamespaceAllocation(TETHERED_NAMESPACE_NAME, null, @@ -163,11 +163,11 @@ protected void configure() { @AfterClass public static void tearDown() throws TopicNotFoundException, IOException { if (txManager != null) { - txManager.stopAndWait(); + txManager.stopAsync().awaitTerminated(); } messagingService.deleteTopic(topicId); if (messagingService instanceof Service) { - ((Service) messagingService).stopAndWait(); + ((Service) messagingService).stopAsync().awaitTerminated(); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/metadata/MetadataAdminAuthorizationTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/metadata/MetadataAdminAuthorizationTest.java index f0037a1175a9..cddb1f3ba851 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/metadata/MetadataAdminAuthorizationTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/metadata/MetadataAdminAuthorizationTest.java @@ -83,9 +83,9 @@ public static void setup() throws Exception { permissionManager = injector.getInstance(PermissionManager.class); appFabricServer = injector.getInstance(AppFabricServer.class); - appFabricServer.startAndWait(); + appFabricServer.startAsync().awaitRunning(); appFabricProcessor = injector.getInstance(AppFabricProcessorService.class); - appFabricProcessor.startAndWait(); + appFabricProcessor.startAsync().awaitRunning(); // Wait for the default namespace creation String user = AuthorizationUtil.getEffectiveMasterUser(cConf); @@ -173,8 +173,8 @@ public void testSearch() throws Exception { @AfterClass public static void tearDown() { - appFabricServer.stopAndWait(); - appFabricProcessor.stopAndWait(); + appFabricServer.stopAsync().awaitTerminated(); + appFabricProcessor.stopAsync().awaitTerminated(); AppFabricTestHelper.shutdown(); } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/metadata/SystemMetadataAuditPublishTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/metadata/SystemMetadataAuditPublishTest.java index 7d871f6b36fc..ff675a126d81 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/metadata/SystemMetadataAuditPublishTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/metadata/SystemMetadataAuditPublishTest.java @@ -70,14 +70,14 @@ protected void configure() { namespaceAdmin = injector.getInstance(NamespaceAdmin.class); scheduler = injector.getInstance(Scheduler.class); if (scheduler instanceof Service) { - ((Service) scheduler).startAndWait(); + ((Service) scheduler).startAsync().awaitRunning(); } } @AfterClass public static void tearDown() { if (scheduler instanceof Service) { - ((Service) scheduler).stopAndWait(); + ((Service) scheduler).stopAsync().awaitTerminated(); } AppFabricTestHelper.shutdown(); } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/runtime/OpenCloseDataSetTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/runtime/OpenCloseDataSetTest.java index eec078139a8b..3f7c8716a0fe 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/runtime/OpenCloseDataSetTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/runtime/OpenCloseDataSetTest.java @@ -17,7 +17,6 @@ package io.cdap.cdap.runtime; import com.google.common.base.Supplier; -import com.google.common.base.Throwables; import com.google.common.collect.Lists; import com.google.gson.Gson; import io.cdap.cdap.DummyAppWithTrackingTable; @@ -73,7 +72,7 @@ public class OpenCloseDataSetTest { try { return TEMP_FOLDER.newFolder(); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } }; diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/scheduler/CoreSchedulerServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/scheduler/CoreSchedulerServiceTest.java index 9095855c80f4..84661daa83b4 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/scheduler/CoreSchedulerServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/scheduler/CoreSchedulerServiceTest.java @@ -146,7 +146,7 @@ public static void setup() { cConf = getInjector().getInstance(CConfiguration.class); scheduler = getInjector().getInstance(Scheduler.class); if (scheduler instanceof Service) { - ((Service) scheduler).startAndWait(); + ((Service) scheduler).startAsync().awaitRunning(); } messagingService = getInjector().getInstance(MessagingService.class); store = getInjector().getInstance(Store.class); @@ -156,7 +156,7 @@ public static void setup() { @AfterClass public static void tearDown() { if (scheduler instanceof Service) { - ((Service) scheduler).stopAndWait(); + ((Service) scheduler).stopAsync().awaitTerminated(); } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/security/auth/AuditLogSingleTopicSubscriberServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/security/auth/AuditLogSingleTopicSubscriberServiceTest.java index 48d6d3e12335..57cbcbcb5f0b 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/security/auth/AuditLogSingleTopicSubscriberServiceTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/security/auth/AuditLogSingleTopicSubscriberServiceTest.java @@ -17,7 +17,6 @@ package io.cdap.cdap.security.auth; import com.google.common.collect.ImmutableList; -import com.google.common.io.Closeables; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; @@ -94,7 +93,13 @@ protected void configure() { @AfterClass public static void afterClass() { - Closeables.closeQuietly(pg); + try { + + pg.close(); + + } catch (Exception ignored) { + + } } diff --git a/cdap-app-fabric/src/test/java/io/cdap/cdap/security/impersonation/DefaultUGIProviderTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/security/impersonation/DefaultUGIProviderTest.java index 6f9ced673f1c..05a0380ceeb8 100644 --- a/cdap-app-fabric/src/test/java/io/cdap/cdap/security/impersonation/DefaultUGIProviderTest.java +++ b/cdap-app-fabric/src/test/java/io/cdap/cdap/security/impersonation/DefaultUGIProviderTest.java @@ -17,7 +17,7 @@ package io.cdap.cdap.security.impersonation; -import com.google.common.io.Files; + import io.cdap.cdap.api.security.AccessException; import io.cdap.cdap.app.store.Store; import io.cdap.cdap.common.conf.CConfiguration; @@ -236,7 +236,9 @@ private void verifyCaching(DefaultUGIProvider provider, ImpersonationRequest ali private Location copyFileToHDFS(Location hdfsKeytabDir, File localFile) throws IOException { Location remoteFile = hdfsKeytabDir.append(localFile.getName()); Assert.assertTrue(remoteFile.createNew()); - Files.copy(localFile, Locations.newOutputSupplier(remoteFile)); + try (java.io.OutputStream os = Locations.newOutputSupplier(remoteFile).getOutput()) { + java.nio.file.Files.copy(localFile.toPath(), os); + } return remoteFile; } diff --git a/cdap-master/src/main/java/io/cdap/cdap/data/runtime/main/MasterServiceMain.java b/cdap-master/src/main/java/io/cdap/cdap/data/runtime/main/MasterServiceMain.java index c2bc17f49069..b056b1ad0d22 100644 --- a/cdap-master/src/main/java/io/cdap/cdap/data/runtime/main/MasterServiceMain.java +++ b/cdap-master/src/main/java/io/cdap/cdap/data/runtime/main/MasterServiceMain.java @@ -17,10 +17,8 @@ package io.cdap.cdap.data.runtime.main; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Lists; -import com.google.common.io.Closeables; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.Service; @@ -135,7 +133,6 @@ import org.apache.twill.api.TwillRunnerService; import org.apache.twill.common.Cancellable; import org.apache.twill.common.Threads; -import org.apache.twill.internal.ServiceListenerAdapter; import org.apache.twill.internal.zookeeper.LeaderElection; import org.apache.twill.internal.zookeeper.ReentrantDistributedLock; import org.apache.twill.kafka.client.KafkaClientService; @@ -234,7 +231,7 @@ public MasterServiceMain() { this.leaderElection = new LeaderElection(zkClient, electionPath, electionHandler); // leader election will normally stay running. Will only stop if there was some issue starting up. - this.leaderElection.addListener(new ServiceListenerAdapter() { + this.leaderElection.addListener(new Service.Listener() { @Override public void terminated(Service.State from) { if (!stopped) { @@ -250,7 +247,7 @@ public void failed(Service.State from, Throwable failure) { System.exit(1); } } - }, MoreExecutors.sameThreadExecutor()); + }, MoreExecutors.directExecutor()); } @Override @@ -273,8 +270,8 @@ public void start() throws Exception { // Tries to create the ZK root node (which can be namespaced through the zk connection string) Futures.getUnchecked(ZKOperations.ignoreError(zkClient.create("/", null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null)); - electionInfoService.startAndWait(); - leaderElection.startAndWait(); + electionInfoService.startAsync().awaitRunning(); + leaderElection.startAsync().awaitRunning(); } @Override @@ -333,7 +330,13 @@ public void stop() { } stopQuietly(electionInfoService); stopQuietly(zkClient); - Closeables.closeQuietly(logAppenderInitializer); + try { + + logAppenderInitializer.close(); + + } catch (Exception ignored) { + + } } @Override @@ -371,7 +374,7 @@ private void createDirectory(FileContext fileContext, String path) { // just log the exception LOG.error("Exception while trying to create directory at {}", path, e); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -400,7 +403,7 @@ private boolean checkDirectoryExists(FileContext fileContext, org.apache.hadoop. private static T getAndStart(Injector injector, Class cls) { T service = injector.getInstance(cls); LOG.debug("Starting service in master {}", service); - service.startAndWait(); + service.startAsync().awaitRunning(); LOG.info("Service {} started in master", service); return service; } @@ -412,7 +415,7 @@ private static void stopQuietly(@Nullable Service service) { try { if (service != null) { LOG.debug("Stopping service in master: {}", service); - service.stopAndWait(); + service.stopAsync().awaitTerminated(); LOG.info("Service {} stopped in master", service); } } catch (Exception e) { @@ -462,7 +465,7 @@ private void login(CConfiguration cConf) { SecurityUtil.loginForMasterService(cConf); } catch (Exception e) { LOG.error("Failed to login as CDAP user", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -672,7 +675,7 @@ public void leader() { } LOG.info("Starting service in master: {}", service); try { - service.startAndWait(); + service.startAsync().awaitRunning(); } catch (Throwable t) { // shut down the executor and stop the twill app, // then throw an exception to cause the leader election service to stop @@ -714,9 +717,27 @@ private void stop(boolean stopRequested) { stopQuietly(service); } services.clear(); - Closeables.closeQuietly(metadataStorage); - Closeables.closeQuietly(accessControllerInstantiator); - Closeables.closeQuietly(logAppenderInitializer); + try { + + metadataStorage.close(); + + } catch (Exception ignored) { + + } + try { + + accessControllerInstantiator.close(); + + } catch (Exception ignored) { + + } + try { + + logAppenderInitializer.close(); + + } catch (Exception ignored) { + + } } /** @@ -990,7 +1011,7 @@ public void run() { throw e; } } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-master/src/main/java/io/cdap/cdap/data/tools/JobQueueDebugger.java b/cdap-master/src/main/java/io/cdap/cdap/data/tools/JobQueueDebugger.java index fc5d98e3df13..461631a66859 100644 --- a/cdap-master/src/main/java/io/cdap/cdap/data/tools/JobQueueDebugger.java +++ b/cdap-master/src/main/java/io/cdap/cdap/data/tools/JobQueueDebugger.java @@ -125,12 +125,12 @@ public JobQueueDebugger(CConfiguration cConf, ZKClientService zkClientService, @Override protected void startUp() { - zkClientService.startAndWait(); + zkClientService.startAsync().awaitRunning(); } @Override protected void shutDown() { - zkClientService.stopAndWait(); + zkClientService.stopAsync().awaitTerminated(); } private JobQueueScanner getJobQueueScanner() { @@ -221,8 +221,8 @@ private JobStatistics scanPartition(final int partition, boolean trace) { private boolean scanJobQueue(JobQueue jobQueue, int partition, JobStatistics jobStatistics) throws IOException { try (CloseableIterator jobs = jobQueue.getJobs(partition, lastJobConsumed)) { - Stopwatch stopwatch = new Stopwatch().start(); - while (stopwatch.elapsedMillis() < 1000) { + Stopwatch stopwatch = Stopwatch.createUnstarted().start(); + while (stopwatch.elapsed(java.util.concurrent.TimeUnit.MILLISECONDS) < 1000) { if (!jobs.hasNext()) { lastJobConsumed = null; return false; @@ -422,7 +422,7 @@ public static void main(String[] args) throws Exception { } JobQueueDebugger debugger = createDebugger(); - debugger.startAndWait(); + debugger.startAsync().awaitRunning(); debugger.printTopicMessageIds(); @@ -431,6 +431,6 @@ public static void main(String[] args) throws Exception { } else { debugger.scanPartition(partition, trace); } - debugger.stopAndWait(); + debugger.stopAsync().awaitTerminated(); } } diff --git a/cdap-master/src/main/java/io/cdap/cdap/master/environment/k8s/MetadataServiceMain.java b/cdap-master/src/main/java/io/cdap/cdap/master/environment/k8s/MetadataServiceMain.java index 8ef580633609..942ba8fd483b 100644 --- a/cdap-master/src/main/java/io/cdap/cdap/master/environment/k8s/MetadataServiceMain.java +++ b/cdap-master/src/main/java/io/cdap/cdap/master/environment/k8s/MetadataServiceMain.java @@ -16,7 +16,6 @@ package io.cdap.cdap.master.environment.k8s; -import com.google.common.io.Closeables; import com.google.common.util.concurrent.AbstractService; import com.google.common.util.concurrent.Service; import com.google.inject.AbstractModule; @@ -145,7 +144,13 @@ protected void doStart() { @Override protected void doStop() { - Closeables.closeQuietly(metadataStorage); + try { + + metadataStorage.close(); + + } catch (Exception ignored) { + + } notifyStopped(); } }); diff --git a/cdap-master/src/main/java/io/cdap/cdap/master/startup/MasterStartupTool.java b/cdap-master/src/main/java/io/cdap/cdap/master/startup/MasterStartupTool.java index ab4b413b7174..08feff89dfb4 100644 --- a/cdap-master/src/main/java/io/cdap/cdap/master/startup/MasterStartupTool.java +++ b/cdap-master/src/main/java/io/cdap/cdap/master/startup/MasterStartupTool.java @@ -19,7 +19,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Splitter; import com.google.common.base.Strings; -import com.google.common.base.Throwables; import com.google.inject.Guice; import com.google.inject.Injector; import io.cdap.cdap.common.conf.CConfiguration; @@ -77,7 +76,7 @@ public static void main(String[] args) { SecurityUtil.loginForMasterService(cConf); } catch (Exception e) { LOG.error("Failed to login as CDAP user", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } Configuration hConf = new Configuration(); diff --git a/cdap-master/src/main/java/io/cdap/cdap/master/upgrade/UpgradeUserIDProvider.java b/cdap-master/src/main/java/io/cdap/cdap/master/upgrade/UpgradeUserIDProvider.java index a5e252c20187..a087b56dd969 100644 --- a/cdap-master/src/main/java/io/cdap/cdap/master/upgrade/UpgradeUserIDProvider.java +++ b/cdap-master/src/main/java/io/cdap/cdap/master/upgrade/UpgradeUserIDProvider.java @@ -15,7 +15,6 @@ */ package io.cdap.cdap.master.upgrade; -import com.google.common.base.Throwables; import java.io.IOException; import org.apache.hadoop.security.UserGroupInformation; @@ -35,7 +34,7 @@ public static String getUserID() { try { userId = UserGroupInformation.getCurrentUser().getShortUserName(); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } return userId; } diff --git a/cdap-master/src/test/java/io/cdap/cdap/master/environment/MockMasterEnvironment.java b/cdap-master/src/test/java/io/cdap/cdap/master/environment/MockMasterEnvironment.java index 534f9926257a..4651aed50343 100644 --- a/cdap-master/src/test/java/io/cdap/cdap/master/environment/MockMasterEnvironment.java +++ b/cdap-master/src/test/java/io/cdap/cdap/master/environment/MockMasterEnvironment.java @@ -42,7 +42,7 @@ public class MockMasterEnvironment implements MasterEnvironment { @Override public void initialize(MasterEnvironmentContext context) { zkClient = ZKClientService.Builder.of(context.getConfigurations().get(Constants.Zookeeper.QUORUM)).build(); - zkClient.startAndWait(); + zkClient.startAsync().awaitRunning(); discoveryService = new ZKDiscoveryService(zkClient); twillRunnerService = new NoopTwillRunnerService(); @@ -56,7 +56,7 @@ public void initialize(MasterEnvironmentContext context) { @Override public void destroy() { discoveryService.close(); - zkClient.stopAndWait(); + zkClient.stopAsync().awaitTerminated(); } @Override diff --git a/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/LogsServiceMainTest.java b/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/LogsServiceMainTest.java index dfea32098ff6..dc87c9da24f2 100644 --- a/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/LogsServiceMainTest.java +++ b/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/LogsServiceMainTest.java @@ -20,7 +20,7 @@ import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.classic.spi.LoggingEvent; import ch.qos.logback.core.AppenderBase; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; import com.google.common.net.HttpHeaders; import com.google.gson.Gson; @@ -168,7 +168,7 @@ LogData getLog() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("log", log) .add("offset", getOffset()) .toString(); @@ -188,7 +188,7 @@ LogOffset getOffset() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("offset", offset) .toString(); } diff --git a/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/MasterServiceMainTestBase.java b/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/MasterServiceMainTestBase.java index ae97bcfecf10..cc28b0c09f9c 100644 --- a/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/MasterServiceMainTestBase.java +++ b/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/MasterServiceMainTestBase.java @@ -68,7 +68,7 @@ public class MasterServiceMainTestBase { public static void init() throws Exception { zkServer = InMemoryZKServer.builder().setAutoCleanDataDir(false) .setDataDir(TEMP_FOLDER.newFolder()).build(); - zkServer.startAndWait(); + zkServer.startAsync().awaitRunning(); // Set the HDFS directory as well as we are using DFSLocationModule in the master services cConf.set(Constants.CFG_HDFS_NAMESPACE, TEMP_FOLDER.newFolder().getAbsolutePath()); @@ -142,7 +142,7 @@ public static void finish() { // Reverse stop services Lists.reverse(new ArrayList<>(SERVICE_MANAGERS.keySet())) .forEach(MasterServiceMainTestBase::stopService); - zkServer.stopAndWait(); + zkServer.stopAsync().awaitTerminated(); } /** diff --git a/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/PreviewServiceMainTest.java b/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/PreviewServiceMainTest.java index 1b9a0287a086..48fdcc40f924 100644 --- a/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/PreviewServiceMainTest.java +++ b/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/PreviewServiceMainTest.java @@ -99,7 +99,7 @@ public static void initPreviewService() throws Exception { cConf.set(Constants.CFG_LOCAL_DATA_DIR, temporaryFolder.newFolder().getAbsolutePath()); Injector injector = ArtifactLocalizerTwillRunnable.createInjector(cConf, new Configuration()); artifactLocalizerService = injector.getInstance(ArtifactLocalizerService.class); - artifactLocalizerService.startAndWait(); + artifactLocalizerService.startAsync().awaitRunning(); // Start the preview service main, which will use its own local datadir and fetch artifacts from app-fabric via // the artifact localizer service. startService(PreviewServiceMain.class); @@ -108,7 +108,7 @@ public static void initPreviewService() throws Exception { @AfterClass public static void afterPreviewService() throws Exception { stopService(PreviewServiceMain.class); - artifactLocalizerService.stopAndWait(); + artifactLocalizerService.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/SystemMetricsExporterServiceMainTest.java b/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/SystemMetricsExporterServiceMainTest.java index 3ce04353d3a4..eb6ce216f9e9 100644 --- a/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/SystemMetricsExporterServiceMainTest.java +++ b/cdap-master/src/test/java/io/cdap/cdap/master/environment/k8s/SystemMetricsExporterServiceMainTest.java @@ -38,9 +38,9 @@ public void testSystemMetricsExporterService() { Map metricTags = ImmutableMap.of("key1", "value1", "key2", "value2"); JmxMetricsCollector metricsCollector = factory.create(metricTags); // JMX server isn't running, but that shouldn't raise exceptions, errors will be logged. - metricsCollector.startAndWait(); + metricsCollector.startAsync().awaitRunning(); Assert.assertTrue(metricsCollector.isRunning()); - metricsCollector.stopAndWait(); + metricsCollector.stopAsync().awaitTerminated(); Assert.assertFalse(metricsCollector.isRunning()); } diff --git a/cdap-master/src/test/java/io/cdap/cdap/metrics/jmx/JmxMetricsCollectorTest.java b/cdap-master/src/test/java/io/cdap/cdap/metrics/jmx/JmxMetricsCollectorTest.java index af9495a68d15..923ca5c7993f 100644 --- a/cdap-master/src/test/java/io/cdap/cdap/metrics/jmx/JmxMetricsCollectorTest.java +++ b/cdap-master/src/test/java/io/cdap/cdap/metrics/jmx/JmxMetricsCollectorTest.java @@ -98,7 +98,7 @@ public void testNumberOfMetricsEmitted() throws InterruptedException, MalformedU cConf.setInt(Constants.JmxMetricsCollector.POLL_INTERVAL_SECS, 1); Map metricTags = ImmutableMap.of("key1", "value1", "key2", "value2"); JmxMetricsCollector jmxMetrics = new JmxMetricsCollector(cConf, publisher, metricTags); - jmxMetrics.startAndWait(); + jmxMetrics.startAsync().awaitRunning(); verify(publisher, times(1)).initialize(); // Poll should run at 0, 1. 2 secs buffer. Tasks.waitFor(true, () -> { @@ -109,6 +109,6 @@ public void testNumberOfMetricsEmitted() throws InterruptedException, MalformedU } return true; }, 3, TimeUnit.SECONDS); - jmxMetrics.stop(); + jmxMetrics.stopAsync().awaitTerminated(); } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/AbstractKeyManager.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/AbstractKeyManager.java index d440b0443066..63d80590a1b9 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/AbstractKeyManager.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/AbstractKeyManager.java @@ -18,7 +18,6 @@ import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; import com.google.common.util.concurrent.AbstractIdleService; import io.cdap.cdap.api.common.Bytes; import io.cdap.cdap.common.conf.CConfiguration; @@ -157,7 +156,7 @@ public final void validateMAC(Codec codec, Signed signedMessage) throw new InvalidDigestException("Token signature is not valid!"); } } catch (IOException ioe) { - throw Throwables.propagate(ioe); + throw new RuntimeException(ioe); } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessToken.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessToken.java index 9d2941fc1479..a5d7c01852e4 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessToken.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessToken.java @@ -16,6 +16,7 @@ package io.cdap.cdap.security.auth; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.collect.Maps; import io.cdap.cdap.api.common.Bytes; @@ -124,7 +125,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("identifier", identifier) .add("keyId", keyId) .add("digest", Bytes.toStringBinary(digest)) diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessTokenValidator.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessTokenValidator.java index 25a4896eed36..3a47f348b64d 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessTokenValidator.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/AccessTokenValidator.java @@ -42,13 +42,13 @@ public AccessTokenValidator(TokenManager tokenManager, Codec access @Override protected void startUp() throws Exception { LOG.info("Starting up AccessTokenValidator service"); - tokenManager.startAndWait(); + tokenManager.startAsync().awaitRunning(); } @Override protected void shutDown() throws Exception { LOG.info("Shutting down AccessTokenValidator service"); - tokenManager.stopAndWait(); + tokenManager.stopAsync().awaitTerminated(); } @Override diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/DistributedKeyManager.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/DistributedKeyManager.java index 2b0493c7b196..b3eafe88e654 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/DistributedKeyManager.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/DistributedKeyManager.java @@ -16,7 +16,6 @@ package io.cdap.cdap.security.auth; -import com.google.common.base.Throwables; import com.google.inject.Inject; import io.cdap.cdap.common.conf.CConfiguration; import io.cdap.cdap.common.conf.Constants; @@ -96,7 +95,7 @@ protected void doInit() { try { keyCache.init(); } catch (InterruptedException ie) { - throw Throwables.propagate(ie); + throw new RuntimeException(ie); } this.leaderElection = new LeaderElection(zookeeper, "/leader", new ElectionHandler() { @Override @@ -114,7 +113,7 @@ public void follower() { LOG.debug("Transitioned to follower"); } }); - this.leaderElection.start(); + this.leaderElection.startAsync(); startExpirationThread(); } @@ -123,7 +122,7 @@ public void shutDown() { if (timer != null) { timer.cancel(); } - leaderElection.stopAndWait(); + leaderElection.stopAsync().awaitTerminated(); } @Override diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/KeyIdentifier.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/KeyIdentifier.java index 69f5d2a81bb5..fb59f0eb2fe5 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/KeyIdentifier.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/KeyIdentifier.java @@ -16,6 +16,7 @@ package io.cdap.cdap.security.auth; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.collect.Maps; import io.cdap.cdap.api.data.schema.Schema; @@ -106,7 +107,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("keyId", keyId) .add("expiration", expiration) .toString(); diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/TokenManager.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/TokenManager.java index 3749baf1e6fb..54663de7fd48 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/TokenManager.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/TokenManager.java @@ -16,7 +16,6 @@ package io.cdap.cdap.security.auth; -import com.google.common.base.Throwables; import com.google.common.util.concurrent.AbstractIdleService; import com.google.inject.Inject; import io.cdap.cdap.common.io.Codec; @@ -44,13 +43,13 @@ public TokenManager(KeyManager keyManager, Codec identifierCodec) @Override public void startUp() { LOG.info("Starting TokenManager service"); - this.keyManager.startAndWait(); + this.keyManager.startAsync().awaitRunning(); } @Override public void shutDown() { LOG.info("Shutting down TokenManager service."); - this.keyManager.stopAndWait(); + this.keyManager.stopAsync().awaitTerminated(); } /** @@ -64,7 +63,7 @@ public AccessToken signIdentifier(UserIdentity identifier) { KeyManager.DigestId digest = keyManager.generateMAC(identifierCodec.encode(identifier)); return new AccessToken(identifier, digest.getId(), digest.getDigest()); } catch (IOException ioe) { - throw Throwables.propagate(ioe); + throw new RuntimeException(ioe); } catch (InvalidKeyException ike) { throw new IllegalStateException("Invalid key configured for KeyManager.", ike); } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/UserIdentity.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/UserIdentity.java index c1690d982a77..e8c39346a2f5 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/UserIdentity.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/UserIdentity.java @@ -16,6 +16,7 @@ package io.cdap.cdap.security.auth; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; @@ -162,7 +163,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("username", username) .add("tokenType", identifierType) .add("groups", groups) diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/AuthenticationContextModules.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/AuthenticationContextModules.java index c451542c0415..7a46b8009225 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/AuthenticationContextModules.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/AuthenticationContextModules.java @@ -16,7 +16,6 @@ package io.cdap.cdap.security.auth.context; -import com.google.common.base.Throwables; import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Injector; @@ -158,7 +157,7 @@ private String getUsername() { try { return UserGroupInformation.getCurrentUser().getShortUserName(); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/MasterAuthenticationContext.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/MasterAuthenticationContext.java index 06657748e00d..8d827a039bec 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/MasterAuthenticationContext.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/MasterAuthenticationContext.java @@ -16,7 +16,6 @@ package io.cdap.cdap.security.auth.context; -import com.google.common.base.Throwables; import io.cdap.cdap.proto.security.Credential; import io.cdap.cdap.proto.security.Principal; import io.cdap.cdap.security.spi.authentication.AuthenticationContext; @@ -51,7 +50,7 @@ public Principal getPrincipal() { try { userId = UserGroupInformation.getCurrentUser().getShortUserName(); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } return new Principal(userId, Principal.PrincipalType.USER, userCredential); diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/SystemAuthenticationContext.java b/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/SystemAuthenticationContext.java index c3e19e4b647b..52130ce282da 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/SystemAuthenticationContext.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/auth/context/SystemAuthenticationContext.java @@ -16,7 +16,6 @@ package io.cdap.cdap.security.auth.context; -import com.google.common.base.Throwables; import com.google.inject.Inject; import io.cdap.cdap.proto.security.Credential; import io.cdap.cdap.proto.security.Principal; @@ -80,7 +79,7 @@ public Principal getPrincipal() { try { userId = UserGroupInformation.getCurrentUser().getShortUserName(); } catch (IOException e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } long currentTimestamp = System.currentTimeMillis(); UserIdentity identity = new UserIdentity(userId, UserIdentity.IdentifierType.INTERNAL, diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AccessControllerInstantiator.java b/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AccessControllerInstantiator.java index 9b52be01fdde..27015d451dcc 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AccessControllerInstantiator.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AccessControllerInstantiator.java @@ -19,8 +19,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; import com.google.common.base.Supplier; -import com.google.common.base.Throwables; -import com.google.common.io.Closeables; import com.google.common.reflect.TypeToken; import com.google.inject.Inject; import io.cdap.cdap.common.conf.CConfiguration; @@ -158,7 +156,7 @@ public AccessControllerSpi get() { accessControllerClassLoader); return accessController; } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } } @@ -311,7 +309,13 @@ public void close() throws IOException { } catch (Throwable t) { LOG.warn("Failed to destroy accessController.", t); } finally { - Closeables.closeQuietly(accessControllerClassLoader); + try { + + accessControllerClassLoader.close(); + + } catch (Exception ignored) { + + } } } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AuthorizerWrapper.java b/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AuthorizerWrapper.java index c326dd6cf3e9..5382065c0e0a 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AuthorizerWrapper.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/authorization/AuthorizerWrapper.java @@ -16,7 +16,6 @@ package io.cdap.cdap.security.authorization; -import com.google.common.base.Throwables; import io.cdap.cdap.api.security.AccessException; import io.cdap.cdap.common.security.AuthEnforceUtil; import io.cdap.cdap.proto.element.EntityType; @@ -54,7 +53,7 @@ public void initialize(AuthorizationContext context) { try { authorizer.initialize(context); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -117,7 +116,7 @@ public void destroy() { try { authorizer.destroy(); } catch (Exception e) { - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/impersonation/ImpersonationUtils.java b/cdap-security/src/main/java/io/cdap/cdap/security/impersonation/ImpersonationUtils.java index da4c942075b2..5b5974d025d6 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/impersonation/ImpersonationUtils.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/impersonation/ImpersonationUtils.java @@ -16,7 +16,6 @@ package io.cdap.cdap.security.impersonation; -import com.google.common.base.Throwables; import io.cdap.cdap.proto.NamespaceMeta; import java.lang.reflect.UndeclaredThrowableException; import java.security.PrivilegedExceptionAction; @@ -50,7 +49,17 @@ public T run() throws Exception { } catch (UndeclaredThrowableException e) { // UserGroupInformation#doAs will wrap any checked exceptions, so unwrap and rethrow here Throwable wrappedException = e.getUndeclaredThrowable(); - Throwables.propagateIfPossible(wrappedException); + if (wrappedException instanceof RuntimeException) { + + throw (RuntimeException) wrappedException; + + } + + if (wrappedException instanceof Error) { + + throw (Error) wrappedException; + + } if (wrappedException instanceof Exception) { throw (Exception) wrappedException; @@ -59,7 +68,7 @@ public T run() throws Exception { // this should never happen LOG.warn("Unexpected exception while executing callable as {}.", ugi.getUserName(), wrappedException); - throw Throwables.propagate(wrappedException); + throw new RuntimeException(wrappedException); } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/runtime/AuthenticationServerMain.java b/cdap-security/src/main/java/io/cdap/cdap/security/runtime/AuthenticationServerMain.java index 85399509197a..581d10fd17d7 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/runtime/AuthenticationServerMain.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/runtime/AuthenticationServerMain.java @@ -87,7 +87,7 @@ public void start() throws Exception { + "ZooKeeper quorum settings are correct in " + "cdap-site.xml. Currently configured as: %s", zkClientService.getConnectString())); - authServer.startAndWait(); + authServer.startAsync().awaitRunning(); } catch (Exception e) { Throwable rootCause = Throwables.getRootCause(e); if (rootCause instanceof ServiceBindException) { diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/server/ExternalAuthenticationServer.java b/cdap-security/src/main/java/io/cdap/cdap/security/server/ExternalAuthenticationServer.java index 2edf817d29c8..e9c292314c34 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/server/ExternalAuthenticationServer.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/server/ExternalAuthenticationServer.java @@ -16,9 +16,9 @@ package io.cdap.cdap.security.server; +import com.google.common.base.Throwables; import com.google.common.base.Preconditions; import com.google.common.base.Strings; -import com.google.common.base.Throwables; import com.google.common.util.concurrent.AbstractIdleService; import com.google.inject.Inject; import com.google.inject.name.Named; @@ -294,7 +294,7 @@ private Map getAuthHandlerConfigs(Configuration configuration) { } @Override - protected Executor executor(State state) { + protected Executor executor() { final AtomicInteger id = new AtomicInteger(); //noinspection NullableProblems diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/server/GrantAccessToken.java b/cdap-security/src/main/java/io/cdap/cdap/security/server/GrantAccessToken.java index 96c57e21b042..e1bbf942911d 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/server/GrantAccessToken.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/server/GrantAccessToken.java @@ -73,7 +73,7 @@ public GrantAccessToken(TokenManager tokenManager, public void init() { // TokenManager may have already been started in AbstractServiceMain if internal auth is enabled. if (!tokenManager.isRunning()) { - tokenManager.start(); + tokenManager.startAsync().awaitRunning(); } } @@ -81,7 +81,7 @@ public void init() { * Stop the TokenManager. */ public void destroy() { - tokenManager.stop(); + tokenManager.stopAsync(); } /** diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapAuthenticationHandler.java b/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapAuthenticationHandler.java index c98cb26b481a..94fa6f8cebaf 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapAuthenticationHandler.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapAuthenticationHandler.java @@ -16,6 +16,7 @@ package io.cdap.cdap.security.server; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import io.cdap.cdap.common.conf.Constants; @@ -61,9 +62,9 @@ public AppConfigurationEntry[] getAppConfigurationEntry(String s) { String ldapsVerifyCertificate = handlerProps.get("ldapsVerifyCertificate"); String useLdaps = handlerProps.get("useLdaps"); - if (Boolean.parseBoolean(Objects.firstNonNull(useLdaps, "false"))) { + if (Boolean.parseBoolean(MoreObjects.firstNonNull(useLdaps, "false"))) { ldapSSLVerifyCertificate = Boolean.parseBoolean( - Objects.firstNonNull(ldapsVerifyCertificate, "true")); + MoreObjects.firstNonNull(ldapsVerifyCertificate, "true")); } return new AppConfigurationEntry[]{ diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapLoginModule.java b/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapLoginModule.java index 75e5d14ff503..2d755b010eca 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapLoginModule.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/server/LdapLoginModule.java @@ -16,7 +16,6 @@ package io.cdap.cdap.security.server; -import com.google.common.base.Throwables; import java.io.IOException; import java.net.InetAddress; import java.net.Socket; @@ -76,7 +75,7 @@ public X509Certificate[] getAcceptedIssuers() { trustAllFactory = sc.getSocketFactory(); } catch (GeneralSecurityException e) { LOG.error("Could not disable certificate verification for connections to LDAP.", e); - throw Throwables.propagate(e); + throw new RuntimeException(e); } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/store/DefaultSecureStoreService.java b/cdap-security/src/main/java/io/cdap/cdap/security/store/DefaultSecureStoreService.java index 268b3cb93b59..b8971fdc113a 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/store/DefaultSecureStoreService.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/store/DefaultSecureStoreService.java @@ -145,11 +145,11 @@ public final void delete(String namespace, String name) throws Exception { @Override protected void startUp() throws Exception { - secureStoreService.startAndWait(); + secureStoreService.startAsync().awaitRunning(); } @Override protected void shutDown() throws Exception { - secureStoreService.stopAndWait(); + secureStoreService.stopAsync().awaitTerminated(); } } diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/tools/AccessTokenGeneratorService.java b/cdap-security/src/main/java/io/cdap/cdap/security/tools/AccessTokenGeneratorService.java index a6491022cfb6..4b5291295577 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/tools/AccessTokenGeneratorService.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/tools/AccessTokenGeneratorService.java @@ -109,7 +109,7 @@ public void stop() { } catch (Exception e) { LOG.warn("Exception when stopping AccessTokenGeneratorService", e); } - handler.tokenManager.stopAndWait(); + handler.tokenManager.stopAsync().awaitTerminated(); } @Override diff --git a/cdap-security/src/main/java/io/cdap/cdap/security/zookeeper/SharedResourceCache.java b/cdap-security/src/main/java/io/cdap/cdap/security/zookeeper/SharedResourceCache.java index c87e464c6b8a..a82410a7ba25 100644 --- a/cdap-security/src/main/java/io/cdap/cdap/security/zookeeper/SharedResourceCache.java +++ b/cdap-security/src/main/java/io/cdap/cdap/security/zookeeper/SharedResourceCache.java @@ -24,6 +24,7 @@ import com.google.common.collect.Sets; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.SettableFuture; import io.cdap.cdap.common.io.Codec; import io.cdap.cdap.common.zookeeper.ZKExtOperations; @@ -91,7 +92,7 @@ public void init() throws InterruptedException { } } catch (ExecutionException ee) { // recheck if already created - throw Throwables.propagate(ee.getCause()); + throw new RuntimeException(ee.getCause()); } this.resources = reloadAll(); listeners.notifyUpdate(); @@ -117,7 +118,7 @@ public void onSuccess(NodeData result) { loaded.put(nodeName, resource); listeners.notifyResourceUpdate(nodeName, resource); } catch (IOException ioe) { - throw Throwables.propagate(ioe); + throw new RuntimeException(ioe); } } @@ -126,7 +127,8 @@ public void onFailure(Throwable t) { LOG.error("Failed to get data for child node {}", nodeName, t); listeners.notifyError(nodeName, t); } - }); + }, + MoreExecutors.directExecutor()); LOG.debug("Added future for {}", child); } } @@ -192,14 +194,14 @@ public void onFailure(Throwable t) { listeners.notifyError(name, t); completion.setException(t); } - } - ); + }, + MoreExecutors.directExecutor()); // Block until it is done completion.get(); } catch (Exception ioe) { - throw Throwables.propagate(ioe); + throw new RuntimeException(ioe); } } @@ -228,7 +230,8 @@ public void onFailure(Throwable t) { LOG.error("Failed to remove znode {}", znode, t); listeners.notifyError(name, t); } - }); + }, + MoreExecutors.directExecutor()); } /** @@ -348,7 +351,8 @@ public void onSuccess(NodeData result) { public void onFailure(Throwable t) { resourceCallback.onFailure(t); } - }); + }, + MoreExecutors.directExecutor()); } private class ZKWatcher implements Watcher { @@ -403,7 +407,11 @@ public void run() { listener.onUpdate(); } catch (Throwable t) { LOG.error("Exception notifying listener {}", listener, t); - Throwables.propagateIfInstanceOf(t, Error.class); + if (t instanceof Error) { + + throw (Error) t; + + } } } } @@ -419,7 +427,11 @@ public void run() { listener.onResourceUpdate(name, resource); } catch (Throwable t) { LOG.error("Exception notifying listener {}", listener, t); - Throwables.propagateIfInstanceOf(t, Error.class); + if (t instanceof Error) { + + throw (Error) t; + + } } } } @@ -435,7 +447,11 @@ public void run() { listener.onResourceDelete(name); } catch (Throwable t) { LOG.error("Exception notifying listener {}", listener, t); - Throwables.propagateIfInstanceOf(t, Error.class); + if (t instanceof Error) { + + throw (Error) t; + + } } } } @@ -451,7 +467,11 @@ public void run() { listener.onError(name, throwable); } catch (Throwable t) { LOG.error("Exception notifying listener {}", listener, t); - Throwables.propagateIfInstanceOf(t, Error.class); + if (t instanceof Error) { + + throw (Error) t; + + } } } } diff --git a/cdap-security/src/test/java/io/cdap/cdap/security/auth/DistributedKeyManagerTest.java b/cdap-security/src/test/java/io/cdap/cdap/security/auth/DistributedKeyManagerTest.java index c37de574bf86..ce3a27c258a6 100644 --- a/cdap-security/src/test/java/io/cdap/cdap/security/auth/DistributedKeyManagerTest.java +++ b/cdap-security/src/test/java/io/cdap/cdap/security/auth/DistributedKeyManagerTest.java @@ -117,8 +117,8 @@ public void testKeyDistribution() throws Exception { new TestingTokenManager(manager1, injector1.getInstance(UserIdentityCodec.class)); TestingTokenManager tokenManager2 = new TestingTokenManager(manager2, injector2.getInstance(UserIdentityCodec.class)); - tokenManager1.startAndWait(); - tokenManager2.startAndWait(); + tokenManager1.startAsync().awaitRunning(); + tokenManager2.startAsync().awaitRunning(); long now = System.currentTimeMillis(); UserIdentity ident1 = new UserIdentity("testuser", UserIdentity.IdentifierType.EXTERNAL, @@ -136,8 +136,8 @@ public void testKeyDistribution() throws Exception { assertEquals(token1.getIdentifier().getGroups(), token2.getIdentifier().getGroups()); assertEquals(token1, token2); - tokenManager1.stopAndWait(); - tokenManager2.stopAndWait(); + tokenManager1.stopAsync().awaitTerminated(); + tokenManager2.stopAsync().awaitTerminated(); } @Test @@ -160,21 +160,21 @@ protected ImmutablePair> getTokenManagerAndCode DistributedKeyManager keyManager = getKeyManager(injector1, true); TokenManager tokenManager = new TokenManager(keyManager, injector1.getInstance(UserIdentityCodec.class)); - tokenManager.startAndWait(); + tokenManager.startAsync().awaitRunning(); return new ImmutablePair<>(tokenManager, injector1.getInstance(AccessTokenCodec.class)); } private DistributedKeyManager getKeyManager(Injector injector, boolean expectLeader) throws Exception { ZKClientService zk = injector.getInstance(ZKClientService.class); - zk.startAndWait(); + zk.startAsync().awaitRunning(); WaitableDistributedKeyManager keyManager = new WaitableDistributedKeyManager(injector.getInstance(CConfiguration.class), injector.getInstance(Key.get(new TypeLiteral>() { })), zk); - keyManager.startAndWait(); + keyManager.startAsync().awaitRunning(); if (expectLeader) { Tasks.waitFor(true, () -> keyManager.getCurrentKey() != null, 5L, TimeUnit.SECONDS); } diff --git a/cdap-security/src/test/java/io/cdap/cdap/security/auth/FileBasedTokenManagerTest.java b/cdap-security/src/test/java/io/cdap/cdap/security/auth/FileBasedTokenManagerTest.java index e535d834b1b0..de26d1a105ff 100644 --- a/cdap-security/src/test/java/io/cdap/cdap/security/auth/FileBasedTokenManagerTest.java +++ b/cdap-security/src/test/java/io/cdap/cdap/security/auth/FileBasedTokenManagerTest.java @@ -60,7 +60,7 @@ protected ImmutablePair> getTokenManagerAndCode new FileBasedCoreSecurityModule(), new InMemoryDiscoveryModule()); TokenManager tokenManager = injector.getInstance(TokenManager.class); - tokenManager.startAndWait(); + tokenManager.startAsync().awaitRunning(); Codec tokenCodec = injector.getInstance(AccessTokenCodec.class); return new ImmutablePair<>(tokenManager, tokenCodec); } @@ -79,14 +79,14 @@ public void testFileBasedKey() throws Exception { new ConfigModule(cConf), new FileBasedCoreSecurityModule(), new InMemoryDiscoveryModule()).getInstance(TokenManager.class); - tokenManager.startAndWait(); + tokenManager.startAsync().awaitRunning(); TokenManager tokenManager2 = Guice.createInjector( new IOModule(), new ConfigModule(cConf), new FileBasedCoreSecurityModule(), new InMemoryDiscoveryModule()).getInstance(TokenManager.class); - tokenManager2.startAndWait(); + tokenManager2.startAsync().awaitRunning(); Assert.assertNotSame("ERROR: Both token managers refer to the same object.", tokenManager, tokenManager2); @@ -129,7 +129,7 @@ public void testKeyUpdate() throws Exception { keyFile.setLastModified(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(10)); try { - keyManager.startAndWait(); + keyManager.startAsync().awaitRunning(); // Upon the key manager starts, the current key should be the same as the one from the key file. Assert.assertEquals(keyIdentifier, keyManager.currentKey); @@ -142,7 +142,7 @@ public void testKeyUpdate() throws Exception { Tasks.waitFor(keyIdentifier, () -> keyManager.currentKey, 20, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); } finally { - keyManager.stopAndWait(); + keyManager.stopAsync().awaitTerminated(); } } diff --git a/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestInMemoryTokenManager.java b/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestInMemoryTokenManager.java index 2c61c976fdbf..edb82072f922 100644 --- a/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestInMemoryTokenManager.java +++ b/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestInMemoryTokenManager.java @@ -36,7 +36,7 @@ protected ImmutablePair> getTokenManagerAndCode Injector injector = Guice.createInjector(new IOModule(), new CoreSecurityRuntimeModule().getStandaloneModules(), new ConfigModule(), new InMemoryDiscoveryModule()); TokenManager tokenManager = injector.getInstance(TokenManager.class); - tokenManager.startAndWait(); + tokenManager.startAsync().awaitRunning(); Codec tokenCodec = injector.getInstance(AccessTokenCodec.class); return new ImmutablePair<>(tokenManager, tokenCodec); } diff --git a/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestTokenManager.java b/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestTokenManager.java index a4a29eb1eb54..9f3e80357d88 100644 --- a/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestTokenManager.java +++ b/cdap-security/src/test/java/io/cdap/cdap/security/auth/TestTokenManager.java @@ -42,7 +42,7 @@ public abstract class TestTokenManager { public void testTokenValidation() throws Exception { ImmutablePair> pair = getTokenManagerAndCodec(); TokenManager tokenManager = pair.getFirst(); - tokenManager.startAndWait(); + tokenManager.startAsync().awaitRunning(); Codec tokenCodec = pair.getSecond(); long now = System.currentTimeMillis(); @@ -91,14 +91,14 @@ public void testTokenValidation() throws Exception { // expected } - tokenManager.stopAndWait(); + tokenManager.stopAsync().awaitTerminated(); } @Test public void testTokenSerialization() throws Exception { ImmutablePair> pair = getTokenManagerAndCodec(); TokenManager tokenManager = pair.getFirst(); - tokenManager.startAndWait(); + tokenManager.startAsync().awaitRunning(); Codec tokenCodec = pair.getSecond(); long now = System.currentTimeMillis(); @@ -116,6 +116,6 @@ public void testTokenSerialization() throws Exception { // should be valid since we just signed it tokenManager.validateSecret(token2); - tokenManager.stopAndWait(); + tokenManager.stopAsync().awaitTerminated(); } } diff --git a/cdap-security/src/test/java/io/cdap/cdap/security/server/ExternalAuthenticationServerTestBase.java b/cdap-security/src/test/java/io/cdap/cdap/security/server/ExternalAuthenticationServerTestBase.java index 9e378e10531c..7fcdbc2a8fa2 100644 --- a/cdap-security/src/test/java/io/cdap/cdap/security/server/ExternalAuthenticationServerTestBase.java +++ b/cdap-security/src/test/java/io/cdap/cdap/security/server/ExternalAuthenticationServerTestBase.java @@ -124,14 +124,14 @@ protected void configure() { startExternalAuthenticationServer(); - server.startAndWait(); + server.startAsync().awaitRunning(); LOG.info("Auth server running on address {}", server.getSocketAddress()); TimeUnit.SECONDS.sleep(3); } protected void tearDown() throws Exception { stopExternalAuthenticationServer(); - server.stopAndWait(); + server.stopAsync().awaitTerminated(); // Clear any security properties for zookeeper. System.clearProperty(Constants.External.Zookeeper.ENV_AUTH_PROVIDER_1); Configuration.setConfiguration(null); diff --git a/cdap-security/src/test/java/io/cdap/cdap/security/store/secretmanager/SecretManagerSecureStoreServiceTest.java b/cdap-security/src/test/java/io/cdap/cdap/security/store/secretmanager/SecretManagerSecureStoreServiceTest.java index b6d2cb829b02..709d7889093a 100644 --- a/cdap-security/src/test/java/io/cdap/cdap/security/store/secretmanager/SecretManagerSecureStoreServiceTest.java +++ b/cdap-security/src/test/java/io/cdap/cdap/security/store/secretmanager/SecretManagerSecureStoreServiceTest.java @@ -48,12 +48,12 @@ public static void setUp() throws Exception { namespaceClient.create(namespaceMeta); secureStoreService = new SecretManagerSecureStoreService(namespaceClient, new MockSecretManagerContext(), "mock", new MockSecretManager()); - secureStoreService.startAndWait(); + secureStoreService.startAsync().awaitRunning(); } @AfterClass public static void cleanUp() { - secureStoreService.stopAndWait(); + secureStoreService.stopAsync().awaitTerminated(); } @Test diff --git a/cdap-security/src/test/java/io/cdap/cdap/security/zookeeper/SharedResourceCacheTest.java b/cdap-security/src/test/java/io/cdap/cdap/security/zookeeper/SharedResourceCacheTest.java index 40fa80649cb4..7e5d2b776b52 100644 --- a/cdap-security/src/test/java/io/cdap/cdap/security/zookeeper/SharedResourceCacheTest.java +++ b/cdap-security/src/test/java/io/cdap/cdap/security/zookeeper/SharedResourceCacheTest.java @@ -84,7 +84,7 @@ public void testCache() throws Exception { // create 2 cache instances ZKClientService zkClient1 = injector1.getInstance(ZKClientService.class); - zkClient1.startAndWait(); + zkClient1.startAsync().awaitRunning(); SharedResourceCache cache1 = new SharedResourceCache<>(zkClient1, new StringCodec(), parentNode, acls); cache1.init(); @@ -95,7 +95,7 @@ public void testCache() throws Exception { cache1.put(key1, value1); ZKClientService zkClient2 = injector2.getInstance(ZKClientService.class); - zkClient2.startAndWait(); + zkClient2.startAsync().awaitRunning(); SharedResourceCache cache2 = new SharedResourceCache<>(zkClient2, new StringCodec(), parentNode, acls); cache2.init(); @@ -194,8 +194,8 @@ private void waitForEntry(SharedResourceCache cache, String key, String String value = cache.get(key); boolean isPresent = expectedValue.equals(value); - Stopwatch watch = new Stopwatch().start(); - while (!isPresent && watch.elapsedTime(TimeUnit.MILLISECONDS) < timeToWaitMillis) { + Stopwatch watch = Stopwatch.createUnstarted().start(); + while (!isPresent && watch.elapsed(TimeUnit.MILLISECONDS) < timeToWaitMillis) { TimeUnit.MILLISECONDS.sleep(200); value = cache.get(key); isPresent = expectedValue.equals(value); From 86899762e647a5d088b5c526fb4501fcce50fe34 Mon Sep 17 00:00:00 2001 From: abhishkkumar Date: Thu, 28 May 2026 04:00:35 +0000 Subject: [PATCH 6/7] upgrading guava version Simplify TxMetricsCollector start/stop methods using direct calls to delegate instead of reflection --- cdap-data-fabric/pom.xml | 7 + .../tephra/metrics/TxMetricsCollector.java | 130 ++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 cdap-data-fabric/src/main/java/org/apache/tephra/metrics/TxMetricsCollector.java diff --git a/cdap-data-fabric/pom.xml b/cdap-data-fabric/pom.xml index 4b05f35282ee..a9e7dbcc7d3b 100644 --- a/cdap-data-fabric/pom.xml +++ b/cdap-data-fabric/pom.xml @@ -31,6 +31,12 @@ jar + + com.google.guava + guava + ${guava.version} + compile + io.cdap.cdap cdap-common @@ -118,6 +124,7 @@ + io.cdap.http netty-http diff --git a/cdap-data-fabric/src/main/java/org/apache/tephra/metrics/TxMetricsCollector.java b/cdap-data-fabric/src/main/java/org/apache/tephra/metrics/TxMetricsCollector.java new file mode 100644 index 000000000000..a2e0d466fcd4 --- /dev/null +++ b/cdap-data-fabric/src/main/java/org/apache/tephra/metrics/TxMetricsCollector.java @@ -0,0 +1,130 @@ +/* + * Copyright © 2026 Cask Data, Inc. + * + * Licensed 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.tephra.metrics; + +import com.google.common.util.concurrent.AbstractIdleService; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.Service; +import java.util.concurrent.Executor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +/** + * Workaround class compiled against Guava 32.0.0-jre to satisfy Tephra TransactionManager. + */ +public class TxMetricsCollector implements MetricsCollector { + + private final Service delegate = new AbstractIdleService() { + @Override + protected void startUp() {} + @Override + protected void shutDown() {} + }; + + public void configure(org.apache.hadoop.conf.Configuration conf) { + // no-op + } + + @Override + public void gauge(String metricName, int value, String... tags) { + // no-op + } + + @Override + public void histogram(String metricName, int value) { + // no-op + } + + @Override + public void rate(String metricName) { + // no-op + } + + @Override + public void rate(String metricName, int count) { + // no-op + } + + public ListenableFuture start() { + delegate.startAsync(); + return Futures.immediateFuture(Service.State.RUNNING); + } + + public ListenableFuture stop() { + delegate.stopAsync(); + return Futures.immediateFuture(Service.State.TERMINATED); + } + + public Service startAsync() { + try { + delegate.getClass().getMethod("startAsync").invoke(delegate); + } catch (Exception e) { + try { + delegate.getClass().getMethod("start").invoke(delegate); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + return this; + } + + public Service stopAsync() { + delegate.stopAsync(); + return this; + } + + @Override + public void awaitRunning() { + delegate.awaitRunning(); + } + + @Override + public void awaitRunning(long timeout, TimeUnit unit) throws TimeoutException { + delegate.awaitRunning(timeout, unit); + } + + @Override + public void awaitTerminated() { + delegate.awaitTerminated(); + } + + @Override + public void awaitTerminated(long timeout, TimeUnit unit) throws TimeoutException { + delegate.awaitTerminated(timeout, unit); + } + + @Override + public Service.State state() { + return delegate.state(); + } + + @Override + public boolean isRunning() { + return delegate.isRunning(); + } + + @Override + public Throwable failureCause() { + return delegate.failureCause(); + } + + @Override + public void addListener(Service.Listener listener, Executor executor) { + delegate.addListener(listener, executor); + } +} From 1ba8e116034ccc56b89a53a3b85076ecc7b27f29 Mon Sep 17 00:00:00 2001 From: abhishkkumar Date: Mon, 8 Jun 2026 22:52:51 +0000 Subject: [PATCH 7/7] new module fixes --- .../java/io/cdap/cdap/StandaloneMain.java | 109 ++++++++---------- .../java/io/cdap/cdap/StandaloneMainTest.java | 10 +- 2 files changed, 56 insertions(+), 63 deletions(-) diff --git a/cdap-standalone/src/main/java/io/cdap/cdap/StandaloneMain.java b/cdap-standalone/src/main/java/io/cdap/cdap/StandaloneMain.java index e2a58907d40c..beb01d56fcae 100644 --- a/cdap-standalone/src/main/java/io/cdap/cdap/StandaloneMain.java +++ b/cdap-standalone/src/main/java/io/cdap/cdap/StandaloneMain.java @@ -17,8 +17,8 @@ package io.cdap.cdap; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Joiner; import com.google.common.base.Throwables; +import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.Service; import com.google.inject.AbstractModule; @@ -248,25 +248,25 @@ public void startUp() throws Exception { ConfigurationLogger.logImportantConfig(cConf); if (messagingService instanceof Service) { - ((Service) messagingService).startAndWait(); + ((Service) messagingService).startAsync().awaitRunning(); } // TODO: CDAP-7688, remove next line after the issue is resolved - injector.getInstance(MessagingHttpService.class).startAndWait(); + injector.getInstance(MessagingHttpService.class).startAsync().awaitRunning(); if (txService != null) { - txService.startAndWait(); + txService.startAsync().awaitRunning(); } // Define all StructuredTable before starting any services that need StructuredTable StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class)); metadataStorage.createIndex(); - metricsCollectionService.startAndWait(); - datasetOpExecutorService.startAndWait(); - datasetService.startAndWait(); - serviceStore.startAndWait(); + metricsCollectionService.startAsync().awaitRunning(); + datasetOpExecutorService.startAsync().awaitRunning(); + datasetService.startAsync().awaitRunning(); + serviceStore.startAsync().awaitRunning(); remoteExecutionTwillRunnerService.start(); - metadataSubscriberService.startAndWait(); + metadataSubscriberService.startAsync().awaitRunning(); // Validate the logging pipeline configuration. // Do it explicitly as Standalone doesn't have a separate master check phase as the distributed does. @@ -275,18 +275,11 @@ public void startUp() throws Exception { // since log appender instantiates a dataset. logAppenderInitializer.initialize(); - runtimeServer.startAndWait(); - Service.State state = appFabricServer.startAndWait(); - if (state != Service.State.RUNNING) { - throw new Exception("Failed to start Application Fabric"); - } - - state = appFabricProcessorService.startAndWait(); - if (state != Service.State.RUNNING) { - throw new Exception("Failed to start Application Fabric Processor"); - } + runtimeServer.startAsync().awaitRunning(); + appFabricServer.startAsync().awaitRunning(); + appFabricProcessorService.startAsync().awaitRunning(); - artifactLocalizerService.startAndWait(); + artifactLocalizerService.startAsync().awaitRunning(); // NOTE: As the artifact localizer client does not use service discovery for port discovery, // We need to set the port after starting the localizer service. cConf.setInt(Constants.ArtifactLocalizer.PORT, artifactLocalizerService.getPort()); @@ -294,27 +287,27 @@ public void startUp() throws Exception { injector.getInstance( Key.get(CConfiguration.class, Names.named(PreviewConfigModule.PREVIEW_CCONF))) .setInt(Constants.ArtifactLocalizer.PORT, artifactLocalizerService.getPort()); - previewHttpServer.startAndWait(); - previewRunnerManager.startAndWait(); + previewHttpServer.startAsync().awaitRunning(); + previewRunnerManager.startAsync().awaitRunning(); - metricsQueryService.startAndWait(); - logQueryService.startAndWait(); - router.startAndWait(); + metricsQueryService.startAsync().awaitRunning(); + logQueryService.startAsync().awaitRunning(); + router.startAsync().awaitRunning(); if (userInterfaceService != null) { - userInterfaceService.startAndWait(); + userInterfaceService.startAsync().awaitRunning(); } if (SecurityUtil.isManagedSecurity(cConf)) { - externalAuthenticationServer.startAndWait(); + externalAuthenticationServer.startAsync().awaitRunning(); } - metadataService.startAndWait(); - operationalStatsService.startAndWait(); - secureStoreService.startAndWait(); - supportBundleInternalService.startAndWait(); - eventPublishManager.startAndWait(); - eventSubscriberManager.startAndWait(); + metadataService.startAsync().awaitRunning(); + operationalStatsService.startAsync().awaitRunning(); + secureStoreService.startAsync().awaitRunning(); + supportBundleInternalService.startAsync().awaitRunning(); + eventPublishManager.startAsync().awaitRunning(); + eventSubscriberManager.startAsync().awaitRunning(); String protocol = sslEnabled ? "https" : "http"; int dashboardPort = sslEnabled @@ -334,52 +327,52 @@ public void shutDown() { try { // order matters: first shut down UI 'cause it will stop working after router is down if (userInterfaceService != null) { - userInterfaceService.stopAndWait(); + userInterfaceService.stopAsync().awaitTerminated(); } // shut down router to stop all incoming traffic - router.stopAndWait(); + router.stopAsync().awaitTerminated(); - secureStoreService.stopAndWait(); - supportBundleInternalService.stopAndWait(); - operationalStatsService.stopAndWait(); + secureStoreService.stopAsync().awaitTerminated(); + supportBundleInternalService.stopAsync().awaitTerminated(); + operationalStatsService.stopAsync().awaitTerminated(); // Stop all services that requires tx service - metadataSubscriberService.stopAndWait(); - metadataService.stopAndWait(); + metadataSubscriberService.stopAsync().awaitTerminated(); + metadataService.stopAsync().awaitTerminated(); remoteExecutionTwillRunnerService.stop(); - serviceStore.stopAndWait(); - previewRunnerManager.stopAndWait(); - previewHttpServer.stopAndWait(); - artifactLocalizerService.stopAndWait(); - eventPublishManager.stopAndWait(); - eventSubscriberManager.stopAndWait(); + serviceStore.stopAsync().awaitTerminated(); + previewRunnerManager.stopAsync().awaitTerminated(); + previewHttpServer.stopAsync().awaitTerminated(); + artifactLocalizerService.stopAsync().awaitTerminated(); + eventPublishManager.stopAsync().awaitTerminated(); + eventSubscriberManager.stopAsync().awaitTerminated(); // app fabric will also stop all programs - appFabricServer.stopAndWait(); - appFabricProcessorService.stopAndWait(); - runtimeServer.stopAndWait(); + appFabricServer.stopAsync().awaitTerminated(); + appFabricProcessorService.stopAsync().awaitTerminated(); + runtimeServer.stopAsync().awaitTerminated(); // all programs are stopped: dataset service, metrics, transactions can stop now - datasetService.stopAndWait(); - datasetOpExecutorService.stopAndWait(); + datasetService.stopAsync().awaitTerminated(); + datasetOpExecutorService.stopAsync().awaitTerminated(); - logQueryService.stopAndWait(); + logQueryService.stopAsync().awaitTerminated(); - metricsCollectionService.stopAndWait(); - metricsQueryService.stopAndWait(); + metricsCollectionService.stopAsync().awaitTerminated(); + metricsQueryService.stopAsync().awaitTerminated(); if (txService != null) { - txService.stopAndWait(); + txService.stopAsync().awaitTerminated(); } if (SecurityUtil.isManagedSecurity(cConf)) { // auth service is on the side anyway - externalAuthenticationServer.stopAndWait(); + externalAuthenticationServer.stopAsync().awaitTerminated(); } // TODO: CDAP-7688, remove next line after the issue is resolved - injector.getInstance(MessagingHttpService.class).startAndWait(); + injector.getInstance(MessagingHttpService.class).stopAsync().awaitTerminated(); if (messagingService instanceof Service) { - ((Service) messagingService).stopAndWait(); + ((Service) messagingService).stopAsync().awaitTerminated(); } logAppenderInitializer.close(); diff --git a/cdap-standalone/src/test/java/io/cdap/cdap/StandaloneMainTest.java b/cdap-standalone/src/test/java/io/cdap/cdap/StandaloneMainTest.java index 320595365b32..79b9134dcad8 100644 --- a/cdap-standalone/src/test/java/io/cdap/cdap/StandaloneMainTest.java +++ b/cdap-standalone/src/test/java/io/cdap/cdap/StandaloneMainTest.java @@ -40,10 +40,10 @@ public void testInjector() { Assert.assertSame(previewRunnerManager, previewRunStopper); TransactionManager txManager = sdk.getInjector().getInstance(TransactionManager.class); - txManager.startAndWait(); - previewHttpServer.startAndWait(); - ((Service) previewRunnerManager).startAndWait(); - ((Service) previewRunnerManager).stopAndWait(); - previewHttpServer.stopAndWait(); + txManager.startAsync().awaitRunning(); + previewHttpServer.startAsync().awaitRunning(); + ((Service) previewRunnerManager).startAsync().awaitRunning(); + ((Service) previewRunnerManager).stopAsync().awaitTerminated(); + previewHttpServer.stopAsync().awaitTerminated(); } }