diff --git a/cdap-api-common/pom.xml b/cdap-api-common/pom.xml
index 4096488d6697..2ac898352e5b 100644
--- a/cdap-api-common/pom.xml
+++ b/cdap-api-common/pom.xml
@@ -45,4 +45,18 @@
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 17
+ 17
+
+
+
+
+
diff --git a/cdap-api-spark3_2.12/pom.xml b/cdap-api-spark3_2.12/pom.xml
index badbb8132e43..733ea9b56a75 100644
--- a/cdap-api-spark3_2.12/pom.xml
+++ b/cdap-api-spark3_2.12/pom.xml
@@ -187,6 +187,15 @@
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.13.0
+
+ 17
+ 17
+
+
net.alchim31.maven
scala-maven-plugin
diff --git a/cdap-api/pom.xml b/cdap-api/pom.xml
index 26e9a4ab3c03..60c807201e9b 100644
--- a/cdap-api/pom.xml
+++ b/cdap-api/pom.xml
@@ -81,5 +81,16 @@
true
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 17
+ 17
+
+
+
diff --git a/cdap-app-fabric-tests/pom.xml b/cdap-app-fabric-tests/pom.xml
index a258bcb191b0..8fc7a35c28a0 100644
--- a/cdap-app-fabric-tests/pom.xml
+++ b/cdap-app-fabric-tests/pom.xml
@@ -132,6 +132,15 @@ the License.
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.13.0
+
+ 17
+ 17
+
+
org.sonatype.central
diff --git a/cdap-app-fabric/pom.xml b/cdap-app-fabric/pom.xml
index 48b08feacaf0..5bce367b68fe 100644
--- a/cdap-app-fabric/pom.xml
+++ b/cdap-app-fabric/pom.xml
@@ -274,10 +274,18 @@
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 17
+ 17
+
+
org.apache.maven.plugins
maven-jar-plugin
- 2.4
test-jar
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..ed72f70e6a80 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
@@ -124,12 +124,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 +144,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 +163,8 @@ public void stop(ApplicationId preview) throws Exception {
}
PreviewRunnerService newRunnerService = createPreviewRunnerService();
- runnerService.stopAndWait();
- newRunnerService.startAndWait();
+ runnerService.stopAsync().awaitTerminated();
+ newRunnerService.startAsync().awaitRunning();
}
@Override
@@ -237,14 +237,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) {
+ public void terminated(Service.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..e5dc6a329ce8 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
@@ -43,6 +43,7 @@
import io.cdap.cdap.proto.id.ProgramId;
import io.cdap.cdap.proto.id.ProgramRunId;
import java.io.Closeable;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
@@ -472,7 +473,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 (IOException e) {
+ // Ignore
+ }
}
}
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..48e9cc9f0877 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
@@ -189,7 +189,7 @@ public void onSuccess(ProgramController result) {
public void onFailure(Throwable t) {
resultFuture.setException(t);
}
- });
+ }, com.google.common.util.concurrent.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..169e8c68b402 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
@@ -124,7 +124,7 @@ public void initialize(EventHandlerContext context) {
if (clusterMode == ClusterMode.ON_PREMISE) {
zkClientService = injector.getInstance(ZKClientService.class);
- zkClientService.startAndWait();
+ zkClientService.startAsync().awaitRunning();
}
LoggingContextAccessor.setLoggingContext(
@@ -210,9 +210,15 @@ public void aborted() {
@Override
public void destroy() {
- Closeables.closeQuietly(logAppenderInitializer);
+ try {
+ if (logAppenderInitializer != null) {
+ logAppenderInitializer.close();
+ }
+ } catch (Exception e) {
+ // Ignore
+ }
if (zkClientService != null) {
- zkClientService.stop();
+ zkClientService.stopAsync();
}
}
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..6a67f4ba87f6 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;
@@ -326,7 +326,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 +334,7 @@ private void createLogEntry(HttpRequest httpRequest, HttpResponseStatus response
}
private Set extends Permission> getRequestPermissions(AuthorizationRequest request) {
- Set extends Permission> permissions = Objects.firstNonNull(request.getPermissions(),
+ Set extends Permission> 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..e60ff0176028 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,9 @@
package io.cdap.cdap.gateway.handlers;
import com.google.common.base.Preconditions;
-import com.google.common.collect.DiscreteDomains;
+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 +120,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 = com.google.common.collect.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/ProgramScheduleHttpHandler.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/gateway/handlers/ProgramScheduleHttpHandler.java
index cf3028ba0c8e..0c243908077b 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;
@@ -592,13 +592,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 extends Constraint> constraints = Objects.firstNonNull(
+ List extends Constraint> 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/internal/app/deploy/InMemoryProgramRunDispatcher.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/deploy/InMemoryProgramRunDispatcher.java
index 3bbe1bf42171..8c90e2bc8105 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
@@ -297,10 +297,14 @@ 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(),
+ java.nio.charset.StandardCharsets.UTF_8);
+ hasher.putString(artifactDescriptor.getArtifactId().getName(),
+ java.nio.charset.StandardCharsets.UTF_8);
+ hasher.putString(artifactDescriptor.getArtifactId().getScope().name(),
+ java.nio.charset.StandardCharsets.UTF_8);
+ hasher.putString(artifactDescriptor.getArtifactId().getVersion().getVersion(),
+ java.nio.charset.StandardCharsets.UTF_8);
Map arguments = new HashMap<>(options.getArguments().asMap());
arguments.put(ProgramOptionConstants.PROGRAM_JAR_HASH, getArtifactHash(hasher));
@@ -493,7 +497,11 @@ private Runnable createCleanupTask(final Object... resources) {
file.delete();
}
} else if (resource instanceof Closeable) {
- Closeables.closeQuietly((Closeable) resource);
+ try {
+ ((Closeable) resource).close();
+ } catch (IOException e) {
+ // Ignore
+ }
} else if (resource instanceof Runnable) {
((Runnable) resource).run();
}
@@ -558,9 +566,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(), java.nio.charset.StandardCharsets.UTF_8);
+ hasher.putString(artifactId.getArtifact(), java.nio.charset.StandardCharsets.UTF_8);
+ hasher.putString(artifactId.getVersion(), java.nio.charset.StandardCharsets.UTF_8);
}
/**
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..ae1c2e62e1b6 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
@@ -147,6 +147,7 @@ public class DefaultPreviewManager extends AbstractIdleService implements Previe
private final PreviewDataCleanupService previewDataCleanupService;
private final MetricsCollectionService metricsCollectionService;
private final AeadCipher userEncryptionAeadCipher;
+ private boolean metricsCollectionServiceStartedByMe = false;
private Injector previewInjector;
private PreviewDataSubscriberService dataSubscriberService;
private PreviewTMSLogSubscriber logSubscriberService;
@@ -191,7 +192,10 @@ public class DefaultPreviewManager extends AbstractIdleService implements Previe
protected void startUp() throws Exception {
previewInjector = createPreviewInjector();
StoreDefinition.createAllTables(previewInjector.getInstance(StructuredTableAdmin.class));
- metricsCollectionService.start();
+ if (metricsCollectionService.state() == Service.State.NEW) {
+ metricsCollectionService.startAsync();
+ metricsCollectionServiceStartedByMe = true;
+ }
logAppender = previewInjector.getInstance(LogAppender.class);
logAppender.start();
LoggingContextAccessor.setLoggingContext(
@@ -199,10 +203,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
@@ -211,7 +215,9 @@ protected void shutDown() throws Exception {
stopQuietly(dataSubscriberService);
stopQuietly(logSubscriberService);
logAppender.stop();
- stopQuietly(metricsCollectionService);
+ if (metricsCollectionServiceStartedByMe) {
+ stopQuietly(metricsCollectionService);
+ }
previewLevelDBTableService.close();
}
@@ -449,7 +455,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..7c2268777a7c 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
@@ -117,6 +117,14 @@ public class DefaultPreviewRunner extends AbstractIdleService implements Preview
private final Path previewIdDirPath;
private final PreferencesFetcher preferencesFetcher;
private final CConfiguration cConf;
+ private boolean messagingServiceStartedByMe = false;
+ private boolean dsOpExecServiceStartedByMe = false;
+ private boolean datasetServiceStartedByMe = false;
+ private boolean applicationLifecycleServiceStartedByMe = false;
+ private boolean programRuntimeServiceStartedByMe = false;
+ private boolean metricsCollectionServiceStartedByMe = false;
+ private boolean programNotificationSubscriberServiceStartedByMe = false;
+ private boolean programStopSubscriberServiceStartedByMe = false;
@Inject
DefaultPreviewRunner(MessagingService messagingService,
@@ -329,10 +337,20 @@ protected void startUp() throws Exception {
LOG.debug("Starting preview runner service");
StoreDefinition.createAllTables(structuredTableAdmin);
if (messagingService instanceof Service) {
- ((Service) messagingService).startAndWait();
+ Service msgService = (Service) messagingService;
+ if (msgService.state() == Service.State.NEW) {
+ msgService.startAsync().awaitRunning();
+ messagingServiceStartedByMe = true;
+ }
+ }
+ if (dsOpExecService.state() == Service.State.NEW) {
+ dsOpExecService.startAsync().awaitRunning();
+ dsOpExecServiceStartedByMe = true;
+ }
+ if (datasetService.state() == Service.State.NEW) {
+ datasetService.startAsync().awaitRunning();
+ datasetServiceStartedByMe = true;
}
- dsOpExecService.startAndWait();
- datasetService.startAndWait();
// It is recommended to initialize log appender after datasetService is started,
// since log appender instantiates a dataset.
@@ -342,13 +360,44 @@ 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();
+
+ if (applicationLifecycleService.state() == Service.State.NEW) {
+ applicationLifecycleService.startAsync();
+ applicationLifecycleServiceStartedByMe = true;
+ }
+ if (programRuntimeService.state() == Service.State.NEW) {
+ programRuntimeService.startAsync();
+ programRuntimeServiceStartedByMe = true;
+ }
+ if (metricsCollectionService.state() == Service.State.NEW) {
+ metricsCollectionService.startAsync();
+ metricsCollectionServiceStartedByMe = true;
+ }
+ if (programNotificationSubscriberService.state() == Service.State.NEW) {
+ programNotificationSubscriberService.startAsync();
+ programNotificationSubscriberServiceStartedByMe = true;
+ }
+ if (programStopSubscriberService.state() == Service.State.NEW) {
+ programStopSubscriberService.startAsync();
+ programStopSubscriberServiceStartedByMe = true;
+ }
+
+ if (applicationLifecycleServiceStartedByMe || applicationLifecycleService.state() == Service.State.STARTING) {
+ applicationLifecycleService.awaitRunning();
+ }
+ if (programRuntimeServiceStartedByMe || programRuntimeService.state() == Service.State.STARTING) {
+ programRuntimeService.awaitRunning();
+ }
+ if (metricsCollectionServiceStartedByMe || metricsCollectionService.state() == Service.State.STARTING) {
+ metricsCollectionService.awaitRunning();
+ }
+ if (programNotificationSubscriberServiceStartedByMe
+ || programNotificationSubscriberService.state() == Service.State.STARTING) {
+ programNotificationSubscriberService.awaitRunning();
+ }
+ if (programStopSubscriberServiceStartedByMe || programStopSubscriberService.state() == Service.State.STARTING) {
+ programStopSubscriberService.awaitRunning();
+ }
Files.createDirectories(previewIdDirPath);
@@ -375,16 +424,30 @@ protected void startUp() throws Exception {
@Override
protected void shutDown() throws Exception {
LOG.debug("Stopping preview runner service");
- programRuntimeService.stopAndWait();
- applicationLifecycleService.stopAndWait();
+ if (programRuntimeServiceStartedByMe) {
+ programRuntimeService.stopAsync().awaitTerminated();
+ }
+ if (applicationLifecycleServiceStartedByMe) {
+ applicationLifecycleService.stopAsync().awaitTerminated();
+ }
logAppenderInitializer.close();
- metricsCollectionService.stopAndWait();
- programNotificationSubscriberService.stopAndWait();
- programStopSubscriberService.stopAndWait();
- datasetService.stopAndWait();
- dsOpExecService.stopAndWait();
- if (messagingService instanceof Service) {
- ((Service) messagingService).stopAndWait();
+ if (metricsCollectionServiceStartedByMe) {
+ metricsCollectionService.stopAsync().awaitTerminated();
+ }
+ if (programNotificationSubscriberServiceStartedByMe) {
+ programNotificationSubscriberService.stopAsync().awaitTerminated();
+ }
+ if (programStopSubscriberServiceStartedByMe) {
+ programStopSubscriberService.stopAsync().awaitTerminated();
+ }
+ if (datasetServiceStartedByMe) {
+ datasetService.stopAsync().awaitTerminated();
+ }
+ if (dsOpExecServiceStartedByMe) {
+ dsOpExecService.stopAsync().awaitTerminated();
+ }
+ if (messagingServiceStartedByMe && messagingService instanceof Service) {
+ ((Service) messagingService).stopAsync().awaitTerminated();
}
levelDBTableService.close();
}
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..19b88766d83a 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
@@ -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/runtime/AbstractProgramController.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/AbstractProgramController.java
index fd3b1ea2cea7..2fa6ae986965 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.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
+import java.util.Objects;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
@@ -471,7 +471,7 @@ public boolean equals(Object o) {
// Only compare with the listener
ListenerCaller other = (ListenerCaller) o;
- return Objects.equal(listener, other.listener);
+ return Objects.equals(listener, other.listener);
}
@Override
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..79077453c95a 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
@@ -61,7 +61,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 +76,13 @@ public void failed(Service.State from, @Nullable final Throwable failure) {
protected void closeAllQuietly(Iterable closeables) {
for (Closeable c : closeables) {
- Closeables.closeQuietly(c);
+ try {
+ if (c != null) {
+ c.close();
+ }
+ } catch (java.io.IOException e) {
+ // Ignore
+ }
}
}
}
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..bddb258306e3 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
@@ -84,7 +84,7 @@ 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);
+ Resources.asByteSource(url).copyTo(Files.asByteSink(tempFile));
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..588ece9c8384 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
@@ -64,7 +64,7 @@ protected void doStop() throws Exception {
stopRequested = true;
long gracefulTimeoutMillis = getGracefulTimeoutMillis();
if (gracefulTimeoutMillis < 0) {
- service.stopAndWait();
+ service.stopAsync().awaitTerminated();
} else {
gracefulStop(gracefulTimeoutMillis);
}
@@ -77,7 +77,7 @@ protected void doStop() throws Exception {
* supports graceful termination with timeout.
*/
protected void gracefulStop(long gracefulTimeoutMillis) {
- service.stopAndWait();
+ service.stopAsync().awaitTerminated();
}
@Override
@@ -86,7 +86,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..3869296a2b85 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
@@ -78,7 +78,20 @@ public static void startAsUser(String user, final Service service)
runAsUser(user, new Callable>() {
@Override
public ListenableFuture call() throws Exception {
- return service.start();
+ com.google.common.util.concurrent.SettableFuture future =
+ com.google.common.util.concurrent.SettableFuture.create();
+ service.addListener(new Service.Listener() {
+ @Override
+ public void running() {
+ future.set(Service.State.RUNNING);
+ }
+ @Override
+ public void failed(Service.State from, Throwable failure) {
+ future.setException(failure);
+ }
+ }, com.google.common.util.concurrent.MoreExecutors.directExecutor());
+ service.startAsync();
+ return future;
}
});
}
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..871a4c1c3f28 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
@@ -113,8 +113,16 @@ private ClassLoaderCleanup(DirectoryClassLoader directoryClassLoader,
@Override
public void close() throws IOException {
- Closeables.closeQuietly(directoryClassLoader);
- Closeables.closeQuietly(folder);
+ try {
+ directoryClassLoader.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ try {
+ folder.close();
+ } catch (IOException e) {
+ // Ignore
+ }
}
}
}
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..9cd8a58fcad4 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
@@ -33,6 +33,7 @@
import io.cdap.cdap.security.impersonation.EntityImpersonator;
import java.io.Closeable;
import java.io.File;
+import java.io.IOException;
import java.util.Iterator;
import javax.annotation.Nullable;
import org.apache.twill.filesystem.Location;
@@ -104,10 +105,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 (IOException e) {
+ // Ignore
+ }
}
if (finalSparkClassLoader instanceof Closeable) {
- Closeables.closeQuietly((Closeable) finalSparkClassLoader);
+ try {
+ ((Closeable) finalSparkClassLoader).close();
+ } catch (IOException e) {
+ // Ignore
+ }
}
});
}
@@ -130,8 +139,16 @@ CloseableClassLoader createClassLoader(Location artifactLocation,
CloseableClassLoader classLoader = createClassLoader(classLoaderFolder.getDir());
return new CloseableClassLoader(classLoader, () -> {
- Closeables.closeQuietly(classLoader);
- Closeables.closeQuietly(classLoaderFolder);
+ try {
+ classLoader.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ try {
+ classLoaderFolder.close();
+ } catch (IOException e) {
+ // Ignore
+ }
});
} catch (Exception e) {
throw Throwables.propagate(e);
@@ -167,8 +184,16 @@ CloseableClassLoader createClassLoader(Iterator artifactLocations,
entityImpersonator);
return new CloseableClassLoader(new DirectoryClassLoader(classLoaderFolder.getDir(),
parentClassLoader, "lib"), () -> {
- Closeables.closeQuietly(parentClassLoader);
- Closeables.closeQuietly(classLoaderFolder);
+ try {
+ parentClassLoader.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ try {
+ classLoaderFolder.close();
+ } catch (IOException e) {
+ // Ignore
+ }
});
} catch (Exception e) {
throw Throwables.propagate(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..fdac75c5b7e0 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
@@ -624,7 +624,7 @@ private boolean isPlugin(String className, ClassLoader classLoader) {
// Use ASM to inspect the class bytecode to see if it is annotated with @Plugin
final boolean[] isPlugin = new boolean[1];
ClassReader cr = new ClassReader(is);
- cr.accept(new ClassVisitor(Opcodes.ASM7) {
+ cr.accept(new ClassVisitor(Opcodes.ASM9) {
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
if (Plugin.class.getName().equals(Type.getType(desc).getClassName()) && visible) {
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..c022ee45ba3d 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
@@ -153,7 +153,11 @@ public MapReduceTaskContextProvider getTaskContextProvider() {
taskContextProvider = Optional.fromNullable(taskContextProvider)
.or(taskContextProviderSupplier);
}
- taskContextProvider.startAndWait();
+ if (taskContextProvider.state() == Service.State.NEW) {
+ taskContextProvider.startAsync().awaitRunning();
+ } else {
+ taskContextProvider.awaitRunning();
+ }
return taskContextProvider;
}
@@ -196,7 +200,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) {
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..724003ce5d8e 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
@@ -231,7 +231,7 @@ 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);
}
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..31c9256351f4 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
@@ -190,7 +190,7 @@ public void destroy() {
}
@Override
- protected String getServiceName() {
+ protected String serviceName() {
return "MapReduceRunner-" + specification.getName();
}
@@ -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 (java.io.InputStream in = new java.io.FileInputStream(file);
+ java.io.OutputStream out = targetLocation.getOutputStream()) {
+ com.google.common.io.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 (java.io.InputStream in = programJarLocation.getInputStream();
+ java.io.OutputStream out = programJarCopy.getOutputStream()) {
+ com.google.common.io.ByteStreams.copy(in, out);
+ }
LOG.debug("Copied Program Jar to {}, source: {}", programJarCopy, programJarLocation);
return programJarCopy;
}
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..90804b29c31a 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
@@ -91,7 +91,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 +107,12 @@ protected void startUp() throws Exception {
@Override
protected void shutDown() throws Exception {
super.shutDown();
- Closeables.closeQuietly(logAppenderInitializer);
+ logAppenderInitializer.close();
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/distributed/AbstractProgramTwillRunnable.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/AbstractProgramTwillRunnable.java
index 6c48872f7224..20be4f43bde0 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
@@ -96,7 +96,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;
-import sun.net.InetAddressCachePolicy;
/**
* A {@link TwillRunnable} for running a program through a {@link ProgramRunner}.
@@ -173,15 +172,7 @@ private void doInitialize(File programOptionFile) throws Exception {
controllerFuture = new CompletableFuture<>();
programCompletion = new CompletableFuture<>();
- // Make sure InetAddressCachePolicy is not set to FOREVER.
- // This is needed because if InetAddressCachePolicy is loaded after System#setSecurityManager() call,
- // caching policy is set to FOREVER. With FOREVER, caching policy, this twill runnable will not be able to
- // reach out to other services within the cluster as IP is cached forever.
- // Look at CDAP-20781 for more information.
- if (InetAddressCachePolicy.get() == InetAddressCachePolicy.FOREVER) {
- LOG.warn("InetAddress cache policy is set to FOREVER. This will ips to be cached forever. "
- + "Ensure cache policy is not set to FOREVER.");
- }
+
// Setup process wide settings
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
@@ -296,9 +287,19 @@ public void error(Throwable cause) {
LOG.info("Program run {} completed. Releasing resources.", programRunId);
// Close the Program and the ProgramRunner
- Closeables.closeQuietly(program);
+ try {
+ if (program != null) {
+ program.close();
+ }
+ } catch (Exception e) {
+ // Ignore
+ }
if (programRunner instanceof Closeable) {
- Closeables.closeQuietly((Closeable) programRunner);
+ try {
+ ((Closeable) programRunner).close();
+ } catch (java.io.IOException e) {
+ // Ignore
+ }
}
stopCoreServices();
@@ -483,16 +484,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 {
+ if (logAppenderInitializer != null) {
+ logAppenderInitializer.close();
+ }
+ } catch (Exception e) {
+ // Ignore
+ }
// 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/DistributedWorkflowProgramRunner.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/distributed/DistributedWorkflowProgramRunner.java
index b3822eb518c5..e1a3c56ab5d5 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
@@ -169,7 +169,11 @@ protected void setupLaunchConfig(ProgramLaunchConfig launchConfig, Program progr
}
} finally {
if (runner instanceof Closeable) {
- Closeables.closeQuietly((Closeable) runner);
+ try {
+ ((Closeable) runner).close();
+ } catch (IOException e) {
+ // Ignore
+ }
}
}
}
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..52d419a00413 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 com.google.common.base.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..b6f2ac22a80c 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, java.nio.charset.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(), java.nio.charset.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;
@@ -674,8 +674,9 @@ private void saveClassPaths(Path targetDir) throws IOException {
}
private void saveArguments(Arguments arguments, final Path targetPath) throws IOException {
- ArgumentsCodec.encode(arguments,
- () -> Files.newBufferedWriter(targetPath, StandardCharsets.UTF_8));
+ try (Writer writer = Files.newBufferedWriter(targetPath, StandardCharsets.UTF_8)) {
+ ArgumentsCodec.encode(arguments, writer);
+ }
}
/**
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..a762bce005a7 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;
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..14c5cbf97b84 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
@@ -88,7 +88,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 +113,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..81e1e4d76473 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
@@ -250,7 +250,8 @@ 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(),
+ java.nio.charset.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..b0b1a01bb9fc 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
@@ -217,7 +217,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 +389,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 +428,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 +549,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 +751,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..46979d77f0f3 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
@@ -61,13 +61,25 @@ protected void doRunTask() throws Exception {
if (sshSession != null && sshSession.isAlive()) {
return;
}
- Closeables.closeQuietly(sshSession);
+ try {
+ if (sshSession != null) {
+ sshSession.close();
+ }
+ } catch (Exception e) {
+ // Ignore
+ }
sshSession = createServiceProxyTunnel();
}
@Override
protected void doShutdown() {
- Closeables.closeQuietly(sshSession);
+ try {
+ if (sshSession != null) {
+ sshSession.close();
+ }
+ } catch (Exception e) {
+ // Ignore
+ }
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..33df437a6730 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
@@ -291,7 +291,11 @@ public void run(RuntimeJobEnvironment runtimeJobEnv) throws Exception {
programCompletion.get();
} finally {
if (programRunner instanceof Closeable) {
- Closeables.closeQuietly((Closeable) programRunner);
+ try {
+ ((Closeable) programRunner).close();
+ } catch (IOException e) {
+ // Ignore
+ }
}
}
} catch (Throwable t) {
@@ -527,7 +531,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 +544,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 +628,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 +725,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 +736,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..b6a618d791b3 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
@@ -305,13 +305,13 @@ public ByteBuf nextChunk() throws Exception {
@Override
public void finished() {
- Closeables.closeQuietly(responseInfo);
+ responseInfo.close();
}
@Override
public void handleError(@Nullable Throwable cause) {
LOG.warn("Exception raised when handling request to {}", url, cause);
- Closeables.closeQuietly(responseInfo);
+ responseInfo.close();
}
}
}
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..d3a6950f824e 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
@@ -227,7 +227,11 @@ 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 (IOException e) {
+ // Ignore
+ }
try {
location.delete();
} catch (IOException 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..9e06cacb5aca 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
@@ -517,7 +517,13 @@ 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 {
+ if (parentClassLoader instanceof Closeable) {
+ ((Closeable) parentClassLoader).close();
+ }
+ } catch (IOException e) {
+ // Ignore
+ }
}
try {
DirUtils.deleteDirectoryContents(tmpDir);
@@ -618,7 +624,13 @@ private static final class ClassLoaderRemovalListener implements
@Override
public void onRemoval(RemovalNotification notification) {
- Closeables.closeQuietly(notification.getValue());
+ try {
+ if (notification.getValue() != null) {
+ notification.getValue().close();
+ }
+ } catch (IOException e) {
+ // Ignore
+ }
}
}
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/queue/JobKey.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/schedule/queue/JobKey.java
index 7267b32df0d6..ba9f6e973cda 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,8 +16,9 @@
package io.cdap.cdap.internal.app.runtime.schedule.queue;
-import com.google.common.base.Objects;
+import com.google.common.base.MoreObjects;
import io.cdap.cdap.proto.id.ScheduleId;
+import java.util.Objects;
/**
* Uniquely identifies a Job.
@@ -57,18 +58,18 @@ public boolean equals(Object o) {
JobKey that = (JobKey) o;
- return Objects.equal(this.scheduleId, that.scheduleId)
- && Objects.equal(this.generationId, that.generationId);
+ return Objects.equals(this.scheduleId, that.scheduleId)
+ && Objects.equals(this.generationId, that.generationId);
}
@Override
public int hashCode() {
- return Objects.hashCode(scheduleId, generationId);
+ return Objects.hash(scheduleId, generationId);
}
@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..66c29165ac9b 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
@@ -425,9 +425,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(), java.nio.charset.StandardCharsets.UTF_8)
+ .putString(scheduleId.getApplication(), java.nio.charset.StandardCharsets.UTF_8)
+ .putString(scheduleId.getSchedule(), java.nio.charset.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..15665babc376 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,8 +16,9 @@
package io.cdap.cdap.internal.app.runtime.schedule.queue;
-import com.google.common.base.Objects;
+import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
+import java.util.Objects;
import io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule;
import io.cdap.cdap.proto.Notification;
import java.util.List;
@@ -97,25 +98,25 @@ public boolean equals(Object o) {
SimpleJob that = (SimpleJob) o;
- return Objects.equal(this.schedule, that.schedule)
- && Objects.equal(this.creationTime, that.creationTime)
- && Objects.equal(this.jobKey, that.jobKey)
- && Objects.equal(this.notifications, that.notifications)
- && Objects.equal(this.state, that.state)
- && Objects.equal(this.scheduleLastUpdatedTime, that.scheduleLastUpdatedTime)
- && Objects.equal(this.deleteTimeMillis, that.deleteTimeMillis);
+ return Objects.equals(this.schedule, that.schedule)
+ && Objects.equals(this.creationTime, that.creationTime)
+ && Objects.equals(this.jobKey, that.jobKey)
+ && Objects.equals(this.notifications, that.notifications)
+ && Objects.equals(this.state, that.state)
+ && Objects.equals(this.scheduleLastUpdatedTime, that.scheduleLastUpdatedTime)
+ && Objects.equals(this.deleteTimeMillis, that.deleteTimeMillis);
}
@Override
public int hashCode() {
- return Objects.hashCode(schedule, creationTime, jobKey, notifications, state,
+ return Objects.hash(schedule, creationTime, jobKey, notifications, state,
scheduleLastUpdatedTime,
deleteTimeMillis);
}
@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/service/ServiceProgramRunner.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/runtime/service/ServiceProgramRunner.java
index 5f8dbf0a7ffb..32dd6062e136 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
@@ -195,10 +195,14 @@ 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 (java.io.IOException e) {
+ // Ignore to avoid masking original exception
+ }
throw t;
}
}
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..22b5b16d4589 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
@@ -111,7 +111,7 @@ public void validateHttpHandler(Iterable handlers) {
createHttpHandler(type, new VerificationDelegateContext<>(handler), metricsContext));
} catch (Exception e) {
throw new IllegalArgumentException(
- "Invalid http handler class " + handler.getClass().getName());
+ "Invalid http handler class " + handler.getClass().getName(), 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..057631a90a12 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
@@ -150,7 +150,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, java.nio.charset.StandardCharsets.UTF_8);
// Generate the class
Type classType = Type.getObjectType(className);
@@ -196,7 +196,7 @@ private void inspectHandler(final TypeToken> delegateType, final TypeToken>
.getResourceAsStream(Type.getInternalName(rawType) + ".class")
) {
ClassReader classReader = new ClassReader(sourceBytes);
- classReader.accept(new ClassVisitor(Opcodes.ASM5) {
+ classReader.accept(new ClassVisitor(Opcodes.ASM9) {
// Only need to visit @Path at the class level if we are inspecting the user handler class
private final boolean inspectDelegate = delegateType.equals(inspectType);
@@ -215,7 +215,7 @@ public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
if (inspectDelegate && type.equals(Type.getType(Path.class))) {
visitedPath = true;
AnnotationVisitor annotationVisitor = classWriter.visitAnnotation(desc, visible);
- return new AnnotationVisitor(Opcodes.ASM5, annotationVisitor) {
+ return new AnnotationVisitor(Opcodes.ASM9, annotationVisitor) {
@Override
public void visit(String name, Object value) {
// "value" is the key for the Path annotation string.
@@ -374,7 +374,7 @@ private class HandlerMethodVisitor extends MethodVisitor {
HandlerMethodVisitor(TypeToken> delegateType, MethodVisitor mv, String desc,
String signature, int access, String name, String[] exceptions,
Type classType, ClassWriter classWriter, List> preservedClasses) {
- super(Opcodes.ASM5, mv);
+ super(Opcodes.ASM9, mv);
this.delegateType = delegateType;
this.desc = desc;
this.signature = signature;
@@ -392,7 +392,7 @@ private class HandlerMethodVisitor extends MethodVisitor {
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
// Memorize all visible annotations
if (visible) {
- AnnotationNode annotationNode = new AnnotationNode(Opcodes.ASM5, desc);
+ AnnotationNode annotationNode = new AnnotationNode(Opcodes.ASM9, desc);
annotations.add(annotationNode);
return annotationNode;
}
@@ -404,7 +404,7 @@ public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, bo
// Memorize all visible annotations for each parameter.
// It needs to store in a Multimap because there can be multiple annotations per parameter.
if (visible) {
- AnnotationNode annotationNode = new AnnotationNode(Opcodes.ASM5, desc);
+ AnnotationNode annotationNode = new AnnotationNode(Opcodes.ASM9, desc);
paramAnnotations.put(parameter, annotationNode);
return annotationNode;
}
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..fdb4ebd740f9 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
@@ -82,7 +82,11 @@ public void onFinish() throws Exception {
@Override
@TransactionPolicy(TransactionControl.EXPLICIT)
public void onError(Throwable failureCause) {
- Closeables.closeQuietly(input);
+ try {
+ input.close();
+ } catch (IOException e) {
+ // Ignore
+ }
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..86facfee0dc6 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
@@ -160,10 +160,14 @@ 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 (java.io.IOException e) {
+ // Ignore
+ }
throw t;
}
}
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..e05f1cb32117 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
@@ -166,7 +166,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 (IOException e) {
+ // Ignore
+ }
throw t;
}
blockForCompletion(closeable, controller);
@@ -210,7 +214,11 @@ public void init(ProgramController.State currentState, @Nullable Throwable cause
@Override
public void completed() {
- Closeables.closeQuietly(closeable);
+ try {
+ closeable.close();
+ } catch (IOException e) {
+ // Ignore
+ }
Set fieldLineageOperations = new HashSet<>();
if (controller instanceof WorkflowDataProvider) {
fieldLineageOperations.addAll(
@@ -224,7 +232,11 @@ public void completed() {
@Override
public void killed() {
- Closeables.closeQuietly(closeable);
+ try {
+ closeable.close();
+ } catch (IOException e) {
+ // Ignore
+ }
nodeStates.put(nodeId,
new WorkflowNodeState(nodeId, NodeStatus.KILLED, controller.getRunId().getId(), null));
completion.set(null);
@@ -232,7 +244,11 @@ public void killed() {
@Override
public void error(Throwable cause) {
- Closeables.closeQuietly(closeable);
+ try {
+ closeable.close();
+ } catch (IOException e) {
+ // Ignore
+ }
nodeStates.put(nodeId,
new WorkflowNodeState(nodeId, NodeStatus.FAILED, controller.getRunId().getId(), cause));
completion.setException(cause);
@@ -271,7 +287,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 (IOException e) {
+ // Ignore
+ }
closeProgramRunner(programRunner);
}
};
@@ -282,7 +302,11 @@ public void close() throws IOException {
*/
private void closeProgramRunner(ProgramRunner programRunner) {
if (programRunner instanceof Closeable) {
- Closeables.closeQuietly((Closeable) programRunner);
+ try {
+ ((Closeable) programRunner).close();
+ } catch (IOException e) {
+ // Ignore
+ }
}
}
}
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..c06db96effd5 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
@@ -54,7 +54,7 @@ protected void doResume() throws Exception {
@Override
protected void doStop() throws Exception {
- driver.stopAndWait();
+ driver.stopAsync().awaitTerminated();
}
@Override
@@ -64,7 +64,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..c115f5d2cfcd 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
@@ -153,7 +153,7 @@ 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);
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..968625801c4d 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
@@ -20,6 +20,7 @@
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.State;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.cdap.cdap.api.feature.FeatureFlagsProvider;
@@ -86,6 +87,19 @@ public class AppFabricProcessorService extends AbstractIdleService {
private CommonNettyHttpServiceFactory commonNettyHttpServiceFactory;
private Cancellable cancelHttpService;
private Set handlers;
+ private boolean auditLogSubscriberServiceStartedByMe = false;
+ private boolean provisioningServiceStartedByMe = false;
+ private boolean applicationLifecycleServiceStartedByMe = false;
+ private boolean bootstrapServiceStartedByMe = false;
+ private boolean programRuntimeServiceStartedByMe = false;
+ private boolean programNotificationSubscriberServiceStartedByMe = false;
+ private boolean programStopSubscriberServiceStartedByMe = false;
+ private boolean runRecordCorrectorServiceStartedByMe = false;
+ private boolean programRunStatusMonitorServiceStartedByMe = false;
+ private boolean coreSchedulerServiceStartedByMe = false;
+ private boolean runRecordCounterServiceStartedByMe = false;
+ private boolean runDataTimeToLiveServiceStartedByMe = false;
+ private boolean operationNotificationSubscriberServiceStartedByMe = false;
/**
* Construct the AppFabricProcessorService with service factory and cConf coming from guice injection.
@@ -146,29 +160,108 @@ 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());
- }
-
- 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();
+ boolean auditLoggingEnabled = Feature.DATAPLANE_AUDIT_LOGGING.isEnabled(featureFlagsProvider)
+ && cConf.getBoolean(Constants.Security.ENABLED);
+
+ if (auditLoggingEnabled && auditLogSubscriberService.state() == State.NEW) {
+ auditLogSubscriberService.startAsync();
+ auditLogSubscriberServiceStartedByMe = true;
+ }
+
+ if (provisioningService.state() == State.NEW) {
+ provisioningService.startAsync();
+ provisioningServiceStartedByMe = true;
+ }
+ if (applicationLifecycleService.state() == State.NEW) {
+ applicationLifecycleService.startAsync();
+ applicationLifecycleServiceStartedByMe = true;
+ }
+ if (bootstrapService.state() == State.NEW) {
+ bootstrapService.startAsync();
+ bootstrapServiceStartedByMe = true;
+ }
+ if (programRuntimeService.state() == State.NEW) {
+ programRuntimeService.startAsync();
+ programRuntimeServiceStartedByMe = true;
+ }
+ if (programNotificationSubscriberService.state() == State.NEW) {
+ programNotificationSubscriberService.startAsync();
+ programNotificationSubscriberServiceStartedByMe = true;
+ }
+ if (programStopSubscriberService.state() == State.NEW) {
+ programStopSubscriberService.startAsync();
+ programStopSubscriberServiceStartedByMe = true;
+ }
+ if (runRecordCorrectorService.state() == State.NEW) {
+ runRecordCorrectorService.startAsync();
+ runRecordCorrectorServiceStartedByMe = true;
+ }
+ if (programRunStatusMonitorService.state() == State.NEW) {
+ programRunStatusMonitorService.startAsync();
+ programRunStatusMonitorServiceStartedByMe = true;
+ }
+ if (coreSchedulerService.state() == State.NEW) {
+ coreSchedulerService.startAsync();
+ coreSchedulerServiceStartedByMe = true;
+ }
+ if (runRecordCounterService.state() == State.NEW) {
+ runRecordCounterService.startAsync();
+ runRecordCounterServiceStartedByMe = true;
+ }
+ if (runDataTimeToLiveService.state() == State.NEW) {
+ runDataTimeToLiveService.startAsync();
+ runDataTimeToLiveServiceStartedByMe = true;
+ }
+ if (operationNotificationSubscriberService.state() == State.NEW) {
+ operationNotificationSubscriberService.startAsync();
+ operationNotificationSubscriberServiceStartedByMe = true;
+ }
+
+ if (auditLoggingEnabled
+ && (auditLogSubscriberServiceStartedByMe
+ || auditLogSubscriberService.state() == State.STARTING)) {
+ auditLogSubscriberService.awaitRunning();
+ }
+ if (provisioningServiceStartedByMe || provisioningService.state() == State.STARTING) {
+ provisioningService.awaitRunning();
+ }
+ if (applicationLifecycleServiceStartedByMe || applicationLifecycleService.state() == State.STARTING) {
+ applicationLifecycleService.awaitRunning();
+ }
+ if (bootstrapServiceStartedByMe || bootstrapService.state() == State.STARTING) {
+ bootstrapService.awaitRunning();
+ }
+ if (programRuntimeServiceStartedByMe || programRuntimeService.state() == State.STARTING) {
+ programRuntimeService.awaitRunning();
+ }
+ if (programNotificationSubscriberServiceStartedByMe
+ || programNotificationSubscriberService.state() == State.STARTING) {
+ programNotificationSubscriberService.awaitRunning();
+ }
+ if (programStopSubscriberServiceStartedByMe || programStopSubscriberService.state() == State.STARTING) {
+ programStopSubscriberService.awaitRunning();
+ }
+ if (runRecordCorrectorServiceStartedByMe || runRecordCorrectorService.state() == State.STARTING) {
+ runRecordCorrectorService.awaitRunning();
+ }
+ if (programRunStatusMonitorServiceStartedByMe
+ || programRunStatusMonitorService.state() == State.STARTING) {
+ programRunStatusMonitorService.awaitRunning();
+ }
+ if (coreSchedulerServiceStartedByMe || coreSchedulerService.state() == State.STARTING) {
+ coreSchedulerService.awaitRunning();
+ }
+ if (runRecordCounterServiceStartedByMe || runRecordCounterService.state() == State.STARTING) {
+ runRecordCounterService.awaitRunning();
+ }
+ if (runDataTimeToLiveServiceStartedByMe || runDataTimeToLiveService.state() == State.STARTING) {
+ runDataTimeToLiveService.awaitRunning();
+ }
+ if (operationNotificationSubscriberServiceStartedByMe
+ || operationNotificationSubscriberService.state() == State.STARTING) {
+ operationNotificationSubscriberService.awaitRunning();
+ }
// Run http service on random port
NettyHttpService.Builder httpServiceBuilder = commonNettyHttpServiceFactory
@@ -196,20 +289,46 @@ 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();
+ if (coreSchedulerServiceStartedByMe) {
+ coreSchedulerService.stopAsync().awaitTerminated();
+ }
+ if (bootstrapServiceStartedByMe) {
+ bootstrapService.stopAsync().awaitTerminated();
+ }
+ systemAppManagementService.stopAsync().awaitTerminated();
+ if (programRuntimeServiceStartedByMe) {
+ programRuntimeService.stopAsync().awaitTerminated();
+ }
+ if (applicationLifecycleServiceStartedByMe) {
+ applicationLifecycleService.stopAsync().awaitTerminated();
+ }
+ if (programNotificationSubscriberServiceStartedByMe) {
+ programNotificationSubscriberService.stopAsync().awaitTerminated();
+ }
+ if (programStopSubscriberServiceStartedByMe) {
+ programStopSubscriberService.stopAsync().awaitTerminated();
+ }
+ if (runRecordCorrectorServiceStartedByMe) {
+ runRecordCorrectorService.stopAsync().awaitTerminated();
+ }
+ if (programRunStatusMonitorServiceStartedByMe) {
+ programRunStatusMonitorService.stopAsync().awaitTerminated();
+ }
+ if (provisioningServiceStartedByMe) {
+ provisioningService.stopAsync().awaitTerminated();
+ }
+ if (runRecordCounterServiceStartedByMe) {
+ runRecordCounterService.stopAsync().awaitTerminated();
+ }
+ if (runDataTimeToLiveServiceStartedByMe) {
+ runDataTimeToLiveService.stopAsync().awaitTerminated();
+ }
+ if (operationNotificationSubscriberServiceStartedByMe) {
+ operationNotificationSubscriberService.stopAsync().awaitTerminated();
+ }
+ if (auditLogSubscriberServiceStartedByMe) {
+ 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..ac00679a16f5 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
@@ -20,6 +20,7 @@
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.name.Named;
import io.cdap.cdap.api.feature.FeatureFlagsProvider;
@@ -92,6 +93,13 @@ public class AppFabricServer extends AbstractIdleService {
private Set handlers;
private MetricsCollectionService metricsCollectionService;
private CommonNettyHttpServiceFactory commonNettyHttpServiceFactory;
+ private boolean namespaceCredentialProviderServiceStartedByMe = false;
+ private boolean provisioningServiceStartedByMe = false;
+ private boolean applicationLifecycleServiceStartedByMe = false;
+ private boolean bootstrapServiceStartedByMe = false;
+ private boolean credentialProviderServiceStartedByMe = false;
+ private boolean sourceControlOperationRunnerStartedByMe = false;
+ private boolean repositoryCleanupServiceStartedByMe = false;
/**
* Construct the AppFabricServer with service factory and cConf coming from guice
@@ -143,20 +151,62 @@ 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());
+ boolean namespacedServiceAccountsEnabled = Feature.NAMESPACED_SERVICE_ACCOUNTS.isEnabled(featureFlagsProvider);
+
+ if (namespacedServiceAccountsEnabled && namespaceCredentialProviderService.state() == Service.State.NEW) {
+ namespaceCredentialProviderService.startAsync();
+ namespaceCredentialProviderServiceStartedByMe = true;
+ }
+
+ if (provisioningService.state() == Service.State.NEW) {
+ provisioningService.startAsync();
+ provisioningServiceStartedByMe = true;
+ }
+ if (applicationLifecycleService.state() == Service.State.NEW) {
+ applicationLifecycleService.startAsync();
+ applicationLifecycleServiceStartedByMe = true;
+ }
+ if (bootstrapService.state() == Service.State.NEW) {
+ bootstrapService.startAsync();
+ bootstrapServiceStartedByMe = true;
+ }
+ if (credentialProviderService.state() == Service.State.NEW) {
+ credentialProviderService.startAsync();
+ credentialProviderServiceStartedByMe = true;
+ }
+ if (sourceControlOperationRunner.state() == Service.State.NEW) {
+ sourceControlOperationRunner.startAsync();
+ sourceControlOperationRunnerStartedByMe = true;
+ }
+ if (repositoryCleanupService.state() == Service.State.NEW) {
+ repositoryCleanupService.startAsync();
+ repositoryCleanupServiceStartedByMe = true;
+ }
+
+ if (namespacedServiceAccountsEnabled
+ && (namespaceCredentialProviderServiceStartedByMe
+ || namespaceCredentialProviderService.state() == Service.State.STARTING)) {
+ namespaceCredentialProviderService.awaitRunning();
+ }
+ if (provisioningServiceStartedByMe || provisioningService.state() == Service.State.STARTING) {
+ provisioningService.awaitRunning();
+ }
+ if (applicationLifecycleServiceStartedByMe || applicationLifecycleService.state() == Service.State.STARTING) {
+ applicationLifecycleService.awaitRunning();
+ }
+ if (bootstrapServiceStartedByMe || bootstrapService.state() == Service.State.STARTING) {
+ bootstrapService.awaitRunning();
+ }
+ if (credentialProviderServiceStartedByMe || credentialProviderService.state() == Service.State.STARTING) {
+ credentialProviderService.awaitRunning();
+ }
+ if (sourceControlOperationRunnerStartedByMe || sourceControlOperationRunner.state() == Service.State.STARTING) {
+ sourceControlOperationRunner.awaitRunning();
+ }
+ if (repositoryCleanupServiceStartedByMe || repositoryCleanupService.state() == Service.State.STARTING) {
+ repositoryCleanupService.awaitRunning();
}
- futuresList.addAll(ImmutableList.of(
- provisioningService.start(),
- applicationLifecycleService.start(),
- bootstrapService.start(),
- credentialProviderService.start(),
- sourceControlOperationRunner.start(),
- repositoryCleanupService.start()
- ));
- Futures.allAsList(futuresList).get();
// Create handler hooks
List handlerHooks = handlerHookNames.stream()
@@ -212,13 +262,27 @@ 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();
+ if (applicationLifecycleServiceStartedByMe) {
+ applicationLifecycleService.stopAsync().awaitTerminated();
+ }
+ if (bootstrapServiceStartedByMe) {
+ bootstrapService.stopAsync().awaitTerminated();
+ }
+ if (provisioningServiceStartedByMe) {
+ provisioningService.stopAsync().awaitTerminated();
+ }
+ if (sourceControlOperationRunnerStartedByMe) {
+ sourceControlOperationRunner.stopAsync().awaitTerminated();
+ }
+ if (repositoryCleanupServiceStartedByMe) {
+ repositoryCleanupService.stopAsync().awaitTerminated();
+ }
+ if (credentialProviderServiceStartedByMe) {
+ credentialProviderService.stopAsync().awaitTerminated();
+ }
+ if (namespaceCredentialProviderServiceStartedByMe) {
+ 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/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/ApplicationMeta.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/ApplicationMeta.java
index 1db650299aeb..cc71ad2e7777 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,8 +16,9 @@
package io.cdap.cdap.internal.app.store;
-import com.google.common.base.Objects;
+import com.google.common.base.MoreObjects;
import io.cdap.cdap.api.app.ApplicationSpecification;
+import java.util.Objects;
import io.cdap.cdap.internal.app.ApplicationSpecificationAdapter;
import io.cdap.cdap.proto.artifact.ChangeDetail;
import io.cdap.cdap.proto.sourcecontrol.SourceControlMeta;
@@ -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)
@@ -86,14 +87,14 @@ public boolean equals(Object o) {
return false;
}
ApplicationMeta that = (ApplicationMeta) o;
- return Objects.equal(id, that.id)
- && Objects.equal(spec, that.spec)
- && Objects.equal(change, that.change)
- && Objects.equal(sourceControlMeta, that.sourceControlMeta);
+ return Objects.equals(id, that.id)
+ && Objects.equals(spec, that.spec)
+ && Objects.equals(change, that.change)
+ && Objects.equals(sourceControlMeta, that.sourceControlMeta);
}
@Override
public int hashCode() {
- return Objects.hashCode(id, spec, change, sourceControlMeta);
+ return Objects.hash(id, spec, change, sourceControlMeta);
}
}
diff --git a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/DefaultStore.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/DefaultStore.java
index 57fb3c102cef..b88798bc4146 100644
--- a/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/DefaultStore.java
+++ b/cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/store/DefaultStore.java
@@ -19,7 +19,6 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
import com.google.common.collect.MapDifference;
import com.google.common.collect.Maps;
import com.google.inject.Inject;
@@ -638,7 +637,7 @@ public List getDeletedProgramSpecifications(ApplicationRef
return getAppMetadataStore(context).getLatest(appRef);
});
- List deletedProgramSpecs = Lists.newArrayList();
+ List deletedProgramSpecs = new ArrayList<>();
if (existing != null) {
ApplicationSpecification existingAppSpec = existing.getSpec();
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..3a938dd0159a 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,7 +16,8 @@
package io.cdap.cdap.internal.app.store.adapters;
-import com.google.common.base.Objects;
+import com.google.common.base.MoreObjects;
+import java.util.Objects;
/**
* Unique key for identifying a plugin. Used for look up and caching.
@@ -106,13 +107,13 @@ public boolean equals(Object o) {
return false;
}
PluginKey pluginKey = (PluginKey) o;
- return Objects.equal(parentName, pluginKey.parentName)
- && Objects.equal(parentNamespace, pluginKey.parentNamespace)
- && Objects.equal(artifactName, pluginKey.artifactName)
- && Objects.equal(artifactNamespace, pluginKey.artifactNamespace)
- && Objects.equal(artifactVersion, pluginKey.artifactVersion)
- && Objects.equal(pluginType, pluginKey.pluginType)
- && Objects.equal(pluginName, pluginKey.pluginName);
+ return Objects.equals(parentName, pluginKey.parentName)
+ && Objects.equals(parentNamespace, pluginKey.parentNamespace)
+ && Objects.equals(artifactName, pluginKey.artifactName)
+ && Objects.equals(artifactNamespace, pluginKey.artifactNamespace)
+ && Objects.equals(artifactVersion, pluginKey.artifactVersion)
+ && Objects.equals(pluginType, pluginKey.pluginType)
+ && Objects.equals(pluginName, pluginKey.pluginName);
}
/**
@@ -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)
@@ -136,7 +137,7 @@ public String toString() {
*/
@Override
public int hashCode() {
- return Objects.hashCode(parentName, parentNamespace, artifactName, artifactNamespace,
+ return Objects.hash(parentName, parentNamespace, artifactName, artifactNamespace,
artifactVersion, pluginType, pluginName);
}
}
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..c3a22e98526f 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
@@ -126,7 +126,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..191649f9df77 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
@@ -147,7 +147,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 +160,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 +173,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(Service::stopAsync);
if (taskWorker != null) {
- taskWorker.stop();
+ taskWorker.stopAsync();
}
}
@@ -203,7 +203,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..a77ae345f806 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
@@ -167,7 +167,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 +180,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 +191,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 +225,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..d576b2c46c6e 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
@@ -106,7 +106,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 +121,7 @@ protected void startUp() throws Exception {
@Override
protected void shutDown() throws Exception {
LOG.debug("Shutting down SystemWorkerService");
- tokenManager.stop();
+ tokenManager.stopAsync().awaitTerminated();
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..79a4a763f394 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
@@ -273,7 +273,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 +286,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 +302,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(Service::stopAsync);
if (systemWorker != null) {
- systemWorker.stop();
+ systemWorker.stopAsync();
}
if (artifactLocalizerService != null) {
- artifactLocalizerService.stop();
+ artifactLocalizerService.stopAsync();
}
}
@@ -342,7 +342,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..f8ed0d4903da 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
@@ -180,7 +180,11 @@ public boolean onReceived(ByteBuffer buffer) {
@Override
public void onFinished() {
- Closeables.closeQuietly(channel);
+ try {
+ channel.close();
+ } catch (IOException e) {
+ // Ignore
+ }
}
}).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..e618f9c9e0b7 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
@@ -52,7 +52,7 @@ public class InMemoryOperationController implements
@Override
public ListenableFuture stop() {
LOG.trace("Stopping operation {}", runId);
- driver.stop();
+ driver.stopAsync();
return completionFuture;
}
@@ -62,7 +62,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/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/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..77c06c130c68 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
@@ -159,7 +159,9 @@ public static void doMain(String[] args) throws Exception {
runnable.stop();
Uninterruptibles.awaitUninterruptibly(shutdownLatch, 30, TimeUnit.SECONDS);
}
- Optional.ofNullable(tokenManager).ifPresent(TokenManager::stopAndWait);
+ if (tokenManager != null) {
+ tokenManager.stopAsync().awaitTerminated();
+ }
}));
runnable.run(runnableArgs);
completed.set(true);
@@ -192,7 +194,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/scheduler/ConstraintCheckerService.java b/cdap-app-fabric/src/main/java/io/cdap/cdap/scheduler/ConstraintCheckerService.java
index e6f12fcbff06..c801a7d88d8f 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.createStarted();
// limit the batches of the scan to 1000ms
- while (!stopping && stopWatch.elapsedMillis() < 1000) {
+ while (!stopping && stopWatch.elapsed(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..6c6b1a8b8f3b 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
@@ -115,25 +115,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 java.util.concurrent.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 +203,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
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..8c34573a04c3 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,7 +16,7 @@
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;
@@ -153,13 +153,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 +167,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 extends Constraint> 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..8c3e83aeee8b 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
@@ -96,23 +96,25 @@ 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();
+ for (Service service : subscriberServices) {
+ service.startAsync();
+ }
+ for (Service service : subscriberServices) {
+ service.awaitRunning();
+ }
}
@Override
protected void shutDown() throws Exception {
- // This never throw
- Futures.successfulAsList(
- subscriberServices.stream().map(Service::stop).collect(Collectors.toList())).get();
+ for (Service service : subscriberServices) {
+ 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.
try {
- service.stop().get();
- } catch (ExecutionException e) {
- LOG.warn("Exception raised when stopping service {}", service, e.getCause());
+ service.awaitTerminated();
+ } catch (IllegalStateException e) {
+ LOG.warn("Exception raised when stopping service {}", service, e);
}
}
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..4af6fd301d46 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
@@ -65,7 +65,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(),
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..5772ef4ef8f0 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();
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 +86,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/AppFabricTestHelper.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/AppFabricTestHelper.java
index 778af9f0d967..07f6388a7090 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,7 @@
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 +213,18 @@ 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 {
+ if (metadataStorage != null) {
+ metadataStorage.close();
+ }
+ } catch (Exception e) {
+ // ignore
+ }
if (services != null) {
- Lists.reverse(services).forEach(Service::stopAndWait);
+ for (Service service : Lists.reverse(services)) {
+ service.stopAsync().awaitTerminated();
+ }
}
InMemoryTableService.reset();
@@ -276,7 +284,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/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/MapReduceProgramRunnerTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/MapReduceProgramRunnerTest.java
index d4ee727b2b5c..b2c077e03faf 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
@@ -324,9 +324,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 (java.io.BufferedReader reader = new java.io.BufferedReader(
+ new java.io.InputStreamReader(resultLocation.getInputStream(), Charsets.UTF_8))) {
+ line = reader.readLine();
+ }
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..a17da83c0be9 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
@@ -120,7 +120,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 +128,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/MapReduceWithMultipleInputsTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/batch/dataset/input/MapReduceWithMultipleInputsTest.java
index a28a67b501fe..ec747ac7517e 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
@@ -80,8 +80,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 (java.io.BufferedReader reader = new java.io.BufferedReader(
+ new java.io.InputStreamReader(outputLocation.getInputStream(), 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..72becff8460a 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
@@ -70,7 +70,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 (java.io.BufferedReader reader = new java.io.BufferedReader(
+ new java.io.InputStreamReader(location.getInputStream(), 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..5cada649de7b 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
@@ -198,11 +198,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 +244,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 +253,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 +270,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 +327,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 +435,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,11 +483,23 @@ 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();
+ com.google.common.util.concurrent.SettableFuture stopFuture =
+ com.google.common.util.concurrent.SettableFuture.create();
+ runtimeClientService.addListener(new Service.Listener() {
+ @Override
+ public void terminated(Service.State from) {
+ stopFuture.set(Service.State.TERMINATED);
+ }
+ @Override
+ public void failed(Service.State from, Throwable failure) {
+ stopFuture.setException(failure);
+ }
+ }, com.google.common.util.concurrent.MoreExecutors.directExecutor());
+ runtimeClientService.stopAsync();
try {
stopFuture.get(2, TimeUnit.SECONDS);
Assert.fail("Expected runtime client service not stopped");
@@ -507,7 +519,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,7 +539,19 @@ public void testExternalStop() throws Exception {
messagePublisher.publish(NamespaceId.SYSTEM.getNamespace(), topic,
"msg1" + topic, "msg2" + topic);
- ListenableFuture stopFuture = runtimeClientService.stop();
+ com.google.common.util.concurrent.SettableFuture stopFuture =
+ com.google.common.util.concurrent.SettableFuture.create();
+ runtimeClientService.addListener(new Service.Listener() {
+ @Override
+ public void terminated(Service.State from) {
+ stopFuture.set(Service.State.TERMINATED);
+ }
+ @Override
+ public void failed(Service.State from, Throwable failure) {
+ stopFuture.setException(failure);
+ }
+ }, com.google.common.util.concurrent.MoreExecutors.directExecutor());
+ runtimeClientService.stopAsync();
try {
stopFuture.get(2, TimeUnit.SECONDS);
Assert.fail("Expected runtime client service not stopped");
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..201a79dd5554 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,8 +269,8 @@ public String getName() {
@Override
public Credential getCredentials() {
- String credentialValue = Base64.getEncoder().encodeToString(Hashing.md5().hashString(programRunId.toString())
- .asBytes());
+ 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..4f36f6c2be03 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
@@ -275,7 +275,11 @@ public void onFinish(HttpServiceResponder responder) throws Exception {
@Override
public void onError(HttpServiceResponder responder, Throwable failureCause) {
validateTransaction();
- Closeables.closeQuietly(channel);
+ try {
+ channel.close();
+ } catch (IOException e) {
+ // ignore
+ }
LOG.error("Failed when handling upload", failureCause);
}
@@ -481,7 +485,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 +512,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 +566,7 @@ 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());
+ urlConn.getOutputStream().write("Hello".getBytes(Charsets.UTF_8));
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..e4c369096fd4 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
@@ -119,12 +119,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/services/AppFabricProcessorServiceTest.java b/cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/services/AppFabricProcessorServiceTest.java
index a147f710fff3..c18779e3ad0a 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
@@ -29,10 +29,12 @@ public void startStopService() {
try {
Injector injector = AppFabricTestHelper.getInjector();
AppFabricProcessorService service = injector.getInstance(AppFabricProcessorService.class);
- Service.State state = service.startAndWait();
+ service.startAsync().awaitRunning();
+ Service.State state = service.state();
Assert.assertSame(state, Service.State.RUNNING);
- state = service.stopAndWait();
+ service.stopAsync().awaitTerminated();
+ state = service.state();
Assert.assertSame(state, Service.State.TERMINATED);
} 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..e12d21fb1171 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
@@ -49,14 +49,16 @@ public void startStopServer() throws Exception {
try {
AppFabricServer server = injector.getInstance(AppFabricServer.class);
DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
- Service.State state = server.startAndWait();
+ server.startAsync().awaitRunning();
+ Service.State state = server.state();
Assert.assertSame(state, Service.State.RUNNING);
final EndpointStrategy endpointStrategy = new RandomEndpointStrategy(
() -> discoveryServiceClient.discover(Constants.Service.APP_FABRIC_HTTP));
Assert.assertNotNull(endpointStrategy.pick(5, TimeUnit.SECONDS));
- state = server.stopAndWait();
+ server.stopAsync().awaitTerminated();
+ state = server.state();
Assert.assertSame(state, Service.State.TERMINATED);
Tasks.waitFor(true, () -> endpointStrategy.pick() == null, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
@@ -74,7 +76,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 +93,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..8ca905a5fc0f 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,6 @@
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 com.google.common.util.concurrent.Service;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -67,6 +65,7 @@
import io.cdap.cdap.common.internal.remote.RemoteClientFactory;
import io.cdap.cdap.common.io.CaseInsensitiveEnumTypeAdapterFactory;
import io.cdap.cdap.common.io.Locations;
+import io.cdap.cdap.common.lang.ThrowingSupplier;
import io.cdap.cdap.common.service.Retries;
import io.cdap.cdap.common.test.AppJarHelper;
import io.cdap.cdap.common.test.PluginJarHelper;
@@ -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 {
+ if (metadataStorage != null) {
+ metadataStorage.close();
+ }
+ } catch (Exception e) {
+ // ignore
}
- Closeables.closeQuietly(metadataStorage);
}
protected static CConfiguration createBasicCconf() throws IOException {
@@ -502,7 +507,8 @@ protected HttpResponse addPluginArtifact(Id.Artifact artifactId, Class> cls,
}
// add an artifact and return the response code
- protected HttpResponse addArtifact(Id.Artifact artifactId, InputSupplier extends InputStream> artifactContents,
+ protected HttpResponse addArtifact(Id.Artifact artifactId,
+ ThrowingSupplier extends InputStream, IOException> artifactContents,
Set parents) throws Exception {
return addArtifact(artifactId, artifactContents, parents, null);
}
@@ -510,7 +516,8 @@ protected HttpResponse addArtifact(Id.Artifact artifactId, InputSupplier exten
/**
* This method accepts GSON serialized form of plugin classes for testing purpose.
*/
- private HttpResponse addArtifact(Id.Artifact artifactId, InputSupplier extends InputStream> artifactContents,
+ private HttpResponse addArtifact(Id.Artifact artifactId,
+ ThrowingSupplier extends InputStream, IOException> artifactContents,
Set parents, @Nullable String pluginClassesJson)
throws Exception {
String path = getVersionedApiPath("artifacts/" + artifactId.getName(), artifactId.getNamespace().getId());
@@ -527,7 +534,12 @@ private HttpResponse addArtifact(Id.Artifact artifactId, InputSupplier extends
if (pluginClassesJson != null) {
builder.addHeader("Artifact-Plugins", pluginClassesJson);
}
- builder.withBody(artifactContents);
+ builder.withBody(new io.cdap.common.ContentProvider() {
+ @Override
+ public InputStream getInput() throws IOException {
+ return artifactContents.get();
+ }
+ });
return HttpRequests.execute(builder.build(), httpRequestConfig);
}
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..1ca1535adfb8 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,7 @@
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 +38,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..8706babe9bf6 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
@@ -100,7 +100,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
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..809b8f5625b6 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,7 @@
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 +98,11 @@ protected void configure() {
@AfterClass
public static void afterClass() {
- Closeables.closeQuietly(postgres);
+ try {
+ postgres.close();
+ } catch (java.io.IOException e) {
+ // ignore
+ }
}
@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..4696ca7ee42a 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,7 @@
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 +99,11 @@ protected void configure() {
@AfterClass
public static void afterClass() {
- Closeables.closeQuietly(pg);
+ try {
+ pg.close();
+ } catch (IOException e) {
+ // ignore
+ }
}
@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..9008d929117f 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,7 @@
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 +71,10 @@ protected void configure() {
@AfterClass
public static void afterClass() {
- Closeables.closeQuietly(pg);
+ try {
+ pg.close();
+ } catch (IOException e) {
+ // ignore
+ }
}
}
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..bb77d435e885 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,8 @@ 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();
+ Assert.assertEquals(Service.State.RUNNING, tetheringEventPublisher.state());
tetheringAgentService = new TetheringAgentService(cConf,
tetheringStore,
injector.getInstance(ProgramStateWriter.class),
@@ -268,14 +269,17 @@ 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();
+ Assert.assertEquals(Service.State.RUNNING, tetheringAgentService.state());
}
@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();
+ Assert.assertEquals(Service.State.TERMINATED, tetheringEventPublisher.state());
+ tetheringAgentService.stopAsync().awaitTerminated();
+ Assert.assertEquals(Service.State.TERMINATED, tetheringAgentService.state());
}
@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/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..065d9f0b774b 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,7 @@
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 +94,11 @@ protected void configure() {
@AfterClass
public static void afterClass() {
- Closeables.closeQuietly(pg);
+ try {
+ pg.close();
+ } catch (IOException e) {
+ // ignore
+ }
}
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..29b46c16e7cb 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
@@ -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 out = remoteFile.getOutputStream()) {
+ Files.copy(localFile, out);
+ }
return remoteFile;
}
diff --git a/cdap-app-templates/cdap-etl/cdap-data-pipeline-base/src/main/java/io/cdap/cdap/datapipeline/DataPipelineApp.java b/cdap-app-templates/cdap-etl/cdap-data-pipeline-base/src/main/java/io/cdap/cdap/datapipeline/DataPipelineApp.java
index 1023c65b9911..ed55713d82ba 100644
--- a/cdap-app-templates/cdap-etl/cdap-data-pipeline-base/src/main/java/io/cdap/cdap/datapipeline/DataPipelineApp.java
+++ b/cdap-app-templates/cdap-etl/cdap-data-pipeline-base/src/main/java/io/cdap/cdap/datapipeline/DataPipelineApp.java
@@ -16,7 +16,7 @@
package io.cdap.cdap.datapipeline;
-import com.google.common.base.Objects;
+import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
import io.cdap.cdap.api.app.AbstractApplication;
import io.cdap.cdap.api.app.ApplicationUpdateContext;
@@ -64,7 +64,7 @@ public void configure() {
return;
}
- setDescription(Objects.firstNonNull(config.getDescription(), DEFAULT_DESCRIPTION));
+ setDescription(MoreObjects.firstNonNull(config.getDescription(), DEFAULT_DESCRIPTION));
addWorkflow(new SmartWorkflow(config, supportedPluginTypes, getConfigurer()));
String timeSchedule = config.getSchedule();
diff --git a/cdap-app-templates/cdap-etl/cdap-data-pipeline-base/src/test/java/io/cdap/cdap/datapipeline/preview/PreviewDataPipelineTest.java b/cdap-app-templates/cdap-etl/cdap-data-pipeline-base/src/test/java/io/cdap/cdap/datapipeline/preview/PreviewDataPipelineTest.java
index b8459bb632b2..6e056f3aa6a6 100644
--- a/cdap-app-templates/cdap-etl/cdap-data-pipeline-base/src/test/java/io/cdap/cdap/datapipeline/preview/PreviewDataPipelineTest.java
+++ b/cdap-app-templates/cdap-etl/cdap-data-pipeline-base/src/test/java/io/cdap/cdap/datapipeline/preview/PreviewDataPipelineTest.java
@@ -673,8 +673,8 @@ private void validateMetric(long expected, ApplicationId previewId,
// Min sleep time is 10ms, max sleep time is 1 seconds
long sleepMillis = TimeUnit.SECONDS.toMillis(1);
- Stopwatch stopwatch = new Stopwatch().start();
- while (value < expected && stopwatch.elapsedTime(TimeUnit.SECONDS) < 20) {
+ Stopwatch stopwatch = Stopwatch.createStarted();
+ while (value < expected && stopwatch.elapsed(TimeUnit.SECONDS) < 20) {
TimeUnit.MILLISECONDS.sleep(sleepMillis);
value = getTotalMetric(tags, metricName, previewManager);
}
diff --git a/cdap-app-templates/cdap-etl/cdap-data-pipeline3_2.12/pom.xml b/cdap-app-templates/cdap-etl/cdap-data-pipeline3_2.12/pom.xml
index 651f2c4c1e59..862abaf589ff 100644
--- a/cdap-app-templates/cdap-etl/cdap-data-pipeline3_2.12/pom.xml
+++ b/cdap-app-templates/cdap-etl/cdap-data-pipeline3_2.12/pom.xml
@@ -66,6 +66,12 @@
${project.version}
provided
+
+ io.cdap.cdap
+ cdap-common
+ ${project.version}
+ provided
+
io.cdap.cdap
cdap-system-app-api
@@ -197,6 +203,15 @@
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.13.0
+
+ 17
+ 17
+
+
net.alchim31.maven
scala-maven-plugin
diff --git a/cdap-app-templates/cdap-etl/cdap-data-streams-base/src/main/java/io/cdap/cdap/datastreams/DataStreamsApp.java b/cdap-app-templates/cdap-etl/cdap-data-streams-base/src/main/java/io/cdap/cdap/datastreams/DataStreamsApp.java
index 5e75c36d7239..9a971e8116af 100644
--- a/cdap-app-templates/cdap-etl/cdap-data-streams-base/src/main/java/io/cdap/cdap/datastreams/DataStreamsApp.java
+++ b/cdap-app-templates/cdap-etl/cdap-data-streams-base/src/main/java/io/cdap/cdap/datastreams/DataStreamsApp.java
@@ -16,7 +16,7 @@
package io.cdap.cdap.datastreams;
-import com.google.common.base.Objects;
+import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
import io.cdap.cdap.api.app.AbstractApplication;
import io.cdap.cdap.api.app.ApplicationUpdateContext;
@@ -36,7 +36,7 @@ public class DataStreamsApp extends AbstractApplication {
@Override
public void configure() {
DataStreamsConfig config = getConfig();
- setDescription(Objects.firstNonNull(config.getDescription(), "Data Streams Application"));
+ setDescription(MoreObjects.firstNonNull(config.getDescription(), "Data Streams Application"));
DataStreamsPipelineSpec spec;
try {
diff --git a/cdap-app-templates/cdap-etl/cdap-data-streams-base/src/test/java/io/cdap/cdap/datastreams/preview/PreviewDataStreamsTest.java b/cdap-app-templates/cdap-etl/cdap-data-streams-base/src/test/java/io/cdap/cdap/datastreams/preview/PreviewDataStreamsTest.java
index bc264400752a..1ddb6f60afc5 100644
--- a/cdap-app-templates/cdap-etl/cdap-data-streams-base/src/test/java/io/cdap/cdap/datastreams/preview/PreviewDataStreamsTest.java
+++ b/cdap-app-templates/cdap-etl/cdap-data-streams-base/src/test/java/io/cdap/cdap/datastreams/preview/PreviewDataStreamsTest.java
@@ -178,8 +178,8 @@ private void validateMetric(long expected, ApplicationId previewId,
// Min sleep time is 10ms, max sleep time is 1 seconds
long sleepMillis = TimeUnit.SECONDS.toMillis(1);
- Stopwatch stopwatch = new Stopwatch().start();
- while (value < expected && stopwatch.elapsedTime(TimeUnit.SECONDS) < 5) {
+ Stopwatch stopwatch = Stopwatch.createStarted();
+ while (value < expected && stopwatch.elapsed(TimeUnit.SECONDS) < 5) {
TimeUnit.MILLISECONDS.sleep(sleepMillis);
value = getTotalMetric(tags, metricName, previewManager);
}
diff --git a/cdap-app-templates/cdap-etl/cdap-data-streams3_2.12/pom.xml b/cdap-app-templates/cdap-etl/cdap-data-streams3_2.12/pom.xml
index e95bde1b5d24..55567fdf18a8 100644
--- a/cdap-app-templates/cdap-etl/cdap-data-streams3_2.12/pom.xml
+++ b/cdap-app-templates/cdap-etl/cdap-data-streams3_2.12/pom.xml
@@ -153,6 +153,15 @@
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.13.0
+
+ 17
+ 17
+
+
org.apache.maven.plugins
diff --git a/cdap-app-templates/cdap-etl/cdap-etl-api-spark/pom.xml b/cdap-app-templates/cdap-etl/cdap-etl-api-spark/pom.xml
index c683ff6c0cfb..8c7c48196c5e 100644
--- a/cdap-app-templates/cdap-etl/cdap-etl-api-spark/pom.xml
+++ b/cdap-app-templates/cdap-etl/cdap-etl-api-spark/pom.xml
@@ -67,6 +67,15 @@
scala-maven-plugin
3.3.1
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.13.0
+
+ 17
+ 17
+
+
diff --git a/cdap-app-templates/cdap-etl/cdap-etl-api/pom.xml b/cdap-app-templates/cdap-etl/cdap-etl-api/pom.xml
index 3315643ef3b2..b6fa94b24c0f 100644
--- a/cdap-app-templates/cdap-etl/cdap-etl-api/pom.xml
+++ b/cdap-app-templates/cdap-etl/cdap-etl-api/pom.xml
@@ -43,4 +43,18 @@
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 17
+ 17
+
+
+
+
+
diff --git a/cdap-app-templates/cdap-etl/cdap-etl-batch/pom.xml b/cdap-app-templates/cdap-etl/cdap-etl-batch/pom.xml
index e9c300b786be..950c3463a090 100644
--- a/cdap-app-templates/cdap-etl/cdap-etl-batch/pom.xml
+++ b/cdap-app-templates/cdap-etl/cdap-etl-batch/pom.xml
@@ -141,6 +141,15 @@
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.13.0
+
+ 17
+ 17
+
+
net.alchim31.maven
scala-maven-plugin
diff --git a/cdap-app-templates/cdap-etl/cdap-etl-core/pom.xml b/cdap-app-templates/cdap-etl/cdap-etl-core/pom.xml
index 32df33d4b7ae..186756edc16c 100644
--- a/cdap-app-templates/cdap-etl/cdap-etl-core/pom.xml
+++ b/cdap-app-templates/cdap-etl/cdap-etl-core/pom.xml
@@ -79,5 +79,16 @@
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 17
+ 17
+
+
+
diff --git a/cdap-app-templates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/common/AbstractServiceRetryableMacroEvaluator.java b/cdap-app-templates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/common/AbstractServiceRetryableMacroEvaluator.java
index 684d62972945..4d6265985403 100644
--- a/cdap-app-templates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/common/AbstractServiceRetryableMacroEvaluator.java
+++ b/cdap-app-templates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/common/AbstractServiceRetryableMacroEvaluator.java
@@ -80,11 +80,11 @@ public String evaluate(String macroFunction, String... args) throws InvalidMacro
RETRY_DELAY_MULTIPLIER - RETRY_DELAY_MULTIPLIER * RETRY_RANDOMIZE_FACTOR;
double maxMultiplier =
RETRY_DELAY_MULTIPLIER + RETRY_DELAY_MULTIPLIER * RETRY_RANDOMIZE_FACTOR;
- Stopwatch stopWatch = new Stopwatch().start();
+ Stopwatch stopWatch = Stopwatch.createStarted();
int retryCount = 0;
RetryableException retryableException = null;
try {
- while (stopWatch.elapsedTime(TimeUnit.MILLISECONDS) < TIMEOUT_MILLIS) {
+ while (stopWatch.elapsed(TimeUnit.MILLISECONDS) < TIMEOUT_MILLIS) {
try {
retryCount++;
return evaluateMacro(macroFunction, args);
@@ -150,9 +150,9 @@ public Map evaluateMap(String macroFunction, String... args)
double minMultiplier = RETRY_DELAY_MULTIPLIER - RETRY_DELAY_MULTIPLIER * RETRY_RANDOMIZE_FACTOR;
double maxMultiplier = RETRY_DELAY_MULTIPLIER + RETRY_DELAY_MULTIPLIER * RETRY_RANDOMIZE_FACTOR;
Exception ex = null;
- Stopwatch stopWatch = new Stopwatch().start();
+ Stopwatch stopWatch = Stopwatch.createStarted();
try {
- while (stopWatch.elapsedTime(TimeUnit.MILLISECONDS) < TIMEOUT_MILLIS) {
+ while (stopWatch.elapsed(TimeUnit.MILLISECONDS) < TIMEOUT_MILLIS) {
try {
return evaluateMacroMap(macroFunction, args);
} catch (RetryableException e) {
diff --git a/cdap-app-templates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/common/PipelineTypeValidator.java b/cdap-app-templates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/common/PipelineTypeValidator.java
index e7b2d352ac35..3eea2f08fbc5 100644
--- a/cdap-app-templates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/common/PipelineTypeValidator.java
+++ b/cdap-app-templates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/common/PipelineTypeValidator.java
@@ -90,7 +90,7 @@ static void validateTypes(List unresTypeList) {
Type firstType = resTypeList.get(i);
Type secondType = resTypeList.get(i + 1);
// Check if secondType can accept firstType
- Preconditions.checkArgument(TypeToken.of(secondType).isAssignableFrom(firstType),
+ Preconditions.checkArgument(TypeToken.of(secondType).isSupertypeOf(TypeToken.of(firstType)),
"Types between stages didn't match. Mismatch between %s -> %s",
firstType, secondType);
}
diff --git a/cdap-app-templates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/common/plugin/MetricsOperationTimer.java b/cdap-app-templates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/common/plugin/MetricsOperationTimer.java
index 54be3ab4c73d..018761b563f4 100644
--- a/cdap-app-templates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/common/plugin/MetricsOperationTimer.java
+++ b/cdap-app-templates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/common/plugin/MetricsOperationTimer.java
@@ -36,7 +36,7 @@ public class MetricsOperationTimer implements OperationTimer {
public MetricsOperationTimer(StageMetrics stageMetrics) {
this.stageMetrics = stageMetrics;
- this.stopwatch = new Stopwatch();
+ this.stopwatch = Stopwatch.createUnstarted();
}
/**
@@ -65,7 +65,7 @@ public void stop() {
*/
@Override
public void reset() {
- emitTimeMetrics(stopwatch.elapsedTime(TimeUnit.MICROSECONDS));
+ emitTimeMetrics(stopwatch.elapsed(TimeUnit.MICROSECONDS));
stopwatch.reset();
}
diff --git a/cdap-app-templates/cdap-etl/cdap-etl-proto/pom.xml b/cdap-app-templates/cdap-etl/cdap-etl-proto/pom.xml
index 1b85b5075989..1156791038ef 100644
--- a/cdap-app-templates/cdap-etl/cdap-etl-proto/pom.xml
+++ b/cdap-app-templates/cdap-etl/cdap-etl-proto/pom.xml
@@ -58,4 +58,18 @@
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 17
+ 17
+
+
+
+
+
diff --git a/cdap-app-templates/cdap-etl/cdap-etl-tools/pom.xml b/cdap-app-templates/cdap-etl/cdap-etl-tools/pom.xml
index ff695b69d2ae..6b47b33fee03 100644
--- a/cdap-app-templates/cdap-etl/cdap-etl-tools/pom.xml
+++ b/cdap-app-templates/cdap-etl/cdap-etl-tools/pom.xml
@@ -70,9 +70,18 @@
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.13.0
+
+ 17
+ 17
+
+
maven-shade-plugin
- 3.2.1
+ 3.5.2
etl-tools-fat-jar
diff --git a/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/batch/BatchSQLEngineAdapter.java b/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/batch/BatchSQLEngineAdapter.java
index 6349970d4f79..8182e78dcf11 100644
--- a/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/batch/BatchSQLEngineAdapter.java
+++ b/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/batch/BatchSQLEngineAdapter.java
@@ -16,7 +16,7 @@
package io.cdap.cdap.etl.spark.batch;
-import com.google.common.base.Objects;
+import com.google.common.base.MoreObjects;
import io.cdap.cdap.api.SQLEngineContext;
import io.cdap.cdap.api.data.format.StructuredRecord;
import io.cdap.cdap.api.data.schema.Schema;
@@ -344,7 +344,7 @@ private BatchCollectionFactory pullInternal(SQLDataset dataset) throws SQ
SQLPullDataset sqlPullDataset = sqlEngine.getPullProvider(pullRequest);
// Run operation to read from the InputFormatProvider supplied by this operation.
- ClassLoader classLoader = Objects.firstNonNull(Thread.currentThread().getContextClassLoader(),
+ ClassLoader classLoader = MoreObjects.firstNonNull(Thread.currentThread().getContextClassLoader(),
getClass().getClassLoader());
JavaPairRDD pairRDD = RDDUtils.readUsingInputFormat(jsc, sqlPullDataset, classLoader, Object.class,
Object.class);
diff --git a/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/batch/DatasetInfoTypeAdapter.java b/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/batch/DatasetInfoTypeAdapter.java
index 9b70578c3bec..3499786de6ef 100644
--- a/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/batch/DatasetInfoTypeAdapter.java
+++ b/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/batch/DatasetInfoTypeAdapter.java
@@ -16,7 +16,7 @@
package io.cdap.cdap.etl.spark.batch;
-import com.google.common.base.Objects;
+import com.google.common.base.MoreObjects;
import com.google.common.reflect.TypeParameter;
import com.google.common.reflect.TypeToken;
import com.google.gson.JsonDeserializationContext;
@@ -48,7 +48,7 @@ public DatasetInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializati
return new DatasetInfo(datasetName, datasetArgs, null);
}
String datasetSplitClass = obj.get("datasetSplitClass").getAsString();
- ClassLoader classLoader = Objects.firstNonNull(Thread.currentThread().getContextClassLoader(),
+ ClassLoader classLoader = MoreObjects.firstNonNull(Thread.currentThread().getContextClassLoader(),
SparkBatchSourceFactory.class.getClassLoader());
try {
Class> splitClass = classLoader.loadClass(datasetSplitClass);
diff --git a/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/batch/SparkBatchSourceFactory.java b/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/batch/SparkBatchSourceFactory.java
index e3b14bc18d59..b24e468af84f 100644
--- a/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/batch/SparkBatchSourceFactory.java
+++ b/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/batch/SparkBatchSourceFactory.java
@@ -16,7 +16,7 @@
package io.cdap.cdap.etl.spark.batch;
-import com.google.common.base.Objects;
+import com.google.common.base.MoreObjects;
import io.cdap.cdap.api.data.batch.Input;
import io.cdap.cdap.api.data.batch.InputFormatProvider;
import io.cdap.cdap.api.data.batch.Split;
@@ -157,7 +157,7 @@ private JavaPairRDD createInputRDD(JavaSparkExecutionContext sec, J
if (inputFormatProviders.containsKey(inputName)) {
InputFormatProvider inputFormatProvider = inputFormatProviders.get(inputName);
- ClassLoader classLoader = Objects.firstNonNull(currentThread().getContextClassLoader(),
+ ClassLoader classLoader = MoreObjects.firstNonNull(currentThread().getContextClassLoader(),
getClass().getClassLoader());
return RDDUtils.readUsingInputFormat(jsc, inputFormatProvider, classLoader, keyClass,
diff --git a/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/function/AlertPassFilter.java b/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/function/AlertPassFilter.java
index 43dc7cba941d..410e275ba9c1 100644
--- a/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/function/AlertPassFilter.java
+++ b/cdap-app-templates/cdap-etl/hydrator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/function/AlertPassFilter.java
@@ -33,6 +33,6 @@ public class AlertPassFilter implements FlatMapFunction, Aler
public Iterator call(RecordInfo