blob: e803d7a4251e15db3c1741e62de6996a8562355d [file] [log] [blame]
Di Qian38c02a72019-11-18 19:14:07 -08001/*
2 * Copyright (C) 2019 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 */
16package com.android.tradefed.cluster;
17
18import com.android.tradefed.config.GlobalConfiguration;
19import com.android.tradefed.config.IConfiguration;
20
21import org.json.JSONException;
22
23import java.io.IOException;
24import java.util.List;
25
26/** An interface for interacting with the TFC backend. */
27public interface IClusterClient {
28 /**
29 * The unique configuration object type name. Used to retrieve the singleton instance from the
30 * {@link GlobalConfiguration}.
31 *
32 * @see IConfiguration#getConfigurationObject(String)
33 */
34 public static final String TYPE_NAME = "cluster_client";
35
36 /**
37 * Get a {@link IClusterEventUploader} that can be used to upload {@link ClusterCommandEvent}s.
38 */
39 public IClusterEventUploader<ClusterCommandEvent> getCommandEventUploader();
40
41 /** Get a {@link IClusterEventUploader} that can be used to upload {@link ClusterHostEvent}s. */
42 public IClusterEventUploader<ClusterHostEvent> getHostEventUploader();
43
44 /**
45 * Lease {@link ClusterCommand} for the give host.
46 *
47 * @param clusterId cluster id for the host
48 * @param hostname hostname
49 * @param devices deviceInfos the host has
50 * @param nextClusterIds a list of next cluster IDs to lease commands from.
51 * @param maxTasksTolease the max number of tasks that can current be leased
52 * @return a list of {@link ClusterCommand}
53 * @throws JSONException
54 */
55 public List<ClusterCommand> leaseHostCommands(
56 final String clusterId,
57 final String hostname,
58 final List<ClusterDeviceInfo> devices,
59 final List<String> nextClusterIds,
60 final int maxTasksTolease)
61 throws JSONException;
62
63 /**
64 * Get {@link TestEnvironment} for a request.
65 *
66 * @param requestId
67 * @return a {@link TestEnvironment} object.
68 * @throws IOException
69 * @throws JSONException
70 */
71 public TestEnvironment getTestEnvironment(final String requestId)
72 throws IOException, JSONException;
73
74 /**
75 * Get {@link TestResource}s for a request.
76 *
77 * @param requestId
78 * @return a list of {@link TestResource}.
79 * @throws IOException
80 * @throws JSONException
81 */
82 public List<TestResource> getTestResources(final String requestId)
83 throws IOException, JSONException;
84
85 public TestContext getTestContext(final String requestId, final String commandId)
86 throws IOException, JSONException;
87
88 public void updateTestContext(
89 final String requestId, final String commandId, TestContext testContext)
90 throws IOException, JSONException;
91
92 /**
93 * Determine the state of a cluster command.
94 *
95 * @param requestId cluster request ID
96 * @param commandId cluster command ID
97 * @return cluster command's state, or {@link ClusterCommand.State#UNKNOWN} if state could not
98 * be determined
99 */
100 public ClusterCommand.State getCommandState(String requestId, String commandId);
101}