use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.
the class CStoreForwardTask method store.
private void store(StoreContext storeCtx) {
InstanceLocations inst = createInstanceLocations(storeCtx);
ctx.addCStoreForward(inst);
String cuid = inst.getSopClassUID();
String iuid = inst.getSopInstanceUID();
Set<String> tsuids = storeas.getTransferSyntaxesFor(cuid);
try {
if (tsuids.isEmpty()) {
throw new NoPresentationContextException(cuid);
}
RetrieveService service = ctx.getRetrieveService();
try (Transcoder transcoder = service.openTranscoder(ctx, inst, tsuids, false)) {
String tsuid = transcoder.getDestinationTransferSyntax();
AttributesCoercion coerce;
List<ArchiveAttributeCoercion2> coercions = service.getArchiveAttributeCoercions(ctx, inst);
if (coercions.isEmpty()) {
ArchiveAttributeCoercion rule = service.getArchiveAttributeCoercion(ctx, inst);
if (rule != null) {
transcoder.setNullifyPixelData(rule.isNullifyPixelData());
}
coerce = service.getAttributesCoercion(ctx, inst, rule);
} else {
transcoder.setNullifyPixelData(ArchiveAttributeCoercion2.containsScheme(coercions, ArchiveAttributeCoercion2.NULLIFY_PIXEL_DATA));
coerce = service.getAttributesCoercion(ctx, inst, coercions);
}
TranscoderDataWriter data = new TranscoderDataWriter(transcoder, coerce);
DimseRSPHandler rspHandler = new CStoreRSPHandler(inst);
long startTime = System.nanoTime();
storeas.cstore(cuid, iuid, ctx.getPriority(), ctx.getMoveOriginatorAETitle(), ctx.getMoveOriginatorMessageID(), data, tsuid, rspHandler);
service.getMetricsService().acceptDataRate("send-to-" + storeas.getRemoteAET(), data.getCount(), startTime);
}
} catch (Exception e) {
ctx.incrementFailed();
ctx.addFailedSOPInstanceUID(iuid);
LOG.info("{}: failed to send {} to {}:", rqas, inst, ctx.getDestinationAETitle(), e);
}
}
use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.
the class RetrieveTaskImpl method run.
@Override
public void run() {
retrieveStart.fire(ctx);
try {
if (ctx.getFallbackAssociation() == null)
startWritePendingRSP();
if (storeass.length > 1)
startStoreOperations();
for (InstanceLocations match : ctx.getMatches()) {
if (!ctx.copyToRetrieveCache(match)) {
matches.offer(new WrappedInstanceLocations(match));
}
}
ctx.copyToRetrieveCache(null);
if (storeass.length == 1) {
matches.offer(new WrappedInstanceLocations(null));
runStoreOperations(storeass[0]);
} else {
InstanceLocations match;
while ((match = ctx.copiedToRetrieveCache()) != null && !canceled) {
matches.offer(new WrappedInstanceLocations(match));
}
for (int i = 0; i < storeass.length; i++) {
matches.offer(new WrappedInstanceLocations(null));
}
}
waitForPendingStoreOperations();
} finally {
waitForPendingCMoveForward();
waitForPendingCStoreForward();
updateCompleteness();
ctx.getRetrieveService().updateLocations(ctx);
ctx.getRetrieveService().updateInstanceAvailability(ctx);
ctx.stopWritePendingRSP();
if (rqas != null) {
writeFinalRSP();
rqas.removeCancelRQHandler(msgId);
}
SafeClose.close(ctx);
}
retrieveEnd.fire(ctx);
}
use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.
the class RetrieveTaskImpl method runStoreOperations.
private void runStoreOperations(Association storeas) {
Collection<InstanceLocations> outstandingRSPs = Collections.synchronizedList(new ArrayList<>());
try {
InstanceLocations match = null;
while (!canceled && (match = matches.take().instanceLocations) != null) {
store(match, storeas, outstandingRSPs);
waitForNonBlockingInvoke(storeas);
}
while (!canceled && (match = ctx.copiedToRetrieveCache()) != null) {
store(match, storeas, outstandingRSPs);
}
} catch (InterruptedException e) {
LOG.warn("{}: failed to fetch next match from queue:\n", rqas, e);
} finally {
waitForOutstandingCStoreRSP(storeas, outstandingRSPs);
releaseStoreAssociation(storeas);
doneSignal.countDown();
}
}
use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.
the class StorageExporter method export.
@Override
public Outcome export(ExportContext exportContext) throws Exception {
String studyIUID = exportContext.getStudyInstanceUID();
try (RetrieveContext retrieveContext = retrieveService.newRetrieveContext(exportContext.getAETitle(), studyIUID, exportContext.getSeriesInstanceUID(), exportContext.getSopInstanceUID())) {
retrieveContext.setHttpServletRequestInfo(exportContext.getHttpServletRequestInfo());
String storageID = descriptor.getExportURI().getSchemeSpecificPart();
ApplicationEntity ae = retrieveContext.getLocalApplicationEntity();
StoreSession storeSession = storeService.newStoreSession(ae).withObjectStorageID(storageID);
storeService.restoreInstances(storeSession, studyIUID, exportContext.getSeriesInstanceUID(), ae.getAEExtensionNotNull(ArchiveAEExtension.class).purgeInstanceRecordsDelay());
if (!retrieveService.calculateMatches(retrieveContext))
return new Outcome(Task.Status.WARNING, noMatches(exportContext));
try {
Set<String> seriesIUIDs = new HashSet<>();
Storage storage = retrieveService.getStorage(storageID, retrieveContext);
retrieveContext.setDestinationStorage(storage.getStorageDescriptor());
for (InstanceLocations instanceLocations : retrieveContext.getMatches()) {
Map<Boolean, List<Location>> locationsOnStorageByStatusOK = instanceLocations.getLocations().stream().filter(l -> l.getStorageID().equals(storageID)).collect(Collectors.partitioningBy(Location::isStatusOK));
if (!locationsOnStorageByStatusOK.get(Boolean.TRUE).isEmpty()) {
retrieveContext.setNumberOfMatches(retrieveContext.getNumberOfMatches() - 1);
continue;
}
WriteContext writeCtx = storage.createWriteContext();
writeCtx.setAttributes(instanceLocations.getAttributes());
writeCtx.setStudyInstanceUID(studyIUID);
Location location = null;
try {
LOG.debug("Start copying {} to {}:\n", instanceLocations, storage.getStorageDescriptor());
location = copyTo(retrieveContext, instanceLocations, storage, writeCtx);
storeService.replaceLocation(storeSession, instanceLocations.getInstancePk(), location, locationsOnStorageByStatusOK.get(Boolean.FALSE));
storage.commitStorage(writeCtx);
retrieveContext.incrementCompleted();
LOG.debug("Finished copying {} to {}:\n", instanceLocations, storage.getStorageDescriptor());
seriesIUIDs.add(instanceLocations.getAttributes().getString(Tag.SeriesInstanceUID));
} catch (Exception e) {
LOG.warn("Failed to copy {} to {}:\n", instanceLocations, storage.getStorageDescriptor(), e);
retrieveContext.incrementFailed();
retrieveContext.addFailedSOPInstanceUID(instanceLocations.getSopInstanceUID());
if (location != null)
try {
storage.revokeStorage(writeCtx);
} catch (Exception e2) {
LOG.warn("Failed to revoke storage", e2);
}
}
}
if (!seriesIUIDs.isEmpty()) {
storeService.addStorageID(studyIUID, storageID);
for (String seriesIUID : seriesIUIDs) {
storeService.scheduleMetadataUpdate(studyIUID, seriesIUID);
}
}
return new Outcome(retrieveContext.failed() > 0 ? Task.Status.FAILED : Task.Status.COMPLETED, outcomeMessage(exportContext, retrieveContext, retrieveContext.getDestinationStorage()));
} finally {
retrieveContext.getRetrieveService().updateLocations(retrieveContext);
}
}
}
Aggregations