Skip to content

Commit

Permalink
v0.1.3-beta
Browse files Browse the repository at this point in the history
fix typos
update to JDK 19
update README
add support for @literal tag-value mappings
improve stability of node auto-reset feature
  • Loading branch information
cvogt729 committed Dec 20, 2022
1 parent b47eac2 commit 7e94988
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Another possible use for this add-on is advanced reporting with automatic data c
4. Click the *Upload Script* button and select your script. An error will be thrown if any compilation/loading errors occur. For debugging purposes, the stack trace of any error is recorded in the *Error Log*.
5. Click *Semantic Mappings* and then *New Mapping* in order to select which parts of the WebCTRL system are accessible to the script.
6. Click *Add Group* and then *Add Equipment* to select which control programs should be tested.
7. Enter in a few semantic tags and mapping expressions to be referenced by the script. The *Examine* button on each control program can help to determine the expression to use for mapping a given semantic tag. Note that each tag mapping is actually a [regular expression](https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/util/regex/Pattern.html).
7. Enter in a few semantic tags and mapping expressions to be referenced by the script. The *Examine* button on each control program can help to determine the expression to use for mapping a given semantic tag. Note that each tag mapping is actually a [regular expression](https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/util/regex/Pattern.html). Expressions prefixed with `@` are interpreted literally as opposed to a node mapping pattern (e.g, the node mapped with `@3.14159` will always return a value of *3.14159*).
8. Press the *Save Changes* button as the last step to create your mapping. Note that all groups and mappings should be named.
9. The *Preview Mapping Resolution* button should be used to determine whether each tag mapping is resolved correctly.
10. Navigate back to the *Scripts* page.
Expand All @@ -52,7 +52,7 @@ However, it is recommended that scripts are compiled and packaged into *.jar* ar

Be mindful to compile your script with a version of Java compatible with the target WebCTRL version of your server. For instance, you should use the build flag `--release 8` if you intend the script to run on WebCTRL7.0, and `--release 11` for WebCTRL8.0. See https://jdk.java.net/ to download the latest version of the java development kit.

