Skip to content

Commit

Permalink
Refactor render client parameters to use ParameterDelegate references…
Browse files Browse the repository at this point in the history
… so that common parameter sets can be easily shared by different clients. Add parameter parsing unit tests for each client.
  • Loading branch information
trautmane committed Nov 7, 2017
1 parent 9ee8abb commit 596e1fd
Show file tree
Hide file tree
Showing 94 changed files with 2,595 additions and 2,076 deletions.
3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package org.janelia.alignment.match;

import java.io.IOException;
import java.io.Reader;
import java.io.Serializable;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.List;

import org.janelia.alignment.json.JsonUtils;
import org.janelia.alignment.util.FileUtil;
import org.slf4j.LoggerFactory;

/**
* List of {@link OrderedCanvasIdPair} objects with a common render parameters URL template.
Expand Down Expand Up @@ -61,11 +66,36 @@ public List<OrderedCanvasIdPair> getNeighborPairs() {
return neighborPairs;
}

/**
* @return pairs object loaded from the specified file.
*/
public static RenderableCanvasIdPairs load(final String dataFile)
throws IOException, IllegalArgumentException {

final RenderableCanvasIdPairs renderableCanvasIdPairs;

final Path path = FileSystems.getDefault().getPath(dataFile).toAbsolutePath();

LOG.info("load: entry, path={}", path);

try (final Reader reader = FileUtil.DEFAULT_INSTANCE.getExtensionBasedReader(path.toString())) {
renderableCanvasIdPairs = RenderableCanvasIdPairs.fromJson(reader);
}

LOG.info("load: exit, loaded {} pairs", renderableCanvasIdPairs.size());


return renderableCanvasIdPairs;
}


public static RenderableCanvasIdPairs fromJson(final Reader json) {
return JSON_HELPER.fromJson(json);
}

private static final JsonUtils.Helper<RenderableCanvasIdPairs> JSON_HELPER =
new JsonUtils.Helper<>(RenderableCanvasIdPairs.class);

private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(RenderableCanvasIdPairs.class);

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.janelia.render.client;
package org.janelia.alignment.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
Expand All @@ -24,7 +24,7 @@
import org.slf4j.LoggerFactory;

/**
* Utility for reading and writing files.
* Shared file management utilities.
*
* @author Eric Trautman
*/
Expand Down Expand Up @@ -110,7 +110,33 @@ public static void ensureWritableDirectory(final File directory) {
}
}

public static boolean deleteRecursive(final File file) {

// could use Apache Commons FileUtils.delete but to have the logging, need to implement here

boolean deleteSuccessful = true;

if (file.isDirectory()){
final File[] files = file.listFiles();
if (files != null) {
for (final File f : files) {
deleteSuccessful = deleteSuccessful && deleteRecursive(f);
}
}
}

if (file.delete()) {
LOG.info("deleted " + file.getAbsolutePath());
} else {
LOG.warn("failed to delete " + file.getAbsolutePath());
deleteSuccessful = false;
}

return deleteSuccessful;
}

private static final Logger LOG = LoggerFactory.getLogger(FileUtil.class);

private static final int DEFAULT_BUFFER_SIZE = 65536;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.janelia.alignment.spec.ChannelSpec;
import org.janelia.alignment.spec.TileSpec;
import org.janelia.alignment.util.FileUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -38,7 +39,7 @@ public void setUp() throws Exception {

@After
public void tearDown() throws Exception {
deleteRecursive(baseMipmapDirectory);
FileUtil.deleteRecursive(baseMipmapDirectory);
}

@Test
Expand Down Expand Up @@ -125,29 +126,6 @@ private void validateMask(final ChannelSpec channelSpec,
}
}

private static boolean deleteRecursive(final File file) {

boolean deleteSuccessful = true;

if (file.isDirectory()){
final File[] files = file.listFiles();
if (files != null) {
for (final File f : files) {
deleteSuccessful = deleteSuccessful && deleteRecursive(f);
}
}
}

if (file.delete()) {
LOG.info("deleted " + file.getAbsolutePath());
} else {
LOG.warn("failed to delete " + file.getAbsolutePath());
deleteSuccessful = false;
}

return deleteSuccessful;
}

