use of diskCacheV111.vehicles.MoverInfoMessage in project dcache by dCache.
the class BillingMessageSerializer method transform.
static JSONObject transform(MoverInfoMessage data) {
JSONObject o = new JSONObject();
o.put("version", "1.0");
o.put("msgType", data.getMessageType());
o.put("date", DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.ofInstant(Instant.ofEpochMilli(data.getTimestamp()), ZoneId.systemDefault())));
o.put("queuingTime", data.getTimeQueued());
o.put("cellName", data.getCellAddress().getCellName());
o.put("cellType", data.getCellType());
o.put("cellDomain", data.getCellAddress().getCellDomainName());
if (!Double.isNaN(data.getMeanReadBandwidth())) {
o.put("meanReadBandwidth", data.getMeanReadBandwidth());
}
if (!Double.isNaN(data.getMeanWriteBandwidth())) {
o.put("meanWriteBandwidth", data.getMeanWriteBandwidth());
}
data.getReadIdle().ifPresent(d -> o.put("readIdle", d.toString()));
data.getWriteIdle().ifPresent(d -> o.put("writeIdle", d.toString()));
data.getReadActive().ifPresent(d -> o.put("readActive", d.toString()));
data.getWriteActive().ifPresent(d -> o.put("writeActive", d.toString()));
JSONObject status = new JSONObject();
status.put("code", data.getResultCode());
status.put("msg", data.getMessage());
o.put("status", status);
o.put("session", data.getTransaction());
JSONArray subject = new JSONArray();
data.getSubject().getPrincipals().forEach(s -> subject.put(s));
o.put("subject", subject);
o.put("pnfsid", data.getPnfsId());
o.put("billingPath", data.getBillingPath());
o.put("fileSize", data.getFileSize());
o.put("storageInfo", data.getStorageInfo().getStorageClass() + "@" + data.getStorageInfo().getHsm());
o.put("transferSize", data.getDataTransferred());
o.put("transferTime", data.getConnectionTime());
o.put("isWrite", data.isFileCreated() ? "write" : "read");
InetSocketAddress remoteHost = ((IpProtocolInfo) data.getProtocolInfo()).getSocketAddress();
JSONObject protocolInfo = new JSONObject();
protocolInfo.put("protocol", data.getProtocolInfo().getProtocol());
protocolInfo.put("versionMajor", data.getProtocolInfo().getMajorVersion());
protocolInfo.put("versionMinor", data.getProtocolInfo().getMinorVersion());
protocolInfo.put("port", remoteHost.getPort());
protocolInfo.put("host", remoteHost.getAddress().getHostAddress());
o.put("protocolInfo", protocolInfo);
o.put("initiator", data.getInitiator());
o.put("isP2p", data.isP2P());
o.put("transferPath", data.getTransferPath());
return o;
}
use of diskCacheV111.vehicles.MoverInfoMessage in project dcache by dCache.
the class DoorRequestMessageSerializer method serialize.
@Override
public byte[] serialize(String topic, DoorRequestInfoMessage data) {
JSONObject o = new JSONObject();
o.put("VERSION", "1.0");
o.put("msgType", data.getMessageType());
o.put("date", DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.ofInstant(Instant.ofEpochMilli(data.getTimestamp()), ZoneId.systemDefault())));
o.put("queuingTime", data.getTimeQueued());
o.put("cellName", data.getCellAddress().getCellName());
o.put("cellType", data.getCellType());
o.put("cellDomain", data.getCellAddress().getCellDomainName());
JSONObject status = new JSONObject();
status.put("code", data.getResultCode());
status.put("msg", data.getMessage());
o.put("status", status);
o.put("session", data.getTransaction());
o.put("sessionDuration", data.getTransactionDuration());
o.put("transferPath", data.getTransferPath());
JSONArray subject = new JSONArray();
data.getSubject().getPrincipals().forEach(s -> subject.put(s));
o.put("subject", subject);
o.put("client", data.getClient());
o.put("clientChain", data.getClientChain());
o.put("mappedUID", data.getUid());
o.put("mappedGID", data.getGid());
o.put("owner", data.getOwner());
o.put("pnfsid", data.getPnfsId());
o.put("billingPath", data.getBillingPath());
o.put("fileSize", data.getFileSize());
StorageInfo info = data.getStorageInfo();
if (info != null) {
o.put("storageInfo", info.getStorageClass() + "@" + info.getHsm());
}
MoverInfoMessage moverInfoMessage = data.getMoverInfo();
if (moverInfoMessage != null) {
JSONObject moverInfo = BillingMessageSerializer.transform(moverInfoMessage);
Arrays.stream(REDUNDANT_MOVER_DATA_KEYS).forEach(moverInfo::remove);
o.put("moverInfo", moverInfo);
}
return o.toString().getBytes(UTF_8);
}
use of diskCacheV111.vehicles.MoverInfoMessage in project dcache by dCache.
the class DefaultPostTransferService method execute.
@Override
public void execute(final Mover<?> mover, final CompletionHandler<Void, Void> completionHandler) {
_executor.execute(new FireAndForgetTask(() -> {
ReplicaDescriptor handle = mover.getIoHandle();
try {
try {
if (mover.getIoMode().contains(StandardOpenOption.WRITE)) {
handle.addChecksums(mover.getExpectedChecksums());
_checksumModule.enforcePostTransferPolicy(handle, mover.getActualChecksums());
}
handle.commit();
} finally {
handle.close();
}
completionHandler.completed(null, null);
} catch (InterruptedIOException | InterruptedException e) {
LOGGER.warn("Transfer was forcefully killed during post-processing");
mover.setTransferStatus(CacheException.DEFAULT_ERROR_CODE, "Transfer was forcefully killed");
completionHandler.failed(e, null);
} catch (CacheException e) {
LOGGER.warn("Transfer failed in post-processing: {}", e.getMessage());
mover.setTransferStatus(e.getRc(), "Post-processing failed: " + e.getMessage());
completionHandler.failed(e, null);
} catch (IOException e) {
LOGGER.warn("Transfer failed in post-processing: {}", e.toString());
mover.setTransferStatus(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Transfer failed in post-processing: " + messageOrClassName(e));
completionHandler.failed(e, null);
} catch (RuntimeException e) {
LOGGER.error("Transfer failed in post-processing. Please report this bug to support@dcache.org.", e);
mover.setTransferStatus(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Transfer failed due to unexpected exception: " + e.getMessage());
completionHandler.failed(e, null);
} catch (Throwable e) {
Thread t = Thread.currentThread();
t.getUncaughtExceptionHandler().uncaughtException(t, e);
mover.setTransferStatus(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Transfer failed due to unexpected exception: " + e.getMessage());
completionHandler.failed(e, null);
}
MoverInfoMessage moverInfoMessage = generateBillingMessage(mover, handle.getReplicaSize());
// as current thread is used to serialize the message, send finish to the door before notifying the billing.
sendFinished(mover, moverInfoMessage);
sendBillingInfo(moverInfoMessage);
}));
}
use of diskCacheV111.vehicles.MoverInfoMessage in project dcache by dCache.
the class DefaultPostTransferService method generateBillingMessage.
public MoverInfoMessage generateBillingMessage(Mover<?> mover, long fileSize) {
FileAttributes fileAttributes = mover.getFileAttributes();
MoverInfoMessage info = new MoverInfoMessage(getCellAddress(), fileAttributes.getPnfsId());
info.setSubject(mover.getSubject());
info.setInitiator(mover.getInitiator());
info.setFileCreated(mover.getIoMode().contains(StandardOpenOption.WRITE));
info.setStorageInfo(fileAttributes.getStorageInfo());
info.setP2P(mover.isPoolToPoolTransfer());
info.setFileSize(fileSize);
info.setResult(mover.getErrorCode(), mover.getErrorMessage());
info.setTransferAttributes(mover.getBytesTransferred(), mover.getTransferTime(), mover.getProtocolInfo());
info.setBillingPath(mover.getBillingPath());
info.setTransferPath(mover.getTransferPath());
MoverInfoMessage infoWithStats = mover.getChannel().flatMap(c -> c.optionallyAs(IoStatisticsChannel.class)).map(c -> c.getStatistics()).map(s -> updateIoStatistics(info, s)).orElse(info);
return infoWithStats;
}
use of diskCacheV111.vehicles.MoverInfoMessage in project dcache by dCache.
the class DefaultPostTransferService method sendFinished.
public void sendFinished(Mover<?> mover, MoverInfoMessage moverInfoMessage) {
DoorTransferFinishedMessage finished = new DoorTransferFinishedMessage(mover.getClientId(), mover.getFileAttributes().getPnfsId(), mover.getProtocolInfo(), mover.getFileAttributes(), _poolName, mover.getQueueName());
finished.setMoverInfo(moverInfoMessage);
if (mover.getErrorCode() == 0) {
finished.setSucceeded();
} else {
finished.setReply(mover.getErrorCode(), mover.getErrorMessage());
}
_door.notify(mover.getPathToDoor(), finished);
}
Aggregations