To ease the development process, it is suggested to use an IDE (e.g, [Visual Studio Code](https://code.visualstudio.com/)), and then add the following dependencies: [CommissioningScripts-0.1.2.jar](https://github.com/automatic-controls/commissioning-scripts/releases/download/v0.1.2-beta/CommissioningScripts-0.1.2.jar) and [CommissioningScripts-0.1.2-sources.jar](https://github.com/automatic-controls/commissioning-scripts/releases/download/v0.1.2-beta/CommissioningScripts-0.1.2-sources.jar). These dependencies will provide you with intellisense and Javadocs for script development. You are also welcome to reference any other dependencies provided by WebCTRL at runtime (e.g, the add-on API, or `javax.servlet`).
To ease the development process, it is suggested to use an IDE (e.g, [Visual Studio Code](https://code.visualstudio.com/)), and then add the following dependencies: [CommissioningScripts-0.1.3.jar](https://github.com/automatic-controls/commissioning-scripts/releases/download/v0.1.3-beta/CommissioningScripts-0.1.3.jar) and [CommissioningScripts-0.1.3-sources.jar](https://github.com/automatic-controls/commissioning-scripts/releases/download/v0.1.3-beta/CommissioningScripts-0.1.3-sources.jar). These dependencies will provide you with intellisense and Javadocs for script development. You are also welcome to reference any other dependencies provided by WebCTRL at runtime (e.g, the add-on API, or `javax.servlet`).

This add-on does not enforce any security restrictions on what scripts can do. Scripts are executed with the same privilege set as the add-on. As such, you must be careful to **use scripts at your own risk.** Note that only WebCTRL server administrators are allowed to manage scripts.

Expand Down
6 changes: 3 additions & 3 deletions config/BUILD_DETAILS
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
JDK Version:
openjdk 18.0.2.1 2022-08-18
OpenJDK Runtime Environment (build 18.0.2.1+1-1)
OpenJDK 64-Bit Server VM (build 18.0.2.1+1-1, mixed mode, sharing)
openjdk 19.0.1 2022-10-18
OpenJDK Runtime Environment (build 19.0.1+10-21)
OpenJDK 64-Bit Server VM (build 19.0.1+10-21, mixed mode, sharing)

Compilation Flags:
--release 8
Expand Down
2 changes: 1 addition & 1 deletion root/info.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<extension version="1">
<name>CommissioningScripts</name>
<description>Executes scripts concurrently on groups of equipment to evaluate performance and detect faults.</description>
<version>0.1.2</version>
<version>0.1.3</version>
<vendor>Automatic Controls Equipment Systems, Inc.</vendor>
</extension>
8 changes: 4 additions & 4 deletions src/aces/webctrl/scripts/commissioning/core/Initializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.concurrent.*;
import java.nio.file.*;
public class Initializer implements ServletContextListener {
/** Contains basic informatin about this addon. */
/** Contains basic information about this addon. */
public volatile static AddOnInfo info = null;
/** The name of this addon */
private volatile static String name;
Expand Down Expand Up @@ -177,16 +177,16 @@ public void execute(WritableSystemAccess sys){
*/
@Override public void contextDestroyed(ServletContextEvent sce){
try{
kill = true;
dataQueryThread.interrupt();
Collection<Test> tests = Test.instances.values();
for (Test t:tests){
t.kill();
}
dataQueryThread.join();
for (Test t:tests){
t.waitForDeath();
}
kill = true;
dataQueryThread.interrupt();
dataQueryThread.join();
ArchivedTest.saveAll();
Mapping.saveAll();
ScheduledTest.saveAll();
Expand Down
52 changes: 52 additions & 0 deletions src/aces/webctrl/scripts/commissioning/core/LiteralNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package aces.webctrl.scripts.commissioning.core;
import com.controlj.green.addonsupport.access.*;
import com.controlj.green.addonsupport.access.node.*;
import java.util.*;
public class LiteralNode implements Node {
private volatile String value;
public LiteralNode(String value){
this.value = value;
}
@Override public String eval(String arg0){
return null;
}
@Override public Node evalToNode(String arg0){
return null;
}
@Override public List<Node> getChildren(){
return null;
}
@Override public String getDisplayName(){
return null;
}
@Override public String getDisplayName(Locale arg0){
return null;
}
@Override public String getDisplayValue(){
return value;
}
@Override public Node getParent(){
return null;
}
@Override public String getReferenceName(){
return null;
}
@Override public String getRelativeReferencePath(Node arg0){
return null;
}
@Override public String getValue(){
return value;
}
@Override public boolean hasParent(){
return false;
}
@Override public Location resolveToLocation(Tree arg0){
return null;
}
@Override public void setDisplayValue(String arg0){
value = arg0;
}
@Override public void setValue(String arg0){
value = arg0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ public ResolvedTestingUnit(TestingUnit tu, Tree tree, Collection<SemanticTag> ta
node = loc.toNode();
group = tu.getGroup();
Node n;
String expr;
for (SemanticTag st:tagMappings){
n = st.resolve(node);
if (st.isLiteral() && (expr=st.getExpression()).charAt(0)=='@'){
n = new LiteralNode(expr.substring(1));
}else{
n = st.resolve(node);
}
if (n!=null){
tags.put(st.getTag(), n);
}
Expand Down Expand Up @@ -120,6 +125,10 @@ public static boolean setValue(final Node n, final Object value, final int tries
return false;
}
final String str = String.valueOf(value);
if (n instanceof LiteralNode){
((LiteralNode)n).setValue(str);
return true;
}
final Result<Boolean> ret = new Result<Boolean>();
for (int i=0;i<tries;++i){
if (i!=0){
Expand Down Expand Up @@ -153,6 +162,13 @@ public String markAndSetValue(final String tag, final Object value) throws Inter
return null;
}
final String str = String.valueOf(value);
if (n instanceof LiteralNode){
final LiteralNode nn = (LiteralNode)n;
final String prev = nn.getValue();
nn.setValue(str);
marks.put(tag,prev);
return prev;
}
final Result<String> ret = new Result<String>();
final Container<String> val = new Container<String>(null);
String s;
Expand Down Expand Up @@ -219,6 +235,8 @@ public String getValue(String tag) throws InterruptedException {
public static String getValue(Node n, final int tries, final long failedAttemptTimeout) throws InterruptedException {
if (n==null){
return null;
}else if (n instanceof LiteralNode){
return ((LiteralNode)n).getValue();
}
final Result<String> ret = new Result<String>();
String s;
Expand Down Expand Up @@ -254,6 +272,8 @@ public String getDisplayValue(String tag) throws InterruptedException {
public static String getDisplayValue(Node n, final int tries, final long failedAttemptTimeout) throws InterruptedException {
if (n==null){
return null;
}else if (n instanceof LiteralNode){
return ((LiteralNode)n).getDisplayValue();
}
final Result<String> ret = new Result<String>();
String s;
Expand Down Expand Up @@ -301,6 +321,11 @@ public boolean reset(String tag) throws InterruptedException {
final String value = marks.get(str);
if (value!=null){
final Node n = entry.getValue();
if (n instanceof LiteralNode){
((LiteralNode)n).setValue(value);
marks.remove(str);
continue;
}
final Result<Boolean> ret = new Result<Boolean>();
rets.add(ret);
Initializer.enqueue(new WriteAction(){
Expand Down
12 changes: 11 additions & 1 deletion src/aces/webctrl/scripts/commissioning/core/SemanticTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class SemanticTag {
private volatile String expr;
private volatile String tag;
private volatile Pattern pattern = null;
private volatile boolean literal;
public void serialize(ByteBuilder b){
b.write(tag);
b.write(expr);
Expand All @@ -30,8 +31,11 @@ public SemanticTag(String tag, String expr) throws PatternSyntaxException {
public void setExpression(String expr) throws PatternSyntaxException {
expr = Utility.V_SPACE.matcher(expr).replaceAll("");
this.expr = expr;
literal = expr.charAt(0)=='@';
pattern = null;
pattern = Pattern.compile(expr);
if (!literal){
pattern = Pattern.compile(expr);
}
}
/**
* @return the expression used to match nodes against this semantic tag.
Expand All @@ -45,6 +49,12 @@ public String getExpression(){
public String getTag(){
return tag;
}
/**
* @return whether the expression should be interpreted as a literal value instead of a node mapping.
*/
public boolean isLiteral(){
return literal;
}
/**
* Attempts to resolve this semantic tag against the provided node.
* @return the resolved node which corresponds to this semantic tag, or {@code null} if no matches are found.
Expand Down
9 changes: 7 additions & 2 deletions src/aces/webctrl/scripts/commissioning/core/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public boolean isRunning(){
*/
public void waitForDeath() throws InterruptedException {
while (running.get()){
Thread.sleep(1000L);
Thread.sleep(500L);
}
}
/**
Expand Down Expand Up @@ -353,7 +353,12 @@ public void run(){
Initializer.log(t);
}
if (autoReset.x){
rtu.reset(null);
while (true){
try{
rtu.reset(null);
break;
}catch(InterruptedException e){}
}
}
rtu.complete();
groups[i].complete();
Expand Down

0 comments on commit 7e94988

Please sign in to comment.