Skip to content

Commit

Permalink
CDAP-21027 : upgrading hadoop version to 3.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
sahusanket committed Jul 22, 2024
1 parent f05eb25 commit 53a1eaa
Show file tree
Hide file tree
Showing 52 changed files with 372 additions and 1,385 deletions.
6 changes: 0 additions & 6 deletions cdap-app-fabric-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,6 @@ the License.
<artifactId>jcl-over-slf4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cdap.cdap</groupId>
<artifactId>cdap-hbase-compat-1.0</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public void apply() throws IOException {
// run the partition writer m/r with this output partition time
Map<String, String> arguments = new HashMap<>();
arguments.put(OUTPUT_PARTITION_KEY, Long.toString(now));
arguments.put("system.mapreduce.mapreduce.fileoutputcommitter.algorithm.version", "1");
arguments.put(allowConcurrencyKey, Boolean.toString(allowConcurrentWriters));
if (partitionWriteOption != null) {
arguments.put("partitionWriteOption", partitionWriteOption.name());
Expand Down
7 changes: 6 additions & 1 deletion cdap-app-fabric/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<artifactId>powermock-api-mockito2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
Expand All @@ -265,6 +265,11 @@
<artifactId>cdap-event-reader-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>2.2</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.JobContext;
Expand All @@ -81,6 +82,7 @@
public class MapReduceProgramRunner extends AbstractProgramRunnerWithPlugin {

private static final Logger LOG = LoggerFactory.getLogger(MapReduceProgramRunner.class);
public static final String MAPREDUCE_CUSTOM_CONFIG_PREFIX = "system.mapreduce.";

private final Injector injector;
private final CConfiguration cConf;
Expand Down Expand Up @@ -205,6 +207,9 @@ public ProgramController run(final Program program, ProgramOptions options) {
hConf.set(JobContext.QUEUE_NAME, schedulerQueue);
}

hConf = setCustomMapReduceConfig(hConf, options.getArguments());
hConf = setCustomMapReduceConfig(hConf, options.getUserArguments());

ClusterMode clusterMode = ProgramRunners.getClusterMode(options);
Service mapReduceRuntimeService = new MapReduceRuntimeService(injector, cConf, hConf,
mapReduce, spec,
Expand Down Expand Up @@ -241,4 +246,19 @@ private File getPluginArchive(ProgramOptions options) {
}
return new File(options.getArguments().getOption(ProgramOptionConstants.PLUGIN_ARCHIVE));
}

private Configuration setCustomMapReduceConfig(Configuration hConf, Arguments options) {
Map<String, String> systemArgs = options.asMap();
for (String name : systemArgs.keySet()) {
if (!name.startsWith(MAPREDUCE_CUSTOM_CONFIG_PREFIX)) {
continue;
}
String value = systemArgs.get(name);
String key = name.substring(MAPREDUCE_CUSTOM_CONFIG_PREFIX.length());
if (key != null && value != null) {
hConf.set(key, value);
}
}
return hConf;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testSendForPaginatedListResponder() throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

Mockito.doAnswer(invocation -> {
ByteBuffers.writeToStream(invocation.getArgumentAt(0, ByteBuffer.class), byteArrayOutputStream);
ByteBuffers.writeToStream(invocation.getArgument(0, ByteBuffer.class), byteArrayOutputStream);
return null;
}).when(chunkResponder).sendChunk(Mockito.any(ByteBuffer.class));

Expand All @@ -65,7 +65,7 @@ public void testMultipleSendForPaginatedListResponder() throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

Mockito.doAnswer(invocation -> {
ByteBuffers.writeToStream(invocation.getArgumentAt(0, ByteBuffer.class), byteArrayOutputStream);
ByteBuffers.writeToStream(invocation.getArgument(0, ByteBuffer.class), byteArrayOutputStream);
return null;
}).when(chunkResponder).sendChunk(Mockito.any(ByteBuffer.class));

Expand All @@ -91,7 +91,7 @@ public void testSendForWholeListResponder() throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

Mockito.doAnswer(invocation -> {
ByteBuffers.writeToStream(invocation.getArgumentAt(0, ByteBuffer.class), byteArrayOutputStream);
ByteBuffers.writeToStream(invocation.getArgument(0, ByteBuffer.class), byteArrayOutputStream);
return null;
}).when(chunkResponder).sendChunk(Mockito.any(ByteBuffer.class));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,23 @@
import io.cdap.cdap.proto.id.ApplicationId;
import io.cdap.cdap.security.auth.context.AuthenticationTestContext;
import io.cdap.http.NettyHttpService;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Optional;
import org.apache.twill.common.Cancellable;
import org.apache.twill.discovery.InMemoryDiscoveryService;
import org.hamcrest.CoreMatchers;
import org.hamcrest.CustomTypeSafeMatcher;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentMatcher;
import org.mockito.Mockito;

import java.io.IOException;

Check warning on line 51 in cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/RemoteAppStateStoreTest.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck

Extra separation in import group before 'java.io.IOException'

Check warning on line 51 in cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/RemoteAppStateStoreTest.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck

Wrong lexicographical order for 'java.io.IOException' import. Should be before 'org.mockito.Mockito'.
import java.nio.charset.StandardCharsets;

Check warning on line 52 in cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/RemoteAppStateStoreTest.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck

Wrong lexicographical order for 'java.nio.charset.StandardCharsets' import. Should be before 'org.mockito.Mockito'.
import java.util.Base64;

Check warning on line 53 in cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/RemoteAppStateStoreTest.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck

Wrong lexicographical order for 'java.util.Base64' import. Should be before 'org.mockito.Mockito'.
import java.util.Optional;

Check warning on line 54 in cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/RemoteAppStateStoreTest.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck

Wrong lexicographical order for 'java.util.Optional' import. Should be before 'org.mockito.Mockito'.

/**
* Tests for {@link RemoteAppStateStore}
*/
Expand Down Expand Up @@ -103,76 +104,70 @@ private static void setUpMockBehaviorForApplicationLifeCycleService() throws App
//Throw ApplicationNotFoundException when ever NOT_FOUND_APP is used
Mockito.doThrow(new ApplicationNotFoundException(new ApplicationId(NAMESPACE, NOT_FOUND_APP)))
.when(applicationLifecycleService)
.saveState(Mockito.argThat(new AppNameAppStateKeyValueMatcher("NOT_FOUND_APP", NOT_FOUND_APP)));
.saveState(Mockito.argThat(new AppNameAppStateKeyValueMatcher(NOT_FOUND_APP)));
Mockito.doThrow(new ApplicationNotFoundException(new ApplicationId(NAMESPACE, NOT_FOUND_APP)))
.when(applicationLifecycleService)
.getState(Mockito.argThat(new AppNameAppStateKeyMatcher("NOT_FOUND_APP", NOT_FOUND_APP)));
.getState(Mockito.argThat(new AppNameAppStateKeyMatcher(NOT_FOUND_APP)));
Mockito.doThrow(new ApplicationNotFoundException(new ApplicationId(NAMESPACE, NOT_FOUND_APP)))
.when(applicationLifecycleService)
.deleteState(Mockito.argThat(new AppNameAppStateKeyMatcher("NOT_FOUND_APP", NOT_FOUND_APP)));
.deleteState(Mockito.argThat(new AppNameAppStateKeyMatcher( NOT_FOUND_APP)));

Check warning on line 113 in cdap-app-fabric/src/test/java/io/cdap/cdap/internal/app/runtime/RemoteAppStateStoreTest.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.whitespace.ParenPadCheck

'(' is followed by whitespace.

//Throw RuntimeException whenever error app is being used
Mockito.doThrow(new RuntimeException("test")).when(applicationLifecycleService)
.saveState(Mockito.argThat(new AppNameAppStateKeyValueMatcher("ERROR_APP", ERROR_APP)));
.saveState(Mockito.argThat(new AppNameAppStateKeyValueMatcher(ERROR_APP)));
Mockito.doThrow(new RuntimeException("test")).when(applicationLifecycleService)
.getState(Mockito.argThat(new AppNameAppStateKeyMatcher("ERROR_APP", ERROR_APP)));
.getState(Mockito.argThat(new AppNameAppStateKeyMatcher(ERROR_APP)));
Mockito.doThrow(new RuntimeException("test")).when(applicationLifecycleService)
.deleteState(Mockito.argThat(new AppNameAppStateKeyMatcher("ERROR_APP", ERROR_APP)));
.deleteState(Mockito.argThat(new AppNameAppStateKeyMatcher(ERROR_APP)));

String encodedInvalidKey = Base64.getEncoder().encodeToString(MISSING_KEY.getBytes(StandardCharsets.UTF_8));
// Different response for valid and invalid keys
Mockito.when(
applicationLifecycleService.getState(
Mockito.argThat(new CustomTypeSafeMatcher<AppStateKey>("valid key match") {
@Override
protected boolean matchesSafely(AppStateKey item) {
return item.getAppName().equals(SUCCESS_APP) && !item.getStateKey().equals(encodedInvalidKey);
}
})))
applicationLifecycleService.getState(
Mockito.argThat(
item -> item == null ? false :
item.getAppName().equals(SUCCESS_APP) && !item.getStateKey().equals(encodedInvalidKey)
)))
.thenReturn(Optional.of(TEST_VALUE.getBytes(StandardCharsets.UTF_8)));

Mockito.when(
applicationLifecycleService.getState(
Mockito.argThat(new CustomTypeSafeMatcher<AppStateKey>("invalid key match") {
@Override
protected boolean matchesSafely(AppStateKey item) {
return item.getAppName().equals(SUCCESS_APP) && item.getStateKey().equals(encodedInvalidKey);
}
})))
applicationLifecycleService.getState(
Mockito.argThat(
item -> item == null ? false :
item.getAppName().equals(SUCCESS_APP) && item.getStateKey().equals(encodedInvalidKey)
)))
.thenReturn(Optional.empty());
}

/**
* Simple AppStateKeyValue matcher that matches for appname
*/
private static class AppNameAppStateKeyValueMatcher extends CustomTypeSafeMatcher<AppStateKeyValue> {
private static class AppNameAppStateKeyValueMatcher implements ArgumentMatcher<AppStateKeyValue> {
private final String appName;

public AppNameAppStateKeyValueMatcher(String description, String appName) {
super(description);
public AppNameAppStateKeyValueMatcher(String appName) {
this.appName = appName;
}

@Override
protected boolean matchesSafely(AppStateKeyValue item) {
return item.getAppName().equals(appName);
public boolean matches(AppStateKeyValue item) {
return item == null ? false : item.getAppName().equals(appName);
}
}

/**
* Simple AppStateKey matcher that matches for appname
*/
private static class AppNameAppStateKeyMatcher extends CustomTypeSafeMatcher<AppStateKey> {
private static class AppNameAppStateKeyMatcher implements ArgumentMatcher<AppStateKey> {
private final String appName;

public AppNameAppStateKeyMatcher(String description, String appName) {
super(description);
public AppNameAppStateKeyMatcher(String appName) {
this.appName = appName;
}

@Override
protected boolean matchesSafely(AppStateKey item) {
return item.getAppName().equals(appName);
public boolean matches(AppStateKey item) {
return item == null ? false : item.getAppName().equals(appName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ public void testAutoInstallPlugins() throws Exception {
ImmutableSet.of());
Mockito.verify(artifactRepository, Mockito.times(1)).writeArtifactProperties(artifact, properties);
// Verify that temp file was deleted
PowerMockito.verifyStatic();
java.nio.file.Files.deleteIfExists(mockPath);
}

Expand Down
Loading

0 comments on commit 53a1eaa

Please sign in to comment.