private static final Logger LOG = LoggerFactory.getLogger(MipmapGeneratorTest.class);

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import org.janelia.alignment.ArgbRenderer;
import org.janelia.alignment.RenderParameters;
import org.janelia.alignment.util.FileUtil;
import org.janelia.alignment.Utils;
import org.janelia.alignment.spec.Bounds;
import org.janelia.alignment.util.LabelImageProcessorCache;
Expand Down Expand Up @@ -85,7 +86,8 @@ public void setup() throws Exception {

@After
public void tearDown() throws Exception {
deleteRecursive(testDirectory);

FileUtil.deleteRecursive(testDirectory);
}

@Test
Expand Down Expand Up @@ -219,29 +221,5 @@ private BoxMipmapGenerator validateNextLevel(final BoxMipmapGenerator boxMipmapG
return nextLevelGenerator;
}

// TODO: replace with Apache Commons FileUtils.delete
public static boolean deleteRecursive(final File file) {

boolean deleteSuccessful = true;

if (file.isDirectory()){
final File[] files = file.listFiles();
if (files != null) {
for (final File f : files) {
deleteSuccessful = deleteSuccessful && deleteRecursive(f);
}
}
}

if (file.delete()) {
LOG.info("deleted " + file.getAbsolutePath());
} else {
LOG.warn("failed to delete " + file.getAbsolutePath());
deleteSuccessful = false;
}

return deleteSuccessful;
}

private static final Logger LOG = LoggerFactory.getLogger(BoxMipmapGeneratorTest.class);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
package org.janelia.acquire.client;

import com.beust.jcommander.Parameter;
import org.janelia.acquire.client.model.*;
import com.beust.jcommander.ParametersDelegate;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.janelia.acquire.client.model.Acquisition;
import org.janelia.acquire.client.model.AcquisitionTile;
import org.janelia.acquire.client.model.AcquisitionTileIdList;
import org.janelia.acquire.client.model.AcquisitionTileList;
import org.janelia.acquire.client.model.AcquisitionTileState;
import org.janelia.acquire.client.model.Calibration;
import org.janelia.alignment.spec.ResolvedTileSpecCollection;
import org.janelia.alignment.spec.TileSpec;
import org.janelia.alignment.spec.TransformSpec;
Expand All @@ -12,25 +28,26 @@
import org.janelia.render.client.ClientRunner;
import org.janelia.render.client.ImportJsonClient;
import org.janelia.render.client.RenderDataClient;
import org.janelia.render.client.RenderDataClientParametersWithValidator;
import org.janelia.render.client.parameter.CommandLineParameters;
import org.janelia.render.client.parameter.RenderWebServiceParameters;
import org.janelia.render.client.parameter.TileSpecValidatorParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.*;

/**
* Java client that pulls tile data from an acquisition system and stores it in the render database.
*
* @author Cristian Goina (based on Eric Trautman's LowLatencyMontageClient)
*/
public class AcquisitionDataImportClient {

@SuppressWarnings("ALL")
static class Parameters extends RenderDataClientParametersWithValidator {
public static class Parameters extends CommandLineParameters {

@ParametersDelegate
RenderWebServiceParameters renderWeb = new RenderWebServiceParameters();

// NOTE: --baseDataUrl, --owner, --project, --validatorClass, and --validatorData parameters defined in RenderDataClientParameters
// NOTE: --validatorClass and --validatorData parameters defined in RenderDataClientParametersWithValidator
@ParametersDelegate
TileSpecValidatorParameters tileSpecValidator = new TileSpecValidatorParameters();

@Parameter(names = "--finalStackState", description = "State render stack should have after import (default is COMPLETE)", required = false)
StackMetaData.StackState finalStackState;
Expand Down Expand Up @@ -85,7 +102,7 @@ public static void main(final String[] args) {
@Override
public void runClient(final String[] args) throws Exception {
final Parameters parameters = new Parameters();
parameters.parse(args, AcquisitionDataImportClient.class);
parameters.parse(args);

LOG.info("runClient: entry, parameters={}", parameters);

Expand Down Expand Up @@ -121,7 +138,7 @@ public void runClient(final String[] args) throws Exception {
public AcquisitionDataImportClient(final Parameters parameters)
throws IOException {
this.parameters = parameters;
this.tileSpecValidator = parameters.getValidatorInstance();
this.tileSpecValidator = parameters.tileSpecValidator.getValidatorInstance();

this.acquisitionDataClient = new AcquisitionDataClient(parameters.baseAcquisitionUrl);

Expand Down Expand Up @@ -199,7 +216,7 @@ public void processAcquisition(final Acquisition acquisition) {
try {
String ownerName = acquisition.getProjectOwner();
if (parameters.overrideOwnerFromParameter) {
ownerName = parameters.owner;
ownerName = parameters.renderWeb.owner;
}
if (ownerName == null || ownerName.trim().length() == 0) {
throw new IllegalArgumentException("Owner for acquisition " + acqId + " is null");
Expand All @@ -218,7 +235,7 @@ public void processAcquisition(final Acquisition acquisition) {

final String acquireStackName = baseStackName + "_acquire";

final RenderDataClient renderDataClient = new RenderDataClient(parameters.baseDataUrl,
final RenderDataClient renderDataClient = new RenderDataClient(parameters.renderWeb.baseDataUrl,
ownerName,
projectName);

Expand Down
Loading

0 comments on commit 596e1fd

Please sign in to comment.