Skip to content

Commit 439b957

Browse files
DmitryLitvintsevkhys95
authored andcommitted
bulk: handle absolute/relative paths in uniform fashion
Motivation: ----------- Recent change(s) that massaged user input target paths and stored absolute paths on bulk backend lead to ambiguity between user provided and dcache resolved paths and also resulted in inability to use full paths (i.e. only relative paths are supported). At Fermilab we need to use both - relative and absolute paths Modification: ------------- Revert all recent changes that appended prefix to user supplied paths, stored the result and then stripped the prefix so that only "original" paths are exposed to the user. Instead, like before, store user supplied paths but carry over request prefix which is computed from user root and door root. When calling PnfsManager using paths the full paths of the targets are reassembled using the prefix Result: ------ Restored ability to use absolute paths when using REST API. Issue: #7693 Patch: https://rb.dcache.org/r/14355/ Target: trunk Request: 10.2, 10.1, 10.0, 9.2 Require-book: no Require-notes: yes Acked-by: Lea Morschel, Tigran Mkrtchyan
1 parent 4471cb9 commit 439b957

File tree

17 files changed

+129
-118
lines changed

17 files changed

+129
-118
lines changed

modules/dcache-bulk/src/main/java/org/dcache/services/bulk/activity/BulkActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ protected BulkActivity(String name, TargetType targetType) {
114114
retryPolicy = DEFAULT_RETRY_POLICY;
115115
}
116116

