diff --git a/modules/dcache/src/main/java/org/dcache/util/Transfer.java b/modules/dcache/src/main/java/org/dcache/util/Transfer.java index e7eb13fbab3..833925ea136 100644 --- a/modules/dcache/src/main/java/org/dcache/util/Transfer.java +++ b/modules/dcache/src/main/java/org/dcache/util/Transfer.java @@ -618,6 +618,11 @@ public synchronized String getDomainName() { return _cellAddress.getCellDomainName(); } + private synchronized String getMessageEventSource() { + return _cellAddress == null ? "" : + _cellAddress.getCellName() + "@" + _cellAddress.getCellDomainName(); + } + /** * The client address is the socket address from which the transfer was initiated. */ @@ -821,7 +826,7 @@ private ListenableFuture readNameSpaceEntryAsync(boolean allowWrite, long request.setUpdateAtime(true); MessageEvent nameSpaceReadEvent = new MessageEvent(); - nameSpaceReadEvent.source = getCellName() + "@" + getDomainName(); + nameSpaceReadEvent.source = getMessageEventSource(); nameSpaceReadEvent.destination = "PnfsManager"; nameSpaceReadEvent.message = PnfsGetFileAttributes.class.getSimpleName(); nameSpaceReadEvent.begin(); @@ -996,7 +1001,7 @@ public ListenableFuture selectPoolAsync(long timeout) { // init JFR event MessageEvent poolSelectEvent = new MessageEvent(); - poolSelectEvent.source = getCellName() + "@" + getDomainName(); + poolSelectEvent.source = getMessageEventSource(); poolSelectEvent.destination = "PoolManager"; poolSelectEvent.message = isWrite() ? PoolMgrSelectReadPoolMsg.class.getSimpleName() : PoolMgrSelectWritePoolMsg.class.getSimpleName(); poolSelectEvent.begin(); @@ -1102,7 +1107,7 @@ public ListenableFuture startMoverAsync(long timeout) { // init JFR event MessageEvent moverStartEvent = new MessageEvent(); - moverStartEvent.source = getCellName() + "@" + getDomainName(); + moverStartEvent.source = getMessageEventSource(); moverStartEvent.destination = pool.getName(); moverStartEvent.message = message.getClass().getSimpleName(); moverStartEvent.begin(); @@ -1169,7 +1174,7 @@ public void killMover(long millis, String explanation) { // init JFR event var killMoverEvent = new MessageEvent(); - killMoverEvent.source = getCellName() + "@" + getDomainName(); + killMoverEvent.source = getMessageEventSource(); killMoverEvent.destination = pool.getName(); killMoverEvent.message = message.getClass().getSimpleName(); diff --git a/modules/dcache/src/test/java/org/dcache/util/TransferTest.java b/modules/dcache/src/test/java/org/dcache/util/TransferTest.java new file mode 100644 index 00000000000..05aa1b80f83 --- /dev/null +++ b/modules/dcache/src/test/java/org/dcache/util/TransferTest.java @@ -0,0 +1,64 @@ +/* dCache - http://www.dcache.org/ + * + * Copyright (C) 2026 Deutsches Elektronen-Synchrotron + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.dcache.util; + +import static com.google.common.util.concurrent.Futures.immediateFuture; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import diskCacheV111.util.FsPath; +import diskCacheV111.util.PnfsHandler; +import diskCacheV111.vehicles.GenericStorageInfo; +import javax.security.auth.Subject; +import org.dcache.auth.attributes.Restrictions; +import org.dcache.cells.CellStub; +import org.dcache.namespace.FileType; +import org.dcache.vehicles.FileAttributes; +import org.dcache.vehicles.PnfsGetFileAttributes; +import org.junit.Test; + +public class TransferTest { + + @Test + public void shouldReadNamespaceEntryWithoutCellAddress() throws Exception { + CellStub stub = mock(CellStub.class); + when(stub.send(any(PnfsGetFileAttributes.class), anyLong())).thenAnswer(invocation -> { + PnfsGetFileAttributes request = invocation.getArgument(0); + PnfsGetFileAttributes reply = + new PnfsGetFileAttributes(request.getPnfsPath(), + request.getRequestedAttributes()); + FileAttributes attributes = FileAttributes.of() + .fileType(FileType.REGULAR) + .size(1L) + .storageInfo(new GenericStorageInfo()) + .build(); + reply.setFileAttributes(attributes); + return immediateFuture(reply); + }); + + Transfer transfer = new Transfer(new PnfsHandler(stub), new Subject(), + Restrictions.none(), FsPath.create("/test/path")); + + transfer.readNameSpaceEntry(false); + + verify(stub).send(any(PnfsGetFileAttributes.class), anyLong()); + } +}