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);
}
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);
}
}
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);
}
}
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());
}
});
}
}
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);
}
Aggregations