Skip to content

Commit 6fce24f

Browse files
cataliniianuvedverma
authored andcommitted
Log first successful container request (#20)
Call internal lyft API using reflection when the executor was successfully requested from K8s (cherry picked from commit 860cb05)
1 parent 303c18c commit 6fce24f

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.util
19+
20+
private[spark] object LyftUtils {
21+
def callObjectMethodNoArguments(objectName: String, method: String): Boolean = {
22+
var ok = true
23+
try {
24+
val m = Utils.classForName(objectName).getField("MODULE$").get(null)
25+
Utils.classForName(objectName).getDeclaredMethod(method).invoke(m)
26+
} catch {
27+
case e: Throwable => ok = false
28+
}
29+
ok
30+
}
31+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.util
19+
20+
import org.apache.spark.{SparkException, SparkFunSuite}
21+
import org.apache.spark.internal.Logging
22+
23+
object TestObjectLyftUtils {
24+
var testVar = 0L
25+
def setVal() = {
26+
testVar = 1L
27+
}
28+
}
29+
30+
class LyftUtilsSuite extends SparkFunSuite with ResetSystemProperties with Logging {
31+
32+
test("callObjectMethodNoArguments") {
33+
// Test calling the method using reflection 1
34+
val v = LyftUtils.callObjectMethodNoArguments("org.apache.spark.util.TestObjectLyftUtils$", "setVal")
35+
assert(v === true)
36+
assert(TestObjectLyftUtils.testVar === 1)
37+
assert(false ==
38+
LyftUtils.callObjectMethodNoArguments("org.apache.spark.util.TestObjectLyftUtils$", "setVal1"))
39+
}
40+
}

resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,12 @@ class ExecutorPodsAllocator(
466466
.build()
467467
val resources = replacePVCsIfNeeded(
468468
podWithAttachedContainer, resolvedExecutorSpec.executorKubernetesResources, reusablePVCs)
469-
val createdExecutorPod =
470-
kubernetesClient.pods().inNamespace(namespace).resource(podWithAttachedContainer).create()
469+
val createdExecutorPod = kubernetesClient.pods().create(podWithAttachedContainer)
470+
471+
org.apache.spark.util.LyftUtils.callObjectMethodNoArguments(
472+
"com.lyft.data.spark.AppMetrics$",
473+
"setFirstExecutorAllocationTime")
474+
471475
try {
472476
addOwnerReference(createdExecutorPod, resources)
473477
resources

0 commit comments

Comments
 (0)