117-
public void cancel(BulkRequestTarget target) {
117+
public void cancel(String prefix, BulkRequestTarget target) {
118118
target.cancel();
119119
}
120120

@@ -173,11 +173,12 @@ public void setDescriptors(Set<BulkActivityArgumentDescriptor> descriptors) {
173173
*
174174
* @param rid of the request.
175175
* @param tid of the target.
176+
* @param prefix target prefix
176177
* @param path of the target on which to perform the activity.
177178
* @return future result of the activity.
178179
* @throws BulkServiceException
179180
*/
180-
public abstract ListenableFuture<R> perform(String rid, long tid, FsPath path, FileAttributes attributes)
181+
public abstract ListenableFuture<R> perform(String rid, long tid, String prefix, FsPath path, FileAttributes attributes)
181182
throws BulkServiceException;
182183

183184
/**

modules/dcache-bulk/src/main/java/org/dcache/services/bulk/activity/plugin/delete/DeleteActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ public DeleteActivity(String name, TargetType targetType) {
8989
}
9090

9191
@Override
92-
public ListenableFuture<PnfsDeleteEntryMessage> perform(String rid, long tid, FsPath path,
92+
public ListenableFuture<PnfsDeleteEntryMessage> perform(String rid, long tid, String prefix, FsPath path,
9393
FileAttributes attributes) {
94-
PnfsDeleteEntryMessage msg = new PnfsDeleteEntryMessage(path.toString());
94+
FsPath absolutePath = BulkRequestTarget.computeFsPath(prefix, path.toString());
95+
PnfsDeleteEntryMessage msg = new PnfsDeleteEntryMessage(absolutePath.toString());
9596
msg.setSubject(subject);
9697
if (attributes != null && attributes.getFileType() == FileType.DIR && skipDirs) {
9798
msg.setSucceeded();

modules/dcache-bulk/src/main/java/org/dcache/services/bulk/activity/plugin/log/LogTargetActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected LogTargetActivity(String name, TargetType targetType) {
8989
}
9090

9191
@Override
92-
public ListenableFuture<BulkRequestTarget> perform(String ruid, long tid, FsPath path,
92+
public ListenableFuture<BulkRequestTarget> perform(String ruid, long tid, String prefix, FsPath path,
9393
FileAttributes attributes) {
9494
long now = System.currentTimeMillis();
9595
BulkRequestTarget t = BulkRequestTargetBuilder.builder(null).activity(this.getName()).id(tid)

modules/dcache-bulk/src/main/java/org/dcache/services/bulk/activity/plugin/pin/PinActivity.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,27 @@ public PinActivity(String name, TargetType targetType) {
9191
super(name, targetType);
9292
}
9393

94-
public void cancel(BulkRequestTarget target) {
95-
super.cancel(target);
94+
public void cancel(String prefix, BulkRequestTarget target) {
95+
super.cancel(prefix, target);
9696
try {
97-
pinManager.send(unpinMessage(id, target));
97+
pinManager.send(unpinMessage(id, prefix, target));
9898
} catch (CacheException e) {
99-
target.setErrorObject(new BulkServiceException("unable to fetch pnfsid of target in "
99+
target.setErrorObject(new BulkServiceException("unable to fetch pnfsid of target in "
100100
+ "order to cancel pinning.", e));
101101
}
102102
}
103103

104104
@Override
105-
public ListenableFuture<Message> perform(String rid, long tid, FsPath target,
105+
public ListenableFuture<Message> perform(String rid, long tid, String prefix, FsPath path,
106106
FileAttributes attributes) {
107107
if (id == null) {
108108
id = rid;
109109
}
110110

111111
try {
112112
if (attributes == null) {
113-
attributes = getAttributes(target);
113+
FsPath absolutePath = BulkRequestTarget.computeFsPath(prefix, path.toString());
114+
attributes = getAttributes(absolutePath);
114115
}
115116

116117
checkPinnable(attributes);

modules/dcache-bulk/src/main/java/org/dcache/services/bulk/activity/plugin/pin/PinManagerActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
6161

6262
import static com.google.common.util.concurrent.Uninterruptibles.getUninterruptibly;
6363
import static diskCacheV111.util.CacheException.INVALID_ARGS;
64+
import static org.dcache.services.bulk.util.BulkRequestTarget.computeFsPath;
6465
import static org.dcache.services.bulk.util.BulkRequestTarget.State.SKIPPED;
6566

6667
import com.google.common.util.concurrent.Futures;
@@ -130,11 +131,12 @@ protected FileAttributes getAttributes(FsPath path) throws CacheException {
130131
return pnfsHandler.getFileAttributes(path, MINIMALLY_REQUIRED_ATTRIBUTES);
131132
}
132133

133-
protected PinManagerUnpinMessage unpinMessage(String id, BulkRequestTarget target)
134+
protected PinManagerUnpinMessage unpinMessage(String id, String prefix, BulkRequestTarget target)
134135
throws CacheException {
135136
PnfsId pnfsId = target.getPnfsId();
136137
if (pnfsId == null) {
137-
pnfsId = getAttributes(target.getPath()).getPnfsId();
138+
FsPath absolutePath = computeFsPath(prefix, target.getPath().toString());
139+
pnfsId = getAttributes(absolutePath).getPnfsId();
138140
}
139141
return unpinMessage(id, pnfsId);
140142
}

modules/dcache-bulk/src/main/java/org/dcache/services/bulk/activity/plugin/pin/ReleaseActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
6060
package org.dcache.services.bulk.activity.plugin.pin;
6161

6262
import static org.dcache.services.bulk.activity.plugin.pin.ReleaseActivityProvider.REQUEST_ID;
63+
import static org.dcache.services.bulk.util.BulkRequestTarget.computeFsPath;
6364

6465
import com.google.common.util.concurrent.Futures;
6566
import com.google.common.util.concurrent.ListenableFuture;
@@ -77,11 +78,12 @@ public ReleaseActivity(String name, TargetType targetType) {
7778
}
7879

7980
@Override
80-
public ListenableFuture<Message> perform(String rid, long tid, FsPath target,
81+
public ListenableFuture<Message> perform(String rid, long tid, String prefix, FsPath path,
8182
FileAttributes attributes) {
8283
try {
8384
if (attributes == null) {
84-
attributes = getAttributes(target);
85+
FsPath absolutePath = computeFsPath(prefix, path.toString());
86+
attributes = getAttributes(absolutePath);
8587
}
8688
return pinManager.send(unpinMessage(id, attributes.getPnfsId()));
8789
} catch (CacheException e) {

modules/dcache-bulk/src/main/java/org/dcache/services/bulk/activity/plugin/pin/StageActivity.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,34 +102,36 @@ public StageActivity(String name, TargetType targetType) {
102102
super(name, targetType);
103103
}
104104

105-
public void cancel(BulkRequestTarget target) {
106-
super.cancel(target);
105+
public void cancel(String prefix, BulkRequestTarget target) {
106+
super.cancel(prefix, target);
107107
try {
108-
pinManager.send(unpinMessage(id, target));
108+
pinManager.send(unpinMessage(id, prefix, target));
109109
} catch (CacheException e) {
110110
target.setErrorObject(new BulkServiceException("unable to fetch pnfsid of target in "
111-
+ "order to cancel staging.", e));
111+
+ "order to cancel staging.", e));
112112
}
113113
}
114114

115115
@Override
116-
public ListenableFuture<Message> perform(String rid, long tid, FsPath target,
116+
public ListenableFuture<Message> perform(String rid, long tid, String prefix, FsPath path,
117117
FileAttributes attributes) {
118118
id = rid;
119119

120120
try {
121121
/*
122122
* refetch the attributes because RP is not stored in the bulk database.
123123
*/
124-
attributes = getAttributes(target);
124+
125+
FsPath absolutePath = BulkRequestTarget.computeFsPath(prefix, path.toString());
126+
attributes = getAttributes(absolutePath);
125127

126128
checkStageable(attributes);
127129

128130
PinManagerPinMessage message
129131
= new PinManagerPinMessage(attributes, getProtocolInfo(),
130132
pnfsHandler.getRestriction(),
131133
id,
132-
getLifetimeInMillis(target));
134+
getLifetimeInMillis(path));
133135
message.setSubject(subject);
134136

135137
Optional<ListenableFuture<Message>> skipOption = skipIfOnline(attributes, message);

modules/dcache-bulk/src/main/java/org/dcache/services/bulk/activity/plugin/pin/UnpinActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
6060
package org.dcache.services.bulk.activity.plugin.pin;
6161

6262
import static org.dcache.services.bulk.activity.plugin.pin.UnpinActivityProvider.UNPIN_REQUEST_ID;
63+
import static org.dcache.services.bulk.util.BulkRequestTarget.computeFsPath;
6364

6465
import com.google.common.util.concurrent.Futures;
6566
import com.google.common.util.concurrent.ListenableFuture;
@@ -78,11 +79,12 @@ public UnpinActivity(String name, TargetType targetType) {
7879
}
7980

8081
@Override
81-
public ListenableFuture<Message> perform(String rid, long tid, FsPath target,
82+
public ListenableFuture<Message> perform(String rid, long tid, String prefix, FsPath path,
8283
FileAttributes attributes) {
8384
try {
8485
if (attributes == null) {
85-
attributes = getAttributes(target);
86+
FsPath absolutePath = computeFsPath(prefix, path.toString());
87+
attributes = getAttributes(absolutePath);
8688
}
8789
return pinManager.send(unpinMessage(id, attributes.getPnfsId()));
8890
} catch (CacheException e) {

modules/dcache-bulk/src/main/java/org/dcache/services/bulk/activity/plugin/qos/UpdateQoSActivity.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,30 +112,45 @@ public UpdateQoSActivity(String name, TargetType targetType) {
112112
}
113113

114114
@Override
115-
public synchronized void cancel(BulkRequestTarget target) {
115+
public synchronized void cancel(String prefix, BulkRequestTarget target) {
116116
RemoteQoSRequirementsClient client = new RemoteQoSRequirementsClient();
117117
client.setRequirementsService(qosEngine);
118-
PnfsId pnfsId = target.getAttributes().getPnfsId();
118+
PnfsId pnfsId = null;
119+
if (target.getAttributes() == null) {
120+
FsPath absolutePath = BulkRequestTarget.computeFsPath(prefix,
121+
target.getPath().toString());
122+
try {
123+
pnfsId = pnfsHandler.getFileAttributes(absolutePath.toString(),
124+
MINIMALLY_REQUIRED_ATTRIBUTES).getPnfsId();
125+
} catch (CacheException e) {
126+
LOGGER.error("fileQoSRequirementsModifiedCancelled failed: failed to fetch attributes for {} {}.",
127+
target.getPath().toString(),
128+
e.getMessage());
129+
}
130+
} else {
131+
pnfsId = target.getAttributes().getPnfsId();
132+
}
119133
try {
120134
client.fileQoSRequirementsModifiedCancelled(pnfsId, subject);
121135
} catch (QoSException e) {
122136
LOGGER.error("fileQoSRequirementsModifiedCancelled failed: {}, {}.", pnfsId,
123137
e.getMessage());
124138
}
125139
responseReceiver.cancel(pnfsId.toString());
126-
super.cancel(target);
140+
super.cancel(prefix, target);
127141
}
128142

129143
@Override
130144
public ListenableFuture<QoSTransitionCompletedMessage> perform(String rid, long tid,
131-
FsPath path, FileAttributes attributes) throws BulkServiceException {
145+
String prefix, FsPath path, FileAttributes attributes) throws BulkServiceException {
132146
if (targetQos == null && qosPolicy == null) {
133147
return Futures.immediateFailedFuture(new IllegalArgumentException("no target qos or policy given."));
134148
}
135149

136150
if (attributes == null) {
137151
try {
138-
attributes = pnfsHandler.getFileAttributes(path, MINIMALLY_REQUIRED_ATTRIBUTES);
152+
FsPath absolutePath = BulkRequestTarget.computeFsPath(prefix, path.toString());
153+
attributes = pnfsHandler.getFileAttributes(absolutePath.toString(), MINIMALLY_REQUIRED_ATTRIBUTES);
139154
} catch (CacheException e) {
140155
throw new BulkServiceException("failed to retrieve file attributes", e);
141156
}
@@ -232,6 +247,3 @@ public void setNamespaceHandler(PnfsHandler pnfsHandler) {
232247
this.pnfsHandler = pnfsHandler;
233248
}
234249
}
235-
236-
237-

0 commit comments

Comments
 (0)