List of usage examples for org.apache.hadoop.yarn.api.records ApplicationId newInstance
@Public @Unstable public static ApplicationId newInstance(long clusterTimestamp, int id)
From source file:org.apache.tez.runtime.library.cartesianproduct.TestCartesianProductVertexManagerPartitioned.java
License:Apache License
@Test(timeout = 5000) public void testVertexStartWithCompletion() throws Exception { CartesianProductConfig config = new CartesianProductConfig(new int[] { 2, 2 }, new String[] { "v0", "v1" }, null);/*from www.j a v a 2 s . co m*/ VertexManagerPluginContext mockContext = mock(VertexManagerPluginContext.class); when(mockContext.getUserPayload()).thenReturn(config.toUserPayload(conf)); Set<String> inputVertices = new HashSet<String>(); inputVertices.add("v0"); inputVertices.add("v1"); when(mockContext.getVertexInputNames()).thenReturn(inputVertices); when(mockContext.getVertexNumTasks("v0")).thenReturn(4); when(mockContext.getVertexNumTasks("v1")).thenReturn(4); EdgeProperty edgeProperty = EdgeProperty.create( EdgeManagerPluginDescriptor.create(CartesianProductEdgeManager.class.getName()), null, null, null, null); Map<String, EdgeProperty> inputEdgeProperties = new HashMap<String, EdgeProperty>(); inputEdgeProperties.put("v0", edgeProperty); inputEdgeProperties.put("v1", edgeProperty); when(mockContext.getInputVertexEdgeProperties()).thenReturn(inputEdgeProperties); CartesianProductVertexManager vertexManager = new CartesianProductVertexManager(mockContext); vertexManager.initialize(); vertexManager.onVertexStateUpdated(new VertexStateUpdate("v0", VertexState.CONFIGURED)); vertexManager.onVertexStateUpdated(new VertexStateUpdate("v1", VertexState.CONFIGURED)); List<TaskAttemptIdentifier> completions = new ArrayList<>(); TezDAGID dagId = TezDAGID.getInstance(ApplicationId.newInstance(0, 0), 0); TezVertexID v0Id = TezVertexID.getInstance(dagId, 0); TezVertexID v1Id = TezVertexID.getInstance(dagId, 1); completions.add(new TaskAttemptIdentifierImpl("dag", "v0", TezTaskAttemptID.getInstance(TezTaskID.getInstance(v0Id, 0), 0))); completions.add(new TaskAttemptIdentifierImpl("dag", "v0", TezTaskAttemptID.getInstance(TezTaskID.getInstance(v0Id, 1), 0))); completions.add(new TaskAttemptIdentifierImpl("dag", "v1", TezTaskAttemptID.getInstance(TezTaskID.getInstance(v1Id, 0), 0))); vertexManager.onVertexStarted(completions); List<ScheduleTaskRequest> scheduleTaskRequests; verify(mockContext, times(1)).scheduleTasks(scheduleTaskRequestCaptor.capture()); scheduleTaskRequests = scheduleTaskRequestCaptor.getValue(); assertEquals(1, scheduleTaskRequests.size()); assertEquals(0, scheduleTaskRequests.get(0).getTaskIndex()); }
From source file:org.apache.tez.runtime.library.common.shuffle.impl.TestShuffleInputEventHandler.java
License:Apache License
private InputContext createTezInputContext() { ApplicationId applicationId = ApplicationId.newInstance(1, 1); InputContext inputContext = mock(InputContext.class); doReturn(applicationId).when(inputContext).getApplicationId(); return inputContext; }
From source file:org.apache.tez.runtime.library.common.shuffle.orderedgrouped.TestShuffle.java
License:Apache License
private InputContext createTezInputContext() throws IOException { ApplicationId applicationId = ApplicationId.newInstance(1, 1); InputContext inputContext = mock(InputContext.class); doReturn(applicationId).when(inputContext).getApplicationId(); doReturn("sourceVertex").when(inputContext).getSourceVertexName(); when(inputContext.getCounters()).thenReturn(new TezCounters()); ExecutionContext executionContext = new ExecutionContextImpl("localhost"); doReturn(executionContext).when(inputContext).getExecutionContext(); ByteBuffer shuffleBuffer = ByteBuffer.allocate(4).putInt(0, 4); doReturn(shuffleBuffer).when(inputContext).getServiceProviderMetaData(anyString()); Token<JobTokenIdentifier> sessionToken = new Token<JobTokenIdentifier>( new JobTokenIdentifier(new Text("text")), new JobTokenSecretManager()); ByteBuffer tokenBuffer = TezCommonUtils.serializeServiceData(sessionToken); doReturn(tokenBuffer).when(inputContext).getServiceConsumerMetaData(anyString()); return inputContext; }
From source file:org.apache.tez.runtime.library.common.shuffle.TestFetcher.java
License:Apache License
@Test(timeout = 3000) public void testLocalFetchModeSetting() throws Exception { TezConfiguration conf = new TezConfiguration(); conf.set(TezRuntimeConfiguration.TEZ_RUNTIME_OPTIMIZE_LOCAL_FETCH, "true"); InputAttemptIdentifier[] srcAttempts = { new InputAttemptIdentifier(0, 1, InputAttemptIdentifier.PATH_PREFIX + "pathComponent_1") }; FetcherCallback fetcherCallback = mock(FetcherCallback.class); Fetcher.FetcherBuilder builder = new Fetcher.FetcherBuilder(fetcherCallback, null, null, ApplicationId.newInstance(0, 1), null, "fetcherTest", conf, true, HOST); builder.assignWork(HOST, PORT, 0, Arrays.asList(srcAttempts)); Fetcher fetcher = spy(builder.build()); FetchResult fr = new FetchResult(HOST, PORT, 0, Arrays.asList(srcAttempts)); Fetcher.HostFetchResult hfr = new Fetcher.HostFetchResult(fr, srcAttempts, false); doReturn(hfr).when(fetcher).setupLocalDiskFetch(); doReturn(null).when(fetcher).doHttpFetch(); doNothing().when(fetcher).shutdown(); fetcher.call();// w ww . j av a 2 s.c o m verify(fetcher).setupLocalDiskFetch(); verify(fetcher, never()).doHttpFetch(); // When disabled use http fetch conf.set(TezRuntimeConfiguration.TEZ_RUNTIME_OPTIMIZE_LOCAL_FETCH, "false"); builder = new Fetcher.FetcherBuilder(fetcherCallback, null, null, ApplicationId.newInstance(0, 1), null, "fetcherTest", conf, false, HOST); builder.assignWork(HOST, PORT, 0, Arrays.asList(srcAttempts)); fetcher = spy(builder.build()); doReturn(null).when(fetcher).setupLocalDiskFetch(); doReturn(hfr).when(fetcher).doHttpFetch(); doNothing().when(fetcher).shutdown(); fetcher.call(); verify(fetcher, never()).setupLocalDiskFetch(); verify(fetcher).doHttpFetch(); }
From source file:org.apache.tez.runtime.library.common.shuffle.TestFetcher.java
License:Apache License
@Test(timeout = 3000) public void testSetupLocalDiskFetch() throws Exception { InputAttemptIdentifier[] srcAttempts = { new InputAttemptIdentifier(0, 1, InputAttemptIdentifier.PATH_PREFIX + "pathComponent_0"), new InputAttemptIdentifier(1, 2, InputAttemptIdentifier.PATH_PREFIX + "pathComponent_1"), new InputAttemptIdentifier(2, 3, InputAttemptIdentifier.PATH_PREFIX + "pathComponent_2"), new InputAttemptIdentifier(3, 4, InputAttemptIdentifier.PATH_PREFIX + "pathComponent_3"), new InputAttemptIdentifier(4, 5, InputAttemptIdentifier.PATH_PREFIX + "pathComponent_4") }; final int FIRST_FAILED_ATTEMPT_IDX = 2; final int SECOND_FAILED_ATTEMPT_IDX = 4; final int[] sucessfulAttempts = { 0, 1, 3 }; TezConfiguration conf = new TezConfiguration(); conf.set(TezRuntimeConfiguration.TEZ_RUNTIME_OPTIMIZE_LOCAL_FETCH, "true"); int partition = 42; FetcherCallback callback = mock(FetcherCallback.class); Fetcher.FetcherBuilder builder = new Fetcher.FetcherBuilder(callback, null, null, ApplicationId.newInstance(0, 1), null, "fetcherTest", conf, true, HOST); builder.assignWork(HOST, PORT, partition, Arrays.asList(srcAttempts)); Fetcher fetcher = spy(builder.build()); doAnswer(new Answer<Path>() { @Override//w ww.java 2s . c om public Path answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); return new Path(SHUFFLE_INPUT_FILE_PREFIX + args[0]); } }).when(fetcher).getShuffleInputFileName(anyString(), anyString()); doAnswer(new Answer<TezIndexRecord>() { @Override public TezIndexRecord answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); InputAttemptIdentifier srcAttemptId = (InputAttemptIdentifier) args[0]; String pathComponent = srcAttemptId.getPathComponent(); int len = pathComponent.length(); long p = Long.valueOf(pathComponent.substring(len - 1, len)); // Fail the 3rd one and 5th one. if (p == FIRST_FAILED_ATTEMPT_IDX || p == SECOND_FAILED_ATTEMPT_IDX) { throw new IOException("failing on 3/5th input to simulate failure case"); } // match with params for copySucceeded below. return new TezIndexRecord(p * 10, p * 1000, p * 100); } }).when(fetcher).getTezIndexRecord(any(InputAttemptIdentifier.class)); doNothing().when(fetcher).shutdown(); doNothing().when(callback).fetchSucceeded(anyString(), any(InputAttemptIdentifier.class), any(FetchedInput.class), anyLong(), anyLong(), anyLong()); doNothing().when(callback).fetchFailed(anyString(), any(InputAttemptIdentifier.class), eq(false)); FetchResult fetchResult = fetcher.call(); verify(fetcher).setupLocalDiskFetch(); // expect 3 sucesses and 2 failures for (int i : sucessfulAttempts) { verifyFetchSucceeded(callback, srcAttempts[i], conf); } verify(callback).fetchFailed(eq(HOST), eq(srcAttempts[FIRST_FAILED_ATTEMPT_IDX]), eq(false)); verify(callback).fetchFailed(eq(HOST), eq(srcAttempts[SECOND_FAILED_ATTEMPT_IDX]), eq(false)); Assert.assertEquals("fetchResult host", fetchResult.getHost(), HOST); Assert.assertEquals("fetchResult partition", fetchResult.getPartition(), partition); Assert.assertEquals("fetchResult port", fetchResult.getPort(), PORT); // 3nd and 5th attempt failed List<InputAttemptIdentifier> pendingInputs = Lists.newArrayList(fetchResult.getPendingInputs()); Assert.assertEquals("fetchResult pendingInput size", pendingInputs.size(), 2); Assert.assertEquals("fetchResult failed attempt", pendingInputs.get(0), srcAttempts[FIRST_FAILED_ATTEMPT_IDX]); Assert.assertEquals("fetchResult failed attempt", pendingInputs.get(1), srcAttempts[SECOND_FAILED_ATTEMPT_IDX]); }
From source file:org.apache.tez.runtime.library.common.shuffle.TestShuffleUtils.java
License:Apache License
private InputContext createTezInputContext() { ApplicationId applicationId = ApplicationId.newInstance(1, 1); InputContext inputContext = mock(InputContext.class); doReturn(applicationId).when(inputContext).getApplicationId(); doReturn("sourceVertex").when(inputContext).getSourceVertexName(); when(inputContext.getCounters()).thenReturn(new TezCounters()); return inputContext; }
From source file:org.apache.tez.runtime.library.common.shuffle.TestShuffleUtils.java
License:Apache License
private OutputContext createTezOutputContext() throws IOException { ApplicationId applicationId = ApplicationId.newInstance(1, 1); OutputContext outputContext = mock(OutputContext.class); ExecutionContextImpl executionContext = mock(ExecutionContextImpl.class); doReturn("localhost").when(executionContext).getHostName(); doReturn(executionContext).when(outputContext).getExecutionContext(); DataOutputBuffer serviceProviderMetaData = new DataOutputBuffer(); serviceProviderMetaData.writeInt(80); doReturn(ByteBuffer.wrap(serviceProviderMetaData.getData())).when(outputContext) .getServiceProviderMetaData(ShuffleUtils.SHUFFLE_HANDLER_SERVICE_ID); doReturn(1).when(outputContext).getTaskVertexIndex(); doReturn(1).when(outputContext).getOutputIndex(); doReturn(0).when(outputContext).getDAGAttemptNumber(); doReturn("destVertex").when(outputContext).getDestinationVertexName(); when(outputContext.getCounters()).thenReturn(new TezCounters()); return outputContext; }
From source file:org.apache.tez.runtime.library.common.sort.impl.TestPipelinedSorter.java
License:Apache License
@Before public void setup() { ApplicationId appId = ApplicationId.newInstance(10000, 1); TezCounters counters = new TezCounters(); String uniqueId = UUID.randomUUID().toString(); this.outputContext = createMockOutputContext(counters, appId, uniqueId); //To enable PipelinedSorter, set 2 threads conf.setInt(TezRuntimeConfiguration.TEZ_RUNTIME_SORT_THREADS, 2); conf.set(TezRuntimeConfiguration.TEZ_RUNTIME_KEY_CLASS, Text.class.getName()); conf.set(TezRuntimeConfiguration.TEZ_RUNTIME_VALUE_CLASS, Text.class.getName()); conf.set(TezRuntimeConfiguration.TEZ_RUNTIME_PARTITIONER_CLASS, HashPartitioner.class.getName()); //Setup localdirs String localDirs = workDir.toString(); conf.setStrings(TezRuntimeFrameworkConfigs.LOCAL_DIRS, localDirs); }
From source file:org.apache.tez.runtime.library.common.writers.TestUnorderedPartitionedKVWriter.java
License:Apache License
@Test(timeout = 10000) public void testBufferSizing() throws IOException { ApplicationId appId = ApplicationId.newInstance(10000, 1); TezCounters counters = new TezCounters(); String uniqueId = UUID.randomUUID().toString(); OutputContext outputContext = createMockOutputContext(counters, appId, uniqueId); int maxSingleBufferSizeBytes = 2047; Configuration conf = createConfiguration(outputContext, IntWritable.class, LongWritable.class, false, maxSingleBufferSizeBytes);// w ww . ja va2 s. com int numOutputs = 10; UnorderedPartitionedKVWriter kvWriter = null; kvWriter = new UnorderedPartitionedKVWriterForTest(outputContext, conf, numOutputs, 2048); assertEquals(2, kvWriter.numBuffers); assertEquals(1024, kvWriter.sizePerBuffer); assertEquals(1, kvWriter.numInitializedBuffers); kvWriter = new UnorderedPartitionedKVWriterForTest(outputContext, conf, numOutputs, maxSingleBufferSizeBytes * 3); assertEquals(3, kvWriter.numBuffers); assertEquals(maxSingleBufferSizeBytes - maxSingleBufferSizeBytes % 4, kvWriter.sizePerBuffer); assertEquals(1, kvWriter.numInitializedBuffers); kvWriter = new UnorderedPartitionedKVWriterForTest(outputContext, conf, numOutputs, maxSingleBufferSizeBytes * 2 + 1); assertEquals(3, kvWriter.numBuffers); assertEquals(1364, kvWriter.sizePerBuffer); assertEquals(1, kvWriter.numInitializedBuffers); kvWriter = new UnorderedPartitionedKVWriterForTest(outputContext, conf, numOutputs, 10240); assertEquals(6, kvWriter.numBuffers); assertEquals(1704, kvWriter.sizePerBuffer); assertEquals(1, kvWriter.numInitializedBuffers); }
From source file:org.apache.tez.runtime.library.common.writers.TestUnorderedPartitionedKVWriter.java
License:Apache License
public void textTest(int numRegularRecords, int numPartitions, long availableMemory, int numLargeKeys, int numLargevalues, int numLargeKvPairs) throws IOException, InterruptedException { Partitioner partitioner = new HashPartitioner(); ApplicationId appId = ApplicationId.newInstance(10000, 1); TezCounters counters = new TezCounters(); String uniqueId = UUID.randomUUID().toString(); OutputContext outputContext = createMockOutputContext(counters, appId, uniqueId); Random random = new Random(); Configuration conf = createConfiguration(outputContext, Text.class, Text.class, shouldCompress, -1, HashPartitioner.class); CompressionCodec codec = null;/*from w ww. j a v a2 s . c o m*/ if (shouldCompress) { codec = new DefaultCodec(); ((Configurable) codec).setConf(conf); } int numRecordsWritten = 0; Map<Integer, Multimap<String, String>> expectedValues = new HashMap<Integer, Multimap<String, String>>(); for (int i = 0; i < numPartitions; i++) { expectedValues.put(i, LinkedListMultimap.<String, String>create()); } UnorderedPartitionedKVWriter kvWriter = new UnorderedPartitionedKVWriterForTest(outputContext, conf, numPartitions, availableMemory); int sizePerBuffer = kvWriter.sizePerBuffer; BitSet partitionsWithData = new BitSet(numPartitions); Text keyText = new Text(); Text valText = new Text(); for (int i = 0; i < numRegularRecords; i++) { String key = createRandomString(Math.abs(random.nextInt(10))); String val = createRandomString(Math.abs(random.nextInt(20))); keyText.set(key); valText.set(val); int partition = partitioner.getPartition(keyText, valText, numPartitions); partitionsWithData.set(partition); expectedValues.get(partition).put(key, val); kvWriter.write(keyText, valText); numRecordsWritten++; } // Write Large key records for (int i = 0; i < numLargeKeys; i++) { String key = createRandomString(sizePerBuffer + Math.abs(random.nextInt(100))); String val = createRandomString(Math.abs(random.nextInt(20))); keyText.set(key); valText.set(val); int partition = partitioner.getPartition(keyText, valText, numPartitions); partitionsWithData.set(partition); expectedValues.get(partition).put(key, val); kvWriter.write(keyText, valText); numRecordsWritten++; } // Write Large val records for (int i = 0; i < numLargevalues; i++) { String key = createRandomString(Math.abs(random.nextInt(10))); String val = createRandomString(sizePerBuffer + Math.abs(random.nextInt(100))); keyText.set(key); valText.set(val); int partition = partitioner.getPartition(keyText, valText, numPartitions); partitionsWithData.set(partition); expectedValues.get(partition).put(key, val); kvWriter.write(keyText, valText); numRecordsWritten++; } // Write records where key + val are large (but both can fit in the buffer individually) for (int i = 0; i < numLargeKvPairs; i++) { String key = createRandomString(sizePerBuffer / 2 + Math.abs(random.nextInt(100))); String val = createRandomString(sizePerBuffer / 2 + Math.abs(random.nextInt(100))); keyText.set(key); valText.set(val); int partition = partitioner.getPartition(keyText, valText, numPartitions); partitionsWithData.set(partition); expectedValues.get(partition).put(key, val); kvWriter.write(keyText, valText); numRecordsWritten++; } List<Event> events = kvWriter.close(); verify(outputContext, never()).fatalError(any(Throwable.class), any(String.class)); TezCounter outputLargeRecordsCounter = counters.findCounter(TaskCounter.OUTPUT_LARGE_RECORDS); assertEquals(numLargeKeys + numLargevalues + numLargeKvPairs, outputLargeRecordsCounter.getValue()); // Validate the event assertEquals(1, events.size()); assertTrue(events.get(0) instanceof CompositeDataMovementEvent); CompositeDataMovementEvent cdme = (CompositeDataMovementEvent) events.get(0); assertEquals(0, cdme.getSourceIndexStart()); assertEquals(numPartitions, cdme.getCount()); DataMovementEventPayloadProto eventProto = DataMovementEventPayloadProto .parseFrom(ByteString.copyFrom(cdme.getUserPayload())); assertFalse(eventProto.hasData()); BitSet emptyPartitionBits = null; if (partitionsWithData.cardinality() != numPartitions) { assertTrue(eventProto.hasEmptyPartitions()); byte[] emptyPartitions = TezCommonUtils .decompressByteStringToByteArray(eventProto.getEmptyPartitions()); emptyPartitionBits = TezUtilsInternal.fromByteArray(emptyPartitions); assertEquals(numPartitions - partitionsWithData.cardinality(), emptyPartitionBits.cardinality()); } else { assertFalse(eventProto.hasEmptyPartitions()); emptyPartitionBits = new BitSet(numPartitions); } assertEquals(HOST_STRING, eventProto.getHost()); assertEquals(SHUFFLE_PORT, eventProto.getPort()); assertEquals(uniqueId, eventProto.getPathComponent()); // Verify the data // Verify the actual data TezTaskOutput taskOutput = new TezTaskOutputFiles(conf, uniqueId); Path outputFilePath = kvWriter.finalOutPath; Path spillFilePath = kvWriter.finalIndexPath; if (numRecordsWritten > 0) { assertTrue(localFs.exists(outputFilePath)); assertTrue(localFs.exists(spillFilePath)); } else { return; } // Special case for 0 records. TezSpillRecord spillRecord = new TezSpillRecord(spillFilePath, conf); DataInputBuffer keyBuffer = new DataInputBuffer(); DataInputBuffer valBuffer = new DataInputBuffer(); Text keyDeser = new Text(); Text valDeser = new Text(); for (int i = 0; i < numPartitions; i++) { if (emptyPartitionBits.get(i)) { continue; } TezIndexRecord indexRecord = spillRecord.getIndex(i); FSDataInputStream inStream = FileSystem.getLocal(conf).open(outputFilePath); inStream.seek(indexRecord.getStartOffset()); IFile.Reader reader = new IFile.Reader(inStream, indexRecord.getPartLength(), codec, null, null, false, 0, -1); while (reader.nextRawKey(keyBuffer)) { reader.nextRawValue(valBuffer); keyDeser.readFields(keyBuffer); valDeser.readFields(valBuffer); int partition = partitioner.getPartition(keyDeser, valDeser, numPartitions); assertTrue(expectedValues.get(partition).remove(keyDeser.toString(), valDeser.toString())); } inStream.close(); } for (int i = 0; i < numPartitions; i++) { assertEquals(0, expectedValues.get(i).size()); expectedValues.remove(i); } assertEquals(0, expectedValues.size()); }