blob: 15c0e1f4277c7e522d8a506ef2ab28e341843cea [file] [log] [blame]
buchgr357cb1e2019-04-03 06:15:02 -07001// Copyright 2019 The Bazel Authors. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.devtools.build.lib.remote;
16
17import com.google.common.base.Preconditions;
18import com.google.common.collect.ImmutableList;
19import com.google.devtools.build.lib.actions.Action;
20import com.google.devtools.build.lib.actions.ActionInputMap;
21import com.google.devtools.build.lib.actions.Artifact;
Jakob Buchgraber484ffae2019-06-19 06:04:12 -070022import com.google.devtools.build.lib.actions.ArtifactPathResolver;
fellyf6408d62019-07-16 12:51:14 -070023import com.google.devtools.build.lib.actions.FilesetOutputSymlink;
buchgr357cb1e2019-04-03 06:15:02 -070024import com.google.devtools.build.lib.actions.cache.MetadataHandler;
25import com.google.devtools.build.lib.events.EventHandler;
26import com.google.devtools.build.lib.vfs.BatchStat;
27import com.google.devtools.build.lib.vfs.FileSystem;
28import com.google.devtools.build.lib.vfs.ModifiedFileSet;
29import com.google.devtools.build.lib.vfs.OutputService;
30import com.google.devtools.build.lib.vfs.Path;
31import com.google.devtools.build.lib.vfs.PathFragment;
32import com.google.devtools.build.lib.vfs.Root;
Jakob Buchgraber484ffae2019-06-19 06:04:12 -070033import java.util.Collection;
34import java.util.Map;
buchgr357cb1e2019-04-03 06:15:02 -070035import java.util.UUID;
buchgr357cb1e2019-04-03 06:15:02 -070036import javax.annotation.Nullable;
37
38/** Output service implementation for the remote module */
39public class RemoteOutputService implements OutputService {
40
41 @Nullable private RemoteActionInputFetcher actionInputFetcher;
42
43 void setActionInputFetcher(RemoteActionInputFetcher actionInputFetcher) {
44 this.actionInputFetcher = Preconditions.checkNotNull(actionInputFetcher, "actionInputFetcher");
45 }
46
47 @Override
48 public ActionFileSystemType actionFileSystemType() {
49 return actionInputFetcher != null
50 ? ActionFileSystemType.STAGE_REMOTE_FILES
51 : ActionFileSystemType.DISABLED;
52 }
53
54 @Nullable
55 @Override
56 public FileSystem createActionFileSystem(
57 FileSystem sourceDelegate,
58 PathFragment execRootFragment,
59 String relativeOutputPath,
60 ImmutableList<Root> sourceRoots,
61 ActionInputMap inputArtifactData,
mschallerb20f5122020-04-23 21:36:25 -070062 Iterable<Artifact> outputArtifacts,
63 boolean trackFailedRemoteReads) {
buchgr357cb1e2019-04-03 06:15:02 -070064 Preconditions.checkNotNull(actionInputFetcher, "actionInputFetcher");
65 return new RemoteActionFileSystem(
66 sourceDelegate,
67 execRootFragment,
68 relativeOutputPath,
69 inputArtifactData,
70 actionInputFetcher);
71 }
72
73 @Override
74 public String getFilesSystemName() {
75 return "remoteActionFS";
76 }
77
78 @Override
79 public ModifiedFileSet startBuild(
80 EventHandler eventHandler, UUID buildId, boolean finalizeActions) {
81 return ModifiedFileSet.EVERYTHING_MODIFIED;
82 }
83
84 @Override
85 public void finalizeBuild(boolean buildSuccessful) {
86 // Intentionally left empty.
87 }
88
89 @Override
90 public void finalizeAction(Action action, MetadataHandler metadataHandler) {
91 // Intentionally left empty.
92 }
93
94 @Nullable
95 @Override
96 public BatchStat getBatchStatter() {
97 return null;
98 }
99
100 @Override
101 public boolean canCreateSymlinkTree() {
102 /* TODO(buchgr): Optimize symlink creation for remote execution */
103 return false;
104 }
105
106 @Override
107 public void createSymlinkTree(
ulfjack1a80bb82019-11-26 07:52:35 -0800108 Map<PathFragment, PathFragment> symlinks, PathFragment symlinkTreeRoot) {
buchgr357cb1e2019-04-03 06:15:02 -0700109 throw new UnsupportedOperationException();
110 }
111
112 @Override
113 public void clean() {
114 // Intentionally left empty.
115 }
116
117 @Override
Jakob Buchgraber484ffae2019-06-19 06:04:12 -0700118 public boolean isRemoteFile(Artifact artifact) {
119 Path path = artifact.getPath();
120 return path.getFileSystem() instanceof RemoteActionFileSystem
121 && ((RemoteActionFileSystem) path.getFileSystem()).isRemote(path);
122 }
123
124 @Override
125 public boolean supportsPathResolverForArtifactValues() {
126 return actionFileSystemType() != ActionFileSystemType.DISABLED;
127 }
128
129 @Override
130 public ArtifactPathResolver createPathResolverForArtifactValues(
131 PathFragment execRoot,
132 String relativeOutputPath,
133 FileSystem fileSystem,
134 ImmutableList<Root> pathEntries,
135 ActionInputMap actionInputMap,
136 Map<Artifact, Collection<Artifact>> expandedArtifacts,
fellyf6408d62019-07-16 12:51:14 -0700137 Map<Artifact, ImmutableList<FilesetOutputSymlink>> filesets) {
Jakob Buchgraber484ffae2019-06-19 06:04:12 -0700138 FileSystem remoteFileSystem =
139 new RemoteActionFileSystem(
140 fileSystem, execRoot, relativeOutputPath, actionInputMap, actionInputFetcher);
141 return ArtifactPathResolver.createPathResolver(remoteFileSystem, fileSystem.getPath(execRoot));
buchgr357cb1e2019-04-03 06:15:02 -0700142 }
143}