[rhq] Branch 'raw-config' - modules/plugins
by John Sanda
modules/plugins/raw-config-test/src/main/groovy/org/rhq/plugins/test/rawconfig/StructuredAndRawServer.groovy | 4 ++--
modules/plugins/raw-config-test/src/main/groovy/org/rhq/plugins/test/rawconfig/StructuredServer.groovy | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
New commits:
commit 6b359822895dc79a6d282e5191ccc4d0ff58a380
Author: John Sanda <john(a)localhost.localdomain>
Date: Wed Mar 3 12:09:18 2010 -0500
Changing default structured validation and update error messages
diff --git a/modules/plugins/raw-config-test/src/main/groovy/org/rhq/plugins/test/rawconfig/StructuredAndRawServer.groovy b/modules/plugins/raw-config-test/src/main/groovy/org/rhq/plugins/test/rawconfig/StructuredAndRawServer.groovy
index 39721d0..97f3622 100644
--- a/modules/plugins/raw-config-test/src/main/groovy/org/rhq/plugins/test/rawconfig/StructuredAndRawServer.groovy
+++ b/modules/plugins/raw-config-test/src/main/groovy/org/rhq/plugins/test/rawconfig/StructuredAndRawServer.groovy
@@ -168,14 +168,14 @@ class StructuredAndRawServer extends ConfigurationServer implements ResourceComp
void validateStructuredConfiguration(Configuration config) {
def failValidation = resourceContext.pluginConfiguration.getSimple("failStructuredValidation")
if (failValidation != null && failValidation.booleanValue) {
- throw new RuntimeException("Validation failed for $config");
+ throw new RuntimeException("Structured validation failed for Structured and Raw Server");
}
}
void persistStructuredConfiguration(Configuration config) {
def failValidation = resourceContext.pluginConfiguration.getSimple("failStructuredUpdate")
if (failValidation != null && failValidation.booleanValue) {
- throw new RuntimeException("Update failed for $configuration");
+ throw new RuntimeException("Structured pdate failed for Structured and Raw Server");
}
pauseForStructuredUpdateIfDelaySet()
diff --git a/modules/plugins/raw-config-test/src/main/groovy/org/rhq/plugins/test/rawconfig/StructuredServer.groovy b/modules/plugins/raw-config-test/src/main/groovy/org/rhq/plugins/test/rawconfig/StructuredServer.groovy
index 2e9b2c5..7579533 100644
--- a/modules/plugins/raw-config-test/src/main/groovy/org/rhq/plugins/test/rawconfig/StructuredServer.groovy
+++ b/modules/plugins/raw-config-test/src/main/groovy/org/rhq/plugins/test/rawconfig/StructuredServer.groovy
@@ -96,7 +96,7 @@ class StructuredServer extends ConfigurationServer implements ResourceComponent,
void persistStructuredConfiguration(Configuration configuration) {
def failValidation = resourceContext.pluginConfiguration.getSimple("failStructuredUpdate")
if (failValidation != null && failValidation.booleanValue) {
- throw new RuntimeException("Validation failed for $configuration");
+ throw new RuntimeException("Update failed for Structured Server");
}
pauseForStructuredUpdateIfDelaySet()
@@ -143,7 +143,7 @@ class StructuredServer extends ConfigurationServer implements ResourceComponent,
void validateStructuredConfiguration(Configuration configuration) {
def failValidation = resourceContext.pluginConfiguration.getSimple("failStructuredValidation")
if (failValidation != null && failValidation.booleanValue) {
- throw new RuntimeException("Validation failed for $configuration");
+ throw new RuntimeException("Validation failed for Structured Server");
}
}
14 years, 2 months
[rhq] Branch 'raw-config' - modules/enterprise
by John Sanda
modules/enterprise/remoting/webservices/src/test/java/org/rhq/enterprise/server/ws/WsConfigurationManagerTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
New commits:
commit eb7e39af8181ed7b06d0baee35c41fffcbde80b6
Author: John Sanda <john(a)localhost.localdomain>
Date: Wed Mar 3 08:09:38 2010 -0500
Fixing compilation error that resulted from making ConfigurationValidationException a checked exception
diff --git a/modules/enterprise/remoting/webservices/src/test/java/org/rhq/enterprise/server/ws/WsConfigurationManagerTest.java b/modules/enterprise/remoting/webservices/src/test/java/org/rhq/enterprise/server/ws/WsConfigurationManagerTest.java
index 7c80417..de5bf1c 100644
--- a/modules/enterprise/remoting/webservices/src/test/java/org/rhq/enterprise/server/ws/WsConfigurationManagerTest.java
+++ b/modules/enterprise/remoting/webservices/src/test/java/org/rhq/enterprise/server/ws/WsConfigurationManagerTest.java
@@ -169,7 +169,7 @@ public class WsConfigurationManagerTest extends AssertJUnit implements TestPrope
}
@Test(enabled = TESTS_ENABLED)
- void testUpdateResourceConfiguration() throws InterruptedException {
+ void testUpdateResourceConfiguration() throws java.lang.Exception {
Resource resource = findService("service-beta-1", "server-omega-1");
// Configuration config = WEBSERVICE_REMOTE.getResourceConfiguration(subject, resource.id);
14 years, 2 months
[rhq] Branch 'alertPlugin' - modules/enterprise pom.xml
by Heiko W. Rupp
modules/enterprise/server/plugins/alert-operations/pom.xml | 98 +++++++------
pom.xml | 33 ++--
2 files changed, 73 insertions(+), 58 deletions(-)
New commits:
commit e840b5ebe391a4e7dfdd75388319bef0cac29b7d
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Mar 3 11:12:42 2010 +0100
Mvn exec-plugin executions need unique ids across the project.
Enable automatic build of the tokens documentation
diff --git a/modules/enterprise/server/plugins/alert-operations/pom.xml b/modules/enterprise/server/plugins/alert-operations/pom.xml
index 98f835e..6f99cce 100644
--- a/modules/enterprise/server/plugins/alert-operations/pom.xml
+++ b/modules/enterprise/server/plugins/alert-operations/pom.xml
@@ -52,6 +52,62 @@
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+ <execution>
+ <!-- Generate tokens.xml file -->
+ <id>generate-tokens-xml</id>
+ <phase>install</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <executable>java</executable>
+ <workingDirectory>target</workingDirectory>
+ <arguments>
+ <argument>-cp</argument>
+ <argument>${project.build.directory}/${project.build.finalName}.jar</argument>
+ <argument>org.rhq.enterprise.server.plugins.alertOperations.PrintTokens</argument>
+ <argument>tokens.xml</argument>
+ </arguments>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>xml-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <!-- translate the tokens.xml file to confluence markup -->
+ <phase>install</phase>
+ <goals>
+ <goal>transform</goal>
+ </goals>
+ <configuration>
+ <transformationSets>
+ <transformationSet>
+ <dir>target</dir>
+ <stylesheet>src/main/token2confluence.xsl</stylesheet>
+ <includes>
+ <include>
+ tokens.xml
+ </include></includes>
+ <fileMappers>
+ <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
+ <targetExtension>.confluence</targetExtension>
+ </fileMapper>
+ </fileMappers>
+ </transformationSet>
+ </transformationSets>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
@@ -129,48 +185,6 @@
</executions>
</plugin>
-<!--
- <plugin>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.0</version>
- <executions>
- <execution>
- <id>copy-resteasy-jars</id>
- <phase>process-resources</phase>
- <goals>
- <goal>copy</goal>
- </goals>
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jaxrs</artifactId>
- <version>${resteasy.version}</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>jaxrs-api</artifactId>
- <version>${resteasy.version}</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <version>1.5.6</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.5.6</version>
- </artifactItem>
-
- </artifactItems>
- <outputDirectory>${project.build.outputDirectory}/lib</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
--->
-
</plugins>
</build>
</profile>
diff --git a/pom.xml b/pom.xml
index 191f86e..37afdcb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -554,10 +554,10 @@
<phase>generate-resources</phase>
<configuration>
<tasks>
- <tstamp>
+ <tstamp>
<format property="buildTime" pattern="MM/dd/yy hh:mm aa z" locale="en,US" timezone="GMT"/>
</tstamp>
- <mkdir dir="target"/>
+ <mkdir dir="target"/>
<echo file="target/build-time.properties" level="error">buildTime = ${buildTime}</echo>
</tasks>
</configuration>
@@ -569,7 +569,7 @@
<inherited>false</inherited>
<goals>
<goal>run</goal>
- </goals>
+ </goals>
<configuration>
<tasks>
<echo level="debug">buildTime = ${buildTime}</echo>
@@ -585,23 +585,24 @@
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
+ <id>generate-build-number-properties</id>
<phase>generate-resources</phase>
<goals>
<goal>exec</goal>
- </goals>
+ </goals>
+ <configuration>
+ <executable>git</executable>
+ <arguments>
+ <argument>log</argument>
+ <argument>--pretty=format:buildNumber = %h</argument>
+ <argument>-n1</argument>
+ </arguments>
+ <outputFile>${project.build.directory}/build-number.properties</outputFile>
+ </configuration>
</execution>
</executions>
- <configuration>
- <executable>git</executable>
- <arguments>
- <argument>log</argument>
- <argument>--pretty=format:buildNumber = %h</argument>
- <argument>-n1</argument>
- </arguments>
- <outputFile>${project.build.directory}/build-number.properties</outputFile>
- </configuration>
</plugin>
-
+
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
@@ -620,7 +621,7 @@
</execution>
</executions>
</plugin>
-
+
<!-- Ensure all code compiles and runs on Java 5 or later. -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
@@ -852,7 +853,7 @@
<property>
<name>rhq.m2.repo.url.oracle</name>
</property>
- </activation>
+ </activation>
<dependencies>
<!-- Oracle JDBC driver - required only if you want to run the tests, or dbsetup, against Oracle.
14 years, 2 months
[rhq] Branch 'bundle' - 3 commits - .classpath dev-cli modules/common modules/plugins
by mazz
.classpath | 1
dev-cli | 1
modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/DeployRecipeCommand.java | 4
modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/FileRecipeCommand.java | 4
modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RealizeRecipeCommand.java | 74 +++
modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeCommand.java | 5
modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeContext.java | 31 +
modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java | 29 -
modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/ScriptRecipeCommand.java | 2
modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java | 10
modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java | 106 +++-
modules/plugins/filetemplate-bundle/src/test/java/org/rhq/plugins/filetemplate/ProcessingRecipeContextTest.java | 225 ++++++++++
12 files changed, 450 insertions(+), 42 deletions(-)
New commits:
commit f7bb4c6924ea155514a7818223737aa89b2aaa04
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 3 01:51:39 2010 -0500
add agent bundle plugin unit tests
diff --git a/.classpath b/.classpath
index c6a1ed2..fe06650 100644
--- a/.classpath
+++ b/.classpath
@@ -126,6 +126,7 @@
<classpathentry kind="src" path="modules/plugins/augeas/src/main/java"/>
<classpathentry kind="src" path="modules/plugins/augeas/src/test/java"/>
<classpathentry kind="src" path="modules/plugins/filetemplate-bundle/src/main/java"/>
+ <classpathentry kind="src" path="modules/plugins/filetemplate-bundle/src/test/java"/>
<classpathentry kind="src" path="modules/helpers/rtfilter/src/main/java"/>
<classpathentry kind="src" path="modules/helpers/pluginAnnotations/src/main/java"/>
<classpathentry kind="src" path="modules/helpers/pluginGen/src/main/java"/>
diff --git a/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java b/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java
index ffe24f2..26199d3 100644
--- a/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java
+++ b/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java
@@ -34,6 +34,7 @@ import org.rhq.core.domain.content.PackageVersion;
import org.rhq.core.system.ProcessExecution;
import org.rhq.core.system.ProcessExecutionResults;
import org.rhq.core.system.SystemInfo;
+import org.rhq.core.util.file.FileUtil;
/**
* A recipe context that processes the recipe as it adds stuff to the context
@@ -61,7 +62,7 @@ public class ProcessingRecipeContext extends RecipeContext {
File existingFile = new File(this.baseWorkingDirectory, filename);
- ProcessExecution pe = getUnzipExecution(filename, directory);
+ ProcessExecution pe = getUnzipExecution(existingFile, directory);
if (pe != null) {
ProcessExecutionResults results = this.systemInfo.executeProcess(pe);
if (results.getError() != null) {
@@ -69,7 +70,7 @@ public class ProcessingRecipeContext extends RecipeContext {
} else if (results.getExitCode() == null || results.getExitCode().intValue() > 0) {
throw new RuntimeException("Failed to unbundle file [" + pe + "]: " + results);
}
- existingFile.delete();
+ // existingFile.delete(); WOULD WE WANT TO REMOVE THE COMPRESSED FILE?
} else {
// not a zipped format - just move the file to the directory as-is
File newFile = new File(directory, filename);
@@ -80,21 +81,27 @@ public class ProcessingRecipeContext extends RecipeContext {
}
@Override
- public void addFile(String filename, String directory) {
- super.addDeployFile(filename, directory);
+ public void addFile(String source, String destination) {
+ super.addFile(source, destination);
- File existingFile = new File(this.baseWorkingDirectory, filename);
- File newFile = new File(directory, filename);
- if (!existingFile.renameTo(newFile)) {
- throw new RuntimeException("Failed to move file [" + existingFile + "] to [" + newFile + "]");
+ File sourceFile = new File(this.baseWorkingDirectory, source);
+ File destinationFile = new File(destination);
+
+ try {
+ destinationFile.getParentFile().mkdirs();
+ FileUtil.copyFile(sourceFile, destinationFile);
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to copy file [" + sourceFile + "] to [" + destinationFile + "]", e);
}
+
+ return;
}
@Override
public void addRealizedFile(String file) {
super.addRealizedFile(file);
- File trueFile = new File(file);
+ File trueFile = new File(this.baseWorkingDirectory, file);
RecipeParser parser = getParser();
File realizedTmpFile = null;
FileWriter realizedTmpFileWriter = null;
@@ -166,42 +173,44 @@ public class ProcessingRecipeContext extends RecipeContext {
}
}
- private ProcessExecution getUnzipExecution(String filename, String directory) {
+ private ProcessExecution getUnzipExecution(File file, String directory) {
String exe;
List<String> args = null;
- if (filename.endsWith(".tar")) {
+ String filepath = file.getAbsolutePath();
+
+ if (filepath.endsWith(".tar")) {
exe = "tar";
args = new ArrayList<String>();
args.add("xf");
- args.add(filename);
+ args.add(filepath);
args.add("-C");
args.add(directory);
- } else if (filename.endsWith(".tar.bz2") || filename.endsWith(".tbz2") || filename.endsWith(".tbz")) {
+ } else if (filepath.endsWith(".tar.bz2") || filepath.endsWith(".tbz2") || filepath.endsWith(".tbz")) {
exe = "tar";
args = new ArrayList<String>();
args.add("xfj");
- args.add(filename);
+ args.add(filepath);
args.add("-C");
args.add(directory);
- } else if (filename.endsWith(".tar.gz") || filename.endsWith(".tgz")) {
+ } else if (filepath.endsWith(".tar.gz") || filepath.endsWith(".tgz")) {
exe = "tar";
args = new ArrayList<String>();
args.add("xfz");
- args.add(filename);
+ args.add(filepath);
args.add("-C");
args.add(directory);
- } else if (filename.endsWith(".zip")) {
+ } else if (filepath.endsWith(".zip")) {
exe = "unzip";
args = new ArrayList<String>();
- args.add(filename);
+ args.add(filepath);
args.add("-d");
args.add(directory);
- } else if (filename.endsWith(".rpm")) {
+ } else if (filepath.endsWith(".rpm")) {
exe = "rpm";
args = new ArrayList<String>();
args.add("-i");
- args.add(filename);
+ args.add(filepath);
if (directory != null && directory.length() > 0) {
args.add("--prefix");
args.add(directory);
@@ -213,6 +222,7 @@ public class ProcessingRecipeContext extends RecipeContext {
ProcessExecution pe = new ProcessExecution(exe);
pe.setArguments(args);
pe.setWaitForCompletion(30 * 60 * 1000L);
+ pe.setCheckExecutableExists(false);
pe.setWorkingDirectory(this.baseWorkingDirectory);
return pe;
}
diff --git a/modules/plugins/filetemplate-bundle/src/test/java/org/rhq/plugins/filetemplate/ProcessingRecipeContextTest.java b/modules/plugins/filetemplate-bundle/src/test/java/org/rhq/plugins/filetemplate/ProcessingRecipeContextTest.java
new file mode 100644
index 0000000..1099481
--- /dev/null
+++ b/modules/plugins/filetemplate-bundle/src/test/java/org/rhq/plugins/filetemplate/ProcessingRecipeContextTest.java
@@ -0,0 +1,225 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.plugins.filetemplate;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import org.rhq.bundle.filetemplate.recipe.RecipeContext;
+import org.rhq.bundle.filetemplate.recipe.RecipeParser;
+import org.rhq.core.domain.content.PackageVersion;
+import org.rhq.core.pluginapi.util.FileUtils;
+import org.rhq.core.system.SystemInfo;
+import org.rhq.core.system.SystemInfoFactory;
+import org.rhq.core.util.stream.StreamUtil;
+
+@Test
+public class ProcessingRecipeContextTest {
+ private StringBuilder recipe;
+
+ @BeforeMethod
+ public void cleanRecipeBeforeMethod() {
+ cleanRecipe();
+ }
+
+ @AfterClass
+ public void afterClass() throws IOException {
+ FileUtils.purge(getTmpDir(), true);
+ }
+
+ public void testRealizeRecipe() throws Exception {
+ File testDir = getTestDir("testrealize");
+ File file = writeFile("a b c\nhello<% var %>world\na b c\n", testDir, "config.txt");
+
+ addRecipeCommand("realize --file=" + file.getName());
+
+ ProcessingRecipeContext context = createRecipeContext(testDir);
+ context.addReplacementVariableValue("var", "BOO");
+ context = parseRecipeNow(context);
+
+ Set<String> files = context.getRealizedFiles();
+ assert files.size() == 1 : files;
+ assert files.contains(file.getName()) : files;
+
+ String realizedContent = readFile(file);
+ assert realizedContent.equals("a b c\nhelloBOOworld\na b c\n") : realizedContent;
+ }
+
+ public void testFileRecipe() throws Exception {
+ File testDir = getTestDir("testfile");
+ File testDestDir = getTestDir("testfile-dest");
+ File runme = writeFile("runme script", testDir, "run-me.sh");
+ File runmeDest = new File(testDestDir, "run-me.sh");
+ File another = writeFile("<wotgorilla/>", testDir, "META-INF/another.xml");
+ File anotherDest = new File(testDestDir, "/OTHER/another.xml");
+
+ addRecipeCommand("file --source=run-me.sh \"--destination=" + runmeDest + "\"");
+ addRecipeCommand("file -s META-INF/another.xml -d \"" + anotherDest + "\"");
+
+ RecipeContext context = parseRecipeNow(testDir);
+
+ Map<String, String> files = context.getFiles();
+ assert files.size() == 2 : files;
+ assert files.get("run-me.sh") != null : files;
+ assert files.get("run-me.sh").equals(runmeDest.getPath()) : files;
+ assert files.get("META-INF/another.xml") != null : files;
+ assert files.get("META-INF/another.xml").equals(anotherDest.getPath()) : files;
+
+ String runmeContent = readFile(runme);
+ String runmeDestContent = readFile(runmeDest);
+ assert runmeContent.equals(runmeDestContent) : runmeDestContent;
+ String anotherContent = readFile(another);
+ String anotherDestContent = readFile(anotherDest);
+ assert anotherContent.equals(anotherDestContent) : anotherDestContent;
+ }
+
+ public void testDeployRecipe() throws Exception {
+ File testDir = getTestDir("testdeploy");
+ File testDestDir = getTestDir("testdeploy-dest");
+ File unzippedFile = new File(testDestDir, "zipped-file.txt");
+ File zipFile = createZip("zipped file content", testDir, "deploy-test.zip", unzippedFile.getName());
+
+ addRecipeCommand("deploy -f " + zipFile.getName() + " -d \"" + testDestDir + "\"");
+
+ RecipeContext context = parseRecipeNow(testDir);
+
+ Map<String, String> files = context.getDeployFiles();
+ assert files.size() == 1 : files;
+ assert files.get(zipFile.getName()) != null;
+
+ String zippedFileContent = readFile(unzippedFile);
+ assert zippedFileContent.equals("zipped file content");
+ }
+
+ @Test(enabled = false)
+ public void testScriptRecipe() throws Exception {
+ File testDir = getTestDir("testscript");
+
+ addRecipeCommand("script echo hello");
+
+ RecipeContext context = parseRecipeNow(testDir);
+
+ Set<String> scripts = context.getScriptFiles();
+ assert scripts.size() == 1 : scripts;
+ assert scripts.contains("run-me.sh") : scripts;
+ assert scripts.contains("lots-o-params.sh") : scripts;
+ }
+
+ private ProcessingRecipeContext parseRecipeNow(File testDir) throws Exception {
+ ProcessingRecipeContext context = createRecipeContext(testDir);
+ return parseRecipeNow(context);
+ }
+
+ private ProcessingRecipeContext createRecipeContext(File testDir) {
+ Map<PackageVersion, File> packageVersionFiles = null; // TODO not used yet
+ SystemInfo sysinfo = SystemInfoFactory.createSystemInfo();
+ String cwd = testDir.getAbsolutePath();
+ ProcessingRecipeContext context = new ProcessingRecipeContext(getRecipe(), packageVersionFiles, sysinfo, cwd);
+ return context;
+ }
+
+ private ProcessingRecipeContext parseRecipeNow(ProcessingRecipeContext context) throws Exception {
+ RecipeParser parser = new RecipeParser();
+ parser.setReplaceReplacementVariables(true);
+ parser.parseRecipe(context);
+ return context;
+ }
+
+ private File getTestDir(String subdir) {
+ return new File(getTmpDir(), subdir);
+ }
+
+ private File getTmpDir() {
+ File tmpdir = new File(System.getProperty("java.io.tmpdir"), "processing-recipe-test");
+ tmpdir.mkdirs();
+ return tmpdir;
+ }
+
+ private void cleanRecipe() {
+ this.recipe = new StringBuilder();
+ }
+
+ private void addRecipeCommand(String commandLine) {
+ this.recipe.append(commandLine).append("\n");
+ }
+
+ private String getRecipe() {
+ return this.recipe.toString();
+ }
+
+ private String readFile(File file) throws Exception {
+ return new String(StreamUtil.slurp(new FileInputStream(file)));
+ }
+
+ private File writeFile(String content, File destDir, String fileName) throws Exception {
+ FileOutputStream out = null;
+
+ try {
+ File destFile = new File(destDir, fileName);
+ destFile.getParentFile().mkdirs();
+ out = new FileOutputStream(destFile);
+ out.write(content.getBytes());
+ return destFile;
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ }
+ }
+
+ private File createZip(String content, File destDir, String zipName, String entryName) throws Exception {
+ FileOutputStream stream = null;
+ ZipOutputStream out = null;
+
+ try {
+ destDir.mkdirs();
+ File zipFile = new File(destDir, zipName);
+ stream = new FileOutputStream(zipFile);
+ out = new ZipOutputStream(stream);
+
+ ZipEntry zipAdd = new ZipEntry(entryName);
+ zipAdd.setTime(System.currentTimeMillis());
+ out.putNextEntry(zipAdd);
+ out.write(content.getBytes());
+ return zipFile;
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ if (stream != null) {
+ stream.close();
+ }
+ }
+ }
+}
commit 150fa0766fb19d1fc6d7ce9918df5fab6848219e
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 3 01:50:55 2010 -0500
remove this broken link
diff --git a/dev-cli b/dev-cli
deleted file mode 120000
index 9e0363b..0000000
--- a/dev-cli
+++ /dev/null
@@ -1 +0,0 @@
-modules/enterprise/remoting/cli/target/rhq-remoting-cli-1.4.0-SNAPSHOT
\ No newline at end of file
commit 981a3c4c5c77774b62e1b4e37f6b341aea1e1f35
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Tue Mar 2 20:30:39 2010 -0500
add realize recipe command
diff --git a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/DeployRecipeCommand.java b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/DeployRecipeCommand.java
index 5f14f2f..d73f871 100644
--- a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/DeployRecipeCommand.java
+++ b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/DeployRecipeCommand.java
@@ -32,7 +32,7 @@ public class DeployRecipeCommand implements RecipeCommand {
return "deploy";
}
- public void parse(RecipeContext context, String[] args) {
+ public void parse(RecipeParser parser, RecipeContext context, String[] args) {
String sopts = ":f:d:";
LongOpt[] lopts = { new LongOpt("file", LongOpt.REQUIRED_ARGUMENT, null, 'f'),
new LongOpt("directory", LongOpt.REQUIRED_ARGUMENT, null, 'd') };
@@ -40,7 +40,7 @@ public class DeployRecipeCommand implements RecipeCommand {
String filename = null;
String directory = null;
- Getopt getopt = new Getopt(context.toString(), args, sopts, lopts);
+ Getopt getopt = new Getopt(getName(), args, sopts, lopts);
int code;
while ((code = getopt.getopt()) != -1) {
diff --git a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/FileRecipeCommand.java b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/FileRecipeCommand.java
index 3b74805..2984bab 100644
--- a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/FileRecipeCommand.java
+++ b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/FileRecipeCommand.java
@@ -32,7 +32,7 @@ public class FileRecipeCommand implements RecipeCommand {
return "file";
}
- public void parse(RecipeContext context, String[] args) {
+ public void parse(RecipeParser parser, RecipeContext context, String[] args) {
String sopts = ":s:d:";
LongOpt[] lopts = { new LongOpt("source", LongOpt.REQUIRED_ARGUMENT, null, 's'),
new LongOpt("destination", LongOpt.REQUIRED_ARGUMENT, null, 'd') };
@@ -40,7 +40,7 @@ public class FileRecipeCommand implements RecipeCommand {
String source = null;
String destination = null;
- Getopt getopt = new Getopt(context.toString(), args, sopts, lopts);
+ Getopt getopt = new Getopt(getName(), args, sopts, lopts);
int code;
while ((code = getopt.getopt()) != -1) {
diff --git a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RealizeRecipeCommand.java b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RealizeRecipeCommand.java
new file mode 100644
index 0000000..b187ed8
--- /dev/null
+++ b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RealizeRecipeCommand.java
@@ -0,0 +1,74 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.bundle.filetemplate.recipe;
+
+import gnu.getopt.Getopt;
+import gnu.getopt.LongOpt;
+
+public class RealizeRecipeCommand implements RecipeCommand {
+
+ public String getName() {
+ return "realize";
+ }
+
+ public void parse(RecipeParser parser, RecipeContext context, String[] args) {
+ String sopts = ":f:";
+ LongOpt[] lopts = { new LongOpt("file", LongOpt.REQUIRED_ARGUMENT, null, 'f') };
+
+ String file = null;
+
+ Getopt getopt = new Getopt(getName(), args, sopts, lopts);
+ int code;
+
+ while ((code = getopt.getopt()) != -1) {
+ switch (code) {
+ case ':':
+ case '?': {
+ throw new IllegalArgumentException("Bad recipe command.");
+ }
+
+ case 1: {
+ throw new IllegalArgumentException("Bad recipe command!");
+ }
+
+ case 'f': {
+ file = getopt.getOptarg();
+ break;
+ }
+
+ default: {
+ throw new IllegalArgumentException("Unexpected error in recipe command");
+ }
+
+ }
+ }
+
+ if (file == null) {
+ throw new IllegalArgumentException("Did not specify the file to realize");
+ }
+
+ context.addRealizedFile(file);
+ return;
+ }
+}
diff --git a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeCommand.java b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeCommand.java
index 7cfa964..01c1da3 100644
--- a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeCommand.java
+++ b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeCommand.java
@@ -34,9 +34,10 @@ public interface RecipeCommand {
/**
* Parses this recipe command and optionally puts information in the context.
- *
+ *
+ * @param parser the parser that is invoking this command
* @param context information where the parser can store information regarding the command that was processed
* @param args arguments passed to the command.
*/
- void parse(RecipeContext context, String[] args);
+ void parse(RecipeParser recipeParser, RecipeContext context, String[] args);
}
diff --git a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeContext.java b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeContext.java
index dcea274..cb76a80 100644
--- a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeContext.java
+++ b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeContext.java
@@ -34,15 +34,17 @@ import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
/**
- * Contains information that is gleened from a recipe after it is parsed.
+ * Contains information that is gleened from a recipe during and after it is parsed.
*
* @author John Mazzitelli
*/
public class RecipeContext {
+ private RecipeParser parser;
private final String recipe;
private final Map<String, String> deployFiles;
private final Map<String, String> files;
+ private final Set<String> realizedFiles;
private final Set<String> replacementVariables;
private Configuration replacementVariableValues;
private final List<Script> scripts;
@@ -51,11 +53,24 @@ public class RecipeContext {
this.recipe = recipe;
this.deployFiles = new HashMap<String, String>();
this.files = new HashMap<String, String>();
+ this.realizedFiles = new HashSet<String>();
this.replacementVariables = new HashSet<String>();
this.scripts = new ArrayList<Script>();
}
/**
+ * If this context is currently in use by a parser, this will be the reference to that parser.
+ * @return parser currently using this context
+ */
+ public RecipeParser getParser() {
+ return parser;
+ }
+
+ public void setParser(RecipeParser parser) {
+ this.parser = parser;
+ }
+
+ /**
* The full recipe that this context represents.
*
* @return the actual recipe text
@@ -95,6 +110,20 @@ public class RecipeContext {
}
/**
+ * Returns the pathnames of all files that are to be realized (meaning, those that should
+ * have replacement variables replaced).
+ *
+ * @return set of all realized files
+ */
+ public Set<String> getRealizedFiles() {
+ return this.realizedFiles;
+ }
+
+ public void addRealizedFile(String file) {
+ this.realizedFiles.add(file);
+ }
+
+ /**
* The names of all replacement variables that are found in the recipe.
*
* @return the replacement variables
diff --git a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java
index 13644e6..98f26f6 100644
--- a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java
+++ b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java
@@ -77,17 +77,22 @@ public class RecipeParser {
public void parseRecipe(RecipeContext context) throws Exception {
- BufferedReader recipeReader = new BufferedReader(new StringReader(context.getRecipe()));
- String line = recipeReader.readLine();
- while (line != null) {
- parseRecipeCommandLine(context, line);
- line = recipeReader.readLine();
+ context.setParser(this);
+ try {
+ BufferedReader recipeReader = new BufferedReader(new StringReader(context.getRecipe()));
+ String line = recipeReader.readLine();
+ while (line != null) {
+ parseRecipeCommandLine(context, line);
+ line = recipeReader.readLine();
+ }
+ } finally {
+ context.setParser(null);
}
return;
}
- public void parseRecipeCommandLine(RecipeContext context, String line) throws Exception {
+ protected void parseRecipeCommandLine(RecipeContext context, String line) throws Exception {
// ignore blank lines or comment lines that start with #
if (line == null || line.trim().length() == 0 || line.startsWith("#")) {
return;
@@ -112,7 +117,7 @@ public class RecipeParser {
}
try {
- recipeCommand.parse(context, arguments);
+ recipeCommand.parse(this, context, arguments);
} catch (Exception e) {
throw new Exception("Error in recipe, line [" + line + "]", e);
}
@@ -125,6 +130,7 @@ public class RecipeParser {
RecipeCommand[] knownCommands = new RecipeCommand[] { new ScriptRecipeCommand(), //
new FileRecipeCommand(), //
+ new RealizeRecipeCommand(), //
new DeployRecipeCommand() //
};
@@ -156,14 +162,9 @@ public class RecipeParser {
return replacementVariables;
}
- protected String replaceReplacementVariables(RecipeContext context, String input) {
+ public String replaceReplacementVariables(RecipeContext context, String input) {
- // don't bother if we have no values to replace them with
Configuration replacementValues = context.getReplacementVariableValues();
- if (replacementValues == null) {
- return input;
- }
-
TemplateEngine templateEngine = null;
StringBuffer buffer = new StringBuffer();
Matcher matcher = this.replacementVariableDeclarationPattern.matcher(input);
@@ -172,7 +173,7 @@ public class RecipeParser {
Matcher nameMatcher = this.replacementVariableNamePattern.matcher(next);
if (nameMatcher.find()) {
String key = nameMatcher.group();
- String value = replacementValues.getSimpleValue(key, null);
+ String value = (replacementValues != null) ? replacementValues.getSimpleValue(key, null) : null;
if (value == null) {
// our replacement values don't know how to replace the key, see if our system info template engine can
if (templateEngine == null) {
diff --git a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/ScriptRecipeCommand.java b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/ScriptRecipeCommand.java
index 2173c06..99a0c7c 100644
--- a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/ScriptRecipeCommand.java
+++ b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/ScriptRecipeCommand.java
@@ -32,7 +32,7 @@ public class ScriptRecipeCommand implements RecipeCommand {
return "script";
}
- public void parse(RecipeContext context, String[] args) {
+ public void parse(RecipeParser parser, RecipeContext context, String[] args) {
if (args == null || args.length == 0) {
throw new IllegalArgumentException("Missing the script command to execute");
diff --git a/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java b/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java
index 7d5abef..bfa58e6 100644
--- a/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java
+++ b/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java
@@ -40,6 +40,16 @@ public class RecipeParserTest {
cleanRecipe();
}
+ public void testRealizeRecipe() throws Exception {
+ addRecipeCommand("realize --file=<%opt.dir%>/config.ini");
+ RecipeParser parser = new RecipeParser();
+ RecipeContext context = new RecipeContext(getRecipe());
+ parser.parseRecipe(context);
+ Set<String> files = context.getRealizedFiles();
+ assert files.size() == 1 : files;
+ assert files.contains("<%opt.dir%>/config.ini") : files;
+ }
+
public void testFileRecipe() throws Exception {
addRecipeCommand("file --source=run-me.sh --destination=/opt/run.sh");
addRecipeCommand("file -s META-INF/another.xml -d /etc/another.xml");
diff --git a/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java b/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java
index b0ae578..ffe24f2 100644
--- a/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java
+++ b/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java
@@ -19,13 +19,17 @@
package org.rhq.plugins.filetemplate;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.rhq.bundle.filetemplate.recipe.RecipeContext;
+import org.rhq.bundle.filetemplate.recipe.RecipeParser;
import org.rhq.core.domain.content.PackageVersion;
import org.rhq.core.system.ProcessExecution;
import org.rhq.core.system.ProcessExecutionResults;
@@ -87,6 +91,60 @@ public class ProcessingRecipeContext extends RecipeContext {
}
@Override
+ public void addRealizedFile(String file) {
+ super.addRealizedFile(file);
+
+ File trueFile = new File(file);
+ RecipeParser parser = getParser();
+ File realizedTmpFile = null;
+ FileWriter realizedTmpFileWriter = null;
+ BufferedReader reader = null;
+
+ try {
+
+ realizedTmpFile = File.createTempFile("rhq-realize-", ".tmp", trueFile.getParentFile());
+ realizedTmpFileWriter = new FileWriter(realizedTmpFile);
+
+ reader = new BufferedReader(new FileReader(trueFile));
+ String line = reader.readLine();
+ while (line != null) {
+ line = parser.replaceReplacementVariables(this, line);
+ realizedTmpFileWriter.write(line);
+ realizedTmpFileWriter.write("\n");
+ line = reader.readLine();
+ }
+
+ realizedTmpFileWriter.close();
+ realizedTmpFileWriter = null;
+ reader.close();
+ reader = null;
+
+ trueFile.delete(); // remove the one with the replacement variables in it
+ if (!realizedTmpFile.renameTo(trueFile)) {
+ throw new RuntimeException("Failed to rename realized tmp file [" + realizedTmpFile + "]");
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("Cannot realize file [" + file + "]", e);
+ } finally {
+ if (realizedTmpFileWriter != null) {
+ try {
+ realizedTmpFileWriter.close();
+ } catch (Exception e) {
+ }
+ }
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (Exception e) {
+ }
+ }
+ if (realizedTmpFile != null && realizedTmpFile.exists()) {
+ realizedTmpFile.delete();
+ }
+ }
+ }
+
+ @Override
public void addReplacementVariables(Set<String> replacementVariables) {
super.addReplacementVariables(replacementVariables);
}
14 years, 2 months
[rhq] Branch 'bundle' - modules/common modules/plugins
by mazz
modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/FileRecipeCommand.java | 85 ++++++++++
modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeContext.java | 18 ++
modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java | 7
modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java | 14 +
modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java | 11 +
5 files changed, 134 insertions(+), 1 deletion(-)
New commits:
commit 3c52854a359fa4fb4fae21fc4d0b9323d0ee800b
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Tue Mar 2 19:03:52 2010 -0500
support the file recipe command
diff --git a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/FileRecipeCommand.java b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/FileRecipeCommand.java
new file mode 100644
index 0000000..3b74805
--- /dev/null
+++ b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/FileRecipeCommand.java
@@ -0,0 +1,85 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.bundle.filetemplate.recipe;
+
+import gnu.getopt.Getopt;
+import gnu.getopt.LongOpt;
+
+public class FileRecipeCommand implements RecipeCommand {
+
+ public String getName() {
+ return "file";
+ }
+
+ public void parse(RecipeContext context, String[] args) {
+ String sopts = ":s:d:";
+ LongOpt[] lopts = { new LongOpt("source", LongOpt.REQUIRED_ARGUMENT, null, 's'),
+ new LongOpt("destination", LongOpt.REQUIRED_ARGUMENT, null, 'd') };
+
+ String source = null;
+ String destination = null;
+
+ Getopt getopt = new Getopt(context.toString(), args, sopts, lopts);
+ int code;
+
+ while ((code = getopt.getopt()) != -1) {
+ switch (code) {
+ case ':':
+ case '?': {
+ throw new IllegalArgumentException("Bad recipe command.");
+ }
+
+ case 1: {
+ throw new IllegalArgumentException("Bad recipe command!");
+ }
+
+ case 's': {
+ source = getopt.getOptarg();
+ break;
+ }
+
+ case 'd': {
+ destination = getopt.getOptarg();
+ break;
+ }
+
+ default: {
+ throw new IllegalArgumentException("Unexpected error in recipe command");
+ }
+
+ }
+ }
+
+ if (source == null) {
+ throw new IllegalArgumentException("Did not specify the source file to copy");
+ }
+
+ if (destination == null) {
+ throw new IllegalArgumentException("Did not specify the destination where the file should be copied");
+ }
+
+ context.addFile(source, destination);
+ return;
+ }
+}
diff --git a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeContext.java b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeContext.java
index fb911f3..dcea274 100644
--- a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeContext.java
+++ b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeContext.java
@@ -42,6 +42,7 @@ public class RecipeContext {
private final String recipe;
private final Map<String, String> deployFiles;
+ private final Map<String, String> files;
private final Set<String> replacementVariables;
private Configuration replacementVariableValues;
private final List<Script> scripts;
@@ -49,6 +50,7 @@ public class RecipeContext {
public RecipeContext(String recipe) {
this.recipe = recipe;
this.deployFiles = new HashMap<String, String>();
+ this.files = new HashMap<String, String>();
this.replacementVariables = new HashSet<String>();
this.scripts = new ArrayList<Script>();
}
@@ -77,6 +79,22 @@ public class RecipeContext {
}
/**
+ * Returns all the files that are strictly to be copied to some location.
+ * The key is the bundle file's name, the value is the full path and filename where
+ * the file should be copied to. No processing of these files will occur other than
+ * they are copied.
+ *
+ * @return map of all files to be deployed and the location where they are to be deployed
+ */
+ public Map<String, String> getFiles() {
+ return this.files;
+ }
+
+ public void addFile(String source, String destination) {
+ this.files.put(source, destination);
+ }
+
+ /**
* The names of all replacement variables that are found in the recipe.
*
* @return the replacement variables
diff --git a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java
index d18fd4b..13644e6 100644
--- a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java
+++ b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java
@@ -111,7 +111,11 @@ public class RecipeParser {
context.addReplacementVariables(replacementVars);
}
- recipeCommand.parse(context, arguments);
+ try {
+ recipeCommand.parse(context, arguments);
+ } catch (Exception e) {
+ throw new Exception("Error in recipe, line [" + line + "]", e);
+ }
return;
}
@@ -120,6 +124,7 @@ public class RecipeParser {
HashMap<String, RecipeCommand> commands = new HashMap<String, RecipeCommand>();
RecipeCommand[] knownCommands = new RecipeCommand[] { new ScriptRecipeCommand(), //
+ new FileRecipeCommand(), //
new DeployRecipeCommand() //
};
diff --git a/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java b/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java
index 40bc7fb..7d5abef 100644
--- a/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java
+++ b/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java
@@ -40,6 +40,20 @@ public class RecipeParserTest {
cleanRecipe();
}
+ public void testFileRecipe() throws Exception {
+ addRecipeCommand("file --source=run-me.sh --destination=/opt/run.sh");
+ addRecipeCommand("file -s META-INF/another.xml -d /etc/another.xml");
+ RecipeParser parser = new RecipeParser();
+ RecipeContext context = new RecipeContext(getRecipe());
+ parser.parseRecipe(context);
+ Map<String, String> files = context.getFiles();
+ assert files.size() == 2 : files;
+ assert files.get("run-me.sh") != null : files;
+ assert files.get("run-me.sh").equals("/opt/run.sh") : files;
+ assert files.get("META-INF/another.xml") != null : files;
+ assert files.get("META-INF/another.xml").equals("/etc/another.xml") : files;
+ }
+
public void testScriptRecipe() throws Exception {
addRecipeCommand("script run-me.sh");
addRecipeCommand("script lots-o-params.sh -d /opt/jboss -- foo.txt \"hello world\"");
diff --git a/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java b/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java
index 2e0d1dc..b0ae578 100644
--- a/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java
+++ b/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java
@@ -76,6 +76,17 @@ public class ProcessingRecipeContext extends RecipeContext {
}
@Override
+ public void addFile(String filename, String directory) {
+ super.addDeployFile(filename, directory);
+
+ File existingFile = new File(this.baseWorkingDirectory, filename);
+ File newFile = new File(directory, filename);
+ if (!existingFile.renameTo(newFile)) {
+ throw new RuntimeException("Failed to move file [" + existingFile + "] to [" + newFile + "]");
+ }
+ }
+
+ @Override
public void addReplacementVariables(Set<String> replacementVariables) {
super.addReplacementVariables(replacementVariables);
}
14 years, 2 months
[rhq] Branch 'bundle' - modules/common modules/enterprise modules/plugins
by mazz
modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/ConfigdefRecipeCommand.java | 78 ---------
modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeContext.java | 68 ++++++++
modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java | 2
modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/ScriptRecipeCommand.java | 51 ++++++
modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java | 14 +
modules/enterprise/server/plugins/filetemplate-bundle/src/main/java/org/rhq/enterprise/server/plugins/filetemplate/BundleServerPluginComponent.java | 2
modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/FileTemplateBundlePluginServerComponent.java | 85 ++++++----
modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java | 17 ++
8 files changed, 208 insertions(+), 109 deletions(-)
New commits:
commit 31cdbfd2db0c5220319665482b41984419dd4cbc
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Tue Mar 2 18:14:44 2010 -0500
add script recipe command
diff --git a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/ConfigdefRecipeCommand.java b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/ConfigdefRecipeCommand.java
deleted file mode 100644
index 26d1b82..0000000
--- a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/ConfigdefRecipeCommand.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.rhq.bundle.filetemplate.recipe;
-
-import gnu.getopt.Getopt;
-import gnu.getopt.LongOpt;
-
-/**
- * @deprecated I think this command will not be used - probably should delete it
- * @author mazz
- */
-public class ConfigdefRecipeCommand implements RecipeCommand {
-
- public String getName() {
- return "configdef";
- }
-
- public void parse(RecipeContext context, String[] args) {
- String sopts = ":f:";
- LongOpt[] lopts = { new LongOpt("file", LongOpt.REQUIRED_ARGUMENT, null, 'f') };
-
- String filename = null;
-
- Getopt getopt = new Getopt(context.toString(), args, sopts, lopts);
- int code;
-
- while ((code = getopt.getopt()) != -1) {
- switch (code) {
- case ':':
- case '?': {
- throw new IllegalArgumentException("Bad recipe argument.");
- }
-
- case 1: {
- throw new IllegalArgumentException("Bad recipe argument!");
- }
-
- case 'f': {
- filename = getopt.getOptarg();
- break;
- }
-
- default: {
- throw new IllegalArgumentException("Unexpected error in recipe command");
- }
- }
- }
-
- if (filename == null) {
- throw new IllegalArgumentException("Missing the -f argument to indicate what the config def filename is");
- }
-
- // TODO: what to do? can I delete this command entirely?
-
- return;
- }
-}
diff --git a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeContext.java b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeContext.java
index 43f0df1..fb911f3 100644
--- a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeContext.java
+++ b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeContext.java
@@ -23,8 +23,10 @@
package org.rhq.bundle.filetemplate.recipe;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -42,11 +44,13 @@ public class RecipeContext {
private final Map<String, String> deployFiles;
private final Set<String> replacementVariables;
private Configuration replacementVariableValues;
+ private final List<Script> scripts;
public RecipeContext(String recipe) {
this.recipe = recipe;
this.deployFiles = new HashMap<String, String>();
this.replacementVariables = new HashSet<String>();
+ this.scripts = new ArrayList<Script>();
}
/**
@@ -114,4 +118,68 @@ public class RecipeContext {
}
values.put(new PropertySimple(name, value));
}
+
+ /**
+ * Returns a set of all the names of scripts found in the recipe.
+ *
+ * @return script names
+ */
+ public Set<String> getScriptFiles() {
+ Set<String> scriptFiles = new HashSet<String>();
+ for (Script script : this.scripts) {
+ scriptFiles.add(script.getExecutable());
+ }
+ return scriptFiles;
+ }
+
+ /**
+ * Adds a script that the recipe wants invoked.
+ *
+ * @param exe the script executable
+ * @param exeArgs the arguments to pass to the script
+ */
+ public void addScript(String exe, List<String> exeArgs) {
+ this.scripts.add(new Script(exe, exeArgs));
+ }
+
+ class Script {
+ private final List<String> args;
+ private final String exe;
+
+ public Script(String exe, List<String> args) {
+ this.exe = exe;
+ this.args = args;
+ }
+
+ public String getExecutable() {
+ return exe;
+ }
+
+ public List<String> getArguments() {
+ return args;
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder str = new StringBuilder("RecipeContext:\n");
+ str.append("Recipe Text:\n").append(getRecipe()).append("\n");
+ str.append("Deploy Files: ").append(getDeployFiles()).append("\n");
+ str.append("Replacement Vars: ").append(getReplacementVariables()).append("\n");
+
+ str.append("Replacement Values: ");
+ Configuration values = getReplacementVariableValues();
+ if (values == null) {
+ str.append("<none>");
+ } else {
+ str.append(values.getProperties());
+ }
+ str.append("\n");
+
+ str.append("Script Files: ").append(getScriptFiles()).append("\n");
+ for (Script script : this.scripts) {
+ str.append("* ").append(script.getExecutable()).append(" ").append(script.getArguments()).append("\n");
+ }
+ return str.toString();
+ }
}
diff --git a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java
index f8db1c8..d18fd4b 100644
--- a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java
+++ b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/RecipeParser.java
@@ -119,7 +119,7 @@ public class RecipeParser {
protected HashMap<String, RecipeCommand> createRecipeCommands() {
HashMap<String, RecipeCommand> commands = new HashMap<String, RecipeCommand>();
- RecipeCommand[] knownCommands = new RecipeCommand[] { new ConfigdefRecipeCommand(), //
+ RecipeCommand[] knownCommands = new RecipeCommand[] { new ScriptRecipeCommand(), //
new DeployRecipeCommand() //
};
diff --git a/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/ScriptRecipeCommand.java b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/ScriptRecipeCommand.java
new file mode 100644
index 0000000..2173c06
--- /dev/null
+++ b/modules/common/filetemplate-bundle/src/main/java/org/rhq/bundle/filetemplate/recipe/ScriptRecipeCommand.java
@@ -0,0 +1,51 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.bundle.filetemplate.recipe;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ScriptRecipeCommand implements RecipeCommand {
+
+ public String getName() {
+ return "script";
+ }
+
+ public void parse(RecipeContext context, String[] args) {
+
+ if (args == null || args.length == 0) {
+ throw new IllegalArgumentException("Missing the script command to execute");
+ }
+
+ String exe = args[0];
+ List<String> exeArgs = new ArrayList<String>(args.length - 1);
+ for (int i = 1; i < args.length; i++) {
+ exeArgs.add(args[i]);
+ }
+
+ context.addScript(exe, exeArgs);
+
+ return;
+ }
+}
diff --git a/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java b/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java
index b2efdaf..40bc7fb 100644
--- a/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java
+++ b/modules/common/filetemplate-bundle/src/test/java/org/rhq/bundle/filetemplate/recipe/RecipeParserTest.java
@@ -24,6 +24,7 @@
package org.rhq.bundle.filetemplate.recipe;
import java.util.Map;
+import java.util.Set;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -39,6 +40,19 @@ public class RecipeParserTest {
cleanRecipe();
}
+ public void testScriptRecipe() throws Exception {
+ addRecipeCommand("script run-me.sh");
+ addRecipeCommand("script lots-o-params.sh -d /opt/jboss -- foo.txt \"hello world\"");
+ addRecipeCommand("script run-me.sh with params");
+ RecipeParser parser = new RecipeParser();
+ RecipeContext context = new RecipeContext(getRecipe());
+ parser.parseRecipe(context);
+ Set<String> scripts = context.getScriptFiles();
+ assert scripts.size() == 2 : scripts;
+ assert scripts.contains("run-me.sh") : scripts;
+ assert scripts.contains("lots-o-params.sh") : scripts;
+ }
+
public void testSimpleRecipeReplacementVariables() throws Exception {
addRecipeCommand("# <% ignored.inside.comment %>");
addRecipeCommand("deploy -f jboss.tar -d \"<% opt.dir %>/jboss\"");
diff --git a/modules/enterprise/server/plugins/filetemplate-bundle/src/main/java/org/rhq/enterprise/server/plugins/filetemplate/BundleServerPluginComponent.java b/modules/enterprise/server/plugins/filetemplate-bundle/src/main/java/org/rhq/enterprise/server/plugins/filetemplate/BundleServerPluginComponent.java
index 34902c0..99b8504 100644
--- a/modules/enterprise/server/plugins/filetemplate-bundle/src/main/java/org/rhq/enterprise/server/plugins/filetemplate/BundleServerPluginComponent.java
+++ b/modules/enterprise/server/plugins/filetemplate-bundle/src/main/java/org/rhq/enterprise/server/plugins/filetemplate/BundleServerPluginComponent.java
@@ -76,6 +76,8 @@ public class BundleServerPluginComponent implements ServerPluginComponent, Bundl
Set<String> bundleFileNames = new HashSet<String>();
Map<String, String> deployFiles = recipeContext.getDeployFiles();
bundleFileNames.addAll(deployFiles.keySet());
+ Set<String> scriptFiles = recipeContext.getScriptFiles();
+ bundleFileNames.addAll(scriptFiles);
ConfigurationDefinition configDef = null;
if (recipeContext.getReplacementVariables() != null) {
diff --git a/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/FileTemplateBundlePluginServerComponent.java b/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/FileTemplateBundlePluginServerComponent.java
index 7f76757..cee69db 100644
--- a/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/FileTemplateBundlePluginServerComponent.java
+++ b/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/FileTemplateBundlePluginServerComponent.java
@@ -75,42 +75,25 @@ public class FileTemplateBundlePluginServerComponent implements ResourceComponen
List<PackageVersion> packageVersions = bundleManager.getAllBundleVersionPackageVersions(bundleVersion);
for (PackageVersion packageVersion : packageVersions) {
File packageFile = new File(tmpDir, packageVersion.getFileName());
- packageFile.getParentFile().mkdirs();
- FileOutputStream fos = new FileOutputStream(packageFile);
- try {
- long size = bundleManager.getFileContent(packageVersion, fos);
- if (packageVersion.getFileSize() != null && size != packageVersion.getFileSize().longValue()) {
- log.warn("Downloaded bundle file [" + packageVersion + "] but its size was [" + size
- + "] when it was expected to be [" + packageVersion.getFileSize() + "].");
- }
- } finally {
- fos.close();
- }
- // verify the content
- if (packageVersion.getMD5() != null) {
- String realMD5 = MessageDigestGenerator.getDigestString(packageFile);
- if (!packageVersion.getMD5().equals(realMD5)) {
- throw new Exception("Package version [" + packageVersion + "] failed MD5 check. expected=["
- + packageVersion.getMD5() + "], actual=[" + realMD5 + "]");
- }
- } else if (packageVersion.getSHA256() != null) {
- FileInputStream is = new FileInputStream(packageFile);
+ try {
+ verifyHash(packageVersion, packageFile);
+ } catch (Exception e) {
+ // file either doesn't exist or it hash doesn't match, download a new copy
+ packageFile.getParentFile().mkdirs();
+ FileOutputStream fos = new FileOutputStream(packageFile);
try {
- MessageDigestGenerator gen = new MessageDigestGenerator("SHA256");
- gen.add(is);
- String realSHA256 = gen.getDigestString();
- if (!packageVersion.getSHA256().equals(realSHA256)) {
- throw new Exception("Package version [" + packageVersion
- + "] failed SHA256 check. expected=[" + packageVersion.getSHA256() + "], actual=["
- + realSHA256 + "]");
+ long size = bundleManager.getFileContent(packageVersion, fos);
+ if (packageVersion.getFileSize() != null && size != packageVersion.getFileSize().longValue()) {
+ log.warn("Downloaded bundle file [" + packageVersion + "] but its size was [" + size
+ + "] when it was expected to be [" + packageVersion.getFileSize() + "].");
}
} finally {
- is.close();
+ fos.close();
}
- } else {
- log.debug("Package version [" + packageVersion + "] has no MD5/SHA256 hash - not verifying it");
+ // now try to verify it again, if this throws an exception, that is very bad and we need to abort
+ verifyHash(packageVersion, packageFile);
}
packageVersionFiles.put(packageVersion, packageFile);
@@ -131,4 +114,46 @@ public class FileTemplateBundlePluginServerComponent implements ResourceComponen
}
return result;
}
+
+ /**
+ * Checks to see if the package file's hash matches that of the given package version.
+ * If the file doesn't exist or the hash doesn't match, an exception is thrown.
+ * This method returns normally if the hash matches the file.
+ * If there is no known hash in the package version, this method returns normally.
+ *
+ * @param packageVersion contains the hash that is expected
+ * @param packageFile the local file whose hash is to be checked
+ * @throws Exception if the file does not match the hash or the file doesn't exist
+ */
+ private void verifyHash(PackageVersion packageVersion, File packageFile) throws Exception {
+ if (!packageFile.exists()) {
+ throw new Exception("Package version [" + packageVersion + "] does not exist, cannot check hash");
+ }
+
+ if (packageVersion.getMD5() != null) {
+ String realMD5 = MessageDigestGenerator.getDigestString(packageFile);
+ if (!packageVersion.getMD5().equals(realMD5)) {
+ throw new Exception("Package version [" + packageVersion + "] failed MD5 check. expected=["
+ + packageVersion.getMD5() + "], actual=[" + realMD5 + "]");
+ }
+ } else if (packageVersion.getSHA256() != null) {
+ FileInputStream is = new FileInputStream(packageFile);
+ try {
+ MessageDigestGenerator gen = new MessageDigestGenerator("SHA256");
+ gen.add(is);
+ String realSHA256 = gen.getDigestString();
+ if (!packageVersion.getSHA256().equals(realSHA256)) {
+ throw new Exception("Package version [" + packageVersion + "] failed SHA256 check. expected=["
+ + packageVersion.getSHA256() + "], actual=[" + realSHA256 + "]");
+ }
+ } finally {
+ is.close();
+ }
+
+ } else {
+ log.debug("Package version [" + packageVersion + "] has no MD5/SHA256 hash - not verifying it");
+ }
+
+ return;
+ }
}
diff --git a/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java b/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java
index 1dbad78..2e0d1dc 100644
--- a/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java
+++ b/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/ProcessingRecipeContext.java
@@ -80,6 +80,23 @@ public class ProcessingRecipeContext extends RecipeContext {
super.addReplacementVariables(replacementVariables);
}
+ @Override
+ public void addScript(String exe, List<String> exeArgs) {
+ super.addScript(exe, exeArgs);
+
+ File scriptFile = new File(this.baseWorkingDirectory, exe);
+
+ ProcessExecution pe = new ProcessExecution(scriptFile.getAbsolutePath());
+ pe.setArguments(exeArgs);
+ pe.setWaitForCompletion(30 * 60 * 1000L);
+ pe.setWorkingDirectory(scriptFile.getParent());
+
+ ProcessExecutionResults results = this.systemInfo.executeProcess(pe);
+ if (results.getError() != null) {
+ throw new RuntimeException("Could not execute script [" + pe + "]: " + results, results.getError());
+ }
+ }
+
private ProcessExecution getUnzipExecution(String filename, String directory) {
String exe;
List<String> args = null;
14 years, 2 months
[rhq] Branch 'gwt' - 2 commits - modules/enterprise
by Greg Hinkle
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java | 27 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tab/SubTabLayout.java | 147 ++++++++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tab/TwoLevelTab.java | 52 +++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tab/TwoLevelTabSet.java | 43 ++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java | 78 +++--
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeView.java | 7
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceView.java | 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/GraphListView.java | 2
8 files changed, 314 insertions(+), 44 deletions(-)
New commits:
commit 013f7b7627edbe17d53ed90a049acfafa94844ac
Author: Greg Hinkle <ghinkle(a)redhat.com>
Date: Tue Mar 2 17:34:25 2010 -0500
New TwoLevelTab component supports the basics of tabs/subtabs (more to add around history navigation for this)
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tab/SubTabLayout.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tab/SubTabLayout.java
new file mode 100644
index 0000000..2e15b68
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tab/SubTabLayout.java
@@ -0,0 +1,147 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.components.tab;
+
+import com.smartgwt.client.types.Overflow;
+import com.smartgwt.client.types.SelectionType;
+import com.smartgwt.client.widgets.Button;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.events.ClickEvent;
+import com.smartgwt.client.widgets.events.ClickHandler;
+import com.smartgwt.client.widgets.layout.VLayout;
+import com.smartgwt.client.widgets.toolbar.ToolStrip;
+
+import java.util.LinkedHashMap;
+
+/**
+ * @author Greg Hinkle
+ */
+public class SubTabLayout extends VLayout {
+
+ ToolStrip buttonBar;
+
+ LinkedHashMap<String, Canvas> subtabs = new LinkedHashMap<String, Canvas>();
+
+ Canvas currentlyDisplayed;
+ String currentlySelected;
+ int currentIndex = 0;
+
+ public SubTabLayout() {
+ super();
+ setOverflow(Overflow.AUTO);
+ }
+
+ @Override
+ protected void onDraw() {
+ super.onDraw();
+
+ setWidth100();
+ setHeight100();
+ setMargin(0);
+ setPadding(0);
+
+
+ buttonBar = new ToolStrip();
+ buttonBar.setBackgroundColor("grey");
+ buttonBar.setWidth100();
+ buttonBar.setBorder(null);
+
+ addMember(buttonBar);
+
+
+ int i = 0;
+
+ for (final String title : subtabs.keySet()) {
+ if (currentlyDisplayed == null) {
+ currentlyDisplayed = subtabs.get(title);
+ }
+
+
+ Button button = new Button(title);
+ button.setShowRollOver(false);
+ button.setActionType(SelectionType.RADIO);
+ button.setRadioGroup("subtabs");
+ button.setBorder(null);
+
+ button.setBaseStyle("SubTabButton");
+
+// button.setStyleName("SubTabButton");
+// button.setStylePrimaryName("SubTabButton");
+
+ final Integer index = i++;
+
+ button.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent clickEvent) {
+ currentlySelected = title;
+ currentIndex = index;
+ draw(subtabs.get(title));
+ }
+ });
+
+ buttonBar.addMember(button);
+
+ }
+
+ // Initial settings
+ Button b = (Button) buttonBar.getMember(0);
+ b.select();
+ if (currentlyDisplayed != null) {
+ addMember(currentlyDisplayed);
+ }
+ }
+
+ public void updateSubTab(String title, Canvas canvas) {
+ subtabs.put(title, canvas);
+ if (isDrawn() && title.equals(currentlySelected)) {
+ draw(canvas);
+ }
+
+ }
+
+ private void draw(Canvas canvas) {
+ if (currentlyDisplayed != null) {
+ currentlyDisplayed.hide();
+// removeMember(currentlyDisplayed);
+ }
+ if (canvas != null) {
+ if (hasMember(canvas)) {
+ canvas.show();
+ } else {
+ if (!canvas.isCreated()) {
+ canvas.setOverflow(Overflow.SCROLL);
+ }
+ addMember(canvas);
+ markForRedraw();
+ }
+ currentlyDisplayed = canvas;
+ }
+ }
+
+
+ public void registerSubTab(String title, Canvas canvas) {
+ if (currentlySelected == null) {
+ currentlySelected = title;
+ }
+ subtabs.put(title, canvas);
+ }
+
+ public int getCurrentIndex() {
+ return currentIndex;
+ }
+}
\ No newline at end of file
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tab/TwoLevelTab.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tab/TwoLevelTab.java
new file mode 100644
index 0000000..7a44277
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tab/TwoLevelTab.java
@@ -0,0 +1,52 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.components.tab;
+
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.tab.Tab;
+
+/**
+ * @author Greg Hinkle
+ */
+public class TwoLevelTab extends Tab {
+
+ private SubTabLayout layout;
+
+ public TwoLevelTab(String title, String icon) {
+ super(title, icon);
+
+ layout = new SubTabLayout();
+ }
+
+
+ public void updateSubTab(String tab, Canvas canvas) {
+ layout.updateSubTab(tab, canvas);
+ }
+
+ public void registerSubTabs(String... tabs) {
+ for (String tab :tabs) {
+ layout.registerSubTab(tab, null);
+ }
+ }
+
+ @Override
+ public Canvas getPane() {
+ return layout;
+ }
+}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tab/TwoLevelTabSet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tab/TwoLevelTabSet.java
new file mode 100644
index 0000000..ba48226
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tab/TwoLevelTabSet.java
@@ -0,0 +1,43 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.components.tab;
+
+import com.smartgwt.client.widgets.tab.Tab;
+import com.smartgwt.client.widgets.tab.TabSet;
+
+/**
+ * @author Greg Hinkle
+ */
+public class TwoLevelTabSet extends TabSet {
+
+
+ @Override
+ public void setTabs(Tab... tabs) {
+ super.setTabs(tabs);
+ for (Tab tab : tabs) {
+ TwoLevelTab tltab = (TwoLevelTab) tab;
+
+
+ updateTab(tab,tltab.getPane());
+
+ }
+
+ }
+}
+
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java
index 38f36a4..9c6d2ae 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java
@@ -24,6 +24,8 @@ import org.rhq.enterprise.gui.coregui.client.components.FullHTMLPane;
import org.rhq.enterprise.gui.coregui.client.components.SimpleCollapsiblePanel;
import org.rhq.enterprise.gui.coregui.client.components.SubTabLayout;
import org.rhq.enterprise.gui.coregui.client.components.configuration.ConfigurationEditor;
+import org.rhq.enterprise.gui.coregui.client.components.tab.TwoLevelTab;
+import org.rhq.enterprise.gui.coregui.client.components.tab.TwoLevelTabSet;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.ResourceSelectListener;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.monitoring.GraphListView;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTypeRepository;
@@ -48,15 +50,16 @@ public class ResourceDetailView extends VLayout implements ResourceSelectListene
private SimpleCollapsiblePanel summaryPanel;
private ResourceSummaryView summaryView;
- private Tab summaryTab;
- private Tab monitoringTab;
- private Tab inventoryTab;
- private Tab operationsTab;
- private Tab alertsTab;
- private Tab configurationTab;
- private Tab eventsTab;
- private Tab contentTab;
- private TabSet topTabSet;
+ private TwoLevelTab summaryTab;
+ private TwoLevelTab monitoringTab;
+ private TwoLevelTab inventoryTab;
+ private TwoLevelTab operationsTab;
+ private TwoLevelTab alertsTab;
+ private TwoLevelTab configurationTab;
+ private TwoLevelTab eventsTab;
+ private TwoLevelTab contentTab;
+
+ private TwoLevelTabSet topTabSet;
HTMLFlow title = new HTMLFlow();
@@ -65,8 +68,8 @@ public class ResourceDetailView extends VLayout implements ResourceSelectListene
}
@Override
- protected void onInit() {
- super.onInit();
+ protected void onDraw() {
+ super.onDraw();
setWidth100();
setHeight100();
@@ -77,21 +80,34 @@ public class ResourceDetailView extends VLayout implements ResourceSelectListene
// The Tabs section
- topTabSet = new TabSet();
+ topTabSet = new TwoLevelTabSet();
topTabSet.setTabBarPosition(Side.TOP);
topTabSet.setWidth100();
topTabSet.setHeight100();
topTabSet.setEdgeMarginSize(0);
topTabSet.setEdgeSize(0);
- summaryTab = new Tab("Summary", "/images/icons/Service_up_16.png");
- monitoringTab = new Tab("Monitoring", "/images/icons/Monitor_grey_16.png");
- inventoryTab = new Tab("Inventory", "/images/icons/Inventory_grey_16.png");
- operationsTab = new Tab("Operations", "/images/icons/Operation_grey_16.png");
- alertsTab = new Tab("Alerts", "/images/icons/Alert_grey_16.png");
- configurationTab = new Tab("Configuration", "/images/icons/Configure_grey_16.png");
- eventsTab = new Tab("Events", "/images/icons/Events_grey_16.png");
- contentTab = new Tab("Content", "/images/icons/Content_grey_16.png");
+ summaryTab = new TwoLevelTab("Summary", "/images/icons/Service_up_16.png");
+ summaryTab.registerSubTabs("Overview","Timeline");
+
+ monitoringTab = new TwoLevelTab("Monitoring", "/images/icons/Monitor_grey_16.png");
+ monitoringTab.registerSubTabs("Graphs","Tables","Traits","Availability","Schedules");
+
+ inventoryTab = new TwoLevelTab("Inventory", "/images/icons/Inventory_grey_16.png");
+ inventoryTab.registerSubTabs("Children","Connection Settings");
+
+ operationsTab = new TwoLevelTab("Operations", "/images/icons/Operation_grey_16.png");
+ operationsTab.registerSubTabs("History", "Scheduled");
+
+ alertsTab = new TwoLevelTab("Alerts", "/images/icons/Alert_grey_16.png");
+ alertsTab.registerSubTabs("Alert History", "Alert Definitions");
+
+ configurationTab = new TwoLevelTab("Configuration", "/images/icons/Configure_grey_16.png");
+ configurationTab.registerSubTabs("Current", "History");
+
+ eventsTab = new TwoLevelTab("Events", "/images/icons/Events_grey_16.png");
+
+ contentTab = new TwoLevelTab("Content", "/images/icons/Content_grey_16.png");
topTabSet.setTabs(summaryTab, monitoringTab, inventoryTab, operationsTab, alertsTab, configurationTab, eventsTab, contentTab);
@@ -119,21 +135,19 @@ public class ResourceDetailView extends VLayout implements ResourceSelectListene
FullHTMLPane summaryPane = new FullHTMLPane("/rhq/resource/summary/overview-plain.xhtml?id=" + resource.getId());
FullHTMLPane timelinePane = new FullHTMLPane("/rhq/resource/summary/timeline-plain.xhtml?id=" + resource.getId());
- SubTabLayout summarySet = new SubTabLayout();
- summarySet.registerSubTab("Overview", summaryPane);
- summarySet.registerSubTab("Timeline", timelinePane);
+ summaryTab.updateSubTab("Overview", summaryPane);
+ summaryTab.updateSubTab("Timeline", timelinePane);
+
+
+ monitoringTab.updateSubTab("Graphs", new GraphListView(resource)); // new FullHTMLPane("/rhq/common/monitor/graphs.xhtml?id=" + resource.getId()));
+ monitoringTab.updateSubTab("Tables", new FullHTMLPane("/rhq/common/monitor/tables.xhtml?id=" + resource.getId()));
+ monitoringTab.updateSubTab("Traits", new FullHTMLPane("/rhq/resource/monitor/traits.xhtml?id=" + resource.getId()));
+ monitoringTab.updateSubTab("Availability", new FullHTMLPane("/rhq/resource/monitor/availabilityHistory.xhtml?id=" + resource.getId()));
+ monitoringTab.updateSubTab("Schedules", new FullHTMLPane("/rhq/resource/monitor/schedules.xhtml?id=" + resource.getId()));
- topTabSet.updateTab(summaryTab, summarySet);
- SubTabLayout monitoringSet = new SubTabLayout();
- monitoringSet.registerSubTab("Graphs", new GraphListView(resource)); // new FullHTMLPane("/rhq/common/monitor/graphs.xhtml?id=" + resource.getId()));
- monitoringSet.registerSubTab("Tables", new FullHTMLPane("/rhq/common/monitor/tables.xhtml?id=" + resource.getId()));
- monitoringSet.registerSubTab("Traits", new FullHTMLPane("/rhq/resource/monitor/traits.xhtml?id=" + resource.getId()));
- monitoringSet.registerSubTab("Availability", new FullHTMLPane("/rhq/resource/monitor/availabilityHistory.xhtml?id=" + resource.getId()));
- monitoringSet.registerSubTab("Schedules", new FullHTMLPane("/rhq/resource/monitor/schedules.xhtml?id=" + resource.getId()));
- topTabSet.updateTab(monitoringTab, monitoringSet);
+ configurationTab.updateSubTab("Current", new ConfigurationEditor(resource.getId(), resource.getResourceType().getId()));
- topTabSet.updateTab(configurationTab, new ConfigurationEditor(resource.getId(), resource.getResourceType().getId()));
topTabSet.setSelectedTab(selectedTab);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeView.java
index dce0409..fb13013 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeView.java
@@ -292,6 +292,10 @@ public class ResourceTreeView extends VLayout {
return null;
}
+ private void setRootResource(Resource rootResource) {
+ this.rootResource = rootResource;
+ }
+
public void setSelectedResource(final Resource selectedResource) {
this.selectedResource = selectedResource;
@@ -317,8 +321,7 @@ public class ResourceTreeView extends VLayout {
}
buildTree();
- ResourceTreeView.this.rootResource = root;
-
+ setRootResource(root);
ResourceTreeDatasource dataSource = new ResourceTreeDatasource(result);
treeGrid.setDataSource(dataSource);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceView.java
index 61a7267..63bcea4 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceView.java
@@ -129,7 +129,7 @@ public class ResourceView extends HLayout implements ViewRenderer {
}
public View renderView(ViewId viewId, boolean lastNode) throws UnknownViewException {
- String parentPath = viewId.getParent().getPath();
+ String parentPath = viewId.getParent().getPath();
if (!parentPath.equals("Resource")) {
throw new UnknownViewException();
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/GraphListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/GraphListView.java
index 2c3a254..1fbeee3 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/GraphListView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/GraphListView.java
@@ -29,6 +29,7 @@ import org.rhq.enterprise.gui.coregui.client.inventory.resource.ResourceSelectLi
import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTypeRepository;
import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.layout.VLayout;
@@ -51,6 +52,7 @@ public class GraphListView extends VLayout implements ResourceSelectListener {
public GraphListView(Resource resource) {
this.resource = resource;
+ setOverflow(Overflow.SCROLL);
}
commit bf8ccaad90117640f514d387b9df8a5422b601b7
Author: Greg Hinkle <ghinkle(a)redhat.com>
Date: Tue Mar 2 17:33:11 2010 -0500
Don't destroy root views when reselecting them
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java
index 468dcea..745c4fc 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java
@@ -163,7 +163,7 @@ public class CoreGUI implements EntryPoint {
// canvas.addChild(new AdministrationView()) ; //DemoCanvas());
- rootCanvas.draw();
+ rootCanvas.draw();
History.addValueChangeHandler(new ValueChangeHandler<String>() {
public void onValueChange(ValueChangeEvent<String> historyChangeEvent) {
@@ -265,7 +265,7 @@ public class CoreGUI implements EntryPoint {
public static void updateBreadCrumbDisplayName(ViewId viewId, String displayName) {
int index = -1;
for (ViewId current = viewId.getParent(); current != null; current = current.getParent()) {
- index++;
+ index++;
}
List<Breadcrumb> breadcrumbs = breadCrumbTrailPane.getBreadcrumbs();
if (index < breadcrumbs.size()) {
@@ -278,20 +278,29 @@ public class CoreGUI implements EntryPoint {
}
private class RootCanvas extends VLayout implements ViewRenderer {
+
+ ViewId currentViewId;
+ Canvas currentCanvas;
+
private RootCanvas() {
setWidth100(); // (1200);
setHeight100(); // (900);
}
public View renderView(ViewId viewId, boolean lastNode) throws UnknownViewException {
- String path = viewId.getPath();
- Canvas canvas = createContent(path);
- if (canvas == null) {
- throw new UnknownViewException();
+ if (!viewId.equals(currentViewId)) {
+ currentViewId = viewId;
+ String path = viewId.getPath();
+ Canvas canvas = createContent(path);
+ if (canvas == null) {
+ throw new UnknownViewException();
+ }
+ currentCanvas = canvas;
+ setContent(canvas);
}
- setContent(canvas);
- ViewRenderer descendantViewRender = (canvas instanceof ViewRenderer) ?
- (ViewRenderer)canvas : null;
+ ViewRenderer descendantViewRender = (currentCanvas instanceof ViewRenderer) ?
+ (ViewRenderer) currentCanvas : null;
+
return new View(viewId, descendantViewRender);
}
}
14 years, 2 months
[rhq] Branch 'bundle' - modules/enterprise
by mazz
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java | 17 --
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java | 61 ----------
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginServiceMBean.java | 24 +++
3 files changed, 36 insertions(+), 66 deletions(-)
New commits:
commit 3c61acc239ef4eb7e4bdd086cb5f533ca845e1c8
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Tue Mar 2 15:57:09 2010 -0500
fix bundle test so the mock PC is started properly
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java
index e8ac546..a7cf52d 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java
@@ -65,18 +65,14 @@ public class BundleManagerBeanTest extends AbstractEJB3Test {
public void beforeMethod() {
super.startTest();
- if (null == ps) {
- ps = new TestBundleServerPluginService();
- pc = ps.createMasterPluginContainer();
- } else {
- pc.initialize(ps.masterConfig);
- }
-
+ this.ps = new TestBundleServerPluginService();
+ prepareCustomServerPluginService(this.ps);
bundleManagerBean = LookupUtil.getBundleManager();
+ this.ps.startMasterPluginContainer();
}
@AfterMethod(alwaysRun = true)
- public void afterMethod() {
+ public void afterMethod() throws Exception {
EntityManager em = null;
@@ -133,9 +129,8 @@ public class BundleManagerBeanTest extends AbstractEJB3Test {
}
}
- if (null != pc) {
- pc.shutdown();
- }
+ unprepareServerPluginService();
+ this.ps = null;
super.endTest();
}
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java
index dcbc951..64bd5af 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java
@@ -39,18 +39,15 @@ import org.rhq.enterprise.server.plugin.pc.ServerPluginEnvironment;
import org.rhq.enterprise.server.plugin.pc.ServerPluginManager;
import org.rhq.enterprise.server.plugin.pc.ServerPluginService;
import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
-import org.rhq.enterprise.server.plugin.pc.generic.GenericServerPluginContainer;
-import org.rhq.enterprise.server.plugin.pc.generic.TestGenericServerPluginServiceMBean;
+import org.rhq.enterprise.server.plugin.pc.bundle.BundleServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.bundle.BundleServerPluginManager;
import org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorMetadataParser;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
/**
- * Used as a mock service for the generic server plugin container.
+ * Used as a mock service for the bundle server plugin container.
*/
-public class TestBundleServerPluginService extends ServerPluginService implements TestGenericServerPluginServiceMBean {
- public enum State {
- INITIALIZED, STARTED, STOPPED, UNINITIALIZED
- }
+public class TestBundleServerPluginService extends ServerPluginService implements TestBundleServerPluginServiceMBean {
// public so tests can directly set these
public TestMasterServerPluginContainer master;
@@ -105,9 +102,7 @@ public class TestBundleServerPluginService extends ServerPluginService implement
}
}
- public class TestBundleServerPluginContainer extends GenericServerPluginContainer {
- public State state = State.UNINITIALIZED;
-
+ public class TestBundleServerPluginContainer extends BundleServerPluginContainer {
public TestBundleServerPluginContainer(MasterServerPluginContainer master) {
super(master);
}
@@ -117,56 +112,12 @@ public class TestBundleServerPluginService extends ServerPluginService implement
TestBundlePluginManager pm = new TestBundlePluginManager(this);
return pm;
}
-
- @Override
- public synchronized void initialize() throws Exception {
- if (state == State.UNINITIALIZED) {
- state = State.INITIALIZED;
- } else {
- System.out.println("!!! PC LIFECYCLE WAS BAD - THIS IS A BUG !!!");
- throw new IllegalStateException("not uninitialized: " + state);
- }
- super.initialize();
- }
-
- @Override
- public synchronized void start() {
- if (state == State.INITIALIZED) {
- state = State.STARTED;
- } else {
- System.out.println("!!! PC LIFECYCLE WAS BAD - THIS IS A BUG !!!");
- throw new IllegalStateException("not initialized: " + state);
- }
- super.start();
- }
-
- @Override
- public synchronized void stop() {
- if (state == State.STARTED) {
- state = State.STOPPED;
- } else {
- System.out.println("!!! PC LIFECYCLE WAS BAD - THIS IS A BUG !!!");
- throw new IllegalStateException("not started: " + state);
- }
- super.stop();
- }
-
- @Override
- public synchronized void shutdown() {
- if (state == State.STOPPED) {
- state = State.UNINITIALIZED;
- } else {
- System.out.println("!!! PC LIFECYCLE WAS BAD - THIS IS A BUG !!!");
- throw new IllegalStateException("not stopped: " + state);
- }
- super.shutdown();
- }
}
/**
* The test plugin manager.
*/
- class TestBundlePluginManager extends ServerPluginManager {
+ class TestBundlePluginManager extends BundleServerPluginManager {
public final Map<String, ServerPluginComponent> components;
public TestBundlePluginManager(TestBundleServerPluginContainer pc) {
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginServiceMBean.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginServiceMBean.java
new file mode 100644
index 0000000..80b2d7f
--- /dev/null
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginServiceMBean.java
@@ -0,0 +1,24 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.server.bundle;
+
+import org.rhq.enterprise.server.plugin.pc.ServerPluginServiceManagement;
+
+public interface TestBundleServerPluginServiceMBean extends ServerPluginServiceManagement {
+}
\ No newline at end of file
14 years, 2 months
[rhq] Branch 'alertPlugin' - 3 commits - modules/enterprise
by Heiko W. Rupp
modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/AlertTokenReplacer.java | 8 +
modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/OperationsSender.java | 41 ++++++----
modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/Token.java | 4
modules/enterprise/server/plugins/alert-operations/src/test/java/org/rhq/enterprise/server/plugins/alertOperations/TokenReplacementTest.java | 3
4 files changed, 40 insertions(+), 16 deletions(-)
New commits:
commit 8addeee897707dc3bddd898218ec1bea2b8ad7f1
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Tue Mar 2 21:40:50 2010 +0100
Don't clone, but deepCopy without the ids.
diff --git a/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/OperationsSender.java b/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/OperationsSender.java
index e355292..95217a2 100644
--- a/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/OperationsSender.java
+++ b/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/OperationsSender.java
@@ -116,7 +116,7 @@ public class OperationsSender extends AlertSender {
if (parameters!=null && tokenMode.equals(INTERPRETED)) {
// We must not pass the original Config object, as this would mean
// our tokens get wiped out.
- theParameters = parameters.clone();
+ theParameters = parameters.deepCopy(false);
Map<String,PropertySimple> propsMap = theParameters.getSimpleProperties();
if (!propsMap.isEmpty()) {
ResourceManagerLocal resMgr = LookupUtil.getResourceManager();
commit 7cd1b3fac0ae4525f78bad4e8269768408d5f156
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Tue Mar 2 21:27:36 2010 +0100
Allow for camelCase in tokens. Actually use the provided target resource.
diff --git a/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/AlertTokenReplacer.java b/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/AlertTokenReplacer.java
index e8c61dd..4966f22 100644
--- a/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/AlertTokenReplacer.java
+++ b/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/AlertTokenReplacer.java
@@ -50,7 +50,8 @@ public class AlertTokenReplacer {
public AlertTokenReplacer(Alert alert, OperationDefinition operationDefinition, Resource targetResource) {
this.alert = alert;
this.operationDefinition = operationDefinition;
- pattern = Pattern.compile("<%\\s*([a-z]+\\.[a-z0-9]+)\\s*%>");
+ this.targetResource = targetResource;
+ pattern = Pattern.compile("<%\\s*([a-zA-Z]+\\.[a-zA-Z0-9]+)\\s*%>");
}
/**
@@ -136,6 +137,9 @@ public class AlertTokenReplacer {
case TEST_FIX:
ret = THE_QUICK_BROWN_FOX_JUMPS_OVER_THE_LAZY_DOG;
break;
+ case TEST_CAMEL:
+ ret ="camel";
+ break;
default:
ret = NOT_YET_IMPLEMENTED;
}
@@ -181,6 +185,8 @@ public class AlertTokenReplacer {
Subject overlord = LookupUtil.getSubjectManager().getOverlord();
Resource parent;
Resource platform = mgr.getPlaformOfResource(overlord,resource.getId());
+ if (platform==null)
+ platform=resource;
switch (token) {
case RESOURCE_ID:
diff --git a/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/Token.java b/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/Token.java
index 2d810f0..4b90bc1 100644
--- a/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/Token.java
+++ b/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/Token.java
@@ -70,8 +70,10 @@ public enum Token {
// only for testing
TEST_ECHO(TokenClass.TEST,"echo", "Echo the input"),
- TEST_FIX(TokenClass.TEST,"fix", "Return a fixed string");
+ TEST_FIX(TokenClass.TEST,"fix", "Return a fixed string"),
+ TEST_CAMEL(TokenClass.TEST,"camelCase","Test matching of camels")
+ ;
private TokenClass tc;
private String name;
diff --git a/modules/enterprise/server/plugins/alert-operations/src/test/java/org/rhq/enterprise/server/plugins/alertOperations/TokenReplacementTest.java b/modules/enterprise/server/plugins/alert-operations/src/test/java/org/rhq/enterprise/server/plugins/alertOperations/TokenReplacementTest.java
index cf6c48d..45b03d6 100644
--- a/modules/enterprise/server/plugins/alert-operations/src/test/java/org/rhq/enterprise/server/plugins/alertOperations/TokenReplacementTest.java
+++ b/modules/enterprise/server/plugins/alert-operations/src/test/java/org/rhq/enterprise/server/plugins/alertOperations/TokenReplacementTest.java
@@ -56,6 +56,9 @@ public class TokenReplacementTest {
assert res != null;
assert res.equals(TEST_ECHO);
+ res = tr.replaceToken("test.camelCase");
+ assert res != null;
+ assert res.equals("camel");
/*
res = tr.replaceToken("alert.id");
assert res != null;
commit e09ef2624024f30c26e77a3220aff300db39d67d
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Tue Mar 2 15:20:12 2010 +0100
Clone the parameters before replacing tokens. Also pass the target resource to the replacer.
diff --git a/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/OperationsSender.java b/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/OperationsSender.java
index 635085a..e355292 100644
--- a/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/OperationsSender.java
+++ b/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/OperationsSender.java
@@ -34,11 +34,13 @@ import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.operation.OperationDefinition;
+import org.rhq.core.domain.resource.Resource;
import org.rhq.enterprise.server.configuration.ConfigurationManagerLocal;
import org.rhq.enterprise.server.exception.ScheduleException;
import org.rhq.enterprise.server.operation.OperationManagerLocal;
import org.rhq.enterprise.server.operation.ResourceOperationSchedule;
import org.rhq.enterprise.server.plugin.pc.alert.AlertSender;
+import org.rhq.enterprise.server.resource.ResourceManagerLocal;
import org.rhq.enterprise.server.util.LookupUtil;
/**
@@ -75,7 +77,7 @@ public class OperationsSender extends AlertSender {
String opName = null;
OperationManagerLocal opMgr = LookupUtil.getOperationManager();
- Subject subject = LookupUtil.getSubjectManager().getOverlord(); // TODO get real subject
+ Subject subject = LookupUtil.getSubjectManager().getOverlord(); // TODO get real subject?
List<OperationDefinition> opdefs = opMgr.findSupportedResourceOperations(subject,resourceId,false);
OperationDefinition opDef = null;
@@ -109,26 +111,37 @@ public class OperationsSender extends AlertSender {
* If we have parameters and the user wants tokens to be interpreted, then loop
* over the parameters and do token replacement.
*/
- if (parameters!=null && tokenMode.equals(INTERPRETED)) {
- Map<String,PropertySimple> propsMap = parameters.getSimpleProperties();
- if (!propsMap.isEmpty()) {
- AlertTokenReplacer tr = new AlertTokenReplacer(alert, opDef, null);
- for (PropertySimple prop : propsMap.values()) {
- String tmp = prop.getStringValue();
- tmp = tr.replaceTokens(tmp);
- prop.setStringValue(tmp);
+ Configuration theParameters = null;
+ try {
+ if (parameters!=null && tokenMode.equals(INTERPRETED)) {
+ // We must not pass the original Config object, as this would mean
+ // our tokens get wiped out.
+ theParameters = parameters.clone();
+ Map<String,PropertySimple> propsMap = theParameters.getSimpleProperties();
+ if (!propsMap.isEmpty()) {
+ ResourceManagerLocal resMgr = LookupUtil.getResourceManager();
+ Resource targetResource = resMgr.getResource(subject,resourceId);
+ AlertTokenReplacer tr = new AlertTokenReplacer(alert, opDef, targetResource);
+ for (PropertySimple prop : propsMap.values()) {
+ String tmp = prop.getStringValue();
+ tmp = tr.replaceTokens(tmp);
+ prop.setStringValue(tmp);
+ }
}
}
+ else {
+ theParameters = parameters;
+ }
+ } catch (Exception e) {
+ e.printStackTrace(); // TODO: Customise this generated block
}
-
-
/*
- * Now fire off the operation with no delay and no repetition.
- */
+ * Now fire off the operation with no delay and no repetition.
+ */
ResourceOperationSchedule sched;
try {
- sched = opMgr.scheduleResourceOperation(subject, resourceId, opName, 0, 0, 0, 0, parameters,
+ sched = opMgr.scheduleResourceOperation(subject, resourceId, opName, 0, 0, 0, 0, theParameters,
"Alert operation for " + alert.getAlertDefinition().getName());
} catch (ScheduleException e) {
return new SenderResult(ResultState.FAILURE, "Scheduling of operation " + opName + " on resource " + resourceId + " failed: " + e.getMessage());
14 years, 2 months
[rhq] Branch 'bundle' - 5 commits - modules/core modules/enterprise
by Jay Shaughnessy
modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java | 16
modules/core/domain/src/main/java/org/rhq/core/domain/criteria/BundleVersionCriteria.java | 13
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java | 228 ++++++++--
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerHelper.java | 34 +
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java | 72 ++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java | 10
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java | 31 +
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java | 218 +++++++++
8 files changed, 583 insertions(+), 39 deletions(-)
New commits:
commit 3a19b87d9f21a5ffa2df1ed6ea2d06421310adb1
Merge: 85ce0d5... cdccd36...
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Tue Mar 2 15:14:51 2010 -0500
Merge branch 'bundle' into bundle-jay
commit 85ce0d5d01e8b74849346640590edcff1afe8b6f
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Tue Mar 2 15:10:22 2010 -0500
SLSB work for Bundles
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
index 6d67e56..29b25cf 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
@@ -18,6 +18,8 @@
*/
package org.rhq.enterprise.server.bundle;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
import java.util.List;
import java.util.Random;
import java.util.UUID;
@@ -32,11 +34,17 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.auth.Subject;
+import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.bundle.Bundle;
import org.rhq.core.domain.bundle.BundleDeployDefinition;
import org.rhq.core.domain.bundle.BundleDeployment;
+import org.rhq.core.domain.bundle.BundleFile;
import org.rhq.core.domain.bundle.BundleType;
import org.rhq.core.domain.bundle.BundleVersion;
+import org.rhq.core.domain.content.Architecture;
+import org.rhq.core.domain.content.Package;
+import org.rhq.core.domain.content.PackageType;
+import org.rhq.core.domain.content.PackageVersion;
import org.rhq.core.domain.content.Repo;
import org.rhq.core.domain.criteria.BundleCriteria;
import org.rhq.core.domain.criteria.BundleDeployDefinitionCriteria;
@@ -48,6 +56,9 @@ import org.rhq.core.domain.util.PersistenceUtility;
import org.rhq.enterprise.server.RHQConstants;
import org.rhq.enterprise.server.authz.AuthorizationManagerLocal;
import org.rhq.enterprise.server.authz.PermissionException;
+import org.rhq.enterprise.server.authz.RequiredPermission;
+import org.rhq.enterprise.server.content.ContentManagerLocal;
+import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.plugin.pc.bundle.BundleServerPluginFacet;
import org.rhq.enterprise.server.resource.ResourceTypeManagerLocal;
import org.rhq.enterprise.server.util.CriteriaQueryGenerator;
@@ -70,49 +81,208 @@ public class BundleManagerBean implements BundleManagerLocal, BundleManagerRemot
private AuthorizationManagerLocal authorizationManager;
@EJB
+ private ContentManagerLocal contentManager;
+
+ @EJB
+ private RepoManagerLocal repoManager;
+
+ @EJB
private ResourceTypeManagerLocal resourceTypeManager;
- public Bundle createBundle(Subject subject, Bundle bundle) {
- if (null == bundle || null == bundle.getName())
- throw new IllegalArgumentException("Missing one or more of: bundle, name");
+ @RequiredPermission(Permission.MANAGE_INVENTORY)
+ public Bundle createBundle(Subject subject, String name, int bundleTypeId) {
+ if (null == name || "".equals(name.trim())) {
+ throw new IllegalArgumentException("Invalid bundleName: " + name);
+ }
- // add the implicit bundle repo, if necessary
- if (null == bundle.getRepo()) {
- Repo repo = new Repo(bundle.getName());
- repo.setCandidate(false);
- repo.setSyncSchedule(null);
- bundle.setRepo(repo);
+ BundleType bundleType = entityManager.find(BundleType.class, bundleTypeId);
+ if (null == bundleType) {
+ throw new IllegalArgumentException("Invalid bundleTypeId: " + bundleTypeId);
}
- log.info("Creating bundle: " + bundle);
+ Bundle bundle = new Bundle(name, bundleType);
+
+ // add the implicit bundle repo
+ Repo repo = new Repo(name);
+ repo.setCandidate(false);
+ repo.setSyncSchedule(null);
+ bundle.setRepo(repo);
+ log.info("Creating bundle: " + bundle);
entityManager.persist(bundle);
+
return bundle;
}
- public BundleType createBundleType(Subject subject, BundleType bundleType) throws Exception {
- if (null == bundleType || null == bundleType.getName())
- throw new IllegalArgumentException("Missing one or more of: bundleType, name");
+ @RequiredPermission(Permission.MANAGE_INVENTORY)
+ public BundleType createBundleType(Subject subject, String name, int resourceTypeId) throws Exception {
+ if (null == name || "".equals(name.trim())) {
+ throw new IllegalArgumentException("Invalid bundleTypeName: " + name);
+ }
+ ResourceType resourceType = entityManager.find(ResourceType.class, resourceTypeId);
+ if (null == resourceType) {
+ throw new IllegalArgumentException("Invalid resourceeTypeId: " + resourceTypeId);
+ }
+
+ BundleType bundleType = new BundleType(name, resourceType);
entityManager.persist(bundleType);
return bundleType;
}
- public BundleVersion createBundleVersion(Subject subject, int bundleId, BundleVersion bundleVersion)
+ @RequiredPermission(Permission.MANAGE_INVENTORY)
+ public BundleVersion createBundleVersion(Subject subject, int bundleId, String name, String version, String recipe)
throws Exception {
+ if (null == name || "".equals(name.trim())) {
+ throw new IllegalArgumentException("Invalid bundleVersionName: " + name);
+ }
+
Bundle bundle = entityManager.find(Bundle.class, bundleId);
+ if (null == bundle) {
+ throw new IllegalArgumentException("Invalid bundleId: " + bundleId);
+ }
+
+ // parse the recipe (validation occurs here) and get the config def and list of files
+ BundleType bundleType = bundle.getBundleType();
+ BundleServerPluginFacet bp = BundleManagerHelper.getPluginContainer().getBundleServerPluginManager()
+ .getBundleServerPluginFacet(bundleType.getName());
+ RecipeParseResults results = bp.parseRecipe(recipe);
- if (null == bundleVersion || null == bundle || null == bundleVersion.getRecipe())
- throw new IllegalArgumentException("Missing one or more of: bundle, bundleVersion, recipe");
+ // ensure we have a version
+ version = getVersion(version, bundle);
- // parse the recipe and get the config def and list of files
- BundleServerPluginFacet bp;
- // bp.parseRecipe;
+ BundleVersion bundleVersion = new BundleVersion(name, version, bundle, recipe);
+ bundleVersion.setConfigurationDefinition(results.getConfigDef());
entityManager.persist(bundleVersion);
return bundleVersion;
}
+ private String getVersion(String version, Bundle bundle) {
+ if (!(null == version || "".equals(version.trim()))) {
+ return version;
+ }
+
+ BundleVersion currentBundleVersion = null;
+ for (BundleVersion bundleVersion : bundle.getBundleVersions()) {
+ if ((null == currentBundleVersion) || (bundleVersion.getId() > currentBundleVersion.getId())) {
+ currentBundleVersion = bundleVersion;
+ }
+ }
+
+ // note - this is the same algo used by ResourceClientProxy in updatebackingContent (for a resource)
+ String oldVersion = (null == currentBundleVersion) ? null : currentBundleVersion.getVersion();
+ String newVersion = "1.0";
+ if (oldVersion != null && oldVersion.length() != 0) {
+ String[] parts = oldVersion.split("[^a-zA-Z0-9]");
+ String lastPart = parts[parts.length - 1];
+ try {
+ int lastNumber = Integer.parseInt(lastPart);
+ newVersion = oldVersion.substring(0, oldVersion.length() - lastPart.length()) + (lastNumber + 1);
+ } catch (NumberFormatException nfe) {
+ newVersion = oldVersion + ".1";
+ }
+ }
+
+ return newVersion;
+ }
+
+ @RequiredPermission(Permission.MANAGE_INVENTORY)
+ public BundleFile addBundleFile(Subject subject, int bundleVersionId, String name, String version,
+ Architecture architecture, InputStream fileStream, boolean pinToPackage) throws Exception {
+
+ if (null == name || "".equals(name.trim())) {
+ throw new IllegalArgumentException("Invalid bundleFileName: " + name);
+ }
+ if (null == version || "".equals(version.trim())) {
+ throw new IllegalArgumentException("Invalid bundleFileVersion: " + version);
+ }
+ if (null == fileStream) {
+ throw new IllegalArgumentException("Invalid fileStream: " + null);
+ }
+ BundleVersion bundleVersion = entityManager.find(BundleVersion.class, bundleVersionId);
+ if (null == bundleVersion) {
+ throw new IllegalArgumentException("Invalid bundleVersionId: " + bundleVersionId);
+ }
+
+ // Create the PackageVersion the BundleFile is tied to. This implicitly creates the
+ // Package for the PackageVersion.
+ Bundle bundle = bundleVersion.getBundle();
+ PackageType packageType = getBundleTypePackageType(bundle.getBundleType());
+ architecture = (null == architecture) ? contentManager.getNoArchitecture() : architecture;
+ PackageVersion packageVersion = contentManager.createPackageVersion(name, packageType.getId(), version,
+ architecture.getId(), fileStream);
+
+ // Create the mapping between the Bundle's Repo and the BundleFile's PackageVersion
+ Repo repo = bundle.getRepo();
+ repoManager.addPackageVersionsToRepo(subject, repo.getId(), new int[] { packageVersion.getId() });
+
+ // Classify the Package with the Bundle name in order to distinguish it from the same package name for
+ // a different bundle.
+ Package generalPackage = packageVersion.getGeneralPackage();
+ generalPackage.setClassification(bundle.getName());
+
+ // With all the plumbing in place, create and persist the BundleFile. Tie it to the Package if the caller
+ // wants this BundleFile pinned to themost recent version.
+ BundleFile bundleFile = new BundleFile();
+ bundleFile.setBundleVersion(bundleVersion);
+ bundleFile.setPackageVersion(packageVersion);
+ if (pinToPackage) {
+ bundleFile.setPackage(generalPackage);
+ }
+
+ entityManager.persist(bundleFile);
+
+ return bundleFile;
+ }
+
+ @RequiredPermission(Permission.MANAGE_INVENTORY)
+ public BundleFile addBundleFileViaByteArray(Subject subject, int bundleVersionId, String name, String version,
+ Architecture architecture, byte[] fileBytes, boolean pinToPackage) throws Exception {
+
+ return addBundleFile(subject, bundleVersionId, name, version, architecture,
+ new ByteArrayInputStream(fileBytes), pinToPackage);
+ }
+
+ @RequiredPermission(Permission.MANAGE_INVENTORY)
+ public BundleFile addBundleFileViaPackageVersion(Subject subject, int bundleVersionId, String name,
+ int packageVersionId, boolean pinToPackage) throws Exception {
+
+ if (null == name || "".equals(name.trim())) {
+ throw new IllegalArgumentException("Invalid bundleFileName: " + name);
+ }
+ BundleVersion bundleVersion = entityManager.find(BundleVersion.class, bundleVersionId);
+ if (null == bundleVersion) {
+ throw new IllegalArgumentException("Invalid bundleVersionId: " + bundleVersionId);
+ }
+ PackageVersion packageVersion = entityManager.find(PackageVersion.class, packageVersionId);
+ if (null == packageVersion) {
+ throw new IllegalArgumentException("Invalid packageVersionId: " + packageVersionId);
+ }
+
+ // With all the plumbing in place, create and persist the BundleFile. Tie it to the Package if the caller
+ // wants this BundleFile pinned to themost recent version.
+ BundleFile bundleFile = new BundleFile();
+ bundleFile.setBundleVersion(bundleVersion);
+ bundleFile.setPackageVersion(packageVersion);
+ if (pinToPackage) {
+ bundleFile.setPackage(packageVersion.getGeneralPackage());
+ }
+
+ entityManager.persist(bundleFile);
+
+ return bundleFile;
+ }
+
+ private PackageType getBundleTypePackageType(BundleType bundleType) {
+
+ Query packageTypeQuery = entityManager.createNamedQuery(PackageType.QUERY_FIND_BY_RESOURCE_TYPE_ID_AND_NAME);
+ packageTypeQuery.setParameter("typeId", bundleType.getResourceType().getId());
+ packageTypeQuery.setParameter("name", bundleType.getName());
+
+ return (PackageType) packageTypeQuery.getSingleResult();
+ }
+
@SuppressWarnings("unchecked")
public List<BundleType> getAllBundleTypes(Subject subject) {
// the list of types will be small, no need to support paging
@@ -198,8 +368,7 @@ public class BundleManagerBean implements BundleManagerLocal, BundleManagerRemot
try {
ResourceType linuxPlatformResourceType = this.resourceTypeManager.getResourceTypeByNameAndPlugin("Linux",
"Platforms");
- BundleType bundleType = new BundleType(UUID.randomUUID().toString(), linuxPlatformResourceType);
- return createBundleType(subject, bundleType);
+ return createBundleType(subject, UUID.randomUUID().toString(), linuxPlatformResourceType.getId());
} catch (Exception e) {
e.printStackTrace();
return null;
@@ -215,9 +384,8 @@ public class BundleManagerBean implements BundleManagerLocal, BundleManagerRemot
int randomIndex = random.nextInt(bundleTypes.size());
bundleType = bundleTypes.get(randomIndex);
}
- Bundle bundle = new Bundle(UUID.randomUUID().toString(), bundleType);
- bundle = createBundle(subject, bundle);
+ Bundle bundle = createBundle(subject, UUID.randomUUID().toString(), bundleType.getId());
// Add 1 to 5 bundle versions.
int bundleVersionCount = random.nextInt(5) + 1;
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerHelper.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerHelper.java
new file mode 100644
index 0000000..7ba49db
--- /dev/null
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerHelper.java
@@ -0,0 +1,34 @@
+package org.rhq.enterprise.server.bundle;
+
+import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginServiceManagement;
+import org.rhq.enterprise.server.plugin.pc.bundle.BundleServerPluginContainer;
+import org.rhq.enterprise.server.util.LookupUtil;
+
+public class BundleManagerHelper {
+
+ public static BundleServerPluginContainer getPluginContainer() {
+ BundleServerPluginContainer pc;
+
+ try {
+ ServerPluginServiceManagement mbean = LookupUtil.getServerPluginService();
+ if (!mbean.isMasterPluginContainerStarted()) {
+ throw new IllegalStateException("The master plugin container is not started!");
+ }
+
+ MasterServerPluginContainer master = mbean.getMasterPluginContainer();
+ pc = master.getPluginContainerByClass(BundleServerPluginContainer.class);
+ } catch (IllegalStateException ise) {
+ throw ise;
+ } catch (Exception e) {
+ throw new IllegalStateException("Cannot obtain the Bundle plugin container!", e);
+ }
+
+ if (pc == null) {
+ throw new IllegalStateException("Bundle plugin container is null!");
+ }
+
+ return pc;
+ }
+
+}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java
index 42f573d..ec3b73b 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java
@@ -18,6 +18,7 @@
*/
package org.rhq.enterprise.server.bundle;
+import java.io.InputStream;
import java.util.List;
import javax.ejb.Local;
@@ -26,8 +27,10 @@ import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.bundle.Bundle;
import org.rhq.core.domain.bundle.BundleDeployDefinition;
import org.rhq.core.domain.bundle.BundleDeployment;
+import org.rhq.core.domain.bundle.BundleFile;
import org.rhq.core.domain.bundle.BundleType;
import org.rhq.core.domain.bundle.BundleVersion;
+import org.rhq.core.domain.content.Architecture;
import org.rhq.core.domain.criteria.BundleCriteria;
import org.rhq.core.domain.criteria.BundleDeployDefinitionCriteria;
import org.rhq.core.domain.criteria.BundleDeploymentCriteria;
@@ -43,26 +46,73 @@ import org.rhq.core.domain.util.PageList;
public interface BundleManagerLocal {
/**
+ * Adds a BundleFile to the BundleVersion and implicitly creates the backing PackageVersion. If the PackageVersion
+ * already exists use {@link addBundleFile(Subject, int, String, int, boolean)}
+ *
* @param subject must be InventoryManager
- * @param bundle required fields: name
+ * @param bundleVersionId id of the BundleVersion incorporating this BundleFile
+ * @param name name of the BundleFile (and the resulting Package)
+ * @param version version of the backing package
+ * @param architecture architecture appropriate for the backing package. Defaults to noarch (i.e. any architecture).
+ * @param fileStream the file bits
+ * @param pinToPackage if true a new version of the backing package can trigger automatic creation of a new
+ * BundleVersion. if false new versions of the backing package have no effect on the BundleFile or its BundleVersion.
+ * @return the new BundleFile
+ * @throws Exception
+ */
+ BundleFile addBundleFile(Subject subject, int bundleVersionId, String bundleFileName, String version,
+ Architecture architecture, InputStream fileStream, boolean pinToPackage) throws Exception;
+
+ /**
+ * A convenience method taking a byte array as opposed to a stream for the file bits.
+ *
+ * @see {@link addBundleFile(Subject, int, String, String, Architecture, InputStream, boolean)}
+ */
+ BundleFile addBundleFileViaByteArray(Subject subject, int bundleVersionId, String name, String version,
+ Architecture architecture, byte[] fileBytes, boolean pinToPackage) throws Exception;
+
+ /**
+ * @param subject must be InventoryManager
+ * @param bundleVersionId id of the BundleVersion incorporating this BundleFile
+ * @param name name of the BundleFile (and the resulting Package)
+ * @param packageVersionId id of the PackageVersion this BundleFile is tied to for this BundleVersion. It is assumed
+ * the PackageVersion is already associated with the Bundle's Repo and the package is classified for the
+ * Bundle.
+ * @param pinToPackage if true a new version of the backing package can trigger automatic creation of a new
+ * BundleVersion. if false new versions of the backing package have no effect on the BundleFile or its BundleVersion.
+ * @return the new BundleFile
+ * @throws Exception
+ */
+ BundleFile addBundleFileViaPackageVersion(Subject subject, int bundleVersionId, String name, int packageVersionId,
+ boolean pinToPackage) throws Exception;
+
+ /**
+ * @param subject must be InventoryManager
+ * @param name not null or empty
+ * @param bundleTypeId valid bundleType
* @return the persisted Bundle (id is assigned)
*/
- Bundle createBundle(Subject subject, Bundle bundle) throws Exception;
+ Bundle createBundle(Subject subject, String name, int bundleTypeId) throws Exception;
/**
+ * Not generally called. For use by Server Side Plugins when registering a Bundle Plugin.
+ *
* @param subject must be InventoryManager
- * @param bundleType required fields: name
+ * @param name not null or empty
+ * @param resourceTypeId id of the ResourceType that handles this BundleType
* @return the persisted BundleType (id is assigned)
*/
- BundleType createBundleType(Subject subject, BundleType bundleType) throws Exception;
+ BundleType createBundleType(Subject subject, String name, int resourceTypeId) throws Exception;
/**
* @param subject must be InventoryManager
- * @param int bundleId the bundle for which this will be the next version
- * @param bundleVersion required fields: recipe (the full recipe as a String)
+ * @param bundleId the bundle for which this will be the next version
+ * @param name not null or empty
+ * @param bundleVersion optional. If not supplied set to 1.0 for first version, or incremented (as best as possible) for subsequent version
* @return the persisted BundleVersion (id is assigned)
*/
- BundleVersion createBundleVersion(Subject subject, int bundleId, BundleVersion bundleVersion) throws Exception;
+ BundleVersion createBundleVersion(Subject subject, int bundleId, String name, String bundleVersion, String recipe)
+ throws Exception;
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java
index e381dd4..e8ac546 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java
@@ -41,6 +41,7 @@ import org.rhq.core.domain.criteria.BundleVersionCriteria;
import org.rhq.core.domain.resource.ResourceCategory;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.domain.util.PageList;
+import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
import org.rhq.enterprise.server.test.AbstractEJB3Test;
import org.rhq.enterprise.server.util.LookupUtil;
@@ -57,8 +58,20 @@ public class BundleManagerBeanTest extends AbstractEJB3Test {
private BundleManagerLocal bundleManagerBean;
+ private TestBundleServerPluginService ps;
+ private MasterServerPluginContainer pc;
+
@BeforeMethod
public void beforeMethod() {
+ super.startTest();
+
+ if (null == ps) {
+ ps = new TestBundleServerPluginService();
+ pc = ps.createMasterPluginContainer();
+ } else {
+ pc.initialize(ps.masterConfig);
+ }
+
bundleManagerBean = LookupUtil.getBundleManager();
}
@@ -119,6 +132,12 @@ public class BundleManagerBeanTest extends AbstractEJB3Test {
em.close();
}
}
+
+ if (null != pc) {
+ pc.shutdown();
+ }
+
+ super.endTest();
}
@Test(enabled = ENABLED)
@@ -232,8 +251,7 @@ public class BundleManagerBeanTest extends AbstractEJB3Test {
private BundleType createBundleType(String name) throws Exception {
final String fullName = TEST_PREFIX + "-type-" + name;
- BundleType bt = new BundleType(fullName, createResourceType(name));
- bt = bundleManagerBean.createBundleType(getOverlord(), bt);
+ BundleType bt = bundleManagerBean.createBundleType(getOverlord(), fullName, createResourceType(name).getId());
assert bt.getId() > 0;
assert bt.getName().endsWith(fullName);
@@ -247,8 +265,7 @@ public class BundleManagerBeanTest extends AbstractEJB3Test {
private Bundle createBundle(String name, BundleType bt) throws Exception {
final String fullName = TEST_PREFIX + "-bundle-" + name;
- Bundle b = new Bundle(fullName, bt);
- b = bundleManagerBean.createBundle(getOverlord(), b);
+ Bundle b = bundleManagerBean.createBundle(getOverlord(), fullName, bt.getId());
assert b.getId() > 0;
assert b.getName().endsWith(fullName);
@@ -257,9 +274,9 @@ public class BundleManagerBeanTest extends AbstractEJB3Test {
private BundleVersion createBundleVersion(String name, String version, Bundle bundle) throws Exception {
final String fullName = TEST_PREFIX + "-version-" + version + "-" + name;
- final String recipe = TEST_PREFIX + "-recipe-" + name;
- BundleVersion bv = new BundleVersion(fullName, version, bundle, recipe);
- bv = bundleManagerBean.createBundleVersion(getOverlord(), bv);
+ final String recipe = "deploy -f " + TEST_PREFIX + ".zip -d <% test.path %>";
+ BundleVersion bv = bundleManagerBean.createBundleVersion(getOverlord(), bundle.getId(), fullName, version,
+ recipe);
assert bv.getId() > 0;
assert bv.getName().endsWith(fullName);
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java
new file mode 100644
index 0000000..dcbc951
--- /dev/null
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java
@@ -0,0 +1,218 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.server.bundle;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.plugin.PluginKey;
+import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
+import org.rhq.core.util.MessageDigestGenerator;
+import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainerConfiguration;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginEnvironment;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginManager;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginService;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
+import org.rhq.enterprise.server.plugin.pc.generic.GenericServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.generic.TestGenericServerPluginServiceMBean;
+import org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorMetadataParser;
+import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
+
+/**
+ * Used as a mock service for the generic server plugin container.
+ */
+public class TestBundleServerPluginService extends ServerPluginService implements TestGenericServerPluginServiceMBean {
+ public enum State {
+ INITIALIZED, STARTED, STOPPED, UNINITIALIZED
+ }
+
+ // public so tests can directly set these
+ public TestMasterServerPluginContainer master;
+ public TestBundleServerPluginContainer bundlePC;
+ public MasterServerPluginContainerConfiguration masterConfig;
+
+ public TestBundleServerPluginService() {
+ // build the config at constructor time so tests have it even before the PC is initialized
+ File dir = new File(System.getProperty("java.io.tmpdir"), "test-server-plugins");
+ this.masterConfig = new MasterServerPluginContainerConfiguration(dir, dir, dir, null);
+ }
+
+ @Override
+ public MasterServerPluginContainer createMasterPluginContainer() {
+ this.master = new TestMasterServerPluginContainer();
+ this.master.initialize(this.masterConfig);
+ return this.master;
+ }
+
+ /**
+ * The test master PC
+ */
+ class TestMasterServerPluginContainer extends MasterServerPluginContainer {
+ @Override
+ protected List<AbstractTypeServerPluginContainer> createPluginContainers() {
+ ArrayList<AbstractTypeServerPluginContainer> pcs = new ArrayList<AbstractTypeServerPluginContainer>(1);
+ bundlePC = new TestBundleServerPluginContainer(this);
+ pcs.add(bundlePC);
+ return pcs;
+ }
+
+ @Override
+ protected ClassLoader createRootServerPluginClassLoader() {
+ return this.getClass().getClassLoader();
+ }
+
+ @Override
+ protected Map<URL, ? extends ServerPluginDescriptorType> preloadAllPlugins() throws Exception {
+ // if our test never setup any plugins, ignore it and just return an empty map
+ File pluginDir = getConfiguration().getPluginDirectory();
+ if (pluginDir == null || pluginDir.listFiles() == null || pluginDir.listFiles().length == 0) {
+ return new HashMap<URL, ServerPluginDescriptorType>();
+ } else {
+ return super.preloadAllPlugins();
+ }
+ }
+
+ @Override
+ protected List<PluginKey> getDisabledPluginKeys() {
+ // in the real world, the db is checked for enable flag, here we say all plugins are enabled
+ return new ArrayList<PluginKey>();
+ }
+ }
+
+ public class TestBundleServerPluginContainer extends GenericServerPluginContainer {
+ public State state = State.UNINITIALIZED;
+
+ public TestBundleServerPluginContainer(MasterServerPluginContainer master) {
+ super(master);
+ }
+
+ @Override
+ protected ServerPluginManager createPluginManager() {
+ TestBundlePluginManager pm = new TestBundlePluginManager(this);
+ return pm;
+ }
+
+ @Override
+ public synchronized void initialize() throws Exception {
+ if (state == State.UNINITIALIZED) {
+ state = State.INITIALIZED;
+ } else {
+ System.out.println("!!! PC LIFECYCLE WAS BAD - THIS IS A BUG !!!");
+ throw new IllegalStateException("not uninitialized: " + state);
+ }
+ super.initialize();
+ }
+
+ @Override
+ public synchronized void start() {
+ if (state == State.INITIALIZED) {
+ state = State.STARTED;
+ } else {
+ System.out.println("!!! PC LIFECYCLE WAS BAD - THIS IS A BUG !!!");
+ throw new IllegalStateException("not initialized: " + state);
+ }
+ super.start();
+ }
+
+ @Override
+ public synchronized void stop() {
+ if (state == State.STARTED) {
+ state = State.STOPPED;
+ } else {
+ System.out.println("!!! PC LIFECYCLE WAS BAD - THIS IS A BUG !!!");
+ throw new IllegalStateException("not started: " + state);
+ }
+ super.stop();
+ }
+
+ @Override
+ public synchronized void shutdown() {
+ if (state == State.STOPPED) {
+ state = State.UNINITIALIZED;
+ } else {
+ System.out.println("!!! PC LIFECYCLE WAS BAD - THIS IS A BUG !!!");
+ throw new IllegalStateException("not stopped: " + state);
+ }
+ super.shutdown();
+ }
+ }
+
+ /**
+ * The test plugin manager.
+ */
+ class TestBundlePluginManager extends ServerPluginManager {
+ public final Map<String, ServerPluginComponent> components;
+
+ public TestBundlePluginManager(TestBundleServerPluginContainer pc) {
+ super(pc);
+ components = new HashMap<String, ServerPluginComponent>();
+ }
+
+ @Override
+ protected ServerPlugin getPlugin(ServerPluginEnvironment env) {
+
+ try {
+ Configuration pluginConfig = null;
+ Configuration scheduledJobsConfig = null;
+ ConfigurationDefinition configDef;
+
+ ServerPluginDescriptorType pluginDescriptor = env.getPluginDescriptor();
+
+ configDef = ServerPluginDescriptorMetadataParser.getPluginConfigurationDefinition(pluginDescriptor);
+ if (configDef != null) {
+ pluginConfig = configDef.getDefaultTemplate().createConfiguration();
+ }
+
+ configDef = ServerPluginDescriptorMetadataParser.getScheduledJobsDefinition(pluginDescriptor);
+ if (configDef != null) {
+ scheduledJobsConfig = configDef.getDefaultTemplate().createConfiguration();
+ }
+
+ File pluginFile = new File(env.getPluginUrl().toURI());
+ ServerPlugin plugin = new ServerPlugin(0, env.getPluginKey().getPluginName(), pluginFile.getName(),
+ pluginDescriptor.getDisplayName(), true, PluginStatusType.INSTALLED, pluginDescriptor
+ .getDescription(), "", MessageDigestGenerator.getDigestString(pluginFile), pluginDescriptor
+ .getVersion(), pluginDescriptor.getVersion(), pluginConfig, scheduledJobsConfig,
+ new ServerPluginType(pluginDescriptor).stringify(), System.currentTimeMillis(), System
+ .currentTimeMillis());
+ return plugin;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ protected ServerPluginComponent createServerPluginComponent(ServerPluginEnvironment environment)
+ throws Exception {
+ ServerPluginComponent component = super.createServerPluginComponent(environment);
+ components.put(environment.getPluginKey().getPluginName(), component);
+ return component;
+ }
+ }
+}
\ No newline at end of file
commit f2f559b7cdb5055bf572804b82db5f1322913582
Merge: 84ebcfc... 7f70926...
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Mar 1 14:50:20 2010 -0500
Merge branch 'bundle' into bundle-jay
commit 84ebcfc94992d0d7f0d6cb1a0a441ece7131d69e
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Mar 1 14:50:13 2010 -0500
local intermittent check-in for merge purposes
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
index ce559bf..6d67e56 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
@@ -35,7 +35,6 @@ import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.bundle.Bundle;
import org.rhq.core.domain.bundle.BundleDeployDefinition;
import org.rhq.core.domain.bundle.BundleDeployment;
-import org.rhq.core.domain.bundle.BundleFile;
import org.rhq.core.domain.bundle.BundleType;
import org.rhq.core.domain.bundle.BundleVersion;
import org.rhq.core.domain.content.Repo;
@@ -49,6 +48,7 @@ import org.rhq.core.domain.util.PersistenceUtility;
import org.rhq.enterprise.server.RHQConstants;
import org.rhq.enterprise.server.authz.AuthorizationManagerLocal;
import org.rhq.enterprise.server.authz.PermissionException;
+import org.rhq.enterprise.server.plugin.pc.bundle.BundleServerPluginFacet;
import org.rhq.enterprise.server.resource.ResourceTypeManagerLocal;
import org.rhq.enterprise.server.util.CriteriaQueryGenerator;
import org.rhq.enterprise.server.util.CriteriaQueryRunner;
@@ -72,15 +72,10 @@ public class BundleManagerBean implements BundleManagerLocal, BundleManagerRemot
@EJB
private ResourceTypeManagerLocal resourceTypeManager;
- @SuppressWarnings("unchecked")
- public List<BundleFile> findBundleFilesForBundleVersion(int bundleVersionId) throws Exception {
- Query q = entityManager.createNamedQuery(BundleFile.QUERY_FIND_BY_BUNDLE_VERSION_ID);
- q.setParameter("id", bundleVersionId);
- List<BundleFile> bundleFiles = (List<BundleFile>) q.getResultList();
- return bundleFiles;
- }
-
public Bundle createBundle(Subject subject, Bundle bundle) {
+ if (null == bundle || null == bundle.getName())
+ throw new IllegalArgumentException("Missing one or more of: bundle, name");
+
// add the implicit bundle repo, if necessary
if (null == bundle.getRepo()) {
Repo repo = new Repo(bundle.getName());
@@ -95,12 +90,25 @@ public class BundleManagerBean implements BundleManagerLocal, BundleManagerRemot
return bundle;
}
- public BundleType createBundleType(Subject subject, BundleType bundleType) {
+ public BundleType createBundleType(Subject subject, BundleType bundleType) throws Exception {
+ if (null == bundleType || null == bundleType.getName())
+ throw new IllegalArgumentException("Missing one or more of: bundleType, name");
+
entityManager.persist(bundleType);
return bundleType;
}
- public BundleVersion createBundleVersion(Subject subject, BundleVersion bundleVersion) {
+ public BundleVersion createBundleVersion(Subject subject, int bundleId, BundleVersion bundleVersion)
+ throws Exception {
+ Bundle bundle = entityManager.find(Bundle.class, bundleId);
+
+ if (null == bundleVersion || null == bundle || null == bundleVersion.getRecipe())
+ throw new IllegalArgumentException("Missing one or more of: bundle, bundleVersion, recipe");
+
+ // parse the recipe and get the config def and list of files
+ BundleServerPluginFacet bp;
+ // bp.parseRecipe;
+
entityManager.persist(bundleVersion);
return bundleVersion;
}
@@ -186,10 +194,16 @@ public class BundleManagerBean implements BundleManagerLocal, BundleManagerRemot
}
public BundleType createMockBundleType(Subject subject) {
- ResourceType linuxPlatformResourceType = this.resourceTypeManager.getResourceTypeByNameAndPlugin("Linux",
- "Platforms");
- BundleType bundleType = new BundleType(UUID.randomUUID().toString(), linuxPlatformResourceType);
- return createBundleType(subject, bundleType);
+
+ try {
+ ResourceType linuxPlatformResourceType = this.resourceTypeManager.getResourceTypeByNameAndPlugin("Linux",
+ "Platforms");
+ BundleType bundleType = new BundleType(UUID.randomUUID().toString(), linuxPlatformResourceType);
+ return createBundleType(subject, bundleType);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
}
public Bundle createMockBundle(Subject subject, List<BundleType> bundleTypes) {
commit 74b491f9cc626a1fa2f603fb0a0dbb22343b0605
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Mar 1 14:42:07 2010 -0500
Add bundleFiles field to BundleVersion and update the criteria object.
Eliminate the getBundleFilesForBundleVersion convenience routine in favor
of a standard criteria fetch.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java b/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java
index 125baa7..b70c53d 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java
@@ -94,6 +94,9 @@ public class BundleVersion implements Serializable {
@OneToMany(mappedBy = "bundleVersion", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<BundleDeployDefinition> bundleDeployDefinitions = new ArrayList<BundleDeployDefinition>();
+ @OneToMany(mappedBy = "bundleVersion", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
+ private List<BundleFile> bundleFiles = new ArrayList<BundleFile>();
+
public BundleVersion() {
// for JPA use
}
@@ -182,6 +185,19 @@ public class BundleVersion implements Serializable {
this.bundleDeployDefinitions = bundleDeployDefinitions;
}
+ public List<BundleFile> getBundleFiles() {
+ return bundleFiles;
+ }
+
+ public void addBundleFile(BundleFile bundleFile) {
+ this.bundleFiles.add(bundleFile);
+ bundleFile.setBundleVersion(this);
+ }
+
+ public void setBundleFiles(List<BundleFile> bundleFiles) {
+ this.bundleFiles = bundleFiles;
+ }
+
@Override
public String toString() {
return "BundleVersion[id=" + id + ",name=" + name + ",version=" + version + ",bundle=" + bundle + "]";
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/BundleVersionCriteria.java b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/BundleVersionCriteria.java
index 72c07ed..5264a76 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/BundleVersionCriteria.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/BundleVersionCriteria.java
@@ -41,6 +41,7 @@ public class BundleVersionCriteria extends Criteria {
private boolean fetchBundle;
private boolean fetchBundleDeployDefinitions;
+ private boolean fetchBundleFiles;
private boolean fetchDistribution;
private boolean fetchConfigurationDefinition;
@@ -70,12 +71,16 @@ public class BundleVersionCriteria extends Criteria {
this.fetchBundle = fetchBundle;
}
- public void fetchDistribution(boolean fetchDistribution) {
- this.fetchDistribution = fetchDistribution;
- }
-
public void fetchBundleDeployDefinitions(boolean fetchBundleDeployDefinitions) {
this.fetchBundleDeployDefinitions = fetchBundleDeployDefinitions;
}
+ public void fetchBundleFiles(boolean fetchBundleFiles) {
+ this.fetchBundleFiles = fetchBundleFiles;
+ }
+
+ public void fetchDistribution(boolean fetchDistribution) {
+ this.fetchDistribution = fetchDistribution;
+ }
+
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java
index 9266530..42f573d 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java
@@ -26,7 +26,6 @@ import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.bundle.Bundle;
import org.rhq.core.domain.bundle.BundleDeployDefinition;
import org.rhq.core.domain.bundle.BundleDeployment;
-import org.rhq.core.domain.bundle.BundleFile;
import org.rhq.core.domain.bundle.BundleType;
import org.rhq.core.domain.bundle.BundleVersion;
import org.rhq.core.domain.criteria.BundleCriteria;
@@ -42,13 +41,28 @@ import org.rhq.core.domain.util.PageList;
*/
@Local
public interface BundleManagerLocal {
- Bundle createBundle(Subject subject, Bundle b);
- BundleType createBundleType(Subject subject, BundleType bundleType);
+ /**
+ * @param subject must be InventoryManager
+ * @param bundle required fields: name
+ * @return the persisted Bundle (id is assigned)
+ */
+ Bundle createBundle(Subject subject, Bundle bundle) throws Exception;
- BundleVersion createBundleVersion(Subject subject, BundleVersion bundleVersion);
+ /**
+ * @param subject must be InventoryManager
+ * @param bundleType required fields: name
+ * @return the persisted BundleType (id is assigned)
+ */
+ BundleType createBundleType(Subject subject, BundleType bundleType) throws Exception;
- List<BundleFile> findBundleFilesForBundleVersion(int bundleVersionId) throws Exception;
+ /**
+ * @param subject must be InventoryManager
+ * @param int bundleId the bundle for which this will be the next version
+ * @param bundleVersion required fields: recipe (the full recipe as a String)
+ * @return the persisted BundleVersion (id is assigned)
+ */
+ BundleVersion createBundleVersion(Subject subject, int bundleId, BundleVersion bundleVersion) throws Exception;
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java
index 09f4669..71d038c 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java
@@ -27,8 +27,11 @@ import org.apache.commons.logging.LogFactory;
import org.rhq.core.clientapi.server.bundle.BundleServerService;
import org.rhq.core.clientapi.server.bundle.BundleStatusUpdate;
+import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.bundle.BundleFile;
+import org.rhq.core.domain.bundle.BundleVersion;
import org.rhq.core.domain.content.PackageVersion;
+import org.rhq.core.domain.criteria.BundleVersionCriteria;
import org.rhq.core.util.exception.WrappedRemotingException;
import org.rhq.enterprise.server.content.ContentSourceManagerLocal;
import org.rhq.enterprise.server.util.LookupUtil;
@@ -49,7 +52,12 @@ public class BundleServerServiceImpl implements BundleServerService {
public List<PackageVersion> getAllBundleVersionPackageVersions(int bundleVersionId) {
try {
BundleManagerLocal bm = LookupUtil.getBundleManager();
- List<BundleFile> bundleFiles = bm.findBundleFilesForBundleVersion(bundleVersionId);
+ BundleVersionCriteria c = new BundleVersionCriteria();
+ Subject subject = LookupUtil.getSubjectManager().getOverlord();
+ c.addFilterId(bundleVersionId);
+ c.fetchBundleFiles(true);
+ List<BundleVersion> bundleVersions = bm.findBundleVersionsByCriteria(subject, c);
+ List<BundleFile> bundleFiles = bundleVersions.get(0).getBundleFiles();
List<PackageVersion> packageVersions = new ArrayList<PackageVersion>(bundleFiles.size());
for (BundleFile bundleFile : bundleFiles) {
packageVersions.add(bundleFile.getPackageVersion());
14 years, 2 months