Search in sources :

Example 31 with InstanceLocations

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);
    }
}
Also used : InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) Transcoder(org.dcm4che3.imageio.codec.Transcoder) ArchiveAttributeCoercion(org.dcm4chee.arc.conf.ArchiveAttributeCoercion) IOException(java.io.IOException) RetrieveService(org.dcm4chee.arc.retrieve.RetrieveService) ArchiveAttributeCoercion2(org.dcm4chee.arc.conf.ArchiveAttributeCoercion2) AttributesCoercion(org.dcm4che3.data.AttributesCoercion)

Example 32 with InstanceLocations

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);
}
Also used : InstanceLocations(org.dcm4chee.arc.store.InstanceLocations)

Example 33 with InstanceLocations

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();
    }
}
Also used : InstanceLocations(org.dcm4chee.arc.store.InstanceLocations)

Example 34 with InstanceLocations

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);
        }
    }
}
Also used : InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) LoggerFactory(org.slf4j.LoggerFactory) ArchiveAEExtension(org.dcm4chee.arc.conf.ArchiveAEExtension) ExportContext(org.dcm4chee.arc.exporter.ExportContext) StoreService(org.dcm4chee.arc.store.StoreService) HashSet(java.util.HashSet) Map(java.util.Map) AbstractExporter(org.dcm4chee.arc.exporter.AbstractExporter) StoreSession(org.dcm4chee.arc.store.StoreSession) Logger(org.slf4j.Logger) Task(org.dcm4chee.arc.entity.Task) RetrieveService(org.dcm4chee.arc.retrieve.RetrieveService) WriteContext(org.dcm4chee.arc.storage.WriteContext) Set(java.util.Set) IOException(java.io.IOException) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) Collectors(java.util.stream.Collectors) Location(org.dcm4chee.arc.entity.Location) ExporterDescriptor(org.dcm4chee.arc.conf.ExporterDescriptor) List(java.util.List) Tag(org.dcm4che3.data.Tag) Outcome(org.dcm4chee.arc.qmgt.Outcome) LocationInputStream(org.dcm4chee.arc.retrieve.LocationInputStream) StorageFactory(org.dcm4chee.arc.storage.StorageFactory) RetrieveContext(org.dcm4chee.arc.retrieve.RetrieveContext) Storage(org.dcm4chee.arc.storage.Storage) RetrieveContext(org.dcm4chee.arc.retrieve.RetrieveContext) IOException(java.io.IOException) WriteContext(org.dcm4chee.arc.storage.WriteContext) Storage(org.dcm4chee.arc.storage.Storage) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) Outcome(org.dcm4chee.arc.qmgt.Outcome) List(java.util.List) StoreSession(org.dcm4chee.arc.store.StoreSession) HashSet(java.util.HashSet) Location(org.dcm4chee.arc.entity.Location)

Aggregations

InstanceLocations (org.dcm4chee.arc.store.InstanceLocations)34 IOException (java.io.IOException)8 RetrieveContext (org.dcm4chee.arc.retrieve.RetrieveContext)7 StoreService (org.dcm4chee.arc.store.StoreService)6 DicomServiceException (org.dcm4che3.net.service.DicomServiceException)5 ArchiveAEExtension (org.dcm4chee.arc.conf.ArchiveAEExtension)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 ZipEntry (java.util.zip.ZipEntry)4 Event (javax.enterprise.event.Event)4 Inject (javax.inject.Inject)4 Attributes (org.dcm4che3.data.Attributes)4 HttpServletRequestInfo (org.dcm4chee.arc.keycloak.HttpServletRequestInfo)4 StoreSession (org.dcm4chee.arc.store.StoreSession)4 Map (java.util.Map)3 ZipOutputStream (java.util.zip.ZipOutputStream)3 Tag (org.dcm4che3.data.Tag)3 DicomInputStream (org.dcm4che3.io.DicomInputStream)3