modules/core/dbutils/pom.xml |
2
modules/core/dbutils/src/main/scripts/dbsetup/measurement-schema.xml |
16
modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml |
37 +
modules/core/domain/src/main/java/org/rhq/core/domain/cloud/StorageNode.java |
239 ++++++++++
modules/core/domain/src/main/java/org/rhq/core/domain/criteria/StorageNodeCriteria.java |
99 ++++
5 files changed, 392 insertions(+), 1 deletion(-)
New commits:
commit af37e8382dea898f19939d3454a3f95737944ab1
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Fri May 3 17:32:55 2013 -0400
Add initial StorageNode entity support: schema/dbupgrade/entity/criteria
TODO: SLSB CRUD
diff --git a/modules/core/dbutils/pom.xml b/modules/core/dbutils/pom.xml
index 65bb69a..703950a 100644
--- a/modules/core/dbutils/pom.xml
+++ b/modules/core/dbutils/pom.xml
@@ -17,7 +17,7 @@
<description>Database schema setup, upgrade and other
utilities</description>
<properties>
- <db.schema.version>2.132</db.schema.version>
+ <db.schema.version>2.133</db.schema.version>
<rhq.ds.type-mapping>${rhq.test.ds.type-mapping}</rhq.ds.type-mapping>
<rhq.ds.server-name>${rhq.test.ds.server-name}</rhq.ds.server-name>
<rhq.ds.db-name>${rhq.test.ds.db-name}</rhq.ds.db-name>
diff --git a/modules/core/dbutils/src/main/scripts/dbsetup/measurement-schema.xml
b/modules/core/dbutils/src/main/scripts/dbsetup/measurement-schema.xml
index 90bd30f..c15aa1f 100644
--- a/modules/core/dbutils/src/main/scripts/dbsetup/measurement-schema.xml
+++ b/modules/core/dbutils/src/main/scripts/dbsetup/measurement-schema.xml
@@ -446,4 +446,20 @@
</constraint>
</table>
+ <table name="RHQ_STORAGE_NODE">
+ <column name="ID" default="sequence-only"
initial="10001" primarykey="true" required="true"
type="INTEGER" />
+ <column name="ADDRESS" required="true" size="255"
type="VARCHAR2" />
+ <column name="JMX_PORT" required="true"
type="INTEGER" />
+ <column name="CQL_PORT" required="true"
type="INTEGER" />
+ <column name="OPERATION_MODE" required="true"
size="32" type="VARCHAR2" />
+ <column name="CTIME" required="true" type="LONG"
/>
+ <column name="MTIME" required="true" type="LONG"
/>
+ <column name="RESOURCE_ID" required="false"
type="INTEGER" references="RHQ_RESOURCE(ID)" />
+
+ <!-- This index is for constraint, not performance -->
+ <index name="RHQ_STORAGE_NODE_UNIQUE" unique="true">
+ <field ref="ADDRESS" />
+ </index>
+ </table>
+
</dbsetup>
\ No newline at end of file
diff --git a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
index 862944a..f9729cf 100644
--- a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
+++ b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
@@ -2037,6 +2037,43 @@
</schema-directSQL>
</schemaSpec>
+ <schemaSpec version="2.133">
+ <!-- RHQ_STORAGE_NODE -->
+ <schema-createSequence name="RHQ_STORAGE_NODE_ID_SEQ"
initial="10001" />
+ <schema-directSQL>
+ <statement desc="Creating table RHQ_STORAGE_NODE">
+ CREATE TABLE RHQ_STORAGE_NODE (
+ ID INTEGER PRIMARY KEY)
+ </statement>
+ </schema-directSQL>
+ <schema-addColumn table="RHQ_STORAGE_NODE"
column="ADDRESS" columnType="VARCHAR2" precision="255"
/>
+ <schema-alterColumn table="RHQ_STORAGE_NODE"
column="ADDRESS" nullable="FALSE" />
+ <schema-addColumn table="RHQ_STORAGE_NODE"
column="JMX_PORT" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_STORAGE_NODE"
column="JMX_PORT" nullable="FALSE" />
+ <schema-addColumn table="RHQ_STORAGE_NODE"
column="CQL_PORT" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_STORAGE_NODE"
column="CQL_PORT" nullable="FALSE" />
+ <schema-addColumn table="RHQ_STORAGE_NODE"
column="OPERATION_MODE" columnType="VARCHAR2"
precision="32"/>
+ <schema-alterColumn table="RHQ_STORAGE_NODE"
column="OPERATION_MODE" nullable="FALSE" />
+ <schema-addColumn table="RHQ_STORAGE_NODE"
column="CTIME" columnType="LONG" />
+ <schema-alterColumn table="RHQ_STORAGE_NODE"
column="CTIME" nullable="FALSE" />
+ <schema-addColumn table="RHQ_STORAGE_NODE"
column="MTIME" columnType="LONG" />
+ <schema-alterColumn table="RHQ_STORAGE_NODE"
column="MTIME" nullable="FALSE" />
+ <schema-addColumn table="RHQ_STORAGE_NODE"
column="RESOURCE_ID" columnType="INTEGER" />
+ <schema-directSQL>
+ <statement desc="Creating RHQ_STORAGE_NODE foreign key to
RHQ_RESOURCE">
+ ALTER TABLE RHQ_STORAGE_NODE
+ ADD CONSTRAINT RHQ_SN_RESOURCE_ID_FK
+ FOREIGN KEY (RESOURCE_ID)
+ REFERENCES RHQ_RESOURCE (ID)
+ </statement>
+ </schema-directSQL>
+ <schema-directSQL ignoreError="true">
+ <statement desc="Creating unique index on ADDRESS
column">
+ CREATE UNIQUE INDEX RHQ_ADDRESS ON RHQ_STORAGE_NODE ( ADDRESS )
+ </statement>
+ </schema-directSQL>
+ </schemaSpec>
+
</dbupgrade>
</target>
</project>
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/cloud/StorageNode.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/cloud/StorageNode.java
new file mode 100644
index 0000000..79b3ece
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/cloud/StorageNode.java
@@ -0,0 +1,239 @@
+/*
+ * 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.cloud;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToOne;
+import javax.persistence.PrePersist;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+import org.rhq.core.domain.resource.Resource;
+
+/**
+ * An RHQ Storage Node (Cassandra)
+ *
+ * @author Jay Shaughnessy
+ */
+@Entity(name = "StorageNode")
+@NamedQueries( //
+{
+ @NamedQuery(name = StorageNode.QUERY_FIND_ALL, query = "SELECT s FROM
StorageNode s"),
+ @NamedQuery(name = StorageNode.QUERY_FIND_BY_ADDRESS, query = "" //
+ + " SELECT s " //
+ + " FROM StorageNode s " //
+ + "LEFT JOIN FETCH s.resource r " //
+ + " WHERE s.address = :address"),
+ @NamedQuery(name = StorageNode.QUERY_FIND_ALL_NOT_INSTALLED, query = "SELECT s
FROM StorageNode s WHERE NOT s.operationMode = 'INSTALLED'"),
+ @NamedQuery(name = StorageNode.QUERY_FIND_ALL_NORMAL, query = "SELECT s FROM
StorageNode s WHERE s.operationMode = 'NORMAL'"),
+ @NamedQuery(name = StorageNode.QUERY_DELETE_BY_ID, query = "" //
+ + "DELETE FROM StorageNode s WHERE s.id = :storageNodeId ") })
+@SequenceGenerator(allocationSize = org.rhq.core.domain.util.Constants.ALLOCATION_SIZE,
name = "RHQ_STORAGE_NODE_ID_SEQ", sequenceName =
"RHQ_STORAGE_NODE_ID_SEQ")
+@Table(name = "RHQ_STORAGE_NODE")
+public class StorageNode implements Serializable {
+
+ public static final long serialVersionUID = 1L;
+
+ public static final String QUERY_FIND_ALL = "StorageNode.findAll";
+ public static final String QUERY_FIND_BY_ADDRESS =
"StorageNode.findByName";
+ public static final String QUERY_FIND_ALL_NOT_INSTALLED =
"StorageNode.findAllCloudMembers";
+ public static final String QUERY_DELETE_BY_ID = "StorageNode.deleteById";
+ public static final String QUERY_FIND_ALL_NORMAL =
"StorageNode.findAllNormalCloudMembers";
+
+ @Column(name = "ID", nullable = false)
+ @GeneratedValue(strategy = GenerationType.AUTO, generator =
"RHQ_STORAGE_NODE_ID_SEQ")
+ @Id
+ private int id;
+
+ @Column(name = "ADDRESS", nullable = false)
+ private String address;
+
+ @Column(name = "JMX_PORT", nullable = false)
+ private int jmxPort;
+
+ @Column(name = "CQL_PORT", nullable = false)
+ private int cqlPort;
+
+ @Column(name = "OPERATION_MODE", nullable = false)
+ @Enumerated(EnumType.STRING)
+ private OperationMode operationMode;
+
+ // the time this storage node was installed into the infrastructure
+ @Column(name = "CTIME", nullable = false)
+ private long ctime;
+
+ // the time this storage node was last updated
+ @Column(name = "MTIME", nullable = false)
+ private long mtime;
+
+ @JoinColumn(name = "RESOURCE_ID", referencedColumnName = "ID",
nullable = true)
+ @OneToOne(fetch = FetchType.LAZY, optional = true)
+ private Resource resource;
+
+ // required for JPA
+ public StorageNode() {
+ }
+
+ public StorageNode(int storageNodeId) {
+ this.id = storageNodeId;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public int getJmxPort() {
+ return jmxPort;
+ }
+
+ public void setJmxPort(int jmxPort) {
+ this.jmxPort = jmxPort;
+ }
+
+ public int getCqlPort() {
+ return cqlPort;
+ }
+
+ public void setCqlPort(int cqlPort) {
+ this.cqlPort = cqlPort;
+ }
+
+ public long getCtime() {
+ return ctime;
+ }
+
+ public long getMtime() {
+ return mtime;
+ }
+
+ public void setMtime(long mtime) {
+ this.mtime = mtime;
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ public void setResource(Resource resource) {
+ this.resource = resource;
+ }
+
+ public OperationMode getOperationMode() {
+ return operationMode;
+ }
+
+ public void setOperationMode(OperationMode operationMode) {
+ this.operationMode = operationMode;
+ }
+
+ public enum OperationMode {
+
+ DOWN("This storage node is down"), //
+ INSTALLED("This storage node is newly installed but not yet
operationial"), //
+ MAINTENANCE("This storage node is in maintenance mode"), //
+ NORMAL("This storage node is running normally");
+
+ public final String message;
+
+ private OperationMode(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "StorageNode [id=" + id + ", address=" + address +
", jmxPort=" + jmxPort + ", cqlPort=" + cqlPort
+ + ", operationMode=" + operationMode + ", mtime=" + mtime
+ "]";
+ }
+
+ @PrePersist
+ void onPersist() {
+ this.ctime = System.currentTimeMillis();
+ this.mtime = this.ctime;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (int) (ctime ^ (ctime >>> 32));
+ result = prime * result + ((address == null) ? 0 : address.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null || !(obj instanceof StorageNode)) {
+ return false;
+ }
+
+ final StorageNode other = (StorageNode) obj;
+
+ if (ctime != other.ctime) {
+ return false;
+ }
+
+ if (address == null) {
+ if (other.address != null) {
+ return false;
+ }
+ } else if (!address.equals(other.address)) {
+ return false;
+ }
+
+ return true;
+ }
+
+}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/StorageNodeCriteria.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/StorageNodeCriteria.java
new file mode 100644
index 0000000..18ae492
--- /dev/null
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/StorageNodeCriteria.java
@@ -0,0 +1,99 @@
+/*
+ * 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 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.core.domain.criteria;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+
+import org.rhq.core.domain.cloud.StorageNode;
+import org.rhq.core.domain.cloud.StorageNode.OperationMode;
+import org.rhq.core.domain.util.PageOrdering;
+
+/**
+ * Criteria object for querying {@link StorageNode}s.
+ * Only subject with MANAGE_SETTINGS can fetch these instances.
+ *
+ * @author Jay Shaughnessy
+ */
+(a)XmlAccessorType(XmlAccessType.FIELD)
+@SuppressWarnings("unused")
+public class StorageNodeCriteria extends Criteria {
+
+ private static final long serialVersionUID = 1L;
+
+ public static final String SORT_FIELD_CTIME = "ctime";
+
+ public static final String SORT_FIELD_ADDRESS = "address";
+
+ private String filterAddress;
+ private Integer filterJmxPort;
+ private Integer filterCqlPort;
+ private List<OperationMode> filterOperationMode; // requires override
+ private Integer filterResourceId; // requires override
+
+ private boolean fetchResource;
+
+ private PageOrdering sortCtime;
+ private PageOrdering sortAddress;
+
+ public StorageNodeCriteria() {
+ filterOverrides.put("operationMode", "operationMode IN ( ?
)");
+ filterOverrides.put("resourceId", "resource.id = ?");
+ }
+
+ public Class<?> getPersistentClass() {
+ return StorageNode.class;
+ }
+
+ public void addFilterAddress(String filterAddress) {
+ this.filterAddress = filterAddress;
+ }
+
+ public void addFilterJmxPort(Integer filterJmxPort) {
+ this.filterJmxPort = filterJmxPort;
+ }
+
+ public void addFilterCqlPort(Integer filterCqlPort) {
+ this.filterCqlPort = filterCqlPort;
+ }
+
+ public void addFilterOperationMode(OperationMode... operationMode) {
+ if (operationMode != null && operationMode.length > 0) {
+ this.filterOperationMode = Arrays.asList(operationMode);
+ }
+ }
+
+ public void addFilterResourceId(Integer filterResourceId) {
+ this.filterResourceId = filterResourceId;
+ }
+
+ public void addSortCtime(PageOrdering sort) {
+ addSortField(SORT_FIELD_CTIME);
+ this.sortCtime = sort;
+ }
+
+ public void addSortAddress(PageOrdering sort) {
+ addSortField(SORT_FIELD_ADDRESS);
+ this.sortAddress = sort;
+ }
+}