phet commented on code in PR #4077: URL: https://github.com/apache/gobblin/pull/4077#discussion_r1875579611
########## gobblin-temporal/src/main/java/org/apache/gobblin/temporal/yarn/YarnService.java: ########## @@ -194,8 +194,8 @@ class YarnService extends AbstractIdleService { private volatile boolean shutdownInProgress = false; private final boolean jarCacheEnabled; - private final WorkerProfile defaultWorkerProfile; - private final AtomicLong allocationRequestIdGenerator = new AtomicLong(0L); + private final long DEFAULT_ALLOCATION_REQUEST_ID = 0L; Review Comment: `private static final` ########## gobblin-temporal/src/test/java/org/apache/gobblin/temporal/yarn/DynamicScalingYarnServiceTest.java: ########## @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.gobblin.temporal.yarn; + +import java.net.URL; +import java.util.Collections; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.mockito.Mockito; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.base.Optional; +import com.google.common.eventbus.EventBus; +import com.typesafe.config.Config; +import com.typesafe.config.ConfigFactory; + +import org.apache.gobblin.temporal.dynamic.ScalingDirective; +import org.apache.gobblin.temporal.dynamic.WorkforceProfiles; + +/** Tests for {@link DynamicScalingYarnService} */ +public class DynamicScalingYarnServiceTest { + private Config defaultConfigs; + private final YarnConfiguration yarnConfiguration = new YarnConfiguration(); + private final FileSystem mockFileSystem = Mockito.mock(FileSystem.class); + private final EventBus eventBus = new EventBus("TemporalDynamicScalingYarnServiceTest"); + + @BeforeClass + public void setup() { + URL url = DynamicScalingYarnServiceTest.class.getClassLoader() + .getResource(YarnServiceTest.class.getSimpleName() + ".conf"); // using same initial config as of YarnServiceTest + Assert.assertNotNull(url, "Could not find resource " + url); + this.defaultConfigs = ConfigFactory.parseURL(url).resolve(); + } + + @Test + public void testReviseWorkforcePlanAndRequestNewContainers() throws Exception { + int numNewContainers = 5; + DynamicScalingYarnService dynamicScalingYarnService = new DynamicScalingYarnService(this.defaultConfigs, "testApp", "testAppId", yarnConfiguration, mockFileSystem, eventBus) { + @Override + protected void requestContainers(int numContainers, Resource resource, Optional<Long> allocationRequestId) { + Assert.assertEquals(numContainers, numNewContainers); + } Review Comment: the verify is in an impl that is not called directly. therefore, how would a maintainer know it's actually invoked? maybe drop the assertion in there and instead spy that: ``` Mockito.verify(dSYS, Mockito.times(1)).requestContainers(numNewContiners, Mockito.any(Resource.class), Mockito.any(Optional.class)); ``` ########## gobblin-temporal/src/main/java/org/apache/gobblin/temporal/yarn/YarnService.java: ########## @@ -558,8 +556,11 @@ protected ByteBuffer getSecurityTokens() throws IOException { protected String buildContainerCommand(Container container, String helixParticipantId, String helixInstanceTag) { long allocationRequestId = container.getAllocationRequestId(); // Using getOrDefault for backward-compatibility with containers that don't have allocationRequestId set - WorkerProfile workerProfile = this.workerProfileByAllocationRequestId.getOrDefault(allocationRequestId, - this.defaultWorkerProfile); + WorkerProfile workerProfile = Optional.fromNullable(this.workerProfileByAllocationRequestId.get(allocationRequestId)) + .or(() -> { + LOGGER.warn("No Worker Profile found for {} ... falling back... ", allocationRequestId); Review Comment: sorry, I meant to suggest we fill in the ellipses, maybe: ``` "No Worker Profile found for {}, so falling back to default" ``` I suppose to be truly robust it would look like ``` WorkerProfile workerProfile = Optional.fromNullable(this.workerProfileByAllocationRequestId.get(allocationRequestId)) .or(() -> { LOGGER.warn("No Worker Profile found for {}, so falling back to default", allocationRequestId); return this.workerProfileByAllocationRequestId.computeIfAbsent(DEFAULT_ALLOCATION_REQUEST_ID, k -> { LOGGER.warn("WARNING: (LIKELY) UNEXPECTED CONCURRENCY: No Worker Profile even yet mapped to the default allocation request ID {} - creating one now", DEFAULT_ALLOCATION_REQUEST_ID); return new WorkerProfile(this.config); }); }); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@gobblin.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org