Skip to content

Commit

Permalink
#259 work in progress on rule handling
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-conway committed Oct 19, 2017
1 parent 5a5f009 commit af7c896
Show file tree
Hide file tree
Showing 38 changed files with 1,385 additions and 446 deletions.
5 changes: 5 additions & 0 deletions jargon-core/.pydevproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
</pydev_project>
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ private ExecMyRuleInp(final IRODSRule irodsRule, final String host, final int po
public Tag getTagValue() throws JargonException {

List<KeyValuePair> kvps = new ArrayList<KeyValuePair>();
if (!ruleInvocationConfiguration.getRuleEngineSpecifier().isEmpty()) {
log.debug("adding rule engine instance:{}", ruleInvocationConfiguration.getRuleEngineSpecifier());
kvps.add(
KeyValuePair.instance(RULE_INSTANCE_NAME_KW, ruleInvocationConfiguration.getRuleEngineSpecifier()));
}

final Tag message = new Tag(PI_TAG,
new Tag[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ public class KeyValuePair {
private final String key;
private final String value;

public static final KeyValuePair instance(final String key,
final String value) throws JargonException {
public static final KeyValuePair instance(final String key, final String value) throws JargonException {
return new KeyValuePair(key, value);
}

private KeyValuePair(final String key, final String value)
throws JargonException {
private KeyValuePair(final String key, final String value) throws JargonException {
if (key == null) {
throw new JargonException("key is null");
}
Expand All @@ -44,4 +42,18 @@ public String getValue() {
return value;
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("KeyValuePair [");
if (key != null) {
builder.append("key=").append(key).append(", ");
}
if (value != null) {
builder.append("value=").append(value);
}
builder.append("]");
return builder.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2730,7 +2730,6 @@ public boolean verifyChecksumBetweenLocalAndIrods(final IRODSFile irodsFile, fin

}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public ChecksumValue computeChecksumOnDataObject(final IRODSFile irodsFile) throws JargonException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,6 @@ public void replicate(final String irodsFileAbsolutePath, final String targetRes
* org.irods.jargon.core.transfer.TransferStatusCallbackListener, boolean,
* org.irods.jargon.core.transfer.TransferControlBlock)
*/
@SuppressWarnings("deprecation")
@Deprecated
@Override
public void copy(final String irodsSourceFileAbsolutePath, final String targetResource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,7 @@ IRODSRuleExecResult executeRule(String irodsRuleAsString, List<IRODSRuleParamete
* @param inputParameterOverrides
* {@code List} of {@link IRODSRuleParameter} that overrides the
* parameters derived from the rule bodies.
* @param ruleProcessingType
* {@link RuleProcessingAO.RuleProcessingType} enum value. Note that
* it should be set to {@code CLASSIC} for classic rules, and
* {@code EXTERNAL} or {@code INTERNAL} for new format rules.
*
* @param ruleInvocationConfiguration
* {@link ruleInvocationConfiguration} that represents the type of
* rule engine the user wishes this rule to be run on. With multiple
Expand All @@ -213,8 +210,7 @@ IRODSRuleExecResult executeRule(String irodsRuleAsString, List<IRODSRuleParamete
* @throws JargonException
* if iRODS processing resulted in an error.
*/
IRODSRuleExecResult executeRule(String irodsRuleAsString, List<IRODSRuleParameter> inputParameterOverrides,
RuleProcessingType ruleProcessingType, final RuleInvocationConfiguration ruleInvocationConfiguration)
IRODSRuleExecResult executeRule(String irodsRuleAsString, List<IRODSRuleParameter> inputParameterOverrides, final RuleInvocationConfiguration ruleInvocationConfiguration)
throws JargonRuleException, JargonException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
import org.irods.jargon.core.rule.IRODSRuleExecResultOutputParameter;
import org.irods.jargon.core.rule.IRODSRuleExecResultOutputParameter.OutputParamType;
import org.irods.jargon.core.rule.IRODSRuleParameter;
import org.irods.jargon.core.rule.IRODSRuleTranslator;
import org.irods.jargon.core.rule.IrodsRuleEngineRuleTranslator;
import org.irods.jargon.core.rule.IrodsRuleFactory;
import org.irods.jargon.core.rule.IrodsRuleInvocationTypeEnum;
import org.irods.jargon.core.rule.JargonRuleException;
import org.irods.jargon.core.rule.RuleEngineInstanceChooser;
import org.irods.jargon.core.rule.RuleInvocationConfiguration;
import org.irods.jargon.core.transfer.TransferControlBlock;
import org.irods.jargon.core.utils.Base64;
Expand Down Expand Up @@ -193,21 +195,12 @@ public IRODSRuleExecResult executeRule(String irodsRuleAsString) throws JargonRu
log.info("executing rule: {}", irodsRuleAsString);
log.warn("using default 'AUTO' ruleInvocationConfiguration - consider setting this explicitly");
RuleInvocationConfiguration ruleInvocationConfiguration = RuleInvocationConfiguration
.instanceWithDefaultAutoSettings();
.instanceWithDefaultAutoSettings(this.getJargonProperties());

final AbstractRuleTranslator irodsRuleTranslator = new IRODSRuleTranslator(getIRODSServerProperties(),
ruleInvocationConfiguration, this.getJargonProperties());

// get
// from
// factory

/*
* if iRODS 3.0+, add the @external parameter to the rule body for new style
* rules
*/

final IRODSRule irodsRule = irodsRuleTranslator.translatePlainTextRuleIntoIRODSRule(irodsRuleAsString);
IrodsRuleFactory irodsRuleFactory = new IrodsRuleFactory(this.getIRODSAccessObjectFactory(),
this.getIRODSAccount());
final IRODSRule irodsRule = irodsRuleFactory.instanceIrodsRule(irodsRuleAsString, null,
ruleInvocationConfiguration);
log.debug("translated rule: {}", irodsRule);
final ExecMyRuleInp execMyRuleInp = ExecMyRuleInp.instance(irodsRule, ruleInvocationConfiguration);
final Tag response = getIRODSProtocol().irodsFunction(execMyRuleInp);
Expand All @@ -233,13 +226,10 @@ public IRODSRuleExecResult executeRule(final String irodsRuleAsString,

log.info("executing rule: {}", irodsRuleAsString);
log.info("with configuration:{}", ruleInvocationConfiguration);
final AbstractRuleTranslator irodsRuleTranslator = new IRODSRuleTranslator(getIRODSServerProperties(),
ruleInvocationConfiguration, this.getJargonProperties()); // FIXME:
// get
// from
// factory

final IRODSRule irodsRule = irodsRuleTranslator.translatePlainTextRuleIntoIRODSRule(irodsRuleAsString);
IrodsRuleFactory irodsRuleFactory = new IrodsRuleFactory(this.getIRODSAccessObjectFactory(),
this.getIRODSAccount());
final IRODSRule irodsRule = irodsRuleFactory.instanceIrodsRule(irodsRuleAsString, null,
ruleInvocationConfiguration);
log.debug("translated rule: {}", irodsRule);
final ExecMyRuleInp execMyRuleInp = ExecMyRuleInp.instance(irodsRule, ruleInvocationConfiguration);
final Tag response = getIRODSProtocol().irodsFunction(execMyRuleInp);
Expand All @@ -253,30 +243,31 @@ public IRODSRuleExecResult executeRule(final String irodsRuleAsString,

@Override
public IRODSRuleExecResult executeRule(String irodsRuleAsString, List<IRODSRuleParameter> inputParameterOverrides,
RuleProcessingType ruleProcessingType, final RuleInvocationConfiguration ruleInvocationConfiguration)
throws JargonRuleException, JargonException {
final RuleInvocationConfiguration ruleInvocationConfiguration) throws JargonRuleException, JargonException {
log.info("executeRule()");
if (irodsRuleAsString == null || irodsRuleAsString.isEmpty()) {
throw new IllegalArgumentException("null or empty irodsRuleAsString");
}

if (ruleProcessingType == null) {
throw new IllegalArgumentException("null ruleProcessingType");
}

if (ruleInvocationConfiguration == null) {
throw new IllegalArgumentException("null ruleInvocationConfiguration");
}

// tolerate null inputParameterOverrides

log.info("executing rule: {}", irodsRuleAsString);
final AbstractRuleTranslator irodsRuleTranslator = new IRODSRuleTranslator(getIRODSServerProperties(),
final AbstractRuleTranslator irodsRuleTranslator = new IrodsRuleEngineRuleTranslator(getIRODSServerProperties(),
ruleInvocationConfiguration, this.getJargonProperties());

final IRODSRule irodsRule = irodsRuleTranslator.translatePlainTextRuleIntoRule(irodsRuleAsString,
final IRODSRule irodsRule = irodsRuleTranslator.translatePlainTextRuleIntoIrodsRule(irodsRuleAsString,
inputParameterOverrides);
log.debug("translated rule: {}", irodsRule);

log.debug("decorating the rule with the appropriate rule engine instance");
RuleEngineInstanceChooser ruleEngineInstanceChooser = new RuleEngineInstanceChooser(this.getJargonProperties(),
this.getIRODSServerProperties());
ruleEngineInstanceChooser.decorateRuleInvocationConfugurationWithRuleEngineInstance(irodsRule);

final ExecMyRuleInp execMyRuleInp = ExecMyRuleInp.instance(irodsRule, ruleInvocationConfiguration);
final Tag response = getIRODSProtocol().irodsFunction(execMyRuleInp);
log.debug("response from rule exec: {}", response.parseTag());
Expand Down Expand Up @@ -305,7 +296,8 @@ public IRODSRuleExecResult executeRule(String irodsRuleAsString,
log.info("executeRule() with a default of AUTO_DETECT");
RuleInvocationConfiguration ruleInvocationConfiguration = new RuleInvocationConfiguration();
ruleInvocationConfiguration.setIrodsRuleInvocationTypeEnum(IrodsRuleInvocationTypeEnum.AUTO_DETECT);
return executeRule(irodsRuleAsString, inputParameterOverrides, ruleProcessingType, ruleInvocationConfiguration);
ruleInvocationConfiguration.setRuleProcessingType(ruleProcessingType);
return executeRule(irodsRuleAsString, inputParameterOverrides, ruleInvocationConfiguration);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,6 @@ private int openWithMode(final DataObjInp.OpenFlags openFlags) throws JargonExce
*
* @see org.irods.jargon.core.pub.io.IRODSFile#openReadOnly()
*/
@SuppressWarnings("deprecation")
@Override
@Deprecated
public synchronized int openReadOnly() throws JargonException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class AbstractRuleTranslator {
*/
public IRODSRule translatePlainTextRuleIntoIRODSRule(final String ruleAsPlainText)
throws JargonRuleException, JargonException {
return translatePlainTextRuleIntoRule(ruleAsPlainText, null);
return translatePlainTextRuleIntoIrodsRule(ruleAsPlainText, null);
}

/**
Expand All @@ -43,7 +43,7 @@ public IRODSRule translatePlainTextRuleIntoIRODSRule(final String ruleAsPlainTex
* @throws JargonRuleException
* @throws JargonException
*/
public abstract IRODSRule translatePlainTextRuleIntoRule(final String ruleAsPlainText,
public abstract IRODSRule translatePlainTextRuleIntoIrodsRule(final String ruleAsPlainText,
final List<IRODSRuleParameter> overrideInputParameters) throws JargonRuleException, JargonException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,6 @@ public String toString() {
return builder.toString();
}

/**
* Return an immutable instance of an {@code IRODSRule}
*
* @param ruleAsOriginalText
* {@code String} with the plain text version of the rule
* @param irodsRuleInputParameters
* {@code List<IRODSRuleParameter>} containing the translated rule
* input parameters
* @param irodsRuleOutputParameters
* {@code List<IRODSRuleParameter>} containing the translated rule
* output parameters
* @param ruleBody
* {@code String} containing the body of the rule
* @return {@code IRODSRule} containing an object model of the rule.
* @throws JargonException
*/
public static IRODSRule instance(final String ruleAsOriginalText,
final List<IRODSRuleParameter> irodsRuleInputParameters,
final List<IRODSRuleParameter> irodsRuleOutputParameters, final String ruleBody) throws JargonException {
RuleInvocationConfiguration ruleEngineConfiguration = new RuleInvocationConfiguration();
ruleEngineConfiguration.setIrodsRuleInvocationTypeEnum(IrodsRuleInvocationTypeEnum.AUTO_DETECT);
return new IRODSRule(ruleAsOriginalText, irodsRuleInputParameters, irodsRuleOutputParameters, ruleBody,
ruleEngineConfiguration);
}

/**
* Return an immutable instance of an {@code IRODSRule}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author Mike Conway - DICE (www.irods.org)
*
*/
public class IRODSRuleTranslator extends AbstractRuleTranslator {
public class IrodsRuleEngineRuleTranslator extends AbstractRuleTranslator {

Logger log = LoggerFactory.getLogger(this.getClass());

Expand All @@ -32,7 +32,7 @@ public class IRODSRuleTranslator extends AbstractRuleTranslator {
* {@link RuleInvocationConfiguration} with configuration regarding
* the type of rule and type of rule processing to be done
*/
public IRODSRuleTranslator(final IRODSServerProperties irodsServerProperties,
public IrodsRuleEngineRuleTranslator(final IRODSServerProperties irodsServerProperties,
final RuleInvocationConfiguration ruleInvocationConfiguration, final JargonProperties jargonProperties) {
super(irodsServerProperties, ruleInvocationConfiguration, jargonProperties);
}
Expand All @@ -48,7 +48,7 @@ public IRODSRuleTranslator(final IRODSServerProperties irodsServerProperties,
* @throws JargonException
*/
@Override
public IRODSRule translatePlainTextRuleIntoRule(final String ruleAsPlainText,
public IRODSRule translatePlainTextRuleIntoIrodsRule(final String ruleAsPlainText,
final List<IRODSRuleParameter> overrideInputParameters) throws JargonRuleException, JargonException {

if (ruleAsPlainText == null || ruleAsPlainText.isEmpty()) {
Expand Down Expand Up @@ -104,7 +104,7 @@ public IRODSRule translatePlainTextRuleIntoRule(final String ruleAsPlainText,
}

irodsRule = IRODSRule.instance(ruleAsPlainText, inputParameters, outputParameters,
ruleCharacteristics.getRuleBody());
ruleCharacteristics.getRuleBody(), this.getRuleInvocationConfiguration());
} else {
log.info("parsing in old format");
if (tokenLines.size() < 3) {
Expand All @@ -125,7 +125,7 @@ public IRODSRule translatePlainTextRuleIntoRule(final String ruleAsPlainText,
outputParameters = processRuleOutputAttributesLine(tokenLines.get(tokenLines.size() - 1));

irodsRule = IRODSRule.instance(ruleAsPlainText, inputParameters, outputParameters,
processRuleBodyOldFormat(tokenLines));
processRuleBodyOldFormat(tokenLines), this.getRuleInvocationConfiguration());

}

Expand Down

This file was deleted.

Loading

0 comments on commit af7c896

Please sign in to comment.