[rhq] modules/common
by snegrea
modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/AbstractManager.java | 251 +++++++
modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/SchemaManager.java | 319 ----------
modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/TopologyManager.java | 130 ++++
modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/VersionManager.java | 149 ++++
modules/common/cassandra-schema/src/main/resources/topology/0001.xml | 13
modules/common/cassandra-schema/src/main/resources/topology/0002.xml | 38 +
6 files changed, 596 insertions(+), 304 deletions(-)
New commits:
commit 245357d903f998c35f093387d7ba7824ade52968
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Fri May 31 17:30:46 2013 -0500
Update topology management to schema manager. No change to the external interface for the schema manager.
The topology update functionality includes updating the replication factor and gc grace period.
diff --git a/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/AbstractManager.java b/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/AbstractManager.java
new file mode 100644
index 0000000..be69c08
--- /dev/null
+++ b/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/AbstractManager.java
@@ -0,0 +1,251 @@
+/*
+ *
+ * * RHQ Management Platform
+ * * Copyright (C) 2005-2012 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.cassandra.schema;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.ProtocolOptions.Compression;
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.core.exceptions.NoHostAvailableException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.rhq.cassandra.util.ClusterBuilder;
+import org.rhq.core.domain.cloud.StorageNode;
+import org.rhq.core.util.StringUtil;
+
+/**
+ * @author Stefan Negrea
+ */
+public class AbstractManager {
+
+ private static final String UPDATE_PLAN_ELEMENT = "updatePlan";
+ private static final String STEP_ELEMENT = "step";
+
+ private static final String SCHEMA_EXISTS_QUERY = "SELECT * FROM system.schema_keyspaces WHERE keyspace_name = 'rhq';";
+ private static final String VERSION_COLUMNFAMILY_EXISTS_QUERY = "SELECT * from system.schema_columnfamilies WHERE keyspace_name='rhq' AND columnfamily_name='schema_version';";
+ private static final String VERSION_QUERY = "SELECT version FROM rhq.schema_version";
+
+
+ private final Log log = LogFactory.getLog(AbstractManager.class);
+
+ protected Session session;
+ protected final String username;
+ protected final String password;
+ protected List<StorageNode> nodes = new ArrayList<StorageNode>();
+
+ public AbstractManager(String username, String password, List<StorageNode> nodes) {
+ try {
+ this.username = username;
+ this.password = password;
+ this.nodes = nodes;
+
+ this.initCluster();
+ this.shutdown();
+ } catch (NoHostAvailableException e) {
+ throw new RuntimeException("Unable create storage node session.", e);
+ }
+ }
+
+ protected boolean schemaExists() {
+ try {
+ ResultSet resultSet = session.execute(SCHEMA_EXISTS_QUERY);
+ if (!resultSet.all().isEmpty()) {
+ resultSet = session.execute(VERSION_COLUMNFAMILY_EXISTS_QUERY);
+ return !resultSet.all().isEmpty();
+ }
+ return false;
+ } catch (Exception e) {
+ log.error(e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected int getSchemaVersion() {
+ int maxVersion = 0;
+ try {
+ ResultSet resultSet = session.execute(VERSION_QUERY);
+ for (Row row : resultSet.all()) {
+ if (maxVersion < row.getInt(0)) {
+ maxVersion = row.getInt(0);
+ }
+ }
+ } catch (Exception e) {
+ log.error(e);
+ throw new RuntimeException(e);
+ }
+
+ return maxVersion;
+ }
+
+ protected void removeAppliedUpdates(List<String> updateFiles, int currentSchemaVersion) {
+ while (!updateFiles.isEmpty()) {
+ int version = this.extractVersionFromUpdateFile(updateFiles.get(0));
+ if (version <= currentSchemaVersion) {
+ updateFiles.remove(0);
+ } else {
+ break;
+ }
+ }
+ }
+
+ protected int extractVersionFromUpdateFile(String file) {
+ file = file.substring(file.lastIndexOf('/') + 1);
+ file = file.substring(0, file.indexOf('.'));
+ return Integer.parseInt(file);
+ }
+
+ protected List<String> getSteps(String file) throws Exception {
+ List<String> steps = new ArrayList<String>();
+ InputStream stream = null;
+ try {
+ stream = SchemaManager.class.getClassLoader().getResourceAsStream(file);
+
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(stream);
+
+ Node rootDocument = doc.getElementsByTagName(UPDATE_PLAN_ELEMENT).item(0);
+ NodeList updateStepElements = rootDocument.getChildNodes();
+
+ for (int index = 0; index < updateStepElements.getLength(); index++) {
+ Node updateStepElement = updateStepElements.item(index);
+ if (STEP_ELEMENT.equals(updateStepElement.getNodeName()) && updateStepElement.getTextContent() != null) {
+ steps.add(updateStepElement.getTextContent());
+ }
+ }
+ } catch (Exception e) {
+ log.error("Error reading the list of steps from " + file + " file.", e);
+ throw e;
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (Exception e) {
+ log.error("Error closing the stream with the list of steps from " + file + " file.", e);
+ throw e;
+ }
+ }
+ }
+
+ return steps;
+ }
+
+ protected List<String> getUpdateFiles(String folder) throws Exception {
+ List<String> files = new ArrayList<String>();
+ InputStream stream = null;
+
+ try {
+ URL resourceFolderURL = this.getClass().getClassLoader().getResource(folder);
+
+ if (resourceFolderURL.getProtocol().equals("file")) {
+ stream = this.getClass().getResourceAsStream(folder);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
+
+ String updateFile;
+ while ((updateFile = reader.readLine()) != null) {
+ files.add(folder + updateFile);
+ }
+ } else if (resourceFolderURL.getProtocol().equals("jar")) {
+ URL jarURL = this.getClass().getClassLoader().getResources(folder).nextElement();
+ JarURLConnection jarURLCon = (JarURLConnection) (jarURL.openConnection());
+ JarFile jarFile = jarURLCon.getJarFile();
+ Enumeration<JarEntry> entries = jarFile.entries();
+ while (entries.hasMoreElements()) {
+ String entry = entries.nextElement().getName();
+ if (entry.startsWith(folder) && !entry.equals(folder)) {
+ files.add(entry);
+ }
+ }
+ }
+
+ Collections.sort(files, new Comparator<String>() {
+ @Override
+ public int compare(String o1, String o2) {
+ return o1.compareTo(o2);
+ }
+ });
+ } catch (Exception e) {
+ log.error("Error reading the list of update files.", e);
+ throw e;
+ } finally {
+ if (stream != null) {
+ try{
+ stream.close();
+ } catch (Exception e) {
+ log.error("Error closing the stream with the list of update files.", e);
+ throw e;
+ }
+ }
+ }
+
+ return files;
+ }
+
+
+ protected void initCluster() throws NoHostAvailableException {
+ String[] hostNames = new String[nodes.size()];
+ for (int i = 0; i < hostNames.length; ++i) {
+ hostNames[i] = nodes.get(i).getAddress();
+ }
+
+ log.info("Initializing session to connect to " + StringUtil.arrayToString(hostNames));
+
+ Cluster cluster = new ClusterBuilder().addContactPoints(hostNames).withCredentials(username, password)
+ .withPort(nodes.get(0).getCqlPort()).withCompression(Compression.NONE).build();
+
+ log.info("Cluster connection configured.");
+
+ session = cluster.connect("system");
+ log.info("Cluster connected.");
+ }
+
+ protected void shutdown() {
+ log.info("Shutting down connections");
+ session.getCluster().shutdown();
+ }
+}
diff --git a/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/SchemaManager.java b/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/SchemaManager.java
index a43d06c..923065c 100644
--- a/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/SchemaManager.java
+++ b/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/SchemaManager.java
@@ -25,32 +25,9 @@
package org.rhq.cassandra.schema;
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.JarURLConnection;
-import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.Enumeration;
import java.util.List;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import com.datastax.driver.core.BoundStatement;
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.PreparedStatement;
-import com.datastax.driver.core.ProtocolOptions.Compression;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.datastax.driver.core.Session;
-import com.datastax.driver.core.exceptions.NoHostAvailableException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -58,284 +35,43 @@ import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.rhq.cassandra.util.ClusterBuilder;
import org.rhq.core.domain.cloud.StorageNode;
-import org.rhq.core.util.StringUtil;
/**
* @author John Sanda
*/
public class SchemaManager {
- private static final String RHQ_KEYSPACE = "rhq";
- private static final String SCHEMA_BASE_FOLDER = "schema";
- private static final String UPDATE_PLAN_ELEMENT = "updatePlan";
- private static final String STEP_ELEMENT = "step";
-
- private static final String SCHEMA_EXISTS_QUERY = "SELECT * FROM system.schema_keyspaces WHERE keyspace_name = 'rhq';";
- private static final String VERSION_COLUMNFAMILY_EXISTS_QUERY = "SELECT * from system.schema_columnfamilies WHERE keyspace_name='rhq' AND columnfamily_name='schema_version';";
- private static final String VERSION_QUERY = "SELECT version FROM rhq.schema_version";
- private static final String INSERT_VERSION_QUERY = "INSERT INTO rhq.schema_version (version, time ) VALUES ( ?, ?);";
-
-
private final Log log = LogFactory.getLog(SchemaManager.class);
- private enum Task {
- Drop("drop"),
- Create("create"),
- Update("update");
-
- private final String folder;
-
- private Task(String folder){
- this.folder = folder;
- }
-
- protected String getFolder() {
- return "" + SCHEMA_BASE_FOLDER + "/" + this.folder + "/";
- }
- }
-
- private Session session;
- private String username;
- private String password;
-
- private List<StorageNode> nodes = new ArrayList<StorageNode>();
+ private final String username;
+ private final String password;
+ private final List<StorageNode> nodes = new ArrayList<StorageNode>();
public SchemaManager(String username, String password, String... nodes) {
this(username, password, parseNodeInformation(nodes));
}
public SchemaManager(String username, String password, List<StorageNode> nodes) {
- try {
- this.username = username;
- this.password = password;
- this.nodes = nodes;
-
- this.initCluster();
- this.shutdown();
- } catch (NoHostAvailableException e) {
- throw new RuntimeException("Unable create storage node session.", e);
- }
+ this.username = username;
+ this.password = password;
+ this.nodes.addAll(nodes);
}
-
public void install() throws Exception {
- log.info("Preparing to install schema");
- try {
- initCluster();
-
- if (!schemaExists()) {
- this.executeTask(Task.Create);
- } else {
- log.info("RHQ schema already exists.");
- }
-
- this.executeTask(Task.Update);
- } catch (NoHostAvailableException e) {
- throw new RuntimeException(e);
- } finally {
- shutdown();
- }
+ VersionManager version = new VersionManager(username, password, nodes);
+ version.install();
}
public void drop() throws Exception {
- log.info("Preparing to drop RHQ schema");
- try {
- initCluster();
-
- if (schemaExists()) {
- this.executeTask(Task.Drop);
- } else {
- log.info("RHQ schema does not exist. Drop operation not required.");
- }
- } catch (NoHostAvailableException e) {
- throw new RuntimeException(e);
- } finally {
- shutdown();
- }
- }
-
- private boolean schemaExists() {
- try {
- ResultSet resultSet = session.execute(SCHEMA_EXISTS_QUERY);
- if (!resultSet.all().isEmpty()) {
- resultSet = session.execute(VERSION_COLUMNFAMILY_EXISTS_QUERY);
- return !resultSet.all().isEmpty();
- }
- return false;
- } catch (Exception e) {
- log.error(e);
- throw new RuntimeException(e);
- }
- }
-
- private int getSchemaVersion() {
- int maxVersion = 0;
- try {
- ResultSet resultSet = session.execute(VERSION_QUERY);
- for (Row row : resultSet.all()) {
- if (maxVersion < row.getInt(0)) {
- maxVersion = row.getInt(0);
- }
- }
- } catch (Exception e) {
- log.error(e);
- throw new RuntimeException(e);
- }
-
- return maxVersion;
- }
-
- private void executeTask(Task task) throws Exception {
- try {
- log.info("Starting to execute " + task + " task.");
-
- List<String> updateFiles = this.getUpdateFiles(task);
-
- if (Task.Update.equals(task)) {
- int currentSchemaVersion = this.getSchemaVersion();
- log.info("Current schema version is " + currentSchemaVersion);
- this.removeAppliedUpdates(updateFiles, currentSchemaVersion);
- }
-
- if (updateFiles.size() == 0 && Task.Update.equals(task)) {
- log.info("RHQ schema is current! No updates applied.");
- }
-
- for (String updateFile : updateFiles) {
- log.info("Applying file " + updateFile + " for " + task + " task.");
- for (String step : getSteps(updateFile)) {
- log.info("Statement: \n" + step);
- session.execute(step);
- }
-
- if (Task.Update.equals(task)) {
- this.updateSchemaVersion(updateFile);
- }
-
- log.info("File " + updateFile + " applied for " + task + " task.");
- }
- } catch (Exception e) {
- log.error(e);
- throw new RuntimeException(e);
- }
-
- log.info("Successfully executed " + task + " task.");
- }
-
- private void updateSchemaVersion(String test) {
- PreparedStatement preparedStatement = session.prepare(INSERT_VERSION_QUERY);
- BoundStatement boundStatement = preparedStatement.bind(this.extractVersionFromUpdateFile(test), new Date());
- session.execute(boundStatement);
- }
-
- private void removeAppliedUpdates(List<String> updateFiles, int currentSchemaVersion) {
- while (!updateFiles.isEmpty()) {
- int version = this.extractVersionFromUpdateFile(updateFiles.get(0));
- if (version <= currentSchemaVersion) {
- updateFiles.remove(0);
- } else {
- break;
- }
- }
- }
-
- private int extractVersionFromUpdateFile(String file) {
- file = file.substring(file.lastIndexOf('/') + 1);
- file = file.substring(0, file.indexOf('.'));
- return Integer.parseInt(file);
+ VersionManager version = new VersionManager(username, password, nodes);
+ version.drop();
}
- private List<String> getSteps(String file) throws Exception {
- List<String> steps = new ArrayList<String>();
- InputStream stream = null;
- try {
- stream = this.getClass().getClassLoader().getResourceAsStream(file);
-
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(stream);
-
- Node rootDocument = doc.getElementsByTagName(UPDATE_PLAN_ELEMENT).item(0);
- NodeList updateStepElements = rootDocument.getChildNodes();
-
- for (int index = 0; index < updateStepElements.getLength(); index++) {
- Node updateStepElement = updateStepElements.item(index);
- if (STEP_ELEMENT.equals(updateStepElement.getNodeName()) && updateStepElement.getTextContent() != null) {
- steps.add(updateStepElement.getTextContent());
- }
- }
- } catch (Exception e) {
- log.error("Error reading the list of steps from " + file + " file.", e);
- throw e;
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (Exception e) {
- log.error("Error closing the stream with the list of steps from " + file + " file.", e);
- throw e;
- }
- }
- }
-
- return steps;
- }
-
- private List<String> getUpdateFiles(Task task) throws Exception {
- List<String> files = new ArrayList<String>();
- InputStream stream = null;
-
- try {
- URL resourceFolderURL = this.getClass().getClassLoader().getResource(task.getFolder());
-
- if (resourceFolderURL.getProtocol().equals("file")) {
- stream = this.getClass().getResourceAsStream(task.getFolder());
- BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
-
- String updateFile;
- while ((updateFile = reader.readLine()) != null) {
- files.add(task.getFolder() + updateFile);
- }
- } else if (resourceFolderURL.getProtocol().equals("jar")) {
- URL jarURL = this.getClass().getClassLoader().getResources(task.getFolder()).nextElement();
- JarURLConnection jarURLCon = (JarURLConnection) (jarURL.openConnection());
- JarFile jarFile = jarURLCon.getJarFile();
- Enumeration<JarEntry> entries = jarFile.entries();
- while (entries.hasMoreElements()) {
- String entry = entries.nextElement().getName();
- if (entry.startsWith(task.getFolder()) && !entry.equals(task.getFolder())) {
- files.add(entry);
- }
- }
- }
-
- Collections.sort(files, new Comparator<String>() {
- @Override
- public int compare(String o1, String o2) {
- return o1.compareTo(o2);
- }
- });
- } catch (Exception e) {
- log.error("Error reading the list of update files.", e);
- throw e;
- } finally {
- if (stream != null) {
- try{
- stream.close();
- } catch (Exception e) {
- log.error("Error closing the stream with the list of update files.", e);
- throw e;
- }
- }
- }
-
- return files;
+ public void updateTopology() throws Exception {
+ TopologyManager topology = new TopologyManager(username, password, nodes);
+ topology.updateTopology();
}
private static List<StorageNode> parseNodeInformation(String... nodes) {
@@ -349,28 +85,6 @@ public class SchemaManager {
return parsedNodes;
}
- private void initCluster() throws NoHostAvailableException {
- String[] hostNames = new String[nodes.size()];
- for (int i = 0; i < hostNames.length; ++i) {
- hostNames[i] = nodes.get(i).getAddress();
- }
-
- log.info("Initializing session to connect to " + StringUtil.arrayToString(hostNames));
-
- Cluster cluster = new ClusterBuilder().addContactPoints(hostNames).withCredentials(username, password)
- .withPort(nodes.get(0).getCqlPort()).withCompression(Compression.NONE).build();
-
- log.info("Cluster connection configured.");
-
- session = cluster.connect("system");
- log.info("Cluster connected.");
- }
-
- private void shutdown() {
- log.info("Shutting down connections");
- session.getCluster().shutdown();
- }
-
public static void main(String[] args) throws Exception {
try {
Logger root = Logger.getRootLogger();
@@ -393,16 +107,15 @@ public class SchemaManager {
String username = args[1];
String password = args[2];
- System.out.println(args[3]);
-
SchemaManager schemaManager = new SchemaManager(username, password,
Arrays.copyOfRange(args, 3, args.length));
- System.out.println(command);
if ("install".equalsIgnoreCase(command)) {
schemaManager.install();
} else if ("drop".equalsIgnoreCase(command)) {
schemaManager.drop();
+ } else if ("topology".equalsIgnoreCase(command)) {
+ schemaManager.updateTopology();
} else {
throw new IllegalArgumentException(command + " not available.");
}
@@ -411,7 +124,5 @@ public class SchemaManager {
} finally {
System.exit(0);
}
-
}
-
}
diff --git a/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/TopologyManager.java b/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/TopologyManager.java
new file mode 100644
index 0000000..87e2a18
--- /dev/null
+++ b/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/TopologyManager.java
@@ -0,0 +1,130 @@
+/*
+ *
+ * * RHQ Management Platform
+ * * Copyright (C) 2005-2012 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.cassandra.schema;
+
+import java.util.List;
+
+import com.datastax.driver.core.BoundStatement;
+import com.datastax.driver.core.PreparedStatement;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.rhq.core.domain.cloud.StorageNode;
+
+/**
+ * @author Stefan Negrea
+ */
+public class TopologyManager extends AbstractManager {
+
+ private final Log log = LogFactory.getLog(TopologyManager.class);
+
+ private static final String TOPOLOGY_BASE_FOLDER = "topology";
+
+
+ private enum Task {
+ UpdateReplicationFactor("0001.xml"),
+ UpdateGCGrace("0002.xml");
+
+ private final String file;
+
+ private Task(String file) {
+ this.file = file;
+ }
+
+ protected String getFile() {
+ return TOPOLOGY_BASE_FOLDER + "/" + this.file;
+ }
+ }
+
+ public TopologyManager(String username, String password, List<StorageNode> nodes) {
+ super(username, password, nodes);
+ }
+
+ public void updateTopology() throws Exception {
+ initCluster();
+ if (schemaExists()) {
+ log.info("Applying topology updates...");
+ this.updateReplicationFactor(nodes.size());
+ this.updateGCGrace(nodes.size());
+ } else {
+ log.info("Topology updates cannot be applied because the schema is not installed.");
+ }
+ shutdown();
+ }
+
+ private boolean updateReplicationFactor(int numberOfNodes) throws Exception {
+ log.info("Starting to execute " + Task.UpdateReplicationFactor + " task.");
+
+ int replicationFactor = 1;
+ if (numberOfNodes < 4) {
+ replicationFactor = numberOfNodes;
+ } else {
+ replicationFactor = 3;
+ }
+
+ log.info("Applying file " + Task.UpdateReplicationFactor.getFile() + " for " + Task.UpdateReplicationFactor
+ + " task.");
+ for (String query : this.getSteps(Task.UpdateReplicationFactor.getFile())) {
+ executedPreparedStatement(query, replicationFactor);
+ }
+ log.info("File " + Task.UpdateReplicationFactor.getFile() + " applied for " + Task.UpdateReplicationFactor
+ + " task.");
+
+ log.info("Successfully executed " + Task.UpdateReplicationFactor + " task.");
+ return true;
+ }
+
+ private boolean updateGCGrace(int numberOfNodes) throws Exception {
+ log.info("Starting to execute " + Task.UpdateGCGrace + " task.");
+
+ int gcGraceSeconds = 864000;
+ if (numberOfNodes == 1) {
+ gcGraceSeconds = 0;
+ } else {
+ gcGraceSeconds = 691200; // 8 days
+ }
+
+
+ log.info("Applying file " + Task.UpdateGCGrace.getFile() + " for " + Task.UpdateGCGrace + " task.");
+ for (String query : this.getSteps(Task.UpdateGCGrace.getFile())) {
+ executedPreparedStatement(query, gcGraceSeconds);
+ }
+ log.info("File " + Task.UpdateGCGrace.getFile() + " applied for " + Task.UpdateGCGrace + " task.");
+
+ log.info("Successfully executed " + Task.UpdateGCGrace + " task.");
+ return true;
+ }
+
+ private void executedPreparedStatement(String query, Object... values) {
+ String formattedQuery = String.format(query, values);
+ log.info("Statement: \n" + formattedQuery);
+ PreparedStatement preparedStatement = session.prepare(formattedQuery);
+ BoundStatement boundStatement = preparedStatement.bind();
+ session.execute(boundStatement);
+ }
+
+}
diff --git a/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/VersionManager.java b/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/VersionManager.java
new file mode 100644
index 0000000..437e097
--- /dev/null
+++ b/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/VersionManager.java
@@ -0,0 +1,149 @@
+/*
+ *
+ * * RHQ Management Platform
+ * * Copyright (C) 2005-2012 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.cassandra.schema;
+
+import java.util.Date;
+import java.util.List;
+
+import com.datastax.driver.core.BoundStatement;
+import com.datastax.driver.core.PreparedStatement;
+import com.datastax.driver.core.exceptions.NoHostAvailableException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.rhq.core.domain.cloud.StorageNode;
+
+/**
+ * @author Stefan Negrea
+ */
+public class VersionManager extends AbstractManager {
+
+ private static final String SCHEMA_BASE_FOLDER = "schema";
+ private static final String INSERT_VERSION_QUERY = "INSERT INTO rhq.schema_version (version, time ) VALUES ( ?, ?);";
+
+ private final Log log = LogFactory.getLog(VersionManager.class);
+
+ private enum Task {
+ Drop("drop"),
+ Create("create"),
+ Update("update");
+
+ private final String folder;
+
+ private Task(String folder){
+ this.folder = folder;
+ }
+
+ protected String getFolder() {
+ return SCHEMA_BASE_FOLDER + "/" + this.folder + "/";
+ }
+ }
+
+ public VersionManager(String username, String password, List<StorageNode> nodes) {
+ super(username, password, nodes);
+ }
+
+ public void install() throws Exception {
+ log.info("Preparing to install schema");
+ try {
+ initCluster();
+
+ if (!schemaExists()) {
+ this.executeTask(Task.Create);
+ } else {
+ log.info("RHQ schema already exists.");
+ }
+
+ this.executeTask(Task.Update);
+ } catch (NoHostAvailableException e) {
+ throw new RuntimeException(e);
+ } finally {
+ shutdown();
+ }
+ }
+
+ public void drop() throws Exception {
+ log.info("Preparing to drop RHQ schema");
+ try {
+ initCluster();
+
+ if (schemaExists()) {
+ this.executeTask(Task.Drop);
+ } else {
+ log.info("RHQ schema does not exist. Drop operation not required.");
+ }
+ } catch (NoHostAvailableException e) {
+ throw new RuntimeException(e);
+ } finally {
+ shutdown();
+ }
+ }
+
+ private void executeTask(Task task) throws Exception {
+ try {
+ log.info("Starting to execute " + task + " task.");
+
+ List<String> updateFiles = this.getUpdateFiles(task.getFolder());
+
+ if (Task.Update.equals(task)) {
+ int currentSchemaVersion = this.getSchemaVersion();
+ log.info("Current schema version is " + currentSchemaVersion);
+ this.removeAppliedUpdates(updateFiles, currentSchemaVersion);
+ }
+
+ if (updateFiles.size() == 0 && Task.Update.equals(task)) {
+ log.info("RHQ schema is current! No updates applied.");
+ }
+
+ for (String updateFile : updateFiles) {
+ log.info("Applying file " + updateFile + " for " + task + " task.");
+ for (String step : getSteps(updateFile)) {
+ log.info("Statement: \n" + step);
+ session.execute(step);
+ }
+
+ if (Task.Update.equals(task)) {
+ this.updateSchemaVersion(updateFile);
+ }
+
+ log.info("File " + updateFile + " applied for " + task + " task.");
+ }
+ } catch (Exception e) {
+ log.error(e);
+ throw new RuntimeException(e);
+ }
+
+ log.info("Successfully executed " + task + " task.");
+ }
+
+ private void updateSchemaVersion(String updateFileName) {
+ PreparedStatement preparedStatement = session.prepare(INSERT_VERSION_QUERY);
+ BoundStatement boundStatement = preparedStatement.bind(this.extractVersionFromUpdateFile(updateFileName),
+ new Date());
+ session.execute(boundStatement);
+ }
+}
diff --git a/modules/common/cassandra-schema/src/main/resources/topology/0001.xml b/modules/common/cassandra-schema/src/main/resources/topology/0001.xml
new file mode 100644
index 0000000..f4382dc
--- /dev/null
+++ b/modules/common/cassandra-schema/src/main/resources/topology/0001.xml
@@ -0,0 +1,13 @@
+<updatePlan>
+ <step>
+ UPDATE system.schema_keyspaces SET
+ strategy_options='{"replication_factor":"%s"}'
+ WHERE keyspace_name='rhq'
+ </step>
+
+ <step>
+ UPDATE system.schema_keyspaces SET
+ strategy_options='{"replication_factor":"%s"}'
+ WHERE keyspace_name='system_auth'
+ </step>
+</updatePlan>
\ No newline at end of file
diff --git a/modules/common/cassandra-schema/src/main/resources/topology/0002.xml b/modules/common/cassandra-schema/src/main/resources/topology/0002.xml
new file mode 100644
index 0000000..250aec0
--- /dev/null
+++ b/modules/common/cassandra-schema/src/main/resources/topology/0002.xml
@@ -0,0 +1,38 @@
+<updatePlan>
+ <step>
+ UPDATE system.schema_columnfamilies
+ SET gc_grace_seconds = %s
+ WHERE keyspace_name='rhq' AND columnfamily_name='metrics_index';
+ </step>
+
+ <step>
+ UPDATE system.schema_columnfamilies
+ SET gc_grace_seconds = %s
+ WHERE keyspace_name='rhq' AND columnfamily_name='raw_metrics';
+ </step>
+
+ <step>
+ UPDATE system.schema_columnfamilies
+ SET gc_grace_seconds = %s
+ WHERE keyspace_name='rhq' AND columnfamily_name='one_hour_metrics';
+ </step>
+
+ <step>
+ UPDATE system.schema_columnfamilies
+ SET gc_grace_seconds = %s
+ WHERE keyspace_name='rhq' AND columnfamily_name='six_hour_metrics';
+ </step>
+
+ <step>
+ UPDATE system.schema_columnfamilies
+ SET gc_grace_seconds = %s
+ WHERE keyspace_name='rhq' AND columnfamily_name='twenty_four_hour_metrics';
+ </step>
+
+ <step>
+ UPDATE system.schema_columnfamilies
+ SET gc_grace_seconds = %s
+ WHERE keyspace_name='rhq' AND columnfamily_name='schema_version';
+ </step>
+
+</updatePlan>
\ No newline at end of file
10 years, 10 months
[rhq] modules/common modules/enterprise
by mazz
modules/common/jboss-as-dmr-client/src/main/java/org/rhq/common/jbossas/client/controller/SocketBindingJBossASClient.java | 73 ++++++++++
modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/ServerInstallUtil.java | 49 +++++-
2 files changed, 113 insertions(+), 9 deletions(-)
New commits:
commit cf58fcee5e938f9e012753f8325c12208763407e
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri May 31 17:05:00 2013 -0400
BZ 966160 bind some internal services to local loopback only
diff --git a/modules/common/jboss-as-dmr-client/src/main/java/org/rhq/common/jbossas/client/controller/SocketBindingJBossASClient.java b/modules/common/jboss-as-dmr-client/src/main/java/org/rhq/common/jbossas/client/controller/SocketBindingJBossASClient.java
index 247eefe..5800956 100644
--- a/modules/common/jboss-as-dmr-client/src/main/java/org/rhq/common/jbossas/client/controller/SocketBindingJBossASClient.java
+++ b/modules/common/jboss-as-dmr-client/src/main/java/org/rhq/common/jbossas/client/controller/SocketBindingJBossASClient.java
@@ -31,6 +31,7 @@ public class SocketBindingJBossASClient extends JBossASClient {
public static final String SOCKET_BINDING_GROUP = "socket-binding-group";
public static final String SOCKET_BINDING = "socket-binding";
public static final String PORT = "port";
+ public static final String INTERFACE = "interface";
public static final String PORT_OFFSET = "port-offset";
public static final String STANDARD_SOCKETS = "standard-sockets";
public static final String JBOSS_SYSPROP_PORT_OFFSET = "jboss.socket.binding.port-offset";
@@ -163,4 +164,76 @@ public class SocketBindingJBossASClient extends JBossASClient {
}
return; // everything is OK
}
+
+ /**
+ * Sets the interface name for the named standard socket binding.
+ *
+ * @param socketBindingName the name of the standard socket binding whose interface is to be set
+ * @param interfaceName the new interface name
+ * @throws Exception
+ */
+ public void setStandardSocketBindingInterface(String socketBindingName, String interfaceName) throws Exception {
+ setStandardSocketBindingInterfaceExpression(socketBindingName, null, interfaceName);
+ }
+
+ /**
+ * Sets the interface name for the named standard socket binding.
+ * If sysPropName is null, this simply sets the interface name explicitly.
+ * If sysPropName is not null, this sets the interface to the expression "${sysPropName:interfaceName}".
+ *
+ * @param socketBindingName the name of the standard socket binding whose interface is to be set
+ * @param sysPropName the name of the system property whose value is to be the interface name
+ * @param interfaceName the default interface name if the sysPropName is not defined
+ * @throws Exception
+ */
+ public void setStandardSocketBindingInterfaceExpression(String socketBindingName, String sysPropName,
+ String interfaceName) throws Exception {
+ setSocketBindingInterfaceExpression(STANDARD_SOCKETS, socketBindingName, sysPropName, interfaceName);
+ }
+
+ /**
+ * Sets the interface name for the named socket binding found in the named socket binding group.
+ *
+ * @param socketBindingGroupName the name of the socket binding group that has the named socket binding
+ * @param socketBindingName the name of the socket binding whose interface is to be set
+ * @param interfaceName the new interface name
+ * @throws Exception
+ */
+ public void setSocketBindingPort(String socketBindingGroupName, String socketBindingName, String interfaceName)
+ throws Exception {
+ setSocketBindingInterfaceExpression(socketBindingGroupName, socketBindingName, null, interfaceName);
+ }
+
+ /**
+ * Sets the interface name for the named socket binding found in the named socket binding group.
+ * If sysPropName is null, this simply sets the interface name explicitly to the given name.
+ * If sysPropName is not null, this sets the interface name to the expression "${sysPropName:interfaceName}".
+ *
+ * @param socketBindingGroupName the name of the socket binding group that has the named socket binding
+ * @param socketBindingName the name of the socket binding whose interface is to be set
+ * @param sysPropName the name of the system property whose value is to be the interface name
+ * @param interfaceName the default interface name if the sysPropName is not defined
+ * @throws Exception
+ */
+ public void setSocketBindingInterfaceExpression(String socketBindingGroupName, String socketBindingName,
+ String sysPropName, String interfaceName) throws Exception {
+
+ // /socket-binding-group=standard-sockets/socket-binding=messaging/:write-attribute(name=interface,value=unsecure)
+
+ String interfaceNameValue;
+ if (sysPropName != null) {
+ interfaceNameValue = "${" + sysPropName + ":" + interfaceName + "}";
+ } else {
+ interfaceNameValue = String.valueOf(interfaceName);
+ }
+
+ Address addr = Address.root().add(SOCKET_BINDING_GROUP, socketBindingGroupName, SOCKET_BINDING,
+ socketBindingName);
+ ModelNode request = createWriteAttributeRequest(INTERFACE, interfaceNameValue, addr);
+ ModelNode results = execute(request);
+ if (!isSuccess(results)) {
+ throw new FailureException(results);
+ }
+ return; // everything is OK
+ }
}
diff --git a/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/ServerInstallUtil.java b/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/ServerInstallUtil.java
index 61c0853..0318e0e 100644
--- a/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/ServerInstallUtil.java
+++ b/modules/enterprise/server/installer/src/main/java/org/rhq/enterprise/server/installer/ServerInstallUtil.java
@@ -95,18 +95,27 @@ public class ServerInstallUtil {
public String sysprop;
public int port;
public boolean required = true;
+ public String interfaceName = null; // not null if we know we want it to be changed from its default setting
public SocketBindingInfo(String n, String s, int p) {
- name = n;
- sysprop = s;
- port = p;
+ this.name = n;
+ this.sysprop = s;
+ this.port = p;
}
- public SocketBindingInfo(String name, String sysprop, int port, boolean required) {
+ public SocketBindingInfo(String n, String s, int p, String i) {
+ this.name = n;
+ this.sysprop = s;
+ this.port = p;
+ this.interfaceName = i;
+ }
+
+ public SocketBindingInfo(String name, String sysprop, int port, String interfaceName, boolean required) {
this.name = name;
+ this.sysprop = sysprop;
this.port = port;
+ this.interfaceName = interfaceName;
this.required = required;
- this.sysprop = sysprop;
}
}
@@ -126,9 +135,9 @@ public class ServerInstallUtil {
defaultSocketBindings.add(new SocketBindingInfo(SocketBindingJBossASClient.DEFAULT_BINDING_JACORB_SSL,
"rhq.server.socket.binding.port.jacorb-ssl", 2529));
defaultSocketBindings.add(new SocketBindingInfo(SocketBindingJBossASClient.DEFAULT_BINDING_MESSAGING,
- "rhq.server.socket.binding.port.messaging", 4445));
+ "rhq.server.socket.binding.port.messaging", 4445, "management"));
defaultSocketBindings.add(new SocketBindingInfo(SocketBindingJBossASClient.DEFAULT_BINDING_MESSAGING_THRUPUT,
- "rhq.server.socket.binding.port.messaging-throughput", 4455));
+ "rhq.server.socket.binding.port.messaging-throughput", 4455, "management"));
defaultSocketBindings.add(new SocketBindingInfo(SocketBindingJBossASClient.DEFAULT_BINDING_MGMT_HTTP,
"jboss.management.http.port", 6990));
defaultSocketBindings.add(new SocketBindingInfo(SocketBindingJBossASClient.DEFAULT_BINDING_MGMT_HTTPS,
@@ -136,7 +145,7 @@ public class ServerInstallUtil {
defaultSocketBindings.add(new SocketBindingInfo(SocketBindingJBossASClient.DEFAULT_BINDING_MGMT_NATIVE,
"jboss.management.native.port", 6999));
defaultSocketBindings.add(new SocketBindingInfo(SocketBindingJBossASClient.DEFAULT_BINDING_REMOTING,
- "rhq.server.socket.binding.port.remoting", 3447));
+ "rhq.server.socket.binding.port.remoting", 3447, "management"));
defaultSocketBindings.add(new SocketBindingInfo(SocketBindingJBossASClient.DEFAULT_BINDING_TXN_RECOVERY_ENV,
"rhq.server.socket.binding.port.txn-recovery-environment", 3712));
defaultSocketBindings.add(new SocketBindingInfo(SocketBindingJBossASClient.DEFAULT_BINDING_TXN_STATUS_MGR,
@@ -1514,6 +1523,7 @@ public class ServerInstallUtil {
public static void setSocketBindings(ModelControllerClient mcc, HashMap<String, String> serverProperties)
throws Exception {
+
final SocketBindingJBossASClient client = new SocketBindingJBossASClient(mcc);
for (SocketBindingInfo binding : defaultSocketBindings) {
// use the port defined by the server's properties if set, otherwise, just use our hardcoded default
@@ -1535,9 +1545,30 @@ public class ServerInstallUtil {
throw e;
}
else {
- LOG.info(String.format("Setting socket binding: [%s] resulted in [%s] -- this is harmless " , binding.name , e.getMessage())); // TODO log at debug level only?
+ LOG.info(String.format("Setting socket binding port for [%s] resulted in [%s] - this is harmless ",
+ binding.name, e.getMessage())); // TODO log at debug level only?
+ }
+ }
+
+ // if we need to switch the binding's interface, do it now
+ if (binding.interfaceName != null) {
+ LOG.info(String.format("Setting socket binding [%s] to use interface [%s]", binding.name,
+ binding.interfaceName));
+ try {
+ client.setStandardSocketBindingInterface(binding.name, binding.interfaceName);
+ } catch (Exception e) {
+ // If the binding is required, we re-throw a possible exception. Otherwise just log
+ if (binding.required) {
+ throw e;
+ } else {
+ LOG.info(String.format(
+ "Setting socket binding interface for [%s] resulted in [%s] - this is harmless ",
+ binding.name, e.getMessage())); // TODO log at debug level only?
+ }
}
}
}
+
+ return;
}
}
10 years, 10 months
[rhq] modules/enterprise
by John Sanda
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementBaselineManagerBean.java | 27 ----------
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementBaselineManagerLocal.java | 12 ----
2 files changed, 39 deletions(-)
New commits:
commit edfe3bb4565b58800a7c02c0ef6a240bdb7ffeaf
Author: John Sanda <jsanda(a)redhat.com>
Date: Fri May 31 13:53:28 2013 -0400
removing unused method that has been replaced with more granular transaction demarcation
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementBaselineManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementBaselineManagerBean.java
index c18ff97..6140c4d 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementBaselineManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementBaselineManagerBean.java
@@ -277,33 +277,6 @@ public class MeasurementBaselineManagerBean implements MeasurementBaselineManage
}
}
- @SuppressWarnings("unchecked")
- @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public int _calculateAutoBaselinesINSERT(long amountOfData) throws Exception {
- long endTime = System.currentTimeMillis();
- long startTime = endTime - amountOfData;
-
- //1. Find dynamic schedule ids that do not have baseline calculated
- Query query = this.entityManager
- .createNamedQuery(MeasurementBaseline.QUERY_FIND_MEASUREMENT_SCHEDULES_WITHOUT_AUTOBASELINES);
- query.setMaxResults(BASELINE_PROCESSING_LIMIT);
- List<MeasurementSchedule> scheduleIdsWithoutBaselines = query.getResultList();
-
- //2. calculate the baselines based metrics data
- MetricsBaselineCalculator baselineCalculator = new MetricsBaselineCalculator(sessionManager.getMetricsDAO());
- List<MeasurementBaseline> results = baselineCalculator.calculateBaselines(scheduleIdsWithoutBaselines,
- startTime, endTime);
-
- //3. persist all calculated baselines to SQL db
- for (Object result : results) {
- entityManager.persist(result);
- }
- entityManager.flush();
-
- //4. return the number of schedule ids initially retrieved for calculation
- return scheduleIdsWithoutBaselines.size();
- }
-
/**
* If the measurement baselines for the corresponding resources are the same, that value will be returned;
* otherwise null will be returned
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementBaselineManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementBaselineManagerLocal.java
index 8781fc5..af6145a 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementBaselineManagerLocal.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementBaselineManagerLocal.java
@@ -66,18 +66,6 @@ public interface MeasurementBaselineManagerLocal {
int _calculateAutoBaselinesDELETE(long olderThanTime) throws Exception;
/**
- * Inserts baselines "as appropriate" for measurements that have at least amountOfData
- * @param amountOfData will use amountOfData to compute new min/max/mean for baselines as appropriate
- * @return number of rows inserted
- * @deprecated This method is pending removal after peer review. Because 1hr data is
- * now stored in Cassandra, transaction boundaries needed to change. This method has
- * been replaced by {@link #getSchedulesWithoutBaselines()}, {@link #calculateBaselines(java.util.List, long)},
- * and {@link #saveNewBaselines(java.util.List)}.
- * @throws Exception
- */
- int _calculateAutoBaselinesINSERT(long amountOfData) throws Exception;
-
- /**
* <strong>Note</strong> This method exists only for transaction demarcation.
*
* @return A list of schedules that do not have baselines. This list is not assumed
10 years, 10 months
[rhq] .classpath
by Jay Shaughnessy
.classpath | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
New commits:
commit 64434917916b9a35a98be729072e9a1f95898257
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Fri May 31 13:38:15 2013 -0400
eclipse .classpath changes
diff --git a/.classpath b/.classpath
index ccd357e..6be942c 100644
--- a/.classpath
+++ b/.classpath
@@ -201,15 +201,12 @@
<classpathentry kind="src" path="etc/samples/custom-serverplugin/src/main/java"/>
<classpathentry kind="src" path="etc/samples/simplereport-serverplugin/src/main/java"/>
<classpathentry kind="src" path="etc/agentspawn/src/main/java"/>
- <classpathentry kind="src" path="modules/common/cassandra-common/src/main/java"/>
- <classpathentry kind="src" path="modules/common/cassandra-common-itests/src/test/java"/>
<classpathentry kind="src" path="modules/plugins/cassandra/src/main/java"/>
<classpathentry kind="src" path="modules/plugins/cassandra/src/test/java"/>
<classpathentry excluding="**" kind="src" path="modules/enterprise/comm/src/test/resources"/>
<classpathentry excluding="**" kind="src" path="modules/enterprise/agent/src/main/resources"/>
<classpathentry excluding="**" kind="src" path="modules/enterprise/agent/src/test/resources"/>
<classpathentry kind="src" path="modules/enterprise/server/server-metrics/src/main/java"/>
- <classpathentry kind="src" path="modules/common/cassandra-common-itests/src/main/java"/>
<classpathentry kind="src" path="modules/enterprise/server/server-metrics/src/test/java"/>
<classpathentry kind="src" path="modules/common/cassandra-schema/src/main/java"/>
<classpathentry kind="src" path="modules/common/cassandra-ccm/cassandra-ccm-core/src/main/java"/>
@@ -375,12 +372,12 @@
<classpathentry exported="true" kind="var" path="M2_REPO/org/jboss/byteman/byteman-install/1.5.2/byteman-install-1.5.2.jar" sourcepath="M2_REPO/org/jboss/byteman/byteman-install/1.5.2/byteman-install-1.5.2-sources.jar"/>
<classpathentry exported="true" kind="var" path="M2_REPO/org/jboss/byteman/byteman-submit/1.5.2/byteman-submit-1.5.2.jar" sourcepath="M2_REPO/org/jboss/byteman/byteman-submit/1.5.2/byteman-submit-1.5.2-sources.jar"/>
<classpathentry exported="true" kind="var" path="M2_REPO/org/jboss/byteman/byteman-bmunit/1.5.2/byteman-bmunit-1.5.2.jar" sourcepath="M2_REPO/org/jboss/byteman/byteman-bmunit/1.5.2/byteman-bmunit-1.5.2-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/apache/cassandra/cassandra-all/1.2.2/cassandra-all-1.2.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/cassandra/cassandra-all/1.2.4/cassandra-all-1.2.4.jar"/>
<classpathentry kind="var" path="M2_REPO/com/datastax/cassandra/cassandra-driver-core/1.0.0-rhq-1.2.4/cassandra-driver-core-1.0.0-rhq-1.2.4.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/thrift/libthrift/0.7.0/libthrift-0.7.0.jar"/>
<classpathentry kind="var" path="M2_REPO/commons-cli/commons-cli/1.2/commons-cli-1.2.jar"/>
<classpathentry kind="var" path="M2_REPO/com/google/guava/guava/12.0/guava-12.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/apache/cassandra/cassandra-thrift/1.2.2/cassandra-thrift-1.2.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/cassandra/cassandra-thrift/1.2.4/cassandra-thrift-1.2.4.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/commons/commons-exec/1.1/commons-exec-1.1.jar"/>
<classpathentry kind="var" path="M2_REPO/org/eclipse/jetty/aggregate/jetty-all/8.1.8.v20121106/jetty-all-8.1.8.v20121106.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
10 years, 10 months
[rhq] modules/core modules/enterprise
by John Sanda
modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementBaseline.java | 4
modules/core/domain/src/test/java/org/rhq/core/domain/measurement/test/MeasurementBaselineTest.java | 54 ----------
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementBaselineManagerBean.java | 11 --
3 files changed, 5 insertions(+), 64 deletions(-)
New commits:
commit 35001d92bab83871f901156f82309fd58665ddb7
Author: John Sanda <jsanda(a)redhat.com>
Date: Fri May 31 13:19:42 2013 -0400
refactor query to find schedules without baselines
The JPQL query previously used resulted in a very inefficient cross join that
could result in statement timeouts in the database with a just a moderately
large number of schedules. This commit removes MeasurementBaselineTest since it
only tested the query that has been replaced. There is already test coverage
of the query in MeasurementBaselineManagerTest.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementBaseline.java b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementBaseline.java
index 743c12a..5bd0e8b 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementBaseline.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementBaseline.java
@@ -42,9 +42,6 @@ import javax.persistence.Table;
@Entity
@NamedQueries( {
- @NamedQuery(name = MeasurementBaseline.QUERY_FIND_MEASUREMENT_SCHEDULES_WITHOUT_AUTOBASELINES, query = "SELECT schedule FROM MeasurementSchedule schedule "
- + "WHERE schedule.definition.numericType = 0 AND "
- + "schedule.id NOT IN (SELECT mb.schedule.id FROM MeasurementBaseline mb)"),
@NamedQuery(name = MeasurementBaseline.QUERY_FIND_BY_RESOURCE, query = "SELECT mb FROM MeasurementBaseline mb WHERE mb.schedule.resource.id = :resourceId"),
@NamedQuery(name = MeasurementBaseline.QUERY_FIND_BY_RESOURCE_IDS_AND_DEF_IDS, query = "SELECT mb FROM MeasurementBaseline mb "
+ "WHERE mb.schedule.resource.id IN (:resourceIds) AND mb.schedule.definition.id IN (:definitionIds)"),
@@ -72,7 +69,6 @@ public class MeasurementBaseline implements Serializable {
public static final String QUERY_DELETE_BY_RESOURCES = "MeasurementBaseline.deleteByResources";
public static final String QUERY_CALC_FIRST_AUTOBASELINE = "MeasurementBaseline.calcFirstAutoBaseline";
public static final String QUERY_DELETE_EXISTING_AUTOBASELINES = "MeasurementBaseline.deleteExistingAutoBaseline";
- public static final String QUERY_FIND_MEASUREMENT_SCHEDULES_WITHOUT_AUTOBASELINES = "MeasurementBaseline.findMetricSchedulesWithoutAutoBaselines";
private static final long serialVersionUID = 1L;
@GeneratedValue(strategy = GenerationType.AUTO, generator = "RHQ_MEASUREMENT_BLINE_ID_SEQ")
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/measurement/test/MeasurementBaselineTest.java b/modules/core/domain/src/test/java/org/rhq/core/domain/measurement/test/MeasurementBaselineTest.java
deleted file mode 100644
index 57d45e0..0000000
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/measurement/test/MeasurementBaselineTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
- /*
- * 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, 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.core.domain.measurement.test;
-
-import java.util.List;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-
-import org.testng.annotations.Test;
-
-import org.rhq.core.domain.measurement.MeasurementBaseline;
-import org.rhq.core.domain.test.AbstractEJB3Test;
-
-/**
- * Tests for MeasurementBaseline entity
- *
- * @author Stefan Negrea
- */
-@Test(groups = "integration.ejb3")
-public class MeasurementBaselineTest extends AbstractEJB3Test {
-
- @Test
- public void testSelectQuery() throws Exception {
- EntityManager entityManager = getEntityManager();
- Query query = entityManager
- .createNamedQuery(MeasurementBaseline.QUERY_FIND_MEASUREMENT_SCHEDULES_WITHOUT_AUTOBASELINES);
- List<String> rows = query.getResultList();
- System.out.println("----------------------------------------------------------------------------");
- System.out.println(rows.size());
- System.out.println(rows);
- System.out.println("----------------------------------------------------------------------------");
- }
-}
\ No newline at end of file
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementBaselineManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementBaselineManagerBean.java
index 22ebb71..c18ff97 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementBaselineManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementBaselineManagerBean.java
@@ -189,8 +189,6 @@ public class MeasurementBaselineManagerBean implements MeasurementBaselineManage
* In any event, an appropriate chunking solution needs to be found, and that partitioning strategy
* needs to replace the limits in the query today.
*/
-// int schedulesWithoutBaselines = measurementBaselineManager
-// ._calculateAutoBaselinesINSERT(amountOfData);
List<MeasurementSchedule> schedulesWithoutBaselines =
measurementBaselineManager.getSchedulesWithoutBaselines();
measurementBaselineManager.calculateBaselines(schedulesWithoutBaselines, now, amountOfData);
@@ -225,12 +223,13 @@ public class MeasurementBaselineManagerBean implements MeasurementBaselineManage
@SuppressWarnings("unchecked")
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public List<MeasurementSchedule> getSchedulesWithoutBaselines() {
- Query query = this.entityManager
- .createNamedQuery(MeasurementBaseline.QUERY_FIND_MEASUREMENT_SCHEDULES_WITHOUT_AUTOBASELINES);
+ String sql =
+ "SELECT s.* FROM rhq_measurement_sched s INNER JOIN rhq_measurement_def d ON s.definition = d.id " +
+ "LEFT JOIN rhq_measurement_bline b ON s.id = b.schedule_id WHERE b.schedule_id IS NULL AND d.numeric_type = 0";
+ Query query = this.entityManager.createNativeQuery(sql, MeasurementSchedule.class);
query.setMaxResults(BASELINE_PROCESSING_LIMIT);
- List<MeasurementSchedule> scheduleIdsWithoutBaselines = query.getResultList();
- return scheduleIdsWithoutBaselines;
+ return query.getResultList();
}
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
10 years, 10 months
[rhq] modules/enterprise
by Jay Shaughnessy
modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java | 90 +++++++---
1 file changed, 71 insertions(+), 19 deletions(-)
New commits:
commit a2f0541fc336477d32a9ffec8c93dd0420d59c6c
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Fri May 31 11:44:49 2013 -0400
Fix test cleanup and add a bit more to test code.
diff --git a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java
index be62ad8..dc742c6 100644
--- a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java
+++ b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java
@@ -37,7 +37,10 @@ import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.rhq.core.domain.alert.AlertCondition;
+import org.rhq.core.domain.alert.AlertConditionCategory;
import org.rhq.core.domain.alert.AlertDampening;
+import org.rhq.core.domain.alert.AlertDampening.TimeUnits;
import org.rhq.core.domain.alert.AlertDefinition;
import org.rhq.core.domain.alert.AlertPriority;
import org.rhq.core.domain.alert.BooleanExpression;
@@ -51,6 +54,11 @@ import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.criteria.AlertDefinitionCriteria;
import org.rhq.core.domain.criteria.ResourceCriteria;
+import org.rhq.core.domain.measurement.DataType;
+import org.rhq.core.domain.measurement.DisplayType;
+import org.rhq.core.domain.measurement.MeasurementCategory;
+import org.rhq.core.domain.measurement.MeasurementDefinition;
+import org.rhq.core.domain.measurement.MeasurementUnits;
import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.domain.resource.Agent;
import org.rhq.core.domain.resource.InventoryStatus;
@@ -156,9 +164,9 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
throw e;
} finally {
- containerTearDown();
logout();
cleanDB();
+ containerTearDown();
}
}
@@ -169,13 +177,13 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
public void execute() throws Exception {
EntityManager em = getEntityManager();
- universalName = getClass().getName();
+ universalName = getClass().getSimpleName();
- agent = new Agent("localhost", "localhost", 0, "foo", "bar");
+ agent = new Agent(universalName, "localhost", 0, "foo", "bar");
server = new Server();
server.setAddress("localhost");
- server.setName("localhost");
+ server.setName(universalName);
server.setOperationMode(OperationMode.NORMAL);
server.setAgents(Collections.singletonList(agent));
@@ -189,6 +197,9 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
resourceType = new ResourceTypeBuilder().createPlatformResourceType().withId(0).withName(universalName)
.withPlugin(universalName).build();
+ MeasurementDefinition md = new MeasurementDefinition(universalName, MeasurementCategory.PERFORMANCE,
+ MeasurementUnits.PERCENTAGE, DataType.MEASUREMENT, false, 100000, DisplayType.DETAIL);
+ resourceType.addMetricDefinition(md);
resourceGroup = new ResourceGroup(universalName, resourceType);
@@ -201,13 +212,13 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
resourceGroup.addExplicitResource(res);
}
- templateAlertDefinition = createDefinitionForTest(universalName + " template", true);
+ templateAlertDefinition = createDefinitionForTest("template", true);
templateAlertDefinition.setResourceType(resourceType);
- groupAlertDefinition = createDefinitionForTest(universalName + " group", true);
+ groupAlertDefinition = createDefinitionForTest("group", true);
groupAlertDefinition.setGroup(resourceGroup);
- resourceAlertDefinition = createDefinitionForTest(universalName + " resource", true);
+ resourceAlertDefinition = createDefinitionForTest("resource", true);
resourceAlertDefinition.setResource(resources.iterator().next());
em.persist(agent);
@@ -247,6 +258,8 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
//@BeforeMethod
private void containerSetup() {
+ prepareScheduler();
+
alertSenderService = new TestAlertSenderPluginService(getTempDir());
prepareCustomServerPluginService(alertSenderService);
alertSenderService.masterConfig.getPluginDirectory().mkdirs();
@@ -260,6 +273,7 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
private void containerTearDown() throws Exception {
unprepareServerPluginService();
unprepareForTestAgents();
+ unprepareScheduler();
}
//@AfterClass(alwaysRun = true)
@@ -271,18 +285,35 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
removeNoExceptions(resourceAlertDefinition);
removeNoExceptions(groupAlertDefinition);
removeNoExceptions(templateAlertDefinition);
+
+ LookupUtil.getResourceGroupManager().deleteResourceGroup(LookupUtil.getSubjectManager().getOverlord(),
+ resourceGroup.getId());
+
executeInTransaction(false, new TransactionCallback() {
public void execute() throws Exception {
- em.createQuery("delete from AlertNotification ").executeUpdate();
- em.createQuery("delete from AlertDefinition ").executeUpdate();
+ em.createQuery("delete from AlertNotification an where an.senderName like '" + universalName + "%'")
+ .executeUpdate();
+ em.createQuery("delete from AlertCondition ac where ac.name like '" + universalName + "%'")
+ .executeUpdate();
+ em.createQuery("delete from AlertDefinition ad where ad.name like '" + universalName + "%'")
+ .executeUpdate();
}
});
- removeNoExceptions(resourceGroup);
- for (Resource r : resources) {
- r.removeExplicitGroup(resourceGroup);
- r.getAlertDefinitions().clear();
- removeNoExceptions(r);
- }
+
+ executeInTransaction(false, new TransactionCallback() {
+ public void execute() throws Exception {
+ em.clear();
+ for (Resource r : resources) {
+ r = em.find(Resource.class, r.getId());
+ try {
+ ResourceTreeHelper.deleteResource(em, r);
+ } catch (Exception e) {
+ LOG.error("Failed to DELETE Resource from database: " + r, e);
+ }
+ }
+ }
+ });
+
removeNoExceptions(resourceType);
removeNoExceptions(subject);
removeNoExceptions(role);
@@ -334,7 +365,7 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
TestAlertSender.setExpectedSubject(null);
TestAlertSender.resetValidateMethodCallCount();
- Resource res = getCopyTestsResource();
+ final Resource res = getCopyTestsResource();
//apply the template manually - this is done in server-agent back-and-forth that we
//don't test here and which is complex to mock out.
@@ -389,7 +420,7 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
AlertDefinition groupOriginatingDef = null;
for (AlertDefinition d : foundAlertDefs) {
- if ((universalName + " group").equals(d.getName())) {
+ if ((universalName + ":group").equals(d.getName())) {
groupOriginatingDef = d;
break;
}
@@ -665,12 +696,33 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
private AlertDefinition createDefinition(String name) {
AlertDefinition ret = new AlertDefinition();
- ret.setName(name);
+ ret.setName(universalName + ":" + name);
ret.setPriority(AlertPriority.MEDIUM);
- ret.setAlertDampening(new AlertDampening(AlertDampening.Category.NONE));
ret.setConditionExpression(BooleanExpression.ANY);
ret.setRecoveryId(0);
+ AlertCondition ac = new AlertCondition();
+ ac.setName(universalName);
+ ac.setCategory(AlertConditionCategory.THRESHOLD);
+ ac.setComparator(">");
+ ac.setThreshold(0.75D);
+ //for (MeasurementDefinition d : resourceType.getMetricDefinitions()) {
+ // if ("Calculated.HeapUsagePercentage".equals(d.getName())) {
+ // ac.setMeasurementDefinition(d);
+ // ac.setName(d.getDisplayName());
+ // break;
+ // }
+ // }
+ //assert null != ac.getMeasurementDefinition() : "Did not find expected measurement definition [Calculated.HeapUsagePercentage] for "
+ // + resourceType;
+ ret.addCondition(ac);
+
+ AlertDampening dampener = new AlertDampening(AlertDampening.Category.PARTIAL_COUNT);
+ dampener.setPeriod(15);
+ dampener.setPeriodUnits(TimeUnits.MINUTES);
+ dampener.setValue(10);
+ ret.setAlertDampening(dampener);
+
return ret;
}
10 years, 11 months
[rhq] Branch 'feature/cassandra-backend' - modules/enterprise
by Jay Shaughnessy
modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java | 90 +++++++---
1 file changed, 71 insertions(+), 19 deletions(-)
New commits:
commit eabd7ffdaae051deda02947d6c787060affb64be
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Fri May 31 11:44:49 2013 -0400
Fix test cleanup and add a bit more to test code.
diff --git a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java
index be62ad8..dc742c6 100644
--- a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java
+++ b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java
@@ -37,7 +37,10 @@ import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.rhq.core.domain.alert.AlertCondition;
+import org.rhq.core.domain.alert.AlertConditionCategory;
import org.rhq.core.domain.alert.AlertDampening;
+import org.rhq.core.domain.alert.AlertDampening.TimeUnits;
import org.rhq.core.domain.alert.AlertDefinition;
import org.rhq.core.domain.alert.AlertPriority;
import org.rhq.core.domain.alert.BooleanExpression;
@@ -51,6 +54,11 @@ import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.criteria.AlertDefinitionCriteria;
import org.rhq.core.domain.criteria.ResourceCriteria;
+import org.rhq.core.domain.measurement.DataType;
+import org.rhq.core.domain.measurement.DisplayType;
+import org.rhq.core.domain.measurement.MeasurementCategory;
+import org.rhq.core.domain.measurement.MeasurementDefinition;
+import org.rhq.core.domain.measurement.MeasurementUnits;
import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.domain.resource.Agent;
import org.rhq.core.domain.resource.InventoryStatus;
@@ -156,9 +164,9 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
throw e;
} finally {
- containerTearDown();
logout();
cleanDB();
+ containerTearDown();
}
}
@@ -169,13 +177,13 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
public void execute() throws Exception {
EntityManager em = getEntityManager();
- universalName = getClass().getName();
+ universalName = getClass().getSimpleName();
- agent = new Agent("localhost", "localhost", 0, "foo", "bar");
+ agent = new Agent(universalName, "localhost", 0, "foo", "bar");
server = new Server();
server.setAddress("localhost");
- server.setName("localhost");
+ server.setName(universalName);
server.setOperationMode(OperationMode.NORMAL);
server.setAgents(Collections.singletonList(agent));
@@ -189,6 +197,9 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
resourceType = new ResourceTypeBuilder().createPlatformResourceType().withId(0).withName(universalName)
.withPlugin(universalName).build();
+ MeasurementDefinition md = new MeasurementDefinition(universalName, MeasurementCategory.PERFORMANCE,
+ MeasurementUnits.PERCENTAGE, DataType.MEASUREMENT, false, 100000, DisplayType.DETAIL);
+ resourceType.addMetricDefinition(md);
resourceGroup = new ResourceGroup(universalName, resourceType);
@@ -201,13 +212,13 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
resourceGroup.addExplicitResource(res);
}
- templateAlertDefinition = createDefinitionForTest(universalName + " template", true);
+ templateAlertDefinition = createDefinitionForTest("template", true);
templateAlertDefinition.setResourceType(resourceType);
- groupAlertDefinition = createDefinitionForTest(universalName + " group", true);
+ groupAlertDefinition = createDefinitionForTest("group", true);
groupAlertDefinition.setGroup(resourceGroup);
- resourceAlertDefinition = createDefinitionForTest(universalName + " resource", true);
+ resourceAlertDefinition = createDefinitionForTest("resource", true);
resourceAlertDefinition.setResource(resources.iterator().next());
em.persist(agent);
@@ -247,6 +258,8 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
//@BeforeMethod
private void containerSetup() {
+ prepareScheduler();
+
alertSenderService = new TestAlertSenderPluginService(getTempDir());
prepareCustomServerPluginService(alertSenderService);
alertSenderService.masterConfig.getPluginDirectory().mkdirs();
@@ -260,6 +273,7 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
private void containerTearDown() throws Exception {
unprepareServerPluginService();
unprepareForTestAgents();
+ unprepareScheduler();
}
//@AfterClass(alwaysRun = true)
@@ -271,18 +285,35 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
removeNoExceptions(resourceAlertDefinition);
removeNoExceptions(groupAlertDefinition);
removeNoExceptions(templateAlertDefinition);
+
+ LookupUtil.getResourceGroupManager().deleteResourceGroup(LookupUtil.getSubjectManager().getOverlord(),
+ resourceGroup.getId());
+
executeInTransaction(false, new TransactionCallback() {
public void execute() throws Exception {
- em.createQuery("delete from AlertNotification ").executeUpdate();
- em.createQuery("delete from AlertDefinition ").executeUpdate();
+ em.createQuery("delete from AlertNotification an where an.senderName like '" + universalName + "%'")
+ .executeUpdate();
+ em.createQuery("delete from AlertCondition ac where ac.name like '" + universalName + "%'")
+ .executeUpdate();
+ em.createQuery("delete from AlertDefinition ad where ad.name like '" + universalName + "%'")
+ .executeUpdate();
}
});
- removeNoExceptions(resourceGroup);
- for (Resource r : resources) {
- r.removeExplicitGroup(resourceGroup);
- r.getAlertDefinitions().clear();
- removeNoExceptions(r);
- }
+
+ executeInTransaction(false, new TransactionCallback() {
+ public void execute() throws Exception {
+ em.clear();
+ for (Resource r : resources) {
+ r = em.find(Resource.class, r.getId());
+ try {
+ ResourceTreeHelper.deleteResource(em, r);
+ } catch (Exception e) {
+ LOG.error("Failed to DELETE Resource from database: " + r, e);
+ }
+ }
+ }
+ });
+
removeNoExceptions(resourceType);
removeNoExceptions(subject);
removeNoExceptions(role);
@@ -334,7 +365,7 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
TestAlertSender.setExpectedSubject(null);
TestAlertSender.resetValidateMethodCallCount();
- Resource res = getCopyTestsResource();
+ final Resource res = getCopyTestsResource();
//apply the template manually - this is done in server-agent back-and-forth that we
//don't test here and which is complex to mock out.
@@ -389,7 +420,7 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
AlertDefinition groupOriginatingDef = null;
for (AlertDefinition d : foundAlertDefs) {
- if ((universalName + " group").equals(d.getName())) {
+ if ((universalName + ":group").equals(d.getName())) {
groupOriginatingDef = d;
break;
}
@@ -665,12 +696,33 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
private AlertDefinition createDefinition(String name) {
AlertDefinition ret = new AlertDefinition();
- ret.setName(name);
+ ret.setName(universalName + ":" + name);
ret.setPriority(AlertPriority.MEDIUM);
- ret.setAlertDampening(new AlertDampening(AlertDampening.Category.NONE));
ret.setConditionExpression(BooleanExpression.ANY);
ret.setRecoveryId(0);
+ AlertCondition ac = new AlertCondition();
+ ac.setName(universalName);
+ ac.setCategory(AlertConditionCategory.THRESHOLD);
+ ac.setComparator(">");
+ ac.setThreshold(0.75D);
+ //for (MeasurementDefinition d : resourceType.getMetricDefinitions()) {
+ // if ("Calculated.HeapUsagePercentage".equals(d.getName())) {
+ // ac.setMeasurementDefinition(d);
+ // ac.setName(d.getDisplayName());
+ // break;
+ // }
+ // }
+ //assert null != ac.getMeasurementDefinition() : "Did not find expected measurement definition [Calculated.HeapUsagePercentage] for "
+ // + resourceType;
+ ret.addCondition(ac);
+
+ AlertDampening dampener = new AlertDampening(AlertDampening.Category.PARTIAL_COUNT);
+ dampener.setPeriod(15);
+ dampener.setPeriodUnits(TimeUnits.MINUTES);
+ dampener.setValue(10);
+ ret.setAlertDampening(dampener);
+
return ret;
}
10 years, 11 months
[rhq] etc/rhq-ircBot
by Jiri Kremser
etc/rhq-ircBot/src/main/java/org/rhq/etc/ircbot/RhqIrcBotListener.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
New commits:
commit 29ccfef5c5ff757501a2ee3e6aa45c80ecd28e97
Author: Jirka Kremser <jkremser(a)redhat.com>
Date: Fri May 31 16:31:28 2013 +0200
Ending curly bracket was missing.
diff --git a/etc/rhq-ircBot/src/main/java/org/rhq/etc/ircbot/RhqIrcBotListener.java b/etc/rhq-ircBot/src/main/java/org/rhq/etc/ircbot/RhqIrcBotListener.java
index 6b8529f..dd22dbf 100644
--- a/etc/rhq-ircBot/src/main/java/org/rhq/etc/ircbot/RhqIrcBotListener.java
+++ b/etc/rhq-ircBot/src/main/java/org/rhq/etc/ircbot/RhqIrcBotListener.java
@@ -347,7 +347,7 @@ public class RhqIrcBotListener extends ListenerAdapter<RhqIrcBot> {
return "404 Developer Not Found, selecting randomly " + doNotNotify(randomDevel) + ". Check the " + SUPPORT_LINK;
}
- private static String whoIsOnPto(String link) {
+ private String whoIsOnPto(String link) {
try {
String onPto = "";
Document doc = Jsoup.connect(link).ignoreContentType(true).get();
@@ -376,3 +376,5 @@ public class RhqIrcBotListener extends ListenerAdapter<RhqIrcBot> {
public void setDocspacePassword(String docspacePassword) {
this.docspacePassword = docspacePassword;
}
+
+}
\ No newline at end of file
10 years, 11 months
[rhq] modules/plugins
by Thomas Segismont
modules/plugins/netservices/src/test/java/org/rhq/plugins/netservices/itest/PortNetServiceComponentTest.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
New commits:
commit 32a4a3b76990d13035974f88e13a328027d88cd8
Author: Thomas Segismont <tsegismo(a)redhat.com>
Date: Fri May 31 15:20:43 2013 +0200
Bad port range in previous commit (PortNetServiceComponentTest)
diff --git a/modules/plugins/netservices/src/test/java/org/rhq/plugins/netservices/itest/PortNetServiceComponentTest.java b/modules/plugins/netservices/src/test/java/org/rhq/plugins/netservices/itest/PortNetServiceComponentTest.java
index ebab01f..7b580da 100644
--- a/modules/plugins/netservices/src/test/java/org/rhq/plugins/netservices/itest/PortNetServiceComponentTest.java
+++ b/modules/plugins/netservices/src/test/java/org/rhq/plugins/netservices/itest/PortNetServiceComponentTest.java
@@ -60,9 +60,9 @@ public class PortNetServiceComponentTest extends NetServiceComponentTest {
private static final InetAddress LOOPBACK_ADDRESS = InetAddress.getLoopbackAddress();
- private static final int MIN_DYNAMIC_PORT = 8080/*49152*/;
+ private static final int MIN_DYNAMIC_PORT = 49152;
- private static final int MAX_PORT_NUMBER = 8081/*65535*/;
+ private static final int MAX_PORT_NUMBER = 65535;
private PortNetServiceComponent portNetServiceComponent;
10 years, 11 months
[rhq] modules/enterprise
by Jiri Kremser
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/storage/StorageNodeDetailView.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
New commits:
commit de1176d72488b08beb30243677adacf155bddc53
Author: Jirka Kremser <jkremser(a)redhat.com>
Date: Fri May 31 15:15:02 2013 +0200
fixing typo in my previous commit (3d3f1aae4)
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/storage/StorageNodeDetailView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/storage/StorageNodeDetailView.java
index 1f94abb..3d75e17 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/storage/StorageNodeDetailView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/storage/StorageNodeDetailView.java
@@ -186,7 +186,7 @@ public class StorageNodeDetailView extends EnhancedVLayout implements Bookmarkab
// portItem.setValidators(portValidator);
jmxPortItem.setValue(storageNode.getJmxPort());
- final StaticTextItem jmxConnectionUrlItem = new StaticTextItem("jmxConnectionUrl", MSG.view_adminTopology_storageNode_jmxUrl());
+ final StaticTextItem jmxConnectionUrlItem = new StaticTextItem("jmxConnectionUrl", MSG.view_adminTopology_storageNode_jmxConnectionUrl());
jmxConnectionUrlItem.setValue(storageNode.getJMXConnectionURL());
final TextItem cqlPortItem = new TextItem(FIELD_CQL_PORT.propertyName(), FIELD_CQL_PORT.title());
10 years, 11 months