Search in sources :

Example 1 with DoorRequestInfoMessage

use of diskCacheV111.vehicles.DoorRequestInfoMessage 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 2 with DoorRequestInfoMessage

use of diskCacheV111.vehicles.DoorRequestInfoMessage in project dcache by dCache.

the class Storage method putDone.

@Override
public void putDone(SRMUser user, String localTransferPath, URI surl, boolean overwrite) throws SRMException {
    try {
        Subject subject = asDcacheUser(user).getSubject();
        Restriction restriction = asDcacheUser(user).getRestriction();
        FsPath fullPath = getPath(surl);
        checkNonBrokenUpload(localTransferPath);
        EnumSet<CreateOption> options = EnumSet.noneOf(CreateOption.class);
        if (overwrite) {
            options.add(CreateOption.OVERWRITE_EXISTING);
        }
        PnfsCommitUpload msg = new PnfsCommitUpload(subject, restriction, FsPath.create(localTransferPath), fullPath, options, EnumSet.of(PNFSID, SIZE, STORAGEINFO));
        msg = _pnfsStub.sendAndWait(msg);
        DoorRequestInfoMessage infoMsg = new DoorRequestInfoMessage(getCellAddress());
        infoMsg.setSubject(subject);
        infoMsg.setBillingPath(fullPath.toString());
        infoMsg.setTransferPath(localTransferPath);
        infoMsg.setTransaction(CDC.getSession());
        infoMsg.setPnfsId(msg.getFileAttributes().getPnfsId());
        infoMsg.setResult(0, "");
        infoMsg.setFileSize(msg.getFileAttributes().getSizeIfPresent().orElse(0L));
        infoMsg.setStorageInfo(msg.getFileAttributes().getStorageInfo());
        Origin origin = Subjects.getOrigin(subject);
        if (origin != null) {
            infoMsg.setClient(origin.getAddress().getHostAddress());
        }
        _billingStub.notify(infoMsg);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException(e.getMessage(), e);
    } catch (FileIsNewCacheException | FileCorruptedCacheException e) {
        throw new SRMException(e.getMessage(), e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied.", e);
    } catch (FileExistsCacheException e) {
        throw new SRMDuplicationException(surl + " exists.", e);
    } catch (CacheException e) {
        throw new SRMInternalErrorException(e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("Operation interrupted", e);
    } catch (NoRouteToCellException e) {
        throw new SRMInternalErrorException("Internal communication failure", e);
    }
}
Also used : DoorRequestInfoMessage(diskCacheV111.vehicles.DoorRequestInfoMessage) Origin(org.dcache.auth.Origin) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) Subject(javax.security.auth.Subject) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) Restriction(org.dcache.auth.attributes.Restriction) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) CreateOption(org.dcache.namespace.CreateOption) PnfsCommitUpload(diskCacheV111.vehicles.PnfsCommitUpload) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException) FsPath(diskCacheV111.util.FsPath)

Example 3 with DoorRequestInfoMessage

use of diskCacheV111.vehicles.DoorRequestInfoMessage in project dcache by dCache.

the class Storage method abortPut.

@Override
public void abortPut(SRMUser user, String localTransferPath, URI surl, String reason) throws SRMException {
    try {
        if (localTransferPath.startsWith("/")) {
            // safe-guard against incompatible file id from earlier versions
            Subject subject = (user == null) ? Subjects.ROOT : asDcacheUser(user).getSubject();
            Restriction restriction = (user == null) ? Restrictions.none() : asDcacheUser(user).getRestriction();
            FsPath actualPnfsPath = getPath(surl);
            PnfsCancelUpload msg = new PnfsCancelUpload(subject, restriction, FsPath.create(localTransferPath), actualPnfsPath, EnumSet.noneOf(FileAttribute.class), "SRM upload aborted: " + reason);
            _pnfsStub.sendAndWait(msg);
            DoorRequestInfoMessage infoMsg = new DoorRequestInfoMessage(getCellAddress());
            infoMsg.setSubject(subject);
            infoMsg.setBillingPath(actualPnfsPath.toString());
            infoMsg.setTransaction(CDC.getSession());
            infoMsg.setPnfsId(msg.getPnfsId());
            infoMsg.setResult(CacheException.DEFAULT_ERROR_CODE, reason);
            Origin origin = Subjects.getOrigin(subject);
            if (origin != null) {
                infoMsg.setClient(origin.getAddress().getHostAddress());
            }
            _billingStub.notify(infoMsg);
        }
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied.", e);
    } catch (CacheException e) {
        throw new SRMInternalErrorException(e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("Operation interrupted", e);
    } catch (NoRouteToCellException e) {
        throw new SRMInternalErrorException("Communication failure", e);
    }
}
Also used : DoorRequestInfoMessage(diskCacheV111.vehicles.DoorRequestInfoMessage) Origin(org.dcache.auth.Origin) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) PnfsCancelUpload(diskCacheV111.vehicles.PnfsCancelUpload) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) Subject(javax.security.auth.Subject) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) Restriction(org.dcache.auth.attributes.Restriction) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) FsPath(diskCacheV111.util.FsPath) FileAttribute(org.dcache.namespace.FileAttribute)

