Search in sources :

Example 1 with MoverInfoMessage

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;
}
Also used : JSONObject(org.json.JSONObject) InetSocketAddress(java.net.InetSocketAddress) JSONArray(org.json.JSONArray) IpProtocolInfo(diskCacheV111.vehicles.IpProtocolInfo)

Example 2 with MoverInfoMessage

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);
}
Also used : MoverInfoMessage(diskCacheV111.vehicles.MoverInfoMessage) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) StorageInfo(diskCacheV111.vehicles.StorageInfo)

Example 3 with MoverInfoMessage

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);
    }));
}
Also used : MoverInfoMessage(diskCacheV111.vehicles.MoverInfoMessage) ReplicaDescriptor(org.dcache.pool.repository.ReplicaDescriptor) CacheException(diskCacheV111.util.CacheException) FireAndForgetTask(org.dcache.util.FireAndForgetTask) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 4 with 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;
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) CellInfoProvider(dmg.cells.nucleus.CellInfoProvider) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) DoorTransferFinishedMessage(diskCacheV111.vehicles.DoorTransferFinishedMessage) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) IoStatistics(org.dcache.pool.statistics.IoStatistics) InterruptedIOException(java.io.InterruptedIOException) Exceptions.messageOrClassName(org.dcache.util.Exceptions.messageOrClassName) CacheException(diskCacheV111.util.CacheException) CellStub(org.dcache.cells.CellStub) MoverInfoMessage(diskCacheV111.vehicles.MoverInfoMessage) KafkaTemplate(org.springframework.kafka.core.KafkaTemplate) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ExecutorService(java.util.concurrent.ExecutorService) FileAttributes(org.dcache.vehicles.FileAttributes) Logger(org.slf4j.Logger) IoStatisticsChannel(org.dcache.pool.statistics.IoStatisticsChannel) FireAndForgetTask(org.dcache.util.FireAndForgetTask) CompletionHandler(java.nio.channels.CompletionHandler) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) Executors(java.util.concurrent.Executors) Mover(org.dcache.pool.movers.Mover) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) DirectedIoStatistics(org.dcache.pool.statistics.DirectedIoStatistics) SnapshotStatistics(org.dcache.pool.statistics.SnapshotStatistics) AbstractCellComponent(dmg.cells.nucleus.AbstractCellComponent) ReplicaDescriptor(org.dcache.pool.repository.ReplicaDescriptor) Required(org.springframework.beans.factory.annotation.Required) CDCExecutorServiceDecorator(org.dcache.util.CDCExecutorServiceDecorator) MoverInfoMessage(diskCacheV111.vehicles.MoverInfoMessage) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 5 with MoverInfoMessage

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);
}
Also used : DoorTransferFinishedMessage(diskCacheV111.vehicles.DoorTransferFinishedMessage)

Aggregations

MoverInfoMessage (diskCacheV111.vehicles.MoverInfoMessage)4 CacheException (diskCacheV111.util.CacheException)2 DoorTransferFinishedMessage (diskCacheV111.vehicles.DoorTransferFinishedMessage)2 StorageInfo (diskCacheV111.vehicles.StorageInfo)2 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 InetSocketAddress (java.net.InetSocketAddress)2 ReplicaDescriptor (org.dcache.pool.repository.ReplicaDescriptor)2 FireAndForgetTask (org.dcache.util.FireAndForgetTask)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 DoorRequestInfoMessage (diskCacheV111.vehicles.DoorRequestInfoMessage)1 IpProtocolInfo (diskCacheV111.vehicles.IpProtocolInfo)1 PnfsFileInfoMessage (diskCacheV111.vehicles.PnfsFileInfoMessage)1 WarningPnfsFileInfoMessage (diskCacheV111.vehicles.WarningPnfsFileInfoMessage)1 AbstractCellComponent (dmg.cells.nucleus.AbstractCellComponent)1 CellAddressCore (dmg.cells.nucleus.CellAddressCore)1 CellInfoProvider (dmg.cells.nucleus.CellInfoProvider)1