Skip to content

Commit

Permalink
RESTful Service : List configured Storage systems should only fetch u…
Browse files Browse the repository at this point in the history
…sed/free space for storage systems which match the specified filter fix #1378
  • Loading branch information
gunterze committed May 8, 2018
1 parent 05325e0 commit 0e46a77
Showing 1 changed file with 53 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.dcm4che3.conf.json.JsonWriter;
import org.dcm4che3.net.ApplicationEntity;
import org.dcm4che3.net.Device;
import org.dcm4che3.util.StringUtils;
import org.dcm4chee.arc.conf.ArchiveAEExtension;
import org.dcm4chee.arc.conf.ArchiveDeviceExtension;
import org.dcm4chee.arc.conf.DeleterThreshold;
Expand All @@ -69,6 +70,8 @@
import java.io.IOException;
import java.util.*;

import static org.dcm4che3.util.StringUtils.contains;

/**
* @author Vrinda Nayak <vrinda.nayak@j4care.com>
* @since May 2017
Expand Down Expand Up @@ -126,8 +129,8 @@ public StreamingOutput search() {
writer.writeNotNullOrDef("dcmExternalRetrieveAET", desc.getExternalRetrieveAETitle(), null);
writer.writeNotNullOrDef("dcmExportStorageID", desc.getExportStorageID(), null);
writer.writeNotEmpty("dcmProperty", descriptorProperties(desc.getProperties()));
writer.writeNotEmpty("dicomAETitle", ss.aets.stream().sorted().toArray(String[]::new));
writer.writeNotEmpty("usages", ss.usages.toArray(new String[ss.usages.size()]));
writer.writeNotEmpty("dicomAETitle", ss.aets);
writer.writeNotEmpty("usages", ss.usages);
if (ss.usableSpace > 0L)
gen.write("usableSpace", ss.usableSpace);
if (ss.usableSpace > 0L)
Expand Down Expand Up @@ -160,72 +163,67 @@ private void writeDeleterThresholds(JsonWriter writer, JsonGenerator gen, List<D
}

private List<StorageSystem> getStorageSystems() {
List<StorageSystem> storageSystems = new ArrayList<>();
if (dicomAETitle != null) {
ApplicationEntity ae = device.getApplicationEntity(dicomAETitle, true);
if (ae == null || !ae.isInstalled()) {
LOG.info("Dicom AE Title in query param is not installed : " + dicomAETitle);
return storageSystems;
LOG.info("Archive AE {} not provided by Device {}", dicomAETitle, device.getDeviceName());
return Collections.EMPTY_LIST;
}
}
for (StorageDescriptor desc : sortedStorageDescriptors())
storageSystems.add(new StorageSystem(desc));
storageSystems.removeIf(ss -> (usableSpaceBelow != null && ss.usableSpace > usableSpaceBelow)
|| (dicomAETitle != null && !ss.aets.contains(dicomAETitle))
|| (usage != null && !ss.usages.contains(usage))
|| (uriScheme != null && !ss.desc.getStorageURI().getScheme().equals(uriScheme)));
return storageSystems;
}

private StorageDescriptor[] sortedStorageDescriptors() {
return device.getDeviceExtension(ArchiveDeviceExtension.class).getStorageDescriptors()
.stream()
.sorted(Comparator.comparing(StorageDescriptor::getStorageID))
.toArray(StorageDescriptor[]::new);
}

class StorageSystem {
private StorageDescriptor desc;
private long usableSpace;
private long totalSpace;
private Set<String> usages = new HashSet<>();
private Set<String> aets = new HashSet<>();

StorageSystem(StorageDescriptor desc) {
this.desc = desc;
getSpaceInfo(desc);
getAETsAndUsages(desc);
}

void getSpaceInfo(StorageDescriptor desc) {
try (Storage storage = storageFactory.getStorage(desc)) {
if (storage.getUsableSpace() != -1)
usableSpace = storage.getUsableSpace();
if (storage.getTotalSpace() != -1)
totalSpace = storage.getTotalSpace();
} catch (IOException e) {
LOG.warn("Failed to access {}", desc, e);
List<StorageSystem> storageSystems = new ArrayList<>();
ArchiveDeviceExtension arcdev = device.getDeviceExtensionNotNull(ArchiveDeviceExtension.class);
for (StorageDescriptor desc : arcdev.getStorageDescriptors()) {
String storageID = desc.getStorageID();
Set<String> usages = new HashSet<>();
Set<String> aets = new HashSet<>();
if (contains(arcdev.getSeriesMetadataStorageIDs(), storageID)) {
usages.add("dcmSeriesMetadataStorageID");
}
}

void getAETsAndUsages(StorageDescriptor desc) {
for (String aet : device.getApplicationAETitles()) {
ApplicationEntity ae = device.getApplicationEntity(aet);
for (ApplicationEntity ae : device.getApplicationEntities()) {
ArchiveAEExtension arcAE = ae.getAEExtension(ArchiveAEExtension.class);
if (Arrays.asList(arcAE.getObjectStorageIDs()).contains(desc.getStorageID())) {
if (contains(arcAE.getObjectStorageIDs(), desc.getStorageID())) {
usages.add("dcmObjectStorageID");
aets.add(aet);
aets.add(ae.getAETitle());
}
if (Arrays.asList(arcAE.getMetadataStorageIDs()).contains(desc.getStorageID())) {
if (contains(arcAE.getMetadataStorageIDs(), desc.getStorageID())) {
usages.add("dcmMetadataStorageID");
aets.add(aet);
aets.add(ae.getAETitle());
}
}
if ((dicomAETitle == null || aets.contains(dicomAETitle))
&& (usage == null || usages.contains(usage))
&& (uriScheme == null || desc.getStorageURI().getScheme().equals(uriScheme))) {
try (Storage storage = storageFactory.getStorage(desc)) {
long usableSpace = storage.getUsableSpace();
long totalSpace = storage.getTotalSpace();
if (usableSpaceBelow == null || usableSpace < usableSpaceBelow) {
storageSystems.add(new StorageSystem(desc, usableSpace, totalSpace, usages, aets));
}
} catch (IOException e) {
LOG.warn("Failed to access {}", desc, e);
}
}
ArchiveDeviceExtension arcDev = device.getDeviceExtension(ArchiveDeviceExtension.class);
for (String seriesMetadataStorageID : arcDev.getSeriesMetadataStorageIDs())
if (arcDev.getStorageDescriptor(seriesMetadataStorageID).getStorageID().equals(desc.getStorageID()))
usages.add("dcmSeriesMetadataStorageID");
}
Collections.sort(storageSystems, Comparator.comparing(storageSystem -> storageSystem.desc.getStorageID()));
return storageSystems;
}

class StorageSystem {
final StorageDescriptor desc;
final long usableSpace;
final long totalSpace;
final String[] usages;
final String[] aets;

StorageSystem(StorageDescriptor desc, long usableSpace, long totalSpace,
Collection<String> usages, Collection<String> aets) {
this.desc = desc;
this.usableSpace = usableSpace;
this.totalSpace = totalSpace;
this.usages = usages.toArray(StringUtils.EMPTY_STRING);
this.aets = aets.toArray(StringUtils.EMPTY_STRING);
Arrays.sort(this.usages);
Arrays.sort(this.aets);
}
}
}

0 comments on commit 0e46a77

Please sign in to comment.