Example 4 with DoorRequestInfoMessage

use of diskCacheV111.vehicles.DoorRequestInfoMessage in project dcache by dCache.

the class AbstractFtpDoorV1 method sendRemoveInfoToBilling.

private void sendRemoveInfoToBilling(PnfsId pnfsId, FsPath path) {
    DoorRequestInfoMessage infoRemove = new DoorRequestInfoMessage(_cellAddress, "remove");
    infoRemove.setSubject(_subject);
    infoRemove.setBillingPath(path.toString());
    infoRemove.setPnfsId(pnfsId);
    infoRemove.setClient(_clientDataAddress.getAddress().getHostAddress());
    _billingStub.notify(infoRemove);
    if (_settings.isKafkaEnabled()) {
        _kafkaProducer.send(new ProducerRecord<String, DoorRequestInfoMessage>("billing", infoRemove), (rm, e) -> {
            if (e != null) {
                LOGGER.error("Unable to send message to topic {} on  partition {}: {}", rm.topic(), rm.partition(), e.getMessage());
            }
        });
    }
}
Also used : DoorRequestInfoMessage(diskCacheV111.vehicles.DoorRequestInfoMessage)

Example 5 with DoorRequestInfoMessage

use of diskCacheV111.vehicles.DoorRequestInfoMessage in project dcache by dCache.

the class Transfer method notifyBilling.

/**
 * Sends billing information to the billing cell. Any invocation beyond the first is ignored.
 *
 * @param code  The error code of the transfer; zero indicates success
 * @param error The error string of the transfer; may be empty
 */
public synchronized void notifyBilling(int code, String error) {
    if (_isBillingNotified) {
        return;
    }
    DoorRequestInfoMessage msg = new DoorRequestInfoMessage(_cellAddress);
    msg.setSubject(_subject);
    msg.setBillingPath(getBillingPath());
    msg.setTransferPath(getTransferPath());
    msg.setTransactionDuration(System.currentTimeMillis() - _startedAt);
    msg.setTransaction(getTransaction());
    String chain = _clientAddresses.stream().map(InetSocketAddress::getAddress).map(InetAddress::getHostAddress).collect(Collectors.joining(","));
    msg.setClientChain(chain);
    msg.setClient(_clientAddresses.get(0).getAddress().getHostAddress());
    msg.setPnfsId(getPnfsId());
    if (_fileAttributes.isDefined(SIZE)) {
        msg.setFileSize(_fileAttributes.getSize());
    }
    msg.setResult(code, error);
    if (_fileAttributes.isDefined(STORAGEINFO)) {
        msg.setStorageInfo(_fileAttributes.getStorageInfo());
    }
    _billing.notify(msg);
    _isBillingNotified = true;
    msg.setMoverInfo(moverInfoMessage);
    _kafkaSender.accept(msg);
}
Also used : DoorRequestInfoMessage(diskCacheV111.vehicles.DoorRequestInfoMessage) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

DoorRequestInfoMessage (diskCacheV111.vehicles.DoorRequestInfoMessage)8 Subject (javax.security.auth.Subject)4 Origin (org.dcache.auth.Origin)3 CacheException (diskCacheV111.util.CacheException)2 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)2 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)2 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)2 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)2 FsPath (diskCacheV111.util.FsPath)2 NotDirCacheException (diskCacheV111.util.NotDirCacheException)2 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)2 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)2 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)2 Restriction (org.dcache.auth.attributes.Restriction)2 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)2 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)2 PnfsId (diskCacheV111.util.PnfsId)1 MoverInfoMessage (diskCacheV111.vehicles.MoverInfoMessage)1 PnfsCancelUpload (diskCacheV111.vehicles.PnfsCancelUpload)1 PnfsCommitUpload (diskCacheV111.vehicles.PnfsCommitUpload)1