Skip to content

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberrolandvaltech committed Aug 24, 2018
2 parents 0037f47 + 712ce87 commit f73da4f
Show file tree
Hide file tree
Showing 43 changed files with 367 additions and 108 deletions.
5 changes: 5 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2018-08-24 1.3.0
- Execute scripts in alphabetical order
- Stop execution after first failed script
- API changes

2018-08-07 1.2.0
- Updated API
- AEM 6.4 fix
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
</parent>

<artifactId>aecu.api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
@ProviderType
public interface AecuService {

/**
* Prefix in CRX where AECU scripts are located.
*/
public static final String AECU_PREFIX = "/etc/groovyconsole/scripts/aecu";

/**
Expand Down
20 changes: 10 additions & 10 deletions api/src/main/java/de/valtech/aecu/api/service/ExecutionResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class ExecutionResult {

private boolean success;
private ExecutionState state;
private String output;
private String time;
private String result;
Expand All @@ -37,16 +37,16 @@ public class ExecutionResult {
/**
* Constructor
*
* @param success execution was successful
* @param state execution state
* @param time execution time
* @param result result
* @param output script output
* @param fallbackResult fallback script result
* @param path script path
*/
public ExecutionResult(boolean success, String time, String result, String output, ExecutionResult fallbackResult,
public ExecutionResult(ExecutionState state, String time, String result, String output, ExecutionResult fallbackResult,
String path) {
this.success = success;
this.state = state;
this.output = output;
this.time = time;
this.result = result;
Expand All @@ -55,12 +55,12 @@ public ExecutionResult(boolean success, String time, String result, String outpu
}

/**
* Returns if execution was successful.
*
* @return successful
* Returns the execution state.
*
* @return state
*/
public boolean isSuccess() {
return success;
public ExecutionState getState() {
return state;
}

/**
Expand Down Expand Up @@ -119,7 +119,7 @@ public String getShortPath() {

@Override
public String toString() {
StringBuilder stringVal = new StringBuilder("Successful: " + Boolean.toString(success) + "Path: " + path);
StringBuilder stringVal = new StringBuilder("Successful: " + state.name() + "Path: " + path);
if (StringUtils.isNotBlank(time)) {
stringVal.append("\n" + "Execution time: " + time);
}
Expand Down
42 changes: 42 additions & 0 deletions api/src/main/java/de/valtech/aecu/api/service/ExecutionState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2018 Valtech GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package de.valtech.aecu.api.service;

/**
* State of a script execution.
*
* @author Roland Gruber
*
*/
public enum ExecutionState {

/**
* Script run without errors.
*/
SUCCESS,
/**
* Script failed with exception.
*/
FAILED,
/**
* Script was skipped because e.g. previous script failed.
*/
SKIPPED

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @author Roland Gruber
*/
@Version("1.0")
@Version("2.0")
package de.valtech.aecu.api.service;

import org.osgi.annotation.versioning.Version;
2 changes: 1 addition & 1 deletion bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
</parent>

<artifactId>aecu.bundle</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:unstructured">
</jcr:root>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:file">
<jcr:content
jcr:lastModifiedBy="admin"
jcr:mimeType="image/png"
jcr:primaryType="nt:resource"/>
</jcr:root>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:file">
<jcr:content
jcr:lastModifiedBy="admin"
jcr:mimeType="image/png"
jcr:primaryType="nt:resource"/>
</jcr:root>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:file">
<jcr:content
jcr:lastModifiedBy="admin"
jcr:mimeType="image/png"
jcr:primaryType="nt:resource"/>
</jcr:root>
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
</parent>

<artifactId>aecu.core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import de.valtech.aecu.api.service.AecuException;
import de.valtech.aecu.api.service.ExecutionResult;
import de.valtech.aecu.api.service.ExecutionState;
import de.valtech.aecu.api.service.HistoryEntry;
import de.valtech.aecu.api.service.HistoryEntry.RESULT;
import de.valtech.aecu.api.service.HistoryEntry.STATE;
Expand All @@ -63,7 +64,7 @@ public class HistoryUtil {

private static final String ATTR_PATH = "path";
private static final String ATTR_RUN_OUTPUT = "runOutput";
private static final String ATTR_RUN_SUCCESS = "runSuccess";
private static final String ATTR_RUN_STATE = "runState";
private static final String ATTR_RUN_RESULT = "runResult";
private static final String ATTR_RUN_TIME = "runTime";
private static final String ATTR_RESULT = "result";
Expand Down Expand Up @@ -315,10 +316,10 @@ private ExecutionResult readHistorySingleResult(Resource resource) {
ValueMap values = resource.adaptTo(ValueMap.class);
String output = values.get(ATTR_RUN_OUTPUT, "");
String time = values.get(ATTR_RUN_TIME, "");
Boolean success = values.get(ATTR_RUN_SUCCESS, Boolean.FALSE);
ExecutionState state = ExecutionState.valueOf(values.get(ATTR_RUN_STATE, ExecutionState.FAILED.name()));
String runResult = values.get(ATTR_RUN_RESULT, "");
String path = values.get(ATTR_PATH, "");
ExecutionResult result = new ExecutionResult(success, time, runResult, output, fallback, path);
ExecutionResult result = new ExecutionResult(state, time, runResult, output, fallback, path);
return result;
}

Expand All @@ -327,7 +328,7 @@ private void saveExecutionResultInHistory(ExecutionResult result, String path, R
createPath(path, resolver, "nt:unstructured");
Resource entry = resolver.getResource(path);
ModifiableValueMap values = entry.adaptTo(ModifiableValueMap.class);
values.put(ATTR_RUN_SUCCESS, result.isSuccess());
values.put(ATTR_RUN_STATE, result.getState().name());
values.put(ATTR_PATH, result.getPath());
if (StringUtils.isNotBlank(result.getOutput())) {
values.put(ATTR_RUN_OUTPUT, result.getOutput());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import de.valtech.aecu.api.service.AecuException;
import de.valtech.aecu.api.service.AecuService;
import de.valtech.aecu.api.service.ExecutionResult;
import de.valtech.aecu.api.service.ExecutionState;
import de.valtech.aecu.api.service.HistoryEntry;
import de.valtech.aecu.api.service.HistoryEntry.RESULT;

/**
* InstallHook handling installation of groovy scripts. The InstallHook gathers groovy scripts
Expand Down Expand Up @@ -158,11 +160,20 @@ private boolean wasNotExecuted(String path, HookExecutionHistory history) {
private HistoryEntry executeScripts(List<String> scriptsForExecution, AecuService aecuService, InstallContext installContext)
throws AecuException, IOException {
HistoryEntry installationHistory = aecuService.createHistoryEntry();
boolean stopExecution = false;
for (String groovyScriptPath : scriptsForExecution) {
HookExecutionHistory hookExecutionHistory = new HookExecutionHistory(installContext.getSession(), groovyScriptPath);
try {
installationHistory = executeScript(aecuService, installationHistory, groovyScriptPath);
hookExecutionHistory.setExecuted();
if (!stopExecution) {
installationHistory = executeScript(aecuService, installationHistory, groovyScriptPath);
hookExecutionHistory.setExecuted();
if (RESULT.FAILURE.equals(installationHistory.getResult())) {
// stop execution on first failed script run
stopExecution = true;
}
} else {
installationHistory = skipScript(aecuService, installationHistory, groovyScriptPath);
}
} catch (AecuException e) {
listener.logError("Error executing script " + groovyScriptPath, e);
}
Expand All @@ -171,6 +182,23 @@ private HistoryEntry executeScripts(List<String> scriptsForExecution, AecuServic
return installationHistory;
}

/**
* Adds an entry to history that the given script was skipped.
*
* @param aecuService AECU service
* @param installationHistory history
* @param groovyScriptPath path of skipped script
* @return history
* @throws AecuException error storing status
*/
private HistoryEntry skipScript(AecuService aecuService, HistoryEntry installationHistory, String groovyScriptPath)
throws AecuException {
listener.logMessage("Skipping script because of previous error " + groovyScriptPath);
ExecutionResult result = new ExecutionResult(ExecutionState.SKIPPED, null, null, null, null, groovyScriptPath);
installationHistory = aecuService.storeExecutionInHistory(installationHistory, result);
return installationHistory;
}

private HistoryEntry executeScript(AecuService aecuService, HistoryEntry installationHistory, String groovyScriptPath)
throws AecuException {
listener.logMessage("Executing script " + groovyScriptPath);
Expand All @@ -190,7 +218,13 @@ private List<String> findCandidates(String parent, Archive.Entry entry, AecuServ
String entryPath = parent + "/" + entryName;

if (entry.isDirectory() && aecuService.matchesRunmodes(entryName)) {
for (Archive.Entry childEntry : entry.getChildren()) {
List<String> childNames = new ArrayList<>();
for (Archive.Entry child : entry.getChildren()) {
childNames.add(child.getName());
}
childNames.sort(null);
for (String childName : childNames) {
Archive.Entry childEntry = entry.getChild(childName);
candidates.addAll(findCandidates(entryPath, childEntry, aecuService));
}
} else if (aecuService.isValidScriptName(entryName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,16 @@ public String getPath() {
return history.getRepositoryPath();
}

/**
* Returns the number of scripts that were executed.
*
* @return script count
*/
public int getScriptCount() {
if (history.getSingleResults() == null) {
return 0;
}
return history.getSingleResults().size();
}

}
Loading

0 comments on commit f73da4f

Please sign in to comment.