1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.tradefed.invoker.sandbox; 17 18 import com.android.tradefed.build.BuildRetrievalError; 19 import com.android.tradefed.config.IConfiguration; 20 import com.android.tradefed.device.DeviceNotAvailableException; 21 import com.android.tradefed.invoker.IInvocationContext; 22 import com.android.tradefed.invoker.IRescheduler; 23 import com.android.tradefed.invoker.InvocationExecution; 24 import com.android.tradefed.log.LogUtil.CLog; 25 import com.android.tradefed.result.ITestInvocationListener; 26 27 /** 28 * Special sandbox execution of the invocation: This is the InvocationExection for when we are 29 * inside the sandbox running the command. The build should already be available in the context. 30 */ 31 public class SandboxedInvocationExecution extends InvocationExecution { 32 33 /** {@inheritDoc} */ 34 @Override fetchBuild( IInvocationContext context, IConfiguration config, IRescheduler rescheduler, ITestInvocationListener listener)35 public boolean fetchBuild( 36 IInvocationContext context, 37 IConfiguration config, 38 IRescheduler rescheduler, 39 ITestInvocationListener listener) 40 throws DeviceNotAvailableException, BuildRetrievalError { 41 // If the invocation is currently sandboxed, builds have already been downloaded. 42 CLog.d("Skipping download in the sandbox."); 43 if (!config.getConfigurationDescription().shouldUseSandbox()) { 44 throw new RuntimeException( 45 "We should only skip download if we are a sandbox. Something went very wrong."); 46 } 47 return true; 48 } 49 50 /** {@inheritDoc} */ 51 @Override resetBuildAndReschedule( Throwable exception, ITestInvocationListener listener, IConfiguration config, IInvocationContext context)52 public boolean resetBuildAndReschedule( 53 Throwable exception, 54 ITestInvocationListener listener, 55 IConfiguration config, 56 IInvocationContext context) { 57 if (!config.getConfigurationDescription().shouldUseSandbox()) { 58 throw new RuntimeException( 59 "We should only skip resetAndReschedule if we are a sandbox. " 60 + "Something went very wrong."); 61 } 62 // If we are sandboxed, build reset and reschedule should happen on the parents. 63 return false; 64 } 65 } 66